* 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);
+ alertWaiter_->allAlerts();
+ connect(alertWaiter_, SIGNAL(alert(Alert const*)), this, SLOT(on_alert(Alert const*)));
+ alertWaiter_->start();
}
}
+QTorrentHandle
+QBittorrentSession::addTorrent(AddTorrentParams const& params)
+{
+ // Delegate to Libtorrent and return QTorrentHandle.
+ //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(Alert const *al)
+ //NOTE: al parameter not necessarily needed here, as we pop_alert() now!
+{
+
+ //qDebug() << "QBittorrentSession:on_alert(" << al << ")";
+// if (al)
+// qDebug() << "on_alert():" << QString::fromStdString(al->message());
+
+ std::auto_ptr<Alert> alertPtr = btSession_.pop_alert();
+ emit alert(alertPtr);
+}
+
+
+