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"
28 QBittorrentSession::QBittorrentSession(QObject *parent):
33 alertWaiter_ = new AlertWaiterThread(&btSession_, this);
34 alertWaiter_->allAlerts();
35 connect(alertWaiter_, SIGNAL(alert(Alert const*)), this, SLOT(on_alert(Alert const*)));
36 alertWaiter_->start();
40 QBittorrentSession::~QBittorrentSession()
45 qtrapids::QTorrentHandle
46 QBittorrentSession::addTorrent(AddTorrentParams const& params)
48 // Delegate to Libtorrent and return QTorrentHandle.
49 //std::auto_ptr<QTorrentHandle> handlePtr(new QTorrentHandle(btSession_.add_torrent(params)));
50 qtrapids::QTorrentHandle handle = qtrapids::QTorrentHandle(btSession_.add_torrent(params));
55 void QBittorrentSession::removeTorrent(qtrapids::QTorrentHandle const& handle)
57 btSession_.remove_torrent(handle.getHandle());
61 // ========================== SLOTS ==============================
62 /// @TODO This function is called when AlertWaiterThread emits alert()
63 /// If connection is direct, as it is now, we need to use QMutex here (if necessary?)
64 void QBittorrentSession::on_alert(Alert const *al)
65 //NOTE: al parameter not necessarily needed here, as we pop_alert() now!
70 qDebug() << "on_alert():" << QString::fromStdString(al->message());
73 std::auto_ptr<Alert> alertPtr = btSession_.pop_alert();
77 } //namespace qtrapids