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();
39 SessionSettings settings;
40 settings.ignore_limits_on_local_network = false;
41 btSession_.set_settings(settings);
46 QBittorrentSession::~QBittorrentSession()
51 qtrapids::QTorrentHandle
52 QBittorrentSession::addTorrent(AddTorrentParams const& params)
54 // Delegate to Libtorrent and return QTorrentHandle.
55 //std::auto_ptr<QTorrentHandle> handlePtr(new QTorrentHandle(btSession_.add_torrent(params)));
56 qtrapids::QTorrentHandle handle = qtrapids::QTorrentHandle(btSession_.add_torrent(params));
61 void QBittorrentSession::removeTorrent(qtrapids::QTorrentHandle const& handle)
63 btSession_.remove_torrent(handle.getHandle());
67 void QBittorrentSession::setUploadRateLimit(int rate)
69 btSession_.set_upload_rate_limit(rate);
73 void QBittorrentSession::setDownloadrateLimit(int rate)
75 btSession_.set_download_rate_limit(rate);
79 int QBittorrentSession::getUploadRateLimt() const
81 return btSession_.upload_rate_limit();
85 int QBittorrentSession::getDownloadRateLimit() const
87 return btSession_.download_rate_limit();
94 // ========================== SLOTS ==============================
95 /// @TODO This function is called when AlertWaiterThread emits alert()
96 /// If connection is direct, as it is now, we need to use QMutex here (if necessary?)
97 void QBittorrentSession::on_alert(Alert const *al)
98 //NOTE: al parameter not necessarily needed here, as we pop_alert() now!
101 #ifdef QTRAPIDS_DEBUG
103 // qDebug() << "on_alert():" << QString::fromStdString(al->message());
106 std::auto_ptr<Alert> alertPtr = btSession_.pop_alert();
107 emit alert(alertPtr);
110 } //namespace qtrapids