Changeset 10931
- Timestamp:
- Jul 3, 2010, 12:25:22 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 55 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cli/cli.c
r10783 r10931 36 36 #include <libtransmission/web.h> /* tr_webRun */ 37 37 38 /*** 39 **** 40 ***/ 41 42 #define MEM_K 1024 43 #define MEM_B_STR "B" 44 #define MEM_K_STR "KiB" 45 #define MEM_M_STR "MiB" 46 #define MEM_G_STR "GiB" 47 48 #define DISK_K 1000 49 #define DISK_B_STR "B" 50 #define DISK_K_STR "kB" 51 #define DISK_M_STR "MB" 52 #define DISK_G_STR "GB" 53 54 #define SPEED_K 1000 55 #define SPEED_B_STR "B/s" 56 #define SPEED_K_STR "kB/s" 57 #define SPEED_M_STR "MB/s" 58 #define SPEED_G_STR "GB/s" 59 60 /*** 61 **** 62 ***/ 63 38 64 #define LINEWIDTH 80 39 65 #define MY_NAME "transmissioncli" 40 66 41 static tr_bool verify = 0;67 static tr_bool verify = 0; 42 68 static sig_atomic_t gotsig = 0; 43 69 static sig_atomic_t manualUpdate = 0; … … 47 73 static const struct tr_option options[] = 48 74 { 49 { 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL 50 { 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL 51 { 'd', "downlimit", "Set max download speed in KiB/s", "d", 1, "<speed>"},52 { 'D', "no-downlimit", "Don't limit the download speed", "D", 0, NULL 53 { 910, "encryption-required", "Encrypt all peer connections", "er", 0, NULL 54 { 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", 0, NULL 55 { 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", 0, NULL 75 { 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL }, 76 { 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL }, 77 { 'd', "downlimit", "Set max download speed in "SPEED_K_STR, "d", 1, "<speed>" }, 78 { 'D', "no-downlimit", "Don't limit the download speed", "D", 0, NULL }, 79 { 910, "encryption-required", "Encrypt all peer connections", "er", 0, NULL }, 80 { 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", 0, NULL }, 81 { 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", 0, NULL }, 56 82 { 'f', "finish", "Run a script when the torrent finishes", "f", 1, "<script>" }, 57 83 { 'g', "config-dir", "Where to find configuration files", "g", 1, "<path>" }, 58 { 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", 0, NULL 59 { 'M', "no-portmap", "Disable portmapping", "M", 0, NULL 84 { 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", 0, NULL }, 85 { 'M', "no-portmap", "Disable portmapping", "M", 0, NULL }, 60 86 { 'p', "port", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "p", 1, "<port>" }, 61 87 { 't', "tos", "Peer socket TOS (0 to 255, default=" TR_DEFAULT_PEER_SOCKET_TOS_STR ")", "t", 1, "<tos>" }, 62 { 'u', "uplimit", "Set max upload speed in KiB/s", "u", 1, "<speed>" },88 { 'u', "uplimit", "Set max upload speed in "SPEED_K_STR, "u", 1, "<speed>" }, 63 89 { 'U', "no-uplimit", "Don't limit the upload speed", "U", 0, NULL }, 64 90 { 'v', "verify", "Verify the specified torrent", "v", 0, NULL }, … … 128 154 else if( st->activity & TR_STATUS_DOWNLOAD ) 129 155 { 156 char upStr[80]; 157 char dnStr[80]; 130 158 char ratioStr[80]; 159 160 tr_formatter_speed( upStr, st->pieceUploadSpeed_Bps, sizeof( upStr ) ); 161 tr_formatter_speed( dnStr, st->pieceDownloadSpeed_Bps, sizeof( dnStr ) ); 131 162 tr_strlratio( ratioStr, st->ratio, sizeof( ratioStr ) ); 132 tr_snprintf( 133 buf, buflen, 134 "Progress: %.1f%%, dl from %d of %d peers (%.0f KiB/s), " 135 "ul to %d (%.0f KiB/s) [%s]", 163 164 tr_snprintf( buf, buflen, 165 "Progress: %.1f%%, " 166 "dl from %d of %d peers (%s), " 167 "ul to %d (%s) " 168 "[%s]", 136 169 tr_truncd( 100 * st->percentDone, 1 ), 137 st->peersSendingToUs, 138 st->peersConnected, 139 st->pieceDownloadSpeed, 140 st->peersGettingFromUs, 141 st->pieceUploadSpeed, 170 st->peersSendingToUs, st->peersConnected, upStr, 171 st->peersGettingFromUs, dnStr, 142 172 ratioStr ); 143 173 } 144 174 else if( st->activity & TR_STATUS_SEED ) 145 175 { 176 char upStr[80]; 146 177 char ratioStr[80]; 178 179 tr_formatter_speed( upStr, st->pieceUploadSpeed_Bps, sizeof( upStr ) ); 147 180 tr_strlratio( ratioStr, st->ratio, sizeof( ratioStr ) ); 148 tr_snprintf( 149 buf, buflen, 150 "Seeding, uploading to %d of %d peer(s), %.0f KiB/s [%s]", 151 st->peersGettingFromUs, st->peersConnected, 152 st->pieceUploadSpeed, ratioStr ); 181 182 tr_snprintf( buf, buflen, 183 "Seeding, uploading to %d of %d peer(s), %s [%s]", 184 st->peersGettingFromUs, st->peersConnected, upStr, ratioStr ); 153 185 } 154 186 else *buf = '\0'; … … 179 211 180 212 int 181 main( int argc, 182 char ** argv ) 213 main( int argc, char ** argv ) 183 214 { 184 215 int error; … … 190 221 uint8_t * fileContents; 191 222 size_t fileLength; 223 224 tr_formatter_mem_init( MEM_K, MEM_B_STR, MEM_K_STR, MEM_M_STR, MEM_G_STR ); 225 tr_formatter_size_init( DISK_K,DISK_B_STR, DISK_K_STR, DISK_M_STR, DISK_G_STR ); 226 tr_formatter_speed_init( SPEED_K, SPEED_B_STR, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR ); 192 227 193 228 printf( "Transmission %s - http://www.transmissionbt.com/\n", … … 324 359 case 'B': tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, FALSE ); 325 360 break; 326 case 'd': tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED , atoi( optarg ));361 case 'd': tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_Bps, atoi( optarg ) * SPEED_K ); 327 362 tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, TRUE ); 328 363 break; … … 342 377 case 't': tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_SOCKET_TOS, atoi( optarg ) ); 343 378 break; 344 case 'u': tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED , atoi( optarg ));379 case 'u': tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_Bps, atoi( optarg ) * SPEED_K ); 345 380 tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, TRUE ); 346 381 break; -
trunk/daemon/remote.c
r10907 r10931 44 44 #define ARGUMENTS "arguments" 45 45 46 #define MEM_K 1024 47 #define MEM_B_STR "B" 48 #define MEM_K_STR "KiB" 49 #define MEM_M_STR "MiB" 50 #define MEM_G_STR "GiB" 51 52 #define DISK_K 1000 53 #define DISK_B_STR "B" 54 #define DISK_K_STR "kB" 55 #define DISK_M_STR "MB" 56 #define DISK_G_STR "GB" 57 58 #define SPEED_K 1000 59 #define SPEED_B_STR "B/s" 60 #define SPEED_K_STR "kB/s" 61 #define SPEED_M_STR "MB/s" 62 #define SPEED_G_STR "GB/s" 63 46 64 /*** 47 65 **** … … 110 128 } 111 129 112 static const double KiB = 1024.0;113 static const double MiB = 1024.0 * 1024.0;114 static const double GiB = 1024.0 * 1024.0 * 1024.0;115 116 130 static char* 117 131 strlpercent( char * buf, double x, size_t buflen ) … … 142 156 143 157 static char* 158 strlmem( char * buf, int64_t bytes, size_t buflen ) 159 { 160 if( !bytes ) 161 tr_strlcpy( buf, "None", buflen ); 162 else 163 tr_formatter_mem( buf, bytes, buflen ); 164 165 return buf; 166 } 167 168 static char* 144 169 strlsize( char * buf, int64_t bytes, size_t buflen ) 145 170 { 146 171 if( !bytes ) 147 tr_strlcpy( buf, _( "None" ), buflen );172 tr_strlcpy( buf, "None", buflen ); 148 173 else 149 174 tr_formatter_size( buf, bytes, buflen ); … … 156 181 { 157 182 if( !bytes_per_second ) 158 tr_strlcpy( buf, _( "None" ), buflen );183 tr_strlcpy( buf, "None", buflen ); 159 184 else 160 185 tr_formatter_speed( buf, bytes_per_second, buflen ); … … 194 219 { 970, "alt-speed", "Use the alternate Limits", "as", 0, NULL }, 195 220 { 971, "no-alt-speed", "Don't use the alternate Limits", "AS", 0, NULL }, 196 { 972, "alt-speed-downlimit", "max alternate download speed (in KiB/s)", "asd", 1, "<speed>" },197 { 973, "alt-speed-uplimit", "max alternate upload speed (in KiB/s)", "asu", 1, "<speed>" },221 { 972, "alt-speed-downlimit", "max alternate download speed (in "SPEED_K_STR")", "asd", 1, "<speed>" }, 222 { 973, "alt-speed-uplimit", "max alternate upload speed (in "SPEED_K_STR")", "asu", 1, "<speed>" }, 198 223 { 974, "alt-speed-scheduler", "Use the scheduled on/off times", "asc", 0, NULL }, 199 224 { 975, "no-alt-speed-scheduler", "Don't use the scheduled on/off times", "ASC", 0, NULL }, … … 205 230 { 'C', "no-incomplete-dir", "Don't store incomplete torrents in a different location", "C", 0, NULL }, 206 231 { 'b', "debug", "Print debugging information", "b", 0, NULL }, 207 { 'd', "downlimit", "Set the max download speed in KiB/sfor the current torrent(s) or globally", "d", 1, "<speed>" },232 { 'd', "downlimit", "Set the max download speed in "SPEED_K_STR" for the current torrent(s) or globally", "d", 1, "<speed>" }, 208 233 { 'D', "no-downlimit", "Disable max download speed for the current torrent(s) or globally", "D", 0, NULL }, 209 { 'e', "cache", "Set the maximum size of the session's memory cache (in MiB)", "e", 1, "<size>" },234 { 'e', "cache", "Set the maximum size of the session's memory cache (in " MEM_M_STR ")", "e", 1, "<size>" }, 210 235 { 910, "encryption-required", "Encrypt all peer connections", "er", 0, NULL }, 211 236 { 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", 0, NULL }, … … 256 281 { 984, "honor-session", "Make the current torrent(s) honor the session limits", "hl", 0, NULL }, 257 282 { 985, "no-honor-session", "Make the current torrent(s) not honor the session limits", "HL", 0, NULL }, 258 { 'u', "uplimit", "Set the max upload speed in KiB/sfor the current torrent(s) or globally", "u", 1, "<speed>" },283 { 'u', "uplimit", "Set the max upload speed in "SPEED_K_STR" for the current torrent(s) or globally", "u", 1, "<speed>" }, 259 284 { 'U', "no-uplimit", "Disable max upload speed for the current torrent(s) or globally", "U", 0, NULL }, 260 285 { 'v', "verify", "Verify the current torrent(s)", "v", 0, NULL }, … … 1073 1098 printf( " Piece Count: %" PRId64 "\n", i ); 1074 1099 if( tr_bencDictFindInt( t, "pieceSize", &i ) ) 1075 printf( " Piece Size: % " PRId64 "\n", i);1100 printf( " Piece Size: %s\n", strlmem( buf, i, sizeof( buf ) ) ); 1076 1101 printf( "\n" ); 1077 1102 … … 1082 1107 printf( " Download Limit: " ); 1083 1108 if( boolVal ) 1084 printf( "%s\n", strlspeed( buf, i *1024, sizeof( buf ) ) );1109 printf( "%s\n", strlspeed( buf, i, sizeof( buf ) ) ); 1085 1110 else 1086 1111 printf( "Unlimited\n" ); … … 1091 1116 printf( " Upload Limit: " ); 1092 1117 if( boolVal ) 1093 printf( "%s\n", strlspeed( buf, i *1024, sizeof( buf ) ) );1118 printf( "%s\n", strlspeed( buf, i, sizeof( buf ) ) ); 1094 1119 else 1095 1120 printf( "Unlimited\n" ); … … 1216 1241 printf( "%-20s %-12s %-5.1f %6.1f %6.1f %s\n", 1217 1242 address, flagstr, (progress*100.0), 1218 rateToClient / 1024.0,1219 rateToPeer / 1024.0,1243 rateToClient / (double)SPEED_K, 1244 rateToPeer / (double)SPEED_K, 1220 1245 client ); 1221 1246 } … … 1319 1344 haveStr, 1320 1345 etaStr, 1321 up / 1024.0,1322 down / 1024.0,1346 up / (double)SPEED_K, 1347 down / (double)SPEED_K, 1323 1348 strlratio2( ratioStr, ratio, sizeof( ratioStr ) ), 1324 1349 getStatusString( d, statusStr, sizeof( statusStr ) ), … … 1333 1358 printf( "Sum: %9s %6.1f %6.1f\n", 1334 1359 strlsize( haveStr, total_size, sizeof( haveStr ) ), 1335 total_up / 1024.0,1336 total_down / 1024.0);1360 total_up / (double)SPEED_K, 1361 total_down / (double)SPEED_K ); 1337 1362 } 1338 1363 } … … 1344 1369 if( ( tr_bencDictFindDict( top, "arguments", &args ) ) ) 1345 1370 { 1346 double d; 1371 int64_t i; 1372 char buf[64]; 1373 tr_bool boolVal; 1347 1374 const char * str; 1348 int64_t i;1349 tr_bool boolVal;1350 char buf[64];1351 1375 1352 1376 printf( "VERSION\n" ); … … 1376 1400 if( tr_bencDictFindStr( args, TR_PREFS_KEY_ENCRYPTION, &str ) ) 1377 1401 printf( " Encryption: %s\n", str ); 1378 if( tr_bencDictFind Real( args, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, &d) )1379 printf( " Maximum memory cache size: %s\n", strlsize( buf, d*MiB, sizeof( buf ) ) );1402 if( tr_bencDictFindInt( args, TR_PREFS_KEY_MAX_CACHE_SIZE, &i ) ) 1403 printf( " Maximum memory cache size: %s\n", strlsize( buf, i, sizeof( buf ) ) ); 1380 1404 printf( "\n" ); 1381 1405 … … 1385 1409 double seedRatioLimit; 1386 1410 1387 if( tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_DOWN , &altDown ) &&1411 if( tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, &altDown ) && 1388 1412 tr_bencDictFindBool( args, TR_PREFS_KEY_ALT_SPEED_ENABLED, &altEnabled ) && 1389 1413 tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &altBegin ) && … … 1391 1415 tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_TIME_END, &altEnd ) && 1392 1416 tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, &altDay ) && 1393 tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_UP , &altUp ) &&1417 tr_bencDictFindInt ( args, TR_PREFS_KEY_ALT_SPEED_UP_Bps, &altUp ) && 1394 1418 tr_bencDictFindInt ( args, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &peerLimit ) && 1395 tr_bencDictFindInt ( args, TR_PREFS_KEY_DSPEED , &downLimit ) &&1419 tr_bencDictFindInt ( args, TR_PREFS_KEY_DSPEED_Bps, &downLimit ) && 1396 1420 tr_bencDictFindBool( args, TR_PREFS_KEY_DSPEED_ENABLED, &downEnabled ) && 1397 tr_bencDictFindInt ( args, TR_PREFS_KEY_USPEED , &upLimit ) &&1421 tr_bencDictFindInt ( args, TR_PREFS_KEY_USPEED_Bps, &upLimit ) && 1398 1422 tr_bencDictFindBool( args, TR_PREFS_KEY_USPEED_ENABLED, &upEnabled ) && 1399 1423 tr_bencDictFindReal( args, "seedRatioLimit", &seedRatioLimit ) && … … 1414 1438 1415 1439 if( altEnabled ) 1416 strlspeed( buf, altUp *1024, sizeof( buf ) );1440 strlspeed( buf, altUp, sizeof( buf ) ); 1417 1441 else if( upEnabled ) 1418 strlspeed( buf, upLimit *1024, sizeof( buf ) );1442 strlspeed( buf, upLimit, sizeof( buf ) ); 1419 1443 else 1420 1444 tr_strlcpy( buf, "Unlimited", sizeof( buf ) ); … … 1422 1446 buf, 1423 1447 upEnabled ? "Enabled" : "Disabled", 1424 strlspeed( buf2, upLimit *1024, sizeof( buf2 ) ),1448 strlspeed( buf2, upLimit, sizeof( buf2 ) ), 1425 1449 altEnabled ? "Enabled" : "Disabled", 1426 strlspeed( buf3, altUp *1024, sizeof( buf3 ) ) );1450 strlspeed( buf3, altUp, sizeof( buf3 ) ) ); 1427 1451 1428 1452 if( altEnabled ) 1429 strlspeed( buf, altDown *1024, sizeof( buf ) );1453 strlspeed( buf, altDown, sizeof( buf ) ); 1430 1454 else if( downEnabled ) 1431 strlspeed( buf, downLimit *1024, sizeof( buf ) );1455 strlspeed( buf, downLimit, sizeof( buf ) ); 1432 1456 else 1433 1457 tr_strlcpy( buf, "Unlimited", sizeof( buf ) ); … … 1435 1459 buf, 1436 1460 downEnabled ? "Enabled" : "Disabled", 1437 strlspeed( buf2, downLimit *1024, sizeof( buf2 ) ),1461 strlspeed( buf2, downLimit, sizeof( buf2 ) ), 1438 1462 altEnabled ? "Enabled" : "Disabled", 1439 strlspeed( buf2, altDown *1024, sizeof( buf2 ) ) );1463 strlspeed( buf2, altDown, sizeof( buf2 ) ) ); 1440 1464 1441 1465 if( altTimeEnabled ) { … … 1822 1846 case 971: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_ENABLED, FALSE ); 1823 1847 break; 1824 case 972: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_DOWN , numarg( optarg ));1825 break; 1826 case 973: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_UP , numarg( optarg ));1848 case 972: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, numarg( optarg ) * SPEED_K ); 1849 break; 1850 case 973: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_UP_Bps, numarg( optarg ) * SPEED_K ); 1827 1851 break; 1828 1852 case 974: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, TRUE ); … … 1841 1865 case 'C': tr_bencDictAddBool( args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, FALSE ); 1842 1866 break; 1843 case 'e': tr_bencDictAddReal( args, TR_PREFS_KEY_MAX_CACHE_SIZE _MiB, atof(optarg));1867 case 'e': tr_bencDictAddReal( args, TR_PREFS_KEY_MAX_CACHE_SIZE, atof(optarg) * MEM_K * MEM_K ); 1844 1868 break; 1845 1869 case 910: tr_bencDictAddStr( args, TR_PREFS_KEY_ENCRYPTION, "required" ); … … 1899 1923 { 1900 1924 case 'd': if( targs ) { 1901 tr_bencDictAddInt( targs, "downloadLimit", numarg( optarg ) );1925 tr_bencDictAddInt( targs, "downloadLimit", numarg( optarg ) * SPEED_K ); 1902 1926 tr_bencDictAddBool( targs, "downloadLimited", TRUE ); 1903 1927 } else { 1904 tr_bencDictAddInt( sargs, TR_PREFS_KEY_DSPEED , numarg( optarg ));1928 tr_bencDictAddInt( sargs, TR_PREFS_KEY_DSPEED_Bps, numarg( optarg ) * SPEED_K ); 1905 1929 tr_bencDictAddBool( sargs, TR_PREFS_KEY_DSPEED_ENABLED, TRUE ); 1906 1930 } … … 1912 1936 break; 1913 1937 case 'u': if( targs ) { 1914 tr_bencDictAddInt( targs, "uploadLimit", numarg( optarg ) );1938 tr_bencDictAddInt( targs, "uploadLimit", numarg( optarg ) * SPEED_K ); 1915 1939 tr_bencDictAddBool( targs, "uploadLimited", TRUE ); 1916 1940 } else { 1917 tr_bencDictAddInt( sargs, TR_PREFS_KEY_USPEED , numarg( optarg ));1941 tr_bencDictAddInt( sargs, TR_PREFS_KEY_USPEED_Bps, numarg( optarg ) * SPEED_K ); 1918 1942 tr_bencDictAddBool( sargs, TR_PREFS_KEY_USPEED_ENABLED, TRUE ); 1919 1943 } … … 2187 2211 } 2188 2212 2189 tr_formatter_size_init ( 1024, "B", "KiB", "MiB", "GiB" ); 2190 tr_formatter_speed_init ( 1024, "B/s", "KiB/s", "MiB/s", "GiB/s" ); 2213 tr_formatter_mem_init( MEM_K, MEM_B_STR, MEM_K_STR, MEM_M_STR, MEM_G_STR ); 2214 tr_formatter_size_init( DISK_K,DISK_B_STR, DISK_K_STR, DISK_M_STR, DISK_G_STR ); 2215 tr_formatter_speed_init( SPEED_K, SPEED_B_STR, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR ); 2191 2216 2192 2217 getHostAndPort( &argc, argv, &host, &port ); -
trunk/doc/rpc-spec.txt
r10906 r10931 90 90 ----------------------+------------------------------------------------- 91 91 "bandwidthPriority" | number this torrent's bandwidth tr_priority_t 92 "downloadLimit" | number maximum download speed ( in K/s)92 "downloadLimit" | number maximum download speed (bytes per second) 93 93 "downloadLimited" | boolean true if "downloadLimit" is honored 94 94 "files-wanted" | array indices of file(s) to download … … 106 106 "trackerEdit" | object (see below) 107 107 "trackerRemove" | object (see below) 108 "uploadLimit" | number maximum upload speed ( in K/s)108 "uploadLimit" | number maximum upload speed (bytes per second) 109 109 "uploadLimited" | boolean true if "uploadLimit" is honored 110 110 | … … 151 151 a "removed" array of torrent-id numbers of recently-removed 152 152 torrents. 153 154 Note: For more information on what these fields mean, see the comments 155 in libtransmission/transmission.h. The "source" column here 156 corresponds to the data structure there. 153 157 154 158 key | type | source … … 415 419 string | value type & description 416 420 ------------------------------+------------------------------------------------- 417 "alt-speed-down" | number max global download speed (in K/s)421 "alt-speed-down" | number max global download speed (in bytes per second) 418 422 "alt-speed-enabled" | boolean true means use the alt speeds 419 423 "alt-speed-time-begin" | number when to turn on alt speeds (units: minutes after midnight) … … 421 425 "alt-speed-time-end" | number when to turn off alt speeds (units: same) 422 426 "alt-speed-time-day" | number what day(s) to turn on alt speeds (look at tr_sched_day) 423 "alt-speed-up" | number max global upload speed (in K/s)427 "alt-speed-up" | number max global upload speed (in bytes per second) 424 428 "blocklist-enabled" | boolean true means enabled 425 429 "blocklist-size" | number number of rules in the blocklist 426 "cache-size -MiB" | number size (in MiB) of the disk cache430 "cache-size" | number maximum size (in bytes) of the disk cache 427 431 "config-dir" | string location of transmission's configuration directory 428 432 "download-dir" | string default path to download torrents … … 445 449 "seedRatioLimit" | double the default seed ratio for torrents to use 446 450 "seedRatioLimited" | boolean true if seedRatioLimit is honored by default 447 "speed-limit-down" | number max global download speed (in K/s)451 "speed-limit-down" | number max global download speed (in bytes per second) 448 452 "speed-limit-down-enabled" | boolean true means enabled 449 "speed-limit-up" | number max global upload speed (in K/s)453 "speed-limit-up" | number max global upload speed (in bytes per second) 450 454 "speed-limit-up-enabled" | boolean true means enabled 451 455 "start-added-torrents" | boolean true means added torrents will be started right away … … 620 624 ------+---------+-----------+----------------+------------------------------- 621 625 9 | 2.00 | yes | session-set | new arg "start-added-torrents" 622 | 2.00 | yes | session-set | new arg "trash-original-torrent-files" 623 | 2.00 | yes | session-get | new arg "start-added-torrents" 624 | 2.00 | yes | session-get | new arg "trash-original-torrent-files" 625 | 2.00 | yes | session-get | new arg "cache-size-MiB" 626 | 2.00 | yes | torrent-get | new arg "isFinished" 627 ------+---------+-----------+----------------+------------------------------- 628 10 | 2.10 | yes | torrent-set | new arg "trackerAdd" 629 | 2.10 | yes | torrent-set | new arg "trackerEdit" 630 | 2.10 | yes | torrent-set | new arg "trackerRemove" 626 | | yes | session-set | new arg "trash-original-torrent-files" 627 | | yes | session-get | new arg "start-added-torrents" 628 | | yes | session-get | new arg "trash-original-torrent-files" 629 | | yes | torrent-get | new arg "isFinished" 630 ------+---------+-----------+----------------+------------------------------- 631 10 | 2.10 | NO | torrent-get | arg "downloadLimit" is now bytes per second 632 | | NO | torrent-get | arg "uploadLimit" is now bytes per second 633 | | NO | session-get | arg "speed-limit-down" is now bytes per second 634 | | NO | session-get | arg "speed-limit-up" is now bytes per second 635 | | NO | session-get | arg "alt-speed-up" is now bytes per second 636 | | NO | session-get | arg "alt-speed-down" is now bytes per second 637 | | yes | session-get | new arg "cache-size" 638 | | yes | session-set | new arg "trash-original-torrent-files" 639 | | yes | session-get | new arg "start-added-torrents" 640 | | yes | session-get | new arg "trash-original-torrent-files" 641 | | yes | torrent-get | new arg "isFinished" 642 | | yes | torrent-set | new arg "trackerAdd" 643 | | yes | torrent-set | new arg "trackerEdit" 644 | | yes | torrent-set | new arg "trackerRemove" -
trunk/gtk/details.c
r10889 r10931 220 220 /* downLimitSpin */ 221 221 if( n ) { 222 const int baseline = tr_torrentGetSpeedLimit ( torrents[0], TR_DOWN );222 const int baseline = tr_torrentGetSpeedLimit_Bps( torrents[0], TR_DOWN ) / speed_K; 223 223 int i; 224 224 for( i=1; i<n; ++i ) 225 if( baseline != tr_torrentGetSpeedLimit( torrents[i], TR_DOWN) )225 if( baseline != ( tr_torrentGetSpeedLimit_Bps( torrents[i], TR_DOWN ) / speed_K ) ) 226 226 break; 227 227 if( i == n ) … … 244 244 /* upLimitSpin */ 245 245 if( n ) { 246 const int baseline = tr_torrentGetSpeedLimit ( torrents[0], TR_UP );246 const int baseline = tr_torrentGetSpeedLimit_Bps( torrents[0], TR_UP ) / speed_K; 247 247 int i; 248 248 for( i=1; i<n; ++i ) 249 if( baseline != tr_torrentGetSpeedLimit( torrents[i], TR_UP) )249 if( baseline != ( tr_torrentGetSpeedLimit_Bps( torrents[i], TR_UP ) / speed_K ) ) 250 250 break; 251 251 if( i == n ) … … 440 440 guint tag; 441 441 int row; 442 char buf[128]; 442 443 const char *s; 443 444 GtkWidget *t, *w, *tb, *h; … … 452 453 d->honorLimitsCheckTag = tag; 453 454 454 tb = gtk_check_button_new_with_mnemonic( _( "Limit _download speed (KiB/s):" ) ); 455 g_snprintf( buf, sizeof( buf ), _( "Limit _download speed (%s):" ), _(speed_K_str) ); 456 tb = gtk_check_button_new_with_mnemonic( buf ); 455 457 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( tb ), FALSE ); 456 458 d->downLimitedCheck = tb; … … 464 466 d->downLimitSpin = w; 465 467 466 tb = gtk_check_button_new_with_mnemonic( _( "Limit _upload speed (KiB/s):" ) ); 468 g_snprintf( buf, sizeof( buf ), _( "Limit _upload speed (%s):" ), _(speed_K_str) ); 469 tb = gtk_check_button_new_with_mnemonic( buf ); 467 470 d->upLimitedCheck = tb; 468 471 tag = g_signal_connect( tb, "toggled", G_CALLBACK( up_speed_toggled_cb ), d ); … … 759 762 else if( pieceSize >= 0 ) { 760 763 char piecebuf[128]; 761 tr_ strlsize( piecebuf, (uint64_t)pieceSize, sizeof( piecebuf ) );764 tr_formatter_mem( piecebuf, pieceSize, sizeof( piecebuf ) ); 762 765 g_snprintf( buf, sizeof( buf ), 763 766 ngettext( "%1$s (%2$'d piece @ %3$s)", … … 1042 1045 WEBSEED_COL_WAS_UPDATED, 1043 1046 WEBSEED_COL_URL, 1044 WEBSEED_COL_DOWNLOAD_RATE_ DOUBLE,1047 WEBSEED_COL_DOWNLOAD_RATE_INT, 1045 1048 WEBSEED_COL_DOWNLOAD_RATE_STRING, 1046 1049 N_WEBSEED_COLS … … 1053 1056 { 1054 1057 case WEBSEED_COL_URL: return _( "Webseeds" ); 1055 case WEBSEED_COL_DOWNLOAD_RATE_ DOUBLE:1058 case WEBSEED_COL_DOWNLOAD_RATE_INT: 1056 1059 case WEBSEED_COL_DOWNLOAD_RATE_STRING: return _( "Down" ); 1057 1060 default: return ""; … … 1066 1069 G_TYPE_BOOLEAN, /* was-updated */ 1067 1070 G_TYPE_STRING, /* url */ 1068 G_TYPE_ DOUBLE, /* download rate double*/1071 G_TYPE_INT, /* download rate int */ 1069 1072 G_TYPE_STRING ); /* download rate string */ 1070 1073 } … … 1076 1079 PEER_COL_ADDRESS, 1077 1080 PEER_COL_ADDRESS_COLLATED, 1078 PEER_COL_DOWNLOAD_RATE_ DOUBLE,1081 PEER_COL_DOWNLOAD_RATE_INT, 1079 1082 PEER_COL_DOWNLOAD_RATE_STRING, 1080 PEER_COL_UPLOAD_RATE_ DOUBLE,1083 PEER_COL_UPLOAD_RATE_INT, 1081 1084 PEER_COL_UPLOAD_RATE_STRING, 1082 1085 PEER_COL_CLIENT, … … 1106 1109 case PEER_COL_ADDRESS: return _( "Address" ); 1107 1110 case PEER_COL_DOWNLOAD_RATE_STRING: 1108 case PEER_COL_DOWNLOAD_RATE_ DOUBLE: return _( "Down" );1111 case PEER_COL_DOWNLOAD_RATE_INT: return _( "Down" ); 1109 1112 case PEER_COL_UPLOAD_RATE_STRING: 1110 case PEER_COL_UPLOAD_RATE_ DOUBLE: return _( "Up" );1113 case PEER_COL_UPLOAD_RATE_INT: return _( "Up" ); 1111 1114 case PEER_COL_CLIENT: return _( "Client" ); 1112 1115 case PEER_COL_PROGRESS: return _( "%" ); … … 1136 1139 G_TYPE_STRING, /* address */ 1137 1140 G_TYPE_STRING, /* collated address */ 1138 G_TYPE_ FLOAT, /* download speed float */1141 G_TYPE_INT, /* download speed int */ 1139 1142 G_TYPE_STRING, /* download speed string */ 1140 G_TYPE_ FLOAT, /* upload speed float */1143 G_TYPE_INT, /* upload speed int */ 1141 1144 G_TYPE_STRING, /* upload speed string */ 1142 1145 G_TYPE_STRING, /* client */ … … 1165 1168 { 1166 1169 int q[4]; 1167 char up_speed[128];1168 char down_speed[128];1169 1170 char collated_name[128]; 1170 1171 const char * client = peer->client; … … 1173 1174 client = ""; 1174 1175 1175 tr_strlspeed( up_speed, peer->rateToPeer, sizeof( up_speed ) );1176 tr_strlspeed( down_speed, peer->rateToClient, sizeof( down_speed ) );1177 1176 if( sscanf( peer->addr, "%d.%d.%d.%d", q, q+1, q+2, q+3 ) != 4 ) 1178 1177 g_strlcpy( collated_name, peer->addr, sizeof( collated_name ) ); … … 1204 1203 char cancelled_by_client[64]; 1205 1204 1206 if( peer->rateToPeer > 0.01)1207 tr_ strlspeed( up_speed, peer->rateToPeer, sizeof( up_speed ) );1205 if( peer->rateToPeer_Bps > 0 ) 1206 tr_formatter_speed( up_speed, peer->rateToPeer_Bps, sizeof( up_speed ) ); 1208 1207 else 1209 1208 *up_speed = '\0'; 1210 1209 1211 if( peer->rateToClient > 0.01)1212 tr_ strlspeed( down_speed, peer->rateToClient, sizeof( down_speed ) );1210 if( peer->rateToClient_Bps > 0 ) 1211 tr_formatter_speed( down_speed, peer->rateToClient_Bps, sizeof( down_speed ) ); 1213 1212 else 1214 1213 *down_speed = '\0'; … … 1250 1249 PEER_COL_DOWNLOAD_REQUEST_COUNT_INT, peer->pendingReqsToPeer, 1251 1250 PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING, down_count, 1252 PEER_COL_DOWNLOAD_RATE_ DOUBLE, peer->rateToClient,1251 PEER_COL_DOWNLOAD_RATE_INT, peer->rateToClient_Bps, 1253 1252 PEER_COL_DOWNLOAD_RATE_STRING, down_speed, 1254 PEER_COL_UPLOAD_RATE_ DOUBLE, peer->rateToPeer,1253 PEER_COL_UPLOAD_RATE_INT, peer->rateToPeer_Bps, 1255 1254 PEER_COL_UPLOAD_RATE_STRING, up_speed, 1256 1255 PEER_COL_STATUS, peer->flagStr, … … 1398 1397 const tr_torrent * tor = torrents[i]; 1399 1398 const tr_info * inf = tr_torrentInfo( tor ); 1400 float * speeds = tr_torrentWebSpeeds( tor );1399 int * speeds_Bps = tr_torrentWebSpeeds_Bps( tor ); 1401 1400 for( j=0; j<inf->webseedCount; ++j ) { 1402 1401 char buf[128]; … … 1409 1408 p = gtk_tree_row_reference_get_path( ref ); 1410 1409 gtk_tree_model_get_iter( model, &iter, p ); 1411 if( speeds [j] > 0.01)1412 tr_ strlspeed( buf, speeds[j], sizeof( buf ) );1410 if( speeds_Bps[j] > 0 ) 1411 tr_formatter_speed( buf, speeds_Bps[j], sizeof( buf ) ); 1413 1412 else 1414 1413 *buf = '\0'; 1415 gtk_list_store_set( store, &iter, WEBSEED_COL_DOWNLOAD_RATE_ DOUBLE, (double)speeds[j],1414 gtk_list_store_set( store, &iter, WEBSEED_COL_DOWNLOAD_RATE_INT, speeds_Bps[j], 1416 1415 WEBSEED_COL_DOWNLOAD_RATE_STRING, buf, 1417 1416 WEBSEED_COL_WAS_UPDATED, TRUE, … … 1419 1418 gtk_tree_path_free( p ); 1420 1419 } 1421 tr_free( speeds );1420 tr_free( speeds_Bps ); 1422 1421 } 1423 1422 … … 1613 1612 g_object_set( G_OBJECT( r ), "xalign", 1.0f, NULL ); 1614 1613 c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL ); 1615 sort_col = PEER_COL_DOWNLOAD_RATE_ DOUBLE;1614 sort_col = PEER_COL_DOWNLOAD_RATE_INT; 1616 1615 break; 1617 1616 case PEER_COL_UPLOAD_RATE_STRING: … … 1619 1618 g_object_set( G_OBJECT( r ), "xalign", 1.0f, NULL ); 1620 1619 c = gtk_tree_view_column_new_with_attributes( t, r, "text", col, NULL ); 1621 sort_col = PEER_COL_UPLOAD_RATE_ DOUBLE;1620 sort_col = PEER_COL_UPLOAD_RATE_INT; 1622 1621 break; 1623 1622 … … 1688 1687 r = gtk_cell_renderer_text_new( ); 1689 1688 c = gtk_tree_view_column_new_with_attributes( str, r, "text", WEBSEED_COL_DOWNLOAD_RATE_STRING, NULL ); 1690 gtk_tree_view_column_set_sort_column_id( c, WEBSEED_COL_DOWNLOAD_RATE_ DOUBLE);1689 gtk_tree_view_column_set_sort_column_id( c, WEBSEED_COL_DOWNLOAD_RATE_INT ); 1691 1690 gtk_tree_view_append_column( GTK_TREE_VIEW( v ), c ); 1692 1691 -
trunk/gtk/main.c
r10863 r10931 533 533 textdomain( domain ); 534 534 g_set_application_name( _( "Transmission" ) ); 535 tr_formatter_size_init( 1024, _("B"), _("KiB"), _("MiB"), _("GiB") ); 536 tr_formatter_speed_init( 1024, _("B/s"), _("KiB/s"), _("MiB/s"), _("GiB/s") ); 535 tr_formatter_mem_init( mem_K, _(mem_B_str), _(mem_K_str), _(mem_M_str), _(mem_G_str) ); 536 tr_formatter_size_init( disk_K, _(disk_B_str), _(disk_K_str), _(disk_M_str), _(disk_G_str) ); 537 tr_formatter_speed_init( speed_K, _(speed_B_str), _(speed_K_str), _(speed_M_str), _(speed_G_str) ); 537 538 538 539 /* initialize gtk */ … … 1203 1204 tr_sessionLimitSpeed( tr, TR_DOWN, pref_flag_get( key ) ); 1204 1205 } 1205 else if( !strcmp( key, TR_PREFS_KEY_DSPEED ) )1206 { 1207 tr_sessionSetSpeedLimit ( tr, TR_DOWN, pref_int_get( key ) );1206 else if( !strcmp( key, TR_PREFS_KEY_DSPEED_Bps ) ) 1207 { 1208 tr_sessionSetSpeedLimit_Bps( tr, TR_DOWN, pref_int_get( key ) ); 1208 1209 } 1209 1210 else if( !strcmp( key, TR_PREFS_KEY_USPEED_ENABLED ) ) … … 1211 1212 tr_sessionLimitSpeed( tr, TR_UP, pref_flag_get( key ) ); 1212 1213 } 1213 else if( !strcmp( key, TR_PREFS_KEY_USPEED ) )1214 { 1215 tr_sessionSetSpeedLimit ( tr, TR_UP, pref_int_get( key ) );1214 else if( !strcmp( key, TR_PREFS_KEY_USPEED_Bps ) ) 1215 { 1216 tr_sessionSetSpeedLimit_Bps( tr, TR_UP, pref_int_get( key ) ); 1216 1217 } 1217 1218 else if( !strcmp( key, TR_PREFS_KEY_RATIO_ENABLED ) ) … … 1299 1300 tr_sessionSetProxyPort( tr, pref_int_get( key ) ); 1300 1301 } 1301 else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_UP ) )1302 { 1303 tr_sessionSetAltSpeed ( tr, TR_UP, pref_int_get( key ) );1304 } 1305 else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN ) )1306 { 1307 tr_sessionSetAltSpeed ( tr, TR_DOWN, pref_int_get( key ) );1302 else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_UP_Bps ) ) 1303 { 1304 tr_sessionSetAltSpeed_Bps( tr, TR_UP, pref_int_get( key ) ); 1305 } 1306 else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps ) ) 1307 { 1308 tr_sessionSetAltSpeed_Bps( tr, TR_DOWN, pref_int_get( key ) ); 1308 1309 } 1309 1310 else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_ENABLED ) ) -
trunk/gtk/torrent-cell-renderer.c
r10822 r10931 155 155 getShortTransferString( const tr_torrent * tor, 156 156 const tr_stat * torStat, 157 double uploadSpeed,158 double downloadSpeed,157 int uploadSpeed_Bps, 158 int downloadSpeed_Bps, 159 159 char * buf, 160 160 size_t buflen ) … … 166 166 167 167 if( haveDown ) 168 tr_strlspeed( downStr, downloadSpeed , sizeof( downStr ) );168 tr_strlspeed( downStr, downloadSpeed_Bps, sizeof( downStr ) ); 169 169 if( haveUp ) 170 tr_strlspeed( upStr, uploadSpeed , sizeof( upStr ) );170 tr_strlspeed( upStr, uploadSpeed_Bps, sizeof( upStr ) ); 171 171 172 172 if( haveDown && haveUp ) … … 195 195 getShortStatusString( const tr_torrent * tor, 196 196 const tr_stat * torStat, 197 double uploadSpeed,198 double downloadSpeed)197 int uploadSpeed_Bps, 198 int downloadSpeed_Bps ) 199 199 { 200 200 GString * gstr = g_string_new( NULL ); … … 229 229 g_string_append( gstr, ", " ); 230 230 } 231 getShortTransferString( tor, torStat, uploadSpeed , downloadSpeed, buf, sizeof( buf ) );231 getShortTransferString( tor, torStat, uploadSpeed_Bps, downloadSpeed_Bps, buf, sizeof( buf ) ); 232 232 g_string_append( gstr, buf ); 233 233 break; … … 244 244 getStatusString( const tr_torrent * tor, 245 245 const tr_stat * torStat, 246 const double uploadSpeed,247 const double downloadSpeed)246 const int uploadSpeed_Bps, 247 const int downloadSpeed_Bps ) 248 248 { 249 249 const int isActive = torStat->activity != TR_STATUS_STOPPED; … … 266 266 case TR_STATUS_CHECK: 267 267 { 268 char * pch = getShortStatusString( tor, torStat, uploadSpeed , downloadSpeed);268 char * pch = getShortStatusString( tor, torStat, uploadSpeed_Bps, downloadSpeed_Bps ); 269 269 g_string_assign( gstr, pch ); 270 270 g_free( pch ); … … 310 310 { 311 311 char buf[256]; 312 getShortTransferString( tor, torStat, uploadSpeed , downloadSpeed, buf, sizeof( buf ) );312 getShortTransferString( tor, torStat, uploadSpeed_Bps, downloadSpeed_Bps, buf, sizeof( buf ) ); 313 313 if( *buf ) 314 314 g_string_append_printf( gstr, " - %s", buf ); … … 337 337 the individual torrents' speeds and the status bar's overall speed 338 338 in sync even if they refresh at slightly different times */ 339 double upload_speed;340 341 /* @see upload_speed */342 double download_speed;339 int upload_speed_Bps; 340 341 /* @see upload_speed_Bps */ 342 int download_speed_Bps; 343 343 344 344 gboolean compact; … … 398 398 icon = get_icon( tor, COMPACT_ICON_SIZE, widget ); 399 399 name = tr_torrentInfo( tor )->name; 400 status = getShortStatusString( tor, st, p->upload_speed , p->download_speed);400 status = getShortStatusString( tor, st, p->upload_speed_Bps, p->download_speed_Bps ); 401 401 402 402 /* get the idealized cell dimensions */ … … 456 456 icon = get_icon( tor, FULL_ICON_SIZE, widget ); 457 457 name = inf->name; 458 status = getStatusString( tor, st, p->upload_speed , p->download_speed);458 status = getStatusString( tor, st, p->upload_speed_Bps, p->download_speed_Bps ); 459 459 progress = getProgressString( tor, inf, st ); 460 460 … … 560 560 icon = get_icon( tor, COMPACT_ICON_SIZE, widget ); 561 561 name = tr_torrentInfo( tor )->name; 562 status = getShortStatusString( tor, st, p->upload_speed , p->download_speed);562 status = getShortStatusString( tor, st, p->upload_speed_Bps, p->download_speed_Bps ); 563 563 564 564 /* get the cell dimensions */ … … 664 664 icon = get_icon( tor, FULL_ICON_SIZE, widget ); 665 665 name = inf->name; 666 status = getStatusString( tor, st, p->upload_speed , p->download_speed);666 status = getStatusString( tor, st, p->upload_speed_Bps, p->download_speed_Bps ); 667 667 progress = getProgressString( tor, inf, st ); 668 668 … … 783 783 switch( property_id ) 784 784 { 785 case P_TORRENT: p->tor = g_value_get_pointer( v ); break;786 case P_UPLOAD_SPEED: p->upload_speed = g_value_get_double( v ); break;787 case P_DOWNLOAD_SPEED: p->download_speed = g_value_get_double( v ); break;788 case P_BAR_HEIGHT: p->bar_height = g_value_get_int( v ); break;789 case P_COMPACT: p->compact = g_value_get_boolean( v ); break;785 case P_TORRENT: p->tor = g_value_get_pointer( v ); break; 786 case P_UPLOAD_SPEED: p->upload_speed_Bps = g_value_get_int( v ); break; 787 case P_DOWNLOAD_SPEED: p->download_speed_Bps = g_value_get_int( v ); break; 788 case P_BAR_HEIGHT: p->bar_height = g_value_get_int( v ); break; 789 case P_COMPACT: p->compact = g_value_get_boolean( v ); break; 790 790 default: G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, pspec ); break; 791 791 } … … 804 804 { 805 805 case P_TORRENT: g_value_set_pointer( v, p->tor ); break; 806 case P_UPLOAD_SPEED: g_value_set_ double( v, p->upload_speed); break;807 case P_DOWNLOAD_SPEED: g_value_set_ double( v, p->download_speed); break;806 case P_UPLOAD_SPEED: g_value_set_int( v, p->upload_speed_Bps ); break; 807 case P_DOWNLOAD_SPEED: g_value_set_int( v, p->download_speed_Bps ); break; 808 808 case P_BAR_HEIGHT: g_value_set_int( v, p->bar_height ); break; 809 809 case P_COMPACT: g_value_set_boolean( v, p->compact ); break; … … 854 854 855 855 g_object_class_install_property( gobject_class, P_UPLOAD_SPEED, 856 g_param_spec_ double( "piece-upload-speed", NULL,857 "tr_stat.pieceUploadSpeed",858 859 856 g_param_spec_int( "piece-upload-speed", NULL, 857 "tr_stat.pieceUploadSpeed_Bps", 858 0, INT_MAX, 0, 859 G_PARAM_READWRITE ) ); 860 860 861 861 g_object_class_install_property( gobject_class, P_DOWNLOAD_SPEED, 862 g_param_spec_ double( "piece-download-speed", NULL,863 "tr_stat.pieceDownloadSpeed",864 865 862 g_param_spec_int( "piece-download-speed", NULL, 863 "tr_stat.pieceDownloadSpeed_Bps", 864 0, INT_MAX, 0, 865 G_PARAM_READWRITE ) ); 866 866 867 867 g_object_class_install_property( gobject_class, P_BAR_HEIGHT, -
trunk/gtk/tr-core.c
r10863 r10931 777 777 TR_TORRENT_TYPE, /* TrTorrent object */ 778 778 G_TYPE_POINTER, /* tr_torrent* */ 779 G_TYPE_ DOUBLE, /* tr_stat.pieceUploadSpeed*/780 G_TYPE_ DOUBLE, /* tr_stat.pieceDownloadSpeed*/779 G_TYPE_INT, /* tr_stat.pieceUploadSpeed_Bps */ 780 G_TYPE_INT, /* tr_stat.pieceDownloadSpeed_Bps */ 781 781 G_TYPE_INT }; /* tr_stat.status */ 782 782 … … 921 921 MC_TORRENT, gtor, 922 922 MC_TORRENT_RAW, tor, 923 MC_SPEED_UP, st->pieceUploadSpeed ,924 MC_SPEED_DOWN, st->pieceDownloadSpeed ,923 MC_SPEED_UP, st->pieceUploadSpeed_Bps, 924 MC_SPEED_DOWN, st->pieceDownloadSpeed_Bps, 925 925 MC_ACTIVITY, st->activity, 926 926 -1 ); … … 1323 1323 { 1324 1324 int oldActivity, newActivity; 1325 doubleoldUpSpeed, newUpSpeed;1326 doubleoldDownSpeed, newDownSpeed;1325 int oldUpSpeed, newUpSpeed; 1326 int oldDownSpeed, newDownSpeed; 1327 1327 const tr_stat * st; 1328 1328 TrTorrent * gtor; … … 1339 1339 st = tr_torrentStat( tr_torrent_handle( gtor ) ); 1340 1340 newActivity = st->activity; 1341 newUpSpeed = st->pieceUploadSpeed ;1342 newDownSpeed = st->pieceDownloadSpeed ;1341 newUpSpeed = st->pieceUploadSpeed_Bps; 1342 newDownSpeed = st->pieceDownloadSpeed_Bps; 1343 1343 1344 1344 /* updating the model triggers off resort/refresh, 1345 1345 so don't do it unless something's actually changed... */ 1346 if( ( newActivity != oldActivity) ||1347 ( (int)(newUpSpeed*10.0) != (int)(oldUpSpeed*10.0)) ||1348 ( (int)(newDownSpeed*10.0) != (int)(oldDownSpeed*10.0)) )1346 if( ( newActivity != oldActivity ) || 1347 ( newUpSpeed != oldUpSpeed ) || 1348 ( newDownSpeed != oldDownSpeed ) ) 1349 1349 { 1350 1350 gtk_list_store_set( GTK_LIST_STORE( model ), iter, -
trunk/gtk/tr-icon.c
r10390 r10931 16 16 #include <libappindicator/app-indicator.h> 17 17 #endif 18 #include <libtransmission/transmission.h> 19 #include <libtransmission/utils.h> 18 20 #include "actions.h" 19 21 #include "tr-icon.h" … … 66 68 tr_icon_refresh( gpointer vicon ) 67 69 { 68 double d;70 int Bps; 69 71 int limit; 70 72 char up[64]; … … 78 80 79 81 /* up */ 80 if(((d = tr_sessionGetRawSpeed( session, TR_UP ))) < 0.1 ) 82 Bps = tr_sessionGetRawSpeed_Bps( session, TR_UP ); 83 if( Bps < 1 ) 81 84 g_strlcpy( up, idle, sizeof( up ) ); 82 85 else 83 tr_ strlspeed( up, d, sizeof( up ) );86 tr_formatter_speed( up, Bps, sizeof( up ) ); 84 87 85 88 /* up limit */ 86 if( !tr_sessionGetActiveSpeedLimit ( session, TR_UP, &limit ) )89 if( !tr_sessionGetActiveSpeedLimit_Bps( session, TR_UP, &limit ) ) 87 90 *upLimit = '\0'; 88 91 else { … … 93 96 94 97 /* down */ 95 if(((d = tr_sessionGetRawSpeed( session, TR_DOWN ))) < 0.1 ) 98 Bps = tr_sessionGetRawSpeed_Bps( session, TR_DOWN ); 99 if( Bps < 1 ) 96 100 g_strlcpy( down, idle, sizeof( down ) ); 97 101 else 98 tr_ strlspeed( down, d, sizeof( down ) );102 tr_formatter_speed( down, Bps, sizeof( down ) ); 99 103 100 104 /* down limit */ 101 if( !tr_sessionGetActiveSpeedLimit ( session, TR_DOWN, &limit ) )105 if( !tr_sessionGetActiveSpeedLimit_Bps( session, TR_DOWN, &limit ) ) 102 106 *downLimit = '\0'; 103 107 else { -
trunk/gtk/tr-prefs.c
r10724 r10931 31 31 **/ 32 32 33 #define MULTIPLIER_KEY "multiplier-key" 33 34 #define PREF_KEY "pref-key" 34 35 … … 97 98 spun_cb_idle( gpointer spin ) 98 99 { 99 gboolean 100 GObject * 100 gboolean keep_waiting = TRUE; 101 GObject * o = G_OBJECT( spin ); 101 102 struct spin_idle_data * data = g_object_get_data( o, IDLE_DATA ); 102 103 … … 106 107 /* update the core */ 107 108 const char * key = g_object_get_data( o, PREF_KEY ); 109 const int multiplier = GPOINTER_TO_INT( g_object_get_data( o, MULTIPLIER_KEY ) ); 110 108 111 if (data->isDouble) 109 112 { 110 const double value = gtk_spin_button_get_value( GTK_SPIN_BUTTON( spin ) ) ;113 const double value = gtk_spin_button_get_value( GTK_SPIN_BUTTON( spin ) ) * multiplier; 111 114 tr_core_set_pref_double( TR_CORE( data->core ), key, value ); 112 115 } 113 116 else 114 117 { 115 const int value = gtk_spin_button_get_value_as_int( 116 GTK_SPIN_BUTTON( spin ) ); 118 const int value = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( spin ) ) * multiplier; 117 119 tr_core_set_pref_int( TR_CORE( data->core ), key, value ); 118 120 } … … 128 130 129 131 static void 130 spun_cb( GtkSpinButton * w, 131 gpointer core, 132 gboolean isDouble ) 132 spun_cb( GtkSpinButton * w, gpointer core, gboolean isDouble ) 133 133 { 134 134 /* user may be spinning through many values, so let's hold off 135 135 for a moment to keep from flooding the core with changes */ 136 GObject * 136 GObject * o = G_OBJECT( w ); 137 137 struct spin_idle_data * data = g_object_get_data( o, IDLE_DATA ); 138 138 … … 151 151 152 152 static void 153 spun_cb_int( GtkSpinButton * w, 154 gpointer core ) 153 spun_cb_int( GtkSpinButton * w, gpointer core ) 155 154 { 156 155 spun_cb( w, core, FALSE ); … … 158 157 159 158 static void 160 spun_cb_double( GtkSpinButton * w, 161 gpointer core ) 159 spun_cb_double( GtkSpinButton * w, gpointer core ) 162 160 { 163 161 spun_cb( w, core, TRUE ); … … 167 165 new_spin_button( const char * key, 168 166 gpointer core, 167 int multiplier, 169 168 int low, 170 169 int high, … … 172 171 { 173 172 GtkWidget * w = gtk_spin_button_new_with_range( low, high, step ); 174 175 g_object_set_data_full( G_OBJECT( w ), PREF_KEY, g_strdup( 176 key ), g_free ); 173 g_object_set_data( G_OBJECT( w ), MULTIPLIER_KEY, GINT_TO_POINTER( multiplier ) ); 174 g_object_set_data_full( G_OBJECT( w ), PREF_KEY, g_strdup( key ), g_free ); 177 175 gtk_spin_button_set_digits( GTK_SPIN_BUTTON( w ), 0 ); 178 gtk_spin_button_set_value( GTK_SPIN_BUTTON( w ), pref_int_get( key ) );176 gtk_spin_button_set_value( GTK_SPIN_BUTTON( w ), pref_int_get( key ) / multiplier ); 179 177 g_signal_connect( w, "value-changed", G_CALLBACK( spun_cb_int ), core ); 180 178 return w; … … 184 182 new_spin_button_double( const char * key, 185 183 gpointer core, 184 int multiplier, 186 185 double low, 187 186 double high, … … 189 188 { 190 189 GtkWidget * w = gtk_spin_button_new_with_range( low, high, step ); 191 192 g_object_set_data_full( G_OBJECT( w ), PREF_KEY, g_strdup( 193 key ), g_free ); 190 g_object_set_data( G_OBJECT( w ), MULTIPLIER_KEY, GINT_TO_POINTER( multiplier ) ); 191 g_object_set_data_full( G_OBJECT( w ), PREF_KEY, g_strdup( key ), g_free ); 194 192 gtk_spin_button_set_digits( GTK_SPIN_BUTTON( w ), 2 ); 195 193 gtk_spin_button_set_value( GTK_SPIN_BUTTON( w ), pref_double_get( key ) ); … … 199 197 200 198 static void 201 entry_changed_cb( GtkEntry * w, 202 gpointer core ) 199 entry_changed_cb( GtkEntry * w, gpointer core ) 203 200 { 204 201 const char * key = g_object_get_data( G_OBJECT( w ), PREF_KEY ); … … 333 330 s = _( "_Seed torrent until its ratio reaches:" ); 334 331 w = new_check_button( s, TR_PREFS_KEY_RATIO_ENABLED, core ); 335 w2 = new_spin_button_double( TR_PREFS_KEY_RATIO, core, 0, INT_MAX, .05 );332 w2 = new_spin_button_double( TR_PREFS_KEY_RATIO, core, 1, 0, INT_MAX, .05 ); 336 333 gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_RATIO_ENABLED ) ); 337 334 g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 ); … … 810 807 811 808 /* port */ 812 w = new_spin_button( TR_PREFS_KEY_RPC_PORT, core, 0, USHRT_MAX, 1 );809 w = new_spin_button( TR_PREFS_KEY_RPC_PORT, core, 1, 0, USHRT_MAX, 1 ); 813 810 page->widgets = g_slist_append( page->widgets, w ); 814 811 w = hig_workarea_add_row( t, &row, _( "Listening _port:" ), w, NULL ); … … 1015 1012 page->proxy_widgets = g_slist_append( page->proxy_widgets, w ); 1016 1013 1017 w = new_spin_button( TR_PREFS_KEY_PROXY_PORT, core, 0, USHRT_MAX, 1 );1014 w = new_spin_button( TR_PREFS_KEY_PROXY_PORT, core, 1, 0, USHRT_MAX, 1 ); 1018 1015 page->proxy_widgets = g_slist_append( page->proxy_widgets, w ); 1019 1016 w = hig_workarea_add_row( t, &row, _( "Proxy _port:" ), w, NULL ); … … 1221 1218 hig_workarea_add_section_title( t, &row, _( "Speed Limits" ) ); 1222 1219 1223 s = _( "Limit _download speed (KiB/s):");1224 w = new_check_button( s, TR_PREFS_KEY_DSPEED_ENABLED, core );1225 w2 = new_spin_button( TR_PREFS_KEY_DSPEED , core, 0, INT_MAX, 5 );1220 g_snprintf( buf, sizeof( buf ), _( "Limit _download speed (%s):" ), _(speed_K_str) ); 1221 w = new_check_button( buf, TR_PREFS_KEY_DSPEED_ENABLED, core ); 1222 w2 = new_spin_button( TR_PREFS_KEY_DSPEED_Bps, core, speed_K, 0, INT_MAX, 5 ); 1226 1223 gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_DSPEED_ENABLED ) ); 1227 1224 g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 ); 1228 1225 hig_workarea_add_row_w( t, &row, w, w2, NULL ); 1229 1226 1230 s = _( "Limit _upload speed (KiB/s):");1231 w = new_check_button( s, TR_PREFS_KEY_USPEED_ENABLED, core );1232 w2 = new_spin_button( TR_PREFS_KEY_USPEED , core, 0, INT_MAX, 5 );1227 g_snprintf( buf, sizeof( buf ), _( "Limit _upload speed (%s):" ), _(speed_K_str) ); 1228 w = new_check_button( buf, TR_PREFS_KEY_USPEED_ENABLED, core ); 1229 w2 = new_spin_button( TR_PREFS_KEY_USPEED_Bps, core, speed_K, 0, INT_MAX, 5 ); 1233 1230 gtk_widget_set_sensitive( GTK_WIDGET( w2 ), pref_flag_get( TR_PREFS_KEY_USPEED_ENABLED ) ); 1234 1231 g_signal_connect( w, "toggled", G_CALLBACK( target_cb ), w2 ); … … 1253 1250 hig_workarea_add_wide_control( t, &row, w ); 1254 1251 1255 s = _( "Limit do_wnload speed (KiB/s):");1256 w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_DOWN , core, 0, INT_MAX, 5 );1257 hig_workarea_add_row( t, &row, s, w, NULL );1258 1259 s = _( "Limit u_pload speed (KiB/s):");1260 w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_UP , core, 0, INT_MAX, 5 );1261 hig_workarea_add_row( t, &row, s, w, NULL );1252 g_snprintf( buf, sizeof( buf ), _( "Limit do_wnload speed (%s):" ), _(speed_K_str) ); 1253 w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, core, speed_K, 0, INT_MAX, 5 ); 1254 hig_workarea_add_row( t, &row, buf, w, NULL ); 1255 1256 g_snprintf( buf, sizeof( buf ), _( "Limit u_pload speed (%s):" ), _(speed_K_str) ); 1257 w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_UP_Bps, core, speed_K, 0, INT_MAX, 5 ); 1258 hig_workarea_add_row( t, &row, buf, w, NULL ); 1262 1259 1263 1260 s = _( "_Scheduled times:" ); … … 1373 1370 1374 1371 s = _( "_Port for incoming connections:" ); 1375 w = data->portSpin = new_spin_button( TR_PREFS_KEY_PEER_PORT, core, 1, USHRT_MAX, 1 );1372 w = data->portSpin = new_spin_button( TR_PREFS_KEY_PEER_PORT, core, 1, 1, USHRT_MAX, 1 ); 1376 1373 hig_workarea_add_row( t, &row, s, w, NULL ); 1377 1374 … … 1398 1395 hig_workarea_add_section_title( t, &row, _( "Limits" ) ); 1399 1396 1400 w = new_spin_button( TR_PREFS_KEY_PEER_LIMIT_TORRENT, core, 1, 300, 5 );1397 w = new_spin_button( TR_PREFS_KEY_PEER_LIMIT_TORRENT, core, 1, 1, 300, 5 ); 1401 1398 hig_workarea_add_row( t, &row, _( "Maximum peers per _torrent:" ), w, NULL ); 1402 w = new_spin_button( TR_PREFS_KEY_PEER_LIMIT_GLOBAL, core, 1, 3000, 5 );1399 w = new_spin_button( TR_PREFS_KEY_PEER_LIMIT_GLOBAL, core, 1, 1, 3000, 5 ); 1403 1400 hig_workarea_add_row( t, &row, _( "Maximum peers _overall:" ), w, NULL ); 1404 1401 -
trunk/gtk/tr-window.c
r10864 r10931 206 206 } 207 207 else if( !strcmp( key, TR_PREFS_KEY_ALT_SPEED_ENABLED ) || 208 !strcmp( key, TR_PREFS_KEY_ALT_SPEED_UP ) ||209 !strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN ) )208 !strcmp( key, TR_PREFS_KEY_ALT_SPEED_UP_Bps ) || 209 !strcmp( key, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps ) ) 210 210 { 211 211 syncAltSpeedButton( p ); … … 267 267 GtkWidget * w = p->alt_speed_button; 268 268 269 tr_strlspeed( u, pref_int_get( TR_PREFS_KEY_ALT_SPEED_UP ), sizeof( u ) );270 tr_strlspeed( d, pref_int_get( TR_PREFS_KEY_ALT_SPEED_DOWN ), sizeof( d ) );269 tr_strlspeed( u, pref_int_get( TR_PREFS_KEY_ALT_SPEED_UP_Bps ), sizeof( u ) ); 270 tr_strlspeed( d, pref_int_get( TR_PREFS_KEY_ALT_SPEED_DOWN_Bps ), sizeof( d ) ); 271 271 fmt = b ? _( "Click to disable Temporary Speed Limits\n(%1$s down, %2$s up)" ) 272 272 : _( "Click to enable Temporary Speed Limits\n(%1$s down, %2$s up)" ); … … 389 389 PrivateData * p = vp; 390 390 GObject * o = G_OBJECT( check ); 391 const int speed = GPOINTER_TO_INT( g_object_get_data( o, SPEED_KEY ) );391 const int Bps = GPOINTER_TO_INT( g_object_get_data( o, SPEED_KEY ) ) * speed_K; 392 392 tr_direction dir = GPOINTER_TO_INT( g_object_get_data( o, DIRECTION_KEY ) ); 393 393 394 key = dir==TR_UP ? TR_PREFS_KEY_USPEED : TR_PREFS_KEY_DSPEED;395 tr_core_set_pref_int( p->core, key, speed);394 key = dir==TR_UP ? TR_PREFS_KEY_USPEED_Bps : TR_PREFS_KEY_DSPEED_Bps; 395 tr_core_set_pref_int( p->core, key, Bps ); 396 396 397 397 key = dir==TR_UP ? TR_PREFS_KEY_USPEED_ENABLED : TR_PREFS_KEY_DSPEED_ENABLED; … … 428 428 { 429 429 char buf[128]; 430 tr_strlspeed( buf, speeds[i] , sizeof( buf ) );430 tr_strlspeed( buf, speeds[i] * speed_K, sizeof( buf ) ); 431 431 w = gtk_menu_item_new_with_label( buf ); 432 432 g_object_set_data( G_OBJECT( w ), DIRECTION_KEY, GINT_TO_POINTER( dir ) ); … … 542 542 543 543 w = p->speedlimit_on_item[TR_DOWN]; 544 tr_strlspeed( buf1, pref_int_get( TR_PREFS_KEY_DSPEED ), sizeof( buf1 ) );544 tr_strlspeed( buf1, pref_int_get( TR_PREFS_KEY_DSPEED_Bps ), sizeof( buf1 ) ); 545 545 gtk_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( w ) ) ), buf1 ); 546 546 … … 550 550 551 551 w = p->speedlimit_on_item[TR_UP]; 552 tr_strlspeed( buf1, pref_int_get( TR_PREFS_KEY_USPEED ), sizeof( buf1 ) );552 tr_strlspeed( buf1, pref_int_get( TR_PREFS_KEY_USPEED_Bps ), sizeof( buf1 ) ); 553 553 gtk_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( w ) ) ), buf1 ); 554 554 … … 843 843 { 844 844 char buf[128]; 845 doubleup=0, down=0;845 int up=0, down=0; 846 846 GtkTreeIter iter; 847 847 GtkTreeModel * model = tr_core_model( p->core ); … … 849 849 if( gtk_tree_model_get_iter_first( model, &iter ) ) do 850 850 { 851 doubleu, d;851 int u, d; 852 852 gtk_tree_model_get( model, &iter, MC_SPEED_UP, &u, 853 853 MC_SPEED_DOWN, &d, -
trunk/gtk/util.c
r10864 r10931 41 41 #include "tr-prefs.h" 42 42 #include "util.h" 43 44 /*** 45 **** UNITS 46 ***/ 47 48 const int mem_K = 1024; 49 /* abbreviation for bytes */ 50 const char * mem_B_str = N_("B"); 51 /* abbreviation IEC base 2 units kilobyte */ 52 const char * mem_K_str = N_("KiB"); 53 /* abbreviation IEC base 2 units megabyte */ 54 const char * mem_M_str = N_("MiB"); 55 /* abbreviation IEC base 2 units gigabyte */ 56 const char * mem_G_str = N_("GiB"); 57 58 const int disk_K = 1000; 59 /* abbreviation for bytes */ 60 const char * disk_B_str = N_("B"); 61 /* abbreviation for SI base 10 kilobyte */ 62 const char * disk_K_str = N_("kB"); 63 /* abbreviation for SI base 10 megabyte */ 64 const char * disk_M_str = N_("MB"); 65 /* abbreviation for SI base 10 gigabyte */ 66 const char * disk_G_str = N_("GB"); 67 68 const int speed_K = 1000; 69 /* abbreviation for bytes per second */ 70 const char * speed_B_str = N_("B/s"); 71 /* abbreviation for kilobytes per second */ 72 const char * speed_K_str = N_("kB/s"); 73 /* abbreviation for megabytes per second */ 74 const char * speed_M_str = N_("MB/s"); 75 /* abbreviation for gigabytes per second */ 76 const char * speed_G_str = N_("GB/s"); 77 78 /*** 79 **** 80 ***/ 43 81 44 82 gtr_lockfile_state_t … … 125 163 126 164 char* 127 tr_strlspeed( char * buf, double kb_sec, size_t buflen ) 128 { 129 const int64_t bytes_per_second = kb_sec * 1024.0; 130 165 tr_strlspeed( char * buf, int bytes_per_second, size_t buflen ) 166 { 131 167 if( bytes_per_second < 1 ) 132 168 g_strlcpy( buf, _( "None" ), buflen ); -
trunk/gtk/util.h
r10864 r10931 18 18 #include <gtk/gtk.h> 19 19 20 #include <libtransmission/transmission.h> 21 22 extern const int mem_K; 23 extern const char * mem_B_str; 24 extern const char * mem_K_str; 25 extern const char * mem_M_str; 26 extern const char * mem_G_str; 27 28 extern const int disk_K; 29 extern const char * disk_B_str; 30 extern const char * disk_K_str; 31 extern const char * disk_M_str; 32 extern const char * disk_G_str; 33 34 extern const int speed_K; 35 extern const char * speed_B_str; 36 extern const char * speed_K_str; 37 extern const char * speed_M_str; 38 extern const char * speed_G_str; 39 20 40 /* portability wrapper around g_warn_if_fail() for older versions of glib */ 21 41 #ifdef g_warn_if_fail … … 46 66 char* tr_strlsize( char * buf, guint64 size, size_t buflen ); 47 67 48 /* return a human-readable string for the transfer rate given in bytes. */49 char* tr_strlspeed( char * buf, double KiBps, size_t buflen );68 /* return a human-readable string for the transfer rate given in Bps. */ 69 char* tr_strlspeed( char * buf, int bytes_per_second, size_t buflen ); 50 70 51 71 /* return a human-readable string for the given ratio. */ -
trunk/libtransmission/bandwidth.c
r10662 r10931 31 31 ***/ 32 32 33 static float34 getSpeed ( const struct bratecontrol * r,int interval_msec, uint64_t now )33 static unsigned int 34 getSpeed_Bps( const struct bratecontrol * r, unsigned int interval_msec, uint64_t now ) 35 35 { 36 36 uint64_t bytes = 0; … … 49 49 } 50 50 51 return ( bytes / 1024.0 ) * ( 1000.0 / interval_msec);51 return (unsigned int)(( bytes * 1000u ) / interval_msec); 52 52 } 53 53 … … 154 154 tr_priority_t parent_priority, 155 155 tr_direction dir, 156 intperiod_msec,156 unsigned int period_msec, 157 157 tr_ptrArray * peer_pool ) 158 158 { … … 165 165 if( b->band[dir].isLimited ) 166 166 { 167 const double desiredSpeed = b->band[dir].desiredSpeed; 168 const double nextPulseSpeed = desiredSpeed; 169 b->band[dir].bytesLeft = MAX( 0.0, nextPulseSpeed * 1024.0 * period_msec / 1000.0 ); 167 const unsigned int nextPulseSpeed = b->band[dir].desiredSpeed_Bps; 168 b->band[dir].bytesLeft = ( nextPulseSpeed * period_msec ) / 1000u; 170 169 171 170 #ifdef DEBUG_DIRECTION 172 171 if( dir == DEBUG_DIRECTION ) 173 fprintf( stderr, "bandwidth %p currentPieceSpeed(%5.2f of %5.2f) desiredSpeed(%5.2f), allocating % 5.2f\n",172 fprintf( stderr, "bandwidth %p currentPieceSpeed(%5.2f of %5.2f) desiredSpeed(%5.2f), allocating %d\n", 174 173 b, currentSpeed, tr_bandwidthGetRawSpeed( b, dir ), desiredSpeed, 175 b->band[dir].bytesLeft /1024.0);174 b->band[dir].bytesLeft ); 176 175 #endif 177 176 } … … 239 238 tr_bandwidthAllocate( tr_bandwidth * b, 240 239 tr_direction dir, 241 intperiod_msec )240 unsigned int period_msec ) 242 241 { 243 242 int i, peerCount; … … 307 306 ***/ 308 307 309 size_t308 unsigned int 310 309 tr_bandwidthClamp( const tr_bandwidth * b, 311 310 tr_direction dir, 312 size_tbyteCount )311 unsigned int byteCount ) 313 312 { 314 313 assert( tr_isBandwidth( b ) ); … … 327 326 } 328 327 329 double 330 tr_bandwidthGetRawSpeed ( const tr_bandwidth * b, const uint64_t now, const tr_direction dir )331 { 332 assert( tr_isBandwidth( b ) ); 333 assert( tr_isDirection( dir ) ); 334 335 return getSpeed ( &b->band[dir].raw, HISTORY_MSEC, now );336 } 337 338 double 339 tr_bandwidthGetPieceSpeed ( const tr_bandwidth * b, const uint64_t now, const tr_direction dir )340 { 341 assert( tr_isBandwidth( b ) ); 342 assert( tr_isDirection( dir ) ); 343 344 return getSpeed ( &b->band[dir].piece, HISTORY_MSEC, now );328 unsigned int 329 tr_bandwidthGetRawSpeed_Bps( const tr_bandwidth * b, const uint64_t now, const tr_direction dir ) 330 { 331 assert( tr_isBandwidth( b ) ); 332 assert( tr_isDirection( dir ) ); 333 334 return getSpeed_Bps( &b->band[dir].raw, HISTORY_MSEC, now ); 335 } 336 337 unsigned int 338 tr_bandwidthGetPieceSpeed_Bps( const tr_bandwidth * b, const uint64_t now, const tr_direction dir ) 339 { 340 assert( tr_isBandwidth( b ) ); 341 assert( tr_isDirection( dir ) ); 342 343 return getSpeed_Bps( &b->band[dir].piece, HISTORY_MSEC, now ); 345 344 } 346 345 -
trunk/libtransmission/bandwidth.h
r9868 r10931 33 33 enum 34 34 { 35 HISTORY_MSEC = 2000 ,35 HISTORY_MSEC = 2000u, 36 36 INTERVAL_MSEC = HISTORY_MSEC, 37 37 GRANULARITY_MSEC = 200, … … 54 54 tr_bool isLimited; 55 55 tr_bool honorParentLimits; 56 size_t bytesLeft;57 double desiredSpeed;56 unsigned int bytesLeft; 57 unsigned int desiredSpeed_Bps; 58 58 struct bratecontrol raw; 59 59 struct bratecontrol piece; … … 148 148 149 149 /** 150 * @brief Set the desired speed (in KiB/s)for this bandwidth subtree.150 * @brief Set the desired speed for this bandwidth subtree. 151 151 * @see tr_bandwidthAllocate 152 152 * @see tr_bandwidthGetDesiredSpeed 153 153 */ 154 static inline tr_bool tr_bandwidthSetDesiredSpeed ( tr_bandwidth * bandwidth,155 tr_direction dir,156 doubledesiredSpeed )157 { 158 double * value = &bandwidth->band[dir].desiredSpeed;159 const tr_bool didChange = (int)(desiredSpeed*1024.0) != (int)(*value*1024.0);154 static inline tr_bool tr_bandwidthSetDesiredSpeed_Bps( tr_bandwidth * bandwidth, 155 tr_direction dir, 156 unsigned int desiredSpeed ) 157 { 158 unsigned int * value = &bandwidth->band[dir].desiredSpeed_Bps; 159 const tr_bool didChange = desiredSpeed != *value; 160 160 *value = desiredSpeed; 161 161 return didChange; … … 163 163 164 164 /** 165 * @brief Get the desired speed (in KiB/s) for thsbandwidth subtree.165 * @brief Get the desired speed for the bandwidth subtree. 166 166 * @see tr_bandwidthSetDesiredSpeed 167 167 */ 168 168 static inline double 169 tr_bandwidthGetDesiredSpeed( const tr_bandwidth * bandwidth, 170 tr_direction dir ) 171 { 172 return bandwidth->band[dir].desiredSpeed; 169 tr_bandwidthGetDesiredSpeed_Bps( const tr_bandwidth * bandwidth, tr_direction dir ) 170 { 171 return bandwidth->band[dir].desiredSpeed_Bps; 173 172 } 174 173 … … 200 199 void tr_bandwidthAllocate ( tr_bandwidth * bandwidth, 201 200 tr_direction direction, 202 intperiod_msec );201 unsigned int period_msec ); 203 202 204 203 /** 205 204 * @brief clamps byteCount down to a number that this bandwidth will allow to be consumed 206 205 */ 207 size_t tr_bandwidthClamp( const tr_bandwidth * bandwidth,206 unsigned int tr_bandwidthClamp ( const tr_bandwidth * bandwidth, 208 207 tr_direction direction, 209 size_tbyteCount );208 unsigned int byteCount ); 210 209 211 210 /****** … … 214 213 215 214 /** @brief Get the raw total of bytes read or sent by this bandwidth subtree. */ 216 double tr_bandwidthGetRawSpeed( const tr_bandwidth * bandwidth,217 const uint64_t now,218 const tr_direction direction );215 unsigned int tr_bandwidthGetRawSpeed_Bps( const tr_bandwidth * bandwidth, 216 const uint64_t now, 217 const tr_direction direction ); 219 218 220 219 /** @brief Get the number of piece data bytes read or sent by this bandwidth subtree. */ 221 double tr_bandwidthGetPieceSpeed( const tr_bandwidth * bandwidth,222 const uint64_t now,223 const tr_direction direction );220 unsigned int tr_bandwidthGetPieceSpeed_Bps( const tr_bandwidth * bandwidth, 221 const uint64_t now, 222 const tr_direction direction ); 224 223 225 224 /** -
trunk/libtransmission/cache.c
r10924 r10931 49 49 { 50 50 tr_ptrArray blocks; 51 int max Blocks;52 size_t max MiB;51 int max_blocks; 52 size_t max_bytes; 53 53 54 54 size_t disk_writes; … … 198 198 int err = 0; 199 199 200 while( !err && ( tr_ptrArraySize( &cache->blocks ) > cache->max Blocks ) )200 while( !err && ( tr_ptrArraySize( &cache->blocks ) > cache->max_blocks ) ) 201 201 { 202 202 int n; … … 213 213 214 214 static int 215 getMaxBlocks( double maxMiB ) 216 { 217 const double maxBytes = maxMiB * (1024 * 1024); 218 return maxBytes / MAX_BLOCK_SIZE; 219 } 220 221 int 222 tr_cacheSetLimit( tr_cache * cache, double maxMiB ) 223 { 224 cache->maxMiB = maxMiB; 225 cache->maxBlocks = getMaxBlocks( maxMiB ); 226 tr_ndbg( MY_NAME, "Maximum cache size set to %.2f MiB (%d blocks)", maxMiB, cache->maxBlocks ); 215 getMaxBlocks( int64_t max_bytes ) 216 { 217 return max_bytes / (double)MAX_BLOCK_SIZE; 218 } 219 220 int 221 tr_cacheSetLimit( tr_cache * cache, int64_t max_bytes ) 222 { 223 char buf[128]; 224 225 cache->max_bytes = max_bytes; 226 cache->max_blocks = getMaxBlocks( max_bytes ); 227 228 tr_formatter_mem( buf, cache->max_bytes, sizeof( buf ) ); 229 tr_ndbg( MY_NAME, "Maximum cache size set to %s (%d blocks)", buf, cache->max_blocks ); 230 227 231 return cacheTrim( cache ); 228 232 } 229 233 230 double 234 int64_t 231 235 tr_cacheGetLimit( const tr_cache * cache ) 232 236 { 233 return cache->max MiB;237 return cache->max_bytes; 234 238 } 235 239 236 240 tr_cache * 237 tr_cacheNew( double maxMiB)241 tr_cacheNew( int64_t max_bytes ) 238 242 { 239 243 tr_cache * cache = tr_new0( tr_cache, 1 ); 240 244 cache->blocks = TR_PTR_ARRAY_INIT; 241 cache->maxBlocks = getMaxBlocks( maxMiB ); 245 cache->max_bytes = max_bytes; 246 cache->max_blocks = getMaxBlocks( max_bytes ); 242 247 return cache; 243 248 } -
trunk/libtransmission/cache.h
r10798 r10931 24 24 ***/ 25 25 26 tr_cache * tr_cacheNew( double max_MiB);26 tr_cache * tr_cacheNew( int64_t max_bytes ); 27 27 28 28 void tr_cacheFree( tr_cache * ); … … 32 32 ***/ 33 33 34 int tr_cacheSetLimit( tr_cache * cache, double max_MiB);34 int tr_cacheSetLimit( tr_cache * cache, int64_t max_bytes ); 35 35 36 doubletr_cacheGetLimit( const tr_cache * );36 int64_t tr_cacheGetLimit( const tr_cache * ); 37 37 38 38 int tr_cacheWriteBlock( tr_cache * cache, -
trunk/libtransmission/peer-io.c
r10913 r10931 67 67 const double assumed_payload_data_rate = 94.0; 68 68 69 return ( size_t)( d * ( 100.0 / assumed_payload_data_rate ) - d );69 return (unsigned int)( d * ( 100.0 / assumed_payload_data_rate ) - d ); 70 70 } 71 71 … … 91 91 92 92 static void 93 didWriteWrapper( tr_peerIo * io, size_t bytes_transferred )93 didWriteWrapper( tr_peerIo * io, unsigned int bytes_transferred ) 94 94 { 95 95 while( bytes_transferred && tr_isPeerIo( io ) ) … … 97 97 struct tr_datatype * next = io->outbuf_datatypes->data; 98 98 99 const size_t payload = MIN( next->length, bytes_transferred );100 const size_t overhead = guessPacketOverhead( payload );99 const unsigned int payload = MIN( next->length, bytes_transferred ); 100 const unsigned int overhead = guessPacketOverhead( payload ); 101 101 102 102 tr_bandwidthUsed( &io->bandwidth, TR_UP, payload, next->isPieceData ); … … 207 207 208 208 /* Limit the input buffer to 256K, so it doesn't grow too large */ 209 size_t howmuch; 209 unsigned int howmuch; 210 unsigned int curlen; 210 211 const tr_direction dir = TR_DOWN; 211 const size_t max = 256 * 1024; 212 size_t curlen; 212 const unsigned int max = 256 * 1024; 213 213 214 214 assert( tr_isPeerIo( io ) ); … … 230 230 231 231 EVUTIL_SET_SOCKET_ERROR( 0 ); 232 res = evbuffer_read( io->inbuf, fd, howmuch );232 res = evbuffer_read( io->inbuf, fd, (int)howmuch ); 233 233 e = EVUTIL_SOCKET_ERROR( ); 234 234 … … 283 283 284 284 if( n > 0 ) 285 evbuffer_drain( buffer, n );285 evbuffer_drain( buffer, (size_t)n ); 286 286 287 287 /* keep the iobuf's excess capacity from growing too large */ … … 717 717 **/ 718 718 719 static size_t719 static unsigned int 720 720 getDesiredOutputBufferSize( const tr_peerIo * io, uint64_t now ) 721 721 { … … 724 724 * or a few blocks, whichever is bigger. 725 725 * It's okay to tweak this as needed */ 726 const double currentSpeed = tr_bandwidthGetPieceSpeed( &io->bandwidth, now, TR_UP ); 727 const double period = 15; /* arbitrary */ 728 const double numBlocks = 3.5; /* the 3 is arbitrary; the .5 is to leave room for messages */ 729 return MAX( MAX_BLOCK_SIZE*numBlocks, currentSpeed*1024*period ); 726 const unsigned int currentSpeed_Bps = tr_bandwidthGetPieceSpeed_Bps( &io->bandwidth, now, TR_UP ); 727 const unsigned int period = 15u; /* arbitrary */ 728 /* the 3 is arbitrary; the .5 is to leave room for messages */ 729 static const unsigned int ceiling = (unsigned int)( MAX_BLOCK_SIZE * 3.5 ); 730 return MAX( ceiling, currentSpeed_Bps*period ); 730 731 } 731 732 … … 883 884 884 885 EVUTIL_SET_SOCKET_ERROR( 0 ); 885 res = evbuffer_read( io->inbuf, io->socket, howmuch );886 res = evbuffer_read( io->inbuf, io->socket, (int)howmuch ); 886 887 e = EVUTIL_SOCKET_ERROR( ); 887 888 -
trunk/libtransmission/peer-io.h
r10912 r10931 369 369 int isPieceData ); 370 370 371 static inline tr_bool tr_peerIoHasBandwidthLeft( const tr_peerIo * io,372 tr_directiondir )371 static inline tr_bool 372 tr_peerIoHasBandwidthLeft( const tr_peerIo * io, tr_direction dir ) 373 373 { 374 374 assert( tr_isPeerIo( io ) ); … … 378 378 } 379 379 380 static inline double tr_peerIoGetPieceSpeed( const tr_peerIo * io, uint64_t now, tr_direction dir ) 380 static inline unsigned int 381 tr_peerIoGetPieceSpeed_Bps( const tr_peerIo * io, uint64_t now, tr_direction dir ) 381 382 { 382 383 assert( tr_isPeerIo( io ) ); 383 384 assert( tr_isDirection( dir ) ); 384 385 385 return tr_bandwidthGetPieceSpeed ( &io->bandwidth, now, dir );386 return tr_bandwidthGetPieceSpeed_Bps( &io->bandwidth, now, dir ); 386 387 } 387 388 -
trunk/libtransmission/peer-mgr.c
r10923 r10931 2251 2251 } 2252 2252 2253 float2254 tr_peerMgrGetWebseedSpeed ( const tr_torrent * tor, uint64_t now )2253 int 2254 tr_peerMgrGetWebseedSpeed_Bps( const tr_torrent * tor, uint64_t now ) 2255 2255 { 2256 2256 int i; 2257 float tmp;2258 float ret = 0;2257 int tmp; 2258 int ret = 0; 2259 2259 2260 2260 const Torrent * t = tor->torrentPeers; … … 2263 2263 2264 2264 for( i=0; i<n; ++i ) 2265 if( tr_webseedGetSpeed ( webseeds[i], now, &tmp ) )2265 if( tr_webseedGetSpeed_Bps( webseeds[i], now, &tmp ) ) 2266 2266 ret += tmp; 2267 2267 … … 2270 2270 2271 2271 2272 float*2273 tr_peerMgrWebSpeeds ( const tr_torrent * tor )2272 int* 2273 tr_peerMgrWebSpeeds_Bps( const tr_torrent * tor ) 2274 2274 { 2275 2275 const Torrent * t = tor->torrentPeers; … … 2277 2277 int i; 2278 2278 int webseedCount; 2279 float * ret;2279 int * ret; 2280 2280 uint64_t now; 2281 2281 … … 2286 2286 webseedCount = tr_ptrArraySize( &t->webseeds ); 2287 2287 assert( webseedCount == tor->info.webseedCount ); 2288 ret = tr_new0( float, webseedCount );2288 ret = tr_new0( int, webseedCount ); 2289 2289 now = tr_date( ); 2290 2290 2291 2291 for( i=0; i<webseedCount; ++i ) 2292 if( !tr_webseedGetSpeed ( webseeds[i], now, &ret[i] ) )2292 if( !tr_webseedGetSpeed_Bps( webseeds[i], now, &ret[i] ) ) 2293 2293 ret[i] = -1.0; 2294 2294 … … 2297 2297 } 2298 2298 2299 double 2300 tr_peerGetPieceSpeed ( const tr_peer * peer, uint64_t now, tr_direction direction )2301 { 2302 return peer->io ? tr_peerIoGetPieceSpeed ( peer->io, now, direction ) : 0.0;2299 int 2300 tr_peerGetPieceSpeed_Bps( const tr_peer * peer, uint64_t now, tr_direction direction ) 2301 { 2302 return peer->io ? tr_peerIoGetPieceSpeed_Bps( peer->io, now, direction ) : 0.0; 2303 2303 } 2304 2304 … … 2337 2337 stat->progress = peer->progress; 2338 2338 stat->isEncrypted = tr_peerIoIsEncrypted( peer->io ) ? 1 : 0; 2339 stat->rateToPeer = tr_peerGetPieceSpeed( peer, now, TR_CLIENT_TO_PEER );2340 stat->rateToClient = tr_peerGetPieceSpeed( peer, now, TR_PEER_TO_CLIENT );2339 stat->rateToPeer_Bps = tr_peerGetPieceSpeed_Bps( peer, now, TR_CLIENT_TO_PEER ); 2340 stat->rateToClient_Bps = tr_peerGetPieceSpeed_Bps( peer, now, TR_PEER_TO_CLIENT ); 2341 2341 stat->peerIsChoked = peer->peerIsChoked; 2342 2342 stat->peerIsInterested = peer->peerIsInterested; … … 2614 2614 getRate( const tr_torrent * tor, struct peer_atom * atom, uint64_t now ) 2615 2615 { 2616 double KiB_s;2616 int Bps; 2617 2617 2618 2618 if( tr_torrentIsSeed( tor ) ) 2619 KiB_s = tr_peerGetPieceSpeed( atom->peer, now, TR_CLIENT_TO_PEER );2619 Bps = tr_peerGetPieceSpeed_Bps( atom->peer, now, TR_CLIENT_TO_PEER ); 2620 2620 2621 2621 /* downloading a private torrent... take upload speed into account 2622 2622 * because there may only be a small window of opportunity to share */ 2623 2623 else if( tr_torrentIsPrivate( tor ) ) 2624 KiB_s = tr_peerGetPieceSpeed( atom->peer, now, TR_PEER_TO_CLIENT )2625 + tr_peerGetPieceSpeed( atom->peer, now, TR_CLIENT_TO_PEER );2624 Bps = tr_peerGetPieceSpeed_Bps( atom->peer, now, TR_PEER_TO_CLIENT ) 2625 + tr_peerGetPieceSpeed_Bps( atom->peer, now, TR_CLIENT_TO_PEER ); 2626 2626 2627 2627 /* downloading a public torrent */ 2628 2628 else 2629 KiB_s = tr_peerGetPieceSpeed( atom->peer, now, TR_PEER_TO_CLIENT );2629 Bps = tr_peerGetPieceSpeed_Bps( atom->peer, now, TR_PEER_TO_CLIENT ); 2630 2630 2631 2631 /* convert it to bytes per second */ 2632 return (int)( KiB_s * 1024 );2632 return Bps; 2633 2633 } 2634 2634 … … 2996 2996 l->pieceDataTime = p->atom->piece_data_time; 2997 2997 l->time = p->atom->time; 2998 l->speed = 1024.0 * ( tr_peerGetPieceSpeed( p, now, TR_UP )2999 + tr_peerGetPieceSpeed( p, now, TR_DOWN ));2998 l->speed = tr_peerGetPieceSpeed_Bps( p, now, TR_UP ) 2999 + tr_peerGetPieceSpeed_Bps( p, now, TR_DOWN ); 3000 3000 if( clientData ) 3001 3001 l->clientData = clientData[i]; … … 3316 3316 return FALSE; 3317 3317 else { 3318 const double got = tr_bandwidthGetPieceSpeed( b, now_msec, dir );3319 const double want = tr_bandwidthGetDesiredSpeed( b, dir );3318 const int got = tr_bandwidthGetPieceSpeed_Bps( b, now_msec, dir ); 3319 const int want = tr_bandwidthGetDesiredSpeed_Bps( b, dir ); 3320 3320 return got >= want; 3321 3321 } -
trunk/libtransmission/peer-mgr.h
r10800 r10931 226 226 int * setmeCount ); 227 227 228 float tr_peerMgrGetWebseedSpeed( const tr_torrent * tor, uint64_t now );229 230 float* tr_peerMgrWebSpeeds( const tr_torrent * tor );231 232 233 double tr_peerGetPieceSpeed( const tr_peer * peer,234 uint64_t now,235 tr_direction direction );228 int tr_peerMgrGetWebseedSpeed_Bps( const tr_torrent * tor, uint64_t now ); 229 230 int* tr_peerMgrWebSpeeds_Bps( const tr_torrent * tor ); 231 232 233 int tr_peerGetPieceSpeed_Bps( const tr_peer * peer, 234 uint64_t now, 235 tr_direction direction ); 236 236 237 237 /* @} */ -
trunk/libtransmission/peer-msgs.c
r10800 r10931 1701 1701 else 1702 1702 { 1703 int irate;1704 1703 int estimatedBlocksInPeriod; 1705 double rate; 1704 int rate_Bps; 1705 int irate_Bps; 1706 1706 const int floor = 4; 1707 1707 const int seconds = REQUEST_BUF_SECS; … … 1709 1709 /* Get the rate limit we should use. 1710 1710 * FIXME: this needs to consider all the other peers as well... */ 1711 rate = tr_peerGetPieceSpeed( msgs->peer, now, TR_PEER_TO_CLIENT );1711 rate_Bps = tr_peerGetPieceSpeed_Bps( msgs->peer, now, TR_PEER_TO_CLIENT ); 1712 1712 if( tr_torrentUsesSpeedLimit( torrent, TR_PEER_TO_CLIENT ) ) 1713 rate = MIN( rate, tr_torrentGetSpeedLimit( torrent, TR_PEER_TO_CLIENT ) );1713 rate_Bps = MIN( rate_Bps, tr_torrentGetSpeedLimit_Bps( torrent, TR_PEER_TO_CLIENT ) ); 1714 1714 1715 1715 /* honor the session limits, if enabled */ 1716 1716 if( tr_torrentUsesSessionLimits( torrent ) ) 1717 if( tr_sessionGetActiveSpeedLimit ( torrent->session, TR_PEER_TO_CLIENT, &irate) )1718 rate = MIN( rate, irate);1717 if( tr_sessionGetActiveSpeedLimit_Bps( torrent->session, TR_PEER_TO_CLIENT, &irate_Bps ) ) 1718 rate_Bps = MIN( rate_Bps, irate_Bps ); 1719 1719 1720 1720 /* use this desired rate to figure out how 1721 1721 * many requests we should send to this peer */ 1722 estimatedBlocksInPeriod = ( rate * seconds * 1024) / torrent->blockSize;1722 estimatedBlocksInPeriod = ( rate_Bps * seconds ) / torrent->blockSize; 1723 1723 msgs->desiredRequestCount = MAX( floor, estimatedBlocksInPeriod ); 1724 1724 -
trunk/libtransmission/ratecontrol.c
r7618 r10931 31 31 32 32 /* return the xfer rate over the last `interval' seconds in KiB/sec */ 33 static float33 static int 34 34 rateForInterval( const tr_ratecontrol * r, 35 35 int interval_msec, … … 51 51 } 52 52 53 return ( bytes / 1024.0 )* ( 1000.0 / interval_msec );53 return bytes * ( 1000.0 / interval_msec ); 54 54 } 55 55 … … 58 58 ***/ 59 59 60 float61 tr_rcRate ( const tr_ratecontrol * r, uint64_t now )60 int 61 tr_rcRate_Bps( const tr_ratecontrol * r, uint64_t now ) 62 62 { 63 float ret = 0.0f;63 int ret = 0; 64 64 65 65 if( r ) -
trunk/libtransmission/ratecontrol.h
r9847 r10931 71 71 size_t byteCount ); 72 72 73 float tr_rcRate( const tr_ratecontrol * ratecontrol,74 73 int tr_rcRate_Bps ( const tr_ratecontrol * ratecontrol, 74 uint64_t now ); 75 75 76 76 -
trunk/libtransmission/resume.c
r10502 r10931 47 47 #define KEY_UPLOADED "uploaded" 48 48 49 #define KEY_SPEED "speed" 49 #define KEY_SPEED_KiBps "speed" 50 #define KEY_SPEED_Bps "speed-Bps" 50 51 #define KEY_USE_GLOBAL_SPEED_LIMIT "use-global-speed-limit" 51 52 #define KEY_USE_SPEED_LIMIT "use-speed-limit" … … 270 271 { 271 272 tr_bencDictReserve( d, 3 ); 272 tr_bencDictAddInt( d, KEY_SPEED , tr_torrentGetSpeedLimit( tor, dir ) );273 tr_bencDictAddInt( d, KEY_SPEED_Bps, tr_torrentGetSpeedLimit_Bps( tor, dir ) ); 273 274 tr_bencDictAddBool( d, KEY_USE_GLOBAL_SPEED_LIMIT, tr_torrentUsesSessionLimits( tor ) ); 274 275 tr_bencDictAddBool( d, KEY_USE_SPEED_LIMIT, tr_torrentUsesSpeedLimit( tor, dir ) ); … … 296 297 tr_bool boolVal; 297 298 298 if( tr_bencDictFindInt( d, KEY_SPEED, &i ) ) 299 tr_torrentSetSpeedLimit( tor, dir, i ); 299 if( tr_bencDictFindInt( d, KEY_SPEED_Bps, &i ) ) 300 tr_torrentSetSpeedLimit_Bps( tor, dir, i ); 301 else if( tr_bencDictFindInt( d, KEY_SPEED_KiBps, &i ) ) 302 tr_torrentSetSpeedLimit_Bps( tor, dir, i*1024 ); 300 303 301 304 if( tr_bencDictFindBool( d, KEY_USE_SPEED_LIMIT, &boolVal ) ) … … 335 338 int64_t i; 336 339 if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_DOWN_SPEED, &i ) ) 337 tr_torrentSetSpeedLimit ( tor, TR_DOWN, i);340 tr_torrentSetSpeedLimit_Bps( tor, TR_DOWN, i*1024 ); 338 341 if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_DOWN_MODE, &i ) ) { 339 342 tr_torrentUseSpeedLimit( tor, TR_DOWN, i==TR_SPEEDLIMIT_SINGLE ); … … 341 344 } 342 345 if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_UP_SPEED, &i ) ) 343 tr_torrentSetSpeedLimit ( tor, TR_UP, i);346 tr_torrentSetSpeedLimit_Bps( tor, TR_UP, i*1024 ); 344 347 if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_UP_MODE, &i ) ) { 345 348 tr_torrentUseSpeedLimit( tor, TR_UP, i==TR_SPEEDLIMIT_SINGLE ); -
trunk/libtransmission/rpcimpl.c
r10906 r10931 443 443 tr_bencDictAddInt ( d, "port", peer->port ); 444 444 tr_bencDictAddReal( d, "progress", peer->progress ); 445 tr_bencDictAddInt ( d, "rateToClient", (int)( peer->rateToClient * 1024.0 ));446 tr_bencDictAddInt ( d, "rateToPeer", (int)( peer->rateToPeer * 1024.0 ));445 tr_bencDictAddInt ( d, "rateToClient", peer->rateToClient_Bps ); 446 tr_bencDictAddInt ( d, "rateToPeer", peer->rateToPeer_Bps ); 447 447 } 448 448 … … 485 485 tr_bencDictAddInt( d, key, st->downloadedEver ); 486 486 else if( tr_streq( key, keylen, "downloadLimit" ) ) 487 tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit ( tor, TR_DOWN ) );487 tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit_Bps( tor, TR_DOWN ) ); 488 488 else if( tr_streq( key, keylen, "downloadLimited" ) ) 489 489 tr_bencDictAddBool( d, key, tr_torrentUsesSpeedLimit( tor, TR_DOWN ) ); … … 570 570 } 571 571 else if( tr_streq( key, keylen, "rateDownload" ) ) 572 tr_bencDictAddInt( d, key, (int)( st->pieceDownloadSpeed * 1024 ));572 tr_bencDictAddInt( d, key, st->pieceDownloadSpeed_Bps ); 573 573 else if( tr_streq( key, keylen, "rateUpload" ) ) 574 tr_bencDictAddInt( d, key, (int)( st->pieceUploadSpeed * 1024 ));574 tr_bencDictAddInt( d, key, st->pieceUploadSpeed_Bps ); 575 575 else if( tr_streq( key, keylen, "recheckProgress" ) ) 576 576 tr_bencDictAddReal( d, key, st->recheckProgress ); … … 600 600 tr_bencDictAddInt( d, key, st->uploadedEver ); 601 601 else if( tr_streq( key, keylen, "uploadLimit" ) ) 602 tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit ( tor, TR_UP ) );602 tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit_Bps( tor, TR_UP ) ); 603 603 else if( tr_streq( key, keylen, "uploadLimited" ) ) 604 604 tr_bencDictAddBool( d, key, tr_torrentUsesSpeedLimit( tor, TR_UP ) ); … … 1005 1005 errmsg = setFilePriorities( tor, TR_PRI_NORMAL, files ); 1006 1006 if( tr_bencDictFindInt( args_in, "downloadLimit", &tmp ) ) 1007 tr_torrentSetSpeedLimit ( tor, TR_DOWN, tmp );1007 tr_torrentSetSpeedLimit_Bps( tor, TR_DOWN, tmp ); 1008 1008 if( tr_bencDictFindBool( args_in, "downloadLimited", &boolVal ) ) 1009 1009 tr_torrentUseSpeedLimit( tor, TR_DOWN, boolVal ); … … 1011 1011 tr_torrentUseSessionLimits( tor, boolVal ); 1012 1012 if( tr_bencDictFindInt( args_in, "uploadLimit", &tmp ) ) 1013 tr_torrentSetSpeedLimit ( tor, TR_UP, tmp );1013 tr_torrentSetSpeedLimit_Bps( tor, TR_UP, tmp ); 1014 1014 if( tr_bencDictFindBool( args_in, "uploadLimited", &boolVal ) ) 1015 1015 tr_torrentUseSpeedLimit( tor, TR_UP, boolVal ); … … 1408 1408 assert( idle_data == NULL ); 1409 1409 1410 if( tr_bencDictFind Real( args_in, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, &d) )1410 if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_MAX_CACHE_SIZE, &i ) ) 1411 1411 tr_sessionSetCacheLimit( session, d ); 1412 if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_UP , &i ) )1413 tr_sessionSetAltSpeed ( session, TR_UP, i );1414 if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_DOWN , &i ) )1415 tr_sessionSetAltSpeed ( session, TR_DOWN, i );1412 if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_UP_Bps, &i ) ) 1413 tr_sessionSetAltSpeed_Bps( session, TR_UP, i ); 1414 if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, &i ) ) 1415 tr_sessionSetAltSpeed_Bps( session, TR_DOWN, i ); 1416 1416 if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_ALT_SPEED_ENABLED, &boolVal ) ) 1417 1417 tr_sessionUseAltSpeed( session, boolVal ); … … 1462 1462 if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_TRASH_ORIGINAL, &boolVal ) ) 1463 1463 tr_sessionSetDeleteSource( session, boolVal ); 1464 if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_DSPEED , &i ) )1465 tr_sessionSetSpeedLimit ( session, TR_DOWN, i );1464 if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_DSPEED_Bps, &i ) ) 1465 tr_sessionSetSpeedLimit_Bps( session, TR_DOWN, i ); 1466 1466 if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_DSPEED_ENABLED, &boolVal ) ) 1467 1467 tr_sessionLimitSpeed( session, TR_DOWN, boolVal ); 1468 if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_USPEED , &i ) )1469 tr_sessionSetSpeedLimit ( session, TR_UP, i );1468 if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_USPEED_Bps, &i ) ) 1469 tr_sessionSetSpeedLimit_Bps( session, TR_UP, i ); 1470 1470 if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_USPEED_ENABLED, &boolVal ) ) 1471 1471 tr_sessionLimitSpeed( session, TR_UP, boolVal ); … … 1509 1509 1510 1510 tr_bencDictAddInt( args_out, "activeTorrentCount", running ); 1511 tr_bencDictAddInt( args_out, "downloadSpeed", (int)( tr_sessionGetPieceSpeed( session, TR_DOWN ) * 1024) );1511 tr_bencDictAddInt( args_out, "downloadSpeed", tr_sessionGetPieceSpeed_Bps( session, TR_DOWN ) ); 1512 1512 tr_bencDictAddInt( args_out, "pausedTorrentCount", total - running ); 1513 1513 tr_bencDictAddInt( args_out, "torrentCount", total ); 1514 tr_bencDictAddInt( args_out, "uploadSpeed", (int)( tr_sessionGetPieceSpeed( session, TR_UP ) * 1024) );1514 tr_bencDictAddInt( args_out, "uploadSpeed", tr_sessionGetPieceSpeed_Bps( session, TR_UP ) ); 1515 1515 1516 1516 d = tr_bencDictAddDict( args_out, "cumulative-stats", 5 ); … … 1541 1541 1542 1542 assert( idle_data == NULL ); 1543 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP , tr_sessionGetAltSpeed(s,TR_UP) );1544 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN , tr_sessionGetAltSpeed(s,TR_DOWN) );1543 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP_Bps, tr_sessionGetAltSpeed_Bps(s,TR_UP) ); 1544 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, tr_sessionGetAltSpeed_Bps(s,TR_DOWN) ); 1545 1545 tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_ENABLED, tr_sessionUsesAltSpeed(s) ); 1546 1546 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, tr_sessionGetAltSpeedBegin(s) ); … … 1549 1549 tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, tr_sessionUsesAltSpeedTime(s) ); 1550 1550 tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled( s ) ); 1551 tr_bencDictAddReal( d, TR_PREFS_KEY_MAX_CACHE_SIZE _MiB, tr_sessionGetCacheLimit( s ) );1551 tr_bencDictAddReal( d, TR_PREFS_KEY_MAX_CACHE_SIZE, tr_sessionGetCacheLimit( s ) ); 1552 1552 tr_bencDictAddInt ( d, "blocklist-size", tr_blocklistGetRuleCount( s ) ); 1553 1553 tr_bencDictAddStr ( d, "config-dir", tr_sessionGetConfigDir( s ) ); … … 1570 1570 tr_bencDictAddBool( d, TR_PREFS_KEY_START, !tr_sessionGetPaused( s ) ); 1571 1571 tr_bencDictAddBool( d, TR_PREFS_KEY_TRASH_ORIGINAL, tr_sessionGetDeleteSource( s ) ); 1572 tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED , tr_sessionGetSpeedLimit( s, TR_UP ) );1572 tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_Bps, tr_sessionGetSpeedLimit_Bps( s, TR_UP ) ); 1573 1573 tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, tr_sessionIsSpeedLimited( s, TR_UP ) ); 1574 tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED , tr_sessionGetSpeedLimit( s, TR_DOWN ) );1574 tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_Bps, tr_sessionGetSpeedLimit_Bps( s, TR_DOWN ) ); 1575 1575 tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, tr_sessionIsSpeedLimited( s, TR_DOWN ) ); 1576 1576 tr_bencDictAddStr ( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, tr_sessionGetTorrentDoneScript( s ) ); -
trunk/libtransmission/session.c
r10798 r10931 24 24 #include <event.h> 25 25 26 //#define TR_SHOW_DEPRECATED 26 27 #include "transmission.h" 27 28 #include "announcer.h" … … 55 56 SAVE_INTERVAL_SECS = 120, 56 57 57 DEFAULT_CACHE_SIZE_ MiB = 2/* 2 MiB */58 DEFAULT_CACHE_SIZE_BYTES = ( 2 * 1024 * 1024 ) /* 2 MiB */ 58 59 }; 59 60 … … 241 242 #endif 242 243 244 static tr_bool 245 getSpeedFromDict( tr_benc * dict, const char * key_in, int64_t * Bps ) 246 { 247 int64_t i; 248 char key[256]; 249 250 /* 1. look for it ending in -Bps */ 251 tr_snprintf( key, sizeof( key ), "%s-Bps", key_in ); 252 if( tr_bencDictFindInt( dict, key, &i ) ) { 253 *Bps = i; 254 return TRUE; 255 } 256 257 /* 2. look for it an old entry without the -Bps suffix. 258 if found, interpret that to be either kB/s or KiB/s 259 based on the formatter settings in utils */ 260 if( tr_bencDictFindInt( dict, key_in, &i ) ) { 261 *Bps = i * tr_formatter_speed_k( ); 262 return TRUE; 263 } 264 265 return FALSE; 266 } 267 243 268 void 244 269 tr_sessionGetDefaultSettings( const char * configDir UNUSED, tr_benc * d ) 245 270 { 271 const int speed_K = tr_formatter_speed_k( ); 272 246 273 assert( tr_bencIsDict( d ) ); 247 274 248 275 tr_bencDictReserve( d, 60 ); 249 276 tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, FALSE ); 250 tr_bencDictAdd Real( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, DEFAULT_CACHE_SIZE_MiB);277 tr_bencDictAddInt ( d, TR_PREFS_KEY_MAX_CACHE_SIZE, DEFAULT_CACHE_SIZE_BYTES ); 251 278 tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, TRUE ); 252 279 tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED, FALSE ); 253 280 tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR, tr_getDefaultDownloadDir( ) ); 254 tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED , 100);281 tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_Bps, 100 * speed_K ); 255 282 tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, FALSE ); 256 283 tr_bencDictAddInt ( d, TR_PREFS_KEY_ENCRYPTION, TR_DEFAULT_ENCRYPTION ); … … 291 318 tr_bencDictAddBool( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, FALSE ); 292 319 tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_ENABLED, FALSE ); 293 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP , 50); /* half the regular */294 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN , 50); /* half the regular */320 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP_Bps, 50 * speed_K ); /* half the regular */ 321 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, 50 * speed_K ); /* half the regular */ 295 322 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, 540 ); /* 9am */ 296 323 tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, FALSE ); 297 324 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_END, 1020 ); /* 5pm */ 298 325 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, TR_SCHED_ALL ); 299 tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED , 100);326 tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_Bps, 100 * speed_K ); 300 327 tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, FALSE ); 301 328 tr_bencDictAddInt ( d, TR_PREFS_KEY_UMASK, 022 ); … … 314 341 tr_bencDictReserve( d, 60 ); 315 342 tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled( s ) ); 316 tr_bencDictAdd Real( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB,tr_cacheGetLimit( s->cache ) );343 tr_bencDictAddInt ( d, TR_PREFS_KEY_MAX_CACHE_SIZE, tr_cacheGetLimit( s->cache ) ); 317 344 tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, s->isDHTEnabled ); 318 345 tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED, s->isLPDEnabled ); 319 346 tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR, s->downloadDir ); 320 tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED , tr_sessionGetSpeedLimit( s, TR_DOWN ) );347 tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_Bps, tr_sessionGetSpeedLimit_Bps( s, TR_DOWN ) ); 321 348 tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, tr_sessionIsSpeedLimited( s, TR_DOWN ) ); 322 349 tr_bencDictAddInt ( d, TR_PREFS_KEY_ENCRYPTION, s->encryptionMode ); … … 359 386 tr_bencDictAddStr ( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, tr_sessionGetTorrentDoneScript( s ) ); 360 387 tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_ENABLED, tr_sessionUsesAltSpeed( s ) ); 361 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP , tr_sessionGetAltSpeed( s, TR_UP ) );362 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN , tr_sessionGetAltSpeed( s, TR_DOWN ) );388 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP_Bps, tr_sessionGetAltSpeed_Bps( s, TR_UP ) ); 389 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, tr_sessionGetAltSpeed_Bps( s, TR_DOWN ) ); 363 390 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, tr_sessionGetAltSpeedBegin( s ) ); 364 391 tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, tr_sessionUsesAltSpeedTime( s ) ); 365 392 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_END, tr_sessionGetAltSpeedEnd( s ) ); 366 393 tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, tr_sessionGetAltSpeedDay( s ) ); 367 tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED , tr_sessionGetSpeedLimit( s, TR_UP ) );394 tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_Bps, tr_sessionGetSpeedLimit_Bps( s, TR_UP ) ); 368 395 tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, tr_sessionIsSpeedLimited( s, TR_UP ) ); 369 396 tr_bencDictAddInt ( d, TR_PREFS_KEY_UMASK, s->umask ); … … 512 539 session->bandwidth = tr_bandwidthNew( session, NULL ); 513 540 session->lock = tr_lockNew( ); 514 session->cache = tr_cacheNew( DEFAULT_CACHE_SIZE_ MiB);541 session->cache = tr_cacheNew( DEFAULT_CACHE_SIZE_BYTES ); 515 542 session->tag = tr_strdup( tag ); 516 543 session->magicNumber = SESSION_MAGIC_NUMBER; … … 678 705 679 706 /* misc features */ 680 if( tr_bencDictFind Real( settings, TR_PREFS_KEY_MAX_CACHE_SIZE_MiB, &d) )681 tr_sessionSetCacheLimit( session, d);707 if( tr_bencDictFindInt( settings, TR_PREFS_KEY_MAX_CACHE_SIZE, &i ) ) 708 tr_sessionSetCacheLimit( session, i ); 682 709 if( tr_bencDictFindBool( settings, TR_PREFS_KEY_LAZY_BITFIELD, &boolVal ) ) 683 710 tr_sessionSetLazyBitfieldEnabled( session, boolVal ); … … 779 806 session->uploadSlotsPerTorrent = i; 780 807 781 if( tr_bencDictFindInt( settings, TR_PREFS_KEY_USPEED, &i ) )782 tr_sessionSetSpeedLimit ( session, TR_UP, i );808 if( getSpeedFromDict( settings, "speed-limit-up", &i ) ) 809 tr_sessionSetSpeedLimit_Bps( session, TR_UP, i ); 783 810 if( tr_bencDictFindBool( settings, TR_PREFS_KEY_USPEED_ENABLED, &boolVal ) ) 784 811 tr_sessionLimitSpeed( session, TR_UP, boolVal ); 785 812 786 if( tr_bencDictFindInt( settings, TR_PREFS_KEY_DSPEED, &i ) )787 tr_sessionSetSpeedLimit ( session, TR_DOWN, i );813 if( getSpeedFromDict( settings, "speed-limit-down", &i ) ) 814 tr_sessionSetSpeedLimit_Bps( session, TR_DOWN, i ); 788 815 if( tr_bencDictFindBool( settings, TR_PREFS_KEY_DSPEED_ENABLED, &boolVal ) ) 789 816 tr_sessionLimitSpeed( session, TR_DOWN, boolVal ); … … 799 826 800 827 /* update the turtle mode's fields */ 801 if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_UP, &i ) )802 turtle->speedLimit [TR_UP] = i;803 if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_DOWN, &i ) )804 turtle->speedLimit [TR_DOWN] = i;828 if( getSpeedFromDict( settings, "alt-speed-up", &i ) ) 829 turtle->speedLimit_Bps[TR_UP] = i; 830 if( getSpeedFromDict( settings, "alt-speed-down", &i ) ) 831 turtle->speedLimit_Bps[TR_DOWN] = i; 805 832 if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &i ) ) 806 833 turtle->beginMinute = i; … … 1101 1128 1102 1129 tr_bool 1103 tr_sessionGetActiveSpeedLimit ( const tr_session * session, tr_direction dir, int * setme )1130 tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session, tr_direction dir, int * setme ) 1104 1131 { 1105 1132 int isLimited = TRUE; … … 1109 1136 1110 1137 if( tr_sessionUsesAltSpeed( session ) ) 1111 *setme = tr_sessionGetAltSpeed ( session, dir );1138 *setme = tr_sessionGetAltSpeed_Bps( session, dir ); 1112 1139 else if( tr_sessionIsSpeedLimited( session, dir ) ) 1113 *setme = tr_sessionGetSpeedLimit ( session, dir );1140 *setme = tr_sessionGetSpeedLimit_Bps( session, dir ); 1114 1141 else 1115 1142 isLimited = FALSE; … … 1121 1148 updateBandwidth( tr_session * session, tr_direction dir ) 1122 1149 { 1123 int limit = 0;1124 const tr_bool isLimited = tr_sessionGetActiveSpeedLimit ( session, dir, &limit);1125 const tr_bool zeroCase = isLimited && !limit ;1150 int limit_Bps = 0; 1151 const tr_bool isLimited = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &limit_Bps ); 1152 const tr_bool zeroCase = isLimited && !limit_Bps; 1126 1153 1127 1154 tr_bandwidthSetLimited( session->bandwidth, dir, isLimited && !zeroCase ); 1128 1155 1129 tr_bandwidthSetDesiredSpeed ( session->bandwidth, dir, limit);1156 tr_bandwidthSetDesiredSpeed_Bps( session->bandwidth, dir, limit_Bps ); 1130 1157 } 1131 1158 … … 1268 1295 1269 1296 void 1270 tr_sessionSetSpeedLimit ( tr_session * s, tr_direction d, int KB_s )1297 tr_sessionSetSpeedLimit_Bps( tr_session * s, tr_direction d, int Bps ) 1271 1298 { 1272 1299 assert( tr_isSession( s ) ); 1273 1300 assert( tr_isDirection( d ) ); 1274 assert( KB_s >= 0 );1275 1276 s->speedLimit [d] = KB_s;1301 assert( Bps >= 0 ); 1302 1303 s->speedLimit_Bps[d] = Bps; 1277 1304 1278 1305 updateBandwidth( s, d ); … … 1280 1307 1281 1308 int 1282 tr_sessionGetSpeedLimit ( const tr_session * s, tr_direction d )1309 tr_sessionGetSpeedLimit_Bps( const tr_session * s, tr_direction d ) 1283 1310 { 1284 1311 assert( tr_isSession( s ) ); 1285 1312 assert( tr_isDirection( d ) ); 1286 1313 1287 return s->speedLimit [d];1314 return s->speedLimit_Bps[d]; 1288 1315 } 1289 1316 … … 1314 1341 1315 1342 void 1316 tr_sessionSetAltSpeed ( tr_session * s, tr_direction d, int KB_s )1343 tr_sessionSetAltSpeed_Bps( tr_session * s, tr_direction d, int Bps ) 1317 1344 { 1318 1345 assert( tr_isSession( s ) ); 1319 1346 assert( tr_isDirection( d ) ); 1320 assert( KB_s >= 0 );1321 1322 s->turtle.speedLimit [d] = KB_s;1347 assert( Bps >= 0 ); 1348 1349 s->turtle.speedLimit_Bps[d] = Bps; 1323 1350 1324 1351 updateBandwidth( s, d ); … … 1326 1353 1327 1354 int 1328 tr_sessionGetAltSpeed ( const tr_session * s, tr_direction d )1355 tr_sessionGetAltSpeed_Bps( const tr_session * s, tr_direction d ) 1329 1356 { 1330 1357 assert( tr_isSession( s ) ); 1331 1358 assert( tr_isDirection( d ) ); 1332 1359 1333 return s->turtle.speedLimit [d];1360 return s->turtle.speedLimit_Bps[d]; 1334 1361 } 1335 1362 … … 1537 1564 ***/ 1538 1565 1539 double 1540 tr_sessionGetPieceSpeed ( const tr_session * session, tr_direction dir )1541 { 1542 return tr_isSession( session ) ? tr_bandwidthGetPieceSpeed ( session->bandwidth, 0, dir ) : 0.0;1543 } 1544 1545 double 1546 tr_sessionGetRawSpeed ( const tr_session * session, tr_direction dir )1547 { 1548 return tr_isSession( session ) ? tr_bandwidthGetRawSpeed ( session->bandwidth, 0, dir ) : 0.0;1566 int 1567 tr_sessionGetPieceSpeed_Bps( const tr_session * session, tr_direction dir ) 1568 { 1569 return tr_isSession( session ) ? tr_bandwidthGetPieceSpeed_Bps( session->bandwidth, 0, dir ) : 0.0; 1570 } 1571 1572 int 1573 tr_sessionGetRawSpeed_Bps( const tr_session * session, tr_direction dir ) 1574 { 1575 return tr_isSession( session ) ? tr_bandwidthGetRawSpeed_Bps( session->bandwidth, 0, dir ) : 0.0; 1549 1576 } 1550 1577 … … 1850 1877 1851 1878 void 1852 tr_sessionSetCacheLimit( tr_session * session, double maxMiB)1853 { 1854 assert( tr_isSession( session ) ); 1855 1856 tr_cacheSetLimit( session->cache, max MiB);1857 } 1858 1859 double 1879 tr_sessionSetCacheLimit( tr_session * session, int64_t max_bytes ) 1880 { 1881 assert( tr_isSession( session ) ); 1882 1883 tr_cacheSetLimit( session->cache, max_bytes ); 1884 } 1885 1886 int64_t 1860 1887 tr_sessionGetCacheLimit( const tr_session * session ) 1861 1888 { -
trunk/libtransmission/session.h
r10798 r10931 47 47 { 48 48 /* TR_UP and TR_DOWN speed limits */ 49 int speedLimit [2];49 int speedLimit_Bps[2]; 50 50 51 51 /* is turtle mode on right now? */ … … 103 103 int umask; 104 104 105 int speedLimit [2];105 int speedLimit_Bps[2]; 106 106 tr_bool speedLimitEnabled[2]; 107 107 -
trunk/libtransmission/torrent.c
r10919 r10931 130 130 131 131 void 132 tr_torrentSetSpeedLimit ( tr_torrent * tor, tr_direction dir, int KiB_sec)132 tr_torrentSetSpeedLimit_Bps( tr_torrent * tor, tr_direction dir, int Bps ) 133 133 { 134 134 assert( tr_isTorrent( tor ) ); 135 135 assert( tr_isDirection( dir ) ); 136 137 if( tr_bandwidthSetDesiredSpeed( tor->bandwidth, dir, KiB_sec ) ) 136 assert( Bps >= 0 ); 137 138 if( tr_bandwidthSetDesiredSpeed_Bps( tor->bandwidth, dir, Bps ) ) 138 139 tr_torrentSetDirty( tor ); 139 140 } 140 141 141 142 int 142 tr_torrentGetSpeedLimit ( const tr_torrent * tor, tr_direction dir )143 tr_torrentGetSpeedLimit_Bps( const tr_torrent * tor, tr_direction dir ) 143 144 { 144 145 assert( tr_isTorrent( tor ) ); 145 146 assert( tr_isDirection( dir ) ); 146 147 147 return tr_bandwidthGetDesiredSpeed ( tor->bandwidth, dir );148 return tr_bandwidthGetDesiredSpeed_Bps( tor->bandwidth, dir ); 148 149 } 149 150 … … 244 245 245 246 if( tr_torrentUsesSpeedLimit( tor, direction ) ) 246 if( tr_torrentGetSpeedLimit ( tor, direction ) <= 0 )247 if( tr_torrentGetSpeedLimit_Bps( tor, direction ) <= 0 ) 247 248 allowed = FALSE; 248 249 249 250 if( tr_torrentUsesSessionLimits( tor ) ) 250 if( tr_sessionGetActiveSpeedLimit ( tor->session, direction, &limit ) )251 if( tr_sessionGetActiveSpeedLimit_Bps( tor->session, direction, &limit ) ) 251 252 if( limit <= 0 ) 252 253 allowed = FALSE; … … 686 687 { 687 688 tr_torrentUseSpeedLimit( tor, TR_UP, FALSE ); 688 tr_torrentSetSpeedLimit ( tor, TR_UP, tr_sessionGetSpeedLimit( tor->session, TR_UP ) );689 tr_torrentSetSpeedLimit_Bps( tor, TR_UP, tr_sessionGetSpeedLimit_Bps( tor->session, TR_UP ) ); 689 690 tr_torrentUseSpeedLimit( tor, TR_DOWN, FALSE ); 690 tr_torrentSetSpeedLimit ( tor, TR_DOWN, tr_sessionGetSpeedLimit( tor->session, TR_DOWN ) );691 tr_torrentSetSpeedLimit_Bps( tor, TR_DOWN, tr_sessionGetSpeedLimit_Bps( tor->session, TR_DOWN ) ); 691 692 tr_torrentUseSessionLimits( tor, TRUE ); 692 693 } … … 967 968 968 969 now = tr_date( ); 969 d = tr_peerMgrGetWebseedSpeed ( tor, now );970 s->rawUploadSpeed = tr_bandwidthGetRawSpeed( tor->bandwidth, now, TR_UP );971 s->pieceUploadSpeed = tr_bandwidthGetPieceSpeed( tor->bandwidth, now, TR_UP );972 s->rawDownloadSpeed = d + tr_bandwidthGetRawSpeed( tor->bandwidth, now, TR_DOWN );973 s->pieceDownloadSpeed = d + tr_bandwidthGetPieceSpeed( tor->bandwidth, now, TR_DOWN );970 d = tr_peerMgrGetWebseedSpeed_Bps( tor, now ); 971 s->rawUploadSpeed_Bps = tr_bandwidthGetRawSpeed_Bps ( tor->bandwidth, now, TR_UP ); 972 s->pieceUploadSpeed_Bps = tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_UP ); 973 s->rawDownloadSpeed_Bps = d + tr_bandwidthGetRawSpeed_Bps ( tor->bandwidth, now, TR_DOWN ); 974 s->pieceDownloadSpeed_Bps = d + tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_DOWN ); 974 975 975 976 usableSeeds += tor->info.webseedCount; … … 1032 1033 case TR_STATUS_DOWNLOAD: 1033 1034 if( ( tor->etaDLSpeedCalculatedAt + 800 ) < now ) { 1034 tor->etaDLSpeed = ( ( tor->etaDLSpeedCalculatedAt + 4000 ) < now )1035 ? s->pieceDownloadSpeed /* if no recent previous speed, no need to smooth */1036 : 0.8*tor->etaDLSpeed + 0.2*s->pieceDownloadSpeed; /* smooth across 5 readings */1035 tor->etaDLSpeed_Bps = ( ( tor->etaDLSpeedCalculatedAt + 4000 ) < now ) 1036 ? s->pieceDownloadSpeed_Bps /* if no recent previous speed, no need to smooth */ 1037 : ((tor->etaDLSpeed_Bps*4) + s->pieceDownloadSpeed_Bps)/5; /* smooth across 5 readings */ 1037 1038 tor->etaDLSpeedCalculatedAt = now; 1038 1039 } … … 1040 1041 if( s->leftUntilDone > s->desiredAvailable ) 1041 1042 s->eta = TR_ETA_NOT_AVAIL; 1042 else if( s->pieceDownloadSpeed < 0.1 )1043 else if( s->pieceDownloadSpeed_Bps < 1 ) 1043 1044 s->eta = TR_ETA_UNKNOWN; 1044 1045 else 1045 s->eta = s->leftUntilDone / tor->etaDLSpeed / 1024.0;1046 s->eta = s->leftUntilDone / tor->etaDLSpeed_Bps; 1046 1047 break; 1047 1048 … … 1051 1052 else { 1052 1053 if( ( tor->etaULSpeedCalculatedAt + 800 ) < now ) { 1053 tor->etaULSpeed = ( ( tor->etaULSpeedCalculatedAt + 4000 ) < now )1054 ? s->pieceUploadSpeed /* if no recent previous speed, no need to smooth */1055 : 0.8*tor->etaULSpeed + 0.2*s->pieceUploadSpeed; /* smooth across 5 readings */1054 tor->etaULSpeed_Bps = ( ( tor->etaULSpeedCalculatedAt + 4000 ) < now ) 1055 ? s->pieceUploadSpeed_Bps /* if no recent previous speed, no need to smooth */ 1056 : ((tor->etaULSpeed_Bps*4) + s->pieceUploadSpeed_Bps)/5; /* smooth across 5 readings */ 1056 1057 tor->etaULSpeedCalculatedAt = now; 1057 1058 } 1058 if( s->pieceUploadSpeed < 0.1 )1059 if( s->pieceUploadSpeed_Bps < 1 ) 1059 1060 s->eta = TR_ETA_UNKNOWN; 1060 1061 else 1061 s->eta = seedRatioBytesLeft / tor->etaULSpeed / 1024.0;1062 s->eta = seedRatioBytesLeft / tor->etaULSpeed_Bps; 1062 1063 } 1063 1064 break; … … 1193 1194 ***/ 1194 1195 1195 float* 1196 tr_torrentWebSpeeds( const tr_torrent * tor ) 1197 { 1198 return tr_isTorrent( tor ) 1199 ? tr_peerMgrWebSpeeds( tor ) 1200 : NULL; 1196 int* 1197 tr_torrentWebSpeeds_Bps( const tr_torrent * tor ) 1198 { 1199 return tr_isTorrent( tor ) ? tr_peerMgrWebSpeeds_Bps( tor ) : NULL; 1201 1200 } 1202 1201 -
trunk/libtransmission/torrent.h
r10918 r10931 211 211 212 212 uint64_t etaDLSpeedCalculatedAt; 213 double etaDLSpeed;213 int etaDLSpeed_Bps; 214 214 uint64_t etaULSpeedCalculatedAt; 215 double etaULSpeed;215 int etaULSpeed_Bps; 216 216 217 217 time_t addedDate; -
trunk/libtransmission/transmission.h
r10918 r10931 157 157 158 158 #define TR_PREFS_KEY_ALT_SPEED_ENABLED "alt-speed-enabled" 159 #define TR_PREFS_KEY_ALT_SPEED_UP "alt-speed-up"160 #define TR_PREFS_KEY_ALT_SPEED_DOWN "alt-speed-down"159 #define TR_PREFS_KEY_ALT_SPEED_UP_Bps "alt-speed-up-Bps" 160 #define TR_PREFS_KEY_ALT_SPEED_DOWN_Bps "alt-speed-down-Bps" 161 161 #define TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN "alt-speed-time-begin" 162 162 #define TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED "alt-speed-time-enabled" … … 166 166 #define TR_PREFS_KEY_BIND_ADDRESS_IPV6 "bind-address-ipv6" 167 167 #define TR_PREFS_KEY_BLOCKLIST_ENABLED "blocklist-enabled" 168 #define TR_PREFS_KEY_MAX_CACHE_SIZE _MiB "cache-size-MiB"168 #define TR_PREFS_KEY_MAX_CACHE_SIZE "cache-size-bytes" 169 169 #define TR_PREFS_KEY_DHT_ENABLED "dht-enabled" 170 170 #define TR_PREFS_KEY_LPD_ENABLED "lpd-enabled" … … 207 207 #define TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED "script-torrent-done-enabled" 208 208 #define TR_PREFS_KEY_RPC_WHITELIST "rpc-whitelist" 209 #define TR_PREFS_KEY_DSPEED "speed-limit-down"209 #define TR_PREFS_KEY_DSPEED_Bps "speed-limit-down-Bps" 210 210 #define TR_PREFS_KEY_DSPEED_ENABLED "speed-limit-down-enabled" 211 #define TR_PREFS_KEY_USPEED_Bps "speed-limit-up-Bps" 211 212 #define TR_PREFS_KEY_USPEED_ENABLED "speed-limit-up-enabled" 212 #define TR_PREFS_KEY_USPEED "speed-limit-up"213 213 #define TR_PREFS_KEY_UMASK "umask" 214 214 #define TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT "upload-slots-per-torrent" … … 599 599 void tr_sessionSetLPDEnabled( tr_session * session, tr_bool enabled ); 600 600 601 void tr_sessionSetCacheLimit( tr_session * session, double MiB);602 doubletr_sessionGetCacheLimit( const tr_session * session );601 void tr_sessionSetCacheLimit( tr_session * session, int64_t bytes ); 602 int64_t tr_sessionGetCacheLimit( const tr_session * session ); 603 603 604 604 void tr_sessionSetLazyBitfieldEnabled( tr_session * session, tr_bool enabled ); … … 658 658 ***/ 659 659 660 void tr_sessionSetSpeedLimit ( tr_session *, tr_direction, int KB_s );661 int tr_sessionGetSpeedLimit( const tr_session *, tr_direction );660 void tr_sessionSetSpeedLimit_Bps( tr_session *, tr_direction, int Bps ); 661 int tr_sessionGetSpeedLimit_Bps( const tr_session *, tr_direction ); 662 662 663 663 void tr_sessionLimitSpeed ( tr_session *, tr_direction, tr_bool ); … … 669 669 ***/ 670 670 671 void tr_sessionSetAltSpeed ( tr_session *, tr_direction, int KB_s );672 int tr_sessionGetAltSpeed( const tr_session *, tr_direction );671 void tr_sessionSetAltSpeed_Bps( tr_session *, tr_direction, int Bps ); 672 int tr_sessionGetAltSpeed_Bps( const tr_session *, tr_direction ); 673 673 674 674 void tr_sessionUseAltSpeed ( tr_session *, tr_bool ); … … 707 707 708 708 709 tr_bool tr_sessionGetActiveSpeedLimit( const tr_session * session,709 tr_bool tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session, 710 710 tr_direction dir, 711 711 int * setme ); 712 713 712 714 713 /*** … … 716 715 ***/ 717 716 718 double tr_sessionGetRawSpeed ( const tr_session *, tr_direction ); 719 double tr_sessionGetPieceSpeed ( const tr_session *, tr_direction ); 720 717 int tr_sessionGetRawSpeed_Bps ( const tr_session *, tr_direction ); 718 int tr_sessionGetPieceSpeed_Bps( const tr_session *, tr_direction ); 721 719 722 720 void tr_sessionSetRatioLimited ( tr_session *, tr_bool isLimited ); … … 1127 1125 ***/ 1128 1126 1129 void tr_torrentSetSpeedLimit 1130 int tr_torrentGetSpeedLimit 1127 void tr_torrentSetSpeedLimit_Bps ( tr_torrent *, tr_direction, int KB_s ); 1128 int tr_torrentGetSpeedLimit_Bps ( const tr_torrent *, tr_direction ); 1131 1129 1132 1130 void tr_torrentUseSpeedLimit ( tr_torrent *, tr_direction, tr_bool ); … … 1383 1381 1384 1382 float progress; 1385 float rateToPeer;1386 float rateToClient;1383 int rateToPeer_Bps; 1384 int rateToClient_Bps; 1387 1385 1388 1386 … … 1547 1545 * NOTE: always free this array with tr_free() when you're done with it. 1548 1546 */ 1549 float* tr_torrentWebSpeeds( const tr_torrent * torrent );1547 int* tr_torrentWebSpeeds_Bps( const tr_torrent * torrent ); 1550 1548 1551 1549 typedef struct tr_file_stat … … 1747 1745 double seedRatioPercentDone; 1748 1746 1749 /** Speed all data being sent for this torrent. (KiB/s)1747 /** Speed all data being sent for this torrent. 1750 1748 This includes piece data, protocol messages, and TCP overhead */ 1751 double rawUploadSpeed;1752 1753 /** Speed all data being received for this torrent. (KiB/s)1749 int rawUploadSpeed_Bps; 1750 1751 /** Speed all data being received for this torrent. 1754 1752 This includes piece data, protocol messages, and TCP overhead */ 1755 double rawDownloadSpeed;1756 1757 /** Speed all piece being sent for this torrent. (KiB/s)1753 int rawDownloadSpeed_Bps; 1754 1755 /** Speed all piece being sent for this torrent. 1758 1756 This ONLY counts piece data. */ 1759 double pieceUploadSpeed;1760 1761 /** Speed all piece being received for this torrent. (KiB/s)1757 int pieceUploadSpeed_Bps; 1758 1759 /** Speed all piece being received for this torrent. 1762 1760 This ONLY counts piece data. */ 1763 double pieceDownloadSpeed;1761 int pieceDownloadSpeed_Bps; 1764 1762 1765 1763 #define TR_ETA_NOT_AVAIL -1 -
trunk/libtransmission/utils-test.c
r10844 r10931 328 328 int n = sizeof( array ) / sizeof( array[0] ); 329 329 330 tr_removeElementFromArray( array, 5 , sizeof( int ), n-- );330 tr_removeElementFromArray( array, 5u, sizeof( int ), n-- ); 331 331 for( i=0; i<n; ++i ) 332 332 check( array[i] == ( i<5 ? i : i+1 ) ); 333 333 334 tr_removeElementFromArray( array, 0 , sizeof( int ), n-- );334 tr_removeElementFromArray( array, 0u, sizeof( int ), n-- ); 335 335 for( i=0; i<n; ++i ) 336 336 check( array[i] == ( i<4 ? i+1 : i+2 ) ); -
trunk/libtransmission/utils.c
r10921 r10931 1066 1066 1067 1067 if( length < 1 ) 1068 length = strlen( input );1068 length = (int)strlen( input ); 1069 1069 1070 1070 bmem = BIO_new( BIO_s_mem( ) ); … … 1470 1470 if( !pageSize ) { 1471 1471 #ifdef HAVE_GETPAGESIZE 1472 pageSize = getpagesize();1472 pageSize = (size_t) getpagesize(); 1473 1473 #else /* guess */ 1474 1474 pageSize = 4096; … … 1517 1517 { 1518 1518 char * name; 1519 doublevalue;1519 unsigned int value; 1520 1520 }; 1521 1521 … … 1525 1525 }; 1526 1526 1527 enum { TR_FMT_B, TR_FMT_KB, TR_FMT_MB, TR_FMT_GB }; 1528 1527 1529 static void 1528 1530 formatter_init( struct formatter_units * units, 1529 doublekilo,1531 unsigned int kilo, 1530 1532 const char * b, const char * kb, 1531 1533 const char * mb, const char * gb ) … … 1538 1540 1539 1541 units->units[TR_FMT_MB].name = tr_strdup( mb ); 1540 units->units[TR_FMT_MB].value = pow( kilo, 2 );1542 units->units[TR_FMT_MB].value = kilo * kilo; 1541 1543 1542 1544 units->units[TR_FMT_GB].name = tr_strdup( gb ); 1543 units->units[TR_FMT_GB].value = pow( kilo, 3 ); 1544 } 1545 1546 static const char* 1547 tr_formatter_units( const struct formatter_units * u, int size ) 1548 { 1549 assert( u != NULL ); 1550 assert( 0<=size && size<4 ); 1551 1552 return u->units[size].name; 1545 units->units[TR_FMT_GB].value = kilo * kilo * kilo; 1553 1546 } 1554 1547 … … 1567 1560 else unit = &u->units[3]; 1568 1561 1569 value = bytes / unit->value;1562 value = (double)bytes / unit->value; 1570 1563 units = unit->name; 1571 1564 if( unit->value == 1 ) … … 1582 1575 1583 1576 void 1584 tr_formatter_size_init( double kilo, const char * b, const char * kb, 1585 const char * mb, const char * gb ) 1577 tr_formatter_size_init( unsigned int kilo, 1578 const char * b, const char * kb, 1579 const char * mb, const char * gb ) 1586 1580 { 1587 1581 formatter_init( &size_units, kilo, b, kb, mb, gb ); … … 1594 1588 } 1595 1589 1596 const char*1597 tr_formatter_size_units( int i )1598 {1599 return tr_formatter_units( &size_units, i );1600 }1601 1602 1590 static struct formatter_units speed_units; 1603 1591 1604 1592 void 1605 tr_formatter_speed_init( double kilo, const char * b, const char * kb, 1606 const char * mb, const char * gb ) 1593 tr_formatter_speed_init( unsigned int kilo, 1594 const char * b, const char * kb, 1595 const char * mb, const char * gb ) 1607 1596 { 1608 1597 formatter_init( &speed_units, kilo, b, kb, mb, gb ); … … 1615 1604 } 1616 1605 1617 const char* 1618 tr_formatter_speed_units( int i ) 1619 { 1620 return tr_formatter_units( &speed_units, i ); 1621 } 1606 unsigned int 1607 tr_formatter_speed_k( void ) 1608 { 1609 return speed_units.units[TR_FMT_KB].value; 1610 } 1611 1612 static struct formatter_units mem_units; 1613 1614 void 1615 tr_formatter_mem_init( unsigned int kilo, 1616 const char * b, const char * kb, 1617 const char * mb, const char * gb ) 1618 { 1619 formatter_init( &mem_units, kilo, b, kb, mb, gb ); 1620 } 1621 1622 char* 1623 tr_formatter_mem( char * buf, uint64_t bytes_per_second, size_t buflen ) 1624 { 1625 return formatter_get_size_str( &mem_units, buf, bytes_per_second, buflen ); 1626 } -
trunk/libtransmission/utils.h
r10918 r10931 565 565 /* example: tr_formatter_size_init( 1024, _("B"), _("KiB"), _("MiB"), _("GiB") ); */ 566 566 567 void tr_formatter_size_init( doublekilo, const char * b, const char * kb,568 const char * mb, const char * gb );569 570 void tr_formatter_speed_init( doublekilo, const char * b, const char * kb,571 const char * mb, const char * gb );572 573 /* format a size into a user-readable string. */ 574 char* tr_formatter_size( char * buf, uint64_t bytes, size_t buflen);567 void tr_formatter_size_init( unsigned int kilo, const char * b, const char * kb, 568 const char * mb, const char * gb ); 569 570 void tr_formatter_speed_init( unsigned int kilo, const char * b, const char * kb, 571 const char * mb, const char * gb ); 572 573 void tr_formatter_mem_init( unsigned int kilo, const char * b, const char * kb, 574 const char * mb, const char * gb ); 575 575 576 576 /* format a speed into a user-readable string. */ 577 577 char* tr_formatter_speed( char * buf, uint64_t bytes_per_second, size_t buflen ); 578 578 579 enum { TR_FMT_B, TR_FMT_KB, TR_FMT_MB, TR_FMT_GB }; 580 /* return the human-readable unit initialized by tr_formatter_size_init() */ 581 const char* tr_formatter_size_units( int size ); 582 /* return the human-readable unit initialized by tr_formatter_speed_init() */ 583 const char* tr_formatter_speed_units( int size ); 579 /* format a file size into a user-readable string. */ 580 char* tr_formatter_size( char * buf, uint64_t bytes, size_t buflen ); 581 582 /* format a memory size into a user-readable string. */ 583 char* tr_formatter_mem( char * buf, uint64_t bytes, size_t buflen ); 584 585 unsigned int tr_formatter_speed_k( void ); 586 584 587 585 588 /*** -
trunk/libtransmission/webseed.c
r10800 r10931 222 222 223 223 int 224 tr_webseedGetSpeed ( const tr_webseed * w, uint64_t now, float * setme_KiBs )224 tr_webseedGetSpeed_Bps( const tr_webseed * w, uint64_t now, int * setme_Bps ) 225 225 { 226 226 const int isActive = tr_webseedIsActive( w ); 227 228 *setme_KiBs = isActive ? tr_rcRate( &w->rateDown, now ) : 0.0f; 227 *setme_Bps = isActive ? tr_rcRate_Bps( &w->rateDown, now ) : 0; 229 228 return isActive; 230 229 } -
trunk/libtransmission/webseed.h
r10800 r10931 35 35 36 36 /** @return true if a request is being processed, or false if idle */ 37 int tr_webseedGetSpeed ( const tr_webseed * w,38 uint64_t now,39 float * setme_KiBs );37 int tr_webseedGetSpeed_Bps( const tr_webseed * w, 38 uint64_t now, 39 int * setme_Bps ); 40 40 41 41 /** @return true if a request is being processed, or false if idle */ -
trunk/qt/app.cc
r10846 r10931 38 38 #include "session-dialog.h" 39 39 #include "torrent-model.h" 40 #include "units.h" 40 41 #include "utils.h" 41 42 #include "watchdir.h" … … 100 101 101 102 // initialize the units formatter 102 103 tr_formatter_size_init ( 1024, qPrintable(tr("B")), 104 qPrintable(tr("KiB")), 105 qPrintable(tr("MiB")), 106 qPrintable(tr("GiB")) ); 107 108 tr_formatter_speed_init( 1024, qPrintable(tr("B/s")), 109 qPrintable(tr("KiB/s")), 110 qPrintable(tr("MiB/s")), 111 qPrintable(tr("GiB/s")) ); 103 tr_formatter_mem_init( Units::mem_K, 104 qPrintable( Units::mem_B_str ), 105 qPrintable( Units::mem_K_str ), 106 qPrintable( Units::mem_M_str ), 107 qPrintable( Units::mem_G_str ) ); 108 tr_formatter_size_init( Units::size_K, 109 qPrintable( Units::size_B_str ), 110 qPrintable( Units::size_K_str ), 111 qPrintable( Units::size_M_str ), 112 qPrintable( Units::size_G_str ) ); 113 tr_formatter_speed_init( Units::speed_K, 114 qPrintable( Units::speed_B_str ), 115 qPrintable( Units::speed_K_str ), 116 qPrintable( Units::speed_M_str ), 117 qPrintable( Units::speed_G_str ) ); 112 118 113 119 // set the default icon -
trunk/qt/details.cc
r10908 r10931 53 53 #include "torrent.h" 54 54 #include "torrent-model.h" 55 #include "u tils.h"55 #include "units.h" 56 56 57 57 class Prefs; … … 215 215 { 216 216 if( seconds > 60 ) seconds -= ( seconds % 60 ); 217 return U tils::timeToString ( seconds );217 return Units::timeToString ( seconds ); 218 218 } 219 219 … … 324 324 else { 325 325 const double d = 100.0 * ( sizeWhenDone ? ( sizeWhenDone - leftUntilDone ) / sizeWhenDone : 1 ); 326 QString pct = U tils::percentToString( d );326 QString pct = Units::percentToString( d ); 327 327 if( !haveUnverified ) 328 328 string = tr( "%1 (%2%)" ) 329 .arg( U tils ::sizeToString( haveVerified + haveUnverified ) )329 .arg( Units::sizeToString( haveVerified + haveUnverified ) ) 330 330 .arg( pct ); 331 331 else 332 332 string = tr( "%1 (%2%); %3 Unverified" ) 333 .arg( U tils ::sizeToString( haveVerified + haveUnverified ) )333 .arg( Units::sizeToString( haveVerified + haveUnverified ) ) 334 334 .arg( pct ) 335 .arg( U tils ::sizeToString( haveUnverified ) );335 .arg( Units::sizeToString( haveUnverified ) ); 336 336 } 337 337 } … … 345 345 string = none; 346 346 else 347 string = QString( "%1%" ).arg( U tils::percentToString( ( 100.0 * available ) / sizeWhenDone ) );347 string = QString( "%1%" ).arg( Units::percentToString( ( 100.0 * available ) / sizeWhenDone ) ); 348 348 } 349 349 myAvailabilityLabel->setText( string ); … … 358 358 f += t->failedEver( ); 359 359 } 360 const QString dstr = U tils::sizeToString( d );361 const QString fstr = U tils::sizeToString( f );360 const QString dstr = Units::sizeToString( d ); 361 const QString fstr = Units::sizeToString( f ); 362 362 if( f ) 363 363 string = tr( "%1 (+%2 corrupt)" ).arg( dstr ).arg( fstr ); … … 372 372 else { 373 373 foreach( const Torrent * t, torrents ) u += t->uploadedEver( ); 374 string = QString( U tils::sizeToString( u ) );374 string = QString( Units::sizeToString( u ) ); 375 375 } 376 376 myUploadedLabel->setText( string ); … … 379 379 string = none; 380 380 else if( torrents.length() == 1 ) 381 string = QString( Utils :: ratioToString( torrents.first()->ratio()) );381 string = Units::ratioToString( torrents.first()->ratio() ); 382 382 else { 383 383 bool isMixed = false; … … 395 395 string = mixed; 396 396 else if( ratioType < 0 ) 397 string = QString( Utils :: ratioToString( ratioType ));397 string = Units::ratioToString( ratioType ); 398 398 else 399 string = QString( Utils :: ratioToString( (double)u / d ));399 string = Units::ratioToString( (double)u / d ); 400 400 } 401 401 myRatioLabel->setText( string ); … … 420 420 string = mixed; 421 421 else 422 string = U tils::timeToString( baseline.secsTo( qdt_now ) );422 string = Units::timeToString( baseline.secsTo( qdt_now ) ); 423 423 } 424 424 myRunTimeLabel->setText( string ); … … 441 441 string = tr( "Unknown" ); 442 442 else 443 string = U tils::timeToString( baseline );443 string = Units::timeToString( baseline ); 444 444 } 445 445 } … … 461 461 string = tr( "Active now" ); 462 462 else 463 string = tr( "%1 ago" ).arg( U tils::timeToString( seconds ) );463 string = tr( "%1 ago" ).arg( Units::timeToString( seconds ) ); 464 464 } 465 465 myLastActivityLabel->setText( string ); … … 503 503 else if( pieceSize > 0 ) 504 504 string = tr( "%1 (%Ln pieces @ %2)", "", pieces ) 505 .arg( U tils::sizeToString( size ) )506 .arg( U tils::sizeToString( pieceSize ) );505 .arg( Units::sizeToString( size ) ) 506 .arg( Units::memToString( pieceSize ) ); 507 507 else 508 508 string = tr( "%1 (%Ln pieces)", "", pieces ) 509 .arg( U tils::sizeToString( size ) );509 .arg( Units::sizeToString( size ) ); 510 510 } 511 511 mySizeLabel->setText( string ); … … 637 637 638 638 mySingleDownSpin->blockSignals( true ); 639 mySingleDownSpin->setValue( int(tor->downloadLimit().kbps()));639 mySingleDownSpin->setValue( tor->downloadLimit().Bps() / Units::speed_K ); 640 640 mySingleDownSpin->blockSignals( false ); 641 641 642 642 mySingleUpSpin->blockSignals( true ); 643 mySingleUpSpin->setValue( int(tor->uploadLimit().kbps()));643 mySingleUpSpin->setValue( tor->uploadLimit().Bps() / Units::speed_K ); 644 644 mySingleUpSpin->blockSignals( false ); 645 645 … … 911 911 codeTip.resize( codeTip.size()-1 ); // eat the trailing linefeed 912 912 913 item->setText( COL_UP, peer.rateToPeer.isZero() ? "" : U tils::speedToString( peer.rateToPeer ) );914 item->setText( COL_DOWN, peer.rateToClient.isZero() ? "" : U tils::speedToString( peer.rateToClient ) );913 item->setText( COL_UP, peer.rateToPeer.isZero() ? "" : Units::speedToString( peer.rateToPeer ) ); 914 item->setText( COL_DOWN, peer.rateToClient.isZero() ? "" : Units::speedToString( peer.rateToClient ) ); 915 915 item->setText( COL_PERCENT, peer.progress > 0 ? QString( "%1%" ).arg( (int)( peer.progress * 100.0 ) ) : "" ); 916 916 item->setText( COL_STATUS, code ); … … 1011 1011 Details :: onDownloadLimitChanged( int val ) 1012 1012 { 1013 mySession.torrentSet( myIds, "downloadLimit", val );1013 mySession.torrentSet( myIds, "downloadLimit", val * Units::speed_K ); 1014 1014 } 1015 1015 void … … 1021 1021 Details :: onUploadLimitChanged( int val ) 1022 1022 { 1023 mySession.torrentSet( myIds, "uploadLimit", val );1023 mySession.torrentSet( myIds, "uploadLimit", val * Units::speed_K ); 1024 1024 } 1025 1025 … … 1192 1192 connect( c, SIGNAL(clicked(bool)), this, SLOT(onHonorsSessionLimitsToggled(bool)) ); 1193 1193 1194 c = new QCheckBox( tr( "Limit &download speed ( KiB/s):") );1194 c = new QCheckBox( tr( "Limit &download speed (%1):" ).arg( Units::speed_K_str ) ); 1195 1195 mySingleDownCheck = c; 1196 1196 s = new QSpinBox( ); … … 1202 1202 connect( s, SIGNAL(valueChanged(int)), this, SLOT(onDownloadLimitChanged(int))); 1203 1203 1204 c = new QCheckBox( tr( "Limit &upload speed ( KiB/s):") );1204 c = new QCheckBox( tr( "Limit &upload speed (%1):" ).arg( Units::speed_K_str ) ); 1205 1205 mySingleUpCheck = c; 1206 1206 s = new QSpinBox( ); -
trunk/qt/file-tree.cc
r10684 r10931 25 25 #include "hig.h" 26 26 #include "torrent.h" // FileList 27 #include "units.h" 27 28 #include "utils.h" // mime icons 28 29 … … 123 124 QString str; 124 125 getSubtreeSize( have, total ); 125 str = QString( name() + " (%1)" ).arg( U tils::sizeToString( total ) );126 str = QString( name() + " (%1)" ).arg( Units::sizeToString( total ) ); 126 127 return str; 127 128 } -
trunk/qt/mainwin.cc
r10859 r10931 52 52 #include "triconpushbutton.h" 53 53 #include "ui_mainwin.h" 54 #include "u tils.h"54 #include "units.h" 55 55 #include "qticonloader.h" 56 56 … … 550 550 g->addAction( a ); 551 551 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); 552 a = myDlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( U tils::speedToString( Speed::fromKbps( currentVal ) ) ) );552 a = myDlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Units::speedToString( Speed::fromBps( currentVal ) ) ) ); 553 553 a->setCheckable( true ); 554 554 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << currentVal << Prefs::DSPEED_ENABLED << true ); … … 557 557 sub->addSeparator( ); 558 558 foreach( int i, stockSpeeds ) { 559 a = sub->addAction( Utils::speedToString( Speed::fromKbps(i) ) ); 560 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << i << Prefs::DSPEED_ENABLED << true ); 559 const int Bps = i * Units::speed_K; 560 a = sub->addAction( Units::speedToString( Speed::fromBps( Bps ) ) ); 561 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::DSPEED << Bps << Prefs::DSPEED_ENABLED << true ); 561 562 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs())); 562 563 } … … 570 571 g->addAction( a ); 571 572 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); 572 a = myUlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( U tils::speedToString( Speed::fromKbps( currentVal ) ) ) );573 a = myUlimitOnAction = sub->addAction( tr( "Limited at %1" ).arg( Units::speedToString( Speed::fromBps( currentVal ) ) ) ); 573 574 a->setCheckable( true ); 574 575 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << currentVal << Prefs::USPEED_ENABLED << true ); … … 577 578 sub->addSeparator( ); 578 579 foreach( int i, stockSpeeds ) { 579 a = sub->addAction( Utils::speedToString( Speed::fromKbps(i) ) ); 580 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << i << Prefs::USPEED_ENABLED << true ); 580 const int Bps = i * Units::speed_K; 581 a = sub->addAction( Units::speedToString( Speed::fromBps( Bps ) ) ); 582 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::USPEED << Bps << Prefs::USPEED_ENABLED << true ); 581 583 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs())); 582 584 } … … 592 594 g->addAction( a ); 593 595 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs(bool)) ); 594 a = myRatioOnAction = sub->addAction( tr( "Stop at Ratio (%1)" ).arg( U tils::ratioToString( d ) ) );596 a = myRatioOnAction = sub->addAction( tr( "Stop at Ratio (%1)" ).arg( Units::ratioToString( d ) ) ); 595 597 a->setCheckable( true ); 596 598 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO << d << Prefs::RATIO_ENABLED << true ); … … 599 601 sub->addSeparator( ); 600 602 foreach( double i, stockRatios ) { 601 a = sub->addAction( U tils::ratioToString( i ) );603 a = sub->addAction( Units::ratioToString( i ) ); 602 604 a->setProperty( PREF_VARIANTS_KEY, QVariantList() << Prefs::RATIO << i << Prefs::RATIO_ENABLED << true ); 603 605 connect( a, SIGNAL(triggered(bool)), this, SLOT(onSetPrefs())); … … 734 736 const Speed up( myModel.getUploadSpeed( ) ); 735 737 const Speed down( myModel.getDownloadSpeed( ) ); 736 myUploadSpeedLabel->setText( U tils :: speedToString( up ) );737 myDownloadSpeedLabel->setText( U tils :: speedToString( down ) );738 myUploadSpeedLabel->setText( Units :: speedToString( up ) ); 739 myDownloadSpeedLabel->setText( Units :: speedToString( down ) ); 738 740 739 741 myNetworkLabel->setVisible( !mySession.isServer( ) ); … … 744 746 if( mode == "session-ratio" ) 745 747 { 746 str = tr( "Ratio: %1" ).arg( U tils :: ratioToString( mySession.getStats().ratio ) );748 str = tr( "Ratio: %1" ).arg( Units :: ratioToString( mySession.getStats().ratio ) ); 747 749 } 748 750 else if( mode == "session-transfer" ) 749 751 { 750 752 const tr_session_stats& stats( mySession.getStats( ) ); 751 str = tr( "Down: %1, Up: %2" ).arg( U tils :: sizeToString( stats.downloadedBytes ) )752 .arg( U tils :: sizeToString( stats.uploadedBytes ) );753 str = tr( "Down: %1, Up: %2" ).arg( Units :: sizeToString( stats.downloadedBytes ) ) 754 .arg( Units :: sizeToString( stats.uploadedBytes ) ); 753 755 } 754 756 else if( mode == "total-transfer" ) 755 757 { 756 758 const tr_session_stats& stats( mySession.getCumulativeStats( ) ); 757 str = tr( "Down: %1, Up: %2" ).arg( U tils :: sizeToString( stats.downloadedBytes ) )758 .arg( U tils :: sizeToString( stats.uploadedBytes ) );759 str = tr( "Down: %1, Up: %2" ).arg( Units :: sizeToString( stats.downloadedBytes ) ) 760 .arg( Units :: sizeToString( stats.uploadedBytes ) ); 759 761 } 760 762 else // default is "total-ratio" 761 763 { 762 str = tr( "Ratio: %1" ).arg( U tils :: ratioToString( mySession.getCumulativeStats().ratio ) );764 str = tr( "Ratio: %1" ).arg( Units :: ratioToString( mySession.getCumulativeStats().ratio ) ); 763 765 } 764 766 … … 1012 1014 1013 1015 case Prefs::DSPEED: 1014 myDlimitOnAction->setText( tr( "Limited at %1" ).arg( U tils::speedToString( Speed::fromKbps( myPrefs.get<int>(key) ) ) ) );1016 myDlimitOnAction->setText( tr( "Limited at %1" ).arg( Units::speedToString( Speed::fromBps( myPrefs.get<int>(key) ) ) ) ); 1015 1017 break; 1016 1018 … … 1020 1022 1021 1023 case Prefs::USPEED: 1022 myUlimitOnAction->setText( tr( "Limited at %1" ).arg( U tils::speedToString( Speed::fromKbps( myPrefs.get<int>(key) ) ) ) );1024 myUlimitOnAction->setText( tr( "Limited at %1" ).arg( Units::speedToString( Speed::fromBps( myPrefs.get<int>(key) ) ) ) ); 1023 1025 break; 1024 1026 … … 1028 1030 1029 1031 case Prefs::RATIO: 1030 myRatioOnAction->setText( tr( "Stop at Ratio (%1)" ).arg( U tils::ratioToString( myPrefs.get<double>(key) ) ) );1032 myRatioOnAction->setText( tr( "Stop at Ratio (%1)" ).arg( Units::ratioToString( myPrefs.get<double>(key) ) ) ); 1031 1033 break; 1032 1034 … … 1086 1088 const QString fmt = b ? tr( "Click to disable Temporary Speed Limits\n(%1 down, %2 up)" ) 1087 1089 : tr( "Click to enable Temporary Speed Limits\n(%1 down, %2 up)" ); 1088 const Speed d = Speed::from Kbps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_DOWN ) );1089 const Speed u = Speed::from Kbps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_UP ) );1090 myAltSpeedButton->setToolTip( fmt.arg( U tils::speedToString( d ) )1091 .arg( U tils::speedToString( u ) ) );1090 const Speed d = Speed::fromBps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_DOWN ) ); 1091 const Speed u = Speed::fromBps( myPrefs.getInt( Prefs::ALT_SPEED_LIMIT_UP ) ); 1092 myAltSpeedButton->setToolTip( fmt.arg( Units::speedToString( d ) ) 1093 .arg( Units::speedToString( u ) ) ); 1092 1094 break; 1093 1095 } … … 1294 1296 myNetworkLabel->setToolTip( isSending || isReading 1295 1297 ? tr( "Transmission server is responding" ) 1296 : tr( "Last response from server was %1 ago" ).arg( U tils::timeToString( now-std::max(myLastReadTime,myLastSendTime))));1298 : tr( "Last response from server was %1 ago" ).arg( Units::timeToString( now-std::max(myLastReadTime,myLastSendTime)))); 1297 1299 } 1298 1300 -
trunk/qt/make-dialog.cc
r9868 r10931 38 38 #include "make-dialog.h" 39 39 #include "session.h" 40 #include "u tils.h"40 #include "units.h" 41 41 42 42 /*** … … 283 283 QString pieces = tr( "%Ln Piece(s)", 0, myBuilder->pieceCount ); 284 284 text = tr( "%1 in %2; %3 @ %4" ) 285 .arg( U tils::sizeToString( myBuilder->totalSize ) )285 .arg( Units::sizeToString( myBuilder->totalSize ) ) 286 286 .arg( files ) 287 287 .arg( pieces ) 288 .arg( U tils::sizeToString( myBuilder->pieceSize ) );288 .arg( Units::sizeToString( myBuilder->pieceSize ) ); 289 289 } 290 290 -
trunk/qt/prefs-dialog.cc
r10922 r10931 42 42 #include "qticonloader.h" 43 43 #include "session.h" 44 #include "units.h" 44 45 #include "utils.h" 45 46 … … 51 52 { 52 53 const char * PREF_KEY( "pref-key" ); 54 const char * MULTIPLIER_KEY( "multiplier-key" ); 53 55 }; 54 56 … … 82 84 { 83 85 const QObject * spin( sender()->property( "SPIN" ).value<QObject*>( ) ); 84 const int key( spin->property( PREF_KEY ).toInt( ) ); 86 const int key = spin->property( PREF_KEY ).toInt( ); 87 const int multiplier = spin->property( MULTIPLIER_KEY ).toInt( ); 85 88 86 89 const QDoubleSpinBox * d = qobject_cast<const QDoubleSpinBox*>( spin ); 87 90 if( d != 0 ) 88 myPrefs.set( key, d->value( ) );91 myPrefs.set( key, multiplier * d->value( ) ); 89 92 else 90 myPrefs.set( key, qobject_cast<const QSpinBox*>(spin)->value( ) );93 myPrefs.set( key, multiplier * qobject_cast<const QSpinBox*>(spin)->value( ) ); 91 94 } 92 95 … … 114 117 115 118 QSpinBox * 116 PrefsDialog :: spinBoxNew( int key, int low, int high, int step )119 PrefsDialog :: spinBoxNew( int key, int low, int high, int step, int multiplier ) 117 120 { 118 121 QSpinBox * spin = new QSpinBox( ); 119 122 spin->setRange( low, high ); 120 123 spin->setSingleStep( step ); 121 spin->setValue( myPrefs.getInt( key ) );124 spin->setValue( myPrefs.getInt( key ) / multiplier ); 122 125 spin->setProperty( PREF_KEY, key ); 126 spin->setProperty( MULTIPLIER_KEY, multiplier ); 123 127 connect( spin, SIGNAL(valueChanged(int)), this, SLOT(spinBoxChanged(int))); 124 128 myWidgets.insert( key, spin ); … … 135 139 136 140 QDoubleSpinBox * 137 PrefsDialog :: doubleSpinBoxNew( int key, double low, double high, double step, int decimals )141 PrefsDialog :: doubleSpinBoxNew( int key, double low, double high, double step, int decimals, int multiplier ) 138 142 { 139 143 QDoubleSpinBox * spin = new QDoubleSpinBox( ); … … 141 145 spin->setSingleStep( step ); 142 146 spin->setDecimals( decimals ); 143 spin->setValue( myPrefs.getDouble( key ) );147 spin->setValue( myPrefs.getDouble( key ) / multiplier ); 144 148 spin->setProperty( PREF_KEY, key ); 149 spin->setProperty( MULTIPLIER_KEY, multiplier ); 145 150 connect( spin, SIGNAL(valueChanged(double)), this, SLOT(doubleSpinBoxChanged(double))); 146 151 myWidgets.insert( key, spin ); … … 268 273 hig->addSectionTitle( tr( "Speed Limits" ) ); 269 274 270 l = checkBoxNew( tr( "Limit &download speed ( KiB/s):"), Prefs::DSPEED_ENABLED );271 r = spinBoxNew( Prefs::DSPEED, 0, INT_MAX, 5 );275 l = checkBoxNew( tr( "Limit &download speed (%1):" ).arg( Units::speed_K_str ), Prefs::DSPEED_ENABLED ); 276 r = spinBoxNew( Prefs::DSPEED, 0, INT_MAX, 5, Units::speed_K ); 272 277 hig->addRow( l, r ); 273 278 enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r ); 274 279 275 l = checkBoxNew( tr( "Limit &upload speed ( KiB/s):"), Prefs::USPEED_ENABLED );276 r = spinBoxNew( Prefs::USPEED, 0, INT_MAX, 5 );280 l = checkBoxNew( tr( "Limit &upload speed (%1):" ).arg( Units::speed_K_str ), Prefs::USPEED_ENABLED ); 281 r = spinBoxNew( Prefs::USPEED, 0, INT_MAX, 5, Units::speed_K ); 277 282 hig->addRow( l, r ); 278 283 enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r ); … … 294 299 hig->addWideControl( new QLabel( s ) ); 295 300 296 s = tr( "Limit d&ownload speed ( KiB/s):");297 r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_DOWN, 0, INT_MAX, 5 );301 s = tr( "Limit d&ownload speed (%1):" ).arg( Units::speed_K_str ); 302 r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_DOWN, 0, INT_MAX, 5, Units::speed_K ); 298 303 hig->addRow( s, r ); 299 304 300 s = tr( "Limit u&pload speed ( KiB/s):");301 r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_UP, 0, INT_MAX, 5 );305 s = tr( "Limit u&pload speed (%1):" ).arg( Units::speed_K_str ); 306 r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_UP, 0, INT_MAX, 5, Units::speed_K ); 302 307 hig->addRow( s, r ); 303 308 -
trunk/qt/prefs-dialog.h
r10722 r10931 65 65 66 66 private: 67 QDoubleSpinBox * doubleSpinBoxNew( int key, double low, double high, double step, int decimals );67 QDoubleSpinBox * doubleSpinBoxNew( int key, double low, double high, double step, int decimals, int multiplier=1 ); 68 68 QCheckBox * checkBoxNew( const QString& text, int key ); 69 QSpinBox * spinBoxNew( int key, int low, int high, int step );69 QSpinBox * spinBoxNew( int key, int low, int high, int step, int multiplier=1 ); 70 70 QTimeEdit * timeEditNew( int key ); 71 71 QLineEdit * lineEditNew( int key, int mode = 0 ); -
trunk/qt/prefs.cc
r10908 r10931 65 65 66 66 /* libtransmission settings */ 67 { ALT_SPEED_LIMIT_UP, TR_PREFS_KEY_ALT_SPEED_UP , QVariant::Int },68 { ALT_SPEED_LIMIT_DOWN, TR_PREFS_KEY_ALT_SPEED_DOWN , QVariant::Int },67 { ALT_SPEED_LIMIT_UP, TR_PREFS_KEY_ALT_SPEED_UP_Bps, QVariant::Int }, 68 { ALT_SPEED_LIMIT_DOWN, TR_PREFS_KEY_ALT_SPEED_DOWN_Bps, QVariant::Int }, 69 69 { ALT_SPEED_LIMIT_ENABLED, TR_PREFS_KEY_ALT_SPEED_ENABLED, QVariant::Bool }, 70 70 { ALT_SPEED_LIMIT_TIME_BEGIN, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, QVariant::Int }, … … 73 73 { ALT_SPEED_LIMIT_TIME_DAY, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, QVariant::Int }, 74 74 { BLOCKLIST_ENABLED, TR_PREFS_KEY_BLOCKLIST_ENABLED, QVariant::Bool }, 75 { DSPEED, TR_PREFS_KEY_DSPEED , QVariant::Int },75 { DSPEED, TR_PREFS_KEY_DSPEED_Bps, QVariant::Int }, 76 76 { DSPEED_ENABLED, TR_PREFS_KEY_DSPEED_ENABLED, QVariant::Bool }, 77 77 { DOWNLOAD_DIR, TR_PREFS_KEY_DOWNLOAD_DIR, QVariant::String }, … … 116 116 { RPC_WHITELIST, TR_PREFS_KEY_RPC_WHITELIST, QVariant::String }, 117 117 { USPEED_ENABLED, TR_PREFS_KEY_USPEED_ENABLED, QVariant::Bool }, 118 { USPEED, TR_PREFS_KEY_USPEED , QVariant::Int },118 { USPEED, TR_PREFS_KEY_USPEED_Bps, QVariant::Int }, 119 119 { UPLOAD_SLOTS_PER_TORRENT, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, QVariant::Int } 120 120 }; -
trunk/qt/qtr.pro
r10887 r10931 36 36 session-dialog.cc squeezelabel.cc stats-dialog.cc torrent.cc \ 37 37 torrent-delegate.cc torrent-delegate-min.cc torrent-filter.cc \ 38 torrent-model.cc triconpushbutton.cc u tils.cc watchdir.cc38 torrent-model.cc triconpushbutton.cc units.cc utils.cc watchdir.cc 39 39 HEADERS += $$replace(SOURCES, .cc, .h) 40 40 HEADERS += speed.h types.h -
trunk/qt/speed.h
r9868 r10931 17 17 { 18 18 private: 19 double _kbps;20 Speed( double kbps ): _kbps(kbps) { }19 int _Bps; 20 Speed( int Bps ): _Bps(Bps) { } 21 21 public: 22 Speed( ): _ kbps(0) { }23 double kbps( ) const { return _kbps; }24 double bps( ) const { return kbps()*1024.0; }25 bool isZero( ) const { return _ kbps < 0.001; }26 static Speed fromK bps( double kbps ) { return Speed( kbps); }27 static Speed fromBps( double bps ) { return Speed( bps/1024.0); }28 void setK bps( double kbps ) { _kbps = kbps; }29 void setBps( double bps ) { _kbps = bps/1024.0; }30 Speed operator+( const Speed& that ) const { return Speed( kbps() + that.kbps() ); }31 Speed & operator+=( const Speed& that ) { _kbps += that._kbps; return *this; }32 bool operator<( const Speed& that ) const { return kbps() < that.kbps(); }22 Speed( ): _Bps(0) { } 23 double KiBps( ) const { return _Bps/1024.0; } 24 int Bps( ) const { return _Bps; } 25 bool isZero( ) const { return _Bps == 0; } 26 static Speed fromKiBps( double KiBps ) { return Speed( KiBps*1024 ); } 27 static Speed fromBps( int Bps ) { return Speed( Bps ); } 28 void setKiBps( double KiBps ) { setBps( KiBps*1024 ); } 29 void setBps( double Bps ) { _Bps = Bps; } 30 Speed& operator+=( const Speed& that ) { _Bps += that._Bps; return *this; } 31 Speed operator+( const Speed& that ) const { return Speed( _Bps + that._Bps ); } 32 bool operator<( const Speed& that ) const { return _Bps < that._Bps; } 33 33 }; 34 34 -
trunk/qt/stats-dialog.cc
r9868 r10931 19 19 #include "session.h" 20 20 #include "stats-dialog.h" 21 #include "u tils.h"21 #include "units.h" 22 22 23 23 enum … … 86 86 const struct tr_session_stats& total( mySession.getCumulativeStats( ) ); 87 87 88 myCurrentUp->setText( U tils ::sizeToString( current.uploadedBytes ) );89 myCurrentDown->setText( U tils ::sizeToString( current.downloadedBytes ) );90 myCurrentRatio->setText( U tils ::ratioToString( current.ratio ) );91 myCurrentDuration->setText( U tils ::timeToString( current.secondsActive ) );88 myCurrentUp->setText( Units::sizeToString( current.uploadedBytes ) ); 89 myCurrentDown->setText( Units::sizeToString( current.downloadedBytes ) ); 90 myCurrentRatio->setText( Units::ratioToString( current.ratio ) ); 91 myCurrentDuration->setText( Units::timeToString( current.secondsActive ) ); 92 92 93 myTotalUp->setText( U tils ::sizeToString( total.uploadedBytes ) );94 myTotalDown->setText( U tils ::sizeToString( total.downloadedBytes ) );95 myTotalRatio->setText( U tils ::ratioToString( total.ratio ) );96 myTotalDuration->setText( U tils ::timeToString( total.secondsActive ) );93 myTotalUp->setText( Units::sizeToString( total.uploadedBytes ) ); 94 myTotalDown->setText( Units::sizeToString( total.downloadedBytes ) ); 95 myTotalRatio->setText( Units::ratioToString( total.ratio ) ); 96 myTotalDuration->setText( Units::timeToString( total.secondsActive ) ); 97 97 98 98 myStartCount->setText( tr( "Started %n time(s)", 0, total.sessionCount ) ); -
trunk/qt/torrent-delegate-min.cc
r10771 r10931 27 27 #include "torrent-delegate-min.h" 28 28 #include "torrent-model.h" 29 #include "utils.h"30 29 31 30 enum -
trunk/qt/torrent-delegate.cc
r10822 r10931 27 27 #include "torrent-delegate.h" 28 28 #include "torrent-model.h" 29 #include "u tils.h"29 #include "units.h" 30 30 31 31 enum … … 75 75 /* %1 is the percentage of torrent metadata downloaded */ 76 76 str = tr( "Magnetized transfer - retrieving metadata (%1%)" ) 77 .arg( U tils::percentToString( tor.metadataPercentDone() * 100.0 ) );77 .arg( Units::percentToString( tor.metadataPercentDone() * 100.0 ) ); 78 78 } 79 79 else if( !isDone ) // downloading … … 82 82 %2 is how much we'll have when done, 83 83 %3 is a percentage of the two */ 84 str = tr( "%1 of %2 (%3%)" ).arg( U tils::sizeToString( haveTotal ) )85 .arg( U tils::sizeToString( tor.sizeWhenDone( ) ) )86 .arg( U tils::percentToString( tor.percentDone( ) * 100.0 ) );84 str = tr( "%1 of %2 (%3%)" ).arg( Units::sizeToString( haveTotal ) ) 85 .arg( Units::sizeToString( tor.sizeWhenDone( ) ) ) 86 .arg( Units::percentToString( tor.percentDone( ) * 100.0 ) ); 87 87 } 88 88 else if( !isSeed ) // partial seed … … 97 97 %6 is the ratio we want to reach before we stop uploading */ 98 98 str = tr( "%1 of %2 (%3%), uploaded %4 (Ratio: %5 Goal: %6)" ) 99 .arg( U tils::sizeToString( haveTotal ) )100 .arg( U tils::sizeToString( tor.totalSize( ) ) )101 .arg( U tils::percentToString( tor.percentComplete( ) * 100.0 ) )102 .arg( U tils::sizeToString( tor.uploadedEver( ) ) )103 .arg( U tils::ratioToString( tor.ratio( ) ) )104 .arg( U tils::ratioToString( seedRatio ) );99 .arg( Units::sizeToString( haveTotal ) ) 100 .arg( Units::sizeToString( tor.totalSize( ) ) ) 101 .arg( Units::percentToString( tor.percentComplete( ) * 100.0 ) ) 102 .arg( Units::sizeToString( tor.uploadedEver( ) ) ) 103 .arg( Units::ratioToString( tor.ratio( ) ) ) 104 .arg( Units::ratioToString( seedRatio ) ); 105 105 } 106 106 else … … 112 112 %5 is our upload-to-download ratio */ 113 113 str = tr( "%1 of %2 (%3%), uploaded %4 (Ratio: %5)" ) 114 .arg( U tils::sizeToString( haveTotal ) )115 .arg( U tils::sizeToString( tor.totalSize( ) ) )116 .arg( U tils::percentToString( tor.percentComplete( ) * 100.0 ) )117 .arg( U tils::sizeToString( tor.uploadedEver( ) ) )118 .arg( U tils::ratioToString( tor.ratio( ) ) );114 .arg( Units::sizeToString( haveTotal ) ) 115 .arg( Units::sizeToString( tor.totalSize( ) ) ) 116 .arg( Units::percentToString( tor.percentComplete( ) * 100.0 ) ) 117 .arg( Units::sizeToString( tor.uploadedEver( ) ) ) 118 .arg( Units::ratioToString( tor.ratio( ) ) ); 119 119 } 120 120 } … … 128 128 %4 is the ratio we want to reach before we stop uploading */ 129 129 str = tr( "%1, uploaded %2 (Ratio: %3 Goal %4)" ) 130 .arg( U tils::sizeToString( haveTotal ) )131 .arg( U tils::sizeToString( tor.uploadedEver( ) ) )132 .arg( U tils::ratioToString( tor.ratio( ) ) )133 .arg( U tils::ratioToString( seedRatio ) );130 .arg( Units::sizeToString( haveTotal ) ) 131 .arg( Units::sizeToString( tor.uploadedEver( ) ) ) 132 .arg( Units::ratioToString( tor.ratio( ) ) ) 133 .arg( Units::ratioToString( seedRatio ) ); 134 134 } 135 135 else /* seeding w/o a ratio */ … … 139 139 %3 is our upload-to-download ratio */ 140 140 str = tr( "%1, uploaded %2 (Ratio: %3)" ) 141 .arg( U tils::sizeToString( haveTotal ) )142 .arg( U tils::sizeToString( tor.uploadedEver( ) ) )143 .arg( U tils::ratioToString( tor.ratio( ) ) );141 .arg( Units::sizeToString( haveTotal ) ) 142 .arg( Units::sizeToString( tor.uploadedEver( ) ) ) 143 .arg( Units::ratioToString( tor.ratio( ) ) ); 144 144 } 145 145 } … … 150 150 str += tr( " - " ); 151 151 if( tor.hasETA( ) ) 152 str += tr( "%1 left" ).arg( U tils::timeToString( tor.getETA( ) ) );152 str += tr( "%1 left" ).arg( Units::timeToString( tor.getETA( ) ) ); 153 153 else 154 154 str += tr( "Remaining time unknown" ); … … 167 167 168 168 if( haveDown ) 169 downStr = U tils ::speedToString( tor.downloadSpeed( ) );169 downStr = Units::speedToString( tor.downloadSpeed( ) ); 170 170 if( haveUp ) 171 upStr = U tils ::speedToString( tor.uploadSpeed( ) );171 upStr = Units::speedToString( tor.uploadSpeed( ) ); 172 172 173 173 if( haveDown && haveUp ) … … 191 191 { 192 192 case TR_STATUS_CHECK: 193 str = tr( "Verifying local data (%1% tested)" ).arg( U tils::percentToString( tor.getVerifyProgress()*100.0 ) );193 str = tr( "Verifying local data (%1% tested)" ).arg( Units::percentToString( tor.getVerifyProgress()*100.0 ) ); 194 194 break; 195 195 … … 197 197 case TR_STATUS_SEED: 198 198 if( !tor.isDownloading( ) ) 199 str = tr( "Ratio: %1, " ).arg( U tils::ratioToString( tor.ratio( ) ) );199 str = tr( "Ratio: %1, " ).arg( Units::ratioToString( tor.ratio( ) ) ); 200 200 str += shortTransferString( tor ); 201 201 break; … … 232 232 else 233 233 str = tr( "Downloading metadata from %n peer(s) (%1% done)", 0, tor.peersWeAreDownloadingFrom( ) ) 234 .arg( U tils::percentToString( 100.0 * tor.metadataPercentDone( ) ) );234 .arg( Units::percentToString( 100.0 * tor.metadataPercentDone( ) ) ); 235 235 break; 236 236 -
trunk/qt/torrent.h
r10872 r10931 285 285 bool hasFileSubstring( const QString& substr ) const; 286 286 bool hasTrackerSubstring( const QString& substr ) const; 287 Speed uploadLimit( ) const { return Speed::from Kbps( getInt( UP_LIMIT ) ); }288 Speed downloadLimit( ) const { return Speed::from Kbps( getInt( DOWN_LIMIT ) ); }287 Speed uploadLimit( ) const { return Speed::fromBps( getInt( UP_LIMIT ) ); } 288 Speed downloadLimit( ) const { return Speed::fromBps( getInt( DOWN_LIMIT ) ); } 289 289 bool uploadIsLimited( ) const { return getBool( UP_LIMITED ); } 290 290 bool downloadIsLimited( ) const { return getBool( DOWN_LIMITED ); } -
trunk/qt/utils.cc
r10822 r10931 29 29 #include "utils.h" 30 30 31 /*** 32 **** 33 ***/ 34 31 35 QString 32 36 Utils :: remoteFileChooser( QWidget * parent, const QString& title, const QString& myPath, bool dir, bool local ) … … 45 49 46 50 return path; 47 }48 49 QString50 Utils :: sizeToString( double bytes )51 {52 if( !bytes )53 return tr( "None" );54 else {55 char buf[128];56 tr_formatter_size( buf, bytes, sizeof( buf ) );57 return buf;58 }59 }60 61 QString62 Utils :: speedToString( const Speed& speed )63 {64 if( speed.isZero( ) )65 return tr( "None" );66 else {67 char buf[128];68 tr_formatter_speed( buf, speed.bps( ), sizeof( buf ) );69 return buf;70 }71 }72 73 QString74 Utils :: percentToString( double x )75 {76 char buf[128];77 return QString( tr_strpercent( buf, x, sizeof(buf) ) );78 }79 80 QString81 Utils :: ratioToString( double ratio )82 {83 char buf[128];84 return QString::fromUtf8( tr_strratio( buf, sizeof(buf), ratio, "\xE2\x88\x9E" ) );85 }86 87 QString88 Utils :: timeToString( int seconds )89 {90 int days, hours, minutes;91 QString d, h, m, s;92 QString str;93 94 if( seconds < 0 )95 seconds = 0;96 97 days = seconds / 86400;98 hours = ( seconds % 86400 ) / 3600;99 minutes = ( seconds % 3600 ) / 60;100 seconds %= 60;101 102 d = tr( "%Ln day(s)", 0, days );103 h = tr( "%Ln hour(s)", 0, hours );104 m = tr( "%Ln minute(s)", 0, minutes );105 s = tr( "%Ln second(s)", 0, seconds );106 107 if( days )108 {109 if( days >= 4 || !hours )110 str = d;111 else112 str = tr( "%1, %2" ).arg( d ).arg( h );113 }114 else if( hours )115 {116 if( hours >= 4 || !minutes )117 str = h;118 else119 str = tr( "%1, %2" ).arg( h ).arg( m );120 }121 else if( minutes )122 {123 if( minutes >= 4 || !seconds )124 str = m;125 else126 str = tr( "%1, %2" ).arg( m ).arg( s );127 }128 else129 {130 str = s;131 }132 133 return str;134 51 } 135 52 -
trunk/qt/utils.h
r10822 r10931 27 27 Utils( ) { } 28 28 virtual ~Utils( ) { } 29 29 30 public: 30 31 static QString remoteFileChooser( QWidget * parent, const QString& title, const QString& myPath, bool dir, bool local ); 31 static QString sizeToString( double bytes );32 static QString speedToString( const Speed& speed );33 static QString percentToString( double x );34 static QString ratioToString( double ratio );35 static QString timeToString( int seconds );36 32 static const QIcon& guessMimeIcon( const QString& filename ); 37 33 -
trunk/utils/show.c
r10854 r10931 29 29 #define TIMEOUT_SECS 30 30 30 31 #define MEM_K 1024 32 #define MEM_B_STR "B" 33 #define MEM_K_STR "KiB" 34 #define MEM_M_STR "MiB" 35 #define MEM_G_STR "GiB" 36 37 #define DISK_K 1000 38 #define DISK_B_STR "B" 39 #define DISK_K_STR "kB" 40 #define DISK_M_STR "MB" 41 #define DISK_G_STR "GB" 42 43 #define SPEED_K 1000 44 #define SPEED_B_STR "B/s" 45 #define SPEED_K_STR "kB/s" 46 #define SPEED_M_STR "MB/s" 47 #define SPEED_G_STR "GB/s" 48 31 49 static tr_option options[] = 32 50 { … … 87 105 printf( " Comment: %s\n", inf->comment ); 88 106 printf( " Piece Count: %d\n", inf->pieceCount ); 89 printf( " Piece Size: %s\n", tr_formatter_ size( buf, inf->pieceSize, sizeof( buf ) ) );107 printf( " Piece Size: %s\n", tr_formatter_mem( buf, inf->pieceSize, sizeof( buf ) ) ); 90 108 printf( " Total Size: %s\n", tr_formatter_size( buf, inf->totalSize, sizeof( buf ) ) ); 91 109 printf( " Privacy: %s\n", inf->isPrivate ? "Private torrent" : "Public torrent" ); … … 232 250 233 251 tr_setMessageLevel( TR_MSG_ERR ); 234 tr_formatter_size_init ( 1024, "B", "KiB", "MiB", "GiB" ); 235 tr_formatter_speed_init( 1024, "B/s", "KiB/s", "MiB/s", "GiB/s" ); 252 tr_formatter_mem_init ( MEM_K, MEM_B_STR, MEM_K_STR, MEM_G_STR ); 253 tr_formatter_size_init ( DISK_K, DISK_B_STR, DIST_K_STR, DISK_G_STR ); 254 tr_formatter_size_init ( SPEED_K, SPEED_B_STR, SPEED_K_STR, SPEED_G_STR ); 236 255 237 256 if( parseCommandLine( argc, (const char**)argv ) ) -
trunk/web/index.html
r10812 r10931 273 273 <label for="limit_download" class="item">Download Rate:</label> 274 274 <input type="text" name="download_rate" id="download_rate"/> 275 <label class="suffix"> KB/s</label>275 <label class="suffix">kB/s</label> 276 276 </div> 277 277 <div class="formdiv checkbox"> … … 279 279 <label for="limit_upload" class="item">Upload Rate:</label> 280 280 <input type="text" name="upload_rate" id="upload_rate"/> 281 <label class="suffix"> KB/s</label>281 <label class="suffix">kB/s</label> 282 282 </div> 283 283 </div> … … 288 288 <label for="turtle_download_rate" class="item">Download Rate:</label> 289 289 <input type="text" name="turtle_download_rate" id="turtle_download_rate"/> 290 <label class="suffix"> KB/s</label>290 <label class="suffix">kB/s</label> 291 291 </div> 292 292 <div class="formdiv"> 293 293 <label for="turtle_upload_rate" class="item">Upload Rate:</label> 294 294 <input type="text" name="turtle_upload_rate" id="turtle_upload_rate"/> 295 <label class="suffix"> KB/s</label>295 <label class="suffix">kB/s</label> 296 296 </div> 297 297 <div class="formdiv checkbox"> … … 414 414 <ul id="footer_download_rate_menu"> 415 415 <li id="unlimited_download_rate">Unlimited</li> 416 <li id="limited_download_rate">Limit (10 KB/s)</li>416 <li id="limited_download_rate">Limit (10 kB/s)</li> 417 417 <li class="separator"></li> 418 <li>5 KB/s</li>419 <li>10 KB/s</li>420 <li>20 KB/s</li>421 <li>30 KB/s</li>422 <li>40 KB/s</li>423 <li>50 KB/s</li>424 <li>75 KB/s</li>425 <li>100 KB/s</li>426 <li>150 KB/s</li>427 <li>200 KB/s</li>428 <li>250 KB/s</li>429 <li>500 KB/s</li>430 <li>750 KB/s</li>418 <li>5 kB/s</li> 419 <li>10 kB/s</li> 420 <li>20 kB/s</li> 421 <li>30 kB/s</li> 422 <li>40 kB/s</li> 423 <li>50 kB/s</li> 424 <li>75 kB/s</li> 425 <li>100 kB/s</li> 426 <li>150 kB/s</li> 427 <li>200 kB/s</li> 428 <li>250 kB/s</li> 429 <li>500 kB/s</li> 430 <li>750 kB/s</li> 431 431 </ul> 432 432 </li> … … 434 434 <ul id="footer_upload_rate_menu"> 435 435 <li id="unlimited_upload_rate">Unlimited</li> 436 <li id="limited_upload_rate">Limit (10 KB/s)</li>436 <li id="limited_upload_rate">Limit (10 kB/s)</li> 437 437 <li class="separator"></li> 438 <li>5 KB/s</li>439 <li>10 KB/s</li>440 <li>20 KB/s</li>441 <li>30 KB/s</li>442 <li>40 KB/s</li>443 <li>50 KB/s</li>444 <li>75 KB/s</li>445 <li>100 KB/s</li>446 <li>150 KB/s</li>447 <li>200 KB/s</li>448 <li>250 KB/s</li>449 <li>500 KB/s</li>450 <li>750 KB/s</li>438 <li>5 kB/s</li> 439 <li>10 kB/s</li> 440 <li>20 kB/s</li> 441 <li>30 kB/s</li> 442 <li>40 kB/s</li> 443 <li>50 kB/s</li> 444 <li>75 kB/s</li> 445 <li>100 kB/s</li> 446 <li>150 kB/s</li> 447 <li>200 kB/s</li> 448 <li>250 kB/s</li> 449 <li>500 kB/s</li> 450 <li>750 kB/s</li> 451 451 </ul> 452 452 </li> -
trunk/web/javascript/formatter.js
r10835 r10931 8 8 Transmission.fmt = (function() 9 9 { 10 var KB_val = 1024; 11 var MB_val = 1024 * 1024; 12 var GB_val = 1024 * 1024 * 1024; 13 var KB_str = 'KiB'; 14 var MB_str = 'MiB'; 15 var GB_str = 'GiB'; 10 var speed_B_str = 'B'; 11 var speed_K_str = 'kB/s'; 12 var speed_M_str = 'MB/s'; 13 var speed_G_str = 'GB/s'; 14 15 var size_B_str = 'B'; 16 var size_K_str = 'KiB'; 17 var size_M_str = 'MiB'; 18 var size_G_str = 'GiB'; 16 19 17 20 return { 18 MODE_IEC: 1, 19 MODE_SI: 2, 21 speed_K: 1000, 22 23 size_K: 1024, 20 24 21 25 /* … … 43 47 }, 44 48 45 setMode: function( mode ) {46 if( mode == MODE_IEC ) {47 this.KB_val = 1024;48 this.MB_val = this.KB_val * 1024;49 this.GB_val = this.MB_val * 1024;50 this.KB_str = 'KiB';51 this.MB_str = 'MiB';52 this.GB_str = 'GiB';53 } else {54 this.KB_val = 1000;55 this.MB_val = this.KB_val * 1000;56 this.GB_val = this.MB_val * 1000;57 this.KB_str = 'kB';58 this.MB_str = 'MB';59 this.GB_str = 'GB';60 }61 },62 63 49 /** 64 50 * Formats the bytes into a string value with B, KiB, MiB, or GiB units. … … 69 55 size: function( bytes ) 70 56 { 57 var size_K = this.size_K; 58 var size_M = size_K * size_K; 59 var size_G = size_K * size_K * size_K; 60 71 61 if( !bytes ) 72 62 return 'None'; 63 if( bytes < size_K ) 64 return bytes.toTruncFixed(0) + size_B_str; 73 65 74 if( bytes < KB_val ) 75 return bytes.toFixed(0) + ' B'; 66 if( bytes < ( size_K * 100 ) ) 67 return (bytes/size_K).toTruncFixed(2) + ' ' + size_K_str; 68 if( bytes < size_M ) 69 return (bytes/size_K).toTruncFixed(1) + ' ' + size_K_str; 76 70 77 if( bytes < ( KB_val* 100 ) )78 return (bytes/ KB_val).toFixed(2) + ' ' + KB_str;79 if( bytes < MB_val)80 return (bytes/ KB_val).toFixed(1) + ' ' + KB_str;71 if( bytes < ( size_M * 100 ) ) 72 return (bytes/size_M).toTruncFixed(2) + ' ' + size_M_str; 73 if( bytes < size_G ) 74 return (bytes/size_M).toTruncFixed(1) + ' ' + size_M_str; 81 75 82 if( bytes < ( MB_val * 100 ) ) 83 return (bytes/MB_val).toFixed(2) + ' ' + MB_str; 84 if( bytes < GB_val ) 85 return (bytes/MB_val).toFixed(1) + ' ' + MB_str; 86 87 if( bytes < ( GB_val * 100 ) ) 88 return (bytes/GB_val).toFixed(2) + ' ' + GB_str; 76 if( bytes < ( size_G * 100 ) ) 77 return (bytes/size_G).toTruncFixed(2) + ' ' + size_G_str; 89 78 else 90 return (bytes/ GB_val).toFixed(1) + ' ' + GB_str;79 return (bytes/size_G).toTruncFixed(1) + ' ' + size_G_str; 91 80 }, 92 81 93 82 speed: function( bytes ) 94 83 { 95 if( !bytes ) 84 var speed_K = this.speed_K; 85 var speed_M = speed_K * speed_K; 86 var speed_G = speed_K * speed_K * speed_K; 87 88 if( bytes==undefined || bytes==0 ) 96 89 return 'None'; 90 91 if( bytes < speed_K ) 92 return bytes.toTruncFixed(0) + ' ' + speed_B_str; 93 94 if( bytes < ( speed_K * 100 ) ) 95 return (bytes/speed_K).toTruncFixed(2) + ' ' + speed_K_str; 96 if( bytes < speed_M ) 97 return (bytes/speed_K).toTruncFixed(1) + ' ' + speed_K_str; 98 99 if( bytes < ( speed_M * 100 ) ) 100 return (bytes/speed_M).toTruncFixed(2) + ' ' + speed_M_str; 101 if( bytes < speed_G ) 102 return (bytes/speed_M).toTruncFixed(1) + ' ' + speed_M_str; 103 104 if( bytes < ( speed_G * 100 ) ) 105 return (bytes/speed_G).toTruncFixed(2) + ' ' + speed_G_str; 97 106 else 98 return this.size( bytes ) + '/s';107 return (bytes/speed_G).toTruncFixed(1) + ' ' + speed_G_str; 99 108 }, 100 109 -
trunk/web/javascript/transmission.js
r10825 r10931 641 641 } 642 642 643 var speed_K = Transmission.fmt.speed_K; 644 var up_bytes = parseInt( $('#prefs_form #upload_rate' )[0].value ) * speed_K; 645 var dn_bytes = parseInt( $('#prefs_form #download_rate')[0].value ) * speed_K; 646 var turtle_up_bytes = parseInt( $('#prefs_form #turtle_upload_rate' )[0].value ) * speed_K; 647 var turtle_dn_bytes = parseInt( $('#prefs_form #turtle_download_rate')[0].value ) * speed_K; 648 643 649 // pass the new prefs upstream to the RPC server 644 650 var o = { }; 645 651 o[RPC._StartAddedTorrent] = $('#prefs_form #auto_start')[0].checked; 646 652 o[RPC._PeerPort] = parseInt( $('#prefs_form #port')[0].value ); 647 o[RPC._UpSpeedLimit] = parseInt( $('#prefs_form #upload_rate')[0].value );648 o[RPC._DownSpeedLimit] = parseInt( $('#prefs_form #download_rate')[0].value );653 o[RPC._UpSpeedLimit] = up_bytes; 654 o[RPC._DownSpeedLimit] = dn_bytes; 649 655 o[RPC._DownloadDir] = $('#prefs_form #download_location')[0].value; 650 o[RPC._UpSpeedLimited] = $('#prefs_form #limit_upload' )[0].checked;656 o[RPC._UpSpeedLimited] = $('#prefs_form #limit_upload' )[0].checked; 651 657 o[RPC._DownSpeedLimited] = $('#prefs_form #limit_download')[0].checked; 652 658 o[RPC._Encryption] = $('#prefs_form #encryption')[0].checked 653 659 ? RPC._EncryptionRequired 654 660 : RPC._EncryptionPreferred; 655 o[RPC._TurtleDownSpeedLimit] = parseInt( $('#prefs_form #turtle_download_rate')[0].value );656 o[RPC._TurtleUpSpeedLimit] = parseInt( $('#prefs_form #turtle_upload_rate')[0].value );661 o[RPC._TurtleDownSpeedLimit] = turtle_dn_bytes; 662 o[RPC._TurtleUpSpeedLimit] = turtle_up_bytes; 657 663 o[RPC._TurtleTimeEnabled] = $('#prefs_form #turtle_schedule')[0].checked; 658 664 o[RPC._TurtleTimeBegin] = parseInt( $('#prefs_form #turtle_start_time').val() ); … … 927 933 this._prefs = prefs; 928 934 929 var down_limit = prefs[RPC._DownSpeedLimit]; 930 var down_limited = prefs[RPC._DownSpeedLimited]; 931 var up_limit = prefs[RPC._UpSpeedLimit]; 932 var up_limited = prefs[RPC._UpSpeedLimited]; 935 var up_limited = prefs[RPC._UpSpeedLimited]; 936 var dn_limited = prefs[RPC._DownSpeedLimited]; 937 var up_limit_b = prefs[RPC._UpSpeedLimit]; 938 var dn_limit_b = prefs[RPC._DownSpeedLimit]; 939 var up_limit_k = up_limit_b / Transmission.fmt.speed_K; 940 var dn_limit_k = dn_limit_b / Transmission.fmt.speed_K; 941 var turtle_up_limit_k = prefs[RPC._TurtleUpSpeedLimit] / Transmission.fmt.speed_K; 942 var turtle_dn_limit_k = prefs[RPC._TurtleDownSpeedLimit] / Transmission.fmt.speed_K; 933 943 934 944 $('div.download_location input')[0].value = prefs[RPC._DownloadDir]; 935 945 $('div.port input')[0].value = prefs[RPC._PeerPort]; 936 946 $('div.auto_start input')[0].checked = prefs[RPC._StartAddedTorrent]; 937 $('input#limit_download')[0].checked = d own_limited;938 $('input#download_rate')[0].value = d own_limit;947 $('input#limit_download')[0].checked = dn_limited; 948 $('input#download_rate')[0].value = dn_limit_k; 939 949 $('input#limit_upload')[0].checked = up_limited; 940 $('input#upload_rate')[0].value = up_limit ;950 $('input#upload_rate')[0].value = up_limit_k; 941 951 $('input#refresh_rate')[0].value = prefs[Prefs._RefreshRate]; 942 952 $('div.encryption input')[0].checked = prefs[RPC._Encryption] == RPC._EncryptionRequired; 943 $('input#turtle_download_rate')[0].value = prefs[RPC._TurtleDownSpeedLimit];944 $('input#turtle_upload_rate')[0].value = prefs[RPC._TurtleUpSpeedLimit];953 $('input#turtle_download_rate')[0].value = turtle_dn_limit_k; 954 $('input#turtle_upload_rate')[0].value = turtle_up_limit_k; 945 955 $('input#turtle_schedule')[0].checked = prefs[RPC._TurtleTimeEnabled]; 946 956 $('select#turtle_start_time').val( prefs[RPC._TurtleTimeBegin] ); … … 951 961 if (!iPhone) 952 962 { 953 setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + Transmission.fmt.speed(d own_limit) + ')' );954 var key = d own_limited ? '#limited_download_rate'963 setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + Transmission.fmt.speed(dn_limit_b) + ')' ); 964 var key = dn_limited ? '#limited_download_rate' 955 965 : '#unlimited_download_rate'; 956 966 $(key).deselectMenuSiblings().selectMenuItem(); 957 967 958 setInnerHTML( $('#limited_ download_rate')[0], 'Limit (' + Transmission.fmt.speed(up_limit) + ')' );968 setInnerHTML( $('#limited_upload_rate')[0], 'Limit (' + Transmission.fmt.speed(up_limit_b) + ')' ); 959 969 key = up_limited ? '#limited_upload_rate' 960 970 : '#unlimited_upload_rate'; … … 1065 1075 case 'footer_download_rate_menu': 1066 1076 var args = { }; 1067 var rate = ($element[0].innerHTML).replace(/[^0-9]/ig, '');1068 1077 if ($element.is('#unlimited_download_rate')) { 1069 1078 $element.deselectMenuSiblings().selectMenuItem(); 1070 1079 args[RPC._DownSpeedLimited] = false; 1071 1080 } else { 1072 setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + Transmission.fmt.speed(rate) + ')' ); 1081 var rate_str = ($element[0].innerHTML).replace(/[^0-9]/ig, ''); 1082 var rate_b = parseInt( rate_str ) * Transmission.fmt.speed_K; 1083 setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + Transmission.fmt.speed(rate_b) + ')' ); 1073 1084 $('#limited_download_rate').deselectMenuSiblings().selectMenuItem(); 1074 $('div.preference input#download_rate')[0].value = rate ;1075 args[RPC._DownSpeedLimit] = parseInt( rate );1085 $('div.preference input#download_rate')[0].value = rate_str; 1086 args[RPC._DownSpeedLimit] = rate_b; 1076 1087 args[RPC._DownSpeedLimited] = true; 1077 1088 } … … 1083 1094 case 'footer_upload_rate_menu': 1084 1095 var args = { }; 1085 var rate = ($element[0].innerHTML).replace(/[^0-9]/ig, '');1086 1096 if ($element.is('#unlimited_upload_rate')) { 1087 1097 $element.deselectMenuSiblings().selectMenuItem(); 1088 1098 args[RPC._UpSpeedLimited] = false; 1089 1099 } else { 1090 setInnerHTML( $('#limited_upload_rate')[0], 'Limit (' + Transmission.fmt.speed(rate) + ')' ); 1100 var rate_str = ($element[0].innerHTML).replace(/[^0-9]/ig, ''); 1101 var rate_b = parseInt( rate_str ) * Transmission.fmt.speed_K; 1102 setInnerHTML( $('#limited_upload_rate')[0], 'Limit (' + Transmission.fmt.speed(rate_b) + ')' ); 1091 1103 $('#limited_upload_rate').deselectMenuSiblings().selectMenuItem(); 1092 $('div.preference input#upload_rate')[0].value = rate ;1093 args[RPC._UpSpeedLimit] = parseInt( rate );1104 $('div.preference input#upload_rate')[0].value = rate_str; 1105 args[RPC._UpSpeedLimit] = rate_b; 1094 1106 args[RPC._UpSpeedLimited] = true; 1095 1107 }
Note: See TracChangeset
for help on using the changeset viewer.