]> granicus.if.org Git - transmission/commitdiff
(trunk qt) #2560 "idle seeding time limit" -- Qt support
authorCharles Kerr <charles@transmissionbt.com>
Sat, 24 Jul 2010 04:14:43 +0000 (04:14 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Sat, 24 Jul 2010 04:14:43 +0000 (04:14 +0000)
qt/details.cc
qt/details.h
qt/torrent.cc
qt/torrent.h

index 410e5a6c58a34b6e9f5dd1fc6278ccf1abd1df1e..6647b96968ec788c7e01bcd1bb69740883d4dcea 100644 (file)
@@ -646,28 +646,38 @@ Details :: refresh( )
         myPeerLimitSpin->blockSignals( true );
         myPeerLimitSpin->setValue( tor->peerLimit() );
         myPeerLimitSpin->blockSignals( false );
+    }
 
-        // ratio radios
-        uniform = true;
-        baselineInt = tor->seedRatioMode( );
+    {
+        const Torrent * tor;
+
+        // ratio
+        bool uniform = true;
+        int baselineInt = torrents[0]->seedRatioMode( );
         foreach( tor, torrents ) if( baselineInt != tor->seedRatioMode( ) ) { uniform = false; break; }
-        if( !uniform ) {
-            mySeedGlobalRadio->setChecked( false );
-            mySeedCustomRadio->setChecked( false );
-            mySeedForeverRadio->setChecked( false );
-        } else {
-            QRadioButton * rb;
-            switch( baselineInt ) {
-                case TR_RATIOLIMIT_GLOBAL:    rb = mySeedGlobalRadio; break;
-                case TR_RATIOLIMIT_SINGLE:    rb = mySeedCustomRadio; break;
-                case TR_RATIOLIMIT_UNLIMITED: rb = mySeedForeverRadio; break;
-            }
-            rb->setChecked( true );
-        }
 
-        mySeedCustomSpin->blockSignals( true );
-        mySeedCustomSpin->setValue( tor->seedRatioLimit( ) );
-        mySeedCustomSpin->blockSignals( false );
+        myRatioCombo->blockSignals( true );
+        myRatioCombo->setCurrentIndex( uniform ? myRatioCombo->findData( baselineInt ) : -1 );
+        myRatioSpin->setVisible( uniform && ( baselineInt == TR_RATIOLIMIT_SINGLE ) );
+        myRatioCombo->blockSignals( false );
+
+        myRatioSpin->blockSignals( true );
+        myRatioSpin->setValue( tor->seedRatioLimit( ) );
+        myRatioSpin->blockSignals( false );
+
+        // idle
+        uniform = true;
+        baselineInt = torrents[0]->seedIdleMode( );
+        foreach( tor, torrents ) if( baselineInt != tor->seedIdleMode( ) ) { uniform = false; break; }
+
+        myIdleCombo->blockSignals( true );
+        myIdleCombo->setCurrentIndex( uniform ? myIdleCombo->findData( baselineInt ) : -1 );
+        myIdleSpin->setVisible( uniform && ( baselineInt == TR_RATIOLIMIT_SINGLE ) );
+        myIdleCombo->blockSignals( false );
+
+        myIdleSpin->blockSignals( true );
+        myIdleSpin->setValue( tor->seedIdleLimit( ) );
+        myIdleSpin->blockSignals( false );
     }
 
     // tracker tab
@@ -1026,28 +1036,30 @@ Details :: onUploadLimitChanged( int val )
     mySession.torrentSet( myIds, "uploadLimit", val );
 }
 
-#define RATIO_KEY "seedRatioMode"
-
 void
-Details :: onSeedUntilChanged( bool b )
+Details :: onIdleModeChanged( int index )
 {
-    if( b )
-        mySession.torrentSet( myIds, RATIO_KEY, sender()->property(RATIO_KEY).toInt() );
+    const int val = myIdleCombo->itemData( index ).toInt( );
+    mySession.torrentSet( myIds, "seedIdleMode", val );
 }
 
 void
