1 /***************************************************************************
2 * Copyright (C) 2010 by Ixonos Plc *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; version 2 of the License. *
8 * This program is distributed in the hope that it will be useful, *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11 * GNU General Public License for more details. *
13 * You should have received a copy of the GNU General Public License *
14 * along with this program; if not, write to the *
15 * Free Software Foundation, Inc., *
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17 ***************************************************************************/
21 #include "AlertWaiterThread.h"
22 #include "QBittorrentSession.h"
27 QBittorrentSession::QBittorrentSession(QObject *parent):
32 alertWaiter_ = new AlertWaiterThread(&btSession_, this);
33 alertWaiter_->allAlerts();
34 connect(alertWaiter_, SIGNAL(alert(Alert const*)), this, SLOT(on_alert(Alert const*)));
35 alertWaiter_->start();
37 SessionSettings settings;
38 settings.ignore_limits_on_local_network = false;
39 btSession_.set_settings(settings);
44 QBittorrentSession::~QBittorrentSession()
49 qtrapids::QTorrentHandle
50 QBittorrentSession::addTorrent(AddTorrentParams const& params)
52 // Delegate to Libtorrent and return QTorrentHandle.
53 //std::auto_ptr<QTorrentHandle> handlePtr(new QTorrentHandle(btSession_.add_torrent(params)));
54 qtrapids::QTorrentHandle handle = qtrapids::QTorrentHandle(btSession_.add_torrent(params));
59 void QBittorrentSession::removeTorrent(qtrapids::QTorrentHandle const& handle)
61 btSession_.remove_torrent(handle.getHandle());
65 void QBittorrentSession::setUploadRateLimit(int rate)
67 btSession_.set_upload_rate_limit(rate);
71 void QBittorrentSession::setDownloadRateLimit(int rate)
73 btSession_.set_download_rate_limit(rate);
77 int QBittorrentSession::getUploadRateLimt() const
79 return btSession_.upload_rate_limit();
83 int QBittorrentSession::getDownloadRateLimit() const
85 return btSession_.download_rate_limit();
92 // ========================== SLOTS ==============================
93 /// @TODO This function is called when AlertWaiterThread emits alert()
94 /// If connection is direct, as it is now, we need to use QMutex here (if necessary?)
95 void QBittorrentSession::on_alert(Alert const *al)
96 //NOTE: al parameter not necessarily needed here, as we pop_alert() now!
101 // qDebug() << "on_alert():" << QString::fromStdString(al->message());
104 std::auto_ptr<Alert> alertPtr = btSession_.pop_alert();
105 emit alert(alertPtr);
108 } //namespace qtrapids