(trunk) #3045 "speed units" -- change the public API of libtransmission based on feedback from livings
This commit is contained in:
parent
62b53b3e10
commit
6e5af03d78
10
cli/cli.c
10
cli/cli.c
|
@ -157,8 +157,8 @@ getStatusStr( const tr_stat * st,
|
|||
char dnStr[80];
|
||||
char ratioStr[80];
|
||||
|
||||
tr_formatter_speed( upStr, st->pieceUploadSpeed_Bps, sizeof( upStr ) );
|
||||
tr_formatter_speed( dnStr, st->pieceDownloadSpeed_Bps, sizeof( dnStr ) );
|
||||
tr_formatter_speed_KBps( upStr, st->pieceUploadSpeed_KBps, sizeof( upStr ) );
|
||||
tr_formatter_speed_KBps( dnStr, st->pieceDownloadSpeed_KBps, sizeof( dnStr ) );
|
||||
tr_strlratio( ratioStr, st->ratio, sizeof( ratioStr ) );
|
||||
|
||||
tr_snprintf( buf, buflen,
|
||||
|
@ -176,7 +176,7 @@ getStatusStr( const tr_stat * st,
|
|||
char upStr[80];
|
||||
char ratioStr[80];
|
||||
|
||||
tr_formatter_speed( upStr, st->pieceUploadSpeed_Bps, sizeof( upStr ) );
|
||||
tr_formatter_speed_KBps( upStr, st->pieceUploadSpeed_KBps, sizeof( upStr ) );
|
||||
tr_strlratio( ratioStr, st->ratio, sizeof( ratioStr ) );
|
||||
|
||||
tr_snprintf( buf, buflen,
|
||||
|
@ -358,7 +358,7 @@ parseCommandLine( tr_benc * d, int argc, const char ** argv )
|
|||
break;
|
||||
case 'B': tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, FALSE );
|
||||
break;
|
||||
case 'd': tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_Bps, atoi( optarg ) * SPEED_K );
|
||||
case 'd': tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_KBps, atoi( optarg ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, TRUE );
|
||||
break;
|
||||
case 'D': tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, FALSE );
|
||||
|
@ -376,7 +376,7 @@ parseCommandLine( tr_benc * d, int argc, const char ** argv )
|
|||
break;
|
||||
case 't': tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_SOCKET_TOS, atoi( optarg ) );
|
||||
break;
|
||||
case 'u': tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_Bps, atoi( optarg ) * SPEED_K );
|
||||
case 'u': tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_KBps, atoi( optarg ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, TRUE );
|
||||
break;
|
||||
case 'U': tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, FALSE );
|
||||
|
|
|
@ -140,13 +140,13 @@ strlratio2( char * buf, double ratio, size_t buflen )
|
|||
}
|
||||
|
||||
static char*
|
||||
strlratio( char * buf, double numerator, double denominator, size_t buflen )
|
||||
strlratio( char * buf, int64_t numerator, int64_t denominator, size_t buflen )
|
||||
{
|
||||
double ratio;
|
||||
|
||||
if( denominator )
|
||||
ratio = numerator / denominator;
|
||||
else if( numerator )
|
||||
if( denominator != 0 )
|
||||
ratio = numerator / (double)denominator;
|
||||
else if( numerator != 0 )
|
||||
ratio = TR_RATIO_INF;
|
||||
else
|
||||
ratio = TR_RATIO_NA;
|
||||
|
@ -160,7 +160,7 @@ strlmem( char * buf, int64_t bytes, size_t buflen )
|
|||
if( !bytes )
|
||||
tr_strlcpy( buf, "None", buflen );
|
||||
else
|
||||
tr_formatter_mem( buf, bytes, buflen );
|
||||
tr_formatter_mem_B( buf, bytes, buflen );
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
@ -171,18 +171,7 @@ strlsize( char * buf, int64_t bytes, size_t buflen )
|
|||
if( !bytes )
|
||||
tr_strlcpy( buf, "None", buflen );
|
||||
else
|
||||
tr_formatter_size( buf, bytes, buflen );
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static char*
|
||||
strlspeed( char * buf, int64_t bytes_per_second, size_t buflen )
|
||||
{
|
||||
if( !bytes_per_second )
|
||||
tr_strlcpy( buf, "None", buflen );
|
||||
else
|
||||
tr_formatter_speed( buf, bytes_per_second, buflen );
|
||||
tr_formatter_size_B( buf, bytes, buflen );
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
@ -831,9 +820,9 @@ printDetails( tr_benc * top )
|
|||
if( tr_bencDictFindInt( t, "eta", &i ) )
|
||||
printf( " ETA: %s\n", tr_strltime( buf, i, sizeof( buf ) ) );
|
||||
if( tr_bencDictFindInt( t, "rateDownload", &i ) )
|
||||
printf( " Download Speed: %s\n", strlspeed( buf, i, sizeof( buf ) ) );
|
||||
printf( " Download Speed: %s\n", tr_formatter_speed_KBps( buf, i, sizeof( buf ) ) );
|
||||
if( tr_bencDictFindInt( t, "rateUpload", &i ) )
|
||||
printf( " Upload Speed: %s\n", strlspeed( buf, i, sizeof( buf ) ) );
|
||||
printf( " Upload Speed: %s\n", tr_formatter_speed_KBps( buf, i, sizeof( buf ) ) );
|
||||
if( tr_bencDictFindInt( t, "haveUnchecked", &i )
|
||||
&& tr_bencDictFindInt( t, "haveValid", &j ) )
|
||||
{
|
||||
|
@ -1106,7 +1095,7 @@ printDetails( tr_benc * top )
|
|||
{
|
||||
printf( " Download Limit: " );
|
||||
if( boolVal )
|
||||
printf( "%s\n", strlspeed( buf, i, sizeof( buf ) ) );
|
||||
printf( "%s\n", tr_formatter_speed_KBps( buf, i, sizeof( buf ) ) );
|
||||
else
|
||||
printf( "Unlimited\n" );
|
||||
}
|
||||
|
@ -1115,7 +1104,7 @@ printDetails( tr_benc * top )
|
|||
{
|
||||
printf( " Upload Limit: " );
|
||||
if( boolVal )
|
||||
printf( "%s\n", strlspeed( buf, i, sizeof( buf ) ) );
|
||||
printf( "%s\n", tr_formatter_speed_KBps( buf, i, sizeof( buf ) ) );
|
||||
else
|
||||
printf( "Unlimited\n" );
|
||||
}
|
||||
|
@ -1240,8 +1229,8 @@ printPeersImpl( tr_benc * peers )
|
|||
{
|
||||
printf( "%-20s %-12s %-5.1f %6.1f %6.1f %s\n",
|
||||
address, flagstr, (progress*100.0),
|
||||
rateToClient / (double)SPEED_K,
|
||||
rateToPeer / (double)SPEED_K,
|
||||
(double)rateToClient,
|
||||
(double)rateToPeer,
|
||||
client );
|
||||
}
|
||||
}
|
||||
|
@ -1399,8 +1388,8 @@ printSession( tr_benc * top )
|
|||
printf( " Peer exchange allowed: %s\n", ( boolVal ? "Yes" : "No" ) );
|
||||
if( tr_bencDictFindStr( args, TR_PREFS_KEY_ENCRYPTION, &str ) )
|
||||
printf( " Encryption: %s\n", str );
|
||||
if( tr_bencDictFindInt( args, TR_PREFS_KEY_MAX_CACHE_SIZE, &i ) )
|
||||
printf( " Maximum memory cache size: %s\n", strlsize( buf, i, sizeof( buf ) ) );
|
||||
if( tr_bencDictFindInt( args, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, &i ) )
|
||||
printf( " Maximum memory cache size: %s\n", tr_formatter_mem_MB( buf, i, sizeof( buf ) ) );
|
||||
printf( "\n" );
|
||||
|
||||
{
|
||||
|
@ -1408,17 +1397,17 @@ printSession( tr_benc * top )
|
|||
int64_t altDown, altUp, altBegin, altEnd, altDay, upLimit, downLimit, peerLimit;
|
||||
double seedRatioLimit;
|
||||
|
||||
if( tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, &altDown ) &&
|
||||
if( tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, &altDown ) &&
|
||||
tr_bencDictFindBool( args, TR_PREFS_KEY_ALT_SPEED_ENABLED, &altEnabled ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &altBegin ) &&
|
||||
tr_bencDictFindBool( args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &altTimeEnabled ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_TIME_END, &altEnd ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, &altDay ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_UP_Bps, &altUp ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_UP_KBps, &altUp ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &peerLimit ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_DSPEED_Bps, &downLimit ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_DSPEED_KBps, &downLimit ) &&
|
||||
tr_bencDictFindBool( args, TR_PREFS_KEY_DSPEED_ENABLED, &downEnabled ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_USPEED_Bps, &upLimit ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_USPEED_KBps, &upLimit ) &&
|
||||
tr_bencDictFindBool( args, TR_PREFS_KEY_USPEED_ENABLED, &upEnabled ) &&
|
||||
tr_bencDictFindReal( args, "seedRatioLimit", &seedRatioLimit ) &&
|
||||
tr_bencDictFindBool( args, "seedRatioLimited", &seedRatioLimited) )
|
||||
|
@ -1437,30 +1426,30 @@ printSession( tr_benc * top )
|
|||
printf( " Default seed ratio limit: %s\n", buf );
|
||||
|
||||
if( altEnabled )
|
||||
strlspeed( buf, altUp, sizeof( buf ) );
|
||||
tr_formatter_speed_KBps( buf, altUp, sizeof( buf ) );
|
||||
else if( upEnabled )
|
||||
strlspeed( buf, upLimit, sizeof( buf ) );
|
||||
tr_formatter_speed_KBps( buf, upLimit, sizeof( buf ) );
|
||||
else
|
||||
tr_strlcpy( buf, "Unlimited", sizeof( buf ) );
|
||||
printf( " Upload speed limit: %s (%s limit: %s; %s turtle limit: %s)\n",
|
||||
buf,
|
||||
upEnabled ? "Enabled" : "Disabled",
|
||||
strlspeed( buf2, upLimit, sizeof( buf2 ) ),
|
||||
tr_formatter_speed_KBps( buf2, upLimit, sizeof( buf2 ) ),
|
||||
altEnabled ? "Enabled" : "Disabled",
|
||||
strlspeed( buf3, altUp, sizeof( buf3 ) ) );
|
||||
tr_formatter_speed_KBps( buf3, altUp, sizeof( buf3 ) ) );
|
||||
|
||||
if( altEnabled )
|
||||
strlspeed( buf, altDown, sizeof( buf ) );
|
||||
tr_formatter_speed_KBps( buf, altDown, sizeof( buf ) );
|
||||
else if( downEnabled )
|
||||
strlspeed( buf, downLimit, sizeof( buf ) );
|
||||
tr_formatter_speed_KBps( buf, downLimit, sizeof( buf ) );
|
||||
else
|
||||
tr_strlcpy( buf, "Unlimited", sizeof( buf ) );
|
||||
printf( " Download speed limit: %s (%s limit: %s; %s turtle limit: %s)\n",
|
||||
buf,
|
||||
downEnabled ? "Enabled" : "Disabled",
|
||||
strlspeed( buf2, downLimit, sizeof( buf2 ) ),
|
||||
tr_formatter_speed_KBps( buf2, downLimit, sizeof( buf2 ) ),
|
||||
altEnabled ? "Enabled" : "Disabled",
|
||||
strlspeed( buf2, altDown, sizeof( buf2 ) ) );
|
||||
tr_formatter_speed_KBps( buf2, altDown, sizeof( buf2 ) ) );
|
||||
|
||||
if( altTimeEnabled ) {
|
||||
printf( " Turtle schedule: %02d:%02d - %02d:%02d ",
|
||||
|
@ -1845,9 +1834,9 @@ processArgs( const char * host, int port, int argc, const char ** argv )
|
|||
break;
|
||||
case 971: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_ENABLED, FALSE );
|
||||
break;
|
||||
case 972: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, numarg( optarg ) * SPEED_K );
|
||||
case 972: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, numarg( optarg ) );
|
||||
break;
|
||||
case 973: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_UP_Bps, numarg( optarg ) * SPEED_K );
|
||||
case 973: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_UP_KBps, numarg( optarg ) );
|
||||
break;
|
||||
case 974: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, TRUE );
|
||||
break;
|
||||
|
@ -1864,7 +1853,7 @@ processArgs( const char * host, int port, int argc, const char ** argv )
|
|||
break;
|
||||
case 'C': tr_bencDictAddBool( args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, FALSE );
|
||||
break;
|
||||
case 'e': tr_bencDictAddReal( args, TR_PREFS_KEY_MAX_CACHE_SIZE, atof(optarg) * MEM_K * MEM_K );
|
||||
case 'e': tr_bencDictAddReal( args, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, atof(optarg) );
|
||||
break;
|
||||
case 910: tr_bencDictAddStr( args, TR_PREFS_KEY_ENCRYPTION, "required" );
|
||||
break;
|
||||
|
@ -1922,10 +1911,10 @@ processArgs( const char * host, int port, int argc, const char ** argv )
|
|||
switch( c )
|
||||
{
|
||||
case 'd': if( targs ) {
|
||||
tr_bencDictAddInt( targs, "downloadLimit", numarg( optarg ) * SPEED_K );
|
||||
tr_bencDictAddInt( targs, "downloadLimit", numarg( optarg ) );
|
||||
tr_bencDictAddBool( targs, "downloadLimited", TRUE );
|
||||
} else {
|
||||
tr_bencDictAddInt( sargs, TR_PREFS_KEY_DSPEED_Bps, numarg( optarg ) * SPEED_K );
|
||||
tr_bencDictAddInt( sargs, TR_PREFS_KEY_DSPEED_KBps, numarg( optarg ) );
|
||||
tr_bencDictAddBool( sargs, TR_PREFS_KEY_DSPEED_ENABLED, TRUE );
|
||||
}
|
||||
break;
|
||||
|
@ -1935,10 +1924,10 @@ processArgs( const char * host, int port, int argc, const char ** argv )
|
|||
tr_bencDictAddBool( sargs, TR_PREFS_KEY_DSPEED_ENABLED, FALSE );
|
||||
break;
|
||||
case 'u': if( targs ) {
|
||||
tr_bencDictAddInt( targs, "uploadLimit", numarg( optarg ) * SPEED_K );
|
||||
tr_bencDictAddInt( targs, "uploadLimit", numarg( optarg ) );
|
||||
tr_bencDictAddBool( targs, "uploadLimited", TRUE );
|
||||
} else {
|
||||
tr_bencDictAddInt( sargs, TR_PREFS_KEY_USPEED_Bps, numarg( optarg ) * SPEED_K );
|
||||
tr_bencDictAddInt( sargs, TR_PREFS_KEY_USPEED_KBps, numarg( optarg ) );
|
||||
tr_bencDictAddBool( sargs, TR_PREFS_KEY_USPEED_ENABLED, TRUE );
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
string | value type & description
|
||||
----------------------+-------------------------------------------------
|
||||
"bandwidthPriority" | number this torrent's bandwidth tr_priority_t
|
||||
"downloadLimit" | number maximum download speed (bytes per second)
|
||||
"downloadLimit" | number maximum download speed (KBps)
|
||||
"downloadLimited" | boolean true if "downloadLimit" is honored
|
||||
"files-wanted" | array indices of file(s) to download
|
||||
"files-unwanted" | array indices of file(s) to not download
|
||||
|
@ -105,7 +105,7 @@
|
|||
"trackerAdd" | object (see below)
|
||||
"trackerEdit" | object (see below)
|
||||
"trackerRemove" | object (see below)
|
||||
"uploadLimit" | number maximum upload speed (bytes per second)
|
||||
"uploadLimit" | number maximum upload speed (KBps)
|
||||
"uploadLimited" | boolean true if "uploadLimit" is honored
|
||||
|
|
||||
----------------------+---------------------------------+
|
||||
|
@ -418,16 +418,16 @@
|
|||
|
||||
string | value type & description
|
||||
------------------------------+-------------------------------------------------
|
||||
"alt-speed-down" | number max global download speed (in bytes per second)
|
||||
"alt-speed-down" | number max global download speed (KBps)
|
||||
"alt-speed-enabled" | boolean true means use the alt speeds
|
||||
"alt-speed-time-begin" | number when to turn on alt speeds (units: minutes after midnight)
|
||||
"alt-speed-time-enabled" | boolean true means the scheduled on/off times are used
|
||||
"alt-speed-time-end" | number when to turn off alt speeds (units: same)
|
||||
"alt-speed-time-day" | number what day(s) to turn on alt speeds (look at tr_sched_day)
|
||||
"alt-speed-up" | number max global upload speed (in bytes per second)
|
||||
"alt-speed-up" | number max global upload speed (KBps)
|
||||
"blocklist-enabled" | boolean true means enabled
|
||||
"blocklist-size" | number number of rules in the blocklist
|
||||
"cache-size" | number maximum size (in bytes) of the disk cache
|
||||
"cache-size" | number maximum size of the disk cache (MB)
|
||||
"config-dir" | string location of transmission's configuration directory
|
||||
"download-dir" | string default path to download torrents
|
||||
"dht-enabled" | boolean true means allow dht in public torrents
|
||||
|
@ -448,9 +448,9 @@
|
|||
"script-torrent-done-enabled" | boolean whether or not to call the "done" script
|
||||
"seedRatioLimit" | double the default seed ratio for torrents to use
|
||||
"seedRatioLimited" | boolean true if seedRatioLimit is honored by default
|
||||
"speed-limit-down" | number max global download speed (in bytes per second)
|
||||
"speed-limit-down" | number max global download speed (KBps)
|
||||
"speed-limit-down-enabled" | boolean true means enabled
|
||||
"speed-limit-up" | number max global upload speed (in bytes per second)
|
||||
"speed-limit-up" | number max global upload speed (KBps)
|
||||
"speed-limit-up-enabled" | boolean true means enabled
|
||||
"start-added-torrents" | boolean true means added torrents will be started right away
|
||||
"trash-original-torrent-files"| boolean true means the .torrent file of added torrents will be deleted
|
||||
|
@ -628,13 +628,7 @@
|
|||
| | yes | session-get | new arg "trash-original-torrent-files"
|
||||
| | yes | torrent-get | new arg "isFinished"
|
||||
------+---------+-----------+----------------+-------------------------------
|
||||
10 | 2.10 | NO | torrent-get | arg "downloadLimit" is now bytes per second
|
||||
| | NO | torrent-get | arg "uploadLimit" is now bytes per second
|
||||
| | NO | session-get | arg "speed-limit-down" is now bytes per second
|
||||
| | NO | session-get | arg "speed-limit-up" is now bytes per second
|
||||
| | NO | session-get | arg "alt-speed-up" is now bytes per second
|
||||
| | NO | session-get | arg "alt-speed-down" is now bytes per second
|
||||
| | yes | session-get | new arg "cache-size"
|
||||
10 | 2.10 | yes | session-get | new arg "cache-size"
|
||||
| | yes | session-set | new arg "trash-original-torrent-files"
|
||||
| | yes | session-get | new arg "start-added-torrents"
|
||||
| | yes | session-get | new arg "trash-original-torrent-files"
|
||||
|
|
|
@ -219,10 +219,10 @@ refreshOptions( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
|
||||
/* downLimitSpin */
|
||||
if( n ) {
|
||||
const int baseline = tr_torrentGetSpeedLimit_Bps( torrents[0], TR_DOWN ) / speed_K;
|
||||
const int baseline = tr_torrentGetSpeedLimit_KBps( torrents[0], TR_DOWN );
|
||||
int i;
|
||||
for( i=1; i<n; ++i )
|
||||
if( baseline != ( tr_torrentGetSpeedLimit_Bps( torrents[i], TR_DOWN ) / speed_K ) )
|
||||
if( baseline != ( tr_torrentGetSpeedLimit_KBps( torrents[i], TR_DOWN ) ) )
|
||||
break;
|
||||
if( i == n )
|
||||
set_int_spin_if_different( di->downLimitSpin,
|
||||
|
@ -243,10 +243,10 @@ refreshOptions( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
|
||||
/* upLimitSpin */
|
||||
if( n ) {
|
||||
const int baseline = tr_torrentGetSpeedLimit_Bps( torrents[0], TR_UP ) / speed_K;
|
||||
const int baseline = tr_torrentGetSpeedLimit_KBps( torrents[0], TR_UP );
|
||||
int i;
|
||||
for( i=1; i<n; ++i )
|
||||
if( baseline != ( tr_torrentGetSpeedLimit_Bps( torrents[i], TR_UP ) / speed_K ) )
|
||||
if( baseline != ( tr_torrentGetSpeedLimit_KBps( torrents[i], TR_UP ) ) )
|
||||
break;
|
||||
if( i == n )
|
||||
set_int_spin_if_different( di->upLimitSpin,
|
||||
|
@ -600,8 +600,8 @@ refreshInfo( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
const char * mixed = _( "Mixed" );
|
||||
const char * stateString;
|
||||
char buf[512];
|
||||
double available = 0;
|
||||
double sizeWhenDone = 0;
|
||||
uint64_t available = 0;
|
||||
uint64_t sizeWhenDone = 0;
|
||||
const tr_stat ** stats = g_new( const tr_stat*, n );
|
||||
const tr_info ** infos = g_new( const tr_info*, n );
|
||||
for( i=0; i<n; ++i ) {
|
||||
|
@ -761,7 +761,7 @@ refreshInfo( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
str = none;
|
||||
else if( pieceSize >= 0 ) {
|
||||
char piecebuf[128];
|
||||
tr_formatter_mem( piecebuf, pieceSize, sizeof( piecebuf ) );
|
||||
tr_formatter_mem_B( piecebuf, pieceSize, sizeof( piecebuf ) );
|
||||
g_snprintf( buf, sizeof( buf ),
|
||||
ngettext( "%1$s (%2$'d piece @ %3$s)",
|
||||
"%1$s (%2$'d pieces @ %3$s)", pieces ),
|
||||
|
@ -782,16 +782,15 @@ refreshInfo( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
if( n <= 0 )
|
||||
str = none;
|
||||
else {
|
||||
double leftUntilDone = 0;
|
||||
double haveUnchecked = 0;
|
||||
double haveValid = 0;
|
||||
double verifiedPieces = 0;
|
||||
uint64_t leftUntilDone = 0;
|
||||
uint64_t haveUnchecked = 0;
|
||||
uint64_t haveValid = 0;
|
||||
uint32_t verifiedPieces = 0;
|
||||
for( i=0; i<n; ++i ) {
|
||||
const tr_stat * st = stats[i];
|
||||
const double v = st->haveValid;
|
||||
haveUnchecked += st->haveUnchecked;
|
||||
haveValid += v;
|
||||
verifiedPieces += v / tr_torrentInfo(torrents[i])->pieceSize;
|
||||
haveValid += st->haveValid;
|
||||
verifiedPieces += st->haveValid / tr_torrentInfo(torrents[i])->pieceSize;
|
||||
sizeWhenDone += st->sizeWhenDone;
|
||||
leftUntilDone += st->leftUntilDone;
|
||||
available += st->sizeWhenDone - st->leftUntilDone + st->desiredAvailable;
|
||||
|
@ -1044,7 +1043,7 @@ enum
|
|||
WEBSEED_COL_KEY,
|
||||
WEBSEED_COL_WAS_UPDATED,
|
||||
WEBSEED_COL_URL,
|
||||
WEBSEED_COL_DOWNLOAD_RATE_INT,
|
||||
WEBSEED_COL_DOWNLOAD_RATE_DOUBLE,
|
||||
WEBSEED_COL_DOWNLOAD_RATE_STRING,
|
||||
N_WEBSEED_COLS
|
||||
};
|
||||
|
@ -1055,7 +1054,7 @@ getWebseedColumnNames( int column )
|
|||
switch( column )
|
||||
{
|
||||
case WEBSEED_COL_URL: return _( "Webseeds" );
|
||||
case WEBSEED_COL_DOWNLOAD_RATE_INT:
|
||||
case WEBSEED_COL_DOWNLOAD_RATE_DOUBLE:
|
||||
case WEBSEED_COL_DOWNLOAD_RATE_STRING: return _( "Down" );
|
||||
default: return "";
|
||||
}
|
||||
|
@ -1078,9 +1077,9 @@ enum
|
|||
PEER_COL_WAS_UPDATED,
|
||||
PEER_COL_ADDRESS,
|
||||
PEER_COL_ADDRESS_COLLATED,
|
||||
PEER_COL_DOWNLOAD_RATE_INT,
|
||||
PEER_COL_DOWNLOAD_RATE_DOUBLE,
|
||||
PEER_COL_DOWNLOAD_RATE_STRING,
|
||||
PEER_COL_UPLOAD_RATE_INT,
|
||||
PEER_COL_UPLOAD_RATE_DOUBLE,
|
||||
PEER_COL_UPLOAD_RATE_STRING,
|
||||
PEER_COL_CLIENT,
|
||||
PEER_COL_PROGRESS,
|
||||
|
@ -1108,9 +1107,9 @@ getPeerColumnName( int column )
|
|||
{
|
||||
case PEER_COL_ADDRESS: return _( "Address" );
|
||||
case PEER_COL_DOWNLOAD_RATE_STRING:
|
||||
case PEER_COL_DOWNLOAD_RATE_INT: return _( "Down" );
|
||||
case PEER_COL_DOWNLOAD_RATE_DOUBLE: return _( "Down" );
|
||||
case PEER_COL_UPLOAD_RATE_STRING:
|
||||
case PEER_COL_UPLOAD_RATE_INT: return _( "Up" );
|
||||
case PEER_COL_UPLOAD_RATE_DOUBLE: return _( "Up" );
|
||||
case PEER_COL_CLIENT: return _( "Client" );
|
||||
case PEER_COL_PROGRESS: return _( "%" );
|
||||
case PEER_COL_UPLOAD_REQUEST_COUNT_INT:
|
||||
|
@ -1138,9 +1137,9 @@ peer_store_new( void )
|
|||
G_TYPE_BOOLEAN, /* was-updated */
|
||||
G_TYPE_STRING, /* address */
|
||||
G_TYPE_STRING, /* collated address */
|
||||
G_TYPE_INT, /* download speed int */
|
||||
G_TYPE_DOUBLE, /* download speed int */
|
||||
G_TYPE_STRING, /* download speed string */
|
||||
G_TYPE_INT, /* upload speed int */
|
||||
G_TYPE_DOUBLE, /* upload speed int */
|
||||
G_TYPE_STRING, /* upload speed string */
|
||||
G_TYPE_STRING, /* client */
|
||||
G_TYPE_INT, /* progress [0..100] */
|
||||
|
@ -1202,13 +1201,13 @@ refreshPeerRow( GtkListStore * store,
|
|||
char cancelled_by_peer[64];
|
||||
char cancelled_by_client[64];
|
||||
|
||||
if( peer->rateToPeer_Bps > 0 )
|
||||
tr_formatter_speed( up_speed, peer->rateToPeer_Bps, sizeof( up_speed ) );
|
||||
if( peer->rateToPeer_KBps > 0.01 )
|
||||
tr_formatter_speed_KBps( up_speed, peer->rateToPeer_KBps, sizeof( up_speed ) );
|
||||
else
|
||||
*up_speed = '\0';
|
||||
|
||||
if( peer->rateToClient_Bps > 0 )
|
||||
tr_formatter_speed( down_speed, peer->rateToClient_Bps, sizeof( down_speed ) );
|
||||
if( peer->rateToClient_KBps > 0 )
|
||||
tr_formatter_speed_KBps( down_speed, peer->rateToClient_KBps, sizeof( down_speed ) );
|
||||
else
|
||||
*down_speed = '\0';
|
||||
|
||||
|
@ -1248,9 +1247,9 @@ refreshPeerRow( GtkListStore * store,
|
|||
PEER_COL_UPLOAD_REQUEST_COUNT_STRING, up_count,
|
||||
PEER_COL_DOWNLOAD_REQUEST_COUNT_INT, peer->pendingReqsToPeer,
|
||||
PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING, down_count,
|
||||
PEER_COL_DOWNLOAD_RATE_INT, peer->rateToClient_Bps,
|
||||
PEER_COL_DOWNLOAD_RATE_DOUBLE, peer->rateToClient_KBps,
|
||||
PEER_COL_DOWNLOAD_RATE_STRING, down_speed,
|
||||
PEER_COL_UPLOAD_RATE_INT, peer->rateToPeer_Bps,
|
||||
PEER_COL_UPLOAD_RATE_DOUBLE, peer->rateToPeer_KBps,
|
||||
PEER_COL_UPLOAD_RATE_STRING, up_speed,
|
||||
PEER_COL_STATUS, peer->flagStr,
|
||||
PEER_COL_WAS_UPDATED, TRUE,
|
||||
|
@ -1396,7 +1395,7 @@ refreshWebseedList( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
int j;
|
||||
const tr_torrent * tor = torrents[i];
|
||||
const tr_info * inf = tr_torrentInfo( tor );
|
||||
int * speeds_Bps = tr_torrentWebSpeeds_Bps( tor );
|
||||
double * speeds_KBps = tr_torrentWebSpeeds_KBps( tor );
|
||||
for( j=0; j<inf->webseedCount; ++j ) {
|
||||
char buf[128];
|
||||
char key[256];
|
||||
|
@ -1407,17 +1406,17 @@ refreshWebseedList( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
ref = g_hash_table_lookup( hash, key );
|
||||
p = gtk_tree_row_reference_get_path( ref );
|
||||
gtk_tree_model_get_iter( model, &iter, p );
|
||||
if( speeds_Bps[j] > 0 )
|
||||
tr_formatter_speed( buf, speeds_Bps[j], sizeof( buf ) );
|
||||
if( speeds_KBps[j] > 0 )
|
||||
tr_formatter_speed_Bps( buf, speeds_KBps[j], sizeof( buf ) );
|
||||
else
|
||||
*buf = '\0';
|
||||
gtk_list_store_set( store, &iter, WEBSEED_COL_DOWNLOAD_RATE_INT, speeds_Bps[j],
|
||||
gtk_list_store_set( store, &iter, WEBSEED_COL_DOWNLOAD_RATE_DOUBLE, speeds_KBps[j],
|
||||
WEBSEED_COL_DOWNLOAD_RATE_STRING, buf,
|
||||
WEBSEED_COL_WAS_UPDATED, TRUE,
|
||||
-1 );
|
||||
gtk_tree_path_free( p );
|
||||
}
|
||||
tr_free( speeds_Bps );
|
||||
tr_free( speeds_KBps );
|
||||
}
|
||||
|
||||
/* step 4: remove webseeds that have disappeared */
|
||||
|
@ -1611,13 +1610,13 @@ setPeerViewColumns( GtkTreeView * peer_view )
|
|||
r = gtk_cell_renderer_text_new( );
|
||||
g_object_set( G_OBJECT( r ), "xalign", 1.0f, NULL );
|
||||
c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
|
||||
sort_col = PEER_COL_DOWNLOAD_RATE_INT;
|
||||
sort_col = PEER_COL_DOWNLOAD_RATE_DOUBLE;
|
||||
break;
|
||||
case PEER_COL_UPLOAD_RATE_STRING:
|
||||
r = gtk_cell_renderer_text_new( );
|
||||
g_object_set( G_OBJECT( r ), "xalign", 1.0f, NULL );
|
||||
c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL );
|
||||
sort_col = PEER_COL_UPLOAD_RATE_INT;
|
||||
sort_col = PEER_COL_UPLOAD_RATE_DOUBLE;
|
||||
break;
|
||||
|
||||
case PEER_COL_STATUS:
|
||||
|
@ -1686,7 +1685,7 @@ peer_page_new( struct DetailsImpl * di )
|
|||
str = getWebseedColumnNames( WEBSEED_COL_DOWNLOAD_RATE_STRING );
|
||||
r = gtk_cell_renderer_text_new( );
|
||||
c = gtk_tree_view_column_new_with_attributes( str, r, "text", WEBSEED_COL_DOWNLOAD_RATE_STRING, NULL );
|
||||
gtk_tree_view_column_set_sort_column_id( c, WEBSEED_COL_DOWNLOAD_RATE_INT );
|
||||
gtk_tree_view_column_set_sort_column_id( c, WEBSEED_COL_DOWNLOAD_RATE_DOUBLE );
|
||||
gtk_tree_view_append_column( GTK_TREE_VIEW( v ), c );
|
||||
|
||||
w = gtk_scrolled_window_new( NULL, NULL );
|
||||
|
|
16
gtk/main.c
16
gtk/main.c
|
@ -1203,17 +1203,17 @@ prefschanged( TrCore * core UNUSED, const char * key, gpointer data )
|
|||
{
|
||||
tr_sessionLimitSpeed( tr, TR_DOWN, pref_flag_get( key ) );
|
||||
}
|
||||
else if( !strcmp( key, TR_PREFS_KEY_DSPEED_Bps ) )
|
||||
else if( !strcmp( key, TR_PREFS_KEY_DSPEED_KBps ) )
|
||||
{
|
||||
tr_sessionSetSpeedLimit_Bps( tr, TR_DOWN, pref_int_get( key ) );
|
||||
tr_sessionSetSpeedLimit_KBps( tr, TR_DOWN, pref_int_get( key ) );
|
||||
}
|
||||
else if( !strcmp( key, TR_PREFS_KEY_USPEED_ENABLED ) )
|
||||
{
|
||||
tr_sessionLimitSpeed( tr, TR_UP, pref_flag_get( key ) );
|
||||
}
|
||||
else if( !strcmp( key, TR_PREFS_KEY_USPEED_Bps ) )
|
||||
else if( !strcmp( key, TR_PREFS_KEY_USPEED_KBps ) )
|
||||
{
|
||||
tr_sessionSetSpeedLimit_Bps( tr, TR_UP, pref_int_get( key ) );
|
||||
tr_sessionSetSpeedLimit_KBps( tr, TR_UP, pref_int_get( key ) );
|
||||
}
|
||||
else if( !strcmp( key, TR_PREFS_KEY_RATIO_ENABLED ) )
|
||||
{
|
||||
|
@ -1299,13 +1299,13 @@ prefschanged( TrCore * core UNUSED, const char * key, gpointer data )
|
|||
{
|
||||
tr_sessionSetProxyPort( tr, pref_int_get( key ) );
|
||||
}
|
||||
else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_UP_Bps ) )
|
||||
else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_UP_KBps ) )
|
||||
{
|
||||
tr_sessionSetAltSpeed_Bps( tr, TR_UP, pref_int_get( key ) );
|
||||
tr_sessionSetAltSpeed_KBps( tr, TR_UP, pref_int_get( key ) );
|
||||
}
|
||||
else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps ) )
|
||||
else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps ) )
|
||||
{
|
||||
tr_sessionSetAltSpeed_Bps( tr, TR_DOWN, pref_int_get( key ) );
|
||||
tr_sessionSetAltSpeed_KBps( tr, TR_DOWN, pref_int_get( key ) );
|
||||
}
|
||||
else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_ENABLED ) )
|
||||
{
|
||||
|
|
12
gtk/msgwin.c
12
gtk/msgwin.c
|
@ -37,12 +37,12 @@ enum
|
|||
|
||||
struct MsgData
|
||||
{
|
||||
TrCore * core;
|
||||
GtkTreeView * view;
|
||||
GtkListStore * store;
|
||||
GtkTreeModel * filter;
|
||||
GtkTreeModel * sort;
|
||||
int maxLevel;
|
||||
TrCore * core;
|
||||
GtkTreeView * view;
|
||||
GtkListStore * store;
|
||||
GtkTreeModel * filter;
|
||||
GtkTreeModel * sort;
|
||||
tr_msg_level maxLevel;
|
||||
gboolean isPaused;
|
||||
guint refresh_tag;
|
||||
};
|
||||
|
|
|
@ -154,8 +154,8 @@ getProgressString( const tr_torrent * tor,
|
|||
static char*
|
||||
getShortTransferString( const tr_torrent * tor,
|
||||
const tr_stat * torStat,
|
||||
int uploadSpeed_Bps,
|
||||
int downloadSpeed_Bps,
|
||||
double uploadSpeed_KBps,
|
||||
double downloadSpeed_KBps,
|
||||
char * buf,
|
||||
size_t buflen )
|
||||
{
|
||||
|
@ -165,9 +165,9 @@ getShortTransferString( const tr_torrent * tor,
|
|||
const int haveUp = haveMeta && torStat->peersGettingFromUs > 0;
|
||||
|
||||
if( haveDown )
|
||||
tr_strlspeed( downStr, downloadSpeed_Bps, sizeof( downStr ) );
|
||||
tr_formatter_speed_KBps( downStr, downloadSpeed_KBps, sizeof( downStr ) );
|
||||
if( haveUp )
|
||||
tr_strlspeed( upStr, uploadSpeed_Bps, sizeof( upStr ) );
|
||||
tr_formatter_speed_KBps( upStr, uploadSpeed_KBps, sizeof( upStr ) );
|
||||
|
||||
if( haveDown && haveUp )
|
||||
/* 1==down speed, 2==down arrow, 3==up speed, 4==down arrow */
|
||||
|
@ -194,8 +194,8 @@ getShortTransferString( const tr_torrent * tor,
|
|||
static char*
|
||||
getShortStatusString( const tr_torrent * tor,
|
||||
const tr_stat * torStat,
|
||||
int uploadSpeed_Bps,
|
||||
int downloadSpeed_Bps )
|
||||
double uploadSpeed_KBps,
|
||||
double downloadSpeed_KBps )
|
||||
{
|
||||
GString * gstr = g_string_new( NULL );
|
||||
|
||||
|
@ -228,7 +228,7 @@ getShortStatusString( const tr_torrent * tor,
|
|||
g_string_append_printf( gstr, _( "Ratio %s" ), buf );
|
||||
g_string_append( gstr, ", " );
|
||||
}
|
||||
getShortTransferString( tor, torStat, uploadSpeed_Bps, downloadSpeed_Bps, buf, sizeof( buf ) );
|
||||
getShortTransferString( tor, torStat, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof( buf ) );
|
||||
g_string_append( gstr, buf );
|
||||
break;
|
||||
}
|
||||
|
@ -243,8 +243,8 @@ getShortStatusString( const tr_torrent * tor,
|
|||
static char*
|
||||
getStatusString( const tr_torrent * tor,
|
||||
const tr_stat * torStat,
|
||||
const int uploadSpeed_Bps,
|
||||
const int downloadSpeed_Bps )
|
||||
const double uploadSpeed_KBps,
|
||||
const double downloadSpeed_KBps )
|
||||
{
|
||||
const int isActive = torStat->activity != TR_STATUS_STOPPED;
|
||||
const int isChecking = torStat->activity == TR_STATUS_CHECK
|
||||
|
@ -265,7 +265,7 @@ getStatusString( const tr_torrent * tor,
|
|||
case TR_STATUS_CHECK_WAIT:
|
||||
case TR_STATUS_CHECK:
|
||||
{
|
||||
char * pch = getShortStatusString( tor, torStat, uploadSpeed_Bps, downloadSpeed_Bps );
|
||||
char * pch = getShortStatusString( tor, torStat, uploadSpeed_KBps, downloadSpeed_KBps );
|
||||
g_string_assign( gstr, pch );
|
||||
g_free( pch );
|
||||
break;
|
||||
|
@ -309,7 +309,7 @@ getStatusString( const tr_torrent * tor,
|
|||
if( isActive && !isChecking )
|
||||
{
|
||||
char buf[256];
|
||||
getShortTransferString( tor, torStat, uploadSpeed_Bps, downloadSpeed_Bps, buf, sizeof( buf ) );
|
||||
getShortTransferString( tor, torStat, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof( buf ) );
|
||||
if( *buf )
|
||||
g_string_append_printf( gstr, " - %s", buf );
|
||||
}
|
||||
|
@ -336,10 +336,10 @@ struct TorrentCellRendererPrivate
|
|||
control when the speed displays get updated. this is done to keep
|
||||
the individual torrents' speeds and the status bar's overall speed
|
||||
in sync even if they refresh at slightly different times */
|
||||
int upload_speed_Bps;
|
||||
double upload_speed_KBps;
|
||||
|
||||
/* @see upload_speed_Bps */
|
||||
int download_speed_Bps;
|
||||
double download_speed_KBps;
|
||||
|
||||
gboolean compact;
|
||||
};
|
||||
|
@ -397,7 +397,7 @@ get_size_compact( TorrentCellRenderer * cell,
|
|||
|
||||
icon = get_icon( tor, COMPACT_ICON_SIZE, widget );
|
||||
name = tr_torrentInfo( tor )->name;
|
||||
status = getShortStatusString( tor, st, p->upload_speed_Bps, p->download_speed_Bps );
|
||||
status = getShortStatusString( tor, st, p->upload_speed_KBps, p->download_speed_KBps );
|
||||
|
||||
/* get the idealized cell dimensions */
|
||||
g_object_set( p->icon_renderer, "pixbuf", icon, NULL );
|
||||
|
@ -455,7 +455,7 @@ get_size_full( TorrentCellRenderer * cell,
|
|||
|
||||
icon = get_icon( tor, FULL_ICON_SIZE, widget );
|
||||
name = inf->name;
|
||||
status = getStatusString( tor, st, p->upload_speed_Bps, p->download_speed_Bps );
|
||||
status = getStatusString( tor, st, p->upload_speed_KBps, p->download_speed_KBps );
|
||||
progress = getProgressString( tor, inf, st );
|
||||
|
||||
/* get the idealized cell dimensions */
|
||||
|
@ -559,7 +559,7 @@ render_compact( TorrentCellRenderer * cell,
|
|||
|
||||
icon = get_icon( tor, COMPACT_ICON_SIZE, widget );
|
||||
name = tr_torrentInfo( tor )->name;
|
||||
status = getShortStatusString( tor, st, p->upload_speed_Bps, p->download_speed_Bps );
|
||||
status = getShortStatusString( tor, st, p->upload_speed_KBps, p->download_speed_KBps );
|
||||
|
||||
/* get the cell dimensions */
|
||||
g_object_set( p->icon_renderer, "pixbuf", icon, NULL );
|
||||
|
@ -663,7 +663,7 @@ render_full( TorrentCellRenderer * cell,
|
|||
|
||||
icon = get_icon( tor, FULL_ICON_SIZE, widget );
|
||||
name = inf->name;
|
||||
status = getStatusString( tor, st, p->upload_speed_Bps, p->download_speed_Bps );
|
||||
status = getStatusString( tor, st, p->upload_speed_KBps, p->download_speed_KBps );
|
||||
progress = getProgressString( tor, inf, st );
|
||||
|
||||
/* get the idealized cell dimensions */
|
||||
|
@ -782,11 +782,11 @@ torrent_cell_renderer_set_property( GObject * object,
|
|||
|
||||
switch( property_id )
|
||||
{
|
||||
case P_TORRENT: p->tor = g_value_get_pointer( v ); break;
|
||||
case P_UPLOAD_SPEED: p->upload_speed_Bps = g_value_get_int( v ); break;
|
||||
case P_DOWNLOAD_SPEED: p->download_speed_Bps = g_value_get_int( v ); break;
|
||||
case P_BAR_HEIGHT: p->bar_height = g_value_get_int( v ); break;
|
||||
case P_COMPACT: p->compact = g_value_get_boolean( v ); break;
|
||||
case P_TORRENT: p->tor = g_value_get_pointer( v ); break;
|
||||
case P_UPLOAD_SPEED: p->upload_speed_KBps = g_value_get_double( v ); break;
|
||||
case P_DOWNLOAD_SPEED: p->download_speed_KBps = g_value_get_double( v ); break;
|
||||
case P_BAR_HEIGHT: p->bar_height = g_value_get_int( v ); break;
|
||||
case P_COMPACT: p->compact = g_value_get_boolean( v ); break;
|
||||
default: G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, pspec ); break;
|
||||
}
|
||||
}
|
||||
|
@ -803,8 +803,8 @@ torrent_cell_renderer_get_property( GObject * object,
|
|||
switch( property_id )
|
||||
{
|
||||
case P_TORRENT: g_value_set_pointer( v, p->tor ); break;
|
||||
case P_UPLOAD_SPEED: g_value_set_int( v, p->upload_speed_Bps ); break;
|
||||
case P_DOWNLOAD_SPEED: g_value_set_int( v, p->download_speed_Bps ); break;
|
||||
case P_UPLOAD_SPEED: g_value_set_double( v, p->upload_speed_KBps ); break;
|
||||
case P_DOWNLOAD_SPEED: g_value_set_double( v, p->download_speed_KBps ); break;
|
||||
case P_BAR_HEIGHT: g_value_set_int( v, p->bar_height ); break;
|
||||
case P_COMPACT: g_value_set_boolean( v, p->compact ); break;
|
||||
default: G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, pspec ); break;
|
||||
|
@ -853,16 +853,16 @@ torrent_cell_renderer_class_init( TorrentCellRendererClass * klass )
|
|||
G_PARAM_READWRITE ) );
|
||||
|
||||
g_object_class_install_property( gobject_class, P_UPLOAD_SPEED,
|
||||
g_param_spec_int( "piece-upload-speed", NULL,
|
||||
"tr_stat.pieceUploadSpeed_Bps",
|
||||
0, INT_MAX, 0,
|
||||
G_PARAM_READWRITE ) );
|
||||
g_param_spec_double( "piece-upload-speed", NULL,
|
||||
"tr_stat.pieceUploadSpeed_KBps",
|
||||
0, INT_MAX, 0,
|
||||
G_PARAM_READWRITE ) );
|
||||
|
||||
g_object_class_install_property( gobject_class, P_DOWNLOAD_SPEED,
|
||||
g_param_spec_int( "piece-download-speed", NULL,
|
||||
"tr_stat.pieceDownloadSpeed_Bps",
|
||||
0, INT_MAX, 0,
|
||||
G_PARAM_READWRITE ) );
|
||||
g_param_spec_double( "piece-download-speed", NULL,
|
||||
"tr_stat.pieceDownloadSpeed_KBps",
|
||||
0, INT_MAX, 0,
|
||||
G_PARAM_READWRITE ) );
|
||||
|
||||
g_object_class_install_property( gobject_class, P_BAR_HEIGHT,
|
||||
g_param_spec_int( "bar-height", NULL,
|
||||
|
|
|
@ -776,8 +776,8 @@ tr_core_init( GTypeInstance * instance,
|
|||
G_TYPE_STRING, /* collated name */
|
||||
TR_TORRENT_TYPE, /* TrTorrent object */
|
||||
G_TYPE_POINTER, /* tr_torrent* */
|
||||
G_TYPE_INT, /* tr_stat.pieceUploadSpeed_Bps */
|
||||
G_TYPE_INT, /* tr_stat.pieceDownloadSpeed_Bps */
|
||||
G_TYPE_DOUBLE, /* tr_stat.pieceUploadSpeed_KBps */
|
||||
G_TYPE_DOUBLE, /* tr_stat.pieceDownloadSpeed_KBps */
|
||||
G_TYPE_INT }; /* tr_stat.status */
|
||||
|
||||
p = self->priv = G_TYPE_INSTANCE_GET_PRIVATE( self,
|
||||
|
@ -920,8 +920,8 @@ tr_core_add_torrent( TrCore * self,
|
|||
MC_NAME_COLLATED, collated,
|
||||
MC_TORRENT, gtor,
|
||||
MC_TORRENT_RAW, tor,
|
||||
MC_SPEED_UP, st->pieceUploadSpeed_Bps,
|
||||
MC_SPEED_DOWN, st->pieceDownloadSpeed_Bps,
|
||||
MC_SPEED_UP, st->pieceUploadSpeed_KBps,
|
||||
MC_SPEED_DOWN, st->pieceDownloadSpeed_KBps,
|
||||
MC_ACTIVITY, st->activity,
|
||||
-1 );
|
||||
|
||||
|
@ -1322,8 +1322,8 @@ update_foreach( GtkTreeModel * model,
|
|||
gpointer data UNUSED )
|
||||
{
|
||||
int oldActivity, newActivity;
|
||||
int oldUpSpeed, newUpSpeed;
|
||||
int oldDownSpeed, newDownSpeed;
|
||||
double oldUpSpeed, newUpSpeed;
|
||||
double oldDownSpeed, newDownSpeed;
|
||||
const tr_stat * st;
|
||||
TrTorrent * gtor;
|
||||
|
||||
|
@ -1338,14 +1338,14 @@ update_foreach( GtkTreeModel * model,
|
|||
/* get the new states */
|
||||
st = tr_torrentStat( tr_torrent_handle( gtor ) );
|
||||
newActivity = st->activity;
|
||||
newUpSpeed = st->pieceUploadSpeed_Bps;
|
||||
newDownSpeed = st->pieceDownloadSpeed_Bps;
|
||||
newUpSpeed = st->pieceUploadSpeed_KBps;
|
||||
newDownSpeed = st->pieceDownloadSpeed_KBps;
|
||||
|
||||
/* updating the model triggers off resort/refresh,
|
||||
so don't do it unless something's actually changed... */
|
||||
if( ( newActivity != oldActivity ) ||
|
||||
( newUpSpeed != oldUpSpeed ) ||
|
||||
( newDownSpeed != oldDownSpeed ) )
|
||||
if( ( newActivity != oldActivity )
|
||||
|| gtr_compare_double( newUpSpeed, oldUpSpeed, 3 )
|
||||
|| gtr_compare_double( newDownSpeed, oldDownSpeed, 3 ) )
|
||||
{
|
||||
gtk_list_store_set( GTK_LIST_STORE( model ), iter,
|
||||
MC_ACTIVITY, newActivity,
|
||||
|
@ -1575,7 +1575,7 @@ tr_core_set_pref_double( TrCore * self,
|
|||
{
|
||||
const double oldval = pref_double_get( key );
|
||||
|
||||
if( oldval != newval )
|
||||
if( gtr_compare_double( oldval, newval, 4 ) )
|
||||
{
|
||||
pref_double_set( key, newval );
|
||||
commitPrefsChange( self, key );
|
||||
|
|
|
@ -67,8 +67,8 @@ popup( GtkStatusIcon * self,
|
|||
void
|
||||
tr_icon_refresh( gpointer vicon )
|
||||
{
|
||||
int Bps;
|
||||
int limit;
|
||||
double KBps;
|
||||
double limit;
|
||||
char up[64];
|
||||
char upLimit[64];
|
||||
char down[64];
|
||||
|
@ -79,34 +79,34 @@ tr_icon_refresh( gpointer vicon )
|
|||
tr_session * session = tr_core_session( g_object_get_data( G_OBJECT( icon ), "tr-core" ) );
|
||||
|
||||
/* up */
|
||||
Bps = tr_sessionGetRawSpeed_Bps( session, TR_UP );
|
||||
if( Bps < 1 )
|
||||
KBps = tr_sessionGetRawSpeed_KBps( session, TR_UP );
|
||||
if( KBps < 0.001 )
|
||||
g_strlcpy( up, idle, sizeof( up ) );
|
||||
else
|
||||
tr_formatter_speed( up, Bps, sizeof( up ) );
|
||||
tr_formatter_speed_KBps( up, KBps, sizeof( up ) );
|
||||
|
||||
/* up limit */
|
||||
if( !tr_sessionGetActiveSpeedLimit_Bps( session, TR_UP, &limit ) )
|
||||
if( !tr_sessionGetActiveSpeedLimit_KBps( session, TR_UP, &limit ) )
|
||||
*upLimit = '\0';
|
||||
else {
|
||||
char buf[64];
|
||||
tr_strlspeed( buf, limit, sizeof( buf ) );
|
||||
tr_formatter_speed_KBps( buf, limit, sizeof( buf ) );
|
||||
g_snprintf( upLimit, sizeof( upLimit ), _( "(Limit: %s)" ), buf );
|
||||
}
|
||||
|
||||
/* down */
|
||||
Bps = tr_sessionGetRawSpeed_Bps( session, TR_DOWN );
|
||||
if( Bps < 1 )
|
||||
KBps = tr_sessionGetRawSpeed_KBps( session, TR_DOWN );
|
||||
if( KBps < 0.001 )
|
||||
g_strlcpy( down, idle, sizeof( down ) );
|
||||
else
|
||||
tr_formatter_speed( down, Bps, sizeof( down ) );
|
||||
tr_formatter_speed_KBps( down, KBps, sizeof( down ) );
|
||||
|
||||
/* down limit */
|
||||
if( !tr_sessionGetActiveSpeedLimit_Bps( session, TR_DOWN, &limit ) )
|
||||
if( !tr_sessionGetActiveSpeedLimit_KBps( session, TR_DOWN, &limit ) )
|
||||
*downLimit = '\0';
|
||||
else {
|
||||
char buf[64];
|
||||
tr_strlspeed( buf, limit, sizeof( buf ) );
|
||||
tr_formatter_speed_KBps( buf, limit, sizeof( buf ) );
|
||||
g_snprintf( downLimit, sizeof( downLimit ), _( "(Limit: %s)" ), buf );
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
***
|
||||
**/
|
||||
|
||||
#define MULTIPLIER_KEY "multiplier-key"
|
||||
#define PREF_KEY "pref-key"
|
||||
|
||||
static void
|
||||
|
@ -106,16 +105,15 @@ spun_cb_idle( gpointer spin )
|
|||
{
|
||||
/* update the core */
|
||||
const char * key = g_object_get_data( o, PREF_KEY );
|
||||
const int multiplier = GPOINTER_TO_INT( g_object_get_data( o, MULTIPLIER_KEY ) );
|
||||
|
||||
if (data->isDouble)
|
||||
{
|
||||
const double value = gtk_spin_button_get_value( GTK_SPIN_BUTTON( spin ) ) * multiplier;
|
||||
const double value = gtk_spin_button_get_value( GTK_SPIN_BUTTON( spin ) );
|
||||
tr_core_set_pref_double( TR_CORE( data->core ), key, value );
|
||||
}
|
||||
else
|
||||
{
|
||||
const int value = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( spin ) ) * multiplier;
|
||||
const int value = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( spin ) );
|
||||
tr_core_set_pref_int( TR_CORE( data->core ), key, value );
|
||||
}
|
||||
|
||||
|
@ -164,16 +162,14 @@ spun_cb_double( GtkSpinButton * w, gpointer core )
|
|||
static GtkWidget*
|
||||
new_spin_button( const char * key,
|
||||
gpointer core,
|
||||
int multiplier,
|
||||
int low,
|
||||
int high,
|
||||
int step )
|
||||
{
|
||||
GtkWidget * w = gtk_spin_button_new_with_range( low, high, step );
|
||||
g_object_set_data( G_OBJECT( w ), MULTIPLIER_KEY, GINT_TO_POINTER( multiplier ) );
|
||||
g_object_set_data_full( G_OBJECT( w ), PREF_KEY, g_strdup( key ), g_free );
|
||||
gtk_spin_button_set_digits( GTK_SPIN_BUTTON( w ), 0 );
|
||||
gtk_spin_button_set_value( GTK_SPIN_BUTTON( w ), pref_int_get( key ) / multiplier );
|
||||
gtk_spin_button_set_value( GTK_SPIN_BUTTON( w ), pref_int_get( key ) );
|
||||
g_signal_connect( w, "value-changed", G_CALLBACK( spun_cb_int ), core );
|
||||
return w;
|
||||
}
|
||||
|
@ -181,13 +177,11 @@ new_spin_button( const char * key,
|
|||
static GtkWidget*
|
||||
new_spin_button_double( const char * key,
|
||||
gpointer core,
|
||||
int multiplier,
|
||||
double low,
|
||||
double high,
|
||||
double step )
|
||||
{
|
||||
GtkWidget * w = gtk_spin_button_new_with_range( low, high, step );
|
||||
g_object_set_data( G_OBJECT( w ), MULTIPLIER_KEY, GINT_TO_POINTER( multiplier ) );
|
||||
g_object_set_data_full( G_OBJECT( w ), PREF_KEY, g_strdup( key ), g_free );
|
||||
gtk_spin_button_set_digits( GTK_SPIN_BUTTON( w ), 2 );
|
||||
gtk_spin_button_set_value( GTK_SPIN_BUTTON( w ), pref_double_get( key ) );
|
||||
|
@ -329,7 +323,7 @@ torrentPage( GObject * core )
|
|||
|
||||
s = _( "_Seed torrent until its ratio reaches:" );
|
||||
w = new_check_button( s, TR_PREFS_KEY_RATIO_ENABLED, core );
|
||||
w2 = new_spin_button_double( TR_PREFS_KEY_RATIO, core, 1, 0, INT_MAX, .05 );
|
||||
w2 = new_spin_button_double( TR_PREFS_KEY_RATIO, core, 0, INT_MAX, .05 );
|
||||
gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_RATIO_ENABLED ) );
|
||||
g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 );
|
||||
hig_workarea_add_row_w( t, &row, w, w2, NULL );
|
||||
|
@ -806,7 +800,7 @@ webPage( GObject * core )
|
|||
hig_workarea_add_wide_control( t, &row, h );
|
||||
|
||||
/* port */
|
||||
w = new_spin_button( TR_PREFS_KEY_RPC_PORT, core, 1, 0, USHRT_MAX, 1 );
|
||||
w = new_spin_button( TR_PREFS_KEY_RPC_PORT, core, 0, USHRT_MAX, 1 );
|
||||
page->widgets = g_slist_append( page->widgets, w );
|
||||
w = hig_workarea_add_row( t, &row, _( "Listening _port:" ), w, NULL );
|
||||
page->widgets = g_slist_append( page->widgets, w );
|
||||
|
@ -1011,7 +1005,7 @@ trackerPage( GObject * core )
|
|||
w = hig_workarea_add_row( t, &row, s, w, NULL );
|
||||
page->proxy_widgets = g_slist_append( page->proxy_widgets, w );
|
||||
|
||||
w = new_spin_button( TR_PREFS_KEY_PROXY_PORT, core, 1, 0, USHRT_MAX, 1 );
|
||||
w = new_spin_button( TR_PREFS_KEY_PROXY_PORT, core, 0, USHRT_MAX, 1 );
|
||||
page->proxy_widgets = g_slist_append( page->proxy_widgets, w );
|
||||
w = hig_workarea_add_row( t, &row, _( "Proxy _port:" ), w, NULL );
|
||||
page->proxy_widgets = g_slist_append( page->proxy_widgets, w );
|
||||
|
@ -1219,14 +1213,14 @@ bandwidthPage( GObject * core )
|
|||
|
||||
g_snprintf( buf, sizeof( buf ), _( "Limit _download speed (%s):" ), _(speed_K_str) );
|
||||
w = new_check_button( buf, TR_PREFS_KEY_DSPEED_ENABLED, core );
|
||||
w2 = new_spin_button( TR_PREFS_KEY_DSPEED_Bps, core, speed_K, 0, INT_MAX, 5 );
|
||||
w2 = new_spin_button( TR_PREFS_KEY_DSPEED_KBps, core, 0, INT_MAX, 5 );
|
||||
gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_DSPEED_ENABLED ) );
|
||||
g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 );
|
||||
hig_workarea_add_row_w( t, &row, w, w2, NULL );
|
||||
|
||||
g_snprintf( buf, sizeof( buf ), _( "Limit _upload speed (%s):" ), _(speed_K_str) );
|
||||
w = new_check_button( buf, TR_PREFS_KEY_USPEED_ENABLED, core );
|
||||
w2 = new_spin_button( TR_PREFS_KEY_USPEED_Bps, core, speed_K, 0, INT_MAX, 5 );
|
||||
w2 = new_spin_button( TR_PREFS_KEY_USPEED_KBps, core, 0, INT_MAX, 5 );
|
||||
gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_USPEED_ENABLED ) );
|
||||
g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 );
|
||||
hig_workarea_add_row_w( t, &row, w, w2, NULL );
|
||||
|
@ -1250,11 +1244,11 @@ bandwidthPage( GObject * core )
|
|||
hig_workarea_add_wide_control( t, &row, w );
|
||||
|
||||
g_snprintf( buf, sizeof( buf ), _( "Limit do_wnload speed (%s):" ), _(speed_K_str) );
|
||||
w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, core, speed_K, 0, INT_MAX, 5 );
|
||||
w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, core, 0, INT_MAX, 5 );
|
||||
hig_workarea_add_row( t, &row, buf, w, NULL );
|
||||
|
||||
g_snprintf( buf, sizeof( buf ), _( "Limit u_pload speed (%s):" ), _(speed_K_str) );
|
||||
w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_UP_Bps, core, speed_K, 0, INT_MAX, 5 );
|
||||
w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_UP_KBps, core, 0, INT_MAX, 5 );
|
||||
hig_workarea_add_row( t, &row, buf, w, NULL );
|
||||
|
||||
s = _( "_Scheduled times:" );
|
||||
|
@ -1369,7 +1363,7 @@ peerPage( GObject * core )
|
|||
hig_workarea_add_section_title( t, &row, _( "Incoming Peers" ) );
|
||||
|
||||
s = _( "_Port for incoming connections:" );
|
||||
w = data->portSpin = new_spin_button( TR_PREFS_KEY_PEER_PORT, core, 1, 1, USHRT_MAX, 1 );
|
||||
w = data->portSpin = new_spin_button( TR_PREFS_KEY_PEER_PORT, core, 1, USHRT_MAX, 1 );
|
||||
hig_workarea_add_row( t, &row, s, w, NULL );
|
||||
|
||||
h = gtk_hbox_new( FALSE, GUI_PAD_BIG );
|
||||
|
@ -1394,9 +1388,9 @@ peerPage( GObject * core )
|
|||
hig_workarea_add_section_divider( t, &row );
|
||||
hig_workarea_add_section_title( t, &row, _( "Limits" ) );
|
||||
|
||||
w = new_spin_button( TR_PREFS_KEY_PEER_LIMIT_TORRENT, core, 1, 1, 300, 5 );
|
||||
w = new_spin_button( TR_PREFS_KEY_PEER_LIMIT_TORRENT, core, 1, 300, 5 );
|
||||
hig_workarea_add_row( t, &row, _( "Maximum peers per _torrent:" ), w, NULL );
|
||||
w = new_spin_button( TR_PREFS_KEY_PEER_LIMIT_GLOBAL, core, 1, 1, 3000, 5 );
|
||||
w = new_spin_button( TR_PREFS_KEY_PEER_LIMIT_GLOBAL, core, 1, 3000, 5 );
|
||||
hig_workarea_add_row( t, &row, _( "Maximum peers _overall:" ), w, NULL );
|
||||
|
||||
hig_workarea_finish( t, &row );
|
||||
|
|
|
@ -205,8 +205,8 @@ prefsChanged( TrCore * core UNUSED,
|
|||
tr_window_update( (TrWindow*)wind );
|
||||
}
|
||||
else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_ENABLED ) ||
|
||||
!strcmp( key, TR_PREFS_KEY_ALT_SPEED_UP_Bps ) ||
|
||||
!strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps ) )
|
||||
!strcmp( key, TR_PREFS_KEY_ALT_SPEED_UP_KBps ) ||
|
||||
!strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps ) )
|
||||
{
|
||||
syncAltSpeedButton( p );
|
||||
}
|
||||
|
@ -266,8 +266,8 @@ syncAltSpeedButton( PrivateData * p )
|
|||
const char * stock = b ? "alt-speed-on" : "alt-speed-off";
|
||||
GtkWidget * w = p->alt_speed_button;
|
||||
|
||||
tr_strlspeed( u, pref_int_get( TR_PREFS_KEY_ALT_SPEED_UP_Bps ), sizeof( u ) );
|
||||
tr_strlspeed( d, pref_int_get( TR_PREFS_KEY_ALT_SPEED_DOWN_Bps ), sizeof( d ) );
|
||||
tr_formatter_speed_KBps( u, pref_int_get( TR_PREFS_KEY_ALT_SPEED_UP_KBps ), sizeof( u ) );
|
||||
tr_formatter_speed_KBps( d, pref_int_get( TR_PREFS_KEY_ALT_SPEED_DOWN_KBps ), sizeof( d ) );
|
||||
fmt = b ? _( "Click to disable Temporary Speed Limits\n(%1$s down, %2$s up)" )
|
||||
: _( "Click to enable Temporary Speed Limits\n(%1$s down, %2$s up)" );
|
||||
str = g_strdup_printf( fmt, d, u );
|
||||
|
@ -388,11 +388,11 @@ onSpeedSet( GtkCheckMenuItem * check, gpointer vp )
|
|||
const char * key;
|
||||
PrivateData * p = vp;
|
||||
GObject * o = G_OBJECT( check );
|
||||
const int Bps = GPOINTER_TO_INT( g_object_get_data( o, SPEED_KEY ) ) * speed_K;
|
||||
const int KBps = GPOINTER_TO_INT( g_object_get_data( o, SPEED_KEY ) );
|
||||
tr_direction dir = GPOINTER_TO_INT( g_object_get_data( o, DIRECTION_KEY ) );
|
||||
|
||||
key = dir==TR_UP ? TR_PREFS_KEY_USPEED_Bps : TR_PREFS_KEY_DSPEED_Bps;
|
||||
tr_core_set_pref_int( p->core, key, Bps );
|
||||
key = dir==TR_UP ? TR_PREFS_KEY_USPEED_KBps : TR_PREFS_KEY_DSPEED_KBps;
|
||||
tr_core_set_pref_int( p->core, key, KBps );
|
||||
|
||||
key = dir==TR_UP ? TR_PREFS_KEY_USPEED_ENABLED : TR_PREFS_KEY_DSPEED_ENABLED;
|
||||
tr_core_set_pref_bool( p->core, key, TRUE );
|
||||
|
@ -541,7 +541,7 @@ onOptionsClicked( GtkButton * button UNUSED, gpointer vp )
|
|||
PrivateData * p = vp;
|
||||
|
||||
w = p->speedlimit_on_item[TR_DOWN];
|
||||
tr_strlspeed( buf1, pref_int_get( TR_PREFS_KEY_DSPEED_Bps ), sizeof( buf1 ) );
|
||||
tr_formatter_speed_KBps( buf1, pref_int_get( TR_PREFS_KEY_DSPEED_KBps ), sizeof( buf1 ) );
|
||||
gtk_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( w ) ) ), buf1 );
|
||||
|
||||
b = pref_flag_get( TR_PREFS_KEY_DSPEED_ENABLED );
|
||||
|
@ -549,7 +549,7 @@ onOptionsClicked( GtkButton * button UNUSED, gpointer vp )
|
|||
gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( w ), TRUE );
|
||||
|
||||
w = p->speedlimit_on_item[TR_UP];
|
||||
tr_strlspeed( buf1, pref_int_get( TR_PREFS_KEY_USPEED_Bps ), sizeof( buf1 ) );
|
||||
tr_formatter_speed_KBps( buf1, pref_int_get( TR_PREFS_KEY_USPEED_KBps ), sizeof( buf1 ) );
|
||||
gtk_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( w ) ) ), buf1 );
|
||||
|
||||
b = pref_flag_get( TR_PREFS_KEY_USPEED_ENABLED );
|
||||
|
@ -842,13 +842,13 @@ updateSpeeds( PrivateData * p )
|
|||
if( session != NULL )
|
||||
{
|
||||
char buf[128];
|
||||
int up=0, down=0;
|
||||
double up=0, down=0;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel * model = tr_core_model( p->core );
|
||||
|
||||
if( gtk_tree_model_get_iter_first( model, &iter ) ) do
|
||||
{
|
||||
int u, d;
|
||||
double u, d;
|
||||
gtk_tree_model_get( model, &iter, MC_SPEED_UP, &u,
|
||||
MC_SPEED_DOWN, &d,
|
||||
-1 );
|
||||
|
@ -857,10 +857,10 @@ updateSpeeds( PrivateData * p )
|
|||
}
|
||||
while( gtk_tree_model_iter_next( model, &iter ) );
|
||||
|
||||
tr_strlspeed( buf, down, sizeof( buf ) );
|
||||
tr_formatter_speed_KBps( buf, down, sizeof( buf ) );
|
||||
gtk_label_set_text( GTK_LABEL( p->dl_lb ), buf );
|
||||
|
||||
tr_strlspeed( buf, up, sizeof( buf ) );
|
||||
tr_formatter_speed_KBps( buf, up, sizeof( buf ) );
|
||||
gtk_label_set_text( GTK_LABEL( p->ul_lb ), buf );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#define TR_WINDOW_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <libtransmission/utils.h> /* tr_formatter_speed_KBps() */
|
||||
#include "tr-core.h"
|
||||
|
||||
typedef GtkWindow TrWindow;
|
||||
|
|
19
gtk/util.c
19
gtk/util.c
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include <ctype.h> /* isxdigit() */
|
||||
#include <errno.h>
|
||||
#include <math.h> /* pow() */
|
||||
#include <stdlib.h> /* free() */
|
||||
#include <string.h> /* strcmp() */
|
||||
|
||||
|
@ -127,6 +128,20 @@ gtr_lockfile( const char * filename )
|
|||
****
|
||||
***/
|
||||
|
||||
int
|
||||
gtr_compare_double( const double a, const double b, int decimal_places )
|
||||
{
|
||||
const int64_t ia = (int64_t)(a * pow( 10, decimal_places ) );
|
||||
const int64_t ib = (int64_t)(b * pow( 10, decimal_places ) );
|
||||
if( ia < ib ) return -1;
|
||||
if( ia > ib ) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
const char*
|
||||
gtr_get_unicode_string( int i )
|
||||
{
|
||||
|
@ -156,7 +171,7 @@ tr_strlsize( char * buf, guint64 bytes, size_t buflen )
|
|||
if( !bytes )
|
||||
g_strlcpy( buf, _( "None" ), buflen );
|
||||
else
|
||||
tr_formatter_size( buf, bytes, buflen );
|
||||
tr_formatter_size_B( buf, bytes, buflen );
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
@ -167,7 +182,7 @@ tr_strlspeed( char * buf, int bytes_per_second, size_t buflen )
|
|||
if( bytes_per_second < 1 )
|
||||
g_strlcpy( buf, _( "None" ), buflen );
|
||||
else
|
||||
tr_formatter_speed( buf, bytes_per_second, buflen );
|
||||
tr_formatter_speed_Bps( buf, bytes_per_second, buflen );
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -77,6 +77,10 @@ char* tr_strltime( char * buf, int secs, size_t buflen );
|
|||
/* similar to asctime, but is utf8-clean */
|
||||
char* gtr_localtime( time_t time );
|
||||
|
||||
|
||||
int gtr_compare_double( const double a, const double b, int decimal_places );
|
||||
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
|
|
@ -225,7 +225,7 @@ tr_cacheSetLimit( tr_cache * cache, int64_t max_bytes )
|
|||
cache->max_bytes = max_bytes;
|
||||
cache->max_blocks = getMaxBlocks( max_bytes );
|
||||
|
||||
tr_formatter_mem( buf, cache->max_bytes, sizeof( buf ) );
|
||||
tr_formatter_mem_B( buf, cache->max_bytes, sizeof( buf ) );
|
||||
tr_ndbg( MY_NAME, "Maximum cache size set to %s (%d blocks)", buf, cache->max_blocks );
|
||||
|
||||
return cacheTrim( cache );
|
||||
|
|
|
@ -2269,14 +2269,14 @@ tr_peerMgrGetWebseedSpeed_Bps( const tr_torrent * tor, uint64_t now )
|
|||
}
|
||||
|
||||
|
||||
int*
|
||||
tr_peerMgrWebSpeeds_Bps( const tr_torrent * tor )
|
||||
double*
|
||||
tr_peerMgrWebSpeeds_KBps( const tr_torrent * tor )
|
||||
{
|
||||
const Torrent * t = tor->torrentPeers;
|
||||
const tr_webseed ** webseeds;
|
||||
int i;
|
||||
int webseedCount;
|
||||
int * ret;
|
||||
double * ret;
|
||||
uint64_t now;
|
||||
|
||||
assert( t->manager );
|
||||
|
@ -2285,12 +2285,16 @@ tr_peerMgrWebSpeeds_Bps( const tr_torrent * tor )
|
|||
webseeds = (const tr_webseed**) tr_ptrArrayBase( &t->webseeds );
|
||||
webseedCount = tr_ptrArraySize( &t->webseeds );
|
||||
assert( webseedCount == tor->info.webseedCount );
|
||||
ret = tr_new0( int, webseedCount );
|
||||
ret = tr_new0( double, webseedCount );
|
||||
now = tr_date( );
|
||||
|
||||
for( i=0; i<webseedCount; ++i )
|
||||
if( !tr_webseedGetSpeed_Bps( webseeds[i], now, &ret[i] ) )
|
||||
for( i=0; i<webseedCount; ++i ) {
|
||||
int Bps;
|
||||
if( tr_webseedGetSpeed_Bps( webseeds[i], now, &Bps ) )
|
||||
ret[i] = Bps / (double)tr_speed_K;
|
||||
else
|
||||
ret[i] = -1.0;
|
||||
}
|
||||
|
||||
managerUnlock( t->manager );
|
||||
return ret;
|
||||
|
@ -2336,8 +2340,8 @@ tr_peerMgrPeerStats( const tr_torrent * tor,
|
|||
stat->from = atom->from;
|
||||
stat->progress = peer->progress;
|
||||
stat->isEncrypted = tr_peerIoIsEncrypted( peer->io ) ? 1 : 0;
|
||||
stat->rateToPeer_Bps = tr_peerGetPieceSpeed_Bps( peer, now, TR_CLIENT_TO_PEER );
|
||||
stat->rateToClient_Bps = tr_peerGetPieceSpeed_Bps( peer, now, TR_PEER_TO_CLIENT );
|
||||
stat->rateToPeer_KBps = toSpeedKBps( tr_peerGetPieceSpeed_Bps( peer, now, TR_CLIENT_TO_PEER ) );
|
||||
stat->rateToClient_KBps = toSpeedKBps( tr_peerGetPieceSpeed_Bps( peer, now, TR_PEER_TO_CLIENT ) );
|
||||
stat->peerIsChoked = peer->peerIsChoked;
|
||||
stat->peerIsInterested = peer->peerIsInterested;
|
||||
stat->clientIsChoked = peer->clientIsChoked;
|
||||
|
|
|
@ -227,7 +227,7 @@ struct tr_peer_stat* tr_peerMgrPeerStats( const tr_torrent * tor,
|
|||
|
||||
int tr_peerMgrGetWebseedSpeed_Bps( const tr_torrent * tor, uint64_t now );
|
||||
|
||||
int* tr_peerMgrWebSpeeds_Bps( const tr_torrent * tor );
|
||||
double* tr_peerMgrWebSpeeds_KBps( const tr_torrent * tor );
|
||||
|
||||
|
||||
int tr_peerGetPieceSpeed_Bps( const tr_peer * peer,
|
||||
|
|
|
@ -442,8 +442,8 @@ addPeers( const tr_torrent * tor,
|
|||
tr_bencDictAddBool( d, "peerIsInterested", peer->peerIsInterested );
|
||||
tr_bencDictAddInt ( d, "port", peer->port );
|
||||
tr_bencDictAddReal( d, "progress", peer->progress );
|
||||
tr_bencDictAddInt ( d, "rateToClient", peer->rateToClient_Bps );
|
||||
tr_bencDictAddInt ( d, "rateToPeer", peer->rateToPeer_Bps );
|
||||
tr_bencDictAddReal( d, "rateToClient", peer->rateToClient_KBps );
|
||||
tr_bencDictAddReal( d, "rateToPeer", peer->rateToPeer_KBps );
|
||||
}
|
||||
|
||||
tr_torrentPeersFree( peers, peerCount );
|
||||
|
@ -484,7 +484,7 @@ addField( const tr_torrent * tor, tr_benc * d, const char * key )
|
|||
else if( tr_streq( key, keylen, "downloadedEver" ) )
|
||||
tr_bencDictAddInt( d, key, st->downloadedEver );
|
||||
else if( tr_streq( key, keylen, "downloadLimit" ) )
|
||||
tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit_Bps( tor, TR_DOWN ) );
|
||||
tr_bencDictAddReal( d, key, tr_torrentGetSpeedLimit_KBps( tor, TR_DOWN ) );
|
||||
else if( tr_streq( key, keylen, "downloadLimited" ) )
|
||||
tr_bencDictAddBool( d, key, tr_torrentUsesSpeedLimit( tor, TR_DOWN ) );
|
||||
else if( tr_streq( key, keylen, "error" ) )
|
||||
|
@ -569,9 +569,9 @@ addField( const tr_torrent * tor, tr_benc * d, const char * key )
|
|||
tr_bencListAddInt( p, inf->files[i].priority );
|
||||
}
|
||||
else if( tr_streq( key, keylen, "rateDownload" ) )
|
||||
tr_bencDictAddInt( d, key, st->pieceDownloadSpeed_Bps );
|
||||
tr_bencDictAddReal( d, key, st->pieceDownloadSpeed_KBps );
|
||||
else if( tr_streq( key, keylen, "rateUpload" ) )
|
||||
tr_bencDictAddInt( d, key, st->pieceUploadSpeed_Bps );
|
||||
tr_bencDictAddReal( d, key, st->pieceUploadSpeed_KBps );
|
||||
else if( tr_streq( key, keylen, "recheckProgress" ) )
|
||||
tr_bencDictAddReal( d, key, st->recheckProgress );
|
||||
else if( tr_streq( key, keylen, "seedRatioLimit" ) )
|
||||
|
@ -599,7 +599,7 @@ addField( const tr_torrent * tor, tr_benc * d, const char * key )
|
|||
else if( tr_streq( key, keylen, "uploadedEver" ) )
|
||||
tr_bencDictAddInt( d, key, st->uploadedEver );
|
||||
else if( tr_streq( key, keylen, "uploadLimit" ) )
|
||||
tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit_Bps( tor, TR_UP ) );
|
||||
tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit_KBps( tor, TR_UP ) );
|
||||
else if( tr_streq( key, keylen, "uploadLimited" ) )
|
||||
tr_bencDictAddBool( d, key, tr_torrentUsesSpeedLimit( tor, TR_UP ) );
|
||||
else if( tr_streq( key, keylen, "uploadRatio" ) )
|
||||
|
@ -1004,13 +1004,13 @@ torrentSet( tr_session * session,
|
|||
if( !errmsg && tr_bencDictFindList( args_in, "priority-normal", &files ) )
|
||||
errmsg = setFilePriorities( tor, TR_PRI_NORMAL, files );
|
||||
if( tr_bencDictFindInt( args_in, "downloadLimit", &tmp ) )
|
||||
tr_torrentSetSpeedLimit_Bps( tor, TR_DOWN, tmp );
|
||||
tr_torrentSetSpeedLimit_KBps( tor, TR_DOWN, tmp );
|
||||
if( tr_bencDictFindBool( args_in, "downloadLimited", &boolVal ) )
|
||||
tr_torrentUseSpeedLimit( tor, TR_DOWN, boolVal );
|
||||
if( tr_bencDictFindBool( args_in, "honorsSessionLimits", &boolVal ) )
|
||||
tr_torrentUseSessionLimits( tor, boolVal );
|
||||
if( tr_bencDictFindInt( args_in, "uploadLimit", &tmp ) )
|
||||
tr_torrentSetSpeedLimit_Bps( tor, TR_UP, tmp );
|
||||
tr_torrentSetSpeedLimit_KBps( tor, TR_UP, tmp );
|
||||
if( tr_bencDictFindBool( args_in, "uploadLimited", &boolVal ) )
|
||||
tr_torrentUseSpeedLimit( tor, TR_UP, boolVal );
|
||||
if( tr_bencDictFindReal( args_in, "seedRatioLimit", &d ) )
|
||||
|
@ -1407,12 +1407,12 @@ sessionSet( tr_session * session,
|
|||
|
||||
assert( idle_data == NULL );
|
||||
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_MAX_CACHE_SIZE, &i ) )
|
||||
tr_sessionSetCacheLimit( session, d );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_UP_Bps, &i ) )
|
||||
tr_sessionSetAltSpeed_Bps( session, TR_UP, i );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, &i ) )
|
||||
tr_sessionSetAltSpeed_Bps( session, TR_DOWN, i );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, &i ) )
|
||||
tr_sessionSetCacheLimit_MB( session, i );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_UP_KBps, &i ) )
|
||||
tr_sessionSetAltSpeed_KBps( session, TR_UP, i );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, &i ) )
|
||||
tr_sessionSetAltSpeed_KBps( session, TR_DOWN, i );
|
||||
if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_ALT_SPEED_ENABLED, &boolVal ) )
|
||||
tr_sessionUseAltSpeed( session, boolVal );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &i ) )
|
||||
|
@ -1461,12 +1461,12 @@ sessionSet( tr_session * session,
|
|||
tr_sessionSetTorrentDoneScriptEnabled( session, boolVal );
|
||||
if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_TRASH_ORIGINAL, &boolVal ) )
|
||||
tr_sessionSetDeleteSource( session, boolVal );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_DSPEED_Bps, &i ) )
|
||||
tr_sessionSetSpeedLimit_Bps( session, TR_DOWN, i );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_DSPEED_KBps, &i ) )
|
||||
tr_sessionSetSpeedLimit_KBps( session, TR_DOWN, i );
|
||||
if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_DSPEED_ENABLED, &boolVal ) )
|
||||
tr_sessionLimitSpeed( session, TR_DOWN, boolVal );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_USPEED_Bps, &i ) )
|
||||
tr_sessionSetSpeedLimit_Bps( session, TR_UP, i );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_USPEED_KBps, &i ) )
|
||||
tr_sessionSetSpeedLimit_KBps( session, TR_UP, i );
|
||||
if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_USPEED_ENABLED, &boolVal ) )
|
||||
tr_sessionLimitSpeed( session, TR_UP, boolVal );
|
||||
if( tr_bencDictFindStr( args_in, TR_PREFS_KEY_ENCRYPTION, &str ) ) {
|
||||
|
@ -1507,11 +1507,11 @@ sessionStats( tr_session * session,
|
|||
tr_sessionGetStats( session, ¤tStats );
|
||||
tr_sessionGetCumulativeStats( session, &cumulativeStats );
|
||||
|
||||
tr_bencDictAddInt( args_out, "activeTorrentCount", running );
|
||||
tr_bencDictAddInt( args_out, "downloadSpeed", tr_sessionGetPieceSpeed_Bps( session, TR_DOWN ) );
|
||||
tr_bencDictAddInt( args_out, "pausedTorrentCount", total - running );
|
||||
tr_bencDictAddInt( args_out, "torrentCount", total );
|
||||
tr_bencDictAddInt( args_out, "uploadSpeed", tr_sessionGetPieceSpeed_Bps( session, TR_UP ) );
|
||||
tr_bencDictAddInt ( args_out, "activeTorrentCount", running );
|
||||
tr_bencDictAddReal( args_out, "downloadSpeed", tr_sessionGetPieceSpeed_KBps( session, TR_DOWN ) );
|
||||
tr_bencDictAddInt ( args_out, "pausedTorrentCount", total - running );
|
||||
tr_bencDictAddInt ( args_out, "torrentCount", total );
|
||||
tr_bencDictAddReal( args_out, "uploadSpeed", tr_sessionGetPieceSpeed_KBps( session, TR_UP ) );
|
||||
|
||||
d = tr_bencDictAddDict( args_out, "cumulative-stats", 5 );
|
||||
tr_bencDictAddInt( d, "downloadedBytes", cumulativeStats.downloadedBytes );
|
||||
|
@ -1540,15 +1540,15 @@ sessionGet( tr_session * s,
|
|||
tr_benc * d = args_out;
|
||||
|
||||
assert( idle_data == NULL );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP_Bps, tr_sessionGetAltSpeed_Bps(s,TR_UP) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, tr_sessionGetAltSpeed_Bps(s,TR_DOWN) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP_KBps, tr_sessionGetAltSpeed_KBps(s,TR_UP) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, tr_sessionGetAltSpeed_KBps(s,TR_DOWN) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_ENABLED, tr_sessionUsesAltSpeed(s) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, tr_sessionGetAltSpeedBegin(s) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_END,tr_sessionGetAltSpeedEnd(s) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY,tr_sessionGetAltSpeedDay(s) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, tr_sessionUsesAltSpeedTime(s) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled( s ) );
|
||||
tr_bencDictAddReal( d, TR_PREFS_KEY_MAX_CACHE_SIZE, tr_sessionGetCacheLimit( s ) );
|
||||
tr_bencDictAddReal( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, tr_sessionGetCacheLimit_MB( s ) );
|
||||
tr_bencDictAddInt ( d, "blocklist-size", tr_blocklistGetRuleCount( s ) );
|
||||
tr_bencDictAddStr ( d, "config-dir", tr_sessionGetConfigDir( s ) );
|
||||
tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR, tr_sessionGetDownloadDir( s ) );
|
||||
|
@ -1569,9 +1569,9 @@ sessionGet( tr_session * s,
|
|||
tr_bencDictAddBool( d, "seedRatioLimited", tr_sessionIsRatioLimited( s ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_START, !tr_sessionGetPaused( s ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_TRASH_ORIGINAL, tr_sessionGetDeleteSource( s ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_Bps, tr_sessionGetSpeedLimit_Bps( s, TR_UP ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_KBps, tr_sessionGetSpeedLimit_KBps( s, TR_UP ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, tr_sessionIsSpeedLimited( s, TR_UP ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_Bps, tr_sessionGetSpeedLimit_Bps( s, TR_DOWN ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_KBps, tr_sessionGetSpeedLimit_KBps( s, TR_DOWN ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, tr_sessionIsSpeedLimited( s, TR_DOWN ) );
|
||||
tr_bencDictAddStr ( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, tr_sessionGetTorrentDoneScript( s ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, tr_sessionIsTorrentDoneScriptEnabled( s ) );
|
||||
|
|
|
@ -55,7 +55,7 @@ enum
|
|||
{
|
||||
SAVE_INTERVAL_SECS = 120,
|
||||
|
||||
DEFAULT_CACHE_SIZE_BYTES = ( 2 * 1024 * 1024 ) /* 2 MiB */
|
||||
DEFAULT_CACHE_SIZE_MB = 2
|
||||
};
|
||||
|
||||
|
||||
|
@ -241,44 +241,18 @@ tr_sessionGetPublicAddress( const tr_session * session, int tr_af_type )
|
|||
#define TR_DEFAULT_ENCRYPTION TR_ENCRYPTION_PREFERRED
|
||||
#endif
|
||||
|
||||
static tr_bool
|
||||
getSpeedFromDict( tr_benc * dict, const char * key_in, int64_t * Bps )
|
||||
{
|
||||
int64_t i;
|
||||
char key[256];
|
||||
|
||||
/* 1. look for it ending in -Bps */
|
||||
tr_snprintf( key, sizeof( key ), "%s-Bps", key_in );
|
||||
if( tr_bencDictFindInt( dict, key, &i ) ) {
|
||||
*Bps = i;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* 2. look for it an old entry without the -Bps suffix.
|
||||
if found, interpret that to be either kB/s or KiB/s
|
||||
based on the formatter settings in utils */
|
||||
if( tr_bencDictFindInt( dict, key_in, &i ) ) {
|
||||
*Bps = i * tr_formatter_speed_k( );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
tr_sessionGetDefaultSettings( const char * configDir UNUSED, tr_benc * d )
|
||||
{
|
||||
const int speed_K = tr_formatter_speed_k( );
|
||||
|
||||
assert( tr_bencIsDict( d ) );
|
||||
|
||||
tr_bencDictReserve( d, 60 );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, FALSE );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAX_CACHE_SIZE, DEFAULT_CACHE_SIZE_BYTES );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, DEFAULT_CACHE_SIZE_MB );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, TRUE );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED, FALSE );
|
||||
tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR, tr_getDefaultDownloadDir( ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_Bps, 100 * speed_K );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_KBps, 100 );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, FALSE );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ENCRYPTION, TR_DEFAULT_ENCRYPTION );
|
||||
tr_bencDictAddStr ( d, TR_PREFS_KEY_INCOMPLETE_DIR, tr_getDefaultDownloadDir( ) );
|
||||
|
@ -317,13 +291,13 @@ tr_sessionGetDefaultSettings( const char * configDir UNUSED, tr_benc * d )
|
|||
tr_bencDictAddStr ( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, "" );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, FALSE );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_ENABLED, FALSE );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP_Bps, 50 * speed_K ); /* half the regular */
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, 50 * speed_K ); /* half the regular */
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP_KBps, 50 ); /* half the regular */
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, 50 ); /* half the regular */
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, 540 ); /* 9am */
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, FALSE );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_END, 1020 ); /* 5pm */
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, TR_SCHED_ALL );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_Bps, 100 * speed_K );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_KBps, 100 );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, FALSE );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_UMASK, 022 );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, 14 );
|
||||
|
@ -340,11 +314,11 @@ tr_sessionGetSettings( tr_session * s, struct tr_benc * d )
|
|||
|
||||
tr_bencDictReserve( d, 60 );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled( s ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAX_CACHE_SIZE, tr_cacheGetLimit( s->cache ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, tr_cacheGetLimit( s->cache ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, s->isDHTEnabled );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED, s->isLPDEnabled );
|
||||
tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR, s->downloadDir );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_Bps, tr_sessionGetSpeedLimit_Bps( s, TR_DOWN ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_KBps, tr_sessionGetSpeedLimit_KBps( s, TR_DOWN ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, tr_sessionIsSpeedLimited( s, TR_DOWN ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ENCRYPTION, s->encryptionMode );
|
||||
tr_bencDictAddStr ( d, TR_PREFS_KEY_INCOMPLETE_DIR, tr_sessionGetIncompleteDir( s ) );
|
||||
|
@ -385,13 +359,13 @@ tr_sessionGetSettings( tr_session * s, struct tr_benc * d )
|
|||
tr_bencDictAddBool( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, tr_sessionIsTorrentDoneScriptEnabled( s ) );
|
||||
tr_bencDictAddStr ( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, tr_sessionGetTorrentDoneScript( s ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_ENABLED, tr_sessionUsesAltSpeed( s ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP_Bps, tr_sessionGetAltSpeed_Bps( s, TR_UP ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, tr_sessionGetAltSpeed_Bps( s, TR_DOWN ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP_KBps, tr_sessionGetAltSpeed_KBps( s, TR_UP ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, tr_sessionGetAltSpeed_KBps( s, TR_DOWN ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, tr_sessionGetAltSpeedBegin( s ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, tr_sessionUsesAltSpeedTime( s ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_END, tr_sessionGetAltSpeedEnd( s ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, tr_sessionGetAltSpeedDay( s ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_Bps, tr_sessionGetSpeedLimit_Bps( s, TR_UP ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_KBps, tr_sessionGetSpeedLimit_KBps( s, TR_UP ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, tr_sessionIsSpeedLimited( s, TR_UP ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_UMASK, s->umask );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, s->uploadSlotsPerTorrent );
|
||||
|
@ -538,7 +512,7 @@ tr_sessionInit( const char * tag,
|
|||
session = tr_new0( tr_session, 1 );
|
||||
session->bandwidth = tr_bandwidthNew( session, NULL );
|
||||
session->lock = tr_lockNew( );
|
||||
session->cache = tr_cacheNew( DEFAULT_CACHE_SIZE_BYTES );
|
||||
session->cache = tr_cacheNew( 1024*1024*2 );
|
||||
session->tag = tr_strdup( tag );
|
||||
session->magicNumber = SESSION_MAGIC_NUMBER;
|
||||
session->buffer = tr_valloc( SESSION_BUFFER_SIZE );
|
||||
|
@ -704,8 +678,8 @@ sessionSetImpl( void * vdata )
|
|||
}
|
||||
|
||||
/* misc features */
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_MAX_CACHE_SIZE, &i ) )
|
||||
tr_sessionSetCacheLimit( session, i );
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, &i ) )
|
||||
tr_sessionSetCacheLimit_MB( session, i );
|
||||
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_LAZY_BITFIELD, &boolVal ) )
|
||||
tr_sessionSetLazyBitfieldEnabled( session, boolVal );
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, &i ) )
|
||||
|
@ -805,13 +779,13 @@ sessionSetImpl( void * vdata )
|
|||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, &i ) )
|
||||
session->uploadSlotsPerTorrent = i;
|
||||
|
||||
if( getSpeedFromDict( settings, "speed-limit-up", &i ) )
|
||||
tr_sessionSetSpeedLimit_Bps( session, TR_UP, i );
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_USPEED_KBps, &i ) )
|
||||
tr_sessionSetSpeedLimit_KBps( session, TR_UP, i );
|
||||
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_USPEED_ENABLED, &boolVal ) )
|
||||
tr_sessionLimitSpeed( session, TR_UP, boolVal );
|
||||
|
||||
if( getSpeedFromDict( settings, "speed-limit-down", &i ) )
|
||||
tr_sessionSetSpeedLimit_Bps( session, TR_DOWN, i );
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_DSPEED_KBps, &i ) )
|
||||
tr_sessionSetSpeedLimit_KBps( session, TR_DOWN, i );
|
||||
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_DSPEED_ENABLED, &boolVal ) )
|
||||
tr_sessionLimitSpeed( session, TR_DOWN, boolVal );
|
||||
|
||||
|
@ -825,10 +799,10 @@ sessionSetImpl( void * vdata )
|
|||
**/
|
||||
|
||||
/* update the turtle mode's fields */
|
||||
if( getSpeedFromDict( settings, "alt-speed-up", &i ) )
|
||||
turtle->speedLimit_Bps[TR_UP] = i;
|
||||
if( getSpeedFromDict( settings, "alt-speed-down", &i ) )
|
||||
turtle->speedLimit_Bps[TR_DOWN] = i;
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_UP_KBps, &i ) )
|
||||
turtle->speedLimit_Bps[TR_UP] = toSpeedBytes( i );
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, &i ) )
|
||||
turtle->speedLimit_Bps[TR_DOWN] = toSpeedBytes( i );
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &i ) )
|
||||
turtle->beginMinute = i;
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_TIME_END, &i ) )
|
||||
|
@ -1127,7 +1101,7 @@ tr_sessionGetRatioLimit( const tr_session * session )
|
|||
***/
|
||||
|
||||
tr_bool
|
||||
tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session, tr_direction dir, int * setme )
|
||||
tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session, tr_direction dir, int * setme_Bps )
|
||||
{
|
||||
int isLimited = TRUE;
|
||||
|
||||
|
@ -1135,14 +1109,24 @@ tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session, tr_direction dir,
|
|||
return FALSE;
|
||||
|
||||
if( tr_sessionUsesAltSpeed( session ) )
|
||||
*setme = tr_sessionGetAltSpeed_Bps( session, dir );
|
||||
*setme_Bps = tr_sessionGetAltSpeed_Bps( session, dir );
|
||||
else if( tr_sessionIsSpeedLimited( session, dir ) )
|
||||
*setme = tr_sessionGetSpeedLimit_Bps( session, dir );
|
||||
*setme_Bps = tr_sessionGetSpeedLimit_Bps( session, dir );
|
||||
else
|
||||
isLimited = FALSE;
|
||||
|
||||
return isLimited;
|
||||
}
|
||||
tr_bool
|
||||
tr_sessionGetActiveSpeedLimit_KBps( const tr_session * session,
|
||||
tr_direction dir,
|
||||
double * setme_KBps )
|
||||
{
|
||||
int Bps;
|
||||
const tr_bool is_active = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &Bps );
|
||||
*setme_KBps = toSpeedKBps( Bps );
|
||||
return is_active;
|
||||
}
|
||||
|
||||
static void
|
||||
updateBandwidth( tr_session * session, tr_direction dir )
|
||||
|
@ -1304,6 +1288,11 @@ tr_sessionSetSpeedLimit_Bps( tr_session * s, tr_direction d, int Bps )
|
|||
|
||||
updateBandwidth( s, d );
|
||||
}
|
||||
void
|
||||
tr_sessionSetSpeedLimit_KBps( tr_session * s, tr_direction d, int KBps )
|
||||
{
|
||||
tr_sessionSetSpeedLimit_Bps( s, d, toSpeedBytes( KBps ) );
|
||||
}
|
||||
|
||||
int
|
||||
tr_sessionGetSpeedLimit_Bps( const tr_session * s, tr_direction d )
|
||||
|
@ -1313,6 +1302,11 @@ tr_sessionGetSpeedLimit_Bps( const tr_session * s, tr_direction d )
|
|||
|
||||
return s->speedLimit_Bps[d];
|
||||
}
|
||||
int
|
||||
tr_sessionGetSpeedLimit_KBps( const tr_session * s, tr_direction d )
|
||||
{
|
||||
return toSpeedKBps( tr_sessionGetSpeedLimit_Bps( s, d ) );
|
||||
}
|
||||
|
||||
void
|
||||
tr_sessionLimitSpeed( tr_session * s, tr_direction d, tr_bool b )
|
||||
|
@ -1351,6 +1345,12 @@ tr_sessionSetAltSpeed_Bps( tr_session * s, tr_direction d, int Bps )
|
|||
updateBandwidth( s, d );
|
||||
}
|
||||
|
||||
void
|
||||
tr_sessionSetAltSpeed_KBps( tr_session * s, tr_direction d, int KBps )
|
||||
{
|
||||
tr_sessionSetAltSpeed_Bps( s, d, toSpeedBytes( KBps ) );
|
||||
}
|
||||
|
||||
int
|
||||
tr_sessionGetAltSpeed_Bps( const tr_session * s, tr_direction d )
|
||||
{
|
||||
|
@ -1359,6 +1359,11 @@ tr_sessionGetAltSpeed_Bps( const tr_session * s, tr_direction d )
|
|||
|
||||
return s->turtle.speedLimit_Bps[d];
|
||||
}
|
||||
int
|
||||
tr_sessionGetAltSpeed_KBps( const tr_session * s, tr_direction d )
|
||||
{
|
||||
return toSpeedKBps( tr_sessionGetAltSpeed_Bps( s, d ) );
|
||||
}
|
||||
|
||||
static void
|
||||
userPokedTheClock( tr_session * s, struct tr_turtle_info * t )
|
||||
|
@ -1566,14 +1571,25 @@ tr_sessionGetDeleteSource( const tr_session * session )
|
|||
int
|
||||
tr_sessionGetPieceSpeed_Bps( const tr_session * session, tr_direction dir )
|
||||
{
|
||||
return tr_isSession( session ) ? tr_bandwidthGetPieceSpeed_Bps( session->bandwidth, 0, dir ) : 0.0;
|
||||
return tr_isSession( session ) ? tr_bandwidthGetPieceSpeed_Bps( session->bandwidth, 0, dir ) : 0;
|
||||
}
|
||||
double
|
||||
tr_sessionGetPieceSpeed_KBps( const tr_session * session, tr_direction dir )
|
||||
{
|
||||
return toSpeedKBps( tr_sessionGetPieceSpeed_Bps( session, dir ) );
|
||||
}
|
||||
|
||||
int
|
||||
tr_sessionGetRawSpeed_Bps( const tr_session * session, tr_direction dir )
|
||||
{
|
||||
return tr_isSession( session ) ? tr_bandwidthGetRawSpeed_Bps( session->bandwidth, 0, dir ) : 0.0;
|
||||
return tr_isSession( session ) ? tr_bandwidthGetRawSpeed_Bps( session->bandwidth, 0, dir ) : 0;
|
||||
}
|
||||
double
|
||||
tr_sessionGetRawSpeed_KBps( const tr_session * session, tr_direction dir )
|
||||
{
|
||||
return toSpeedKBps( tr_sessionGetRawSpeed_Bps( session, dir ) );
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
tr_sessionCountTorrents( const tr_session * session )
|
||||
|
@ -1876,20 +1892,31 @@ tr_sessionAllowsLPD( const tr_session * session )
|
|||
***/
|
||||
|
||||
void
|
||||
tr_sessionSetCacheLimit( tr_session * session, int64_t max_bytes )
|
||||
tr_sessionSetCacheLimit_B( tr_session * session, uint64_t max_bytes )
|
||||
{
|
||||
assert( tr_isSession( session ) );
|
||||
|
||||
tr_cacheSetLimit( session->cache, max_bytes );
|
||||
}
|
||||
void
|
||||
tr_sessionSetCacheLimit_MB( tr_session * session, int MB )
|
||||
{
|
||||
tr_sessionSetCacheLimit_B( session, toMemBytes( MB ) );
|
||||
}
|
||||
|
||||
int64_t
|
||||
tr_sessionGetCacheLimit( const tr_session * session )
|
||||
uint64_t
|
||||
tr_sessionGetCacheLimit_B( const tr_session * session )
|
||||
{
|
||||
assert( tr_isSession( session ) );
|
||||
|
||||
return tr_cacheGetLimit( session->cache );
|
||||
}
|
||||
int
|
||||
tr_sessionGetCacheLimit_MB( const tr_session * session )
|
||||
{
|
||||
return toMemMB( tr_sessionGetCacheLimit_B( session ) );
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
****
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "bencode.h"
|
||||
#include "bitfield.h"
|
||||
#include "utils.h"
|
||||
|
||||
typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
|
||||
|
||||
|
@ -248,4 +249,33 @@ static inline tr_bool tr_isPriority( tr_priority_t p )
|
|||
|| ( p == TR_PRI_HIGH );
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
static inline unsigned int toSpeedBytes ( unsigned int KBps ) { return KBps * tr_speed_K; }
|
||||
static inline double toSpeedKBps ( unsigned int Bps ) { return Bps / (double)tr_speed_K; }
|
||||
|
||||
static inline uint64_t toMemBytes ( unsigned int MB ) { uint64_t B = tr_mem_K * tr_mem_K; B *= MB; return B; }
|
||||
static inline int toMemMB ( uint64_t B ) { return B / tr_mem_K; }
|
||||
|
||||
/**
|
||||
**/
|
||||
|
||||
void tr_sessionSetCacheLimit_B ( tr_session * session, uint64_t B );
|
||||
uint64_t tr_sessionGetCacheLimit_B ( const tr_session * session );
|
||||
|
||||
int tr_sessionGetSpeedLimit_Bps( const tr_session *, tr_direction );
|
||||
int tr_sessionGetAltSpeed_Bps ( const tr_session *, tr_direction );
|
||||
int tr_sessionGetRawSpeed_Bps ( const tr_session *, tr_direction );
|
||||
int tr_sessionGetPieceSpeed_Bps( const tr_session *, tr_direction );
|
||||
|
||||
void tr_sessionSetSpeedLimit_Bps( tr_session *, tr_direction, int Bps );
|
||||
void tr_sessionSetAltSpeed_Bps ( tr_session *, tr_direction, int Bps );
|
||||
|
||||
tr_bool tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session,
|
||||
tr_direction dir,
|
||||
int * setme );
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -138,6 +138,11 @@ tr_torrentSetSpeedLimit_Bps( tr_torrent * tor, tr_direction dir, int Bps )
|
|||
if( tr_bandwidthSetDesiredSpeed_Bps( tor->bandwidth, dir, Bps ) )
|
||||
tr_torrentSetDirty( tor );
|
||||
}
|
||||
void
|
||||
tr_torrentSetSpeedLimit_KBps( tr_torrent * tor, tr_direction dir, int KBps )
|
||||
{
|
||||
tr_torrentSetSpeedLimit_Bps( tor, dir, toSpeedBytes( KBps ) );
|
||||
}
|
||||
|
||||
int
|
||||
tr_torrentGetSpeedLimit_Bps( const tr_torrent * tor, tr_direction dir )
|
||||
|
@ -147,6 +152,11 @@ tr_torrentGetSpeedLimit_Bps( const tr_torrent * tor, tr_direction dir )
|
|||
|
||||
return tr_bandwidthGetDesiredSpeed_Bps( tor->bandwidth, dir );
|
||||
}
|
||||
int
|
||||
tr_torrentGetSpeedLimit_KBps( const tr_torrent * tor, tr_direction dir )
|
||||
{
|
||||
return toSpeedKBps( tr_torrentGetSpeedLimit_Bps( tor, dir ) );
|
||||
}
|
||||
|
||||
void
|
||||
tr_torrentUseSpeedLimit( tr_torrent * tor, tr_direction dir, tr_bool do_use )
|
||||
|
@ -968,10 +978,10 @@ tr_torrentStat( tr_torrent * tor )
|
|||
|
||||
now = tr_date( );
|
||||
d = tr_peerMgrGetWebseedSpeed_Bps( tor, now );
|
||||
s->rawUploadSpeed_Bps = tr_bandwidthGetRawSpeed_Bps ( tor->bandwidth, now, TR_UP );
|
||||
s->pieceUploadSpeed_Bps = tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_UP );
|
||||
s->rawDownloadSpeed_Bps = d + tr_bandwidthGetRawSpeed_Bps ( tor->bandwidth, now, TR_DOWN );
|
||||
s->pieceDownloadSpeed_Bps = d + tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_DOWN );
|
||||
s->rawUploadSpeed_KBps = toSpeedKBps( tr_bandwidthGetRawSpeed_Bps ( tor->bandwidth, now, TR_UP ) );
|
||||
s->pieceUploadSpeed_KBps = toSpeedKBps( tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_UP ) );
|
||||
s->rawDownloadSpeed_KBps = toSpeedKBps( d + tr_bandwidthGetRawSpeed_Bps ( tor->bandwidth, now, TR_DOWN ) );
|
||||
s->pieceDownloadSpeed_KBps = toSpeedKBps( d + tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_DOWN ) );
|
||||
|
||||
usableSeeds += tor->info.webseedCount;
|
||||
|
||||
|
@ -1032,18 +1042,18 @@ tr_torrentStat( tr_torrent * tor )
|
|||
|
||||
case TR_STATUS_DOWNLOAD:
|
||||
if( ( tor->etaDLSpeedCalculatedAt + 800 ) < now ) {
|
||||
tor->etaDLSpeed_Bps = ( ( tor->etaDLSpeedCalculatedAt + 4000 ) < now )
|
||||
? s->pieceDownloadSpeed_Bps /* if no recent previous speed, no need to smooth */
|
||||
: ((tor->etaDLSpeed_Bps*4) + s->pieceDownloadSpeed_Bps)/5; /* smooth across 5 readings */
|
||||
tor->etaDLSpeed_KBps = ( ( tor->etaDLSpeedCalculatedAt + 4000 ) < now )
|
||||
? s->pieceDownloadSpeed_KBps /* if no recent previous speed, no need to smooth */
|
||||
: ((tor->etaDLSpeed_KBps*4.0) + s->pieceDownloadSpeed_KBps)/5.0; /* smooth across 5 readings */
|
||||
tor->etaDLSpeedCalculatedAt = now;
|
||||
}
|
||||
|
||||
if( s->leftUntilDone > s->desiredAvailable )
|
||||
s->eta = TR_ETA_NOT_AVAIL;
|
||||
else if( s->pieceDownloadSpeed_Bps < 1 )
|
||||
else if( tor->etaDLSpeed_KBps < 1 )
|
||||
s->eta = TR_ETA_UNKNOWN;
|
||||
else
|
||||
s->eta = s->leftUntilDone / tor->etaDLSpeed_Bps;
|
||||
s->eta = s->leftUntilDone / toSpeedBytes(tor->etaDLSpeed_KBps);
|
||||
break;
|
||||
|
||||
case TR_STATUS_SEED: {
|
||||
|
@ -1051,15 +1061,15 @@ tr_torrentStat( tr_torrent * tor )
|
|||
s->eta = TR_ETA_NOT_AVAIL;
|
||||
else {
|
||||
if( ( tor->etaULSpeedCalculatedAt + 800 ) < now ) {
|
||||
tor->etaULSpeed_Bps = ( ( tor->etaULSpeedCalculatedAt + 4000 ) < now )
|
||||
? s->pieceUploadSpeed_Bps /* if no recent previous speed, no need to smooth */
|
||||
: ((tor->etaULSpeed_Bps*4) + s->pieceUploadSpeed_Bps)/5; /* smooth across 5 readings */
|
||||
tor->etaULSpeed_KBps = ( ( tor->etaULSpeedCalculatedAt + 4000 ) < now )
|
||||
? s->pieceUploadSpeed_KBps /* if no recent previous speed, no need to smooth */
|
||||
: ((tor->etaULSpeed_KBps*4.0) + s->pieceUploadSpeed_KBps)/5.0; /* smooth across 5 readings */
|
||||
tor->etaULSpeedCalculatedAt = now;
|
||||
}
|
||||
if( s->pieceUploadSpeed_Bps < 1 )
|
||||
if( tor->etaULSpeed_KBps < 1 )
|
||||
s->eta = TR_ETA_UNKNOWN;
|
||||
else
|
||||
s->eta = seedRatioBytesLeft / tor->etaULSpeed_Bps;
|
||||
s->eta = seedRatioBytesLeft / toSpeedBytes(tor->etaULSpeed_KBps);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1193,10 +1203,10 @@ tr_torrentFilesFree( tr_file_stat * files,
|
|||
****
|
||||
***/
|
||||
|
||||
int*
|
||||
tr_torrentWebSpeeds_Bps( const tr_torrent * tor )
|
||||
double*
|
||||
tr_torrentWebSpeeds_KBps( const tr_torrent * tor )
|
||||
{
|
||||
return tr_isTorrent( tor ) ? tr_peerMgrWebSpeeds_Bps( tor ) : NULL;
|
||||
return tr_isTorrent( tor ) ? tr_peerMgrWebSpeeds_KBps( tor ) : NULL;
|
||||
}
|
||||
|
||||
tr_peer_stat *
|
||||
|
|
|
@ -210,9 +210,9 @@ struct tr_torrent
|
|||
uint64_t corruptPrev;
|
||||
|
||||
uint64_t etaDLSpeedCalculatedAt;
|
||||
int etaDLSpeed_Bps;
|
||||
double etaDLSpeed_KBps;
|
||||
uint64_t etaULSpeedCalculatedAt;
|
||||
int etaULSpeed_Bps;
|
||||
double etaULSpeed_KBps;
|
||||
|
||||
time_t addedDate;
|
||||
time_t activityDate;
|
||||
|
@ -421,4 +421,8 @@ char* tr_torrentBuildPartial( const tr_torrent *, tr_file_index_t fileNo );
|
|||
* piece size, etc. such as in BEP 9 where peers exchange metadata */
|
||||
void tr_torrentGotNewInfoDict( tr_torrent * tor );
|
||||
|
||||
void tr_torrentSetSpeedLimit_Bps ( tr_torrent *, tr_direction, int Bps );
|
||||
int tr_torrentGetSpeedLimit_Bps ( const tr_torrent *, tr_direction );
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -156,8 +156,8 @@ const char* tr_getDefaultDownloadDir( void );
|
|||
#define TR_DEFAULT_PEER_LIMIT_TORRENT_STR "60"
|
||||
|
||||
#define TR_PREFS_KEY_ALT_SPEED_ENABLED "alt-speed-enabled"
|
||||
#define TR_PREFS_KEY_ALT_SPEED_UP_Bps "alt-speed-up-Bps"
|
||||
#define TR_PREFS_KEY_ALT_SPEED_DOWN_Bps "alt-speed-down-Bps"
|
||||
#define TR_PREFS_KEY_ALT_SPEED_UP_KBps "alt-speed-up"
|
||||
#define TR_PREFS_KEY_ALT_SPEED_DOWN_KBps "alt-speed-down"
|
||||
#define TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN "alt-speed-time-begin"
|
||||
#define TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED "alt-speed-time-enabled"
|
||||
#define TR_PREFS_KEY_ALT_SPEED_TIME_END "alt-speed-time-end"
|
||||
|
@ -165,7 +165,7 @@ const char* tr_getDefaultDownloadDir( void );
|
|||
#define TR_PREFS_KEY_BIND_ADDRESS_IPV4 "bind-address-ipv4"
|
||||
#define TR_PREFS_KEY_BIND_ADDRESS_IPV6 "bind-address-ipv6"
|
||||
#define TR_PREFS_KEY_BLOCKLIST_ENABLED "blocklist-enabled"
|
||||
#define TR_PREFS_KEY_MAX_CACHE_SIZE "cache-size-bytes"
|
||||
#define TR_PREFS_KEY_MAX_CACHE_SIZE_MB "cache-size-mb"
|
||||
#define TR_PREFS_KEY_DHT_ENABLED "dht-enabled"
|
||||
#define TR_PREFS_KEY_LPD_ENABLED "lpd-enabled"
|
||||
#define TR_PREFS_KEY_DOWNLOAD_DIR "download-dir"
|
||||
|
@ -206,9 +206,9 @@ const char* tr_getDefaultDownloadDir( void );
|
|||
#define TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME "script-torrent-done-filename"
|
||||
#define TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED "script-torrent-done-enabled"
|
||||
#define TR_PREFS_KEY_RPC_WHITELIST "rpc-whitelist"
|
||||
#define TR_PREFS_KEY_DSPEED_Bps "speed-limit-down-Bps"
|
||||
#define TR_PREFS_KEY_DSPEED_KBps "speed-limit-down"
|
||||
#define TR_PREFS_KEY_DSPEED_ENABLED "speed-limit-down-enabled"
|
||||
#define TR_PREFS_KEY_USPEED_Bps "speed-limit-up-Bps"
|
||||
#define TR_PREFS_KEY_USPEED_KBps "speed-limit-up"
|
||||
#define TR_PREFS_KEY_USPEED_ENABLED "speed-limit-up-enabled"
|
||||
#define TR_PREFS_KEY_UMASK "umask"
|
||||
#define TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT "upload-slots-per-torrent"
|
||||
|
@ -598,8 +598,8 @@ void tr_sessionSetDHTEnabled( tr_session * session, tr_bool );
|
|||
tr_bool tr_sessionIsLPDEnabled( const tr_session * session );
|
||||
void tr_sessionSetLPDEnabled( tr_session * session, tr_bool enabled );
|
||||
|
||||
void tr_sessionSetCacheLimit( tr_session * session, int64_t bytes );
|
||||
int64_t tr_sessionGetCacheLimit( const tr_session * session );
|
||||
void tr_sessionSetCacheLimit_MB( tr_session * session, int mb );
|
||||
int tr_sessionGetCacheLimit_MB( const tr_session * session );
|
||||
|
||||
void tr_sessionSetLazyBitfieldEnabled( tr_session * session, tr_bool enabled );
|
||||
tr_bool tr_sessionIsLazyBitfieldEnabled( const tr_session * session );
|
||||
|
@ -657,8 +657,8 @@ tr_direction;
|
|||
**** Primary session speed limits
|
||||
***/
|
||||
|
||||
void tr_sessionSetSpeedLimit_Bps( tr_session *, tr_direction, int Bps );
|
||||
int tr_sessionGetSpeedLimit_Bps( const tr_session *, tr_direction );
|
||||
void tr_sessionSetSpeedLimit_KBps( tr_session *, tr_direction, int Bps );
|
||||
int tr_sessionGetSpeedLimit_KBps( const tr_session *, tr_direction );
|
||||
|
||||
void tr_sessionLimitSpeed ( tr_session *, tr_direction, tr_bool );
|
||||
tr_bool tr_sessionIsSpeedLimited ( const tr_session *, tr_direction );
|
||||
|
@ -668,8 +668,8 @@ tr_bool tr_sessionIsSpeedLimited ( const tr_session *, tr_direction );
|
|||
**** Alternative speed limits that are used during scheduled times
|
||||
***/
|
||||
|
||||
void tr_sessionSetAltSpeed_Bps( tr_session *, tr_direction, int Bps );
|
||||
int tr_sessionGetAltSpeed_Bps( const tr_session *, tr_direction );
|
||||
void tr_sessionSetAltSpeed_KBps( tr_session *, tr_direction, int Bps );
|
||||
int tr_sessionGetAltSpeed_KBps( const tr_session *, tr_direction );
|
||||
|
||||
void tr_sessionUseAltSpeed ( tr_session *, tr_bool );
|
||||
tr_bool tr_sessionUsesAltSpeed ( const tr_session * );
|
||||
|
@ -706,16 +706,16 @@ void tr_sessionClearAltSpeedFunc ( tr_session * );
|
|||
void tr_sessionSetAltSpeedFunc ( tr_session *, tr_altSpeedFunc *, void * );
|
||||
|
||||
|
||||
tr_bool tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session,
|
||||
tr_direction dir,
|
||||
int * setme );
|
||||
tr_bool tr_sessionGetActiveSpeedLimit_KBps( const tr_session * session,
|
||||
tr_direction dir,
|
||||
double * setme );
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
int tr_sessionGetRawSpeed_Bps ( const tr_session *, tr_direction );
|
||||
int tr_sessionGetPieceSpeed_Bps( const tr_session *, tr_direction );
|
||||
double tr_sessionGetRawSpeed_KBps ( const tr_session *, tr_direction );
|
||||
double tr_sessionGetPieceSpeed_KBps( const tr_session *, tr_direction );
|
||||
|
||||
void tr_sessionSetRatioLimited ( tr_session *, tr_bool isLimited );
|
||||
tr_bool tr_sessionIsRatioLimited ( const tr_session * );
|
||||
|
@ -1124,8 +1124,8 @@ char* tr_torrentFindFile( const tr_torrent * tor, tr_file_index_t fileNo );
|
|||
****
|
||||
***/
|
||||
|
||||
void tr_torrentSetSpeedLimit_Bps ( tr_torrent *, tr_direction, int KB_s );
|
||||
int tr_torrentGetSpeedLimit_Bps ( const tr_torrent *, tr_direction );
|
||||
void tr_torrentSetSpeedLimit_KBps ( tr_torrent *, tr_direction, int KBps );
|
||||
int tr_torrentGetSpeedLimit_KBps ( const tr_torrent *, tr_direction );
|
||||
|
||||
void tr_torrentUseSpeedLimit ( tr_torrent *, tr_direction, tr_bool );
|
||||
tr_bool tr_torrentUsesSpeedLimit ( const tr_torrent *, tr_direction );
|
||||
|
@ -1380,8 +1380,8 @@ typedef struct tr_peer_stat
|
|||
char flagStr[32];
|
||||
|
||||
float progress;
|
||||
int rateToPeer_Bps;
|
||||
int rateToClient_Bps;
|
||||
double rateToPeer_KBps;
|
||||
double rateToClient_KBps;
|
||||
|
||||
|
||||
/***
|
||||
|
@ -1544,7 +1544,7 @@ void tr_torrentTrackersFree( tr_tracker_stat * trackerStats,
|
|||
* return -1 instead of 0 KiB/s.
|
||||
* NOTE: always free this array with tr_free() when you're done with it.
|
||||
*/
|
||||
int* tr_torrentWebSpeeds_Bps( const tr_torrent * torrent );
|
||||
double* tr_torrentWebSpeeds_KBps( const tr_torrent * torrent );
|
||||
|
||||
typedef struct tr_file_stat
|
||||
{
|
||||
|
@ -1746,19 +1746,19 @@ typedef struct tr_stat
|
|||
|
||||
/** Speed all data being sent for this torrent.
|
||||
This includes piece data, protocol messages, and TCP overhead */
|
||||
int rawUploadSpeed_Bps;
|
||||
double rawUploadSpeed_KBps;
|
||||
|
||||
/** Speed all data being received for this torrent.
|
||||
This includes piece data, protocol messages, and TCP overhead */
|
||||
int rawDownloadSpeed_Bps;
|
||||
double rawDownloadSpeed_KBps;
|
||||
|
||||
/** Speed all piece being sent for this torrent.
|
||||
This ONLY counts piece data. */
|
||||
int pieceUploadSpeed_Bps;
|
||||
double pieceUploadSpeed_KBps;
|
||||
|
||||
/** Speed all piece being received for this torrent.
|
||||
This ONLY counts piece data. */
|
||||
int pieceDownloadSpeed_Bps;
|
||||
double pieceDownloadSpeed_KBps;
|
||||
|
||||
#define TR_ETA_NOT_AVAIL -1
|
||||
#define TR_ETA_UNKNOWN -2
|
||||
|
|
|
@ -1582,45 +1582,46 @@ tr_formatter_size_init( unsigned int kilo,
|
|||
}
|
||||
|
||||
char*
|
||||
tr_formatter_size( char * buf, uint64_t bytes, size_t buflen )
|
||||
tr_formatter_size_B( char * buf, uint64_t bytes, size_t buflen )
|
||||
{
|
||||
return formatter_get_size_str( &size_units, buf, bytes, buflen );
|
||||
}
|
||||
|
||||
static struct formatter_units speed_units;
|
||||
|
||||
unsigned int tr_speed_K = 0u;
|
||||
|
||||
void
|
||||
tr_formatter_speed_init( unsigned int kilo,
|
||||
const char * b, const char * kb,
|
||||
const char * mb, const char * gb )
|
||||
{
|
||||
tr_speed_K = kilo;
|
||||
formatter_init( &speed_units, kilo, b, kb, mb, gb );
|
||||
}
|
||||
|
||||
char*
|
||||
tr_formatter_speed( char * buf, uint64_t bytes_per_second, size_t buflen )
|
||||
tr_formatter_speed_Bps( char * buf, uint64_t bytes_per_second, size_t buflen )
|
||||
{
|
||||
return formatter_get_size_str( &speed_units, buf, bytes_per_second, buflen );
|
||||
}
|
||||
|
||||
unsigned int
|
||||
tr_formatter_speed_k( void )
|
||||
{
|
||||
return speed_units.units[TR_FMT_KB].value;
|
||||
formatter_get_size_str( &speed_units, buf, bytes_per_second, buflen );
|
||||
return buf;
|
||||
}
|
||||
|
||||
static struct formatter_units mem_units;
|
||||
|
||||
unsigned int tr_mem_K = 0u;
|
||||
|
||||
void
|
||||
tr_formatter_mem_init( unsigned int kilo,
|
||||
const char * b, const char * kb,
|
||||
const char * mb, const char * gb )
|
||||
{
|
||||
tr_mem_K = kilo;
|
||||
formatter_init( &mem_units, kilo, b, kb, mb, gb );
|
||||
}
|
||||
|
||||
char*
|
||||
tr_formatter_mem( char * buf, uint64_t bytes_per_second, size_t buflen )
|
||||
tr_formatter_mem_B( char * buf, uint64_t bytes_per_second, size_t buflen )
|
||||
{
|
||||
return formatter_get_size_str( &mem_units, buf, bytes_per_second, buflen );
|
||||
}
|
||||
|
|
|
@ -574,15 +574,25 @@ void tr_formatter_mem_init( unsigned int kilo, const char * b, const char * kb,
|
|||
const char * mb, const char * gb );
|
||||
|
||||
/* format a speed into a user-readable string. */
|
||||
char* tr_formatter_speed( char * buf, uint64_t bytes_per_second, size_t buflen );
|
||||
|
||||
/* format a file size into a user-readable string. */
|
||||
char* tr_formatter_size( char * buf, uint64_t bytes, size_t buflen );
|
||||
extern unsigned int tr_speed_K;
|
||||
char* tr_formatter_speed_Bps( char * buf, uint64_t Bps, size_t buflen );
|
||||
static inline char* tr_formatter_speed_KBps( char * buf, double KBps, size_t buflen ) { return tr_formatter_speed_Bps( buf, KBps * tr_speed_K, buflen ); }
|
||||
static inline char* tr_formatter_speed_MBps( char * buf, double MBps, size_t buflen ) { return tr_formatter_speed_Bps( buf, MBps * tr_speed_K * tr_speed_K, buflen ); }
|
||||
static inline char* tr_formatter_speed_GBps( char * buf, double GBps, size_t buflen ) { return tr_formatter_speed_Bps( buf, GBps * tr_speed_K * tr_speed_K * tr_speed_K, buflen ); }
|
||||
|
||||
/* format a memory size into a user-readable string. */
|
||||
char* tr_formatter_mem( char * buf, uint64_t bytes, size_t buflen );
|
||||
extern unsigned int tr_mem_K;
|
||||
char* tr_formatter_mem_B( char * buf, uint64_t bytes, size_t buflen );
|
||||
static inline char* tr_formatter_mem_KB( char * buf, double KBps, size_t buflen ) { return tr_formatter_mem_B( buf, KBps * tr_mem_K, buflen ); }
|
||||
static inline char* tr_formatter_mem_MB( char * buf, double MBps, size_t buflen ) { return tr_formatter_mem_B( buf, MBps * tr_mem_K * tr_mem_K, buflen ); }
|
||||
static inline char* tr_formatter_mem_GB( char * buf, double GBps, size_t buflen ) { return tr_formatter_mem_B( buf, GBps * tr_mem_K * tr_mem_K * tr_mem_K, buflen ); }
|
||||
|
||||
unsigned int tr_formatter_speed_k( void );
|
||||
/* format a file size into a user-readable string. */
|
||||
extern unsigned int tr_size_K;
|
||||
char* tr_formatter_size_B( char * buf, uint64_t bytes, size_t buflen );
|
||||
static inline char* tr_formatter_size_KB( char * buf, double KBps, size_t buflen ) { return tr_formatter_size_B( buf, KBps * tr_size_K, buflen ); }
|
||||
static inline char* tr_formatter_size_MB( char * buf, double MBps, size_t buflen ) { return tr_formatter_size_B( buf, MBps * tr_size_K * tr_size_K, buflen ); }
|
||||
static inline char* tr_formatter_size_GB( char * buf, double GBps, size_t buflen ) { return tr_formatter_size_B( buf, GBps * tr_size_K * tr_size_K * tr_size_K, buflen ); }
|
||||
|
||||
|
||||
/***
|
||||
|
|
|
@ -44,6 +44,16 @@ const QString Formatter :: mem_G_str = "GiB";
|
|||
****
|
||||
***/
|
||||
|
||||
Speed
|
||||
Speed :: fromKBps( double KBps )
|
||||
{
|
||||
return KBps * Formatter::speed_K;
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
QString
|
||||
Formatter :: memToString( double bytes )
|
||||
{
|
||||
|
@ -51,7 +61,7 @@ Formatter :: memToString( double bytes )
|
|||
return tr( "None" );
|
||||
else {
|
||||
char buf[128];
|
||||
tr_formatter_mem( buf, bytes, sizeof( buf ) );
|
||||
tr_formatter_mem_B( buf, bytes, sizeof( buf ) );
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +73,7 @@ Formatter :: sizeToString( double bytes )
|
|||
return tr( "None" );
|
||||
else {
|
||||
char buf[128];
|
||||
tr_formatter_size( buf, bytes, sizeof( buf ) );
|
||||
tr_formatter_size_B( buf, bytes, sizeof( buf ) );
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +85,7 @@ Formatter :: speedToString( const Speed& speed )
|
|||
return tr( "None" );
|
||||
else {
|
||||
char buf[128];
|
||||
tr_formatter_speed( buf, speed.Bps( ), sizeof( buf ) );
|
||||
tr_formatter_speed_KBps( buf, speed.Bps( ), sizeof( buf ) );
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -549,16 +549,15 @@ TrMainWindow :: createOptionsMenu( )
|
|||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED_ENABLED << false );
|
||||
g->addAction( a );
|
||||
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) );
|
||||
a = myDlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromBps( currentVal ) ) ) );
|
||||
a = myDlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromKBps( currentVal ) ) ) );
|
||||
a->setCheckable( true );
|
||||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << currentVal << Prefs::DSPEED_ENABLED << true );
|
||||
g->addAction( a );
|
||||
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) );
|
||||
sub->addSeparator( );
|
||||
foreach( int i, stockSpeeds ) {
|
||||
const int Bps = i * Formatter::speed_K;
|
||||
a = sub->addAction( Formatter::speedToString( Speed::fromBps( Bps ) ) );
|
||||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << Bps << Prefs::DSPEED_ENABLED << true );
|
||||
a = sub->addAction( Formatter::speedToString( Speed::fromKBps( i ) ) );
|
||||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << i << Prefs::DSPEED_ENABLED << true );
|
||||
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs()));
|
||||
}
|
||||
|
||||
|
@ -570,16 +569,15 @@ TrMainWindow :: createOptionsMenu( )
|
|||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED_ENABLED << false );
|
||||
g->addAction( a );
|
||||
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) );
|
||||
a = myUlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromBps( currentVal ) ) ) );
|
||||
a = myUlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromKBps( currentVal ) ) ) );
|
||||
a->setCheckable( true );
|
||||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << currentVal << Prefs::USPEED_ENABLED << true );
|
||||
g->addAction( a );
|
||||
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) );
|
||||
sub->addSeparator( );
|
||||
foreach( int i, stockSpeeds ) {
|
||||
const int Bps = i * Formatter::speed_K;
|
||||
a = sub->addAction( Formatter::speedToString( Speed::fromBps( Bps ) ) );
|
||||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << Bps << Prefs::USPEED_ENABLED << true );
|
||||
a = sub->addAction( Formatter::speedToString( Speed::fromKBps( i ) ) );
|
||||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << i << Prefs::USPEED_ENABLED << true );
|
||||
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs()));
|
||||
}
|
||||
|
||||
|
@ -1013,7 +1011,7 @@ TrMainWindow :: refreshPref( int key )
|
|||
break;
|
||||
|
||||
case Prefs::DSPEED:
|
||||
myDlimitOnAction->setText( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromBps( myPrefs.get<int>(key) ) ) ) );
|
||||
myDlimitOnAction->setText( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromKBps( myPrefs.get<int>(key) ) ) ) );
|
||||
break;
|
||||
|
||||
case Prefs::USPEED_ENABLED:
|
||||
|
@ -1021,7 +1019,7 @@ TrMainWindow :: refreshPref( int key )
|
|||
break;
|
||||
|
||||
case Prefs::USPEED:
|
||||
myUlimitOnAction->setText( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromBps( myPrefs.get<int>(key) ) ) ) );
|
||||
myUlimitOnAction->setText( tr( "Limited at %1" ).arg( Formatter::speedToString( Speed::fromKBps( myPrefs.get<int>(key) ) ) ) );
|
||||
break;
|
||||
|
||||
case Prefs::RATIO_ENABLED:
|
||||
|
@ -1087,8 +1085,8 @@ TrMainWindow :: refreshPref( int key )
|
|||
myAltSpeedButton->setIcon( b ? mySpeedModeOnIcon : mySpeedModeOffIcon );
|
||||
const QString fmt = b ? tr( "Click to disable Temporary Speed Limits\n(%1 down, %2 up)" )
|
||||
: tr( "Click to enable Temporary Speed Limits\n(%1 down, %2 up)" );
|
||||
const Speed d = Speed::fromBps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_DOWN ) );
|
||||
const Speed u = Speed::fromBps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_UP ) );
|
||||
const Speed d = Speed::fromKBps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_DOWN ) );
|
||||
const Speed u = Speed::fromKBps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_UP ) );
|
||||
myAltSpeedButton->setToolTip( fmt.arg( Formatter::speedToString( d ) )
|
||||
.arg( Formatter::speedToString( u ) ) );
|
||||
break;
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
namespace
|
||||
{
|
||||
const char * PREF_KEY( "pref-key" );
|
||||
const char * MULTIPLIER_KEY( "multiplier-key" );
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -84,13 +83,12 @@ PrefsDialog :: spinBoxChangedIdle( )
|
|||
{
|
||||
const QObject * spin( sender()->property( "SPIN" ).value<QObject*>( ) );
|
||||
const int key = spin->property( PREF_KEY ).toInt( );
|
||||
const int multiplier = spin->property( MULTIPLIER_KEY ).toInt( );
|
||||
|
||||
const QDoubleSpinBox * d = qobject_cast<const QDoubleSpinBox*>( spin );
|
||||
if( d != 0 )
|
||||
myPrefs.set( key, multiplier * d->value( ) );
|
||||
myPrefs.set( key, d->value( ) );
|
||||
else
|
||||
myPrefs.set( key, multiplier * qobject_cast<const QSpinBox*>(spin)->value( ) );
|
||||
myPrefs.set( key, qobject_cast<const QSpinBox*>(spin)->value( ) );
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -116,14 +114,13 @@ PrefsDialog :: spinBoxChanged( int value )
|
|||
}
|
||||
|
||||
QSpinBox *
|
||||
PrefsDialog :: spinBoxNew( int key, int low, int high, int step, int multiplier )
|
||||
PrefsDialog :: spinBoxNew( int key, int low, int high, int step )
|
||||
{
|
||||
QSpinBox * spin = new QSpinBox( );
|
||||
spin->setRange( low, high );
|
||||
spin->setSingleStep( step );
|
||||
spin->setValue( myPrefs.getInt( key ) / multiplier );
|
||||
spin->setValue( myPrefs.getInt( key ) );
|
||||
spin->setProperty( PREF_KEY, key );
|
||||
spin->setProperty( MULTIPLIER_KEY, multiplier );
|
||||
connect( spin, SIGNAL(valueChanged(int)), this, SLOT(spinBoxChanged(int)));
|
||||
myWidgets.insert( key, spin );
|
||||
return spin;
|
||||
|
@ -138,15 +135,13 @@ PrefsDialog :: doubleSpinBoxChanged( double value )
|
|||
}
|
||||
|
||||
QDoubleSpinBox *
|
||||
PrefsDialog :: doubleSpinBoxNew( int key, double low, double high, double step, int decimals, int multiplier )
|
||||
PrefsDialog :: doubleSpinBoxNew( int key, double low, double high, double step, int decimals )
|
||||
{
|
||||
QDoubleSpinBox * spin = new QDoubleSpinBox( );
|
||||
spin->setRange( low, high );
|
||||
spin->setSingleStep( step );
|
||||
spin->setDecimals( decimals );
|
||||
spin->setValue( myPrefs.getDouble( key ) / multiplier );
|
||||
spin->setProperty( PREF_KEY, key );
|
||||
spin->setProperty( MULTIPLIER_KEY, multiplier );
|
||||
connect( spin, SIGNAL(valueChanged(double)), this, SLOT(doubleSpinBoxChanged(double)));
|
||||
myWidgets.insert( key, spin );
|
||||
return spin;
|
||||
|
@ -273,12 +268,12 @@ PrefsDialog :: createSpeedTab( )
|
|||
hig->addSectionTitle( tr( "Speed Limits" ) );
|
||||
|
||||
l = checkBoxNew( tr( "Limit &download speed (%1):" ).arg( Formatter::speed_K_str ), Prefs::DSPEED_ENABLED );
|
||||
r = spinBoxNew( Prefs::DSPEED, 0, INT_MAX, 5, Formatter::speed_K );
|
||||
r = spinBoxNew( Prefs::DSPEED, 0, INT_MAX, 5 );
|
||||
hig->addRow( l, r );
|
||||
enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r );
|
||||
|
||||
l = checkBoxNew( tr( "Limit &upload speed (%1):" ).arg( Formatter::speed_K_str ), Prefs::USPEED_ENABLED );
|
||||
r = spinBoxNew( Prefs::USPEED, 0, INT_MAX, 5, Formatter::speed_K );
|
||||
r = spinBoxNew( Prefs::USPEED, 0, INT_MAX, 5 );
|
||||
hig->addRow( l, r );
|
||||
enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r );
|
||||
|
||||
|
@ -299,11 +294,11 @@ PrefsDialog :: createSpeedTab( )
|
|||
hig->addWideControl( new QLabel( s ) );
|
||||
|
||||
s = tr( "Limit d&ownload speed (%1):" ).arg( Formatter::speed_K_str );
|
||||
r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_DOWN, 0, INT_MAX, 5, Formatter::speed_K );
|
||||
r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_DOWN, 0, INT_MAX, 5 );
|
||||
hig->addRow( s, r );
|
||||
|
||||
s = tr( "Limit u&pload speed (%1):" ).arg( Formatter::speed_K_str );
|
||||
r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_UP, 0, INT_MAX, 5, Formatter::speed_K );
|
||||
r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_UP, 0, INT_MAX, 5 );
|
||||
hig->addRow( s, r );
|
||||
|
||||
QCheckBox * c = checkBoxNew( tr( "&Scheduled times:" ), Prefs::ALT_SPEED_LIMIT_TIME_ENABLED );
|
||||
|
|
|
@ -64,9 +64,9 @@ class PrefsDialog: public QDialog
|
|||
void onBlocklistUpdated( int n );
|
||||
|
||||
private:
|
||||
QDoubleSpinBox * doubleSpinBoxNew( int key, double low, double high, double step, int decimals, int multiplier=1 );
|
||||
QDoubleSpinBox * doubleSpinBoxNew( int key, double low, double high, double step, int decimals );
|
||||
QCheckBox * checkBoxNew( const QString& text, int key );
|
||||
QSpinBox * spinBoxNew( int key, int low, int high, int step, int multiplier=1 );
|
||||
QSpinBox * spinBoxNew( int key, int low, int high, int step );
|
||||
QTimeEdit * timeEditNew( int key );
|
||||
QLineEdit * lineEditNew( int key, int mode = 0 );
|
||||
void enableBuddyWhenChecked( QCheckBox *, QWidget * );
|
||||
|
|
|
@ -64,15 +64,15 @@ Prefs::PrefItem Prefs::myItems[] =
|
|||
{ USER_HAS_GIVEN_INFORMED_CONSENT, "user-has-given-informed-consent", QVariant::Bool },
|
||||
|
||||
/* libtransmission settings */
|
||||
{ ALT_SPEED_LIMIT_UP, TR_PREFS_KEY_ALT_SPEED_UP_Bps, QVariant::Int },
|
||||
{ ALT_SPEED_LIMIT_DOWN, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, QVariant::Int },
|
||||
{ ALT_SPEED_LIMIT_UP, TR_PREFS_KEY_ALT_SPEED_UP_KBps, QVariant::Int },
|
||||
{ ALT_SPEED_LIMIT_DOWN, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, QVariant::Int },
|
||||
{ ALT_SPEED_LIMIT_ENABLED, TR_PREFS_KEY_ALT_SPEED_ENABLED, QVariant::Bool },
|
||||
{ ALT_SPEED_LIMIT_TIME_BEGIN, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, QVariant::Int },
|
||||
{ ALT_SPEED_LIMIT_TIME_END, TR_PREFS_KEY_ALT_SPEED_TIME_END, QVariant::Int },
|
||||
{ ALT_SPEED_LIMIT_TIME_ENABLED, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, QVariant::Bool },
|
||||
{ ALT_SPEED_LIMIT_TIME_DAY, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, QVariant::Int },
|
||||
{ BLOCKLIST_ENABLED, TR_PREFS_KEY_BLOCKLIST_ENABLED, QVariant::Bool },
|
||||
{ DSPEED, TR_PREFS_KEY_DSPEED_Bps, QVariant::Int },
|
||||
{ DSPEED, TR_PREFS_KEY_DSPEED_KBps, QVariant::Int },
|
||||
{ DSPEED_ENABLED, TR_PREFS_KEY_DSPEED_ENABLED, QVariant::Bool },
|
||||
{ DOWNLOAD_DIR, TR_PREFS_KEY_DOWNLOAD_DIR, QVariant::String },
|
||||
{ ENCRYPTION, TR_PREFS_KEY_ENCRYPTION, QVariant::Int },
|
||||
|
@ -115,7 +115,7 @@ Prefs::PrefItem Prefs::myItems[] =
|
|||
{ RPC_WHITELIST_ENABLED, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, QVariant::Bool },
|
||||
{ RPC_WHITELIST, TR_PREFS_KEY_RPC_WHITELIST, QVariant::String },
|
||||
{ USPEED_ENABLED, TR_PREFS_KEY_USPEED_ENABLED, QVariant::Bool },
|
||||
{ USPEED, TR_PREFS_KEY_USPEED_Bps, QVariant::Int },
|
||||
{ USPEED, TR_PREFS_KEY_USPEED_KBps, QVariant::Int },
|
||||
{ UPLOAD_SLOTS_PER_TORRENT, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, QVariant::Int }
|
||||
};
|
||||
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
|
||||
#include <libtransmission/transmission.h>
|
||||
|
||||
#include "speed.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
struct tr_benc;
|
||||
|
|
|
@ -23,7 +23,7 @@ class Speed
|
|||
double KiBps( ) const { return _Bps/1024.0; }
|
||||
int Bps( ) const { return _Bps; }
|
||||
bool isZero( ) const { return _Bps == 0; }
|
||||
static Speed fromKiBps( double KiBps ) { return Speed( KiBps*1024 ); }
|
||||
static Speed fromKBps( double KBps );
|
||||
static Speed fromBps( int Bps ) { return Speed( Bps ); }
|
||||
void setKiBps( double KiBps ) { setBps( KiBps*1024 ); }
|
||||
void setBps( double Bps ) { _Bps = Bps; }
|
||||
|
|
|
@ -53,8 +53,8 @@ Torrent :: Property
|
|||
Torrent :: myProperties[] =
|
||||
{
|
||||
{ ID, "id", QVariant::Int, INFO, },
|
||||
{ UPLOAD_SPEED, "rateUpload", QVariant::Int, STAT } /* B/s */,
|
||||
{ DOWNLOAD_SPEED, "rateDownload", QVariant::Int, STAT }, /* B/s */
|
||||
{ UPLOAD_SPEED, "rateUpload", QVariant::Double, STAT } /* KBps */,
|
||||
{ DOWNLOAD_SPEED, "rateDownload", QVariant::Double, STAT }, /* KBps */
|
||||
{ DOWNLOAD_DIR, "downloadDir", QVariant::String, STAT },
|
||||
{ ACTIVITY, "status", QVariant::Int, STAT },
|
||||
{ NAME, "name", QVariant::String, INFO },
|
||||
|
@ -89,9 +89,9 @@ Torrent :: myProperties[] =
|
|||
{ MIME_ICON, "ccc", QVariant::Icon, DERIVED },
|
||||
{ SEED_RATIO_LIMIT, "seedRatioLimit", QVariant::Double, STAT },
|
||||
{ SEED_RATIO_MODE, "seedRatioMode", QVariant::Int, STAT },
|
||||
{ DOWN_LIMIT, "downloadLimit", QVariant::Int, STAT_EXTRA }, /* KiB/s */
|
||||
{ DOWN_LIMIT, "downloadLimit", QVariant::Int, STAT_EXTRA }, /* KB/s */
|
||||
{ DOWN_LIMITED, "downloadLimited", QVariant::Bool, STAT_EXTRA },
|
||||
{ UP_LIMIT, "uploadLimit", QVariant::Int, STAT_EXTRA }, /* KiB/s */
|
||||
{ UP_LIMIT, "uploadLimit", QVariant::Int, STAT_EXTRA }, /* KB/s */
|
||||
{ UP_LIMITED, "uploadLimited", QVariant::Bool, STAT_EXTRA },
|
||||
{ HONORS_SESSION_LIMITS, "honorsSessionLimits", QVariant::Bool, STAT_EXTRA },
|
||||
{ PEER_LIMIT, "peer-limit", QVariant::Int, STAT_EXTRA },
|
||||
|
@ -653,10 +653,10 @@ Torrent :: update( tr_benc * d )
|
|||
peer.port = i;
|
||||
if( tr_bencDictFindReal( child, "progress", &d ) )
|
||||
peer.progress = d;
|
||||
if( tr_bencDictFindInt( child, "rateToClient", &i ) )
|
||||
peer.rateToClient = Speed::fromBps( i );
|
||||
if( tr_bencDictFindInt( child, "rateToPeer", &i ) )
|
||||
peer.rateToPeer = Speed::fromBps( i );
|
||||
if( tr_bencDictFindReal( child, "rateToClient", &d ) )
|
||||
peer.rateToClient = Speed::fromKBps( d );
|
||||
if( tr_bencDictFindReal( child, "rateToPeer", &d ) )
|
||||
peer.rateToPeer = Speed::fromKBps( d );
|
||||
peerList << peer;
|
||||
}
|
||||
myValues[PEERS].setValue( peerList );
|
||||
|
|
|
@ -279,13 +279,13 @@ class Torrent: public QObject
|
|||
bool isUploading( ) const { return peersWeAreUploadingTo( ) > 0; }
|
||||
int connectedPeers( ) const { return getInt( PEERS_CONNECTED ); }
|
||||
int connectedPeersAndWebseeds( ) const { return connectedPeers( ) + getInt( WEBSEEDS_SENDING_TO_US ); }
|
||||
Speed downloadSpeed( ) const { return Speed::fromBps( getInt( DOWNLOAD_SPEED ) ); }
|
||||
Speed uploadSpeed( ) const { return Speed::fromBps( getInt( UPLOAD_SPEED ) ); }
|
||||
Speed downloadSpeed( ) const { return Speed::fromKBps( getDouble( DOWNLOAD_SPEED ) ); }
|
||||
Speed uploadSpeed( ) const { return Speed::fromKBps( getDouble( UPLOAD_SPEED ) ); }
|
||||
double getVerifyProgress( ) const { return getDouble( PERCENT_VERIFIED ); }
|
||||
bool hasFileSubstring( const QString& substr ) const;
|
||||
bool hasTrackerSubstring( const QString& substr ) const;
|
||||
Speed uploadLimit( ) const { return Speed::fromBps( getInt( UP_LIMIT ) ); }
|
||||
Speed downloadLimit( ) const { return Speed::fromBps( getInt( DOWN_LIMIT ) ); }
|
||||
Speed uploadLimit( ) const { return Speed::fromKBps( getInt( UP_LIMIT ) ); }
|
||||
Speed downloadLimit( ) const { return Speed::fromKBps( getInt( DOWN_LIMIT ) ); }
|
||||
bool uploadIsLimited( ) const { return getBool( UP_LIMITED ); }
|
||||
bool downloadIsLimited( ) const { return getBool( DOWN_LIMITED ); }
|
||||
bool honorsSessionLimits( ) const { return getBool( HONORS_SESSION_LIMITS ); }
|
||||
|
|
|
@ -104,8 +104,8 @@ showInfo( const tr_info * inf )
|
|||
if( inf->comment && *inf->comment )
|
||||
printf( " Comment: %s\n", inf->comment );
|
||||
printf( " Piece Count: %d\n", inf->pieceCount );
|
||||
printf( " Piece Size: %s\n", tr_formatter_mem( buf, inf->pieceSize, sizeof( buf ) ) );
|
||||
printf( " Total Size: %s\n", tr_formatter_size( buf, inf->totalSize, sizeof( buf ) ) );
|
||||
printf( " Piece Size: %s\n", tr_formatter_mem_B( buf, inf->pieceSize, sizeof( buf ) ) );
|
||||
printf( " Total Size: %s\n", tr_formatter_size_B( buf, inf->totalSize, sizeof( buf ) ) );
|
||||
printf( " Privacy: %s\n", inf->isPrivate ? "Private torrent" : "Public torrent" );
|
||||
|
||||
/**
|
||||
|
@ -130,7 +130,7 @@ showInfo( const tr_info * inf )
|
|||
|
||||
printf( "\nFILES\n\n" );
|
||||
for( i=0; i<(int)inf->fileCount; ++i )
|
||||
printf( " %s (%s)\n", inf->files[i].name, tr_formatter_size( buf, inf->files[i].length, sizeof( buf ) ) );
|
||||
printf( " %s (%s)\n", inf->files[i].name, tr_formatter_size_B( buf, inf->files[i].length, sizeof( buf ) ) );
|
||||
}
|
||||
|
||||
static size_t
|
||||
|
|
Loading…
Reference in New Issue