#include "AlertWaiterThread.h"
#include "QBittorrentSession.h"
+namespace qtrapids
+{
QBittorrentSession::QBittorrentSession(QObject *parent):
- QObject(parent),
- btSession_(),
- alertWaiter_(NULL)
+ QObject(parent),
+ btSession_(),
+ alertWaiter_(NULL)
{
- alertWaiter_ = new AlertWaiterThread(&btSession_, this);
- alertWaiter_->allAlerts();
- connect(alertWaiter_, SIGNAL(alert(TorrentAlert const*)), this, SLOT(on_alert(TorrentAlert const*)));
- alertWaiter_->start();
+ alertWaiter_ = new AlertWaiterThread(&btSession_, this);
+ alertWaiter_->allAlerts();
+ connect(alertWaiter_, SIGNAL(alert(Alert const*)), this, SLOT(on_alert(Alert const*)));
+ alertWaiter_->start();
}
}
-std::auto_ptr<QTorrentHandle>
+qtrapids::QTorrentHandle
QBittorrentSession::addTorrent(AddTorrentParams const& params)
{
- // Delegate to Libtorrent and return QTorrentHandle.
- std::auto_ptr<QTorrentHandle> handlePtr(new QTorrentHandle(btSession_.add_torrent(params)));
- return handlePtr;
+ // Delegate to Libtorrent and return QTorrentHandle.
+ //std::auto_ptr<QTorrentHandle> handlePtr(new QTorrentHandle(btSession_.add_torrent(params)));
+ qtrapids::QTorrentHandle handle = qtrapids::QTorrentHandle(btSession_.add_torrent(params));
+ return handle;
}
-// ========================== SLOTS ==============================
-void QBittorrentSession::on_alert(TorrentAlert const *al)
- //NOTE: al parameter not necessarily needed here, as we pop_alert() now!
+void QBittorrentSession::removeTorrent(qtrapids::QTorrentHandle const& handle)
{
-
- //qDebug() << "QBittorrentSession:on_alert(" << al << ")";
-// if (al)
-// qDebug() << "on_alert():" << QString::fromStdString(al->message());
-
- std::auto_ptr<TorrentAlert> alertPtr = btSession_.pop_alert();
- emit alert(alertPtr);
+ btSession_.remove_torrent(handle.getHandle());
}
+// ========================== SLOTS ==============================
+/// @TODO This function is called when AlertWaiterThread emits alert()
+/// If connection is direct, as it is now, we need to use QMutex here (if necessary?)
+void QBittorrentSession::on_alert(Alert const *al)
+//NOTE: al parameter not necessarily needed here, as we pop_alert() now!
+{
+
+#ifdef QTRAPIDS_DEBUG
+ if (al)
+ qDebug() << "on_alert():" << QString::fromStdString(al->message());
+#endif
+
+ std::auto_ptr<Alert> alertPtr = btSession_.pop_alert();
+ emit alert(alertPtr);
+}
+
+} //namespace qtrapids