diff --git a/qt/license.cc b/qt/license.cc index 0077c2eb0..8da1d0c73 100644 --- a/qt/license.cc +++ b/qt/license.cc @@ -16,27 +16,27 @@ #include "license.h" -LicenseDialog :: LicenseDialog( QWidget * parent ): - QDialog( parent, Qt::Dialog ) +LicenseDialog :: LicenseDialog (QWidget * parent): + QDialog (parent, Qt::Dialog) { - setWindowTitle( tr( "License" ) ); - resize( 400, 300 ); - QVBoxLayout * v = new QVBoxLayout( this ); + setWindowTitle (tr ("License")); + resize (400, 300); + QVBoxLayout * v = new QVBoxLayout (this); - QPlainTextEdit * t = new QPlainTextEdit( this ); - t->setReadOnly( true ); - t->setPlainText( + QPlainTextEdit * t = new QPlainTextEdit (this); + t->setReadOnly (true); + t->setPlainText ( "The OS X client, CLI client, and parts of libtransmission are licensed under the terms of the MIT license.\n\n" "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" -"1. The MIT-licensed portions of Transmission listed above are exempt from GPLv2 clause 2(b) and may retain their MIT license.\n\n" -"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." ); - v->addWidget( t ); +"1. The MIT-licensed portions of Transmission listed above are exempt from GPLv2 clause 2 (b) and may retain their MIT license.\n\n" +"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."); + v->addWidget (t); - QDialogButtonBox * box = new QDialogButtonBox; - box->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); - box->setOrientation( Qt::Horizontal ); - box->setStandardButtons( QDialogButtonBox::Close ); - v->addWidget( box ); + QDialogButtonBox * box = new QDialogButtonBox; + box->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed); + box->setOrientation (Qt::Horizontal); + box->setStandardButtons (QDialogButtonBox::Close); + v->addWidget (box); - connect( box, SIGNAL(rejected()), this, SLOT(hide()) ); + connect (box, SIGNAL (rejected ()), this, SLOT (hide ())); } diff --git a/qt/license.h b/qt/license.h index c9f5639b5..61b47e38d 100644 --- a/qt/license.h +++ b/qt/license.h @@ -17,12 +17,11 @@ class LicenseDialog: public QDialog { - Q_OBJECT - - public: - LicenseDialog( QWidget * parent = 0 ); - ~LicenseDialog( ) { } + Q_OBJECT + public: + LicenseDialog (QWidget * parent = 0); + ~LicenseDialog () {} }; #endif diff --git a/qt/relocate.cc b/qt/relocate.cc index 16e460e3b..cf46f2890 100644 --- a/qt/relocate.cc +++ b/qt/relocate.cc @@ -32,82 +32,89 @@ bool RelocateDialog :: myMoveFlag = true; void -RelocateDialog :: onSetLocation( ) +RelocateDialog :: onSetLocation () { - mySession.torrentSetLocation( myIds, myPath, myMoveFlag ); - deleteLater( ); + mySession.torrentSetLocation (myIds, myPath, myMoveFlag); + deleteLater (); } void -RelocateDialog :: onFileSelected( const QString& path ) +RelocateDialog :: onFileSelected (const QString& path) { - myPath = path; - myDirButton->setText( myPath ); + myPath = path; + myDirButton->setText (myPath); } void -RelocateDialog :: onDirButtonClicked( ) +RelocateDialog :: onDirButtonClicked () { - const QString title = tr( "Select Location" ); - const QString path = Utils::remoteFileChooser( this, title, myPath, true, mySession.isServer() ); + const QString title = tr ("Select Location"); + const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer ()); - if( !path.isEmpty() ) - onFileSelected( path ); + if (!path.isEmpty ()) + onFileSelected (path); } void -RelocateDialog :: onMoveToggled( bool b ) +RelocateDialog :: onMoveToggled (bool b) { - myMoveFlag = b; + myMoveFlag = b; } -RelocateDialog :: RelocateDialog( Session& session, TorrentModel& model, const QSet& ids, QWidget * parent ): - QDialog( parent ), - mySession( session ), - myModel( model ), - myIds( ids ) +RelocateDialog :: RelocateDialog (Session & session, + TorrentModel & model, + const QSet & ids, + QWidget * parent): + QDialog (parent), + mySession (session), + myModel (model), + myIds (ids) { - const int iconSize( style( )->pixelMetric( QStyle :: PM_SmallIconSize ) ); - const QFileIconProvider iconProvider; - const QIcon folderIcon = iconProvider.icon( QFileIconProvider::Folder ); - const QPixmap folderPixmap = folderIcon.pixmap( iconSize ); + const int iconSize (style ()->pixelMetric (QStyle :: PM_SmallIconSize)); + const QFileIconProvider iconProvider; + const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder); + const QPixmap folderPixmap = folderIcon.pixmap (iconSize); - QRadioButton * find_rb; - setWindowTitle( tr( "Set Torrent Location" ) ); + QRadioButton * find_rb; + setWindowTitle (tr ("Set Torrent Location")); - foreach( int id, myIds ) { - const Torrent * tor = myModel.getTorrentFromId( id ); - if( myPath.isEmpty() ) - myPath = tor->getPath(); - else if( myPath != tor->getPath() ) + foreach (int id, myIds) + { + const Torrent * tor = myModel.getTorrentFromId (id); + + if (myPath.isEmpty ()) { - if( mySession.isServer() ) - myPath = QDir::homePath( ); - else - myPath = QDir::rootPath( ); + myPath = tor->getPath (); + } + else if (myPath != tor->getPath ()) + { + if (mySession.isServer ()) + myPath = QDir::homePath (); + else + myPath = QDir::rootPath (); } } - HIG * hig = new HIG( ); - hig->addSectionTitle( tr( "Set Location" ) ); - hig->addRow( tr( "New &location:" ), myDirButton = new QPushButton( folderPixmap, myPath ) ); - hig->addWideControl( myMoveRadio = new QRadioButton( tr( "&Move from the current folder" ), this ) ); - hig->addWideControl( find_rb = new QRadioButton( tr( "Local data is &already there" ), this ) ); - hig->finish( ); + HIG * hig = new HIG (); + hig->addSectionTitle (tr ("Set Location")); + hig->addRow (tr ("New &location:"), myDirButton = new QPushButton (folderPixmap, myPath)); + hig->addWideControl (myMoveRadio = new QRadioButton (tr ("&Move from the current folder"), this)); + hig->addWideControl (find_rb = new QRadioButton (tr ("Local data is &already there"), this)); + hig->finish (); - if( myMoveFlag ) - myMoveRadio->setChecked( true ); - else - find_rb->setChecked( true ); + if (myMoveFlag) + myMoveRadio->setChecked (true); + else + find_rb->setChecked (true); - connect( myMoveRadio, SIGNAL(toggled(bool)), this, SLOT(onMoveToggled(bool))); - connect( myDirButton, SIGNAL(clicked(bool)), this, SLOT(onDirButtonClicked())); + connect (myMoveRadio, SIGNAL (toggled (bool)), this, SLOT (onMoveToggled (bool))); + connect (myDirButton, SIGNAL (clicked (bool)), this, SLOT (onDirButtonClicked ())); - QLayout * layout = new QVBoxLayout( this ); - layout->addWidget( hig ); - QDialogButtonBox * buttons = new QDialogButtonBox( QDialogButtonBox::Ok|QDialogButtonBox::Cancel ); - connect( buttons, SIGNAL(rejected()), this, SLOT(deleteLater())); - connect( buttons, SIGNAL(accepted()), this, SLOT(onSetLocation())); - layout->addWidget( buttons ); - QWidget::setAttribute( Qt::WA_DeleteOnClose, true ); + QLayout * layout = new QVBoxLayout (this); + layout->addWidget (hig); + QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Ok|QDialogButtonBox::Cancel); + connect (buttons, SIGNAL (rejected ()), this, SLOT (deleteLater ())); + connect (buttons, SIGNAL (accepted ()), this, SLOT (onSetLocation ())); + layout->addWidget (buttons); + QWidget::setAttribute (Qt::WA_DeleteOnClose, true); } diff --git a/qt/relocate.h b/qt/relocate.h index 4c2c52d2c..966d3cf1a 100644 --- a/qt/relocate.h +++ b/qt/relocate.h @@ -25,28 +25,28 @@ class TorrentModel; class RelocateDialog: public QDialog { - Q_OBJECT + Q_OBJECT - private: - QString myPath; - static bool myMoveFlag; + private: + QString myPath; + static bool myMoveFlag; - private: - Session & mySession; - TorrentModel& myModel; - QSet myIds; - QPushButton * myDirButton; - QRadioButton * myMoveRadio; + private: + Session & mySession; + TorrentModel& myModel; + QSet myIds; + QPushButton * myDirButton; + QRadioButton * myMoveRadio; - private slots: - void onFileSelected( const QString& path ); - void onDirButtonClicked( ); - void onSetLocation( ); - void onMoveToggled( bool ); + private slots: + void onFileSelected (const QString& path); + void onDirButtonClicked (); + void onSetLocation (); + void onMoveToggled (bool); - public: - RelocateDialog( Session&, TorrentModel&, const QSet& ids, QWidget * parent = 0 ); - ~RelocateDialog( ) { } + public: + RelocateDialog (Session&, TorrentModel&, const QSet& ids, QWidget * parent = 0); + ~RelocateDialog () { } }; #endif diff --git a/qt/session.cc b/qt/session.cc index 3c0e8804b..72c998222 100644 --- a/qt/session.cc +++ b/qt/session.cc @@ -50,20 +50,20 @@ namespace { - enum - { - TAG_SOME_TORRENTS, - TAG_ALL_TORRENTS, - TAG_SESSION_STATS, - TAG_SESSION_INFO, - TAG_BLOCKLIST_UPDATE, - TAG_ADD_TORRENT, - TAG_PORT_TEST, - TAG_MAGNET_LINK, - TAG_RENAME_PATH, + enum + { + TAG_SOME_TORRENTS, + TAG_ALL_TORRENTS, + TAG_SESSION_STATS, + TAG_SESSION_INFO, + TAG_BLOCKLIST_UPDATE, + TAG_ADD_TORRENT, + TAG_PORT_TEST, + TAG_MAGNET_LINK, + TAG_RENAME_PATH, - FIRST_UNIQUE_TAG - }; + FIRST_UNIQUE_TAG + }; } /*** @@ -73,14 +73,14 @@ namespace namespace { typedef Torrent::KeyList KeyList; - const KeyList& getInfoKeys() { return Torrent::getInfoKeys(); } - const KeyList& getStatKeys() { return Torrent::getStatKeys(); } - const KeyList& getExtraStatKeys() { return Torrent::getExtraStatKeys(); } + const KeyList& getInfoKeys () { return Torrent::getInfoKeys (); } + const KeyList& getStatKeys () { return Torrent::getStatKeys (); } + const KeyList& getExtraStatKeys () { return Torrent::getExtraStatKeys (); } void addList (tr_variant * list, const KeyList& keys) { - tr_variantListReserve (list, keys.size()); + tr_variantListReserve (list, keys.size ()); foreach (tr_quark key, keys) tr_variantListAddQuark (list, key); } @@ -91,154 +91,160 @@ namespace ***/ void -Session :: sessionSet( const tr_quark key, const QVariant& value ) +Session :: sessionSet (const tr_quark key, const QVariant& value) { - tr_variant top; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddStr( &top, TR_KEY_method, "session-set" ); - tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 1 ) ); - switch( value.type( ) ) { - case QVariant::Bool: tr_variantDictAddBool ( args, key, value.toBool() ); break; - case QVariant::Int: tr_variantDictAddInt ( args, key, value.toInt() ); break; - case QVariant::Double: tr_variantDictAddReal ( args, key, value.toDouble() ); break; - case QVariant::String: tr_variantDictAddStr ( args, key, value.toString().toUtf8().constData() ); break; - default: assert( "unknown type" ); - } - exec( &top ); - tr_variantFree( &top ); -} - -void -Session :: portTest( ) -{ - tr_variant top; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddStr( &top, TR_KEY_method, "port-test" ); - tr_variantDictAddInt( &top, TR_KEY_tag, TAG_PORT_TEST ); - exec( &top ); - tr_variantFree( &top ); -} - -void -Session :: copyMagnetLinkToClipboard( int torrentId ) -{ - tr_variant top; - tr_variantInitDict( &top, 3 ); - tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get ); - tr_variantDictAddInt( &top, TR_KEY_tag, TAG_MAGNET_LINK ); - tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ); - tr_variantListAddInt( tr_variantDictAddList( args, TR_KEY_ids, 1 ), torrentId ); - tr_variantListAddStr( tr_variantDictAddList( args, TR_KEY_fields, 1 ), "magnetLink" ); - - exec( &top ); - tr_variantFree( &top ); -} - -void -Session :: updatePref( int key ) -{ - if( myPrefs.isCore( key ) ) switch( key ) + tr_variant top; + tr_variantInitDict (&top, 2); + tr_variantDictAddStr (&top, TR_KEY_method, "session-set"); + tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 1)); + switch (value.type ()) { - case Prefs :: ALT_SPEED_LIMIT_DOWN: - case Prefs :: ALT_SPEED_LIMIT_ENABLED: - case Prefs :: ALT_SPEED_LIMIT_TIME_BEGIN: - case Prefs :: ALT_SPEED_LIMIT_TIME_DAY: - case Prefs :: ALT_SPEED_LIMIT_TIME_ENABLED: - case Prefs :: ALT_SPEED_LIMIT_TIME_END: - case Prefs :: ALT_SPEED_LIMIT_UP: - case Prefs :: BLOCKLIST_DATE: - case Prefs :: BLOCKLIST_ENABLED: - case Prefs :: BLOCKLIST_URL: - case Prefs :: DHT_ENABLED: - case Prefs :: DOWNLOAD_QUEUE_ENABLED: - case Prefs :: DOWNLOAD_QUEUE_SIZE: - case Prefs :: DSPEED: - case Prefs :: DSPEED_ENABLED: - case Prefs :: IDLE_LIMIT: - case Prefs :: IDLE_LIMIT_ENABLED: - case Prefs :: INCOMPLETE_DIR: - case Prefs :: INCOMPLETE_DIR_ENABLED: - case Prefs :: LPD_ENABLED: - case Prefs :: PEER_LIMIT_GLOBAL: - case Prefs :: PEER_LIMIT_TORRENT: - case Prefs :: PEER_PORT: - case Prefs :: PEER_PORT_RANDOM_ON_START: - case Prefs :: QUEUE_STALLED_MINUTES: - case Prefs :: PEX_ENABLED: - case Prefs :: PORT_FORWARDING: - case Prefs :: RENAME_PARTIAL_FILES: - case Prefs :: SCRIPT_TORRENT_DONE_ENABLED: - case Prefs :: SCRIPT_TORRENT_DONE_FILENAME: - case Prefs :: START: - case Prefs :: TRASH_ORIGINAL: - case Prefs :: USPEED: - case Prefs :: USPEED_ENABLED: - case Prefs :: UTP_ENABLED: - sessionSet( myPrefs.getKey(key), myPrefs.variant(key) ); - break; + case QVariant::Bool: tr_variantDictAddBool (args, key, value.toBool ()); break; + case QVariant::Int: tr_variantDictAddInt (args, key, value.toInt ()); break; + case QVariant::Double: tr_variantDictAddReal (args, key, value.toDouble ()); break; + case QVariant::String: tr_variantDictAddStr (args, key, value.toString ().toUtf8 ().constData ()); break; + default: assert ("unknown type"); + } + exec (&top); + tr_variantFree (&top); +} - case Prefs :: DOWNLOAD_DIR: - sessionSet (myPrefs.getKey(key), myPrefs.variant(key)); - /* this will change the 'freespace' argument, so refresh */ - refreshSessionInfo (); - break; +void +Session :: portTest () +{ + tr_variant top; + tr_variantInitDict (&top, 2); + tr_variantDictAddStr (&top, TR_KEY_method, "port-test"); + tr_variantDictAddInt (&top, TR_KEY_tag, TAG_PORT_TEST); + exec (&top); + tr_variantFree (&top); +} - case Prefs :: RATIO: - sessionSet( TR_KEY_seedRatioLimit, myPrefs.variant(key) ); - break; - case Prefs :: RATIO_ENABLED: - sessionSet( TR_KEY_seedRatioLimited, myPrefs.variant(key) ); - break; +void +Session :: copyMagnetLinkToClipboard (int torrentId) +{ + tr_variant top; + tr_variantInitDict (&top, 3); + tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get); + tr_variantDictAddInt (&top, TR_KEY_tag, TAG_MAGNET_LINK); + tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); + tr_variantListAddInt (tr_variantDictAddList (args, TR_KEY_ids, 1), torrentId); + tr_variantListAddStr (tr_variantDictAddList (args, TR_KEY_fields, 1), "magnetLink"); + exec (&top); + tr_variantFree (&top); +} - case Prefs :: ENCRYPTION: +void +Session :: updatePref (int key) +{ + if (myPrefs.isCore (key)) switch (key) + { + case Prefs :: ALT_SPEED_LIMIT_DOWN: + case Prefs :: ALT_SPEED_LIMIT_ENABLED: + case Prefs :: ALT_SPEED_LIMIT_TIME_BEGIN: + case Prefs :: ALT_SPEED_LIMIT_TIME_DAY: + case Prefs :: ALT_SPEED_LIMIT_TIME_ENABLED: + case Prefs :: ALT_SPEED_LIMIT_TIME_END: + case Prefs :: ALT_SPEED_LIMIT_UP: + case Prefs :: BLOCKLIST_DATE: + case Prefs :: BLOCKLIST_ENABLED: + case Prefs :: BLOCKLIST_URL: + case Prefs :: DHT_ENABLED: + case Prefs :: DOWNLOAD_QUEUE_ENABLED: + case Prefs :: DOWNLOAD_QUEUE_SIZE: + case Prefs :: DSPEED: + case Prefs :: DSPEED_ENABLED: + case Prefs :: IDLE_LIMIT: + case Prefs :: IDLE_LIMIT_ENABLED: + case Prefs :: INCOMPLETE_DIR: + case Prefs :: INCOMPLETE_DIR_ENABLED: + case Prefs :: LPD_ENABLED: + case Prefs :: PEER_LIMIT_GLOBAL: + case Prefs :: PEER_LIMIT_TORRENT: + case Prefs :: PEER_PORT: + case Prefs :: PEER_PORT_RANDOM_ON_START: + case Prefs :: QUEUE_STALLED_MINUTES: + case Prefs :: PEX_ENABLED: + case Prefs :: PORT_FORWARDING: + case Prefs :: RENAME_PARTIAL_FILES: + case Prefs :: SCRIPT_TORRENT_DONE_ENABLED: + case Prefs :: SCRIPT_TORRENT_DONE_FILENAME: + case Prefs :: START: + case Prefs :: TRASH_ORIGINAL: + case Prefs :: USPEED: + case Prefs :: USPEED_ENABLED: + case Prefs :: UTP_ENABLED: + sessionSet (myPrefs.getKey (key), myPrefs.variant (key)); + break; + + case Prefs :: DOWNLOAD_DIR: + sessionSet (myPrefs.getKey (key), myPrefs.variant (key)); + /* this will change the 'freespace' argument, so refresh */ + refreshSessionInfo (); + break; + + case Prefs :: RATIO: + sessionSet (TR_KEY_seedRatioLimit, myPrefs.variant (key)); + break; + case Prefs :: RATIO_ENABLED: + sessionSet (TR_KEY_seedRatioLimited, myPrefs.variant (key)); + break; + + case Prefs :: ENCRYPTION: + { + const int i = myPrefs.variant (key).toInt (); + switch (i) { - const int i = myPrefs.variant(key).toInt(); - switch( i ) - { - case 0: - sessionSet( myPrefs.getKey(key), "tolerated" ); - break; - case 1: - sessionSet( myPrefs.getKey(key), "preferred" ); - break; - case 2: - sessionSet( myPrefs.getKey(key), "required" ); - break; - } + case 0: + sessionSet (myPrefs.getKey (key), "tolerated"); + break; + case 1: + sessionSet (myPrefs.getKey (key), "preferred"); + break; + case 2: + sessionSet (myPrefs.getKey (key), "required"); break; } + break; + } - case Prefs :: RPC_AUTH_REQUIRED: - if( mySession ) - tr_sessionSetRPCPasswordEnabled( mySession, myPrefs.getBool(key) ); - break; - case Prefs :: RPC_ENABLED: - if( mySession ) - tr_sessionSetRPCEnabled( mySession, myPrefs.getBool(key) ); - break; - case Prefs :: RPC_PASSWORD: - if( mySession ) - tr_sessionSetRPCPassword( mySession, myPrefs.getString(key).toUtf8().constData() ); - break; - case Prefs :: RPC_PORT: - if( mySession ) - tr_sessionSetRPCPort( mySession, myPrefs.getInt(key) ); - break; - case Prefs :: RPC_USERNAME: - if( mySession ) - tr_sessionSetRPCUsername( mySession, myPrefs.getString(key).toUtf8().constData() ); - break; - case Prefs :: RPC_WHITELIST_ENABLED: - if( mySession ) - tr_sessionSetRPCWhitelistEnabled( mySession, myPrefs.getBool(key) ); - break; - case Prefs :: RPC_WHITELIST: - if( mySession ) - tr_sessionSetRPCWhitelist( mySession, myPrefs.getString(key).toUtf8().constData() ); - break; + case Prefs :: RPC_AUTH_REQUIRED: + if (mySession) + tr_sessionSetRPCPasswordEnabled (mySession, myPrefs.getBool (key)); + break; - default: - std::cerr << "unhandled pref: " << key << std::endl; + case Prefs :: RPC_ENABLED: + if (mySession) + tr_sessionSetRPCEnabled (mySession, myPrefs.getBool (key)); + break; + + case Prefs :: RPC_PASSWORD: + if (mySession) + tr_sessionSetRPCPassword (mySession, myPrefs.getString (key).toUtf8 ().constData ()); + break; + + case Prefs :: RPC_PORT: + if (mySession) + tr_sessionSetRPCPort (mySession, myPrefs.getInt (key)); + break; + + case Prefs :: RPC_USERNAME: + if (mySession) + tr_sessionSetRPCUsername (mySession, myPrefs.getString (key).toUtf8 ().constData ()); + break; + + case Prefs :: RPC_WHITELIST_ENABLED: + if (mySession) + tr_sessionSetRPCWhitelistEnabled (mySession, myPrefs.getBool (key)); + break; + + case Prefs :: RPC_WHITELIST: + if (mySession) + tr_sessionSetRPCWhitelist (mySession, myPrefs.getString (key).toUtf8 ().constData ()); + break; + + default: + std::cerr << "unhandled pref: " << key << std::endl; } } @@ -246,49 +252,49 @@ Session :: updatePref( int key ) **** ***/ -Session :: Session( const char * configDir, Prefs& prefs ): - nextUniqueTag( FIRST_UNIQUE_TAG ), - myBlocklistSize( -1 ), - myPrefs( prefs ), - mySession( 0 ), - myConfigDir( QString::fromUtf8( configDir ) ), - myNAM( 0 ), - myDownloadDirFreeSpace( -1 ) +Session :: Session (const char * configDir, Prefs& prefs): + nextUniqueTag (FIRST_UNIQUE_TAG), + myBlocklistSize (-1), + myPrefs (prefs), + mySession (0), + myConfigDir (QString::fromUtf8 (configDir)), + myNAM (0), + myDownloadDirFreeSpace (-1) { - myStats.ratio = TR_RATIO_NA; - myStats.uploadedBytes = 0; - myStats.downloadedBytes = 0; - myStats.filesAdded = 0; - myStats.sessionCount = 0; - myStats.secondsActive = 0; - myCumulativeStats = myStats; + myStats.ratio = TR_RATIO_NA; + myStats.uploadedBytes = 0; + myStats.downloadedBytes = 0; + myStats.filesAdded = 0; + myStats.sessionCount = 0; + myStats.secondsActive = 0; + myCumulativeStats = myStats; - connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(updatePref(int)) ); + connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (updatePref (int))); - connect (this, SIGNAL(responseReceived(const QByteArray&)), - this, SLOT(onResponseReceived(const QByteArray&))); + connect (this, SIGNAL (responseReceived (const QByteArray&)), + this, SLOT (onResponseReceived (const QByteArray&))); } -Session :: ~Session( ) +Session :: ~Session () { - stop( ); + stop (); } QNetworkAccessManager * -Session :: networkAccessManager( ) +Session :: networkAccessManager () { - if( myNAM == 0 ) + if (myNAM == 0) { - myNAM = new QNetworkAccessManager; + myNAM = new QNetworkAccessManager; - connect( myNAM, SIGNAL(finished(QNetworkReply*)), - this, SLOT(onFinished(QNetworkReply*)) ); + connect (myNAM, SIGNAL (finished (QNetworkReply*)), + this, SLOT (onFinished (QNetworkReply*))); - connect( myNAM, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), - this, SIGNAL(httpAuthenticationRequired()) ); + connect (myNAM, SIGNAL (authenticationRequired (QNetworkReply*,QAuthenticator*)), + this, SIGNAL (httpAuthenticationRequired ())); } - return myNAM; + return myNAM; } /*** @@ -296,84 +302,84 @@ Session :: networkAccessManager( ) ***/ void -Session :: stop( ) +Session :: stop () { - if( myNAM != 0 ) + if (myNAM != 0) { - myNAM->deleteLater( ); - myNAM = 0; + myNAM->deleteLater (); + myNAM = 0; } - myUrl.clear( ); + myUrl.clear (); - if( mySession ) + if (mySession) { - tr_sessionClose( mySession ); - mySession = 0; + tr_sessionClose (mySession); + mySession = 0; } } void -Session :: restart( ) +Session :: restart () { - stop( ); - start( ); + stop (); + start (); } void -Session :: start( ) +Session :: start () { - if( myPrefs.get(Prefs::SESSION_IS_REMOTE) ) + if (myPrefs.get (Prefs::SESSION_IS_REMOTE)) { - QUrl url; - url.setScheme( "http" ); - url.setHost( myPrefs.get(Prefs::SESSION_REMOTE_HOST) ); - url.setPort( myPrefs.get(Prefs::SESSION_REMOTE_PORT) ); - url.setPath( "/transmission/rpc" ); - if( myPrefs.get(Prefs::SESSION_REMOTE_AUTH) ) + QUrl url; + url.setScheme ("http"); + url.setHost (myPrefs.get (Prefs::SESSION_REMOTE_HOST)); + url.setPort (myPrefs.get (Prefs::SESSION_REMOTE_PORT)); + url.setPath ("/transmission/rpc"); + if (myPrefs.get (Prefs::SESSION_REMOTE_AUTH)) { - url.setUserName( myPrefs.get(Prefs::SESSION_REMOTE_USERNAME) ); - url.setPassword( myPrefs.get(Prefs::SESSION_REMOTE_PASSWORD) ); + url.setUserName (myPrefs.get (Prefs::SESSION_REMOTE_USERNAME)); + url.setPassword (myPrefs.get (Prefs::SESSION_REMOTE_PASSWORD)); } - myUrl = url; + myUrl = url; } - else + else { - tr_variant settings; - tr_variantInitDict( &settings, 0 ); - tr_sessionLoadSettings( &settings, myConfigDir.toUtf8().constData(), "qt" ); - mySession = tr_sessionInit( "qt", myConfigDir.toUtf8().constData(), true, &settings ); - tr_variantFree( &settings ); + tr_variant settings; + tr_variantInitDict (&settings, 0); + tr_sessionLoadSettings (&settings, myConfigDir.toUtf8 ().constData (), "qt"); + mySession = tr_sessionInit ("qt", myConfigDir.toUtf8 ().constData (), true, &settings); + tr_variantFree (&settings); - tr_ctor * ctor = tr_ctorNew( mySession ); - int torrentCount; - tr_torrent ** torrents = tr_sessionLoadTorrents( mySession, ctor, &torrentCount ); - tr_free( torrents ); - tr_ctorFree( ctor ); + tr_ctor * ctor = tr_ctorNew (mySession); + int torrentCount; + tr_torrent ** torrents = tr_sessionLoadTorrents (mySession, ctor, &torrentCount); + tr_free (torrents); + tr_ctorFree (ctor); } - emit sourceChanged( ); + emit sourceChanged (); } bool -Session :: isServer( ) const +Session :: isServer () const { - return mySession != 0; + return mySession != 0; } bool -Session :: isLocal( ) const +Session :: isLocal () const { - if( mySession != 0 ) - return true; + if (mySession != 0) + return true; - if( myUrl.host() == "127.0.0.1" ) - return true; + if (myUrl.host () == "127.0.0.1") + return true; - if( !myUrl.host().compare( "localhost", Qt::CaseInsensitive ) ) - return true; + if (!myUrl.host ().compare ("localhost", Qt::CaseInsensitive)) + return true; - return false; + return false; } /*** @@ -395,11 +401,11 @@ namespace } void - addOptionalIds( tr_variant * args, const QSet& ids ) + addOptionalIds (tr_variant * args, const QSet& ids) { - if (!ids.isEmpty()) + if (!ids.isEmpty ()) { - tr_variant * idList (tr_variantDictAddList (args, TR_KEY_ids, ids.size())); + tr_variant * idList (tr_variantDictAddList (args, TR_KEY_ids, ids.size ())); foreach (int i, ids) tr_variantListAddInt (idList, i); } @@ -407,76 +413,76 @@ namespace } void -Session :: torrentSet( const QSet& ids, const tr_quark key, double value ) +Session :: torrentSet (const QSet& ids, const tr_quark key, double value) { - tr_variant top; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set ); - tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ); - tr_variantDictAddReal( args, key, value ); - addOptionalIds( args, ids ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + tr_variantInitDict (&top, 2); + tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set); + tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); + tr_variantDictAddReal (args, key, value); + addOptionalIds (args, ids); + exec (&top); + tr_variantFree (&top); } void -Session :: torrentSet( const QSet& ids, const tr_quark key, int value ) +Session :: torrentSet (const QSet& ids, const tr_quark key, int value) { - tr_variant top; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set ); - tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ); - tr_variantDictAddInt( args, key, value ); - addOptionalIds( args, ids ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + tr_variantInitDict (&top, 2); + tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set); + tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); + tr_variantDictAddInt (args, key, value); + addOptionalIds (args, ids); + exec (&top); + tr_variantFree (&top); } void -Session :: torrentSet( const QSet& ids, const tr_quark key, bool value ) +Session :: torrentSet (const QSet& ids, const tr_quark key, bool value) { - tr_variant top; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set ); - tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ); - tr_variantDictAddBool( args, key, value ); - addOptionalIds( args, ids ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + tr_variantInitDict (&top, 2); + tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set); + tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); + tr_variantDictAddBool (args, key, value); + addOptionalIds (args, ids); + exec (&top); + tr_variantFree (&top); } void -Session :: torrentSet( const QSet& ids, const tr_quark key, const QStringList& value ) +Session :: torrentSet (const QSet& ids, const tr_quark key, const QStringList& value) { - tr_variant top; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set ); - tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ); - addOptionalIds( args, ids ); - tr_variant * list( tr_variantDictAddList( args, key, value.size( ) ) ); - foreach( const QString str, value ) - tr_variantListAddStr( list, str.toUtf8().constData() ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + tr_variantInitDict (&top, 2); + tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set); + tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); + addOptionalIds (args, ids); + tr_variant * list (tr_variantDictAddList (args, key, value.size ())); + foreach (const QString str, value) + tr_variantListAddStr (list, str.toUtf8 ().constData ()); + exec (&top); + tr_variantFree (&top); } void -Session :: torrentSet( const QSet& ids, const tr_quark key, const QList& value ) +Session :: torrentSet (const QSet& ids, const tr_quark key, const QList& value) { - tr_variant top; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set ); - tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ) ); - addOptionalIds( args, ids ); - tr_variant * list( tr_variantDictAddList( args, key, value.size( ) ) ); - foreach( int i, value ) - tr_variantListAddInt( list, i ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + tr_variantInitDict (&top, 2); + tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set); + tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2)); + addOptionalIds (args, ids); + tr_variant * list (tr_variantDictAddList (args, key, value.size ())); + foreach (int i, value) + tr_variantListAddInt (list, i); + exec (&top); + tr_variantFree (&top); } void -Session :: torrentSet( const QSet& ids, const tr_quark key, const QPair& value ) +Session :: torrentSet (const QSet& ids, const tr_quark key, const QPair& value) { tr_variant top; tr_variantInitDict (&top, 2); @@ -485,20 +491,20 @@ Session :: torrentSet( const QSet& ids, const tr_quark key, const QPair& ids, const QString& location, bool doMove) +Session :: torrentSetLocation (const QSet& ids, const QString& location, bool doMove) { tr_variant top; tr_variantInitDict (&top, 2); tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set_location); - tr_variant * args (tr_variantDictAddDict(&top, TR_KEY_arguments, 3)); + tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 3)); addOptionalIds (args, ids); - tr_variantDictAddStr (args, TR_KEY_location, location.toUtf8().constData()); + tr_variantDictAddStr (args, TR_KEY_location, location.toUtf8 ().constData ()); tr_variantDictAddBool (args, TR_KEY_move, doMove); exec (&top); tr_variantFree (&top); @@ -511,51 +517,51 @@ Session :: torrentRenamePath (const QSet& ids, const QString& oldpath, cons tr_variantInitDict (&top, 2); tr_variantDictAddStr (&top, TR_KEY_method, "torrent-rename-path"); tr_variantDictAddInt (&top, TR_KEY_tag, TAG_RENAME_PATH); - tr_variant * args (tr_variantDictAddDict(&top, TR_KEY_arguments, 3)); + tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 3)); addOptionalIds (args, ids); - tr_variantDictAddStr (args, TR_KEY_path, oldpath.toUtf8().constData()); - tr_variantDictAddStr (args, TR_KEY_name, newname.toUtf8().constData()); + tr_variantDictAddStr (args, TR_KEY_path, oldpath.toUtf8 ().constData ()); + tr_variantDictAddStr (args, TR_KEY_name, newname.toUtf8 ().constData ()); exec (&top); tr_variantFree (&top); } void -Session :: refreshTorrents( const QSet& ids ) +Session :: refreshTorrents (const QSet& ids) { - if( ids.empty( ) ) + if (ids.empty ()) { - refreshAllTorrents( ); + refreshAllTorrents (); } - else + else { - tr_variant top; - tr_variantInitDict( &top, 3 ); - tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get ); - tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SOME_TORRENTS ); - tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ) ); - addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys( ) ); - addOptionalIds( args, ids ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + tr_variantInitDict (&top, 3); + tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get); + tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SOME_TORRENTS); + tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2)); + addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys ()); + addOptionalIds (args, ids); + exec (&top); + tr_variantFree (&top); } } void -Session :: refreshExtraStats( const QSet& ids ) +Session :: refreshExtraStats (const QSet& ids) { - tr_variant top; - tr_variantInitDict( &top, 3 ); - tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get ); - tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SOME_TORRENTS ); - tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ) ); - addOptionalIds( args, ids ); - addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys( ) + getExtraStatKeys( )); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + tr_variantInitDict (&top, 3); + tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get); + tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SOME_TORRENTS); + tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2)); + addOptionalIds (args, ids); + addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys () + getExtraStatKeys ()); + exec (&top); + tr_variantFree (&top); } void -Session :: sendTorrentRequest (const char * request, const QSet& ids ) +Session :: sendTorrentRequest (const char * request, const QSet& ids) { tr_variant top; @@ -576,75 +582,75 @@ void Session :: queueMoveDown (const QSet& ids) { sendTorrentRequest ("t void Session :: queueMoveBottom (const QSet& ids) { sendTorrentRequest ("torrent-move-bottom", ids); } void -Session :: refreshActiveTorrents( ) +Session :: refreshActiveTorrents () { - tr_variant top; - tr_variantInitDict( &top, 3 ); - tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get ); - tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SOME_TORRENTS ); - tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ) ); - tr_variantDictAddStr( args, TR_KEY_ids, "recently-active" ); - addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys( ) ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + tr_variantInitDict (&top, 3); + tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get); + tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SOME_TORRENTS); + tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2)); + tr_variantDictAddStr (args, TR_KEY_ids, "recently-active"); + addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys ()); + exec (&top); + tr_variantFree (&top); } void -Session :: refreshAllTorrents( ) +Session :: refreshAllTorrents () { - tr_variant top; - tr_variantInitDict( &top, 3 ); - tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get ); - tr_variantDictAddInt( &top, TR_KEY_tag, TAG_ALL_TORRENTS ); - tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 1 ) ); - addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys( ) ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + tr_variantInitDict (&top, 3); + tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_get); + tr_variantDictAddInt (&top, TR_KEY_tag, TAG_ALL_TORRENTS); + tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 1)); + addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys ()); + exec (&top); + tr_variantFree (&top); } void -Session :: initTorrents( const QSet& ids ) +Session :: initTorrents (const QSet& ids) { - tr_variant top; - const int tag( ids.isEmpty() ? TAG_ALL_TORRENTS : TAG_SOME_TORRENTS ); - tr_variant * args( buildRequest( "torrent-get", top, tag ) ); - addOptionalIds( args, ids ); - addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys()+getInfoKeys() ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + const int tag (ids.isEmpty () ? TAG_ALL_TORRENTS : TAG_SOME_TORRENTS); + tr_variant * args (buildRequest ("torrent-get", top, tag)); + addOptionalIds (args, ids); + addList (tr_variantDictAddList (args, TR_KEY_fields, 0), getStatKeys ()+getInfoKeys ()); + exec (&top); + tr_variantFree (&top); } void -Session :: refreshSessionStats( ) +Session :: refreshSessionStats () { - tr_variant top; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddStr( &top, TR_KEY_method, "session-stats" ); - tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SESSION_STATS ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + tr_variantInitDict (&top, 2); + tr_variantDictAddStr (&top, TR_KEY_method, "session-stats"); + tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SESSION_STATS); + exec (&top); + tr_variantFree (&top); } void -Session :: refreshSessionInfo( ) +Session :: refreshSessionInfo () { - tr_variant top; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddStr( &top, TR_KEY_method, "session-get" ); - tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SESSION_INFO ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + tr_variantInitDict (&top, 2); + tr_variantDictAddStr (&top, TR_KEY_method, "session-get"); + tr_variantDictAddInt (&top, TR_KEY_tag, TAG_SESSION_INFO); + exec (&top); + tr_variantFree (&top); } void -Session :: updateBlocklist( ) +Session :: updateBlocklist () { - tr_variant top; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddStr( &top, TR_KEY_method, "blocklist-update" ); - tr_variantDictAddInt( &top, TR_KEY_tag, TAG_BLOCKLIST_UPDATE ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top; + tr_variantInitDict (&top, 2); + tr_variantDictAddStr (&top, TR_KEY_method, "blocklist-update"); + tr_variantDictAddInt (&top, TR_KEY_tag, TAG_BLOCKLIST_UPDATE); + exec (&top); + tr_variantFree (&top); } /*** @@ -652,154 +658,155 @@ Session :: updateBlocklist( ) ***/ void -Session :: exec( const tr_variant * request ) +Session :: exec (const tr_variant * request) { - char * str = tr_variantToStr( request, TR_VARIANT_FMT_JSON_LEAN, NULL ); - exec( str ); - tr_free( str ); + char * str = tr_variantToStr (request, TR_VARIANT_FMT_JSON_LEAN, NULL); + exec (str); + tr_free (str); } void -Session :: localSessionCallback( tr_session * s, struct evbuffer * json, void * vself ) +Session :: localSessionCallback (tr_session * s, struct evbuffer * json, void * vself) { Q_UNUSED (s); - Session * self = static_cast(vself); + Session * self = static_cast (vself); /* this callback is invoked in the libtransmission thread, so we don't want to process the response here... let's push it over to the Qt thread. */ - self->responseReceived (QByteArray ((const char *)evbuffer_pullup (json, -1), - (int)evbuffer_get_length (json))); + self->responseReceived (QByteArray ( (const char *)evbuffer_pullup (json, -1), + (int)evbuffer_get_length (json))); } #define REQUEST_DATA_PROPERTY_KEY "requestData" void -Session :: exec( const char * json ) +Session :: exec (const char * json) { - if( mySession ) + if (mySession ) { - tr_rpc_request_exec_json( mySession, json, strlen( json ), localSessionCallback, this ); + tr_rpc_request_exec_json (mySession, json, strlen (json), localSessionCallback, this); } - else if( !myUrl.isEmpty( ) ) + else if (!myUrl.isEmpty ()) { - QNetworkRequest request; - request.setUrl( myUrl ); - request.setRawHeader( "User-Agent", QString( QCoreApplication::instance()->applicationName() + "/" + LONG_VERSION_STRING ).toAscii() ); - request.setRawHeader( "Content-Type", "application/json; charset=UTF-8" ); - if( !mySessionId.isEmpty( ) ) - request.setRawHeader( TR_RPC_SESSION_ID_HEADER, mySessionId.toAscii() ); + QNetworkRequest request; + request.setUrl (myUrl); + request.setRawHeader ("User-Agent", QString (QCoreApplication::instance ()->applicationName () + "/" + LONG_VERSION_STRING).toAscii ()); + request.setRawHeader ("Content-Type", "application/json; charset=UTF-8"); - const QByteArray requestData( json ); - QNetworkReply * reply = networkAccessManager()->post( request, requestData ); - reply->setProperty( REQUEST_DATA_PROPERTY_KEY, requestData ); - connect( reply, SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(dataReadProgress())); - connect( reply, SIGNAL(uploadProgress(qint64,qint64)), this, SIGNAL(dataSendProgress())); + if (!mySessionId.isEmpty ()) + request.setRawHeader (TR_RPC_SESSION_ID_HEADER, mySessionId.toAscii ()); + + const QByteArray requestData (json); + QNetworkReply * reply = networkAccessManager ()->post (request, requestData); + reply->setProperty (REQUEST_DATA_PROPERTY_KEY, requestData); + connect (reply, SIGNAL (downloadProgress (qint64,qint64)), this, SIGNAL (dataReadProgress ())); + connect (reply, SIGNAL (uploadProgress (qint64,qint64)), this, SIGNAL (dataSendProgress ())); #ifdef DEBUG_HTTP - std::cerr << "sending " << "POST " << qPrintable( myUrl.path() ) << std::endl; - foreach( QByteArray b, request.rawHeaderList() ) - std::cerr << b.constData() - << ": " - << request.rawHeader( b ).constData() - << std::endl; - std::cerr << "Body:\n" << json << std::endl; + std::cerr << "sending " << "POST " << qPrintable (myUrl.path ()) << std::endl; + foreach (QByteArray b, request.rawHeaderList ()) + std::cerr << b.constData () + << ": " + << request.rawHeader (b).constData () + << std::endl; + std::cerr << "Body:\n" << json << std::endl; #endif } } void -Session :: onFinished( QNetworkReply * reply ) +Session :: onFinished (QNetworkReply * reply) { #ifdef DEBUG_HTTP std::cerr << "http response header: " << std::endl; - foreach( QByteArray b, reply->rawHeaderList() ) - std::cerr << b.constData() + foreach (QByteArray b, reply->rawHeaderList ()) + std::cerr << b.constData () << ": " - << reply->rawHeader( b ).constData() + << reply->rawHeader (b).constData () << std::endl; - std::cerr << "json:\n" << reply->peek( reply->bytesAvailable() ).constData() << std::endl; + std::cerr << "json:\n" << reply->peek (reply->bytesAvailable ()).constData () << std::endl; #endif - if( ( reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt() == 409 ) - && ( reply->hasRawHeader( TR_RPC_SESSION_ID_HEADER ) ) ) + if ( (reply->attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt () == 409) + && (reply->hasRawHeader (TR_RPC_SESSION_ID_HEADER))) { // we got a 409 telling us our session id has expired. // update it and resubmit the request. - mySessionId = QString( reply->rawHeader( TR_RPC_SESSION_ID_HEADER ) ); - exec( reply->property( REQUEST_DATA_PROPERTY_KEY ).toByteArray( ).constData( ) ); + mySessionId = QString (reply->rawHeader (TR_RPC_SESSION_ID_HEADER)); + exec (reply->property (REQUEST_DATA_PROPERTY_KEY).toByteArray ().constData ()); } - else if( reply->error() != QNetworkReply::NoError ) + else if (reply->error () != QNetworkReply::NoError) { - std::cerr << "http error: " << qPrintable( reply->errorString() ) << std::endl; + std::cerr << "http error: " << qPrintable (reply->errorString ()) << std::endl; } else { - const QByteArray response( reply->readAll() ); - const char * json( response.constData( ) ); - int jsonLength( response.size( ) ); - if( jsonLength>0 && json[jsonLength-1] == '\n' ) --jsonLength; - parseResponse( json, jsonLength ); + const QByteArray response (reply->readAll ()); + const char * json (response.constData ()); + int jsonLength (response.size ()); + if (jsonLength>0 && json[jsonLength-1] == '\n') --jsonLength; + parseResponse (json, jsonLength); } - reply->deleteLater(); + reply->deleteLater (); } void Session :: onResponseReceived (const QByteArray& utf8) { - parseResponse (utf8.constData(), utf8.length()); + parseResponse (utf8.constData (), utf8.length ()); } void -Session :: parseResponse( const char * json, size_t jsonLength ) +Session :: parseResponse (const char * json, size_t jsonLength) { tr_variant top; const int err (tr_variantFromJson (&top, json, jsonLength)); - if( !err ) + if (!err) { int64_t tag = -1; const char * result = NULL; tr_variant * args = NULL; - tr_variantDictFindInt ( &top, TR_KEY_tag, &tag ); - tr_variantDictFindStr ( &top, TR_KEY_result, &result, NULL ); - tr_variantDictFindDict( &top, TR_KEY_arguments, &args ); + tr_variantDictFindInt (&top, TR_KEY_tag, &tag); + tr_variantDictFindStr (&top, TR_KEY_result, &result, NULL); + tr_variantDictFindDict (&top, TR_KEY_arguments, &args); - emit executed( tag, result, args ); + emit executed (tag, result, args); tr_variant * torrents; const char * str; - if( tr_variantDictFindInt( &top, TR_KEY_tag, &tag ) ) + if (tr_variantDictFindInt (&top, TR_KEY_tag, &tag)) { - switch( tag ) + switch (tag) { case TAG_SOME_TORRENTS: case TAG_ALL_TORRENTS: - if( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ) ) { - if( tr_variantDictFindList( args, TR_KEY_torrents, &torrents ) ) - emit torrentsUpdated( torrents, tag==TAG_ALL_TORRENTS ); - if( tr_variantDictFindList( args, TR_KEY_removed, &torrents ) ) - emit torrentsRemoved( torrents ); + if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) { + if (tr_variantDictFindList (args, TR_KEY_torrents, &torrents)) + emit torrentsUpdated (torrents, tag==TAG_ALL_TORRENTS); + if (tr_variantDictFindList (args, TR_KEY_removed, &torrents)) + emit torrentsRemoved (torrents); } break; case TAG_SESSION_STATS: - if( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ) ) - updateStats( args ); + if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) + updateStats (args); break; case TAG_SESSION_INFO: - if( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ) ) - updateInfo( args ); + if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) + updateInfo (args); break; case TAG_BLOCKLIST_UPDATE: { int64_t intVal = 0; - if( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ) ) - if( tr_variantDictFindInt( args, TR_KEY_blocklist_size, &intVal ) ) - setBlocklistSize( intVal ); + if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) + if (tr_variantDictFindInt (args, TR_KEY_blocklist_size, &intVal)) + setBlocklistSize (intVal); break; } @@ -807,26 +814,26 @@ Session :: parseResponse( const char * json, size_t jsonLength ) { int64_t id = 0; const char * result = 0; - if( tr_variantDictFindStr (&top, TR_KEY_result, &result, 0) && strcmp (result, "success") ) + if (tr_variantDictFindStr (&top, TR_KEY_result, &result, 0) && strcmp (result, "success")) { const char * path = ""; const char * name = ""; tr_variantDictFindStr (args, TR_KEY_path, &path, 0); tr_variantDictFindStr (args, TR_KEY_name, &name, 0); - const QString title = tr("Error Renaming Path"); - const QString text = tr("

