From 6692699072b20819c0315deefb029d919a67fb9e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 24 Jul 2010 04:14:43 +0000 Subject: [PATCH] (trunk qt) #2560 "idle seeding time limit" -- Qt support --- qt/details.cc | 127 ++++++++++++++++++++++++++++---------------------- qt/details.h | 14 +++--- qt/torrent.cc | 2 + qt/torrent.h | 4 ++ 4 files changed, 84 insertions(+), 63 deletions(-) diff --git a/qt/details.cc b/qt/details.cc index 410e5a6c5..6647b9696 100644 --- a/qt/details.cc +++ b/qt/details.cc @@ -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 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 ®ardless 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 ); + 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(onRatioLimitChanged(double))); + h->addWidget( myRatioSpin = ds ); + hig->addRow( tr( "&Ratio:" ), h, m ); 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 ); - 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 ); + 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" ) ); diff --git a/qt/details.h b/qt/details.h index 3917b042e..0d5071d80 100644 --- a/qt/details.h +++ b/qt/details.h @@ -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( ); diff --git a/qt/torrent.cc b/qt/torrent.cc index 797eaa7e9..a5c2de99a 100644 --- a/qt/torrent.cc +++ b/qt/torrent.cc @@ -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 */ diff --git a/qt/torrent.h b/qt/torrent.h index 691a9ebe2..02a7a5b1e 100644 --- a/qt/torrent.h +++ b/qt/torrent.h @@ -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(); } PeerList peers( ) const{ return myValues[PEERS].value(); } const FileList& files( ) const { return myFiles; }