</debugarguments>
</run>
<general>
- <activedir>src/gui</activedir>
+ <activedir>src</activedir>
</general>
<make>
<abortonerror>true</abortonerror>
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#include <QDebug>
#include "AlertWaiterThread.h"
-AlertWaiterThread::AlertWaiterThread(QObject* parent): QThread(parent)
+// Constants:
+// Timeout for waiting alerts
+const libtorrent::time_duration ALERT_WAIT_TIMEOUT
+ = libtorrent::time_duration(libtorrent::seconds(15));
+
+
+AlertWaiterThread::AlertWaiterThread(TorrentSession *const session, QObject* parent) :
+ QThread(parent),
+ btSession_(session)
{
}
void AlertWaiterThread::run()
{
+ TorrentAlert const *alertTemp = NULL;
while (true)
{
qDebug() << "AlertWaiter running";
- emit alert();
- sleep(2);
+ // wait_for_alert() returns libtorrent alert.
+ // Returns NULL, if no alerts in timeout period.
+ alertTemp = btSession_->wait_for_alert(ALERT_WAIT_TIMEOUT);
+ emit alert(alertTemp);
}
}
-// =================== SIGNALS =======================
-// AlertWaiterThread::alert()
-// {
-// }
-
-
#define ALERTWAITERTHREAD_H
#include <QThread>
+#include "QBittorrentSession.h"
+
/**
@author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
Q_OBJECT
public:
- AlertWaiterThread(QObject* parent = 0);
+ AlertWaiterThread(TorrentSession *const session, QObject *parent = 0);
- ~AlertWaiterThread();
+ virtual ~AlertWaiterThread();
- void run(); // Overridden from QThread
+ virtual void run(); // Overridden from QThread
signals:
- void alert();
+ void alert(TorrentAlert const *alert);
private:
-
+ TorrentSession *const btSession_;
+
};
#endif
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
+#include <QDebug>
+
+#include "AlertWaiterThread.h"
#include "QBittorrentSession.h"
-QBittorrentSession::QBittorrentSession()
+
+QBittorrentSession::QBittorrentSession(QObject *parent):
+ QObject(parent),
+ btSession_(),
+ alertWaiter_(NULL)
{
+ alertWaiter_ = new AlertWaiterThread(&btSession_, this);
+ connect(alertWaiter_, SIGNAL(alert(TorrentAlert const*)), this, SLOT(on_alert(TorrentAlert const*)));
+ alertWaiter_->start();
}
}
+QTorrentHandle QBittorrentSession::addTorrent(AddTorrentParams const& params)
+{
+ // Delegate to Libtorrent and return QTorrentHandle.
+ QTorrentHandle handle(btSession_.add_torrent(params));
+ return handle;
+}
+
+
+// ========================== SLOTS ==============================
+void QBittorrentSession::on_alert(TorrentAlert const *al)
+{
+ qDebug() << "QBittorrentSession:on_alert(" << al << ")";
+ emit alert(al);
+}
+
+
#ifndef QBITTORRENTSESSION_H
#define QBITTORRENTSESSION_H
+#include <QObject>
+
+#include <libtorrent/session.hpp>
+
+#include "QTorrentHandle.h"
+
+
+// Forward declarations and typedefs
+class AlertWaiterThread;
+typedef libtorrent::session TorrentSession;
+typedef libtorrent::add_torrent_params AddTorrentParams;
+typedef libtorrent::alert TorrentAlert;
+
+
/**
@author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
*/
-class QBittorrentSession {
-
+class QBittorrentSession : public QObject {
+ Q_OBJECT
+// class BitTorrentSession;
+
public:
- QBittorrentSession();
-
+ QBittorrentSession(QObject *parent = 0);
~QBittorrentSession();
- public slots:
+
+ /// @brief Add torrent to session.
+ QTorrentHandle addTorrent(AddTorrentParams const& params);
+
+ signals:
+ void alert(TorrentAlert const *al);
+
private slots:
+ void on_alert(TorrentAlert const *al);
+
private:
+ TorrentSession btSession_;
+ AlertWaiterThread *alertWaiter_;
-
};
#endif
--- /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 "QTorrentHandle.h"
+
+QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) :
+ torrentHandle(handle)
+{
+}
+
+
+QTorrentHandle::~QTorrentHandle()
+{
+}
+
+
--- /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 QTORRENTHANDLE_H
+#define QTORRENTHANDLE_H
+
+#include <libtorrent/torrent_handle.hpp>
+
+
+
+/**
+ @author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
+*/
+class QTorrentHandle
+{
+
+ public:
+ QTorrentHandle(libtorrent::torrent_handle handle);
+ ~QTorrentHandle();
+
+
+ private:
+ QTorrentHandle(); // Prevent default construct.
+ libtorrent::torrent_handle torrentHandle;
+
+};
+
+#endif
VERSION = 0.1
-HEADERS += AlertWaiterThread.h
+HEADERS += AlertWaiterThread.h \
+ QBittorrentSession.h \
+ QTorrentHandle.h
-SOURCES += AlertWaiterThread.cpp
+SOURCES += AlertWaiterThread.cpp \
+ QBittorrentSession.cpp \
+ QTorrentHandle.cpp
QT -= gui
DESTDIR = ../../bin
+LIBS += -ltorrent-rasterbar \
+ -lboost_filesystem-mt \
+ -lboost_date_time-mt \
+ -lboost_thread-mt
+
#include "DownloadView.h"
#include "SeedView.h"
-#include "AlertWaiterThread.h"
#include "MainWindow.h"
"\n\nIxonos Plc, Finland\n"));
-
+// Consturctor
MainWindow::MainWindow():
QMainWindow(), // Superclass
tabWidget_(NULL),
dlView_(NULL),
- seedView_(NULL)
+ seedView_(NULL),
+ btSession_()
{
-
// MENUBAR
QMenuBar *menuBar = new QMenuBar();
QMenu *tempMenu = NULL;
tempMenu = menuBar->addMenu(tr("&File"));
- tempMenu->addAction(tr("&Open"));
+ QAction *openAction = tempMenu->addAction(tr("&Open"));
+ QAction *quitAction = tempMenu->addAction(tr("&Quit"));
tempMenu = menuBar->addMenu(tr("&Help"));
QAction *aboutAction = tempMenu->addAction(tr("&About"));
QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt"));
- setMenuBar(menuBar);
+ setMenuBar(menuBar);
+ connect(openAction, SIGNAL(triggered()), this, SLOT(on_openAction_clicked()));
+ connect(quitAction, SIGNAL(triggered()), this, SLOT(on_quitAction_clicked()));
connect(aboutAction, SIGNAL(triggered()), this, SLOT(on_aboutAction_clicked()));
connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(on_aboutQtAction_clicked()));
addToolBar(Qt::TopToolBarArea, toolBar);
connect(toolBar, SIGNAL(actionTriggered(QAction*)), this, SLOT(handleToolBarAction(QAction*)));
- alertWaiter_ = new AlertWaiterThread(this);
- connect(alertWaiter_, SIGNAL(alert()), this, SLOT(on_alert()));
- alertWaiter_->start();
}
{
}
+// =========================== SLOTS =================================
+void MainWindow::on_openAction_clicked()
+{
+ QFileDialog *dialog = new QFileDialog( this, "Open torrent file", QString(), tr("Torrent files (*.torrent)"));
+ dialog->setFileMode(QFileDialog::ExistingFile);
+ connect(dialog, SIGNAL(fileSelected(const QString&)), this, SLOT(on_torrentFileSelected(const QString&)));
+ dialog->show();
+
+}
+
+
+void MainWindow::on_quitAction_clicked()
+{
+ close();
+}
+
void MainWindow::on_aboutAction_clicked()
{
QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT);
}
+
void MainWindow::on_aboutQtAction_clicked()
{
QMessageBox::aboutQt (this, tr("About Qt"));
void MainWindow::handleToolBarAction(QAction* action)
{
if (action->text() == "Open") {
- QFileDialog *dialog = new QFileDialog( this, "Open torrent file", QString(), tr("Torrent files (*.torrent)"));
- dialog->setFileMode(QFileDialog::ExistingFile);
- dialog->show();
+ on_openAction_clicked();
} else {
}
}
-void MainWindow::on_alert()
+void MainWindow::on_torrentFileSelected(const QString& file)
{
- qDebug() << "MainWindow: got alert()";
+ qDebug() << " MainWindow::on_torrentFileSelected(): " << file;
+ // Torrent filename empty, do nothing.
+ if (file == "") {
+ return;
+ }
+
+ // 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.
+ //addParams.storage_mode = libtorrent::storage_mode_allocate;
+ btSession_.addTorrent();
+ */
}
#include <QMainWindow>
+#include "QBittorrentSession.h"
class QTabWidget;
class DownloadView;
class SeedView;
-class AlertWaiterThread;
/**
@author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
public slots:
private slots:
+ void on_openAction_clicked();
+ void on_quitAction_clicked();
void on_aboutAction_clicked();
void on_aboutQtAction_clicked();
void handleToolBarAction(QAction* action);
-
- void on_alert();
+ void on_torrentFileSelected(const QString& file);
private:
QTabWidget *tabWidget_;
DownloadView *dlView_;
SeedView *seedView_;
- AlertWaiterThread *alertWaiter_;
+ QBittorrentSession btSession_;
+
+
};
#endif
qtestlib
-TARGETDEPS += ../engine/liblibqtbittorrent.so
DESTDIR = ../../bin
-L../engine
QMAKE_LFLAGS_DEBUG += -L.
+TARGETDEPS += ../engine/liblibqtbittorrent.so \
+ ../../bin/libqtbittorrent.so
+