Unable to rename \"%1\" as \"%2\": %3.

Please correct the errors and try again.

").arg(path).arg(name).arg(result); - QMessageBox * d = new QMessageBox( QMessageBox::Information, title, text, + const QString title = tr ("Error Renaming Path"); + const QString text = tr ("

Unable to rename \"%1\" as \"%2\": %3.

Please correct the errors and try again.

").arg (path).arg (name).arg (result); + QMessageBox * d = new QMessageBox (QMessageBox::Information, title, text, QMessageBox::Close, - QApplication::activeWindow()); - connect( d, SIGNAL(rejected()), d, SLOT(deleteLater()) ); - d->show( ); + QApplication::activeWindow ()); + connect (d, SIGNAL (rejected ()), d, SLOT (deleteLater ())); + d->show (); } else if (tr_variantDictFindInt (args, TR_KEY_id, &id) && id) { // let's get the updated file list char * req = tr_strdup_printf ("{ \"arguments\": { \"fields\": [ \"fileStats\", \"files\", \"id\", \"name\" ], \"ids\": %d }, \"method\": \"torrent-get\", \"tag\": %d }", - int(id), - int(TAG_SOME_TORRENTS)); + int (id), + int (TAG_SOME_TORRENTS)); exec (req); tr_free (req); } @@ -836,9 +843,9 @@ Session :: parseResponse( const char * json, size_t jsonLength ) case TAG_PORT_TEST: { bool isOpen = 0; - if( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ) ) - tr_variantDictFindBool( args, TR_KEY_port_is_open, &isOpen ); - emit portTested( (bool)isOpen ); + if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) + tr_variantDictFindBool (args, TR_KEY_port_is_open, &isOpen); + emit portTested ( (bool)isOpen); break; } @@ -847,24 +854,24 @@ Session :: parseResponse( const char * json, size_t jsonLength ) tr_variant * torrents; tr_variant * child; const char * str; - if( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ) - && tr_variantDictFindList( args, TR_KEY_torrents, &torrents ) - && (( child = tr_variantListChild( torrents, 0 ))) - && tr_variantDictFindStr( child, TR_KEY_magnetLink, &str, NULL ) ) - QApplication::clipboard()->setText( str ); + if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args) + && tr_variantDictFindList (args, TR_KEY_torrents, &torrents) + && ( (child = tr_variantListChild (torrents, 0))) + && tr_variantDictFindStr (child, TR_KEY_magnetLink, &str, NULL)) + QApplication::clipboard ()->setText (str); break; } case TAG_ADD_TORRENT: str = ""; - if( tr_variantDictFindStr( &top, TR_KEY_result, &str, NULL ) && strcmp( str, "success" ) ) { - QMessageBox * d = new QMessageBox( QMessageBox::Information, - tr( "Add Torrent" ), - QString::fromUtf8(str), + if (tr_variantDictFindStr (&top, TR_KEY_result, &str, NULL) && strcmp (str, "success")) { + QMessageBox * d = new QMessageBox (QMessageBox::Information, + tr ("Add Torrent"), + QString::fromUtf8 (str), QMessageBox::Close, - QApplication::activeWindow()); - connect( d, SIGNAL(rejected()), d, SLOT(deleteLater()) ); - d->show( ); + QApplication::activeWindow ()); + connect (d, SIGNAL (rejected ()), d, SLOT (deleteLater ())); + d->show (); } break; @@ -872,42 +879,41 @@ Session :: parseResponse( const char * json, size_t jsonLength ) break; } } - tr_variantFree( &top ); + tr_variantFree (&top); } } void -Session :: updateStats( tr_variant * d, struct tr_session_stats * stats ) +Session :: updateStats (tr_variant * d, struct tr_session_stats * stats) { - int64_t i; + int64_t i; - if( tr_variantDictFindInt( d, TR_KEY_uploadedBytes, &i ) ) - stats->uploadedBytes = i; - if( tr_variantDictFindInt( d, TR_KEY_downloadedBytes, &i ) ) - stats->downloadedBytes = i; - if( tr_variantDictFindInt( d, TR_KEY_filesAdded, &i ) ) - stats->filesAdded = i; - if( tr_variantDictFindInt( d, TR_KEY_sessionCount, &i ) ) - stats->sessionCount = i; - if( tr_variantDictFindInt( d, TR_KEY_secondsActive, &i ) ) - stats->secondsActive = i; - - stats->ratio = tr_getRatio( stats->uploadedBytes, stats->downloadedBytes ); + if (tr_variantDictFindInt (d, TR_KEY_uploadedBytes, &i)) + stats->uploadedBytes = i; + if (tr_variantDictFindInt (d, TR_KEY_downloadedBytes, &i)) + stats->downloadedBytes = i; + if (tr_variantDictFindInt (d, TR_KEY_filesAdded, &i)) + stats->filesAdded = i; + if (tr_variantDictFindInt (d, TR_KEY_sessionCount, &i)) + stats->sessionCount = i; + if (tr_variantDictFindInt (d, TR_KEY_secondsActive, &i)) + stats->secondsActive = i; + stats->ratio = tr_getRatio (stats->uploadedBytes, stats->downloadedBytes); } void -Session :: updateStats( tr_variant * d ) +Session :: updateStats (tr_variant * d) { - tr_variant * c; + tr_variant * c; - if( tr_variantDictFindDict( d, TR_KEY_current_stats, &c ) ) - updateStats( c, &myStats ); + if (tr_variantDictFindDict (d, TR_KEY_current_stats, &c)) + updateStats (c, &myStats); - if( tr_variantDictFindDict( d, TR_KEY_cumulative_stats, &c ) ) - updateStats( c, &myCumulativeStats ); + if (tr_variantDictFindDict (d, TR_KEY_cumulative_stats, &c)) + updateStats (c, &myCumulativeStats); - emit statsUpdated( ); + emit statsUpdated (); } void @@ -916,11 +922,11 @@ Session :: updateInfo (tr_variant * d) int64_t i; const char * str; - disconnect (&myPrefs, SIGNAL(changed(int)), this, SLOT(updatePref(int))); + disconnect (&myPrefs, SIGNAL (changed (int)), this, SLOT (updatePref (int))); for (int i=Prefs::FIRST_CORE_PREF; i<=Prefs::LAST_CORE_PREF; ++i) { - const tr_variant * b( tr_variantDictFind (d, myPrefs.getKey(i))); + const tr_variant * b (tr_variantDictFind (d, myPrefs.getKey (i))); if (!b) continue; @@ -928,174 +934,192 @@ Session :: updateInfo (tr_variant * d) if (i == Prefs :: ENCRYPTION) { const char * val; - if( tr_variantGetStr( b, &val, NULL ) ) + if (tr_variantGetStr (b, &val, NULL)) { - if( !qstrcmp( val , "required" ) ) - myPrefs.set( i, 2 ); - else if( !qstrcmp( val , "preferred" ) ) - myPrefs.set( i, 1 ); - else if( !qstrcmp( val , "tolerated" ) ) - myPrefs.set( i, 0 ); + if (!qstrcmp (val , "required")) + myPrefs.set (i, 2); + else if (!qstrcmp (val , "preferred")) + myPrefs.set (i, 1); + else if (!qstrcmp (val , "tolerated")) + myPrefs.set (i, 0); } continue; } - switch( myPrefs.type( i ) ) + switch (myPrefs.type (i)) { - case QVariant :: Int: { - int64_t val; - if( tr_variantGetInt( b, &val ) ) - myPrefs.set( i, (int)val ); - break; + case QVariant :: Int: + { + int64_t val; + if (tr_variantGetInt (b, &val)) + myPrefs.set (i, (int)val); + break; } - case QVariant :: Double: { - double val; - if( tr_variantGetReal( b, &val ) ) - myPrefs.set( i, val ); - break; + case QVariant :: Double: + { + double val; + if (tr_variantGetReal (b, &val)) + myPrefs.set (i, val); + break; } - case QVariant :: Bool: { - bool val; - if( tr_variantGetBool( b, &val ) ) - myPrefs.set( i, (bool)val ); - break; + case QVariant :: Bool: + { + bool val; + if (tr_variantGetBool (b, &val)) + myPrefs.set (i, (bool)val); + break; } - case TrTypes :: FilterModeType: - case TrTypes :: SortModeType: - case QVariant :: String: { - const char * val; - if( tr_variantGetStr( b, &val, NULL ) ) - myPrefs.set( i, QString(val) ); - break; + case TrTypes :: FilterModeType: + case TrTypes :: SortModeType: + case QVariant :: String: + { + const char * val; + if (tr_variantGetStr (b, &val, NULL)) + myPrefs.set (i, QString (val)); + break; } - default: - break; + default: + break; } } - bool b; - double x; - if( tr_variantDictFindBool( d, TR_KEY_seedRatioLimited, &b ) ) - myPrefs.set( Prefs::RATIO_ENABLED, b ? true : false ); - if( tr_variantDictFindReal( d, TR_KEY_seedRatioLimit, &x ) ) - myPrefs.set( Prefs::RATIO, x ); + bool b; + double x; + if (tr_variantDictFindBool (d, TR_KEY_seedRatioLimited, &b)) + myPrefs.set (Prefs::RATIO_ENABLED, b ? true : false); + if (tr_variantDictFindReal (d, TR_KEY_seedRatioLimit, &x)) + myPrefs.set (Prefs::RATIO, x); - /* Use the C API to get settings that, for security reasons, aren't supported by RPC */ - if( mySession != 0 ) + /* Use the C API to get settings that, for security reasons, aren't supported by RPC */ + if (mySession != 0) { - myPrefs.set( Prefs::RPC_ENABLED, tr_sessionIsRPCEnabled ( mySession ) ); - myPrefs.set( Prefs::RPC_AUTH_REQUIRED, tr_sessionIsRPCPasswordEnabled ( mySession ) ); - myPrefs.set( Prefs::RPC_PASSWORD, tr_sessionGetRPCPassword ( mySession ) ); - myPrefs.set( Prefs::RPC_PORT, tr_sessionGetRPCPort ( mySession ) ); - myPrefs.set( Prefs::RPC_USERNAME, tr_sessionGetRPCUsername ( mySession ) ); - myPrefs.set( Prefs::RPC_WHITELIST_ENABLED, tr_sessionGetRPCWhitelistEnabled ( mySession ) ); - myPrefs.set( Prefs::RPC_WHITELIST, tr_sessionGetRPCWhitelist ( mySession ) ); + myPrefs.set (Prefs::RPC_ENABLED, tr_sessionIsRPCEnabled (mySession)); + myPrefs.set (Prefs::RPC_AUTH_REQUIRED, tr_sessionIsRPCPasswordEnabled (mySession)); + myPrefs.set (Prefs::RPC_PASSWORD, tr_sessionGetRPCPassword (mySession)); + myPrefs.set (Prefs::RPC_PORT, tr_sessionGetRPCPort (mySession)); + myPrefs.set (Prefs::RPC_USERNAME, tr_sessionGetRPCUsername (mySession)); + myPrefs.set (Prefs::RPC_WHITELIST_ENABLED, tr_sessionGetRPCWhitelistEnabled (mySession)); + myPrefs.set (Prefs::RPC_WHITELIST, tr_sessionGetRPCWhitelist (mySession)); } - if( tr_variantDictFindInt( d, TR_KEY_blocklist_size, &i ) && i!=blocklistSize( ) ) - setBlocklistSize( i ); + if (tr_variantDictFindInt (d, TR_KEY_blocklist_size, &i) && i!=blocklistSize ()) + setBlocklistSize (i); - if( tr_variantDictFindStr( d, TR_KEY_version, &str, NULL ) && ( mySessionVersion != str ) ) - mySessionVersion = str; + if (tr_variantDictFindStr (d, TR_KEY_version, &str, NULL) && (mySessionVersion != str)) + mySessionVersion = str; - if( tr_variantDictFindInt( d, TR_KEY_download_dir_free_space, &i ) && ( myDownloadDirFreeSpace != i ) ) - myDownloadDirFreeSpace = i; + if (tr_variantDictFindInt (d, TR_KEY_download_dir_free_space, &i) && (myDownloadDirFreeSpace != i)) + myDownloadDirFreeSpace = i; - //std::cerr << "Session :: updateInfo end" << std::endl; - connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(updatePref(int)) ); + //std::cerr << "Session :: updateInfo end" << std::endl; + connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (updatePref (int))); - emit sessionUpdated( ); + emit sessionUpdated (); } void -Session :: setBlocklistSize( int64_t i ) +Session :: setBlocklistSize (int64_t i) { - myBlocklistSize = i; + myBlocklistSize = i; - emit blocklistUpdated( i ); + emit blocklistUpdated (i); } void -Session :: addTorrent( const AddData& addMe ) +Session :: addTorrent (const AddData& addMe) { - const QByteArray b64 = addMe.toBase64(); + const QByteArray b64 = addMe.toBase64 (); - tr_variant top, *args; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddStr( &top, TR_KEY_method, "torrent-add" ); - args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ); - tr_variantDictAddBool( args, TR_KEY_paused, !myPrefs.getBool( Prefs::START ) ); - switch( addMe.type ) { - case AddData::MAGNET: tr_variantDictAddStr( args, TR_KEY_filename, addMe.magnet.toUtf8().constData() ); break; - case AddData::URL: tr_variantDictAddStr( args, TR_KEY_filename, addMe.url.toString().toUtf8().constData() ); break; - case AddData::FILENAME: /* fall-through */ - case AddData::METAINFO: tr_variantDictAddRaw( args, TR_KEY_metainfo, b64.constData(), b64.size() ); break; - default: std::cerr << "Unhandled AddData type: " << addMe.type << std::endl; - } - exec( &top ); - tr_variantFree( &top ); -} + tr_variant top, *args; + tr_variantInitDict (&top, 2); + tr_variantDictAddStr (&top, TR_KEY_method, "torrent-add"); + args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); + tr_variantDictAddBool (args, TR_KEY_paused, !myPrefs.getBool (Prefs::START)); -void -Session :: addNewlyCreatedTorrent( const QString& filename, const QString& localPath ) -{ - const QByteArray b64 = AddData(filename).toBase64(); - const QByteArray localPathUtf8 = localPath.toUtf8(); - - tr_variant top, *args; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddStr( &top, TR_KEY_method, "torrent-add" ); - args = tr_variantDictAddDict( &top, TR_KEY_arguments, 3 ); - tr_variantDictAddStr( args, TR_KEY_download_dir, localPathUtf8.constData() ); - tr_variantDictAddBool( args, TR_KEY_paused, !myPrefs.getBool( Prefs::START ) ); - tr_variantDictAddRaw( args, TR_KEY_metainfo, b64.constData(), b64.size() ); - exec( &top ); - tr_variantFree( &top ); -} - -void -Session :: removeTorrents( const QSet& ids, bool deleteFiles ) -{ - if( !ids.isEmpty( ) ) + switch (addMe.type) { - tr_variant top, *args; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddStr( &top, TR_KEY_method, "torrent-remove" ); - args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ); - addOptionalIds( args, ids ); - tr_variantDictAddInt( args, TR_KEY_delete_local_data, deleteFiles ); - exec( &top ); - tr_variantFree( &top ); + case AddData::MAGNET: + tr_variantDictAddStr (args, TR_KEY_filename, addMe.magnet.toUtf8 ().constData ()); + break; + + case AddData::URL: + tr_variantDictAddStr (args, TR_KEY_filename, addMe.url.toString ().toUtf8 ().constData ()); + break; + + case AddData::FILENAME: /* fall-through */ + case AddData::METAINFO: + tr_variantDictAddRaw (args, TR_KEY_metainfo, b64.constData (), b64.size ()); + break; + + default: + std::cerr << "Unhandled AddData type: " << addMe.type << std::endl; + break; + } + + exec (&top); + tr_variantFree (&top); +} + +void +Session :: addNewlyCreatedTorrent (const QString& filename, const QString& localPath) +{ + const QByteArray b64 = AddData (filename).toBase64 (); + const QByteArray localPathUtf8 = localPath.toUtf8 (); + + tr_variant top, *args; + tr_variantInitDict (&top, 2); + tr_variantDictAddStr (&top, TR_KEY_method, "torrent-add"); + args = tr_variantDictAddDict (&top, TR_KEY_arguments, 3); + tr_variantDictAddStr (args, TR_KEY_download_dir, localPathUtf8.constData ()); + tr_variantDictAddBool (args, TR_KEY_paused, !myPrefs.getBool (Prefs::START)); + tr_variantDictAddRaw (args, TR_KEY_metainfo, b64.constData (), b64.size ()); + exec (&top); + tr_variantFree (&top); +} + +void +Session :: removeTorrents (const QSet& ids, bool deleteFiles) +{ + if (!ids.isEmpty ()) + { + tr_variant top, *args; + tr_variantInitDict (&top, 2); + tr_variantDictAddStr (&top, TR_KEY_method, "torrent-remove"); + args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2); + addOptionalIds (args, ids); + tr_variantDictAddInt (args, TR_KEY_delete_local_data, deleteFiles); + exec (&top); + tr_variantFree (&top); } } void -Session :: verifyTorrents( const QSet& ids ) +Session :: verifyTorrents (const QSet& ids) { - if( !ids.isEmpty( ) ) + if (!ids.isEmpty ()) { - tr_variant top, *args; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddStr( &top, TR_KEY_method, "torrent-verify" ); - args = tr_variantDictAddDict( &top, TR_KEY_arguments, 1 ); - addOptionalIds( args, ids ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top, *args; + tr_variantInitDict (&top, 2); + tr_variantDictAddStr (&top, TR_KEY_method, "torrent-verify"); + args = tr_variantDictAddDict (&top, TR_KEY_arguments, 1); + addOptionalIds (args, ids); + exec (&top); + tr_variantFree (&top); } } void -Session :: reannounceTorrents( const QSet& ids ) +Session :: reannounceTorrents (const QSet& ids) { - if( !ids.isEmpty( ) ) + if (!ids.isEmpty ()) { - tr_variant top, *args; - tr_variantInitDict( &top, 2 ); - tr_variantDictAddStr( &top, TR_KEY_method, "torrent-reannounce" ); - args = tr_variantDictAddDict( &top, TR_KEY_arguments, 1 ); - addOptionalIds( args, ids ); - exec( &top ); - tr_variantFree( &top ); + tr_variant top, *args; + tr_variantInitDict (&top, 2); + tr_variantDictAddStr (&top, TR_KEY_method, "torrent-reannounce"); + args = tr_variantDictAddDict (&top, TR_KEY_arguments, 1); + addOptionalIds (args, ids); + exec (&top); + tr_variantFree (&top); } } @@ -1104,19 +1128,21 @@ Session :: reannounceTorrents( const QSet& ids ) ***/ void -Session :: launchWebInterface( ) +Session :: launchWebInterface () { - QUrl url; - if( !mySession ) // remote session + QUrl url; + + if (!mySession) // remote session { - url = myUrl; - url.setPath( "/transmission/web/" ); + url = myUrl; + url.setPath ("/transmission/web/"); } - else // local session + else // local session { - url.setScheme( "http" ); - url.setHost( "localhost" ); - url.setPort( myPrefs.getInt( Prefs::RPC_PORT ) ); + url.setScheme ("http"); + url.setHost ("localhost"); + url.setPort (myPrefs.getInt (Prefs::RPC_PORT)); } - QDesktopServices :: openUrl( url ); + + QDesktopServices :: openUrl (url); } diff --git a/qt/session.h b/qt/session.h index b947b8224..fb905c352 100644 --- a/qt/session.h +++ b/qt/session.h @@ -31,136 +31,136 @@ class AddData; extern "C" { - struct evbuffer; - struct tr_variant; + struct evbuffer; + struct tr_variant; } class Prefs; class Session: public QObject { - Q_OBJECT + Q_OBJECT - public: - Session( const char * configDir, Prefs& prefs ); - ~Session( ); + public: + Session (const char * configDir, Prefs& prefs); + ~Session (); - public: - void stop( ); - void restart( ); + public: + void stop (); + void restart (); - private: - void start( ); + private: + void start (); - public: - const QUrl& getRemoteUrl( ) const { return myUrl; } - const struct tr_session_stats& getStats( ) const { return myStats; } - const struct tr_session_stats& getCumulativeStats( ) const { return myCumulativeStats; } - const QString& sessionVersion( ) const { return mySessionVersion; } - int64_t downloadDirFreeSpace( ) const { return myDownloadDirFreeSpace; } + public: + const QUrl& getRemoteUrl () const { return myUrl; } + const struct tr_session_stats& getStats () const { return myStats; } + const struct tr_session_stats& getCumulativeStats () const { return myCumulativeStats; } + const QString& sessionVersion () const { return mySessionVersion; } + int64_t downloadDirFreeSpace () const { return myDownloadDirFreeSpace; } - public: - int64_t blocklistSize( ) const { return myBlocklistSize; } - void setBlocklistSize( int64_t i ); - void updateBlocklist( ); - void portTest( ); - void copyMagnetLinkToClipboard( int torrentId ); + public: + int64_t blocklistSize () const { return myBlocklistSize; } + void setBlocklistSize (int64_t i); + void updateBlocklist (); + void portTest (); + void copyMagnetLinkToClipboard (int torrentId); - public: + public: - /** returns true if the transmission session is being run inside this client */ - bool isServer( ) const; + /** returns true if the transmission session is being run inside this client */ + bool isServer () const; - /** returns true if isServer() is true or if the remote address is the localhost */ - bool isLocal( ) const; + /** returns true if isServer () is true or if the remote address is the localhost */ + bool isLocal () const; - private: - void updateStats( struct tr_variant * args ); - void updateInfo( struct tr_variant * args ); - void parseResponse( const char * json, size_t len ); - static void localSessionCallback( tr_session *, struct evbuffer *, void * ); + private: + void updateStats (struct tr_variant * args); + void updateInfo (struct tr_variant * args); + void parseResponse (const char * json, size_t len); + static void localSessionCallback (tr_session *, struct evbuffer *, void *); - public: - void exec( const char * json ); - void exec( const struct tr_variant * request ); + public: + void exec (const char * json); + void exec (const struct tr_variant * request); - public: - int64_t getUniqueTag( ) { return nextUniqueTag++; } + public: + int64_t getUniqueTag () { return nextUniqueTag++; } - private: - void sessionSet( const tr_quark key, const QVariant& variant ); - void pumpRequests( ); - void sendTorrentRequest( const char * request, const QSet& torrentIds ); - static void updateStats( struct tr_variant * d, struct tr_session_stats * stats ); - void refreshTorrents( const QSet& torrentIds ); - QNetworkAccessManager * networkAccessManager( ); + private: + void sessionSet (const tr_quark key, const QVariant& variant); + void pumpRequests (); + void sendTorrentRequest (const char * request, const QSet& torrentIds); + static void updateStats (struct tr_variant * d, struct tr_session_stats * stats); + void refreshTorrents (const QSet& torrentIds); + QNetworkAccessManager * networkAccessManager (); - public: - void torrentSet( const QSet& ids, const tr_quark key, bool val ); - void torrentSet( const QSet& ids, const tr_quark key, int val ); - void torrentSet( const QSet& ids, const tr_quark key, double val ); - void torrentSet( const QSet& ids, const tr_quark key, const QList& val ); - void torrentSet( const QSet& ids, const tr_quark key, const QStringList& val ); - void torrentSet( const QSet& ids, const tr_quark key, const QPair& val); - void torrentSetLocation( const QSet& ids, const QString& path, bool doMove ); - void torrentRenamePath( const QSet& ids, const QString& oldpath, const QString& newname ); + public: + void torrentSet (const QSet& ids, const tr_quark key, bool val); + void torrentSet (const QSet& ids, const tr_quark key, int val); + void torrentSet (const QSet& ids, const tr_quark key, double val); + void torrentSet (const QSet& ids, const tr_quark key, const QList& val); + void torrentSet (const QSet& ids, const tr_quark key, const QStringList& val); + void torrentSet (const QSet& ids, const tr_quark key, const QPair& val); + void torrentSetLocation (const QSet& ids, const QString& path, bool doMove); + void torrentRenamePath (const QSet& ids, const QString& oldpath, const QString& newname); - public slots: - void pauseTorrents( const QSet& torrentIds = QSet() ); - void startTorrents( const QSet& torrentIds = QSet() ); - void startTorrentsNow( const QSet& torrentIds = QSet() ); - void queueMoveTop( const QSet& torrentIds = QSet() ); - void queueMoveUp( const QSet& torrentIds = QSet() ); - void queueMoveDown( const QSet& torrentIds = QSet() ); - void queueMoveBottom( const QSet& torrentIds = QSet() ); - void refreshSessionInfo( ); - void refreshSessionStats( ); - void refreshActiveTorrents( ); - void refreshAllTorrents( ); - void initTorrents( const QSet& ids = QSet() ); - void addNewlyCreatedTorrent( const QString& filename, const QString& localPath ); - void addTorrent( const AddData& addme ); - void removeTorrents( const QSet& torrentIds, bool deleteFiles=false ); - void verifyTorrents( const QSet& torrentIds ); - void reannounceTorrents( const QSet& torrentIds ); - void launchWebInterface( ); - void updatePref( int key ); + public slots: + void pauseTorrents (const QSet& torrentIds = QSet ()); + void startTorrents (const QSet& torrentIds = QSet ()); + void startTorrentsNow (const QSet& torrentIds = QSet ()); + void queueMoveTop (const QSet& torrentIds = QSet ()); + void queueMoveUp (const QSet& torrentIds = QSet ()); + void queueMoveDown (const QSet& torrentIds = QSet ()); + void queueMoveBottom (const QSet& torrentIds = QSet ()); + void refreshSessionInfo (); + void refreshSessionStats (); + void refreshActiveTorrents (); + void refreshAllTorrents (); + void initTorrents (const QSet& ids = QSet ()); + void addNewlyCreatedTorrent (const QString& filename, const QString& localPath); + void addTorrent (const AddData& addme); + void removeTorrents (const QSet& torrentIds, bool deleteFiles=false); + void verifyTorrents (const QSet& torrentIds); + void reannounceTorrents (const QSet& torrentIds); + void launchWebInterface (); + void updatePref (int key); - /** request a refresh for statistics, including the ones only used by the properties dialog, for a specific torrent */ - void refreshExtraStats( const QSet& ids ); + /** request a refresh for statistics, including the ones only used by the properties dialog, for a specific torrent */ + void refreshExtraStats (const QSet& ids); - private slots: - void onFinished( QNetworkReply * reply ); - void onResponseReceived (const QByteArray& json); + private slots: + void onFinished (QNetworkReply * reply); + void onResponseReceived (const QByteArray& json); - signals: - void responseReceived (const QByteArray& json); - void executed( int64_t tag, const QString& result, struct tr_variant * arguments ); - void sourceChanged( ); - void portTested( bool isOpen ); - void statsUpdated( ); - void sessionUpdated( ); - void blocklistUpdated( int ); - void torrentsUpdated( struct tr_variant * torrentList, bool completeList ); - void torrentsRemoved( struct tr_variant * torrentList ); - void dataReadProgress( ); - void dataSendProgress( ); - void httpAuthenticationRequired( ); + signals: + void responseReceived (const QByteArray& json); + void executed (int64_t tag, const QString& result, struct tr_variant * arguments); + void sourceChanged (); + void portTested (bool isOpen); + void statsUpdated (); + void sessionUpdated (); + void blocklistUpdated (int); + void torrentsUpdated (struct tr_variant * torrentList, bool completeList); + void torrentsRemoved (struct tr_variant * torrentList); + void dataReadProgress (); + void dataSendProgress (); + void httpAuthenticationRequired (); - private: - int64_t nextUniqueTag; - int64_t myBlocklistSize; - Prefs& myPrefs; - tr_session * mySession; - QString myConfigDir; - QString mySessionId; - QStringList myIdleJSON; - QUrl myUrl; - QNetworkAccessManager * myNAM; - struct tr_session_stats myStats; - struct tr_session_stats myCumulativeStats; - QString mySessionVersion; - int64_t myDownloadDirFreeSpace; + private: + int64_t nextUniqueTag; + int64_t myBlocklistSize; + Prefs& myPrefs; + tr_session * mySession; + QString myConfigDir; + QString mySessionId; + QStringList myIdleJSON; + QUrl myUrl; + QNetworkAccessManager * myNAM; + struct tr_session_stats myStats; + struct tr_session_stats myCumulativeStats; + QString mySessionVersion; + int64_t myDownloadDirFreeSpace; }; #endif diff --git a/qt/speed.h b/qt/speed.h index b37b6f3b4..3032d468b 100644 --- a/qt/speed.h +++ b/qt/speed.h @@ -17,20 +17,21 @@ class Speed { - private: - int _Bps; - Speed( int Bps ): _Bps(Bps) { } - public: - Speed( ): _Bps(0) { } - double KBps( ) const; - int Bps( ) const { return _Bps; } - bool isZero( ) const { return _Bps == 0; } - static Speed fromKBps( double KBps ); - static Speed fromBps( int Bps ) { return Speed( Bps ); } - void setBps( int Bps ) { _Bps = Bps; } - Speed& operator+=( const Speed& that ) { _Bps += that._Bps; return *this; } - Speed operator+( const Speed& that ) const { return Speed( _Bps + that._Bps ); } - bool operator<( const Speed& that ) const { return _Bps < that._Bps; } + private: + int _Bps; + Speed (int Bps): _Bps (Bps) {} + + public: + Speed (): _Bps (0) { } + double KBps () const; + int Bps () const { return _Bps; } + bool isZero () const { return _Bps == 0; } + static Speed fromKBps (double KBps); + static Speed fromBps (int Bps) { return Speed (Bps); } + void setBps (int Bps) { _Bps = Bps; } + Speed& operator+= (const Speed& that) { _Bps += that._Bps; return *this; } + Speed operator+ (const Speed& that) const { return Speed (_Bps + that._Bps); } + bool operator< (const Speed& that) const { return _Bps < that._Bps; } }; #endif diff --git a/qt/stats-dialog.cc b/qt/stats-dialog.cc index 616089271..6ce120016 100644 --- a/qt/stats-dialog.cc +++ b/qt/stats-dialog.cc @@ -22,78 +22,78 @@ enum { - REFRESH_INTERVAL_MSEC = (15*1000) + REFRESH_INTERVAL_MSEC = (15*1000) }; -StatsDialog :: StatsDialog( Session & session, QWidget * parent ): - QDialog( parent, Qt::Dialog ), - mySession( session ), - myTimer( new QTimer( this ) ) +StatsDialog :: StatsDialog (Session & session, QWidget * parent): + QDialog (parent, Qt::Dialog), + mySession (session), + myTimer (new QTimer (this)) { - myTimer->setSingleShot( false ); - connect( myTimer, SIGNAL(timeout()), this, SLOT(onTimer()) ); - setWindowTitle( tr( "Statistics" ) ); + myTimer->setSingleShot (false); + connect (myTimer, SIGNAL (timeout ()), this, SLOT (onTimer ())); + setWindowTitle (tr ("Statistics")); - HIG * hig = new HIG( ); - hig->addSectionTitle( tr( "Current Session" ) ); - hig->addRow( tr( "Uploaded:" ), myCurrentUp = new QLabel( ) ); - hig->addRow( tr( "Downloaded:" ), myCurrentDown = new QLabel( ) ); - hig->addRow( tr( "Ratio:" ), myCurrentRatio = new QLabel( ) ); - hig->addRow( tr( "Duration:" ), myCurrentDuration = new QLabel( ) ); - hig->addSectionDivider( ); - hig->addSectionTitle( tr( "Total" ) ); - hig->addRow( myStartCount = new QLabel( tr( "Started %n time(s)", 0, 1 ) ), 0 ); - hig->addRow( tr( "Uploaded:" ), myTotalUp = new QLabel( ) ); - hig->addRow( tr( "Downloaded:" ), myTotalDown = new QLabel( ) ); - hig->addRow( tr( "Ratio:" ), myTotalRatio = new QLabel( ) ); - hig->addRow( tr( "Duration:" ), myTotalDuration = new QLabel( ) ); - hig->finish( ); + HIG * hig = new HIG (); + hig->addSectionTitle (tr ("Current Session")); + hig->addRow (tr ("Uploaded:"), myCurrentUp = new QLabel ()); + hig->addRow (tr ("Downloaded:"), myCurrentDown = new QLabel ()); + hig->addRow (tr ("Ratio:"), myCurrentRatio = new QLabel ()); + hig->addRow (tr ("Duration:"), myCurrentDuration = new QLabel ()); + hig->addSectionDivider (); + hig->addSectionTitle (tr ("Total")); + hig->addRow (myStartCount = new QLabel (tr ("Started %n time (s)", 0, 1)), 0); + hig->addRow (tr ("Uploaded:"), myTotalUp = new QLabel ()); + hig->addRow (tr ("Downloaded:"), myTotalDown = new QLabel ()); + hig->addRow (tr ("Ratio:"), myTotalRatio = new QLabel ()); + hig->addRow (tr ("Duration:"), myTotalDuration = new QLabel ()); + hig->finish (); - QLayout * layout = new QVBoxLayout( this ); - layout->addWidget( hig ); - QDialogButtonBox * buttons = new QDialogButtonBox( QDialogButtonBox::Close, Qt::Horizontal, this ); - connect( buttons, SIGNAL(rejected()), this, SLOT(hide()) ); // "close" triggers rejected - layout->addWidget( buttons ); + QLayout * layout = new QVBoxLayout (this); + layout->addWidget (hig); + QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Close, Qt::Horizontal, this); + connect (buttons, SIGNAL (rejected ()), this, SLOT (hide ())); // "close" triggers rejected + layout->addWidget (buttons); - connect( &mySession, SIGNAL(statsUpdated()), this, SLOT(updateStats()) ); - updateStats( ); - mySession.refreshSessionStats( ); + connect (&mySession, SIGNAL (statsUpdated ()), this, SLOT (updateStats ())); + updateStats (); + mySession.refreshSessionStats (); } -StatsDialog :: ~StatsDialog( ) +StatsDialog :: ~StatsDialog () { } void -StatsDialog :: setVisible( bool visible ) +StatsDialog :: setVisible (bool visible) { - myTimer->stop( ); - if( visible ) - myTimer->start( REFRESH_INTERVAL_MSEC ); - QDialog::setVisible( visible ); + myTimer->stop (); + if (visible) + myTimer->start (REFRESH_INTERVAL_MSEC); + QDialog::setVisible (visible); } void -StatsDialog :: onTimer( ) +StatsDialog :: onTimer () { - mySession.refreshSessionStats( ); + mySession.refreshSessionStats (); } void -StatsDialog :: updateStats( ) +StatsDialog :: updateStats () { - const struct tr_session_stats& current( mySession.getStats( ) ); - const struct tr_session_stats& total( mySession.getCumulativeStats( ) ); + const struct tr_session_stats& current (mySession.getStats ()); + const struct tr_session_stats& total (mySession.getCumulativeStats ()); - myCurrentUp->setText( Formatter::sizeToString( current.uploadedBytes ) ); - myCurrentDown->setText( Formatter::sizeToString( current.downloadedBytes ) ); - myCurrentRatio->setText( Formatter::ratioToString( current.ratio ) ); - myCurrentDuration->setText( Formatter::timeToString( current.secondsActive ) ); + myCurrentUp->setText (Formatter::sizeToString (current.uploadedBytes)); + myCurrentDown->setText (Formatter::sizeToString (current.downloadedBytes)); + myCurrentRatio->setText (Formatter::ratioToString (current.ratio)); + myCurrentDuration->setText (Formatter::timeToString (current.secondsActive)); - myTotalUp->setText( Formatter::sizeToString( total.uploadedBytes ) ); - myTotalDown->setText( Formatter::sizeToString( total.downloadedBytes ) ); - myTotalRatio->setText( Formatter::ratioToString( total.ratio ) ); - myTotalDuration->setText( Formatter::timeToString( total.secondsActive ) ); + myTotalUp->setText (Formatter::sizeToString (total.uploadedBytes)); + myTotalDown->setText (Formatter::sizeToString (total.downloadedBytes)); + myTotalRatio->setText (Formatter::ratioToString (total.ratio)); + myTotalDuration->setText (Formatter::timeToString (total.secondsActive)); - myStartCount->setText( tr( "Started %n time(s)", 0, total.sessionCount ) ); + myStartCount->setText (tr ("Started %n time (s)", 0, total.sessionCount)); } diff --git a/qt/stats-dialog.h b/qt/stats-dialog.h index 8dc9558a2..ccd476fb2 100644 --- a/qt/stats-dialog.h +++ b/qt/stats-dialog.h @@ -21,34 +21,34 @@ class QTimer; class StatsDialog: public QDialog { - Q_OBJECT + Q_OBJECT - signals: - void accepted( ); + signals: + void accepted (); - public slots: - void updateStats( ); + public slots: + void updateStats (); - private slots: - void onTimer( ); + private slots: + void onTimer (); - public: - StatsDialog( Session&, QWidget * parent = 0 ); - ~StatsDialog( ); - virtual void setVisible( bool visible ); + public: + StatsDialog (Session&, QWidget * parent = 0); + ~StatsDialog (); + virtual void setVisible (bool visible); - private: - Session & mySession; - QTimer * myTimer; - QLabel * myCurrentUp; - QLabel * myCurrentDown; - QLabel * myCurrentRatio; - QLabel * myCurrentDuration; - QLabel * myStartCount; - QLabel * myTotalUp; - QLabel * myTotalDown; - QLabel * myTotalRatio; - QLabel * myTotalDuration; + private: + Session & mySession; + QTimer * myTimer; + QLabel * myCurrentUp; + QLabel * myCurrentDown; + QLabel * myCurrentRatio; + QLabel * myCurrentDuration; + QLabel * myStartCount; + QLabel * myTotalUp; + QLabel * myTotalDown; + QLabel * myTotalRatio; + QLabel * myTotalDuration; }; #endif