diff --git a/qt/details.cc b/qt/details.cc index c07422b93..4dedd1749 100644 --- a/qt/details.cc +++ b/qt/details.cc @@ -56,7 +56,7 @@ class Session; namespace { - const int REFRESH_INTERVAL_MSEC = 3500; + const int REFRESH_INTERVAL_MSEC = 4000; enum // peer columns { @@ -243,25 +243,12 @@ Details :: onTorrentChanged( ) mySeedersLabel->setText( locale.toString( myTorrent.seeders( ) ) ); myLeechersLabel->setText( locale.toString( myTorrent.leechers( ) ) ); myTimesCompletedLabel->setText( locale.toString( myTorrent.timesCompleted( ) ) ); - //const PeerList peers( myTorrent.peers( ) ); - PeerList peers( myTorrent.peers( ) ); -#if 0 -static double progress = 0.01; -{ -Peer peer; -peer.address = "127.0.0.1"; -peer.isEncrypted = true; -peer.progress = progress; -peer.rateToPeer = Speed::fromKbps(20); -peers << peer; -progress += 0.01; -} -#endif + const PeerList peers( myTorrent.peers( ) ); QMap peers2; QList newItems; static const QIcon myEncryptionIcon( ":/icons/encrypted.png" ); static const QIcon myEmptyIcon; - foreach( Peer peer, peers ) + foreach( const Peer& peer, peers ) { PeerItem * item = (PeerItem*) myPeers.value( peer.address, 0 ); if( item == 0 ) { // new peer has connected @@ -372,9 +359,50 @@ Details :: createActivityTab( ) ***/ void -Details :: onSessionLimitsToggled( bool b ) +Details :: onHonorsSessionLimitsToggled( bool val ) { - mySession.torrentSet( myTorrent.id(), "honorsSessionLimits", b ); + mySession.torrentSet( myTorrent.id(), "honorsSessionLimits", val ); +} +void +Details :: onDownloadLimitedToggled( bool val ) +{ + mySession.torrentSet( myTorrent.id(), "downloadLimited", val ); +} +void +Details :: onDownloadLimitChanged( int val ) +{ + mySession.torrentSet( myTorrent.id(), "downloadLimit", val ); +} +void +Details :: onUploadLimitedToggled( bool val ) +{ + mySession.torrentSet( myTorrent.id(), "uploadLimited", val ); +} +void +Details :: onUploadLimitChanged( int val ) +{ + mySession.torrentSet( myTorrent.id(), "uploadLimit", val ); +} + +#define RATIO_KEY "seedRatioMode" + +void +Details :: onSeedUntilChanged( bool b ) +{ + if( b ) + mySession.torrentSet( myTorrent.id(), RATIO_KEY, sender()->property(RATIO_KEY).toInt() ); +} + +void +Details :: onSeedRatioLimitChanged( double val ) +{ + mySession.torrentSet( myTorrent.id(), "seedRatioLimit", val ); +} + +void +Details :: onMaxPeersChanged( int val ) +{ + mySession.torrentSet( myTorrent.id(), "peer-limit", val ); } QWidget * @@ -393,7 +421,7 @@ Details :: createOptionsTab( ) c = new QCheckBox( tr( "Honor global &limits" ) ); mySessionLimitCheck = c; hig->addWideControl( c ); - connect( c, SIGNAL(toggled(bool)), this, SLOT(onSessionLimitsToggled(bool)) ); + connect( c, SIGNAL(toggled(bool)), this, SLOT(onHonorsSessionLimitsToggled(bool)) ); c = new QCheckBox( tr( "Limit &download speed (KB/s)" ) ); mySingleDownCheck = c; @@ -402,6 +430,8 @@ Details :: createOptionsTab( ) s->setRange( 0, INT_MAX ); hig->addRow( c, s ); enableWhenChecked( c, s ); + connect( c, SIGNAL(toggled(bool)), this, SLOT(onDownloadLimitedToggled(bool)) ); + connect( s, SIGNAL(valueChanged(int)), this, SLOT(onDownloadLimitChanged(int))); c = new QCheckBox( tr( "Limit &upload speed (KB/s)" ) ); mySingleUpCheck = c; @@ -410,25 +440,34 @@ Details :: createOptionsTab( ) s->setRange( 0, INT_MAX ); hig->addRow( c, s ); enableWhenChecked( c, s ); + connect( c, SIGNAL(toggled(bool)), this, SLOT(onUploadLimitedToggled(bool)) ); + connect( s, SIGNAL(valueChanged(int)), this, SLOT(onUploadLimitChanged(int))); hig->addSectionDivider( ); hig->addSectionTitle( tr( "Seed-Until Ratio" ) ); r = new QRadioButton( tr( "Use &global setting" ) ); + r->setProperty( RATIO_KEY, TR_RATIOLIMIT_GLOBAL ); + connect( r, SIGNAL(toggled(bool)), this, SLOT(onSeedUntilChanged(bool))); mySeedGlobalRadio = r; hig->addWideControl( r ); r = new QRadioButton( tr( "Seed ®ardless of ratio" ) ); + r->setProperty( RATIO_KEY, TR_RATIOLIMIT_UNLIMITED ); + connect( r, SIGNAL(toggled(bool)), this, SLOT(onSeedUntilChanged(bool))); mySeedForeverRadio = r; hig->addWideControl( r ); h = new QHBoxLayout( ); h->setSpacing( HIG :: PAD ); r = new QRadioButton( tr( "&Stop seeding when a torrent's ratio reaches" ) ); + r->setProperty( RATIO_KEY, TR_RATIOLIMIT_SINGLE ); + connect( r, SIGNAL(toggled(bool)), this, SLOT(onSeedUntilChanged(bool))); mySeedCustomRadio = r; h->addWidget( r ); ds = new QDoubleSpinBox( ); ds->setRange( 0.5, INT_MAX ); + connect( ds, SIGNAL(valueChanged(double)), this, SLOT(onSeedRatioLimitChanged(double))); mySeedCustomSpin = ds; h->addWidget( ds ); hig->addWideControl( h ); @@ -438,6 +477,7 @@ Details :: createOptionsTab( ) s = new QSpinBox( ); s->setRange( 1, 300 ); + connect( s, SIGNAL(valueChanged(int)), this, SLOT(onMaxPeersChanged(int))); myPeerLimitSpin = s; hig->addRow( tr( "&Maximum Peers" ), s ); diff --git a/qt/details.h b/qt/details.h index 5e83d2a03..a041a2bac 100644 --- a/qt/details.h +++ b/qt/details.h @@ -114,11 +114,16 @@ class Details: public QDialog FileTreeView * myFileTreeView; private slots: - void onSessionLimitsToggled( bool ); void onFilePriorityChanged( const QSet& fileIndices, int ); void onFileWantedChanged( const QSet& fileIndices, bool ); - - + void onHonorsSessionLimitsToggled( bool ); + void onDownloadLimitedToggled( bool ); + void onDownloadLimitChanged( int ); + void onUploadLimitedToggled( bool ); + void onUploadLimitChanged( int ); + void onSeedUntilChanged( bool ); + void onSeedRatioLimitChanged( double ); + void onMaxPeersChanged( int ); }; #endif diff --git a/qt/session.cc b/qt/session.cc index 34faa7261..ea76cb17f 100644 --- a/qt/session.cc +++ b/qt/session.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -86,6 +87,7 @@ Session :: sessionSet( const char * key, const QVariant& value ) case QVariant::String: tr_bencDictAddStr ( args, key, value.toString().toUtf8() ); break; default: assert( "unknown type" ); } +std::cerr << tr_bencToJSON(&top) << std::endl; exec( &top ); tr_bencFree( &top ); } @@ -274,17 +276,34 @@ namespace const int Session :: ADD_TORRENT_TAG = TAG_ADD_TORRENT; +void +Session :: torrentSet( int id, const QString& key, double value ) +{ + QString s; + QTextStream( &s ) << "{ \"method\": \"torrent-set\", \"arguments\": { \"ids\": "<& value ) tr_bencDictAddStr( &top, "method", "torrent-set" ); tr_benc * args( tr_bencDictAddDict( &top, "arguments", 2 ) ); tr_bencListAddInt( tr_bencDictAddList( args, "ids", 1 ), id ); - tr_benc * list( tr_bencDictAddList( args, key.toUtf8(), value.size( ) ) ); + tr_benc * list( tr_bencDictAddList( args, key.toUtf8().constData(), value.size( ) ) ); foreach( int i, value ) tr_bencListAddInt( list, i ); exec( &top ); tr_bencFree( &top ); + refreshExtraStats( id ); } diff --git a/qt/session.h b/qt/session.h index 1c97b42a2..42eb38777 100644 --- a/qt/session.h +++ b/qt/session.h @@ -74,6 +74,8 @@ class Session: public QObject public: void torrentSet( int id, const QString& key, bool val ); + void torrentSet( int id, const QString& key, int val ); + void torrentSet( int id, const QString& key, double val ); void torrentSet( int id, const QString& key, const QList& val ); public slots: diff --git a/qt/torrent-filter.cc b/qt/torrent-filter.cc index e75ced7c6..385e0e46b 100644 --- a/qt/torrent-filter.cc +++ b/qt/torrent-filter.cc @@ -25,6 +25,8 @@ TorrentFilter :: TorrentFilter( Prefs& prefs ): // listen for changes to the preferences to know when to refilter / resort connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(refreshPref(int))); + setDynamicSortFilter( true ); + // initialize our state from the current prefs QList initKeys; initKeys << Prefs :: SORT_MODE