- Added buildconf.pri to hold the master-level build options.
[qtrapids] / src / engine / QBittorrentSession.cpp
index 4cefcec..7d88e26 100644 (file)
@@ -30,7 +30,8 @@ QBittorrentSession::QBittorrentSession(QObject *parent):
                alertWaiter_(NULL)
 {
        alertWaiter_ = new AlertWaiterThread(&btSession_, this);
-       connect(alertWaiter_, SIGNAL(alert(TorrentAlert const*)), this, SLOT(on_alert(TorrentAlert const*)));
+       alertWaiter_->allAlerts();
+       connect(alertWaiter_, SIGNAL(alert(Alert const*)), this, SLOT(on_alert(Alert const*)));
        alertWaiter_->start();
 }
 
@@ -40,19 +41,37 @@ QBittorrentSession::~QBittorrentSession()
 }
 
 
-QTorrentHandle QBittorrentSession::addTorrent(AddTorrentParams const& params)
+QTorrentHandle
+QBittorrentSession::addTorrent(AddTorrentParams const& params)
 {
        // Delegate to Libtorrent and return QTorrentHandle.
-       QTorrentHandle handle(btSession_.add_torrent(params));
+       //std::auto_ptr<QTorrentHandle> handlePtr(new QTorrentHandle(btSession_.add_torrent(params)));
+       QTorrentHandle  handle = QTorrentHandle(btSession_.add_torrent(params));
        return handle;
 }
 
 
+void QBittorrentSession::removeTorrent(QTorrentHandle const& handle) 
+{
+       btSession_.remove_torrent(handle.getHandle());
+}
+
+
 // ========================== SLOTS ==============================
-void QBittorrentSession::on_alert(TorrentAlert const *al)
+/// @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!
 {
-       qDebug() << "QBittorrentSession:on_alert(" << al << ")";
-       emit alert(al);
+       
+#ifdef QTRAPIDS_DEBUG
+       if (al)
+               qDebug() << "on_alert():" << QString::fromStdString(al->message());
+#endif
+
+       std::auto_ptr<Alert> alertPtr = btSession_.pop_alert();
+       emit alert(alertPtr);
 }
 
 
+