2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2016-04-19 20:41:59 +00:00
|
|
|
* This file Copyright (C) 2009-2016 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QString>
|
2013-01-20 01:31:58 +00:00
|
|
|
#include <QStringList>
|
2010-08-01 18:55:04 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2012-12-22 20:35:19 +00:00
|
|
|
#include <libtransmission/quark.h>
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "RpcClient.h"
|
2016-04-19 20:41:59 +00:00
|
|
|
#include "Torrent.h"
|
2014-12-27 20:03:10 +00:00
|
|
|
|
|
|
|
class AddData;
|
|
|
|
class Prefs;
|
|
|
|
|
2009-04-13 18:21:22 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_variant;
|
2009-04-13 18:21:22 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
class Session : public QObject
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2017-04-20 16:02:19 +00:00
|
|
|
Session(QString const& configDir, Prefs& prefs);
|
2017-04-19 12:04:45 +00:00
|
|
|
virtual ~Session();
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void stop();
|
|
|
|
void restart();
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QUrl const& getRemoteUrl() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return myRpc.url();
|
|
|
|
}
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_session_stats const& getStats() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return myStats;
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_session_stats const& getCumulativeStats() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return myCumulativeStats;
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const& sessionVersion() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
return mySessionVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t blocklistSize() const
|
|
|
|
{
|
|
|
|
return myBlocklistSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setBlocklistSize(int64_t i);
|
|
|
|
void updateBlocklist();
|
|
|
|
void portTest();
|
|
|
|
void copyMagnetLinkToClipboard(int torrentId);
|
2013-02-03 19:40:20 +00:00
|
|
|
|
|
|
|
/** returns true if the transmission session is being run inside this client */
|
2017-04-19 12:04:45 +00:00
|
|
|
bool isServer() const;
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-21 07:40:57 +00:00
|
|
|
/** returns true if isServer() is true or if the remote address is the localhost */
|
2017-04-19 12:04:45 +00:00
|
|
|
bool isLocal() const;
|
|
|
|
|
|
|
|
RpcResponseFuture exec(tr_quark method, tr_variant* args);
|
2017-04-20 16:02:19 +00:00
|
|
|
RpcResponseFuture exec(char const* method, tr_variant* args);
|
|
|
|
|
|
|
|
void torrentSet(QSet<int> const& ids, tr_quark const key, bool val);
|
|
|
|
void torrentSet(QSet<int> const& ids, tr_quark const key, int val);
|
|
|
|
void torrentSet(QSet<int> const& ids, tr_quark const key, double val);
|
|
|
|
void torrentSet(QSet<int> const& ids, tr_quark const key, QList<int> const& val);
|
|
|
|
void torrentSet(QSet<int> const& ids, tr_quark const key, QStringList const& val);
|
|
|
|
void torrentSet(QSet<int> const& ids, tr_quark const key, QPair<int, QString> const& val);
|
|
|
|
void torrentSetLocation(QSet<int> const& ids, QString const& path, bool doMove);
|
|
|
|
void torrentRenamePath(QSet<int> const& ids, QString const& oldpath, QString const& newname);
|
|
|
|
void addTorrent(AddData const& addme, tr_variant* top, bool trashOriginal);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
public slots:
|
2017-04-20 16:02:19 +00:00
|
|
|
void pauseTorrents(QSet<int> const& torrentIds = QSet<int>());
|
|
|
|
void startTorrents(QSet<int> const& torrentIds = QSet<int>());
|
|
|
|
void startTorrentsNow(QSet<int> const& torrentIds = QSet<int>());
|
|
|
|
void queueMoveTop(QSet<int> const& torrentIds = QSet<int>());
|
|
|
|
void queueMoveUp(QSet<int> const& torrentIds = QSet<int>());
|
|
|
|
void queueMoveDown(QSet<int> const& torrentIds = QSet<int>());
|
|
|
|
void queueMoveBottom(QSet<int> const& torrentIds = QSet<int>());
|
2017-04-19 12:04:45 +00:00
|
|
|
void refreshSessionInfo();
|
|
|
|
void refreshSessionStats();
|
|
|
|
void refreshActiveTorrents();
|
|
|
|
void refreshAllTorrents();
|
2017-04-20 16:02:19 +00:00
|
|
|
void initTorrents(QSet<int> const& ids = QSet<int>());
|
|
|
|
void addNewlyCreatedTorrent(QString const& filename, QString const& localPath);
|
|
|
|
void addTorrent(AddData const& addme);
|
|
|
|
void removeTorrents(QSet<int> const& torrentIds, bool deleteFiles = false);
|
|
|
|
void verifyTorrents(QSet<int> const& torrentIds);
|
|
|
|
void reannounceTorrents(QSet<int> const& torrentIds);
|
2017-04-19 12:04:45 +00:00
|
|
|
void launchWebInterface();
|
|
|
|
void updatePref(int key);
|
|
|
|
|
2013-02-03 19:40:20 +00:00
|
|
|
/** request a refresh for statistics, including the ones only used by the properties dialog, for a specific torrent */
|
2017-04-20 16:02:19 +00:00
|
|
|
void refreshExtraStats(QSet<int> const& ids);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
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();
|
2017-04-20 16:02:19 +00:00
|
|
|
void networkResponse(QNetworkReply::NetworkError code, QString const& message);
|
2017-04-19 12:04:45 +00:00
|
|
|
void httpAuthenticationRequired();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void start();
|
|
|
|
|
|
|
|
void updateStats(tr_variant* args);
|
|
|
|
void updateInfo(tr_variant* args);
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void sessionSet(tr_quark const key, QVariant const& variant);
|
2017-04-19 12:04:45 +00:00
|
|
|
void pumpRequests();
|
2017-04-20 16:02:19 +00:00
|
|
|
void sendTorrentRequest(char const* request, QSet<int> const& torrentIds);
|
|
|
|
void refreshTorrents(QSet<int> const& torrentIds, Torrent::KeyList const& keys);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
static void updateStats(tr_variant* d, tr_session_stats* stats);
|
|
|
|
|
|
|
|
private:
|
2015-06-12 22:12:12 +00:00
|
|
|
QString const myConfigDir;
|
|
|
|
Prefs& myPrefs;
|
|
|
|
|
2013-08-29 00:37:37 +00:00
|
|
|
int64_t myBlocklistSize;
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_session* mySession;
|
2013-02-03 19:40:20 +00:00
|
|
|
QStringList myIdleJSON;
|
2014-12-12 23:21:04 +00:00
|
|
|
tr_session_stats myStats;
|
|
|
|
tr_session_stats myCumulativeStats;
|
2013-02-03 19:40:20 +00:00
|
|
|
QString mySessionVersion;
|
2016-10-03 18:26:28 +00:00
|
|
|
QString mySessionId;
|
|
|
|
bool myIsDefinitelyLocalSession;
|
2014-12-27 20:03:10 +00:00
|
|
|
RpcClient myRpc;
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|