1 | /* |
---|
2 | * This file Copyright (C) Mnemosyne LLC |
---|
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 version 2 |
---|
6 | * as published by the Free Software Foundation. |
---|
7 | * |
---|
8 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
9 | * |
---|
10 | * $Id: session.h 11109 2010-08-04 13:56:52Z charles $ |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef TR_APP_SESSION_H |
---|
14 | #define TR_APP_SESSION_H |
---|
15 | |
---|
16 | #include <QObject> |
---|
17 | #include <QSet> |
---|
18 | #include <QBuffer> |
---|
19 | #include <QFileInfoList> |
---|
20 | #include <QNetworkAccessManager> |
---|
21 | #include <QString> |
---|
22 | #include <QUrl> |
---|
23 | |
---|
24 | class QStringList; |
---|
25 | |
---|
26 | class AddData; |
---|
27 | |
---|
28 | #include <libtransmission/transmission.h> |
---|
29 | |
---|
30 | extern "C" |
---|
31 | { |
---|
32 | struct tr_benc; |
---|
33 | } |
---|
34 | |
---|
35 | class Prefs; |
---|
36 | |
---|
37 | class Session: public QObject |
---|
38 | { |
---|
39 | Q_OBJECT |
---|
40 | |
---|
41 | public: |
---|
42 | Session( const char * configDir, Prefs& prefs ); |
---|
43 | ~Session( ); |
---|
44 | |
---|
45 | public: |
---|
46 | void stop( ); |
---|
47 | void restart( ); |
---|
48 | |
---|
49 | private: |
---|
50 | void start( ); |
---|
51 | |
---|
52 | public: |
---|
53 | const QUrl& getRemoteUrl( ) const { return myUrl; } |
---|
54 | const struct tr_session_stats& getStats( ) const { return myStats; } |
---|
55 | const struct tr_session_stats& getCumulativeStats( ) const { return myCumulativeStats; } |
---|
56 | const QString& sessionVersion( ) const { return mySessionVersion; } |
---|
57 | |
---|
58 | public: |
---|
59 | int64_t blocklistSize( ) const { return myBlocklistSize; } |
---|
60 | void setBlocklistSize( int64_t i ); |
---|
61 | void updateBlocklist( ); |
---|
62 | void portTest( ); |
---|
63 | void copyMagnetLinkToClipboard( int torrentId ); |
---|
64 | |
---|
65 | public: |
---|
66 | |
---|
67 | /** returns true if the transmission session is being run inside this client */ |
---|
68 | bool isServer( ) const; |
---|
69 | |
---|
70 | /** returns true if isServer() is true or if the remote address is the localhost */ |
---|
71 | bool isLocal( ) const; |
---|
72 | |
---|
73 | private: |
---|
74 | void updateStats( struct tr_benc * args ); |
---|
75 | void updateInfo( struct tr_benc * args ); |
---|
76 | void parseResponse( const char * json, size_t len ); |
---|
77 | static void localSessionCallback( tr_session *, const char *, size_t, void * ); |
---|
78 | |
---|
79 | public: |
---|
80 | void exec( const char * json ); |
---|
81 | void exec( const struct tr_benc * request ); |
---|
82 | |
---|
83 | public: |
---|
84 | int64_t getUniqueTag( ) { return nextUniqueTag++; } |
---|
85 | |
---|
86 | private: |
---|
87 | void sessionSet( const char * key, const QVariant& variant ); |
---|
88 | void pumpRequests( ); |
---|
89 | void sendTorrentRequest( const char * request, const QSet<int>& torrentIds ); |
---|
90 | static void updateStats( struct tr_benc * d, struct tr_session_stats * stats ); |
---|
91 | void refreshTorrents( const QSet<int>& torrentIds ); |
---|
92 | QNetworkAccessManager * networkAccessManager( ); |
---|
93 | |
---|
94 | public: |
---|
95 | void torrentSet( const QSet<int>& ids, const QString& key, bool val ); |
---|
96 | void torrentSet( const QSet<int>& ids, const QString& key, int val ); |
---|
97 | void torrentSet( const QSet<int>& ids, const QString& key, double val ); |
---|
98 | void torrentSet( const QSet<int>& ids, const QString& key, const QList<int>& val ); |
---|
99 | void torrentSet( const QSet<int>& ids, const QString& key, const QStringList& val ); |
---|
100 | void torrentSetLocation( const QSet<int>& ids, const QString& path, bool doMove ); |
---|
101 | |
---|
102 | |
---|
103 | public slots: |
---|
104 | void pauseTorrents( const QSet<int>& torrentIds = QSet<int>() ); |
---|
105 | void startTorrents( const QSet<int>& torrentIds = QSet<int>() ); |
---|
106 | void refreshSessionInfo( ); |
---|
107 | void refreshSessionStats( ); |
---|
108 | void refreshActiveTorrents( ); |
---|
109 | void refreshAllTorrents( ); |
---|
110 | void initTorrents( const QSet<int>& ids = QSet<int>() ); |
---|
111 | void addNewlyCreatedTorrent( const QString& filename, const QString& localPath ); |
---|
112 | void addTorrent( const AddData& addme ); |
---|
113 | void removeTorrents( const QSet<int>& torrentIds, bool deleteFiles=false ); |
---|
114 | void verifyTorrents( const QSet<int>& torrentIds ); |
---|
115 | void reannounceTorrents( const QSet<int>& torrentIds ); |
---|
116 | void launchWebInterface( ); |
---|
117 | void updatePref( int key ); |
---|
118 | |
---|
119 | /** request a refresh for statistics, including the ones only used by the properties dialog, for a specific torrent */ |
---|
120 | void refreshExtraStats( const QSet<int>& ids ); |
---|
121 | |
---|
122 | private slots: |
---|
123 | void onFinished( QNetworkReply * reply ); |
---|
124 | |
---|
125 | signals: |
---|
126 | void executed( int64_t tag, const QString& result, struct tr_benc * arguments ); |
---|
127 | void sourceChanged( ); |
---|
128 | void portTested( bool isOpen ); |
---|
129 | void statsUpdated( ); |
---|
130 | void sessionUpdated( ); |
---|
131 | void blocklistUpdated( int ); |
---|
132 | void torrentsUpdated( struct tr_benc * torrentList, bool completeList ); |
---|
133 | void torrentsRemoved( struct tr_benc * torrentList ); |
---|
134 | void dataReadProgress( ); |
---|
135 | void dataSendProgress( ); |
---|
136 | void httpAuthenticationRequired( ); |
---|
137 | |
---|
138 | private: |
---|
139 | int64_t nextUniqueTag; |
---|
140 | int64_t myBlocklistSize; |
---|
141 | Prefs& myPrefs; |
---|
142 | tr_session * mySession; |
---|
143 | QString myConfigDir; |
---|
144 | QString mySessionId; |
---|
145 | QUrl myUrl; |
---|
146 | QNetworkAccessManager * myNAM; |
---|
147 | struct tr_session_stats myStats; |
---|
148 | struct tr_session_stats myCumulativeStats; |
---|
149 | QString mySessionVersion; |
---|
150 | }; |
---|
151 | |
---|
152 | #endif |
---|
153 | |
---|