1 /***************************************************************************
2 * Copyright (C) 2009 by Lassi Väätämöinen *
3 * lassi.vaatamoinen@ixonos.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
23 #include "AlertWaiterThread.h"
24 #include "QBittorrentSession.h"
29 QBittorrentSession::QBittorrentSession(QObject *parent):
34 alertWaiter_ = new AlertWaiterThread(&btSession_, this);
35 alertWaiter_->allAlerts();
36 connect(alertWaiter_, SIGNAL(alert(Alert const*)), this, SLOT(on_alert(Alert const*)));
37 alertWaiter_->start();
41 QBittorrentSession::~QBittorrentSession()
46 qtrapids::QTorrentHandle
47 QBittorrentSession::addTorrent(AddTorrentParams const& params)
49 // Delegate to Libtorrent and return QTorrentHandle.
50 //std::auto_ptr<QTorrentHandle> handlePtr(new QTorrentHandle(btSession_.add_torrent(params)));
51 qtrapids::QTorrentHandle handle = qtrapids::QTorrentHandle(btSession_.add_torrent(params));
56 void QBittorrentSession::removeTorrent(qtrapids::QTorrentHandle const& handle)
58 btSession_.remove_torrent(handle.getHandle());
62 // ========================== SLOTS ==============================
63 /// @TODO This function is called when AlertWaiterThread emits alert()
64 /// If connection is direct, as it is now, we need to use QMutex here (if necessary?)
65 void QBittorrentSession::on_alert(Alert const *al)
66 //NOTE: al parameter not necessarily needed here, as we pop_alert() now!
71 qDebug() << "on_alert():" << QString::fromStdString(al->message());
74 std::auto_ptr<Alert> alertPtr = btSession_.pop_alert();
78 } //namespace qtrapids