Changeset 13944
- Timestamp:
- Feb 3, 2013, 7:40:20 PM (8 years ago)
- Location:
- trunk/qt
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt/license.cc
r11092 r13944 17 17 #include "license.h" 18 18 19 LicenseDialog :: LicenseDialog ( QWidget * parent):20 QDialog( parent, Qt::Dialog)19 LicenseDialog :: LicenseDialog (QWidget * parent): 20 QDialog (parent, Qt::Dialog) 21 21 { 22 setWindowTitle( tr( "License" ));23 resize( 400, 300);24 QVBoxLayout * v = new QVBoxLayout( this);22 setWindowTitle (tr ("License")); 23 resize (400, 300); 24 QVBoxLayout * v = new QVBoxLayout (this); 25 25 26 QPlainTextEdit * t = new QPlainTextEdit( this);27 t->setReadOnly( true);28 t->setPlainText(26 QPlainTextEdit * t = new QPlainTextEdit (this); 27 t->setReadOnly (true); 28 t->setPlainText ( 29 29 "The OS X client, CLI client, and parts of libtransmission are licensed under the terms of the MIT license.\n\n" 30 30 "The Transmission daemon, GTK+ client, Qt client, Web client, and most of libtransmission are licensed under the terms of the GNU GPL version 2, with two special exceptions:\n\n" 31 "1. The MIT-licensed portions of Transmission listed above are exempt from GPLv2 clause 2 (b) and may retain their MIT license.\n\n"32 "2. Permission is granted to link the code in this release with the OpenSSL project's 'OpenSSL' library and to distribute the linked executables. Works derived from Transmission may, at their authors' discretion, keep or delete this exception." 33 v->addWidget( t);31 "1. The MIT-licensed portions of Transmission listed above are exempt from GPLv2 clause 2 (b) and may retain their MIT license.\n\n" 32 "2. Permission is granted to link the code in this release with the OpenSSL project's 'OpenSSL' library and to distribute the linked executables. Works derived from Transmission may, at their authors' discretion, keep or delete this exception."); 33 v->addWidget (t); 34 34 35 36 box->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed);37 box->setOrientation( Qt::Horizontal);38 box->setStandardButtons( QDialogButtonBox::Close);39 v->addWidget( box);35 QDialogButtonBox * box = new QDialogButtonBox; 36 box->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed); 37 box->setOrientation (Qt::Horizontal); 38 box->setStandardButtons (QDialogButtonBox::Close); 39 v->addWidget (box); 40 40 41 connect( box, SIGNAL(rejected()), this, SLOT(hide()));41 connect (box, SIGNAL (rejected ()), this, SLOT (hide ())); 42 42 } -
trunk/qt/license.h
r11092 r13944 18 18 class LicenseDialog: public QDialog 19 19 { 20 20 Q_OBJECT 21 21 22 public: 23 LicenseDialog( QWidget * parent = 0 ); 24 ~LicenseDialog( ) { } 25 22 public: 23 LicenseDialog (QWidget * parent = 0); 24 ~LicenseDialog () {} 26 25 }; 27 26 -
trunk/qt/relocate.cc
r12697 r13944 33 33 34 34 void 35 RelocateDialog :: onSetLocation ()35 RelocateDialog :: onSetLocation () 36 36 { 37 mySession.torrentSetLocation( myIds, myPath, myMoveFlag);38 deleteLater();37 mySession.torrentSetLocation (myIds, myPath, myMoveFlag); 38 deleteLater (); 39 39 } 40 40 41 41 void 42 RelocateDialog :: onFileSelected ( const QString& path)42 RelocateDialog :: onFileSelected (const QString& path) 43 43 { 44 45 myDirButton->setText( myPath);44 myPath = path; 45 myDirButton->setText (myPath); 46 46 } 47 47 48 48 void 49 RelocateDialog :: onDirButtonClicked ()49 RelocateDialog :: onDirButtonClicked () 50 50 { 51 const QString title = tr( "Select Location");52 const QString path = Utils::remoteFileChooser( this, title, myPath, true, mySession.isServer());51 const QString title = tr ("Select Location"); 52 const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer ()); 53 53 54 if( !path.isEmpty())55 onFileSelected( path);54 if (!path.isEmpty ()) 55 onFileSelected (path); 56 56 } 57 57 58 58 void 59 RelocateDialog :: onMoveToggled ( bool b)59 RelocateDialog :: onMoveToggled (bool b) 60 60 { 61 61 myMoveFlag = b; 62 62 } 63 63 64 RelocateDialog :: RelocateDialog( Session& session, TorrentModel& model, const QSet<int>& ids, QWidget * parent ): 65 QDialog( parent ), 66 mySession( session ), 67 myModel( model ), 68 myIds( ids ) 64 RelocateDialog :: RelocateDialog (Session & session, 65 TorrentModel & model, 66 const QSet<int> & ids, 67 QWidget * parent): 68 QDialog (parent), 69 mySession (session), 70 myModel (model), 71 myIds (ids) 69 72 { 70 const int iconSize( style( )->pixelMetric( QStyle :: PM_SmallIconSize ));71 72 const QIcon folderIcon = iconProvider.icon( QFileIconProvider::Folder);73 const QPixmap folderPixmap = folderIcon.pixmap( iconSize);73 const int iconSize (style ()->pixelMetric (QStyle :: PM_SmallIconSize)); 74 const QFileIconProvider iconProvider; 75 const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder); 76 const QPixmap folderPixmap = folderIcon.pixmap (iconSize); 74 77 75 76 setWindowTitle( tr( "Set Torrent Location" ));78 QRadioButton * find_rb; 79 setWindowTitle (tr ("Set Torrent Location")); 77 80 78 foreach( int id, myIds ) {79 const Torrent * tor = myModel.getTorrentFromId( id );80 if( myPath.isEmpty() )81 myPath = tor->getPath(); 82 else if( myPath != tor->getPath())81 foreach (int id, myIds) 82 { 83 const Torrent * tor = myModel.getTorrentFromId (id); 84 85 if (myPath.isEmpty ()) 83 86 { 84 if( mySession.isServer() ) 85 myPath = QDir::homePath( ); 86 else 87 myPath = QDir::rootPath( ); 87 myPath = tor->getPath (); 88 } 89 else if (myPath != tor->getPath ()) 90 { 91 if (mySession.isServer ()) 92 myPath = QDir::homePath (); 93 else 94 myPath = QDir::rootPath (); 88 95 } 89 96 } 90 97 91 HIG * hig = new HIG();92 hig->addSectionTitle( tr( "Set Location" ));93 hig->addRow( tr( "New &location:" ), myDirButton = new QPushButton( folderPixmap, myPath ));94 hig->addWideControl( myMoveRadio = new QRadioButton( tr( "&Move from the current folder" ), this ));95 hig->addWideControl( find_rb = new QRadioButton( tr( "Local data is &already there" ), this ));96 hig->finish();98 HIG * hig = new HIG (); 99 hig->addSectionTitle (tr ("Set Location")); 100 hig->addRow (tr ("New &location:"), myDirButton = new QPushButton (folderPixmap, myPath)); 101 hig->addWideControl (myMoveRadio = new QRadioButton (tr ("&Move from the current folder"), this)); 102 hig->addWideControl (find_rb = new QRadioButton (tr ("Local data is &already there"), this)); 103 hig->finish (); 97 104 98 if( myMoveFlag)99 myMoveRadio->setChecked( true);100 101 find_rb->setChecked( true);105 if (myMoveFlag) 106 myMoveRadio->setChecked (true); 107 else 108 find_rb->setChecked (true); 102 109 103 connect( myMoveRadio, SIGNAL(toggled(bool)), this, SLOT(onMoveToggled(bool)));104 connect( myDirButton, SIGNAL(clicked(bool)), this, SLOT(onDirButtonClicked()));110 connect (myMoveRadio, SIGNAL (toggled (bool)), this, SLOT (onMoveToggled (bool))); 111 connect (myDirButton, SIGNAL (clicked (bool)), this, SLOT (onDirButtonClicked ())); 105 112 106 QLayout * layout = new QVBoxLayout( this);107 layout->addWidget( hig);108 QDialogButtonBox * buttons = new QDialogButtonBox( QDialogButtonBox::Ok|QDialogButtonBox::Cancel);109 connect( buttons, SIGNAL(rejected()), this, SLOT(deleteLater()));110 connect( buttons, SIGNAL(accepted()), this, SLOT(onSetLocation()));111 layout->addWidget( buttons);112 QWidget::setAttribute( Qt::WA_DeleteOnClose, true);113 QLayout * layout = new QVBoxLayout (this); 114 layout->addWidget (hig); 115 QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Ok|QDialogButtonBox::Cancel); 116 connect (buttons, SIGNAL (rejected ()), this, SLOT (deleteLater ())); 117 connect (buttons, SIGNAL (accepted ()), this, SLOT (onSetLocation ())); 118 layout->addWidget (buttons); 119 QWidget::setAttribute (Qt::WA_DeleteOnClose, true); 113 120 } -
trunk/qt/relocate.h
r11092 r13944 26 26 class RelocateDialog: public QDialog 27 27 { 28 28 Q_OBJECT 29 29 30 31 32 30 private: 31 QString myPath; 32 static bool myMoveFlag; 33 33 34 35 36 37 38 39 34 private: 35 Session & mySession; 36 TorrentModel& myModel; 37 QSet<int> myIds; 38 QPushButton * myDirButton; 39 QRadioButton * myMoveRadio; 40 40 41 42 void onFileSelected( const QString& path);43 void onDirButtonClicked();44 void onSetLocation();45 void onMoveToggled( bool);41 private slots: 42 void onFileSelected (const QString& path); 43 void onDirButtonClicked (); 44 void onSetLocation (); 45 void onMoveToggled (bool); 46 46 47 48 RelocateDialog( Session&, TorrentModel&, const QSet<int>& ids, QWidget * parent = 0);49 ~RelocateDialog() { }47 public: 48 RelocateDialog (Session&, TorrentModel&, const QSet<int>& ids, QWidget * parent = 0); 49 ~RelocateDialog () { } 50 50 }; 51 51 -
trunk/qt/session.cc
r13893 r13944 51 51 namespace 52 52 { 53 54 55 56 57 58 59 60 61 62 63 64 65 66 53 enum 54 { 55 TAG_SOME_TORRENTS, 56 TAG_ALL_TORRENTS, 57 TAG_SESSION_STATS, 58 TAG_SESSION_INFO, 59 TAG_BLOCKLIST_UPDATE, 60 TAG_ADD_TORRENT, 61 TAG_PORT_TEST, 62 TAG_MAGNET_LINK, 63 TAG_RENAME_PATH, 64 65 FIRST_UNIQUE_TAG 66 }; 67 67 } 68 68 … … 74 74 { 75 75 typedef Torrent::KeyList KeyList; 76 const KeyList& getInfoKeys () { return Torrent::getInfoKeys(); }77 const KeyList& getStatKeys () { return Torrent::getStatKeys(); }78 const KeyList& getExtraStatKeys () { return Torrent::getExtraStatKeys(); }76 const KeyList& getInfoKeys () { return Torrent::getInfoKeys (); } 77 const KeyList& getStatKeys () { return Torrent::getStatKeys (); } 78 const KeyList& getExtraStatKeys () { return Torrent::getExtraStatKeys (); } 79 79 80 80 void 81 81 addList (tr_variant * list, const KeyList& keys) 82 82 { 83 tr_variantListReserve (list, keys.size ());83 tr_variantListReserve (list, keys.size ()); 84 84 foreach (tr_quark key, keys) 85 85 tr_variantListAddQuark (list, key); … … 92 92 93 93 void 94 Session :: sessionSet( const tr_quark key, const QVariant& value ) 95 { 96 tr_variant top; 97 tr_variantInitDict( &top, 2 ); 98 tr_variantDictAddStr( &top, TR_KEY_method, "session-set" ); 99 tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 1 ) ); 100 switch( value.type( ) ) { 101 case QVariant::Bool: tr_variantDictAddBool ( args, key, value.toBool() ); break; 102 case QVariant::Int: tr_variantDictAddInt ( args, key, value.toInt() ); break; 103 case QVariant::Double: tr_variantDictAddReal ( args, key, value.toDouble() ); break; 104 case QVariant::String: tr_variantDictAddStr ( args, key, value.toString().toUtf8().constData() ); break; 105 default: assert( "unknown type" ); 106 } 107 exec( &top ); 108 tr_variantFree( &top ); 109 } 110 111 void 112 Session :: portTest( ) 113 { 114 tr_variant top; 115 tr_variantInitDict( &top, 2 ); 116 tr_variantDictAddStr( &top, TR_KEY_method, "port-test" ); 117 tr_variantDictAddInt( &top, TR_KEY_tag, TAG_PORT_TEST ); 118 exec( &top ); 119 tr_variantFree( &top ); 120 } 121 122 void 123 Session :: copyMagnetLinkToClipboard( int torrentId ) 124 { 125 tr_variant top; 126 tr_variantInitDict( &top, 3 ); 127 tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get ); 128 tr_variantDictAddInt( &top, TR_KEY_tag, TAG_MAGNET_LINK ); 129 tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ); 130 tr_variantListAddInt( tr_variantDictAddList( args, TR_KEY_ids, 1 ), torrentId ); 131 tr_variantListAddStr( tr_variantDictAddList( args, TR_KEY_fields, 1 ), "magnetLink" ); 132 133 exec( &top ); 134 tr_variantFree( &top ); 135 } 136 137 void 138 Session :: updatePref( int key ) 139 { 140 if( myPrefs.isCore( key ) ) switch( key ) 141 { 142 case Prefs :: ALT_SPEED_LIMIT_DOWN: 143 case Prefs :: ALT_SPEED_LIMIT_ENABLED: 144 case Prefs :: ALT_SPEED_LIMIT_TIME_BEGIN: 145 case Prefs :: ALT_SPEED_LIMIT_TIME_DAY: 146 case Prefs :: ALT_SPEED_LIMIT_TIME_ENABLED: 147 case Prefs :: ALT_SPEED_LIMIT_TIME_END: 148 case Prefs :: ALT_SPEED_LIMIT_UP: 149 case Prefs :: BLOCKLIST_DATE: 150 case Prefs :: BLOCKLIST_ENABLED: 151 case Prefs :: BLOCKLIST_URL: 152 case Prefs :: DHT_ENABLED: 153 case Prefs :: DOWNLOAD_QUEUE_ENABLED: 154 case Prefs :: DOWNLOAD_QUEUE_SIZE: 155 case Prefs :: DSPEED: 156 case Prefs :: DSPEED_ENABLED: 157 case Prefs :: IDLE_LIMIT: 158 case Prefs :: IDLE_LIMIT_ENABLED: 159 case Prefs :: INCOMPLETE_DIR: 160 case Prefs :: INCOMPLETE_DIR_ENABLED: 161 case Prefs :: LPD_ENABLED: 162 case Prefs :: PEER_LIMIT_GLOBAL: 163 case Prefs :: PEER_LIMIT_TORRENT: 164 case Prefs :: PEER_PORT: 165 case Prefs :: PEER_PORT_RANDOM_ON_START: 166 case Prefs :: QUEUE_STALLED_MINUTES: 167 case Prefs :: PEX_ENABLED: 168 case Prefs :: PORT_FORWARDING: 169 case Prefs :: RENAME_PARTIAL_FILES: 170 case Prefs :: SCRIPT_TORRENT_DONE_ENABLED: 171 case Prefs :: SCRIPT_TORRENT_DONE_FILENAME: 172 case Prefs :: START: 173 case Prefs :: TRASH_ORIGINAL: 174 case Prefs :: USPEED: 175 case Prefs :: USPEED_ENABLED: 176 case Prefs :: UTP_ENABLED: 177 sessionSet( myPrefs.getKey(key), myPrefs.variant(key) ); 178 break; 179 180 case Prefs :: DOWNLOAD_DIR: 181 sessionSet (myPrefs.getKey(key), myPrefs.variant(key)); 182 /* this will change the 'freespace' argument, so refresh */ 183 refreshSessionInfo (); 184 break; 185 186 case Prefs :: RATIO: 187 sessionSet( TR_KEY_seedRatioLimit, myPrefs.variant(key) ); 188 break; 189 case Prefs :: RATIO_ENABLED: 190 sessionSet( TR_KEY_seedRatioLimited, myPrefs.variant(key) ); 191 break; 192 193 case Prefs :: ENCRYPTION: 94 Session :: sessionSet (const tr_quark key, const QVariant& value) 95 { 96 tr_variant top; 97 tr_variantInitDict (&top, 2); 98 tr_variantDictAddStr (&top, TR_KEY_method, "session-set"); 99 tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 1)); 100 switch (value.type ()) 101 { 102 case QVariant::Bool: tr_variantDictAddBool (args, key, value.toBool ()); break; 103 case QVariant::Int: tr_variantDictAddInt (args, key, value.toInt ()); break; 104 case QVariant::Double: tr_variantDictAddReal (args, key, value.toDouble ()); break; 105 case QVariant::String: tr_variantDictAddStr (args, key, value.toString ().toUtf8 ().constData ()); break; 106 default: assert ("unknown type"); 107 } 108 exec (&top); 109 tr_variantFree (&top); 110 } 111 112 void 113 Session :: portTest () 114 { 115 tr_variant top; 116 tr_variantInitDict (&top, 2); 117 tr_variantDictAddStr (&top, TR_KEY_method, "port-test"); 118 tr_variantDictAddInt (&top, TR_KEY_tag, TAG_PORT_TEST); 119 exec (&top); 120 tr_variantFree (&top); 121 } 122 123 void 124 Session :: copyMagnetLinkToClipboard (int torrentId) 125 { 126 tr_variant top; 127 tr_variantInitDict (&top, 3); 128 tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get); 129 tr_variantDictAddInt (&top, TR_KEY_tag, TAG_MAGNET_LINK); 130 tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); 131 tr_variantListAddInt (tr_variantDictAddList (args, TR_KEY_ids, 1), torrentId); 132 tr_variantListAddStr (tr_variantDictAddList (args, TR_KEY_fields, 1), "magnetLink"); 133 exec (&top); 134 tr_variantFree (&top); 135 } 136 137 void 138 Session :: updatePref (int key) 139 { 140 if (myPrefs.isCore (key)) switch (key) 141 { 142 case Prefs :: ALT_SPEED_LIMIT_DOWN: 143 case Prefs :: ALT_SPEED_LIMIT_ENABLED: 144 case Prefs :: ALT_SPEED_LIMIT_TIME_BEGIN: 145 case Prefs :: ALT_SPEED_LIMIT_TIME_DAY: 146 case Prefs :: ALT_SPEED_LIMIT_TIME_ENABLED: 147 case Prefs :: ALT_SPEED_LIMIT_TIME_END: 148 case Prefs :: ALT_SPEED_LIMIT_UP: 149 case Prefs :: BLOCKLIST_DATE: 150 case Prefs :: BLOCKLIST_ENABLED: 151 case Prefs :: BLOCKLIST_URL: 152 case Prefs :: DHT_ENABLED: 153 case Prefs :: DOWNLOAD_QUEUE_ENABLED: 154 case Prefs :: DOWNLOAD_QUEUE_SIZE: 155 case Prefs :: DSPEED: 156 case Prefs :: DSPEED_ENABLED: 157 case Prefs :: IDLE_LIMIT: 158 case Prefs :: IDLE_LIMIT_ENABLED: 159 case Prefs :: INCOMPLETE_DIR: 160 case Prefs :: INCOMPLETE_DIR_ENABLED: 161 case Prefs :: LPD_ENABLED: 162 case Prefs :: PEER_LIMIT_GLOBAL: 163 case Prefs :: PEER_LIMIT_TORRENT: 164 case Prefs :: PEER_PORT: 165 case Prefs :: PEER_PORT_RANDOM_ON_START: 166 case Prefs :: QUEUE_STALLED_MINUTES: 167 case Prefs :: PEX_ENABLED: 168 case Prefs :: PORT_FORWARDING: 169 case Prefs :: RENAME_PARTIAL_FILES: 170 case Prefs :: SCRIPT_TORRENT_DONE_ENABLED: 171 case Prefs :: SCRIPT_TORRENT_DONE_FILENAME: 172 case Prefs :: START: 173 case Prefs :: TRASH_ORIGINAL: 174 case Prefs :: USPEED: 175 case Prefs :: USPEED_ENABLED: 176 case Prefs :: UTP_ENABLED: 177 sessionSet (myPrefs.getKey (key), myPrefs.variant (key)); 178 break; 179 180 case Prefs :: DOWNLOAD_DIR: 181 sessionSet (myPrefs.getKey (key), myPrefs.variant (key)); 182 /* this will change the 'freespace' argument, so refresh */ 183 refreshSessionInfo (); 184 break; 185 186 case Prefs :: RATIO: 187 sessionSet (TR_KEY_seedRatioLimit, myPrefs.variant (key)); 188 break; 189 case Prefs :: RATIO_ENABLED: 190 sessionSet (TR_KEY_seedRatioLimited, myPrefs.variant (key)); 191 break; 192 193 case Prefs :: ENCRYPTION: 194 { 195 const int i = myPrefs.variant (key).toInt (); 196 switch (i) 194 197 { 195 const int i = myPrefs.variant(key).toInt(); 196 switch( i ) 197 { 198 case 0: 199 sessionSet( myPrefs.getKey(key), "tolerated" ); 200 break; 201 case 1: 202 sessionSet( myPrefs.getKey(key), "preferred" ); 203 break; 204 case 2: 205 sessionSet( myPrefs.getKey(key), "required" ); 206 break; 207 } 198 case 0: 199 sessionSet (myPrefs.getKey (key), "tolerated"); 200 break; 201 case 1: 202 sessionSet (myPrefs.getKey (key), "preferred"); 203 break; 204 case 2: 205 sessionSet (myPrefs.getKey (key), "required"); 208 206 break; 209 207 } 210 211 case Prefs :: RPC_AUTH_REQUIRED: 212 if( mySession ) 213 tr_sessionSetRPCPasswordEnabled( mySession, myPrefs.getBool(key) ); 214 break; 215 case Prefs :: RPC_ENABLED: 216 if( mySession ) 217 tr_sessionSetRPCEnabled( mySession, myPrefs.getBool(key) ); 218 break; 219 case Prefs :: RPC_PASSWORD: 220 if( mySession ) 221 tr_sessionSetRPCPassword( mySession, myPrefs.getString(key).toUtf8().constData() ); 222 break; 223 case Prefs :: RPC_PORT: 224 if( mySession ) 225 tr_sessionSetRPCPort( mySession, myPrefs.getInt(key) ); 226 break; 227 case Prefs :: RPC_USERNAME: 228 if( mySession ) 229 tr_sessionSetRPCUsername( mySession, myPrefs.getString(key).toUtf8().constData() ); 230 break; 231 case Prefs :: RPC_WHITELIST_ENABLED: 232 if( mySession ) 233 tr_sessionSetRPCWhitelistEnabled( mySession, myPrefs.getBool(key) ); 234 break; 235 case Prefs :: RPC_WHITELIST: 236 if( mySession ) 237 tr_sessionSetRPCWhitelist( mySession, myPrefs.getString(key).toUtf8().constData() ); 238 break; 239 240 default: 241 std::cerr << "unhandled pref: " << key << std::endl; 208 break; 209 } 210 211 case Prefs :: RPC_AUTH_REQUIRED: 212 if (mySession) 213 tr_sessionSetRPCPasswordEnabled (mySession, myPrefs.getBool (key)); 214 break; 215 216 case Prefs :: RPC_ENABLED: 217 if (mySession) 218 tr_sessionSetRPCEnabled (mySession, myPrefs.getBool (key)); 219 break; 220 221 case Prefs :: RPC_PASSWORD: 222 if (mySession) 223 tr_sessionSetRPCPassword (mySession, myPrefs.getString (key).toUtf8 ().constData ()); 224 break; 225 226 case Prefs :: RPC_PORT: 227 if (mySession) 228 tr_sessionSetRPCPort (mySession, myPrefs.getInt (key)); 229 break; 230 231 case Prefs :: RPC_USERNAME: 232 if (mySession) 233 tr_sessionSetRPCUsername (mySession, myPrefs.getString (key).toUtf8 ().constData ()); 234 break; 235 236 case Prefs :: RPC_WHITELIST_ENABLED: 237 if (mySession) 238 tr_sessionSetRPCWhitelistEnabled (mySession, myPrefs.getBool (key)); 239 break; 240 241 case Prefs :: RPC_WHITELIST: 242 if (mySession) 243 tr_sessionSetRPCWhitelist (mySession, myPrefs.getString (key).toUtf8 ().constData ()); 244 break; 245 246 default: 247 std::cerr << "unhandled pref: " << key << std::endl; 242 248 } 243 249 } … … 247 253 ***/ 248 254 249 Session :: Session ( const char * configDir, Prefs& prefs):250 nextUniqueTag( FIRST_UNIQUE_TAG),251 myBlocklistSize( -1),252 myPrefs( prefs),253 mySession( 0),254 myConfigDir( QString::fromUtf8( configDir )),255 myNAM( 0),256 myDownloadDirFreeSpace( -1)257 { 258 259 260 261 262 263 264 265 266 connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(updatePref(int)));267 268 connect (this, SIGNAL(responseReceived(const QByteArray&)),269 this, SLOT(onResponseReceived(const QByteArray&)));270 } 271 272 Session :: ~Session ()273 { 274 stop ();255 Session :: Session (const char * configDir, Prefs& prefs): 256 nextUniqueTag (FIRST_UNIQUE_TAG), 257 myBlocklistSize (-1), 258 myPrefs (prefs), 259 mySession (0), 260 myConfigDir (QString::fromUtf8 (configDir)), 261 myNAM (0), 262 myDownloadDirFreeSpace (-1) 263 { 264 myStats.ratio = TR_RATIO_NA; 265 myStats.uploadedBytes = 0; 266 myStats.downloadedBytes = 0; 267 myStats.filesAdded = 0; 268 myStats.sessionCount = 0; 269 myStats.secondsActive = 0; 270 myCumulativeStats = myStats; 271 272 connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (updatePref (int))); 273 274 connect (this, SIGNAL (responseReceived (const QByteArray&)), 275 this, SLOT (onResponseReceived (const QByteArray&))); 276 } 277 278 Session :: ~Session () 279 { 280 stop (); 275 281 } 276 282 277 283 QNetworkAccessManager * 278 Session :: networkAccessManager ()279 { 280 if( myNAM == 0)281 { 282 283 284 connect( myNAM, SIGNAL(finished(QNetworkReply*)),285 this, SLOT(onFinished(QNetworkReply*)));286 287 connect( myNAM, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),288 this, SIGNAL(httpAuthenticationRequired()));289 } 290 291 284 Session :: networkAccessManager () 285 { 286 if (myNAM == 0) 287 { 288 myNAM = new QNetworkAccessManager; 289 290 connect (myNAM, SIGNAL (finished (QNetworkReply*)), 291 this, SLOT (onFinished (QNetworkReply*))); 292 293 connect (myNAM, SIGNAL (authenticationRequired (QNetworkReply*,QAuthenticator*)), 294 this, SIGNAL (httpAuthenticationRequired ())); 295 } 296 297 return myNAM; 292 298 } 293 299 … … 297 303 298 304 void 299 Session :: stop ()300 { 301 if( myNAM != 0)302 { 303 myNAM->deleteLater();304 305 } 306 307 myUrl.clear ();308 309 if( mySession)310 { 311 tr_sessionClose( mySession);312 313 } 314 } 315 316 void 317 Session :: restart ()318 { 319 stop();320 start();321 } 322 323 void 324 Session :: start ()325 { 326 if( myPrefs.get<bool>(Prefs::SESSION_IS_REMOTE))327 { 328 329 url.setScheme( "http");330 url.setHost( myPrefs.get<QString>(Prefs::SESSION_REMOTE_HOST));331 url.setPort( myPrefs.get<int>(Prefs::SESSION_REMOTE_PORT));332 url.setPath( "/transmission/rpc");333 if( myPrefs.get<bool>(Prefs::SESSION_REMOTE_AUTH))305 Session :: stop () 306 { 307 if (myNAM != 0) 308 { 309 myNAM->deleteLater (); 310 myNAM = 0; 311 } 312 313 myUrl.clear (); 314 315 if (mySession) 316 { 317 tr_sessionClose (mySession); 318 mySession = 0; 319 } 320 } 321 322 void 323 Session :: restart () 324 { 325 stop (); 326 start (); 327 } 328 329 void 330 Session :: start () 331 { 332 if (myPrefs.get<bool> (Prefs::SESSION_IS_REMOTE)) 333 { 334 QUrl url; 335 url.setScheme ("http"); 336 url.setHost (myPrefs.get<QString> (Prefs::SESSION_REMOTE_HOST)); 337 url.setPort (myPrefs.get<int> (Prefs::SESSION_REMOTE_PORT)); 338 url.setPath ("/transmission/rpc"); 339 if (myPrefs.get<bool> (Prefs::SESSION_REMOTE_AUTH)) 334 340 { 335 url.setUserName( myPrefs.get<QString>(Prefs::SESSION_REMOTE_USERNAME));336 url.setPassword( myPrefs.get<QString>(Prefs::SESSION_REMOTE_PASSWORD));341 url.setUserName (myPrefs.get<QString> (Prefs::SESSION_REMOTE_USERNAME)); 342 url.setPassword (myPrefs.get<QString> (Prefs::SESSION_REMOTE_PASSWORD)); 337 343 } 338 339 } 340 341 { 342 343 tr_variantInitDict( &settings, 0);344 tr_sessionLoadSettings( &settings, myConfigDir.toUtf8().constData(), "qt");345 mySession = tr_sessionInit( "qt", myConfigDir.toUtf8().constData(), true, &settings);346 tr_variantFree( &settings);347 348 tr_ctor * ctor = tr_ctorNew( mySession);349 350 tr_torrent ** torrents = tr_sessionLoadTorrents( mySession, ctor, &torrentCount);351 tr_free( torrents);352 tr_ctorFree( ctor);353 } 354 355 emit sourceChanged();344 myUrl = url; 345 } 346 else 347 { 348 tr_variant settings; 349 tr_variantInitDict (&settings, 0); 350 tr_sessionLoadSettings (&settings, myConfigDir.toUtf8 ().constData (), "qt"); 351 mySession = tr_sessionInit ("qt", myConfigDir.toUtf8 ().constData (), true, &settings); 352 tr_variantFree (&settings); 353 354 tr_ctor * ctor = tr_ctorNew (mySession); 355 int torrentCount; 356 tr_torrent ** torrents = tr_sessionLoadTorrents (mySession, ctor, &torrentCount); 357 tr_free (torrents); 358 tr_ctorFree (ctor); 359 } 360 361 emit sourceChanged (); 356 362 } 357 363 358 364 bool 359 Session :: isServer () const360 { 361 365 Session :: isServer () const 366 { 367 return mySession != 0; 362 368 } 363 369 364 370 bool 365 Session :: isLocal () const366 { 367 if( mySession != 0)368 369 370 if( myUrl.host() == "127.0.0.1")371 372 373 if( !myUrl.host().compare( "localhost", Qt::CaseInsensitive ))374 375 376 371 Session :: isLocal () const 372 { 373 if (mySession != 0) 374 return true; 375 376 if (myUrl.host () == "127.0.0.1") 377 return true; 378 379 if (!myUrl.host ().compare ("localhost", Qt::CaseInsensitive)) 380 return true; 381 382 return false; 377 383 } 378 384 … … 396 402 397 403 void 398 addOptionalIds ( tr_variant * args, const QSet<int>& ids)404 addOptionalIds (tr_variant * args, const QSet<int>& ids) 399 405 { 400 if (!ids.isEmpty ())406 if (!ids.isEmpty ()) 401 407 { 402 tr_variant * idList (tr_variantDictAddList (args, TR_KEY_ids, ids.size ()));408 tr_variant * idList (tr_variantDictAddList (args, TR_KEY_ids, ids.size ())); 403 409 foreach (int i, ids) 404 410 tr_variantListAddInt (idList, i); … … 408 414 409 415 void 410 Session :: torrentSet ( const QSet<int>& ids, const tr_quark key, double value)411 { 412 413 tr_variantInitDict( &top, 2);414 tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set);415 tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2);416 tr_variantDictAddReal( args, key, value);417 addOptionalIds( args, ids);418 exec( &top);419 tr_variantFree( &top);420 } 421 422 void 423 Session :: torrentSet ( const QSet<int>& ids, const tr_quark key, int value)424 { 425 426 tr_variantInitDict( &top, 2);427 tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set);428 tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2);429 tr_variantDictAddInt( args, key, value);430 addOptionalIds( args, ids);431 exec( &top);432 tr_variantFree( &top);433 } 434 435 void 436 Session :: torrentSet ( const QSet<int>& ids, const tr_quark key, bool value)437 { 438 439 tr_variantInitDict( &top, 2);440 tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set);441 tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2);442 tr_variantDictAddBool( args, key, value);443 addOptionalIds( args, ids);444 exec( &top);445 tr_variantFree( &top);446 } 447 448 void 449 Session :: torrentSet ( const QSet<int>& ids, const tr_quark key, const QStringList& value)450 { 451 452 tr_variantInitDict( &top, 2);453 tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set);454 tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2);455 addOptionalIds( args, ids);456 tr_variant * list( tr_variantDictAddList( args, key, value.size( ) ));457 foreach( const QString str, value)458 tr_variantListAddStr( list, str.toUtf8().constData());459 exec( &top);460 tr_variantFree( &top);461 } 462 463 void 464 Session :: torrentSet ( const QSet<int>& ids, const tr_quark key, const QList<int>& value)465 { 466 467 tr_variantInitDict( &top, 2);468 tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set);469 tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ));470 addOptionalIds( args, ids);471 tr_variant * list( tr_variantDictAddList( args, key, value.size( ) ));472 foreach( int i, value)473 tr_variantListAddInt( list, i);474 exec( &top);475 tr_variantFree( &top);476 } 477 478 void 479 Session :: torrentSet ( const QSet<int>& ids, const tr_quark key, const QPair<int,QString>& value)416 Session :: torrentSet (const QSet<int>& ids, const tr_quark key, double value) 417 { 418 tr_variant top; 419 tr_variantInitDict (&top, 2); 420 tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set); 421 tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); 422 tr_variantDictAddReal (args, key, value); 423 addOptionalIds (args, ids); 424 exec (&top); 425 tr_variantFree (&top); 426 } 427 428 void 429 Session :: torrentSet (const QSet<int>& ids, const tr_quark key, int value) 430 { 431 tr_variant top; 432 tr_variantInitDict (&top, 2); 433 tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set); 434 tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); 435 tr_variantDictAddInt (args, key, value); 436 addOptionalIds (args, ids); 437 exec (&top); 438 tr_variantFree (&top); 439 } 440 441 void 442 Session :: torrentSet (const QSet<int>& ids, const tr_quark key, bool value) 443 { 444 tr_variant top; 445 tr_variantInitDict (&top, 2); 446 tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set); 447 tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); 448 tr_variantDictAddBool (args, key, value); 449 addOptionalIds (args, ids); 450 exec (&top); 451 tr_variantFree (&top); 452 } 453 454 void 455 Session :: torrentSet (const QSet<int>& ids, const tr_quark key, const QStringList& value) 456 { 457 tr_variant top; 458 tr_variantInitDict (&top, 2); 459 tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set); 460 tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); 461 addOptionalIds (args, ids); 462 tr_variant * list (tr_variantDictAddList (args, key, value.size ())); 463 foreach (const QString str, value) 464 tr_variantListAddStr (list, str.toUtf8 ().constData ()); 465 exec (&top); 466 tr_variantFree (&top); 467 } 468 469 void 470 Session :: torrentSet (const QSet<int>& ids, const tr_quark key, const QList<int>& value) 471 { 472 tr_variant top; 473 tr_variantInitDict (&top, 2); 474 tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set); 475 tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2)); 476 addOptionalIds (args, ids); 477 tr_variant * list (tr_variantDictAddList (args, key, value.size ())); 478 foreach (int i, value) 479 tr_variantListAddInt (list, i); 480 exec (&top); 481 tr_variantFree (&top); 482 } 483 484 void 485 Session :: torrentSet (const QSet<int>& ids, const tr_quark key, const QPair<int,QString>& value) 480 486 { 481 487 tr_variant top; … … 486 492 tr_variant * list (tr_variantDictAddList (args, key, 2)); 487 493 tr_variantListAddInt (list, value.first); 488 tr_variantListAddStr (list, value.second.toUtf8 ().constData());489 exec (&top); 490 tr_variantFree (&top); 491 } 492 493 void 494 Session :: torrentSetLocation (const QSet<int>& ids, const QString& location, bool doMove)494 tr_variantListAddStr (list, value.second.toUtf8 ().constData ()); 495 exec (&top); 496 tr_variantFree (&top); 497 } 498 499 void 500 Session :: torrentSetLocation (const QSet<int>& ids, const QString& location, bool doMove) 495 501 { 496 502 tr_variant top; 497 503 tr_variantInitDict (&top, 2); 498 504 tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set_location); 499 tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 3));505 tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 3)); 500 506 addOptionalIds (args, ids); 501 tr_variantDictAddStr (args, TR_KEY_location, location.toUtf8 ().constData());507 tr_variantDictAddStr (args, TR_KEY_location, location.toUtf8 ().constData ()); 502 508 tr_variantDictAddBool (args, TR_KEY_move, doMove); 503 509 exec (&top); … … 512 518 tr_variantDictAddStr (&top, TR_KEY_method, "torrent-rename-path"); 513 519 tr_variantDictAddInt (&top, TR_KEY_tag, TAG_RENAME_PATH); 514 tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 3));520 tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 3)); 515 521 addOptionalIds (args, ids); 516 tr_variantDictAddStr (args, TR_KEY_path, oldpath.toUtf8 ().constData());517 tr_variantDictAddStr (args, TR_KEY_name, newname.toUtf8 ().constData());518 exec (&top); 519 tr_variantFree (&top); 520 } 521 522 void 523 Session :: refreshTorrents ( const QSet<int>& ids)524 { 525 if( ids.empty( ))526 { 527 refreshAllTorrents();528 } 529 530 { 531 532 tr_variantInitDict( &top, 3);533 tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get);534 tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SOME_TORRENTS);535 tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ));536 addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys( ));537 addOptionalIds( args, ids);538 exec( &top);539 tr_variantFree( &top);540 } 541 } 542 543 void 544 Session :: refreshExtraStats ( const QSet<int>& ids)545 { 546 547 tr_variantInitDict( &top, 3);548 tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get);549 tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SOME_TORRENTS);550 tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ));551 addOptionalIds( args, ids);552 addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys( ) + getExtraStatKeys());553 exec( &top);554 tr_variantFree( &top);555 } 556 557 void 558 Session :: sendTorrentRequest (const char * request, const QSet<int>& ids 522 tr_variantDictAddStr (args, TR_KEY_path, oldpath.toUtf8 ().constData ()); 523 tr_variantDictAddStr (args, TR_KEY_name, newname.toUtf8 ().constData ()); 524 exec (&top); 525 tr_variantFree (&top); 526 } 527 528 void 529 Session :: refreshTorrents (const QSet<int>& ids) 530 { 531 if (ids.empty ()) 532 { 533 refreshAllTorrents (); 534 } 535 else 536 { 537 tr_variant top; 538 tr_variantInitDict (&top, 3); 539 tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get); 540 tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SOME_TORRENTS); 541 tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2)); 542 addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys ()); 543 addOptionalIds (args, ids); 544 exec (&top); 545 tr_variantFree (&top); 546 } 547 } 548 549 void 550 Session :: refreshExtraStats (const QSet<int>& ids) 551 { 552 tr_variant top; 553 tr_variantInitDict (&top, 3); 554 tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get); 555 tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SOME_TORRENTS); 556 tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2)); 557 addOptionalIds (args, ids); 558 addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys () + getExtraStatKeys ()); 559 exec (&top); 560 tr_variantFree (&top); 561 } 562 563 void 564 Session :: sendTorrentRequest (const char * request, const QSet<int>& ids) 559 565 { 560 566 tr_variant top; … … 577 583 578 584 void 579 Session :: refreshActiveTorrents ()580 { 581 582 tr_variantInitDict( &top, 3);583 tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get);584 tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SOME_TORRENTS);585 tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ));586 tr_variantDictAddStr( args, TR_KEY_ids, "recently-active");587 addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys( ));588 exec( &top);589 tr_variantFree( &top);590 } 591 592 void 593 Session :: refreshAllTorrents ()594 { 595 596 tr_variantInitDict( &top, 3);597 tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get);598 tr_variantDictAddInt( &top, TR_KEY_tag, TAG_ALL_TORRENTS);599 tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 1 ));600 addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys( ));601 exec( &top);602 tr_variantFree( &top);603 } 604 605 void 606 Session :: initTorrents ( const QSet<int>& ids)607 { 608 609 const int tag( ids.isEmpty() ? TAG_ALL_TORRENTS : TAG_SOME_TORRENTS);610 tr_variant * args( buildRequest( "torrent-get", top, tag ));611 addOptionalIds( args, ids);612 addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys()+getInfoKeys());613 exec( &top);614 tr_variantFree( &top);615 } 616 617 void 618 Session :: refreshSessionStats ()619 { 620 621 tr_variantInitDict( &top, 2);622 tr_variantDictAddStr( &top, TR_KEY_method, "session-stats");623 tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SESSION_STATS);624 exec( &top);625 tr_variantFree( &top);626 } 627 628 void 629 Session :: refreshSessionInfo ()630 { 631 632 tr_variantInitDict( &top, 2);633 tr_variantDictAddStr( &top, TR_KEY_method, "session-get");634 tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SESSION_INFO);635 exec( &top);636 tr_variantFree( &top);637 } 638 639 void 640 Session :: updateBlocklist ()641 { 642 643 tr_variantInitDict( &top, 2);644 tr_variantDictAddStr( &top, TR_KEY_method, "blocklist-update");645 tr_variantDictAddInt( &top, TR_KEY_tag, TAG_BLOCKLIST_UPDATE);646 exec( &top);647 tr_variantFree( &top);585 Session :: refreshActiveTorrents () 586 { 587 tr_variant top; 588 tr_variantInitDict (&top, 3); 589 tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get); 590 tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SOME_TORRENTS); 591 tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2)); 592 tr_variantDictAddStr (args, TR_KEY_ids, "recently-active"); 593 addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys ()); 594 exec (&top); 595 tr_variantFree (&top); 596 } 597 598 void 599 Session :: refreshAllTorrents () 600 { 601 tr_variant top; 602 tr_variantInitDict (&top, 3); 603 tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get); 604 tr_variantDictAddInt (&top, TR_KEY_tag, TAG_ALL_TORRENTS); 605 tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 1)); 606 addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys ()); 607 exec (&top); 608 tr_variantFree (&top); 609 } 610 611 void 612 Session :: initTorrents (const QSet<int>& ids) 613 { 614 tr_variant top; 615 const int tag (ids.isEmpty () ? TAG_ALL_TORRENTS : TAG_SOME_TORRENTS); 616 tr_variant * args (buildRequest ("torrent-get", top, tag)); 617 addOptionalIds (args, ids); 618 addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys ()+getInfoKeys ()); 619 exec (&top); 620 tr_variantFree (&top); 621 } 622 623 void 624 Session :: refreshSessionStats () 625 { 626 tr_variant top; 627 tr_variantInitDict (&top, 2); 628 tr_variantDictAddStr (&top, TR_KEY_method, "session-stats"); 629 tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SESSION_STATS); 630 exec (&top); 631 tr_variantFree (&top); 632 } 633 634 void 635 Session :: refreshSessionInfo () 636 { 637 tr_variant top; 638 tr_variantInitDict (&top, 2); 639 tr_variantDictAddStr (&top, TR_KEY_method, "session-get"); 640 tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SESSION_INFO); 641 exec (&top); 642 tr_variantFree (&top); 643 } 644 645 void 646 Session :: updateBlocklist () 647 { 648 tr_variant top; 649 tr_variantInitDict (&top, 2); 650 tr_variantDictAddStr (&top, TR_KEY_method, "blocklist-update"); 651 tr_variantDictAddInt (&top, TR_KEY_tag, TAG_BLOCKLIST_UPDATE); 652 exec (&top); 653 tr_variantFree (&top); 648 654 } 649 655 … … 653 659 654 660 void 655 Session :: exec ( const tr_variant * request)656 { 657 char * str = tr_variantToStr( request, TR_VARIANT_FMT_JSON_LEAN, NULL);658 exec( str);659 tr_free( str);660 } 661 662 void 663 Session :: localSessionCallback ( tr_session * s, struct evbuffer * json, void * vself)661 Session :: exec (const tr_variant * request) 662 { 663 char * str = tr_variantToStr (request, TR_VARIANT_FMT_JSON_LEAN, NULL); 664 exec (str); 665 tr_free (str); 666 } 667 668 void 669 Session :: localSessionCallback (tr_session * s, struct evbuffer * json, void * vself) 664 670 { 665 671 Q_UNUSED (s); 666 672 667 Session * self = static_cast<Session*> (vself);673 Session * self = static_cast<Session*> (vself); 668 674 669 675 /* this callback is invoked in the libtransmission thread, so we don't want 670 676 to process the response here... let's push it over to the Qt thread. */ 671 self->responseReceived (QByteArray ( (const char *)evbuffer_pullup (json, -1),672 677 self->responseReceived (QByteArray ( (const char *)evbuffer_pullup (json, -1), 678 (int)evbuffer_get_length (json))); 673 679 } 674 680 … … 676 682 677 683 void 678 Session :: exec( const char * json ) 679 { 680 if( mySession ) 681 { 682 tr_rpc_request_exec_json( mySession, json, strlen( json ), localSessionCallback, this ); 683 } 684 else if( !myUrl.isEmpty( ) ) 685 { 686 QNetworkRequest request; 687 request.setUrl( myUrl ); 688 request.setRawHeader( "User-Agent", QString( QCoreApplication::instance()->applicationName() + "/" + LONG_VERSION_STRING ).toAscii() ); 689 request.setRawHeader( "Content-Type", "application/json; charset=UTF-8" ); 690 if( !mySessionId.isEmpty( ) ) 691 request.setRawHeader( TR_RPC_SESSION_ID_HEADER, mySessionId.toAscii() ); 692 693 const QByteArray requestData( json ); 694 QNetworkReply * reply = networkAccessManager()->post( request, requestData ); 695 reply->setProperty( REQUEST_DATA_PROPERTY_KEY, requestData ); 696 connect( reply, SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(dataReadProgress())); 697 connect( reply, SIGNAL(uploadProgress(qint64,qint64)), this, SIGNAL(dataSendProgress())); 684 Session :: exec (const char * json) 685 { 686 if (mySession ) 687 { 688 tr_rpc_request_exec_json (mySession, json, strlen (json), localSessionCallback, this); 689 } 690 else if (!myUrl.isEmpty ()) 691 { 692 QNetworkRequest request; 693 request.setUrl (myUrl); 694 request.setRawHeader ("User-Agent", QString (QCoreApplication::instance ()->applicationName () + "/" + LONG_VERSION_STRING).toAscii ()); 695 request.setRawHeader ("Content-Type", "application/json; charset=UTF-8"); 696 697 if (!mySessionId.isEmpty ()) 698 request.setRawHeader (TR_RPC_SESSION_ID_HEADER, mySessionId.toAscii ()); 699 700 const QByteArray requestData (json); 701 QNetworkReply * reply = networkAccessManager ()->post (request, requestData); 702 reply->setProperty (REQUEST_DATA_PROPERTY_KEY, requestData); 703 connect (reply, SIGNAL (downloadProgress (qint64,qint64)), this, SIGNAL (dataReadProgress ())); 704 connect (reply, SIGNAL (uploadProgress (qint64,qint64)), this, SIGNAL (dataSendProgress ())); 698 705 699 706 #ifdef DEBUG_HTTP 700 std::cerr << "sending " << "POST " << qPrintable( myUrl.path()) << std::endl;701 foreach( QByteArray b, request.rawHeaderList())702 std::cerr << b.constData()703 704 << request.rawHeader( b ).constData()705 706 707 std::cerr << "sending " << "POST " << qPrintable (myUrl.path ()) << std::endl; 708 foreach (QByteArray b, request.rawHeaderList ()) 709 std::cerr << b.constData () 710 << ": " 711 << request.rawHeader (b).constData () 712 << std::endl; 713 std::cerr << "Body:\n" << json << std::endl; 707 714 #endif 708 715 } … … 710 717 711 718 void 712 Session :: onFinished ( QNetworkReply * reply)719 Session :: onFinished (QNetworkReply * reply) 713 720 { 714 721 #ifdef DEBUG_HTTP 715 722 std::cerr << "http response header: " << std::endl; 716 foreach ( QByteArray b, reply->rawHeaderList())717 std::cerr << b.constData ()723 foreach (QByteArray b, reply->rawHeaderList ()) 724 std::cerr << b.constData () 718 725 << ": " 719 << reply->rawHeader ( b ).constData()726 << reply->rawHeader (b).constData () 720 727 << std::endl; 721 std::cerr << "json:\n" << reply->peek ( reply->bytesAvailable() ).constData() << std::endl;728 std::cerr << "json:\n" << reply->peek (reply->bytesAvailable ()).constData () << std::endl; 722 729 #endif 723 730 724 if ( ( reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt() == 409)725 && ( reply->hasRawHeader( TR_RPC_SESSION_ID_HEADER ) ))731 if ( (reply->attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt () == 409) 732 && (reply->hasRawHeader (TR_RPC_SESSION_ID_HEADER))) 726 733 { 727 734 // we got a 409 telling us our session id has expired. 728 735 // update it and resubmit the request. 729 mySessionId = QString ( reply->rawHeader( TR_RPC_SESSION_ID_HEADER ));730 exec ( reply->property( REQUEST_DATA_PROPERTY_KEY ).toByteArray( ).constData( ));731 } 732 else if ( reply->error() != QNetworkReply::NoError)733 { 734 std::cerr << "http error: " << qPrintable ( reply->errorString()) << std::endl;736 mySessionId = QString (reply->rawHeader (TR_RPC_SESSION_ID_HEADER)); 737 exec (reply->property (REQUEST_DATA_PROPERTY_KEY).toByteArray ().constData ()); 738 } 739 else if (reply->error () != QNetworkReply::NoError) 740 { 741 std::cerr << "http error: " << qPrintable (reply->errorString ()) << std::endl; 735 742 } 736 743 else 737 744 { 738 const QByteArray response ( reply->readAll());739 const char * json ( response.constData( ));740 int jsonLength ( response.size( ));741 if ( jsonLength>0 && json[jsonLength-1] == '\n') --jsonLength;742 parseResponse ( json, jsonLength);743 } 744 745 reply->deleteLater ();745 const QByteArray response (reply->readAll ()); 746 const char * json (response.constData ()); 747 int jsonLength (response.size ()); 748 if (jsonLength>0 && json[jsonLength-1] == '\n') --jsonLength; 749 parseResponse (json, jsonLength); 750 } 751 752 reply->deleteLater (); 746 753 } 747 754 … … 749 756 Session :: onResponseReceived (const QByteArray& utf8) 750 757 { 751 parseResponse (utf8.constData (), utf8.length());752 } 753 754 void 755 Session :: parseResponse ( const char * json, size_t jsonLength)758 parseResponse (utf8.constData (), utf8.length ()); 759 } 760 761 void 762 Session :: parseResponse (const char * json, size_t jsonLength) 756 763 { 757 764 tr_variant top; 758 765 const int err (tr_variantFromJson (&top, json, jsonLength)); 759 if ( !err)766 if (!err) 760 767 { 761 768 int64_t tag = -1; … … 763 770 tr_variant * args = NULL; 764 771 765 tr_variantDictFindInt ( &top, TR_KEY_tag, &tag);766 tr_variantDictFindStr ( &top, TR_KEY_result, &result, NULL);767 tr_variantDictFindDict ( &top, TR_KEY_arguments, &args);768 769 emit executed ( tag, result, args);772 tr_variantDictFindInt (&top, TR_KEY_tag, &tag); 773 tr_variantDictFindStr (&top, TR_KEY_result, &result, NULL); 774 tr_variantDictFindDict (&top, TR_KEY_arguments, &args); 775 776 emit executed (tag, result, args); 770 777 771 778 tr_variant * torrents; 772 779 const char * str; 773 780 774 if ( tr_variantDictFindInt( &top, TR_KEY_tag, &tag ))781 if (tr_variantDictFindInt (&top, TR_KEY_tag, &tag)) 775 782 { 776 switch ( tag)783 switch (tag) 777 784 { 778 785 case TAG_SOME_TORRENTS: 779 786 case TAG_ALL_TORRENTS: 780 if ( tr_variantDictFindDict( &top, TR_KEY_arguments, &args )) {781 if ( tr_variantDictFindList( args, TR_KEY_torrents, &torrents ))782 emit torrentsUpdated ( torrents, tag==TAG_ALL_TORRENTS);783 if ( tr_variantDictFindList( args, TR_KEY_removed, &torrents ))784 emit torrentsRemoved ( torrents);787 if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) { 788 if (tr_variantDictFindList (args, TR_KEY_torrents, &torrents)) 789 emit torrentsUpdated (torrents, tag==TAG_ALL_TORRENTS); 790 if (tr_variantDictFindList (args, TR_KEY_removed, &torrents)) 791 emit torrentsRemoved (torrents); 785 792 } 786 793 break; 787 794 788 795 case TAG_SESSION_STATS: 789 if ( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ))790 updateStats ( args);796 if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) 797 updateStats (args); 791 798 break; 792 799 793 800 case TAG_SESSION_INFO: 794 if ( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ))795 updateInfo ( args);801 if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) 802 updateInfo (args); 796 803 break; 797 804 798 805 case TAG_BLOCKLIST_UPDATE: { 799 806 int64_t intVal = 0; 800 if ( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ))801 if ( tr_variantDictFindInt( args, TR_KEY_blocklist_size, &intVal ))802 setBlocklistSize ( intVal);807 if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) 808 if (tr_variantDictFindInt (args, TR_KEY_blocklist_size, &intVal)) 809 setBlocklistSize (intVal); 803 810 break; 804 811 } … … 808 815 int64_t id = 0; 809 816 const char * result = 0; 810 if ( tr_variantDictFindStr (&top, TR_KEY_result, &result, 0) && strcmp (result, "success"))817 if (tr_variantDictFindStr (&top, TR_KEY_result, &result, 0) && strcmp (result, "success")) 811 818 { 812 819 const char * path = ""; … … 814 821 tr_variantDictFindStr (args, TR_KEY_path, &path, 0); 815 822 tr_variantDictFindStr (args, TR_KEY_name, &name, 0); 816 const QString title = tr ("Error Renaming Path");817 const QString text = tr ("<p><b>Unable to rename \"%1\" as \"%2\": %3.</b></p> <p>Please correct the errors and try again.</p>").arg(path).arg(name).arg(result);818 QMessageBox * d = new QMessageBox (QMessageBox::Information, title, text,823 const QString title = tr ("Error Renaming Path"); 824 const QString text = tr ("<p><b>Unable to rename \"%1\" as \"%2\": %3.</b></p> <p>Please correct the errors and try again.</p>").arg (path).arg (name).arg (result); 825 QMessageBox * d = new QMessageBox (QMessageBox::Information, title, text, 819 826 QMessageBox::Close, 820 QApplication::activeWindow ());821 connect ( d, SIGNAL(rejected()), d, SLOT(deleteLater()));822 d->show ();827 QApplication::activeWindow ()); 828 connect (d, SIGNAL (rejected ()), d, SLOT (deleteLater ())); 829 d->show (); 823 830 } 824 831 else if (tr_variantDictFindInt (args, TR_KEY_id, &id) && id) … … 826 833 // let's get the updated file list 827 834 char * req = tr_strdup_printf ("{ \"arguments\": { \"fields\": [ \"fileStats\", \"files\", \"id\", \"name\" ], \"ids\": %d }, \"method\": \"torrent-get\", \"tag\": %d }", 828 int (id),829 int (TAG_SOME_TORRENTS));835 int (id), 836 int (TAG_SOME_TORRENTS)); 830 837 exec (req); 831 838 tr_free (req); … … 837 844 case TAG_PORT_TEST: { 838 845 bool isOpen = 0; 839 if ( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ))840 tr_variantDictFindBool ( args, TR_KEY_port_is_open, &isOpen);841 emit portTested ( (bool)isOpen);846 if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) 847 tr_variantDictFindBool (args, TR_KEY_port_is_open, &isOpen); 848 emit portTested ( (bool)isOpen); 842 849 break; 843 850 } … … 848 855 tr_variant * child; 849 856 const char * str; 850 if ( tr_variantDictFindDict( &top, TR_KEY_arguments, &args)851 && tr_variantDictFindList ( args, TR_KEY_torrents, &torrents)852 && ( ( child = tr_variantListChild( torrents, 0)))853 && tr_variantDictFindStr ( child, TR_KEY_magnetLink, &str, NULL ))854 QApplication::clipboard ()->setText( str);857 if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args) 858 && tr_variantDictFindList (args, TR_KEY_torrents, &torrents) 859 && ( (child = tr_variantListChild (torrents, 0))) 860 && tr_variantDictFindStr (child, TR_KEY_magnetLink, &str, NULL)) 861 QApplication::clipboard ()->setText (str); 855 862 break; 856 863 } … … 858 865 case TAG_ADD_TORRENT: 859 866 str = ""; 860 if ( tr_variantDictFindStr( &top, TR_KEY_result, &str, NULL ) && strcmp( str, "success" )) {861 QMessageBox * d = new QMessageBox (QMessageBox::Information,862 tr ( "Add Torrent"),863 QString::fromUtf8 (str),867 if (tr_variantDictFindStr (&top, TR_KEY_result, &str, NULL) && strcmp (str, "success")) { 868 QMessageBox * d = new QMessageBox (QMessageBox::Information, 869 tr ("Add Torrent"), 870 QString::fromUtf8 (str), 864 871 QMessageBox::Close, 865 QApplication::activeWindow ());866 connect ( d, SIGNAL(rejected()), d, SLOT(deleteLater()));867 d->show ();872 QApplication::activeWindow ()); 873 connect (d, SIGNAL (rejected ()), d, SLOT (deleteLater ())); 874 d->show (); 868 875 } 869 876 break; … … 873 880 } 874 881 } 875 tr_variantFree( &top ); 876 } 877 } 878 879 void 880 Session :: updateStats( tr_variant * d, struct tr_session_stats * stats ) 881 { 882 int64_t i; 883 884 if( tr_variantDictFindInt( d, TR_KEY_uploadedBytes, &i ) ) 885 stats->uploadedBytes = i; 886 if( tr_variantDictFindInt( d, TR_KEY_downloadedBytes, &i ) ) 887 stats->downloadedBytes = i; 888 if( tr_variantDictFindInt( d, TR_KEY_filesAdded, &i ) ) 889 stats->filesAdded = i; 890 if( tr_variantDictFindInt( d, TR_KEY_sessionCount, &i ) ) 891 stats->sessionCount = i; 892 if( tr_variantDictFindInt( d, TR_KEY_secondsActive, &i ) ) 893 stats->secondsActive = i; 894 895 stats->ratio = tr_getRatio( stats->uploadedBytes, stats->downloadedBytes ); 896 897 } 898 899 void 900 Session :: updateStats( tr_variant * d ) 901 { 902 tr_variant * c; 903 904 if( tr_variantDictFindDict( d, TR_KEY_current_stats, &c ) ) 905 updateStats( c, &myStats ); 906 907 if( tr_variantDictFindDict( d, TR_KEY_cumulative_stats, &c ) ) 908 updateStats( c, &myCumulativeStats ); 909 910 emit statsUpdated( ); 882 tr_variantFree (&top); 883 } 884 } 885 886 void 887 Session :: updateStats (tr_variant * d, struct tr_session_stats * stats) 888 { 889 int64_t i; 890 891 if (tr_variantDictFindInt (d, TR_KEY_uploadedBytes, &i)) 892 stats->uploadedBytes = i; 893 if (tr_variantDictFindInt (d, TR_KEY_downloadedBytes, &i)) 894 stats->downloadedBytes = i; 895 if (tr_variantDictFindInt (d, TR_KEY_filesAdded, &i)) 896 stats->filesAdded = i; 897 if (tr_variantDictFindInt (d, TR_KEY_sessionCount, &i)) 898 stats->sessionCount = i; 899 if (tr_variantDictFindInt (d, TR_KEY_secondsActive, &i)) 900 stats->secondsActive = i; 901 902 stats->ratio = tr_getRatio (stats->uploadedBytes, stats->downloadedBytes); 903 } 904 905 void 906 Session :: updateStats (tr_variant * d) 907 { 908 tr_variant * c; 909 910 if (tr_variantDictFindDict (d, TR_KEY_current_stats, &c)) 911 updateStats (c, &myStats); 912 913 if (tr_variantDictFindDict (d, TR_KEY_cumulative_stats, &c)) 914 updateStats (c, &myCumulativeStats); 915 916 emit statsUpdated (); 911 917 } 912 918 … … 917 923 const char * str; 918 924 919 disconnect (&myPrefs, SIGNAL (changed(int)), this, SLOT(updatePref(int)));925 disconnect (&myPrefs, SIGNAL (changed (int)), this, SLOT (updatePref (int))); 920 926 921 927 for (int i=Prefs::FIRST_CORE_PREF; i<=Prefs::LAST_CORE_PREF; ++i) 922 928 { 923 const tr_variant * b ( tr_variantDictFind (d, myPrefs.getKey(i)));929 const tr_variant * b (tr_variantDictFind (d, myPrefs.getKey (i))); 924 930 925 931 if (!b) … … 929 935 { 930 936 const char * val; 931 if ( tr_variantGetStr( b, &val, NULL ))937 if (tr_variantGetStr (b, &val, NULL)) 932 938 { 933 if ( !qstrcmp( val , "required" ))934 myPrefs.set ( i, 2);935 else if ( !qstrcmp( val , "preferred" ))936 myPrefs.set ( i, 1);937 else if ( !qstrcmp( val , "tolerated" ))938 myPrefs.set ( i, 0);939 if (!qstrcmp (val , "required")) 940 myPrefs.set (i, 2); 941 else if (!qstrcmp (val , "preferred")) 942 myPrefs.set (i, 1); 943 else if (!qstrcmp (val , "tolerated")) 944 myPrefs.set (i, 0); 939 945 } 940 946 continue; 941 947 } 942 948 943 switch( myPrefs.type( i ))949 switch (myPrefs.type (i)) 944 950 { 945 case QVariant :: Int: { 946 int64_t val; 947 if( tr_variantGetInt( b, &val ) ) 948 myPrefs.set( i, (int)val ); 949 break; 951 case QVariant :: Int: 952 { 953 int64_t val; 954 if (tr_variantGetInt (b, &val)) 955 myPrefs.set (i, (int)val); 956 break; 950 957 } 951 case QVariant :: Double: { 952 double val; 953 if( tr_variantGetReal( b, &val ) ) 954 myPrefs.set( i, val ); 955 break; 958 case QVariant :: Double: 959 { 960 double val; 961 if (tr_variantGetReal (b, &val)) 962 myPrefs.set (i, val); 963 break; 956 964 } 957 case QVariant :: Bool: { 958 bool val; 959 if( tr_variantGetBool( b, &val ) ) 960 myPrefs.set( i, (bool)val ); 961 break; 965 case QVariant :: Bool: 966 { 967 bool val; 968 if (tr_variantGetBool (b, &val)) 969 myPrefs.set (i, (bool)val); 970 break; 962 971 } 963 case TrTypes :: FilterModeType: 964 case TrTypes :: SortModeType: 965 case QVariant :: String: { 966 const char * val; 967 if( tr_variantGetStr( b, &val, NULL ) ) 968 myPrefs.set( i, QString(val) ); 969 break; 972 case TrTypes :: FilterModeType: 973 case TrTypes :: SortModeType: 974 case QVariant :: String: 975 { 976 const char * val; 977 if (tr_variantGetStr (b, &val, NULL)) 978 myPrefs.set (i, QString (val)); 979 break; 970 980 } 971 972 981 default: 982 break; 973 983 } 974 984 } 975 985 976 bool b; 977 double x; 978 if( tr_variantDictFindBool( d, TR_KEY_seedRatioLimited, &b ) ) 979 myPrefs.set( Prefs::RATIO_ENABLED, b ? true : false ); 980 if( tr_variantDictFindReal( d, TR_KEY_seedRatioLimit, &x ) ) 981 myPrefs.set( Prefs::RATIO, x ); 982 983 /* Use the C API to get settings that, for security reasons, aren't supported by RPC */ 984 if( mySession != 0 ) 985 { 986 myPrefs.set( Prefs::RPC_ENABLED, tr_sessionIsRPCEnabled ( mySession ) ); 987 myPrefs.set( Prefs::RPC_AUTH_REQUIRED, tr_sessionIsRPCPasswordEnabled ( mySession ) ); 988 myPrefs.set( Prefs::RPC_PASSWORD, tr_sessionGetRPCPassword ( mySession ) ); 989 myPrefs.set( Prefs::RPC_PORT, tr_sessionGetRPCPort ( mySession ) ); 990 myPrefs.set( Prefs::RPC_USERNAME, tr_sessionGetRPCUsername ( mySession ) ); 991 myPrefs.set( Prefs::RPC_WHITELIST_ENABLED, tr_sessionGetRPCWhitelistEnabled ( mySession ) ); 992 myPrefs.set( Prefs::RPC_WHITELIST, tr_sessionGetRPCWhitelist ( mySession ) ); 993 } 994 995 if( tr_variantDictFindInt( d, TR_KEY_blocklist_size, &i ) && i!=blocklistSize( ) ) 996 setBlocklistSize( i ); 997 998 if( tr_variantDictFindStr( d, TR_KEY_version, &str, NULL ) && ( mySessionVersion != str ) ) 999 mySessionVersion = str; 1000 1001 if( tr_variantDictFindInt( d, TR_KEY_download_dir_free_space, &i ) && ( myDownloadDirFreeSpace != i ) ) 1002 myDownloadDirFreeSpace = i; 1003 1004 //std::cerr << "Session :: updateInfo end" << std::endl; 1005 connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(updatePref(int)) ); 1006 1007 emit sessionUpdated( ); 1008 } 1009 1010 void 1011 Session :: setBlocklistSize( int64_t i ) 1012 { 1013 myBlocklistSize = i; 1014 1015 emit blocklistUpdated( i ); 1016 } 1017 1018 void 1019 Session :: addTorrent( const AddData& addMe ) 1020 { 1021 const QByteArray b64 = addMe.toBase64(); 1022 1023 tr_variant top, *args; 1024 tr_variantInitDict( &top, 2 ); 1025 tr_variantDictAddStr( &top, TR_KEY_method, "torrent-add" ); 1026 args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ); 1027 tr_variantDictAddBool( args, TR_KEY_paused, !myPrefs.getBool( Prefs::START ) ); 1028 switch( addMe.type ) { 1029 case AddData::MAGNET: tr_variantDictAddStr( args, TR_KEY_filename, addMe.magnet.toUtf8().constData() ); break; 1030 case AddData::URL: tr_variantDictAddStr( args, TR_KEY_filename, addMe.url.toString().toUtf8().constData() ); break; 1031 case AddData::FILENAME: /* fall-through */ 1032 case AddData::METAINFO: tr_variantDictAddRaw( args, TR_KEY_metainfo, b64.constData(), b64.size() ); break; 1033 default: std::cerr << "Unhandled AddData type: " << addMe.type << std::endl; 1034 } 1035 exec( &top ); 1036 tr_variantFree( &top ); 1037 } 1038 1039 void 1040 Session :: addNewlyCreatedTorrent( const QString& filename, const QString& localPath ) 1041 { 1042 const QByteArray b64 = AddData(filename).toBase64(); 1043 const QByteArray localPathUtf8 = localPath.toUtf8(); 1044 1045 tr_variant top, *args; 1046 tr_variantInitDict( &top, 2 ); 1047 tr_variantDictAddStr( &top, TR_KEY_method, "torrent-add" ); 1048 args = tr_variantDictAddDict( &top, TR_KEY_arguments, 3 ); 1049 tr_variantDictAddStr( args, TR_KEY_download_dir, localPathUtf8.constData() ); 1050 tr_variantDictAddBool( args, TR_KEY_paused, !myPrefs.getBool( Prefs::START ) ); 1051 tr_variantDictAddRaw( args, TR_KEY_metainfo, b64.constData(), b64.size() ); 1052 exec( &top ); 1053 tr_variantFree( &top ); 1054 } 1055 1056 void 1057 Session :: removeTorrents( const QSet<int>& ids, bool deleteFiles ) 1058 { 1059 if( !ids.isEmpty( ) ) 1060 { 1061 tr_variant top, *args; 1062 tr_variantInitDict( &top, 2 ); 1063 tr_variantDictAddStr( &top, TR_KEY_method, "torrent-remove" ); 1064 args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ); 1065 addOptionalIds( args, ids ); 1066 tr_variantDictAddInt( args, TR_KEY_delete_local_data, deleteFiles ); 1067 exec( &top ); 1068 tr_variantFree( &top ); 1069 } 1070 } 1071 1072 void 1073 Session :: verifyTorrents( const QSet<int>& ids ) 1074 { 1075 if( !ids.isEmpty( ) ) 1076 { 1077 tr_variant top, *args; 1078 tr_variantInitDict( &top, 2 ); 1079 tr_variantDictAddStr( &top, TR_KEY_method, "torrent-verify" ); 1080 args = tr_variantDictAddDict( &top, TR_KEY_arguments, 1 ); 1081 addOptionalIds( args, ids ); 1082 exec( &top ); 1083 tr_variantFree( &top ); 1084 } 1085 } 1086 1087 void 1088 Session :: reannounceTorrents( const QSet<int>& ids ) 1089 { 1090 if( !ids.isEmpty( ) ) 1091 { 1092 tr_variant top, *args; 1093 tr_variantInitDict( &top, 2 ); 1094 tr_variantDictAddStr( &top, TR_KEY_method, "torrent-reannounce" ); 1095 args = tr_variantDictAddDict( &top, TR_KEY_arguments, 1 ); 1096 addOptionalIds( args, ids ); 1097 exec( &top ); 1098 tr_variantFree( &top ); 986 bool b; 987 double x; 988 if (tr_variantDictFindBool (d, TR_KEY_seedRatioLimited, &b)) 989 myPrefs.set (Prefs::RATIO_ENABLED, b ? true : false); 990 if (tr_variantDictFindReal (d, TR_KEY_seedRatioLimit, &x)) 991 myPrefs.set (Prefs::RATIO, x); 992 993 /* Use the C API to get settings that, for security reasons, aren't supported by RPC */ 994 if (mySession != 0) 995 { 996 myPrefs.set (Prefs::RPC_ENABLED, tr_sessionIsRPCEnabled (mySession)); 997 myPrefs.set (Prefs::RPC_AUTH_REQUIRED, tr_sessionIsRPCPasswordEnabled (mySession)); 998 myPrefs.set (Prefs::RPC_PASSWORD, tr_sessionGetRPCPassword (mySession)); 999 myPrefs.set (Prefs::RPC_PORT, tr_sessionGetRPCPort (mySession)); 1000 myPrefs.set (Prefs::RPC_USERNAME, tr_sessionGetRPCUsername (mySession)); 1001 myPrefs.set (Prefs::RPC_WHITELIST_ENABLED, tr_sessionGetRPCWhitelistEnabled (mySession)); 1002 myPrefs.set (Prefs::RPC_WHITELIST, tr_sessionGetRPCWhitelist (mySession)); 1003 } 1004 1005 if (tr_variantDictFindInt (d, TR_KEY_blocklist_size, &i) && i!=blocklistSize ()) 1006 setBlocklistSize (i); 1007 1008 if (tr_variantDictFindStr (d, TR_KEY_version, &str, NULL) && (mySessionVersion != str)) 1009 mySessionVersion = str; 1010 1011 if (tr_variantDictFindInt (d, TR_KEY_download_dir_free_space, &i) && (myDownloadDirFreeSpace != i)) 1012 myDownloadDirFreeSpace = i; 1013 1014 //std::cerr << "Session :: updateInfo end" << std::endl; 1015 connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (updatePref (int))); 1016 1017 emit sessionUpdated (); 1018 } 1019 1020 void 1021 Session :: setBlocklistSize (int64_t i) 1022 { 1023 myBlocklistSize = i; 1024 1025 emit blocklistUpdated (i); 1026 } 1027 1028 void 1029 Session :: addTorrent (const AddData& addMe) 1030 { 1031 const QByteArray b64 = addMe.toBase64 (); 1032 1033 tr_variant top, *args; 1034 tr_variantInitDict (&top, 2); 1035 tr_variantDictAddStr (&top, TR_KEY_method, "torrent-add"); 1036 args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); 1037 tr_variantDictAddBool (args, TR_KEY_paused, !myPrefs.getBool (Prefs::START)); 1038 1039 switch (addMe.type) 1040 { 1041 case AddData::MAGNET: 1042 tr_variantDictAddStr (args, TR_KEY_filename, addMe.magnet.toUtf8 ().constData ()); 1043 break; 1044 1045 case AddData::URL: 1046 tr_variantDictAddStr (args, TR_KEY_filename, addMe.url.toString ().toUtf8 ().constData ()); 1047 break; 1048 1049 case AddData::FILENAME: /* fall-through */ 1050 case AddData::METAINFO: 1051 tr_variantDictAddRaw (args, TR_KEY_metainfo, b64.constData (), b64.size ()); 1052 break; 1053 1054 default: 1055 std::cerr << "Unhandled AddData type: " << addMe.type << std::endl; 1056 break; 1057 } 1058 1059 exec (&top); 1060 tr_variantFree (&top); 1061 } 1062 1063 void 1064 Session :: addNewlyCreatedTorrent (const QString& filename, const QString& localPath) 1065 { 1066 const QByteArray b64 = AddData (filename).toBase64 (); 1067 const QByteArray localPathUtf8 = localPath.toUtf8 (); 1068 1069 tr_variant top, *args; 1070 tr_variantInitDict (&top, 2); 1071 tr_variantDictAddStr (&top, TR_KEY_method, "torrent-add"); 1072 args = tr_variantDictAddDict (&top, TR_KEY_arguments, 3); 1073 tr_variantDictAddStr (args, TR_KEY_download_dir, localPathUtf8.constData ()); 1074 tr_variantDictAddBool (args, TR_KEY_paused, !myPrefs.getBool (Prefs::START)); 1075 tr_variantDictAddRaw (args, TR_KEY_metainfo, b64.constData (), b64.size ()); 1076 exec (&top); 1077 tr_variantFree (&top); 1078 } 1079 1080 void 1081 Session :: removeTorrents (const QSet<int>& ids, bool deleteFiles) 1082 { 1083 if (!ids.isEmpty ()) 1084 { 1085 tr_variant top, *args; 1086 tr_variantInitDict (&top, 2); 1087 tr_variantDictAddStr (&top, TR_KEY_method, "torrent-remove"); 1088 args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); 1089 addOptionalIds (args, ids); 1090 tr_variantDictAddInt (args, TR_KEY_delete_local_data, deleteFiles); 1091 exec (&top); 1092 tr_variantFree (&top); 1093 } 1094 } 1095 1096 void 1097 Session :: verifyTorrents (const QSet<int>& ids) 1098 { 1099 if (!ids.isEmpty ()) 1100 { 1101 tr_variant top, *args; 1102 tr_variantInitDict (&top, 2); 1103 tr_variantDictAddStr (&top, TR_KEY_method, "torrent-verify"); 1104 args = tr_variantDictAddDict (&top, TR_KEY_arguments, 1); 1105 addOptionalIds (args, ids); 1106 exec (&top); 1107 tr_variantFree (&top); 1108 } 1109 } 1110 1111 void 1112 Session :: reannounceTorrents (const QSet<int>& ids) 1113 { 1114 if (!ids.isEmpty ()) 1115 { 1116 tr_variant top, *args; 1117 tr_variantInitDict (&top, 2); 1118 tr_variantDictAddStr (&top, TR_KEY_method, "torrent-reannounce"); 1119 args = tr_variantDictAddDict (&top, TR_KEY_arguments, 1); 1120 addOptionalIds (args, ids); 1121 exec (&top); 1122 tr_variantFree (&top); 1099 1123 } 1100 1124 } … … 1105 1129 1106 1130 void 1107 Session :: launchWebInterface( ) 1108 { 1109 QUrl url; 1110 if( !mySession ) // remote session 1111 { 1112 url = myUrl; 1113 url.setPath( "/transmission/web/" ); 1114 } 1115 else // local session 1116 { 1117 url.setScheme( "http" ); 1118 url.setHost( "localhost" ); 1119 url.setPort( myPrefs.getInt( Prefs::RPC_PORT ) ); 1120 } 1121 QDesktopServices :: openUrl( url ); 1122 } 1131 Session :: launchWebInterface () 1132 { 1133 QUrl url; 1134 1135 if (!mySession) // remote session 1136 { 1137 url = myUrl; 1138 url.setPath ("/transmission/web/"); 1139 } 1140 else // local session 1141 { 1142 url.setScheme ("http"); 1143 url.setHost ("localhost"); 1144 url.setPort (myPrefs.getInt (Prefs::RPC_PORT)); 1145 } 1146 1147 QDesktopServices :: openUrl (url); 1148 } -
trunk/qt/session.h
r13883 r13944 32 32 extern "C" 33 33 { 34 35 34 struct evbuffer; 35 struct tr_variant; 36 36 } 37 37 … … 40 40 class Session: public QObject 41 41 { 42 42 Q_OBJECT 43 43 44 45 Session( const char * configDir, Prefs& prefs);46 ~Session();44 public: 45 Session (const char * configDir, Prefs& prefs); 46 ~Session (); 47 47 48 49 void stop();50 void restart();48 public: 49 void stop (); 50 void restart (); 51 51 52 53 void start();52 private: 53 void start (); 54 54 55 56 const QUrl& getRemoteUrl() const { return myUrl; }57 const struct tr_session_stats& getStats() const { return myStats; }58 const struct tr_session_stats& getCumulativeStats() const { return myCumulativeStats; }59 const QString& sessionVersion() const { return mySessionVersion; }60 int64_t downloadDirFreeSpace() const { return myDownloadDirFreeSpace; }55 public: 56 const QUrl& getRemoteUrl () const { return myUrl; } 57 const struct tr_session_stats& getStats () const { return myStats; } 58 const struct tr_session_stats& getCumulativeStats () const { return myCumulativeStats; } 59 const QString& sessionVersion () const { return mySessionVersion; } 60 int64_t downloadDirFreeSpace () const { return myDownloadDirFreeSpace; } 61 61 62 63 int64_t blocklistSize() const { return myBlocklistSize; }64 void setBlocklistSize( int64_t i);65 void updateBlocklist();66 void portTest();67 void copyMagnetLinkToClipboard( int torrentId);62 public: 63 int64_t blocklistSize () const { return myBlocklistSize; } 64 void setBlocklistSize (int64_t i); 65 void updateBlocklist (); 66 void portTest (); 67 void copyMagnetLinkToClipboard (int torrentId); 68 68 69 69 public: 70 70 71 72 bool isServer() const;71 /** returns true if the transmission session is being run inside this client */ 72 bool isServer () const; 73 73 74 /** returns true if isServer() is true or if the remote address is the localhost */75 bool isLocal() const;74 /** returns true if isServer () is true or if the remote address is the localhost */ 75 bool isLocal () const; 76 76 77 78 void updateStats( struct tr_variant * args);79 void updateInfo( struct tr_variant * args);80 void parseResponse( const char * json, size_t len);81 static void localSessionCallback( tr_session *, struct evbuffer *, void *);77 private: 78 void updateStats (struct tr_variant * args); 79 void updateInfo (struct tr_variant * args); 80 void parseResponse (const char * json, size_t len); 81 static void localSessionCallback (tr_session *, struct evbuffer *, void *); 82 82 83 84 void exec( const char * json);85 void exec( const struct tr_variant * request);83 public: 84 void exec (const char * json); 85 void exec (const struct tr_variant * request); 86 86 87 88 int64_t getUniqueTag() { return nextUniqueTag++; }87 public: 88 int64_t getUniqueTag () { return nextUniqueTag++; } 89 89 90 91 void sessionSet( const tr_quark key, const QVariant& variant);92 void pumpRequests();93 void sendTorrentRequest( const char * request, const QSet<int>& torrentIds);94 static void updateStats( struct tr_variant * d, struct tr_session_stats * stats);95 void refreshTorrents( const QSet<int>& torrentIds);96 QNetworkAccessManager * networkAccessManager();90 private: 91 void sessionSet (const tr_quark key, const QVariant& variant); 92 void pumpRequests (); 93 void sendTorrentRequest (const char * request, const QSet<int>& torrentIds); 94 static void updateStats (struct tr_variant * d, struct tr_session_stats * stats); 95 void refreshTorrents (const QSet<int>& torrentIds); 96 QNetworkAccessManager * networkAccessManager (); 97 97 98 99 void torrentSet( const QSet<int>& ids, const tr_quark key, bool val);100 void torrentSet( const QSet<int>& ids, const tr_quark key, int val);101 void torrentSet( const QSet<int>& ids, const tr_quark key, double val);102 void torrentSet( const QSet<int>& ids, const tr_quark key, const QList<int>& val);103 void torrentSet( const QSet<int>& ids, const tr_quark key, const QStringList& val);104 void torrentSet(const QSet<int>& ids, const tr_quark key, const QPair<int,QString>& val);105 void torrentSetLocation( const QSet<int>& ids, const QString& path, bool doMove);106 void torrentRenamePath( const QSet<int>& ids, const QString& oldpath, const QString& newname);98 public: 99 void torrentSet (const QSet<int>& ids, const tr_quark key, bool val); 100 void torrentSet (const QSet<int>& ids, const tr_quark key, int val); 101 void torrentSet (const QSet<int>& ids, const tr_quark key, double val); 102 void torrentSet (const QSet<int>& ids, const tr_quark key, const QList<int>& val); 103 void torrentSet (const QSet<int>& ids, const tr_quark key, const QStringList& val); 104 void torrentSet (const QSet<int>& ids, const tr_quark key, const QPair<int,QString>& val); 105 void torrentSetLocation (const QSet<int>& ids, const QString& path, bool doMove); 106 void torrentRenamePath (const QSet<int>& ids, const QString& oldpath, const QString& newname); 107 107 108 109 void pauseTorrents( const QSet<int>& torrentIds = QSet<int>());110 void startTorrents( const QSet<int>& torrentIds = QSet<int>());111 void startTorrentsNow( const QSet<int>& torrentIds = QSet<int>());112 void queueMoveTop( const QSet<int>& torrentIds = QSet<int>());113 void queueMoveUp( const QSet<int>& torrentIds = QSet<int>());114 void queueMoveDown( const QSet<int>& torrentIds = QSet<int>());115 void queueMoveBottom( const QSet<int>& torrentIds = QSet<int>());116 void refreshSessionInfo();117 void refreshSessionStats();118 void refreshActiveTorrents();119 void refreshAllTorrents();120 void initTorrents( const QSet<int>& ids = QSet<int>());121 void addNewlyCreatedTorrent( const QString& filename, const QString& localPath);122 void addTorrent( const AddData& addme);123 void removeTorrents( const QSet<int>& torrentIds, bool deleteFiles=false);124 void verifyTorrents( const QSet<int>& torrentIds);125 void reannounceTorrents( const QSet<int>& torrentIds);126 void launchWebInterface();127 void updatePref( int key);108 public slots: 109 void pauseTorrents (const QSet<int>& torrentIds = QSet<int> ()); 110 void startTorrents (const QSet<int>& torrentIds = QSet<int> ()); 111 void startTorrentsNow (const QSet<int>& torrentIds = QSet<int> ()); 112 void queueMoveTop (const QSet<int>& torrentIds = QSet<int> ()); 113 void queueMoveUp (const QSet<int>& torrentIds = QSet<int> ()); 114 void queueMoveDown (const QSet<int>& torrentIds = QSet<int> ()); 115 void queueMoveBottom (const QSet<int>& torrentIds = QSet<int> ()); 116 void refreshSessionInfo (); 117 void refreshSessionStats (); 118 void refreshActiveTorrents (); 119 void refreshAllTorrents (); 120 void initTorrents (const QSet<int>& ids = QSet<int> ()); 121 void addNewlyCreatedTorrent (const QString& filename, const QString& localPath); 122 void addTorrent (const AddData& addme); 123 void removeTorrents (const QSet<int>& torrentIds, bool deleteFiles=false); 124 void verifyTorrents (const QSet<int>& torrentIds); 125 void reannounceTorrents (const QSet<int>& torrentIds); 126 void launchWebInterface (); 127 void updatePref (int key); 128 128 129 130 void refreshExtraStats( const QSet<int>& ids);129 /** request a refresh for statistics, including the ones only used by the properties dialog, for a specific torrent */ 130 void refreshExtraStats (const QSet<int>& ids); 131 131 132 133 void onFinished( QNetworkReply * reply);134 132 private slots: 133 void onFinished (QNetworkReply * reply); 134 void onResponseReceived (const QByteArray& json); 135 135 136 137 138 void executed( int64_t tag, const QString& result, struct tr_variant * arguments);139 void sourceChanged();140 void portTested( bool isOpen);141 void statsUpdated();142 void sessionUpdated();143 void blocklistUpdated( int);144 void torrentsUpdated( struct tr_variant * torrentList, bool completeList);145 void torrentsRemoved( struct tr_variant * torrentList);146 void dataReadProgress();147 void dataSendProgress();148 void httpAuthenticationRequired();136 signals: 137 void responseReceived (const QByteArray& json); 138 void executed (int64_t tag, const QString& result, struct tr_variant * arguments); 139 void sourceChanged (); 140 void portTested (bool isOpen); 141 void statsUpdated (); 142 void sessionUpdated (); 143 void blocklistUpdated (int); 144 void torrentsUpdated (struct tr_variant * torrentList, bool completeList); 145 void torrentsRemoved (struct tr_variant * torrentList); 146 void dataReadProgress (); 147 void dataSendProgress (); 148 void httpAuthenticationRequired (); 149 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 150 private: 151 int64_t nextUniqueTag; 152 int64_t myBlocklistSize; 153 Prefs& myPrefs; 154 tr_session * mySession; 155 QString myConfigDir; 156 QString mySessionId; 157 QStringList myIdleJSON; 158 QUrl myUrl; 159 QNetworkAccessManager * myNAM; 160 struct tr_session_stats myStats; 161 struct tr_session_stats myCumulativeStats; 162 QString mySessionVersion; 163 int64_t myDownloadDirFreeSpace; 164 164 }; 165 165 -
trunk/qt/speed.h
r11092 r13944 18 18 class Speed 19 19 { 20 private: 21 int _Bps; 22 Speed( int Bps ): _Bps(Bps) { } 23 public: 24 Speed( ): _Bps(0) { } 25 double KBps( ) const; 26 int Bps( ) const { return _Bps; } 27 bool isZero( ) const { return _Bps == 0; } 28 static Speed fromKBps( double KBps ); 29 static Speed fromBps( int Bps ) { return Speed( Bps ); } 30 void setBps( int Bps ) { _Bps = Bps; } 31 Speed& operator+=( const Speed& that ) { _Bps += that._Bps; return *this; } 32 Speed operator+( const Speed& that ) const { return Speed( _Bps + that._Bps ); } 33 bool operator<( const Speed& that ) const { return _Bps < that._Bps; } 20 private: 21 int _Bps; 22 Speed (int Bps): _Bps (Bps) {} 23 24 public: 25 Speed (): _Bps (0) { } 26 double KBps () const; 27 int Bps () const { return _Bps; } 28 bool isZero () const { return _Bps == 0; } 29 static Speed fromKBps (double KBps); 30 static Speed fromBps (int Bps) { return Speed (Bps); } 31 void setBps (int Bps) { _Bps = Bps; } 32 Speed& operator+= (const Speed& that) { _Bps += that._Bps; return *this; } 33 Speed operator+ (const Speed& that) const { return Speed (_Bps + that._Bps); } 34 bool operator< (const Speed& that) const { return _Bps < that._Bps; } 34 35 }; 35 36 -
trunk/qt/stats-dialog.cc
r11092 r13944 23 23 enum 24 24 { 25 25 REFRESH_INTERVAL_MSEC = (15*1000) 26 26 }; 27 27 28 StatsDialog :: StatsDialog ( Session & session, QWidget * parent):29 QDialog( parent, Qt::Dialog),30 mySession( session),31 myTimer( new QTimer( this ))28 StatsDialog :: StatsDialog (Session & session, QWidget * parent): 29 QDialog (parent, Qt::Dialog), 30 mySession (session), 31 myTimer (new QTimer (this)) 32 32 { 33 myTimer->setSingleShot( false);34 connect( myTimer, SIGNAL(timeout()), this, SLOT(onTimer()));35 setWindowTitle( tr( "Statistics" ));33 myTimer->setSingleShot (false); 34 connect (myTimer, SIGNAL (timeout ()), this, SLOT (onTimer ())); 35 setWindowTitle (tr ("Statistics")); 36 36 37 HIG * hig = new HIG();38 hig->addSectionTitle( tr( "Current Session" ));39 hig->addRow( tr( "Uploaded:" ), myCurrentUp = new QLabel( ));40 hig->addRow( tr( "Downloaded:" ), myCurrentDown = new QLabel( ));41 hig->addRow( tr( "Ratio:" ), myCurrentRatio = new QLabel( ));42 hig->addRow( tr( "Duration:" ), myCurrentDuration = new QLabel( ));43 hig->addSectionDivider();44 hig->addSectionTitle( tr( "Total" ));45 hig->addRow( myStartCount = new QLabel( tr( "Started %n time(s)", 0, 1 ) ), 0);46 hig->addRow( tr( "Uploaded:" ), myTotalUp = new QLabel( ));47 hig->addRow( tr( "Downloaded:" ), myTotalDown = new QLabel( ));48 hig->addRow( tr( "Ratio:" ), myTotalRatio = new QLabel( ));49 hig->addRow( tr( "Duration:" ), myTotalDuration = new QLabel( ));50 hig->finish();37 HIG * hig = new HIG (); 38 hig->addSectionTitle (tr ("Current Session")); 39 hig->addRow (tr ("Uploaded:"), myCurrentUp = new QLabel ()); 40 hig->addRow (tr ("Downloaded:"), myCurrentDown = new QLabel ()); 41 hig->addRow (tr ("Ratio:"), myCurrentRatio = new QLabel ()); 42 hig->addRow (tr ("Duration:"), myCurrentDuration = new QLabel ()); 43 hig->addSectionDivider (); 44 hig->addSectionTitle (tr ("Total")); 45 hig->addRow (myStartCount = new QLabel (tr ("Started %n time (s)", 0, 1)), 0); 46 hig->addRow (tr ("Uploaded:"), myTotalUp = new QLabel ()); 47 hig->addRow (tr ("Downloaded:"), myTotalDown = new QLabel ()); 48 hig->addRow (tr ("Ratio:"), myTotalRatio = new QLabel ()); 49 hig->addRow (tr ("Duration:"), myTotalDuration = new QLabel ()); 50 hig->finish (); 51 51 52 QLayout * layout = new QVBoxLayout( this);53 layout->addWidget( hig);54 QDialogButtonBox * buttons = new QDialogButtonBox( QDialogButtonBox::Close, Qt::Horizontal, this);55 connect( buttons, SIGNAL(rejected()), this, SLOT(hide())); // "close" triggers rejected56 layout->addWidget( buttons);52 QLayout * layout = new QVBoxLayout (this); 53 layout->addWidget (hig); 54 QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Close, Qt::Horizontal, this); 55 connect (buttons, SIGNAL (rejected ()), this, SLOT (hide ())); // "close" triggers rejected 56 layout->addWidget (buttons); 57 57 58 connect( &mySession, SIGNAL(statsUpdated()), this, SLOT(updateStats()));59 updateStats();60 mySession.refreshSessionStats();58 connect (&mySession, SIGNAL (statsUpdated ()), this, SLOT (updateStats ())); 59 updateStats (); 60 mySession.refreshSessionStats (); 61 61 } 62 62 63 StatsDialog :: ~StatsDialog ()63 StatsDialog :: ~StatsDialog () 64 64 { 65 65 } 66 66 67 67 void 68 StatsDialog :: setVisible ( bool visible)68 StatsDialog :: setVisible (bool visible) 69 69 { 70 myTimer->stop();71 if( visible)72 myTimer->start( REFRESH_INTERVAL_MSEC);73 QDialog::setVisible( visible);70 myTimer->stop (); 71 if (visible) 72 myTimer->start (REFRESH_INTERVAL_MSEC); 73 QDialog::setVisible (visible); 74 74 } 75 75 76 76 void 77 StatsDialog :: onTimer ()77 StatsDialog :: onTimer () 78 78 { 79 mySession.refreshSessionStats();79 mySession.refreshSessionStats (); 80 80 } 81 81 82 82 void 83 StatsDialog :: updateStats ()83 StatsDialog :: updateStats () 84 84 { 85 const struct tr_session_stats& current( mySession.getStats( ));86 const struct tr_session_stats& total( mySession.getCumulativeStats( ));85 const struct tr_session_stats& current (mySession.getStats ()); 86 const struct tr_session_stats& total (mySession.getCumulativeStats ()); 87 87 88 myCurrentUp->setText( Formatter::sizeToString( current.uploadedBytes ));89 myCurrentDown->setText( Formatter::sizeToString( current.downloadedBytes ));90 myCurrentRatio->setText( Formatter::ratioToString( current.ratio ));91 myCurrentDuration->setText( Formatter::timeToString( current.secondsActive ));88 myCurrentUp->setText (Formatter::sizeToString (current.uploadedBytes)); 89 myCurrentDown->setText (Formatter::sizeToString (current.downloadedBytes)); 90 myCurrentRatio->setText (Formatter::ratioToString (current.ratio)); 91 myCurrentDuration->setText (Formatter::timeToString (current.secondsActive)); 92 92 93 myTotalUp->setText( Formatter::sizeToString( total.uploadedBytes ));94 myTotalDown->setText( Formatter::sizeToString( total.downloadedBytes ));95 myTotalRatio->setText( Formatter::ratioToString( total.ratio ));96 myTotalDuration->setText( Formatter::timeToString( total.secondsActive ));93 myTotalUp->setText (Formatter::sizeToString (total.uploadedBytes)); 94 myTotalDown->setText (Formatter::sizeToString (total.downloadedBytes)); 95 myTotalRatio->setText (Formatter::ratioToString (total.ratio)); 96 myTotalDuration->setText (Formatter::timeToString (total.secondsActive)); 97 97 98 myStartCount->setText( tr( "Started %n time(s)", 0, total.sessionCount ));98 myStartCount->setText (tr ("Started %n time (s)", 0, total.sessionCount)); 99 99 } -
trunk/qt/stats-dialog.h
r11092 r13944 22 22 class StatsDialog: public QDialog 23 23 { 24 24 Q_OBJECT 25 25 26 27 void accepted();26 signals: 27 void accepted (); 28 28 29 30 void updateStats();29 public slots: 30 void updateStats (); 31 31 32 33 void onTimer();32 private slots: 33 void onTimer (); 34 34 35 36 StatsDialog( Session&, QWidget * parent = 0);37 ~StatsDialog();38 virtual void setVisible( bool visible);35 public: 36 StatsDialog (Session&, QWidget * parent = 0); 37 ~StatsDialog (); 38 virtual void setVisible (bool visible); 39 39 40 41 42 43 44 45 46 47 48 49 50 51 40 private: 41 Session & mySession; 42 QTimer * myTimer; 43 QLabel * myCurrentUp; 44 QLabel * myCurrentDown; 45 QLabel * myCurrentRatio; 46 QLabel * myCurrentDuration; 47 QLabel * myStartCount; 48 QLabel * myTotalUp; 49 QLabel * myTotalDown; 50 QLabel * myTotalRatio; 51 QLabel * myTotalDuration; 52 52 }; 53 53
Note: See TracChangeset
for help on using the changeset viewer.