<projectname>qtrapids</projectname>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
- <description></description>
- <defaultencoding></defaultencoding>
+ <description/>
+ <defaultencoding/>
</general>
<kdevfileview>
<groups>
<includePaths>.;</includePaths>
</codecompletion>
<creategettersetter>
- <prefixGet></prefixGet>
+ <prefixGet/>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>
</kdevdoctreeview>
<kdevdebugger>
<general>
- <dbgshell></dbgshell>
+ <dbgshell/>
<breakpoints/>
<programargs/>
<gdbpath>/usr/bin/gdb</gdbpath>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>false</floatingtoolbar>
- <configGdbScript></configGdbScript>
- <runShellScript></runShellScript>
- <runGdbScript></runGdbScript>
+ <configGdbScript/>
+ <runShellScript/>
+ <runGdbScript/>
<raiseGDBOnStart>false</raiseGDBOnStart>
</general>
<display>
<kdevtrollproject>
<run>
<mainprogram>/home/vaatala/Projects/qtrapids/trunk/bin/qtrapids</mainprogram>
- <programargs></programargs>
+ <programargs/>
<directoryradio>executable</directoryradio>
- <globaldebugarguments></globaldebugarguments>
+ <globaldebugarguments/>
<globalcwd>/home/vaatala/Projects/qtrapids/trunk/bin</globalcwd>
<useglobalprogram>true</useglobalprogram>
<terminal>false</terminal>
<runmultiplejobs>false</runmultiplejobs>
<numberofjobs>1</numberofjobs>
<dontact>false</dontact>
- <makebin></makebin>
+ <makebin/>
<prio>0</prio>
<envvars/>
</make>
}
+void AlertWaiterThread::allAlerts(bool enable)
+{
+ // If all enabled, set all alert cateogries:
+ if (enable) {
+ btSession_->set_alert_mask(libtorrent::alert::all_categories);
+ } else {
+ // Otherwise set to default, which is only error notifications.
+ btSession_->set_alert_mask(libtorrent::alert::error_notification);
+ }
+}
+
+
void AlertWaiterThread::run()
{
TorrentAlert const *alertTemp = NULL;
while (true)
{
qDebug() << "AlertWaiter running";
- // wait_for_alert() returns libtorrent alert.
+ // wait_for_alert() call blocks. Returns libtorrent alert.
// Returns NULL, if no alerts in timeout period.
alertTemp = btSession_->wait_for_alert(ALERT_WAIT_TIMEOUT);
emit alert(alertTemp);
+ // 2000 us = 2ms. Gives main thread time to handle alert signal.
+ usleep(2000);
}
}
-
-
virtual ~AlertWaiterThread();
+ void allAlerts(bool enable = true);
+
virtual void run(); // Overridden from QThread
signals:
alertWaiter_(NULL)
{
alertWaiter_ = new AlertWaiterThread(&btSession_, this);
+ alertWaiter_->allAlerts();
connect(alertWaiter_, SIGNAL(alert(TorrentAlert const*)), this, SLOT(on_alert(TorrentAlert const*)));
alertWaiter_->start();
}
{
// Delegate to Libtorrent and return QTorrentHandle.
QTorrentHandle handle(btSession_.add_torrent(params));
+ qDebug() << "Is valid: " << handle.isValid();
return handle;
}
// ========================== SLOTS ==============================
-void QBittorrentSession::on_alert(TorrentAlert const *al)
+void QBittorrentSession::on_alert(TorrentAlert const *al)
+ //NOTE: al parameter not necessarily needed here, as we pop_alert() now!
{
+
qDebug() << "QBittorrentSession:on_alert(" << al << ")";
- emit alert(al);
+// if (al)
+// qDebug() << "on_alert():" << QString::fromStdString(al->message());
+
+
+ std::auto_ptr<TorrentAlert> alertPtr = btSession_.pop_alert();
+ emit alert(alertPtr);
}
#ifndef QBITTORRENTSESSION_H
#define QBITTORRENTSESSION_H
+#include <memory>
+
#include <QObject>
#include <libtorrent/session.hpp>
+#include <libtorrent/torrent_info.hpp>
#include "QTorrentHandle.h"
QTorrentHandle addTorrent(AddTorrentParams const& params);
signals:
- void alert(TorrentAlert const *al);
+ void alert(std::auto_ptr<TorrentAlert> al);
private slots:
void on_alert(TorrentAlert const *al);
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+#include <QDebug>
+
#include "QTorrentHandle.h"
QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) :
- torrentHandle(handle)
+ torrentHandle_(handle)
{
}
{
}
+bool QTorrentHandle::isValid() const
+{
+ return torrentHandle_.is_valid();
+}
+
QTorrentHandle(libtorrent::torrent_handle handle);
~QTorrentHandle();
+ bool isValid() const;
private:
QTorrentHandle(); // Prevent default construct.
- libtorrent::torrent_handle torrentHandle;
+ libtorrent::torrent_handle torrentHandle_;
};
#include "DownloadView.h"
#include "SeedView.h"
+#include "PreferencesDialog.h"
#include "MainWindow.h"
tabWidget_(NULL),
dlView_(NULL),
seedView_(NULL),
+ preferencesDialog_(NULL),
+ settings_(),
btSession_()
{
// MENUBAR
QAction *openAction = tempMenu->addAction(tr("&Open"));
QAction *quitAction = tempMenu->addAction(tr("&Quit"));
+ tempMenu = menuBar->addMenu(tr("&Settings"));
+ QAction *preferencesAction = tempMenu->addAction(tr("&Preferences"));
+
tempMenu = menuBar->addMenu(tr("&Help"));
QAction *aboutAction = tempMenu->addAction(tr("&About"));
QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt"));
setMenuBar(menuBar);
connect(openAction, SIGNAL(triggered()), this, SLOT(on_openAction_clicked()));
connect(quitAction, SIGNAL(triggered()), this, SLOT(on_quitAction_clicked()));
+ connect(preferencesAction, SIGNAL(triggered()), this, SLOT(on_preferencesAction_clicked()));
connect(aboutAction, SIGNAL(triggered()), this, SLOT(on_aboutAction_clicked()));
connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(on_aboutQtAction_clicked()));
-
// TABWIDGET (central widget)
tabWidget_ = new QTabWidget();
close();
}
+void MainWindow::on_preferencesAction_clicked()
+{
+ if (!preferencesDialog_) {
+ preferencesDialog_ = new PreferencesDialog(this);
+ }
+ preferencesDialog_->show();
+ preferencesDialog_->raise();
+ preferencesDialog_->activateWindow();
+}
void MainWindow::on_aboutAction_clicked()
{
}
// Otherwise add torrent
- /*
// For params, see: http://www.rasterbar.com/products/libtorrent/manual.html#add-torrent
AddTorrentParams addParams;
- addParams.ti = torrent_info(boost::filesystem::path const& filename);
- addParams.save_path = "/home/vaatala/Downloads"; // The only mandatory parameter, rest are optional.
+ boost::intrusive_ptr<libtorrent::torrent_info> tiTmp =
+ new libtorrent::torrent_info(boost::filesystem::path(file.toStdString()));
+ addParams.ti = tiTmp;
+ addParams.save_path = boost::filesystem::path(settings_.value("download/directory").toString().toStdString()); // The only mandatory parameter, rest are optional.
//addParams.storage_mode = libtorrent::storage_mode_allocate;
- btSession_.addTorrent();
- */
+ btSession_.addTorrent(addParams);
}
#define MAINWINDOW_H
#include <QMainWindow>
+#include <QSettings>
#include "QBittorrentSession.h"
class QTabWidget;
class DownloadView;
class SeedView;
-
+class PreferencesDialog;
/**
@author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
private slots:
void on_openAction_clicked();
void on_quitAction_clicked();
+ void on_preferencesAction_clicked();
void on_aboutAction_clicked();
void on_aboutQtAction_clicked();
void handleToolBarAction(QAction* action);
QTabWidget *tabWidget_;
DownloadView *dlView_;
SeedView *seedView_;
+ PreferencesDialog *preferencesDialog_;
+ QSettings settings_;
QBittorrentSession btSession_;
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2009 by Lassi Väätämöinen *
+ * lassi.vaatamoinen@ixonos.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#include <QDebug>
+#include <QBoxLayout>
+#include <QLineEdit>
+#include <QLabel>
+#include <QPushButton>
+#include <QDialogButtonBox>
+#include <QAbstractButton>
+#include <QFileDialog>
+
+#include "PreferencesDialog.h"
+
+PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) :
+ QDialog(parent, f), // Superclass
+ dirLineEdit_(NULL),
+ dialogButtons_(NULL),
+ settings_()
+{
+ setWindowTitle("Preferences");
+
+ QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom);
+ QBoxLayout *horizontalBox1 = new QBoxLayout(QBoxLayout::LeftToRight);
+ setLayout(verticalBox);
+ verticalBox->addLayout(horizontalBox1);
+
+ QLabel *dirLabel = new QLabel(tr("Download directory: "));
+ dirLineEdit_ = new QLineEdit(this);
+ QPushButton *browseDirButton = new QPushButton(tr("Browse.."));
+
+ horizontalBox1->addWidget(dirLabel);
+ horizontalBox1->addWidget(dirLineEdit_);
+ horizontalBox1->addWidget(browseDirButton);
+
+ connect(browseDirButton, SIGNAL(clicked()),
+ this, SLOT(on_browseDirButtonClicked()));
+
+
+ dialogButtons_ = new QDialogButtonBox(this);
+ dialogButtons_->setStandardButtons(QDialogButtonBox::Ok
+ | QDialogButtonBox::Apply
+ | QDialogButtonBox::Cancel);
+
+ verticalBox->addWidget(dialogButtons_);
+
+ connect(dialogButtons_, SIGNAL(clicked(QAbstractButton*)),
+ this, SLOT(on_buttonClicked(QAbstractButton*)));
+
+ // Set saved preference values to fields.
+ ReadSettings();
+
+}
+
+
+PreferencesDialog::~PreferencesDialog()
+{
+}
+
+// ======================== SLOTS ========================
+void PreferencesDialog::on_browseDirButtonClicked()
+{
+ QFileDialog *dialog
+ = new QFileDialog(this, "Download directory",
+ QString(), tr("Torrent files (*.torrent)"));
+
+ dialog->setFileMode(QFileDialog::Directory);
+ dialog->setOption(QFileDialog::ShowDirsOnly, true);
+
+ connect(dialog, SIGNAL(fileSelected(const QString&)),
+ this, SLOT(on_downloadDirectorySelected(const QString&)));
+
+ dialog->show();
+}
+
+void PreferencesDialog::on_buttonClicked(QAbstractButton* button)
+{
+ switch (dialogButtons_->buttonRole ( button ) )
+ {
+ case QDialogButtonBox::AcceptRole :
+ qDebug() << "PreferencesDialog: OK";
+ WriteSettings();
+ close();
+ break;
+ case QDialogButtonBox::ApplyRole :
+ qDebug() << "PreferencesDialog: APPLY";
+ WriteSettings();
+ break;
+ case QDialogButtonBox::RejectRole :
+ qDebug() << "PreferencesDialog: CANCEL";
+ close();
+ break;
+ default:
+ return;
+ }
+}
+
+void PreferencesDialog::on_downloadDirectorySelected(const QString& directory)
+{
+ qDebug() << "PreferencesDialog::on_downloadDirectorySelected(): " << directory;
+ // Torrent filename empty, do nothing.
+ if (directory == "")
+ return;
+
+ dirLineEdit_->insert(directory);
+
+ /// @todo check that user has privileges to write to this directory.
+}
+
+
+// ========================= Private functions ==========================
+void PreferencesDialog::WriteSettings()
+{
+ settings_.setValue("download/directory", dirLineEdit_->text());
+
+ // NOTE: We might need to call QSettigns::sync() here to instantly write settings.
+ // settings are written also by QSettings() destructor and by event loop at regular interval.
+}
+
+void PreferencesDialog::ReadSettings()
+{
+ dirLineEdit_->insert(settings_.value("download/directory").toString());
+
+ // NOTE: We might need to call QSettigns::sync() here to instantly write settings.
+ // settings are written also by QSettings() destructor and by event loop at regular interval.
+}
+
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2009 by Lassi Väätämöinen *
+ * lassi.vaatamoinen@ixonos.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef PREFERENCESDIALOG_H
+#define PREFERENCESDIALOG_H
+
+#include <QDialog>
+#include <QSettings>
+
+
+class QAbstractButton;
+class QLineEdit;
+class QDialogButtonBox;
+
+/**
+ @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
+*/
+class PreferencesDialog : public QDialog
+{
+
+ Q_OBJECT
+
+ public:
+ PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
+
+ ~PreferencesDialog();
+
+ private slots:
+ void on_browseDirButtonClicked();
+ void on_buttonClicked(QAbstractButton* button);
+ void on_downloadDirectorySelected(const QString& directory);
+
+ private:
+ QLineEdit *dirLineEdit_;
+ QDialogButtonBox *dialogButtons_;
+ QSettings settings_;
+
+ // Private functions:
+ void WriteSettings();
+ void ReadSettings();
+};
+
+#endif
SOURCES += DownloadView.cpp \
MainWindow.cpp \
SeedView.cpp \
- main.cpp
+ main.cpp \
+ PreferencesDialog.cpp
HEADERS += DownloadView.h \
MainWindow.h \
-SeedView.h
+SeedView.h \
+ PreferencesDialog.h
TEMPLATE = app
TARGET = qtrapids
int main(int argc, char *argv[])
{
+ QCoreApplication::setOrganizationName("Ixonos");
+ QCoreApplication::setOrganizationDomain("ixonos.com");
+ QCoreApplication::setApplicationName("QtRapids");
- // Q_INIT_RESOURCE(application);
+ // Q_INIT_RESOURCE(application);
QApplication app(argc, argv);
MainWindow *mainWindow = new MainWindow();
mainWindow->show();