(trunk) #3045 "make libtransmission's API byte-oriented instead of KiB-oriented." -- implemented. This is a largish commit and will break the mac build for a little while.
This commit is contained in:
parent
fff1655fb6
commit
cdcc4705aa
93
cli/cli.c
93
cli/cli.c
|
@ -35,10 +35,36 @@
|
|||
#include <libtransmission/version.h>
|
||||
#include <libtransmission/web.h> /* tr_webRun */
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
#define MEM_K 1024
|
||||
#define MEM_B_STR "B"
|
||||
#define MEM_K_STR "KiB"
|
||||
#define MEM_M_STR "MiB"
|
||||
#define MEM_G_STR "GiB"
|
||||
|
||||
#define DISK_K 1000
|
||||
#define DISK_B_STR "B"
|
||||
#define DISK_K_STR "kB"
|
||||
#define DISK_M_STR "MB"
|
||||
#define DISK_G_STR "GB"
|
||||
|
||||
#define SPEED_K 1000
|
||||
#define SPEED_B_STR "B/s"
|
||||
#define SPEED_K_STR "kB/s"
|
||||
#define SPEED_M_STR "MB/s"
|
||||
#define SPEED_G_STR "GB/s"
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
#define LINEWIDTH 80
|
||||
#define MY_NAME "transmissioncli"
|
||||
|
||||
static tr_bool verify = 0;
|
||||
static tr_bool verify = 0;
|
||||
static sig_atomic_t gotsig = 0;
|
||||
static sig_atomic_t manualUpdate = 0;
|
||||
|
||||
|
@ -46,20 +72,20 @@ static const char * torrentPath = NULL;
|
|||
|
||||
static const struct tr_option options[] =
|
||||
{
|
||||
{ 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL },
|
||||
{ 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL },
|
||||
{ 'd', "downlimit", "Set max download speed in KiB/s", "d", 1, "<speed>" },
|
||||
{ 'D', "no-downlimit", "Don't limit the download speed", "D", 0, NULL },
|
||||
{ 910, "encryption-required", "Encrypt all peer connections", "er", 0, NULL },
|
||||
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", 0, NULL },
|
||||
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", 0, NULL },
|
||||
{ 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL },
|
||||
{ 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL },
|
||||
{ 'd', "downlimit", "Set max download speed in "SPEED_K_STR, "d", 1, "<speed>" },
|
||||
{ 'D', "no-downlimit", "Don't limit the download speed", "D", 0, NULL },
|
||||
{ 910, "encryption-required", "Encrypt all peer connections", "er", 0, NULL },
|
||||
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", 0, NULL },
|
||||
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", 0, NULL },
|
||||
{ 'f', "finish", "Run a script when the torrent finishes", "f", 1, "<script>" },
|
||||
{ 'g', "config-dir", "Where to find configuration files", "g", 1, "<path>" },
|
||||
{ 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", 0, NULL },
|
||||
{ 'M', "no-portmap", "Disable portmapping", "M", 0, NULL },
|
||||
{ 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", 0, NULL },
|
||||
{ 'M', "no-portmap", "Disable portmapping", "M", 0, NULL },
|
||||
{ 'p', "port", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "p", 1, "<port>" },
|
||||
{ 't', "tos", "Peer socket TOS (0 to 255, default=" TR_DEFAULT_PEER_SOCKET_TOS_STR ")", "t", 1, "<tos>" },
|
||||
{ 'u', "uplimit", "Set max upload speed in KiB/s", "u", 1, "<speed>" },
|
||||
{ 'u', "uplimit", "Set max upload speed in "SPEED_K_STR, "u", 1, "<speed>" },
|
||||
{ 'U', "no-uplimit", "Don't limit the upload speed", "U", 0, NULL },
|
||||
{ 'v', "verify", "Verify the specified torrent", "v", 0, NULL },
|
||||
{ 'w', "download-dir", "Where to save downloaded data", "w", 1, "<path>" },
|
||||
|
@ -127,29 +153,35 @@ getStatusStr( const tr_stat * st,
|
|||
}
|
||||
else if( st->activity & TR_STATUS_DOWNLOAD )
|
||||
{
|
||||
char upStr[80];
|
||||
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_strlratio( ratioStr, st->ratio, sizeof( ratioStr ) );
|
||||
tr_snprintf(
|
||||
buf, buflen,
|
||||
"Progress: %.1f%%, dl from %d of %d peers (%.0f KiB/s), "
|
||||
"ul to %d (%.0f KiB/s) [%s]",
|
||||
|
||||
tr_snprintf( buf, buflen,
|
||||
"Progress: %.1f%%, "
|
||||
"dl from %d of %d peers (%s), "
|
||||
"ul to %d (%s) "
|
||||
"[%s]",
|
||||
tr_truncd( 100 * st->percentDone, 1 ),
|
||||
st->peersSendingToUs,
|
||||
st->peersConnected,
|
||||
st->pieceDownloadSpeed,
|
||||
st->peersGettingFromUs,
|
||||
st->pieceUploadSpeed,
|
||||
st->peersSendingToUs, st->peersConnected, upStr,
|
||||
st->peersGettingFromUs, dnStr,
|
||||
ratioStr );
|
||||
}
|
||||
else if( st->activity & TR_STATUS_SEED )
|
||||
{
|
||||
char upStr[80];
|
||||
char ratioStr[80];
|
||||
|
||||
tr_formatter_speed( upStr, st->pieceUploadSpeed_Bps, sizeof( upStr ) );
|
||||
tr_strlratio( ratioStr, st->ratio, sizeof( ratioStr ) );
|
||||
tr_snprintf(
|
||||
buf, buflen,
|
||||
"Seeding, uploading to %d of %d peer(s), %.0f KiB/s [%s]",
|
||||
st->peersGettingFromUs, st->peersConnected,
|
||||
st->pieceUploadSpeed, ratioStr );
|
||||
|
||||
tr_snprintf( buf, buflen,
|
||||
"Seeding, uploading to %d of %d peer(s), %s [%s]",
|
||||
st->peersGettingFromUs, st->peersConnected, upStr, ratioStr );
|
||||
}
|
||||
else *buf = '\0';
|
||||
}
|
||||
|
@ -178,8 +210,7 @@ getConfigDir( int argc, const char ** argv )
|
|||
}
|
||||
|
||||
int
|
||||
main( int argc,
|
||||
char ** argv )
|
||||
main( int argc, char ** argv )
|
||||
{
|
||||
int error;
|
||||
tr_session * h;
|
||||
|
@ -190,6 +221,10 @@ main( int argc,
|
|||
uint8_t * fileContents;
|
||||
size_t fileLength;
|
||||
|
||||
tr_formatter_mem_init( MEM_K, MEM_B_STR, MEM_K_STR, MEM_M_STR, MEM_G_STR );
|
||||
tr_formatter_size_init( DISK_K,DISK_B_STR, DISK_K_STR, DISK_M_STR, DISK_G_STR );
|
||||
tr_formatter_speed_init( SPEED_K, SPEED_B_STR, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR );
|
||||
|
||||
printf( "Transmission %s - http://www.transmissionbt.com/\n",
|
||||
LONG_VERSION_STRING );
|
||||
|
||||
|
@ -323,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, atoi( optarg ) );
|
||||
case 'd': tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_Bps, atoi( optarg ) * SPEED_K );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, TRUE );
|
||||
break;
|
||||
case 'D': tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, FALSE );
|
||||
|
@ -341,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, atoi( optarg ) );
|
||||
case 'u': tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_Bps, atoi( optarg ) * SPEED_K );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, TRUE );
|
||||
break;
|
||||
case 'U': tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, FALSE );
|
||||
|
|
119
daemon/remote.c
119
daemon/remote.c
|
@ -43,6 +43,24 @@
|
|||
|
||||
#define ARGUMENTS "arguments"
|
||||
|
||||
#define MEM_K 1024
|
||||
#define MEM_B_STR "B"
|
||||
#define MEM_K_STR "KiB"
|
||||
#define MEM_M_STR "MiB"
|
||||
#define MEM_G_STR "GiB"
|
||||
|
||||
#define DISK_K 1000
|
||||
#define DISK_B_STR "B"
|
||||
#define DISK_K_STR "kB"
|
||||
#define DISK_M_STR "MB"
|
||||
#define DISK_G_STR "GB"
|
||||
|
||||
#define SPEED_K 1000
|
||||
#define SPEED_B_STR "B/s"
|
||||
#define SPEED_K_STR "kB/s"
|
||||
#define SPEED_M_STR "MB/s"
|
||||
#define SPEED_G_STR "GB/s"
|
||||
|
||||
/***
|
||||
****
|
||||
**** Display Utilities
|
||||
|
@ -109,10 +127,6 @@ tr_strltime( char * buf, int seconds, size_t buflen )
|
|||
return buf;
|
||||
}
|
||||
|
||||
static const double KiB = 1024.0;
|
||||
static const double MiB = 1024.0 * 1024.0;
|
||||
static const double GiB = 1024.0 * 1024.0 * 1024.0;
|
||||
|
||||
static char*
|
||||
strlpercent( char * buf, double x, size_t buflen )
|
||||
{
|
||||
|
@ -140,11 +154,22 @@ strlratio( char * buf, double numerator, double denominator, size_t buflen )
|
|||
return strlratio2( buf, ratio, buflen );
|
||||
}
|
||||
|
||||
static char*
|
||||
strlmem( char * buf, int64_t bytes, size_t buflen )
|
||||
{
|
||||
if( !bytes )
|
||||
tr_strlcpy( buf, "None", buflen );
|
||||
else
|
||||
tr_formatter_mem( buf, bytes, buflen );
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static char*
|
||||
strlsize( char * buf, int64_t bytes, size_t buflen )
|
||||
{
|
||||
if( !bytes )
|
||||
tr_strlcpy( buf, _( "None" ), buflen );
|
||||
tr_strlcpy( buf, "None", buflen );
|
||||
else
|
||||
tr_formatter_size( buf, bytes, buflen );
|
||||
|
||||
|
@ -155,7 +180,7 @@ static char*
|
|||
strlspeed( char * buf, int64_t bytes_per_second, size_t buflen )
|
||||
{
|
||||
if( !bytes_per_second )
|
||||
tr_strlcpy( buf, _( "None" ), buflen );
|
||||
tr_strlcpy( buf, "None", buflen );
|
||||
else
|
||||
tr_formatter_speed( buf, bytes_per_second, buflen );
|
||||
|
||||
|
@ -193,8 +218,8 @@ static tr_option opts[] =
|
|||
{ 'a', "add", "Add torrent files by filename or URL", "a", 0, NULL },
|
||||
{ 970, "alt-speed", "Use the alternate Limits", "as", 0, NULL },
|
||||
{ 971, "no-alt-speed", "Don't use the alternate Limits", "AS", 0, NULL },
|
||||
{ 972, "alt-speed-downlimit", "max alternate download speed (in KiB/s)", "asd", 1, "<speed>" },
|
||||
{ 973, "alt-speed-uplimit", "max alternate upload speed (in KiB/s)", "asu", 1, "<speed>" },
|
||||
{ 972, "alt-speed-downlimit", "max alternate download speed (in "SPEED_K_STR")", "asd", 1, "<speed>" },
|
||||
{ 973, "alt-speed-uplimit", "max alternate upload speed (in "SPEED_K_STR")", "asu", 1, "<speed>" },
|
||||
{ 974, "alt-speed-scheduler", "Use the scheduled on/off times", "asc", 0, NULL },
|
||||
{ 975, "no-alt-speed-scheduler", "Don't use the scheduled on/off times", "ASC", 0, NULL },
|
||||
{ 976, "alt-speed-time-begin", "Time to start using the alt speed limits (in hhmm)", NULL, 1, "<time>" },
|
||||
|
@ -204,9 +229,9 @@ static tr_option opts[] =
|
|||
{ 'c', "incomplete-dir", "Where to store new torrents until they're complete", "c", 1, "<dir>" },
|
||||
{ 'C', "no-incomplete-dir", "Don't store incomplete torrents in a different location", "C", 0, NULL },
|
||||
{ 'b', "debug", "Print debugging information", "b", 0, NULL },
|
||||
{ 'd', "downlimit", "Set the max download speed in KiB/s for the current torrent(s) or globally", "d", 1, "<speed>" },
|
||||
{ 'd', "downlimit", "Set the max download speed in "SPEED_K_STR" for the current torrent(s) or globally", "d", 1, "<speed>" },
|
||||
{ 'D', "no-downlimit", "Disable max download speed for the current torrent(s) or globally", "D", 0, NULL },
|
||||
{ 'e', "cache", "Set the maximum size of the session's memory cache (in MiB)", "e", 1, "<size>" },
|
||||
{ 'e', "cache", "Set the maximum size of the session's memory cache (in " MEM_M_STR ")", "e", 1, "<size>" },
|
||||
{ 910, "encryption-required", "Encrypt all peer connections", "er", 0, NULL },
|
||||
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", 0, NULL },
|
||||
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", 0, NULL },
|
||||
|
@ -255,7 +280,7 @@ static tr_option opts[] =
|
|||
{ 993, "no-trash-torrent", "Do not delete torrents after adding", NULL, 0, NULL },
|
||||
{ 984, "honor-session", "Make the current torrent(s) honor the session limits", "hl", 0, NULL },
|
||||
{ 985, "no-honor-session", "Make the current torrent(s) not honor the session limits", "HL", 0, NULL },
|
||||
{ 'u', "uplimit", "Set the max upload speed in KiB/s for the current torrent(s) or globally", "u", 1, "<speed>" },
|
||||
{ 'u', "uplimit", "Set the max upload speed in "SPEED_K_STR" for the current torrent(s) or globally", "u", 1, "<speed>" },
|
||||
{ 'U', "no-uplimit", "Disable max upload speed for the current torrent(s) or globally", "U", 0, NULL },
|
||||
{ 'v', "verify", "Verify the current torrent(s)", "v", 0, NULL },
|
||||
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
|
||||
|
@ -1072,7 +1097,7 @@ printDetails( tr_benc * top )
|
|||
if( tr_bencDictFindInt( t, "pieceCount", &i ) )
|
||||
printf( " Piece Count: %" PRId64 "\n", i );
|
||||
if( tr_bencDictFindInt( t, "pieceSize", &i ) )
|
||||
printf( " Piece Size: %" PRId64 "\n", i );
|
||||
printf( " Piece Size: %s\n", strlmem( buf, i, sizeof( buf ) ) );
|
||||
printf( "\n" );
|
||||
|
||||
printf( "LIMITS & BANDWIDTH\n" );
|
||||
|
@ -1081,7 +1106,7 @@ printDetails( tr_benc * top )
|
|||
{
|
||||
printf( " Download Limit: " );
|
||||
if( boolVal )
|
||||
printf( "%s\n", strlspeed( buf, i*1024, sizeof( buf ) ) );
|
||||
printf( "%s\n", strlspeed( buf, i, sizeof( buf ) ) );
|
||||
else
|
||||
printf( "Unlimited\n" );
|
||||
}
|
||||
|
@ -1090,7 +1115,7 @@ printDetails( tr_benc * top )
|
|||
{
|
||||
printf( " Upload Limit: " );
|
||||
if( boolVal )
|
||||
printf( "%s\n", strlspeed( buf, i*1024, sizeof( buf ) ) );
|
||||
printf( "%s\n", strlspeed( buf, i, sizeof( buf ) ) );
|
||||
else
|
||||
printf( "Unlimited\n" );
|
||||
}
|
||||
|
@ -1215,8 +1240,8 @@ printPeersImpl( tr_benc * peers )
|
|||
{
|
||||
printf( "%-20s %-12s %-5.1f %6.1f %6.1f %s\n",
|
||||
address, flagstr, (progress*100.0),
|
||||
rateToClient / 1024.0,
|
||||
rateToPeer / 1024.0,
|
||||
rateToClient / (double)SPEED_K,
|
||||
rateToPeer / (double)SPEED_K,
|
||||
client );
|
||||
}
|
||||
}
|
||||
|
@ -1318,8 +1343,8 @@ printTorrentList( tr_benc * top )
|
|||
doneStr,
|
||||
haveStr,
|
||||
etaStr,
|
||||
up / 1024.0,
|
||||
down / 1024.0,
|
||||
up / (double)SPEED_K,
|
||||
down / (double)SPEED_K,
|
||||
strlratio2( ratioStr, ratio, sizeof( ratioStr ) ),
|
||||
getStatusString( d, statusStr, sizeof( statusStr ) ),
|
||||
name );
|
||||
|
@ -1332,8 +1357,8 @@ printTorrentList( tr_benc * top )
|
|||
|
||||
printf( "Sum: %9s %6.1f %6.1f\n",
|
||||
strlsize( haveStr, total_size, sizeof( haveStr ) ),
|
||||
total_up / 1024.0,
|
||||
total_down / 1024.0 );
|
||||
total_up / (double)SPEED_K,
|
||||
total_down / (double)SPEED_K );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1343,11 +1368,10 @@ printSession( tr_benc * top )
|
|||
tr_benc *args;
|
||||
if( ( tr_bencDictFindDict( top, "arguments", &args ) ) )
|
||||
{
|
||||
double d;
|
||||
const char * str;
|
||||
int64_t i;
|
||||
tr_bool boolVal;
|
||||
int64_t i;
|
||||
char buf[64];
|
||||
tr_bool boolVal;
|
||||
const char * str;
|
||||
|
||||
printf( "VERSION\n" );
|
||||
if( tr_bencDictFindStr( args, "version", &str ) )
|
||||
|
@ -1375,8 +1399,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_bencDictFindReal( args, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, &d ) )
|
||||
printf( " Maximum memory cache size: %s\n", strlsize( buf, d*MiB, sizeof( buf ) ) );
|
||||
if( tr_bencDictFindInt( args, TR_PREFS_KEY_MAX_CACHE_SIZE, &i ) )
|
||||
printf( " Maximum memory cache size: %s\n", strlsize( buf, i, sizeof( buf ) ) );
|
||||
printf( "\n" );
|
||||
|
||||
{
|
||||
|
@ -1384,17 +1408,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, &altDown ) &&
|
||||
if( tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, &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, &altUp ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_UP_Bps, &altUp ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &peerLimit ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_DSPEED, &downLimit ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_DSPEED_Bps, &downLimit ) &&
|
||||
tr_bencDictFindBool( args, TR_PREFS_KEY_DSPEED_ENABLED, &downEnabled ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_USPEED, &upLimit ) &&
|
||||
tr_bencDictFindInt ( args, TR_PREFS_KEY_USPEED_Bps, &upLimit ) &&
|
||||
tr_bencDictFindBool( args, TR_PREFS_KEY_USPEED_ENABLED, &upEnabled ) &&
|
||||
tr_bencDictFindReal( args, "seedRatioLimit", &seedRatioLimit ) &&
|
||||
tr_bencDictFindBool( args, "seedRatioLimited", &seedRatioLimited) )
|
||||
|
@ -1413,30 +1437,30 @@ printSession( tr_benc * top )
|
|||
printf( " Default seed ratio limit: %s\n", buf );
|
||||
|
||||
if( altEnabled )
|
||||
strlspeed( buf, altUp*1024, sizeof( buf ) );
|
||||
strlspeed( buf, altUp, sizeof( buf ) );
|
||||
else if( upEnabled )
|
||||
strlspeed( buf, upLimit*1024, sizeof( buf ) );
|
||||
strlspeed( 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*1024, sizeof( buf2 ) ),
|
||||
strlspeed( buf2, upLimit, sizeof( buf2 ) ),
|
||||
altEnabled ? "Enabled" : "Disabled",
|
||||
strlspeed( buf3, altUp*1024, sizeof( buf3 ) ) );
|
||||
strlspeed( buf3, altUp, sizeof( buf3 ) ) );
|
||||
|
||||
if( altEnabled )
|
||||
strlspeed( buf, altDown*1024, sizeof( buf ) );
|
||||
strlspeed( buf, altDown, sizeof( buf ) );
|
||||
else if( downEnabled )
|
||||
strlspeed( buf, downLimit*1024, sizeof( buf ) );
|
||||
strlspeed( 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*1024, sizeof( buf2 ) ),
|
||||
strlspeed( buf2, downLimit, sizeof( buf2 ) ),
|
||||
altEnabled ? "Enabled" : "Disabled",
|
||||
strlspeed( buf2, altDown*1024, sizeof( buf2 ) ) );
|
||||
strlspeed( buf2, altDown, sizeof( buf2 ) ) );
|
||||
|
||||
if( altTimeEnabled ) {
|
||||
printf( " Turtle schedule: %02d:%02d - %02d:%02d ",
|
||||
|
@ -1821,9 +1845,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, numarg( optarg ) );
|
||||
case 972: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, numarg( optarg ) * SPEED_K );
|
||||
break;
|
||||
case 973: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_UP, numarg( optarg ) );
|
||||
case 973: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_UP_Bps, numarg( optarg ) * SPEED_K );
|
||||
break;
|
||||
case 974: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, TRUE );
|
||||
break;
|
||||
|
@ -1840,7 +1864,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_MiB, atof(optarg) );
|
||||
case 'e': tr_bencDictAddReal( args, TR_PREFS_KEY_MAX_CACHE_SIZE, atof(optarg) * MEM_K * MEM_K );
|
||||
break;
|
||||
case 910: tr_bencDictAddStr( args, TR_PREFS_KEY_ENCRYPTION, "required" );
|
||||
break;
|
||||
|
@ -1898,10 +1922,10 @@ processArgs( const char * host, int port, int argc, const char ** argv )
|
|||
switch( c )
|
||||
{
|
||||
case 'd': if( targs ) {
|
||||
tr_bencDictAddInt( targs, "downloadLimit", numarg( optarg ) );
|
||||
tr_bencDictAddInt( targs, "downloadLimit", numarg( optarg ) * SPEED_K );
|
||||
tr_bencDictAddBool( targs, "downloadLimited", TRUE );
|
||||
} else {
|
||||
tr_bencDictAddInt( sargs, TR_PREFS_KEY_DSPEED, numarg( optarg ) );
|
||||
tr_bencDictAddInt( sargs, TR_PREFS_KEY_DSPEED_Bps, numarg( optarg ) * SPEED_K );
|
||||
tr_bencDictAddBool( sargs, TR_PREFS_KEY_DSPEED_ENABLED, TRUE );
|
||||
}
|
||||
break;
|
||||
|
@ -1911,10 +1935,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 ) );
|
||||
tr_bencDictAddInt( targs, "uploadLimit", numarg( optarg ) * SPEED_K );
|
||||
tr_bencDictAddBool( targs, "uploadLimited", TRUE );
|
||||
} else {
|
||||
tr_bencDictAddInt( sargs, TR_PREFS_KEY_USPEED, numarg( optarg ) );
|
||||
tr_bencDictAddInt( sargs, TR_PREFS_KEY_USPEED_Bps, numarg( optarg ) * SPEED_K );
|
||||
tr_bencDictAddBool( sargs, TR_PREFS_KEY_USPEED_ENABLED, TRUE );
|
||||
}
|
||||
break;
|
||||
|
@ -2186,8 +2210,9 @@ main( int argc, char ** argv )
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
tr_formatter_size_init ( 1024, "B", "KiB", "MiB", "GiB" );
|
||||
tr_formatter_speed_init ( 1024, "B/s", "KiB/s", "MiB/s", "GiB/s" );
|
||||
tr_formatter_mem_init( MEM_K, MEM_B_STR, MEM_K_STR, MEM_M_STR, MEM_G_STR );
|
||||
tr_formatter_size_init( DISK_K,DISK_B_STR, DISK_K_STR, DISK_M_STR, DISK_G_STR );
|
||||
tr_formatter_speed_init( SPEED_K, SPEED_B_STR, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR );
|
||||
|
||||
getHostAndPort( &argc, argv, &host, &port );
|
||||
if( host == NULL )
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
string | value type & description
|
||||
----------------------+-------------------------------------------------
|
||||
"bandwidthPriority" | number this torrent's bandwidth tr_priority_t
|
||||
"downloadLimit" | number maximum download speed (in K/s)
|
||||
"downloadLimit" | number maximum download speed (bytes per second)
|
||||
"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 (in K/s)
|
||||
"uploadLimit" | number maximum upload speed (bytes per second)
|
||||
"uploadLimited" | boolean true if "uploadLimit" is honored
|
||||
|
|
||||
----------------------+---------------------------------+
|
||||
|
@ -151,6 +151,10 @@
|
|||
a "removed" array of torrent-id numbers of recently-removed
|
||||
torrents.
|
||||
|
||||
Note: For more information on what these fields mean, see the comments
|
||||
in libtransmission/transmission.h. The "source" column here
|
||||
corresponds to the data structure there.
|
||||
|
||||
key | type | source
|
||||
----------------------------+-----------------------------+---------
|
||||
activityDate | number | tr_stat
|
||||
|
@ -414,16 +418,16 @@
|
|||
|
||||
string | value type & description
|
||||
------------------------------+-------------------------------------------------
|
||||
"alt-speed-down" | number max global download speed (in K/s)
|
||||
"alt-speed-down" | number max global download speed (in bytes per second)
|
||||
"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 K/s)
|
||||
"alt-speed-up" | number max global upload speed (in bytes per second)
|
||||
"blocklist-enabled" | boolean true means enabled
|
||||
"blocklist-size" | number number of rules in the blocklist
|
||||
"cache-size-MiB" | number size (in MiB) of the disk cache
|
||||
"cache-size" | number maximum size (in bytes) of the disk cache
|
||||
"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
|
||||
|
@ -444,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 K/s)
|
||||
"speed-limit-down" | number max global download speed (in bytes per second)
|
||||
"speed-limit-down-enabled" | boolean true means enabled
|
||||
"speed-limit-up" | number max global upload speed (in K/s)
|
||||
"speed-limit-up" | number max global upload speed (in bytes per second)
|
||||
"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
|
||||
|
@ -619,12 +623,22 @@
|
|||
8 | 1.92 | yes | torrent-get | new trackerStats arg "lastScrapeTimedOut"
|
||||
------+---------+-----------+----------------+-------------------------------
|
||||
9 | 2.00 | yes | session-set | new arg "start-added-torrents"
|
||||
| 2.00 | yes | session-set | new arg "trash-original-torrent-files"
|
||||
| 2.00 | yes | session-get | new arg "start-added-torrents"
|
||||
| 2.00 | yes | session-get | new arg "trash-original-torrent-files"
|
||||
| 2.00 | yes | session-get | new arg "cache-size-MiB"
|
||||
| 2.00 | yes | torrent-get | new arg "isFinished"
|
||||
| | 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"
|
||||
| | yes | torrent-get | new arg "isFinished"
|
||||
------+---------+-----------+----------------+-------------------------------
|
||||
10 | 2.10 | yes | torrent-set | new arg "trackerAdd"
|
||||
| 2.10 | yes | torrent-set | new arg "trackerEdit"
|
||||
| 2.10 | yes | torrent-set | new arg "trackerRemove"
|
||||
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"
|
||||
| | 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"
|
||||
| | yes | torrent-get | new arg "isFinished"
|
||||
| | yes | torrent-set | new arg "trackerAdd"
|
||||
| | yes | torrent-set | new arg "trackerEdit"
|
||||
| | yes | torrent-set | new arg "trackerRemove"
|
||||
|
|
|
@ -219,10 +219,10 @@ refreshOptions( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
|
||||
/* downLimitSpin */
|
||||
if( n ) {
|
||||
const int baseline = tr_torrentGetSpeedLimit( torrents[0], TR_DOWN );
|
||||
const int baseline = tr_torrentGetSpeedLimit_Bps( torrents[0], TR_DOWN ) / speed_K;
|
||||
int i;
|
||||
for( i=1; i<n; ++i )
|
||||
if( baseline != tr_torrentGetSpeedLimit( torrents[i], TR_DOWN ) )
|
||||
if( baseline != ( tr_torrentGetSpeedLimit_Bps( torrents[i], TR_DOWN ) / speed_K ) )
|
||||
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( torrents[0], TR_UP );
|
||||
const int baseline = tr_torrentGetSpeedLimit_Bps( torrents[0], TR_UP ) / speed_K;
|
||||
int i;
|
||||
for( i=1; i<n; ++i )
|
||||
if( baseline != tr_torrentGetSpeedLimit( torrents[i], TR_UP ) )
|
||||
if( baseline != ( tr_torrentGetSpeedLimit_Bps( torrents[i], TR_UP ) / speed_K ) )
|
||||
break;
|
||||
if( i == n )
|
||||
set_int_spin_if_different( di->upLimitSpin,
|
||||
|
@ -439,6 +439,7 @@ options_page_new( struct DetailsImpl * d )
|
|||
{
|
||||
guint tag;
|
||||
int row;
|
||||
char buf[128];
|
||||
const char *s;
|
||||
GtkWidget *t, *w, *tb, *h;
|
||||
|
||||
|
@ -451,7 +452,8 @@ options_page_new( struct DetailsImpl * d )
|
|||
tag = g_signal_connect( tb, "toggled", G_CALLBACK( global_speed_toggled_cb ), d );
|
||||
d->honorLimitsCheckTag = tag;
|
||||
|
||||
tb = gtk_check_button_new_with_mnemonic( _( "Limit _download speed (KiB/s):" ) );
|
||||
g_snprintf( buf, sizeof( buf ), _( "Limit _download speed (%s):" ), _(speed_K_str) );
|
||||
tb = gtk_check_button_new_with_mnemonic( buf );
|
||||
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( tb ), FALSE );
|
||||
d->downLimitedCheck = tb;
|
||||
tag = g_signal_connect( tb, "toggled", G_CALLBACK( down_speed_toggled_cb ), d );
|
||||
|
@ -463,7 +465,8 @@ options_page_new( struct DetailsImpl * d )
|
|||
hig_workarea_add_row_w( t, &row, tb, w, NULL );
|
||||
d->downLimitSpin = w;
|
||||
|
||||
tb = gtk_check_button_new_with_mnemonic( _( "Limit _upload speed (KiB/s):" ) );
|
||||
g_snprintf( buf, sizeof( buf ), _( "Limit _upload speed (%s):" ), _(speed_K_str) );
|
||||
tb = gtk_check_button_new_with_mnemonic( buf );
|
||||
d->upLimitedCheck = tb;
|
||||
tag = g_signal_connect( tb, "toggled", G_CALLBACK( up_speed_toggled_cb ), d );
|
||||
d->upLimitedCheckTag = tag;
|
||||
|
@ -758,7 +761,7 @@ refreshInfo( struct DetailsImpl * di, tr_torrent ** torrents, int n )
|
|||
str = none;
|
||||
else if( pieceSize >= 0 ) {
|
||||
char piecebuf[128];
|
||||
tr_strlsize( piecebuf, (uint64_t)pieceSize, sizeof( piecebuf ) );
|
||||
tr_formatter_mem( 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 ),
|
||||
|
@ -1041,7 +1044,7 @@ enum
|
|||
WEBSEED_COL_KEY,
|
||||
WEBSEED_COL_WAS_UPDATED,
|
||||
WEBSEED_COL_URL,
|
||||
WEBSEED_COL_DOWNLOAD_RATE_DOUBLE,
|
||||
WEBSEED_COL_DOWNLOAD_RATE_INT,
|
||||
WEBSEED_COL_DOWNLOAD_RATE_STRING,
|
||||
N_WEBSEED_COLS
|
||||
};
|
||||
|
@ -1052,7 +1055,7 @@ getWebseedColumnNames( int column )
|
|||
switch( column )
|
||||
{
|
||||
case WEBSEED_COL_URL: return _( "Webseeds" );
|
||||
case WEBSEED_COL_DOWNLOAD_RATE_DOUBLE:
|
||||
case WEBSEED_COL_DOWNLOAD_RATE_INT:
|
||||
case WEBSEED_COL_DOWNLOAD_RATE_STRING: return _( "Down" );
|
||||
default: return "";
|
||||
}
|
||||
|
@ -1065,7 +1068,7 @@ webseed_model_new( void )
|
|||
G_TYPE_STRING, /* key */
|
||||
G_TYPE_BOOLEAN, /* was-updated */
|
||||
G_TYPE_STRING, /* url */
|
||||
G_TYPE_DOUBLE, /* download rate double */
|
||||
G_TYPE_INT, /* download rate int */
|
||||
G_TYPE_STRING ); /* download rate string */
|
||||
}
|
||||
|
||||
|
@ -1075,9 +1078,9 @@ enum
|
|||
PEER_COL_WAS_UPDATED,
|
||||
PEER_COL_ADDRESS,
|
||||
PEER_COL_ADDRESS_COLLATED,
|
||||
PEER_COL_DOWNLOAD_RATE_DOUBLE,
|
||||
PEER_COL_DOWNLOAD_RATE_INT,
|
||||
PEER_COL_DOWNLOAD_RATE_STRING,
|
||||
PEER_COL_UPLOAD_RATE_DOUBLE,
|
||||
PEER_COL_UPLOAD_RATE_INT,
|
||||
PEER_COL_UPLOAD_RATE_STRING,
|
||||
PEER_COL_CLIENT,
|
||||
PEER_COL_PROGRESS,
|
||||
|
@ -1105,9 +1108,9 @@ getPeerColumnName( int column )
|
|||
{
|
||||
case PEER_COL_ADDRESS: return _( "Address" );
|
||||
case PEER_COL_DOWNLOAD_RATE_STRING:
|
||||
case PEER_COL_DOWNLOAD_RATE_DOUBLE: return _( "Down" );
|
||||
case PEER_COL_DOWNLOAD_RATE_INT: return _( "Down" );
|
||||
case PEER_COL_UPLOAD_RATE_STRING:
|
||||
case PEER_COL_UPLOAD_RATE_DOUBLE: return _( "Up" );
|
||||
case PEER_COL_UPLOAD_RATE_INT: return _( "Up" );
|
||||
case PEER_COL_CLIENT: return _( "Client" );
|
||||
case PEER_COL_PROGRESS: return _( "%" );
|
||||
case PEER_COL_UPLOAD_REQUEST_COUNT_INT:
|
||||
|
@ -1135,9 +1138,9 @@ peer_store_new( void )
|
|||
G_TYPE_BOOLEAN, /* was-updated */
|
||||
G_TYPE_STRING, /* address */
|
||||
G_TYPE_STRING, /* collated address */
|
||||
G_TYPE_FLOAT, /* download speed float */
|
||||
G_TYPE_INT, /* download speed int */
|
||||
G_TYPE_STRING, /* download speed string */
|
||||
G_TYPE_FLOAT, /* upload speed float */
|
||||
G_TYPE_INT, /* upload speed int */
|
||||
G_TYPE_STRING, /* upload speed string */
|
||||
G_TYPE_STRING, /* client */
|
||||
G_TYPE_INT, /* progress [0..100] */
|
||||
|
@ -1164,16 +1167,12 @@ initPeerRow( GtkListStore * store,
|
|||
const tr_peer_stat * peer )
|
||||
{
|
||||
int q[4];
|
||||
char up_speed[128];
|
||||
char down_speed[128];
|
||||
char collated_name[128];
|
||||
const char * client = peer->client;
|
||||
|
||||
if( !client || !strcmp( client, "Unknown Client" ) )
|
||||
client = "";
|
||||
|
||||
tr_strlspeed( up_speed, peer->rateToPeer, sizeof( up_speed ) );
|
||||
tr_strlspeed( down_speed, peer->rateToClient, sizeof( down_speed ) );
|
||||
if( sscanf( peer->addr, "%d.%d.%d.%d", q, q+1, q+2, q+3 ) != 4 )
|
||||
g_strlcpy( collated_name, peer->addr, sizeof( collated_name ) );
|
||||
else
|
||||
|
@ -1203,13 +1202,13 @@ refreshPeerRow( GtkListStore * store,
|
|||
char cancelled_by_peer[64];
|
||||
char cancelled_by_client[64];
|
||||
|
||||
if( peer->rateToPeer > 0.01 )
|
||||
tr_strlspeed( up_speed, peer->rateToPeer, sizeof( up_speed ) );
|
||||
if( peer->rateToPeer_Bps > 0 )
|
||||
tr_formatter_speed( up_speed, peer->rateToPeer_Bps, sizeof( up_speed ) );
|
||||
else
|
||||
*up_speed = '\0';
|
||||
|
||||
if( peer->rateToClient > 0.01 )
|
||||
tr_strlspeed( down_speed, peer->rateToClient, sizeof( down_speed ) );
|
||||
if( peer->rateToClient_Bps > 0 )
|
||||
tr_formatter_speed( down_speed, peer->rateToClient_Bps, sizeof( down_speed ) );
|
||||
else
|
||||
*down_speed = '\0';
|
||||
|
||||
|
@ -1249,9 +1248,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_DOUBLE, peer->rateToClient,
|
||||
PEER_COL_DOWNLOAD_RATE_INT, peer->rateToClient_Bps,
|
||||
PEER_COL_DOWNLOAD_RATE_STRING, down_speed,
|
||||
PEER_COL_UPLOAD_RATE_DOUBLE, peer->rateToPeer,
|
||||
PEER_COL_UPLOAD_RATE_INT, peer->rateToPeer_Bps,
|
||||
PEER_COL_UPLOAD_RATE_STRING, up_speed,
|
||||
PEER_COL_STATUS, peer->flagStr,
|
||||
PEER_COL_WAS_UPDATED, TRUE,
|
||||
|
@ -1397,7 +1396,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 );
|
||||
float * speeds = tr_torrentWebSpeeds( tor );
|
||||
int * speeds_Bps = tr_torrentWebSpeeds_Bps( tor );
|
||||
for( j=0; j<inf->webseedCount; ++j ) {
|
||||
char buf[128];
|
||||
char key[256];
|
||||
|
@ -1408,17 +1407,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[j] > 0.01 )
|
||||
tr_strlspeed( buf, speeds[j], sizeof( buf ) );
|
||||
if( speeds_Bps[j] > 0 )
|
||||
tr_formatter_speed( buf, speeds_Bps[j], sizeof( buf ) );
|
||||
else
|
||||
*buf = '\0';
|
||||
gtk_list_store_set( store, &iter, WEBSEED_COL_DOWNLOAD_RATE_DOUBLE, (double)speeds[j],
|
||||
gtk_list_store_set( store, &iter, WEBSEED_COL_DOWNLOAD_RATE_INT, speeds_Bps[j],
|
||||
WEBSEED_COL_DOWNLOAD_RATE_STRING, buf,
|
||||
WEBSEED_COL_WAS_UPDATED, TRUE,
|
||||
-1 );
|
||||
gtk_tree_path_free( p );
|
||||
}
|
||||
tr_free( speeds );
|
||||
tr_free( speeds_Bps );
|
||||
}
|
||||
|
||||
/* step 4: remove webseeds that have disappeared */
|
||||
|
@ -1612,13 +1611,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_DOUBLE;
|
||||
sort_col = PEER_COL_DOWNLOAD_RATE_INT;
|
||||
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_DOUBLE;
|
||||
sort_col = PEER_COL_UPLOAD_RATE_INT;
|
||||
break;
|
||||
|
||||
case PEER_COL_STATUS:
|
||||
|
@ -1687,7 +1686,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_DOUBLE );
|
||||
gtk_tree_view_column_set_sort_column_id( c, WEBSEED_COL_DOWNLOAD_RATE_INT );
|
||||
gtk_tree_view_append_column( GTK_TREE_VIEW( v ), c );
|
||||
|
||||
w = gtk_scrolled_window_new( NULL, NULL );
|
||||
|
|
21
gtk/main.c
21
gtk/main.c
|
@ -532,8 +532,9 @@ main( int argc, char ** argv )
|
|||
bind_textdomain_codeset( domain, "UTF-8" );
|
||||
textdomain( domain );
|
||||
g_set_application_name( _( "Transmission" ) );
|
||||
tr_formatter_size_init( 1024, _("B"), _("KiB"), _("MiB"), _("GiB") );
|
||||
tr_formatter_speed_init( 1024, _("B/s"), _("KiB/s"), _("MiB/s"), _("GiB/s") );
|
||||
tr_formatter_mem_init( mem_K, _(mem_B_str), _(mem_K_str), _(mem_M_str), _(mem_G_str) );
|
||||
tr_formatter_size_init( disk_K, _(disk_B_str), _(disk_K_str), _(disk_M_str), _(disk_G_str) );
|
||||
tr_formatter_speed_init( speed_K, _(speed_B_str), _(speed_K_str), _(speed_M_str), _(speed_G_str) );
|
||||
|
||||
/* initialize gtk */
|
||||
if( !g_thread_supported( ) )
|
||||
|
@ -1202,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 ) )
|
||||
else if( !strcmp( key, TR_PREFS_KEY_DSPEED_Bps ) )
|
||||
{
|
||||
tr_sessionSetSpeedLimit( tr, TR_DOWN, pref_int_get( key ) );
|
||||
tr_sessionSetSpeedLimit_Bps( 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 ) )
|
||||
else if( !strcmp( key, TR_PREFS_KEY_USPEED_Bps ) )
|
||||
{
|
||||
tr_sessionSetSpeedLimit( tr, TR_UP, pref_int_get( key ) );
|
||||
tr_sessionSetSpeedLimit_Bps( tr, TR_UP, pref_int_get( key ) );
|
||||
}
|
||||
else if( !strcmp( key, TR_PREFS_KEY_RATIO_ENABLED ) )
|
||||
{
|
||||
|
@ -1298,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 ) )
|
||||
else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_UP_Bps ) )
|
||||
{
|
||||
tr_sessionSetAltSpeed( tr, TR_UP, pref_int_get( key ) );
|
||||
tr_sessionSetAltSpeed_Bps( tr, TR_UP, pref_int_get( key ) );
|
||||
}
|
||||
else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN ) )
|
||||
else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps ) )
|
||||
{
|
||||
tr_sessionSetAltSpeed( tr, TR_DOWN, pref_int_get( key ) );
|
||||
tr_sessionSetAltSpeed_Bps( tr, TR_DOWN, pref_int_get( key ) );
|
||||
}
|
||||
else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_ENABLED ) )
|
||||
{
|
||||
|
|
|
@ -154,8 +154,8 @@ getProgressString( const tr_torrent * tor,
|
|||
static char*
|
||||
getShortTransferString( const tr_torrent * tor,
|
||||
const tr_stat * torStat,
|
||||
double uploadSpeed,
|
||||
double downloadSpeed,
|
||||
int uploadSpeed_Bps,
|
||||
int downloadSpeed_Bps,
|
||||
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, sizeof( downStr ) );
|
||||
tr_strlspeed( downStr, downloadSpeed_Bps, sizeof( downStr ) );
|
||||
if( haveUp )
|
||||
tr_strlspeed( upStr, uploadSpeed, sizeof( upStr ) );
|
||||
tr_strlspeed( upStr, uploadSpeed_Bps, 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,
|
||||
double uploadSpeed,
|
||||
double downloadSpeed )
|
||||
int uploadSpeed_Bps,
|
||||
int downloadSpeed_Bps )
|
||||
{
|
||||
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, downloadSpeed, buf, sizeof( buf ) );
|
||||
getShortTransferString( tor, torStat, uploadSpeed_Bps, downloadSpeed_Bps, 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 double uploadSpeed,
|
||||
const double downloadSpeed )
|
||||
const int uploadSpeed_Bps,
|
||||
const int downloadSpeed_Bps )
|
||||
{
|
||||
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, downloadSpeed );
|
||||
char * pch = getShortStatusString( tor, torStat, uploadSpeed_Bps, downloadSpeed_Bps );
|
||||
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, downloadSpeed, buf, sizeof( buf ) );
|
||||
getShortTransferString( tor, torStat, uploadSpeed_Bps, downloadSpeed_Bps, 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 */
|
||||
double upload_speed;
|
||||
int upload_speed_Bps;
|
||||
|
||||
/* @see upload_speed */
|
||||
double download_speed;
|
||||
/* @see upload_speed_Bps */
|
||||
int download_speed_Bps;
|
||||
|
||||
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, p->download_speed );
|
||||
status = getShortStatusString( tor, st, p->upload_speed_Bps, p->download_speed_Bps );
|
||||
|
||||
/* 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, p->download_speed );
|
||||
status = getStatusString( tor, st, p->upload_speed_Bps, p->download_speed_Bps );
|
||||
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, p->download_speed );
|
||||
status = getShortStatusString( tor, st, p->upload_speed_Bps, p->download_speed_Bps );
|
||||
|
||||
/* 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, p->download_speed );
|
||||
status = getStatusString( tor, st, p->upload_speed_Bps, p->download_speed_Bps );
|
||||
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 = g_value_get_double( v ); break;
|
||||
case P_DOWNLOAD_SPEED: p->download_speed = 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;
|
||||
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;
|
||||
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_double( v, p->upload_speed ); break;
|
||||
case P_DOWNLOAD_SPEED: g_value_set_double( v, p->download_speed ); 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_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_double( "piece-upload-speed", NULL,
|
||||
"tr_stat.pieceUploadSpeed",
|
||||
0, INT_MAX, 0,
|
||||
G_PARAM_READWRITE ) );
|
||||
g_param_spec_int( "piece-upload-speed", NULL,
|
||||
"tr_stat.pieceUploadSpeed_Bps",
|
||||
0, INT_MAX, 0,
|
||||
G_PARAM_READWRITE ) );
|
||||
|
||||
g_object_class_install_property( gobject_class, P_DOWNLOAD_SPEED,
|
||||
g_param_spec_double( "piece-download-speed", NULL,
|
||||
"tr_stat.pieceDownloadSpeed",
|
||||
0, INT_MAX, 0,
|
||||
G_PARAM_READWRITE ) );
|
||||
g_param_spec_int( "piece-download-speed", NULL,
|
||||
"tr_stat.pieceDownloadSpeed_Bps",
|
||||
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_DOUBLE, /* tr_stat.pieceUploadSpeed */
|
||||
G_TYPE_DOUBLE, /* tr_stat.pieceDownloadSpeed */
|
||||
G_TYPE_INT, /* tr_stat.pieceUploadSpeed_Bps */
|
||||
G_TYPE_INT, /* tr_stat.pieceDownloadSpeed_Bps */
|
||||
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,
|
||||
MC_SPEED_DOWN, st->pieceDownloadSpeed,
|
||||
MC_SPEED_UP, st->pieceUploadSpeed_Bps,
|
||||
MC_SPEED_DOWN, st->pieceDownloadSpeed_Bps,
|
||||
MC_ACTIVITY, st->activity,
|
||||
-1 );
|
||||
|
||||
|
@ -1322,8 +1322,8 @@ update_foreach( GtkTreeModel * model,
|
|||
gpointer data UNUSED )
|
||||
{
|
||||
int oldActivity, newActivity;
|
||||
double oldUpSpeed, newUpSpeed;
|
||||
double oldDownSpeed, newDownSpeed;
|
||||
int oldUpSpeed, newUpSpeed;
|
||||
int 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;
|
||||
newDownSpeed = st->pieceDownloadSpeed;
|
||||
newUpSpeed = st->pieceUploadSpeed_Bps;
|
||||
newDownSpeed = st->pieceDownloadSpeed_Bps;
|
||||
|
||||
/* updating the model triggers off resort/refresh,
|
||||
so don't do it unless something's actually changed... */
|
||||
if( ( newActivity != oldActivity ) ||
|
||||
( (int)(newUpSpeed*10.0) != (int)(oldUpSpeed*10.0) ) ||
|
||||
( (int)(newDownSpeed*10.0) != (int)(oldDownSpeed*10.0) ) )
|
||||
if( ( newActivity != oldActivity ) ||
|
||||
( newUpSpeed != oldUpSpeed ) ||
|
||||
( newDownSpeed != oldDownSpeed ) )
|
||||
{
|
||||
gtk_list_store_set( GTK_LIST_STORE( model ), iter,
|
||||
MC_ACTIVITY, newActivity,
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#ifdef HAVE_LIBAPPINDICATOR
|
||||
#include <libappindicator/app-indicator.h>
|
||||
#endif
|
||||
#include <libtransmission/transmission.h>
|
||||
#include <libtransmission/utils.h>
|
||||
#include "actions.h"
|
||||
#include "tr-icon.h"
|
||||
#include "util.h"
|
||||
|
@ -65,7 +67,7 @@ popup( GtkStatusIcon * self,
|
|||
void
|
||||
tr_icon_refresh( gpointer vicon )
|
||||
{
|
||||
double d;
|
||||
int Bps;
|
||||
int limit;
|
||||
char up[64];
|
||||
char upLimit[64];
|
||||
|
@ -77,13 +79,14 @@ tr_icon_refresh( gpointer vicon )
|
|||
tr_session * session = tr_core_session( g_object_get_data( G_OBJECT( icon ), "tr-core" ) );
|
||||
|
||||
/* up */
|
||||
if(((d = tr_sessionGetRawSpeed( session, TR_UP ))) < 0.1 )
|
||||
Bps = tr_sessionGetRawSpeed_Bps( session, TR_UP );
|
||||
if( Bps < 1 )
|
||||
g_strlcpy( up, idle, sizeof( up ) );
|
||||
else
|
||||
tr_strlspeed( up, d, sizeof( up ) );
|
||||
tr_formatter_speed( up, Bps, sizeof( up ) );
|
||||
|
||||
/* up limit */
|
||||
if( !tr_sessionGetActiveSpeedLimit( session, TR_UP, &limit ) )
|
||||
if( !tr_sessionGetActiveSpeedLimit_Bps( session, TR_UP, &limit ) )
|
||||
*upLimit = '\0';
|
||||
else {
|
||||
char buf[64];
|
||||
|
@ -92,13 +95,14 @@ tr_icon_refresh( gpointer vicon )
|
|||
}
|
||||
|
||||
/* down */
|
||||
if(((d = tr_sessionGetRawSpeed( session, TR_DOWN ))) < 0.1 )
|
||||
Bps = tr_sessionGetRawSpeed_Bps( session, TR_DOWN );
|
||||
if( Bps < 1 )
|
||||
g_strlcpy( down, idle, sizeof( down ) );
|
||||
else
|
||||
tr_strlspeed( down, d, sizeof( down ) );
|
||||
tr_formatter_speed( down, Bps, sizeof( down ) );
|
||||
|
||||
/* down limit */
|
||||
if( !tr_sessionGetActiveSpeedLimit( session, TR_DOWN, &limit ) )
|
||||
if( !tr_sessionGetActiveSpeedLimit_Bps( session, TR_DOWN, &limit ) )
|
||||
*downLimit = '\0';
|
||||
else {
|
||||
char buf[64];
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
***
|
||||
**/
|
||||
|
||||
#define MULTIPLIER_KEY "multiplier-key"
|
||||
#define PREF_KEY "pref-key"
|
||||
|
||||
static void
|
||||
|
@ -96,8 +97,8 @@ spin_idle_data_free( gpointer gdata )
|
|||
static gboolean
|
||||
spun_cb_idle( gpointer spin )
|
||||
{
|
||||
gboolean keep_waiting = TRUE;
|
||||
GObject * o = G_OBJECT( spin );
|
||||
gboolean keep_waiting = TRUE;
|
||||
GObject * o = G_OBJECT( spin );
|
||||
struct spin_idle_data * data = g_object_get_data( o, IDLE_DATA );
|
||||
|
||||
/* has the user stopped making changes? */
|
||||
|
@ -105,15 +106,16 @@ 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 ) );
|
||||
const double value = gtk_spin_button_get_value( GTK_SPIN_BUTTON( spin ) ) * multiplier;
|
||||
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 ) );
|
||||
const int value = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( spin ) ) * multiplier;
|
||||
tr_core_set_pref_int( TR_CORE( data->core ), key, value );
|
||||
}
|
||||
|
||||
|
@ -127,13 +129,11 @@ spun_cb_idle( gpointer spin )
|
|||
}
|
||||
|
||||
static void
|
||||
spun_cb( GtkSpinButton * w,
|
||||
gpointer core,
|
||||
gboolean isDouble )
|
||||
spun_cb( GtkSpinButton * w, gpointer core, gboolean isDouble )
|
||||
{
|
||||
/* user may be spinning through many values, so let's hold off
|
||||
for a moment to keep from flooding the core with changes */
|
||||
GObject * o = G_OBJECT( w );
|
||||
GObject * o = G_OBJECT( w );
|
||||
struct spin_idle_data * data = g_object_get_data( o, IDLE_DATA );
|
||||
|
||||
if( data == NULL )
|
||||
|
@ -150,15 +150,13 @@ spun_cb( GtkSpinButton * w,
|
|||
}
|
||||
|
||||
static void
|
||||
spun_cb_int( GtkSpinButton * w,
|
||||
gpointer core )
|
||||
spun_cb_int( GtkSpinButton * w, gpointer core )
|
||||
{
|
||||
spun_cb( w, core, FALSE );
|
||||
}
|
||||
|
||||
static void
|
||||
spun_cb_double( GtkSpinButton * w,
|
||||
gpointer core )
|
||||
spun_cb_double( GtkSpinButton * w, gpointer core )
|
||||
{
|
||||
spun_cb( w, core, TRUE );
|
||||
}
|
||||
|
@ -166,16 +164,16 @@ spun_cb_double( GtkSpinButton * w,
|
|||
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_full( G_OBJECT( w ), PREF_KEY, g_strdup(
|
||||
key ), g_free );
|
||||
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 ) );
|
||||
gtk_spin_button_set_value( GTK_SPIN_BUTTON( w ), pref_int_get( key ) / multiplier );
|
||||
g_signal_connect( w, "value-changed", G_CALLBACK( spun_cb_int ), core );
|
||||
return w;
|
||||
}
|
||||
|
@ -183,14 +181,14 @@ 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_full( G_OBJECT( w ), PREF_KEY, g_strdup(
|
||||
key ), g_free );
|
||||
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 ) );
|
||||
g_signal_connect( w, "value-changed", G_CALLBACK( spun_cb_double ), core );
|
||||
|
@ -198,8 +196,7 @@ new_spin_button_double( const char * key,
|
|||
}
|
||||
|
||||
static void
|
||||
entry_changed_cb( GtkEntry * w,
|
||||
gpointer core )
|
||||
entry_changed_cb( GtkEntry * w, gpointer core )
|
||||
{
|
||||
const char * key = g_object_get_data( G_OBJECT( w ), PREF_KEY );
|
||||
const char * value = gtk_entry_get_text( w );
|
||||
|
@ -332,7 +329,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, 0, INT_MAX, .05 );
|
||||
w2 = new_spin_button_double( TR_PREFS_KEY_RATIO, core, 1, 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 );
|
||||
|
@ -809,7 +806,7 @@ webPage( GObject * core )
|
|||
hig_workarea_add_wide_control( t, &row, h );
|
||||
|
||||
/* port */
|
||||
w = new_spin_button( TR_PREFS_KEY_RPC_PORT, core, 0, USHRT_MAX, 1 );
|
||||
w = new_spin_button( TR_PREFS_KEY_RPC_PORT, core, 1, 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 );
|
||||
|
@ -1014,7 +1011,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, 0, USHRT_MAX, 1 );
|
||||
w = new_spin_button( TR_PREFS_KEY_PROXY_PORT, core, 1, 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 );
|
||||
|
@ -1220,16 +1217,16 @@ bandwidthPage( GObject * core )
|
|||
t = hig_workarea_create( );
|
||||
hig_workarea_add_section_title( t, &row, _( "Speed Limits" ) );
|
||||
|
||||
s = _( "Limit _download speed (KiB/s):" );
|
||||
w = new_check_button( s, TR_PREFS_KEY_DSPEED_ENABLED, core );
|
||||
w2 = new_spin_button( TR_PREFS_KEY_DSPEED, core, 0, INT_MAX, 5 );
|
||||
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 );
|
||||
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 );
|
||||
|
||||
s = _( "Limit _upload speed (KiB/s):" );
|
||||
w = new_check_button( s, TR_PREFS_KEY_USPEED_ENABLED, core );
|
||||
w2 = new_spin_button( TR_PREFS_KEY_USPEED, core, 0, INT_MAX, 5 );
|
||||
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 );
|
||||
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 );
|
||||
|
@ -1252,13 +1249,13 @@ bandwidthPage( GObject * core )
|
|||
gtk_misc_set_alignment( GTK_MISC( w ), 0.5f, 0.5f );
|
||||
hig_workarea_add_wide_control( t, &row, w );
|
||||
|
||||
s = _( "Limit do_wnload speed (KiB/s):" );
|
||||
w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_DOWN, core, 0, INT_MAX, 5 );
|
||||
hig_workarea_add_row( t, &row, s, w, NULL );
|
||||
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 );
|
||||
hig_workarea_add_row( t, &row, buf, w, NULL );
|
||||
|
||||
s = _( "Limit u_pload speed (KiB/s):" );
|
||||
w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_UP, core, 0, INT_MAX, 5 );
|
||||
hig_workarea_add_row( t, &row, s, 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 );
|
||||
hig_workarea_add_row( t, &row, buf, w, NULL );
|
||||
|
||||
s = _( "_Scheduled times:" );
|
||||
h = gtk_hbox_new( FALSE, 0 );
|
||||
|
@ -1372,7 +1369,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, USHRT_MAX, 1 );
|
||||
w = data->portSpin = new_spin_button( TR_PREFS_KEY_PEER_PORT, core, 1, 1, USHRT_MAX, 1 );
|
||||
hig_workarea_add_row( t, &row, s, w, NULL );
|
||||
|
||||
h = gtk_hbox_new( FALSE, GUI_PAD_BIG );
|
||||
|
@ -1397,9 +1394,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, 300, 5 );
|
||||
w = new_spin_button( TR_PREFS_KEY_PEER_LIMIT_TORRENT, core, 1, 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, 3000, 5 );
|
||||
w = new_spin_button( TR_PREFS_KEY_PEER_LIMIT_GLOBAL, core, 1, 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 ) ||
|
||||
!strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN ) )
|
||||
!strcmp( key, TR_PREFS_KEY_ALT_SPEED_UP_Bps ) ||
|
||||
!strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps ) )
|
||||
{
|
||||
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 ), sizeof( u ) );
|
||||
tr_strlspeed( d, pref_int_get( TR_PREFS_KEY_ALT_SPEED_DOWN ), sizeof( d ) );
|
||||
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 ) );
|
||||
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 speed = GPOINTER_TO_INT( g_object_get_data( o, SPEED_KEY ) );
|
||||
const int Bps = GPOINTER_TO_INT( g_object_get_data( o, SPEED_KEY ) ) * speed_K;
|
||||
tr_direction dir = GPOINTER_TO_INT( g_object_get_data( o, DIRECTION_KEY ) );
|
||||
|
||||
key = dir==TR_UP ? TR_PREFS_KEY_USPEED : TR_PREFS_KEY_DSPEED;
|
||||
tr_core_set_pref_int( p->core, key, speed );
|
||||
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_ENABLED : TR_PREFS_KEY_DSPEED_ENABLED;
|
||||
tr_core_set_pref_bool( p->core, key, TRUE );
|
||||
|
@ -427,7 +427,7 @@ createSpeedMenu( PrivateData * p, tr_direction dir )
|
|||
for( i=0, n=G_N_ELEMENTS(speeds); i<n; ++i )
|
||||
{
|
||||
char buf[128];
|
||||
tr_strlspeed( buf, speeds[i], sizeof( buf ) );
|
||||
tr_strlspeed( buf, speeds[i] * speed_K, sizeof( buf ) );
|
||||
w = gtk_menu_item_new_with_label( buf );
|
||||
g_object_set_data( G_OBJECT( w ), DIRECTION_KEY, GINT_TO_POINTER( dir ) );
|
||||
g_object_set_data( G_OBJECT( w ), SPEED_KEY, GINT_TO_POINTER( speeds[i] ) );
|
||||
|
@ -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 ), sizeof( buf1 ) );
|
||||
tr_strlspeed( buf1, pref_int_get( TR_PREFS_KEY_DSPEED_Bps ), 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 ), sizeof( buf1 ) );
|
||||
tr_strlspeed( buf1, pref_int_get( TR_PREFS_KEY_USPEED_Bps ), 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];
|
||||
double up=0, down=0;
|
||||
int up=0, down=0;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel * model = tr_core_model( p->core );
|
||||
|
||||
if( gtk_tree_model_get_iter_first( model, &iter ) ) do
|
||||
{
|
||||
double u, d;
|
||||
int u, d;
|
||||
gtk_tree_model_get( model, &iter, MC_SPEED_UP, &u,
|
||||
MC_SPEED_DOWN, &d,
|
||||
-1 );
|
||||
|
|
42
gtk/util.c
42
gtk/util.c
|
@ -41,6 +41,44 @@
|
|||
#include "tr-prefs.h"
|
||||
#include "util.h"
|
||||
|
||||
/***
|
||||
**** UNITS
|
||||
***/
|
||||
|
||||
const int mem_K = 1024;
|
||||
/* abbreviation for bytes */
|
||||
const char * mem_B_str = N_("B");
|
||||
/* abbreviation IEC base 2 units kilobyte */
|
||||
const char * mem_K_str = N_("KiB");
|
||||
/* abbreviation IEC base 2 units megabyte */
|
||||
const char * mem_M_str = N_("MiB");
|
||||
/* abbreviation IEC base 2 units gigabyte */
|
||||
const char * mem_G_str = N_("GiB");
|
||||
|
||||
const int disk_K = 1000;
|
||||
/* abbreviation for bytes */
|
||||
const char * disk_B_str = N_("B");
|
||||
/* abbreviation for SI base 10 kilobyte */
|
||||
const char * disk_K_str = N_("kB");
|
||||
/* abbreviation for SI base 10 megabyte */
|
||||
const char * disk_M_str = N_("MB");
|
||||
/* abbreviation for SI base 10 gigabyte */
|
||||
const char * disk_G_str = N_("GB");
|
||||
|
||||
const int speed_K = 1000;
|
||||
/* abbreviation for bytes per second */
|
||||
const char * speed_B_str = N_("B/s");
|
||||
/* abbreviation for kilobytes per second */
|
||||
const char * speed_K_str = N_("kB/s");
|
||||
/* abbreviation for megabytes per second */
|
||||
const char * speed_M_str = N_("MB/s");
|
||||
/* abbreviation for gigabytes per second */
|
||||
const char * speed_G_str = N_("GB/s");
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
gtr_lockfile_state_t
|
||||
gtr_lockfile( const char * filename )
|
||||
{
|
||||
|
@ -124,10 +162,8 @@ tr_strlsize( char * buf, guint64 bytes, size_t buflen )
|
|||
}
|
||||
|
||||
char*
|
||||
tr_strlspeed( char * buf, double kb_sec, size_t buflen )
|
||||
tr_strlspeed( char * buf, int bytes_per_second, size_t buflen )
|
||||
{
|
||||
const int64_t bytes_per_second = kb_sec * 1024.0;
|
||||
|
||||
if( bytes_per_second < 1 )
|
||||
g_strlcpy( buf, _( "None" ), buflen );
|
||||
else
|
||||
|
|
24
gtk/util.h
24
gtk/util.h
|
@ -17,6 +17,26 @@
|
|||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <libtransmission/transmission.h>
|
||||
|
||||
extern const int mem_K;
|
||||
extern const char * mem_B_str;
|
||||
extern const char * mem_K_str;
|
||||
extern const char * mem_M_str;
|
||||
extern const char * mem_G_str;
|
||||
|
||||
extern const int disk_K;
|
||||
extern const char * disk_B_str;
|
||||
extern const char * disk_K_str;
|
||||
extern const char * disk_M_str;
|
||||
extern const char * disk_G_str;
|
||||
|
||||
extern const int speed_K;
|
||||
extern const char * speed_B_str;
|
||||
extern const char * speed_K_str;
|
||||
extern const char * speed_M_str;
|
||||
extern const char * speed_G_str;
|
||||
|
||||
/* portability wrapper around g_warn_if_fail() for older versions of glib */
|
||||
#ifdef g_warn_if_fail
|
||||
#define gtr_warn_if_fail(expr) g_warn_if_fail(expr)
|
||||
|
@ -45,8 +65,8 @@ char* tr_strlpercent( char * buf, double x, size_t buflen );
|
|||
/* return a human-readable string for the size given in bytes. */
|
||||
char* tr_strlsize( char * buf, guint64 size, size_t buflen );
|
||||
|
||||
/* return a human-readable string for the transfer rate given in bytes. */
|
||||
char* tr_strlspeed( char * buf, double KiBps, size_t buflen );
|
||||
/* return a human-readable string for the transfer rate given in Bps. */
|
||||
char* tr_strlspeed( char * buf, int bytes_per_second, size_t buflen );
|
||||
|
||||
/* return a human-readable string for the given ratio. */
|
||||
char* tr_strlratio( char * buf, double ratio, size_t buflen );
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
****
|
||||
***/
|
||||
|
||||
static float
|
||||
getSpeed( const struct bratecontrol * r, int interval_msec, uint64_t now )
|
||||
static unsigned int
|
||||
getSpeed_Bps( const struct bratecontrol * r, unsigned int interval_msec, uint64_t now )
|
||||
{
|
||||
uint64_t bytes = 0;
|
||||
const uint64_t cutoff = (now?now:tr_date()) - interval_msec;
|
||||
|
@ -48,7 +48,7 @@ getSpeed( const struct bratecontrol * r, int interval_msec, uint64_t now )
|
|||
if( i == r->newest ) break; /* we've come all the way around */
|
||||
}
|
||||
|
||||
return ( bytes / 1024.0 ) * ( 1000.0 / interval_msec );
|
||||
return (unsigned int)(( bytes * 1000u ) / interval_msec);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -153,7 +153,7 @@ static void
|
|||
allocateBandwidth( tr_bandwidth * b,
|
||||
tr_priority_t parent_priority,
|
||||
tr_direction dir,
|
||||
int period_msec,
|
||||
unsigned int period_msec,
|
||||
tr_ptrArray * peer_pool )
|
||||
{
|
||||
tr_priority_t priority;
|
||||
|
@ -164,15 +164,14 @@ allocateBandwidth( tr_bandwidth * b,
|
|||
/* set the available bandwidth */
|
||||
if( b->band[dir].isLimited )
|
||||
{
|
||||
const double desiredSpeed = b->band[dir].desiredSpeed;
|
||||
const double nextPulseSpeed = desiredSpeed;
|
||||
b->band[dir].bytesLeft = MAX( 0.0, nextPulseSpeed * 1024.0 * period_msec / 1000.0 );
|
||||
const unsigned int nextPulseSpeed = b->band[dir].desiredSpeed_Bps;
|
||||
b->band[dir].bytesLeft = ( nextPulseSpeed * period_msec ) / 1000u;
|
||||
|
||||
#ifdef DEBUG_DIRECTION
|
||||
if( dir == DEBUG_DIRECTION )
|
||||
fprintf( stderr, "bandwidth %p currentPieceSpeed(%5.2f of %5.2f) desiredSpeed(%5.2f), allocating %5.2f\n",
|
||||
fprintf( stderr, "bandwidth %p currentPieceSpeed(%5.2f of %5.2f) desiredSpeed(%5.2f), allocating %d\n",
|
||||
b, currentSpeed, tr_bandwidthGetRawSpeed( b, dir ), desiredSpeed,
|
||||
b->band[dir].bytesLeft/1024.0 );
|
||||
b->band[dir].bytesLeft );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -238,7 +237,7 @@ phaseOne( tr_ptrArray * peerArray, tr_direction dir )
|
|||
void
|
||||
tr_bandwidthAllocate( tr_bandwidth * b,
|
||||
tr_direction dir,
|
||||
int period_msec )
|
||||
unsigned int period_msec )
|
||||
{
|
||||
int i, peerCount;
|
||||
tr_ptrArray tmp = TR_PTR_ARRAY_INIT;
|
||||
|
@ -306,10 +305,10 @@ tr_bandwidthSetPeer( tr_bandwidth * b, tr_peerIo * peer )
|
|||
****
|
||||
***/
|
||||
|
||||
size_t
|
||||
unsigned int
|
||||
tr_bandwidthClamp( const tr_bandwidth * b,
|
||||
tr_direction dir,
|
||||
size_t byteCount )
|
||||
unsigned int byteCount )
|
||||
{
|
||||
assert( tr_isBandwidth( b ) );
|
||||
assert( tr_isDirection( dir ) );
|
||||
|
@ -326,22 +325,22 @@ tr_bandwidthClamp( const tr_bandwidth * b,
|
|||
return byteCount;
|
||||
}
|
||||
|
||||
double
|
||||
tr_bandwidthGetRawSpeed( const tr_bandwidth * b, const uint64_t now, const tr_direction dir )
|
||||
unsigned int
|
||||
tr_bandwidthGetRawSpeed_Bps( const tr_bandwidth * b, const uint64_t now, const tr_direction dir )
|
||||
{
|
||||
assert( tr_isBandwidth( b ) );
|
||||
assert( tr_isDirection( dir ) );
|
||||
|
||||
return getSpeed( &b->band[dir].raw, HISTORY_MSEC, now );
|
||||
return getSpeed_Bps( &b->band[dir].raw, HISTORY_MSEC, now );
|
||||
}
|
||||
|
||||
double
|
||||
tr_bandwidthGetPieceSpeed( const tr_bandwidth * b, const uint64_t now, const tr_direction dir )
|
||||
unsigned int
|
||||
tr_bandwidthGetPieceSpeed_Bps( const tr_bandwidth * b, const uint64_t now, const tr_direction dir )
|
||||
{
|
||||
assert( tr_isBandwidth( b ) );
|
||||
assert( tr_isDirection( dir ) );
|
||||
|
||||
return getSpeed( &b->band[dir].piece, HISTORY_MSEC, now );
|
||||
return getSpeed_Bps( &b->band[dir].piece, HISTORY_MSEC, now );
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -32,7 +32,7 @@ struct tr_peerIo;
|
|||
* it's included in the header for inlining and composition. */
|
||||
enum
|
||||
{
|
||||
HISTORY_MSEC = 2000,
|
||||
HISTORY_MSEC = 2000u,
|
||||
INTERVAL_MSEC = HISTORY_MSEC,
|
||||
GRANULARITY_MSEC = 200,
|
||||
HISTORY_SIZE = ( INTERVAL_MSEC / GRANULARITY_MSEC ),
|
||||
|
@ -53,8 +53,8 @@ struct tr_band
|
|||
{
|
||||
tr_bool isLimited;
|
||||
tr_bool honorParentLimits;
|
||||
size_t bytesLeft;
|
||||
double desiredSpeed;
|
||||
unsigned int bytesLeft;
|
||||
unsigned int desiredSpeed_Bps;
|
||||
struct bratecontrol raw;
|
||||
struct bratecontrol piece;
|
||||
};
|
||||
|
@ -147,29 +147,28 @@ static inline tr_bool tr_isBandwidth( const tr_bandwidth * b )
|
|||
******/
|
||||
|
||||
/**
|
||||
* @brief Set the desired speed (in KiB/s) for this bandwidth subtree.
|
||||
* @brief Set the desired speed for this bandwidth subtree.
|
||||
* @see tr_bandwidthAllocate
|
||||
* @see tr_bandwidthGetDesiredSpeed
|
||||
*/
|
||||
static inline tr_bool tr_bandwidthSetDesiredSpeed( tr_bandwidth * bandwidth,
|
||||
tr_direction dir,
|
||||
double desiredSpeed )
|
||||
static inline tr_bool tr_bandwidthSetDesiredSpeed_Bps( tr_bandwidth * bandwidth,
|
||||
tr_direction dir,
|
||||
unsigned int desiredSpeed )
|
||||
{
|
||||
double * value = &bandwidth->band[dir].desiredSpeed;
|
||||
const tr_bool didChange = (int)(desiredSpeed*1024.0) != (int)(*value*1024.0);
|
||||
unsigned int * value = &bandwidth->band[dir].desiredSpeed_Bps;
|
||||
const tr_bool didChange = desiredSpeed != *value;
|
||||
*value = desiredSpeed;
|
||||
return didChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the desired speed (in KiB/s) for ths bandwidth subtree.
|
||||
* @brief Get the desired speed for the bandwidth subtree.
|
||||
* @see tr_bandwidthSetDesiredSpeed
|
||||
*/
|
||||
static inline double
|
||||
tr_bandwidthGetDesiredSpeed( const tr_bandwidth * bandwidth,
|
||||
tr_direction dir )
|
||||
tr_bandwidthGetDesiredSpeed_Bps( const tr_bandwidth * bandwidth, tr_direction dir )
|
||||
{
|
||||
return bandwidth->band[dir].desiredSpeed;
|
||||
return bandwidth->band[dir].desiredSpeed_Bps;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,28 +198,28 @@ static inline tr_bool tr_bandwidthIsLimited( const tr_bandwidth * bandwidth,
|
|||
*/
|
||||
void tr_bandwidthAllocate ( tr_bandwidth * bandwidth,
|
||||
tr_direction direction,
|
||||
int period_msec );
|
||||
unsigned int period_msec );
|
||||
|
||||
/**
|
||||
* @brief clamps byteCount down to a number that this bandwidth will allow to be consumed
|
||||
*/
|
||||
size_t tr_bandwidthClamp ( const tr_bandwidth * bandwidth,
|
||||
unsigned int tr_bandwidthClamp ( const tr_bandwidth * bandwidth,
|
||||
tr_direction direction,
|
||||
size_t byteCount );
|
||||
unsigned int byteCount );
|
||||
|
||||
/******
|
||||
*******
|
||||
******/
|
||||
|
||||
/** @brief Get the raw total of bytes read or sent by this bandwidth subtree. */
|
||||
double tr_bandwidthGetRawSpeed( const tr_bandwidth * bandwidth,
|
||||
const uint64_t now,
|
||||
const tr_direction direction );
|
||||
unsigned int tr_bandwidthGetRawSpeed_Bps( const tr_bandwidth * bandwidth,
|
||||
const uint64_t now,
|
||||
const tr_direction direction );
|
||||
|
||||
/** @brief Get the number of piece data bytes read or sent by this bandwidth subtree. */
|
||||
double tr_bandwidthGetPieceSpeed( const tr_bandwidth * bandwidth,
|
||||
const uint64_t now,
|
||||
const tr_direction direction );
|
||||
unsigned int tr_bandwidthGetPieceSpeed_Bps( const tr_bandwidth * bandwidth,
|
||||
const uint64_t now,
|
||||
const tr_direction direction );
|
||||
|
||||
/**
|
||||
* @brief Notify the bandwidth object that some of its allocated bandwidth has been consumed.
|
||||
|
|
|
@ -48,8 +48,8 @@ struct cache_block
|
|||
struct tr_cache
|
||||
{
|
||||
tr_ptrArray blocks;
|
||||
int maxBlocks;
|
||||
size_t maxMiB;
|
||||
int max_blocks;
|
||||
size_t max_bytes;
|
||||
|
||||
size_t disk_writes;
|
||||
size_t disk_write_bytes;
|
||||
|
@ -197,7 +197,7 @@ cacheTrim( tr_cache * cache )
|
|||
{
|
||||
int err = 0;
|
||||
|
||||
while( !err && ( tr_ptrArraySize( &cache->blocks ) > cache->maxBlocks ) )
|
||||
while( !err && ( tr_ptrArraySize( &cache->blocks ) > cache->max_blocks ) )
|
||||
{
|
||||
int n;
|
||||
const int i = findChunk2Discard( cache, &n );
|
||||
|
@ -212,33 +212,38 @@ cacheTrim( tr_cache * cache )
|
|||
***/
|
||||
|
||||
static int
|
||||
getMaxBlocks( double maxMiB )
|
||||
getMaxBlocks( int64_t max_bytes )
|
||||
{
|
||||
const double maxBytes = maxMiB * (1024 * 1024);
|
||||
return maxBytes / MAX_BLOCK_SIZE;
|
||||
return max_bytes / (double)MAX_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
int
|
||||
tr_cacheSetLimit( tr_cache * cache, double maxMiB )
|
||||
tr_cacheSetLimit( tr_cache * cache, int64_t max_bytes )
|
||||
{
|
||||
cache->maxMiB = maxMiB;
|
||||
cache->maxBlocks = getMaxBlocks( maxMiB );
|
||||
tr_ndbg( MY_NAME, "Maximum cache size set to %.2f MiB (%d blocks)", maxMiB, cache->maxBlocks );
|
||||
char buf[128];
|
||||
|
||||
cache->max_bytes = max_bytes;
|
||||
cache->max_blocks = getMaxBlocks( max_bytes );
|
||||
|
||||
tr_formatter_mem( 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 );
|
||||
}
|
||||
|
||||
double
|
||||
int64_t
|
||||
tr_cacheGetLimit( const tr_cache * cache )
|
||||
{
|
||||
return cache->maxMiB;
|
||||
return cache->max_bytes;
|
||||
}
|
||||
|
||||
tr_cache *
|
||||
tr_cacheNew( double maxMiB )
|
||||
tr_cacheNew( int64_t max_bytes )
|
||||
{
|
||||
tr_cache * cache = tr_new0( tr_cache, 1 );
|
||||
cache->blocks = TR_PTR_ARRAY_INIT;
|
||||
cache->maxBlocks = getMaxBlocks( maxMiB );
|
||||
cache->max_bytes = max_bytes;
|
||||
cache->max_blocks = getMaxBlocks( max_bytes );
|
||||
return cache;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ typedef struct tr_cache tr_cache;
|
|||
****
|
||||
***/
|
||||
|
||||
tr_cache * tr_cacheNew( double max_MiB );
|
||||
tr_cache * tr_cacheNew( int64_t max_bytes );
|
||||
|
||||
void tr_cacheFree( tr_cache * );
|
||||
|
||||
|
@ -31,9 +31,9 @@ void tr_cacheFree( tr_cache * );
|
|||
****
|
||||
***/
|
||||
|
||||
int tr_cacheSetLimit( tr_cache * cache, double max_MiB );
|
||||
int tr_cacheSetLimit( tr_cache * cache, int64_t max_bytes );
|
||||
|
||||
double tr_cacheGetLimit( const tr_cache * );
|
||||
int64_t tr_cacheGetLimit( const tr_cache * );
|
||||
|
||||
int tr_cacheWriteBlock( tr_cache * cache,
|
||||
tr_torrent * torrent,
|
||||
|
|
|
@ -66,7 +66,7 @@ guessPacketOverhead( size_t d )
|
|||
*/
|
||||
const double assumed_payload_data_rate = 94.0;
|
||||
|
||||
return (size_t)( d * ( 100.0 / assumed_payload_data_rate ) - d );
|
||||
return (unsigned int)( d * ( 100.0 / assumed_payload_data_rate ) - d );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,14 +90,14 @@ struct tr_datatype
|
|||
***/
|
||||
|
||||
static void
|
||||
didWriteWrapper( tr_peerIo * io, size_t bytes_transferred )
|
||||
didWriteWrapper( tr_peerIo * io, unsigned int bytes_transferred )
|
||||
{
|
||||
while( bytes_transferred && tr_isPeerIo( io ) )
|
||||
{
|
||||
struct tr_datatype * next = io->outbuf_datatypes->data;
|
||||
|
||||
const size_t payload = MIN( next->length, bytes_transferred );
|
||||
const size_t overhead = guessPacketOverhead( payload );
|
||||
const unsigned int payload = MIN( next->length, bytes_transferred );
|
||||
const unsigned int overhead = guessPacketOverhead( payload );
|
||||
|
||||
tr_bandwidthUsed( &io->bandwidth, TR_UP, payload, next->isPieceData );
|
||||
|
||||
|
@ -206,10 +206,10 @@ event_read_cb( int fd, short event UNUSED, void * vio )
|
|||
tr_peerIo * io = vio;
|
||||
|
||||
/* Limit the input buffer to 256K, so it doesn't grow too large */
|
||||
size_t howmuch;
|
||||
unsigned int howmuch;
|
||||
unsigned int curlen;
|
||||
const tr_direction dir = TR_DOWN;
|
||||
const size_t max = 256 * 1024;
|
||||
size_t curlen;
|
||||
const unsigned int max = 256 * 1024;
|
||||
|
||||
assert( tr_isPeerIo( io ) );
|
||||
|
||||
|
@ -229,7 +229,7 @@ event_read_cb( int fd, short event UNUSED, void * vio )
|
|||
}
|
||||
|
||||
EVUTIL_SET_SOCKET_ERROR( 0 );
|
||||
res = evbuffer_read( io->inbuf, fd, howmuch );
|
||||
res = evbuffer_read( io->inbuf, fd, (int)howmuch );
|
||||
e = EVUTIL_SOCKET_ERROR( );
|
||||
|
||||
if( res > 0 )
|
||||
|
@ -282,7 +282,7 @@ tr_evbuffer_write( tr_peerIo * io, int fd, size_t howmuch )
|
|||
dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?tr_net_strerror(errstr,sizeof(errstr),e):"") );
|
||||
|
||||
if( n > 0 )
|
||||
evbuffer_drain( buffer, n );
|
||||
evbuffer_drain( buffer, (size_t)n );
|
||||
|
||||
/* keep the iobuf's excess capacity from growing too large */
|
||||
if( EVBUFFER_LENGTH( io->outbuf ) == 0 ) {
|
||||
|
@ -716,17 +716,18 @@ tr_peerIoSetPeersId( tr_peerIo * io,
|
|||
***
|
||||
**/
|
||||
|
||||
static size_t
|
||||
static unsigned int
|
||||
getDesiredOutputBufferSize( const tr_peerIo * io, uint64_t now )
|
||||
{
|
||||
/* this is all kind of arbitrary, but what seems to work well is
|
||||
* being large enough to hold the next 20 seconds' worth of input,
|
||||
* or a few blocks, whichever is bigger.
|
||||
* It's okay to tweak this as needed */
|
||||
const double currentSpeed = tr_bandwidthGetPieceSpeed( &io->bandwidth, now, TR_UP );
|
||||
const double period = 15; /* arbitrary */
|
||||
const double numBlocks = 3.5; /* the 3 is arbitrary; the .5 is to leave room for messages */
|
||||
return MAX( MAX_BLOCK_SIZE*numBlocks, currentSpeed*1024*period );
|
||||
const unsigned int currentSpeed_Bps = tr_bandwidthGetPieceSpeed_Bps( &io->bandwidth, now, TR_UP );
|
||||
const unsigned int period = 15u; /* arbitrary */
|
||||
/* the 3 is arbitrary; the .5 is to leave room for messages */
|
||||
static const unsigned int ceiling = (unsigned int)( MAX_BLOCK_SIZE * 3.5 );
|
||||
return MAX( ceiling, currentSpeed_Bps*period );
|
||||
}
|
||||
|
||||
size_t
|
||||
|
@ -882,7 +883,7 @@ tr_peerIoTryRead( tr_peerIo * io, size_t howmuch )
|
|||
int e;
|
||||
|
||||
EVUTIL_SET_SOCKET_ERROR( 0 );
|
||||
res = evbuffer_read( io->inbuf, io->socket, howmuch );
|
||||
res = evbuffer_read( io->inbuf, io->socket, (int)howmuch );
|
||||
e = EVUTIL_SOCKET_ERROR( );
|
||||
|
||||
dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(e):"") );
|
||||
|
|
|
@ -368,8 +368,8 @@ void tr_peerIoBandwidthUsed( tr_peerIo * io,
|
|||
size_t byteCount,
|
||||
int isPieceData );
|
||||
|
||||
static inline tr_bool tr_peerIoHasBandwidthLeft( const tr_peerIo * io,
|
||||
tr_direction dir )
|
||||
static inline tr_bool
|
||||
tr_peerIoHasBandwidthLeft( const tr_peerIo * io, tr_direction dir )
|
||||
{
|
||||
assert( tr_isPeerIo( io ) );
|
||||
|
||||
|
@ -377,12 +377,13 @@ static inline tr_bool tr_peerIoHasBandwidthLeft( const tr_peerIo * io,
|
|||
|| ( tr_bandwidthClamp( &io->bandwidth, dir, 1024 ) > 0 );
|
||||
}
|
||||
|
||||
static inline double tr_peerIoGetPieceSpeed( const tr_peerIo * io, uint64_t now, tr_direction dir )
|
||||
static inline unsigned int
|
||||
tr_peerIoGetPieceSpeed_Bps( const tr_peerIo * io, uint64_t now, tr_direction dir )
|
||||
{
|
||||
assert( tr_isPeerIo( io ) );
|
||||
assert( tr_isDirection( dir ) );
|
||||
|
||||
return tr_bandwidthGetPieceSpeed( &io->bandwidth, now, dir );
|
||||
return tr_bandwidthGetPieceSpeed_Bps( &io->bandwidth, now, dir );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2250,33 +2250,33 @@ tr_peerMgrTorrentStats( tr_torrent * tor,
|
|||
managerUnlock( t->manager );
|
||||
}
|
||||
|
||||
float
|
||||
tr_peerMgrGetWebseedSpeed( const tr_torrent * tor, uint64_t now )
|
||||
int
|
||||
tr_peerMgrGetWebseedSpeed_Bps( const tr_torrent * tor, uint64_t now )
|
||||
{
|
||||
int i;
|
||||
float tmp;
|
||||
float ret = 0;
|
||||
int tmp;
|
||||
int ret = 0;
|
||||
|
||||
const Torrent * t = tor->torrentPeers;
|
||||
const int n = tr_ptrArraySize( &t->webseeds );
|
||||
const tr_webseed ** webseeds = (const tr_webseed**) tr_ptrArrayBase( &t->webseeds );
|
||||
|
||||
for( i=0; i<n; ++i )
|
||||
if( tr_webseedGetSpeed( webseeds[i], now, &tmp ) )
|
||||
if( tr_webseedGetSpeed_Bps( webseeds[i], now, &tmp ) )
|
||||
ret += tmp;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
float*
|
||||
tr_peerMgrWebSpeeds( const tr_torrent * tor )
|
||||
int*
|
||||
tr_peerMgrWebSpeeds_Bps( const tr_torrent * tor )
|
||||
{
|
||||
const Torrent * t = tor->torrentPeers;
|
||||
const tr_webseed ** webseeds;
|
||||
int i;
|
||||
int webseedCount;
|
||||
float * ret;
|
||||
int * ret;
|
||||
uint64_t now;
|
||||
|
||||
assert( t->manager );
|
||||
|
@ -2285,21 +2285,21 @@ tr_peerMgrWebSpeeds( 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( float, webseedCount );
|
||||
ret = tr_new0( int, webseedCount );
|
||||
now = tr_date( );
|
||||
|
||||
for( i=0; i<webseedCount; ++i )
|
||||
if( !tr_webseedGetSpeed( webseeds[i], now, &ret[i] ) )
|
||||
if( !tr_webseedGetSpeed_Bps( webseeds[i], now, &ret[i] ) )
|
||||
ret[i] = -1.0;
|
||||
|
||||
managerUnlock( t->manager );
|
||||
return ret;
|
||||
}
|
||||
|
||||
double
|
||||
tr_peerGetPieceSpeed( const tr_peer * peer, uint64_t now, tr_direction direction )
|
||||
int
|
||||
tr_peerGetPieceSpeed_Bps( const tr_peer * peer, uint64_t now, tr_direction direction )
|
||||
{
|
||||
return peer->io ? tr_peerIoGetPieceSpeed( peer->io, now, direction ) : 0.0;
|
||||
return peer->io ? tr_peerIoGetPieceSpeed_Bps( peer->io, now, direction ) : 0.0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2336,8 +2336,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 = tr_peerGetPieceSpeed( peer, now, TR_CLIENT_TO_PEER );
|
||||
stat->rateToClient = tr_peerGetPieceSpeed( peer, now, TR_PEER_TO_CLIENT );
|
||||
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->peerIsChoked = peer->peerIsChoked;
|
||||
stat->peerIsInterested = peer->peerIsInterested;
|
||||
stat->clientIsChoked = peer->clientIsChoked;
|
||||
|
@ -2613,23 +2613,23 @@ isNew( const tr_peer * peer )
|
|||
static int
|
||||
getRate( const tr_torrent * tor, struct peer_atom * atom, uint64_t now )
|
||||
{
|
||||
double KiB_s;
|
||||
int Bps;
|
||||
|
||||
if( tr_torrentIsSeed( tor ) )
|
||||
KiB_s = tr_peerGetPieceSpeed( atom->peer, now, TR_CLIENT_TO_PEER );
|
||||
Bps = tr_peerGetPieceSpeed_Bps( atom->peer, now, TR_CLIENT_TO_PEER );
|
||||
|
||||
/* downloading a private torrent... take upload speed into account
|
||||
* because there may only be a small window of opportunity to share */
|
||||
else if( tr_torrentIsPrivate( tor ) )
|
||||
KiB_s = tr_peerGetPieceSpeed( atom->peer, now, TR_PEER_TO_CLIENT )
|
||||
+ tr_peerGetPieceSpeed( atom->peer, now, TR_CLIENT_TO_PEER );
|
||||
Bps = tr_peerGetPieceSpeed_Bps( atom->peer, now, TR_PEER_TO_CLIENT )
|
||||
+ tr_peerGetPieceSpeed_Bps( atom->peer, now, TR_CLIENT_TO_PEER );
|
||||
|
||||
/* downloading a public torrent */
|
||||
else
|
||||
KiB_s = tr_peerGetPieceSpeed( atom->peer, now, TR_PEER_TO_CLIENT );
|
||||
Bps = tr_peerGetPieceSpeed_Bps( atom->peer, now, TR_PEER_TO_CLIENT );
|
||||
|
||||
/* convert it to bytes per second */
|
||||
return (int)( KiB_s * 1024 );
|
||||
return Bps;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2995,8 +2995,8 @@ sortPeersByLivelinessImpl( tr_peer ** peers,
|
|||
l->doPurge = p->doPurge;
|
||||
l->pieceDataTime = p->atom->piece_data_time;
|
||||
l->time = p->atom->time;
|
||||
l->speed = 1024.0 * ( tr_peerGetPieceSpeed( p, now, TR_UP )
|
||||
+ tr_peerGetPieceSpeed( p, now, TR_DOWN ) );
|
||||
l->speed = tr_peerGetPieceSpeed_Bps( p, now, TR_UP )
|
||||
+ tr_peerGetPieceSpeed_Bps( p, now, TR_DOWN );
|
||||
if( clientData )
|
||||
l->clientData = clientData[i];
|
||||
}
|
||||
|
@ -3315,8 +3315,8 @@ isBandwidthMaxedOut( const tr_bandwidth * b,
|
|||
if( !tr_bandwidthIsLimited( b, dir ) )
|
||||
return FALSE;
|
||||
else {
|
||||
const double got = tr_bandwidthGetPieceSpeed( b, now_msec, dir );
|
||||
const double want = tr_bandwidthGetDesiredSpeed( b, dir );
|
||||
const int got = tr_bandwidthGetPieceSpeed_Bps( b, now_msec, dir );
|
||||
const int want = tr_bandwidthGetDesiredSpeed_Bps( b, dir );
|
||||
return got >= want;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -225,14 +225,14 @@ void tr_peerMgrTorrentStats( tr_torrent * tor,
|
|||
struct tr_peer_stat* tr_peerMgrPeerStats( const tr_torrent * tor,
|
||||
int * setmeCount );
|
||||
|
||||
float tr_peerMgrGetWebseedSpeed( const tr_torrent * tor, uint64_t now );
|
||||
int tr_peerMgrGetWebseedSpeed_Bps( const tr_torrent * tor, uint64_t now );
|
||||
|
||||
float* tr_peerMgrWebSpeeds( const tr_torrent * tor );
|
||||
int* tr_peerMgrWebSpeeds_Bps( const tr_torrent * tor );
|
||||
|
||||
|
||||
double tr_peerGetPieceSpeed( const tr_peer * peer,
|
||||
uint64_t now,
|
||||
tr_direction direction );
|
||||
int tr_peerGetPieceSpeed_Bps( const tr_peer * peer,
|
||||
uint64_t now,
|
||||
tr_direction direction );
|
||||
|
||||
/* @} */
|
||||
|
||||
|
|
|
@ -1700,26 +1700,26 @@ updateDesiredRequestCount( tr_peermsgs * msgs, uint64_t now )
|
|||
}
|
||||
else
|
||||
{
|
||||
int irate;
|
||||
int estimatedBlocksInPeriod;
|
||||
double rate;
|
||||
int rate_Bps;
|
||||
int irate_Bps;
|
||||
const int floor = 4;
|
||||
const int seconds = REQUEST_BUF_SECS;
|
||||
|
||||
/* Get the rate limit we should use.
|
||||
* FIXME: this needs to consider all the other peers as well... */
|
||||
rate = tr_peerGetPieceSpeed( msgs->peer, now, TR_PEER_TO_CLIENT );
|
||||
rate_Bps = tr_peerGetPieceSpeed_Bps( msgs->peer, now, TR_PEER_TO_CLIENT );
|
||||
if( tr_torrentUsesSpeedLimit( torrent, TR_PEER_TO_CLIENT ) )
|
||||
rate = MIN( rate, tr_torrentGetSpeedLimit( torrent, TR_PEER_TO_CLIENT ) );
|
||||
rate_Bps = MIN( rate_Bps, tr_torrentGetSpeedLimit_Bps( torrent, TR_PEER_TO_CLIENT ) );
|
||||
|
||||
/* honor the session limits, if enabled */
|
||||
if( tr_torrentUsesSessionLimits( torrent ) )
|
||||
if( tr_sessionGetActiveSpeedLimit( torrent->session, TR_PEER_TO_CLIENT, &irate ) )
|
||||
rate = MIN( rate, irate );
|
||||
if( tr_sessionGetActiveSpeedLimit_Bps( torrent->session, TR_PEER_TO_CLIENT, &irate_Bps ) )
|
||||
rate_Bps = MIN( rate_Bps, irate_Bps );
|
||||
|
||||
/* use this desired rate to figure out how
|
||||
* many requests we should send to this peer */
|
||||
estimatedBlocksInPeriod = ( rate * seconds * 1024 ) / torrent->blockSize;
|
||||
estimatedBlocksInPeriod = ( rate_Bps * seconds ) / torrent->blockSize;
|
||||
msgs->desiredRequestCount = MAX( floor, estimatedBlocksInPeriod );
|
||||
|
||||
/* honor the peer's maximum request count, if specified */
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "utils.h"
|
||||
|
||||
/* return the xfer rate over the last `interval' seconds in KiB/sec */
|
||||
static float
|
||||
static int
|
||||
rateForInterval( const tr_ratecontrol * r,
|
||||
int interval_msec,
|
||||
uint64_t now )
|
||||
|
@ -50,17 +50,17 @@ rateForInterval( const tr_ratecontrol * r,
|
|||
if( i == r->newest ) break; /* we've come all the way around */
|
||||
}
|
||||
|
||||
return ( bytes / 1024.0 ) * ( 1000.0 / interval_msec );
|
||||
return bytes * ( 1000.0 / interval_msec );
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
float
|
||||
tr_rcRate( const tr_ratecontrol * r, uint64_t now )
|
||||
int
|
||||
tr_rcRate_Bps( const tr_ratecontrol * r, uint64_t now )
|
||||
{
|
||||
float ret = 0.0f;
|
||||
int ret = 0;
|
||||
|
||||
if( r )
|
||||
ret = rateForInterval( r, TR_RC_HISTORY_MSEC, now );
|
||||
|
|
|
@ -70,8 +70,8 @@ static inline void tr_rcDestruct ( tr_ratecontrol * rc ) { memset( rc, 0xDEAD,
|
|||
void tr_rcTransferred ( tr_ratecontrol * ratecontrol,
|
||||
size_t byteCount );
|
||||
|
||||
float tr_rcRate ( const tr_ratecontrol * ratecontrol,
|
||||
uint64_t now );
|
||||
int tr_rcRate_Bps ( const tr_ratecontrol * ratecontrol,
|
||||
uint64_t now );
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -46,7 +46,8 @@
|
|||
#define KEY_RATIOLIMIT "ratio-limit"
|
||||
#define KEY_UPLOADED "uploaded"
|
||||
|
||||
#define KEY_SPEED "speed"
|
||||
#define KEY_SPEED_KiBps "speed"
|
||||
#define KEY_SPEED_Bps "speed-Bps"
|
||||
#define KEY_USE_GLOBAL_SPEED_LIMIT "use-global-speed-limit"
|
||||
#define KEY_USE_SPEED_LIMIT "use-speed-limit"
|
||||
#define KEY_SPEEDLIMIT_DOWN_SPEED "down-speed"
|
||||
|
@ -269,7 +270,7 @@ static void
|
|||
saveSingleSpeedLimit( tr_benc * d, const tr_torrent * tor, tr_direction dir )
|
||||
{
|
||||
tr_bencDictReserve( d, 3 );
|
||||
tr_bencDictAddInt( d, KEY_SPEED, tr_torrentGetSpeedLimit( tor, dir ) );
|
||||
tr_bencDictAddInt( d, KEY_SPEED_Bps, tr_torrentGetSpeedLimit_Bps( tor, dir ) );
|
||||
tr_bencDictAddBool( d, KEY_USE_GLOBAL_SPEED_LIMIT, tr_torrentUsesSessionLimits( tor ) );
|
||||
tr_bencDictAddBool( d, KEY_USE_SPEED_LIMIT, tr_torrentUsesSpeedLimit( tor, dir ) );
|
||||
}
|
||||
|
@ -295,8 +296,10 @@ loadSingleSpeedLimit( tr_benc * d, tr_direction dir, tr_torrent * tor )
|
|||
int64_t i;
|
||||
tr_bool boolVal;
|
||||
|
||||
if( tr_bencDictFindInt( d, KEY_SPEED, &i ) )
|
||||
tr_torrentSetSpeedLimit( tor, dir, i );
|
||||
if( tr_bencDictFindInt( d, KEY_SPEED_Bps, &i ) )
|
||||
tr_torrentSetSpeedLimit_Bps( tor, dir, i );
|
||||
else if( tr_bencDictFindInt( d, KEY_SPEED_KiBps, &i ) )
|
||||
tr_torrentSetSpeedLimit_Bps( tor, dir, i*1024 );
|
||||
|
||||
if( tr_bencDictFindBool( d, KEY_USE_SPEED_LIMIT, &boolVal ) )
|
||||
tr_torrentUseSpeedLimit( tor, dir, boolVal );
|
||||
|
@ -334,13 +337,13 @@ loadSpeedLimits( tr_benc * dict, tr_torrent * tor )
|
|||
|
||||
int64_t i;
|
||||
if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_DOWN_SPEED, &i ) )
|
||||
tr_torrentSetSpeedLimit( tor, TR_DOWN, i );
|
||||
tr_torrentSetSpeedLimit_Bps( tor, TR_DOWN, i*1024 );
|
||||
if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_DOWN_MODE, &i ) ) {
|
||||
tr_torrentUseSpeedLimit( tor, TR_DOWN, i==TR_SPEEDLIMIT_SINGLE );
|
||||
tr_torrentUseSessionLimits( tor, i==TR_SPEEDLIMIT_GLOBAL );
|
||||
}
|
||||
if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_UP_SPEED, &i ) )
|
||||
tr_torrentSetSpeedLimit( tor, TR_UP, i );
|
||||
tr_torrentSetSpeedLimit_Bps( tor, TR_UP, i*1024 );
|
||||
if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_UP_MODE, &i ) ) {
|
||||
tr_torrentUseSpeedLimit( tor, TR_UP, i==TR_SPEEDLIMIT_SINGLE );
|
||||
tr_torrentUseSessionLimits( tor, i==TR_SPEEDLIMIT_GLOBAL );
|
||||
|
|
|
@ -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", (int)( peer->rateToClient * 1024.0 ) );
|
||||
tr_bencDictAddInt ( d, "rateToPeer", (int)( peer->rateToPeer * 1024.0 ) );
|
||||
tr_bencDictAddInt ( d, "rateToClient", peer->rateToClient_Bps );
|
||||
tr_bencDictAddInt ( d, "rateToPeer", peer->rateToPeer_Bps );
|
||||
}
|
||||
|
||||
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( tor, TR_DOWN ) );
|
||||
tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit_Bps( 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, (int)( st->pieceDownloadSpeed * 1024 ) );
|
||||
tr_bencDictAddInt( d, key, st->pieceDownloadSpeed_Bps );
|
||||
else if( tr_streq( key, keylen, "rateUpload" ) )
|
||||
tr_bencDictAddInt( d, key, (int)( st->pieceUploadSpeed * 1024 ) );
|
||||
tr_bencDictAddInt( d, key, st->pieceUploadSpeed_Bps );
|
||||
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( tor, TR_UP ) );
|
||||
tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit_Bps( 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( tor, TR_DOWN, tmp );
|
||||
tr_torrentSetSpeedLimit_Bps( 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( tor, TR_UP, tmp );
|
||||
tr_torrentSetSpeedLimit_Bps( 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_bencDictFindReal( args_in, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, &d ) )
|
||||
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, &i ) )
|
||||
tr_sessionSetAltSpeed( session, TR_UP, i );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_DOWN, &i ) )
|
||||
tr_sessionSetAltSpeed( session, TR_DOWN, i );
|
||||
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_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, &i ) )
|
||||
tr_sessionSetSpeedLimit( session, TR_DOWN, i );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_DSPEED_Bps, &i ) )
|
||||
tr_sessionSetSpeedLimit_Bps( 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, &i ) )
|
||||
tr_sessionSetSpeedLimit( session, TR_UP, i );
|
||||
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_USPEED_Bps, &i ) )
|
||||
tr_sessionSetSpeedLimit_Bps( 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 ) ) {
|
||||
|
@ -1508,10 +1508,10 @@ sessionStats( tr_session * session,
|
|||
tr_sessionGetCumulativeStats( session, &cumulativeStats );
|
||||
|
||||
tr_bencDictAddInt( args_out, "activeTorrentCount", running );
|
||||
tr_bencDictAddInt( args_out, "downloadSpeed", (int)( tr_sessionGetPieceSpeed( session, TR_DOWN ) * 1024 ) );
|
||||
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", (int)( tr_sessionGetPieceSpeed( session, TR_UP ) * 1024 ) );
|
||||
tr_bencDictAddInt( args_out, "uploadSpeed", tr_sessionGetPieceSpeed_Bps( 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, tr_sessionGetAltSpeed(s,TR_UP) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN, tr_sessionGetAltSpeed(s,TR_DOWN) );
|
||||
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_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_MiB, tr_sessionGetCacheLimit( s ) );
|
||||
tr_bencDictAddReal( d, TR_PREFS_KEY_MAX_CACHE_SIZE, tr_sessionGetCacheLimit( 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, tr_sessionGetSpeedLimit( s, TR_UP ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_Bps, tr_sessionGetSpeedLimit_Bps( s, TR_UP ) );
|
||||
tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, tr_sessionIsSpeedLimited( s, TR_UP ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED, tr_sessionGetSpeedLimit( s, TR_DOWN ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_Bps, tr_sessionGetSpeedLimit_Bps( 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 ) );
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <event.h>
|
||||
|
||||
//#define TR_SHOW_DEPRECATED
|
||||
#include "transmission.h"
|
||||
#include "announcer.h"
|
||||
#include "bandwidth.h"
|
||||
|
@ -54,7 +55,7 @@ enum
|
|||
{
|
||||
SAVE_INTERVAL_SECS = 120,
|
||||
|
||||
DEFAULT_CACHE_SIZE_MiB = 2 /* 2 MiB */
|
||||
DEFAULT_CACHE_SIZE_BYTES = ( 2 * 1024 * 1024 ) /* 2 MiB */
|
||||
};
|
||||
|
||||
|
||||
|
@ -240,18 +241,44 @@ 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_bencDictAddReal( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, DEFAULT_CACHE_SIZE_MiB );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAX_CACHE_SIZE, DEFAULT_CACHE_SIZE_BYTES );
|
||||
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, 100 );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_Bps, 100 * speed_K );
|
||||
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( ) );
|
||||
|
@ -290,13 +317,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, 50 ); /* half the regular */
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN, 50 ); /* half the regular */
|
||||
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_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, 100 );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_Bps, 100 * speed_K );
|
||||
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 );
|
||||
|
@ -313,11 +340,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_bencDictAddReal( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, tr_cacheGetLimit( s->cache ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAX_CACHE_SIZE, 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, tr_sessionGetSpeedLimit( s, TR_DOWN ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_Bps, tr_sessionGetSpeedLimit_Bps( 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 ) );
|
||||
|
@ -358,13 +385,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, tr_sessionGetAltSpeed( s, TR_UP ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN, tr_sessionGetAltSpeed( s, TR_DOWN ) );
|
||||
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_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, tr_sessionGetSpeedLimit( s, TR_UP ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_Bps, tr_sessionGetSpeedLimit_Bps( 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 );
|
||||
|
@ -511,7 +538,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_MiB );
|
||||
session->cache = tr_cacheNew( DEFAULT_CACHE_SIZE_BYTES );
|
||||
session->tag = tr_strdup( tag );
|
||||
session->magicNumber = SESSION_MAGIC_NUMBER;
|
||||
session->buffer = tr_valloc( SESSION_BUFFER_SIZE );
|
||||
|
@ -677,8 +704,8 @@ sessionSetImpl( void * vdata )
|
|||
}
|
||||
|
||||
/* misc features */
|
||||
if( tr_bencDictFindReal( settings, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, &d ) )
|
||||
tr_sessionSetCacheLimit( session, d );
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_MAX_CACHE_SIZE, &i ) )
|
||||
tr_sessionSetCacheLimit( 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 ) )
|
||||
|
@ -778,13 +805,13 @@ sessionSetImpl( void * vdata )
|
|||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, &i ) )
|
||||
session->uploadSlotsPerTorrent = i;
|
||||
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_USPEED, &i ) )
|
||||
tr_sessionSetSpeedLimit( session, TR_UP, i );
|
||||
if( getSpeedFromDict( settings, "speed-limit-up", &i ) )
|
||||
tr_sessionSetSpeedLimit_Bps( session, TR_UP, i );
|
||||
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_USPEED_ENABLED, &boolVal ) )
|
||||
tr_sessionLimitSpeed( session, TR_UP, boolVal );
|
||||
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_DSPEED, &i ) )
|
||||
tr_sessionSetSpeedLimit( session, TR_DOWN, i );
|
||||
if( getSpeedFromDict( settings, "speed-limit-down", &i ) )
|
||||
tr_sessionSetSpeedLimit_Bps( session, TR_DOWN, i );
|
||||
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_DSPEED_ENABLED, &boolVal ) )
|
||||
tr_sessionLimitSpeed( session, TR_DOWN, boolVal );
|
||||
|
||||
|
@ -798,10 +825,10 @@ sessionSetImpl( void * vdata )
|
|||
**/
|
||||
|
||||
/* update the turtle mode's fields */
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_UP, &i ) )
|
||||
turtle->speedLimit[TR_UP] = i;
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_DOWN, &i ) )
|
||||
turtle->speedLimit[TR_DOWN] = i;
|
||||
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_TIME_BEGIN, &i ) )
|
||||
turtle->beginMinute = i;
|
||||
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_TIME_END, &i ) )
|
||||
|
@ -1100,7 +1127,7 @@ tr_sessionGetRatioLimit( const tr_session * session )
|
|||
***/
|
||||
|
||||
tr_bool
|
||||
tr_sessionGetActiveSpeedLimit( const tr_session * session, tr_direction dir, int * setme )
|
||||
tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session, tr_direction dir, int * setme )
|
||||
{
|
||||
int isLimited = TRUE;
|
||||
|
||||
|
@ -1108,9 +1135,9 @@ tr_sessionGetActiveSpeedLimit( const tr_session * session, tr_direction dir, int
|
|||
return FALSE;
|
||||
|
||||
if( tr_sessionUsesAltSpeed( session ) )
|
||||
*setme = tr_sessionGetAltSpeed( session, dir );
|
||||
*setme = tr_sessionGetAltSpeed_Bps( session, dir );
|
||||
else if( tr_sessionIsSpeedLimited( session, dir ) )
|
||||
*setme = tr_sessionGetSpeedLimit( session, dir );
|
||||
*setme = tr_sessionGetSpeedLimit_Bps( session, dir );
|
||||
else
|
||||
isLimited = FALSE;
|
||||
|
||||
|
@ -1120,13 +1147,13 @@ tr_sessionGetActiveSpeedLimit( const tr_session * session, tr_direction dir, int
|
|||
static void
|
||||
updateBandwidth( tr_session * session, tr_direction dir )
|
||||
{
|
||||
int limit = 0;
|
||||
const tr_bool isLimited = tr_sessionGetActiveSpeedLimit( session, dir, &limit );
|
||||
const tr_bool zeroCase = isLimited && !limit;
|
||||
int limit_Bps = 0;
|
||||
const tr_bool isLimited = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &limit_Bps );
|
||||
const tr_bool zeroCase = isLimited && !limit_Bps;
|
||||
|
||||
tr_bandwidthSetLimited( session->bandwidth, dir, isLimited && !zeroCase );
|
||||
|
||||
tr_bandwidthSetDesiredSpeed( session->bandwidth, dir, limit );
|
||||
tr_bandwidthSetDesiredSpeed_Bps( session->bandwidth, dir, limit_Bps );
|
||||
}
|
||||
|
||||
enum
|
||||
|
@ -1267,24 +1294,24 @@ turtleBootstrap( tr_session * session, struct tr_turtle_info * turtle )
|
|||
***/
|
||||
|
||||
void
|
||||
tr_sessionSetSpeedLimit( tr_session * s, tr_direction d, int KB_s )
|
||||
tr_sessionSetSpeedLimit_Bps( tr_session * s, tr_direction d, int Bps )
|
||||
{
|
||||
assert( tr_isSession( s ) );
|
||||
assert( tr_isDirection( d ) );
|
||||
assert( KB_s >= 0 );
|
||||
assert( Bps >= 0 );
|
||||
|
||||
s->speedLimit[d] = KB_s;
|
||||
s->speedLimit_Bps[d] = Bps;
|
||||
|
||||
updateBandwidth( s, d );
|
||||
}
|
||||
|
||||
int
|
||||
tr_sessionGetSpeedLimit( const tr_session * s, tr_direction d )
|
||||
tr_sessionGetSpeedLimit_Bps( const tr_session * s, tr_direction d )
|
||||
{
|
||||
assert( tr_isSession( s ) );
|
||||
assert( tr_isDirection( d ) );
|
||||
|
||||
return s->speedLimit[d];
|
||||
return s->speedLimit_Bps[d];
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1313,24 +1340,24 @@ tr_sessionIsSpeedLimited( const tr_session * s, tr_direction d )
|
|||
***/
|
||||
|
||||
void
|
||||
tr_sessionSetAltSpeed( tr_session * s, tr_direction d, int KB_s )
|
||||
tr_sessionSetAltSpeed_Bps( tr_session * s, tr_direction d, int Bps )
|
||||
{
|
||||
assert( tr_isSession( s ) );
|
||||
assert( tr_isDirection( d ) );
|
||||
assert( KB_s >= 0 );
|
||||
assert( Bps >= 0 );
|
||||
|
||||
s->turtle.speedLimit[d] = KB_s;
|
||||
s->turtle.speedLimit_Bps[d] = Bps;
|
||||
|
||||
updateBandwidth( s, d );
|
||||
}
|
||||
|
||||
int
|
||||
tr_sessionGetAltSpeed( const tr_session * s, tr_direction d )
|
||||
tr_sessionGetAltSpeed_Bps( const tr_session * s, tr_direction d )
|
||||
{
|
||||
assert( tr_isSession( s ) );
|
||||
assert( tr_isDirection( d ) );
|
||||
|
||||
return s->turtle.speedLimit[d];
|
||||
return s->turtle.speedLimit_Bps[d];
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1536,16 +1563,16 @@ tr_sessionGetDeleteSource( const tr_session * session )
|
|||
****
|
||||
***/
|
||||
|
||||
double
|
||||
tr_sessionGetPieceSpeed( const tr_session * session, tr_direction dir )
|
||||
int
|
||||
tr_sessionGetPieceSpeed_Bps( const tr_session * session, tr_direction dir )
|
||||
{
|
||||
return tr_isSession( session ) ? tr_bandwidthGetPieceSpeed( session->bandwidth, 0, dir ) : 0.0;
|
||||
return tr_isSession( session ) ? tr_bandwidthGetPieceSpeed_Bps( session->bandwidth, 0, dir ) : 0.0;
|
||||
}
|
||||
|
||||
double
|
||||
tr_sessionGetRawSpeed( const tr_session * session, tr_direction dir )
|
||||
int
|
||||
tr_sessionGetRawSpeed_Bps( const tr_session * session, tr_direction dir )
|
||||
{
|
||||
return tr_isSession( session ) ? tr_bandwidthGetRawSpeed( session->bandwidth, 0, dir ) : 0.0;
|
||||
return tr_isSession( session ) ? tr_bandwidthGetRawSpeed_Bps( session->bandwidth, 0, dir ) : 0.0;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -1849,14 +1876,14 @@ tr_sessionAllowsLPD( const tr_session * session )
|
|||
***/
|
||||
|
||||
void
|
||||
tr_sessionSetCacheLimit( tr_session * session, double maxMiB )
|
||||
tr_sessionSetCacheLimit( tr_session * session, int64_t max_bytes )
|
||||
{
|
||||
assert( tr_isSession( session ) );
|
||||
|
||||
tr_cacheSetLimit( session->cache, maxMiB );
|
||||
tr_cacheSetLimit( session->cache, max_bytes );
|
||||
}
|
||||
|
||||
double
|
||||
int64_t
|
||||
tr_sessionGetCacheLimit( const tr_session * session )
|
||||
{
|
||||
assert( tr_isSession( session ) );
|
||||
|
|
|
@ -46,7 +46,7 @@ struct tr_fdInfo;
|
|||
struct tr_turtle_info
|
||||
{
|
||||
/* TR_UP and TR_DOWN speed limits */
|
||||
int speedLimit[2];
|
||||
int speedLimit_Bps[2];
|
||||
|
||||
/* is turtle mode on right now? */
|
||||
tr_bool isEnabled;
|
||||
|
@ -102,7 +102,7 @@ struct tr_session
|
|||
|
||||
int umask;
|
||||
|
||||
int speedLimit[2];
|
||||
int speedLimit_Bps[2];
|
||||
tr_bool speedLimitEnabled[2];
|
||||
|
||||
struct tr_turtle_info turtle;
|
||||
|
|
|
@ -129,22 +129,23 @@ tr_torrentFindFromObfuscatedHash( tr_session * session,
|
|||
***/
|
||||
|
||||
void
|
||||
tr_torrentSetSpeedLimit( tr_torrent * tor, tr_direction dir, int KiB_sec )
|
||||
tr_torrentSetSpeedLimit_Bps( tr_torrent * tor, tr_direction dir, int Bps )
|
||||
{
|
||||
assert( tr_isTorrent( tor ) );
|
||||
assert( tr_isDirection( dir ) );
|
||||
assert( Bps >= 0 );
|
||||
|
||||
if( tr_bandwidthSetDesiredSpeed( tor->bandwidth, dir, KiB_sec ) )
|
||||
if( tr_bandwidthSetDesiredSpeed_Bps( tor->bandwidth, dir, Bps ) )
|
||||
tr_torrentSetDirty( tor );
|
||||
}
|
||||
|
||||
int
|
||||
tr_torrentGetSpeedLimit( const tr_torrent * tor, tr_direction dir )
|
||||
tr_torrentGetSpeedLimit_Bps( const tr_torrent * tor, tr_direction dir )
|
||||
{
|
||||
assert( tr_isTorrent( tor ) );
|
||||
assert( tr_isDirection( dir ) );
|
||||
|
||||
return tr_bandwidthGetDesiredSpeed( tor->bandwidth, dir );
|
||||
return tr_bandwidthGetDesiredSpeed_Bps( tor->bandwidth, dir );
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -243,11 +244,11 @@ tr_torrentIsPieceTransferAllowed( const tr_torrent * tor,
|
|||
tr_bool allowed = TRUE;
|
||||
|
||||
if( tr_torrentUsesSpeedLimit( tor, direction ) )
|
||||
if( tr_torrentGetSpeedLimit( tor, direction ) <= 0 )
|
||||
if( tr_torrentGetSpeedLimit_Bps( tor, direction ) <= 0 )
|
||||
allowed = FALSE;
|
||||
|
||||
if( tr_torrentUsesSessionLimits( tor ) )
|
||||
if( tr_sessionGetActiveSpeedLimit( tor->session, direction, &limit ) )
|
||||
if( tr_sessionGetActiveSpeedLimit_Bps( tor->session, direction, &limit ) )
|
||||
if( limit <= 0 )
|
||||
allowed = FALSE;
|
||||
|
||||
|
@ -685,9 +686,9 @@ torrentInit( tr_torrent * tor, const tr_ctor * ctor )
|
|||
if( !( loaded & TR_FR_SPEEDLIMIT ) )
|
||||
{
|
||||
tr_torrentUseSpeedLimit( tor, TR_UP, FALSE );
|
||||
tr_torrentSetSpeedLimit( tor, TR_UP, tr_sessionGetSpeedLimit( tor->session, TR_UP ) );
|
||||
tr_torrentSetSpeedLimit_Bps( tor, TR_UP, tr_sessionGetSpeedLimit_Bps( tor->session, TR_UP ) );
|
||||
tr_torrentUseSpeedLimit( tor, TR_DOWN, FALSE );
|
||||
tr_torrentSetSpeedLimit( tor, TR_DOWN, tr_sessionGetSpeedLimit( tor->session, TR_DOWN ) );
|
||||
tr_torrentSetSpeedLimit_Bps( tor, TR_DOWN, tr_sessionGetSpeedLimit_Bps( tor->session, TR_DOWN ) );
|
||||
tr_torrentUseSessionLimits( tor, TRUE );
|
||||
}
|
||||
|
||||
|
@ -966,11 +967,11 @@ tr_torrentStat( tr_torrent * tor )
|
|||
s->peersFrom );
|
||||
|
||||
now = tr_date( );
|
||||
d = tr_peerMgrGetWebseedSpeed( tor, now );
|
||||
s->rawUploadSpeed = tr_bandwidthGetRawSpeed ( tor->bandwidth, now, TR_UP );
|
||||
s->pieceUploadSpeed = tr_bandwidthGetPieceSpeed( tor->bandwidth, now, TR_UP );
|
||||
s->rawDownloadSpeed = d + tr_bandwidthGetRawSpeed ( tor->bandwidth, now, TR_DOWN );
|
||||
s->pieceDownloadSpeed = d + tr_bandwidthGetPieceSpeed( tor->bandwidth, now, TR_DOWN );
|
||||
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 );
|
||||
|
||||
usableSeeds += tor->info.webseedCount;
|
||||
|
||||
|
@ -1031,18 +1032,18 @@ tr_torrentStat( tr_torrent * tor )
|
|||
|
||||
case TR_STATUS_DOWNLOAD:
|
||||
if( ( tor->etaDLSpeedCalculatedAt + 800 ) < now ) {
|
||||
tor->etaDLSpeed = ( ( tor->etaDLSpeedCalculatedAt + 4000 ) < now )
|
||||
? s->pieceDownloadSpeed /* if no recent previous speed, no need to smooth */
|
||||
: 0.8*tor->etaDLSpeed + 0.2*s->pieceDownloadSpeed; /* smooth across 5 readings */
|
||||
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->etaDLSpeedCalculatedAt = now;
|
||||
}
|
||||
|
||||
if( s->leftUntilDone > s->desiredAvailable )
|
||||
s->eta = TR_ETA_NOT_AVAIL;
|
||||
else if( s->pieceDownloadSpeed < 0.1 )
|
||||
else if( s->pieceDownloadSpeed_Bps < 1 )
|
||||
s->eta = TR_ETA_UNKNOWN;
|
||||
else
|
||||
s->eta = s->leftUntilDone / tor->etaDLSpeed / 1024.0;
|
||||
s->eta = s->leftUntilDone / tor->etaDLSpeed_Bps;
|
||||
break;
|
||||
|
||||
case TR_STATUS_SEED: {
|
||||
|
@ -1050,15 +1051,15 @@ tr_torrentStat( tr_torrent * tor )
|
|||
s->eta = TR_ETA_NOT_AVAIL;
|
||||
else {
|
||||
if( ( tor->etaULSpeedCalculatedAt + 800 ) < now ) {
|
||||
tor->etaULSpeed = ( ( tor->etaULSpeedCalculatedAt + 4000 ) < now )
|
||||
? s->pieceUploadSpeed /* if no recent previous speed, no need to smooth */
|
||||
: 0.8*tor->etaULSpeed + 0.2*s->pieceUploadSpeed; /* smooth across 5 readings */
|
||||
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->etaULSpeedCalculatedAt = now;
|
||||
}
|
||||
if( s->pieceUploadSpeed < 0.1 )
|
||||
if( s->pieceUploadSpeed_Bps < 1 )
|
||||
s->eta = TR_ETA_UNKNOWN;
|
||||
else
|
||||
s->eta = seedRatioBytesLeft / tor->etaULSpeed / 1024.0;
|
||||
s->eta = seedRatioBytesLeft / tor->etaULSpeed_Bps;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1192,12 +1193,10 @@ tr_torrentFilesFree( tr_file_stat * files,
|
|||
****
|
||||
***/
|
||||
|
||||
float*
|
||||
tr_torrentWebSpeeds( const tr_torrent * tor )
|
||||
int*
|
||||
tr_torrentWebSpeeds_Bps( const tr_torrent * tor )
|
||||
{
|
||||
return tr_isTorrent( tor )
|
||||
? tr_peerMgrWebSpeeds( tor )
|
||||
: NULL;
|
||||
return tr_isTorrent( tor ) ? tr_peerMgrWebSpeeds_Bps( tor ) : NULL;
|
||||
}
|
||||
|
||||
tr_peer_stat *
|
||||
|
|
|
@ -210,9 +210,9 @@ struct tr_torrent
|
|||
uint64_t corruptPrev;
|
||||
|
||||
uint64_t etaDLSpeedCalculatedAt;
|
||||
double etaDLSpeed;
|
||||
int etaDLSpeed_Bps;
|
||||
uint64_t etaULSpeedCalculatedAt;
|
||||
double etaULSpeed;
|
||||
int etaULSpeed_Bps;
|
||||
|
||||
time_t addedDate;
|
||||
time_t activityDate;
|
||||
|
|
|
@ -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 "alt-speed-up"
|
||||
#define TR_PREFS_KEY_ALT_SPEED_DOWN "alt-speed-down"
|
||||
#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_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_MiB "cache-size-MiB"
|
||||
#define TR_PREFS_KEY_MAX_CACHE_SIZE "cache-size-bytes"
|
||||
#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,10 +206,10 @@ 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 "speed-limit-down"
|
||||
#define TR_PREFS_KEY_DSPEED_Bps "speed-limit-down-Bps"
|
||||
#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_ENABLED "speed-limit-up-enabled"
|
||||
#define TR_PREFS_KEY_USPEED "speed-limit-up"
|
||||
#define TR_PREFS_KEY_UMASK "umask"
|
||||
#define TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT "upload-slots-per-torrent"
|
||||
#define TR_PREFS_KEY_START "start-added-torrents"
|
||||
|
@ -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, double MiB );
|
||||
double tr_sessionGetCacheLimit( const tr_session * session );
|
||||
void tr_sessionSetCacheLimit( tr_session * session, int64_t bytes );
|
||||
int64_t tr_sessionGetCacheLimit( 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 ( tr_session *, tr_direction, int KB_s );
|
||||
int tr_sessionGetSpeedLimit ( const tr_session *, tr_direction );
|
||||
void tr_sessionSetSpeedLimit_Bps( tr_session *, tr_direction, int Bps );
|
||||
int tr_sessionGetSpeedLimit_Bps( 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 ( tr_session *, tr_direction, int KB_s );
|
||||
int tr_sessionGetAltSpeed ( const tr_session *, tr_direction );
|
||||
void tr_sessionSetAltSpeed_Bps( tr_session *, tr_direction, int Bps );
|
||||
int tr_sessionGetAltSpeed_Bps( const tr_session *, tr_direction );
|
||||
|
||||
void tr_sessionUseAltSpeed ( tr_session *, tr_bool );
|
||||
tr_bool tr_sessionUsesAltSpeed ( const tr_session * );
|
||||
|
@ -706,18 +706,16 @@ void tr_sessionClearAltSpeedFunc ( tr_session * );
|
|||
void tr_sessionSetAltSpeedFunc ( tr_session *, tr_altSpeedFunc *, void * );
|
||||
|
||||
|
||||
tr_bool tr_sessionGetActiveSpeedLimit( const tr_session * session,
|
||||
tr_bool tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session,
|
||||
tr_direction dir,
|
||||
int * setme );
|
||||
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
double tr_sessionGetRawSpeed ( const tr_session *, tr_direction );
|
||||
double tr_sessionGetPieceSpeed ( 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_sessionSetRatioLimited ( tr_session *, tr_bool isLimited );
|
||||
tr_bool tr_sessionIsRatioLimited ( const tr_session * );
|
||||
|
@ -1126,8 +1124,8 @@ char* tr_torrentFindFile( const tr_torrent * tor, tr_file_index_t fileNo );
|
|||
****
|
||||
***/
|
||||
|
||||
void tr_torrentSetSpeedLimit ( tr_torrent *, tr_direction, int KB_s );
|
||||
int tr_torrentGetSpeedLimit ( const tr_torrent *, tr_direction );
|
||||
void tr_torrentSetSpeedLimit_Bps ( tr_torrent *, tr_direction, int KB_s );
|
||||
int tr_torrentGetSpeedLimit_Bps ( const tr_torrent *, tr_direction );
|
||||
|
||||
void tr_torrentUseSpeedLimit ( tr_torrent *, tr_direction, tr_bool );
|
||||
tr_bool tr_torrentUsesSpeedLimit ( const tr_torrent *, tr_direction );
|
||||
|
@ -1382,8 +1380,8 @@ typedef struct tr_peer_stat
|
|||
char flagStr[32];
|
||||
|
||||
float progress;
|
||||
float rateToPeer;
|
||||
float rateToClient;
|
||||
int rateToPeer_Bps;
|
||||
int rateToClient_Bps;
|
||||
|
||||
|
||||
/***
|
||||
|
@ -1546,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.
|
||||
*/
|
||||
float* tr_torrentWebSpeeds( const tr_torrent * torrent );
|
||||
int* tr_torrentWebSpeeds_Bps( const tr_torrent * torrent );
|
||||
|
||||
typedef struct tr_file_stat
|
||||
{
|
||||
|
@ -1746,21 +1744,21 @@ typedef struct tr_stat
|
|||
Range is [0..1] */
|
||||
double seedRatioPercentDone;
|
||||
|
||||
/** Speed all data being sent for this torrent. (KiB/s)
|
||||
/** Speed all data being sent for this torrent.
|
||||
This includes piece data, protocol messages, and TCP overhead */
|
||||
double rawUploadSpeed;
|
||||
int rawUploadSpeed_Bps;
|
||||
|
||||
/** Speed all data being received for this torrent. (KiB/s)
|
||||
/** Speed all data being received for this torrent.
|
||||
This includes piece data, protocol messages, and TCP overhead */
|
||||
double rawDownloadSpeed;
|
||||
int rawDownloadSpeed_Bps;
|
||||
|
||||
/** Speed all piece being sent for this torrent. (KiB/s)
|
||||
/** Speed all piece being sent for this torrent.
|
||||
This ONLY counts piece data. */
|
||||
double pieceUploadSpeed;
|
||||
int pieceUploadSpeed_Bps;
|
||||
|
||||
/** Speed all piece being received for this torrent. (KiB/s)
|
||||
/** Speed all piece being received for this torrent.
|
||||
This ONLY counts piece data. */
|
||||
double pieceDownloadSpeed;
|
||||
int pieceDownloadSpeed_Bps;
|
||||
|
||||
#define TR_ETA_NOT_AVAIL -1
|
||||
#define TR_ETA_UNKNOWN -2
|
||||
|
|
|
@ -327,11 +327,11 @@ test_array( void )
|
|||
int array[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
int n = sizeof( array ) / sizeof( array[0] );
|
||||
|
||||
tr_removeElementFromArray( array, 5, sizeof( int ), n-- );
|
||||
tr_removeElementFromArray( array, 5u, sizeof( int ), n-- );
|
||||
for( i=0; i<n; ++i )
|
||||
check( array[i] == ( i<5 ? i : i+1 ) );
|
||||
|
||||
tr_removeElementFromArray( array, 0, sizeof( int ), n-- );
|
||||
tr_removeElementFromArray( array, 0u, sizeof( int ), n-- );
|
||||
for( i=0; i<n; ++i )
|
||||
check( array[i] == ( i<4 ? i+1 : i+2 ) );
|
||||
|
||||
|
|
|
@ -1065,7 +1065,7 @@ tr_base64_encode( const void * input, int length, int * setme_len )
|
|||
BUF_MEM * bptr;
|
||||
|
||||
if( length < 1 )
|
||||
length = strlen( input );
|
||||
length = (int)strlen( input );
|
||||
|
||||
bmem = BIO_new( BIO_s_mem( ) );
|
||||
b64 = BIO_new( BIO_f_base64( ) );
|
||||
|
@ -1469,7 +1469,7 @@ tr_valloc( size_t bufLen )
|
|||
|
||||
if( !pageSize ) {
|
||||
#ifdef HAVE_GETPAGESIZE
|
||||
pageSize = getpagesize();
|
||||
pageSize = (size_t) getpagesize();
|
||||
#else /* guess */
|
||||
pageSize = 4096;
|
||||
#endif
|
||||
|
@ -1516,7 +1516,7 @@ tr_realpath( const char * path, char * resolved_path )
|
|||
struct formatter_unit
|
||||
{
|
||||
char * name;
|
||||
double value;
|
||||
unsigned int value;
|
||||
};
|
||||
|
||||
struct formatter_units
|
||||
|
@ -1524,9 +1524,11 @@ struct formatter_units
|
|||
struct formatter_unit units[4];
|
||||
};
|
||||
|
||||
enum { TR_FMT_B, TR_FMT_KB, TR_FMT_MB, TR_FMT_GB };
|
||||
|
||||
static void
|
||||
formatter_init( struct formatter_units * units,
|
||||
double kilo,
|
||||
unsigned int kilo,
|
||||
const char * b, const char * kb,
|
||||
const char * mb, const char * gb )
|
||||
{
|
||||
|
@ -1537,19 +1539,10 @@ formatter_init( struct formatter_units * units,
|
|||
units->units[TR_FMT_KB].value = kilo;
|
||||
|
||||
units->units[TR_FMT_MB].name = tr_strdup( mb );
|
||||
units->units[TR_FMT_MB].value = pow( kilo, 2 );
|
||||
units->units[TR_FMT_MB].value = kilo * kilo;
|
||||
|
||||
units->units[TR_FMT_GB].name = tr_strdup( gb );
|
||||
units->units[TR_FMT_GB].value = pow( kilo, 3 );
|
||||
}
|
||||
|
||||
static const char*
|
||||
tr_formatter_units( const struct formatter_units * u, int size )
|
||||
{
|
||||
assert( u != NULL );
|
||||
assert( 0<=size && size<4 );
|
||||
|
||||
return u->units[size].name;
|
||||
units->units[TR_FMT_GB].value = kilo * kilo * kilo;
|
||||
}
|
||||
|
||||
static char*
|
||||
|
@ -1566,7 +1559,7 @@ formatter_get_size_str( const struct formatter_units * u,
|
|||
else if( bytes < u->units[3].value ) unit = &u->units[2];
|
||||
else unit = &u->units[3];
|
||||
|
||||
value = bytes / unit->value;
|
||||
value = (double)bytes / unit->value;
|
||||
units = unit->name;
|
||||
if( unit->value == 1 )
|
||||
precision = 0;
|
||||
|
@ -1581,8 +1574,9 @@ formatter_get_size_str( const struct formatter_units * u,
|
|||
static struct formatter_units size_units;
|
||||
|
||||
void
|
||||
tr_formatter_size_init( double kilo, const char * b, const char * kb,
|
||||
const char * mb, const char * gb )
|
||||
tr_formatter_size_init( unsigned int kilo,
|
||||
const char * b, const char * kb,
|
||||
const char * mb, const char * gb )
|
||||
{
|
||||
formatter_init( &size_units, kilo, b, kb, mb, gb );
|
||||
}
|
||||
|
@ -1593,17 +1587,12 @@ tr_formatter_size( char * buf, uint64_t bytes, size_t buflen )
|
|||
return formatter_get_size_str( &size_units, buf, bytes, buflen );
|
||||
}
|
||||
|
||||
const char*
|
||||
tr_formatter_size_units( int i )
|
||||
{
|
||||
return tr_formatter_units( &size_units, i );
|
||||
}
|
||||
|
||||
static struct formatter_units speed_units;
|
||||
|
||||
void
|
||||
tr_formatter_speed_init( double kilo, const char * b, const char * kb,
|
||||
const char * mb, const char * gb )
|
||||
tr_formatter_speed_init( unsigned int kilo,
|
||||
const char * b, const char * kb,
|
||||
const char * mb, const char * gb )
|
||||
{
|
||||
formatter_init( &speed_units, kilo, b, kb, mb, gb );
|
||||
}
|
||||
|
@ -1614,8 +1603,24 @@ tr_formatter_speed( char * buf, uint64_t bytes_per_second, size_t buflen )
|
|||
return formatter_get_size_str( &speed_units, buf, bytes_per_second, buflen );
|
||||
}
|
||||
|
||||
const char*
|
||||
tr_formatter_speed_units( int i )
|
||||
unsigned int
|
||||
tr_formatter_speed_k( void )
|
||||
{
|
||||
return tr_formatter_units( &speed_units, i );
|
||||
return speed_units.units[TR_FMT_KB].value;
|
||||
}
|
||||
|
||||
static struct formatter_units mem_units;
|
||||
|
||||
void
|
||||
tr_formatter_mem_init( unsigned int kilo,
|
||||
const char * b, const char * kb,
|
||||
const char * mb, const char * gb )
|
||||
{
|
||||
formatter_init( &mem_units, kilo, b, kb, mb, gb );
|
||||
}
|
||||
|
||||
char*
|
||||
tr_formatter_mem( char * buf, uint64_t bytes_per_second, size_t buflen )
|
||||
{
|
||||
return formatter_get_size_str( &mem_units, buf, bytes_per_second, buflen );
|
||||
}
|
||||
|
|
|
@ -564,23 +564,26 @@ char* tr_realpath( const char *path, char * resolved_path );
|
|||
|
||||
/* example: tr_formatter_size_init( 1024, _("B"), _("KiB"), _("MiB"), _("GiB") ); */
|
||||
|
||||
void tr_formatter_size_init( double kilo, const char * b, const char * kb,
|
||||
const char * mb, const char * gb );
|
||||
void tr_formatter_size_init( unsigned int kilo, const char * b, const char * kb,
|
||||
const char * mb, const char * gb );
|
||||
|
||||
void tr_formatter_speed_init( double kilo, const char * b, const char * kb,
|
||||
const char * mb, const char * gb );
|
||||
void tr_formatter_speed_init( unsigned int kilo, const char * b, const char * kb,
|
||||
const char * mb, const char * gb );
|
||||
|
||||
/* format a size into a user-readable string. */
|
||||
char* tr_formatter_size( char * buf, uint64_t bytes, size_t buflen );
|
||||
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 );
|
||||
|
||||
enum { TR_FMT_B, TR_FMT_KB, TR_FMT_MB, TR_FMT_GB };
|
||||
/* return the human-readable unit initialized by tr_formatter_size_init() */
|
||||
const char* tr_formatter_size_units( int size );
|
||||
/* return the human-readable unit initialized by tr_formatter_speed_init() */
|
||||
const char* tr_formatter_speed_units( int size );
|
||||
/* format a file size into a user-readable string. */
|
||||
char* tr_formatter_size( char * buf, uint64_t bytes, size_t buflen );
|
||||
|
||||
/* format a memory size into a user-readable string. */
|
||||
char* tr_formatter_mem( char * buf, uint64_t bytes, size_t buflen );
|
||||
|
||||
unsigned int tr_formatter_speed_k( void );
|
||||
|
||||
|
||||
/***
|
||||
****
|
||||
|
|
|
@ -221,11 +221,10 @@ tr_webseedIsActive( const tr_webseed * w )
|
|||
}
|
||||
|
||||
int
|
||||
tr_webseedGetSpeed( const tr_webseed * w, uint64_t now, float * setme_KiBs )
|
||||
tr_webseedGetSpeed_Bps( const tr_webseed * w, uint64_t now, int * setme_Bps )
|
||||
{
|
||||
const int isActive = tr_webseedIsActive( w );
|
||||
|
||||
*setme_KiBs = isActive ? tr_rcRate( &w->rateDown, now ) : 0.0f;
|
||||
*setme_Bps = isActive ? tr_rcRate_Bps( &w->rateDown, now ) : 0;
|
||||
return isActive;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,9 +34,9 @@ tr_addreq_t tr_webseedAddRequest( tr_webseed * w,
|
|||
uint32_t length );
|
||||
|
||||
/** @return true if a request is being processed, or false if idle */
|
||||
int tr_webseedGetSpeed( const tr_webseed * w,
|
||||
uint64_t now,
|
||||
float * setme_KiBs );
|
||||
int tr_webseedGetSpeed_Bps( const tr_webseed * w,
|
||||
uint64_t now,
|
||||
int * setme_Bps );
|
||||
|
||||
/** @return true if a request is being processed, or false if idle */
|
||||
int tr_webseedIsActive( const tr_webseed * w );
|
||||
|
|
26
qt/app.cc
26
qt/app.cc
|
@ -37,6 +37,7 @@
|
|||
#include "session.h"
|
||||
#include "session-dialog.h"
|
||||
#include "torrent-model.h"
|
||||
#include "units.h"
|
||||
#include "utils.h"
|
||||
#include "watchdir.h"
|
||||
|
||||
|
@ -99,16 +100,21 @@ MyApp :: MyApp( int& argc, char ** argv ):
|
|||
installTranslator( t );
|
||||
|
||||
// initialize the units formatter
|
||||
|
||||
tr_formatter_size_init ( 1024, qPrintable(tr("B")),
|
||||
qPrintable(tr("KiB")),
|
||||
qPrintable(tr("MiB")),
|
||||
qPrintable(tr("GiB")) );
|
||||
|
||||
tr_formatter_speed_init( 1024, qPrintable(tr("B/s")),
|
||||
qPrintable(tr("KiB/s")),
|
||||
qPrintable(tr("MiB/s")),
|
||||
qPrintable(tr("GiB/s")) );
|
||||
tr_formatter_mem_init( Units::mem_K,
|
||||
qPrintable( Units::mem_B_str ),
|
||||
qPrintable( Units::mem_K_str ),
|
||||
qPrintable( Units::mem_M_str ),
|
||||
qPrintable( Units::mem_G_str ) );
|
||||
tr_formatter_size_init( Units::size_K,
|
||||
qPrintable( Units::size_B_str ),
|
||||
qPrintable( Units::size_K_str ),
|
||||
qPrintable( Units::size_M_str ),
|
||||
qPrintable( Units::size_G_str ) );
|
||||
tr_formatter_speed_init( Units::speed_K,
|
||||
qPrintable( Units::speed_B_str ),
|
||||
qPrintable( Units::speed_K_str ),
|
||||
qPrintable( Units::speed_M_str ),
|
||||
qPrintable( Units::speed_G_str ) );
|
||||
|
||||
// set the default icon
|
||||
QIcon icon;
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
#include "squeezelabel.h"
|
||||
#include "torrent.h"
|
||||
#include "torrent-model.h"
|
||||
#include "utils.h"
|
||||
#include "units.h"
|
||||
|
||||
class Prefs;
|
||||
class Session;
|
||||
|
@ -214,7 +214,7 @@ QString
|
|||
Details :: timeToStringRounded( int seconds )
|
||||
{
|
||||
if( seconds > 60 ) seconds -= ( seconds % 60 );
|
||||
return Utils::timeToString ( seconds );
|
||||
return Units::timeToString ( seconds );
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -323,16 +323,16 @@ Details :: refresh( )
|
|||
string = none;
|
||||
else {
|
||||
const double d = 100.0 * ( sizeWhenDone ? ( sizeWhenDone - leftUntilDone ) / sizeWhenDone : 1 );
|
||||
QString pct = Utils::percentToString( d );
|
||||
QString pct = Units::percentToString( d );
|
||||
if( !haveUnverified )
|
||||
string = tr( "%1 (%2%)" )
|
||||
.arg( Utils :: sizeToString( haveVerified + haveUnverified ) )
|
||||
.arg( Units::sizeToString( haveVerified + haveUnverified ) )
|
||||
.arg( pct );
|
||||
else
|
||||
string = tr( "%1 (%2%); %3 Unverified" )
|
||||
.arg( Utils :: sizeToString( haveVerified + haveUnverified ) )
|
||||
.arg( Units::sizeToString( haveVerified + haveUnverified ) )
|
||||
.arg( pct )
|
||||
.arg( Utils :: sizeToString( haveUnverified ) );
|
||||
.arg( Units::sizeToString( haveUnverified ) );
|
||||
}
|
||||
}
|
||||
myHaveLabel->setText( string );
|
||||
|
@ -344,7 +344,7 @@ Details :: refresh( )
|
|||
if( sizeWhenDone == 0 )
|
||||
string = none;
|
||||
else
|
||||
string = QString( "%1%" ).arg( Utils::percentToString( ( 100.0 * available ) / sizeWhenDone ) );
|
||||
string = QString( "%1%" ).arg( Units::percentToString( ( 100.0 * available ) / sizeWhenDone ) );
|
||||
}
|
||||
myAvailabilityLabel->setText( string );
|
||||
|
||||
|
@ -357,8 +357,8 @@ Details :: refresh( )
|
|||
d += t->downloadedEver( );
|
||||
f += t->failedEver( );
|
||||
}
|
||||
const QString dstr = Utils::sizeToString( d );
|
||||
const QString fstr = Utils::sizeToString( f );
|
||||
const QString dstr = Units::sizeToString( d );
|
||||
const QString fstr = Units::sizeToString( f );
|
||||
if( f )
|
||||
string = tr( "%1 (+%2 corrupt)" ).arg( dstr ).arg( fstr );
|
||||
else
|
||||
|
@ -371,14 +371,14 @@ Details :: refresh( )
|
|||
string = none;
|
||||
else {
|
||||
foreach( const Torrent * t, torrents ) u += t->uploadedEver( );
|
||||
string = QString( Utils::sizeToString( u ) );
|
||||
string = QString( Units::sizeToString( u ) );
|
||||
}
|
||||
myUploadedLabel->setText( string );
|
||||
|
||||
if( torrents.empty( ) )
|
||||
string = none;
|
||||
else if( torrents.length() == 1 )
|
||||
string = QString( Utils :: ratioToString( torrents.first()->ratio() ) );
|
||||
string = Units::ratioToString( torrents.first()->ratio() );
|
||||
else {
|
||||
bool isMixed = false;
|
||||
int ratioType = torrents.first()->ratio();
|
||||
|
@ -394,9 +394,9 @@ Details :: refresh( )
|
|||
if( isMixed )
|
||||
string = mixed;
|
||||
else if( ratioType < 0 )
|
||||
string = QString( Utils :: ratioToString( ratioType ) );
|
||||
string = Units::ratioToString( ratioType );
|
||||
else
|
||||
string = QString( Utils :: ratioToString( (double)u / d ) );
|
||||
string = Units::ratioToString( (double)u / d );
|
||||
}
|
||||
myRatioLabel->setText( string );
|
||||
|
||||
|
@ -419,7 +419,7 @@ Details :: refresh( )
|
|||
else if( baseline.isNull( ) )
|
||||
string = mixed;
|
||||
else
|
||||
string = Utils::timeToString( baseline.secsTo( qdt_now ) );
|
||||
string = Units::timeToString( baseline.secsTo( qdt_now ) );
|
||||
}
|
||||
myRunTimeLabel->setText( string );
|
||||
|
||||
|
@ -440,7 +440,7 @@ Details :: refresh( )
|
|||
if( baseline < 0 )
|
||||
string = tr( "Unknown" );
|
||||
else
|
||||
string = Utils::timeToString( baseline );
|
||||
string = Units::timeToString( baseline );
|
||||
}
|
||||
}
|
||||
myETALabel->setText( string );
|
||||
|
@ -460,7 +460,7 @@ Details :: refresh( )
|
|||
if( seconds < 5 )
|
||||
string = tr( "Active now" );
|
||||
else
|
||||
string = tr( "%1 ago" ).arg( Utils::timeToString( seconds ) );
|
||||
string = tr( "%1 ago" ).arg( Units::timeToString( seconds ) );
|
||||
}
|
||||
myLastActivityLabel->setText( string );
|
||||
|
||||
|
@ -502,11 +502,11 @@ Details :: refresh( )
|
|||
string = none;
|
||||
else if( pieceSize > 0 )
|
||||
string = tr( "%1 (%Ln pieces @ %2)", "", pieces )
|
||||
.arg( Utils::sizeToString( size ) )
|
||||
.arg( Utils::sizeToString( pieceSize ) );
|
||||
.arg( Units::sizeToString( size ) )
|
||||
.arg( Units::memToString( pieceSize ) );
|
||||
else
|
||||
string = tr( "%1 (%Ln pieces)", "", pieces )
|
||||
.arg( Utils::sizeToString( size ) );
|
||||
.arg( Units::sizeToString( size ) );
|
||||
}
|
||||
mySizeLabel->setText( string );
|
||||
|
||||
|
@ -636,11 +636,11 @@ Details :: refresh( )
|
|||
myBandwidthPriorityCombo->blockSignals( false );
|
||||
|
||||
mySingleDownSpin->blockSignals( true );
|
||||
mySingleDownSpin->setValue( int(tor->downloadLimit().kbps()) );
|
||||
mySingleDownSpin->setValue( tor->downloadLimit().Bps() / Units::speed_K );
|
||||
mySingleDownSpin->blockSignals( false );
|
||||
|
||||
mySingleUpSpin->blockSignals( true );
|
||||
mySingleUpSpin->setValue( int(tor->uploadLimit().kbps()) );
|
||||
mySingleUpSpin->setValue( tor->uploadLimit().Bps() / Units::speed_K );
|
||||
mySingleUpSpin->blockSignals( false );
|
||||
|
||||
myPeerLimitSpin->blockSignals( true );
|
||||
|
@ -910,8 +910,8 @@ Details :: refresh( )
|
|||
if( !codeTip.isEmpty() )
|
||||
codeTip.resize( codeTip.size()-1 ); // eat the trailing linefeed
|
||||
|
||||
item->setText( COL_UP, peer.rateToPeer.isZero() ? "" : Utils::speedToString( peer.rateToPeer ) );
|
||||
item->setText( COL_DOWN, peer.rateToClient.isZero() ? "" : Utils::speedToString( peer.rateToClient ) );
|
||||
item->setText( COL_UP, peer.rateToPeer.isZero() ? "" : Units::speedToString( peer.rateToPeer ) );
|
||||
item->setText( COL_DOWN, peer.rateToClient.isZero() ? "" : Units::speedToString( peer.rateToClient ) );
|
||||
item->setText( COL_PERCENT, peer.progress > 0 ? QString( "%1%" ).arg( (int)( peer.progress * 100.0 ) ) : "" );
|
||||
item->setText( COL_STATUS, code );
|
||||
item->setToolTip( COL_STATUS, codeTip );
|
||||
|
@ -1010,7 +1010,7 @@ Details :: onDownloadLimitedToggled( bool val )
|
|||
void
|
||||
Details :: onDownloadLimitChanged( int val )
|
||||
{
|
||||
mySession.torrentSet( myIds, "downloadLimit", val );
|
||||
mySession.torrentSet( myIds, "downloadLimit", val * Units::speed_K );
|
||||
}
|
||||
void
|
||||
Details :: onUploadLimitedToggled( bool val )
|
||||
|
@ -1020,7 +1020,7 @@ Details :: onUploadLimitedToggled( bool val )
|
|||
void
|
||||
Details :: onUploadLimitChanged( int val )
|
||||
{
|
||||
mySession.torrentSet( myIds, "uploadLimit", val );
|
||||
mySession.torrentSet( myIds, "uploadLimit", val * Units::speed_K );
|
||||
}
|
||||
|
||||
#define RATIO_KEY "seedRatioMode"
|
||||
|
@ -1191,7 +1191,7 @@ Details :: createOptionsTab( )
|
|||
hig->addWideControl( c );
|
||||
connect( c, SIGNAL(clicked(bool)), this, SLOT(onHonorsSessionLimitsToggled(bool)) );
|
||||
|
||||
c = new QCheckBox( tr( "Limit &download speed (KiB/s):" ) );
|
||||
c = new QCheckBox( tr( "Limit &download speed (%1):" ).arg( Units::speed_K_str ) );
|
||||
mySingleDownCheck = c;
|
||||
s = new QSpinBox( );
|
||||
mySingleDownSpin = s;
|
||||
|
@ -1201,7 +1201,7 @@ Details :: createOptionsTab( )
|
|||
connect( c, SIGNAL(clicked(bool)), this, SLOT(onDownloadLimitedToggled(bool)) );
|
||||
connect( s, SIGNAL(valueChanged(int)), this, SLOT(onDownloadLimitChanged(int)));
|
||||
|
||||
c = new QCheckBox( tr( "Limit &upload speed (KiB/s):" ) );
|
||||
c = new QCheckBox( tr( "Limit &upload speed (%1):" ).arg( Units::speed_K_str ) );
|
||||
mySingleUpCheck = c;
|
||||
s = new QSpinBox( );
|
||||
mySingleUpSpin = s;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "file-tree.h"
|
||||
#include "hig.h"
|
||||
#include "torrent.h" // FileList
|
||||
#include "units.h"
|
||||
#include "utils.h" // mime icons
|
||||
|
||||
enum
|
||||
|
@ -122,7 +123,7 @@ FileTreeItem :: fileSizeName( ) const
|
|||
uint64_t have(0), total(0);
|
||||
QString str;
|
||||
getSubtreeSize( have, total );
|
||||
str = QString( name() + " (%1)" ).arg( Utils::sizeToString( total ) );
|
||||
str = QString( name() + " (%1)" ).arg( Units::sizeToString( total ) );
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
#include "torrent-model.h"
|
||||
#include "triconpushbutton.h"
|
||||
#include "ui_mainwin.h"
|
||||
#include "utils.h"
|
||||
#include "units.h"
|
||||
#include "qticonloader.h"
|
||||
|
||||
#define PREFS_KEY "prefs-key";
|
||||
|
@ -549,15 +549,16 @@ 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( Utils::speedToString( Speed::fromKbps( currentVal ) ) ) );
|
||||
a = myDlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Units::speedToString( Speed::fromBps( 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 ) {
|
||||
a = sub->addAction( Utils::speedToString( Speed::fromKbps(i) ) );
|
||||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << i << Prefs::DSPEED_ENABLED << true );
|
||||
const int Bps = i * Units::speed_K;
|
||||
a = sub->addAction( Units::speedToString( Speed::fromBps( Bps ) ) );
|
||||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << Bps << Prefs::DSPEED_ENABLED << true );
|
||||
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs()));
|
||||
}
|
||||
|
||||
|
@ -569,15 +570,16 @@ 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( Utils::speedToString( Speed::fromKbps( currentVal ) ) ) );
|
||||
a = myUlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Units::speedToString( Speed::fromBps( 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 ) {
|
||||
a = sub->addAction( Utils::speedToString( Speed::fromKbps(i) ) );
|
||||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << i << Prefs::USPEED_ENABLED << true );
|
||||
const int Bps = i * Units::speed_K;
|
||||
a = sub->addAction( Units::speedToString( Speed::fromBps( Bps ) ) );
|
||||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << Bps << Prefs::USPEED_ENABLED << true );
|
||||
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs()));
|
||||
}
|
||||
|
||||
|
@ -591,14 +593,14 @@ TrMainWindow :: createOptionsMenu( )
|
|||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO_ENABLED << false );
|
||||
g->addAction( a );
|
||||
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) );
|
||||
a = myRatioOnAction = sub->addAction( tr( "Stop at Ratio (%1)" ).arg( Utils::ratioToString( d ) ) );
|
||||
a = myRatioOnAction = sub->addAction( tr( "Stop at Ratio (%1)" ).arg( Units::ratioToString( d ) ) );
|
||||
a->setCheckable( true );
|
||||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO << d << Prefs::RATIO_ENABLED << true );
|
||||
g->addAction( a );
|
||||
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) );
|
||||
sub->addSeparator( );
|
||||
foreach( double i, stockRatios ) {
|
||||
a = sub->addAction( Utils::ratioToString( i ) );
|
||||
a = sub->addAction( Units::ratioToString( i ) );
|
||||
a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO << i << Prefs::RATIO_ENABLED << true );
|
||||
connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs()));
|
||||
}
|
||||
|
@ -733,8 +735,8 @@ TrMainWindow :: refreshStatusBar( )
|
|||
{
|
||||
const Speed up( myModel.getUploadSpeed( ) );
|
||||
const Speed down( myModel.getDownloadSpeed( ) );
|
||||
myUploadSpeedLabel->setText( Utils :: speedToString( up ) );
|
||||
myDownloadSpeedLabel->setText( Utils :: speedToString( down ) );
|
||||
myUploadSpeedLabel->setText( Units :: speedToString( up ) );
|
||||
myDownloadSpeedLabel->setText( Units :: speedToString( down ) );
|
||||
|
||||
myNetworkLabel->setVisible( !mySession.isServer( ) );
|
||||
|
||||
|
@ -743,23 +745,23 @@ TrMainWindow :: refreshStatusBar( )
|
|||
|
||||
if( mode == "session-ratio" )
|
||||
{
|
||||
str = tr( "Ratio: %1" ).arg( Utils :: ratioToString( mySession.getStats().ratio ) );
|
||||
str = tr( "Ratio: %1" ).arg( Units :: ratioToString( mySession.getStats().ratio ) );
|
||||
}
|
||||
else if( mode == "session-transfer" )
|
||||
{
|
||||
const tr_session_stats& stats( mySession.getStats( ) );
|
||||
str = tr( "Down: %1, Up: %2" ).arg( Utils :: sizeToString( stats.downloadedBytes ) )
|
||||
.arg( Utils :: sizeToString( stats.uploadedBytes ) );
|
||||
str = tr( "Down: %1, Up: %2" ).arg( Units :: sizeToString( stats.downloadedBytes ) )
|
||||
.arg( Units :: sizeToString( stats.uploadedBytes ) );
|
||||
}
|
||||
else if( mode == "total-transfer" )
|
||||
{
|
||||
const tr_session_stats& stats( mySession.getCumulativeStats( ) );
|
||||
str = tr( "Down: %1, Up: %2" ).arg( Utils :: sizeToString( stats.downloadedBytes ) )
|
||||
.arg( Utils :: sizeToString( stats.uploadedBytes ) );
|
||||
str = tr( "Down: %1, Up: %2" ).arg( Units :: sizeToString( stats.downloadedBytes ) )
|
||||
.arg( Units :: sizeToString( stats.uploadedBytes ) );
|
||||
}
|
||||
else // default is "total-ratio"
|
||||
{
|
||||
str = tr( "Ratio: %1" ).arg( Utils :: ratioToString( mySession.getCumulativeStats().ratio ) );
|
||||
str = tr( "Ratio: %1" ).arg( Units :: ratioToString( mySession.getCumulativeStats().ratio ) );
|
||||
}
|
||||
|
||||
myStatsLabel->setText( str );
|
||||
|
@ -1011,7 +1013,7 @@ TrMainWindow :: refreshPref( int key )
|
|||
break;
|
||||
|
||||
case Prefs::DSPEED:
|
||||
myDlimitOnAction->setText( tr( "Limited at %1" ).arg( Utils::speedToString( Speed::fromKbps( myPrefs.get<int>(key) ) ) ) );
|
||||
myDlimitOnAction->setText( tr( "Limited at %1" ).arg( Units::speedToString( Speed::fromBps( myPrefs.get<int>(key) ) ) ) );
|
||||
break;
|
||||
|
||||
case Prefs::USPEED_ENABLED:
|
||||
|
@ -1019,7 +1021,7 @@ TrMainWindow :: refreshPref( int key )
|
|||
break;
|
||||
|
||||
case Prefs::USPEED:
|
||||
myUlimitOnAction->setText( tr( "Limited at %1" ).arg( Utils::speedToString( Speed::fromKbps( myPrefs.get<int>(key) ) ) ) );
|
||||
myUlimitOnAction->setText( tr( "Limited at %1" ).arg( Units::speedToString( Speed::fromBps( myPrefs.get<int>(key) ) ) ) );
|
||||
break;
|
||||
|
||||
case Prefs::RATIO_ENABLED:
|
||||
|
@ -1027,7 +1029,7 @@ TrMainWindow :: refreshPref( int key )
|
|||
break;
|
||||
|
||||
case Prefs::RATIO:
|
||||
myRatioOnAction->setText( tr( "Stop at Ratio (%1)" ).arg( Utils::ratioToString( myPrefs.get<double>(key) ) ) );
|
||||
myRatioOnAction->setText( tr( "Stop at Ratio (%1)" ).arg( Units::ratioToString( myPrefs.get<double>(key) ) ) );
|
||||
break;
|
||||
|
||||
case Prefs::FILTER_MODE:
|
||||
|
@ -1085,10 +1087,10 @@ 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::fromKbps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_DOWN ) );
|
||||
const Speed u = Speed::fromKbps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_UP ) );
|
||||
myAltSpeedButton->setToolTip( fmt.arg( Utils::speedToString( d ) )
|
||||
.arg( Utils::speedToString( u ) ) );
|
||||
const Speed d = Speed::fromBps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_DOWN ) );
|
||||
const Speed u = Speed::fromBps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_UP ) );
|
||||
myAltSpeedButton->setToolTip( fmt.arg( Units::speedToString( d ) )
|
||||
.arg( Units::speedToString( u ) ) );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1293,7 +1295,7 @@ TrMainWindow :: updateNetworkIcon( )
|
|||
myNetworkLabel->setPixmap( pixmap );
|
||||
myNetworkLabel->setToolTip( isSending || isReading
|
||||
? tr( "Transmission server is responding" )
|
||||
: tr( "Last response from server was %1 ago" ).arg( Utils::timeToString( now-std::max(myLastReadTime,myLastSendTime))));
|
||||
: tr( "Last response from server was %1 ago" ).arg( Units::timeToString( now-std::max(myLastReadTime,myLastSendTime))));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
#include "hig.h"
|
||||
#include "make-dialog.h"
|
||||
#include "session.h"
|
||||
#include "utils.h"
|
||||
#include "units.h"
|
||||
|
||||
/***
|
||||
****
|
||||
|
@ -282,10 +282,10 @@ MakeDialog :: onSourceChanged( )
|
|||
QString files = tr( "%Ln File(s)", 0, myBuilder->fileCount );
|
||||
QString pieces = tr( "%Ln Piece(s)", 0, myBuilder->pieceCount );
|
||||
text = tr( "%1 in %2; %3 @ %4" )
|
||||
.arg( Utils::sizeToString( myBuilder->totalSize ) )
|
||||
.arg( Units::sizeToString( myBuilder->totalSize ) )
|
||||
.arg( files )
|
||||
.arg( pieces )
|
||||
.arg( Utils::sizeToString( myBuilder->pieceSize ) );
|
||||
.arg( Units::sizeToString( myBuilder->pieceSize ) );
|
||||
}
|
||||
|
||||
mySourceLabel->setText( text );
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "prefs-dialog.h"
|
||||
#include "qticonloader.h"
|
||||
#include "session.h"
|
||||
#include "units.h"
|
||||
#include "utils.h"
|
||||
|
||||
/***
|
||||
|
@ -50,6 +51,7 @@
|
|||
namespace
|
||||
{
|
||||
const char * PREF_KEY( "pref-key" );
|
||||
const char * MULTIPLIER_KEY( "multiplier-key" );
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -81,13 +83,14 @@ void
|
|||
PrefsDialog :: spinBoxChangedIdle( )
|
||||
{
|
||||
const QObject * spin( sender()->property( "SPIN" ).value<QObject*>( ) );
|
||||
const int key( spin->property( PREF_KEY ).toInt( ) );
|
||||
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, d->value( ) );
|
||||
myPrefs.set( key, multiplier * d->value( ) );
|
||||
else
|
||||
myPrefs.set( key, qobject_cast<const QSpinBox*>(spin)->value( ) );
|
||||
myPrefs.set( key, multiplier * qobject_cast<const QSpinBox*>(spin)->value( ) );
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -113,13 +116,14 @@ PrefsDialog :: spinBoxChanged( int value )
|
|||
}
|
||||
|
||||
QSpinBox *
|
||||
PrefsDialog :: spinBoxNew( int key, int low, int high, int step )
|
||||
PrefsDialog :: spinBoxNew( int key, int low, int high, int step, int multiplier )
|
||||
{
|
||||
QSpinBox * spin = new QSpinBox( );
|
||||
spin->setRange( low, high );
|
||||
spin->setSingleStep( step );
|
||||
spin->setValue( myPrefs.getInt( key ) );
|
||||
spin->setValue( myPrefs.getInt( key ) / multiplier );
|
||||
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;
|
||||
|
@ -134,14 +138,15 @@ PrefsDialog :: doubleSpinBoxChanged( double value )
|
|||
}
|
||||
|
||||
QDoubleSpinBox *
|
||||
PrefsDialog :: doubleSpinBoxNew( int key, double low, double high, double step, int decimals )
|
||||
PrefsDialog :: doubleSpinBoxNew( int key, double low, double high, double step, int decimals, int multiplier )
|
||||
{
|
||||
QDoubleSpinBox * spin = new QDoubleSpinBox( );
|
||||
spin->setRange( low, high );
|
||||
spin->setSingleStep( step );
|
||||
spin->setDecimals( decimals );
|
||||
spin->setValue( myPrefs.getDouble( key ) );
|
||||
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;
|
||||
|
@ -267,13 +272,13 @@ PrefsDialog :: createSpeedTab( )
|
|||
HIG * hig = new HIG( this );
|
||||
hig->addSectionTitle( tr( "Speed Limits" ) );
|
||||
|
||||
l = checkBoxNew( tr( "Limit &download speed (KiB/s):" ), Prefs::DSPEED_ENABLED );
|
||||
r = spinBoxNew( Prefs::DSPEED, 0, INT_MAX, 5 );
|
||||
l = checkBoxNew( tr( "Limit &download speed (%1):" ).arg( Units::speed_K_str ), Prefs::DSPEED_ENABLED );
|
||||
r = spinBoxNew( Prefs::DSPEED, 0, INT_MAX, 5, Units::speed_K );
|
||||
hig->addRow( l, r );
|
||||
enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r );
|
||||
|
||||
l = checkBoxNew( tr( "Limit &upload speed (KiB/s):" ), Prefs::USPEED_ENABLED );
|
||||
r = spinBoxNew( Prefs::USPEED, 0, INT_MAX, 5 );
|
||||
l = checkBoxNew( tr( "Limit &upload speed (%1):" ).arg( Units::speed_K_str ), Prefs::USPEED_ENABLED );
|
||||
r = spinBoxNew( Prefs::USPEED, 0, INT_MAX, 5, Units::speed_K );
|
||||
hig->addRow( l, r );
|
||||
enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r );
|
||||
|
||||
|
@ -293,12 +298,12 @@ PrefsDialog :: createSpeedTab( )
|
|||
QString s = tr( "<small>Override normal speed limits manually or at scheduled times</small>" );
|
||||
hig->addWideControl( new QLabel( s ) );
|
||||
|
||||
s = tr( "Limit d&ownload speed (KiB/s):" );
|
||||
r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_DOWN, 0, INT_MAX, 5 );
|
||||
s = tr( "Limit d&ownload speed (%1):" ).arg( Units::speed_K_str );
|
||||
r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_DOWN, 0, INT_MAX, 5, Units::speed_K );
|
||||
hig->addRow( s, r );
|
||||
|
||||
s = tr( "Limit u&pload speed (KiB/s):" );
|
||||
r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_UP, 0, INT_MAX, 5 );
|
||||
s = tr( "Limit u&pload speed (%1):" ).arg( Units::speed_K_str );
|
||||
r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_UP, 0, INT_MAX, 5, Units::speed_K );
|
||||
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 );
|
||||
QDoubleSpinBox * doubleSpinBoxNew( int key, double low, double high, double step, int decimals, int multiplier=1 );
|
||||
QCheckBox * checkBoxNew( const QString& text, int key );
|
||||
QSpinBox * spinBoxNew( int key, int low, int high, int step );
|
||||
QSpinBox * spinBoxNew( int key, int low, int high, int step, int multiplier=1 );
|
||||
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, QVariant::Int },
|
||||
{ ALT_SPEED_LIMIT_DOWN, TR_PREFS_KEY_ALT_SPEED_DOWN, QVariant::Int },
|
||||
{ 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_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, QVariant::Int },
|
||||
{ DSPEED, TR_PREFS_KEY_DSPEED_Bps, 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, QVariant::Int },
|
||||
{ USPEED, TR_PREFS_KEY_USPEED_Bps, QVariant::Int },
|
||||
{ UPLOAD_SLOTS_PER_TORRENT, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, QVariant::Int }
|
||||
};
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ SOURCES += about.cc app.cc dbus-adaptor.cc details.cc file-tree.cc filters.cc \
|
|||
prefs-dialog.cc qticonloader.cc relocate.cc session.cc \
|
||||
session-dialog.cc squeezelabel.cc stats-dialog.cc torrent.cc \
|
||||
torrent-delegate.cc torrent-delegate-min.cc torrent-filter.cc \
|
||||
torrent-model.cc triconpushbutton.cc utils.cc watchdir.cc
|
||||
torrent-model.cc triconpushbutton.cc units.cc utils.cc watchdir.cc
|
||||
HEADERS += $$replace(SOURCES, .cc, .h)
|
||||
HEADERS += speed.h types.h
|
||||
|
||||
|
|
26
qt/speed.h
26
qt/speed.h
|
@ -16,20 +16,20 @@
|
|||
class Speed
|
||||
{
|
||||
private:
|
||||
double _kbps;
|
||||
Speed( double kbps ): _kbps(kbps) { }
|
||||
int _Bps;
|
||||
Speed( int Bps ): _Bps(Bps) { }
|
||||
public:
|
||||
Speed( ): _kbps(0) { }
|
||||
double kbps( ) const { return _kbps; }
|
||||
double bps( ) const { return kbps()*1024.0; }
|
||||
bool isZero( ) const { return _kbps < 0.001; }
|
||||
static Speed fromKbps( double kbps ) { return Speed( kbps ); }
|
||||
static Speed fromBps( double bps ) { return Speed( bps/1024.0 ); }
|
||||
void setKbps( double kbps ) { _kbps = kbps; }
|
||||
void setBps( double bps ) { _kbps = bps/1024.0; }
|
||||
Speed operator+( const Speed& that ) const { return Speed( kbps() + that.kbps() ); }
|
||||
Speed& operator+=( const Speed& that ) { _kbps += that._kbps; return *this; }
|
||||
bool operator<( const Speed& that ) const { return kbps() < that.kbps(); }
|
||||
Speed( ): _Bps(0) { }
|
||||
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 fromBps( int Bps ) { return Speed( Bps ); }
|
||||
void setKiBps( double KiBps ) { setBps( KiBps*1024 ); }
|
||||
void setBps( double Bps ) { _Bps = Bps; }
|
||||
Speed& operator+=( const Speed& that ) { _Bps += that._Bps; return *this; }
|
||||
Speed operator+( const Speed& that ) const { return Speed( _Bps + that._Bps ); }
|
||||
bool operator<( const Speed& that ) const { return _Bps < that._Bps; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "hig.h"
|
||||
#include "session.h"
|
||||
#include "stats-dialog.h"
|
||||
#include "utils.h"
|
||||
#include "units.h"
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -85,15 +85,15 @@ StatsDialog :: updateStats( )
|
|||
const struct tr_session_stats& current( mySession.getStats( ) );
|
||||
const struct tr_session_stats& total( mySession.getCumulativeStats( ) );
|
||||
|
||||
myCurrentUp->setText( Utils :: sizeToString( current.uploadedBytes ) );
|
||||
myCurrentDown->setText( Utils :: sizeToString( current.downloadedBytes ) );
|
||||
myCurrentRatio->setText( Utils :: ratioToString( current.ratio ) );
|
||||
myCurrentDuration->setText( Utils :: timeToString( current.secondsActive ) );
|
||||
myCurrentUp->setText( Units::sizeToString( current.uploadedBytes ) );
|
||||
myCurrentDown->setText( Units::sizeToString( current.downloadedBytes ) );
|
||||
myCurrentRatio->setText( Units::ratioToString( current.ratio ) );
|
||||
myCurrentDuration->setText( Units::timeToString( current.secondsActive ) );
|
||||
|
||||
myTotalUp->setText( Utils :: sizeToString( total.uploadedBytes ) );
|
||||
myTotalDown->setText( Utils :: sizeToString( total.downloadedBytes ) );
|
||||
myTotalRatio->setText( Utils :: ratioToString( total.ratio ) );
|
||||
myTotalDuration->setText( Utils :: timeToString( total.secondsActive ) );
|
||||
myTotalUp->setText( Units::sizeToString( total.uploadedBytes ) );
|
||||
myTotalDown->setText( Units::sizeToString( total.downloadedBytes ) );
|
||||
myTotalRatio->setText( Units::ratioToString( total.ratio ) );
|
||||
myTotalDuration->setText( Units::timeToString( total.secondsActive ) );
|
||||
|
||||
myStartCount->setText( tr( "Started %n time(s)", 0, total.sessionCount ) );
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "torrent.h"
|
||||
#include "torrent-delegate-min.h"
|
||||
#include "torrent-model.h"
|
||||
#include "utils.h"
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "torrent.h"
|
||||
#include "torrent-delegate.h"
|
||||
#include "torrent-model.h"
|
||||
#include "utils.h"
|
||||
#include "units.h"
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -74,16 +74,16 @@ TorrentDelegate :: progressString( const Torrent& tor ) const
|
|||
{
|
||||
/* %1 is the percentage of torrent metadata downloaded */
|
||||
str = tr( "Magnetized transfer - retrieving metadata (%1%)" )
|
||||
.arg( Utils::percentToString( tor.metadataPercentDone() * 100.0 ) );
|
||||
.arg( Units::percentToString( tor.metadataPercentDone() * 100.0 ) );
|
||||
}
|
||||
else if( !isDone ) // downloading
|
||||
{
|
||||
/* %1 is how much we've got,
|
||||
%2 is how much we'll have when done,
|
||||
%3 is a percentage of the two */
|
||||
str = tr( "%1 of %2 (%3%)" ).arg( Utils::sizeToString( haveTotal ) )
|
||||
.arg( Utils::sizeToString( tor.sizeWhenDone( ) ) )
|
||||
.arg( Utils::percentToString( tor.percentDone( ) * 100.0 ) );
|
||||
str = tr( "%1 of %2 (%3%)" ).arg( Units::sizeToString( haveTotal ) )
|
||||
.arg( Units::sizeToString( tor.sizeWhenDone( ) ) )
|
||||
.arg( Units::percentToString( tor.percentDone( ) * 100.0 ) );
|
||||
}
|
||||
else if( !isSeed ) // partial seed
|
||||
{
|
||||
|
@ -96,12 +96,12 @@ TorrentDelegate :: progressString( const Torrent& tor ) const
|
|||
%5 is our upload-to-download ratio
|
||||
%6 is the ratio we want to reach before we stop uploading */
|
||||
str = tr( "%1 of %2 (%3%), uploaded %4 (Ratio: %5 Goal: %6)" )
|
||||
.arg( Utils::sizeToString( haveTotal ) )
|
||||
.arg( Utils::sizeToString( tor.totalSize( ) ) )
|
||||
.arg( Utils::percentToString( tor.percentComplete( ) * 100.0 ) )
|
||||
.arg( Utils::sizeToString( tor.uploadedEver( ) ) )
|
||||
.arg( Utils::ratioToString( tor.ratio( ) ) )
|
||||
.arg( Utils::ratioToString( seedRatio ) );
|
||||
.arg( Units::sizeToString( haveTotal ) )
|
||||
.arg( Units::sizeToString( tor.totalSize( ) ) )
|
||||
.arg( Units::percentToString( tor.percentComplete( ) * 100.0 ) )
|
||||
.arg( Units::sizeToString( tor.uploadedEver( ) ) )
|
||||
.arg( Units::ratioToString( tor.ratio( ) ) )
|
||||
.arg( Units::ratioToString( seedRatio ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -111,11 +111,11 @@ TorrentDelegate :: progressString( const Torrent& tor ) const
|
|||
%4 is how much we've uploaded,
|
||||
%5 is our upload-to-download ratio */
|
||||
str = tr( "%1 of %2 (%3%), uploaded %4 (Ratio: %5)" )
|
||||
.arg( Utils::sizeToString( haveTotal ) )
|
||||
.arg( Utils::sizeToString( tor.totalSize( ) ) )
|
||||
.arg( Utils::percentToString( tor.percentComplete( ) * 100.0 ) )
|
||||
.arg( Utils::sizeToString( tor.uploadedEver( ) ) )
|
||||
.arg( Utils::ratioToString( tor.ratio( ) ) );
|
||||
.arg( Units::sizeToString( haveTotal ) )
|
||||
.arg( Units::sizeToString( tor.totalSize( ) ) )
|
||||
.arg( Units::percentToString( tor.percentComplete( ) * 100.0 ) )
|
||||
.arg( Units::sizeToString( tor.uploadedEver( ) ) )
|
||||
.arg( Units::ratioToString( tor.ratio( ) ) );
|
||||
}
|
||||
}
|
||||
else // seeding
|
||||
|
@ -127,10 +127,10 @@ TorrentDelegate :: progressString( const Torrent& tor ) const
|
|||
%3 is our upload-to-download ratio,
|
||||
%4 is the ratio we want to reach before we stop uploading */
|
||||
str = tr( "%1, uploaded %2 (Ratio: %3 Goal %4)" )
|
||||
.arg( Utils::sizeToString( haveTotal ) )
|
||||
.arg( Utils::sizeToString( tor.uploadedEver( ) ) )
|
||||
.arg( Utils::ratioToString( tor.ratio( ) ) )
|
||||
.arg( Utils::ratioToString( seedRatio ) );
|
||||
.arg( Units::sizeToString( haveTotal ) )
|
||||
.arg( Units::sizeToString( tor.uploadedEver( ) ) )
|
||||
.arg( Units::ratioToString( tor.ratio( ) ) )
|
||||
.arg( Units::ratioToString( seedRatio ) );
|
||||
}
|
||||
else /* seeding w/o a ratio */
|
||||
{
|
||||
|
@ -138,9 +138,9 @@ TorrentDelegate :: progressString( const Torrent& tor ) const
|
|||
%2 is how much we've uploaded,
|
||||
%3 is our upload-to-download ratio */
|
||||
str = tr( "%1, uploaded %2 (Ratio: %3)" )
|
||||
.arg( Utils::sizeToString( haveTotal ) )
|
||||
.arg( Utils::sizeToString( tor.uploadedEver( ) ) )
|
||||
.arg( Utils::ratioToString( tor.ratio( ) ) );
|
||||
.arg( Units::sizeToString( haveTotal ) )
|
||||
.arg( Units::sizeToString( tor.uploadedEver( ) ) )
|
||||
.arg( Units::ratioToString( tor.ratio( ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ TorrentDelegate :: progressString( const Torrent& tor ) const
|
|||
{
|
||||
str += tr( " - " );
|
||||
if( tor.hasETA( ) )
|
||||
str += tr( "%1 left" ).arg( Utils::timeToString( tor.getETA( ) ) );
|
||||
str += tr( "%1 left" ).arg( Units::timeToString( tor.getETA( ) ) );
|
||||
else
|
||||
str += tr( "Remaining time unknown" );
|
||||
}
|
||||
|
@ -166,9 +166,9 @@ TorrentDelegate :: shortTransferString( const Torrent& tor ) const
|
|||
QString downStr, upStr, str;
|
||||
|
||||
if( haveDown )
|
||||
downStr = Utils :: speedToString( tor.downloadSpeed( ) );
|
||||
downStr = Units::speedToString( tor.downloadSpeed( ) );
|
||||
if( haveUp )
|
||||
upStr = Utils :: speedToString( tor.uploadSpeed( ) );
|
||||
upStr = Units::speedToString( tor.uploadSpeed( ) );
|
||||
|
||||
if( haveDown && haveUp )
|
||||
str = tr( "Down: %1, Up: %2" ).arg(downStr).arg(upStr);
|
||||
|
@ -190,13 +190,13 @@ TorrentDelegate :: shortStatusString( const Torrent& tor ) const
|
|||
switch( tor.getActivity( ) )
|
||||
{
|
||||
case TR_STATUS_CHECK:
|
||||
str = tr( "Verifying local data (%1% tested)" ).arg( Utils::percentToString( tor.getVerifyProgress()*100.0 ) );
|
||||
str = tr( "Verifying local data (%1% tested)" ).arg( Units::percentToString( tor.getVerifyProgress()*100.0 ) );
|
||||
break;
|
||||
|
||||
case TR_STATUS_DOWNLOAD:
|
||||
case TR_STATUS_SEED:
|
||||
if( !tor.isDownloading( ) )
|
||||
str = tr( "Ratio: %1, " ).arg( Utils::ratioToString( tor.ratio( ) ) );
|
||||
str = tr( "Ratio: %1, " ).arg( Units::ratioToString( tor.ratio( ) ) );
|
||||
str += shortTransferString( tor );
|
||||
break;
|
||||
|
||||
|
@ -231,7 +231,7 @@ TorrentDelegate :: statusString( const Torrent& tor ) const
|
|||
.arg( tor.peersWeAreDownloadingFrom( ) );
|
||||
else
|
||||
str = tr( "Downloading metadata from %n peer(s) (%1% done)", 0, tor.peersWeAreDownloadingFrom( ) )
|
||||
.arg( Utils::percentToString( 100.0 * tor.metadataPercentDone( ) ) );
|
||||
.arg( Units::percentToString( 100.0 * tor.metadataPercentDone( ) ) );
|
||||
break;
|
||||
|
||||
case TR_STATUS_SEED:
|
||||
|
|
|
@ -284,8 +284,8 @@ class Torrent: public QObject
|
|||
double getVerifyProgress( ) const { return getDouble( PERCENT_VERIFIED ); }
|
||||
bool hasFileSubstring( const QString& substr ) const;
|
||||
bool hasTrackerSubstring( const QString& substr ) const;
|
||||
Speed uploadLimit( ) const { return Speed::fromKbps( getInt( UP_LIMIT ) ); }
|
||||
Speed downloadLimit( ) const { return Speed::fromKbps( getInt( DOWN_LIMIT ) ); }
|
||||
Speed uploadLimit( ) const { return Speed::fromBps( getInt( UP_LIMIT ) ); }
|
||||
Speed downloadLimit( ) const { return Speed::fromBps( 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 ); }
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* This file Copyright (C) 2010 Mnemosyne LLC
|
||||
*
|
||||
* This file is licensed by the GPL version 2. Works owned by the
|
||||
* Transmission project are granted a special exemption to clause 2(b)
|
||||
* so that the bulk of its code can remain under the MIT license.
|
||||
* This exemption does not extend to derived works not owned by
|
||||
* the Transmission project.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <libtransmission/transmission.h>
|
||||
#include <libtransmission/utils.h> // tr_formatter
|
||||
|
||||
#include "speed.h"
|
||||
#include "units.h"
|
||||
|
||||
/***
|
||||
**** Constants
|
||||
***/
|
||||
|
||||
const int Units :: speed_K = 1000;
|
||||
const QString Units :: speed_B_str = "B/s";
|
||||
const QString Units :: speed_K_str = "kB/s";
|
||||
const QString Units :: speed_M_str = "MB/s";
|
||||
const QString Units :: speed_G_str = "GB/s";
|
||||
|
||||
const int Units :: size_K = 1000;
|
||||
const QString Units :: size_B_str = "B";
|
||||
const QString Units :: size_K_str = "kB";
|
||||
const QString Units :: size_M_str = "MB";
|
||||
const QString Units :: size_G_str = "GB";
|
||||
|
||||
const int Units :: mem_K = 1024;
|
||||
const QString Units :: mem_B_str = "B";
|
||||
const QString Units :: mem_K_str = "KiB";
|
||||
const QString Units :: mem_M_str = "MiB";
|
||||
const QString Units :: mem_G_str = "GiB";
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
QString
|
||||
Units :: memToString( double bytes )
|
||||
{
|
||||
if( !bytes )
|
||||
return tr( "None" );
|
||||
else {
|
||||
char buf[128];
|
||||
tr_formatter_mem( buf, bytes, sizeof( buf ) );
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
QString
|
||||
Units :: sizeToString( double bytes )
|
||||
{
|
||||
if( !bytes )
|
||||
return tr( "None" );
|
||||
else {
|
||||
char buf[128];
|
||||
tr_formatter_size( buf, bytes, sizeof( buf ) );
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
QString
|
||||
Units :: speedToString( const Speed& speed )
|
||||
{
|
||||
if( speed.isZero( ) )
|
||||
return tr( "None" );
|
||||
else {
|
||||
char buf[128];
|
||||
tr_formatter_speed( buf, speed.Bps( ), sizeof( buf ) );
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
QString
|
||||
Units :: percentToString( double x )
|
||||
{
|
||||
char buf[128];
|
||||
return QString( tr_strpercent( buf, x, sizeof(buf) ) );
|
||||
}
|
||||
|
||||
QString
|
||||
Units :: ratioToString( double ratio )
|
||||
{
|
||||
char buf[128];
|
||||
return QString::fromUtf8( tr_strratio( buf, sizeof(buf), ratio, "\xE2\x88\x9E" ) );
|
||||
}
|
||||
|
||||
QString
|
||||
Units :: timeToString( int seconds )
|
||||
{
|
||||
int days, hours, minutes;
|
||||
QString d, h, m, s;
|
||||
QString str;
|
||||
|
||||
if( seconds < 0 )
|
||||
seconds = 0;
|
||||
|
||||
days = seconds / 86400;
|
||||
hours = ( seconds % 86400 ) / 3600;
|
||||
minutes = ( seconds % 3600 ) / 60;
|
||||
seconds %= 60;
|
||||
|
||||
d = tr( "%Ln day(s)", 0, days );
|
||||
h = tr( "%Ln hour(s)", 0, hours );
|
||||
m = tr( "%Ln minute(s)", 0, minutes );
|
||||
s = tr( "%Ln second(s)", 0, seconds );
|
||||
|
||||
if( days )
|
||||
{
|
||||
if( days >= 4 || !hours )
|
||||
str = d;
|
||||
else
|
||||
str = tr( "%1, %2" ).arg( d ).arg( h );
|
||||
}
|
||||
else if( hours )
|
||||
{
|
||||
if( hours >= 4 || !minutes )
|
||||
str = h;
|
||||
else
|
||||
str = tr( "%1, %2" ).arg( h ).arg( m );
|
||||
}
|
||||
else if( minutes )
|
||||
{
|
||||
if( minutes >= 4 || !seconds )
|
||||
str = m;
|
||||
else
|
||||
str = tr( "%1, %2" ).arg( m ).arg( s );
|
||||
}
|
||||
else
|
||||
{
|
||||
str = s;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* This file Copyright (C) 2010 Mnemosyne LLC
|
||||
*
|
||||
* This file is licensed by the GPL version 2. Works owned by the
|
||||
* Transmission project are granted a special exemption to clause 2(b)
|
||||
* so that the bulk of its code can remain under the MIT license.
|
||||
* This exemption does not extend to derived works not owned by
|
||||
* the Transmission project.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef QTR_UNITS
|
||||
#define QTR_UNITS
|
||||
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
#include <QIcon>
|
||||
|
||||
class Speed;
|
||||
|
||||
class Units: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
Units( ) { }
|
||||
virtual ~Units( ) { }
|
||||
|
||||
public:
|
||||
|
||||
static QString memToString( double bytes );
|
||||
static QString sizeToString( double bytes );
|
||||
static QString speedToString( const Speed& speed );
|
||||
static QString percentToString( double x );
|
||||
static QString ratioToString( double ratio );
|
||||
static QString timeToString( int seconds );
|
||||
|
||||
public:
|
||||
|
||||
static const int speed_K;
|
||||
static const QString speed_B_str;
|
||||
static const QString speed_K_str;
|
||||
static const QString speed_M_str;
|
||||
static const QString speed_G_str;
|
||||
|
||||
static const int size_K;
|
||||
static const QString size_B_str;
|
||||
static const QString size_K_str;
|
||||
static const QString size_M_str;
|
||||
static const QString size_G_str;
|
||||
|
||||
static const int mem_K;
|
||||
static const QString mem_B_str;
|
||||
static const QString mem_K_str;
|
||||
static const QString mem_M_str;
|
||||
static const QString mem_G_str;
|
||||
};
|
||||
|
||||
#endif
|
91
qt/utils.cc
91
qt/utils.cc
|
@ -28,6 +28,10 @@
|
|||
#include "qticonloader.h"
|
||||
#include "utils.h"
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
QString
|
||||
Utils :: remoteFileChooser( QWidget * parent, const QString& title, const QString& myPath, bool dir, bool local )
|
||||
{
|
||||
|
@ -46,93 +50,6 @@ Utils :: remoteFileChooser( QWidget * parent, const QString& title, const QStrin
|
|||
return path;
|
||||
}
|
||||
|
||||
QString
|
||||
Utils :: sizeToString( double bytes )
|
||||
{
|
||||
if( !bytes )
|
||||
return tr( "None" );
|
||||
else {
|
||||
char buf[128];
|
||||
tr_formatter_size( buf, bytes, sizeof( buf ) );
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
QString
|
||||
Utils :: speedToString( const Speed& speed )
|
||||
{
|
||||
if( speed.isZero( ) )
|
||||
return tr( "None" );
|
||||
else {
|
||||
char buf[128];
|
||||
tr_formatter_speed( buf, speed.bps( ), sizeof( buf ) );
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
QString
|
||||
Utils :: percentToString( double x )
|
||||
{
|
||||
char buf[128];
|
||||
return QString( tr_strpercent( buf, x, sizeof(buf) ) );
|
||||
}
|
||||
|
||||
QString
|
||||
Utils :: ratioToString( double ratio )
|
||||
{
|
||||
char buf[128];
|
||||
return QString::fromUtf8( tr_strratio( buf, sizeof(buf), ratio, "\xE2\x88\x9E" ) );
|
||||
}
|
||||
|
||||
QString
|
||||
Utils :: timeToString( int seconds )
|
||||
{
|
||||
int days, hours, minutes;
|
||||
QString d, h, m, s;
|
||||
QString str;
|
||||
|
||||
if( seconds < 0 )
|
||||
seconds = 0;
|
||||
|
||||
days = seconds / 86400;
|
||||
hours = ( seconds % 86400 ) / 3600;
|
||||
minutes = ( seconds % 3600 ) / 60;
|
||||
seconds %= 60;
|
||||
|
||||
d = tr( "%Ln day(s)", 0, days );
|
||||
h = tr( "%Ln hour(s)", 0, hours );
|
||||
m = tr( "%Ln minute(s)", 0, minutes );
|
||||
s = tr( "%Ln second(s)", 0, seconds );
|
||||
|
||||
if( days )
|
||||
{
|
||||
if( days >= 4 || !hours )
|
||||
str = d;
|
||||
else
|
||||
str = tr( "%1, %2" ).arg( d ).arg( h );
|
||||
}
|
||||
else if( hours )
|
||||
{
|
||||
if( hours >= 4 || !minutes )
|
||||
str = h;
|
||||
else
|
||||
str = tr( "%1, %2" ).arg( h ).arg( m );
|
||||
}
|
||||
else if( minutes )
|
||||
{
|
||||
if( minutes >= 4 || !seconds )
|
||||
str = m;
|
||||
else
|
||||
str = tr( "%1, %2" ).arg( m ).arg( s );
|
||||
}
|
||||
else
|
||||
{
|
||||
str = s;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void
|
||||
Utils :: toStderr( const QString& str )
|
||||
{
|
||||
|
|
|
@ -26,13 +26,9 @@ class Utils: public QObject
|
|||
public:
|
||||
Utils( ) { }
|
||||
virtual ~Utils( ) { }
|
||||
|
||||
public:
|
||||
static QString remoteFileChooser( QWidget * parent, const QString& title, const QString& myPath, bool dir, bool local );
|
||||
static QString sizeToString( double bytes );
|
||||
static QString speedToString( const Speed& speed );
|
||||
static QString percentToString( double x );
|
||||
static QString ratioToString( double ratio );
|
||||
static QString timeToString( int seconds );
|
||||
static const QIcon& guessMimeIcon( const QString& filename );
|
||||
|
||||
// meh
|
||||
|
|
25
utils/show.c
25
utils/show.c
|
@ -28,6 +28,24 @@
|
|||
#define MY_NAME "transmission-show"
|
||||
#define TIMEOUT_SECS 30
|
||||
|
||||
#define MEM_K 1024
|
||||
#define MEM_B_STR "B"
|
||||
#define MEM_K_STR "KiB"
|
||||
#define MEM_M_STR "MiB"
|
||||
#define MEM_G_STR "GiB"
|
||||
|
||||
#define DISK_K 1000
|
||||
#define DISK_B_STR "B"
|
||||
#define DISK_K_STR "kB"
|
||||
#define DISK_M_STR "MB"
|
||||
#define DISK_G_STR "GB"
|
||||
|
||||
#define SPEED_K 1000
|
||||
#define SPEED_B_STR "B/s"
|
||||
#define SPEED_K_STR "kB/s"
|
||||
#define SPEED_M_STR "MB/s"
|
||||
#define SPEED_G_STR "GB/s"
|
||||
|
||||
static tr_option options[] =
|
||||
{
|
||||
{ 's', "scrape", "Ask the torrent's trackers how many peers are in the torrent's swarm", "s", 0, NULL },
|
||||
|
@ -86,7 +104,7 @@ 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_size( buf, inf->pieceSize, sizeof( buf ) ) );
|
||||
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( " Privacy: %s\n", inf->isPrivate ? "Private torrent" : "Public torrent" );
|
||||
|
||||
|
@ -231,8 +249,9 @@ main( int argc, char * argv[] )
|
|||
tr_ctor * ctor;
|
||||
|
||||
tr_setMessageLevel( TR_MSG_ERR );
|
||||
tr_formatter_size_init ( 1024, "B", "KiB", "MiB", "GiB" );
|
||||
tr_formatter_speed_init( 1024, "B/s", "KiB/s", "MiB/s", "GiB/s" );
|
||||
tr_formatter_mem_init ( MEM_K, MEM_B_STR, MEM_K_STR, MEM_G_STR );
|
||||
tr_formatter_size_init ( DISK_K, DISK_B_STR, DIST_K_STR, DISK_G_STR );
|
||||
tr_formatter_size_init ( SPEED_K, SPEED_B_STR, SPEED_K_STR, SPEED_G_STR );
|
||||
|
||||
if( parseCommandLine( argc, (const char**)argv ) )
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -272,13 +272,13 @@
|
|||
<input type="checkbox" name="limit_download" id="limit_download"/>
|
||||
<label for="limit_download" class="item">Download Rate:</label>
|
||||
<input type="text" name="download_rate" id="download_rate"/>
|
||||
<label class="suffix">KB/s</label>
|
||||
<label class="suffix">kB/s</label>
|
||||
</div>
|
||||
<div class="formdiv checkbox">
|
||||
<input type="checkbox" name="limit_upload" id="limit_upload"/>
|
||||
<label for="limit_upload" class="item">Upload Rate:</label>
|
||||
<input type="text" name="upload_rate" id="upload_rate"/>
|
||||
<label class="suffix">KB/s</label>
|
||||
<label class="suffix">kB/s</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="preference limit_turtle">
|
||||
|
@ -287,12 +287,12 @@
|
|||
<div class="formdiv">
|
||||
<label for="turtle_download_rate" class="item">Download Rate:</label>
|
||||
<input type="text" name="turtle_download_rate" id="turtle_download_rate"/>
|
||||
<label class="suffix">KB/s</label>
|
||||
<label class="suffix">kB/s</label>
|
||||
</div>
|
||||
<div class="formdiv">
|
||||
<label for="turtle_upload_rate" class="item">Upload Rate:</label>
|
||||
<input type="text" name="turtle_upload_rate" id="turtle_upload_rate"/>
|
||||
<label class="suffix">KB/s</label>
|
||||
<label class="suffix">kB/s</label>
|
||||
</div>
|
||||
<div class="formdiv checkbox">
|
||||
<input type="checkbox" name="turtle_schedule" id="turtle_schedule"/>
|
||||
|
@ -413,41 +413,41 @@
|
|||
<li>Total Download Rate
|
||||
<ul id="footer_download_rate_menu">
|
||||
<li id="unlimited_download_rate">Unlimited</li>
|
||||
<li id="limited_download_rate">Limit (10 KB/s)</li>
|
||||
<li id="limited_download_rate">Limit (10 kB/s)</li>
|
||||
<li class="separator"></li>
|
||||
<li>5 KB/s</li>
|
||||
<li>10 KB/s</li>
|
||||
<li>20 KB/s</li>
|
||||
<li>30 KB/s</li>
|
||||
<li>40 KB/s</li>
|
||||
<li>50 KB/s</li>
|
||||
<li>75 KB/s</li>
|
||||
<li>100 KB/s</li>
|
||||
<li>150 KB/s</li>
|
||||
<li>200 KB/s</li>
|
||||
<li>250 KB/s</li>
|
||||
<li>500 KB/s</li>
|
||||
<li>750 KB/s</li>
|
||||
<li>5 kB/s</li>
|
||||
<li>10 kB/s</li>
|
||||
<li>20 kB/s</li>
|
||||
<li>30 kB/s</li>
|
||||
<li>40 kB/s</li>
|
||||
<li>50 kB/s</li>
|
||||
<li>75 kB/s</li>
|
||||
<li>100 kB/s</li>
|
||||
<li>150 kB/s</li>
|
||||
<li>200 kB/s</li>
|
||||
<li>250 kB/s</li>
|
||||
<li>500 kB/s</li>
|
||||
<li>750 kB/s</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Total Upload Rate
|
||||
<ul id="footer_upload_rate_menu">
|
||||
<li id="unlimited_upload_rate">Unlimited</li>
|
||||
<li id="limited_upload_rate">Limit (10 KB/s)</li>
|
||||
<li id="limited_upload_rate">Limit (10 kB/s)</li>
|
||||
<li class="separator"></li>
|
||||
<li>5 KB/s</li>
|
||||
<li>10 KB/s</li>
|
||||
<li>20 KB/s</li>
|
||||
<li>30 KB/s</li>
|
||||
<li>40 KB/s</li>
|
||||
<li>50 KB/s</li>
|
||||
<li>75 KB/s</li>
|
||||
<li>100 KB/s</li>
|
||||
<li>150 KB/s</li>
|
||||
<li>200 KB/s</li>
|
||||
<li>250 KB/s</li>
|
||||
<li>500 KB/s</li>
|
||||
<li>750 KB/s</li>
|
||||
<li>5 kB/s</li>
|
||||
<li>10 kB/s</li>
|
||||
<li>20 kB/s</li>
|
||||
<li>30 kB/s</li>
|
||||
<li>40 kB/s</li>
|
||||
<li>50 kB/s</li>
|
||||
<li>75 kB/s</li>
|
||||
<li>100 kB/s</li>
|
||||
<li>150 kB/s</li>
|
||||
<li>200 kB/s</li>
|
||||
<li>250 kB/s</li>
|
||||
<li>500 kB/s</li>
|
||||
<li>750 kB/s</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="separator"></li>
|
||||
|
|
|
@ -7,16 +7,20 @@
|
|||
|
||||
Transmission.fmt = (function()
|
||||
{
|
||||
var KB_val = 1024;
|
||||
var MB_val = 1024 * 1024;
|
||||
var GB_val = 1024 * 1024 * 1024;
|
||||
var KB_str = 'KiB';
|
||||
var MB_str = 'MiB';
|
||||
var GB_str = 'GiB';
|
||||
var speed_B_str = 'B';
|
||||
var speed_K_str = 'kB/s';
|
||||
var speed_M_str = 'MB/s';
|
||||
var speed_G_str = 'GB/s';
|
||||
|
||||
var size_B_str = 'B';
|
||||
var size_K_str = 'KiB';
|
||||
var size_M_str = 'MiB';
|
||||
var size_G_str = 'GiB';
|
||||
|
||||
return {
|
||||
MODE_IEC: 1,
|
||||
MODE_SI: 2,
|
||||
speed_K: 1000,
|
||||
|
||||
size_K: 1024,
|
||||
|
||||
/*
|
||||
* Format a percentage to a string
|
||||
|
@ -42,24 +46,6 @@ Transmission.fmt = (function()
|
|||
return this.percentString( x );
|
||||
},
|
||||
|
||||
setMode: function( mode ) {
|
||||
if( mode == MODE_IEC ) {
|
||||
this.KB_val = 1024;
|
||||
this.MB_val = this.KB_val * 1024;
|
||||
this.GB_val = this.MB_val * 1024;
|
||||
this.KB_str = 'KiB';
|
||||
this.MB_str = 'MiB';
|
||||
this.GB_str = 'GiB';
|
||||
} else {
|
||||
this.KB_val = 1000;
|
||||
this.MB_val = this.KB_val * 1000;
|
||||
this.GB_val = this.MB_val * 1000;
|
||||
this.KB_str = 'kB';
|
||||
this.MB_str = 'MB';
|
||||
this.GB_str = 'GB';
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Formats the bytes into a string value with B, KiB, MiB, or GiB units.
|
||||
*
|
||||
|
@ -68,34 +54,57 @@ Transmission.fmt = (function()
|
|||
*/
|
||||
size: function( bytes )
|
||||
{
|
||||
var size_K = this.size_K;
|
||||
var size_M = size_K * size_K;
|
||||
var size_G = size_K * size_K * size_K;
|
||||
|
||||
if( !bytes )
|
||||
return 'None';
|
||||
if( bytes < size_K )
|
||||
return bytes.toTruncFixed(0) + size_B_str;
|
||||
|
||||
if( bytes < KB_val )
|
||||
return bytes.toFixed(0) + ' B';
|
||||
if( bytes < ( size_K * 100 ) )
|
||||
return (bytes/size_K).toTruncFixed(2) + ' ' + size_K_str;
|
||||
if( bytes < size_M )
|
||||
return (bytes/size_K).toTruncFixed(1) + ' ' + size_K_str;
|
||||
|
||||
if( bytes < ( KB_val * 100 ) )
|
||||
return (bytes/KB_val).toFixed(2) + ' ' + KB_str;
|
||||
if( bytes < MB_val )
|
||||
return (bytes/KB_val).toFixed(1) + ' ' + KB_str;
|
||||
if( bytes < ( size_M * 100 ) )
|
||||
return (bytes/size_M).toTruncFixed(2) + ' ' + size_M_str;
|
||||
if( bytes < size_G )
|
||||
return (bytes/size_M).toTruncFixed(1) + ' ' + size_M_str;
|
||||
|
||||
if( bytes < ( MB_val * 100 ) )
|
||||
return (bytes/MB_val).toFixed(2) + ' ' + MB_str;
|
||||
if( bytes < GB_val )
|
||||
return (bytes/MB_val).toFixed(1) + ' ' + MB_str;
|
||||
|
||||
if( bytes < ( GB_val * 100 ) )
|
||||
return (bytes/GB_val).toFixed(2) + ' ' + GB_str;
|
||||
if( bytes < ( size_G * 100 ) )
|
||||
return (bytes/size_G).toTruncFixed(2) + ' ' + size_G_str;
|
||||
else
|
||||
return (bytes/GB_val).toFixed(1) + ' ' + GB_str;
|
||||
return (bytes/size_G).toTruncFixed(1) + ' ' + size_G_str;
|
||||
},
|
||||
|
||||
speed: function( bytes )
|
||||
{
|
||||
if( !bytes )
|
||||
var speed_K = this.speed_K;
|
||||
var speed_M = speed_K * speed_K;
|
||||
var speed_G = speed_K * speed_K * speed_K;
|
||||
|
||||
if( bytes==undefined || bytes==0 )
|
||||
return 'None';
|
||||
|
||||
if( bytes < speed_K )
|
||||
return bytes.toTruncFixed(0) + ' ' + speed_B_str;
|
||||
|
||||
if( bytes < ( speed_K * 100 ) )
|
||||
return (bytes/speed_K).toTruncFixed(2) + ' ' + speed_K_str;
|
||||
if( bytes < speed_M )
|
||||
return (bytes/speed_K).toTruncFixed(1) + ' ' + speed_K_str;
|
||||
|
||||
if( bytes < ( speed_M * 100 ) )
|
||||
return (bytes/speed_M).toTruncFixed(2) + ' ' + speed_M_str;
|
||||
if( bytes < speed_G )
|
||||
return (bytes/speed_M).toTruncFixed(1) + ' ' + speed_M_str;
|
||||
|
||||
if( bytes < ( speed_G * 100 ) )
|
||||
return (bytes/speed_G).toTruncFixed(2) + ' ' + speed_G_str;
|
||||
else
|
||||
return this.size( bytes ) + '/s';
|
||||
return (bytes/speed_G).toTruncFixed(1) + ' ' + speed_G_str;
|
||||
},
|
||||
|
||||
timeInterval: function( seconds )
|
||||
|
|
|
@ -640,20 +640,26 @@ Transmission.prototype =
|
|||
tr.togglePeriodicRefresh( true );
|
||||
}
|
||||
|
||||
var speed_K = Transmission.fmt.speed_K;
|
||||
var up_bytes = parseInt( $('#prefs_form #upload_rate' )[0].value ) * speed_K;
|
||||
var dn_bytes = parseInt( $('#prefs_form #download_rate')[0].value ) * speed_K;
|
||||
var turtle_up_bytes = parseInt( $('#prefs_form #turtle_upload_rate' )[0].value ) * speed_K;
|
||||
var turtle_dn_bytes = parseInt( $('#prefs_form #turtle_download_rate')[0].value ) * speed_K;
|
||||
|
||||
// pass the new prefs upstream to the RPC server
|
||||
var o = { };
|
||||
o[RPC._StartAddedTorrent] = $('#prefs_form #auto_start')[0].checked;
|
||||
o[RPC._PeerPort] = parseInt( $('#prefs_form #port')[0].value );
|
||||
o[RPC._UpSpeedLimit] = parseInt( $('#prefs_form #upload_rate')[0].value );
|
||||
o[RPC._DownSpeedLimit] = parseInt( $('#prefs_form #download_rate')[0].value );
|
||||
o[RPC._UpSpeedLimit] = up_bytes;
|
||||
o[RPC._DownSpeedLimit] = dn_bytes;
|
||||
o[RPC._DownloadDir] = $('#prefs_form #download_location')[0].value;
|
||||
o[RPC._UpSpeedLimited] = $('#prefs_form #limit_upload')[0].checked;
|
||||
o[RPC._UpSpeedLimited] = $('#prefs_form #limit_upload' )[0].checked;
|
||||
o[RPC._DownSpeedLimited] = $('#prefs_form #limit_download')[0].checked;
|
||||
o[RPC._Encryption] = $('#prefs_form #encryption')[0].checked
|
||||
? RPC._EncryptionRequired
|
||||
: RPC._EncryptionPreferred;
|
||||
o[RPC._TurtleDownSpeedLimit] = parseInt( $('#prefs_form #turtle_download_rate')[0].value );
|
||||
o[RPC._TurtleUpSpeedLimit] = parseInt( $('#prefs_form #turtle_upload_rate')[0].value );
|
||||
o[RPC._TurtleDownSpeedLimit] = turtle_dn_bytes;
|
||||
o[RPC._TurtleUpSpeedLimit] = turtle_up_bytes;
|
||||
o[RPC._TurtleTimeEnabled] = $('#prefs_form #turtle_schedule')[0].checked;
|
||||
o[RPC._TurtleTimeBegin] = parseInt( $('#prefs_form #turtle_start_time').val() );
|
||||
o[RPC._TurtleTimeEnd] = parseInt( $('#prefs_form #turtle_end_time').val() );
|
||||
|
@ -926,22 +932,26 @@ Transmission.prototype =
|
|||
// remember them for later
|
||||
this._prefs = prefs;
|
||||
|
||||
var down_limit = prefs[RPC._DownSpeedLimit];
|
||||
var down_limited = prefs[RPC._DownSpeedLimited];
|
||||
var up_limit = prefs[RPC._UpSpeedLimit];
|
||||
var up_limited = prefs[RPC._UpSpeedLimited];
|
||||
var up_limited = prefs[RPC._UpSpeedLimited];
|
||||
var dn_limited = prefs[RPC._DownSpeedLimited];
|
||||
var up_limit_b = prefs[RPC._UpSpeedLimit];
|
||||
var dn_limit_b = prefs[RPC._DownSpeedLimit];
|
||||
var up_limit_k = up_limit_b / Transmission.fmt.speed_K;
|
||||
var dn_limit_k = dn_limit_b / Transmission.fmt.speed_K;
|
||||
var turtle_up_limit_k = prefs[RPC._TurtleUpSpeedLimit] / Transmission.fmt.speed_K;
|
||||
var turtle_dn_limit_k = prefs[RPC._TurtleDownSpeedLimit] / Transmission.fmt.speed_K;
|
||||
|
||||
$('div.download_location input')[0].value = prefs[RPC._DownloadDir];
|
||||
$('div.port input')[0].value = prefs[RPC._PeerPort];
|
||||
$('div.auto_start input')[0].checked = prefs[RPC._StartAddedTorrent];
|
||||
$('input#limit_download')[0].checked = down_limited;
|
||||
$('input#download_rate')[0].value = down_limit;
|
||||
$('input#limit_download')[0].checked = dn_limited;
|
||||
$('input#download_rate')[0].value = dn_limit_k;
|
||||
$('input#limit_upload')[0].checked = up_limited;
|
||||
$('input#upload_rate')[0].value = up_limit;
|
||||
$('input#upload_rate')[0].value = up_limit_k;
|
||||
$('input#refresh_rate')[0].value = prefs[Prefs._RefreshRate];
|
||||
$('div.encryption input')[0].checked = prefs[RPC._Encryption] == RPC._EncryptionRequired;
|
||||
$('input#turtle_download_rate')[0].value = prefs[RPC._TurtleDownSpeedLimit];
|
||||
$('input#turtle_upload_rate')[0].value = prefs[RPC._TurtleUpSpeedLimit];
|
||||
$('input#turtle_download_rate')[0].value = turtle_dn_limit_k;
|
||||
$('input#turtle_upload_rate')[0].value = turtle_up_limit_k;
|
||||
$('input#turtle_schedule')[0].checked = prefs[RPC._TurtleTimeEnabled];
|
||||
$('select#turtle_start_time').val( prefs[RPC._TurtleTimeBegin] );
|
||||
$('select#turtle_end_time').val( prefs[RPC._TurtleTimeEnd] );
|
||||
|
@ -950,12 +960,12 @@ Transmission.prototype =
|
|||
|
||||
if (!iPhone)
|
||||
{
|
||||
setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + Transmission.fmt.speed(down_limit) + ')' );
|
||||
var key = down_limited ? '#limited_download_rate'
|
||||
setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + Transmission.fmt.speed(dn_limit_b) + ')' );
|
||||
var key = dn_limited ? '#limited_download_rate'
|
||||
: '#unlimited_download_rate';
|
||||
$(key).deselectMenuSiblings().selectMenuItem();
|
||||
|
||||
setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + Transmission.fmt.speed(up_limit) + ')' );
|
||||
setInnerHTML( $('#limited_upload_rate')[0], 'Limit (' + Transmission.fmt.speed(up_limit_b) + ')' );
|
||||
key = up_limited ? '#limited_upload_rate'
|
||||
: '#unlimited_upload_rate';
|
||||
$(key).deselectMenuSiblings().selectMenuItem();
|
||||
|
@ -1064,15 +1074,16 @@ Transmission.prototype =
|
|||
// Limit the download rate
|
||||
case 'footer_download_rate_menu':
|
||||
var args = { };
|
||||
var rate = ($element[0].innerHTML).replace(/[^0-9]/ig, '');
|
||||
if ($element.is('#unlimited_download_rate')) {
|
||||
$element.deselectMenuSiblings().selectMenuItem();
|
||||
args[RPC._DownSpeedLimited] = false;
|
||||
} else {
|
||||
setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + Transmission.fmt.speed(rate) + ')' );
|
||||
var rate_str = ($element[0].innerHTML).replace(/[^0-9]/ig, '');
|
||||
var rate_b = parseInt( rate_str ) * Transmission.fmt.speed_K;
|
||||
setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + Transmission.fmt.speed(rate_b) + ')' );
|
||||
$('#limited_download_rate').deselectMenuSiblings().selectMenuItem();
|
||||
$('div.preference input#download_rate')[0].value = rate;
|
||||
args[RPC._DownSpeedLimit] = parseInt( rate );
|
||||
$('div.preference input#download_rate')[0].value = rate_str;
|
||||
args[RPC._DownSpeedLimit] = rate_b;
|
||||
args[RPC._DownSpeedLimited] = true;
|
||||
}
|
||||
$('div.preference input#limit_download')[0].checked = args[RPC._DownSpeedLimited];
|
||||
|
@ -1082,15 +1093,16 @@ Transmission.prototype =
|
|||
// Limit the upload rate
|
||||
case 'footer_upload_rate_menu':
|
||||
var args = { };
|
||||
var rate = ($element[0].innerHTML).replace(/[^0-9]/ig, '');
|
||||
if ($element.is('#unlimited_upload_rate')) {
|
||||
$element.deselectMenuSiblings().selectMenuItem();
|
||||
args[RPC._UpSpeedLimited] = false;
|
||||
} else {
|
||||
setInnerHTML( $('#limited_upload_rate')[0], 'Limit (' + Transmission.fmt.speed(rate) + ')' );
|
||||
var rate_str = ($element[0].innerHTML).replace(/[^0-9]/ig, '');
|
||||
var rate_b = parseInt( rate_str ) * Transmission.fmt.speed_K;
|
||||
setInnerHTML( $('#limited_upload_rate')[0], 'Limit (' + Transmission.fmt.speed(rate_b) + ')' );
|
||||
$('#limited_upload_rate').deselectMenuSiblings().selectMenuItem();
|
||||
$('div.preference input#upload_rate')[0].value = rate;
|
||||
args[RPC._UpSpeedLimit] = parseInt( rate );
|
||||
$('div.preference input#upload_rate')[0].value = rate_str;
|
||||
args[RPC._UpSpeedLimit] = rate_b;
|
||||
args[RPC._UpSpeedLimited] = true;
|
||||
}
|
||||
$('div.preference input#limit_upload')[0].checked = args[RPC._UpSpeedLimited];
|
||||
|
|
Loading…
Reference in New Issue