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"
|
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
struct tr_variant;
|
2009-04-13 18:21:22 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
class Session: public QObject
|
|
|
|
{
|
2013-02-03 19:40:20 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2015-01-28 22:57:46 +00:00
|
|
|
Session (const QString& configDir, Prefs& prefs);
|
2015-06-12 22:12:12 +00:00
|
|
|
virtual ~Session ();
|
2013-02-03 19:40:20 +00:00
|
|
|
|
|
|
|
void stop ();
|
|
|
|
void restart ();
|
|
|
|
|
2014-12-27 20:03:10 +00:00
|
|
|
const QUrl& getRemoteUrl () const { return myRpc.url (); }
|
2014-12-12 23:21:04 +00:00
|
|
|
const tr_session_stats& getStats () const { return myStats; }
|
|
|
|
const tr_session_stats& getCumulativeStats () const { return myCumulativeStats; }
|
2013-02-03 19:40:20 +00:00
|
|
|
const QString& sessionVersion () const { return mySessionVersion; }
|
|
|
|
|
2013-08-29 00:37:37 +00:00
|
|
|
int64_t blocklistSize () const { return myBlocklistSize; }
|
|
|
|
void setBlocklistSize (int64_t i);
|
2013-02-03 19:40:20 +00:00
|
|
|
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;
|
|
|
|
|
2016-04-19 20:41:59 +00:00
|
|
|
RpcResponseFuture exec (tr_quark method, tr_variant * args);
|
|
|
|
RpcResponseFuture exec (const char * method, tr_variant * args);
|
2013-02-03 19:40:20 +00:00
|
|
|
|
|
|
|
void torrentSet (const QSet<int>& ids, const tr_quark key, bool val);
|
|
|
|
void torrentSet (const QSet<int>& ids, const tr_quark key, int val);
|
|
|
|
void torrentSet (const QSet<int>& ids, const tr_quark key, double val);
|
|
|
|
void torrentSet (const QSet<int>& ids, const tr_quark key, const QList<int>& val);
|
|
|
|
void torrentSet (const QSet<int>& ids, const tr_quark key, const QStringList& val);
|
|
|
|
void torrentSet (const QSet<int>& ids, const tr_quark key, const QPair<int,QString>& val);
|
|
|
|
void torrentSetLocation (const QSet<int>& ids, const QString& path, bool doMove);
|
|
|
|
void torrentRenamePath (const QSet<int>& ids, const QString& oldpath, const QString& newname);
|
2014-12-27 20:03:10 +00:00
|
|
|
void addTorrent (const AddData& addme, tr_variant * top, bool trashOriginal);
|
2013-02-03 19:40:20 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void pauseTorrents (const QSet<int>& torrentIds = QSet<int> ());
|
|
|
|
void startTorrents (const QSet<int>& torrentIds = QSet<int> ());
|
|
|
|
void startTorrentsNow (const QSet<int>& torrentIds = QSet<int> ());
|
|
|
|
void queueMoveTop (const QSet<int>& torrentIds = QSet<int> ());
|
|
|
|
void queueMoveUp (const QSet<int>& torrentIds = QSet<int> ());
|
|
|
|
void queueMoveDown (const QSet<int>& torrentIds = QSet<int> ());
|
|
|
|
void queueMoveBottom (const QSet<int>& torrentIds = QSet<int> ());
|
|
|
|
void refreshSessionInfo ();
|
|
|
|
void refreshSessionStats ();
|
|
|
|
void refreshActiveTorrents ();
|
|
|
|
void refreshAllTorrents ();
|
|
|
|
void initTorrents (const QSet<int>& ids = QSet<int> ());
|
|
|
|
void addNewlyCreatedTorrent (const QString& filename, const QString& localPath);
|
|
|
|
void addTorrent (const AddData& addme);
|
2015-06-12 22:12:12 +00:00
|
|
|
void removeTorrents (const QSet<int>& torrentIds, bool deleteFiles = false);
|
2013-02-03 19:40:20 +00:00
|
|
|
void verifyTorrents (const QSet<int>& torrentIds);
|
|
|
|
void reannounceTorrents (const QSet<int>& torrentIds);
|
|
|
|
void launchWebInterface ();
|
|
|
|
void updatePref (int key);
|
2015-06-12 22:12:12 +00:00
|
|
|
|
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 */
|
|
|
|
void refreshExtraStats (const QSet<int>& ids);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void sourceChanged ();
|
|
|
|
void portTested (bool isOpen);
|
|
|
|
void statsUpdated ();
|
|
|
|
void sessionUpdated ();
|
|
|
|
void blocklistUpdated (int);
|
2014-12-12 23:21:04 +00:00
|
|
|
void torrentsUpdated (tr_variant * torrentList, bool completeList);
|
|
|
|
void torrentsRemoved (tr_variant * torrentList);
|
2013-02-03 19:40:20 +00:00
|
|
|
void dataReadProgress ();
|
|
|
|
void dataSendProgress ();
|
2016-04-19 20:41:59 +00:00
|
|
|
void networkResponse (QNetworkReply::NetworkError code, const QString& message);
|
2013-02-03 19:40:20 +00:00
|
|
|
void httpAuthenticationRequired ();
|
|
|
|
|
|
|
|
private:
|
2015-06-12 22:12:12 +00:00
|
|
|
void start ();
|
|
|
|
|
|
|
|
void updateStats (tr_variant * args);
|
|
|
|
void updateInfo (tr_variant * args);
|
|
|
|
|
|
|
|
void sessionSet (const tr_quark key, const QVariant& variant);
|
|
|
|
void pumpRequests ();
|
|
|
|
void sendTorrentRequest (const char * request, const QSet<int>& torrentIds);
|
2016-04-19 20:41:59 +00:00
|
|
|
void refreshTorrents (const QSet<int>& torrentIds, const Torrent::KeyList& keys);
|
2015-06-12 22:12:12 +00:00
|
|
|
|
|
|
|
static void updateStats (tr_variant * d, tr_session_stats * stats);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString const myConfigDir;
|
|
|
|
Prefs& myPrefs;
|
|
|
|
|
2013-08-29 00:37:37 +00:00
|
|
|
int64_t myBlocklistSize;
|
2013-02-03 19:40:20 +00:00
|
|
|
tr_session * mySession;
|
|
|
|
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
|
|
|
};
|
|
|
|
|