Added Q_FUNC_INFO macros to some functions.
[qtrapids] / src / engine / QBittorrentSession.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Ixonos Plc   *
3  *                                                                         *
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.               *
7  *                                                                         *
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.                          *
12  *                                                                         *
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  ***************************************************************************/
18
19 #include <QDebug>
20
21 #include "AlertWaiterThread.h"
22 #include "QBittorrentSession.h"
23
24 namespace qtrapids
25 {
26
27 QBittorrentSession::QBittorrentSession(QObject *parent):
28                 QObject(parent),
29                 btSession_(),
30                 alertWaiter_(NULL)
31 {
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();
36         
37         SessionSettings settings;
38         settings.ignore_limits_on_local_network = false;
39         btSession_.set_settings(settings);
40         
41 }
42
43
44 QBittorrentSession::~QBittorrentSession()
45 {
46 }
47
48
49 qtrapids::QTorrentHandle
50 QBittorrentSession::addTorrent(AddTorrentParams const& params)
51 {
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));
55         return handle;
56 }
57
58
59 void QBittorrentSession::removeTorrent(qtrapids::QTorrentHandle const& handle)
60 {
61         btSession_.remove_torrent(handle.getHandle());
62 }
63
64
65 void QBittorrentSession::setUploadRateLimit(int rate)
66 {
67         btSession_.set_upload_rate_limit(rate);
68 }
69
70
71 void QBittorrentSession::setDownloadRateLimit(int rate)
72 {
73         btSession_.set_download_rate_limit(rate);
74 }
75
76
77 int QBittorrentSession::getUploadRateLimt() const
78 {
79         return btSession_.upload_rate_limit();
80 }
81
82
83 int QBittorrentSession::getDownloadRateLimit() const
84 {
85         return btSession_.download_rate_limit();
86 }
87
88
89
90
91
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!
97 {
98
99 #ifdef QTRAPIDS_DEBUG
100         //if (al)
101         //      qDebug() << "on_alert():" << QString::fromStdString(al->message());
102 #endif
103
104         std::auto_ptr<Alert> alertPtr = btSession_.pop_alert();
105         emit alert(alertPtr);
106 }
107
108 } //namespace qtrapids