-Details :: onSeedRatioLimitChanged( double val )
+Details :: onIdleLimitChanged( int val )
 {
-    QSet<int> ids;
+    mySession.torrentSet( myIds, "seedIdleLimit", val );
+}
 
-    foreach( int id, myIds ) {
-        const Torrent * tor = myModel.getTorrentFromId( id );
-        if( tor && tor->seedRatioLimit( ) )
-            ids.insert( id );
-    }
+void
+Details :: onRatioModeChanged( int index )
+{
+    const int val = myRatioCombo->itemData( index ).toInt( );
+    mySession.torrentSet( myIds, "seedRatioMode", val );
+}
 
-    if( !ids.empty( ) )
-        mySession.torrentSet( ids, "seedRatioLimit", val );
+void
+Details :: onRatioLimitChanged( double val )
+{
+    mySession.torrentSet( myIds, "seedRatioLimit", val );
 }
 
 void
@@ -1183,12 +1195,10 @@ Details :: onRemoveTrackerPushed( )
 QWidget *
 Details :: createOptionsTab( )
 {
-    //QWidget * l;
     QSpinBox * s;
     QCheckBox * c;
     QComboBox * m;
     QHBoxLayout * h;
-    QRadioButton * r;
     QDoubleSpinBox * ds;
     const QString speed_K_str = Formatter::unitStr( Formatter::SPEED, Formatter::KB );
 
@@ -1231,31 +1241,34 @@ Details :: createOptionsTab( )
     hig->addSectionDivider( );
     hig->addSectionTitle( tr( "Seeding Limits" ) );
 
-    r = new QRadioButton( tr( "Use &global settings" ) );
-    r->setProperty( RATIO_KEY, TR_RATIOLIMIT_GLOBAL );
-    connect( r, SIGNAL(clicked(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(clicked(bool)), this, SLOT(onSeedUntilChanged(bool)));
-    mySeedForeverRadio = r;
-    hig->addWideControl( r );
-
     h = new QHBoxLayout( );
     h->setSpacing( HIG :: PAD );
-    r = new QRadioButton( tr( "&Seed torrent until its ratio reaches:" ) );
-    r->setProperty( RATIO_KEY, TR_RATIOLIMIT_SINGLE );
-    connect( r, SIGNAL(clicked(bool)), this, SLOT(onSeedUntilChanged(bool)));
-    mySeedCustomRadio = r;
-    h->addWidget( r );
+    m = new QComboBox;
+    m->addItem( tr( "Use Global Settings" ),      TR_RATIOLIMIT_GLOBAL );
+    m->addItem( tr( "Seed regardless of ratio" ), TR_RATIOLIMIT_UNLIMITED );
+    m->addItem( tr( "Stop seeding at ratio:" ),   TR_RATIOLIMIT_SINGLE );
+    connect( m, SIGNAL(currentIndexChanged(int)), this, SLOT(onRatioModeChanged(int)));
+    h->addWidget( myRatioCombo = m );
     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 );
+    connect( ds, SIGNAL(valueChanged(double)), this, SLOT(onRatioLimitChanged(double)));
+    h->addWidget( myRatioSpin = ds );
+    hig->addRow( tr( "&Ratio:" ), h, m );
+
+    h = new QHBoxLayout( );
+    h->setSpacing( HIG :: PAD );
+    m = new QComboBox;
+    m->addItem( tr( "Use Global Settings" ),                 TR_IDLELIMIT_GLOBAL );
+    m->addItem( tr( "Seed regardless of activity" ),         TR_IDLELIMIT_UNLIMITED );
+    m->addItem( tr( "Stop seeding if idle for N minutes:" ), TR_IDLELIMIT_SINGLE );
+    connect( m, SIGNAL(currentIndexChanged(int)), this, SLOT(onIdleModeChanged(int)));
+    h->addWidget( myIdleCombo = m );
+    s = new QSpinBox( );
+    s->setRange( 1, 9999 );
+    connect( s, SIGNAL(valueChanged(int)), this, SLOT(onIdleLimitChanged(int)));
+    h->addWidget( myIdleSpin = s );
+    hig->addRow( tr( "&Idle:" ), h, m );
+
 
     hig->addSectionDivider( );
     hig->addSectionTitle( tr( "Peer Connections" ) );
index 3917b042e307d2efbc9275af57e20b6fa909b348..0d5071d8056e8fcbaa50d7173ee9f51dac2ce399 100644 (file)
@@ -103,10 +103,10 @@ class Details: public QDialog
         QPushButton * myRemoveTrackerButton;
         QSpinBox * mySingleDownSpin;
         QSpinBox * mySingleUpSpin;
-        QRadioButton * mySeedGlobalRadio;
-        QRadioButton * mySeedForeverRadio;
-        QRadioButton * mySeedCustomRadio;
-        QDoubleSpinBox * mySeedCustomSpin;
+        QComboBox * myRatioCombo;
+        QDoubleSpinBox * myRatioSpin;
+        QComboBox * myIdleCombo;
+        QSpinBox * myIdleSpin;
         QSpinBox * myPeerLimitSpin;
         QComboBox * myBandwidthPriorityCombo;
 
@@ -144,8 +144,10 @@ class Details: public QDialog
         void onDownloadLimitChanged( int );
         void onUploadLimitedToggled( bool );
         void onUploadLimitChanged( int );
-        void onSeedUntilChanged( bool );
-        void onSeedRatioLimitChanged( double );
+        void onRatioModeChanged( int );
+        void onRatioLimitChanged( double );
+        void onIdleModeChanged( int );
+        void onIdleLimitChanged( int );
         void onShowTrackerScrapesToggled( bool );
         void onTrackerSelectionChanged( );
         void onAddTrackerPushed( );
index 797eaa7e97bf8c61128ed9760569b16e83a77492..a5c2de99a86c4a82b5b70762be85bd01afef2aee 100644 (file)
@@ -89,6 +89,8 @@ Torrent :: myProperties[] =
     { MIME_ICON, "ccc", QVariant::Icon, DERIVED },
     { SEED_RATIO_LIMIT, "seedRatioLimit", QVariant::Double, STAT },
     { SEED_RATIO_MODE, "seedRatioMode", QVariant::Int, STAT },
+    { SEED_IDLE_LIMIT, "seedIdleLimit", QVariant::Int, STAT_EXTRA },
+    { SEED_IDLE_MODE, "seedIdleMode", QVariant::Int, STAT_EXTRA },
     { DOWN_LIMIT, "downloadLimit", QVariant::Int, STAT_EXTRA }, /* KB/s */
     { DOWN_LIMITED, "downloadLimited", QVariant::Bool, STAT_EXTRA },
     { UP_LIMIT, "uploadLimit", QVariant::Int, STAT_EXTRA }, /* KB/s */
index 691a9ebe271a9f7d289d6d28fe47cb07ff9f9a4e..02a7a5b1ec8aa87bbdc5ff42090339dc7a254027 100644 (file)
@@ -153,6 +153,8 @@ class Torrent: public QObject
             MIME_ICON,
             SEED_RATIO_LIMIT,
             SEED_RATIO_MODE,
+            SEED_IDLE_LIMIT,
+            SEED_IDLE_MODE,
             DOWN_LIMIT,
             DOWN_LIMITED,
             UP_LIMIT,
@@ -292,6 +294,8 @@ class Torrent: public QObject
         int peerLimit( ) const { return getInt( PEER_LIMIT ); }
         double seedRatioLimit( ) const { return getDouble( SEED_RATIO_LIMIT ); }
         tr_ratiolimit seedRatioMode( ) const { return (tr_ratiolimit) getInt( SEED_RATIO_MODE ); }
+        int seedIdleLimit( ) const { return getInt( SEED_IDLE_LIMIT ); }
+        tr_idlelimit seedIdleMode( ) const { return (tr_idlelimit) getInt( SEED_IDLE_MODE ); }
         TrackerStatsList trackerStats( ) const{ return myValues[TRACKERSTATS].value<TrackerStatsList>(); }
         PeerList peers( ) const{ return myValues[PEERS].value<PeerList>(); }
         const FileList& files( ) const { return myFiles; }