1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/*
* This file Copyright (C) 2009-2016 Mnemosyne LLC
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
*
*/
#pragma once
#include <QObject>
#include <QString>
#include <QStringList>
#include <libtransmission/transmission.h>
#include <libtransmission/quark.h>
#include "RpcClient.h"
#include "Torrent.h"
#include "Typedefs.h"
class AddData;
class Prefs;
extern "C"
{
struct tr_variant;
}
class Session : public QObject
{
Q_OBJECT
public:
Session(QString const& configDir, Prefs& prefs);
virtual ~Session();
void stop();
void restart();
QUrl const& getRemoteUrl() const
{
return myRpc.url();
}
tr_session_stats const& getStats() const
{
return myStats;
}
tr_session_stats const& getCumulativeStats() const
{
return myCumulativeStats;
}
QString const& sessionVersion() const
{
return mySessionVersion;
}
int64_t blocklistSize() const
{
return myBlocklistSize;
}
void setBlocklistSize(int64_t i);
void updateBlocklist();
void portTest();
void copyMagnetLinkToClipboard(int torrentId);
/** returns true if the transmission session is being run inside this client */
bool isServer() const;
/** returns true if isServer() is true or if the remote address is the localhost */
bool isLocal() const;
RpcResponseFuture exec(tr_quark method, tr_variant* args);
RpcResponseFuture exec(char const* method, tr_variant* args);
void torrentSet(torrent_ids_t const& ids, tr_quark const key, bool val);
void torrentSet(torrent_ids_t const& ids, tr_quark const key, int val);
void torrentSet(torrent_ids_t const& ids, tr_quark const key, double val);
void torrentSet(torrent_ids_t const& ids, tr_quark const key, QList<int> const& val);
void torrentSet(torrent_ids_t const& ids, tr_quark const key, QStringList const& val);
void torrentSet(torrent_ids_t const& ids, tr_quark const key, QPair<int, QString> const& val);
void torrentSetLocation(torrent_ids_t const& ids, QString const& path, bool doMove);
void torrentRenamePath(torrent_ids_t const& ids, QString const& oldpath, QString const& newname);
void addTorrent(AddData const& addme, tr_variant* top, bool trashOriginal);
void initTorrents(torrent_ids_t const& ids = {});
void pauseTorrents(torrent_ids_t const& torrentIds = {});
void startTorrents(torrent_ids_t const& torrentIds = {});
void startTorrentsNow(torrent_ids_t const& torrentIds = {});
void refreshDetailInfo(torrent_ids_t const& torrentIds);
void refreshActiveTorrents();
void refreshAllTorrents();
void addNewlyCreatedTorrent(QString const& filename, QString const& localPath);
void verifyTorrents(torrent_ids_t const& torrentIds);
void reannounceTorrents(torrent_ids_t const& torrentIds);
void refreshExtraStats(torrent_ids_t const& ids);
public slots:
void addTorrent(AddData const& addme);
void launchWebInterface();
void queueMoveBottom(torrent_ids_t const& torrentIds = {});
void queueMoveDown(torrent_ids_t const& torrentIds = {});
void queueMoveTop(torrent_ids_t const& torrentIds = {});
void queueMoveUp(torrent_ids_t const& torrentIds = {});
void refreshSessionInfo();
void refreshSessionStats();
void removeTorrents(torrent_ids_t const& torrentIds, bool deleteFiles = false);
void updatePref(int key);
signals:
void sourceChanged();
void portTested(bool isOpen);
void statsUpdated();
void sessionUpdated();
void blocklistUpdated(int);
void torrentsUpdated(tr_variant* torrentList, bool completeList);
void torrentsRemoved(tr_variant* torrentList);
void dataReadProgress();
void dataSendProgress();
void networkResponse(QNetworkReply::NetworkError code, QString const& message);
void httpAuthenticationRequired();
private:
void start();
void updateStats(tr_variant* args);
void updateInfo(tr_variant* args);
void sessionSet(tr_quark const key, QVariant const& variant);
void pumpRequests();
void sendTorrentRequest(char const* request, torrent_ids_t const& torrentIds);
void refreshTorrents(torrent_ids_t const& torrentIds, Torrent::KeyList const& keys);
static void updateStats(tr_variant* d, tr_session_stats* stats);
private:
QString const myConfigDir;
Prefs& myPrefs;
int64_t myBlocklistSize;
tr_session* mySession;
QStringList myIdleJSON;
tr_session_stats myStats;
tr_session_stats myCumulativeStats;
QString mySessionVersion;
QString mySessionId;
bool myIsDefinitelyLocalSession;
RpcClient myRpc;
};
|