1 | /* |
---|
2 | * This file Copyright (C) 2009-2014 Mnemosyne LLC |
---|
3 | * |
---|
4 | * It may be used under the GNU GPL versions 2 or 3 |
---|
5 | * or any future license endorsed by Mnemosyne LLC. |
---|
6 | * |
---|
7 | * $Id: session.h 14378 2014-12-12 23:21:04Z mikedld $ |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef TR_APP_SESSION_H |
---|
11 | #define TR_APP_SESSION_H |
---|
12 | |
---|
13 | #include <QObject> |
---|
14 | #include <QSet> |
---|
15 | #include <QBuffer> |
---|
16 | #include <QFileInfoList> |
---|
17 | #include <QNetworkAccessManager> |
---|
18 | #include <QString> |
---|
19 | #include <QStringList> |
---|
20 | #include <QUrl> |
---|
21 | #include <QNetworkReply> |
---|
22 | |
---|
23 | class QStringList; |
---|
24 | |
---|
25 | class AddData; |
---|
26 | |
---|
27 | #include <libtransmission/transmission.h> |
---|
28 | #include <libtransmission/quark.h> |
---|
29 | |
---|
30 | extern "C" |
---|
31 | { |
---|
32 | struct evbuffer; |
---|
33 | struct tr_variant; |
---|
34 | } |
---|
35 | |
---|
36 | class Prefs; |
---|
37 | |
---|
38 | class FileAdded: public QObject |
---|
39 | { |
---|
40 | Q_OBJECT |
---|
41 | |
---|
42 | public: |
---|
43 | FileAdded (int tag, const QString& name): myTag (tag), myName (name) {} |
---|
44 | ~FileAdded () {} |
---|
45 | void setFileToDelete (const QString& file) { myDelFile = file; } |
---|
46 | |
---|
47 | public slots: |
---|
48 | void executed (int64_t tag, const QString& result, tr_variant * arguments); |
---|
49 | |
---|
50 | private: |
---|
51 | const int64_t myTag; |
---|
52 | const QString myName; |
---|
53 | QString myDelFile; |
---|
54 | }; |
---|
55 | |
---|
56 | class Session: public QObject |
---|
57 | { |
---|
58 | Q_OBJECT |
---|
59 | |
---|
60 | public: |
---|
61 | Session (const char * configDir, Prefs& prefs); |
---|
62 | ~Session (); |
---|
63 | |
---|
64 | public: |
---|
65 | void stop (); |
---|
66 | void restart (); |
---|
67 | |
---|
68 | private: |
---|
69 | void start (); |
---|
70 | |
---|
71 | public: |
---|
72 | const QUrl& getRemoteUrl () const { return myUrl; } |
---|
73 | const tr_session_stats& getStats () const { return myStats; } |
---|
74 | const tr_session_stats& getCumulativeStats () const { return myCumulativeStats; } |
---|
75 | const QString& sessionVersion () const { return mySessionVersion; } |
---|
76 | |
---|
77 | public: |
---|
78 | int64_t blocklistSize () const { return myBlocklistSize; } |
---|
79 | void setBlocklistSize (int64_t i); |
---|
80 | void updateBlocklist (); |
---|
81 | void portTest (); |
---|
82 | void copyMagnetLinkToClipboard (int torrentId); |
---|
83 | |
---|
84 | public: |
---|
85 | |
---|
86 | /** returns true if the transmission session is being run inside this client */ |
---|
87 | bool isServer () const; |
---|
88 | |
---|
89 | /** returns true if isServer () is true or if the remote address is the localhost */ |
---|
90 | bool isLocal () const; |
---|
91 | |
---|
92 | private: |
---|
93 | void updateStats (tr_variant * args); |
---|
94 | void updateInfo (tr_variant * args); |
---|
95 | void parseResponse (const char * json, size_t len); |
---|
96 | static void localSessionCallback (tr_session *, evbuffer *, void *); |
---|
97 | |
---|
98 | public: |
---|
99 | void exec (const char * json); |
---|
100 | void exec (const tr_variant * request); |
---|
101 | |
---|
102 | public: |
---|
103 | int64_t getUniqueTag () { return nextUniqueTag++; } |
---|
104 | |
---|
105 | private: |
---|
106 | void sessionSet (const tr_quark key, const QVariant& variant); |
---|
107 | void pumpRequests (); |
---|
108 | void sendTorrentRequest (const char * request, const QSet<int>& torrentIds); |
---|
109 | static void updateStats (tr_variant * d, tr_session_stats * stats); |
---|
110 | void refreshTorrents (const QSet<int>& torrentIds); |
---|
111 | QNetworkAccessManager * networkAccessManager (); |
---|
112 | |
---|
113 | public: |
---|
114 | void torrentSet (const QSet<int>& ids, const tr_quark key, bool val); |
---|
115 | void torrentSet (const QSet<int>& ids, const tr_quark key, int val); |
---|
116 | void torrentSet (const QSet<int>& ids, const tr_quark key, double val); |
---|
117 | void torrentSet (const QSet<int>& ids, const tr_quark key, const QList<int>& val); |
---|
118 | void torrentSet (const QSet<int>& ids, const tr_quark key, const QStringList& val); |
---|
119 | void torrentSet (const QSet<int>& ids, const tr_quark key, const QPair<int,QString>& val); |
---|
120 | void torrentSetLocation (const QSet<int>& ids, const QString& path, bool doMove); |
---|
121 | void torrentRenamePath (const QSet<int>& ids, const QString& oldpath, const QString& newname); |
---|
122 | void addTorrent (const AddData& addme, tr_variant& top, bool trashOriginal); |
---|
123 | |
---|
124 | public slots: |
---|
125 | void pauseTorrents (const QSet<int>& torrentIds = QSet<int> ()); |
---|
126 | void startTorrents (const QSet<int>& torrentIds = QSet<int> ()); |
---|
127 | void startTorrentsNow (const QSet<int>& torrentIds = QSet<int> ()); |
---|
128 | void queueMoveTop (const QSet<int>& torrentIds = QSet<int> ()); |
---|
129 | void queueMoveUp (const QSet<int>& torrentIds = QSet<int> ()); |
---|
130 | void queueMoveDown (const QSet<int>& torrentIds = QSet<int> ()); |
---|
131 | void queueMoveBottom (const QSet<int>& torrentIds = QSet<int> ()); |
---|
132 | void refreshSessionInfo (); |
---|
133 | void refreshSessionStats (); |
---|
134 | void refreshActiveTorrents (); |
---|
135 | void refreshAllTorrents (); |
---|
136 | void initTorrents (const QSet<int>& ids = QSet<int> ()); |
---|
137 | void addNewlyCreatedTorrent (const QString& filename, const QString& localPath); |
---|
138 | void addTorrent (const AddData& addme); |
---|
139 | void removeTorrents (const QSet<int>& torrentIds, bool deleteFiles=false); |
---|
140 | void verifyTorrents (const QSet<int>& torrentIds); |
---|
141 | void reannounceTorrents (const QSet<int>& torrentIds); |
---|
142 | void launchWebInterface (); |
---|
143 | void updatePref (int key); |
---|
144 | |
---|
145 | /** request a refresh for statistics, including the ones only used by the properties dialog, for a specific torrent */ |
---|
146 | void refreshExtraStats (const QSet<int>& ids); |
---|
147 | |
---|
148 | private slots: |
---|
149 | void onFinished (QNetworkReply * reply); |
---|
150 | void onResponseReceived (const QByteArray& json); |
---|
151 | |
---|
152 | signals: |
---|
153 | void responseReceived (const QByteArray& json); |
---|
154 | void executed (int64_t tag, const QString& result, tr_variant * arguments); |
---|
155 | void sourceChanged (); |
---|
156 | void portTested (bool isOpen); |
---|
157 | void statsUpdated (); |
---|
158 | void sessionUpdated (); |
---|
159 | void blocklistUpdated (int); |
---|
160 | void torrentsUpdated (tr_variant * torrentList, bool completeList); |
---|
161 | void torrentsRemoved (tr_variant * torrentList); |
---|
162 | void dataReadProgress (); |
---|
163 | void dataSendProgress (); |
---|
164 | void error (QNetworkReply::NetworkError); |
---|
165 | void errorMessage (const QString); |
---|
166 | void httpAuthenticationRequired (); |
---|
167 | |
---|
168 | private: |
---|
169 | int64_t nextUniqueTag; |
---|
170 | int64_t myBlocklistSize; |
---|
171 | Prefs& myPrefs; |
---|
172 | tr_session * mySession; |
---|
173 | QString myConfigDir; |
---|
174 | QString mySessionId; |
---|
175 | QStringList myIdleJSON; |
---|
176 | QUrl myUrl; |
---|
177 | QNetworkAccessManager * myNAM; |
---|
178 | tr_session_stats myStats; |
---|
179 | tr_session_stats myCumulativeStats; |
---|
180 | QString mySessionVersion; |
---|
181 | }; |
---|
182 | |
---|
183 | #endif |
---|
184 | |
---|