]> granicus.if.org Git - transmission/commitdiff
(trunk qt) first stab at getting the properties dialog's "options" controls operational.
authorCharles Kerr <charles@transmissionbt.com>
Sun, 12 Apr 2009 21:15:35 +0000 (21:15 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Sun, 12 Apr 2009 21:15:35 +0000 (21:15 +0000)
qt/details.cc
qt/details.h
qt/session.cc
qt/session.h
qt/torrent-filter.cc

index c07422b935be2e65fc0ef9fd240e060072e91bc5..4dedd17495d9ef720aa9dc1469b8d4c33c03987c 100644 (file)
@@ -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<QString,QTreeWidgetItem*> peers2;
     QList<QTreeWidgetItem*> 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", 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(), "honorsSessionLimits", b );
+    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 &regardless 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 );
 
index 5e83d2a03f68f611a1ed00ffdc48c2c84f368239..a041a2bac5eb47cbb3283f48541298d7ae4a27e6 100644 (file)
@@ -114,11 +114,16 @@ class Details: public QDialog
         FileTreeView * myFileTreeView;
 
     private slots:
-        void onSessionLimitsToggled( bool );
         void onFilePriorityChanged( const QSet<int>& fileIndices, int );
         void onFileWantedChanged( const QSet<int>& 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
index 34faa7261fab66c35d80fa00cc0e2844de2fda69..ea76cb17f95197132b72764084878ffc2cbbce04 100644 (file)
@@ -20,6 +20,7 @@
 #include <QMessageBox>
 #include <QSet>
 #include <QStyle>
+#include <QTextStream>
 
 #include <libtransmission/transmission.h>
 #include <libtransmission/bencode.h>
@@ -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\": "<<id<<", \""<<key<<"\": "<<value<<" } }";
+std::cerr << qPrintable(s) << std::endl;
+    exec( s.toUtf8().constData() );
+    refreshExtraStats( id );
+}
+
+void
+Session :: torrentSet( int id, const QString& key, int value )
+{
+    QString s;
+    QTextStream( &s ) << "{ \"method\": \"torrent-set\", \"arguments\": { \"ids\": "<<id<<", \""<<key<<"\": "<<value<<" } }";
+std::cerr << qPrintable(s) << std::endl;
+    exec( s.toUtf8().constData() );
+    refreshExtraStats( id );
+}
+
 void
 Session :: torrentSet( int id, const QString& key, bool value )
 {
-    tr_benc top;
-    tr_bencInitDict( &top, 2 );
-    tr_bencDictAddStr( &top, "method", "torrent-set" );
-    tr_benc * args( tr_bencDictAddDict( &top, "arguments", 2 ) );
-    tr_bencDictAddInt( args, key.toUtf8(), value );
-    tr_bencListAddInt( tr_bencDictAddList( args, "ids", 1 ), id );
-    exec( &top );
-    tr_bencFree( &top );
+    QString s;
+    QTextStream( &s ) << "{ \"method\": \"torrent-set\", \"arguments\": { \"ids\": "<<id<<", \""<<key<<"\": "<<(value?"true":"false")<<" } }";
+std::cerr << qPrintable(s) << std::endl;
+    exec( s.toUtf8().constData() );
+    refreshExtraStats( id );
 }
 
 void
@@ -295,11 +314,12 @@ Session :: torrentSet( int id, const QString& key, const QList<int>& 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 );
 }
 
 
index 1c97b42a2a205d9dd26d2d66394a87e0f913da1b..42eb38777d38e4c5129e723a50e0abffe0d55f88 100644 (file)
@@ -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<int>& val );
 
     public slots:
index e75ced7c63a3d3ae1296b26d4049cebae14c32ff..385e0e46b9eac40d532c8c9882a545803e5d71c4 100644 (file)
@@ -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<int> initKeys;
     initKeys << Prefs :: SORT_MODE