namespace
{
- const int REFRESH_INTERVAL_MSEC = 3500;
+ const int REFRESH_INTERVAL_MSEC = 4000;
enum // peer columns
{
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
***/
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 *
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;
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;
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 );
s = new QSpinBox( );
s->setRange( 1, 300 );
+ connect( s, SIGNAL(valueChanged(int)), this, SLOT(onMaxPeersChanged(int)));
myPeerLimitSpin = s;
hig->addRow( tr( "&Maximum Peers" ), s );
#include <QMessageBox>
#include <QSet>
#include <QStyle>
+#include <QTextStream>
#include <libtransmission/transmission.h>
#include <libtransmission/bencode.h>
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 );
}
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
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 );
}