return EXIT_FAILURE;
}
- if (tr_variantDictFindStr (&settings, TR_PREFS_KEY_DOWNLOAD_DIR, &str, NULL))
+ if (tr_variantDictFindStr (&settings, TR_KEY_download_dir, &str, NULL))
{
str = tr_realpath (str, buf);
if (str != NULL)
{
- tr_variantDictAddStr (&settings, TR_PREFS_KEY_DOWNLOAD_DIR, str);
+ tr_variantDictAddStr (&settings, TR_KEY_download_dir, str);
}
else
{
switch (c)
{
case 'b':
- tr_variantDictAddBool (d, TR_PREFS_KEY_BLOCKLIST_ENABLED, true);
+ tr_variantDictAddBool (d, TR_KEY_blocklist_enabled, true);
break;
- case 'B': tr_variantDictAddBool (d, TR_PREFS_KEY_BLOCKLIST_ENABLED, false);
+ case 'B': tr_variantDictAddBool (d, TR_KEY_blocklist_enabled, false);
break;
case 'd':
- tr_variantDictAddInt (d, TR_PREFS_KEY_DSPEED_KBps, atoi (optarg));
- tr_variantDictAddBool (d, TR_PREFS_KEY_DSPEED_ENABLED, true);
+ tr_variantDictAddInt (d, TR_KEY_speed_limit_down, atoi (optarg));
+ tr_variantDictAddBool (d, TR_KEY_speed_limit_down_enabled, true);
break;
- case 'D': tr_variantDictAddBool (d, TR_PREFS_KEY_DSPEED_ENABLED, false);
+ case 'D': tr_variantDictAddBool (d, TR_KEY_speed_limit_down_enabled, false);
break;
case 'f':
- tr_variantDictAddStr (d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, optarg);
- tr_variantDictAddBool (d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, true);
+ tr_variantDictAddStr (d, TR_KEY_script_torrent_done_filename, optarg);
+ tr_variantDictAddBool (d, TR_KEY_script_torrent_done_enabled, true);
break;
case 'g': /* handled above */
break;
case 'm':
- tr_variantDictAddBool (d, TR_PREFS_KEY_PORT_FORWARDING, true);
+ tr_variantDictAddBool (d, TR_KEY_port_forwarding_enabled, true);
break;
case 'M':
- tr_variantDictAddBool (d, TR_PREFS_KEY_PORT_FORWARDING, false);
+ tr_variantDictAddBool (d, TR_KEY_port_forwarding_enabled, false);
break;
case 'p':
- tr_variantDictAddInt (d, TR_PREFS_KEY_PEER_PORT, atoi (optarg));
+ tr_variantDictAddInt (d, TR_KEY_peer_port, atoi (optarg));
break;
case 't':
- tr_variantDictAddInt (d, TR_PREFS_KEY_PEER_SOCKET_TOS, atoi (optarg));
+ tr_variantDictAddInt (d, TR_KEY_peer_socket_tos, atoi (optarg));
break;
case 'u':
- tr_variantDictAddInt (d, TR_PREFS_KEY_USPEED_KBps, atoi (optarg));
- tr_variantDictAddBool (d, TR_PREFS_KEY_USPEED_ENABLED, true);
+ tr_variantDictAddInt (d, TR_KEY_speed_limit_up, atoi (optarg));
+ tr_variantDictAddBool (d, TR_KEY_speed_limit_up_enabled, true);
break;
case 'U':
- tr_variantDictAddBool (d, TR_PREFS_KEY_USPEED_ENABLED, false);
+ tr_variantDictAddBool (d, TR_KEY_speed_limit_up_enabled, false);
break;
case 'v':
break;
case 'w':
- tr_variantDictAddStr (d, TR_PREFS_KEY_DOWNLOAD_DIR, optarg);
+ tr_variantDictAddStr (d, TR_KEY_download_dir, optarg);
break;
case 910:
- tr_variantDictAddInt (d, TR_PREFS_KEY_ENCRYPTION, TR_ENCRYPTION_REQUIRED);
+ tr_variantDictAddInt (d, TR_KEY_encryption, TR_ENCRYPTION_REQUIRED);
break;
case 911:
- tr_variantDictAddInt (d, TR_PREFS_KEY_ENCRYPTION, TR_ENCRYPTION_PREFERRED);
+ tr_variantDictAddInt (d, TR_KEY_encryption, TR_ENCRYPTION_PREFERRED);
break;
case 912:
- tr_variantDictAddInt (d, TR_PREFS_KEY_ENCRYPTION, TR_CLEAR_PREFERRED);
+ tr_variantDictAddInt (d, TR_KEY_encryption, TR_CLEAR_PREFERRED);
break;
case TR_OPT_UNK:
#define MY_NAME "transmission-daemon"
-#define PREF_KEY_DIR_WATCH "watch-dir"
-#define PREF_KEY_DIR_WATCH_ENABLED "watch-dir-enabled"
-#define PREF_KEY_PIDFILE "pidfile"
-
#define MEM_K 1024
#define MEM_K_STR "KiB"
#define MEM_M_STR "MiB"
static const char *logfileName = NULL;
static FILE *logfile = NULL;
static tr_session * mySession = NULL;
+static tr_quark key_pidfile = 0;
/***
**** Config File
configDir = tr_sessionGetConfigDir (mySession);
tr_inf ("Reloading settings from \"%s\"", configDir);
tr_variantInitDict (&settings, 0);
- tr_variantDictAddBool (&settings, TR_PREFS_KEY_RPC_ENABLED, true);
+ tr_variantDictAddBool (&settings, TR_KEY_rpc_enabled, true);
tr_sessionLoadSettings (&settings, configDir, MY_NAME);
tr_sessionSet (mySession, &settings);
tr_variantFree (&settings);
bool pidfile_created = false;
tr_session * session = NULL;
+ key_pidfile = tr_quark_new ("pidfile", 7);
+
signal (SIGINT, gotsig);
signal (SIGTERM, gotsig);
#ifndef WIN32
/* load settings from defaults + config file */
tr_variantInitDict (&settings, 0);
- tr_variantDictAddBool (&settings, TR_PREFS_KEY_RPC_ENABLED, true);
+ tr_variantDictAddBool (&settings, TR_KEY_rpc_enabled, true);
configDir = getConfigDir (argc, (const char**)argv);
loaded = tr_sessionLoadSettings (&settings, configDir, MY_NAME);
tr_optind = 1;
while ((c = tr_getopt (getUsage (), argc, (const char**)argv, options, &optarg))) {
switch (c) {
- case 'a': tr_variantDictAddStr (&settings, TR_PREFS_KEY_RPC_WHITELIST, optarg);
- tr_variantDictAddBool (&settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, true);
+ case 'a': tr_variantDictAddStr (&settings, TR_KEY_rpc_whitelist, optarg);
+ tr_variantDictAddBool (&settings, TR_KEY_rpc_whitelist_enabled, true);
break;
- case 'b': tr_variantDictAddBool (&settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, true);
+ case 'b': tr_variantDictAddBool (&settings, TR_KEY_blocklist_enabled, true);
break;
- case 'B': tr_variantDictAddBool (&settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, false);
+ case 'B': tr_variantDictAddBool (&settings, TR_KEY_blocklist_enabled, false);
break;
- case 'c': tr_variantDictAddStr (&settings, PREF_KEY_DIR_WATCH, optarg);
- tr_variantDictAddBool (&settings, PREF_KEY_DIR_WATCH_ENABLED, true);
+ case 'c': tr_variantDictAddStr (&settings, TR_KEY_watch_dir, optarg);
+ tr_variantDictAddBool (&settings, TR_KEY_watch_dir_enabled, true);
break;
- case 'C': tr_variantDictAddBool (&settings, PREF_KEY_DIR_WATCH_ENABLED, false);
+ case 'C': tr_variantDictAddBool (&settings, TR_KEY_watch_dir_enabled, false);
break;
- case 941: tr_variantDictAddStr (&settings, TR_PREFS_KEY_INCOMPLETE_DIR, optarg);
- tr_variantDictAddBool (&settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, true);
+ case 941: tr_variantDictAddStr (&settings, TR_KEY_incomplete_dir, optarg);
+ tr_variantDictAddBool (&settings, TR_KEY_incomplete_dir_enabled, true);
break;
- case 942: tr_variantDictAddBool (&settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, false);
+ case 942: tr_variantDictAddBool (&settings, TR_KEY_incomplete_dir_enabled, false);
break;
case 'd': dumpSettings = true;
break;
case 'V': /* version */
fprintf (stderr, "%s %s\n", MY_NAME, LONG_VERSION_STRING);
exit (0);
- case 'o': tr_variantDictAddBool (&settings, TR_PREFS_KEY_DHT_ENABLED, true);
+ case 'o': tr_variantDictAddBool (&settings, TR_KEY_dht_enabled, true);
break;
- case 'O': tr_variantDictAddBool (&settings, TR_PREFS_KEY_DHT_ENABLED, false);
+ case 'O': tr_variantDictAddBool (&settings, TR_KEY_dht_enabled, false);
break;
- case 'p': tr_variantDictAddInt (&settings, TR_PREFS_KEY_RPC_PORT, atoi (optarg));
+ case 'p': tr_variantDictAddInt (&settings, TR_KEY_rpc_port, atoi (optarg));
break;
- case 't': tr_variantDictAddBool (&settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, true);
+ case 't': tr_variantDictAddBool (&settings, TR_KEY_rpc_authentication_required, true);
break;
- case 'T': tr_variantDictAddBool (&settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, false);
+ case 'T': tr_variantDictAddBool (&settings, TR_KEY_rpc_authentication_required, false);
break;
- case 'u': tr_variantDictAddStr (&settings, TR_PREFS_KEY_RPC_USERNAME, optarg);
+ case 'u': tr_variantDictAddStr (&settings, TR_KEY_rpc_username, optarg);
break;
- case 'v': tr_variantDictAddStr (&settings, TR_PREFS_KEY_RPC_PASSWORD, optarg);
+ case 'v': tr_variantDictAddStr (&settings, TR_KEY_rpc_password, optarg);
break;
- case 'w': tr_variantDictAddStr (&settings, TR_PREFS_KEY_DOWNLOAD_DIR, optarg);
+ case 'w': tr_variantDictAddStr (&settings, TR_KEY_download_dir, optarg);
break;
- case 'P': tr_variantDictAddInt (&settings, TR_PREFS_KEY_PEER_PORT, atoi (optarg));
+ case 'P': tr_variantDictAddInt (&settings, TR_KEY_peer_port, atoi (optarg));
break;
- case 'm': tr_variantDictAddBool (&settings, TR_PREFS_KEY_PORT_FORWARDING, true);
+ case 'm': tr_variantDictAddBool (&settings, TR_KEY_port_forwarding_enabled, true);
break;
- case 'M': tr_variantDictAddBool (&settings, TR_PREFS_KEY_PORT_FORWARDING, false);
+ case 'M': tr_variantDictAddBool (&settings, TR_KEY_port_forwarding_enabled, false);
break;
- case 'L': tr_variantDictAddInt (&settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, atoi (optarg));
+ case 'L': tr_variantDictAddInt (&settings, TR_KEY_peer_limit_global, atoi (optarg));
break;
- case 'l': tr_variantDictAddInt (&settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, atoi (optarg));
+ case 'l': tr_variantDictAddInt (&settings, TR_KEY_peer_limit_per_torrent, atoi (optarg));
break;
case 800: paused = true;
break;
- case 910: tr_variantDictAddInt (&settings, TR_PREFS_KEY_ENCRYPTION, TR_ENCRYPTION_REQUIRED);
+ case 910: tr_variantDictAddInt (&settings, TR_KEY_encryption, TR_ENCRYPTION_REQUIRED);
break;
- case 911: tr_variantDictAddInt (&settings, TR_PREFS_KEY_ENCRYPTION, TR_ENCRYPTION_PREFERRED);
+ case 911: tr_variantDictAddInt (&settings, TR_KEY_encryption, TR_ENCRYPTION_PREFERRED);
break;
- case 912: tr_variantDictAddInt (&settings, TR_PREFS_KEY_ENCRYPTION, TR_CLEAR_PREFERRED);
+ case 912: tr_variantDictAddInt (&settings, TR_KEY_encryption, TR_CLEAR_PREFERRED);
break;
- case 'i': tr_variantDictAddStr (&settings, TR_PREFS_KEY_BIND_ADDRESS_IPV4, optarg);
+ case 'i': tr_variantDictAddStr (&settings, TR_KEY_bind_address_ipv4, optarg);
break;
- case 'I': tr_variantDictAddStr (&settings, TR_PREFS_KEY_BIND_ADDRESS_IPV6, optarg);
+ case 'I': tr_variantDictAddStr (&settings, TR_KEY_bind_address_ipv6, optarg);
break;
- case 'r': tr_variantDictAddStr (&settings, TR_PREFS_KEY_RPC_BIND_ADDRESS, optarg);
+ case 'r': tr_variantDictAddStr (&settings, TR_KEY_rpc_bind_address, optarg);
break;
- case 953: tr_variantDictAddReal (&settings, TR_PREFS_KEY_RATIO, atof (optarg));
- tr_variantDictAddBool (&settings, TR_PREFS_KEY_RATIO_ENABLED, true);
+ case 953: tr_variantDictAddReal (&settings, TR_KEY_ratio_limit, atof (optarg));
+ tr_variantDictAddBool (&settings, TR_KEY_ratio_limit_enabled, true);
break;
- case 954: tr_variantDictAddBool (&settings, TR_PREFS_KEY_RATIO_ENABLED, false);
+ case 954: tr_variantDictAddBool (&settings, TR_KEY_ratio_limit_enabled, false);
break;
- case 'x': tr_variantDictAddStr (&settings, PREF_KEY_PIDFILE, optarg);
+ case 'x': tr_variantDictAddStr (&settings, key_pidfile, optarg);
break;
- case 'y': tr_variantDictAddBool (&settings, TR_PREFS_KEY_LPD_ENABLED, true);
+ case 'y': tr_variantDictAddBool (&settings, TR_KEY_lpd_enabled, true);
break;
- case 'Y': tr_variantDictAddBool (&settings, TR_PREFS_KEY_LPD_ENABLED, false);
+ case 'Y': tr_variantDictAddBool (&settings, TR_KEY_lpd_enabled, false);
break;
- case 810: tr_variantDictAddInt (&settings, TR_PREFS_KEY_MSGLEVEL, TR_MSG_ERR);
+ case 810: tr_variantDictAddInt (&settings, TR_KEY_message_level, TR_MSG_ERR);
break;
- case 811: tr_variantDictAddInt (&settings, TR_PREFS_KEY_MSGLEVEL, TR_MSG_INF);
+ case 811: tr_variantDictAddInt (&settings, TR_KEY_message_level, TR_MSG_INF);
break;
- case 812: tr_variantDictAddInt (&settings, TR_PREFS_KEY_MSGLEVEL, TR_MSG_DBG);
+ case 812: tr_variantDictAddInt (&settings, TR_KEY_message_level, TR_MSG_DBG);
break;
- case 830: tr_variantDictAddBool (&settings, TR_PREFS_KEY_UTP_ENABLED, true);
+ case 830: tr_variantDictAddBool (&settings, TR_KEY_utp_enabled, true);
break;
- case 831: tr_variantDictAddBool (&settings, TR_PREFS_KEY_UTP_ENABLED, false);
+ case 831: tr_variantDictAddBool (&settings, TR_KEY_utp_enabled, false);
break;
default: showUsage ();
break;
tr_sessionSaveSettings (session, configDir, &settings);
pid_filename = NULL;
- tr_variantDictFindStr (&settings, PREF_KEY_PIDFILE, &pid_filename, NULL);
+ tr_variantDictFindStr (&settings, key_pidfile, &pid_filename, NULL);
if (pid_filename && *pid_filename)
{
FILE * fp = fopen (pid_filename, "w+");
tr_err ("Unable to save pidfile \"%s\": %s", pid_filename, tr_strerror (errno));
}
- if (tr_variantDictFindBool (&settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &boolVal) && boolVal)
+ if (tr_variantDictFindBool (&settings, TR_KEY_rpc_authentication_required, &boolVal) && boolVal)
tr_ninf (MY_NAME, "requiring authentication");
mySession = session;
{
const char * dir;
- if (tr_variantDictFindBool (&settings, PREF_KEY_DIR_WATCH_ENABLED, &boolVal)
+ if (tr_variantDictFindBool (&settings, TR_KEY_watch_dir_enabled, &boolVal)
&& boolVal
- && tr_variantDictFindStr (&settings, PREF_KEY_DIR_WATCH, &dir, NULL)
+ && tr_variantDictFindStr (&settings, TR_KEY_watch_dir, &dir, NULL)
&& dir
&& *dir)
{
#define DEFAULT_PORT atoi (TR_DEFAULT_RPC_PORT_STR)
#define DEFAULT_URL TR_DEFAULT_RPC_URL_STR "rpc/"
-#define ARGUMENTS "arguments"
+#define ARGUMENTS TR_KEY_arguments
#define MEM_K 1024
#define MEM_B_STR "B"
static int
numarg (const char * arg)
{
- char * end = NULL;
- const long num = strtol (arg, &end, 10);
+ char * end = NULL;
+ const long num = strtol (arg, &end, 10);
- if (*end)
+ if (*end)
{
- fprintf (stderr, "Not a number: \"%s\"\n", arg);
- showUsage ();
- exit (EXIT_FAILURE);
+ fprintf (stderr, "Not a number: \"%s\"\n", arg);
+ showUsage ();
+ exit (EXIT_FAILURE);
}
- return num;
+
+ return num;
}
enum
{
- MODE_TORRENT_START = (1<<0),
- MODE_TORRENT_STOP = (1<<1),
- MODE_TORRENT_VERIFY = (1<<2),
- MODE_TORRENT_REANNOUNCE = (1<<3),
- MODE_TORRENT_SET = (1<<4),
- MODE_TORRENT_GET = (1<<5),
- MODE_TORRENT_ADD = (1<<6),
- MODE_TORRENT_REMOVE = (1<<7),
- MODE_TORRENT_SET_LOCATION = (1<<8),
- MODE_SESSION_SET = (1<<9),
- MODE_SESSION_GET = (1<<10),
- MODE_SESSION_STATS = (1<<11),
- MODE_SESSION_CLOSE = (1<<12),
- MODE_BLOCKLIST_UPDATE = (1<<13),
- MODE_PORT_TEST = (1<<14)
+ MODE_TORRENT_START = (1<<0),
+ MODE_TORRENT_STOP = (1<<1),
+ MODE_TORRENT_VERIFY = (1<<2),
+ MODE_TORRENT_REANNOUNCE = (1<<3),
+ MODE_TORRENT_SET = (1<<4),
+ MODE_TORRENT_GET = (1<<5),
+ MODE_TORRENT_ADD = (1<<6),
+ MODE_TORRENT_REMOVE = (1<<7),
+ MODE_TORRENT_SET_LOCATION = (1<<8),
+ MODE_SESSION_SET = (1<<9),
+ MODE_SESSION_GET = (1<<10),
+ MODE_SESSION_STATS = (1<<11),
+ MODE_SESSION_CLOSE = (1<<12),
+ MODE_BLOCKLIST_UPDATE = (1<<13),
+ MODE_PORT_TEST = (1<<14)
};
static int
getOptMode (int val)
{
- switch (val)
+ switch (val)
{
- case TR_OPT_ERR:
- case TR_OPT_UNK:
- case 'a': /* add torrent */
- case 'b': /* debug */
- case 'n': /* auth */
- case 810: /* authenv */
- case 'N': /* netrc */
- case 820: /* UseSSL */
- case 't': /* set current torrent */
- case 'V': /* show version number */
- return 0;
-
- case 'c': /* incomplete-dir */
- case 'C': /* no-incomplete-dir */
- case 'e': /* cache */
- case 'm': /* portmap */
- case 'M': /* "no-portmap */
- case 'o': /* dht */
- case 'O': /* no-dht */
- case 'p': /* incoming peer port */
- case 'P': /* random incoming peer port */
- case 'x': /* pex */
- case 'X': /* no-pex */
- case 'y': /* lpd */
- case 'Y': /* no-lpd */
- case 800: /* torrent-done-script */
- case 801: /* no-torrent-done-script */
- case 830: /* utp */
- case 831: /* no-utp */
- case 970: /* alt-speed */
- case 971: /* no-alt-speed */
- case 972: /* alt-speed-downlimit */
- case 973: /* alt-speed-uplimit */
- case 974: /* alt-speed-scheduler */
- case 975: /* no-alt-speed-scheduler */
- case 976: /* alt-speed-time-begin */
- case 977: /* alt-speed-time-end */
- case 978: /* alt-speed-days */
- case 910: /* encryption-required */
- case 911: /* encryption-preferred */
- case 912: /* encryption-tolerated */
- case 953: /* global-seedratio */
- case 954: /* no-global-seedratio */
- case 990: /* start-paused */
- case 991: /* no-start-paused */
- case 992: /* trash-torrent */
- case 993: /* no-trash-torrent */
- return MODE_SESSION_SET;
-
- case 712: /* tracker-remove */
- case 950: /* seedratio */
- case 951: /* seedratio-default */
- case 952: /* no-seedratio */
- case 984: /* honor-session */
- case 985: /* no-honor-session */
- return MODE_TORRENT_SET;
-
- case 920: /* session-info */
- return MODE_SESSION_GET;
-
- case 'g': /* get */
- case 'G': /* no-get */
- case 700: /* torrent priority-high */
- case 701: /* torrent priority-normal */
- case 702: /* torrent priority-low */
- case 710: /* tracker-add */
- case 900: /* file priority-high */
- case 901: /* file priority-normal */
- case 902: /* file priority-low */
- return MODE_TORRENT_SET | MODE_TORRENT_ADD;
-
- case 961: /* find */
- return MODE_TORRENT_SET_LOCATION | MODE_TORRENT_ADD;
-
- case 'i': /* info */
- case 'l': /* list all torrents */
- case 940: /* info-files */
- case 941: /* info-peer */
- case 942: /* info-pieces */
- case 943: /* info-tracker */
- return MODE_TORRENT_GET;
-
- case 'd': /* download speed limit */
- case 'D': /* no download speed limit */
- case 'u': /* upload speed limit */
- case 'U': /* no upload speed limit */
- case 930: /* peers */
- return MODE_SESSION_SET | MODE_TORRENT_SET;
-
- case 's': /* start */
- return MODE_TORRENT_START | MODE_TORRENT_ADD;
-
- case 'S': /* stop */
- return MODE_TORRENT_STOP | MODE_TORRENT_ADD;
-
- case 'w': /* download-dir */
- return MODE_SESSION_SET | MODE_TORRENT_ADD;
-
- case 850: /* session-close */
- return MODE_SESSION_CLOSE;
-
- case 963: /* blocklist-update */
- return MODE_BLOCKLIST_UPDATE;
-
- case 921: /* session-stats */
- return MODE_SESSION_STATS;
-
- case 'v': /* verify */
- return MODE_TORRENT_VERIFY;
-
- case 600: /* reannounce */
- return MODE_TORRENT_REANNOUNCE;
-
- case 962: /* port-test */
- return MODE_PORT_TEST;
-
- case 'r': /* remove */
- case 'R': /* remove and delete */
- return MODE_TORRENT_REMOVE;
-
- case 960: /* move */
- return MODE_TORRENT_SET_LOCATION;
-
- default:
- fprintf (stderr, "unrecognized argument %d\n", val);
- assert ("unrecognized argument" && 0);
- return 0;
+ case TR_OPT_ERR:
+ case TR_OPT_UNK:
+ case 'a': /* add torrent */
+ case 'b': /* debug */
+ case 'n': /* auth */
+ case 810: /* authenv */
+ case 'N': /* netrc */
+ case 820: /* UseSSL */
+ case 't': /* set current torrent */
+ case 'V': /* show version number */
+ return 0;
+
+ case 'c': /* incomplete-dir */
+ case 'C': /* no-incomplete-dir */
+ case 'e': /* cache */
+ case 'm': /* portmap */
+ case 'M': /* "no-portmap */
+ case 'o': /* dht */
+ case 'O': /* no-dht */
+ case 'p': /* incoming peer port */
+ case 'P': /* random incoming peer port */
+ case 'x': /* pex */
+ case 'X': /* no-pex */
+ case 'y': /* lpd */
+ case 'Y': /* no-lpd */
+ case 800: /* torrent-done-script */
+ case 801: /* no-torrent-done-script */
+ case 830: /* utp */
+ case 831: /* no-utp */
+ case 970: /* alt-speed */
+ case 971: /* no-alt-speed */
+ case 972: /* alt-speed-downlimit */
+ case 973: /* alt-speed-uplimit */
+ case 974: /* alt-speed-scheduler */
+ case 975: /* no-alt-speed-scheduler */
+ case 976: /* alt-speed-time-begin */
+ case 977: /* alt-speed-time-end */
+ case 978: /* alt-speed-days */
+ case 910: /* encryption-required */
+ case 911: /* encryption-preferred */
+ case 912: /* encryption-tolerated */
+ case 953: /* global-seedratio */
+ case 954: /* no-global-seedratio */
+ case 990: /* start-paused */
+ case 991: /* no-start-paused */
+ case 992: /* trash-torrent */
+ case 993: /* no-trash-torrent */
+ return MODE_SESSION_SET;
+
+ case 712: /* tracker-remove */
+ case 950: /* seedratio */
+ case 951: /* seedratio-default */
+ case 952: /* no-seedratio */
+ case 984: /* honor-session */
+ case 985: /* no-honor-session */
+ return MODE_TORRENT_SET;
+
+ case 920: /* session-info */
+ return MODE_SESSION_GET;
+
+ case 'g': /* get */
+ case 'G': /* no-get */
+ case 700: /* torrent priority-high */
+ case 701: /* torrent priority-normal */
+ case 702: /* torrent priority-low */
+ case 710: /* tracker-add */
+ case 900: /* file priority-high */
+ case 901: /* file priority-normal */
+ case 902: /* file priority-low */
+ return MODE_TORRENT_SET | MODE_TORRENT_ADD;
+
+ case 961: /* find */
+ return MODE_TORRENT_SET_LOCATION | MODE_TORRENT_ADD;
+
+ case 'i': /* info */
+ case 'l': /* list all torrents */
+ case 940: /* info-files */
+ case 941: /* info-peer */
+ case 942: /* info-pieces */
+ case 943: /* info-tracker */
+ return MODE_TORRENT_GET;
+
+ case 'd': /* download speed limit */
+ case 'D': /* no download speed limit */
+ case 'u': /* upload speed limit */
+ case 'U': /* no upload speed limit */
+ case 930: /* peers */
+ return MODE_SESSION_SET | MODE_TORRENT_SET;
+
+ case 's': /* start */
+ return MODE_TORRENT_START | MODE_TORRENT_ADD;
+
+ case 'S': /* stop */
+ return MODE_TORRENT_STOP | MODE_TORRENT_ADD;
+
+ case 'w': /* download-dir */
+ return MODE_SESSION_SET | MODE_TORRENT_ADD;
+
+ case 850: /* session-close */
+ return MODE_SESSION_CLOSE;
+
+ case 963: /* blocklist-update */
+ return MODE_BLOCKLIST_UPDATE;
+
+ case 921: /* session-stats */
+ return MODE_SESSION_STATS;
+
+ case 'v': /* verify */
+ return MODE_TORRENT_VERIFY;
+
+ case 600: /* reannounce */
+ return MODE_TORRENT_REANNOUNCE;
+
+ case 962: /* port-test */
+ return MODE_PORT_TEST;
+
+ case 'r': /* remove */
+ case 'R': /* remove and delete */
+ return MODE_TORRENT_REMOVE;
+
+ case 960: /* move */
+ return MODE_TORRENT_SET_LOCATION;
+
+ default:
+ fprintf (stderr, "unrecognized argument %d\n", val);
+ assert ("unrecognized argument" && 0);
+ return 0;
}
}
static char*
tr_getcwd (void)
{
- char * result;
- char buf[2048];
+ char * result;
+ char buf[2048];
+
#ifdef WIN32
- result = _getcwd (buf, sizeof (buf));
+ result = _getcwd (buf, sizeof (buf));
#else
- result = getcwd (buf, sizeof (buf));
+ result = getcwd (buf, sizeof (buf));
#endif
- if (result == NULL)
+
+ if (result == NULL)
{
- fprintf (stderr, "getcwd error: \"%s\"", tr_strerror (errno));
- *buf = '\0';
+ fprintf (stderr, "getcwd error: \"%s\"", tr_strerror (errno));
+ *buf = '\0';
}
- return tr_strdup (buf);
+
+ return tr_strdup (buf);
}
static char*
absolutify (const char * path)
{
- char * buf;
+ char * buf;
- if (*path == '/')
- buf = tr_strdup (path);
- else {
- char * cwd = tr_getcwd ();
- buf = tr_buildPath (cwd, path, NULL);
- tr_free (cwd);
+ if (*path == '/')
+ {
+ buf = tr_strdup (path);
+ }
+ else
+ {
+ char * cwd = tr_getcwd ();
+ buf = tr_buildPath (cwd, path, NULL);
+ tr_free (cwd);
}
- return buf;
+ return buf;
}
static char*
if (!isdigit (*pch))
isNum = false;
if (isNum || isList)
- tr_rpc_parse_list_str (tr_variantDictAdd (args, "ids", 3), id, strlen (id));
+ tr_rpc_parse_list_str (tr_variantDictAdd (args, TR_KEY_ids), id, strlen (id));
else
- tr_variantDictAddStr (args, "ids", id); /* it's a torrent sha hash */
+ tr_variantDictAddStr (args, TR_KEY_ids, id); /* it's a torrent sha hash */
}
}
static void
-addTime (tr_variant * args, const char * key, const char * arg)
+addTime (tr_variant * args, const tr_quark key, const char * arg)
{
int time;
bool success = false;
}
static void
-addDays (tr_variant * args, const char * key, const char * arg)
+addDays (tr_variant * args, const tr_quark key, const char * arg)
{
- int days = 0;
+ int days = 0;
- if (arg)
+ if (arg)
{
- int i;
- int valueCount;
- int * values = tr_parseNumberRange (arg, -1, &valueCount);
- for (i=0; i<valueCount; ++i)
+ int i;
+ int valueCount;
+ int * values;
+
+ values = tr_parseNumberRange (arg, -1, &valueCount);
+ for (i=0; i<valueCount; ++i)
{
- if (values[i] < 0 || values[i] > 7) continue;
- if (values[i] == 7) values[i] = 0;
+ if (values[i] < 0 || values[i] > 7)
+ continue;
- days |= 1 << values[i];
+ if (values[i] == 7)
+ values[i] = 0;
+
+ days |= 1 << values[i];
}
- tr_free (values);
+
+ tr_free (values);
}
- if (days)
- tr_variantDictAddInt (args, key, days);
- else
- fprintf (stderr, "Please specify the days of the week in '1-3,4,7' format.\n");
+ if (days)
+ tr_variantDictAddInt (args, key, days);
+ else
+ fprintf (stderr, "Please specify the days of the week in '1-3,4,7' format.\n");
}
static void
-addFiles (tr_variant * args,
- const char * key,
- const char * arg)
+addFiles (tr_variant * args,
+ const tr_quark key,
+ const char * arg)
{
- tr_variant * files = tr_variantDictAddList (args, key, 100);
+ tr_variant * files = tr_variantDictAddList (args, key, 100);
- if (!*arg)
+ if (!*arg)
{
- fprintf (stderr, "No files specified!\n");
- arg = "-1"; /* no file will have this index, so should be a no-op */
+ fprintf (stderr, "No files specified!\n");
+ arg = "-1"; /* no file will have this index, so should be a no-op */
}
- if (strcmp (arg, "all"))
+
+ if (strcmp (arg, "all"))
{
- int i;
- int valueCount;
- int * values = tr_parseNumberRange (arg, -1, &valueCount);
- for (i=0; i<valueCount; ++i)
- tr_variantListAddInt (files, values[i]);
- tr_free (values);
+ int i;
+ int valueCount;
+ int * values = tr_parseNumberRange (arg, -1, &valueCount);
+
+ for (i=0; i<valueCount; ++i)
+ tr_variantListAddInt (files, values[i]);
+
+ tr_free (values);
}
}
#define TR_N_ELEMENTS(ary) (sizeof (ary) / sizeof (*ary))
-static const char * files_keys[] = {
- "files",
- "name",
- "priorities",
- "wanted"
+static const tr_quark files_keys[] = {
+ TR_KEY_files,
+ TR_KEY_name,
+ TR_KEY_priorities,
+ TR_KEY_wanted
};
-static const char * details_keys[] = {
- "activityDate",
- "addedDate",
- "bandwidthPriority",
- "comment",
- "corruptEver",
- "creator",
- "dateCreated",
- "desiredAvailable",
- "doneDate",
- "downloadDir",
- "downloadedEver",
- "downloadLimit",
- "downloadLimited",
- "error",
- "errorString",
- "eta",
- "hashString",
- "haveUnchecked",
- "haveValid",
- "honorsSessionLimits",
- "id",
- "isFinished",
- "isPrivate",
- "leftUntilDone",
- "magnetLink",
- "name",
- "peersConnected",
- "peersGettingFromUs",
- "peersSendingToUs",
- "peer-limit",
- "pieceCount",
- "pieceSize",
- "rateDownload",
- "rateUpload",
- "recheckProgress",
- "secondsDownloading",
- "secondsSeeding",
- "seedRatioMode",
- "seedRatioLimit",
- "sizeWhenDone",
- "startDate",
- "status",
- "totalSize",
- "uploadedEver",
- "uploadLimit",
- "uploadLimited",
- "webseeds",
- "webseedsSendingToUs"
+static const tr_quark details_keys[] = {
+ TR_KEY_activityDate,
+ TR_KEY_addedDate,
+ TR_KEY_bandwidthPriority,
+ TR_KEY_comment,
+ TR_KEY_corruptEver,
+ TR_KEY_creator,
+ TR_KEY_dateCreated,
+ TR_KEY_desiredAvailable,
+ TR_KEY_doneDate,
+ TR_KEY_downloadDir,
+ TR_KEY_downloadedEver,
+ TR_KEY_downloadLimit,
+ TR_KEY_downloadLimited,
+ TR_KEY_error,
+ TR_KEY_errorString,
+ TR_KEY_eta,
+ TR_KEY_hashString,
+ TR_KEY_haveUnchecked,
+ TR_KEY_haveValid,
+ TR_KEY_honorsSessionLimits,
+ TR_KEY_id,
+ TR_KEY_isFinished,
+ TR_KEY_isPrivate,
+ TR_KEY_leftUntilDone,
+ TR_KEY_magnetLink,
+ TR_KEY_name,
+ TR_KEY_peersConnected,
+ TR_KEY_peersGettingFromUs,
+ TR_KEY_peersSendingToUs,
+ TR_KEY_peer_limit,
+ TR_KEY_pieceCount,
+ TR_KEY_pieceSize,
+ TR_KEY_rateDownload,
+ TR_KEY_rateUpload,
+ TR_KEY_recheckProgress,
+ TR_KEY_secondsDownloading,
+ TR_KEY_secondsSeeding,
+ TR_KEY_seedRatioMode,
+ TR_KEY_seedRatioLimit,
+ TR_KEY_sizeWhenDone,
+ TR_KEY_startDate,
+ TR_KEY_status,
+ TR_KEY_totalSize,
+ TR_KEY_uploadedEver,
+ TR_KEY_uploadLimit,
+ TR_KEY_uploadLimited,
+ TR_KEY_webseeds,
+ TR_KEY_webseedsSendingToUs
};
-static const char * list_keys[] = {
- "error",
- "errorString",
- "eta",
- "id",
- "isFinished",
- "leftUntilDone",
- "name",
- "peersGettingFromUs",
- "peersSendingToUs",
- "rateDownload",
- "rateUpload",
- "sizeWhenDone",
- "status",
- "uploadRatio"
+static const tr_quark list_keys[] = {
+ TR_KEY_error,
+ TR_KEY_errorString,
+ TR_KEY_eta,
+ TR_KEY_id,
+ TR_KEY_isFinished,
+ TR_KEY_leftUntilDone,
+ TR_KEY_name,
+ TR_KEY_peersGettingFromUs,
+ TR_KEY_peersSendingToUs,
+ TR_KEY_rateDownload,
+ TR_KEY_rateUpload,
+ TR_KEY_sizeWhenDone,
+ TR_KEY_status,
+ TR_KEY_uploadRatio
};
static size_t
int64_t status;
bool boolVal;
- if (!tr_variantDictFindInt (t, "status", &status))
+ if (!tr_variantDictFindInt (t, TR_KEY_status, &status))
{
*buf = '\0';
}
break;
case TR_STATUS_STOPPED:
- if (tr_variantDictFindBool (t, "isFinished", &boolVal) && boolVal)
+ if (tr_variantDictFindBool (t, TR_KEY_isFinished, &boolVal) && boolVal)
tr_strlcpy (buf, "Finished", buflen);
else
tr_strlcpy (buf, "Stopped", buflen);
? "Will Verify"
: "Verifying";
double percent;
- if (tr_variantDictFindReal (t, "recheckProgress", &percent))
+ if (tr_variantDictFindReal (t, TR_KEY_recheckProgress, &percent))
tr_snprintf (buf, buflen, "%s (%.0f%%)", str, floor (percent*100.0));
else
tr_strlcpy (buf, str, buflen);
case TR_STATUS_SEED: {
int64_t fromUs = 0;
int64_t toUs = 0;
- tr_variantDictFindInt (t, "peersGettingFromUs", &fromUs);
- tr_variantDictFindInt (t, "peersSendingToUs", &toUs);
+ tr_variantDictFindInt (t, TR_KEY_peersGettingFromUs, &fromUs);
+ tr_variantDictFindInt (t, TR_KEY_peersSendingToUs, &toUs);
if (fromUs && toUs)
tr_strlcpy (buf, "Up & Down", buflen);
else if (toUs)
tr_strlcpy (buf, "Downloading", buflen);
else if (fromUs) {
int64_t leftUntilDone = 0;
- tr_variantDictFindInt (t, "leftUntilDone", &leftUntilDone);
+ tr_variantDictFindInt (t, TR_KEY_leftUntilDone, &leftUntilDone);
if (leftUntilDone > 0)
tr_strlcpy (buf, "Uploading", buflen);
else
{
tr_variant *args, *torrents;
- if ((tr_variantDictFindDict (top, "arguments", &args))
- && (tr_variantDictFindList (args, "torrents", &torrents)))
+ if ((tr_variantDictFindDict (top, TR_KEY_arguments, &args))
+ && (tr_variantDictFindList (args, TR_KEY_torrents, &torrents)))
{
int ti, tCount;
for (ti = 0, tCount = tr_variantListSize (torrents); ti < tCount;
double d;
printf ("NAME\n");
- if (tr_variantDictFindInt (t, "id", &i))
+ if (tr_variantDictFindInt (t, TR_KEY_id, &i))
printf (" Id: %" PRId64 "\n", i);
- if (tr_variantDictFindStr (t, "name", &str, NULL))
+ if (tr_variantDictFindStr (t, TR_KEY_name, &str, NULL))
printf (" Name: %s\n", str);
- if (tr_variantDictFindStr (t, "hashString", &str, NULL))
+ if (tr_variantDictFindStr (t, TR_KEY_hashString, &str, NULL))
printf (" Hash: %s\n", str);
- if (tr_variantDictFindStr (t, "magnetLink", &str, NULL))
+ if (tr_variantDictFindStr (t, TR_KEY_magnetLink, &str, NULL))
printf (" Magnet: %s\n", str);
printf ("\n");
getStatusString (t, buf, sizeof (buf));
printf (" State: %s\n", buf);
- if (tr_variantDictFindStr (t, "downloadDir", &str, NULL))
+ if (tr_variantDictFindStr (t, TR_KEY_downloadDir, &str, NULL))
printf (" Location: %s\n", str);
- if (tr_variantDictFindInt (t, "sizeWhenDone", &i)
- && tr_variantDictFindInt (t, "leftUntilDone", &j))
+ if (tr_variantDictFindInt (t, TR_KEY_sizeWhenDone, &i)
+ && tr_variantDictFindInt (t, TR_KEY_leftUntilDone, &j))
{
strlpercent (buf, 100.0 * (i - j) / i, sizeof (buf));
printf (" Percent Done: %s%%\n", buf);
}
- if (tr_variantDictFindInt (t, "eta", &i))
+ if (tr_variantDictFindInt (t, TR_KEY_eta, &i))
printf (" ETA: %s\n", tr_strltime (buf, i, sizeof (buf)));
- if (tr_variantDictFindInt (t, "rateDownload", &i))
+ if (tr_variantDictFindInt (t, TR_KEY_rateDownload, &i))
printf (" Download Speed: %s\n", tr_formatter_speed_KBps (buf, i/ (double)tr_speed_K, sizeof (buf)));
- if (tr_variantDictFindInt (t, "rateUpload", &i))
+ if (tr_variantDictFindInt (t, TR_KEY_rateUpload, &i))
printf (" Upload Speed: %s\n", tr_formatter_speed_KBps (buf, i/ (double)tr_speed_K, sizeof (buf)));
- if (tr_variantDictFindInt (t, "haveUnchecked", &i)
- && tr_variantDictFindInt (t, "haveValid", &j))
+ if (tr_variantDictFindInt (t, TR_KEY_haveUnchecked, &i)
+ && tr_variantDictFindInt (t, TR_KEY_haveValid, &j))
{
strlsize (buf, i + j, sizeof (buf));
strlsize (buf2, j, sizeof (buf2));
printf (" Have: %s (%s verified)\n", buf, buf2);
}
- if (tr_variantDictFindInt (t, "sizeWhenDone", &i))
+ if (tr_variantDictFindInt (t, TR_KEY_sizeWhenDone, &i))
{
if (i < 1)
printf (" Availability: None\n");
- if (tr_variantDictFindInt (t, "desiredAvailable", &j)
- && tr_variantDictFindInt (t, "leftUntilDone", &k))
+ if (tr_variantDictFindInt (t, TR_KEY_desiredAvailable, &j)
+ && tr_variantDictFindInt (t, TR_KEY_leftUntilDone, &k))
{
j += i - k;
strlpercent (buf, 100.0 * j / i, sizeof (buf));
printf (" Availability: %s%%\n", buf);
}
- if (tr_variantDictFindInt (t, "totalSize", &j))
+ if (tr_variantDictFindInt (t, TR_KEY_totalSize, &j))
{
strlsize (buf2, i, sizeof (buf2));
strlsize (buf, j, sizeof (buf));
printf (" Total size: %s (%s wanted)\n", buf, buf2);
}
}
- if (tr_variantDictFindInt (t, "downloadedEver", &i)
- && tr_variantDictFindInt (t, "uploadedEver", &j))
+ if (tr_variantDictFindInt (t, TR_KEY_downloadedEver, &i)
+ && tr_variantDictFindInt (t, TR_KEY_uploadedEver, &j))
{
strlsize (buf, i, sizeof (buf));
printf (" Downloaded: %s\n", buf);
strlratio (buf, j, i, sizeof (buf));
printf (" Ratio: %s\n", buf);
}
- if (tr_variantDictFindInt (t, "corruptEver", &i))
+ if (tr_variantDictFindInt (t, TR_KEY_corruptEver, &i))
{
strlsize (buf, i, sizeof (buf));
printf (" Corrupt DL: %s\n", buf);
}
- if (tr_variantDictFindStr (t, "errorString", &str, NULL) && str && *str &&
- tr_variantDictFindInt (t, "error", &i) && i)
+ if (tr_variantDictFindStr (t, TR_KEY_errorString, &str, NULL) && str && *str &&
+ tr_variantDictFindInt (t, TR_KEY_error, &i) && i)
{
switch (i) {
case TR_STAT_TRACKER_WARNING: printf (" Tracker gave a warning: %s\n", str); break;
default: break; /* no error */
}
}
- if (tr_variantDictFindInt (t, "peersConnected", &i)
- && tr_variantDictFindInt (t, "peersGettingFromUs", &j)
- && tr_variantDictFindInt (t, "peersSendingToUs", &k))
+ if (tr_variantDictFindInt (t, TR_KEY_peersConnected, &i)
+ && tr_variantDictFindInt (t, TR_KEY_peersGettingFromUs, &j)
+ && tr_variantDictFindInt (t, TR_KEY_peersSendingToUs, &k))
{
printf (
" Peers: "
i, j, k);
}
- if (tr_variantDictFindList (t, "webseeds", &l)
- && tr_variantDictFindInt (t, "webseedsSendingToUs", &i))
+ if (tr_variantDictFindList (t, TR_KEY_webseeds, &l)
+ && tr_variantDictFindInt (t, TR_KEY_webseedsSendingToUs, &i))
{
const int64_t n = tr_variantListSize (l);
if (n > 0)
printf ("\n");
printf ("HISTORY\n");
- if (tr_variantDictFindInt (t, "addedDate", &i) && i)
+ if (tr_variantDictFindInt (t, TR_KEY_addedDate, &i) && i)
{
const time_t tt = i;
printf (" Date added: %s", ctime (&tt));
}
- if (tr_variantDictFindInt (t, "doneDate", &i) && i)
+ if (tr_variantDictFindInt (t, TR_KEY_doneDate, &i) && i)
{
const time_t tt = i;
printf (" Date finished: %s", ctime (&tt));
}
- if (tr_variantDictFindInt (t, "startDate", &i) && i)
+ if (tr_variantDictFindInt (t, TR_KEY_startDate, &i) && i)
{
const time_t tt = i;
printf (" Date started: %s", ctime (&tt));
}
- if (tr_variantDictFindInt (t, "activityDate", &i) && i)
+ if (tr_variantDictFindInt (t, TR_KEY_activityDate, &i) && i)
{
const time_t tt = i;
printf (" Latest activity: %s", ctime (&tt));
}
- if (tr_variantDictFindInt (t, "secondsDownloading", &i) && (i > 0))
+ if (tr_variantDictFindInt (t, TR_KEY_secondsDownloading, &i) && (i > 0))
printf (" Downloading Time: %s\n", tr_strltime (buf, i, sizeof (buf)));
- if (tr_variantDictFindInt (t, "secondsSeeding", &i) && (i > 0))
+ if (tr_variantDictFindInt (t, TR_KEY_secondsSeeding, &i) && (i > 0))
printf (" Seeding Time: %s\n", tr_strltime (buf, i, sizeof (buf)));
printf ("\n");
printf ("ORIGINS\n");
- if (tr_variantDictFindInt (t, "dateCreated", &i) && i)
+ if (tr_variantDictFindInt (t, TR_KEY_dateCreated, &i) && i)
{
const time_t tt = i;
printf (" Date created: %s", ctime (&tt));
}
- if (tr_variantDictFindBool (t, "isPrivate", &boolVal))
+ if (tr_variantDictFindBool (t, TR_KEY_isPrivate, &boolVal))
printf (" Public torrent: %s\n", (boolVal ? "No" : "Yes"));
- if (tr_variantDictFindStr (t, "comment", &str, NULL) && str && *str)
+ if (tr_variantDictFindStr (t, TR_KEY_comment, &str, NULL) && str && *str)
printf (" Comment: %s\n", str);
- if (tr_variantDictFindStr (t, "creator", &str, NULL) && str && *str)
+ if (tr_variantDictFindStr (t, TR_KEY_creator, &str, NULL) && str && *str)
printf (" Creator: %s\n", str);
- if (tr_variantDictFindInt (t, "pieceCount", &i))
+ if (tr_variantDictFindInt (t, TR_KEY_pieceCount, &i))
printf (" Piece Count: %" PRId64 "\n", i);
- if (tr_variantDictFindInt (t, "pieceSize", &i))
+ if (tr_variantDictFindInt (t, TR_KEY_pieceSize, &i))
printf (" Piece Size: %s\n", strlmem (buf, i, sizeof (buf)));
printf ("\n");
printf ("LIMITS & BANDWIDTH\n");
- if (tr_variantDictFindBool (t, "downloadLimited", &boolVal)
- && tr_variantDictFindInt (t, "downloadLimit", &i))
+ if (tr_variantDictFindBool (t, TR_KEY_downloadLimited, &boolVal)
+ && tr_variantDictFindInt (t, TR_KEY_downloadLimit, &i))
{
printf (" Download Limit: ");
if (boolVal)
else
printf ("Unlimited\n");
}
- if (tr_variantDictFindBool (t, "uploadLimited", &boolVal)
- && tr_variantDictFindInt (t, "uploadLimit", &i))
+ if (tr_variantDictFindBool (t, TR_KEY_uploadLimited, &boolVal)
+ && tr_variantDictFindInt (t, TR_KEY_uploadLimit, &i))
{
printf (" Upload Limit: ");
if (boolVal)
else
printf ("Unlimited\n");
}
- if (tr_variantDictFindInt (t, "seedRatioMode", &i))
+ if (tr_variantDictFindInt (t, TR_KEY_seedRatioMode, &i))
{
switch (i) {
case TR_RATIOLIMIT_GLOBAL:
printf (" Ratio Limit: Default\n");
break;
case TR_RATIOLIMIT_SINGLE:
- if (tr_variantDictFindReal (t, "seedRatioLimit", &d))
+ if (tr_variantDictFindReal (t, TR_KEY_seedRatioLimit, &d))
printf (" Ratio Limit: %.2f\n", d);
break;
case TR_RATIOLIMIT_UNLIMITED:
default: break;
}
}
- if (tr_variantDictFindBool (t, "honorsSessionLimits", &boolVal))
+ if (tr_variantDictFindBool (t, TR_KEY_honorsSessionLimits, &boolVal))
printf (" Honors Session Limits: %s\n", (boolVal ? "Yes" : "No"));
- if (tr_variantDictFindInt (t, "peer-limit", &i))
+ if (tr_variantDictFindInt (t, TR_KEY_peer_limit, &i))
printf (" Peer limit: %" PRId64 "\n", i);
- if (tr_variantDictFindInt (t, "bandwidthPriority", &i))
+ if (tr_variantDictFindInt (t, TR_KEY_bandwidthPriority, &i))
printf (" Bandwidth Priority: %s\n",
bandwidthPriorityNames[ (i + 1) & 3]);
{
tr_variant *args, *torrents;
- if ((tr_variantDictFindDict (top, "arguments", &args))
- && (tr_variantDictFindList (args, "torrents", &torrents)))
+ if ((tr_variantDictFindDict (top, TR_KEY_arguments, &args))
+ && (tr_variantDictFindList (args, TR_KEY_torrents, &torrents)))
{
int i, in;
for (i = 0, in = tr_variantListSize (torrents); i < in; ++i)
tr_variant * d = tr_variantListChild (torrents, i);
tr_variant * files, *priorities, *wanteds;
const char * name;
- if (tr_variantDictFindStr (d, "name", &name, NULL)
- && tr_variantDictFindList (d, "files", &files)
- && tr_variantDictFindList (d, "priorities", &priorities)
- && tr_variantDictFindList (d, "wanted", &wanteds))
+ if (tr_variantDictFindStr (d, TR_KEY_name, &name, NULL)
+ && tr_variantDictFindList (d, TR_KEY_files, &files)
+ && tr_variantDictFindList (d, TR_KEY_priorities, &priorities)
+ && tr_variantDictFindList (d, TR_KEY_wanted, &wanteds))
{
int j = 0, jn = tr_variantListSize (files);
printf ("%s (%d files):\n", name, jn);
int64_t wanted;
const char * filename;
tr_variant * file = tr_variantListChild (files, j);
- if (tr_variantDictFindInt (file, "length", &length)
- && tr_variantDictFindStr (file, "name", &filename, NULL)
- && tr_variantDictFindInt (file, "bytesCompleted", &have)
- && tr_variantGetInt (tr_variantListChild (priorities,
- j), &priority)
- && tr_variantGetInt (tr_variantListChild (wanteds,
- j), &wanted))
+ if (tr_variantDictFindInt (file, TR_KEY_length, &length)
+ && tr_variantDictFindStr (file, TR_KEY_name, &filename, NULL)
+ && tr_variantDictFindInt (file, TR_KEY_bytesCompleted, &have)
+ && tr_variantGetInt (tr_variantListChild (priorities, j), &priority)
+ && tr_variantGetInt (tr_variantListChild (wanteds, j), &wanted))
{
char sizestr[64];
double percent = (double)have / length;
static void
printPeersImpl (tr_variant * peers)
{
- int i, n;
- printf ("%-20s %-12s %-5s %-6s %-6s %s\n",
- "Address", "Flags", "Done", "Down", "Up", "Client");
- for (i = 0, n = tr_variantListSize (peers); i < n; ++i)
+ int i, n;
+ printf ("%-20s %-12s %-5s %-6s %-6s %s\n",
+ "Address", "Flags", "Done", "Down", "Up", "Client");
+
+ for (i=0, n=tr_variantListSize(peers); i<n; ++i)
{
- double progress;
- const char * address, * client, * flagstr;
- int64_t rateToClient, rateToPeer;
- tr_variant * d = tr_variantListChild (peers, i);
-
- if (tr_variantDictFindStr (d, "address", &address, NULL)
- && tr_variantDictFindStr (d, "clientName", &client, NULL)
- && tr_variantDictFindReal (d, "progress", &progress)
- && tr_variantDictFindStr (d, "flagStr", &flagstr, NULL)
- && tr_variantDictFindInt (d, "rateToClient", &rateToClient)
- && tr_variantDictFindInt (d, "rateToPeer", &rateToPeer))
+ double progress;
+ const char * address, * client, * flagstr;
+ int64_t rateToClient, rateToPeer;
+ tr_variant * d = tr_variantListChild (peers, i);
+
+ if (tr_variantDictFindStr (d, TR_KEY_address, &address, NULL)
+ && tr_variantDictFindStr (d, TR_KEY_clientName, &client, NULL)
+ && tr_variantDictFindReal (d, TR_KEY_progress, &progress)
+ && tr_variantDictFindStr (d, TR_KEY_flagStr, &flagstr, NULL)
+ && tr_variantDictFindInt (d, TR_KEY_rateToClient, &rateToClient)
+ && tr_variantDictFindInt (d, TR_KEY_rateToPeer, &rateToPeer))
{
- printf ("%-20s %-12s %-5.1f %6.1f %6.1f %s\n",
- address, flagstr, (progress*100.0),
- rateToClient / (double)tr_speed_K,
- rateToPeer / (double)tr_speed_K,
- client);
+ printf ("%-20s %-12s %-5.1f %6.1f %6.1f %s\n",
+ address, flagstr, (progress*100.0),
+ rateToClient / (double)tr_speed_K,
+ rateToPeer / (double)tr_speed_K,
+ client);
}
}
}
static void
printPeers (tr_variant * top)
{
- tr_variant *args, *torrents;
+ tr_variant *args, *torrents;
- if (tr_variantDictFindDict (top, "arguments", &args)
- && tr_variantDictFindList (args, "torrents", &torrents))
+ if (tr_variantDictFindDict (top, TR_KEY_arguments, &args)
+ && tr_variantDictFindList (args, TR_KEY_torrents, &torrents))
{
- int i, n;
- for (i=0, n=tr_variantListSize (torrents); i<n; ++i)
+ int i, n;
+ for (i=0, n=tr_variantListSize (torrents); i<n; ++i)
{
- tr_variant * peers;
- tr_variant * torrent = tr_variantListChild (torrents, i);
- if (tr_variantDictFindList (torrent, "peers", &peers)) {
- printPeersImpl (peers);
- if (i+1<n)
- printf ("\n");
+ tr_variant * peers;
+ tr_variant * torrent = tr_variantListChild (torrents, i);
+ if (tr_variantDictFindList (torrent, TR_KEY_peers, &peers))
+ {
+ printPeersImpl (peers);
+ if (i+1<n)
+ printf ("\n");
}
}
}
{
tr_variant *args, *torrents;
- if (tr_variantDictFindDict (top, "arguments", &args)
- && tr_variantDictFindList (args, "torrents", &torrents))
+ if (tr_variantDictFindDict (top, TR_KEY_arguments, &args)
+ && tr_variantDictFindList (args, TR_KEY_torrents, &torrents))
{
int i, n;
for (i=0, n=tr_variantListSize (torrents); i<n; ++i)
const uint8_t * raw;
size_t rawlen;
tr_variant * torrent = tr_variantListChild (torrents, i);
- if (tr_variantDictFindRaw (torrent, "pieces", &raw, &rawlen) &&
- tr_variantDictFindInt (torrent, "pieceCount", &j)) {
+ if (tr_variantDictFindRaw (torrent, TR_KEY_pieces, &raw, &rawlen) &&
+ tr_variantDictFindInt (torrent, TR_KEY_pieceCount, &j)) {
printPiecesImpl (raw, rawlen, j);
if (i+1<n)
printf ("\n");
printPortTest (tr_variant * top)
{
tr_variant *args;
- if ((tr_variantDictFindDict (top, "arguments", &args)))
+ if ((tr_variantDictFindDict (top, TR_KEY_arguments, &args)))
{
bool boolVal;
- if (tr_variantDictFindBool (args, "port-is-open", &boolVal))
+ if (tr_variantDictFindBool (args, TR_KEY_port_is_open, &boolVal))
printf ("Port is open: %s\n", (boolVal ? "Yes" : "No"));
}
}
{
tr_variant *args, *list;
- if ((tr_variantDictFindDict (top, "arguments", &args))
- && (tr_variantDictFindList (args, "torrents", &list)))
+ if ((tr_variantDictFindDict (top, TR_KEY_arguments, &args))
+ && (tr_variantDictFindList (args, TR_KEY_torrents, &list)))
{
int i, n;
int64_t total_size=0;
double ratio;
const char * name;
tr_variant * d = tr_variantListChild (list, i);
- if (tr_variantDictFindInt (d, "eta", &eta)
- && tr_variantDictFindInt (d, "id", &id)
- && tr_variantDictFindInt (d, "leftUntilDone", &leftUntilDone)
- && tr_variantDictFindStr (d, "name", &name, NULL)
- && tr_variantDictFindInt (d, "rateDownload", &down)
- && tr_variantDictFindInt (d, "rateUpload", &up)
- && tr_variantDictFindInt (d, "sizeWhenDone", &sizeWhenDone)
- && tr_variantDictFindInt (d, "status", &status)
- && tr_variantDictFindReal (d, "uploadRatio", &ratio))
+ if (tr_variantDictFindInt (d, TR_KEY_eta, &eta)
+ && tr_variantDictFindInt (d, TR_KEY_id, &id)
+ && tr_variantDictFindInt (d, TR_KEY_leftUntilDone, &leftUntilDone)
+ && tr_variantDictFindStr (d, TR_KEY_name, &name, NULL)
+ && tr_variantDictFindInt (d, TR_KEY_rateDownload, &down)
+ && tr_variantDictFindInt (d, TR_KEY_rateUpload, &up)
+ && tr_variantDictFindInt (d, TR_KEY_sizeWhenDone, &sizeWhenDone)
+ && tr_variantDictFindInt (d, TR_KEY_status, &status)
+ && tr_variantDictFindReal (d, TR_KEY_uploadRatio, &ratio))
{
char etaStr[16];
char statusStr[64];
etaToString (etaStr, sizeof (etaStr), eta);
else
tr_snprintf (etaStr, sizeof (etaStr), "Done");
- if (tr_variantDictFindInt (d, "error", &error) && error)
+ if (tr_variantDictFindInt (d, TR_KEY_error, &error) && error)
errorMark = '*';
else
errorMark = ' ';
int64_t announceState;
int64_t scrapeState;
- if (tr_variantDictFindInt (t, "downloadCount", &downloadCount) &&
- tr_variantDictFindBool (t, "hasAnnounced", &hasAnnounced) &&
- tr_variantDictFindBool (t, "hasScraped", &hasScraped) &&
- tr_variantDictFindStr (t, "host", &host, NULL) &&
- tr_variantDictFindInt (t, "id", &id) &&
- tr_variantDictFindBool (t, "isBackup", &isBackup) &&
- tr_variantDictFindInt (t, "announceState", &announceState) &&
- tr_variantDictFindInt (t, "scrapeState", &scrapeState) &&
- tr_variantDictFindInt (t, "lastAnnouncePeerCount", &lastAnnouncePeerCount) &&
- tr_variantDictFindStr (t, "lastAnnounceResult", &lastAnnounceResult, NULL) &&
- tr_variantDictFindInt (t, "lastAnnounceStartTime", &lastAnnounceStartTime) &&
- tr_variantDictFindBool (t, "lastAnnounceSucceeded", &lastAnnounceSucceeded) &&
- tr_variantDictFindInt (t, "lastAnnounceTime", &lastAnnounceTime) &&
- tr_variantDictFindBool (t, "lastAnnounceTimedOut", &lastAnnounceTimedOut) &&
- tr_variantDictFindStr (t, "lastScrapeResult", &lastScrapeResult, NULL) &&
- tr_variantDictFindInt (t, "lastScrapeStartTime", &lastScrapeStartTime) &&
- tr_variantDictFindBool (t, "lastScrapeSucceeded", &lastScrapeSucceeded) &&
- tr_variantDictFindInt (t, "lastScrapeTime", &lastScrapeTime) &&
- tr_variantDictFindBool (t, "lastScrapeTimedOut", &lastScrapeTimedOut) &&
- tr_variantDictFindInt (t, "leecherCount", &leecherCount) &&
- tr_variantDictFindInt (t, "nextAnnounceTime", &nextAnnounceTime) &&
- tr_variantDictFindInt (t, "nextScrapeTime", &nextScrapeTime) &&
- tr_variantDictFindInt (t, "seederCount", &seederCount) &&
- tr_variantDictFindInt (t, "tier", &tier))
+ if (tr_variantDictFindInt (t, TR_KEY_downloadCount, &downloadCount) &&
+ tr_variantDictFindBool (t, TR_KEY_hasAnnounced, &hasAnnounced) &&
+ tr_variantDictFindBool (t, TR_KEY_hasScraped, &hasScraped) &&
+ tr_variantDictFindStr (t, TR_KEY_host, &host, NULL) &&
+ tr_variantDictFindInt (t, TR_KEY_id, &id) &&
+ tr_variantDictFindBool (t, TR_KEY_isBackup, &isBackup) &&
+ tr_variantDictFindInt (t, TR_KEY_announceState, &announceState) &&
+ tr_variantDictFindInt (t, TR_KEY_scrapeState, &scrapeState) &&
+ tr_variantDictFindInt (t, TR_KEY_lastAnnouncePeerCount, &lastAnnouncePeerCount) &&
+ tr_variantDictFindStr (t, TR_KEY_lastAnnounceResult, &lastAnnounceResult, NULL) &&
+ tr_variantDictFindInt (t, TR_KEY_lastAnnounceStartTime, &lastAnnounceStartTime) &&
+ tr_variantDictFindBool (t, TR_KEY_lastAnnounceSucceeded, &lastAnnounceSucceeded) &&
+ tr_variantDictFindInt (t, TR_KEY_lastAnnounceTime, &lastAnnounceTime) &&
+ tr_variantDictFindBool (t, TR_KEY_lastAnnounceTimedOut, &lastAnnounceTimedOut) &&
+ tr_variantDictFindStr (t, TR_KEY_lastScrapeResult, &lastScrapeResult, NULL) &&
+ tr_variantDictFindInt (t, TR_KEY_lastScrapeStartTime, &lastScrapeStartTime) &&
+ tr_variantDictFindBool (t, TR_KEY_lastScrapeSucceeded, &lastScrapeSucceeded) &&
+ tr_variantDictFindInt (t, TR_KEY_lastScrapeTime, &lastScrapeTime) &&
+ tr_variantDictFindBool (t, TR_KEY_lastScrapeTimedOut, &lastScrapeTimedOut) &&
+ tr_variantDictFindInt (t, TR_KEY_leecherCount, &leecherCount) &&
+ tr_variantDictFindInt (t, TR_KEY_nextAnnounceTime, &nextAnnounceTime) &&
+ tr_variantDictFindInt (t, TR_KEY_nextScrapeTime, &nextScrapeTime) &&
+ tr_variantDictFindInt (t, TR_KEY_seederCount, &seederCount) &&
+ tr_variantDictFindInt (t, TR_KEY_tier, &tier))
{
const time_t now = time (NULL);
static void
printTrackers (tr_variant * top)
{
- tr_variant *args, *torrents;
+ tr_variant *args, *torrents;
- if (tr_variantDictFindDict (top, "arguments", &args)
- && tr_variantDictFindList (args, "torrents", &torrents))
+ if (tr_variantDictFindDict (top, TR_KEY_arguments, &args)
+ && tr_variantDictFindList (args, TR_KEY_torrents, &torrents))
{
- int i, n;
- for (i=0, n=tr_variantListSize (torrents); i<n; ++i)
+ int i, n;
+ for (i=0, n=tr_variantListSize (torrents); i<n; ++i)
{
- tr_variant * trackerStats;
- tr_variant * torrent = tr_variantListChild (torrents, i);
- if (tr_variantDictFindList (torrent, "trackerStats", &trackerStats)) {
- printTrackersImpl (trackerStats);
- if (i+1<n)
- printf ("\n");
+ tr_variant * trackerStats;
+ tr_variant * torrent = tr_variantListChild (torrents, i);
+
+ if (tr_variantDictFindList (torrent, TR_KEY_trackerStats, &trackerStats))
+ {
+ printTrackersImpl (trackerStats);
+
+ if (i+1<n)
+ printf ("\n");
}
}
}
static void
printSession (tr_variant * top)
{
- tr_variant *args;
- if ((tr_variantDictFindDict (top, "arguments", &args)))
+ tr_variant *args;
+ if ((tr_variantDictFindDict (top, TR_KEY_arguments, &args)))
{
- int64_t i;
- char buf[64];
- bool boolVal;
- const char * str;
-
- printf ("VERSION\n");
- if (tr_variantDictFindStr (args, "version", &str, NULL))
- printf (" Daemon version: %s\n", str);
- if (tr_variantDictFindInt (args, "rpc-version", &i))
- printf (" RPC version: %" PRId64 "\n", i);
- if (tr_variantDictFindInt (args, "rpc-version-minimum", &i))
- printf (" RPC minimum version: %" PRId64 "\n", i);
- printf ("\n");
-
- printf ("CONFIG\n");
- if (tr_variantDictFindStr (args, "config-dir", &str, NULL))
- printf (" Configuration directory: %s\n", str);
- if (tr_variantDictFindStr (args, TR_PREFS_KEY_DOWNLOAD_DIR, &str, NULL))
- printf (" Download directory: %s\n", str);
- if (tr_variantDictFindInt (args, "download-dir-free-space", &i))
- printf (" Download directory free space: %s\n", strlsize (buf, i, sizeof buf));
- if (tr_variantDictFindInt (args, TR_PREFS_KEY_PEER_PORT, &i))
- printf (" Listenport: %" PRId64 "\n", i);
- if (tr_variantDictFindBool (args, TR_PREFS_KEY_PORT_FORWARDING, &boolVal))
- printf (" Portforwarding enabled: %s\n", (boolVal ? "Yes" : "No"));
- if (tr_variantDictFindBool (args, TR_PREFS_KEY_UTP_ENABLED, &boolVal))
- printf (" uTP enabled: %s\n", (boolVal ? "Yes" : "No"));
- if (tr_variantDictFindBool (args, TR_PREFS_KEY_DHT_ENABLED, &boolVal))
- printf (" Distributed hash table enabled: %s\n", (boolVal ? "Yes" : "No"));
- if (tr_variantDictFindBool (args, TR_PREFS_KEY_LPD_ENABLED, &boolVal))
- printf (" Local peer discovery enabled: %s\n", (boolVal ? "Yes" : "No"));
- if (tr_variantDictFindBool (args, TR_PREFS_KEY_PEX_ENABLED, &boolVal))
- printf (" Peer exchange allowed: %s\n", (boolVal ? "Yes" : "No"));
- if (tr_variantDictFindStr (args, TR_PREFS_KEY_ENCRYPTION, &str, NULL))
- printf (" Encryption: %s\n", str);
- if (tr_variantDictFindInt (args, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, &i))
- printf (" Maximum memory cache size: %s\n", tr_formatter_mem_MB (buf, i, sizeof (buf)));
- printf ("\n");
+ int64_t i;
+ char buf[64];
+ bool boolVal;
+ const char * str;
+
+ printf ("VERSION\n");
+ if (tr_variantDictFindStr (args, TR_KEY_version, &str, NULL))
+ printf (" Daemon version: %s\n", str);
+ if (tr_variantDictFindInt (args, TR_KEY_rpc_version, &i))
+ printf (" RPC version: %" PRId64 "\n", i);
+ if (tr_variantDictFindInt (args, TR_KEY_rpc_version_minimum, &i))
+ printf (" RPC minimum version: %" PRId64 "\n", i);
+ printf ("\n");
+
+ printf ("CONFIG\n");
+ if (tr_variantDictFindStr (args, TR_KEY_config_dir, &str, NULL))
+ printf (" Configuration directory: %s\n", str);
+ if (tr_variantDictFindStr (args, TR_KEY_download_dir, &str, NULL))
+ printf (" Download directory: %s\n", str);
+ if (tr_variantDictFindInt (args, TR_KEY_download_dir_free_space, &i))
+ printf (" Download directory free space: %s\n", strlsize (buf, i, sizeof buf));
+ if (tr_variantDictFindInt (args, TR_KEY_peer_port, &i))
+ printf (" Listenport: %" PRId64 "\n", i);
+ if (tr_variantDictFindBool (args, TR_KEY_port_forwarding_enabled, &boolVal))
+ printf (" Portforwarding enabled: %s\n", (boolVal ? "Yes" : "No"));
+ if (tr_variantDictFindBool (args, TR_KEY_utp_enabled, &boolVal))
+ printf (" uTP enabled: %s\n", (boolVal ? "Yes" : "No"));
+ if (tr_variantDictFindBool (args, TR_KEY_dht_enabled, &boolVal))
+ printf (" Distributed hash table enabled: %s\n", (boolVal ? "Yes" : "No"));
+ if (tr_variantDictFindBool (args, TR_KEY_lpd_enabled, &boolVal))
+ printf (" Local peer discovery enabled: %s\n", (boolVal ? "Yes" : "No"));
+ if (tr_variantDictFindBool (args, TR_KEY_pex_enabled, &boolVal))
+ printf (" Peer exchange allowed: %s\n", (boolVal ? "Yes" : "No"));
+ if (tr_variantDictFindStr (args, TR_KEY_encryption, &str, NULL))
+ printf (" Encryption: %s\n", str);
+ if (tr_variantDictFindInt (args, TR_KEY_cache_size_mb, &i))
+ printf (" Maximum memory cache size: %s\n", tr_formatter_mem_MB (buf, i, sizeof (buf)));
+ printf ("\n");
{
bool altEnabled, altTimeEnabled, upEnabled, downEnabled, seedRatioLimited;
int64_t altDown, altUp, altBegin, altEnd, altDay, upLimit, downLimit, peerLimit;
double seedRatioLimit;
- if (tr_variantDictFindInt (args, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, &altDown) &&
- tr_variantDictFindBool (args, TR_PREFS_KEY_ALT_SPEED_ENABLED, &altEnabled) &&
- tr_variantDictFindInt (args, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &altBegin) &&
- tr_variantDictFindBool (args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &altTimeEnabled) &&
- tr_variantDictFindInt (args, TR_PREFS_KEY_ALT_SPEED_TIME_END, &altEnd) &&
- tr_variantDictFindInt (args, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, &altDay) &&
- tr_variantDictFindInt (args, TR_PREFS_KEY_ALT_SPEED_UP_KBps, &altUp) &&
- tr_variantDictFindInt (args, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &peerLimit) &&
- tr_variantDictFindInt (args, TR_PREFS_KEY_DSPEED_KBps, &downLimit) &&
- tr_variantDictFindBool (args, TR_PREFS_KEY_DSPEED_ENABLED, &downEnabled) &&
- tr_variantDictFindInt (args, TR_PREFS_KEY_USPEED_KBps, &upLimit) &&
- tr_variantDictFindBool (args, TR_PREFS_KEY_USPEED_ENABLED, &upEnabled) &&
- tr_variantDictFindReal (args, "seedRatioLimit", &seedRatioLimit) &&
- tr_variantDictFindBool (args, "seedRatioLimited", &seedRatioLimited))
+ if (tr_variantDictFindInt (args, TR_KEY_alt_speed_down, &altDown) &&
+ tr_variantDictFindBool (args, TR_KEY_alt_speed_enabled, &altEnabled) &&
+ tr_variantDictFindInt (args, TR_KEY_alt_speed_time_begin, &altBegin) &&
+ tr_variantDictFindBool (args, TR_KEY_alt_speed_time_enabled, &altTimeEnabled) &&
+ tr_variantDictFindInt (args, TR_KEY_alt_speed_time_end, &altEnd) &&
+ tr_variantDictFindInt (args, TR_KEY_alt_speed_time_day, &altDay) &&
+ tr_variantDictFindInt (args, TR_KEY_alt_speed_up, &altUp) &&
+ tr_variantDictFindInt (args, TR_KEY_peer_limit_global, &peerLimit) &&
+ tr_variantDictFindInt (args, TR_KEY_speed_limit_down, &downLimit) &&
+ tr_variantDictFindBool (args, TR_KEY_speed_limit_down_enabled, &downEnabled) &&
+ tr_variantDictFindInt (args, TR_KEY_speed_limit_up, &upLimit) &&
+ tr_variantDictFindBool (args, TR_KEY_speed_limit_up_enabled, &upEnabled) &&
+ tr_variantDictFindReal (args, TR_KEY_seedRatioLimit, &seedRatioLimit) &&
+ tr_variantDictFindBool (args, TR_KEY_seedRatioLimited, &seedRatioLimited))
{
char buf[128];
char buf2[128];
printf ("\n");
printf ("MISC\n");
- if (tr_variantDictFindBool (args, TR_PREFS_KEY_START, &boolVal))
+ if (tr_variantDictFindBool (args, TR_KEY_start_added_torrents, &boolVal))
printf (" Autostart added torrents: %s\n", (boolVal ? "Yes" : "No"));
- if (tr_variantDictFindBool (args, TR_PREFS_KEY_TRASH_ORIGINAL, &boolVal))
+ if (tr_variantDictFindBool (args, TR_KEY_trash_original_torrent_files, &boolVal))
printf (" Delete automatically added torrents: %s\n", (boolVal ? "Yes" : "No"));
}
}
static void
printSessionStats (tr_variant * top)
{
- tr_variant *args, *d;
- if ((tr_variantDictFindDict (top, "arguments", &args)))
+ tr_variant *args, *d;
+ if ((tr_variantDictFindDict (top, TR_KEY_arguments, &args)))
{
- char buf[512];
- int64_t up, down, secs, sessions;
+ char buf[512];
+ int64_t up, down, secs, sessions;
- if (tr_variantDictFindDict (args, "current-stats", &d)
- && tr_variantDictFindInt (d, "uploadedBytes", &up)
- && tr_variantDictFindInt (d, "downloadedBytes", &down)
- && tr_variantDictFindInt (d, "secondsActive", &secs))
+ if (tr_variantDictFindDict (args, TR_KEY_current_stats, &d)
+ && tr_variantDictFindInt (d, TR_KEY_uploadedBytes, &up)
+ && tr_variantDictFindInt (d, TR_KEY_downloadedBytes, &down)
+ && tr_variantDictFindInt (d, TR_KEY_secondsActive, &secs))
{
- printf ("\nCURRENT SESSION\n");
- printf (" Uploaded: %s\n", strlsize (buf, up, sizeof (buf)));
- printf (" Downloaded: %s\n", strlsize (buf, down, sizeof (buf)));
- printf (" Ratio: %s\n", strlratio (buf, up, down, sizeof (buf)));
- printf (" Duration: %s\n", tr_strltime (buf, secs, sizeof (buf)));
+ printf ("\nCURRENT SESSION\n");
+ printf (" Uploaded: %s\n", strlsize (buf, up, sizeof (buf)));
+ printf (" Downloaded: %s\n", strlsize (buf, down, sizeof (buf)));
+ printf (" Ratio: %s\n", strlratio (buf, up, down, sizeof (buf)));
+ printf (" Duration: %s\n", tr_strltime (buf, secs, sizeof (buf)));
}
- if (tr_variantDictFindDict (args, "cumulative-stats", &d)
- && tr_variantDictFindInt (d, "sessionCount", &sessions)
- && tr_variantDictFindInt (d, "uploadedBytes", &up)
- && tr_variantDictFindInt (d, "downloadedBytes", &down)
- && tr_variantDictFindInt (d, "secondsActive", &secs))
+ if (tr_variantDictFindDict (args, TR_KEY_cumulative_stats, &d)
+ && tr_variantDictFindInt (d, TR_KEY_sessionCount, &sessions)
+ && tr_variantDictFindInt (d, TR_KEY_uploadedBytes, &up)
+ && tr_variantDictFindInt (d, TR_KEY_downloadedBytes, &down)
+ && tr_variantDictFindInt (d, TR_KEY_secondsActive, &secs))
{
- printf ("\nTOTAL\n");
- printf (" Started %lu times\n", (unsigned long)sessions);
- printf (" Uploaded: %s\n", strlsize (buf, up, sizeof (buf)));
- printf (" Downloaded: %s\n", strlsize (buf, down, sizeof (buf)));
- printf (" Ratio: %s\n", strlratio (buf, up, down, sizeof (buf)));
- printf (" Duration: %s\n", tr_strltime (buf, secs, sizeof (buf)));
+ printf ("\nTOTAL\n");
+ printf (" Started %lu times\n", (unsigned long)sessions);
+ printf (" Uploaded: %s\n", strlsize (buf, up, sizeof (buf)));
+ printf (" Downloaded: %s\n", strlsize (buf, down, sizeof (buf)));
+ printf (" Ratio: %s\n", strlratio (buf, up, down, sizeof (buf)));
+ printf (" Duration: %s\n", tr_strltime (buf, secs, sizeof (buf)));
}
}
}
int64_t tag = -1;
const char * str;
- if (tr_variantDictFindStr (&top, "result", &str, NULL))
+ if (tr_variantDictFindStr (&top, TR_KEY_result, &str, NULL))
{
if (strcmp (str, "success"))
{
}
else
{
- tr_variantDictFindInt (&top, "tag", &tag);
+ tr_variantDictFindInt (&top, TR_KEY_tag, &tag);
switch (tag)
{
int64_t i;
tr_variant * b = ⊤
if (tr_variantDictFindDict (&top, ARGUMENTS, &b)
- && tr_variantDictFindDict (b, "torrent-added", &b)
- && tr_variantDictFindInt (b, "id", &i))
+ && tr_variantDictFindDict (b, TR_KEY_torrent_added, &b)
+ && tr_variantDictFindInt (b, TR_KEY_id, &i))
tr_snprintf (id, sizeof (id), "%"PRId64, i);
/* fall-through to default: to give success or failure msg */
}
default:
- if (!tr_variantDictFindStr (&top, "result", &str, NULL))
+ if (!tr_variantDictFindStr (&top, TR_KEY_result, &str, NULL))
status |= EXIT_FAILURE;
else {
printf ("%s responded: \"%s\"\n", rpcurl, str);
else {
*sset = tr_new0 (tr_variant, 1);
tr_variantInitDict (*sset, 3);
- tr_variantDictAddStr (*sset, "method", "session-set");
+ tr_variantDictAddStr (*sset, TR_KEY_method, "session-set");
args = tr_variantDictAddDict (*sset, ARGUMENTS, 0);
}
else {
*tset = tr_new0 (tr_variant, 1);
tr_variantInitDict (*tset, 3);
- tr_variantDictAddStr (*tset, "method", "torrent-set");
+ tr_variantDictAddStr (*tset, TR_KEY_method, "torrent-set");
args = tr_variantDictAddDict (*tset, ARGUMENTS, 1);
}
if (tset != 0) { addIdArg (tr_variantDictFind (tset, ARGUMENTS), id); status |= flush (rpcurl, &tset); }
tadd = tr_new0 (tr_variant, 1);
tr_variantInitDict (tadd, 3);
- tr_variantDictAddStr (tadd, "method", "torrent-add");
- tr_variantDictAddInt (tadd, "tag", TAG_TORRENT_ADD);
+ tr_variantDictAddStr (tadd, TR_KEY_method, "torrent-add");
+ tr_variantDictAddInt (tadd, TR_KEY_tag, TAG_TORRENT_ADD);
tr_variantDictAddDict (tadd, ARGUMENTS, 0);
break;
tr_variant * args = tr_variantDictFind (tadd, ARGUMENTS);
char * tmp = getEncodedMetainfo (optarg);
if (tmp)
- tr_variantDictAddStr (args, "metainfo", tmp);
+ tr_variantDictAddStr (args, TR_KEY_metainfo, tmp);
else
- tr_variantDictAddStr (args, "filename", optarg);
+ tr_variantDictAddStr (args, TR_KEY_filename, optarg);
tr_free (tmp);
} else {
fprintf (stderr, "Unknown option: %s\n", optarg);
tr_variant * args;
tr_variant * fields;
tr_variantInitDict (top, 3);
- tr_variantDictAddStr (top, "method", "torrent-get");
+ tr_variantDictAddStr (top, TR_KEY_method, "torrent-get");
args = tr_variantDictAddDict (top, ARGUMENTS, 0);
- fields = tr_variantDictAddList (args, "fields", 0);
+ fields = tr_variantDictAddList (args, TR_KEY_fields, 0);
if (tset != 0) { addIdArg (tr_variantDictFind (tset, ARGUMENTS), id); status |= flush (rpcurl, &tset); }
switch (c)
{
- case 'i': tr_variantDictAddInt (top, "tag", TAG_DETAILS);
+ case 'i': tr_variantDictAddInt (top, TR_KEY_tag, TAG_DETAILS);
n = TR_N_ELEMENTS (details_keys);
- for (i=0; i<n; ++i) tr_variantListAddStr (fields, details_keys[i]);
+ for (i=0; i<n; ++i) tr_variantListAddQuark (fields, details_keys[i]);
addIdArg (args, id);
break;
- case 'l': tr_variantDictAddInt (top, "tag", TAG_LIST);
+ case 'l': tr_variantDictAddInt (top, TR_KEY_tag, TAG_LIST);
n = TR_N_ELEMENTS (list_keys);
- for (i=0; i<n; ++i) tr_variantListAddStr (fields, list_keys[i]);
+ for (i=0; i<n; ++i) tr_variantListAddQuark (fields, list_keys[i]);
break;
- case 940: tr_variantDictAddInt (top, "tag", TAG_FILES);
+ case 940: tr_variantDictAddInt (top, TR_KEY_tag, TAG_FILES);
n = TR_N_ELEMENTS (files_keys);
- for (i=0; i<n; ++i) tr_variantListAddStr (fields, files_keys[i]);
+ for (i=0; i<n; ++i) tr_variantListAddQuark (fields, files_keys[i]);
addIdArg (args, id);
break;
- case 941: tr_variantDictAddInt (top, "tag", TAG_PEERS);
+ case 941: tr_variantDictAddInt (top, TR_KEY_tag, TAG_PEERS);
tr_variantListAddStr (fields, "peers");
addIdArg (args, id);
break;
- case 942: tr_variantDictAddInt (top, "tag", TAG_PIECES);
+ case 942: tr_variantDictAddInt (top, TR_KEY_tag, TAG_PIECES);
tr_variantListAddStr (fields, "pieces");
tr_variantListAddStr (fields, "pieceCount");
addIdArg (args, id);
break;
- case 943: tr_variantDictAddInt (top, "tag", TAG_TRACKERS);
+ case 943: tr_variantDictAddInt (top, TR_KEY_tag, TAG_TRACKERS);
tr_variantListAddStr (fields, "trackerStats");
addIdArg (args, id);
break;
switch (c)
{
- case 800: tr_variantDictAddStr (args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, optarg);
- tr_variantDictAddBool (args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, true);
+ case 800: tr_variantDictAddStr (args, TR_KEY_script_torrent_done_filename, optarg);
+ tr_variantDictAddBool (args, TR_KEY_script_torrent_done_enabled, true);
break;
- case 801: tr_variantDictAddBool (args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, false);
+ case 801: tr_variantDictAddBool (args, TR_KEY_script_torrent_done_enabled, false);
break;
- case 970: tr_variantDictAddBool (args, TR_PREFS_KEY_ALT_SPEED_ENABLED, true);
+ case 970: tr_variantDictAddBool (args, TR_KEY_alt_speed_enabled, true);
break;
- case 971: tr_variantDictAddBool (args, TR_PREFS_KEY_ALT_SPEED_ENABLED, false);
+ case 971: tr_variantDictAddBool (args, TR_KEY_alt_speed_enabled, false);
break;
- case 972: tr_variantDictAddInt (args, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, numarg (optarg));
+ case 972: tr_variantDictAddInt (args, TR_KEY_alt_speed_down, numarg (optarg));
break;
- case 973: tr_variantDictAddInt (args, TR_PREFS_KEY_ALT_SPEED_UP_KBps, numarg (optarg));
+ case 973: tr_variantDictAddInt (args, TR_KEY_alt_speed_up, numarg (optarg));
break;
- case 974: tr_variantDictAddBool (args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, true);
+ case 974: tr_variantDictAddBool (args, TR_KEY_alt_speed_time_enabled, true);
break;
- case 975: tr_variantDictAddBool (args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, false);
+ case 975: tr_variantDictAddBool (args, TR_KEY_alt_speed_time_enabled, false);
break;
- case 976: addTime (args, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, optarg);
+ case 976: addTime (args, TR_KEY_alt_speed_time_begin, optarg);
break;
- case 977: addTime (args, TR_PREFS_KEY_ALT_SPEED_TIME_END, optarg);
+ case 977: addTime (args, TR_KEY_alt_speed_time_end, optarg);
break;
- case 978: addDays (args, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, optarg);
+ case 978: addDays (args, TR_KEY_alt_speed_time_day, optarg);
break;
- case 'c': tr_variantDictAddStr (args, TR_PREFS_KEY_INCOMPLETE_DIR, optarg);
- tr_variantDictAddBool (args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, true);
+ case 'c': tr_variantDictAddStr (args, TR_KEY_incomplete_dir, optarg);
+ tr_variantDictAddBool (args, TR_KEY_incomplete_dir_enabled, true);
break;
- case 'C': tr_variantDictAddBool (args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, false);
+ case 'C': tr_variantDictAddBool (args, TR_KEY_incomplete_dir_enabled, false);
break;
- case 'e': tr_variantDictAddInt (args, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, atoi (optarg));
+ case 'e': tr_variantDictAddInt (args, TR_KEY_cache_size_mb, atoi (optarg));
break;
- case 910: tr_variantDictAddStr (args, TR_PREFS_KEY_ENCRYPTION, "required");
+ case 910: tr_variantDictAddStr (args, TR_KEY_encryption, "required");
break;
- case 911: tr_variantDictAddStr (args, TR_PREFS_KEY_ENCRYPTION, "preferred");
+ case 911: tr_variantDictAddStr (args, TR_KEY_encryption, "preferred");
break;
- case 912: tr_variantDictAddStr (args, TR_PREFS_KEY_ENCRYPTION, "tolerated");
+ case 912: tr_variantDictAddStr (args, TR_KEY_encryption, "tolerated");
break;
- case 'm': tr_variantDictAddBool (args, TR_PREFS_KEY_PORT_FORWARDING, true);
+ case 'm': tr_variantDictAddBool (args, TR_KEY_port_forwarding_enabled, true);
break;
- case 'M': tr_variantDictAddBool (args, TR_PREFS_KEY_PORT_FORWARDING, false);
+ case 'M': tr_variantDictAddBool (args, TR_KEY_port_forwarding_enabled, false);
break;
- case 'o': tr_variantDictAddBool (args, TR_PREFS_KEY_DHT_ENABLED, true);
+ case 'o': tr_variantDictAddBool (args, TR_KEY_dht_enabled, true);
break;
- case 'O': tr_variantDictAddBool (args, TR_PREFS_KEY_DHT_ENABLED, false);
+ case 'O': tr_variantDictAddBool (args, TR_KEY_dht_enabled, false);
break;
- case 830: tr_variantDictAddBool (args, TR_PREFS_KEY_UTP_ENABLED, true);
+ case 830: tr_variantDictAddBool (args, TR_KEY_utp_enabled, true);
break;
- case 831: tr_variantDictAddBool (args, TR_PREFS_KEY_UTP_ENABLED, false);
+ case 831: tr_variantDictAddBool (args, TR_KEY_utp_enabled, false);
break;
- case 'p': tr_variantDictAddInt (args, TR_PREFS_KEY_PEER_PORT, numarg (optarg));
+ case 'p': tr_variantDictAddInt (args, TR_KEY_peer_port, numarg (optarg));
break;
- case 'P': tr_variantDictAddBool (args, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, true);
+ case 'P': tr_variantDictAddBool (args, TR_KEY_peer_port_random_on_start, true);
break;
- case 'x': tr_variantDictAddBool (args, TR_PREFS_KEY_PEX_ENABLED, true);
+ case 'x': tr_variantDictAddBool (args, TR_KEY_pex_enabled, true);
break;
- case 'X': tr_variantDictAddBool (args, TR_PREFS_KEY_PEX_ENABLED, false);
+ case 'X': tr_variantDictAddBool (args, TR_KEY_pex_enabled, false);
break;
- case 'y': tr_variantDictAddBool (args, TR_PREFS_KEY_LPD_ENABLED, true);
+ case 'y': tr_variantDictAddBool (args, TR_KEY_lpd_enabled, true);
break;
- case 'Y': tr_variantDictAddBool (args, TR_PREFS_KEY_LPD_ENABLED, false);
+ case 'Y': tr_variantDictAddBool (args, TR_KEY_lpd_enabled, false);
break;
- case 953: tr_variantDictAddReal (args, "seedRatioLimit", atof (optarg));
- tr_variantDictAddBool (args, "seedRatioLimited", true);
+ case 953: tr_variantDictAddReal (args, TR_KEY_seedRatioLimit, atof (optarg));
+ tr_variantDictAddBool (args, TR_KEY_seedRatioLimited, true);
break;
- case 954: tr_variantDictAddBool (args, "seedRatioLimited", false);
+ case 954: tr_variantDictAddBool (args, TR_KEY_seedRatioLimited, false);
break;
- case 990: tr_variantDictAddBool (args, TR_PREFS_KEY_START, false);
+ case 990: tr_variantDictAddBool (args, TR_KEY_start_added_torrents, false);
break;
- case 991: tr_variantDictAddBool (args, TR_PREFS_KEY_START, true);
+ case 991: tr_variantDictAddBool (args, TR_KEY_start_added_torrents, true);
break;
- case 992: tr_variantDictAddBool (args, TR_PREFS_KEY_TRASH_ORIGINAL, true);
+ case 992: tr_variantDictAddBool (args, TR_KEY_trash_original_torrent_files, true);
break;
- case 993: tr_variantDictAddBool (args, TR_PREFS_KEY_TRASH_ORIGINAL, false);
+ case 993: tr_variantDictAddBool (args, TR_KEY_trash_original_torrent_files, false);
break;
default: assert ("unhandled value" && 0);
break;
switch (c)
{
case 'd': if (targs) {
- tr_variantDictAddInt (targs, "downloadLimit", numarg (optarg));
- tr_variantDictAddBool (targs, "downloadLimited", true);
+ tr_variantDictAddInt (targs, TR_KEY_downloadLimit, numarg (optarg));
+ tr_variantDictAddBool (targs, TR_KEY_downloadLimited, true);
} else {
- tr_variantDictAddInt (sargs, TR_PREFS_KEY_DSPEED_KBps, numarg (optarg));
- tr_variantDictAddBool (sargs, TR_PREFS_KEY_DSPEED_ENABLED, true);
+ tr_variantDictAddInt (sargs, TR_KEY_speed_limit_down, numarg (optarg));
+ tr_variantDictAddBool (sargs, TR_KEY_speed_limit_down_enabled, true);
}
break;
case 'D': if (targs)
- tr_variantDictAddBool (targs, "downloadLimited", false);
+ tr_variantDictAddBool (targs, TR_KEY_downloadLimited, false);
else
- tr_variantDictAddBool (sargs, TR_PREFS_KEY_DSPEED_ENABLED, false);
+ tr_variantDictAddBool (sargs, TR_KEY_speed_limit_down_enabled, false);
break;
case 'u': if (targs) {
- tr_variantDictAddInt (targs, "uploadLimit", numarg (optarg));
- tr_variantDictAddBool (targs, "uploadLimited", true);
+ tr_variantDictAddInt (targs, TR_KEY_uploadLimit, numarg (optarg));
+ tr_variantDictAddBool (targs, TR_KEY_uploadLimited, true);
} else {
- tr_variantDictAddInt (sargs, TR_PREFS_KEY_USPEED_KBps, numarg (optarg));
- tr_variantDictAddBool (sargs, TR_PREFS_KEY_USPEED_ENABLED, true);
+ tr_variantDictAddInt (sargs, TR_KEY_speed_limit_up, numarg (optarg));
+ tr_variantDictAddBool (sargs, TR_KEY_speed_limit_up_enabled, true);
}
break;
case 'U': if (targs)
- tr_variantDictAddBool (targs, "uploadLimited", false);
+ tr_variantDictAddBool (targs, TR_KEY_uploadLimited, false);
else
- tr_variantDictAddBool (sargs, TR_PREFS_KEY_USPEED_ENABLED, false);
+ tr_variantDictAddBool (sargs, TR_KEY_speed_limit_up_enabled, false);
break;
case 930: if (targs)
- tr_variantDictAddInt (targs, "peer-limit", atoi (optarg));
+ tr_variantDictAddInt (targs, TR_KEY_peer_limit, atoi (optarg));
else
- tr_variantDictAddInt (sargs, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, atoi (optarg));
+ tr_variantDictAddInt (sargs, TR_KEY_peer_limit_global, atoi (optarg));
break;
default: assert ("unhandled value" && 0);
break;
switch (c)
{
- case 712: tr_variantListAddInt (tr_variantDictAddList (args, "trackerRemove", 1), atoi (optarg));
+ case 712: tr_variantListAddInt (tr_variantDictAddList (args, TR_KEY_trackerRemove, 1), atoi (optarg));
break;
- case 950: tr_variantDictAddReal (args, "seedRatioLimit", atof (optarg));
- tr_variantDictAddInt (args, "seedRatioMode", TR_RATIOLIMIT_SINGLE);
+ case 950: tr_variantDictAddReal (args, TR_KEY_seedRatioLimit, atof (optarg));
+ tr_variantDictAddInt (args, TR_KEY_seedRatioMode, TR_RATIOLIMIT_SINGLE);
break;
- case 951: tr_variantDictAddInt (args, "seedRatioMode", TR_RATIOLIMIT_GLOBAL);
+ case 951: tr_variantDictAddInt (args, TR_KEY_seedRatioMode, TR_RATIOLIMIT_GLOBAL);
break;
- case 952: tr_variantDictAddInt (args, "seedRatioMode", TR_RATIOLIMIT_UNLIMITED);
+ case 952: tr_variantDictAddInt (args, TR_KEY_seedRatioMode, TR_RATIOLIMIT_UNLIMITED);
break;
- case 984: tr_variantDictAddBool (args, "honorsSessionLimits", true);
+ case 984: tr_variantDictAddBool (args, TR_KEY_honorsSessionLimits, true);
break;
- case 985: tr_variantDictAddBool (args, "honorsSessionLimits", false);
+ case 985: tr_variantDictAddBool (args, TR_KEY_honorsSessionLimits, false);
break;
default: assert ("unhandled value" && 0);
break;
switch (c)
{
- case 'g': addFiles (args, "files-wanted", optarg);
+ case 'g': addFiles (args, TR_KEY_files_wanted, optarg);
break;
- case 'G': addFiles (args, "files-unwanted", optarg);
+ case 'G': addFiles (args, TR_KEY_files_unwanted, optarg);
break;
- case 900: addFiles (args, "priority-high", optarg);
+ case 900: addFiles (args, TR_KEY_priority_high, optarg);
break;
- case 901: addFiles (args, "priority-normal", optarg);
+ case 901: addFiles (args, TR_KEY_priority_normal, optarg);
break;
- case 902: addFiles (args, "priority-low", optarg);
+ case 902: addFiles (args, TR_KEY_priority_low, optarg);
break;
- case 700: tr_variantDictAddInt (args, "bandwidthPriority", 1);
+ case 700: tr_variantDictAddInt (args, TR_KEY_bandwidthPriority, 1);
break;
- case 701: tr_variantDictAddInt (args, "bandwidthPriority", 0);
+ case 701: tr_variantDictAddInt (args, TR_KEY_bandwidthPriority, 0);
break;
- case 702: tr_variantDictAddInt (args, "bandwidthPriority", -1);
+ case 702: tr_variantDictAddInt (args, TR_KEY_bandwidthPriority, -1);
break;
- case 710: tr_variantListAddStr (tr_variantDictAddList (args, "trackerAdd", 1), optarg);
+ case 710: tr_variantListAddStr (tr_variantDictAddList (args, TR_KEY_trackerAdd, 1), optarg);
break;
default: assert ("unhandled value" && 0);
break;
if (tadd)
{
tr_variant * args = tr_variantDictFind (tadd, ARGUMENTS);
- tr_variantDictAddStr (args, "download-dir", optarg);
+ tr_variantDictAddStr (args, TR_KEY_download_dir, optarg);
}
else
{
tr_variant * args;
tr_variant * top = tr_new0 (tr_variant, 1);
tr_variantInitDict (top, 2);
- tr_variantDictAddStr (top, "method", "torrent-set-location");
+ tr_variantDictAddStr (top, TR_KEY_method, "torrent-set-location");
args = tr_variantDictAddDict (top, ARGUMENTS, 3);
- tr_variantDictAddStr (args, "location", optarg);
- tr_variantDictAddBool (args, "move", false);
+ tr_variantDictAddStr (args, TR_KEY_location, optarg);
+ tr_variantDictAddBool (args, TR_KEY_move, false);
addIdArg (args, id);
status |= flush (rpcurl, &top);
break;
{
tr_variant * top = tr_new0 (tr_variant, 1);
tr_variantInitDict (top, 2);
- tr_variantDictAddStr (top, "method", "session-get");
- tr_variantDictAddInt (top, "tag", TAG_SESSION);
+ tr_variantDictAddStr (top, TR_KEY_method, "session-get");
+ tr_variantDictAddInt (top, TR_KEY_tag, TAG_SESSION);
status |= flush (rpcurl, &top);
break;
}
case 's': /* start */
{
if (tadd)
- tr_variantDictAddBool (tr_variantDictFind (tadd, "arguments"), "paused", false);
+ tr_variantDictAddBool (tr_variantDictFind (tadd, TR_KEY_arguments), TR_KEY_paused, false);
else {
tr_variant * top = tr_new0 (tr_variant, 1);
tr_variantInitDict (top, 2);
- tr_variantDictAddStr (top, "method", "torrent-start");
+ tr_variantDictAddStr (top, TR_KEY_method, "torrent-start");
addIdArg (tr_variantDictAddDict (top, ARGUMENTS, 1), id);
status |= flush (rpcurl, &top);
}
case 'S': /* stop */
{
if (tadd)
- tr_variantDictAddBool (tr_variantDictFind (tadd, "arguments"), "paused", true);
+ tr_variantDictAddBool (tr_variantDictFind (tadd, TR_KEY_arguments), TR_KEY_paused, true);
else {
tr_variant * top = tr_new0 (tr_variant, 1);
tr_variantInitDict (top, 2);
- tr_variantDictAddStr (top, "method", "torrent-stop");
+ tr_variantDictAddStr (top, TR_KEY_method, "torrent-stop");
addIdArg (tr_variantDictAddDict (top, ARGUMENTS, 1), id);
status |= flush (rpcurl, &top);
}
{
char * path = absolutify (optarg);
if (tadd)
- tr_variantDictAddStr (tr_variantDictFind (tadd, "arguments"), "download-dir", path);
+ tr_variantDictAddStr (tr_variantDictFind (tadd, TR_KEY_arguments), TR_KEY_download_dir, path);
else {
tr_variant * args = ensure_sset (&sset);
- tr_variantDictAddStr (args, "download-dir", path);
+ tr_variantDictAddStr (args, TR_KEY_download_dir, path);
}
tr_free (path);
break;
{
tr_variant * top = tr_new0 (tr_variant, 1);
tr_variantInitDict (top, 1);
- tr_variantDictAddStr (top, "method", "session-close");
+ tr_variantDictAddStr (top, TR_KEY_method, "session-close");
status |= flush (rpcurl, &top);
break;
}
{
tr_variant * top = tr_new0 (tr_variant, 1);
tr_variantInitDict (top, 1);
- tr_variantDictAddStr (top, "method", "blocklist-update");
+ tr_variantDictAddStr (top, TR_KEY_method, "blocklist-update");
status |= flush (rpcurl, &top);
break;
}
{
tr_variant * top = tr_new0 (tr_variant, 1);
tr_variantInitDict (top, 2);
- tr_variantDictAddStr (top, "method", "session-stats");
- tr_variantDictAddInt (top, "tag", TAG_STATS);
+ tr_variantDictAddStr (top, TR_KEY_method, "session-stats");
+ tr_variantDictAddInt (top, TR_KEY_tag, TAG_STATS);
status |= flush (rpcurl, &top);
break;
}
{
tr_variant * top = tr_new0 (tr_variant, 1);
tr_variantInitDict (top, 2);
- tr_variantDictAddStr (top, "method", "port-test");
- tr_variantDictAddInt (top, "tag", TAG_PORTTEST);
+ tr_variantDictAddStr (top, TR_KEY_method, "port-test");
+ tr_variantDictAddInt (top, TR_KEY_tag, TAG_PORTTEST);
status |= flush (rpcurl, &top);
break;
}
if (tset != 0) { addIdArg (tr_variantDictFind (tset, ARGUMENTS), id); status |= flush (rpcurl, &tset); }
top = tr_new0 (tr_variant, 1);
tr_variantInitDict (top, 2);
- tr_variantDictAddStr (top, "method", "torrent-reannounce");
+ tr_variantDictAddStr (top, TR_KEY_method, "torrent-reannounce");
addIdArg (tr_variantDictAddDict (top, ARGUMENTS, 1), id);
status |= flush (rpcurl, &top);
break;
if (tset != 0) { addIdArg (tr_variantDictFind (tset, ARGUMENTS), id); status |= flush (rpcurl, &tset); }
top = tr_new0 (tr_variant, 1);
tr_variantInitDict (top, 2);
- tr_variantDictAddStr (top, "method", "torrent-verify");
+ tr_variantDictAddStr (top, TR_KEY_method, "torrent-verify");
addIdArg (tr_variantDictAddDict (top, ARGUMENTS, 1), id);
status |= flush (rpcurl, &top);
break;
tr_variant * args;
tr_variant * top = tr_new0 (tr_variant, 1);
tr_variantInitDict (top, 2);
- tr_variantDictAddStr (top, "method", "torrent-remove");
+ tr_variantDictAddStr (top, TR_KEY_method, "torrent-remove");
args = tr_variantDictAddDict (top, ARGUMENTS, 2);
- tr_variantDictAddBool (args, "delete-local-data", c=='R');
+ tr_variantDictAddBool (args, TR_KEY_delete_local_data, c=='R');
addIdArg (args, id);
status |= flush (rpcurl, &top);
break;
tr_variant * args;
tr_variant * top = tr_new0 (tr_variant, 1);
tr_variantInitDict (top, 2);
- tr_variantDictAddStr (top, "method", "torrent-set-location");
+ tr_variantDictAddStr (top, TR_KEY_method, "torrent-set-location");
args = tr_variantDictAddDict (top, ARGUMENTS, 3);
- tr_variantDictAddStr (args, "location", optarg);
- tr_variantDictAddBool (args, "move", true);
+ tr_variantDictAddStr (args, TR_KEY_location, optarg);
+ tr_variantDictAddBool (args, TR_KEY_move, true);
addIdArg (args, id);
status |= flush (rpcurl, &top);
break;
static void
sort_changed_cb (GtkAction * action UNUSED,
- GtkRadioAction * current,
- gpointer user_data UNUSED)
+ GtkRadioAction * current,
+ gpointer user_data UNUSED)
{
- const char * key = PREF_KEY_SORT_MODE;
- const int i = gtk_radio_action_get_current_value (current);
- const char * val = sort_radio_entries[i].name;
+ const tr_quark key = TR_KEY_sort_mode;
+ const int i = gtk_radio_action_get_current_value (current);
+ const char * val = sort_radio_entries[i].name;
gtr_core_set_pref (myCore, key, val);
}
const char * key = gtk_action_get_name (GTK_ACTION (action));
const gboolean val = gtk_toggle_action_get_active (action);
- gtr_core_set_pref_bool (myCore, key, val);
+ gtr_core_set_pref_bool (myCore, tr_quark_new(key,-1), val);
}
static GtkToggleActionEntry pref_toggle_entries[] =
action_group = myGroup = gtk_action_group_new ("Actions");
gtk_action_group_set_translation_domain (action_group, NULL);
-
- match = gtr_pref_string_get (PREF_KEY_SORT_MODE);
+ match = gtr_pref_string_get (TR_KEY_sort_mode);
for (i = 0, n = G_N_ELEMENTS (sort_radio_entries), active = -1;
active == -1 && i < n; ++i)
if (!strcmp (sort_radio_entries[i].name, match))
for (i = 0, n = G_N_ELEMENTS (pref_toggle_entries); i < n; ++i)
pref_toggle_entries[i].is_active =
- gtr_pref_flag_get (pref_toggle_entries[i].name);
+ gtr_pref_flag_get (tr_quark_new (pref_toggle_entries[i].name, -1));
gtk_action_group_add_toggle_actions (action_group,
pref_toggle_entries,
****
***/
-static void cf_check_older_configs (void);
-
/**
* This is where we initialize the preferences file with the default values.
* If you add a new preferences key, you /must/ add a default value here.
const char * str;
const char * special_dl_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD);
- cf_check_older_configs ();
-
str = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD);
if (!str)
str = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
str = tr_getDefaultDownloadDir ();
tr_variantDictReserve (d, 29);
-
- tr_variantDictAddStr (d, PREF_KEY_DIR_WATCH, str);
- tr_variantDictAddBool (d, PREF_KEY_DIR_WATCH_ENABLED, FALSE);
-
- tr_variantDictAddBool (d, PREF_KEY_USER_HAS_GIVEN_INFORMED_CONSENT, FALSE);
- tr_variantDictAddBool (d, PREF_KEY_INHIBIT_HIBERNATION, FALSE);
- tr_variantDictAddBool (d, PREF_KEY_BLOCKLIST_UPDATES_ENABLED, TRUE);
-
- tr_variantDictAddStr (d, PREF_KEY_OPEN_DIALOG_FOLDER, g_get_home_dir ());
-
- tr_variantDictAddBool (d, PREF_KEY_TOOLBAR, TRUE);
- tr_variantDictAddBool (d, PREF_KEY_FILTERBAR, TRUE);
- tr_variantDictAddBool (d, PREF_KEY_STATUSBAR, TRUE);
- tr_variantDictAddBool (d, PREF_KEY_TRASH_CAN_ENABLED, TRUE);
- tr_variantDictAddBool (d, PREF_KEY_SHOW_TRAY_ICON, FALSE);
- tr_variantDictAddBool (d, PREF_KEY_SHOW_MORE_TRACKER_INFO, FALSE);
- tr_variantDictAddBool (d, PREF_KEY_SHOW_MORE_PEER_INFO, FALSE);
- tr_variantDictAddBool (d, PREF_KEY_SHOW_BACKUP_TRACKERS, FALSE);
- tr_variantDictAddStr (d, PREF_KEY_STATUSBAR_STATS, "total-ratio");
-
- tr_variantDictAddBool (d, PREF_KEY_TORRENT_ADDED_NOTIFICATION_ENABLED, true);
- tr_variantDictAddBool (d, PREF_KEY_TORRENT_COMPLETE_NOTIFICATION_ENABLED, true);
- tr_variantDictAddStr (d, PREF_KEY_TORRENT_COMPLETE_SOUND_COMMAND, "canberra-gtk-play -i complete-download -d 'transmission torrent downloaded'");
- tr_variantDictAddBool (d, PREF_KEY_TORRENT_COMPLETE_SOUND_ENABLED, true);
-
- tr_variantDictAddBool (d, PREF_KEY_OPTIONS_PROMPT, TRUE);
-
- tr_variantDictAddBool (d, PREF_KEY_MAIN_WINDOW_IS_MAXIMIZED, FALSE);
- tr_variantDictAddInt (d, PREF_KEY_MAIN_WINDOW_HEIGHT, 500);
- tr_variantDictAddInt (d, PREF_KEY_MAIN_WINDOW_WIDTH, 300);
- tr_variantDictAddInt (d, PREF_KEY_MAIN_WINDOW_X, 50);
- tr_variantDictAddInt (d, PREF_KEY_MAIN_WINDOW_Y, 50);
-
- tr_variantDictAddStr (d, TR_PREFS_KEY_DOWNLOAD_DIR, special_dl_dir ? special_dl_dir : str);
-
- tr_variantDictAddStr (d, PREF_KEY_SORT_MODE, "sort-by-name");
- tr_variantDictAddBool (d, PREF_KEY_SORT_REVERSED, FALSE);
- tr_variantDictAddBool (d, PREF_KEY_COMPACT_VIEW, FALSE);
-}
-
-static char*
-getPrefsFilename (void)
-{
- g_assert (gl_confdir != NULL);
- return g_build_filename (gl_confdir, "settings.json", NULL);
+ tr_variantDictAddStr (d, TR_KEY_watch_dir, str);
+ tr_variantDictAddBool (d, TR_KEY_watch_dir_enabled, FALSE);
+ tr_variantDictAddBool (d, TR_KEY_user_has_given_informed_consent, FALSE);
+ tr_variantDictAddBool (d, TR_KEY_inhibit_desktop_hibernation, FALSE);
+ tr_variantDictAddBool (d, TR_KEY_blocklist_updates_enabled, TRUE);
+ tr_variantDictAddStr (d, TR_KEY_open_dialog_dir, g_get_home_dir ());
+ tr_variantDictAddBool (d, TR_KEY_show_toolbar, TRUE);
+ tr_variantDictAddBool (d, TR_KEY_show_filterbar, TRUE);
+ tr_variantDictAddBool (d, TR_KEY_show_statusbar, TRUE);
+ tr_variantDictAddBool (d, TR_KEY_trash_can_enabled, TRUE);
+ tr_variantDictAddBool (d, TR_KEY_show_notification_area_icon, FALSE);
+ tr_variantDictAddBool (d, TR_KEY_show_tracker_scrapes, FALSE);
+ tr_variantDictAddBool (d, TR_KEY_show_extra_peer_details, FALSE);
+ tr_variantDictAddBool (d, TR_KEY_show_backup_trackers, FALSE);
+ tr_variantDictAddStr (d, TR_KEY_statusbar_stats, "total-ratio");
+ tr_variantDictAddBool (d, TR_KEY_torrent_added_notification_enabled, true);
+ tr_variantDictAddBool (d, TR_KEY_torrent_complete_notification_enabled, true);
+ tr_variantDictAddStr (d, TR_KEY_torrent_complete_sound_command, "canberra-gtk-play -i complete-download -d 'transmission torrent downloaded'");
+ tr_variantDictAddBool (d, TR_KEY_torrent_complete_sound_enabled, true);
+ tr_variantDictAddBool (d, TR_KEY_show_options_window, TRUE);
+ tr_variantDictAddBool (d, TR_KEY_main_window_is_maximized, FALSE);
+ tr_variantDictAddInt (d, TR_KEY_main_window_height, 500);
+ tr_variantDictAddInt (d, TR_KEY_main_window_width, 300);
+ tr_variantDictAddInt (d, TR_KEY_main_window_x, 50);
+ tr_variantDictAddInt (d, TR_KEY_main_window_y, 50);
+ tr_variantDictAddStr (d, TR_KEY_download_dir, special_dl_dir ? special_dl_dir : str);
+ tr_variantDictAddStr (d, TR_KEY_sort_mode, "sort-by-name");
+ tr_variantDictAddBool (d, TR_KEY_sort_reversed, FALSE);
+ tr_variantDictAddBool (d, TR_KEY_compact_view, FALSE);
}
static tr_variant*
}
int64_t
-gtr_pref_int_get (const char * key)
+gtr_pref_int_get (const tr_quark key)
{
int64_t i = 0;
}
void
-gtr_pref_int_set (const char * key, int64_t value)
+gtr_pref_int_set (const tr_quark key, int64_t value)
{
tr_variantDictAddInt (getPrefs (), key, value);
}
double
-gtr_pref_double_get (const char * key)
+gtr_pref_double_get (const tr_quark key)
{
double d = 0.0;
}
void
-gtr_pref_double_set (const char * key, double value)
+gtr_pref_double_set (const tr_quark key, double value)
{
tr_variantDictAddReal (getPrefs (), key, value);
}
***/
gboolean
-gtr_pref_flag_get (const char * key)
+gtr_pref_flag_get (const tr_quark key)
{
bool boolVal;
}
void
-gtr_pref_flag_set (const char * key, gboolean value)
+gtr_pref_flag_set (const tr_quark key, gboolean value)
{
tr_variantDictAddBool (getPrefs (), key, value);
}
***/
const char*
-gtr_pref_string_get (const char * key)
+gtr_pref_string_get (const tr_quark key)
{
const char * str = NULL;
}
void
-gtr_pref_string_set (const char * key, const char * value)
+gtr_pref_string_set (const tr_quark key, const char * value)
{
tr_variantDictAddStr (getPrefs (), key, value);
}
tr_sessionSaveSettings (session, gl_confdir, getPrefs ());
}
-/***
-****
-***/
-
-static char*
-getCompat090PrefsFilename (void)
-{
- g_assert (gl_confdir != NULL);
-
- return g_build_filename (g_get_home_dir (), ".transmission", "gtk", "prefs.ini", NULL);
-}
-
-static char*
-getCompat121PrefsFilename (void)
-{
- return g_build_filename (g_get_user_config_dir (), "transmission", "gtk", "prefs.ini", NULL);
-}
-
-static void
-translate_keyfile_to_json (const char * old_file, const char * new_file)
-{
- tr_variant dict;
- GKeyFile * keyfile;
- gchar ** keys;
- gsize i;
- gsize length;
-
- static struct pref_entry {
- const char* oldkey;
- const char* newkey;
- } renamed[] = {
- { "default-download-directory", "download-dir" },
- { "encrypted-connections-only", "encryption" },
- { "listening-port", "peer-port" },
- { "nat-traversal-enabled", "port-forwarding-enabled" },
- { "open-dialog-folder", "open-dialog-dir" },
- { "watch-folder", "watch-dir" },
- { "watch-folder-enabled", "watch-dir-enabled" }
- };
-
- keyfile = g_key_file_new ();
- g_key_file_load_from_file (keyfile, old_file, 0, NULL);
- length = 0;
- keys = g_key_file_get_keys (keyfile, "general", &length, NULL);
-
- tr_variantInitDict (&dict, length);
- for (i=0; i<length; i++)
- {
- guint j;
- const char * key = keys[i];
- gchar * val = g_key_file_get_value (keyfile, "general", key, NULL);
-
- for (j=0; j<G_N_ELEMENTS (renamed); j++)
- if (!strcmp (renamed[j].oldkey, key))
- key = renamed[j].newkey;
-
- if (!strcmp (val, "true") || !strcmp (val, "false"))
- {
- tr_variantDictAddInt (&dict, key, !strcmp (val, "true"));
- }
- else
- {
- char * end;
- long l;
-
- errno = 0;
-
- l = strtol (val, &end, 10);
- if (!errno && end && !*end)
- tr_variantDictAddInt (&dict, key, l);
- else
- tr_variantDictAddStr (&dict, key, val);
- }
-
- g_free (val);
- }
-
- g_key_file_free (keyfile);
- tr_variantToFile (&dict, TR_VARIANT_FMT_JSON, new_file);
- tr_variantFree (&dict);
-}
-
-static void
-cf_check_older_configs (void)
-{
- char * filename = getPrefsFilename ();
-
- if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR))
- {
- char * key1 = getCompat121PrefsFilename ();
- char * key2 = getCompat090PrefsFilename ();
-
- if (g_file_test (key1, G_FILE_TEST_IS_REGULAR))
- {
- g_message (_("Importing \"%s\""), key1);
- translate_keyfile_to_json (key1, filename);
- }
- else if (g_file_test (key2, G_FILE_TEST_IS_REGULAR))
- {
- g_message (_("Importing \"%s\""), key2);
- translate_keyfile_to_json (key2, filename);
- }
-
- g_free (key2);
- g_free (key1);
- }
-
- g_free (filename);
-}
#include <inttypes.h>
#include <libtransmission/transmission.h> /* tr_variant, tr_session */
+#include <libtransmission/quark.h>
-void gtr_pref_init (const char * config_dir);
+void gtr_pref_init (const char * config_dir);
-int64_t gtr_pref_int_get (const char * key);
-void gtr_pref_int_set (const char * key, int64_t value);
+int64_t gtr_pref_int_get (const tr_quark key);
+void gtr_pref_int_set (const tr_quark key, int64_t value);
-double gtr_pref_double_get (const char * key);
-void gtr_pref_double_set (const char * key, double value);
+double gtr_pref_double_get (const tr_quark key);
+void gtr_pref_double_set (const tr_quark key, double value);
-gboolean gtr_pref_flag_get (const char * key);
-void gtr_pref_flag_set (const char * key, gboolean value);
+gboolean gtr_pref_flag_get (const tr_quark key);
+void gtr_pref_flag_set (const tr_quark key, gboolean value);
-const char* gtr_pref_string_get (const char * key);
-void gtr_pref_string_set (const char * key, const char * value);
+const char* gtr_pref_string_get (const tr_quark key);
+void gtr_pref_string_set (const tr_quark key, const char * value);
-void gtr_pref_save (tr_session *);
+void gtr_pref_save (tr_session *);
struct tr_variant* gtr_pref_get_all (void);
#endif /* GTR_CONFIG_H */
}
static void
-torrent_set_bool (struct DetailsImpl * di, const char * key, gboolean value)
+torrent_set_bool (struct DetailsImpl * di, const tr_quark key, gboolean value)
{
GSList *l;
tr_variant top, *args, *ids;
tr_variantInitDict (&top, 2);
- tr_variantDictAddStr (&top, "method", "torrent-set");
- args = tr_variantDictAddDict (&top, "arguments", 2);
+ tr_variantDictAddStr (&top, TR_KEY_method, "torrent-set");
+ args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2);
tr_variantDictAddBool (args, key, value);
- ids = tr_variantDictAddList (args, "ids", g_slist_length (di->ids));
+ ids = tr_variantDictAddList (args, TR_KEY_ids, g_slist_length (di->ids));
for (l=di->ids; l; l=l->next)
tr_variantListAddInt (ids, GPOINTER_TO_INT (l->data));
}
static void
-torrent_set_int (struct DetailsImpl * di, const char * key, int value)
+torrent_set_int (struct DetailsImpl * di, const tr_quark key, int value)
{
GSList *l;
tr_variant top, *args, *ids;
tr_variantInitDict (&top, 2);
- tr_variantDictAddStr (&top, "method", "torrent-set");
- args = tr_variantDictAddDict (&top, "arguments", 2);
+ tr_variantDictAddStr (&top, TR_KEY_method, "torrent-set");
+ args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2);
tr_variantDictAddInt (args, key, value);
- ids = tr_variantDictAddList (args, "ids", g_slist_length (di->ids));
+ ids = tr_variantDictAddList (args, TR_KEY_ids, g_slist_length (di->ids));
for (l=di->ids; l; l=l->next)
tr_variantListAddInt (ids, GPOINTER_TO_INT (l->data));
}
static void
-torrent_set_real (struct DetailsImpl * di, const char * key, double value)
+torrent_set_real (struct DetailsImpl * di, const tr_quark key, double value)
{
GSList *l;
tr_variant top, *args, *ids;
tr_variantInitDict (&top, 2);
- tr_variantDictAddStr (&top, "method", "torrent-set");
- args = tr_variantDictAddDict (&top, "arguments", 2);
+ tr_variantDictAddStr (&top, TR_KEY_method, "torrent-set");
+ args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2);
tr_variantDictAddReal (args, key, value);
- ids = tr_variantDictAddList (args, "ids", g_slist_length (di->ids));
+ ids = tr_variantDictAddList (args, TR_KEY_ids, g_slist_length (di->ids));
for (l=di->ids; l; l=l->next)
tr_variantListAddInt (ids, GPOINTER_TO_INT (l->data));
static void
up_speed_toggled_cb (GtkToggleButton * tb, gpointer d)
{
- torrent_set_bool (d, "uploadLimited", gtk_toggle_button_get_active (tb));
+ torrent_set_bool (d, TR_KEY_uploadLimited, gtk_toggle_button_get_active (tb));
}
static void
down_speed_toggled_cb (GtkToggleButton *tb, gpointer d)
{
- torrent_set_bool (d, "downloadLimited", gtk_toggle_button_get_active (tb));
+ torrent_set_bool (d, TR_KEY_downloadLimited, gtk_toggle_button_get_active (tb));
}
static void
global_speed_toggled_cb (GtkToggleButton * tb, gpointer d)
{
- torrent_set_bool (d, "honorsSessionLimits", gtk_toggle_button_get_active (tb));
+ torrent_set_bool (d, TR_KEY_honorsSessionLimits, gtk_toggle_button_get_active (tb));
}
static void
up_speed_spun_cb (GtkSpinButton * s, struct DetailsImpl * di)
{
- torrent_set_int (di, "uploadLimit", gtk_spin_button_get_value_as_int (s));
+ torrent_set_int (di, TR_KEY_uploadLimit, gtk_spin_button_get_value_as_int (s));
}
static void
down_speed_spun_cb (GtkSpinButton * s, struct DetailsImpl * di)
{
- torrent_set_int (di, "downloadLimit", gtk_spin_button_get_value_as_int (s));
+ torrent_set_int (di, TR_KEY_downloadLimit, gtk_spin_button_get_value_as_int (s));
}
static void
idle_spun_cb (GtkSpinButton * s, struct DetailsImpl * di)
{
- torrent_set_int (di, "seedIdleLimit", gtk_spin_button_get_value_as_int (s));
+ torrent_set_int (di, TR_KEY_seedIdleLimit, gtk_spin_button_get_value_as_int (s));
}
static void
ratio_spun_cb (GtkSpinButton * s, struct DetailsImpl * di)
{
- torrent_set_real (di, "seedRatioLimit", gtk_spin_button_get_value (s));
+ torrent_set_real (di, TR_KEY_seedRatioLimit, gtk_spin_button_get_value (s));
}
static void
max_peers_spun_cb (GtkSpinButton * s, struct DetailsImpl * di)
{
- torrent_set_int (di, "peer-limit", gtk_spin_button_get_value (s));
+ torrent_set_int (di, TR_KEY_peer_limit, gtk_spin_button_get_value (s));
}
static void
onPriorityChanged (GtkComboBox * combo_box, struct DetailsImpl * di)
{
const tr_priority_t priority = gtr_priority_combo_get_value (combo_box);
- torrent_set_int (di, "bandwidthPriority", priority);
+ torrent_set_int (di, TR_KEY_bandwidthPriority, priority);
}
static GtkWidget*
static void
onComboEnumChanged (GtkComboBox * combo_box, struct DetailsImpl * di)
{
- const char * key = g_object_get_qdata (G_OBJECT (combo_box), ARG_KEY);
+ const tr_quark key = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (combo_box), ARG_KEY));
torrent_set_int (di, key, gtr_combo_box_get_active_enum (combo_box));
refresh (di);
}
_("Seed regardless of ratio"), TR_RATIOLIMIT_UNLIMITED,
_("Stop seeding at ratio:"), TR_RATIOLIMIT_SINGLE,
NULL);
- g_object_set_qdata (G_OBJECT (w), ARG_KEY, (gpointer)"seedRatioMode");
+ g_object_set_qdata (G_OBJECT (w), ARG_KEY, GINT_TO_POINTER(TR_KEY_seedRatioMode));
return w;
}
_("Seed regardless of activity"), TR_IDLELIMIT_UNLIMITED,
_("Stop seeding if idle for N minutes:"), TR_IDLELIMIT_SINGLE,
NULL);
- g_object_set_qdata (G_OBJECT (w), ARG_KEY, (gpointer)"seedIdleMode");
+ g_object_set_qdata (G_OBJECT (w), ARG_KEY, GINT_TO_POINTER(TR_KEY_seedIdleMode));
return w;
}
{
int i;
int n = 0;
- const bool more = gtr_pref_flag_get (PREF_KEY_SHOW_MORE_PEER_INFO);
+ const bool more = gtr_pref_flag_get (TR_KEY_show_extra_peer_details);
int view_columns[32];
GtkTreeViewColumn * c;
GtkCellRenderer * r;
static void
onMorePeerInfoToggled (GtkToggleButton * button, struct DetailsImpl * di)
{
- const char * key = PREF_KEY_SHOW_MORE_PEER_INFO;
+ const tr_quark key = TR_KEY_show_extra_peer_details;
const gboolean value = gtk_toggle_button_get_active (button);
gtr_core_set_pref_bool (di->core, key, value);
setPeerViewColumns (GTK_TREE_VIEW (di->peer_view));
w = gtk_check_button_new_with_mnemonic (_("Show _more details"));
di->more_peer_details_check = w;
- b = gtr_pref_flag_get (PREF_KEY_SHOW_MORE_PEER_INFO);
+ b = gtr_pref_flag_get (TR_KEY_show_extra_peer_details);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), b);
g_signal_connect (w, "toggled", G_CALLBACK (onMorePeerInfoToggled), di);
gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
static void
onScrapeToggled (GtkToggleButton * button, struct DetailsImpl * di)
{
- const char * key = PREF_KEY_SHOW_MORE_TRACKER_INFO;
- const gboolean value = gtk_toggle_button_get_active (button);
- gtr_core_set_pref_bool (di->core, key, value);
- refresh (di);
+ const tr_quark key = TR_KEY_show_tracker_scrapes;
+ const gboolean value = gtk_toggle_button_get_active (button);
+ gtr_core_set_pref_bool (di->core, key, value);
+ refresh (di);
}
static void
onBackupToggled (GtkToggleButton * button, struct DetailsImpl * di)
{
- const char * key = PREF_KEY_SHOW_BACKUP_TRACKERS;
- const gboolean value = gtk_toggle_button_get_active (button);
- gtr_core_set_pref_bool (di->core, key, value);
- refresh (di);
+ const tr_quark key = TR_KEY_show_backup_trackers;
+ const gboolean value = gtk_toggle_button_get_active (button);
+ gtr_core_set_pref_bool (di->core, key, value);
+ refresh (di);
}
static void
w = gtk_check_button_new_with_mnemonic (_("Show _more details"));
di->scrape_check = w;
- b = gtr_pref_flag_get (PREF_KEY_SHOW_MORE_TRACKER_INFO);
+ b = gtr_pref_flag_get (TR_KEY_show_tracker_scrapes);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), b);
g_signal_connect (w, "toggled", G_CALLBACK (onScrapeToggled), di);
gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
w = gtk_check_button_new_with_mnemonic (_("Show _backup trackers"));
di->all_check = w;
- b = gtr_pref_flag_get (PREF_KEY_SHOW_BACKUP_TRACKERS);
+ b = gtr_pref_flag_get (TR_KEY_show_backup_trackers);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), b);
g_signal_connect (w, "toggled", G_CALLBACK (onBackupToggled), di);
gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
const gboolean isMaximized = (gdk_window != NULL)
&& (gdk_window_get_state (gdk_window) & GDK_WINDOW_STATE_MAXIMIZED);
- gtr_pref_int_set (PREF_KEY_MAIN_WINDOW_IS_MAXIMIZED, isMaximized);
+ gtr_pref_int_set (TR_KEY_main_window_is_maximized, isMaximized);
if (!isMaximized)
{
int x, y, w, h;
gtk_window_get_position (GTK_WINDOW (gtk_window), &x, &y);
gtk_window_get_size (GTK_WINDOW (gtk_window), &w, &h);
- gtr_pref_int_set (PREF_KEY_MAIN_WINDOW_X, x);
- gtr_pref_int_set (PREF_KEY_MAIN_WINDOW_Y, y);
- gtr_pref_int_set (PREF_KEY_MAIN_WINDOW_WIDTH, w);
- gtr_pref_int_set (PREF_KEY_MAIN_WINDOW_HEIGHT, h);
+ gtr_pref_int_set (TR_KEY_main_window_x, x);
+ gtr_pref_int_set (TR_KEY_main_window_y, y);
+ gtr_pref_int_set (TR_KEY_main_window_width, w);
+ gtr_pref_int_set (TR_KEY_main_window_height, h);
}
}
tr_variant tmp;
tr_variant * newval;
tr_variant * oldvals = gtr_pref_get_all ();
- const char * key;
+ tr_quark key;
GSList * l;
GSList * changed_keys = NULL;
tr_variantInitDict (&tmp, 100);
}
if (changed)
- changed_keys = g_slist_append (changed_keys, (gpointer)key);
+ changed_keys = g_slist_append (changed_keys, GINT_TO_POINTER(key));
}
tr_sessionGetSettings (session, oldvals);
for (l=changed_keys; l!=NULL; l=l->next)
- gtr_core_pref_changed (cbdata->core, l->data);
+ gtr_core_pref_changed (cbdata->core, GPOINTER_TO_INT(l->data));
g_slist_free (changed_keys);
tr_variantFree (&tmp);
sighandler_cbdata = cbdata;
/* ensure the directories are created */
- if ((str = gtr_pref_string_get (TR_PREFS_KEY_DOWNLOAD_DIR)))
+ if ((str = gtr_pref_string_get (TR_KEY_download_dir)))
g_mkdir_with_parents (str, 0777);
- if ((str = gtr_pref_string_get (TR_PREFS_KEY_INCOMPLETE_DIR)))
+ if ((str = gtr_pref_string_get (TR_KEY_incomplete_dir)))
g_mkdir_with_parents (str, 0777);
/* initialize the libtransmission session */
session = tr_sessionInit ("gtk", cbdata->config_dir, TRUE, gtr_pref_get_all ());
- gtr_pref_flag_set (TR_PREFS_KEY_ALT_SPEED_ENABLED, tr_sessionUsesAltSpeed (session));
- gtr_pref_int_set (TR_PREFS_KEY_PEER_PORT, tr_sessionGetPeerPort (session));
+ gtr_pref_flag_set (TR_KEY_alt_speed_enabled, tr_sessionUsesAltSpeed (session));
+ gtr_pref_int_set (TR_KEY_peer_port, tr_sessionGetPeerPort (session));
cbdata->core = gtr_core_new (session);
/* init the ui manager */
tr_sessionSetRPCCallback (session, on_rpc_changed, cbdata);
/* check & see if it's time to update the blocklist */
- if (gtr_pref_flag_get (TR_PREFS_KEY_BLOCKLIST_ENABLED))
+ if (gtr_pref_flag_get (TR_KEY_blocklist_enabled))
{
- if (gtr_pref_flag_get (PREF_KEY_BLOCKLIST_UPDATES_ENABLED))
+ if (gtr_pref_flag_get (TR_KEY_blocklist_updates_enabled))
{
- const int64_t last_time = gtr_pref_int_get ("blocklist-date");
+ const int64_t last_time = gtr_pref_int_get (TR_KEY_blocklist_date);
const int SECONDS_IN_A_WEEK = 7 * 24 * 60 * 60;
const time_t now = time (NULL);
if (last_time + SECONDS_IN_A_WEEK < now)
open_files (GSList * files, gpointer gdata)
{
struct cbdata * cbdata = gdata;
- const gboolean do_start = gtr_pref_flag_get (TR_PREFS_KEY_START) && !cbdata->start_paused;
- const gboolean do_prompt = gtr_pref_flag_get (PREF_KEY_OPTIONS_PROMPT);
+ const gboolean do_start = gtr_pref_flag_get (TR_KEY_start_added_torrents) && !cbdata->start_paused;
+ const gboolean do_prompt = gtr_pref_flag_get (TR_KEY_show_options_window);
const gboolean do_notify = TRUE;
gtr_core_add_files (cbdata->core, files, do_start, do_prompt, do_notify);
static void on_core_error (TrCore *, guint, const char *, struct cbdata *);
static void on_add_torrent (TrCore *, tr_ctor *, gpointer);
-static void on_prefs_changed (TrCore * core, const char * key, gpointer);
+static void on_prefs_changed (TrCore * core, const tr_quark key, gpointer);
static void main_window_setup (struct cbdata * cbdata, GtkWindow * wind);
static gboolean update_model_loop (gpointer gdata);
static gboolean update_model_once (gpointer gdata);
app_setup (GtkWindow * wind, struct cbdata * cbdata)
{
if (cbdata->is_iconified)
- gtr_pref_flag_set (PREF_KEY_SHOW_TRAY_ICON, TRUE);
+ gtr_pref_flag_set (TR_KEY_show_notification_area_icon, TRUE);
gtr_actions_set_core (cbdata->core);
main_window_setup (cbdata, wind);
/* set up the icon */
- on_prefs_changed (cbdata->core, PREF_KEY_SHOW_TRAY_ICON, cbdata);
+ on_prefs_changed (cbdata->core, TR_KEY_show_notification_area_icon, cbdata);
/* start model update timer */
cbdata->timer = gdk_threads_add_timeout_seconds (MAIN_WINDOW_REFRESH_INTERVAL_SECONDS, update_model_loop, cbdata);
gtr_action_set_toggled ("toggle-main-window", FALSE);
}
- if (!gtr_pref_flag_get (PREF_KEY_USER_HAS_GIVEN_INFORMED_CONSENT))
+ if (!gtr_pref_flag_get (TR_KEY_user_has_given_informed_consent))
{
GtkWidget * w = gtk_message_dialog_new (GTK_WINDOW (wind),
GTK_DIALOG_DESTROY_WITH_PARENT,
{
case GTK_RESPONSE_ACCEPT:
/* only show it once */
- gtr_pref_flag_set (PREF_KEY_USER_HAS_GIVEN_INFORMED_CONSENT, TRUE);
+ gtr_pref_flag_set (TR_KEY_user_has_given_informed_consent, TRUE);
gtk_widget_destroy (w);
break;
if (!gtk_widget_get_visible (GTK_WIDGET (window)))
{
- gtk_window_resize (window, gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_WIDTH),
- gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_HEIGHT));
- gtk_window_move (window, gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_X),
- gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_Y));
+ gtk_window_resize (window, gtr_pref_int_get (TR_KEY_main_window_width),
+ gtr_pref_int_get (TR_KEY_main_window_height));
+ gtk_window_move (window, gtr_pref_int_get (TR_KEY_main_window_x),
+ gtr_pref_int_get (TR_KEY_main_window_y));
gtr_widget_set_visible (GTK_WIDGET (window), TRUE);
}
/* ensure the window is in its previous position & size.
* this seems to be necessary because changing the main window's
* child seems to unset the size */
- gtk_window_resize (cbdata->wind, gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_WIDTH),
- gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_HEIGHT));
- gtk_window_move (cbdata->wind, gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_X),
- gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_Y));
+ gtk_window_resize (cbdata->wind, gtr_pref_int_get (TR_KEY_main_window_width),
+ gtr_pref_int_get (TR_KEY_main_window_height));
+ gtk_window_move (cbdata->wind, gtr_pref_int_get (TR_KEY_main_window_x),
+ gtr_pref_int_get (TR_KEY_main_window_y));
/* shut down libT */
g_thread_new ("shutdown-thread", session_close_threadfunc, vdata);
}
static void
-on_prefs_changed (TrCore * core UNUSED, const char * key, gpointer data)
+on_prefs_changed (TrCore * core UNUSED, const tr_quark key, gpointer data)
{
struct cbdata * cbdata = data;
tr_session * tr = gtr_core_session (cbdata->core);
- if (!strcmp (key, TR_PREFS_KEY_ENCRYPTION))
- {
- tr_sessionSetEncryption (tr, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_DOWNLOAD_DIR))
- {
- tr_sessionSetDownloadDir (tr, gtr_pref_string_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_MSGLEVEL))
- {
- tr_setMessageLevel (gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_PEER_PORT))
- {
- tr_sessionSetPeerPort (tr, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_BLOCKLIST_ENABLED))
+ switch (key)
{
+ case TR_KEY_encryption:
+ tr_sessionSetEncryption (tr, gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_download_dir:
+ tr_sessionSetDownloadDir (tr, gtr_pref_string_get (key));
+ break;
+
+ case TR_KEY_message_level:
+ tr_setMessageLevel (gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_peer_port:
+ tr_sessionSetPeerPort (tr, gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_blocklist_enabled:
tr_blocklistSetEnabled (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_BLOCKLIST_URL))
- {
+ break;
+
+ case TR_KEY_blocklist_url:
tr_blocklistSetURL (tr, gtr_pref_string_get (key));
- }
- else if (!strcmp (key, PREF_KEY_SHOW_TRAY_ICON))
- {
- const int show = gtr_pref_flag_get (key);
- if (show && !cbdata->icon)
- cbdata->icon = gtr_icon_new (cbdata->core);
- else if (!show && cbdata->icon)
- g_clear_object (&cbdata->icon);
- }
- else if (!strcmp (key, TR_PREFS_KEY_DSPEED_ENABLED))
- {
- tr_sessionLimitSpeed (tr, TR_DOWN, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_DSPEED_KBps))
- {
- tr_sessionSetSpeedLimit_KBps (tr, TR_DOWN, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_USPEED_ENABLED))
- {
- tr_sessionLimitSpeed (tr, TR_UP, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_USPEED_KBps))
- {
- tr_sessionSetSpeedLimit_KBps (tr, TR_UP, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_RATIO_ENABLED))
- {
- tr_sessionSetRatioLimited (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_RATIO))
- {
- tr_sessionSetRatioLimit (tr, gtr_pref_double_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_IDLE_LIMIT))
- {
- tr_sessionSetIdleLimit (tr, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_IDLE_LIMIT_ENABLED))
- {
- tr_sessionSetIdleLimited (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_PORT_FORWARDING))
- {
- tr_sessionSetPortForwardingEnabled (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_PEX_ENABLED))
- {
- tr_sessionSetPexEnabled (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_RENAME_PARTIAL_FILES))
- {
- tr_sessionSetIncompleteFileNamingEnabled (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_DOWNLOAD_QUEUE_SIZE))
- {
- tr_sessionSetQueueSize (tr, TR_DOWN, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_QUEUE_STALLED_MINUTES))
- {
- tr_sessionSetQueueStalledMinutes (tr, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_DHT_ENABLED))
- {
- tr_sessionSetDHTEnabled (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_UTP_ENABLED))
- {
- tr_sessionSetUTPEnabled (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_LPD_ENABLED))
- {
- tr_sessionSetLPDEnabled (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_RPC_PORT))
- {
- tr_sessionSetRPCPort (tr, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_RPC_ENABLED))
- {
- tr_sessionSetRPCEnabled (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_RPC_WHITELIST))
- {
- tr_sessionSetRPCWhitelist (tr, gtr_pref_string_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_RPC_WHITELIST_ENABLED))
- {
- tr_sessionSetRPCWhitelistEnabled (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_RPC_USERNAME))
- {
- tr_sessionSetRPCUsername (tr, gtr_pref_string_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_RPC_PASSWORD))
- {
- tr_sessionSetRPCPassword (tr, gtr_pref_string_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_RPC_AUTH_REQUIRED))
- {
- tr_sessionSetRPCPasswordEnabled (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_ALT_SPEED_UP_KBps))
- {
- tr_sessionSetAltSpeed_KBps (tr, TR_UP, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps))
- {
+ break;
+
+ case TR_KEY_show_notification_area_icon:
+ {
+ const bool show = gtr_pref_flag_get (key);
+ if (show && !cbdata->icon)
+ cbdata->icon = gtr_icon_new (cbdata->core);
+ else if (!show && cbdata->icon)
+ g_clear_object (&cbdata->icon);
+ break;
+ }
+
+ case TR_KEY_speed_limit_down_enabled:
+ tr_sessionLimitSpeed (tr, TR_DOWN, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_speed_limit_down:
+ tr_sessionSetSpeedLimit_KBps (tr, TR_DOWN, gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_speed_limit_up_enabled:
+ tr_sessionLimitSpeed (tr, TR_UP, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_speed_limit_up:
+ tr_sessionSetSpeedLimit_KBps (tr, TR_UP, gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_ratio_limit_enabled:
+ tr_sessionSetRatioLimited (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_ratio_limit:
+ tr_sessionSetRatioLimit (tr, gtr_pref_double_get (key));
+ break;
+
+ case TR_KEY_idle_seeding_limit:
+ tr_sessionSetIdleLimit (tr, gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_idle_seeding_limit_enabled:
+ tr_sessionSetIdleLimited (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_port_forwarding_enabled:
+ tr_sessionSetPortForwardingEnabled (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_pex_enabled:
+ tr_sessionSetPexEnabled (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_rename_partial_files:
+ tr_sessionSetIncompleteFileNamingEnabled (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_download_queue_size:
+ tr_sessionSetQueueSize (tr, TR_DOWN, gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_queue_stalled_minutes:
+ tr_sessionSetQueueStalledMinutes (tr, gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_dht_enabled:
+ tr_sessionSetDHTEnabled (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_utp_enabled:
+ tr_sessionSetUTPEnabled (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_lpd_enabled:
+ tr_sessionSetLPDEnabled (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_rpc_port:
+ tr_sessionSetRPCPort (tr, gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_rpc_enabled:
+ tr_sessionSetRPCEnabled (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_rpc_whitelist:
+ tr_sessionSetRPCWhitelist (tr, gtr_pref_string_get (key));
+ break;
+
+ case TR_KEY_rpc_whitelist_enabled:
+ tr_sessionSetRPCWhitelistEnabled (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_rpc_username:
+ tr_sessionSetRPCUsername (tr, gtr_pref_string_get (key));
+ break;
+
+ case TR_KEY_rpc_password:
+ tr_sessionSetRPCPassword (tr, gtr_pref_string_get (key));
+ break;
+
+ case TR_KEY_rpc_authentication_required:
+ tr_sessionSetRPCPasswordEnabled (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_alt_speed_up:
+ tr_sessionSetAltSpeed_KBps (tr, TR_UP, gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_alt_speed_down:
tr_sessionSetAltSpeed_KBps (tr, TR_DOWN, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_ALT_SPEED_ENABLED))
- {
- const gboolean b = gtr_pref_flag_get (key);
- tr_sessionUseAltSpeed (tr, b);
- gtr_action_set_toggled (key, b);
- }
- else if (!strcmp (key, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN))
- {
- tr_sessionSetAltSpeedBegin (tr, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_ALT_SPEED_TIME_END))
- {
- tr_sessionSetAltSpeedEnd (tr, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED))
- {
- tr_sessionUseAltSpeedTime (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_ALT_SPEED_TIME_DAY))
- {
- tr_sessionSetAltSpeedDay (tr, gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START))
- {
- tr_sessionSetPeerPortRandomOnStart (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_INCOMPLETE_DIR))
- {
- tr_sessionSetIncompleteDir (tr, gtr_pref_string_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED))
- {
- tr_sessionSetIncompleteDirEnabled (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED))
- {
- tr_sessionSetTorrentDoneScriptEnabled (tr, gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME))
- {
- tr_sessionSetTorrentDoneScript (tr, gtr_pref_string_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_START))
- {
- tr_sessionSetPaused (tr, !gtr_pref_flag_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_TRASH_ORIGINAL))
- {
- tr_sessionSetDeleteSource (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_alt_speed_enabled:
+ {
+ const bool b = gtr_pref_flag_get (key);
+ tr_sessionUseAltSpeed (tr, b);
+ gtr_action_set_toggled (tr_quark_get_string(key,NULL), b);
+ break;
+ }
+
+ case TR_KEY_alt_speed_time_begin:
+ tr_sessionSetAltSpeedBegin (tr, gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_alt_speed_time_end:
+ tr_sessionSetAltSpeedEnd (tr, gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_alt_speed_time_enabled:
+ tr_sessionUseAltSpeedTime (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_alt_speed_time_day:
+ tr_sessionSetAltSpeedDay (tr, gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_peer_port_random_on_start:
+ tr_sessionSetPeerPortRandomOnStart (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_incomplete_dir:
+ tr_sessionSetIncompleteDir (tr, gtr_pref_string_get (key));
+ break;
+
+ case TR_KEY_incomplete_dir_enabled:
+ tr_sessionSetIncompleteDirEnabled (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_script_torrent_done_enabled:
+ tr_sessionSetTorrentDoneScriptEnabled (tr, gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_script_torrent_done_filename:
+ tr_sessionSetTorrentDoneScript (tr, gtr_pref_string_get (key));
+ break;
+
+ case TR_KEY_start_added_torrents:
+ tr_sessionSetPaused (tr, !gtr_pref_flag_get (key));
+ break;
+
+ case TR_KEY_trash_original_torrent_files:
+ tr_sessionSetDeleteSource (tr, gtr_pref_flag_get (key));
+ break;
+
+ default:
+ break;
}
}
tr_session * session = gtr_core_session (data->core);
tr_variantInitDict (&top, 2);
- tr_variantDictAddStr (&top, "method", method);
- args = tr_variantDictAddDict (&top, "arguments", 1);
- ids = tr_variantDictAddList (args, "ids", 0);
+ tr_variantDictAddStr (&top, TR_KEY_method, method);
+ args = tr_variantDictAddDict (&top, TR_KEY_arguments, 1);
+ ids = tr_variantDictAddList (args, TR_KEY_ids, 0);
gtk_tree_selection_selected_foreach (s, append_id_to_benc_list, ids);
if (tr_variantListSize (ids) != 0)
const gboolean pinned_to_new = is_pinned_to_new (data);
tr_setMessageLevel (level);
- gtr_core_set_pref_int (data->core, TR_PREFS_KEY_MSGLEVEL, level);
+ gtr_core_set_pref_int (data->core, TR_KEY_message_level, level);
data->maxLevel = level;
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (data->filter));
_("Information"), TR_MSG_INF,
_("Debug"), TR_MSG_DBG,
NULL);
- gtr_combo_box_set_active_enum (GTK_COMBO_BOX (w), gtr_pref_int_get (TR_PREFS_KEY_MSGLEVEL));
+ gtr_combo_box_set_active_enum (GTK_COMBO_BOX (w), gtr_pref_int_get (TR_KEY_message_level));
return w;
}
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (data->sort),
COL_SEQUENCE,
GTK_SORT_ASCENDING);
- data->maxLevel = gtr_pref_int_get (TR_PREFS_KEY_MSGLEVEL);
+ data->maxLevel = gtr_pref_int_get (TR_KEY_message_level);
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (data->filter),
isRowVisible, data, NULL);
GVariantBuilder actions_builder;
TrNotification * n;
tr_torrent * tor;
- const char * cmd = gtr_pref_string_get (PREF_KEY_TORRENT_COMPLETE_SOUND_COMMAND);
+ const char * cmd = gtr_pref_string_get (TR_KEY_torrent_complete_sound_command);
- if (gtr_pref_flag_get (PREF_KEY_TORRENT_COMPLETE_SOUND_ENABLED))
+ if (gtr_pref_flag_get (TR_KEY_torrent_complete_sound_enabled))
g_spawn_command_line_async (cmd, NULL);
- if (!gtr_pref_flag_get (PREF_KEY_TORRENT_COMPLETE_NOTIFICATION_ENABLED))
+ if (!gtr_pref_flag_get (TR_KEY_torrent_complete_notification_enabled))
return;
g_return_if_fail (G_IS_DBUS_PROXY (proxy));
g_return_if_fail (G_IS_DBUS_PROXY (proxy));
- if (!gtr_pref_flag_get (PREF_KEY_TORRENT_ADDED_NOTIFICATION_ENABLED))
+ if (!gtr_pref_flag_get (TR_KEY_torrent_added_notification_enabled))
return;
n = g_new0 (TrNotification, 1);
char key[64];
const char * val;
g_snprintf (key, sizeof (key), "recent-download-dir-%d", i+1);
- if ((val = gtr_pref_string_get (key)))
+ if ((val = gtr_pref_string_get (tr_quark_new(key,-1))))
list = g_slist_append (list, (void*)val);
}
return list;
for (l=list, i=0; l && (i<N_RECENT); ++i, l=l->next) {
char key[64];
g_snprintf (key, sizeof (key), "recent-download-dir-%d", i + 1);
- gtr_pref_string_set (key, l->data);
+ gtr_pref_string_set (tr_quark_new(key,-1), l->data);
}
gtr_pref_save (gtr_core_session (core));
/* remember this folder the next time we use this dialog */
folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
- gtr_pref_string_set (PREF_KEY_OPEN_DIALOG_FOLDER, folder);
+ gtr_pref_string_set (TR_KEY_open_dialog_dir, folder);
g_free (folder);
if (response == GTK_RESPONSE_ACCEPT)
GtkFileChooser * chooser = GTK_FILE_CHOOSER (dialog);
GtkWidget * w = gtk_file_chooser_get_extra_widget (chooser);
GtkToggleButton * tb = GTK_TOGGLE_BUTTON (w);
- const gboolean do_start = gtr_pref_flag_get (TR_PREFS_KEY_START);
+ const gboolean do_start = gtr_pref_flag_get (TR_KEY_start_added_torrents);
const gboolean do_prompt = gtk_toggle_button_get_active (tb);
const gboolean do_notify = FALSE;
GSList * files = gtk_file_chooser_get_files (chooser);
addTorrentFilters (GTK_FILE_CHOOSER (w));
g_signal_connect (w, "response", G_CALLBACK (onOpenDialogResponse), core);
- if ((folder = gtr_pref_string_get (PREF_KEY_OPEN_DIALOG_FOLDER)))
+ if ((folder = gtr_pref_string_get (TR_KEY_open_dialog_dir)))
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w), folder);
c = gtk_check_button_new_with_mnemonic (_("Show _options dialog"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (c),
- gtr_pref_flag_get (PREF_KEY_OPTIONS_PROMPT));
+ gtr_pref_flag_get (TR_KEY_show_options_window));
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (w), c);
gtk_widget_show (c);
hig_workarea_add_section_title (t, &row, _("Location"));
if (previousLocation == NULL)
- previousLocation = g_strdup (gtr_pref_string_get (TR_PREFS_KEY_DOWNLOAD_DIR));
+ previousLocation = g_strdup (gtr_pref_string_get (TR_KEY_download_dir));
w = gtk_file_chooser_button_new (_("Set Torrent Location"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w), previousLocation);
g_object_set_data (G_OBJECT (d), "chooser", w);
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (TrCoreClass, prefs_changed),
NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
+ g_cclosure_marshal_VOID__INT,
G_TYPE_NONE,
1, G_TYPE_STRING);
}
}
void
-gtr_core_pref_changed (TrCore * core, const char * key)
+gtr_core_pref_changed (TrCore * core, const tr_quark key)
{
g_signal_emit (core, signals[PREFS_SIGNAL], 0, key);
}
/* add the files that have stopped changing */
if (unchanging != NULL)
{
- const gboolean do_start = gtr_pref_flag_get (TR_PREFS_KEY_START);
- const gboolean do_prompt = gtr_pref_flag_get (PREF_KEY_OPTIONS_PROMPT);
+ const gboolean do_start = gtr_pref_flag_get (TR_KEY_start_added_torrents);
+ const gboolean do_prompt = gtr_pref_flag_get (TR_KEY_show_options_window);
core->priv->adding_from_watch_dir = TRUE;
gtr_core_add_files (core, unchanging, do_start, do_prompt, TRUE);
static void
core_watchdir_scan (TrCore * core)
{
- const char * dirname = gtr_pref_string_get (PREF_KEY_DIR_WATCH);
+ const char * dirname = gtr_pref_string_get (TR_KEY_watch_dir);
GDir * dir = g_dir_open (dirname, 0, NULL);
if (dir != NULL)
static void
core_watchdir_update (TrCore * core)
{
- const gboolean is_enabled = gtr_pref_flag_get (PREF_KEY_DIR_WATCH_ENABLED);
- GFile * dir = g_file_new_for_path (gtr_pref_string_get (PREF_KEY_DIR_WATCH));
+ const gboolean is_enabled = gtr_pref_flag_get (TR_KEY_watch_dir_enabled);
+ GFile * dir = g_file_new_for_path (gtr_pref_string_get (TR_KEY_watch_dir));
struct TrCorePrivate * p = core->priv;
if (p->monitor && (!is_enabled || !g_file_equal (dir, p->monitor_dir)))
***/
static void
-on_pref_changed (TrCore * core, const char * key, gpointer data UNUSED)
+on_pref_changed (TrCore * core, const tr_quark key, gpointer data UNUSED)
{
- if (!strcmp (key, PREF_KEY_SORT_MODE) ||
- !strcmp (key, PREF_KEY_SORT_REVERSED))
- {
- const char * mode = gtr_pref_string_get (PREF_KEY_SORT_MODE);
- gboolean is_reversed = gtr_pref_flag_get (PREF_KEY_SORT_REVERSED);
- core_set_sort_mode (core, mode, is_reversed);
- }
- else if (!strcmp (key, TR_PREFS_KEY_PEER_LIMIT_GLOBAL))
- {
- tr_sessionSetPeerLimit (gtr_core_session (core),
- gtr_pref_int_get (key));
- }
- else if (!strcmp (key, TR_PREFS_KEY_PEER_LIMIT_TORRENT))
- {
- tr_sessionSetPeerLimitPerTorrent (gtr_core_session (core),
- gtr_pref_int_get (key));
- }
- else if (!strcmp (key, PREF_KEY_INHIBIT_HIBERNATION))
- {
- core_maybe_inhibit_hibernation (core);
- }
- else if (!strcmp (key, PREF_KEY_DIR_WATCH)
- || !strcmp (key, PREF_KEY_DIR_WATCH_ENABLED))
+ switch (key)
{
- core_watchdir_update (core);
+ case TR_KEY_sort_mode:
+ case TR_KEY_sort_reversed:
+ {
+ const char * mode = gtr_pref_string_get (TR_KEY_sort_mode);
+ const gboolean is_reversed = gtr_pref_flag_get (TR_KEY_sort_reversed);
+ core_set_sort_mode (core, mode, is_reversed);
+ break;
+ }
+
+ case TR_KEY_peer_limit_global:
+ tr_sessionSetPeerLimit (gtr_core_session (core), gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_peer_limit_per_torrent:
+ tr_sessionSetPeerLimitPerTorrent (gtr_core_session (core), gtr_pref_int_get (key));
+ break;
+
+ case TR_KEY_inhibit_desktop_hibernation:
+ core_maybe_inhibit_hibernation (core);
+ break;
+
+ case TR_KEY_watch_dir:
+ case TR_KEY_watch_dir_enabled:
+ core_watchdir_update (core);
+ break;
+
+ default:
+ break;
}
}
core->priv->session = session;
/* init from prefs & listen to pref changes */
- on_pref_changed (core, PREF_KEY_SORT_MODE, NULL);
- on_pref_changed (core, PREF_KEY_SORT_REVERSED, NULL);
- on_pref_changed (core, PREF_KEY_DIR_WATCH_ENABLED, NULL);
- on_pref_changed (core, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, NULL);
- on_pref_changed (core, PREF_KEY_INHIBIT_HIBERNATION, NULL);
+ on_pref_changed (core, TR_KEY_sort_mode, NULL);
+ on_pref_changed (core, TR_KEY_sort_reversed, NULL);
+ on_pref_changed (core, TR_KEY_watch_dir_enabled, NULL);
+ on_pref_changed (core, TR_KEY_peer_limit_global, NULL);
+ on_pref_changed (core, TR_KEY_inhibit_desktop_hibernation, NULL);
g_signal_connect (core, "prefs-changed", G_CALLBACK (on_pref_changed), NULL);
return core;
core_apply_defaults (tr_ctor * ctor)
{
if (tr_ctorGetPaused (ctor, TR_FORCE, NULL))
- tr_ctorSetPaused (ctor, TR_FORCE, !gtr_pref_flag_get (TR_PREFS_KEY_START));
+ tr_ctorSetPaused (ctor, TR_FORCE, !gtr_pref_flag_get (TR_KEY_start_added_torrents));
if (tr_ctorGetDeleteSource (ctor, NULL))
- tr_ctorSetDeleteSource (ctor, gtr_pref_flag_get (TR_PREFS_KEY_TRASH_ORIGINAL));
+ tr_ctorSetDeleteSource (ctor, gtr_pref_flag_get (TR_KEY_trash_original_torrent_files));
if (tr_ctorGetPeerLimit (ctor, TR_FORCE, NULL))
- tr_ctorSetPeerLimit (ctor, TR_FORCE, gtr_pref_int_get (TR_PREFS_KEY_PEER_LIMIT_TORRENT));
+ tr_ctorSetPeerLimit (ctor, TR_FORCE, gtr_pref_int_get (TR_KEY_peer_limit_per_torrent));
if (tr_ctorGetDownloadDir (ctor, TR_FORCE, NULL))
- tr_ctorSetDownloadDir (ctor, TR_FORCE, gtr_pref_string_get (TR_PREFS_KEY_DOWNLOAD_DIR));
+ tr_ctorSetDownloadDir (ctor, TR_FORCE, gtr_pref_string_get (TR_KEY_download_dir));
}
void
gtr_core_add_ctor (TrCore * core, tr_ctor * ctor)
{
const gboolean do_notify = FALSE;
- const gboolean do_prompt = gtr_pref_flag_get (PREF_KEY_OPTIONS_PROMPT);
+ const gboolean do_prompt = gtr_pref_flag_get (TR_KEY_show_options_window);
core_apply_defaults (ctor);
core_add_ctor (core, ctor, do_prompt, do_notify);
}
gtr_core_add_from_url (TrCore * core, const char * uri)
{
bool handled;
- const bool do_start = gtr_pref_flag_get (TR_PREFS_KEY_START);
- const bool do_prompt = gtr_pref_flag_get (PREF_KEY_OPTIONS_PROMPT);
+ const bool do_start = gtr_pref_flag_get (TR_KEY_start_added_torrents);
+ const bool do_prompt = gtr_pref_flag_get (TR_KEY_show_options_window);
const bool do_notify = false;
GFile * file = g_file_new_for_uri (uri);
if (forcePaused)
tr_ctorSetPaused (ctor, TR_FORCE, TRUE);
tr_ctorSetPeerLimit (ctor, TR_FALLBACK,
- gtr_pref_int_get (TR_PREFS_KEY_PEER_LIMIT_TORRENT));
+ gtr_pref_int_get (TR_KEY_peer_limit_per_torrent));
torrents = tr_sessionLoadTorrents (gtr_core_session (self), ctor, &count);
for (i=0; i<count; ++i)
/* hibernation is allowed if EITHER
* (a) the "inhibit" pref is turned off OR
* (b) there aren't any active torrents */
- const gboolean hibernation_allowed = !gtr_pref_flag_get (PREF_KEY_INHIBIT_HIBERNATION)
+ const gboolean hibernation_allowed = !gtr_pref_flag_get (TR_KEY_inhibit_desktop_hibernation)
|| !gtr_core_get_active_torrent_count (core);
gtr_core_set_hibernation_allowed (core, hibernation_allowed);
}
**/
static void
-core_commit_prefs_change (TrCore * core, const char * key)
+core_commit_prefs_change (TrCore * core, const tr_quark key)
{
gtr_core_pref_changed (core, key);
gtr_pref_save (gtr_core_session (core));
}
void
-gtr_core_set_pref (TrCore * self, const char * key, const char * newval)
+gtr_core_set_pref (TrCore * self, const tr_quark key, const char * newval)
{
if (tr_strcmp0 (newval, gtr_pref_string_get (key)))
{
}
void
-gtr_core_set_pref_bool (TrCore * self, const char * key, gboolean newval)
+gtr_core_set_pref_bool (TrCore * self, const tr_quark key, gboolean newval)
{
if (newval != gtr_pref_flag_get (key))
{
}
void
-gtr_core_set_pref_int (TrCore * self, const char * key, int newval)
+gtr_core_set_pref_int (TrCore * self, const tr_quark key, int newval)
{
if (newval != gtr_pref_int_get (key))
{
}
void
-gtr_core_set_pref_double (TrCore * self, const char * key, double newval)
+gtr_core_set_pref_double (TrCore * self, const tr_quark key, double newval)
{
if (gtr_compare_double (newval, gtr_pref_double_get (key), 4))
{
tr_variantFromJson (&top, evbuffer_pullup (response, -1), evbuffer_get_length (response));
- if (tr_variantDictFindInt (&top, "tag", &intVal))
+ if (tr_variantDictFindInt (&top, TR_KEY_tag, &intVal))
{
const int tag = (int)intVal;
struct pending_request_data * data = g_hash_table_lookup (pendingRequests, &tag);
tr_variant * args;
bool is_open = FALSE;
- if (tr_variantDictFindDict (response, "arguments", &args))
- tr_variantDictFindBool (args, "port-is-open", &is_open);
+ if (tr_variantDictFindDict (response, TR_KEY_arguments, &args))
+ tr_variantDictFindBool (args, TR_KEY_port_is_open, &is_open);
core_emit_port_tested (core, is_open);
}
tr_variant * args;
int64_t ruleCount = -1;
- if (tr_variantDictFindDict (response, "arguments", &args))
- tr_variantDictFindInt (args, "blocklist-size", &ruleCount);
+ if (tr_variantDictFindDict (response, TR_KEY_arguments, &args))
+ tr_variantDictFindInt (args, TR_KEY_blocklist_size, &ruleCount);
if (ruleCount > 0)
- gtr_pref_int_set ("blocklist-date", tr_time ());
+ gtr_pref_int_set (TR_KEY_blocklist_date, tr_time ());
core_emit_blocklist_udpated (core, ruleCount);
}
void (* add_prompt) (TrCore*, gpointer ctor);
void (* blocklist_updated)(TrCore*, int ruleCount);
void (* busy) (TrCore*, gboolean is_busy);
- void (* prefs_changed) (TrCore*, const char* key);
+ void (* prefs_changed) (TrCore*, const tr_quark key);
void (* port_tested) (TrCore*, gboolean is_open);
void (* quit) (TrCore*);
}
tr_torrent * gtr_core_find_torrent (TrCore * core, int id);
-void gtr_core_pref_changed (TrCore * core, const char * key);
+void gtr_core_pref_changed (TrCore * core, const tr_quark key);
/******
*** Set a preference value, save the prefs file, and emit the "prefs-changed" signal
**/
-void gtr_core_set_pref (TrCore * self, const char * key, const char * val);
-void gtr_core_set_pref_bool (TrCore * self, const char * key, gboolean val);
-void gtr_core_set_pref_int (TrCore * self, const char * key, int val);
-void gtr_core_set_pref_double (TrCore * self, const char * key, double val);
+void gtr_core_set_pref (TrCore * self, const tr_quark key, const char * val);
+void gtr_core_set_pref_bool (TrCore * self, const tr_quark key, gboolean val);
+void gtr_core_set_pref_int (TrCore * self, const tr_quark key, int val);
+void gtr_core_set_pref_double (TrCore * self, const tr_quark key, double val);
/**
***
toggled_cb (GtkToggleButton * w,
gpointer core)
{
- const char * key = g_object_get_data (G_OBJECT (w), PREF_KEY);
+ const tr_quark key = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (w), PREF_KEY));
const gboolean flag = gtk_toggle_button_get_active (w);
gtr_core_set_pref_bool (TR_CORE (core), key, flag);
}
static GtkWidget*
-new_check_button (const char * mnemonic,
- const char * key,
- gpointer core)
+new_check_button (const char * mnemonic,
+ const tr_quark key,
+ gpointer core)
{
GtkWidget * w = gtk_check_button_new_with_mnemonic (mnemonic);
-
- g_object_set_data_full (G_OBJECT (w), PREF_KEY, g_strdup (
- key), g_free);
+ g_object_set_data (G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w),
gtr_pref_flag_get (key));
g_signal_connect (w, "toggled", G_CALLBACK (toggled_cb), core);
if (g_timer_elapsed (data->last_change, NULL) > 0.33f)
{
/* update the core */
- const char * key = g_object_get_data (o, PREF_KEY);
+ const tr_quark key = GPOINTER_TO_INT (g_object_get_data (o, PREF_KEY));
if (data->isDouble)
{
}
static GtkWidget*
-new_spin_button (const char * key,
- gpointer core,
- int low,
- int high,
- int step)
+new_spin_button (const tr_quark key,
+ gpointer core,
+ int low,
+ int high,
+ int step)
{
GtkWidget * w = gtk_spin_button_new_with_range (low, high, step);
- g_object_set_data_full (G_OBJECT (w), PREF_KEY, g_strdup (key), g_free);
+ g_object_set_data (G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (w), 0);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), gtr_pref_int_get (key));
g_signal_connect (w, "value-changed", G_CALLBACK (spun_cb_int), core);
}
static GtkWidget*
-new_spin_button_double (const char * key,
- gpointer core,
- double low,
- double high,
- double step)
+new_spin_button_double (const tr_quark key,
+ gpointer core,
+ double low,
+ double high,
+ double step)
{
GtkWidget * w = gtk_spin_button_new_with_range (low, high, step);
- g_object_set_data_full (G_OBJECT (w), PREF_KEY, g_strdup (key), g_free);
+ g_object_set_data (G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (w), 2);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), gtr_pref_double_get (key));
g_signal_connect (w, "value-changed", G_CALLBACK (spun_cb_double), core);
}
static void
-entry_changed_cb (GtkEntry * w, gpointer core)
+entry_changed_cb (GtkEntry * w, gpointer core)
{
- const char * key = g_object_get_data (G_OBJECT (w), PREF_KEY);
- const char * value = gtk_entry_get_text (w);
+ const tr_quark key = GPOINTER_TO_INT (g_object_get_data (G_OBJECT(w), PREF_KEY));
+ const char * value = gtk_entry_get_text (w);
- gtr_core_set_pref (TR_CORE (core), key, value);
+ gtr_core_set_pref (TR_CORE(core), key, value);
}
static GtkWidget*
-new_entry (const char * key,
- gpointer core)
+new_entry (const tr_quark key,
+ gpointer core)
{
- GtkWidget * w = gtk_entry_new ();
- const char * value = gtr_pref_string_get (key);
-
- if (value)
- gtk_entry_set_text (GTK_ENTRY (w), value);
- g_object_set_data_full (G_OBJECT (w), PREF_KEY, g_strdup (
- key), g_free);
- g_signal_connect (w, "changed", G_CALLBACK (entry_changed_cb), core);
- return w;
+ GtkWidget * w = gtk_entry_new ();
+ const char * value = gtr_pref_string_get (key);
+
+ if (value)
+ gtk_entry_set_text (GTK_ENTRY (w), value);
+
+ g_object_set_data (G_OBJECT (w), PREF_KEY, GINT_TO_POINTER(key));
+ g_signal_connect (w, "changed", G_CALLBACK (entry_changed_cb), core);
+ return w;
}
static void
chosen_cb (GtkFileChooser * w, gpointer core)
{
- const char * key = g_object_get_data (G_OBJECT (w), PREF_KEY);
- char * value = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (w));
- gtr_core_set_pref (TR_CORE (core), key, value);
- g_free (value);
+ const tr_quark key = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (w), PREF_KEY));
+ char * value = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (w));
+ gtr_core_set_pref (TR_CORE (core), key, value);
+ g_free (value);
}
static GtkWidget*
-new_path_chooser_button (const char * key, gpointer core)
+new_path_chooser_button (const tr_quark key, gpointer core)
{
- GtkWidget * w = gtk_file_chooser_button_new (NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
- const char * path = gtr_pref_string_get (key);
- g_object_set_data_full (G_OBJECT (w), PREF_KEY, g_strdup (key), g_free);
- g_signal_connect (w, "selection-changed", G_CALLBACK (chosen_cb), core);
- if (path != NULL)
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w), path);
- return w;
+ GtkWidget * w = gtk_file_chooser_button_new (NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+ const char * path = gtr_pref_string_get (key);
+ g_object_set_data (G_OBJECT (w), PREF_KEY, GINT_TO_POINTER(key));
+ g_signal_connect (w, "selection-changed", G_CALLBACK (chosen_cb), core);
+
+ if (path != NULL)
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w), path);
+
+ return w;
}
static GtkWidget*
-new_file_chooser_button (const char * key, gpointer core)
+new_file_chooser_button (const tr_quark key, gpointer core)
{
- GtkWidget * w = gtk_file_chooser_button_new (NULL, GTK_FILE_CHOOSER_ACTION_OPEN);
- const char * path = gtr_pref_string_get (key);
- g_object_set_data_full (G_OBJECT (w), PREF_KEY, g_strdup (key), g_free);
- if (path != NULL)
- gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (w), path);
- g_signal_connect (w, "selection-changed", G_CALLBACK (chosen_cb), core);
- return w;
+ GtkWidget * w = gtk_file_chooser_button_new (NULL, GTK_FILE_CHOOSER_ACTION_OPEN);
+ const char * path = gtr_pref_string_get (key);
+ g_object_set_data (G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
+ if (path != NULL)
+ gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (w), path);
+ g_signal_connect (w, "selection-changed", G_CALLBACK (chosen_cb), core);
+ return w;
}
static void
target_cb (GtkWidget * tb, gpointer target)
{
- const gboolean b = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tb));
+ const gboolean b = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tb));
- gtk_widget_set_sensitive (GTK_WIDGET (target), b);
+ gtk_widget_set_sensitive (GTK_WIDGET (target), b);
}
/****
hig_workarea_add_section_title (t, &row, _("Location"));
- w = new_path_chooser_button (TR_PREFS_KEY_DOWNLOAD_DIR, core);
+ w = new_path_chooser_button (TR_KEY_download_dir, core);
hig_workarea_add_row (t, &row, _("Save to _Location:"), w, NULL);
hig_workarea_add_section_divider (t, &row);
hig_workarea_add_section_title (t, &row, _("Queue"));
s = _("Maximum active _downloads:");
- w = new_spin_button (TR_PREFS_KEY_DOWNLOAD_QUEUE_SIZE, core, 0, INT_MAX, 1);
+ w = new_spin_button (TR_KEY_download_queue_size, core, 0, INT_MAX, 1);
hig_workarea_add_row (t, &row, s, w, NULL);
s = _("Downloads sharing data in the last N minutes are _active:");
- w = new_spin_button (TR_PREFS_KEY_QUEUE_STALLED_MINUTES, core, 1, INT_MAX, 15);
+ w = new_spin_button (TR_KEY_queue_stalled_minutes, core, 1, INT_MAX, 15);
hig_workarea_add_row (t, &row, s, w, NULL);
hig_workarea_add_section_divider (t, &row);
hig_workarea_add_section_title (t, &row, _("Incomplete"));
s = _("Append \"._part\" to incomplete files' names");
- w = new_check_button (s, TR_PREFS_KEY_RENAME_PARTIAL_FILES, core);
+ w = new_check_button (s, TR_KEY_rename_partial_files, core);
hig_workarea_add_wide_control (t, &row, w);
s = _("Keep _incomplete torrents in:");
- l = new_check_button (s, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, core);
- w = new_path_chooser_button (TR_PREFS_KEY_INCOMPLETE_DIR, core);
- gtk_widget_set_sensitive (GTK_WIDGET (w), gtr_pref_flag_get (TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED));
+ l = new_check_button (s, TR_KEY_incomplete_dir_enabled, core);
+ w = new_path_chooser_button (TR_KEY_incomplete_dir, core);
+ gtk_widget_set_sensitive (GTK_WIDGET (w), gtr_pref_flag_get (TR_KEY_incomplete_dir_enabled));
g_signal_connect (l, "toggled", G_CALLBACK (target_cb), w);
hig_workarea_add_row_w (t, &row, l, w, NULL);
s = _("Call _script when torrent is completed:");
- l = new_check_button (s, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, core);
- w = new_file_chooser_button (TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, core);
- gtk_widget_set_sensitive (GTK_WIDGET (w), gtr_pref_flag_get (TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED));
+ l = new_check_button (s, TR_KEY_script_torrent_done_enabled, core);
+ w = new_file_chooser_button (TR_KEY_script_torrent_done_filename, core);
+ gtk_widget_set_sensitive (GTK_WIDGET (w), gtr_pref_flag_get (TR_KEY_script_torrent_done_enabled));
g_signal_connect (l, "toggled", G_CALLBACK (target_cb), w);
hig_workarea_add_row_w (t, &row, l, w, NULL);
hig_workarea_add_section_title (t, &row, C_("Gerund", "Adding"));
s = _("_Start when added");
- w = new_check_button (s, TR_PREFS_KEY_START, core);
+ w = new_check_button (s, TR_KEY_start_added_torrents, core);
hig_workarea_add_wide_control (t, &row, w);
s = _("Show _options dialog");
- w = new_check_button (s, PREF_KEY_OPTIONS_PROMPT, core);
+ w = new_check_button (s, TR_KEY_show_options_window, core);
hig_workarea_add_wide_control (t, &row, w);
s = _("Mo_ve .torrent file to the trash");
- w = new_check_button (s, TR_PREFS_KEY_TRASH_ORIGINAL, core);
+ w = new_check_button (s, TR_KEY_trash_original_torrent_files, core);
hig_workarea_add_wide_control (t, &row, w);
s = _("Automatically _add torrents from:");
- l = new_check_button (s, PREF_KEY_DIR_WATCH_ENABLED, core);
- w = new_path_chooser_button (PREF_KEY_DIR_WATCH, core);
- gtk_widget_set_sensitive (GTK_WIDGET (w), gtr_pref_flag_get (PREF_KEY_DIR_WATCH_ENABLED));
+ l = new_check_button (s, TR_KEY_watch_dir_enabled, core);
+ w = new_path_chooser_button (TR_KEY_watch_dir, core);
+ gtk_widget_set_sensitive (GTK_WIDGET (w), gtr_pref_flag_get (TR_KEY_watch_dir_enabled));
g_signal_connect (l, "toggled", G_CALLBACK (target_cb), w);
hig_workarea_add_row_w (t, &row, l, w, NULL);
hig_workarea_add_section_title (t, &row, C_("Gerund", "Seeding"));
s = _("Stop seeding at _ratio:");
- w = new_check_button (s, TR_PREFS_KEY_RATIO_ENABLED, core);
- w2 = new_spin_button_double (TR_PREFS_KEY_RATIO, core, 0, 1000, .05);
- gtk_widget_set_sensitive (GTK_WIDGET (w2), gtr_pref_flag_get (TR_PREFS_KEY_RATIO_ENABLED));
+ w = new_check_button (s, TR_KEY_ratio_limit_enabled, core);
+ w2 = new_spin_button_double (TR_KEY_ratio_limit, core, 0, 1000, .05);
+ gtk_widget_set_sensitive (GTK_WIDGET (w2), gtr_pref_flag_get (TR_KEY_ratio_limit_enabled));
g_signal_connect (w, "toggled", G_CALLBACK (target_cb), w2);
hig_workarea_add_row_w (t, &row, w, w2, NULL);
s = _("Stop seeding if idle for _N minutes:");
- w = new_check_button (s, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, core);
- w2 = new_spin_button (TR_PREFS_KEY_IDLE_LIMIT, core, 1, 9999, 5);
- gtk_widget_set_sensitive (GTK_WIDGET (w2), gtr_pref_flag_get (TR_PREFS_KEY_IDLE_LIMIT_ENABLED));
+ w = new_check_button (s, TR_KEY_idle_seeding_limit_enabled, core);
+ w2 = new_spin_button (TR_KEY_idle_seeding_limit, core, 1, 9999, 5);
+ gtk_widget_set_sensitive (GTK_WIDGET (w2), gtr_pref_flag_get (TR_KEY_idle_seeding_limit_enabled));
g_signal_connect (w, "toggled", G_CALLBACK (target_cb), w2);
hig_workarea_add_row_w (t, &row, w, w2, NULL);
hig_workarea_add_section_title (t, &row, _("Desktop"));
s = _("_Inhibit hibernation when torrents are active");
- w = new_check_button (s, PREF_KEY_INHIBIT_HIBERNATION, core);
+ w = new_check_button (s, TR_KEY_inhibit_desktop_hibernation, core);
hig_workarea_add_wide_control (t, &row, w);
s = _("Show Transmission icon in the _notification area");
- w = new_check_button (s, PREF_KEY_SHOW_TRAY_ICON, core);
+ w = new_check_button (s, TR_KEY_show_notification_area_icon, core);
hig_workarea_add_wide_control (t, &row, w);
hig_workarea_add_section_divider (t, &row);
hig_workarea_add_section_title (t, &row, _("Notification"));
s = _("Show a notification when torrents are a_dded");
- w = new_check_button (s, PREF_KEY_TORRENT_ADDED_NOTIFICATION_ENABLED, core);
+ w = new_check_button (s, TR_KEY_torrent_added_notification_enabled, core);
hig_workarea_add_wide_control (t, &row, w);
s = _("Show a notification when torrents _finish");
- w = new_check_button (s, PREF_KEY_TORRENT_COMPLETE_NOTIFICATION_ENABLED, core);
+ w = new_check_button (s, TR_KEY_torrent_complete_notification_enabled, core);
hig_workarea_add_wide_control (t, &row, w);
s = _("Play a _sound when torrents finish");
- w = new_check_button (s, PREF_KEY_TORRENT_COMPLETE_SOUND_ENABLED, core);
+ w = new_check_button (s, TR_KEY_torrent_complete_sound_enabled, core);
hig_workarea_add_wide_control (t, &row, w);
return t;
static void
on_blocklist_url_changed (GtkEditable * e, gpointer gbutton)
{
- gchar * url = gtk_editable_get_chars (e, 0, -1);
- const gboolean err = tr_urlParse (url, -1, NULL, NULL, NULL, NULL);
- gtk_widget_set_sensitive (GTK_WIDGET (gbutton), !err);
- g_free (url);
+ gchar * url = gtk_editable_get_chars (e, 0, -1);
+ const gboolean err = tr_urlParse (url, -1, NULL, NULL, NULL, NULL);
+ gtk_widget_set_sensitive (GTK_WIDGET (gbutton), !err);
+ g_free (url);
}
static void
onIntComboChanged (GtkComboBox * combo_box, gpointer core)
{
- const int val = gtr_combo_box_get_active_enum (combo_box);
- const char * key = g_object_get_data (G_OBJECT (combo_box), PREF_KEY);
- gtr_core_set_pref_int (TR_CORE (core), key, val);
+ const int val = gtr_combo_box_get_active_enum (combo_box);
+ const tr_quark key = GPOINTER_TO_INT (g_object_get_data (G_OBJECT(combo_box), PREF_KEY));
+ gtr_core_set_pref_int (TR_CORE (core), key, val);
}
static GtkWidget*
-new_encryption_combo (GObject * core, const char * key)
+new_encryption_combo (GObject * core, const tr_quark key)
{
- GtkWidget * w = gtr_combo_box_new_enum (_("Allow encryption"), TR_CLEAR_PREFERRED,
- _("Prefer encryption"), TR_ENCRYPTION_PREFERRED,
- _("Require encryption"), TR_ENCRYPTION_REQUIRED,
- NULL);
- gtr_combo_box_set_active_enum (GTK_COMBO_BOX (w), gtr_pref_int_get (key));
- g_object_set_data_full (G_OBJECT (w), PREF_KEY, tr_strdup (key), g_free);
- g_signal_connect (w, "changed", G_CALLBACK (onIntComboChanged), core);
- return w;
+ GtkWidget * w = gtr_combo_box_new_enum (_("Allow encryption"), TR_CLEAR_PREFERRED,
+ _("Prefer encryption"), TR_ENCRYPTION_PREFERRED,
+ _("Require encryption"), TR_ENCRYPTION_REQUIRED,
+ NULL);
+ gtr_combo_box_set_active_enum (GTK_COMBO_BOX (w), gtr_pref_int_get (key));
+ g_object_set_data (G_OBJECT (w), PREF_KEY, GINT_TO_POINTER(key));
+ g_signal_connect (w, "changed", G_CALLBACK (onIntComboChanged), core);
+ return w;
}
static GtkWidget*
t = hig_workarea_create ();
hig_workarea_add_section_title (t, &row, _("Blocklist"));
- b = new_check_button (_("Enable _blocklist:"), TR_PREFS_KEY_BLOCKLIST_ENABLED, core);
- e = new_entry (TR_PREFS_KEY_BLOCKLIST_URL, core);
+ b = new_check_button (_("Enable _blocklist:"), TR_KEY_blocklist_enabled, core);
+ e = new_entry (TR_KEY_blocklist_url, core);
gtk_widget_set_size_request (e, 300, -1);
hig_workarea_add_row_w (t, &row, b, e, NULL);
data->check = b;
on_blocklist_url_changed (GTK_EDITABLE (e), data->updateBlocklistButton);
s = _("Enable _automatic updates");
- w = new_check_button (s, PREF_KEY_BLOCKLIST_UPDATES_ENABLED, core);
+ w = new_check_button (s, TR_KEY_blocklist_updates_enabled, core);
hig_workarea_add_wide_control (t, &row, w);
g_signal_connect (data->check, "toggled", G_CALLBACK (target_cb), w); target_cb (data->check, w);
hig_workarea_add_section_title (t, &row, _("Privacy"));
s = _("_Encryption mode:");
- w = new_encryption_combo (core, "encryption");
+ w = new_encryption_combo (core, TR_KEY_encryption);
hig_workarea_add_row (t, &row, s, w, NULL);
s = _("Use PE_X to find more peers");
- w = new_check_button (s, TR_PREFS_KEY_PEX_ENABLED, core);
+ w = new_check_button (s, TR_KEY_pex_enabled, core);
s = _("PEX is a tool for exchanging peer lists with the peers you're connected to.");
gtk_widget_set_tooltip_text (w, s);
hig_workarea_add_wide_control (t, &row, w);
s = _("Use _DHT to find more peers");
- w = new_check_button (s, TR_PREFS_KEY_DHT_ENABLED, core);
+ w = new_check_button (s, TR_KEY_dht_enabled, core);
s = _("DHT is a tool for finding peers without a tracker.");
gtk_widget_set_tooltip_text (w, s);
hig_workarea_add_wide_control (t, &row, w);
s = _("Use _Local Peer Discovery to find more peers");
- w = new_check_button (s, TR_PREFS_KEY_LPD_ENABLED, core);
+ w = new_check_button (s, TR_KEY_lpd_enabled, core);
s = _("LPD is a tool for finding peers on your local network.");
gtk_widget_set_tooltip_text (w, s);
hig_workarea_add_wide_control (t, &row, w);
g_string_truncate (gstr, gstr->len - 1); /* remove the trailing comma */
- gtr_core_set_pref (page->core, TR_PREFS_KEY_RPC_WHITELIST, gstr->str);
+ gtr_core_set_pref (page->core, TR_KEY_rpc_whitelist, gstr->str);
g_string_free (gstr, TRUE);
}
static void
onLaunchClutchCB (GtkButton * w UNUSED, gpointer data UNUSED)
{
- const int port = gtr_pref_int_get (TR_PREFS_KEY_RPC_PORT);
- char * uri = g_strdup_printf ("http://localhost:%d/", port);
+ char * uri;
+ const int port = gtr_pref_int_get (TR_KEY_rpc_port);
- gtr_open_uri (uri);
- g_free (uri);
+ uri = g_strdup_printf ("http://localhost:%d/", port);
+ gtr_open_uri (uri);
+ g_free (uri);
}
static void
/* "enabled" checkbutton */
s = _("_Enable web client");
- w = new_check_button (s, TR_PREFS_KEY_RPC_ENABLED, core);
+ w = new_check_button (s, TR_KEY_rpc_enabled, core);
page->rpc_tb = GTK_TOGGLE_BUTTON (w);
g_signal_connect (w, "clicked", G_CALLBACK (onRPCToggled), page);
h = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
hig_workarea_add_wide_control (t, &row, h);
/* port */
- w = new_spin_button (TR_PREFS_KEY_RPC_PORT, core, 0, USHRT_MAX, 1);
+ w = new_spin_button (TR_KEY_rpc_port, core, 0, USHRT_MAX, 1);
page->widgets = g_slist_prepend (page->widgets, w);
w = hig_workarea_add_row (t, &row, _("HTTP _port:"), w, NULL);
page->widgets = g_slist_prepend (page->widgets, w);
/* require authentication */
s = _("Use _authentication");
- w = new_check_button (s, TR_PREFS_KEY_RPC_AUTH_REQUIRED, core);
+ w = new_check_button (s, TR_KEY_rpc_authentication_required, core);
hig_workarea_add_wide_control (t, &row, w);
page->auth_tb = GTK_TOGGLE_BUTTON (w);
page->widgets = g_slist_prepend (page->widgets, w);
/* username */
s = _("_Username:");
- w = new_entry (TR_PREFS_KEY_RPC_USERNAME, core);
+ w = new_entry (TR_KEY_rpc_username, core);
page->auth_widgets = g_slist_prepend (page->auth_widgets, w);
w = hig_workarea_add_row (t, &row, s, w, NULL);
page->auth_widgets = g_slist_prepend (page->auth_widgets, w);
/* password */
s = _("Pass_word:");
- w = new_entry (TR_PREFS_KEY_RPC_PASSWORD, core);
+ w = new_entry (TR_KEY_rpc_password, core);
gtk_entry_set_visibility (GTK_ENTRY (w), FALSE);
page->auth_widgets = g_slist_prepend (page->auth_widgets, w);
w = hig_workarea_add_row (t, &row, s, w, NULL);
/* require authentication */
s = _("Only allow these IP a_ddresses to connect:");
- w = new_check_button (s, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, core);
+ w = new_check_button (s, TR_KEY_rpc_whitelist_enabled, core);
hig_workarea_add_wide_control (t, &row, w);
page->whitelist_tb = GTK_TOGGLE_BUTTON (w);
page->widgets = g_slist_prepend (page->widgets, w);
/* access control list */
{
- const char * val = gtr_pref_string_get (TR_PREFS_KEY_RPC_WHITELIST);
+ const char * val = gtr_pref_string_get (TR_KEY_rpc_whitelist);
GtkTreeModel * m = whitelist_tree_model_new (val);
GtkTreeViewColumn * c;
GtkCellRenderer * r;
struct BandwidthPage
{
- TrCore * core;
- GSList * sched_widgets;
+ TrCore * core;
+ GSList * sched_widgets;
};
static void
refreshSchedSensitivity (struct BandwidthPage * p)
{
- GSList * l;
- const gboolean sched_enabled = gtr_pref_flag_get (TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED);
+ GSList * l;
+ const gboolean sched_enabled = gtr_pref_flag_get (TR_KEY_alt_speed_time_enabled);
- for (l = p->sched_widgets; l != NULL; l = l->next)
- gtk_widget_set_sensitive (GTK_WIDGET (l->data), sched_enabled);
+ for (l=p->sched_widgets; l!=NULL; l=l->next)
+ gtk_widget_set_sensitive (GTK_WIDGET (l->data), sched_enabled);
}
static void
}
static void
-onTimeComboChanged (GtkComboBox * w,
- gpointer core)
+onTimeComboChanged (GtkComboBox * w, gpointer core)
{
- GtkTreeIter iter;
+ GtkTreeIter iter;
- if (gtk_combo_box_get_active_iter (w, &iter))
+ if (gtk_combo_box_get_active_iter (w, &iter))
{
- const char * key = g_object_get_data (G_OBJECT (w), PREF_KEY);
- int val = 0;
- gtk_tree_model_get (gtk_combo_box_get_model (
- w), &iter, 0, &val, -1);
- gtr_core_set_pref_int (TR_CORE (core), key, val);
+ int val = 0;
+ const tr_quark key = GPOINTER_TO_INT (g_object_get_data (G_OBJECT(w), PREF_KEY));
+ gtk_tree_model_get (gtk_combo_box_get_model(w), &iter, 0, &val, -1);
+ gtr_core_set_pref_int (TR_CORE(core), key, val);
}
}
static GtkWidget*
-new_time_combo (GObject * core,
- const char * key)
+new_time_combo (GObject * core, const tr_quark key)
{
- int val;
- int i;
- GtkWidget * w;
- GtkCellRenderer * r;
- GtkListStore * store;
-
- /* build a store at 15 minute intervals */
- store = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
- for (i = 0; i < 60 * 24; i += 15)
+ int val;
+ int i;
+ GtkWidget * w;
+ GtkCellRenderer * r;
+ GtkListStore * store;
+
+ /* build a store at 15 minute intervals */
+ store = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
+ for (i=0; i<60*24; i+=15)
{
- char buf[128];
- GtkTreeIter iter;
- struct tm tm;
- tm.tm_hour = i / 60;
- tm.tm_min = i % 60;
- tm.tm_sec = 0;
- strftime (buf, sizeof (buf), "%H:%M", &tm);
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter, 0, i, 1, buf, -1);
+ char buf[128];
+ GtkTreeIter iter;
+ struct tm tm;
+ tm.tm_hour = i / 60;
+ tm.tm_min = i % 60;
+ tm.tm_sec = 0;
+ strftime (buf, sizeof (buf), "%H:%M", &tm);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter, 0, i, 1, buf, -1);
}
- /* build the widget */
- w = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
- gtk_combo_box_set_wrap_width (GTK_COMBO_BOX (w), 4);
- r = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (w), r, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (
- w), r, "text", 1, NULL);
- g_object_set_data_full (G_OBJECT (w), PREF_KEY, tr_strdup (
- key), g_free);
- val = gtr_pref_int_get (key);
- gtk_combo_box_set_active (GTK_COMBO_BOX (w), val / (15));
- g_signal_connect (w, "changed", G_CALLBACK (onTimeComboChanged), core);
-
- /* cleanup */
- g_object_unref (G_OBJECT (store));
- return w;
+ /* build the widget */
+ w = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
+ gtk_combo_box_set_wrap_width (GTK_COMBO_BOX (w), 4);
+ r = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (w), r, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (w), r, "text", 1, NULL);
+ g_object_set_data (G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
+ val = gtr_pref_int_get (key);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (w), val / (15));
+ g_signal_connect (w, "changed", G_CALLBACK (onTimeComboChanged), core);
+
+ /* cleanup */
+ g_object_unref (G_OBJECT (store));
+ return w;
}
static GtkWidget*
-new_week_combo (GObject * core, const char * key)
+new_week_combo (GObject * core, const tr_quark key)
{
- GtkWidget * w = gtr_combo_box_new_enum (_("Every Day"), TR_SCHED_ALL,
- _("Weekdays"), TR_SCHED_WEEKDAY,
- _("Weekends"), TR_SCHED_WEEKEND,
- _("Sunday"), TR_SCHED_SUN,
- _("Monday"), TR_SCHED_MON,
- _("Tuesday"), TR_SCHED_TUES,
- _("Wednesday"), TR_SCHED_WED,
- _("Thursday"), TR_SCHED_THURS,
- _("Friday"), TR_SCHED_FRI,
- _("Saturday"), TR_SCHED_SAT,
- NULL);
- gtr_combo_box_set_active_enum (GTK_COMBO_BOX (w), gtr_pref_int_get (key));
- g_object_set_data_full (G_OBJECT (w), PREF_KEY, tr_strdup (key), g_free);
- g_signal_connect (w, "changed", G_CALLBACK (onIntComboChanged), core);
- return w;
+ GtkWidget * w = gtr_combo_box_new_enum (_("Every Day"), TR_SCHED_ALL,
+ _("Weekdays"), TR_SCHED_WEEKDAY,
+ _("Weekends"), TR_SCHED_WEEKEND,
+ _("Sunday"), TR_SCHED_SUN,
+ _("Monday"), TR_SCHED_MON,
+ _("Tuesday"), TR_SCHED_TUES,
+ _("Wednesday"), TR_SCHED_WED,
+ _("Thursday"), TR_SCHED_THURS,
+ _("Friday"), TR_SCHED_FRI,
+ _("Saturday"), TR_SCHED_SAT,
+ NULL);
+ gtr_combo_box_set_active_enum (GTK_COMBO_BOX (w), gtr_pref_int_get (key));
+ g_object_set_data (G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
+ g_signal_connect (w, "changed", G_CALLBACK (onIntComboChanged), core);
+ return w;
}
static void
hig_workarea_add_section_title (t, &row, _("Speed Limits"));
g_snprintf (buf, sizeof (buf), _("_Upload (%s):"), _ (speed_K_str));
- w = new_check_button (buf, TR_PREFS_KEY_USPEED_ENABLED, core);
- w2 = new_spin_button (TR_PREFS_KEY_USPEED_KBps, core, 0, INT_MAX, 5);
- gtk_widget_set_sensitive (GTK_WIDGET (w2), gtr_pref_flag_get (TR_PREFS_KEY_USPEED_ENABLED));
+ w = new_check_button (buf, TR_KEY_speed_limit_up_enabled, core);
+ w2 = new_spin_button (TR_KEY_speed_limit_up, core, 0, INT_MAX, 5);
+ gtk_widget_set_sensitive (GTK_WIDGET (w2), gtr_pref_flag_get (TR_KEY_speed_limit_up_enabled));
g_signal_connect (w, "toggled", G_CALLBACK (target_cb), w2);
hig_workarea_add_row_w (t, &row, w, w2, NULL);
g_snprintf (buf, sizeof (buf), _("_Download (%s):"), _ (speed_K_str));
- w = new_check_button (buf, TR_PREFS_KEY_DSPEED_ENABLED, core);
- w2 = new_spin_button (TR_PREFS_KEY_DSPEED_KBps, core, 0, INT_MAX, 5);
- gtk_widget_set_sensitive (GTK_WIDGET (w2), gtr_pref_flag_get (TR_PREFS_KEY_DSPEED_ENABLED));
+ w = new_check_button (buf, TR_KEY_speed_limit_down_enabled, core);
+ w2 = new_spin_button (TR_KEY_speed_limit_down, core, 0, INT_MAX, 5);
+ gtk_widget_set_sensitive (GTK_WIDGET (w2), gtr_pref_flag_get (TR_KEY_speed_limit_down_enabled));
g_signal_connect (w, "toggled", G_CALLBACK (target_cb), w2);
hig_workarea_add_row_w (t, &row, w, w2, NULL);
hig_workarea_add_wide_control (t, &row, w);
g_snprintf (buf, sizeof (buf), _("U_pload (%s):"), _ (speed_K_str));
- w = new_spin_button (TR_PREFS_KEY_ALT_SPEED_UP_KBps, core, 0, INT_MAX, 5);
+ w = new_spin_button (TR_KEY_alt_speed_up, core, 0, INT_MAX, 5);
hig_workarea_add_row (t, &row, buf, w, NULL);
g_snprintf (buf, sizeof (buf), _("Do_wnload (%s):"), _ (speed_K_str));
- w = new_spin_button (TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, core, 0, INT_MAX, 5);
+ w = new_spin_button (TR_KEY_alt_speed_down, core, 0, INT_MAX, 5);
hig_workarea_add_row (t, &row, buf, w, NULL);
s = _("_Scheduled times:");
h = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- w2 = new_time_combo (core, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN);
+ w2 = new_time_combo (core, TR_KEY_alt_speed_time_begin);
page->sched_widgets = g_slist_prepend (page->sched_widgets, w2);
gtk_box_pack_start (GTK_BOX (h), w2, TRUE, TRUE, 0);
w2 = l = gtk_label_new_with_mnemonic (_(" _to "));
page->sched_widgets = g_slist_prepend (page->sched_widgets, w2);
gtk_box_pack_start (GTK_BOX (h), w2, FALSE, FALSE, 0);
- w2 = new_time_combo (core, TR_PREFS_KEY_ALT_SPEED_TIME_END);
+ w2 = new_time_combo (core, TR_KEY_alt_speed_time_end);
gtk_label_set_mnemonic_widget (GTK_LABEL (l), w2);
page->sched_widgets = g_slist_prepend (page->sched_widgets, w2);
gtk_box_pack_start (GTK_BOX (h), w2, TRUE, TRUE, 0);
- w = new_check_button (s, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, core);
+ w = new_check_button (s, TR_KEY_alt_speed_time_enabled, core);
g_signal_connect (w, "toggled", G_CALLBACK (onSchedToggled), page);
hig_workarea_add_row_w (t, &row, w, h, NULL);
s = _("_On days:");
- w = new_week_combo (core, TR_PREFS_KEY_ALT_SPEED_TIME_DAY);
+ w = new_week_combo (core, TR_KEY_alt_speed_time_day);
page->sched_widgets = g_slist_prepend (page->sched_widgets, w);
w = hig_workarea_add_row (t, &row, s, w, NULL);
page->sched_widgets = g_slist_prepend (page->sched_widgets, w);
};
static void
-onCorePrefsChanged (TrCore * core UNUSED, const char * key, gpointer gdata)
+onCorePrefsChanged (TrCore * core UNUSED, const tr_quark key, gpointer gdata)
{
- if (!strcmp (key, TR_PREFS_KEY_PEER_PORT))
+ if (key == TR_KEY_peer_port)
{
struct network_page_data * data = gdata;
gdk_threads_enter ();
struct network_page_data * data = vdata;
const char * markup = isOpen ? _("Port is <b>open</b>") : _("Port is <b>closed</b>");
- gdk_threads_enter ();
+ //gdk_threads_enter ();
gtk_label_set_markup (GTK_LABEL (data->portLabel), markup);
gtk_widget_set_sensitive (data->portButton, TRUE);
gtk_widget_set_sensitive (data->portSpin, TRUE);
- gdk_threads_leave ();
+ //gdk_threads_leave ();
}
static void
hig_workarea_add_section_title (t, &row, _("Listening Port"));
s = _("_Port used for incoming connections:");
- w = data->portSpin = new_spin_button (TR_PREFS_KEY_PEER_PORT, core, 1, USHRT_MAX, 1);
+ w = data->portSpin = new_spin_button (TR_KEY_peer_port, core, 1, USHRT_MAX, 1);
hig_workarea_add_row (t, &row, s, w, NULL);
h = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
g_object_weak_ref (G_OBJECT (t), networkPageDestroyed, data);
s = _("Pick a _random port every time Transmission is started");
- w = new_check_button (s, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, core);
+ w = new_check_button (s, TR_KEY_peer_port_random_on_start, core);
hig_workarea_add_wide_control (t, &row, w);
s = _("Use UPnP or NAT-PMP port _forwarding from my router");
- w = new_check_button (s, TR_PREFS_KEY_PORT_FORWARDING, core);
+ w = new_check_button (s, TR_KEY_port_forwarding_enabled, core);
hig_workarea_add_wide_control (t, &row, w);
hig_workarea_add_section_divider (t, &row);
hig_workarea_add_section_title (t, &row, _("Peer Limits"));
- w = new_spin_button (TR_PREFS_KEY_PEER_LIMIT_TORRENT, core, 1, FD_SETSIZE, 5);
+ w = new_spin_button (TR_KEY_peer_limit_per_torrent, core, 1, FD_SETSIZE, 5);
hig_workarea_add_row (t, &row, _("Maximum peers per _torrent:"), w, NULL);
- w = new_spin_button (TR_PREFS_KEY_PEER_LIMIT_GLOBAL, core, 1, FD_SETSIZE, 5);
+ w = new_spin_button (TR_KEY_peer_limit_global, core, 1, FD_SETSIZE, 5);
hig_workarea_add_row (t, &row, _("Maximum peers _overall:"), w, NULL);
hig_workarea_add_section_divider (t, &row);
#ifdef WITH_UTP
s = _("Enable _uTP for peer communication");
- w = new_check_button (s, TR_PREFS_KEY_UTP_ENABLED, core);
+ w = new_check_button (s, TR_KEY_utp_enabled, core);
s = _("uTP is a tool for reducing network congestion.");
gtk_widget_set_tooltip_text (w, s);
hig_workarea_add_wide_control (t, &row, w);
static void syncAltSpeedButton (PrivateData * p);
static void
-prefsChanged (TrCore * core UNUSED,
- const char * key,
- gpointer wind)
+prefsChanged (TrCore * core UNUSED,
+ const tr_quark key,
+ gpointer wind)
{
+ gboolean isEnabled;
PrivateData * p = get_private_data (GTK_WINDOW (wind));
- if (!strcmp (key, PREF_KEY_COMPACT_VIEW))
+ switch (key)
{
- g_object_set (p->renderer, "compact", gtr_pref_flag_get (key), NULL);
- /* since the cell size has changed, we need gtktreeview to revalidate
- * its fixed-height mode values. Unfortunately there's not an API call
- * for that, but it *does* revalidate when it thinks the style's been tweaked */
- g_signal_emit_by_name (p->view, "style-updated", NULL, NULL);
- }
- else if (!strcmp (key, PREF_KEY_STATUSBAR))
- {
- const gboolean isEnabled = gtr_pref_flag_get (key);
- g_object_set (p->status, "visible", isEnabled, NULL);
- }
- else if (!strcmp (key, PREF_KEY_FILTERBAR))
- {
- const gboolean isEnabled = gtr_pref_flag_get (key);
- g_object_set (p->filter, "visible", isEnabled, NULL);
- }
- else if (!strcmp (key, PREF_KEY_TOOLBAR))
- {
- const gboolean isEnabled = gtr_pref_flag_get (key);
- g_object_set (p->toolbar, "visible", isEnabled, NULL);
- }
- else if (!strcmp (key, PREF_KEY_STATUSBAR_STATS))
- {
- gtr_window_refresh (wind);
- }
- else if (!strcmp (key, TR_PREFS_KEY_ALT_SPEED_ENABLED) ||
- !strcmp (key, TR_PREFS_KEY_ALT_SPEED_UP_KBps) ||
- !strcmp (key, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps))
- {
- syncAltSpeedButton (p);
+ case TR_KEY_compact_view:
+ g_object_set (p->renderer, "compact", gtr_pref_flag_get (key), NULL);
+ /* since the cell size has changed, we need gtktreeview to revalidate
+ * its fixed-height mode values. Unfortunately there's not an API call
+ * for that, but it *does* revalidate when it thinks the style's been tweaked */
+ g_signal_emit_by_name (p->view, "style-updated", NULL, NULL);
+ break;
+
+ case TR_KEY_show_statusbar:
+ isEnabled = gtr_pref_flag_get (key);
+ g_object_set (p->status, "visible", isEnabled, NULL);
+ break;
+
+ case TR_KEY_show_filterbar:
+ isEnabled = gtr_pref_flag_get (key);
+ g_object_set (p->filter, "visible", isEnabled, NULL);
+ break;
+
+ case TR_KEY_show_toolbar:
+ isEnabled = gtr_pref_flag_get (key);
+ g_object_set (p->toolbar, "visible", isEnabled, NULL);
+ break;
+
+ case TR_KEY_statusbar_stats:
+ gtr_window_refresh (wind);
+ break;
+
+ case TR_KEY_alt_speed_enabled:
+ case TR_KEY_alt_speed_up:
+ case TR_KEY_alt_speed_down:
+ syncAltSpeedButton (p);
+ break;
+
+ default:
+ break;
}
}
{
PrivateData * p = vprivate;
const char * val = g_object_get_data (G_OBJECT (menu_item), STATS_MODE);
- gtr_core_set_pref (p->core, PREF_KEY_STATUSBAR_STATS, val);
+ gtr_core_set_pref (p->core, TR_KEY_statusbar_stats, val);
}
}
char d[32];
char * str;
const char * fmt;
- const gboolean b = gtr_pref_flag_get (TR_PREFS_KEY_ALT_SPEED_ENABLED);
+ const gboolean b = gtr_pref_flag_get (TR_KEY_alt_speed_enabled);
const char * stock = b ? "alt-speed-on" : "alt-speed-off";
GtkWidget * w = p->alt_speed_button;
- tr_formatter_speed_KBps (u, gtr_pref_int_get (TR_PREFS_KEY_ALT_SPEED_UP_KBps), sizeof (u));
- tr_formatter_speed_KBps (d, gtr_pref_int_get (TR_PREFS_KEY_ALT_SPEED_DOWN_KBps), sizeof (d));
+ tr_formatter_speed_KBps (u, gtr_pref_int_get (TR_KEY_alt_speed_up), sizeof (u));
+ tr_formatter_speed_KBps (d, gtr_pref_int_get (TR_KEY_alt_speed_down), sizeof (d));
fmt = b ? _("Click to disable Alternative Speed Limits\n (%1$s down, %2$s up)")
: _("Click to enable Alternative Speed Limits\n (%1$s down, %2$s up)");
str = g_strdup_printf (fmt, d, u);
{
PrivateData * p = vprivate;
const gboolean b = gtk_toggle_button_get_active (button);
- gtr_core_set_pref_bool (p->core, TR_PREFS_KEY_ALT_SPEED_ENABLED, b);
+ gtr_core_set_pref_bool (p->core, TR_KEY_alt_speed_enabled, b);
}
/***
{
PrivateData * p = vp;
gboolean b = tr_sessionUsesAltSpeed (gtr_core_session (p->core));
- gtr_core_set_pref_bool (p->core, TR_PREFS_KEY_ALT_SPEED_ENABLED, b);
+ gtr_core_set_pref_bool (p->core, TR_KEY_alt_speed_enabled, b);
return FALSE;
}
GObject * o = G_OBJECT (check);
gboolean isEnabled = g_object_get_data (o, ENABLED_KEY) != 0;
tr_direction dir = GPOINTER_TO_INT (g_object_get_data (o, DIRECTION_KEY));
- const char * key = dir == TR_UP ? TR_PREFS_KEY_USPEED_ENABLED
- : TR_PREFS_KEY_DSPEED_ENABLED;
+ const tr_quark key = dir == TR_UP ? TR_KEY_speed_limit_up_enabled
+ : TR_KEY_speed_limit_down_enabled;
if (gtk_check_menu_item_get_active (check))
gtr_core_set_pref_bool (p->core, key, isEnabled);
static void
onSpeedSet (GtkCheckMenuItem * check, gpointer vp)
{
- const char * key;
+ tr_quark key;
PrivateData * p = vp;
GObject * o = G_OBJECT (check);
const int KBps = GPOINTER_TO_INT (g_object_get_data (o, SPEED_KEY));
tr_direction dir = GPOINTER_TO_INT (g_object_get_data (o, DIRECTION_KEY));
- key = dir==TR_UP ? TR_PREFS_KEY_USPEED_KBps : TR_PREFS_KEY_DSPEED_KBps;
+ key = dir==TR_UP ? TR_KEY_speed_limit_up : TR_KEY_speed_limit_down;
gtr_core_set_pref_int (p->core, key, KBps);
- key = dir==TR_UP ? TR_PREFS_KEY_USPEED_ENABLED : TR_PREFS_KEY_DSPEED_ENABLED;
+ key = dir==TR_UP ? TR_KEY_speed_limit_up_enabled : TR_KEY_speed_limit_down_enabled;
gtr_core_set_pref_bool (p->core, key, TRUE);
}
if (gtk_check_menu_item_get_active (check))
{
gboolean f = g_object_get_data (G_OBJECT (check), ENABLED_KEY) != 0;
- gtr_core_set_pref_bool (p->core, TR_PREFS_KEY_RATIO_ENABLED, f);
+ gtr_core_set_pref_bool (p->core, TR_KEY_ratio_limit_enabled, f);
}
}
static void
PrivateData * p = vp;
int i = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (check), RATIO_KEY));
const double ratio = stockRatios[i];
- gtr_core_set_pref_double (p->core, TR_PREFS_KEY_RATIO, ratio);
- gtr_core_set_pref_bool (p->core, TR_PREFS_KEY_RATIO_ENABLED, TRUE);
+ gtr_core_set_pref_double (p->core, TR_KEY_ratio_limit, ratio);
+ gtr_core_set_pref_bool (p->core, TR_KEY_ratio_limit_enabled, TRUE);
}
static GtkWidget*
PrivateData * p = vp;
w = p->speedlimit_on_item[TR_DOWN];
- tr_formatter_speed_KBps (buf1, gtr_pref_int_get (TR_PREFS_KEY_DSPEED_KBps), sizeof (buf1));
+ tr_formatter_speed_KBps (buf1, gtr_pref_int_get (TR_KEY_speed_limit_down), sizeof (buf1));
gtr_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (w))), buf1);
- b = gtr_pref_flag_get (TR_PREFS_KEY_DSPEED_ENABLED);
+ b = gtr_pref_flag_get (TR_KEY_speed_limit_down_enabled);
w = b ? p->speedlimit_on_item[TR_DOWN] : p->speedlimit_off_item[TR_DOWN];
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), TRUE);
w = p->speedlimit_on_item[TR_UP];
- tr_formatter_speed_KBps (buf1, gtr_pref_int_get (TR_PREFS_KEY_USPEED_KBps), sizeof (buf1));
+ tr_formatter_speed_KBps (buf1, gtr_pref_int_get (TR_KEY_speed_limit_up), sizeof (buf1));
gtr_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (w))), buf1);
- b = gtr_pref_flag_get (TR_PREFS_KEY_USPEED_ENABLED);
+ b = gtr_pref_flag_get (TR_KEY_speed_limit_up_enabled);
w = b ? p->speedlimit_on_item[TR_UP] : p->speedlimit_off_item[TR_UP];
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w), TRUE);
- tr_strlratio (buf1, gtr_pref_double_get (TR_PREFS_KEY_RATIO), sizeof (buf1));
+ tr_strlratio (buf1, gtr_pref_double_get (TR_KEY_ratio_limit), sizeof (buf1));
g_snprintf (buf2, sizeof (buf2), _("Stop at Ratio (%s)"), buf1);
gtr_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (p->ratio_on_item))), buf2);
- b = gtr_pref_flag_get (TR_PREFS_KEY_RATIO_ENABLED);
+ b = gtr_pref_flag_get (TR_KEY_ratio_limit_enabled);
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (b ? p->ratio_on_item : p->ratio_off_item), TRUE);
gtk_menu_popup (GTK_MENU (p->options_menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
gtk_window_set_title (win, g_get_application_name ());
gtk_window_set_role (win, "tr-main");
gtk_window_set_default_size (win,
- gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_WIDTH),
- gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_HEIGHT));
- gtk_window_move (win, gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_X),
- gtr_pref_int_get (PREF_KEY_MAIN_WINDOW_Y));
- if (gtr_pref_flag_get (PREF_KEY_MAIN_WINDOW_IS_MAXIMIZED))
+ gtr_pref_int_get (TR_KEY_main_window_width),
+ gtr_pref_int_get (TR_KEY_main_window_height));
+ gtk_window_move (win, gtr_pref_int_get (TR_KEY_main_window_x),
+ gtr_pref_int_get (TR_KEY_main_window_y));
+ if (gtr_pref_flag_get (TR_KEY_main_window_is_maximized))
gtk_window_maximize (win);
gtk_window_add_accel_group (win, gtk_ui_manager_get_accel_group (ui_mgr));
/* status menu */
menu = p->status_menu = gtk_menu_new ();
l = NULL;
- pch = gtr_pref_string_get (PREF_KEY_STATUSBAR_STATS);
+ pch = gtr_pref_string_get (TR_KEY_statusbar_stats);
for (i=0, n=G_N_ELEMENTS (stats_modes); i<n; ++i)
{
const char * val = stats_modes[i].val;
/* listen for prefs changes that affect the window */
p->core = core;
- prefsChanged (core, PREF_KEY_COMPACT_VIEW, self);
- prefsChanged (core, PREF_KEY_FILTERBAR, self);
- prefsChanged (core, PREF_KEY_STATUSBAR, self);
- prefsChanged (core, PREF_KEY_STATUSBAR_STATS, self);
- prefsChanged (core, PREF_KEY_TOOLBAR, self);
- prefsChanged (core, TR_PREFS_KEY_ALT_SPEED_ENABLED, self);
+ prefsChanged (core, TR_KEY_compact_view, self);
+ prefsChanged (core, TR_KEY_show_filterbar, self);
+ prefsChanged (core, TR_KEY_show_statusbar, self);
+ prefsChanged (core, TR_KEY_statusbar_stats, self);
+ prefsChanged (core, TR_KEY_show_toolbar, self);
+ prefsChanged (core, TR_KEY_alt_speed_enabled, self);
p->pref_handler_id = g_signal_connect (core, "prefs-changed",
G_CALLBACK (prefsChanged), self);
tr_session * session = gtr_core_session (p->core);
/* update the stats */
- pch = gtr_pref_string_get (PREF_KEY_STATUSBAR_STATS);
+ pch = gtr_pref_string_get (TR_KEY_statusbar_stats);
if (!strcmp (pch, "session-ratio"))
{
tr_sessionGetStats (session, &stats);
int
gtr_file_trash_or_remove (const char * filename)
{
- GFile * file;
- gboolean trashed = FALSE;
+ GFile * file;
+ gboolean trashed = FALSE;
- g_return_val_if_fail (filename && *filename, 0);
+ g_return_val_if_fail (filename && *filename, 0);
- file = g_file_new_for_path (filename);
+ file = g_file_new_for_path (filename);
- if (gtr_pref_flag_get (PREF_KEY_TRASH_CAN_ENABLED)) {
- GError * err = NULL;
- trashed = g_file_trash (file, NULL, &err);
- if (err) {
- g_message ("Unable to trash file \"%s\": %s", filename, err->message);
- g_clear_error (&err);
+ if (gtr_pref_flag_get (TR_KEY_trash_can_enabled))
+ {
+ GError * err = NULL;
+ trashed = g_file_trash (file, NULL, &err);
+ if (err)
+ {
+ g_message ("Unable to trash file \"%s\": %s", filename, err->message);
+ g_clear_error (&err);
}
}
- if (!trashed) {
- GError * err = NULL;
- g_file_delete (file, NULL, &err);
- if (err) {
- g_message ("Unable to delete file \"%s\": %s", filename, err->message);
- g_clear_error (&err);
+ if (!trashed)
+ {
+ GError * err = NULL;
+ g_file_delete (file, NULL, &err);
+ if (err)
+ {
+ g_message ("Unable to delete file \"%s\": %s", filename, err->message);
+ g_clear_error (&err);
}
}
- g_object_unref (G_OBJECT (file));
- return 0;
+ g_object_unref (G_OBJECT (file));
+ return 0;
}
const char*
platform.c \
port-forwarding.c \
ptrarray.c \
+ quark.c \
resume.c \
rpcimpl.c \
rpc-server.c \
platform.h \
port-forwarding.h \
ptrarray.h \
+ quark.h \
resume.h \
rpcimpl.h \
rpc-server.h \
magnet-test \
metainfo-test \
peer-msgs-test \
+ quark-test \
rpc-test \
test-peer-id \
utils-test \
json_test_LDADD = ${apps_ldadd}
json_test_LDFLAGS = ${apps_ldflags}
+quark_test_SOURCES = quark-test.c $(TEST_SOURCES)
+quark_test_LDADD = ${apps_ldadd}
+quark_test_LDFLAGS = ${apps_ldflags}
+
magnet_test_SOURCES = magnet-test.c $(TEST_SOURCES)
magnet_test_LDADD = ${apps_ldadd}
magnet_test_LDFLAGS = ${apps_ldflags}
if (peer == NULL)
continue;
- if (!tr_variantDictFindStr (peer, "ip", &ip, NULL))
+ if (!tr_variantDictFindStr (peer, TR_KEY_ip, &ip, NULL))
continue;
if (!tr_address_from_string (&addr, ip))
continue;
- if (!tr_variantDictFindInt (peer, "port", &port))
+ if (!tr_variantDictFindInt (peer, TR_KEY_port, &port))
continue;
if ((port < 0) || (port > USHRT_MAX))
continue;
const char * str;
const uint8_t * raw;
- if (tr_variantDictFindStr (&benc, "failure reason", &str, &len))
+ if (tr_variantDictFindStr (&benc, TR_KEY_failure_reason, &str, &len))
response->errmsg = tr_strndup (str, len);
- if (tr_variantDictFindStr (&benc, "warning message", &str, &len))
+ if (tr_variantDictFindStr (&benc, TR_KEY_warning_message, &str, &len))
response->warning = tr_strndup (str, len);
- if (tr_variantDictFindInt (&benc, "interval", &i))
+ if (tr_variantDictFindInt (&benc, TR_KEY_interval, &i))
response->interval = i;
- if (tr_variantDictFindInt (&benc, "min interval", &i))
+ if (tr_variantDictFindInt (&benc, TR_KEY_min_interval, &i))
response->min_interval = i;
- if (tr_variantDictFindStr (&benc, "tracker id", &str, &len))
+ if (tr_variantDictFindStr (&benc, TR_KEY_tracker_id, &str, &len))
response->tracker_id_str = tr_strndup (str, len);
- if (tr_variantDictFindInt (&benc, "complete", &i))
+ if (tr_variantDictFindInt (&benc, TR_KEY_complete, &i))
response->seeders = i;
- if (tr_variantDictFindInt (&benc, "incomplete", &i))
+ if (tr_variantDictFindInt (&benc, TR_KEY_incomplete, &i))
response->leechers = i;
- if (tr_variantDictFindInt (&benc, "downloaded", &i))
+ if (tr_variantDictFindInt (&benc, TR_KEY_downloaded, &i))
response->downloads = i;
- if (tr_variantDictFindRaw (&benc, "peers6", &raw, &len)) {
+ if (tr_variantDictFindRaw (&benc, TR_KEY_peers6, &raw, &len)) {
dbgmsg (data->log_name, "got a peers6 length of %zu", len);
response->pex6 = tr_peerMgrCompact6ToPex (raw, len,
NULL, 0, &response->pex6_count);
}
- if (tr_variantDictFindRaw (&benc, "peers", &raw, &len)) {
+ if (tr_variantDictFindRaw (&benc, TR_KEY_peers, &raw, &len)) {
dbgmsg (data->log_name, "got a compact peers length of %zu", len);
response->pex = tr_peerMgrCompactToPex (raw, len,
NULL, 0, &response->pex_count);
- } else if (tr_variantDictFindList (&benc, "peers", &tmp)) {
+ } else if (tr_variantDictFindList (&benc, TR_KEY_peers, &tmp)) {
response->pex = listToPex (tmp, &response->pex_count);
dbgmsg (data->log_name, "got a peers list with %zu entries",
response->pex_count);
if (variant_loaded)
{
- if (tr_variantDictFindStr (&top, "failure reason", &str, &len))
+ if (tr_variantDictFindStr (&top, TR_KEY_failure_reason, &str, &len))
response->errmsg = tr_strndup (str, len);
- if (tr_variantDictFindDict (&top, "flags", &flags))
- if (tr_variantDictFindInt (flags, "min_request_interval", &intVal))
+ if (tr_variantDictFindDict (&top, TR_KEY_flags, &flags))
+ if (tr_variantDictFindInt (flags, TR_KEY_min_request_interval, &intVal))
response->min_request_interval = intVal;
- if (tr_variantDictFindDict (&top, "files", &files))
+ if (tr_variantDictFindDict (&top, TR_KEY_files, &files))
{
int i = 0;
for (;;)
{
int j;
+ tr_quark key;
tr_variant * val;
- const char * key;
/* get the next "file" */
if (!tr_variantDictChild (files, i++, &key, &val))
for (j=0; j<response->row_count; ++j)
{
struct tr_scrape_response_row * row = &response->rows[j];
- if (!memcmp (key, row->info_hash, SHA_DIGEST_LENGTH))
+ if (!memcmp (tr_quark_get_string(key,NULL), row->info_hash, SHA_DIGEST_LENGTH))
{
- if (tr_variantDictFindInt (val, "complete", &intVal))
+ if (tr_variantDictFindInt (val, TR_KEY_complete, &intVal))
row->seeders = intVal;
- if (tr_variantDictFindInt (val, "incomplete", &intVal))
+ if (tr_variantDictFindInt (val, TR_KEY_incomplete, &intVal))
row->leechers = intVal;
- if (tr_variantDictFindInt (val, "downloaded", &intVal))
+ if (tr_variantDictFindInt (val, TR_KEY_downloaded, &intVal))
row->downloads = intVal;
- if (tr_variantDictFindInt (val, "downloaders", &intVal))
+ if (tr_variantDictFindInt (val, TR_KEY_downloaders, &intVal))
row->downloaders = intVal;
break;
}
#include <string.h> /* strlen () */
+
+#define __LIBTRANSMISSION_VARIANT_MODULE___
#include "transmission.h"
#include "utils.h" /* tr_free */
#include "variant.h"
-
+#include "variant-common.h"
#include "libtransmission-test.h"
+static inline tr_quark
+toQuark (const char * str)
+{
+ return tr_quark_new (str, strlen(str));
+}
+
static int
test_elements (void)
{
double d;
int64_t i;
int err = 0;
+ tr_quark key;
in = "{ \"string\": \"hello world\","
" \"escaped\": \"bell \\b formfeed \\f linefeed \\n carriage return \\r tab \\t\","
check_int_eq (0, err);
check (tr_variantIsDict (&top));
str = NULL;
- check (tr_variantDictFindStr (&top, "string", &str, NULL));
+ key = tr_quark_new ("string", 6);
+ check (tr_variantDictFindStr (&top, key, &str, NULL));
check_streq ("hello world", str);
- check (tr_variantDictFindStr (&top, "escaped", &str, NULL));
+ check (tr_variantDictFindStr (&top, tr_quark_new("escaped",7), &str, NULL));
check_streq ("bell \b formfeed \f linefeed \n carriage return \r tab \t", str);
i = 0;
- check (tr_variantDictFindInt (&top, "int", &i));
+ check (tr_variantDictFindInt (&top, tr_quark_new("int",3), &i));
check_int_eq (5, i);
d = 0;
- check (tr_variantDictFindReal (&top, "float", &d));
+ check (tr_variantDictFindReal (&top, tr_quark_new("float",5), &d));
check_int_eq (65, ((int)(d*10)));
f = false;
- check (tr_variantDictFindBool (&top, "true", &f));
+ check (tr_variantDictFindBool (&top, tr_quark_new("true",4), &f));
check_int_eq (true, f);
- check (tr_variantDictFindBool (&top, "false", &f));
+ check (tr_variantDictFindBool (&top, tr_quark_new("false",5), &f));
check_int_eq (false, f);
- check (tr_variantDictFindStr (&top, "null", &str, NULL));
+ check (tr_variantDictFindStr (&top, tr_quark_new("null",4), &str, NULL));
check_streq ("", str);
if (!err)
const char * str;
char * json;
int err;
+ const tr_quark key = tr_quark_new ("key", 3);
err = tr_variantFromJson (&top, in, strlen(in));
check (!err);
check (tr_variantIsDict (&top));
- check (tr_variantDictFindStr (&top, "key", &str, NULL));
+ check (tr_variantDictFindStr (&top, key, &str, NULL));
check_streq ("Letöltések", str);
if (!err)
tr_variantFree (&top);
err = tr_variantFromJson (&top, in, strlen(in));
check (!err);
check (tr_variantIsDict (&top));
- check (tr_variantDictFindStr (&top, "key", &str, NULL));
+ check (tr_variantDictFindStr (&top, key, &str, NULL));
check_streq ("\\", str);
if (!err)
tr_variantFree (&top);
err = tr_variantFromJson (&top, in, strlen(in));
check (!err);
check (tr_variantIsDict (&top));
- check (tr_variantDictFindStr (&top, "key", &str, NULL));
+ check (tr_variantDictFindStr (&top, key, &str, NULL));
check_streq ("Letöltések", str);
json = tr_variantToStr (&top, TR_VARIANT_FMT_JSON, NULL);
if (!err)
err = tr_variantFromJson (&top, json, strlen(json));
check (!err);
check (tr_variantIsDict (&top));
- check (tr_variantDictFindStr (&top, "key", &str, NULL));
+ check (tr_variantDictFindStr (&top, key, &str, NULL));
check_streq ("Letöltések", str);
if (!err)
tr_variantFree (&top);
check (!err);
check (tr_variantIsDict (&top));
- check ((headers = tr_variantDictFind (&top, "headers")));
+ check ((headers = tr_variantDictFind (&top, tr_quark_new("headers",7))));
check (tr_variantIsDict (headers));
- check (tr_variantDictFindStr (headers, "type", &str, NULL));
+ check (tr_variantDictFindStr (headers, tr_quark_new("type",4), &str, NULL));
check_streq ("request", str);
- check (tr_variantDictFindInt (headers, "tag", &i));
+ check (tr_variantDictFindInt (headers, TR_KEY_tag, &i));
check_int_eq (666, i);
- check ((body = tr_variantDictFind (&top, "body")));
- check (tr_variantDictFindStr (body, "name", &str, NULL));
+ check ((body = tr_variantDictFind (&top, tr_quark_new("body",4))));
+ check (tr_variantDictFindStr (body, TR_KEY_name, &str, NULL));
check_streq ("torrent-info", str);
- check ((args = tr_variantDictFind (body, "arguments")));
+ check ((args = tr_variantDictFind (body, tr_quark_new("arguments",9))));
check (tr_variantIsDict (args));
- check ((ids = tr_variantDictFind (args, "ids")));
+ check ((ids = tr_variantDictFind (args, TR_KEY_ids)));
check (tr_variantIsList (ids));
check_int_eq (2, tr_variantListSize (ids));
check (tr_variantGetInt (tr_variantListChild (ids, 0), &i));
const int err = tr_variantFromJson (&top, in, strlen(in));
check (!err);
- check (tr_variantDictFindStr (&top, "errorString", &str, NULL));
+ check (tr_variantDictFindStr (&top, TR_KEY_errorString, &str, NULL));
check_streq ("torrent not registered with this tracker 6UHsVW'*C", str);
tr_variantFree (&top);
const int err = tr_variantFromJson (&top, in, strlen(in));
check_int_eq (0, err);
- check (tr_variantDictFindStr (&top, "string-1", &str, NULL));
+ check (tr_variantDictFindStr (&top, tr_quark_new("string-1",8), &str, NULL));
check_streq ("/usr/lib", str);
tr_variantFree (&top);
/* announce list */
if (info->trackerCount == 1)
{
- tr_variantDictAddStr (top, "announce", info->trackers[0]);
+ tr_variantDictAddStr (top, TR_KEY_announce, info->trackers[0]);
}
else
{
- tr_variant * trackers = tr_variantDictAddList (top, "announce-list", info->trackerCount);
+ tr_variant * trackers = tr_variantDictAddList (top, TR_KEY_announce_list, info->trackerCount);
for (i=0; i<info->trackerCount; ++i)
tr_variantListAddStr (tr_variantListAddList (trackers, 1), info->trackers[i]);
}
/* webseeds */
if (info->webseedCount > 0)
{
- tr_variant * urls = tr_variantDictAddList (top, "url-list", info->webseedCount);
+ tr_variant * urls = tr_variantDictAddList (top, TR_KEY_url_list, info->webseedCount);
for (i=0; i<info->webseedCount; ++i)
tr_variantListAddStr (urls, info->webseeds[i]);
}
/* nonstandard keys */
- d = tr_variantDictAddDict (top, "magnet-info", 2);
- tr_variantDictAddRaw (d, "info_hash", info->hash, 20);
+ d = tr_variantDictAddDict (top, TR_KEY_magnet_info, 2);
+ tr_variantDictAddRaw (d, TR_KEY_info_hash, info->hash, 20);
if (info->displayName != NULL)
- tr_variantDictAddStr (d, "display-name", info->displayName);
+ tr_variantDictAddStr (d, TR_KEY_display_name, info->displayName);
}
if (builder->isSingleFile)
{
- tr_variantDictAddInt (dict, "length", builder->files[0].size);
+ tr_variantDictAddInt (dict, TR_KEY_length, builder->files[0].size);
}
else /* root node is a directory */
{
uint32_t i;
- tr_variant * list = tr_variantDictAddList (dict, "files",
+ tr_variant * list = tr_variantDictAddList (dict, TR_KEY_files,
builder->fileCount);
for (i = 0; i < builder->fileCount; ++i)
{
tr_variant * d = tr_variantListAddDict (list, 2);
- tr_variant * length = tr_variantDictAdd (d, "length", 6);
- tr_variant * pathVal = tr_variantDictAdd (d, "path", 4);
+ tr_variant * length = tr_variantDictAdd (d, TR_KEY_length);
+ tr_variant * pathVal = tr_variantDictAdd (d, TR_KEY_path);
getFileInfo (builder->top, &builder->files[i], length, pathVal);
}
}
base = tr_basename (builder->top);
- tr_variantDictAddStr (dict, "name", base);
+ tr_variantDictAddStr (dict, TR_KEY_name, base);
tr_free (base);
- tr_variantDictAddInt (dict, "piece length", builder->pieceSize);
+ tr_variantDictAddInt (dict, TR_KEY_piece_length, builder->pieceSize);
if ((pch = getHashInfo (builder)))
{
- tr_variantDictAddRaw (dict, "pieces", pch,
- SHA_DIGEST_LENGTH * builder->pieceCount);
+ tr_variantDictAddRaw (dict, TR_KEY_pieces, pch,
+ SHA_DIGEST_LENGTH * builder->pieceCount);
tr_free (pch);
}
- tr_variantDictAddInt (dict, "private", builder->isPrivate ? 1 : 0);
+ tr_variantDictAddInt (dict, TR_KEY_private, builder->isPrivate ? 1 : 0);
}
static void
if (builder->trackerCount > 1)
{
- tr_variant * annList = tr_variantDictAddList (&top, "announce-list",
- 0);
+ tr_variant * annList = tr_variantDictAddList (&top, TR_KEY_announce_list, 0);
for (i = 0; i < builder->trackerCount; ++i)
{
if (prevTier != builder->trackers[i].tier)
}
}
- tr_variantDictAddStr (&top, "announce", builder->trackers[0].announce);
+ tr_variantDictAddStr (&top, TR_KEY_announce, builder->trackers[0].announce);
}
if (!builder->result && !builder->abortFlag)
{
if (builder->comment && *builder->comment)
- tr_variantDictAddStr (&top, "comment", builder->comment);
- tr_variantDictAddStr (&top, "created by",
+ tr_variantDictAddStr (&top, TR_KEY_comment, builder->comment);
+ tr_variantDictAddStr (&top, TR_KEY_created_by,
TR_NAME "/" LONG_VERSION_STRING);
- tr_variantDictAddInt (&top, "creation date", time (NULL));
- tr_variantDictAddStr (&top, "encoding", "UTF-8");
- makeInfoDict (tr_variantDictAddDict (&top, "info", 666), builder);
+ tr_variantDictAddInt (&top, TR_KEY_creation_date, time (NULL));
+ tr_variantDictAddStr (&top, TR_KEY_encoding, "UTF-8");
+ makeInfoDict (tr_variantDictAddDict (&top, TR_KEY_info, 666), builder);
}
/* save the file */
if (!tr_variantIsDict (file))
return "files";
- if (!tr_variantDictFindList (file, "path.utf-8", &path))
- if (!tr_variantDictFindList (file, "path", &path))
+ if (!tr_variantDictFindList (file, TR_KEY_path_utf_8, &path))
+ if (!tr_variantDictFindList (file, TR_KEY_path, &path))
return "path";
if (!getfile (&inf->files[i].name, inf->name, path, buf))
return "path";
- if (!tr_variantDictFindInt (file, "length", &len))
+ if (!tr_variantDictFindInt (file, TR_KEY_length, &len))
return "length";
inf->files[i].length = len;
tr_variant * tiers;
/* Announce-list */
- if (tr_variantDictFindList (meta, "announce-list", &tiers))
+ if (tr_variantDictFindList (meta, TR_KEY_announce_list, &tiers))
{
int n;
int i, j, validTiers;
}
/* Regular announce value */
- if (!trackerCount && tr_variantDictFindStr (meta, "announce", &str, &len))
+ if (!trackerCount && tr_variantDictFindStr (meta, TR_KEY_announce, &str, &len))
{
char * url = tr_strstrip (tr_strndup (str, len));
if (!tr_urlIsValidTracker (url))
tr_variant * urls;
const char * url;
- if (tr_variantDictFindList (meta, "url-list", &urls))
+ if (tr_variantDictFindList (meta, TR_KEY_url_list, &urls))
{
int i;
const int n = tr_variantListSize (urls);
}
}
}
- else if (tr_variantDictFindStr (meta, "url-list", &url, NULL)) /* handle single items in webseeds */
+ else if (tr_variantDictFindStr (meta, TR_KEY_url_list, &url, NULL)) /* handle single items in webseeds */
{
char * fixed_url = fix_webseed_url (inf, url);
/* info_hash: urlencoded 20-byte SHA1 hash of the value of the info key
* from the Metainfo file. Note that the value will be a bencoded
* dictionary, given the definition of the info key above. */
- b = tr_variantDictFindDict (meta, "info", &infoDict);
+ b = tr_variantDictFindDict (meta, TR_KEY_info, &infoDict);
if (hasInfoDict != NULL)
*hasInfoDict = b;
if (!b)
{
/* no info dictionary... is this a magnet link? */
- if (tr_variantDictFindDict (meta, "magnet-info", &d))
+ if (tr_variantDictFindDict (meta, TR_KEY_magnet_info, &d))
{
isMagnet = true;
/* get the info-hash */
- if (!tr_variantDictFindRaw (d, "info_hash", &raw, &len))
+ if (!tr_variantDictFindRaw (d, TR_KEY_info_hash, &raw, &len))
return "info_hash";
if (len != SHA_DIGEST_LENGTH)
return "info_hash";
tr_sha1_to_hex (inf->hashString, inf->hash);
/* maybe get the display name */
- if (tr_variantDictFindStr (d, "display-name", &str, &len))
+ if (tr_variantDictFindStr (d, TR_KEY_display_name, &str, &len))
{
tr_free (inf->name);
inf->name = tr_strndup (str, len);
if (!isMagnet)
{
len = 0;
- if (!tr_variantDictFindStr (infoDict, "name.utf-8", &str, &len))
- if (!tr_variantDictFindStr (infoDict, "name", &str, &len))
+ if (!tr_variantDictFindStr (infoDict, TR_KEY_name_utf_8, &str, &len))
+ if (!tr_variantDictFindStr (infoDict, TR_KEY_name, &str, &len))
str = "";
if (!str || !*str)
return "name";
/* comment */
len = 0;
- if (!tr_variantDictFindStr (meta, "comment.utf-8", &str, &len))
- if (!tr_variantDictFindStr (meta, "comment", &str, &len))
+ if (!tr_variantDictFindStr (meta, TR_KEY_comment_utf_8, &str, &len))
+ if (!tr_variantDictFindStr (meta, TR_KEY_comment, &str, &len))
str = "";
tr_free (inf->comment);
inf->comment = tr_utf8clean (str, len);
/* created by */
len = 0;
- if (!tr_variantDictFindStr (meta, "created by.utf-8", &str, &len))
- if (!tr_variantDictFindStr (meta, "created by", &str, &len))
+ if (!tr_variantDictFindStr (meta, TR_KEY_created_by_utf_8, &str, &len))
+ if (!tr_variantDictFindStr (meta, TR_KEY_created_by, &str, &len))
str = "";
tr_free (inf->creator);
inf->creator = tr_utf8clean (str, len);
/* creation date */
- if (!tr_variantDictFindInt (meta, "creation date", &i))
+ if (!tr_variantDictFindInt (meta, TR_KEY_creation_date, &i))
i = 0;
inf->dateCreated = i;
/* private */
- if (!tr_variantDictFindInt (infoDict, "private", &i))
- if (!tr_variantDictFindInt (meta, "private", &i))
+ if (!tr_variantDictFindInt (infoDict, TR_KEY_private, &i))
+ if (!tr_variantDictFindInt (meta, TR_KEY_private, &i))
i = 0;
inf->isPrivate = i != 0;
/* piece length */
if (!isMagnet)
{
- if (!tr_variantDictFindInt (infoDict, "piece length", &i) || (i < 1))
+ if (!tr_variantDictFindInt (infoDict, TR_KEY_piece_length, &i) || (i < 1))
return "piece length";
inf->pieceSize = i;
}
/* pieces */
if (!isMagnet)
{
- if (!tr_variantDictFindRaw (infoDict, "pieces", &raw, &len))
+ if (!tr_variantDictFindRaw (infoDict, TR_KEY_pieces, &raw, &len))
return "pieces";
if (len % SHA_DIGEST_LENGTH)
return "pieces";
/* files */
if (!isMagnet)
{
- if ((str = parseFiles (inf, tr_variantDictFind (infoDict, "files"),
- tr_variantDictFind (infoDict, "length"))))
+ if ((str = parseFiles (inf, tr_variantDictFind (infoDict, TR_KEY_files),
+ tr_variantDictFind (infoDict, TR_KEY_length))))
return str;
if (!inf->fileCount || !inf->totalSize)
tr_bitfieldDestruct (&peer->have);
tr_bitfieldDestruct (&peer->blame);
- tr_free (peer->client);
if (peer->atom)
peer->atom->peer = NULL;
else
{
peer = getPeer (t, atom);
- tr_free (peer->client);
if (!peer_id)
- peer->client = NULL;
+ peer->client = TR_KEY_NONE;
else {
char client[128];
tr_clientForId (client, sizeof (client), peer_id);
- peer->client = tr_strdup (client);
+ peer->client = tr_quark_new (client, -1);
}
peer->io = tr_handshakeStealIO (handshake); /* this steals its refcount too, which is
tr_peer_stat * stat = ret + i;
tr_address_to_string_with_buf (&atom->addr, stat->addr, sizeof (stat->addr));
- tr_strlcpy (stat->client, (peer->client ? peer->client : ""), sizeof (stat->client));
+ tr_strlcpy (stat->client, tr_quark_get_string(peer->client,NULL), sizeof (stat->client));
stat->port = ntohs (peer->atom->port);
stat->from = atom->fromFirst;
stat->progress = peer->progress;
#include "history.h"
#include "net.h" /* tr_address */
#include "peer-common.h" /* struct peer_request */
+#include "quark.h"
/**
* @addtogroup peers Peers
float progress;
/* the client name from the `v' string in LTEP's handshake dictionary */
- char * client;
+ tr_quark client;
time_t chokeChangedAt;
tr_getLogTimeStr (timestr, sizeof (timestr)),
tr_torrentName (msgs->torrent),
tr_peerIoGetAddrStr (msgs->peer->io),
- msgs->peer->client);
+ tr_quark_get_string (msgs->peer->client, NULL));
va_start (args, fmt);
evbuffer_add_vprintf (buf, fmt, args);
va_end (args);
struct evbuffer * payload;
struct evbuffer * out = msgs->outMessages;
const unsigned char * ipv6 = tr_globalIPv6 ();
+ static tr_quark version_quark = 0;
if (msgs->clientSentLtepHandshake)
return;
+ if (!version_quark)
+ version_quark = tr_quark_new (TR_NAME " " USERAGENT_PREFIX, -1);
+
dbgmsg (msgs, "sending an ltep handshake");
msgs->clientSentLtepHandshake = 1;
allow_pex = 1;
tr_variantInitDict (&val, 8);
- tr_variantDictAddInt (&val, "e", getSession (msgs)->encryptionMode != TR_CLEAR_PREFERRED);
+ tr_variantDictAddInt (&val, TR_KEY_e, getSession (msgs)->encryptionMode != TR_CLEAR_PREFERRED);
if (ipv6 != NULL)
- tr_variantDictAddRaw (&val, "ipv6", ipv6, 16);
+ tr_variantDictAddRaw (&val, TR_KEY_ipv6, ipv6, 16);
if (allow_metadata_xfer && tr_torrentHasMetadata (msgs->torrent)
&& (msgs->torrent->infoDictLength > 0))
- tr_variantDictAddInt (&val, "metadata_size", msgs->torrent->infoDictLength);
- tr_variantDictAddInt (&val, "p", tr_sessionGetPublicPeerPort (getSession (msgs)));
- tr_variantDictAddInt (&val, "reqq", REQQ);
- tr_variantDictAddInt (&val, "upload_only", tr_torrentIsSeed (msgs->torrent));
- tr_variantDictAddStr (&val, "v", TR_NAME " " USERAGENT_PREFIX);
+ tr_variantDictAddInt (&val, TR_KEY_metadata_size, msgs->torrent->infoDictLength);
+ tr_variantDictAddInt (&val, TR_KEY_p, tr_sessionGetPublicPeerPort (getSession (msgs)));
+ tr_variantDictAddInt (&val, TR_KEY_reqq, REQQ);
+ tr_variantDictAddInt (&val, TR_KEY_upload_only, tr_torrentIsSeed (msgs->torrent));
+ tr_variantDictAddQuark (&val, TR_KEY_v, version_quark);
if (allow_metadata_xfer || allow_pex) {
- tr_variant * m = tr_variantDictAddDict (&val, "m", 2);
+ tr_variant * m = tr_variantDictAddDict (&val, TR_KEY_m, 2);
if (allow_metadata_xfer)
- tr_variantDictAddInt (m, "ut_metadata", UT_METADATA_ID);
+ tr_variantDictAddInt (m, TR_KEY_ut_metadata, UT_METADATA_ID);
if (allow_pex)
- tr_variantDictAddInt (m, "ut_pex", UT_PEX_ID);
+ tr_variantDictAddInt (m, TR_KEY_ut_pex, UT_PEX_ID);
}
payload = tr_variantToBuf (&val, TR_VARIANT_FMT_BENC);
dbgmsg (msgs, "here is the handshake: [%*.*s]", len, len, tmp);
/* does the peer prefer encrypted connections? */
- if (tr_variantDictFindInt (&val, "e", &i)) {
+ if (tr_variantDictFindInt (&val, TR_KEY_e, &i)) {
msgs->peer->encryption_preference = i ? ENCRYPTION_PREFERENCE_YES
: ENCRYPTION_PREFERENCE_NO;
if (i)
msgs->peerSupportsPex = 0;
msgs->peerSupportsMetadataXfer = 0;
- if (tr_variantDictFindDict (&val, "m", &sub)) {
- if (tr_variantDictFindInt (sub, "ut_pex", &i)) {
+ if (tr_variantDictFindDict (&val, TR_KEY_m, &sub)) {
+ if (tr_variantDictFindInt (sub, TR_KEY_ut_pex, &i)) {
msgs->peerSupportsPex = i != 0;
msgs->ut_pex_id = (uint8_t) i;
dbgmsg (msgs, "msgs->ut_pex is %d", (int)msgs->ut_pex_id);
}
- if (tr_variantDictFindInt (sub, "ut_metadata", &i)) {
+ if (tr_variantDictFindInt (sub, TR_KEY_ut_metadata, &i)) {
msgs->peerSupportsMetadataXfer = i != 0;
msgs->ut_metadata_id = (uint8_t) i;
dbgmsg (msgs, "msgs->ut_metadata_id is %d", (int)msgs->ut_metadata_id);
}
- if (tr_variantDictFindInt (sub, "ut_holepunch", &i)) {
+ if (tr_variantDictFindInt (sub, TR_KEY_ut_holepunch, &i)) {
/* Mysterious µTorrent extension that we don't grok. However,
it implies support for µTP, so use it to indicate that. */
tr_peerMgrSetUtpFailed (msgs->torrent,
}
/* look for metainfo size (BEP 9) */
- if (tr_variantDictFindInt (&val, "metadata_size", &i)) {
+ if (tr_variantDictFindInt (&val, TR_KEY_metadata_size, &i)) {
tr_torrentSetMetadataSizeHint (msgs->torrent, i);
msgs->metadata_size_hint = (size_t) i;
}
/* look for upload_only (BEP 21) */
- if (tr_variantDictFindInt (&val, "upload_only", &i))
+ if (tr_variantDictFindInt (&val, TR_KEY_upload_only, &i))
seedProbability = i==0 ? 0 : 100;
/* get peer's listening port */
- if (tr_variantDictFindInt (&val, "p", &i)) {
+ if (tr_variantDictFindInt (&val, TR_KEY_p, &i)) {
pex.port = htons ((uint16_t)i);
fireClientGotPort (msgs, pex.port);
dbgmsg (msgs, "peer's port is now %d", (int)i);
}
if (tr_peerIoIsIncoming (msgs->peer->io)
- && tr_variantDictFindRaw (&val, "ipv4", &addr, &addr_len)
+ && tr_variantDictFindRaw (&val, TR_KEY_ipv4, &addr, &addr_len)
&& (addr_len == 4))
{
pex.addr.type = TR_AF_INET;
}
if (tr_peerIoIsIncoming (msgs->peer->io)
- && tr_variantDictFindRaw (&val, "ipv6", &addr, &addr_len)
+ && tr_variantDictFindRaw (&val, TR_KEY_ipv6, &addr, &addr_len)
&& (addr_len == 16))
{
pex.addr.type = TR_AF_INET6;
}
/* get peer's maximum request queue size */
- if (tr_variantDictFindInt (&val, "reqq", &i))
+ if (tr_variantDictFindInt (&val, TR_KEY_reqq, &i))
msgs->reqq = i;
tr_variantFree (&val);
if (!tr_variantFromBencFull (&dict, tmp, msglen, NULL, &benc_end))
{
- tr_variantDictFindInt (&dict, "msg_type", &msg_type);
- tr_variantDictFindInt (&dict, "piece", &piece);
- tr_variantDictFindInt (&dict, "total_size", &total_size);
+ tr_variantDictFindInt (&dict, TR_KEY_msg_type, &msg_type);
+ tr_variantDictFindInt (&dict, TR_KEY_piece, &piece);
+ tr_variantDictFindInt (&dict, TR_KEY_total_size, &total_size);
tr_variantFree (&dict);
}
/* build the rejection message */
tr_variantInitDict (&tmp, 2);
- tr_variantDictAddInt (&tmp, "msg_type", METADATA_MSG_TYPE_REJECT);
- tr_variantDictAddInt (&tmp, "piece", piece);
+ tr_variantDictAddInt (&tmp, TR_KEY_msg_type, METADATA_MSG_TYPE_REJECT);
+ tr_variantDictAddInt (&tmp, TR_KEY_piece, piece);
payload = tr_variantToBuf (&tmp, TR_VARIANT_FMT_BENC);
/* write it out as a LTEP message to our outMessages buffer */
if (tr_torrentAllowsPex (tor)
&& ((loaded = !tr_variantFromBenc (&val, tmp, msglen))))
{
- if (tr_variantDictFindRaw (&val, "added", &added, &added_len))
+ if (tr_variantDictFindRaw (&val, TR_KEY_added, &added, &added_len))
{
tr_pex * pex;
size_t i, n;
size_t added_f_len = 0;
const uint8_t * added_f = NULL;
- tr_variantDictFindRaw (&val, "added.f", &added_f, &added_f_len);
+ tr_variantDictFindRaw (&val, TR_KEY_added_f, &added_f, &added_f_len);
pex = tr_peerMgrCompactToPex (added, added_len, added_f, added_f_len, &n);
n = MIN (n, MAX_PEX_PEER_COUNT);
tr_free (pex);
}
- if (tr_variantDictFindRaw (&val, "added6", &added, &added_len))
+ if (tr_variantDictFindRaw (&val, TR_KEY_added6, &added, &added_len))
{
tr_pex * pex;
size_t i, n;
size_t added_f_len = 0;
const uint8_t * added_f = NULL;
- tr_variantDictFindRaw (&val, "added6.f", &added_f, &added_f_len);
+ tr_variantDictFindRaw (&val, TR_KEY_added6_f, &added_f, &added_f_len);
pex = tr_peerMgrCompact6ToPex (added, added_len, added_f, added_f_len, &n);
n = MIN (n, MAX_PEX_PEER_COUNT);
/* build the data message */
tr_variantInitDict (&tmp, 3);
- tr_variantDictAddInt (&tmp, "msg_type", METADATA_MSG_TYPE_REQUEST);
- tr_variantDictAddInt (&tmp, "piece", piece);
+ tr_variantDictAddInt (&tmp, TR_KEY_msg_type, METADATA_MSG_TYPE_REQUEST);
+ tr_variantDictAddInt (&tmp, TR_KEY_piece, piece);
payload = tr_variantToBuf (&tmp, TR_VARIANT_FMT_BENC);
dbgmsg (msgs, "requesting metadata piece #%d", piece);
/* build the data message */
tr_variantInitDict (&tmp, 3);
- tr_variantDictAddInt (&tmp, "msg_type", METADATA_MSG_TYPE_DATA);
- tr_variantDictAddInt (&tmp, "piece", piece);
- tr_variantDictAddInt (&tmp, "total_size", msgs->torrent->infoDictLength);
+ tr_variantDictAddInt (&tmp, TR_KEY_msg_type, METADATA_MSG_TYPE_DATA);
+ tr_variantDictAddInt (&tmp, TR_KEY_piece, piece);
+ tr_variantDictAddInt (&tmp, TR_KEY_total_size, msgs->torrent->infoDictLength);
payload = tr_variantToBuf (&tmp, TR_VARIANT_FMT_BENC);
/* write it out as a LTEP message to our outMessages buffer */
/* build the rejection message */
tr_variantInitDict (&tmp, 2);
- tr_variantDictAddInt (&tmp, "msg_type", METADATA_MSG_TYPE_REJECT);
- tr_variantDictAddInt (&tmp, "piece", piece);
+ tr_variantDictAddInt (&tmp, TR_KEY_msg_type, METADATA_MSG_TYPE_REJECT);
+ tr_variantDictAddInt (&tmp, TR_KEY_piece, piece);
payload = tr_variantToBuf (&tmp, TR_VARIANT_FMT_BENC);
/* write it out as a LTEP message to our outMessages buffer */
memcpy (walk, &diffs.added[i].port, 2); walk += 2;
}
assert ((walk - tmp) == diffs.addedCount * 6);
- tr_variantDictAddRaw (&val, "added", tmp, walk - tmp);
+ tr_variantDictAddRaw (&val, TR_KEY_added, tmp, walk - tmp);
tr_free (tmp);
/* "added.f"
for (i = 0; i < diffs.addedCount; ++i)
*walk++ = diffs.added[i].flags & ~ADDED_F_HOLEPUNCH;
assert ((walk - tmp) == diffs.addedCount);
- tr_variantDictAddRaw (&val, "added.f", tmp, walk - tmp);
+ tr_variantDictAddRaw (&val, TR_KEY_added_f, tmp, walk - tmp);
tr_free (tmp);
}
memcpy (walk, &diffs.dropped[i].port, 2); walk += 2;
}
assert ((walk - tmp) == diffs.droppedCount * 6);
- tr_variantDictAddRaw (&val, "dropped", tmp, walk - tmp);
+ tr_variantDictAddRaw (&val, TR_KEY_dropped, tmp, walk - tmp);
tr_free (tmp);
}
walk += 2;
}
assert ((walk - tmp) == diffs6.addedCount * 18);
- tr_variantDictAddRaw (&val, "added6", tmp, walk - tmp);
+ tr_variantDictAddRaw (&val, TR_KEY_added6, tmp, walk - tmp);
tr_free (tmp);
/* "added6.f"
for (i = 0; i < diffs6.addedCount; ++i)
*walk++ = diffs6.added[i].flags & ~ADDED_F_HOLEPUNCH;
assert ((walk - tmp) == diffs6.addedCount);
- tr_variantDictAddRaw (&val, "added6.f", tmp, walk - tmp);
+ tr_variantDictAddRaw (&val, TR_KEY_added6_f, tmp, walk - tmp);
tr_free (tmp);
}
walk += 2;
}
assert ((walk - tmp) == diffs6.droppedCount * 18);
- tr_variantDictAddRaw (&val, "dropped6", tmp, walk - tmp);
+ tr_variantDictAddRaw (&val, TR_KEY_dropped6, tmp, walk - tmp);
tr_free (tmp);
}
#define FLOOR 32
-const tr_ptrArray TR_PTR_ARRAY_INIT = { NULL, 0, 0 };
+const tr_ptrArray TR_PTR_ARRAY_INIT = TR_PTR_ARRAY_INIT_STATIC;
void
tr_ptrArrayDestruct (tr_ptrArray * p, PtrArrayForeachFunc func)
typedef void (*PtrArrayForeachFunc)(void *);
+#define TR_PTR_ARRAY_INIT_STATIC { NULL, 0, 0 }
+
extern const tr_ptrArray TR_PTR_ARRAY_INIT;
/** @brief Destructor to free a tr_ptrArray's internal memory */
--- /dev/null
+#include <string.h> /* strlen() */
+
+#include "transmission.h"
+#include "quark.h"
+#include "libtransmission-test.h"
+
+static int
+test_static_quarks (void)
+{
+ int i;
+
+ for (i=0; i<TR_N_KEYS; i++)
+ {
+ tr_quark q;
+ size_t len;
+ const char * str;
+
+ str = tr_quark_get_string (i, &len);
+ check_int_eq (strlen(str), len);
+ check (tr_quark_lookup (str, len, &q));
+ check_int_eq (i, q);
+ }
+
+ for (i=0; i+1<TR_N_KEYS; i++)
+ {
+ size_t len1, len2;
+ const char *str1, *str2;
+
+ str1 = tr_quark_get_string (i, &len1);
+ str2 = tr_quark_get_string (i+1, &len2);
+
+ check (strcmp (str1, str2) < 0);
+ }
+
+ return 0;
+}
+
+MAIN_SINGLE_TEST(test_static_quarks)
--- /dev/null
+#include <assert.h>
+#include <stdlib.h> /* bsearch() */
+#include <string.h> /* memcmp() */
+
+#include "transmission.h"
+#include "ptrarray.h"
+#include "quark.h"
+#include "utils.h" /* tr_memdup(), tr_strndup() */
+
+struct tr_key_struct
+{
+ const char * str;
+ size_t len;
+};
+
+static const struct tr_key_struct my_static[] =
+{
+ { "", 0 },
+ { "activeTorrentCount", 18 },
+ { "activity-date", 13 },
+ { "activityDate", 12 },
+ { "added", 5 },
+ { "added-date", 10 },
+ { "added.f", 7 },
+ { "added6", 6 },
+ { "added6.f", 8 },
+ { "addedDate", 9 },
+ { "address", 7 },
+ { "alt-speed-down", 14 },
+ { "alt-speed-enabled", 17 },
+ { "alt-speed-time-begin", 20 },
+ { "alt-speed-time-day", 18 },
+ { "alt-speed-time-enabled", 22 },
+ { "alt-speed-time-end", 18 },
+ { "alt-speed-up", 12 },
+ { "announce", 8 },
+ { "announce-list", 13 },
+ { "announceState", 13 },
+ { "arguments", 9 },
+ { "bandwidth-priority", 18 },
+ { "bandwidthPriority", 17 },
+ { "bind-address-ipv4", 17 },
+ { "bind-address-ipv6", 17 },
+ { "bitfield", 8 },
+ { "blocklist-date", 14 },
+ { "blocklist-enabled", 17 },
+ { "blocklist-size", 14 },
+ { "blocklist-updates-enabled", 25 },
+ { "blocklist-url", 13 },
+ { "blocks", 6 },
+ { "bytesCompleted", 14 },
+ { "cache-size-mb", 13 },
+ { "clientIsChoked", 14 },
+ { "clientIsInterested", 18 },
+ { "clientName", 10 },
+ { "comment", 7 },
+ { "comment_utf_8", 13 },
+ { "compact-view", 12 },
+ { "complete", 8 },
+ { "config-dir", 10 },
+ { "cookies", 7 },
+ { "corrupt", 7 },
+ { "corruptEver", 11 },
+ { "created by", 10 },
+ { "created by.utf-8", 16 },
+ { "creation date", 13 },
+ { "creator", 7 },
+ { "cumulative-stats", 16 },
+ { "current-stats", 13 },
+ { "date", 4 },
+ { "dateCreated", 11 },
+ { "delete-local-data", 17 },
+ { "desiredAvailable", 16 },
+ { "destination", 11 },
+ { "dht-enabled", 11 },
+ { "display-name", 12 },
+ { "dnd", 3 },
+ { "done-date", 9 },
+ { "doneDate", 8 },
+ { "download-dir", 12 },
+ { "download-dir-free-space", 23 },
+ { "download-queue-enabled", 22 },
+ { "download-queue-size", 19 },
+ { "downloadCount", 13 },
+ { "downloadDir", 11 },
+ { "downloadLimit", 13 },
+ { "downloadLimited", 15 },
+ { "downloadSpeed", 13 },
+ { "downloaded", 10 },
+ { "downloaded-bytes", 16 },
+ { "downloadedBytes", 15 },
+ { "downloadedEver", 14 },
+ { "downloaders", 11 },
+ { "downloading-time-seconds", 24 },
+ { "dropped", 7 },
+ { "dropped6", 8 },
+ { "e", 1 },
+ { "encoding", 8 },
+ { "encryption", 10 },
+ { "error", 5 },
+ { "errorString", 11 },
+ { "eta", 3 },
+ { "failure reason", 14 },
+ { "fields", 6 },
+ { "fileStats", 9 },
+ { "filename", 8 },
+ { "files", 5 },
+ { "files-added", 11 },
+ { "files-unwanted", 14 },
+ { "files-wanted", 12 },
+ { "filesAdded", 10 },
+ { "filter-mode", 11 },
+ { "filter-text", 11 },
+ { "filter-trackers", 15 },
+ { "flagStr", 7 },
+ { "flags", 5 },
+ { "fromCache", 9 },
+ { "fromDht", 7 },
+ { "fromIncoming", 12 },
+ { "fromLpd", 7 },
+ { "fromLtep", 8 },
+ { "fromPex", 7 },
+ { "fromTracker", 11 },
+ { "hasAnnounced", 12 },
+ { "hasScraped", 10 },
+ { "hashString", 10 },
+ { "have", 4 },
+ { "haveUnchecked", 13 },
+ { "haveValid", 9 },
+ { "honorsSessionLimits", 19 },
+ { "host", 4 },
+ { "id", 2 },
+ { "idle-limit", 10 },
+ { "idle-mode", 9 },
+ { "idle-seeding-limit", 18 },
+ { "idle-seeding-limit-enabled", 26 },
+ { "ids", 3 },
+ { "incomplete", 10 },
+ { "incomplete-dir", 14 },
+ { "incomplete-dir-enabled", 22 },
+ { "info", 4 },
+ { "info_hash", 9 },
+ { "inhibit-desktop-hibernation", 27 },
+ { "interval", 8 },
+ { "ip", 2 },
+ { "ipv4", 4 },
+ { "ipv6", 4 },
+ { "isBackup", 8 },
+ { "isDownloadingFrom", 17 },
+ { "isEncrypted", 11 },
+ { "isFinished", 10 },
+ { "isIncoming", 10 },
+ { "isPrivate", 9 },
+ { "isStalled", 9 },
+ { "isUTP", 5 },
+ { "isUploadingTo", 13 },
+ { "lastAnnouncePeerCount", 21 },
+ { "lastAnnounceResult", 18 },
+ { "lastAnnounceStartTime", 21 },
+ { "lastAnnounceSucceeded", 21 },
+ { "lastAnnounceTime", 16 },
+ { "lastAnnounceTimedOut", 20 },
+ { "lastScrapeResult", 16 },
+ { "lastScrapeStartTime", 19 },
+ { "lastScrapeSucceeded", 19 },
+ { "lastScrapeTime", 14 },
+ { "lastScrapeTimedOut", 18 },
+ { "ldp-enabled", 11 },
+ { "leecherCount", 12 },
+ { "leftUntilDone", 13 },
+ { "length", 6 },
+ { "location", 8 },
+ { "lpd-enabled", 11 },
+ { "m", 1 },
+ { "magnet-info", 11 },
+ { "magnetLink", 10 },
+ { "main-window-height", 18 },
+ { "main-window-is-maximized", 24 },
+ { "main-window-layout-order", 24 },
+ { "main-window-width", 17 },
+ { "main-window-x", 13 },
+ { "main-window-y", 13 },
+ { "manualAnnounceTime", 18 },
+ { "max-peers", 9 },
+ { "maxConnectedPeers", 17 },
+ { "memory-bytes", 12 },
+ { "memory-units", 12 },
+ { "message-level", 13 },
+ { "metadataPercentComplete", 23 },
+ { "metadata_size", 13 },
+ { "metainfo", 8 },
+ { "method", 6 },
+ { "min interval", 12 },
+ { "min_request_interval", 20 },
+ { "move", 4 },
+ { "msg_type", 8 },
+ { "mtimes", 6 },
+ { "name", 4 },
+ { "name.utf-8", 10 },
+ { "nextAnnounceTime", 16 },
+ { "nextScrapeTime", 14 },
+ { "nodes", 5 },
+ { "nodes6", 6 },
+ { "open-dialog-dir", 15 },
+ { "p", 1 },
+ { "path", 4 },
+ { "path.utf-8", 10 },
+ { "paused", 6 },
+ { "pausedTorrentCount", 18 },
+ { "peer-congestion-algorithm", 25 },
+ { "peer-limit", 10 },
+ { "peer-limit-global", 17 },
+ { "peer-limit-per-torrent", 22 },
+ { "peer-port", 9 },
+ { "peer-port-random-high", 21 },
+ { "peer-port-random-low", 20 },
+ { "peer-port-random-on-start", 25 },
+ { "peer-socket-tos", 15 },
+ { "peerIsChoked", 12 },
+ { "peerIsInterested", 16 },
+ { "peers", 5 },
+ { "peers2", 6 },
+ { "peers2-6", 8 },
+ { "peers6", 6 },
+ { "peersConnected", 14 },
+ { "peersFrom", 9 },
+ { "peersGettingFromUs", 18 },
+ { "peersSendingToUs", 16 },
+ { "percentDone", 11 },
+ { "pex-enabled", 11 },
+ { "piece", 5 },
+ { "piece length", 12 },
+ { "pieceCount", 10 },
+ { "pieceSize", 9 },
+ { "pieces", 6 },
+ { "play-download-complete-sound", 28 },
+ { "port", 4 },
+ { "port-forwarding-enabled", 23 },
+ { "port-is-open", 12 },
+ { "preallocation", 13 },
+ { "prefetch-enabled", 16 },
+ { "priorities", 10 },
+ { "priority", 8 },
+ { "priority-high", 13 },
+ { "priority-low", 12 },
+ { "priority-normal", 15 },
+ { "private", 7 },
+ { "progress", 8 },
+ { "prompt-before-exit", 18 },
+ { "queue-move-bottom", 17 },
+ { "queue-move-down", 15 },
+ { "queue-move-top", 14 },
+ { "queue-move-up", 13 },
+ { "queue-stalled-enabled", 21 },
+ { "queue-stalled-minutes", 21 },
+ { "queuePosition", 13 },
+ { "rateDownload", 12 },
+ { "rateToClient", 12 },
+ { "rateToPeer", 10 },
+ { "rateUpload", 10 },
+ { "ratio-limit", 11 },
+ { "ratio-limit-enabled", 19 },
+ { "ratio-mode", 10 },
+ { "recent-download-dir-1", 21 },
+ { "recent-download-dir-2", 21 },
+ { "recent-download-dir-3", 21 },
+ { "recent-download-dir-4", 21 },
+ { "recheckProgress", 15 },
+ { "remote-session-enabled", 22 },
+ { "remote-session-host", 19 },
+ { "remote-session-password", 23 },
+ { "remote-session-port", 19 },
+ { "remote-session-requres-authentication", 37 },
+ { "remote-session-username", 23 },
+ { "removed", 7 },
+ { "rename-partial-files", 20 },
+ { "reqq", 4 },
+ { "result", 6 },
+ { "rpc-authentication-required", 27 },
+ { "rpc-bind-address", 16 },
+ { "rpc-enabled", 11 },
+ { "rpc-password", 12 },
+ { "rpc-port", 8 },
+ { "rpc-url", 7 },
+ { "rpc-username", 12 },
+ { "rpc-version", 11 },
+ { "rpc-version-minimum", 19 },
+ { "rpc-whitelist", 13 },
+ { "rpc-whitelist-enabled", 21 },
+ { "scrape", 6 },
+ { "scrape-paused-torrents-enabled", 30 },
+ { "scrapeState", 11 },
+ { "script-torrent-done-enabled", 27 },
+ { "script-torrent-done-filename", 28 },
+ { "seconds-active", 14 },
+ { "secondsActive", 13 },
+ { "secondsDownloading", 18 },
+ { "secondsSeeding", 14 },
+ { "seed-queue-enabled", 18 },
+ { "seed-queue-size", 15 },
+ { "seedIdleLimit", 13 },
+ { "seedIdleMode", 12 },
+ { "seedRatioLimit", 14 },
+ { "seedRatioLimited", 16 },
+ { "seedRatioMode", 13 },
+ { "seederCount", 11 },
+ { "seeding-time-seconds", 20 },
+ { "session-count", 13 },
+ { "sessionCount", 12 },
+ { "show-backup-trackers", 20 },
+ { "show-desktop-notification", 25 },
+ { "show-extra-peer-details", 23 },
+ { "show-filterbar", 14 },
+ { "show-notification-area-icon", 27 },
+ { "show-options-window", 19 },
+ { "show-statusbar", 14 },
+ { "show-toolbar", 12 },
+ { "show-tracker-scrapes", 20 },
+ { "size-bytes", 10 },
+ { "size-units", 10 },
+ { "sizeWhenDone", 12 },
+ { "sort-mode", 9 },
+ { "sort-reversed", 13 },
+ { "speed", 5 },
+ { "speed-Bps", 9 },
+ { "speed-bytes", 11 },
+ { "speed-limit-down", 16 },
+ { "speed-limit-down-enabled", 24 },
+ { "speed-limit-up", 14 },
+ { "speed-limit-up-enabled", 22 },
+ { "speed-units", 11 },
+ { "start-added-torrents", 20 },
+ { "startDate", 9 },
+ { "status", 6 },
+ { "statusbar-stats", 15 },
+ { "tag", 3 },
+ { "tier", 4 },
+ { "time-checked", 12 },
+ { "torrent-added", 13 },
+ { "torrent-added-notification-command", 34 },
+ { "torrent-added-notification-enabled", 34 },
+ { "torrent-complete-notification-command", 37 },
+ { "torrent-complete-notification-enabled", 37 },
+ { "torrent-complete-sound-command", 30 },
+ { "torrent-complete-sound-enabled", 30 },
+ { "torrent-get", 11 },
+ { "torrent-set", 11 },
+ { "torrentCount", 12 },
+ { "torrentFile", 11 },
+ { "torrents", 8 },
+ { "totalSize", 9 },
+ { "total_size", 10 },
+ { "tracker id", 10 },
+ { "trackerAdd", 10 },
+ { "trackerRemove", 13 },
+ { "trackerReplace", 14 },
+ { "trackerStats", 12 },
+ { "trackers", 8 },
+ { "trash-can-enabled", 17 },
+ { "trash-original-torrent-files", 28 },
+ { "umask", 5 },
+ { "units", 5 },
+ { "upload-slots-per-torrent", 24 },
+ { "uploadLimit", 11 },
+ { "uploadLimited", 13 },
+ { "uploadRatio", 11 },
+ { "uploadSpeed", 11 },
+ { "upload_only", 11 },
+ { "uploaded", 8 },
+ { "uploaded-bytes", 14 },
+ { "uploadedBytes", 13 },
+ { "uploadedEver", 12 },
+ { "url-list", 8 },
+ { "use-global-speed-limit", 22 },
+ { "use-speed-limit", 15 },
+ { "user-has-given-informed-consent", 31 },
+ { "ut_comment", 10 },
+ { "ut_holepunch", 12 },
+ { "ut_metadata", 11 },
+ { "ut_pex", 6 },
+ { "ut_recommend", 12 },
+ { "utp-enabled", 11 },
+ { "v", 1 },
+ { "version", 7 },
+ { "wanted", 6 },
+ { "warning message", 15 },
+ { "watch-dir", 9 },
+ { "watch-dir-enabled", 17 },
+ { "webseeds", 8 },
+ { "webseedsSendingToUs", 19 }
+};
+
+static int
+compareKeys (const void * va, const void * vb)
+{
+ int ret;
+ const struct tr_key_struct * a = va;
+ const struct tr_key_struct * b = vb;
+
+ if (a->len == b->len)
+ {
+ ret = memcmp (a->str, b->str, a->len);
+ }
+ else if (a->len < b->len)
+ {
+ ret = memcmp (a->str, b->str, a->len);
+ if (!ret)
+ ret = -1;
+ }
+ else /* a->len > b->len */
+ {
+ ret = memcmp (a->str, b->str, b->len);
+ if (!ret)
+ ret = 1;
+ }
+
+ return ret;
+}
+
+static tr_ptrArray my_runtime = TR_PTR_ARRAY_INIT_STATIC;
+
+bool
+tr_quark_lookup (const void * str, size_t len, tr_quark * setme)
+{
+ struct tr_key_struct tmp;
+ struct tr_key_struct * match;
+ static const size_t n_static = sizeof(my_static) / sizeof(struct tr_key_struct);
+ bool success = false;
+
+ assert (n_static == TR_N_KEYS);
+
+ tmp.str = str;
+ tmp.len = len;
+
+ /* is it in our static array? */
+ match = bsearch (&tmp, my_static, n_static, sizeof(struct tr_key_struct), compareKeys);
+ if (match != NULL)
+ {
+ *setme = match - my_static;
+ success = true;
+ }
+
+ /* was it added during runtime? */
+ if (!success && !tr_ptrArrayEmpty(&my_runtime))
+ {
+ size_t i;
+ struct tr_key_struct ** runtime = (struct tr_key_struct **) tr_ptrArrayBase (&my_runtime);
+ const size_t n_runtime = tr_ptrArraySize (&my_runtime);
+ for (i=0; i<n_runtime; ++i)
+ {
+ if (compareKeys (&tmp, runtime[i]) == 0)
+ {
+ *setme = TR_N_KEYS + i;
+ success = true;
+ break;
+ }
+ }
+ }
+
+ return success;
+}
+
+static tr_quark
+append_new_quark (const void * str, size_t len)
+{
+ tr_quark ret;
+ struct tr_key_struct * tmp;
+ tmp = tr_new (struct tr_key_struct, 1);
+ tmp->str = tr_strndup (str, len);
+ tmp->len = len;
+ ret = TR_N_KEYS + tr_ptrArraySize (&my_runtime);
+ tr_ptrArrayAppend (&my_runtime, tmp);
+ return ret;
+}
+
+tr_quark
+tr_quark_new (const void * str, size_t len)
+{
+ tr_quark ret = TR_KEY_NONE;
+
+ if (str == NULL)
+ len = 0;
+ else if (len == (size_t)-1)
+ len = strlen (str);
+
+ if (!tr_quark_lookup (str, len, &ret))
+ ret = append_new_quark (str, len);
+
+ return ret;
+}
+
+const char *
+tr_quark_get_string (tr_quark q, size_t * len)
+{
+ const struct tr_key_struct * tmp;
+
+ if (q < TR_N_KEYS)
+ tmp = &my_static[q];
+ else
+ tmp = tr_ptrArrayNth (&my_runtime, q-TR_N_KEYS);
+
+ if (len != NULL)
+ *len = tmp->len;
+
+ return tmp->str;
+}
--- /dev/null
+/*
+ * This file Copyright (C) Mnemosyne LLC
+ *
+ * This file is licensed by the GPL version 2. Works owned by the
+ * Transmission project are granted a special exemption to clause 2 (b)
+ * so that the bulk of its code can remain under the MIT license.
+ * This exemption does not extend to derived works not owned by
+ * the Transmission project.
+ *
+ * $Id: utils.h 13667 2012-12-14 04:34:42Z jordan $
+ */
+
+#ifndef TR_QUARK_H
+#define TR_QUARK_H 1
+
+/* Quarks — a 2-way association between a string and a unique integer identifier */
+typedef size_t tr_quark;
+
+/*
+ * Predefined Quarks.
+ *
+ * TODO: it would be nice to clean up all the naming inconsistencies
+ * between RPC and settings. This will be a mess and we shouldn't be
+ * in a hurry to do it.
+ */
+enum
+{
+ TR_KEY_NONE, /* represented as an empty string */
+ TR_KEY_activeTorrentCount, /* rpc */
+ TR_KEY_activity_date, /* resume file */
+ TR_KEY_activityDate, /* rpc */
+ TR_KEY_added, /* pex */
+ TR_KEY_added_date, /* rpc */
+ TR_KEY_added_f, /* pex */
+ TR_KEY_added6, /* pex */
+ TR_KEY_added6_f, /* pex */
+ TR_KEY_addedDate, /* rpc */
+ TR_KEY_address, /* rpc */
+ TR_KEY_alt_speed_down, /* rpc, settings */
+ TR_KEY_alt_speed_enabled, /* rpc, settings */
+ TR_KEY_alt_speed_time_begin, /* rpc, settings */
+ TR_KEY_alt_speed_time_day, /* rpc, settings */
+ TR_KEY_alt_speed_time_enabled, /* rpc, settings */
+ TR_KEY_alt_speed_time_end, /* rpc, settings */
+ TR_KEY_alt_speed_up, /* rpc, settings */
+ TR_KEY_announce, /* metainfo */
+ TR_KEY_announce_list, /* metainfo */
+ TR_KEY_announceState, /* rpc */
+ TR_KEY_arguments, /* rpc */
+ TR_KEY_bandwidth_priority,
+ TR_KEY_bandwidthPriority,
+ TR_KEY_bind_address_ipv4,
+ TR_KEY_bind_address_ipv6,
+ TR_KEY_bitfield,
+ TR_KEY_blocklist_date,
+ TR_KEY_blocklist_enabled,
+ TR_KEY_blocklist_size,
+ TR_KEY_blocklist_updates_enabled,
+ TR_KEY_blocklist_url,
+ TR_KEY_blocks,
+ TR_KEY_bytesCompleted,
+ TR_KEY_cache_size_mb,
+ TR_KEY_clientIsChoked,
+ TR_KEY_clientIsInterested,
+ TR_KEY_clientName,
+ TR_KEY_comment,
+ TR_KEY_comment_utf_8,
+ TR_KEY_compact_view,
+ TR_KEY_complete,
+ TR_KEY_config_dir,
+ TR_KEY_cookies,
+ TR_KEY_corrupt,
+ TR_KEY_corruptEver,
+ TR_KEY_created_by,
+ TR_KEY_created_by_utf_8,
+ TR_KEY_creation_date,
+ TR_KEY_creator,
+ TR_KEY_cumulative_stats,
+ TR_KEY_current_stats,
+ TR_KEY_date,
+ TR_KEY_dateCreated,
+ TR_KEY_delete_local_data,
+ TR_KEY_desiredAvailable,
+ TR_KEY_destination,
+ TR_KEY_dht_enabled,
+ TR_KEY_display_name,
+ TR_KEY_dnd,
+ TR_KEY_done_date,
+ TR_KEY_doneDate,
+ TR_KEY_download_dir,
+ TR_KEY_download_dir_free_space,
+ TR_KEY_download_queue_enabled,
+ TR_KEY_download_queue_size,
+ TR_KEY_downloadCount,
+ TR_KEY_downloadDir,
+ TR_KEY_downloadLimit,
+ TR_KEY_downloadLimited,
+ TR_KEY_downloadSpeed,
+ TR_KEY_downloaded,
+ TR_KEY_downloaded_bytes,
+ TR_KEY_downloadedBytes,
+ TR_KEY_downloadedEver,
+ TR_KEY_downloaders,
+ TR_KEY_downloading_time_seconds,
+ TR_KEY_dropped,
+ TR_KEY_dropped6,
+ TR_KEY_e,
+ TR_KEY_encoding,
+ TR_KEY_encryption,
+ TR_KEY_error,
+ TR_KEY_errorString,
+ TR_KEY_eta,
+ TR_KEY_failure_reason,
+ TR_KEY_fields,
+ TR_KEY_fileStats,
+ TR_KEY_filename,
+ TR_KEY_files,
+ TR_KEY_files_added,
+ TR_KEY_files_unwanted,
+ TR_KEY_files_wanted,
+ TR_KEY_filesAdded,
+ TR_KEY_filter_mode,
+ TR_KEY_filter_text,
+ TR_KEY_filter_trackers,
+ TR_KEY_flagStr,
+ TR_KEY_flags,
+ TR_KEY_fromCache,
+ TR_KEY_fromDht,
+ TR_KEY_fromIncoming,
+ TR_KEY_fromLpd,
+ TR_KEY_fromLtep,
+ TR_KEY_fromPex,
+ TR_KEY_fromTracker,
+ TR_KEY_hasAnnounced,
+ TR_KEY_hasScraped,
+ TR_KEY_hashString,
+ TR_KEY_have,
+ TR_KEY_haveUnchecked,
+ TR_KEY_haveValid,
+ TR_KEY_honorsSessionLimits,
+ TR_KEY_host,
+ TR_KEY_id,
+ TR_KEY_idle_limit,
+ TR_KEY_idle_mode,
+ TR_KEY_idle_seeding_limit,
+ TR_KEY_idle_seeding_limit_enabled,
+ TR_KEY_ids,
+ TR_KEY_incomplete,
+ TR_KEY_incomplete_dir,
+ TR_KEY_incomplete_dir_enabled,
+ TR_KEY_info,
+ TR_KEY_info_hash,
+ TR_KEY_inhibit_desktop_hibernation,
+ TR_KEY_interval,
+ TR_KEY_ip,
+ TR_KEY_ipv4,
+ TR_KEY_ipv6,
+ TR_KEY_isBackup,
+ TR_KEY_isDownloadingFrom,
+ TR_KEY_isEncrypted,
+ TR_KEY_isFinished,
+ TR_KEY_isIncoming,
+ TR_KEY_isPrivate,
+ TR_KEY_isStalled,
+ TR_KEY_isUTP,
+ TR_KEY_isUploadingTo,
+ TR_KEY_lastAnnouncePeerCount,
+ TR_KEY_lastAnnounceResult,
+ TR_KEY_lastAnnounceStartTime,
+ TR_KEY_lastAnnounceSucceeded,
+ TR_KEY_lastAnnounceTime,
+ TR_KEY_lastAnnounceTimedOut,
+ TR_KEY_lastScrapeResult,
+ TR_KEY_lastScrapeStartTime,
+ TR_KEY_lastScrapeSucceeded,
+ TR_KEY_lastScrapeTime,
+ TR_KEY_lastScrapeTimedOut,
+ TR_KEY_ldp_enabled,
+ TR_KEY_leecherCount,
+ TR_KEY_leftUntilDone,
+ TR_KEY_length,
+ TR_KEY_location,
+ TR_KEY_lpd_enabled,
+ TR_KEY_m,
+ TR_KEY_magnet_info,
+ TR_KEY_magnetLink,
+ TR_KEY_main_window_height,
+ TR_KEY_main_window_is_maximized,
+ TR_KEY_main_window_layout_order,
+ TR_KEY_main_window_width,
+ TR_KEY_main_window_x,
+ TR_KEY_main_window_y,
+ TR_KEY_manualAnnounceTime,
+ TR_KEY_max_peers,
+ TR_KEY_maxConnectedPeers,
+ TR_KEY_memory_bytes,
+ TR_KEY_memory_units,
+ TR_KEY_message_level,
+ TR_KEY_metadataPercentComplete,
+ TR_KEY_metadata_size,
+ TR_KEY_metainfo,
+ TR_KEY_method,
+ TR_KEY_min_interval,
+ TR_KEY_min_request_interval,
+ TR_KEY_move,
+ TR_KEY_msg_type,
+ TR_KEY_mtimes,
+ TR_KEY_name,
+ TR_KEY_name_utf_8,
+ TR_KEY_nextAnnounceTime,
+ TR_KEY_nextScrapeTime,
+ TR_KEY_nodes,
+ TR_KEY_nodes6,
+ TR_KEY_open_dialog_dir,
+ TR_KEY_p,
+ TR_KEY_path,
+ TR_KEY_path_utf_8,
+ TR_KEY_paused,
+ TR_KEY_pausedTorrentCount,
+ TR_KEY_peer_congestion_algorithm,
+ TR_KEY_peer_limit,
+ TR_KEY_peer_limit_global,
+ TR_KEY_peer_limit_per_torrent,
+ TR_KEY_peer_port,
+ TR_KEY_peer_port_random_high,
+ TR_KEY_peer_port_random_low,
+ TR_KEY_peer_port_random_on_start,
+ TR_KEY_peer_socket_tos,
+ TR_KEY_peerIsChoked,
+ TR_KEY_peerIsInterested,
+ TR_KEY_peers,
+ TR_KEY_peers2,
+ TR_KEY_peers2_6,
+ TR_KEY_peers6,
+ TR_KEY_peersConnected,
+ TR_KEY_peersFrom,
+ TR_KEY_peersGettingFromUs,
+ TR_KEY_peersSendingToUs,
+ TR_KEY_percentDone,
+ TR_KEY_pex_enabled,
+ TR_KEY_piece,
+ TR_KEY_piece_length,
+ TR_KEY_pieceCount,
+ TR_KEY_pieceSize,
+ TR_KEY_pieces,
+ TR_KEY_play_download_complete_sound,
+ TR_KEY_port,
+ TR_KEY_port_forwarding_enabled,
+ TR_KEY_port_is_open,
+ TR_KEY_preallocation,
+ TR_KEY_prefetch_enabled,
+ TR_KEY_priorities,
+ TR_KEY_priority,
+ TR_KEY_priority_high,
+ TR_KEY_priority_low,
+ TR_KEY_priority_normal,
+ TR_KEY_private,
+ TR_KEY_progress,
+ TR_KEY_prompt_before_exit,
+ TR_KEY_queue_move_bottom,
+ TR_KEY_queue_move_down,
+ TR_KEY_queue_move_top,
+ TR_KEY_queue_move_up,
+ TR_KEY_queue_stalled_enabled,
+ TR_KEY_queue_stalled_minutes,
+ TR_KEY_queuePosition,
+ TR_KEY_rateDownload,
+ TR_KEY_rateToClient,
+ TR_KEY_rateToPeer,
+ TR_KEY_rateUpload,
+ TR_KEY_ratio_limit,
+ TR_KEY_ratio_limit_enabled,
+ TR_KEY_ratio_mode,
+ TR_KEY_recent_download_dir_1,
+ TR_KEY_recent_download_dir_2,
+ TR_KEY_recent_download_dir_3,
+ TR_KEY_recent_download_dir_4,
+ TR_KEY_recheckProgress,
+ TR_KEY_remote_session_enabled,
+ TR_KEY_remote_session_host,
+ TR_KEY_remote_session_password,
+ TR_KEY_remote_session_port,
+ TR_KEY_remote_session_requres_authentication,
+ TR_KEY_remote_session_username,
+ TR_KEY_removed,
+ TR_KEY_rename_partial_files,
+ TR_KEY_reqq,
+ TR_KEY_result,
+ TR_KEY_rpc_authentication_required,
+ TR_KEY_rpc_bind_address,
+ TR_KEY_rpc_enabled,
+ TR_KEY_rpc_password,
+ TR_KEY_rpc_port,
+ TR_KEY_rpc_url,
+ TR_KEY_rpc_username,
+ TR_KEY_rpc_version,
+ TR_KEY_rpc_version_minimum,
+ TR_KEY_rpc_whitelist,
+ TR_KEY_rpc_whitelist_enabled,
+ TR_KEY_scrape,
+ TR_KEY_scrape_paused_torrents_enabled,
+ TR_KEY_scrapeState,
+ TR_KEY_script_torrent_done_enabled,
+ TR_KEY_script_torrent_done_filename,
+ TR_KEY_seconds_active,
+ TR_KEY_secondsActive,
+ TR_KEY_secondsDownloading,
+ TR_KEY_secondsSeeding,
+ TR_KEY_seed_queue_enabled,
+ TR_KEY_seed_queue_size,
+ TR_KEY_seedIdleLimit,
+ TR_KEY_seedIdleMode,
+ TR_KEY_seedRatioLimit,
+ TR_KEY_seedRatioLimited,
+ TR_KEY_seedRatioMode,
+ TR_KEY_seederCount,
+ TR_KEY_seeding_time_seconds,
+ TR_KEY_session_count,
+ TR_KEY_sessionCount,
+ TR_KEY_show_backup_trackers,
+ TR_KEY_show_desktop_notification,
+ TR_KEY_show_extra_peer_details,
+ TR_KEY_show_filterbar,
+ TR_KEY_show_notification_area_icon,
+ TR_KEY_show_options_window,
+ TR_KEY_show_statusbar,
+ TR_KEY_show_toolbar,
+ TR_KEY_show_tracker_scrapes,
+ TR_KEY_size_bytes,
+ TR_KEY_size_units,
+ TR_KEY_sizeWhenDone,
+ TR_KEY_sort_mode,
+ TR_KEY_sort_reversed,
+ TR_KEY_speed,
+ TR_KEY_speed_Bps,
+ TR_KEY_speed_bytes,
+ TR_KEY_speed_limit_down,
+ TR_KEY_speed_limit_down_enabled,
+ TR_KEY_speed_limit_up,
+ TR_KEY_speed_limit_up_enabled,
+ TR_KEY_speed_units,
+ TR_KEY_start_added_torrents,
+ TR_KEY_startDate,
+ TR_KEY_status,
+ TR_KEY_statusbar_stats,
+ TR_KEY_tag,
+ TR_KEY_tier,
+ TR_KEY_time_checked,
+ TR_KEY_torrent_added,
+ TR_KEY_torrent_added_notification_command,
+ TR_KEY_torrent_added_notification_enabled,
+ TR_KEY_torrent_complete_notification_command,
+ TR_KEY_torrent_complete_notification_enabled,
+ TR_KEY_torrent_complete_sound_command,
+ TR_KEY_torrent_complete_sound_enabled,
+ TR_KEY_torrent_get,
+ TR_KEY_torrent_set,
+ TR_KEY_torrentCount,
+ TR_KEY_torrentFile,
+ TR_KEY_torrents,
+ TR_KEY_totalSize,
+ TR_KEY_total_size,
+ TR_KEY_tracker_id,
+ TR_KEY_trackerAdd,
+ TR_KEY_trackerRemove,
+ TR_KEY_trackerReplace,
+ TR_KEY_trackerStats,
+ TR_KEY_trackers,
+ TR_KEY_trash_can_enabled,
+ TR_KEY_trash_original_torrent_files,
+ TR_KEY_umask,
+ TR_KEY_units,
+ TR_KEY_upload_slots_per_torrent,
+ TR_KEY_uploadLimit,
+ TR_KEY_uploadLimited,
+ TR_KEY_uploadRatio,
+ TR_KEY_uploadSpeed,
+ TR_KEY_upload_only,
+ TR_KEY_uploaded,
+ TR_KEY_uploaded_bytes,
+ TR_KEY_uploadedBytes,
+ TR_KEY_uploadedEver,
+ TR_KEY_url_list,
+ TR_KEY_use_global_speed_limit,
+ TR_KEY_use_speed_limit,
+ TR_KEY_user_has_given_informed_consent,
+ TR_KEY_ut_comment,
+ TR_KEY_ut_holepunch,
+ TR_KEY_ut_metadata,
+ TR_KEY_ut_pex,
+ TR_KEY_ut_recommend,
+ TR_KEY_utp_enabled,
+ TR_KEY_v,
+ TR_KEY_version,
+ TR_KEY_wanted,
+ TR_KEY_warning_message,
+ TR_KEY_watch_dir,
+ TR_KEY_watch_dir_enabled,
+ TR_KEY_webseeds,
+ TR_KEY_webseedsSendingToUs,
+ TR_N_KEYS
+};
+
+/**
+ * Find the quark that matches the specified string
+ *
+ * @return true if the specified string exists as a quark
+ */
+bool tr_quark_lookup (const void * str, size_t len, tr_quark * setme);
+
+/**
+ * Get the string that corresponds to the specified quark
+ */
+const char * tr_quark_get_string (const tr_quark quark, size_t * len);
+
+/**
+ * Create a new quark for the specified string. If a quark already
+ * exists for that string, it is returned so that no duplicates are
+ * created.
+ */
+tr_quark tr_quark_new (const void * str, size_t len);
+
+
+#endif
#include "utils.h" /* tr_buildPath */
#include "variant.h"
-#define KEY_ACTIVITY_DATE "activity-date"
-#define KEY_ADDED_DATE "added-date"
-#define KEY_CORRUPT "corrupt"
-#define KEY_DONE_DATE "done-date"
-#define KEY_DOWNLOAD_DIR "destination"
-#define KEY_DND "dnd"
-#define KEY_DOWNLOADED "downloaded"
-#define KEY_INCOMPLETE_DIR "incomplete-dir"
-#define KEY_MAX_PEERS "max-peers"
-#define KEY_PAUSED "paused"
-#define KEY_PEERS "peers2"
-#define KEY_PEERS6 "peers2-6"
-#define KEY_FILE_PRIORITIES "priority"
-#define KEY_BANDWIDTH_PRIORITY "bandwidth-priority"
-#define KEY_PROGRESS "progress"
-#define KEY_SPEEDLIMIT_OLD "speed-limit"
-#define KEY_SPEEDLIMIT_UP "speed-limit-up"
-#define KEY_SPEEDLIMIT_DOWN "speed-limit-down"
-#define KEY_RATIOLIMIT "ratio-limit"
-#define KEY_IDLELIMIT "idle-limit"
-#define KEY_UPLOADED "uploaded"
-
-#define KEY_SPEED_KiBps "speed"
-#define KEY_SPEED_Bps "speed-Bps"
-#define KEY_USE_GLOBAL_SPEED_LIMIT "use-global-speed-limit"
-#define KEY_USE_SPEED_LIMIT "use-speed-limit"
-#define KEY_TIME_SEEDING "seeding-time-seconds"
-#define KEY_TIME_DOWNLOADING "downloading-time-seconds"
-#define KEY_SPEEDLIMIT_DOWN_SPEED "down-speed"
-#define KEY_SPEEDLIMIT_DOWN_MODE "down-mode"
-#define KEY_SPEEDLIMIT_UP_SPEED "up-speed"
-#define KEY_SPEEDLIMIT_UP_MODE "up-mode"
-#define KEY_RATIOLIMIT_RATIO "ratio-limit"
-#define KEY_RATIOLIMIT_MODE "ratio-mode"
-#define KEY_IDLELIMIT_MINS "idle-limit"
-#define KEY_IDLELIMIT_MODE "idle-mode"
-
-#define KEY_PROGRESS_CHECKTIME "time-checked"
-#define KEY_PROGRESS_MTIMES "mtimes"
-#define KEY_PROGRESS_BITFIELD "bitfield"
-#define KEY_PROGRESS_BLOCKS "blocks"
-#define KEY_PROGRESS_BLOCKS_STRLEN 6
-#define KEY_PROGRESS_HAVE "have"
-
enum
{
MAX_REMEMBERED_PEERS = 200
count = tr_peerMgrGetPeers ((tr_torrent*) tor, &pex, TR_AF_INET, TR_PEERS_INTERESTING, MAX_REMEMBERED_PEERS);
if (count > 0)
- tr_variantDictAddRaw (dict, KEY_PEERS, pex, sizeof (tr_pex) * count);
+ tr_variantDictAddRaw (dict, TR_KEY_peers2, pex, sizeof (tr_pex) * count);
tr_free (pex);
count = tr_peerMgrGetPeers ((tr_torrent*) tor, &pex, TR_AF_INET6, TR_PEERS_INTERESTING, MAX_REMEMBERED_PEERS);
if (count > 0)
- tr_variantDictAddRaw (dict, KEY_PEERS6, pex, sizeof (tr_pex) * count);
+ tr_variantDictAddRaw (dict, TR_KEY_peers2_6, pex, sizeof (tr_pex) * count);
tr_free (pex);
}
const uint8_t * str;
size_t len;
- if (tr_variantDictFindRaw (dict, KEY_PEERS, &str, &len))
+ if (tr_variantDictFindRaw (dict, TR_KEY_peers, &str, &len))
{
const int numAdded = addPeers (tor, str, len);
tr_tordbg (tor, "Loaded %d IPv4 peers from resume file", numAdded);
ret = TR_FR_PEERS;
}
- if (tr_variantDictFindRaw (dict, KEY_PEERS6, &str, &len))
+ if (tr_variantDictFindRaw (dict, TR_KEY_peers6, &str, &len))
{
const int numAdded = addPeers (tor, str, len);
tr_tordbg (tor, "Loaded %d IPv6 peers from resume file", numAdded);
const tr_info * const inf = tr_torrentInfo (tor);
const tr_file_index_t n = inf->fileCount;
- list = tr_variantDictAddList (dict, KEY_DND, n);
+ list = tr_variantDictAddList (dict, TR_KEY_dnd, n);
for (i=0; i<n; ++i)
tr_variantListAddInt (list, inf->files[i].dnd ? 1 : 0);
}
tr_variant * list = NULL;
const tr_file_index_t n = tor->info.fileCount;
- if (tr_variantDictFindList (dict, KEY_DND, &list)
+ if (tr_variantDictFindList (dict, TR_KEY_dnd, &list)
&& (tr_variantListSize (list) == n))
{
int64_t tmp;
const tr_info * const inf = tr_torrentInfo (tor);
const tr_file_index_t n = inf->fileCount;
- list = tr_variantDictAddList (dict, KEY_FILE_PRIORITIES, n);
+ list = tr_variantDictAddList (dict, TR_KEY_priority, n);
for (i = 0; i < n; ++i)
tr_variantListAddInt (list, inf->files[i].priority);
}
uint64_t ret = 0;
const tr_file_index_t n = tor->info.fileCount;
- if (tr_variantDictFindList (dict, KEY_FILE_PRIORITIES, &list)
+ if (tr_variantDictFindList (dict, TR_KEY_priority, &list)
&& (tr_variantListSize (list) == n))
{
int64_t priority;
saveSingleSpeedLimit (tr_variant * d, tr_torrent * tor, tr_direction dir)
{
tr_variantDictReserve (d, 3);
- tr_variantDictAddInt (d, KEY_SPEED_Bps, tr_torrentGetSpeedLimit_Bps (tor, dir));
- tr_variantDictAddBool (d, KEY_USE_GLOBAL_SPEED_LIMIT, tr_torrentUsesSessionLimits (tor));
- tr_variantDictAddBool (d, KEY_USE_SPEED_LIMIT, tr_torrentUsesSpeedLimit (tor, dir));
+ tr_variantDictAddInt (d, TR_KEY_speed_Bps, tr_torrentGetSpeedLimit_Bps (tor, dir));
+ tr_variantDictAddBool (d, TR_KEY_use_global_speed_limit, tr_torrentUsesSessionLimits (tor));
+ tr_variantDictAddBool (d, TR_KEY_use_speed_limit, tr_torrentUsesSpeedLimit (tor, dir));
}
static void
saveSpeedLimits (tr_variant * dict, tr_torrent * tor)
{
- saveSingleSpeedLimit (tr_variantDictAddDict (dict, KEY_SPEEDLIMIT_DOWN, 0), tor, TR_DOWN);
- saveSingleSpeedLimit (tr_variantDictAddDict (dict, KEY_SPEEDLIMIT_UP, 0), tor, TR_UP);
+ saveSingleSpeedLimit (tr_variantDictAddDict (dict, TR_KEY_speed_limit_down, 0), tor, TR_DOWN);
+ saveSingleSpeedLimit (tr_variantDictAddDict (dict, TR_KEY_speed_limit_up, 0), tor, TR_UP);
}
static void
saveRatioLimits (tr_variant * dict, tr_torrent * tor)
{
- tr_variant * d = tr_variantDictAddDict (dict, KEY_RATIOLIMIT, 2);
- tr_variantDictAddReal (d, KEY_RATIOLIMIT_RATIO, tr_torrentGetRatioLimit (tor));
- tr_variantDictAddInt (d, KEY_RATIOLIMIT_MODE, tr_torrentGetRatioMode (tor));
+ tr_variant * d = tr_variantDictAddDict (dict, TR_KEY_ratio_limit, 2);
+ tr_variantDictAddReal (d, TR_KEY_ratio_limit, tr_torrentGetRatioLimit (tor));
+ tr_variantDictAddInt (d, TR_KEY_ratio_mode, tr_torrentGetRatioMode (tor));
}
static void
saveIdleLimits (tr_variant * dict, tr_torrent * tor)
{
- tr_variant * d = tr_variantDictAddDict (dict, KEY_IDLELIMIT, 2);
- tr_variantDictAddInt (d, KEY_IDLELIMIT_MINS, tr_torrentGetIdleLimit (tor));
- tr_variantDictAddInt (d, KEY_IDLELIMIT_MODE, tr_torrentGetIdleMode (tor));
+ tr_variant * d = tr_variantDictAddDict (dict, TR_KEY_idle_limit, 2);
+ tr_variantDictAddInt (d, TR_KEY_idle_limit, tr_torrentGetIdleLimit (tor));
+ tr_variantDictAddInt (d, TR_KEY_idle_mode, tr_torrentGetIdleMode (tor));
}
static void
int64_t i;
bool boolVal;
- if (tr_variantDictFindInt (d, KEY_SPEED_Bps, &i))
+ if (tr_variantDictFindInt (d, TR_KEY_speed_Bps, &i))
tr_torrentSetSpeedLimit_Bps (tor, dir, i);
- else if (tr_variantDictFindInt (d, KEY_SPEED_KiBps, &i))
+ else if (tr_variantDictFindInt (d, TR_KEY_speed, &i))
tr_torrentSetSpeedLimit_Bps (tor, dir, i*1024);
- if (tr_variantDictFindBool (d, KEY_USE_SPEED_LIMIT, &boolVal))
+ if (tr_variantDictFindBool (d, TR_KEY_use_speed_limit, &boolVal))
tr_torrentUseSpeedLimit (tor, dir, boolVal);
- if (tr_variantDictFindBool (d, KEY_USE_GLOBAL_SPEED_LIMIT, &boolVal))
+ if (tr_variantDictFindBool (d, TR_KEY_use_global_speed_limit, &boolVal))
tr_torrentUseSessionLimits (tor, boolVal);
}
uint64_t ret = 0;
- if (tr_variantDictFindDict (dict, KEY_SPEEDLIMIT_UP, &d))
+ if (tr_variantDictFindDict (dict, TR_KEY_speed_limit_up, &d))
{
loadSingleSpeedLimit (d, TR_UP, tor);
ret = TR_FR_SPEEDLIMIT;
}
- if (tr_variantDictFindDict (dict, KEY_SPEEDLIMIT_DOWN, &d))
+ if (tr_variantDictFindDict (dict, TR_KEY_speed_limit_down, &d))
{
loadSingleSpeedLimit (d, TR_DOWN, tor);
ret = TR_FR_SPEEDLIMIT;
}
- /* older speedlimit structure */
- if (!ret && tr_variantDictFindDict (dict, KEY_SPEEDLIMIT_OLD, &d))
- {
-
- int64_t i;
- if (tr_variantDictFindInt (d, KEY_SPEEDLIMIT_DOWN_SPEED, &i))
- tr_torrentSetSpeedLimit_Bps (tor, TR_DOWN, i*1024);
- if (tr_variantDictFindInt (d, KEY_SPEEDLIMIT_DOWN_MODE, &i)) {
- tr_torrentUseSpeedLimit (tor, TR_DOWN, i==TR_SPEEDLIMIT_SINGLE);
- tr_torrentUseSessionLimits (tor, i==TR_SPEEDLIMIT_GLOBAL);
- }
- if (tr_variantDictFindInt (d, KEY_SPEEDLIMIT_UP_SPEED, &i))
- tr_torrentSetSpeedLimit_Bps (tor, TR_UP, i*1024);
- if (tr_variantDictFindInt (d, KEY_SPEEDLIMIT_UP_MODE, &i)) {
- tr_torrentUseSpeedLimit (tor, TR_UP, i==TR_SPEEDLIMIT_SINGLE);
- tr_torrentUseSessionLimits (tor, i==TR_SPEEDLIMIT_GLOBAL);
- }
- ret = TR_FR_SPEEDLIMIT;
- }
-
return ret;
}
tr_variant * d;
uint64_t ret = 0;
- if (tr_variantDictFindDict (dict, KEY_RATIOLIMIT, &d))
+ if (tr_variantDictFindDict (dict, TR_KEY_ratio_limit, &d))
{
int64_t i;
double dratio;
- if (tr_variantDictFindReal (d, KEY_RATIOLIMIT_RATIO, &dratio))
+ if (tr_variantDictFindReal (d, TR_KEY_ratio_limit, &dratio))
tr_torrentSetRatioLimit (tor, dratio);
- if (tr_variantDictFindInt (d, KEY_RATIOLIMIT_MODE, &i))
+ if (tr_variantDictFindInt (d, TR_KEY_ratio_mode, &i))
tr_torrentSetRatioMode (tor, i);
ret = TR_FR_RATIOLIMIT;
}
tr_variant * d;
uint64_t ret = 0;
- if (tr_variantDictFindDict (dict, KEY_IDLELIMIT, &d))
+ if (tr_variantDictFindDict (dict, TR_KEY_idle_limit, &d))
{
int64_t i;
int64_t imin;
- if (tr_variantDictFindInt (d, KEY_IDLELIMIT_MINS, &imin))
+ if (tr_variantDictFindInt (d, TR_KEY_idle_limit, &imin))
tr_torrentSetIdleLimit (tor, imin);
- if (tr_variantDictFindInt (d, KEY_IDLELIMIT_MODE, &i))
+ if (tr_variantDictFindInt (d, TR_KEY_idle_mode, &i))
tr_torrentSetIdleMode (tor, i);
ret = TR_FR_IDLELIMIT;
}
const tr_info * inf = tr_torrentInfo (tor);
const time_t now = tr_time ();
- prog = tr_variantDictAddDict (dict, KEY_PROGRESS, 3);
+ prog = tr_variantDictAddDict (dict, TR_KEY_progress, 3);
/* add the file/piece check timestamps... */
- l = tr_variantDictAddList (prog, KEY_PROGRESS_CHECKTIME, inf->fileCount);
+ l = tr_variantDictAddList (prog, TR_KEY_time_checked, inf->fileCount);
for (fi=0; fi<inf->fileCount; ++fi)
{
const tr_piece * p;
/* add the progress */
if (tor->completeness == TR_SEED)
- tr_variantDictAddStr (prog, KEY_PROGRESS_HAVE, "all");
+ tr_variantDictAddStr (prog, TR_KEY_have, "all");
/* add the blocks bitfield */
- bitfieldToBenc (&tor->completion.blockBitfield,
- tr_variantDictAdd (prog, KEY_PROGRESS_BLOCKS, KEY_PROGRESS_BLOCKS_STRLEN));
+ bitfieldToBenc (&tor->completion.blockBitfield, tr_variantDictAdd (prog, TR_KEY_blocks));
}
static uint64_t
for (i=0, n=inf->pieceCount; i<n; ++i)
inf->pieces[i].timeChecked = 0;
- if (tr_variantDictFindDict (dict, KEY_PROGRESS, &prog))
+ if (tr_variantDictFindDict (dict, TR_KEY_progress, &prog))
{
const char * err;
const char * str;
tr_variant * b;
struct tr_bitfield blocks = TR_BITFIELD_INIT;
- if (tr_variantDictFindList (prog, KEY_PROGRESS_CHECKTIME, &l))
+ if (tr_variantDictFindList (prog, TR_KEY_time_checked, &l))
{
/* per-piece timestamps were added in 2.20.
}
}
}
- else if (tr_variantDictFindList (prog, KEY_PROGRESS_MTIMES, &l))
+ else if (tr_variantDictFindList (prog, TR_KEY_mtimes, &l))
{
tr_file_index_t fi;
err = NULL;
tr_bitfieldConstruct (&blocks, tor->blockCount);
- if ((b = tr_variantDictFind (prog, KEY_PROGRESS_BLOCKS)))
+ if ((b = tr_variantDictFind (prog, TR_KEY_blocks)))
{
size_t buflen;
const uint8_t * buf;
else
tr_bitfieldSetRaw (&blocks, buf, buflen, true);
}
- else if (tr_variantDictFindStr (prog, KEY_PROGRESS_HAVE, &str, NULL))
+ else if (tr_variantDictFindStr (prog, TR_KEY_have, &str, NULL))
{
if (!strcmp (str, "all"))
tr_bitfieldSetHasAll (&blocks);
else
err = "Invalid value for HAVE";
}
- else if (tr_variantDictFindRaw (prog, KEY_PROGRESS_BITFIELD, &raw, &rawlen))
+ else if (tr_variantDictFindRaw (prog, TR_KEY_bitfield, &raw, &rawlen))
{
tr_bitfieldSetRaw (&blocks, raw, rawlen, true);
}
return;
tr_variantInitDict (&top, 50); /* arbitrary "big enough" number */
- tr_variantDictAddInt (&top, KEY_TIME_SEEDING, tor->secondsSeeding);
- tr_variantDictAddInt (&top, KEY_TIME_DOWNLOADING, tor->secondsDownloading);
- tr_variantDictAddInt (&top, KEY_ACTIVITY_DATE, tor->activityDate);
- tr_variantDictAddInt (&top, KEY_ADDED_DATE, tor->addedDate);
- tr_variantDictAddInt (&top, KEY_CORRUPT, tor->corruptPrev + tor->corruptCur);
- tr_variantDictAddInt (&top, KEY_DONE_DATE, tor->doneDate);
- tr_variantDictAddStr (&top, KEY_DOWNLOAD_DIR, tor->downloadDir);
+ tr_variantDictAddInt (&top, TR_KEY_seeding_time_seconds, tor->secondsSeeding);
+ tr_variantDictAddInt (&top, TR_KEY_downloading_time_seconds, tor->secondsDownloading);
+ tr_variantDictAddInt (&top, TR_KEY_activity_date, tor->activityDate);
+ tr_variantDictAddInt (&top, TR_KEY_added_date, tor->addedDate);
+ tr_variantDictAddInt (&top, TR_KEY_corrupt, tor->corruptPrev + tor->corruptCur);
+ tr_variantDictAddInt (&top, TR_KEY_done_date, tor->doneDate);
+ tr_variantDictAddStr (&top, TR_KEY_destination, tor->downloadDir);
if (tor->incompleteDir != NULL)
- tr_variantDictAddStr (&top, KEY_INCOMPLETE_DIR, tor->incompleteDir);
- tr_variantDictAddInt (&top, KEY_DOWNLOADED, tor->downloadedPrev + tor->downloadedCur);
- tr_variantDictAddInt (&top, KEY_UPLOADED, tor->uploadedPrev + tor->uploadedCur);
- tr_variantDictAddInt (&top, KEY_MAX_PEERS, tor->maxConnectedPeers);
- tr_variantDictAddInt (&top, KEY_BANDWIDTH_PRIORITY, tr_torrentGetPriority (tor));
- tr_variantDictAddBool (&top, KEY_PAUSED, !tor->isRunning);
+ tr_variantDictAddStr (&top, TR_KEY_incomplete_dir, tor->incompleteDir);
+ tr_variantDictAddInt (&top, TR_KEY_downloaded, tor->downloadedPrev + tor->downloadedCur);
+ tr_variantDictAddInt (&top, TR_KEY_uploaded, tor->uploadedPrev + tor->uploadedCur);
+ tr_variantDictAddInt (&top, TR_KEY_max_peers, tor->maxConnectedPeers);
+ tr_variantDictAddInt (&top, TR_KEY_bandwidth_priority, tr_torrentGetPriority (tor));
+ tr_variantDictAddBool (&top, TR_KEY_paused, !tor->isRunning);
savePeers (&top, tor);
if (tr_torrentHasMetadata (tor))
{
tr_tordbg (tor, "Read resume file \"%s\"", filename);
if ((fieldsToLoad & TR_FR_CORRUPT)
- && tr_variantDictFindInt (&top, KEY_CORRUPT, &i))
+ && tr_variantDictFindInt (&top, TR_KEY_corrupt, &i))
{
tor->corruptPrev = i;
fieldsLoaded |= TR_FR_CORRUPT;
}
if ((fieldsToLoad & (TR_FR_PROGRESS | TR_FR_DOWNLOAD_DIR))
- && (tr_variantDictFindStr (&top, KEY_DOWNLOAD_DIR, &str, &len))
+ && (tr_variantDictFindStr (&top, TR_KEY_destination, &str, &len))
&& (str && *str))
{
tr_free (tor->downloadDir);
}
if ((fieldsToLoad & (TR_FR_PROGRESS | TR_FR_INCOMPLETE_DIR))
- && (tr_variantDictFindStr (&top, KEY_INCOMPLETE_DIR, &str, &len))
+ && (tr_variantDictFindStr (&top, TR_KEY_incomplete_dir, &str, &len))
&& (str && *str))
{
tr_free (tor->incompleteDir);
}
if ((fieldsToLoad & TR_FR_DOWNLOADED)
- && tr_variantDictFindInt (&top, KEY_DOWNLOADED, &i))
+ && tr_variantDictFindInt (&top, TR_KEY_downloaded, &i))
{
tor->downloadedPrev = i;
fieldsLoaded |= TR_FR_DOWNLOADED;
}
if ((fieldsToLoad & TR_FR_UPLOADED)
- && tr_variantDictFindInt (&top, KEY_UPLOADED, &i))
+ && tr_variantDictFindInt (&top, TR_KEY_uploaded, &i))
{
tor->uploadedPrev = i;
fieldsLoaded |= TR_FR_UPLOADED;
}
if ((fieldsToLoad & TR_FR_MAX_PEERS)
- && tr_variantDictFindInt (&top, KEY_MAX_PEERS, &i))
+ && tr_variantDictFindInt (&top, TR_KEY_max_peers, &i))
{
tor->maxConnectedPeers = i;
fieldsLoaded |= TR_FR_MAX_PEERS;
}
if ((fieldsToLoad & TR_FR_RUN)
- && tr_variantDictFindBool (&top, KEY_PAUSED, &boolVal))
+ && tr_variantDictFindBool (&top, TR_KEY_paused, &boolVal))
{
tor->isRunning = !boolVal;
fieldsLoaded |= TR_FR_RUN;
}
if ((fieldsToLoad & TR_FR_ADDED_DATE)
- && tr_variantDictFindInt (&top, KEY_ADDED_DATE, &i))
+ && tr_variantDictFindInt (&top, TR_KEY_added_date, &i))
{
tor->addedDate = i;
fieldsLoaded |= TR_FR_ADDED_DATE;
}
if ((fieldsToLoad & TR_FR_DONE_DATE)
- && tr_variantDictFindInt (&top, KEY_DONE_DATE, &i))
+ && tr_variantDictFindInt (&top, TR_KEY_done_date, &i))
{
tor->doneDate = i;
fieldsLoaded |= TR_FR_DONE_DATE;
}
if ((fieldsToLoad & TR_FR_ACTIVITY_DATE)
- && tr_variantDictFindInt (&top, KEY_ACTIVITY_DATE, &i))
+ && tr_variantDictFindInt (&top, TR_KEY_activity_date, &i))
{
tr_torrentSetActivityDate (tor, i);
fieldsLoaded |= TR_FR_ACTIVITY_DATE;
}
if ((fieldsToLoad & TR_FR_TIME_SEEDING)
- && tr_variantDictFindInt (&top, KEY_TIME_SEEDING, &i))
+ && tr_variantDictFindInt (&top, TR_KEY_seeding_time_seconds, &i))
{
tor->secondsSeeding = i;
fieldsLoaded |= TR_FR_TIME_SEEDING;
}
if ((fieldsToLoad & TR_FR_TIME_DOWNLOADING)
- && tr_variantDictFindInt (&top, KEY_TIME_DOWNLOADING, &i))
+ && tr_variantDictFindInt (&top, TR_KEY_downloading_time_seconds, &i))
{
tor->secondsDownloading = i;
fieldsLoaded |= TR_FR_TIME_DOWNLOADING;
}
if ((fieldsToLoad & TR_FR_BANDWIDTH_PRIORITY)
- && tr_variantDictFindInt (&top, KEY_BANDWIDTH_PRIORITY, &i)
+ && tr_variantDictFindInt (&top, TR_KEY_bandwidth_priority, &i)
&& tr_isPriority (i))
{
tr_torrentSetPriority (tor, i);
body_len -= 2;
tr_variantInitDict (&top, 2);
- tr_variantDictAddStr (&top, "method", "torrent-add");
- args = tr_variantDictAddDict (&top, "arguments", 2);
- tr_variantDictAddBool (args, "paused", paused);
+ tr_variantDictAddStr (&top, TR_KEY_method, "torrent-add");
+ args = tr_variantDictAddDict (&top, TR_KEY_arguments, 2);
+ tr_variantDictAddBool (args, TR_KEY_paused, paused);
if (tr_urlIsValid (body, body_len))
{
- tr_variantDictAddRaw (args, "filename", body, body_len);
+ tr_variantDictAddRaw (args, TR_KEY_filename, body, body_len);
have_source = true;
}
else if (!tr_variantFromBenc (&test, body, body_len))
{
char * b64 = tr_base64_encode (body, body_len, NULL);
- tr_variantDictAddStr (args, "metainfo", b64);
+ tr_variantDictAddStr (args, TR_KEY_metainfo, b64);
tr_free (b64);
have_source = true;
}
*ps = NULL;
}
+static void
+missing_settings_key (const tr_quark q)
+{
+ const char * str = tr_quark_get_string (q, NULL);
+ tr_nerr (MY_NAME, _("Couldn't find settings key \"%s\""), str);
+}
+
tr_rpc_server *
tr_rpcInit (tr_session * session, tr_variant * settings)
{
bool boolVal;
int64_t i;
const char * str;
- const char * key;
+ tr_quark key;
tr_address address;
s = tr_new0 (tr_rpc_server, 1);
s->session = session;
- key = TR_PREFS_KEY_RPC_ENABLED;
+ key = TR_KEY_rpc_enabled;
if (!tr_variantDictFindBool (settings, key, &boolVal))
- tr_nerr (MY_NAME, _("Couldn't find settings key \"%s\""), key);
+ missing_settings_key (key);
else
s->isEnabled = boolVal;
- key = TR_PREFS_KEY_RPC_PORT;
+ key = TR_KEY_rpc_port;
if (!tr_variantDictFindInt (settings, key, &i))
- tr_nerr (MY_NAME, _("Couldn't find settings key \"%s\""), key);
+ missing_settings_key (key);
else
s->port = i;
- key = TR_PREFS_KEY_RPC_URL;
- if (!tr_variantDictFindStr (settings, TR_PREFS_KEY_RPC_URL, &str, NULL))
- tr_nerr (MY_NAME, _("Couldn't find settings key \"%s\""), key);
+ key = TR_KEY_rpc_url;
+ if (!tr_variantDictFindStr (settings, key, &str, NULL))
+ missing_settings_key (key);
else
s->url = tr_strdup (str);
- key = TR_PREFS_KEY_RPC_WHITELIST_ENABLED;
+ key = TR_KEY_rpc_whitelist_enabled;
if (!tr_variantDictFindBool (settings, key, &boolVal))
- tr_nerr (MY_NAME, _("Couldn't find settings key \"%s\""), key);
+ missing_settings_key (key);
else
tr_rpcSetWhitelistEnabled (s, boolVal);
- key = TR_PREFS_KEY_RPC_AUTH_REQUIRED;
+ key = TR_KEY_rpc_authentication_required;
if (!tr_variantDictFindBool (settings, key, &boolVal))
- tr_nerr (MY_NAME, _("Couldn't find settings key \"%s\""), key);
+ missing_settings_key (key);
else
tr_rpcSetPasswordEnabled (s, boolVal);
- key = TR_PREFS_KEY_RPC_WHITELIST;
+ key = TR_KEY_rpc_whitelist;
if (!tr_variantDictFindStr (settings, key, &str, NULL) && str)
- tr_nerr (MY_NAME, _("Couldn't find settings key \"%s\""), key);
+ missing_settings_key (key);
else
tr_rpcSetWhitelist (s, str);
- key = TR_PREFS_KEY_RPC_USERNAME;
+ key = TR_KEY_rpc_username;
if (!tr_variantDictFindStr (settings, key, &str, NULL))
- tr_nerr (MY_NAME, _("Couldn't find settings key \"%s\""), key);
+ missing_settings_key (key);
else
tr_rpcSetUsername (s, str);
- key = TR_PREFS_KEY_RPC_PASSWORD;
+ key = TR_KEY_rpc_password;
if (!tr_variantDictFindStr (settings, key, &str, NULL))
- tr_nerr (MY_NAME, _("Couldn't find settings key \"%s\""), key);
+ missing_settings_key (key);
else
tr_rpcSetPassword (s, str);
- key = TR_PREFS_KEY_RPC_BIND_ADDRESS;
- if (!tr_variantDictFindStr (settings, TR_PREFS_KEY_RPC_BIND_ADDRESS, &str, NULL)) {
- tr_nerr (MY_NAME, _("Couldn't find settings key \"%s\""), key);
+ key = TR_KEY_rpc_bind_address;
+ if (!tr_variantDictFindStr (settings, key, &str, NULL)) {
+ missing_settings_key (key);
address = tr_inaddr_any;
} else if (!tr_address_from_string (&address, str)) {
tr_nerr (MY_NAME, _("%s is not a valid address"), str);
if (result == NULL)
result = "success";
- tr_variantDictAddStr (data->response, "result", result);
+ tr_variantDictAddStr (data->response, TR_KEY_result, result);
buf = tr_variantToBuf (data->response, TR_VARIANT_FMT_JSON_LEAN);
(*data->callback)(data->session, buf, data->callback_user_data);
tr_variant * ids;
const char * str;
- if (tr_variantDictFindList (args, "ids", &ids))
+ if (tr_variantDictFindList (args, TR_KEY_ids, &ids))
{
int i;
const int n = tr_variantListSize (ids);
torrents[torrentCount++] = tor;
}
}
- else if (tr_variantDictFindInt (args, "ids", &id)
- || tr_variantDictFindInt (args, "id", &id))
+ else if (tr_variantDictFindInt (args, TR_KEY_ids, &id)
+ || tr_variantDictFindInt (args, TR_KEY_id, &id))
{
tr_torrent * tor;
torrents = tr_new0 (tr_torrent *, 1);
if ((tor = tr_torrentFindFromId (session, id)))
torrents[torrentCount++] = tor;
}
- else if (tr_variantDictFindStr (args, "ids", &str, NULL))
+ else if (tr_variantDictFindStr (args, TR_KEY_ids, &str, NULL))
{
if (!strcmp (str, "recently-active"))
{
assert (idle_data == NULL);
- tr_variantDictFindBool (args_in, "delete-local-data", &deleteFlag);
+ tr_variantDictFindBool (args_in, TR_KEY_delete_local_data, &deleteFlag);
type = deleteFlag ? TR_RPC_TORRENT_TRASHING
: TR_RPC_TORRENT_REMOVING;
{
const tr_file * file = &info->files[i];
tr_variant * d = tr_variantListAddDict (list, 3);
- tr_variantDictAddInt (d, "bytesCompleted", files[i].bytesCompleted);
- tr_variantDictAddInt (d, "priority", file->priority);
- tr_variantDictAddBool (d, "wanted", !file->dnd);
+ tr_variantDictAddInt (d, TR_KEY_bytesCompleted, files[i].bytesCompleted);
+ tr_variantDictAddInt (d, TR_KEY_priority, file->priority);
+ tr_variantDictAddBool (d, TR_KEY_wanted, !file->dnd);
}
tr_torrentFilesFree (files, n);
{
const tr_file * file = &info->files[i];
tr_variant * d = tr_variantListAddDict (list, 3);
- tr_variantDictAddInt (d, "bytesCompleted", files[i].bytesCompleted);
- tr_variantDictAddInt (d, "length", file->length);
- tr_variantDictAddStr (d, "name", file->name);
+ tr_variantDictAddInt (d, TR_KEY_bytesCompleted, files[i].bytesCompleted);
+ tr_variantDictAddInt (d, TR_KEY_length, file->length);
+ tr_variantDictAddStr (d, TR_KEY_name, file->name);
}
tr_torrentFilesFree (files, n);
{
const tr_tracker_info * t = &info->trackers[i];
tr_variant * d = tr_variantListAddDict (trackers, 4);
- tr_variantDictAddStr (d, "announce", t->announce);
- tr_variantDictAddInt (d, "id", t->id);
- tr_variantDictAddStr (d, "scrape", t->scrape);
- tr_variantDictAddInt (d, "tier", t->tier);
+ tr_variantDictAddStr (d, TR_KEY_announce, t->announce);
+ tr_variantDictAddInt (d, TR_KEY_id, t->id);
+ tr_variantDictAddStr (d, TR_KEY_scrape, t->scrape);
+ tr_variantDictAddInt (d, TR_KEY_tier, t->tier);
}
}
{
const tr_tracker_stat * s = &st[i];
tr_variant * d = tr_variantListAddDict (list, 26);
- tr_variantDictAddStr (d, "announce", s->announce);
- tr_variantDictAddInt (d, "announceState", s->announceState);
- tr_variantDictAddInt (d, "downloadCount", s->downloadCount);
- tr_variantDictAddBool (d, "hasAnnounced", s->hasAnnounced);
- tr_variantDictAddBool (d, "hasScraped", s->hasScraped);
- tr_variantDictAddStr (d, "host", s->host);
- tr_variantDictAddInt (d, "id", s->id);
- tr_variantDictAddBool (d, "isBackup", s->isBackup);
- tr_variantDictAddInt (d, "lastAnnouncePeerCount", s->lastAnnouncePeerCount);
- tr_variantDictAddStr (d, "lastAnnounceResult", s->lastAnnounceResult);
- tr_variantDictAddInt (d, "lastAnnounceStartTime", s->lastAnnounceStartTime);
- tr_variantDictAddBool (d, "lastAnnounceSucceeded", s->lastAnnounceSucceeded);
- tr_variantDictAddInt (d, "lastAnnounceTime", s->lastAnnounceTime);
- tr_variantDictAddBool (d, "lastAnnounceTimedOut", s->lastAnnounceTimedOut);
- tr_variantDictAddStr (d, "lastScrapeResult", s->lastScrapeResult);
- tr_variantDictAddInt (d, "lastScrapeStartTime", s->lastScrapeStartTime);
- tr_variantDictAddBool (d, "lastScrapeSucceeded", s->lastScrapeSucceeded);
- tr_variantDictAddInt (d, "lastScrapeTime", s->lastScrapeTime);
- tr_variantDictAddInt (d, "lastScrapeTimedOut", s->lastScrapeTimedOut);
- tr_variantDictAddInt (d, "leecherCount", s->leecherCount);
- tr_variantDictAddInt (d, "nextAnnounceTime", s->nextAnnounceTime);
- tr_variantDictAddInt (d, "nextScrapeTime", s->nextScrapeTime);
- tr_variantDictAddStr (d, "scrape", s->scrape);
- tr_variantDictAddInt (d, "scrapeState", s->scrapeState);
- tr_variantDictAddInt (d, "seederCount", s->seederCount);
- tr_variantDictAddInt (d, "tier", s->tier);
+ tr_variantDictAddStr (d, TR_KEY_announce, s->announce);
+ tr_variantDictAddInt (d, TR_KEY_announceState, s->announceState);
+ tr_variantDictAddInt (d, TR_KEY_downloadCount, s->downloadCount);
+ tr_variantDictAddBool (d, TR_KEY_hasAnnounced, s->hasAnnounced);
+ tr_variantDictAddBool (d, TR_KEY_hasScraped, s->hasScraped);
+ tr_variantDictAddStr (d, TR_KEY_host, s->host);
+ tr_variantDictAddInt (d, TR_KEY_id, s->id);
+ tr_variantDictAddBool (d, TR_KEY_isBackup, s->isBackup);
+ tr_variantDictAddInt (d, TR_KEY_lastAnnouncePeerCount, s->lastAnnouncePeerCount);
+ tr_variantDictAddStr (d, TR_KEY_lastAnnounceResult, s->lastAnnounceResult);
+ tr_variantDictAddInt (d, TR_KEY_lastAnnounceStartTime, s->lastAnnounceStartTime);
+ tr_variantDictAddBool (d, TR_KEY_lastAnnounceSucceeded, s->lastAnnounceSucceeded);
+ tr_variantDictAddInt (d, TR_KEY_lastAnnounceTime, s->lastAnnounceTime);
+ tr_variantDictAddBool (d, TR_KEY_lastAnnounceTimedOut, s->lastAnnounceTimedOut);
+ tr_variantDictAddStr (d, TR_KEY_lastScrapeResult, s->lastScrapeResult);
+ tr_variantDictAddInt (d, TR_KEY_lastScrapeStartTime, s->lastScrapeStartTime);
+ tr_variantDictAddBool (d, TR_KEY_lastScrapeSucceeded, s->lastScrapeSucceeded);
+ tr_variantDictAddInt (d, TR_KEY_lastScrapeTime, s->lastScrapeTime);
+ tr_variantDictAddInt (d, TR_KEY_lastScrapeTimedOut, s->lastScrapeTimedOut);
+ tr_variantDictAddInt (d, TR_KEY_leecherCount, s->leecherCount);
+ tr_variantDictAddInt (d, TR_KEY_nextAnnounceTime, s->nextAnnounceTime);
+ tr_variantDictAddInt (d, TR_KEY_nextScrapeTime, s->nextScrapeTime);
+ tr_variantDictAddStr (d, TR_KEY_scrape, s->scrape);
+ tr_variantDictAddInt (d, TR_KEY_scrapeState, s->scrapeState);
+ tr_variantDictAddInt (d, TR_KEY_seederCount, s->seederCount);
+ tr_variantDictAddInt (d, TR_KEY_tier, s->tier);
}
}
for (i=0; i<peerCount; ++i)
{
- tr_variant * d = tr_variantListAddDict (list, 16);
+ tr_variant * d = tr_variantListAddDict (list, 16);
const tr_peer_stat * peer = peers + i;
- tr_variantDictAddStr (d, "address", peer->addr);
- tr_variantDictAddStr (d, "clientName", peer->client);
- tr_variantDictAddBool (d, "clientIsChoked", peer->clientIsChoked);
- tr_variantDictAddBool (d, "clientIsInterested", peer->clientIsInterested);
- tr_variantDictAddStr (d, "flagStr", peer->flagStr);
- tr_variantDictAddBool (d, "isDownloadingFrom", peer->isDownloadingFrom);
- tr_variantDictAddBool (d, "isEncrypted", peer->isEncrypted);
- tr_variantDictAddBool (d, "isIncoming", peer->isIncoming);
- tr_variantDictAddBool (d, "isUploadingTo", peer->isUploadingTo);
- tr_variantDictAddBool (d, "isUTP", peer->isUTP);
- tr_variantDictAddBool (d, "peerIsChoked", peer->peerIsChoked);
- tr_variantDictAddBool (d, "peerIsInterested", peer->peerIsInterested);
- tr_variantDictAddInt (d, "port", peer->port);
- tr_variantDictAddReal (d, "progress", peer->progress);
- tr_variantDictAddInt (d, "rateToClient", toSpeedBytes (peer->rateToClient_KBps));
- tr_variantDictAddInt (d, "rateToPeer", toSpeedBytes (peer->rateToPeer_KBps));
+ tr_variantDictAddStr (d, TR_KEY_address, peer->addr);
+ tr_variantDictAddStr (d, TR_KEY_clientName, peer->client);
+ tr_variantDictAddBool (d, TR_KEY_clientIsChoked, peer->clientIsChoked);
+ tr_variantDictAddBool (d, TR_KEY_clientIsInterested, peer->clientIsInterested);
+ tr_variantDictAddStr (d, TR_KEY_flagStr, peer->flagStr);
+ tr_variantDictAddBool (d, TR_KEY_isDownloadingFrom, peer->isDownloadingFrom);
+ tr_variantDictAddBool (d, TR_KEY_isEncrypted, peer->isEncrypted);
+ tr_variantDictAddBool (d, TR_KEY_isIncoming, peer->isIncoming);
+ tr_variantDictAddBool (d, TR_KEY_isUploadingTo, peer->isUploadingTo);
+ tr_variantDictAddBool (d, TR_KEY_isUTP, peer->isUTP);
+ tr_variantDictAddBool (d, TR_KEY_peerIsChoked, peer->peerIsChoked);
+ tr_variantDictAddBool (d, TR_KEY_peerIsInterested, peer->peerIsInterested);
+ tr_variantDictAddInt (d, TR_KEY_port, peer->port);
+ tr_variantDictAddReal (d, TR_KEY_progress, peer->progress);
+ tr_variantDictAddInt (d, TR_KEY_rateToClient, toSpeedBytes (peer->rateToClient_KBps));
+ tr_variantDictAddInt (d, TR_KEY_rateToPeer, toSpeedBytes (peer->rateToPeer_KBps));
}
tr_torrentPeersFree (peers, peerCount);
}
-/* faster-than-strcmp () optimization. This is kind of clumsy,
- but addField () was in the profiler's top 10 list, and this
- makes it 4x faster... */
-#define tr_streq(a,alen,b)((alen+1==sizeof (b)) && !memcmp (a,b,alen))
-
static void
addField (tr_torrent * const tor,
const tr_info * const inf,
const tr_stat * const st,
- tr_variant * const d,
- const char * const key)
+ tr_variant * const d,
+ const tr_quark key)
{
- const size_t keylen = strlen (key);
+ char * str;
- if (tr_streq (key, keylen, "activityDate"))
+ switch (key)
+ {
+ case TR_KEY_activityDate:
tr_variantDictAddInt (d, key, st->activityDate);
- else if (tr_streq (key, keylen, "addedDate"))
+ break;
+
+ case TR_KEY_addedDate:
tr_variantDictAddInt (d, key, st->addedDate);
- else if (tr_streq (key, keylen, "bandwidthPriority"))
+ break;
+
+ case TR_KEY_bandwidthPriority:
tr_variantDictAddInt (d, key, tr_torrentGetPriority (tor));
- else if (tr_streq (key, keylen, "comment"))
+ break;
+
+ case TR_KEY_comment:
tr_variantDictAddStr (d, key, inf->comment ? inf->comment : "");
- else if (tr_streq (key, keylen, "corruptEver"))
+ break;
+
+ case TR_KEY_corruptEver:
tr_variantDictAddInt (d, key, st->corruptEver);
- else if (tr_streq (key, keylen, "creator"))
+ break;
+
+ case TR_KEY_creator:
tr_variantDictAddStr (d, key, inf->creator ? inf->creator : "");
- else if (tr_streq (key, keylen, "dateCreated"))
+ break;
+
+ case TR_KEY_dateCreated:
tr_variantDictAddInt (d, key, inf->dateCreated);
- else if (tr_streq (key, keylen, "desiredAvailable"))
+ break;
+
+ case TR_KEY_desiredAvailable:
tr_variantDictAddInt (d, key, st->desiredAvailable);
- else if (tr_streq (key, keylen, "doneDate"))
+ break;
+
+ case TR_KEY_doneDate:
tr_variantDictAddInt (d, key, st->doneDate);
- else if (tr_streq (key, keylen, "downloadDir"))
+ break;
+
+ case TR_KEY_downloadDir:
tr_variantDictAddStr (d, key, tr_torrentGetDownloadDir (tor));
- else if (tr_streq (key, keylen, "downloadedEver"))
+ break;
+
+ case TR_KEY_downloadedEver:
tr_variantDictAddInt (d, key, st->downloadedEver);
- else if (tr_streq (key, keylen, "downloadLimit"))
+ break;
+
+ case TR_KEY_downloadLimit:
tr_variantDictAddInt (d, key, tr_torrentGetSpeedLimit_KBps (tor, TR_DOWN));
- else if (tr_streq (key, keylen, "downloadLimited"))
+ break;
+
+ case TR_KEY_downloadLimited:
tr_variantDictAddBool (d, key, tr_torrentUsesSpeedLimit (tor, TR_DOWN));
- else if (tr_streq (key, keylen, "error"))
+ break;
+
+ case TR_KEY_error:
tr_variantDictAddInt (d, key, st->error);
- else if (tr_streq (key, keylen, "errorString"))
+ break;
+
+ case TR_KEY_errorString:
tr_variantDictAddStr (d, key, st->errorString);
- else if (tr_streq (key, keylen, "eta"))
+ break;
+
+ case TR_KEY_eta:
tr_variantDictAddInt (d, key, st->eta);
- else if (tr_streq (key, keylen, "files"))
+ break;
+
+ case TR_KEY_files:
addFiles (tor, tr_variantDictAddList (d, key, inf->fileCount));
- else if (tr_streq (key, keylen, "fileStats"))
+ break;
+
+ case TR_KEY_fileStats:
addFileStats (tor, tr_variantDictAddList (d, key, inf->fileCount));
- else if (tr_streq (key, keylen, "hashString"))
+ break;
+
+ case TR_KEY_hashString:
tr_variantDictAddStr (d, key, tor->info.hashString);
- else if (tr_streq (key, keylen, "haveUnchecked"))
+ break;
+
+ case TR_KEY_haveUnchecked:
tr_variantDictAddInt (d, key, st->haveUnchecked);
- else if (tr_streq (key, keylen, "haveValid"))
+ break;
+
+ case TR_KEY_haveValid:
tr_variantDictAddInt (d, key, st->haveValid);
- else if (tr_streq (key, keylen, "honorsSessionLimits"))
+ break;
+
+ case TR_KEY_honorsSessionLimits:
tr_variantDictAddBool (d, key, tr_torrentUsesSessionLimits (tor));
- else if (tr_streq (key, keylen, "id"))
+ break;
+
+ case TR_KEY_id:
tr_variantDictAddInt (d, key, st->id);
- else if (tr_streq (key, keylen, "isFinished"))
+ break;
+
+ case TR_KEY_isFinished:
tr_variantDictAddBool (d, key, st->finished);
- else if (tr_streq (key, keylen, "isPrivate"))
+ break;
+
+ case TR_KEY_isPrivate:
tr_variantDictAddBool (d, key, tr_torrentIsPrivate (tor));
- else if (tr_streq (key, keylen, "isStalled"))
+ break;
+
+ case TR_KEY_isStalled:
tr_variantDictAddBool (d, key, st->isStalled);
- else if (tr_streq (key, keylen, "leftUntilDone"))
+ break;
+
+ case TR_KEY_leftUntilDone:
tr_variantDictAddInt (d, key, st->leftUntilDone);
- else if (tr_streq (key, keylen, "manualAnnounceTime"))
+ break;
+
+ case TR_KEY_manualAnnounceTime:
tr_variantDictAddInt (d, key, st->manualAnnounceTime);
- else if (tr_streq (key, keylen, "maxConnectedPeers"))
+ break;
+
+ case TR_KEY_maxConnectedPeers:
tr_variantDictAddInt (d, key, tr_torrentGetPeerLimit (tor));
- else if (tr_streq (key, keylen, "magnetLink")) {
- char * str = tr_torrentGetMagnetLink (tor);
+ break;
+
+ case TR_KEY_magnetLink:
+ str = tr_torrentGetMagnetLink (tor);
tr_variantDictAddStr (d, key, str);
tr_free (str);
- }
- else if (tr_streq (key, keylen, "metadataPercentComplete"))
+ break;
+
+ case TR_KEY_metadataPercentComplete:
tr_variantDictAddReal (d, key, st->metadataPercentComplete);
- else if (tr_streq (key, keylen, "name"))
+ break;
+
+ case TR_KEY_name:
tr_variantDictAddStr (d, key, tr_torrentName (tor));
- else if (tr_streq (key, keylen, "percentDone"))
+ break;
+
+ case TR_KEY_percentDone:
tr_variantDictAddReal (d, key, st->percentDone);
- else if (tr_streq (key, keylen, "peer-limit"))
+ break;
+
+ case TR_KEY_peer_limit:
tr_variantDictAddInt (d, key, tr_torrentGetPeerLimit (tor));
- else if (tr_streq (key, keylen, "peers"))
- addPeers (tor, tr_variantDictAdd (d, key, keylen));
- else if (tr_streq (key, keylen, "peersConnected"))
+ break;
+
+ case TR_KEY_peers:
+ addPeers (tor, tr_variantDictAdd (d, key));
+ break;
+
+ case TR_KEY_peersConnected:
tr_variantDictAddInt (d, key, st->peersConnected);
- else if (tr_streq (key, keylen, "peersFrom"))
- {
- tr_variant * tmp = tr_variantDictAddDict (d, key, 7);
- const int * f = st->peersFrom;
- tr_variantDictAddInt (tmp, "fromCache", f[TR_PEER_FROM_RESUME]);
- tr_variantDictAddInt (tmp, "fromDht", f[TR_PEER_FROM_DHT]);
- tr_variantDictAddInt (tmp, "fromIncoming", f[TR_PEER_FROM_INCOMING]);
- tr_variantDictAddInt (tmp, "fromLpd", f[TR_PEER_FROM_LPD]);
- tr_variantDictAddInt (tmp, "fromLtep", f[TR_PEER_FROM_LTEP]);
- tr_variantDictAddInt (tmp, "fromPex", f[TR_PEER_FROM_PEX]);
- tr_variantDictAddInt (tmp, "fromTracker", f[TR_PEER_FROM_TRACKER]);
- }
- else if (tr_streq (key, keylen, "peersGettingFromUs"))
+ break;
+
+ case TR_KEY_peersFrom:
+ {
+ tr_variant * tmp = tr_variantDictAddDict (d, key, 7);
+ const int * f = st->peersFrom;
+ tr_variantDictAddInt (tmp, TR_KEY_fromCache, f[TR_PEER_FROM_RESUME]);
+ tr_variantDictAddInt (tmp, TR_KEY_fromDht, f[TR_PEER_FROM_DHT]);
+ tr_variantDictAddInt (tmp, TR_KEY_fromIncoming, f[TR_PEER_FROM_INCOMING]);
+ tr_variantDictAddInt (tmp, TR_KEY_fromLpd, f[TR_PEER_FROM_LPD]);
+ tr_variantDictAddInt (tmp, TR_KEY_fromLtep, f[TR_PEER_FROM_LTEP]);
+ tr_variantDictAddInt (tmp, TR_KEY_fromPex, f[TR_PEER_FROM_PEX]);
+ tr_variantDictAddInt (tmp, TR_KEY_fromTracker, f[TR_PEER_FROM_TRACKER]);
+ break;
+ }
+
+ case TR_KEY_peersGettingFromUs:
tr_variantDictAddInt (d, key, st->peersGettingFromUs);
- else if (tr_streq (key, keylen, "peersSendingToUs"))
+ break;
+
+ case TR_KEY_peersSendingToUs:
tr_variantDictAddInt (d, key, st->peersSendingToUs);
- else if (tr_streq (key, keylen, "pieces")) {
- if (tr_torrentHasMetadata (tor)) {
+ break;
+
+ case TR_KEY_pieces:
+ if (tr_torrentHasMetadata (tor))
+ {
size_t byte_count = 0;
void * bytes = tr_cpCreatePieceBitfield (&tor->completion, &byte_count);
char * str = tr_base64_encode (bytes, byte_count, NULL);
tr_variantDictAddStr (d, key, str!=NULL ? str : "");
tr_free (str);
tr_free (bytes);
- } else {
+ }
+ else
+ {
tr_variantDictAddStr (d, key, "");
- }
- }
- else if (tr_streq (key, keylen, "pieceCount"))
+ }
+ break;
+
+ case TR_KEY_pieceCount:
tr_variantDictAddInt (d, key, inf->pieceCount);
- else if (tr_streq (key, keylen, "pieceSize"))
+ break;
+
+ case TR_KEY_pieceSize:
tr_variantDictAddInt (d, key, inf->pieceSize);
- else if (tr_streq (key, keylen, "priorities"))
- {
- tr_file_index_t i;
- tr_variant * p = tr_variantDictAddList (d, key, inf->fileCount);
- for (i = 0; i < inf->fileCount; ++i)
+ break;
+
+ case TR_KEY_priorities:
+ {
+ tr_file_index_t i;
+ tr_variant * p = tr_variantDictAddList (d, key, inf->fileCount);
+ for (i=0; i<inf->fileCount; ++i)
tr_variantListAddInt (p, inf->files[i].priority);
- }
- else if (tr_streq (key, keylen, "queuePosition"))
+ break;
+ }
+
+ case TR_KEY_queuePosition:
tr_variantDictAddInt (d, key, st->queuePosition);
- else if (tr_streq (key, keylen, "rateDownload"))
+ break;
+
+ case TR_KEY_rateDownload:
tr_variantDictAddInt (d, key, toSpeedBytes (st->pieceDownloadSpeed_KBps));
- else if (tr_streq (key, keylen, "rateUpload"))
+ break;
+
+ case TR_KEY_rateUpload:
tr_variantDictAddInt (d, key, toSpeedBytes (st->pieceUploadSpeed_KBps));
- else if (tr_streq (key, keylen, "recheckProgress"))
+ break;
+
+ case TR_KEY_recheckProgress:
tr_variantDictAddReal (d, key, st->recheckProgress);
- else if (tr_streq (key, keylen, "seedIdleLimit"))
+ break;
+
+ case TR_KEY_seedIdleLimit:
tr_variantDictAddInt (d, key, tr_torrentGetIdleLimit (tor));
- else if (tr_streq (key, keylen, "seedIdleMode"))
+ break;
+
+ case TR_KEY_seedIdleMode:
tr_variantDictAddInt (d, key, tr_torrentGetIdleMode (tor));
- else if (tr_streq (key, keylen, "seedRatioLimit"))
+ break;
+
+ case TR_KEY_seedRatioLimit:
tr_variantDictAddReal (d, key, tr_torrentGetRatioLimit (tor));
- else if (tr_streq (key, keylen, "seedRatioMode"))
+ break;
+
+ case TR_KEY_seedRatioMode:
tr_variantDictAddInt (d, key, tr_torrentGetRatioMode (tor));
- else if (tr_streq (key, keylen, "sizeWhenDone"))
+ break;
+
+ case TR_KEY_sizeWhenDone:
tr_variantDictAddInt (d, key, st->sizeWhenDone);
- else if (tr_streq (key, keylen, "startDate"))
+ break;
+
+ case TR_KEY_startDate:
tr_variantDictAddInt (d, key, st->startDate);
- else if (tr_streq (key, keylen, "status"))
+ break;
+
+ case TR_KEY_status:
tr_variantDictAddInt (d, key, st->activity);
- else if (tr_streq (key, keylen, "secondsDownloading"))
+ break;
+
+ case TR_KEY_secondsDownloading:
tr_variantDictAddInt (d, key, st->secondsDownloading);
- else if (tr_streq (key, keylen, "secondsSeeding"))
+ break;
+
+ case TR_KEY_secondsSeeding:
tr_variantDictAddInt (d, key, st->secondsSeeding);
- else if (tr_streq (key, keylen, "trackers"))
+ break;
+
+ case TR_KEY_trackers:
addTrackers (inf, tr_variantDictAddList (d, key, inf->trackerCount));
- else if (tr_streq (key, keylen, "trackerStats")) {
- int n;
- tr_tracker_stat * s = tr_torrentTrackers (tor, &n);
- addTrackerStats (s, n, tr_variantDictAddList (d, key, n));
- tr_torrentTrackersFree (s, n);
- }
- else if (tr_streq (key, keylen, "torrentFile"))
+ break;
+
+ case TR_KEY_trackerStats:
+ {
+ int n;
+ tr_tracker_stat * s = tr_torrentTrackers (tor, &n);
+ addTrackerStats (s, n, tr_variantDictAddList (d, key, n));
+ tr_torrentTrackersFree (s, n);
+ break;
+ }
+
+ case TR_KEY_torrentFile:
tr_variantDictAddStr (d, key, inf->torrent);
- else if (tr_streq (key, keylen, "totalSize"))
+ break;
+
+ case TR_KEY_totalSize:
tr_variantDictAddInt (d, key, inf->totalSize);
- else if (tr_streq (key, keylen, "uploadedEver"))
+ break;
+
+ case TR_KEY_uploadedEver:
tr_variantDictAddInt (d, key, st->uploadedEver);
- else if (tr_streq (key, keylen, "uploadLimit"))
+ break;
+
+ case TR_KEY_uploadLimit:
tr_variantDictAddInt (d, key, tr_torrentGetSpeedLimit_KBps (tor, TR_UP));
- else if (tr_streq (key, keylen, "uploadLimited"))
+ break;
+
+ case TR_KEY_uploadLimited:
tr_variantDictAddBool (d, key, tr_torrentUsesSpeedLimit (tor, TR_UP));
- else if (tr_streq (key, keylen, "uploadRatio"))
+ break;
+
+ case TR_KEY_uploadRatio:
tr_variantDictAddReal (d, key, st->ratio);
- else if (tr_streq (key, keylen, "wanted"))
- {
- tr_file_index_t i;
- tr_variant * w = tr_variantDictAddList (d, key, inf->fileCount);
- for (i = 0; i < inf->fileCount; ++i)
+ break;
+
+ case TR_KEY_wanted:
+ {
+ tr_file_index_t i;
+ tr_variant * w = tr_variantDictAddList (d, key, inf->fileCount);
+ for (i=0; i<inf->fileCount; ++i)
tr_variantListAddInt (w, inf->files[i].dnd ? 0 : 1);
- }
- else if (tr_streq (key, keylen, "webseeds"))
+ break;
+ }
+
+ case TR_KEY_webseeds:
addWebseeds (inf, tr_variantDictAddList (d, key, inf->webseedCount));
- else if (tr_streq (key, keylen, "webseedsSendingToUs"))
+ break;
+
+ case TR_KEY_webseedsSendingToUs:
tr_variantDictAddInt (d, key, st->webseedsSendingToUs);
+ break;
+
+ default:
+ break;
+ }
}
static void
addInfo (tr_torrent * tor, tr_variant * d, tr_variant * fields)
{
- const char * str;
- const int n = tr_variantListSize (fields);
+ const int n = tr_variantListSize (fields);
- tr_variantInitDict (d, n);
+ tr_variantInitDict (d, n);
- if (n > 0)
+ if (n > 0)
{
- int i;
- const tr_info const * inf = tr_torrentInfo (tor);
- const tr_stat const * st = tr_torrentStat ((tr_torrent*)tor);
+ int i;
+ const tr_info const * inf = tr_torrentInfo (tor);
+ const tr_stat const * st = tr_torrentStat ((tr_torrent*)tor);
- for (i=0; i<n; ++i)
- if (tr_variantGetStr (tr_variantListChild (fields, i), &str, NULL))
- addField (tor, inf, st, d, str);
+ for (i=0; i<n; ++i)
+ {
+ size_t len;
+ const char * str;
+ if (tr_variantGetStr (tr_variantListChild (fields, i), &str, &len))
+ addField (tor, inf, st, d, tr_quark_new (str, len));
+ }
}
}
{
int i, torrentCount;
tr_torrent ** torrents = getTorrents (session, args_in, &torrentCount);
- tr_variant * list = tr_variantDictAddList (args_out, "torrents", torrentCount);
+ tr_variant * list = tr_variantDictAddList (args_out, TR_KEY_torrents, torrentCount);
tr_variant * fields;
const char * msg = NULL;
const char * strVal;
assert (idle_data == NULL);
- if (tr_variantDictFindStr (args_in, "ids", &strVal, NULL) && !strcmp (strVal, "recently-active")) {
+ if (tr_variantDictFindStr (args_in, TR_KEY_ids, &strVal, NULL) && !strcmp (strVal, "recently-active")) {
int n = 0;
tr_variant * d;
const time_t now = tr_time ();
const int interval = RECENTLY_ACTIVE_SECONDS;
- tr_variant * removed_out = tr_variantDictAddList (args_out, "removed", 0);
+ tr_variant * removed_out = tr_variantDictAddList (args_out, TR_KEY_removed, 0);
while ((d = tr_variantListChild (&session->removedTorrents, n++))) {
int64_t intVal;
- if (tr_variantDictFindInt (d, "date", &intVal) && (intVal >= now - interval)) {
- tr_variantDictFindInt (d, "id", &intVal);
+ if (tr_variantDictFindInt (d, TR_KEY_date, &intVal) && (intVal >= now - interval)) {
+ tr_variantDictFindInt (d, TR_KEY_id, &intVal);
tr_variantListAddInt (removed_out, intVal);
}
}
}
- if (!tr_variantDictFindList (args_in, "fields", &fields))
+ if (!tr_variantDictFindList (args_in, TR_KEY_fields, &fields))
msg = "no fields specified";
else for (i = 0; i < torrentCount; ++i)
addInfo (torrents[i], tr_variantListAdd (list), fields);
bool boolVal;
tr_torrent * tor = torrents[i];
- if (tr_variantDictFindInt (args_in, "bandwidthPriority", &tmp))
+ if (tr_variantDictFindInt (args_in, TR_KEY_bandwidthPriority, &tmp))
if (tr_isPriority (tmp))
tr_torrentSetPriority (tor, tmp);
- if (!errmsg && tr_variantDictFindList (args_in, "files-unwanted", &files))
+ if (!errmsg && tr_variantDictFindList (args_in, TR_KEY_files_unwanted, &files))
errmsg = setFileDLs (tor, false, files);
- if (!errmsg && tr_variantDictFindList (args_in, "files-wanted", &files))
+ if (!errmsg && tr_variantDictFindList (args_in, TR_KEY_files_wanted, &files))
errmsg = setFileDLs (tor, true, files);
- if (tr_variantDictFindInt (args_in, "peer-limit", &tmp))
+ if (tr_variantDictFindInt (args_in, TR_KEY_peer_limit, &tmp))
tr_torrentSetPeerLimit (tor, tmp);
- if (!errmsg && tr_variantDictFindList (args_in, "priority-high", &files))
+ if (!errmsg && tr_variantDictFindList (args_in, TR_KEY_priority_high, &files))
errmsg = setFilePriorities (tor, TR_PRI_HIGH, files);
- if (!errmsg && tr_variantDictFindList (args_in, "priority-low", &files))
+ if (!errmsg && tr_variantDictFindList (args_in, TR_KEY_priority_low, &files))
errmsg = setFilePriorities (tor, TR_PRI_LOW, files);
- if (!errmsg && tr_variantDictFindList (args_in, "priority-normal", &files))
+ if (!errmsg && tr_variantDictFindList (args_in, TR_KEY_priority_normal, &files))
errmsg = setFilePriorities (tor, TR_PRI_NORMAL, files);
- if (tr_variantDictFindInt (args_in, "downloadLimit", &tmp))
+ if (tr_variantDictFindInt (args_in, TR_KEY_downloadLimit, &tmp))
tr_torrentSetSpeedLimit_KBps (tor, TR_DOWN, tmp);
- if (tr_variantDictFindBool (args_in, "downloadLimited", &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_downloadLimited, &boolVal))
tr_torrentUseSpeedLimit (tor, TR_DOWN, boolVal);
- if (tr_variantDictFindBool (args_in, "honorsSessionLimits", &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_honorsSessionLimits, &boolVal))
tr_torrentUseSessionLimits (tor, boolVal);
- if (tr_variantDictFindInt (args_in, "uploadLimit", &tmp))
+ if (tr_variantDictFindInt (args_in, TR_KEY_uploadLimit, &tmp))
tr_torrentSetSpeedLimit_KBps (tor, TR_UP, tmp);
- if (tr_variantDictFindBool (args_in, "uploadLimited", &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_uploadLimited, &boolVal))
tr_torrentUseSpeedLimit (tor, TR_UP, boolVal);
- if (tr_variantDictFindInt (args_in, "seedIdleLimit", &tmp))
+ if (tr_variantDictFindInt (args_in, TR_KEY_seedIdleLimit, &tmp))
tr_torrentSetIdleLimit (tor, tmp);
- if (tr_variantDictFindInt (args_in, "seedIdleMode", &tmp))
+ if (tr_variantDictFindInt (args_in, TR_KEY_seedIdleMode, &tmp))
tr_torrentSetIdleMode (tor, tmp);
- if (tr_variantDictFindReal (args_in, "seedRatioLimit", &d))
+ if (tr_variantDictFindReal (args_in, TR_KEY_seedRatioLimit, &d))
tr_torrentSetRatioLimit (tor, d);
- if (tr_variantDictFindInt (args_in, "seedRatioMode", &tmp))
+ if (tr_variantDictFindInt (args_in, TR_KEY_seedRatioMode, &tmp))
tr_torrentSetRatioMode (tor, tmp);
- if (tr_variantDictFindInt (args_in, "queuePosition", &tmp))
+ if (tr_variantDictFindInt (args_in, TR_KEY_queuePosition, &tmp))
tr_torrentSetQueuePosition (tor, tmp);
- if (!errmsg && tr_variantDictFindList (args_in, "trackerAdd", &trackers))
+ if (!errmsg && tr_variantDictFindList (args_in, TR_KEY_trackerAdd, &trackers))
errmsg = addTrackerUrls (tor, trackers);
- if (!errmsg && tr_variantDictFindList (args_in, "trackerRemove", &trackers))
+ if (!errmsg && tr_variantDictFindList (args_in, TR_KEY_trackerRemove, &trackers))
errmsg = removeTrackers (tor, trackers);
- if (!errmsg && tr_variantDictFindList (args_in, "trackerReplace", &trackers))
+ if (!errmsg && tr_variantDictFindList (args_in, TR_KEY_trackerReplace, &trackers))
errmsg = replaceTrackers (tor, trackers);
notify (session, TR_RPC_TORRENT_CHANGED, tor);
}
static const char*
torrentSetLocation (tr_session * session,
- tr_variant * args_in,
- tr_variant * args_out UNUSED,
+ tr_variant * args_in,
+ tr_variant * args_out UNUSED,
struct tr_rpc_idle_data * idle_data UNUSED)
{
- const char * errmsg = NULL;
- const char * location = NULL;
+ const char * errmsg = NULL;
+ const char * location = NULL;
- assert (idle_data == NULL);
+ assert (idle_data == NULL);
- if (!tr_variantDictFindStr (args_in, "location", &location, NULL))
+ if (!tr_variantDictFindStr (args_in, TR_KEY_location, &location, NULL))
{
- errmsg = "no location";
+ errmsg = "no location";
}
- else
+ else
{
- bool move = false;
- int i, torrentCount;
- tr_torrent ** torrents = getTorrents (session, args_in, &torrentCount);
+ bool move = false;
+ int i, torrentCount;
+ tr_torrent ** torrents = getTorrents (session, args_in, &torrentCount);
- tr_variantDictFindBool (args_in, "move", &move);
+ tr_variantDictFindBool (args_in, TR_KEY_move, &move);
- for (i=0; i<torrentCount; ++i)
+ for (i=0; i<torrentCount; ++i)
{
- tr_torrent * tor = torrents[i];
- tr_torrentSetLocation (tor, location, move, NULL, NULL);
- notify (session, TR_RPC_TORRENT_MOVED, tor);
+ tr_torrent * tor = torrents[i];
+ tr_torrentSetLocation (tor, location, move, NULL, NULL);
+ notify (session, TR_RPC_TORRENT_MOVED, tor);
}
- tr_free (torrents);
+ tr_free (torrents);
}
- return errmsg;
+ return errmsg;
}
/***
else /* success */
{
const bool isOpen = response_byte_count && * (char*)response == '1';
- tr_variantDictAddBool (data->args_out, "port-is-open", isOpen);
+ tr_variantDictAddBool (data->args_out, TR_KEY_port_is_open, isOpen);
tr_snprintf (result, sizeof (result), "success");
}
else {
/* feed it to the session and give the client a response */
const int rule_count = tr_blocklistSetContent (session, filename);
- tr_variantDictAddInt (data->args_out, "blocklist-size", rule_count);
+ tr_variantDictAddInt (data->args_out, TR_KEY_blocklist_size, rule_count);
tr_snprintf (result, sizeof (result), "success");
}
tr_variantListAddStr (&fields, "id");
tr_variantListAddStr (&fields, "name");
tr_variantListAddStr (&fields, "hashString");
- addInfo (tor, tr_variantDictAdd (data->args_out, "torrent-added", 13), &fields);
+ addInfo (tor, tr_variantDictAdd (data->args_out, TR_KEY_torrent_added), &fields);
notify (data->session, TR_RPC_TORRENT_ADDED, tor);
tr_variantFree (&fields);
}
assert (idle_data != NULL);
- tr_variantDictFindStr (args_in, "filename", &filename, NULL);
- tr_variantDictFindStr (args_in, "metainfo", &metainfo_base64, NULL);
+ tr_variantDictFindStr (args_in, TR_KEY_filename, &filename, NULL);
+ tr_variantDictFindStr (args_in, TR_KEY_metainfo, &metainfo_base64, NULL);
if (!filename && !metainfo_base64)
return "no filename or metainfo specified";
else
/* set the optional arguments */
- tr_variantDictFindStr (args_in, "cookies", &cookies, NULL);
+ tr_variantDictFindStr (args_in, TR_KEY_cookies, &cookies, NULL);
- if (tr_variantDictFindStr (args_in, TR_PREFS_KEY_DOWNLOAD_DIR, &str, NULL))
+ if (tr_variantDictFindStr (args_in, TR_KEY_download_dir, &str, NULL))
tr_ctorSetDownloadDir (ctor, TR_FORCE, str);
- if (tr_variantDictFindBool (args_in, "paused", &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_paused, &boolVal))
tr_ctorSetPaused (ctor, TR_FORCE, boolVal);
- if (tr_variantDictFindInt (args_in, "peer-limit", &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_peer_limit, &i))
tr_ctorSetPeerLimit (ctor, TR_FORCE, i);
- if (tr_variantDictFindInt (args_in, "bandwidthPriority", &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_bandwidthPriority, &i))
tr_ctorSetBandwidthPriority (ctor, i);
- if (tr_variantDictFindList (args_in, "files-unwanted", &l)) {
+ if (tr_variantDictFindList (args_in, TR_KEY_files_unwanted, &l)) {
tr_file_index_t fileCount;
tr_file_index_t * files = fileListFromList (l, &fileCount);
tr_ctorSetFilesWanted (ctor, files, fileCount, false);
tr_free (files);
}
- if (tr_variantDictFindList (args_in, "files-wanted", &l)) {
+ if (tr_variantDictFindList (args_in, TR_KEY_files_wanted, &l)) {
tr_file_index_t fileCount;
tr_file_index_t * files = fileListFromList (l, &fileCount);
tr_ctorSetFilesWanted (ctor, files, fileCount, true);
tr_free (files);
}
- if (tr_variantDictFindList (args_in, "priority-low", &l)) {
+ if (tr_variantDictFindList (args_in, TR_KEY_priority_low, &l)) {
tr_file_index_t fileCount;
tr_file_index_t * files = fileListFromList (l, &fileCount);
tr_ctorSetFilePriorities (ctor, files, fileCount, TR_PRI_LOW);
tr_free (files);
}
- if (tr_variantDictFindList (args_in, "priority-normal", &l)) {
+ if (tr_variantDictFindList (args_in, TR_KEY_priority_normal, &l)) {
tr_file_index_t fileCount;
tr_file_index_t * files = fileListFromList (l, &fileCount);
tr_ctorSetFilePriorities (ctor, files, fileCount, TR_PRI_NORMAL);
tr_free (files);
}
- if (tr_variantDictFindList (args_in, "priority-high", &l)) {
+ if (tr_variantDictFindList (args_in, TR_KEY_priority_high, &l)) {
tr_file_index_t fileCount;
tr_file_index_t * files = fileListFromList (l, &fileCount);
tr_ctorSetFilePriorities (ctor, files, fileCount, TR_PRI_HIGH);
assert (idle_data == NULL);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_cache_size_mb, &i))
tr_sessionSetCacheLimit_MB (session, i);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_ALT_SPEED_UP_KBps, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_alt_speed_up, &i))
tr_sessionSetAltSpeed_KBps (session, TR_UP, i);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_alt_speed_down, &i))
tr_sessionSetAltSpeed_KBps (session, TR_DOWN, i);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_ALT_SPEED_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_alt_speed_enabled, &boolVal))
tr_sessionUseAltSpeed (session, boolVal);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_alt_speed_time_begin, &i))
tr_sessionSetAltSpeedBegin (session, i);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_ALT_SPEED_TIME_END, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_alt_speed_time_end, &i))
tr_sessionSetAltSpeedEnd (session, i);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_alt_speed_time_day, &i))
tr_sessionSetAltSpeedDay (session, i);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_alt_speed_time_enabled, &boolVal))
tr_sessionUseAltSpeedTime (session, boolVal);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_BLOCKLIST_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_blocklist_enabled, &boolVal))
tr_blocklistSetEnabled (session, boolVal);
- if (tr_variantDictFindStr (args_in, TR_PREFS_KEY_BLOCKLIST_URL, &str, NULL))
+ if (tr_variantDictFindStr (args_in, TR_KEY_blocklist_url, &str, NULL))
tr_blocklistSetURL (session, str);
- if (tr_variantDictFindStr (args_in, TR_PREFS_KEY_DOWNLOAD_DIR, &str, NULL))
+ if (tr_variantDictFindStr (args_in, TR_KEY_download_dir, &str, NULL))
tr_sessionSetDownloadDir (session, str);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_QUEUE_STALLED_MINUTES, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_queue_stalled_minutes, &i))
tr_sessionSetQueueStalledMinutes (session, i);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_QUEUE_STALLED_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_queue_stalled_enabled, &boolVal))
tr_sessionSetQueueStalledEnabled (session, boolVal);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_DOWNLOAD_QUEUE_SIZE, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_download_queue_size, &i))
tr_sessionSetQueueSize (session, TR_DOWN, i);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_DOWNLOAD_QUEUE_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_download_queue_enabled, &boolVal))
tr_sessionSetQueueEnabled (session, TR_DOWN, boolVal);
- if (tr_variantDictFindStr (args_in, TR_PREFS_KEY_INCOMPLETE_DIR, &str, NULL))
+ if (tr_variantDictFindStr (args_in, TR_KEY_incomplete_dir, &str, NULL))
tr_sessionSetIncompleteDir (session, str);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_incomplete_dir_enabled, &boolVal))
tr_sessionSetIncompleteDirEnabled (session, boolVal);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_peer_limit_global, &i))
tr_sessionSetPeerLimit (session, i);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_PEER_LIMIT_TORRENT, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_peer_limit_per_torrent, &i))
tr_sessionSetPeerLimitPerTorrent (session, i);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_PEX_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_pex_enabled, &boolVal))
tr_sessionSetPexEnabled (session, boolVal);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_DHT_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_dht_enabled, &boolVal))
tr_sessionSetDHTEnabled (session, boolVal);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_UTP_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_utp_enabled, &boolVal))
tr_sessionSetUTPEnabled (session, boolVal);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_LPD_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_lpd_enabled, &boolVal))
tr_sessionSetLPDEnabled (session, boolVal);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_peer_port_random_on_start, &boolVal))
tr_sessionSetPeerPortRandomOnStart (session, boolVal);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_PEER_PORT, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_peer_port, &i))
tr_sessionSetPeerPort (session, i);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_PORT_FORWARDING, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_port_forwarding_enabled, &boolVal))
tr_sessionSetPortForwardingEnabled (session, boolVal);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_RENAME_PARTIAL_FILES, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_rename_partial_files, &boolVal))
tr_sessionSetIncompleteFileNamingEnabled (session, boolVal);
- if (tr_variantDictFindReal (args_in, "seedRatioLimit", &d))
+ if (tr_variantDictFindReal (args_in, TR_KEY_seedRatioLimit, &d))
tr_sessionSetRatioLimit (session, d);
- if (tr_variantDictFindBool (args_in, "seedRatioLimited", &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_seedRatioLimited, &boolVal))
tr_sessionSetRatioLimited (session, boolVal);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_IDLE_LIMIT, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_idle_seeding_limit, &i))
tr_sessionSetIdleLimit (session, i);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_idle_seeding_limit_enabled, &boolVal))
tr_sessionSetIdleLimited (session, boolVal);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_START, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_start_added_torrents, &boolVal))
tr_sessionSetPaused (session, !boolVal);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_SEED_QUEUE_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_seed_queue_enabled, &boolVal))
tr_sessionSetQueueEnabled (session, TR_UP, boolVal);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_SEED_QUEUE_SIZE, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_seed_queue_size, &i))
tr_sessionSetQueueSize (session, TR_UP, i);
- if (tr_variantDictFindStr (args_in, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, &str, NULL))
+ if (tr_variantDictFindStr (args_in, TR_KEY_script_torrent_done_filename, &str, NULL))
tr_sessionSetTorrentDoneScript (session, str);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_script_torrent_done_enabled, &boolVal))
tr_sessionSetTorrentDoneScriptEnabled (session, boolVal);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_TRASH_ORIGINAL, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_trash_original_torrent_files, &boolVal))
tr_sessionSetDeleteSource (session, boolVal);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_DSPEED_KBps, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_speed_limit_down, &i))
tr_sessionSetSpeedLimit_KBps (session, TR_DOWN, i);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_DSPEED_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_speed_limit_down_enabled, &boolVal))
tr_sessionLimitSpeed (session, TR_DOWN, boolVal);
- if (tr_variantDictFindInt (args_in, TR_PREFS_KEY_USPEED_KBps, &i))
+ if (tr_variantDictFindInt (args_in, TR_KEY_speed_limit_up, &i))
tr_sessionSetSpeedLimit_KBps (session, TR_UP, i);
- if (tr_variantDictFindBool (args_in, TR_PREFS_KEY_USPEED_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (args_in, TR_KEY_speed_limit_up_enabled, &boolVal))
tr_sessionLimitSpeed (session, TR_UP, boolVal);
- if (tr_variantDictFindStr (args_in, TR_PREFS_KEY_ENCRYPTION, &str, NULL)) {
+ if (tr_variantDictFindStr (args_in, TR_KEY_encryption, &str, NULL)) {
if (!strcmp (str, "required"))
tr_sessionSetEncryption (session, TR_ENCRYPTION_REQUIRED);
else if (!strcmp (str, "tolerated"))
tr_sessionGetStats (session, ¤tStats);
tr_sessionGetCumulativeStats (session, &cumulativeStats);
- tr_variantDictAddInt (args_out, "activeTorrentCount", running);
- tr_variantDictAddReal (args_out, "downloadSpeed", tr_sessionGetPieceSpeed_Bps (session, TR_DOWN));
- tr_variantDictAddInt (args_out, "pausedTorrentCount", total - running);
- tr_variantDictAddInt (args_out, "torrentCount", total);
- tr_variantDictAddReal (args_out, "uploadSpeed", tr_sessionGetPieceSpeed_Bps (session, TR_UP));
-
- d = tr_variantDictAddDict (args_out, "cumulative-stats", 5);
- tr_variantDictAddInt (d, "downloadedBytes", cumulativeStats.downloadedBytes);
- tr_variantDictAddInt (d, "filesAdded", cumulativeStats.filesAdded);
- tr_variantDictAddInt (d, "secondsActive", cumulativeStats.secondsActive);
- tr_variantDictAddInt (d, "sessionCount", cumulativeStats.sessionCount);
- tr_variantDictAddInt (d, "uploadedBytes", cumulativeStats.uploadedBytes);
-
- d = tr_variantDictAddDict (args_out, "current-stats", 5);
- tr_variantDictAddInt (d, "downloadedBytes", currentStats.downloadedBytes);
- tr_variantDictAddInt (d, "filesAdded", currentStats.filesAdded);
- tr_variantDictAddInt (d, "secondsActive", currentStats.secondsActive);
- tr_variantDictAddInt (d, "sessionCount", currentStats.sessionCount);
- tr_variantDictAddInt (d, "uploadedBytes", currentStats.uploadedBytes);
+ tr_variantDictAddInt (args_out, TR_KEY_activeTorrentCount, running);
+ tr_variantDictAddReal (args_out, TR_KEY_downloadSpeed, tr_sessionGetPieceSpeed_Bps (session, TR_DOWN));
+ tr_variantDictAddInt (args_out, TR_KEY_pausedTorrentCount, total - running);
+ tr_variantDictAddInt (args_out, TR_KEY_torrentCount, total);
+ tr_variantDictAddReal (args_out, TR_KEY_uploadSpeed, tr_sessionGetPieceSpeed_Bps (session, TR_UP));
+
+ d = tr_variantDictAddDict (args_out, TR_KEY_cumulative_stats, 5);
+ tr_variantDictAddInt (d, TR_KEY_downloadedBytes, cumulativeStats.downloadedBytes);
+ tr_variantDictAddInt (d, TR_KEY_filesAdded, cumulativeStats.filesAdded);
+ tr_variantDictAddInt (d, TR_KEY_secondsActive, cumulativeStats.secondsActive);
+ tr_variantDictAddInt (d, TR_KEY_sessionCount, cumulativeStats.sessionCount);
+ tr_variantDictAddInt (d, TR_KEY_uploadedBytes, cumulativeStats.uploadedBytes);
+
+ d = tr_variantDictAddDict (args_out, TR_KEY_current_stats, 5);
+ tr_variantDictAddInt (d, TR_KEY_downloadedBytes, currentStats.downloadedBytes);
+ tr_variantDictAddInt (d, TR_KEY_filesAdded, currentStats.filesAdded);
+ tr_variantDictAddInt (d, TR_KEY_secondsActive, currentStats.secondsActive);
+ tr_variantDictAddInt (d, TR_KEY_sessionCount, currentStats.sessionCount);
+ tr_variantDictAddInt (d, TR_KEY_uploadedBytes, currentStats.uploadedBytes);
return NULL;
}
tr_variant * d = args_out;
assert (idle_data == NULL);
- tr_variantDictAddInt (d, TR_PREFS_KEY_ALT_SPEED_UP_KBps, tr_sessionGetAltSpeed_KBps (s,TR_UP));
- tr_variantDictAddInt (d, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, tr_sessionGetAltSpeed_KBps (s,TR_DOWN));
- tr_variantDictAddBool (d, TR_PREFS_KEY_ALT_SPEED_ENABLED, tr_sessionUsesAltSpeed (s));
- tr_variantDictAddInt (d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, tr_sessionGetAltSpeedBegin (s));
- tr_variantDictAddInt (d, TR_PREFS_KEY_ALT_SPEED_TIME_END,tr_sessionGetAltSpeedEnd (s));
- tr_variantDictAddInt (d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY,tr_sessionGetAltSpeedDay (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, tr_sessionUsesAltSpeedTime (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled (s));
- tr_variantDictAddStr (d, TR_PREFS_KEY_BLOCKLIST_URL, tr_blocklistGetURL (s));
- tr_variantDictAddInt (d, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, tr_sessionGetCacheLimit_MB (s));
- tr_variantDictAddInt (d, "blocklist-size", tr_blocklistGetRuleCount (s));
- tr_variantDictAddStr (d, "config-dir", tr_sessionGetConfigDir (s));
- tr_variantDictAddStr (d, TR_PREFS_KEY_DOWNLOAD_DIR, tr_sessionGetDownloadDir (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_DOWNLOAD_QUEUE_ENABLED, tr_sessionGetQueueEnabled (s, TR_DOWN));
- tr_variantDictAddInt (d, TR_PREFS_KEY_DOWNLOAD_QUEUE_SIZE, tr_sessionGetQueueSize (s, TR_DOWN));
- tr_variantDictAddInt (d, "download-dir-free-space", tr_sessionGetDownloadDirFreeSpace (s));
- tr_variantDictAddInt (d, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, tr_sessionGetPeerLimit (s));
- tr_variantDictAddInt (d, TR_PREFS_KEY_PEER_LIMIT_TORRENT, tr_sessionGetPeerLimitPerTorrent (s));
- tr_variantDictAddStr (d, TR_PREFS_KEY_INCOMPLETE_DIR, tr_sessionGetIncompleteDir (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, tr_sessionIsIncompleteDirEnabled (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_PEX_ENABLED, tr_sessionIsPexEnabled (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_UTP_ENABLED, tr_sessionIsUTPEnabled (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_DHT_ENABLED, tr_sessionIsDHTEnabled (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_LPD_ENABLED, tr_sessionIsLPDEnabled (s));
- tr_variantDictAddInt (d, TR_PREFS_KEY_PEER_PORT, tr_sessionGetPeerPort (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, tr_sessionGetPeerPortRandomOnStart (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_PORT_FORWARDING, tr_sessionIsPortForwardingEnabled (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_RENAME_PARTIAL_FILES, tr_sessionIsIncompleteFileNamingEnabled (s));
- tr_variantDictAddInt (d, "rpc-version", RPC_VERSION);
- tr_variantDictAddInt (d, "rpc-version-minimum", RPC_VERSION_MIN);
- tr_variantDictAddReal (d, "seedRatioLimit", tr_sessionGetRatioLimit (s));
- tr_variantDictAddBool (d, "seedRatioLimited", tr_sessionIsRatioLimited (s));
- tr_variantDictAddInt (d, TR_PREFS_KEY_IDLE_LIMIT, tr_sessionGetIdleLimit (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, tr_sessionIsIdleLimited (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_SEED_QUEUE_ENABLED, tr_sessionGetQueueEnabled (s, TR_UP));
- tr_variantDictAddInt (d, TR_PREFS_KEY_SEED_QUEUE_SIZE, tr_sessionGetQueueSize (s, TR_UP));
- tr_variantDictAddBool (d, TR_PREFS_KEY_START, !tr_sessionGetPaused (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_TRASH_ORIGINAL, tr_sessionGetDeleteSource (s));
- tr_variantDictAddInt (d, TR_PREFS_KEY_USPEED_KBps, tr_sessionGetSpeedLimit_KBps (s, TR_UP));
- tr_variantDictAddBool (d, TR_PREFS_KEY_USPEED_ENABLED, tr_sessionIsSpeedLimited (s, TR_UP));
- tr_variantDictAddInt (d, TR_PREFS_KEY_DSPEED_KBps, tr_sessionGetSpeedLimit_KBps (s, TR_DOWN));
- tr_variantDictAddBool (d, TR_PREFS_KEY_DSPEED_ENABLED, tr_sessionIsSpeedLimited (s, TR_DOWN));
- tr_variantDictAddStr (d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, tr_sessionGetTorrentDoneScript (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, tr_sessionIsTorrentDoneScriptEnabled (s));
- tr_variantDictAddInt (d, TR_PREFS_KEY_QUEUE_STALLED_MINUTES, tr_sessionGetQueueStalledMinutes (s));
- tr_variantDictAddBool (d, TR_PREFS_KEY_QUEUE_STALLED_ENABLED, tr_sessionGetQueueStalledEnabled (s));
- tr_formatter_get_units (tr_variantDictAddDict (d, "units", 0));
- tr_variantDictAddStr (d, "version", LONG_VERSION_STRING);
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_up, tr_sessionGetAltSpeed_KBps (s,TR_UP));
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_down, tr_sessionGetAltSpeed_KBps (s,TR_DOWN));
+ tr_variantDictAddBool (d, TR_KEY_alt_speed_enabled, tr_sessionUsesAltSpeed (s));
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_time_begin, tr_sessionGetAltSpeedBegin (s));
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_time_end,tr_sessionGetAltSpeedEnd (s));
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_time_day,tr_sessionGetAltSpeedDay (s));
+ tr_variantDictAddBool (d, TR_KEY_alt_speed_time_enabled, tr_sessionUsesAltSpeedTime (s));
+ tr_variantDictAddBool (d, TR_KEY_blocklist_enabled, tr_blocklistIsEnabled (s));
+ tr_variantDictAddStr (d, TR_KEY_blocklist_url, tr_blocklistGetURL (s));
+ tr_variantDictAddInt (d, TR_KEY_cache_size_mb, tr_sessionGetCacheLimit_MB (s));
+ tr_variantDictAddInt (d, TR_KEY_blocklist_size, tr_blocklistGetRuleCount (s));
+ tr_variantDictAddStr (d, TR_KEY_config_dir, tr_sessionGetConfigDir (s));
+ tr_variantDictAddStr (d, TR_KEY_download_dir, tr_sessionGetDownloadDir (s));
+ tr_variantDictAddBool (d, TR_KEY_download_queue_enabled, tr_sessionGetQueueEnabled (s, TR_DOWN));
+ tr_variantDictAddInt (d, TR_KEY_download_queue_size, tr_sessionGetQueueSize (s, TR_DOWN));
+ tr_variantDictAddInt (d, TR_KEY_download_dir_free_space, tr_sessionGetDownloadDirFreeSpace (s));
+ tr_variantDictAddInt (d, TR_KEY_peer_limit_global, tr_sessionGetPeerLimit (s));
+ tr_variantDictAddInt (d, TR_KEY_peer_limit_per_torrent, tr_sessionGetPeerLimitPerTorrent (s));
+ tr_variantDictAddStr (d, TR_KEY_incomplete_dir, tr_sessionGetIncompleteDir (s));
+ tr_variantDictAddBool (d, TR_KEY_incomplete_dir_enabled, tr_sessionIsIncompleteDirEnabled (s));
+ tr_variantDictAddBool (d, TR_KEY_pex_enabled, tr_sessionIsPexEnabled (s));
+ tr_variantDictAddBool (d, TR_KEY_utp_enabled, tr_sessionIsUTPEnabled (s));
+ tr_variantDictAddBool (d, TR_KEY_dht_enabled, tr_sessionIsDHTEnabled (s));
+ tr_variantDictAddBool (d, TR_KEY_ldp_enabled, tr_sessionIsLPDEnabled (s));
+ tr_variantDictAddInt (d, TR_KEY_peer_port, tr_sessionGetPeerPort (s));
+ tr_variantDictAddBool (d, TR_KEY_peer_port_random_on_start, tr_sessionGetPeerPortRandomOnStart (s));
+ tr_variantDictAddBool (d, TR_KEY_port_forwarding_enabled, tr_sessionIsPortForwardingEnabled (s));
+ tr_variantDictAddBool (d, TR_KEY_rename_partial_files, tr_sessionIsIncompleteFileNamingEnabled (s));
+ tr_variantDictAddInt (d, TR_KEY_rpc_version, RPC_VERSION);
+ tr_variantDictAddInt (d, TR_KEY_rpc_version_minimum, RPC_VERSION_MIN);
+ tr_variantDictAddReal (d, TR_KEY_seedRatioLimit, tr_sessionGetRatioLimit (s));
+ tr_variantDictAddBool (d, TR_KEY_seedRatioLimited, tr_sessionIsRatioLimited (s));
+ tr_variantDictAddInt (d, TR_KEY_idle_seeding_limit, tr_sessionGetIdleLimit (s));
+ tr_variantDictAddBool (d, TR_KEY_idle_seeding_limit_enabled, tr_sessionIsIdleLimited (s));
+ tr_variantDictAddBool (d, TR_KEY_seed_queue_enabled, tr_sessionGetQueueEnabled (s, TR_UP));
+ tr_variantDictAddInt (d, TR_KEY_seed_queue_size, tr_sessionGetQueueSize (s, TR_UP));
+ tr_variantDictAddBool (d, TR_KEY_start_added_torrents, !tr_sessionGetPaused (s));
+ tr_variantDictAddBool (d, TR_KEY_trash_original_torrent_files, tr_sessionGetDeleteSource (s));
+ tr_variantDictAddInt (d, TR_KEY_speed_limit_up, tr_sessionGetSpeedLimit_KBps (s, TR_UP));
+ tr_variantDictAddBool (d, TR_KEY_speed_limit_up_enabled, tr_sessionIsSpeedLimited (s, TR_UP));
+ tr_variantDictAddInt (d, TR_KEY_speed_limit_down, tr_sessionGetSpeedLimit_KBps (s, TR_DOWN));
+ tr_variantDictAddBool (d, TR_KEY_speed_limit_down_enabled, tr_sessionIsSpeedLimited (s, TR_DOWN));
+ tr_variantDictAddStr (d, TR_KEY_script_torrent_done_filename, tr_sessionGetTorrentDoneScript (s));
+ tr_variantDictAddBool (d, TR_KEY_script_torrent_done_enabled, tr_sessionIsTorrentDoneScriptEnabled (s));
+ tr_variantDictAddBool (d, TR_KEY_queue_stalled_enabled, tr_sessionGetQueueStalledEnabled (s));
+ tr_variantDictAddInt (d, TR_KEY_queue_stalled_minutes, tr_sessionGetQueueStalledMinutes (s));
+ tr_formatter_get_units (tr_variantDictAddDict (d, TR_KEY_units, 0));
+ tr_variantDictAddStr (d, TR_KEY_version, LONG_VERSION_STRING);
switch (tr_sessionGetEncryption (s)) {
case TR_CLEAR_PREFERRED: str = "tolerated"; break;
case TR_ENCRYPTION_REQUIRED: str = "required"; break;
default: str = "preferred"; break;
}
- tr_variantDictAddStr (d, TR_PREFS_KEY_ENCRYPTION, str);
+ tr_variantDictAddStr (d, TR_KEY_encryption, str);
return NULL;
}
static void
request_exec (tr_session * session,
- tr_variant * request,
+ tr_variant * request,
tr_rpc_response_func callback,
void * callback_user_data)
{
int i;
const char * str;
- tr_variant * args_in = tr_variantDictFind (request, "arguments");
+ tr_variant * args_in = tr_variantDictFind (request, TR_KEY_arguments);
const char * result = NULL;
if (callback == NULL)
callback = noop_response_callback;
/* parse the request */
- if (!tr_variantDictFindStr (request, "method", &str, NULL))
+ if (!tr_variantDictFindStr (request, TR_KEY_method, &str, NULL))
result = "no method name";
else {
const int n = TR_N_ELEMENTS (methods);
struct evbuffer * buf;
tr_variantInitDict (&response, 3);
- tr_variantDictAddDict (&response, "arguments", 0);
- tr_variantDictAddStr (&response, "result", result);
- if (tr_variantDictFindInt (request, "tag", &tag))
- tr_variantDictAddInt (&response, "tag", tag);
+ tr_variantDictAddDict (&response, TR_KEY_arguments, 0);
+ tr_variantDictAddStr (&response, TR_KEY_result, result);
+ if (tr_variantDictFindInt (request, TR_KEY_tag, &tag))
+ tr_variantDictAddInt (&response, TR_KEY_tag, tag);
buf = tr_variantToBuf (&response, TR_VARIANT_FMT_JSON_LEAN);
(*callback)(session, buf, callback_user_data);
struct evbuffer * buf;
tr_variantInitDict (&response, 3);
- args_out = tr_variantDictAddDict (&response, "arguments", 0);
+ args_out = tr_variantDictAddDict (&response, TR_KEY_arguments, 0);
result = (*methods[i].func)(session, args_in, args_out, NULL);
if (result == NULL)
result = "success";
- tr_variantDictAddStr (&response, "result", result);
- if (tr_variantDictFindInt (request, "tag", &tag))
- tr_variantDictAddInt (&response, "tag", tag);
+ tr_variantDictAddStr (&response, TR_KEY_result, result);
+ if (tr_variantDictFindInt (request, TR_KEY_tag, &tag))
+ tr_variantDictAddInt (&response, TR_KEY_tag, tag);
buf = tr_variantToBuf (&response, TR_VARIANT_FMT_JSON_LEAN);
(*callback)(session, buf, callback_user_data);
data->session = session;
data->response = tr_new0 (tr_variant, 1);
tr_variantInitDict (data->response, 3);
- if (tr_variantDictFindInt (request, "tag", &tag))
- tr_variantDictAddInt (data->response, "tag", tag);
- data->args_out = tr_variantDictAddDict (data->response, "arguments", 0);
+ if (tr_variantDictFindInt (request, TR_KEY_tag, &tag))
+ tr_variantDictAddInt (data->response, TR_KEY_tag, tag);
+ data->args_out = tr_variantDictAddDict (data->response, TR_KEY_arguments, 0);
data->callback = callback;
data->callback_user_data = callback_user_data;
(*methods[i].func)(session, args_in, data->args_out, data);
const char * pch;
tr_variantInitDict (&top, 3);
- args = tr_variantDictAddDict (&top, "arguments", 0);
+ args = tr_variantDictAddDict (&top, TR_KEY_arguments, 0);
pch = strchr (request, '?');
if (!pch) pch = request;
char * key = tr_strndup (pch, delim - pch);
int isArg = strcmp (key, "method") && strcmp (key, "tag");
tr_variant * parent = isArg ? args : ⊤
- tr_rpc_parse_list_str (tr_variantDictAdd (parent, key, delim-pch),
+ tr_rpc_parse_list_str (tr_variantDictAdd (parent, tr_quark_new (key, delim-pch)),
delim + 1,
next ? (size_t)(
next -
}
void
-tr_sessionGetDefaultSettings (tr_variant * dict)
-{
- assert (tr_variantIsDict (dict));
-
- tr_variantDictReserve (dict, 62);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_BLOCKLIST_ENABLED, false);
- tr_variantDictAddStr (dict, TR_PREFS_KEY_BLOCKLIST_URL, "http://www.example.com/blocklist");
- tr_variantDictAddInt (dict, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, DEFAULT_CACHE_SIZE_MB);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_DHT_ENABLED, true);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_UTP_ENABLED, true);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_LPD_ENABLED, false);
- tr_variantDictAddStr (dict, TR_PREFS_KEY_DOWNLOAD_DIR, tr_getDefaultDownloadDir ());
- tr_variantDictAddInt (dict, TR_PREFS_KEY_DSPEED_KBps, 100);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_DSPEED_ENABLED, false);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_ENCRYPTION, TR_DEFAULT_ENCRYPTION);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_IDLE_LIMIT, 30);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, false);
- tr_variantDictAddStr (dict, TR_PREFS_KEY_INCOMPLETE_DIR, tr_getDefaultDownloadDir ());
- tr_variantDictAddBool (dict, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, false);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_MSGLEVEL, TR_MSG_INF);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_DOWNLOAD_QUEUE_SIZE, 5);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_DOWNLOAD_QUEUE_ENABLED, true);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, atoi (TR_DEFAULT_PEER_LIMIT_GLOBAL_STR));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PEER_LIMIT_TORRENT, atoi (TR_DEFAULT_PEER_LIMIT_TORRENT_STR));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PEER_PORT, atoi (TR_DEFAULT_PEER_PORT_STR));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, false);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, 49152);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, 65535);
- tr_variantDictAddStr (dict, TR_PREFS_KEY_PEER_SOCKET_TOS, TR_DEFAULT_PEER_SOCKET_TOS_STR);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_PEX_ENABLED, true);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_PORT_FORWARDING, true);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PREALLOCATION, TR_PREALLOCATE_SPARSE);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_PREFETCH_ENABLED, DEFAULT_PREFETCH_ENABLED);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_QUEUE_STALLED_ENABLED, true);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_QUEUE_STALLED_MINUTES, 30);
- tr_variantDictAddReal (dict, TR_PREFS_KEY_RATIO, 2.0);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_RATIO_ENABLED, false);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_RENAME_PARTIAL_FILES, true);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_RPC_AUTH_REQUIRED, false);
- tr_variantDictAddStr (dict, TR_PREFS_KEY_RPC_BIND_ADDRESS, "0.0.0.0");
- tr_variantDictAddBool (dict, TR_PREFS_KEY_RPC_ENABLED, false);
- tr_variantDictAddStr (dict, TR_PREFS_KEY_RPC_PASSWORD, "");
- tr_variantDictAddStr (dict, TR_PREFS_KEY_RPC_USERNAME, "");
- tr_variantDictAddStr (dict, TR_PREFS_KEY_RPC_WHITELIST, TR_DEFAULT_RPC_WHITELIST);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, true);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_RPC_PORT, atoi (TR_DEFAULT_RPC_PORT_STR));
- tr_variantDictAddStr (dict, TR_PREFS_KEY_RPC_URL, TR_DEFAULT_RPC_URL_STR);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_SCRAPE_PAUSED_TORRENTS, true);
- tr_variantDictAddStr (dict, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, "");
- tr_variantDictAddBool (dict, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, false);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_SEED_QUEUE_SIZE, 10);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_SEED_QUEUE_ENABLED, false);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_ALT_SPEED_ENABLED, false);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_ALT_SPEED_UP_KBps, 50); /* half the regular */
- tr_variantDictAddInt (dict, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, 50); /* half the regular */
- tr_variantDictAddInt (dict, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, 540); /* 9am */
- tr_variantDictAddBool (dict, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, false);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_ALT_SPEED_TIME_END, 1020); /* 5pm */
- tr_variantDictAddInt (dict, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, TR_SCHED_ALL);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_USPEED_KBps, 100);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_USPEED_ENABLED, false);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_UMASK, 022);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, 14);
- tr_variantDictAddStr (dict, TR_PREFS_KEY_BIND_ADDRESS_IPV4, TR_DEFAULT_BIND_ADDRESS_IPV4);
- tr_variantDictAddStr (dict, TR_PREFS_KEY_BIND_ADDRESS_IPV6, TR_DEFAULT_BIND_ADDRESS_IPV6);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_START, true);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_TRASH_ORIGINAL, false);
+tr_sessionGetDefaultSettings (tr_variant * d)
+{
+ assert (tr_variantIsDict (d));
+
+ tr_variantDictReserve (d, 62);
+ tr_variantDictAddBool (d, TR_KEY_blocklist_enabled, false);
+ tr_variantDictAddStr (d, TR_KEY_blocklist_url, "http://www.example.com/blocklist");
+ tr_variantDictAddInt (d, TR_KEY_cache_size_mb, DEFAULT_CACHE_SIZE_MB);
+ tr_variantDictAddBool (d, TR_KEY_dht_enabled, true);
+ tr_variantDictAddBool (d, TR_KEY_utp_enabled, true);
+ tr_variantDictAddBool (d, TR_KEY_lpd_enabled, false);
+ tr_variantDictAddStr (d, TR_KEY_download_dir, tr_getDefaultDownloadDir ());
+ tr_variantDictAddInt (d, TR_KEY_speed_limit_down, 100);
+ tr_variantDictAddBool (d, TR_KEY_speed_limit_down_enabled, false);
+ tr_variantDictAddInt (d, TR_KEY_encryption, TR_DEFAULT_ENCRYPTION);
+ tr_variantDictAddInt (d, TR_KEY_idle_seeding_limit, 30);
+ tr_variantDictAddBool (d, TR_KEY_idle_seeding_limit_enabled, false);
+ tr_variantDictAddStr (d, TR_KEY_incomplete_dir, tr_getDefaultDownloadDir ());
+ tr_variantDictAddBool (d, TR_KEY_incomplete_dir_enabled, false);
+ tr_variantDictAddInt (d, TR_KEY_message_level, TR_MSG_INF);
+ tr_variantDictAddInt (d, TR_KEY_download_queue_size, 5);
+ tr_variantDictAddBool (d, TR_KEY_download_queue_enabled, true);
+ tr_variantDictAddInt (d, TR_KEY_peer_limit_global, atoi (TR_DEFAULT_PEER_LIMIT_GLOBAL_STR));
+ tr_variantDictAddInt (d, TR_KEY_peer_limit_per_torrent, atoi (TR_DEFAULT_PEER_LIMIT_TORRENT_STR));
+ tr_variantDictAddInt (d, TR_KEY_peer_port, atoi (TR_DEFAULT_PEER_PORT_STR));
+ tr_variantDictAddBool (d, TR_KEY_peer_port_random_on_start, false);
+ tr_variantDictAddInt (d, TR_KEY_peer_port_random_low, 49152);
+ tr_variantDictAddInt (d, TR_KEY_peer_port_random_high, 65535);
+ tr_variantDictAddStr (d, TR_KEY_peer_socket_tos, TR_DEFAULT_PEER_SOCKET_TOS_STR);
+ tr_variantDictAddBool (d, TR_KEY_pex_enabled, true);
+ tr_variantDictAddBool (d, TR_KEY_port_forwarding_enabled, true);
+ tr_variantDictAddInt (d, TR_KEY_preallocation, TR_PREALLOCATE_SPARSE);
+ tr_variantDictAddBool (d, TR_KEY_prefetch_enabled, DEFAULT_PREFETCH_ENABLED);
+ tr_variantDictAddBool (d, TR_KEY_queue_stalled_enabled, true);
+ tr_variantDictAddInt (d, TR_KEY_queue_stalled_minutes, 30);
+ tr_variantDictAddReal (d, TR_KEY_ratio_limit, 2.0);
+ tr_variantDictAddBool (d, TR_KEY_ratio_limit_enabled, false);
+ tr_variantDictAddBool (d, TR_KEY_rename_partial_files, true);
+ tr_variantDictAddBool (d, TR_KEY_rpc_authentication_required, false);
+ tr_variantDictAddStr (d, TR_KEY_rpc_bind_address, "0.0.0.0");
+ tr_variantDictAddBool (d, TR_KEY_rpc_enabled, false);
+ tr_variantDictAddStr (d, TR_KEY_rpc_password, "");
+ tr_variantDictAddStr (d, TR_KEY_rpc_username, "");
+ tr_variantDictAddStr (d, TR_KEY_rpc_whitelist, TR_DEFAULT_RPC_WHITELIST);
+ tr_variantDictAddBool (d, TR_KEY_rpc_whitelist_enabled, true);
+ tr_variantDictAddInt (d, TR_KEY_rpc_port, atoi (TR_DEFAULT_RPC_PORT_STR));
+ tr_variantDictAddStr (d, TR_KEY_rpc_url, TR_DEFAULT_RPC_URL_STR);
+ tr_variantDictAddBool (d, TR_KEY_scrape_paused_torrents_enabled, true);
+ tr_variantDictAddStr (d, TR_KEY_script_torrent_done_filename, "");
+ tr_variantDictAddBool (d, TR_KEY_script_torrent_done_enabled, false);
+ tr_variantDictAddInt (d, TR_KEY_seed_queue_size, 10);
+ tr_variantDictAddBool (d, TR_KEY_seed_queue_enabled, false);
+ tr_variantDictAddBool (d, TR_KEY_alt_speed_enabled, false);
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_up, 50); /* half the regular */
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_down, 50); /* half the regular */
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_time_begin, 540); /* 9am */
+ tr_variantDictAddBool (d, TR_KEY_alt_speed_time_enabled, false);
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_time_end, 1020); /* 5pm */
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_time_day, TR_SCHED_ALL);
+ tr_variantDictAddInt (d, TR_KEY_speed_limit_up, 100);
+ tr_variantDictAddBool (d, TR_KEY_speed_limit_up_enabled, false);
+ tr_variantDictAddInt (d, TR_KEY_umask, 022);
+ tr_variantDictAddInt (d, TR_KEY_upload_slots_per_torrent, 14);
+ tr_variantDictAddStr (d, TR_KEY_bind_address_ipv4, TR_DEFAULT_BIND_ADDRESS_IPV4);
+ tr_variantDictAddStr (d, TR_KEY_bind_address_ipv6, TR_DEFAULT_BIND_ADDRESS_IPV6);
+ tr_variantDictAddBool (d, TR_KEY_start_added_torrents, true);
+ tr_variantDictAddBool (d, TR_KEY_trash_original_torrent_files, false);
}
void
-tr_sessionGetSettings (tr_session * s, tr_variant * dict)
-{
- assert (tr_variantIsDict (dict));
-
- tr_variantDictReserve (dict, 63);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled (s));
- tr_variantDictAddStr (dict, TR_PREFS_KEY_BLOCKLIST_URL, tr_blocklistGetURL (s));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, tr_sessionGetCacheLimit_MB (s));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_DHT_ENABLED, s->isDHTEnabled);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_UTP_ENABLED, s->isUTPEnabled);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_LPD_ENABLED, s->isLPDEnabled);
- tr_variantDictAddStr (dict, TR_PREFS_KEY_DOWNLOAD_DIR, s->downloadDir);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_DOWNLOAD_QUEUE_SIZE, tr_sessionGetQueueSize (s, TR_DOWN));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_DOWNLOAD_QUEUE_ENABLED, tr_sessionGetQueueEnabled (s, TR_DOWN));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_DSPEED_KBps, tr_sessionGetSpeedLimit_KBps (s, TR_DOWN));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_DSPEED_ENABLED, tr_sessionIsSpeedLimited (s, TR_DOWN));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_ENCRYPTION, s->encryptionMode);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_IDLE_LIMIT, tr_sessionGetIdleLimit (s));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, tr_sessionIsIdleLimited (s));
- tr_variantDictAddStr (dict, TR_PREFS_KEY_INCOMPLETE_DIR, tr_sessionGetIncompleteDir (s));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, tr_sessionIsIncompleteDirEnabled (s));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_MSGLEVEL, tr_getMessageLevel ());
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, s->peerLimit);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PEER_LIMIT_TORRENT, s->peerLimitPerTorrent);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PEER_PORT, tr_sessionGetPeerPort (s));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, s->isPortRandom);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, s->randomPortLow);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, s->randomPortHigh);
- tr_variantDictAddStr (dict, TR_PREFS_KEY_PEER_SOCKET_TOS, format_tos (s->peerSocketTOS));
- tr_variantDictAddStr (dict, TR_PREFS_KEY_PEER_CONGESTION_ALGORITHM, s->peer_congestion_algorithm);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_PEX_ENABLED, s->isPexEnabled);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_PORT_FORWARDING, tr_sessionIsPortForwardingEnabled (s));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PREALLOCATION, s->preallocationMode);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_PREFETCH_ENABLED, s->isPrefetchEnabled);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_QUEUE_STALLED_ENABLED, tr_sessionGetQueueStalledEnabled (s));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_QUEUE_STALLED_MINUTES, tr_sessionGetQueueStalledMinutes (s));
- tr_variantDictAddReal (dict, TR_PREFS_KEY_RATIO, s->desiredRatio);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_RATIO_ENABLED, s->isRatioLimited);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_RENAME_PARTIAL_FILES, tr_sessionIsIncompleteFileNamingEnabled (s));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_RPC_AUTH_REQUIRED, tr_sessionIsRPCPasswordEnabled (s));
- tr_variantDictAddStr (dict, TR_PREFS_KEY_RPC_BIND_ADDRESS, tr_sessionGetRPCBindAddress (s));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_RPC_ENABLED, tr_sessionIsRPCEnabled (s));
- tr_variantDictAddStr (dict, TR_PREFS_KEY_RPC_PASSWORD, tr_sessionGetRPCPassword (s));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_RPC_PORT, tr_sessionGetRPCPort (s));
- tr_variantDictAddStr (dict, TR_PREFS_KEY_RPC_URL, tr_sessionGetRPCUrl (s));
- tr_variantDictAddStr (dict, TR_PREFS_KEY_RPC_USERNAME, tr_sessionGetRPCUsername (s));
- tr_variantDictAddStr (dict, TR_PREFS_KEY_RPC_WHITELIST, tr_sessionGetRPCWhitelist (s));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, tr_sessionGetRPCWhitelistEnabled (s));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_SCRAPE_PAUSED_TORRENTS, s->scrapePausedTorrents);
- tr_variantDictAddBool (dict, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, tr_sessionIsTorrentDoneScriptEnabled (s));
- tr_variantDictAddStr (dict, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, tr_sessionGetTorrentDoneScript (s));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_SEED_QUEUE_SIZE, tr_sessionGetQueueSize (s, TR_UP));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_SEED_QUEUE_ENABLED, tr_sessionGetQueueEnabled (s, TR_UP));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_ALT_SPEED_ENABLED, tr_sessionUsesAltSpeed (s));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_ALT_SPEED_UP_KBps, tr_sessionGetAltSpeed_KBps (s, TR_UP));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, tr_sessionGetAltSpeed_KBps (s, TR_DOWN));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, tr_sessionGetAltSpeedBegin (s));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, tr_sessionUsesAltSpeedTime (s));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_ALT_SPEED_TIME_END, tr_sessionGetAltSpeedEnd (s));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, tr_sessionGetAltSpeedDay (s));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_USPEED_KBps, tr_sessionGetSpeedLimit_KBps (s, TR_UP));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_USPEED_ENABLED, tr_sessionIsSpeedLimited (s, TR_UP));
- tr_variantDictAddInt (dict, TR_PREFS_KEY_UMASK, s->umask);
- tr_variantDictAddInt (dict, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, s->uploadSlotsPerTorrent);
- tr_variantDictAddStr (dict, TR_PREFS_KEY_BIND_ADDRESS_IPV4, tr_address_to_string (&s->public_ipv4->addr));
- tr_variantDictAddStr (dict, TR_PREFS_KEY_BIND_ADDRESS_IPV6, tr_address_to_string (&s->public_ipv6->addr));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_START, !tr_sessionGetPaused (s));
- tr_variantDictAddBool (dict, TR_PREFS_KEY_TRASH_ORIGINAL, tr_sessionGetDeleteSource (s));
+tr_sessionGetSettings (tr_session * s, tr_variant * d)
+{
+ assert (tr_variantIsDict (d));
+
+ tr_variantDictReserve (d, 63);
+ tr_variantDictAddBool (d, TR_KEY_blocklist_enabled, tr_blocklistIsEnabled (s));
+ tr_variantDictAddStr (d, TR_KEY_blocklist_url, tr_blocklistGetURL (s));
+ tr_variantDictAddInt (d, TR_KEY_cache_size_mb, tr_sessionGetCacheLimit_MB (s));
+ tr_variantDictAddBool (d, TR_KEY_dht_enabled, s->isDHTEnabled);
+ tr_variantDictAddBool (d, TR_KEY_utp_enabled, s->isUTPEnabled);
+ tr_variantDictAddBool (d, TR_KEY_lpd_enabled, s->isLPDEnabled);
+ tr_variantDictAddStr (d, TR_KEY_download_dir, s->downloadDir);
+ tr_variantDictAddInt (d, TR_KEY_download_queue_size, tr_sessionGetQueueSize (s, TR_DOWN));
+ tr_variantDictAddBool (d, TR_KEY_download_queue_enabled, tr_sessionGetQueueEnabled (s, TR_DOWN));
+ tr_variantDictAddInt (d, TR_KEY_speed_limit_down, tr_sessionGetSpeedLimit_KBps (s, TR_DOWN));
+ tr_variantDictAddBool (d, TR_KEY_speed_limit_down_enabled, tr_sessionIsSpeedLimited (s, TR_DOWN));
+ tr_variantDictAddInt (d, TR_KEY_encryption, s->encryptionMode);
+ tr_variantDictAddInt (d, TR_KEY_idle_seeding_limit, tr_sessionGetIdleLimit (s));
+ tr_variantDictAddBool (d, TR_KEY_idle_seeding_limit_enabled, tr_sessionIsIdleLimited (s));
+ tr_variantDictAddStr (d, TR_KEY_incomplete_dir, tr_sessionGetIncompleteDir (s));
+ tr_variantDictAddBool (d, TR_KEY_incomplete_dir_enabled, tr_sessionIsIncompleteDirEnabled (s));
+ tr_variantDictAddInt (d, TR_KEY_message_level, tr_getMessageLevel ());
+ tr_variantDictAddInt (d, TR_KEY_peer_limit_global, s->peerLimit);
+ tr_variantDictAddInt (d, TR_KEY_peer_limit_per_torrent, s->peerLimitPerTorrent);
+ tr_variantDictAddInt (d, TR_KEY_peer_port, tr_sessionGetPeerPort (s));
+ tr_variantDictAddBool (d, TR_KEY_peer_port_random_on_start, s->isPortRandom);
+ tr_variantDictAddInt (d, TR_KEY_peer_port_random_low, s->randomPortLow);
+ tr_variantDictAddInt (d, TR_KEY_peer_port_random_high, s->randomPortHigh);
+ tr_variantDictAddStr (d, TR_KEY_peer_socket_tos, format_tos (s->peerSocketTOS));
+ tr_variantDictAddStr (d, TR_KEY_peer_congestion_algorithm, s->peer_congestion_algorithm);
+ tr_variantDictAddBool (d, TR_KEY_pex_enabled, s->isPexEnabled);
+ tr_variantDictAddBool (d, TR_KEY_port_forwarding_enabled, tr_sessionIsPortForwardingEnabled (s));
+ tr_variantDictAddInt (d, TR_KEY_preallocation, s->preallocationMode);
+ tr_variantDictAddInt (d, TR_KEY_prefetch_enabled, s->isPrefetchEnabled);
+ tr_variantDictAddBool (d, TR_KEY_queue_stalled_enabled, tr_sessionGetQueueStalledEnabled (s));
+ tr_variantDictAddInt (d, TR_KEY_queue_stalled_minutes, tr_sessionGetQueueStalledMinutes (s));
+ tr_variantDictAddReal (d, TR_KEY_ratio_limit, s->desiredRatio);
+ tr_variantDictAddBool (d, TR_KEY_ratio_limit_enabled, s->isRatioLimited);
+ tr_variantDictAddBool (d, TR_KEY_rename_partial_files, tr_sessionIsIncompleteFileNamingEnabled (s));
+ tr_variantDictAddBool (d, TR_KEY_rpc_authentication_required, tr_sessionIsRPCPasswordEnabled (s));
+ tr_variantDictAddStr (d, TR_KEY_rpc_bind_address, tr_sessionGetRPCBindAddress (s));
+ tr_variantDictAddBool (d, TR_KEY_rpc_enabled, tr_sessionIsRPCEnabled (s));
+ tr_variantDictAddStr (d, TR_KEY_rpc_password, tr_sessionGetRPCPassword (s));
+ tr_variantDictAddInt (d, TR_KEY_rpc_port, tr_sessionGetRPCPort (s));
+ tr_variantDictAddStr (d, TR_KEY_rpc_url, tr_sessionGetRPCUrl (s));
+ tr_variantDictAddStr (d, TR_KEY_rpc_username, tr_sessionGetRPCUsername (s));
+ tr_variantDictAddStr (d, TR_KEY_rpc_whitelist, tr_sessionGetRPCWhitelist (s));
+ tr_variantDictAddBool (d, TR_KEY_rpc_whitelist_enabled, tr_sessionGetRPCWhitelistEnabled (s));
+ tr_variantDictAddBool (d, TR_KEY_scrape_paused_torrents_enabled, s->scrapePausedTorrents);
+ tr_variantDictAddBool (d, TR_KEY_script_torrent_done_enabled, tr_sessionIsTorrentDoneScriptEnabled (s));
+ tr_variantDictAddStr (d, TR_KEY_script_torrent_done_filename, tr_sessionGetTorrentDoneScript (s));
+ tr_variantDictAddInt (d, TR_KEY_seed_queue_size, tr_sessionGetQueueSize (s, TR_UP));
+ tr_variantDictAddBool (d, TR_KEY_seed_queue_enabled, tr_sessionGetQueueEnabled (s, TR_UP));
+ tr_variantDictAddBool (d, TR_KEY_alt_speed_enabled, tr_sessionUsesAltSpeed (s));
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_up, tr_sessionGetAltSpeed_KBps (s, TR_UP));
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_down, tr_sessionGetAltSpeed_KBps (s, TR_DOWN));
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_time_begin, tr_sessionGetAltSpeedBegin (s));
+ tr_variantDictAddBool (d, TR_KEY_alt_speed_time_enabled, tr_sessionUsesAltSpeedTime (s));
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_time_end, tr_sessionGetAltSpeedEnd (s));
+ tr_variantDictAddInt (d, TR_KEY_alt_speed_time_day, tr_sessionGetAltSpeedDay (s));
+ tr_variantDictAddInt (d, TR_KEY_speed_limit_up, tr_sessionGetSpeedLimit_KBps (s, TR_UP));
+ tr_variantDictAddBool (d, TR_KEY_speed_limit_up_enabled, tr_sessionIsSpeedLimited (s, TR_UP));
+ tr_variantDictAddInt (d, TR_KEY_umask, s->umask);
+ tr_variantDictAddInt (d, TR_KEY_upload_slots_per_torrent, s->uploadSlotsPerTorrent);
+ tr_variantDictAddStr (d, TR_KEY_bind_address_ipv4, tr_address_to_string (&s->public_ipv4->addr));
+ tr_variantDictAddStr (d, TR_KEY_bind_address_ipv6, tr_address_to_string (&s->public_ipv6->addr));
+ tr_variantDictAddBool (d, TR_KEY_start_added_torrents, !tr_sessionGetPaused (s));
+ tr_variantDictAddBool (d, TR_KEY_trash_original_torrent_files, tr_sessionGetDeleteSource (s));
}
bool
tr_variantInitList (&session->removedTorrents, 0);
/* nice to start logging at the very beginning */
- if (tr_variantDictFindInt (clientSettings, TR_PREFS_KEY_MSGLEVEL, &i))
+ if (tr_variantDictFindInt (clientSettings, TR_KEY_message_level, &i))
tr_setMessageLevel (i);
/* start the libtransmission thread */
assert (tr_variantIsDict (settings));
assert (tr_amInEventThread (session));
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_MSGLEVEL, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_message_level, &i))
tr_setMessageLevel (i);
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_UMASK, &i)) {
+ if (tr_variantDictFindInt (settings, TR_KEY_umask, &i)) {
session->umask = (mode_t)i;
umask (session->umask);
}
/* misc features */
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_cache_size_mb, &i))
tr_sessionSetCacheLimit_MB (session, i);
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_peer_limit_per_torrent, &i))
tr_sessionSetPeerLimitPerTorrent (session, i);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_PEX_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_pex_enabled, &boolVal))
tr_sessionSetPexEnabled (session, boolVal);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_DHT_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_dht_enabled, &boolVal))
tr_sessionSetDHTEnabled (session, boolVal);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_UTP_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_utp_enabled, &boolVal))
tr_sessionSetUTPEnabled (session, boolVal);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_LPD_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_lpd_enabled, &boolVal))
tr_sessionSetLPDEnabled (session, boolVal);
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_ENCRYPTION, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_encryption, &i))
tr_sessionSetEncryption (session, i);
- if (tr_variantDictFindStr (settings, TR_PREFS_KEY_PEER_SOCKET_TOS, &str, NULL))
+ if (tr_variantDictFindStr (settings, TR_KEY_peer_socket_tos, &str, NULL))
session->peerSocketTOS = parse_tos (str);
- if (tr_variantDictFindStr (settings, TR_PREFS_KEY_PEER_CONGESTION_ALGORITHM, &str, NULL))
+ if (tr_variantDictFindStr (settings, TR_KEY_peer_congestion_algorithm, &str, NULL))
session->peer_congestion_algorithm = tr_strdup (str);
else
session->peer_congestion_algorithm = tr_strdup ("");
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_blocklist_enabled, &boolVal))
tr_blocklistSetEnabled (session, boolVal);
- if (tr_variantDictFindStr (settings, TR_PREFS_KEY_BLOCKLIST_URL, &str, NULL))
+ if (tr_variantDictFindStr (settings, TR_KEY_blocklist_url, &str, NULL))
tr_blocklistSetURL (session, str);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_START, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_start_added_torrents, &boolVal))
tr_sessionSetPaused (session, !boolVal);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_TRASH_ORIGINAL, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_trash_original_torrent_files, &boolVal))
tr_sessionSetDeleteSource (session, boolVal);
/* torrent queues */
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_QUEUE_STALLED_MINUTES, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_queue_stalled_minutes, &i))
tr_sessionSetQueueStalledMinutes (session, i);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_QUEUE_STALLED_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_queue_stalled_enabled, &boolVal))
tr_sessionSetQueueStalledEnabled (session, boolVal);
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_DOWNLOAD_QUEUE_SIZE, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_download_queue_size, &i))
tr_sessionSetQueueSize (session, TR_DOWN, i);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_DOWNLOAD_QUEUE_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_download_queue_enabled, &boolVal))
tr_sessionSetQueueEnabled (session, TR_DOWN, boolVal);
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_SEED_QUEUE_SIZE, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_seed_queue_size, &i))
tr_sessionSetQueueSize (session, TR_UP, i);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_SEED_QUEUE_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_seed_queue_enabled, &boolVal))
tr_sessionSetQueueEnabled (session, TR_UP, boolVal);
/* files and directories */
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_PREFETCH_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_prefetch_enabled, &boolVal))
session->isPrefetchEnabled = boolVal;
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_PREALLOCATION, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_preallocation, &i))
session->preallocationMode = i;
- if (tr_variantDictFindStr (settings, TR_PREFS_KEY_DOWNLOAD_DIR, &str, NULL))
+ if (tr_variantDictFindStr (settings, TR_KEY_download_dir, &str, NULL))
tr_sessionSetDownloadDir (session, str);
- if (tr_variantDictFindStr (settings, TR_PREFS_KEY_INCOMPLETE_DIR, &str, NULL))
+ if (tr_variantDictFindStr (settings, TR_KEY_incomplete_dir, &str, NULL))
tr_sessionSetIncompleteDir (session, str);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_incomplete_dir_enabled, &boolVal))
tr_sessionSetIncompleteDirEnabled (session, boolVal);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_RENAME_PARTIAL_FILES, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_rename_partial_files, &boolVal))
tr_sessionSetIncompleteFileNamingEnabled (session, boolVal);
/* rpc server */
free_incoming_peer_port (session);
- str = TR_PREFS_KEY_BIND_ADDRESS_IPV4;
- tr_variantDictFindStr (settings, TR_PREFS_KEY_BIND_ADDRESS_IPV4, &str, NULL);
+ tr_variantDictFindStr (settings, TR_KEY_bind_address_ipv4, &str, NULL);
if (!tr_address_from_string (&b.addr, str) || (b.addr.type != TR_AF_INET))
b.addr = tr_inaddr_any;
b.socket = -1;
session->public_ipv4 = tr_memdup (&b, sizeof (struct tr_bindinfo));
- str = TR_PREFS_KEY_BIND_ADDRESS_IPV6;
- tr_variantDictFindStr (settings, TR_PREFS_KEY_BIND_ADDRESS_IPV6, &str, NULL);
+ tr_variantDictFindStr (settings, TR_KEY_bind_address_ipv6, &str, NULL);
if (!tr_address_from_string (&b.addr, str) || (b.addr.type != TR_AF_INET6))
b.addr = tr_in6addr_any;
b.socket = -1;
session->public_ipv6 = tr_memdup (&b, sizeof (struct tr_bindinfo));
/* incoming peer port */
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_peer_port_random_low, &i))
session->randomPortLow = i;
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_peer_port_random_high, &i))
session->randomPortHigh = i;
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_peer_port_random_on_start, &boolVal))
tr_sessionSetPeerPortRandomOnStart (session, boolVal);
- if (!tr_variantDictFindInt (settings, TR_PREFS_KEY_PEER_PORT, &i))
+ if (!tr_variantDictFindInt (settings, TR_KEY_peer_port, &i))
i = session->private_peer_port;
setPeerPort (session, boolVal ? getRandomPort (session) : i);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_PORT_FORWARDING, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_port_forwarding_enabled, &boolVal))
tr_sessionSetPortForwardingEnabled (session, boolVal);
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_peer_limit_global, &i))
session->peerLimit = i;
/**
**/
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_upload_slots_per_torrent, &i))
session->uploadSlotsPerTorrent = i;
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_USPEED_KBps, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_speed_limit_up, &i))
tr_sessionSetSpeedLimit_KBps (session, TR_UP, i);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_USPEED_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_speed_limit_up_enabled, &boolVal))
tr_sessionLimitSpeed (session, TR_UP, boolVal);
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_DSPEED_KBps, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_speed_limit_down, &i))
tr_sessionSetSpeedLimit_KBps (session, TR_DOWN, i);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_DSPEED_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_speed_limit_down_enabled, &boolVal))
tr_sessionLimitSpeed (session, TR_DOWN, boolVal);
- if (tr_variantDictFindReal (settings, TR_PREFS_KEY_RATIO, &d))
+ if (tr_variantDictFindReal (settings, TR_KEY_ratio_limit, &d))
tr_sessionSetRatioLimit (session, d);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_RATIO_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_ratio_limit_enabled, &boolVal))
tr_sessionSetRatioLimited (session, boolVal);
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_IDLE_LIMIT, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_idle_seeding_limit, &i))
tr_sessionSetIdleLimit (session, i);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_idle_seeding_limit_enabled, &boolVal))
tr_sessionSetIdleLimited (session, boolVal);
/**
**/
/* update the turtle mode's fields */
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_ALT_SPEED_UP_KBps, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_alt_speed_up, &i))
turtle->speedLimit_Bps[TR_UP] = toSpeedBytes (i);
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_alt_speed_down, &i))
turtle->speedLimit_Bps[TR_DOWN] = toSpeedBytes (i);
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_alt_speed_time_begin, &i))
turtle->beginMinute = i;
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_ALT_SPEED_TIME_END, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_alt_speed_time_end, &i))
turtle->endMinute = i;
- if (tr_variantDictFindInt (settings, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, &i))
+ if (tr_variantDictFindInt (settings, TR_KEY_alt_speed_time_day, &i))
turtle->days = i;
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_alt_speed_time_enabled, &boolVal))
turtle->isClockEnabled = boolVal;
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_ALT_SPEED_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_alt_speed_enabled, &boolVal))
turtle->isEnabled = boolVal;
turtleBootstrap (session, turtle);
*** Scripts
**/
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_script_torrent_done_enabled, &boolVal))
tr_sessionSetTorrentDoneScriptEnabled (session, boolVal);
- if (tr_variantDictFindStr (settings, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, &str, NULL))
+ if (tr_variantDictFindStr (settings, TR_KEY_script_torrent_done_filename, &str, NULL))
tr_sessionSetTorrentDoneScript (session, str);
- if (tr_variantDictFindBool (settings, TR_PREFS_KEY_SCRAPE_PAUSED_TORRENTS, &boolVal))
+ if (tr_variantDictFindBool (settings, TR_KEY_scrape_paused_torrents_enabled, &boolVal))
session->scrapePausedTorrents = boolVal;
data->done = true;
if (!tr_torrentParse (ctor, &inf))
{
++n;
- tr_variantDictAddStr (lookup, inf.hashString, path);
+ tr_variantDictAddStr (lookup, tr_quark_new(inf.hashString,-1), path);
}
tr_free (path);
}
const char * filename = NULL;
if (!session->metainfoLookup)
metainfoLookupInit ((tr_session*)session);
- tr_variantDictFindStr (session->metainfoLookup, hashString, &filename, NULL);
+ tr_variantDictFindStr (session->metainfoLookup, tr_quark_new(hashString,-1), &filename, NULL);
return filename;
}
* in that same directory, we don't need to do anything here if the
* lookup table hasn't been built yet */
if (session->metainfoLookup)
- tr_variantDictAddStr (session->metainfoLookup, hashString, filename);
+ tr_variantDictAddStr (session->metainfoLookup, tr_quark_new(hashString,-1), filename);
}
/***
{
int64_t i;
- if (tr_variantDictFindInt (&top, "downloaded-bytes", &i))
+ if (tr_variantDictFindInt (&top, TR_KEY_downloaded_bytes, &i))
setme->downloadedBytes = (uint64_t) i;
- if (tr_variantDictFindInt (&top, "files-added", &i))
+ if (tr_variantDictFindInt (&top, TR_KEY_files_added, &i))
setme->filesAdded = (uint64_t) i;
- if (tr_variantDictFindInt (&top, "seconds-active", &i))
+ if (tr_variantDictFindInt (&top, TR_KEY_seconds_active, &i))
setme->secondsActive = (uint64_t) i;
- if (tr_variantDictFindInt (&top, "session-count", &i))
+ if (tr_variantDictFindInt (&top, TR_KEY_session_count, &i))
setme->sessionCount = (uint64_t) i;
- if (tr_variantDictFindInt (&top, "uploaded-bytes", &i))
+ if (tr_variantDictFindInt (&top, TR_KEY_uploaded_bytes, &i))
setme->uploadedBytes = (uint64_t) i;
tr_variantFree (&top);
tr_variant top;
tr_variantInitDict (&top, 5);
- tr_variantDictAddInt (&top, "downloaded-bytes", s->downloadedBytes);
- tr_variantDictAddInt (&top, "files-added", s->filesAdded);
- tr_variantDictAddInt (&top, "seconds-active", s->secondsActive);
- tr_variantDictAddInt (&top, "session-count", s->sessionCount);
- tr_variantDictAddInt (&top, "uploaded-bytes", s->uploadedBytes);
+ tr_variantDictAddInt (&top, TR_KEY_downloaded_bytes, s->downloadedBytes);
+ tr_variantDictAddInt (&top, TR_KEY_files_added, s->filesAdded);
+ tr_variantDictAddInt (&top, TR_KEY_seconds_active, s->secondsActive);
+ tr_variantDictAddInt (&top, TR_KEY_session_count, s->sessionCount);
+ tr_variantDictAddInt (&top, TR_KEY_uploaded_bytes, s->uploadedBytes);
filename = getFilename (session);
tr_deepLog (__FILE__, __LINE__, NULL, "Saving stats to \"%s\"", filename);
if (ctor->isSet_metainfo)
{
tr_variant * info;
- if (tr_variantDictFindDict (&ctor->metainfo, "info", &info))
+ if (tr_variantDictFindDict (&ctor->metainfo, TR_KEY_info, &info))
{
const char * name;
- if (!tr_variantDictFindStr (info, "name.utf-8", &name, NULL))
- if (!tr_variantDictFindStr (info, "name", &name, NULL))
+ if (!tr_variantDictFindStr (info, TR_KEY_name_utf_8, &name, NULL))
+ if (!tr_variantDictFindStr (info, TR_KEY_name, &name, NULL))
name = NULL;
if (!name || !*name)
{
char * base = tr_basename (filename);
- tr_variantDictAddStr (info, "name", base);
+ tr_variantDictAddStr (info, TR_KEY_name, base);
tr_free (base);
}
}
{
tr_variant * infoDict;
- if (tr_variantDictFindDict (&top, "info", &infoDict))
+ if (tr_variantDictFindDict (&top, TR_KEY_info, &infoDict))
{
int infoLen;
char * infoContents = tr_variantToStr (infoDict, TR_VARIANT_FMT_BENC, &infoLen);
tr_torrentRemoveResume (tor);
dbgmsg (tor, "Saving completed metadata to \"%s\"", path);
- tr_variantMergeDicts (tr_variantDictAddDict (&newMetainfo, "info", 0), &infoDict);
+ tr_variantMergeDicts (tr_variantDictAddDict (&newMetainfo, TR_KEY_info, 0), &infoDict);
memset (&info, 0, sizeof (tr_info));
success = tr_metainfoParse (tor->session, &newMetainfo, &info, &hasInfo, &infoDictLength);
assert (tr_isTorrent (tor));
d = tr_variantListAddDict (&tor->session->removedTorrents, 2);
- tr_variantDictAddInt (d, "id", tor->uniqueId);
- tr_variantDictAddInt (d, "date", tr_time ());
+ tr_variantDictAddInt (d, TR_KEY_id, tor->uniqueId);
+ tr_variantDictAddInt (d, TR_KEY_date, tr_time ());
tr_torinf (tor, "%s", _("Removing torrent"));
tr_info tmpInfo;
/* remove the old fields */
- tr_variantDictRemove (&metainfo, "announce");
- tr_variantDictRemove (&metainfo, "announce-list");
+ tr_variantDictRemove (&metainfo, TR_KEY_announce);
+ tr_variantDictRemove (&metainfo, TR_KEY_announce_list);
/* add the new fields */
if (trackerCount > 0)
{
- tr_variantDictAddStr (&metainfo, "announce", trackers[0].announce);
+ tr_variantDictAddStr (&metainfo, TR_KEY_announce, trackers[0].announce);
}
if (trackerCount > 1)
{
int i;
int prevTier = -1;
tr_variant * tier = NULL;
- tr_variant * announceList = tr_variantDictAddList (&metainfo, "announce-list", 0);
+ tr_variant * announceList = tr_variantDictAddList (&metainfo, TR_KEY_announce_list, 0);
for (i=0; i<trackerCount; ++i) {
if (prevTier != trackers[i].tier) {
rc = tr_variantFromFile (&benc, TR_VARIANT_FMT_BENC, dat_file);
tr_free (dat_file);
if (rc == 0) {
- have_id = tr_variantDictFindRaw (&benc, "id", &raw, &len);
+ have_id = tr_variantDictFindRaw (&benc, TR_KEY_id, &raw, &len);
if (have_id && len==20)
memcpy (myid, raw, len);
if (ss->udp_socket >= 0 &&
- tr_variantDictFindRaw (&benc, "nodes", &raw, &len) && ! (len%6)) {
+ tr_variantDictFindRaw (&benc, TR_KEY_nodes, &raw, &len) && ! (len%6)) {
nodes = tr_memdup (raw, len);
}
if (ss->udp6_socket > 0 &&
- tr_variantDictFindRaw (&benc, "nodes6", &raw, &len6) && ! (len6%18)) {
+ tr_variantDictFindRaw (&benc, TR_KEY_nodes6, &raw, &len6) && ! (len6%18)) {
nodes6 = tr_memdup (raw, len6);
}
tr_variantFree (&benc);
j += 18;
}
tr_variantInitDict (&benc, 3);
- tr_variantDictAddRaw (&benc, "id", myid, 20);
+ tr_variantDictAddRaw (&benc, TR_KEY_id, myid, 20);
if (num > 0)
- tr_variantDictAddRaw (&benc, "nodes", compact, num * 6);
+ tr_variantDictAddRaw (&benc, TR_KEY_nodes, compact, num * 6);
if (num6 > 0)
- tr_variantDictAddRaw (&benc, "nodes6", compact6, num6 * 18);
+ tr_variantDictAddRaw (&benc, TR_KEY_nodes6, compact6, num6 * 18);
dat_file = tr_buildPath (ss->configDir, "dht.dat", NULL);
tr_variantToFile (&benc, TR_VARIANT_FMT_BENC, dat_file);
tr_variantFree (&benc);
#define TR_DEFAULT_PEER_LIMIT_GLOBAL_STR "240"
#define TR_DEFAULT_PEER_LIMIT_TORRENT_STR "60"
-#define TR_PREFS_KEY_ALT_SPEED_ENABLED "alt-speed-enabled"
-#define TR_PREFS_KEY_ALT_SPEED_UP_KBps "alt-speed-up"
-#define TR_PREFS_KEY_ALT_SPEED_DOWN_KBps "alt-speed-down"
-#define TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN "alt-speed-time-begin"
-#define TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED "alt-speed-time-enabled"
-#define TR_PREFS_KEY_ALT_SPEED_TIME_END "alt-speed-time-end"
-#define TR_PREFS_KEY_ALT_SPEED_TIME_DAY "alt-speed-time-day"
-#define TR_PREFS_KEY_BIND_ADDRESS_IPV4 "bind-address-ipv4"
-#define TR_PREFS_KEY_BIND_ADDRESS_IPV6 "bind-address-ipv6"
-#define TR_PREFS_KEY_BLOCKLIST_ENABLED "blocklist-enabled"
-#define TR_PREFS_KEY_BLOCKLIST_URL "blocklist-url"
-#define TR_PREFS_KEY_MAX_CACHE_SIZE_MB "cache-size-mb"
-#define TR_PREFS_KEY_DHT_ENABLED "dht-enabled"
-#define TR_PREFS_KEY_UTP_ENABLED "utp-enabled"
-#define TR_PREFS_KEY_LPD_ENABLED "lpd-enabled"
-#define TR_PREFS_KEY_DOWNLOAD_QUEUE_SIZE "download-queue-size"
-#define TR_PREFS_KEY_DOWNLOAD_QUEUE_ENABLED "download-queue-enabled"
-#define TR_PREFS_KEY_PREFETCH_ENABLED "prefetch-enabled"
-#define TR_PREFS_KEY_DOWNLOAD_DIR "download-dir"
-#define TR_PREFS_KEY_ENCRYPTION "encryption"
-#define TR_PREFS_KEY_IDLE_LIMIT "idle-seeding-limit"
-#define TR_PREFS_KEY_IDLE_LIMIT_ENABLED "idle-seeding-limit-enabled"
-#define TR_PREFS_KEY_INCOMPLETE_DIR "incomplete-dir"
-#define TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED "incomplete-dir-enabled"
-#define TR_PREFS_KEY_MSGLEVEL "message-level"
-#define TR_PREFS_KEY_PEER_LIMIT_GLOBAL "peer-limit-global"
-#define TR_PREFS_KEY_PEER_LIMIT_TORRENT "peer-limit-per-torrent"
-#define TR_PREFS_KEY_PEER_PORT "peer-port"
-#define TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START "peer-port-random-on-start"
-#define TR_PREFS_KEY_PEER_PORT_RANDOM_LOW "peer-port-random-low"
-#define TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH "peer-port-random-high"
-#define TR_PREFS_KEY_PEER_SOCKET_TOS "peer-socket-tos"
-#define TR_PREFS_KEY_PEER_CONGESTION_ALGORITHM "peer-congestion-algorithm"
-#define TR_PREFS_KEY_PEX_ENABLED "pex-enabled"
-#define TR_PREFS_KEY_PORT_FORWARDING "port-forwarding-enabled"
-#define TR_PREFS_KEY_PREALLOCATION "preallocation"
-#define TR_PREFS_KEY_RATIO "ratio-limit"
-#define TR_PREFS_KEY_RATIO_ENABLED "ratio-limit-enabled"
-#define TR_PREFS_KEY_RENAME_PARTIAL_FILES "rename-partial-files"
-#define TR_PREFS_KEY_RPC_AUTH_REQUIRED "rpc-authentication-required"
-#define TR_PREFS_KEY_RPC_BIND_ADDRESS "rpc-bind-address"
-#define TR_PREFS_KEY_RPC_ENABLED "rpc-enabled"
-#define TR_PREFS_KEY_RPC_PASSWORD "rpc-password"
-#define TR_PREFS_KEY_RPC_PORT "rpc-port"
-#define TR_PREFS_KEY_RPC_USERNAME "rpc-username"
-#define TR_PREFS_KEY_RPC_URL "rpc-url"
-#define TR_PREFS_KEY_RPC_WHITELIST_ENABLED "rpc-whitelist-enabled"
-#define TR_PREFS_KEY_SCRAPE_PAUSED_TORRENTS "scrape-paused-torrents-enabled"
-#define TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME "script-torrent-done-filename"
-#define TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED "script-torrent-done-enabled"
-#define TR_PREFS_KEY_SEED_QUEUE_SIZE "seed-queue-size"
-#define TR_PREFS_KEY_SEED_QUEUE_ENABLED "seed-queue-enabled"
-#define TR_PREFS_KEY_RPC_WHITELIST "rpc-whitelist"
-#define TR_PREFS_KEY_QUEUE_STALLED_ENABLED "queue-stalled-enabled"
-#define TR_PREFS_KEY_QUEUE_STALLED_MINUTES "queue-stalled-minutes"
-#define TR_PREFS_KEY_DSPEED_KBps "speed-limit-down"
-#define TR_PREFS_KEY_DSPEED_ENABLED "speed-limit-down-enabled"
-#define TR_PREFS_KEY_USPEED_KBps "speed-limit-up"
-#define TR_PREFS_KEY_USPEED_ENABLED "speed-limit-up-enabled"
-#define TR_PREFS_KEY_UMASK "umask"
-#define TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT "upload-slots-per-torrent"
-#define TR_PREFS_KEY_START "start-added-torrents"
-#define TR_PREFS_KEY_TRASH_ORIGINAL "trash-original-torrent-files"
-
-
/**
* Add libtransmission's default settings to the benc dictionary.
*
tr_variantDictReserve (dict, 6);
- tr_variantDictAddInt (dict, "memory-bytes", mem_units.units[TR_FMT_KB].value);
- l = tr_variantDictAddList (dict, "memory-units", 4);
+ tr_variantDictAddInt (dict, TR_KEY_memory_bytes, mem_units.units[TR_FMT_KB].value);
+ l = tr_variantDictAddList (dict, TR_KEY_memory_units, 4);
for (i=0; i<4; i++)
tr_variantListAddStr (l, mem_units.units[i].name);
- tr_variantDictAddInt (dict, "size-bytes", size_units.units[TR_FMT_KB].value);
- l = tr_variantDictAddList (dict, "size-units", 4);
+ tr_variantDictAddInt (dict, TR_KEY_size_bytes, size_units.units[TR_FMT_KB].value);
+ l = tr_variantDictAddList (dict, TR_KEY_size_units, 4);
for (i=0; i<4; i++)
tr_variantListAddStr (l, size_units.units[i].name);
- tr_variantDictAddInt (dict, "speed-bytes", speed_units.units[TR_FMT_KB].value);
- l = tr_variantDictAddList (dict, "speed-units", 4);
+ tr_variantDictAddInt (dict, TR_KEY_speed_bytes, speed_units.units[TR_FMT_KB].value);
+ l = tr_variantDictAddList (dict, TR_KEY_speed_units, 4);
for (i=0; i<4; i++)
tr_variantListAddStr (l, speed_units.units[i].name);
}
return 0;
}
+static inline bool
+isReadyForDictKey (tr_ptrArray * parentStack)
+{
+ tr_variant * parent = tr_ptrArrayBack (parentStack);
+
+ return (parent != NULL)
+ && (tr_variantIsDict(parent))
+ && ((parent->val.l.count%2)==0);
+}
+
static tr_variant*
getNode (tr_variant * top,
tr_ptrArray * parentStack,
const uint8_t * str;
size_t str_len;
tr_variant * node;
+ const bool is_key = isReadyForDictKey (parentStack);
if ((err = tr_bencParseStr (buf, bufend, &end, &str, &str_len)))
return err;
if (!node)
return EILSEQ;
- tr_variantInitStr (node, str, str_len);
+ if (is_key)
+ tr_variantInitQuark (node, tr_quark_new (str, str_len));
+ else
+ tr_variantInitStr (node, str, str_len);
+
buf = end;
if (tr_ptrArrayEmpty (parentStack))
}
else if (tr_variantIsDict (parent) && (data->key!=NULL))
{
- node = tr_variantDictAdd (parent, data->key, data->keylen);
+ node = tr_variantDictAdd (parent, tr_quark_new (data->key, data->keylen));
data->key = NULL;
data->keylen = 0;
else if (state->special_flags & JSONSL_SPECIALf_NULL)
{
data->has_content = true;
- tr_variantInitStr (get_node (jsn), "", 0);
+ tr_variantInitQuark (get_node (jsn), TR_KEY_NONE);
}
}
}
tr_variant dest, src;
int64_t i;
const char * s;
+ const tr_quark i1 = tr_quark_new ("i1", 2);
+ const tr_quark i2 = tr_quark_new ("i2", 2);
+ const tr_quark i3 = tr_quark_new ("i3", 2);
+ const tr_quark i4 = tr_quark_new ("i4", 2);
+ const tr_quark s5 = tr_quark_new ("s5", 2);
+ const tr_quark s6 = tr_quark_new ("s6", 2);
+ const tr_quark s7 = tr_quark_new ("s7", 2);
+ const tr_quark s8 = tr_quark_new ("s8", 2);
/* initial dictionary (default values) */
tr_variantInitDict (&dest, 10);
- tr_variantDictAddInt (&dest, "i1", 1);
- tr_variantDictAddInt (&dest, "i2", 2);
- tr_variantDictAddInt (&dest, "i4", -35); /* remains untouched */
- tr_variantDictAddStr (&dest, "s5", "abc");
- tr_variantDictAddStr (&dest, "s6", "def");
- tr_variantDictAddStr (&dest, "s7", "127.0.0.1"); /* remains untouched */
+ tr_variantDictAddInt (&dest, i1, 1);
+ tr_variantDictAddInt (&dest, i2, 2);
+ tr_variantDictAddInt (&dest, i4, -35); /* remains untouched */
+ tr_variantDictAddStr (&dest, s5, "abc");
+ tr_variantDictAddStr (&dest, s6, "def");
+ tr_variantDictAddStr (&dest, s7, "127.0.0.1"); /* remains untouched */
/* new dictionary, will overwrite items in dest */
tr_variantInitDict (&src, 10);
- tr_variantDictAddInt (&src, "i1", 1); /* same value */
- tr_variantDictAddInt (&src, "i2", 4); /* new value */
- tr_variantDictAddInt (&src, "i3", 3); /* new key:value */
- tr_variantDictAddStr (&src, "s5", "abc"); /* same value */
- tr_variantDictAddStr (&src, "s6", "xyz"); /* new value */
- tr_variantDictAddStr (&src, "s8", "ghi"); /* new key:value */
+ tr_variantDictAddInt (&src, i1, 1); /* same value */
+ tr_variantDictAddInt (&src, i2, 4); /* new value */
+ tr_variantDictAddInt (&src, i3, 3); /* new key:value */
+ tr_variantDictAddStr (&src, s5, "abc"); /* same value */
+ tr_variantDictAddStr (&src, s6, "xyz"); /* new value */
+ tr_variantDictAddStr (&src, s8, "ghi"); /* new key:value */
tr_variantMergeDicts (&dest, /*const*/ &src);
- check (tr_variantDictFindInt (&dest, "i1", &i));
+ check (tr_variantDictFindInt (&dest, i1, &i));
check_int_eq (1, i);
- check (tr_variantDictFindInt (&dest, "i2", &i));
+ check (tr_variantDictFindInt (&dest, i2, &i));
check_int_eq (4, i);
- check (tr_variantDictFindInt (&dest, "i3", &i));
+ check (tr_variantDictFindInt (&dest, i3, &i));
check_int_eq (3, i);
- check (tr_variantDictFindInt (&dest, "i4", &i));
+ check (tr_variantDictFindInt (&dest, i4, &i));
check_int_eq (-35, i);
- check (tr_variantDictFindStr (&dest, "s5", &s, &len));
+ check (tr_variantDictFindStr (&dest, s5, &s, &len));
check_int_eq (3, len);
check_streq ("abc", s);
- check (tr_variantDictFindStr (&dest, "s6", &s, &len));
+ check (tr_variantDictFindStr (&dest, s6, &s, &len));
check_int_eq (3, len);
check_streq ("xyz", s);
- check (tr_variantDictFindStr (&dest, "s7", &s, &len));
+ check (tr_variantDictFindStr (&dest, s7, &s, &len));
check_int_eq (9, len);
check_streq ("127.0.0.1", s);
- check (tr_variantDictFindStr (&dest, "s8", &s, &len));
+ check (tr_variantDictFindStr (&dest, s8, &s, &len));
check_int_eq (3, len);
check_streq ("ghi", s);
tr_variant top;
int64_t intVal;
bool boolVal;
+ const tr_quark key1 = tr_quark_new ("key1", 4);
+ const tr_quark key2 = tr_quark_new ("key2", 4);
+ const tr_quark key3 = tr_quark_new ("key3", 4);
+ const tr_quark key4 = tr_quark_new ("key4", 4);
tr_variantInitDict (&top, 0);
- tr_variantDictAddBool (&top, "key1", false);
- tr_variantDictAddBool (&top, "key2", 0);
- tr_variantDictAddInt (&top, "key3", true);
- tr_variantDictAddInt (&top, "key4", 1);
- check (tr_variantDictFindBool (&top, "key1", &boolVal));
+ tr_variantDictAddBool (&top, key1, false);
+ tr_variantDictAddBool (&top, key2, 0);
+ tr_variantDictAddInt (&top, key3, true);
+ tr_variantDictAddInt (&top, key4, 1);
+ check (tr_variantDictFindBool (&top, key1, &boolVal));
check (!boolVal);
- check (tr_variantDictFindBool (&top, "key2", &boolVal));
+ check (tr_variantDictFindBool (&top, key2, &boolVal));
check (!boolVal);
- check (tr_variantDictFindBool (&top, "key3", &boolVal));
+ check (tr_variantDictFindBool (&top, key3, &boolVal));
check (boolVal);
- check (tr_variantDictFindBool (&top, "key4", &boolVal));
+ check (tr_variantDictFindBool (&top, key4, &boolVal));
check (boolVal);
- check (tr_variantDictFindInt (&top, "key1", &intVal));
+ check (tr_variantDictFindInt (&top, key1, &intVal));
check (!intVal);
- check (tr_variantDictFindInt (&top, "key2", &intVal));
+ check (tr_variantDictFindInt (&top, key2, &intVal));
check (!intVal);
- check (tr_variantDictFindInt (&top, "key3", &intVal));
+ check (tr_variantDictFindInt (&top, key3, &intVal));
check (intVal);
- check (tr_variantDictFindInt (&top, "key4", &intVal));
+ check (tr_variantDictFindInt (&top, key4, &intVal));
check (intVal);
tr_variantFree (&top);
char * benc;
const char * end;
size_t strLen;
+ const tr_quark key_bool = tr_quark_new ("this-is-a-bool", -1);
+ const tr_quark key_real = tr_quark_new ("this-is-a-real", -1);
+ const tr_quark key_int = tr_quark_new ("this-is-an-int", -1);
+ const tr_quark key_str = tr_quark_new ("this-is-a-string", -1);
tr_variantInitDict (&top, 0);
- tr_variantDictAddBool (&top, "this-is-a-bool", true);
- tr_variantDictAddInt (&top, "this-is-an-int", 1234);
- tr_variantDictAddReal (&top, "this-is-a-real", 0.5);
- tr_variantDictAddStr (&top, "this-is-a-string", "this-is-a-string");
+ tr_variantDictAddBool (&top, key_bool, true);
+ tr_variantDictAddInt (&top, key_int, 1234);
+ tr_variantDictAddReal (&top, key_real, 0.5);
+ tr_variantDictAddStr (&top, key_str, "this-is-a-string");
benc = tr_variantToStr (&top, TR_VARIANT_FMT_BENC, &len);
check_streq ("d14:this-is-a-booli1e14:this-is-a-real8:0.50000016:this-is-a-string16:this-is-a-string14:this-is-an-inti1234ee", benc);
check (!tr_variantFromBencFull (&top2, benc, len, NULL, &end));
check (end == benc + len);
check (tr_variantIsDict (&top2));
- check (tr_variantDictFindInt (&top, "this-is-an-int", &intVal));
+ check (tr_variantDictFindInt (&top, key_int, &intVal));
check_int_eq (1234, intVal);
- check (tr_variantDictFindBool (&top, "this-is-a-bool", &boolVal));
+ check (tr_variantDictFindBool (&top, key_bool, &boolVal));
check (boolVal == true);
- check (tr_variantDictFindStr (&top, "this-is-a-string", &strVal, &strLen));
+ check (tr_variantDictFindStr (&top, key_str, &strVal, &strLen));
check_int_eq (16, strLen);
check_streq ("this-is-a-string", strVal);
- check (tr_variantDictFindReal (&top, "this-is-a-real", &realVal));
+ check (tr_variantDictFindReal (&top, key_real, &realVal));
check_int_eq (50, (int)(realVal*100));
tr_variantFree (&top2);
testBool,
testParse2,
testStackSmash };
-
return runTests (tests, NUM_TESTS (tests));
}
****
***/
-/* returns true if the variant's string was malloced.
- * this occurs when the string is too long for our string buffer */
-static inline int
-stringIsAlloced (const tr_variant * variant)
+/*
+zzz
+
+typedef enum
+{
+ TR_STRING_TYPE_KEY,
+ TR_STRING_TYPE_HEAP,
+ TR_STRING_TYPE_BUF
+}
+tr_string_type;
+
+struct tr_variant_string
+{
+ tr_key key;
+ tr_string_type type;
+ size_t len;
+ union { char buf[8]; char * ptr; } str;
+};
+*/
+
+static const struct tr_variant_string STRING_INIT =
+{
+ .type = TR_STRING_TYPE_QUARK,
+ .quark = TR_KEY_NONE,
+ .len = 0,
+ .str.str = ""
+};
+
+static void
+tr_variant_string_clear (struct tr_variant_string * str)
{
- return variant->val.s.len >= sizeof (variant->val.s.str.buf);
+ if (str->type == TR_STRING_TYPE_HEAP)
+ tr_free ((char*)(str->str.str));
+
+ *str = STRING_INIT;
}
/* returns a const pointer to the variant's string */
-static inline const char*
-getStr (const tr_variant* variant)
+static const char *
+tr_variant_string_get_string (const struct tr_variant_string * str)
{
- return stringIsAlloced (variant) ? variant->val.s.str.ptr
- : variant->val.s.str.buf;
+ const char * ret;
+
+ switch (str->type)
+ {
+ case TR_STRING_TYPE_BUF: ret = str->str.buf; break;
+ case TR_STRING_TYPE_HEAP: ret = str->str.str; break;
+ case TR_STRING_TYPE_QUARK: ret = str->str.str; break;
+ default: ret = NULL;
+ }
+
+ return ret;
+}
+
+static void
+tr_variant_string_set_quark (struct tr_variant_string * str, const tr_quark quark)
+{
+ tr_variant_string_clear (str);
+
+ str->type = TR_STRING_TYPE_QUARK;
+ str->quark = quark;
+ str->str.str = tr_quark_get_string (quark, &str->len);
+}
+
+static void
+tr_variant_string_set_string (struct tr_variant_string * str, const char * bytes, int len)
+{
+ tr_quark quark;
+ tr_variant_string_clear (str);
+
+ if (bytes == NULL)
+ len = 0;
+ else if (len < 0)
+ len = strlen (bytes);
+
+ if (tr_quark_lookup (bytes, len, &quark))
+ {
+ str->type = TR_STRING_TYPE_QUARK;
+ str->quark = quark;
+ str->str.str = tr_quark_get_string (quark, &str->len);
+ }
+ else if ((size_t)len < sizeof(str->str.buf))
+ {
+ str->type = TR_STRING_TYPE_BUF;
+ memcpy (str->str.buf, bytes, len);
+ str->str.buf[len] = '\0';
+ str->len = len;
+ }
+ else
+ {
+ char * tmp = tr_new (char, len+1);
+ memcpy (tmp, bytes, len);
+ tmp[len] = '\0';
+ str->type = TR_STRING_TYPE_HEAP;
+ str->str.str = tmp;
+ str->len = len;
+ }
+}
+
+
+/***
+****
+***/
+
+static inline const char *
+getStr (const tr_variant * v)
+{
+ assert (tr_variantIsString (v));
+
+ return tr_variant_string_get_string (&v->val.s);
}
static int
-dictIndexOf (const tr_variant * dict, const char * key)
+dictIndexOf (const tr_variant * dict, const tr_quark key)
{
if (tr_variantIsDict (dict))
{
const tr_variant * walk;
const tr_variant * const begin = dict->val.l.vals;
const tr_variant * const end = begin + dict->val.l.count;
- const size_t len = strlen (key);
for (walk=begin; walk!=end; walk+=2)
{
assert (walk->type == TR_VARIANT_TYPE_STR);
+ assert (walk->val.s.type == TR_STRING_TYPE_QUARK);
- if ((walk->val.s.len==len) && !memcmp (getStr(walk), key, len))
+ if (walk->val.s.quark == key)
return walk - begin;
}
}
}
tr_variant *
-tr_variantDictFind (tr_variant * dict,
- const char * key)
+tr_variantDictFind (tr_variant * dict, const tr_quark key)
{
const int i = dictIndexOf (dict, key);
}
static bool
-tr_variantDictFindType (tr_variant * dict,
- const char * key,
- int type,
- tr_variant ** setme)
+tr_variantDictFindType (tr_variant * dict,
+ const tr_quark key,
+ int type,
+ tr_variant ** setme)
{
return tr_variantIsType (*setme = tr_variantDictFind (dict, key), type);
}
}
bool
-tr_variantDictFindInt (tr_variant * dict,
- const char * key,
- int64_t * setme)
+tr_variantDictFindInt (tr_variant * dict,
+ const tr_quark key,
+ int64_t * setme)
{
tr_variant * child = tr_variantDictFind (dict, key);
return tr_variantGetInt (child, setme);
}
bool
-tr_variantDictFindBool (tr_variant * dict,
- const char * key,
- bool * setme)
+tr_variantDictFindBool (tr_variant * dict,
+ const tr_quark key,
+ bool * setme)
{
tr_variant * child = tr_variantDictFind (dict, key);
return tr_variantGetBool (child, setme);
}
bool
-tr_variantDictFindReal (tr_variant * dict,
- const char * key,
- double * setme)
+tr_variantDictFindReal (tr_variant * dict,
+ const tr_quark key,
+ double * setme)
{
tr_variant * child = tr_variantDictFind (dict, key);
return tr_variantGetReal (child, setme);
}
bool
-tr_variantDictFindStr (tr_variant * dict,
- const char * key,
- const char ** setme,
- size_t * len)
+tr_variantDictFindStr (tr_variant * dict,
+ const tr_quark key,
+ const char ** setme,
+ size_t * len)
{
tr_variant * child = tr_variantDictFind (dict, key);
return tr_variantGetStr (child, setme, len);
}
bool
-tr_variantDictFindList (tr_variant * dict,
- const char * key,
- tr_variant ** setme)
+tr_variantDictFindList (tr_variant * dict,
+ const tr_quark key,
+ tr_variant ** setme)
{
return tr_variantDictFindType (dict,
key,
}
bool
-tr_variantDictFindDict (tr_variant * dict,
- const char * key,
- tr_variant ** setme)
+tr_variantDictFindDict (tr_variant * dict,
+ const tr_quark key,
+ tr_variant ** setme)
{
return tr_variantDictFindType (dict,
key,
bool
tr_variantDictFindRaw (tr_variant * dict,
- const char * key,
+ const tr_quark key,
const uint8_t ** setme_raw,
size_t * setme_len)
{
***/
void
-tr_variantInitRaw (tr_variant * variant, const void * src, size_t byteCount)
+tr_variantInitRaw (tr_variant * v, const void * src, size_t byteCount)
{
- char * setme;
- tr_variantInit (variant, TR_VARIANT_TYPE_STR);
-
- /* There's no way in benc notation to distinguish between
- * zero-terminated strings and raw byte arrays.
- * Because of this, tr_variantMergeDicts () and tr_variantListCopy ()
- * don't know whether or not a TR_VARIANT_TYPE_STR node needs a '\0'.
- * Append one, een to the raw arrays, just to be safe. */
-
- if (byteCount < sizeof (variant->val.s.str.buf))
- setme = variant->val.s.str.buf;
- else
- setme = variant->val.s.str.ptr = tr_new (char, byteCount + 1);
-
- memcpy (setme, src, byteCount);
- setme[byteCount] = '\0';
- variant->val.s.len = byteCount;
+ tr_variantInit (v, TR_VARIANT_TYPE_STR);
+ tr_variant_string_set_string (&v->val.s, src, byteCount);
}
void
-tr_variantInitStr (tr_variant * variant, const void * str, int len)
+tr_variantInitQuark (tr_variant * v, const tr_quark q)
{
- if (str == NULL)
- len = 0;
- else if (len < 0)
- len = strlen (str);
+ tr_variantInit (v, TR_VARIANT_TYPE_STR);
+ tr_variant_string_set_quark (&v->val.s, q);
+}
- tr_variantInitRaw (variant, str, len);
+void
+tr_variantInitStr (tr_variant * v, const void * str, int len)
+{
+ tr_variantInit (v, TR_VARIANT_TYPE_STR);
+ tr_variant_string_set_string (&v->val.s, str, len);
}
void
while (n < needed)
n *= 2u;
- tmp = realloc (container->val.l.vals, n * sizeof (tr_variant));
+ tmp = tr_renew (tr_variant, container->val.l.vals, n);
if (tmp == NULL)
return 1;
return child;
}
+tr_variant *
+tr_variantListAddQuark (tr_variant * list,
+ const tr_quark val)
+{
+ tr_variant * child = tr_variantListAdd (list);
+ tr_variantInitQuark (child, val);
+ return child;
+}
+
tr_variant *
tr_variantListAddRaw (tr_variant * list,
const void * val,
}
tr_variant *
-tr_variantDictAdd (tr_variant * dict,
- const char * key,
- int keylen)
+tr_variantDictAdd (tr_variant * dict,
+ const tr_quark key)
{
tr_variant * child_key;
tr_variant * child_val;
containerReserve (dict, 2);
child_key = dict->val.l.vals + dict->val.l.count++;
- tr_variantInitStr (child_key, key, keylen);
+ tr_variantInitQuark (child_key, key);
child_val = dict->val.l.vals + dict->val.l.count++;
tr_variantInit (child_val, TR_VARIANT_TYPE_INT);
}
static tr_variant*
-dictFindOrAdd (tr_variant * dict, const char * key, int type)
+dictFindOrAdd (tr_variant * dict, const tr_quark key, int type)
{
tr_variant * child;
tr_variantDictRemove (dict, key);
child = NULL;
}
+ else if (child->type == TR_VARIANT_TYPE_STR)
+ {
+ tr_variant_string_clear (&child->val.s);
+ }
}
/* if it doesn't exist, create it */
if (child == NULL)
- child = tr_variantDictAdd (dict, key, -1);
+ child = tr_variantDictAdd (dict, key);
return child;
}
tr_variant*
-tr_variantDictAddInt (tr_variant * dict,
- const char * key,
- int64_t val)
+tr_variantDictAddInt (tr_variant * dict,
+ const tr_quark key,
+ int64_t val)
{
tr_variant * child = dictFindOrAdd (dict, key, TR_VARIANT_TYPE_INT);
tr_variantInitInt (child, val);
}
tr_variant*
-tr_variantDictAddBool (tr_variant * dict, const char * key, bool val)
+tr_variantDictAddBool (tr_variant * dict, const tr_quark key, bool val)
{
tr_variant * child = dictFindOrAdd (dict, key, TR_VARIANT_TYPE_BOOL);
tr_variantInitBool (child, val);
}
tr_variant*
-tr_variantDictAddReal (tr_variant * dict, const char * key, double val)
+tr_variantDictAddReal (tr_variant * dict, const tr_quark key, double val)
{
tr_variant * child = dictFindOrAdd (dict, key, TR_VARIANT_TYPE_REAL);
tr_variantInitReal (child, val);
return child;
}
-static tr_variant *
-dictRecycleOrAdd (tr_variant * dict, const char * key)
+tr_variant*
+tr_variantDictAddQuark (tr_variant * dict, const tr_quark key, const tr_quark val)
{
- tr_variant * child;
-
- /* see if it already exists, and if so, try to reuse it */
- if ((child = tr_variantDictFind (dict, key)))
- {
- if (tr_variantIsString (child))
- {
- if (stringIsAlloced (child))
- tr_free (child->val.s.str.ptr);
- }
- else
- {
- tr_variantDictRemove (dict, key);
- child = NULL;
- }
- }
-
- /* if it doesn't exist, create it */
- if (child == NULL)
- child = tr_variantDictAdd (dict, key, -1);
-
+ tr_variant * child = dictFindOrAdd (dict, key, TR_VARIANT_TYPE_STR);
+ tr_variantInitQuark (child, val);
return child;
}
-
tr_variant*
-tr_variantDictAddStr (tr_variant * dict, const char * key, const char * val)
+tr_variantDictAddStr (tr_variant * dict, const tr_quark key, const char * val)
{
- tr_variant * child = dictRecycleOrAdd (dict, key);
+ tr_variant * child = dictFindOrAdd (dict, key, TR_VARIANT_TYPE_STR);
tr_variantInitStr (child, val, -1);
return child;
}
tr_variant*
-tr_variantDictAddRaw (tr_variant * dict,
- const char * key,
- const void * src,
- size_t len)
+tr_variantDictAddRaw (tr_variant * dict,
+ const tr_quark key,
+ const void * src,
+ size_t len)
{
- tr_variant * child = dictRecycleOrAdd (dict, key);
+ tr_variant * child = dictFindOrAdd (dict, key, TR_VARIANT_TYPE_STR);
tr_variantInitRaw (child, src, len);
return child;
}
tr_variant*
-tr_variantDictAddList (tr_variant * dict,
- const char * key,
- size_t reserve_count)
+tr_variantDictAddList (tr_variant * dict,
+ const tr_quark key,
+ size_t reserve_count)
{
- tr_variant * child = tr_variantDictAdd (dict, key, -1);
+ tr_variant * child = tr_variantDictAdd (dict, key);
tr_variantInitList (child, reserve_count);
return child;
}
tr_variant*
-tr_variantDictAddDict (tr_variant * dict,
- const char * key,
- size_t reserve_count)
+tr_variantDictAddDict (tr_variant * dict,
+ const tr_quark key,
+ size_t reserve_count)
{
- tr_variant * child = tr_variantDictAdd (dict, key, -1);
+ tr_variant * child = tr_variantDictAdd (dict, key);
tr_variantInitDict (child, reserve_count);
return child;
}
int
-tr_variantDictRemove (tr_variant * dict,
- const char * key)
+tr_variantDictRemove (tr_variant * dict,
+ const tr_quark key)
{
const int i = dictIndexOf (dict, key);
****/
static void
-freeDummyFunc (const tr_variant * val UNUSED, void * buf UNUSED)
+freeDummyFunc (const tr_variant * v UNUSED, void * buf UNUSED)
{}
static void
-freeStringFunc (const tr_variant * val, void * unused UNUSED)
+freeStringFunc (const tr_variant * v, void * unused UNUSED)
{
- if (stringIsAlloced (val))
- tr_free (val->val.s.str.ptr);
+ tr_variant_string_clear (&((tr_variant*)v)->val.s);
}
static void
-freeContainerEndFunc (const tr_variant * val, void * unused UNUSED)
+freeContainerEndFunc (const tr_variant * v, void * unused UNUSED)
{
- tr_free (val->val.l.vals);
+ tr_free (v->val.l.vals);
}
static const struct VariantWalkFuncs freeWalkFuncs = { freeDummyFunc,
bool
tr_variantDictChild (tr_variant * dict,
size_t n,
- const char ** key,
+ tr_quark * key,
tr_variant ** val)
{
bool success = 0;
{
tr_variant * k = dict->val.l.vals + (n*2);
tr_variant * v = dict->val.l.vals + (n*2) + 1;
- if ((success = tr_variantGetStr (k, key, NULL) && tr_variantIsSomething (v)))
- *val = v;
+ if ((k->val.s.type == TR_STRING_TYPE_QUARK) && tr_variantIsSomething (v))
+ {
+ *key = k->val.s.quark;
+ *val = v;
+ success = true;
+ }
}
return success;
for (i=0; i<sourceCount; ++i)
{
- const char * key;
+ tr_quark key;
tr_variant * val;
tr_variant * t;
}
else
{
- tr_dbg ("tr_variantMergeDicts skipping \"%s\"", key);
+ tr_dbg ("tr_variantMergeDicts skipping \"%s\"", tr_quark_get_string(key,NULL));
}
}
}
#endif
#include <inttypes.h> /* for int64_t */
+#include <libtransmission/quark.h>
struct evbuffer;
* @{
*/
+typedef enum
+{
+ TR_STRING_TYPE_QUARK,
+ TR_STRING_TYPE_HEAP,
+ TR_STRING_TYPE_BUF
+}
+tr_string_type;
+
+/* these are PRIVATE IMPLEMENTATION details that should not be touched.
+ * I'll probably change them just to break your code! HA HA HA!
+ * it's included in the header for inlining and composition */
+struct tr_variant_string
+{
+ tr_string_type type;
+ tr_quark quark;
+ size_t len;
+ union { char buf[16]; const char * str; } str;
+};
+
+
/* these are PRIVATE IMPLEMENTATION details that should not be touched.
* I'll probably change them just to break your code! HA HA HA!
* it's included in the header for inlining and composition */
int64_t i;
- struct
- {
- size_t len; /* the string length */
- union
- {
- char buf[16]; /* local buffer for short strings */
- char * ptr; /* alloc'ed pointer for long strings */
- }
- str;
- }
- s;
+ struct tr_variant_string s;
struct
{
static inline bool
tr_variantIsString (const tr_variant * b)
{
- return tr_variantIsType (b, TR_VARIANT_TYPE_STR);
+ return (b != NULL) && (b->type == TR_VARIANT_TYPE_STR);
}
bool tr_variantGetStr (const tr_variant * variant,
const void * str,
int str_len);
+void tr_variantInitQuark (tr_variant * initme,
+ const tr_quark quark);
+
void tr_variantInitRaw (tr_variant * initme,
const void * raw,
size_t raw_len);
***/
static inline bool
-tr_variantIsReal (const tr_variant * b)
+tr_variantIsReal (const tr_variant * v)
{
- return tr_variantIsType (b, TR_VARIANT_TYPE_REAL);
+ return (v != NULL) && (v->type == TR_VARIANT_TYPE_REAL);
}
void tr_variantInitReal (tr_variant * initme,
***/
static inline bool
-tr_variantIsBool (const tr_variant * b)
+tr_variantIsBool (const tr_variant * v)
{
- return tr_variantIsType (b, TR_VARIANT_TYPE_BOOL);
+ return (v != NULL) && (v->type == TR_VARIANT_TYPE_BOOL);
}
void tr_variantInitBool (tr_variant * initme,
***/
static inline bool
-tr_variantIsInt (const tr_variant * b)
+tr_variantIsInt (const tr_variant * v)
{
- return tr_variantIsType (b, TR_VARIANT_TYPE_INT);
+ return (v != NULL) && (v->type == TR_VARIANT_TYPE_INT);
}
void tr_variantInitInt (tr_variant * variant,
***/
static inline bool
-tr_variantIsList (const tr_variant * b)
+tr_variantIsList (const tr_variant * v)
{
- return tr_variantIsType (b, TR_VARIANT_TYPE_LIST);
+ return (v != NULL) && (v->type == TR_VARIANT_TYPE_LIST);
}
int tr_variantInitList (tr_variant * list,
tr_variant * tr_variantListAddStr (tr_variant * list,
const char * addme);
+tr_variant * tr_variantListAddQuark (tr_variant * list,
+ const tr_quark addme);
+
tr_variant * tr_variantListAddRaw (tr_variant * list,
const void * addme_value,
size_t addme_len);
***/
static inline bool
-tr_variantIsDict (const tr_variant * b)
+tr_variantIsDict (const tr_variant * v)
{
- return tr_variantIsType (b, TR_VARIANT_TYPE_DICT);
+ return (v != NULL) && (v->type == TR_VARIANT_TYPE_DICT);
}
int tr_variantInitDict (tr_variant * initme,
size_t reserve_count);
int tr_variantDictRemove (tr_variant * dict,
- const char * key);
+ const tr_quark key);
tr_variant * tr_variantDictAdd (tr_variant * dict,
- const char * key,
- int keylen);
+ const tr_quark key);
tr_variant * tr_variantDictAddReal (tr_variant * dict,
- const char * key,
+ const tr_quark key,
double value);
tr_variant * tr_variantDictAddInt (tr_variant * dict,
- const char * key,
+ const tr_quark key,
int64_t value);
tr_variant * tr_variantDictAddBool (tr_variant * dict,
- const char * key,
+ const tr_quark key,
bool value);
tr_variant * tr_variantDictAddStr (tr_variant * dict,
- const char * key,
+ const tr_quark key,
const char * value);
+tr_variant * tr_variantDictAddQuark (tr_variant * dict,
+ const tr_quark key,
+ const tr_quark val);
+
tr_variant * tr_variantDictAddList (tr_variant * dict,
- const char * key,
+ const tr_quark key,
size_t reserve_count);
tr_variant * tr_variantDictAddDict (tr_variant * dict,
- const char * key,
+ const tr_quark key,
size_t reserve_count);
tr_variant * tr_variantDictAddRaw (tr_variant * dict,
- const char * key,
+ const tr_quark key,
const void * value,
size_t len);
bool tr_variantDictChild (tr_variant * dict,
size_t pos,
- const char ** setme_key,
+ tr_quark * setme_key,
tr_variant ** setme_value);
tr_variant * tr_variantDictFind (tr_variant * dict,
- const char * key);
+ const tr_quark key);
bool tr_variantDictFindList (tr_variant * dict,
- const char * key,
+ const tr_quark key,
tr_variant ** setme);
bool tr_variantDictFindDict (tr_variant * dict,
- const char * key,
+ const tr_quark key,
tr_variant ** setme_value);
bool tr_variantDictFindInt (tr_variant * dict,
- const char * key,
+ const tr_quark key,
int64_t * setme);
bool tr_variantDictFindReal (tr_variant * dict,
- const char * key,
+ const tr_quark key,
double * setme);
bool tr_variantDictFindBool (tr_variant * dict,
- const char * key,
+ const tr_quark key,
bool * setme);
bool tr_variantDictFindStr (tr_variant * dict,
- const char * key,
+ const tr_quark key,
const char ** setme,
size_t * len);
bool tr_variantDictFindRaw (tr_variant * dict,
- const char * key,
+ const tr_quark key,
const uint8_t ** setme_raw,
size_t * setme_len);
tr_peerConstruct (peer);
peer->peerIsChoked = true;
peer->clientIsInterested = !tr_torrentIsSeed (tor);
- peer->client = tr_strdup ("webseed");
+ peer->client = TR_KEY_webseeds;
tr_bitfieldSetHasAll (&peer->have);
tr_peerUpdateProgress (tor, peer);
***/
void
-Details :: onShowTrackerScrapesToggled( bool val )
+Details :: onShowTrackerScrapesToggled (bool val)
{
- myPrefs.set( Prefs::SHOW_TRACKER_SCRAPES, val );
+ myPrefs.set (Prefs::SHOW_TRACKER_SCRAPES, val);
}
void
-Details :: onShowBackupTrackersToggled( bool val )
+Details :: onShowBackupTrackersToggled (bool val)
{
- myPrefs.set( Prefs::SHOW_BACKUP_TRACKERS, val );
+ myPrefs.set (Prefs::SHOW_BACKUP_TRACKERS, val);
}
void
-Details :: onHonorsSessionLimitsToggled( bool val )
+Details :: onHonorsSessionLimitsToggled (bool val)
{
- mySession.torrentSet( myIds, "honorsSessionLimits", val );
- getNewData( );
+ mySession.torrentSet (myIds, TR_KEY_honorsSessionLimits, val);
+ getNewData ();
}
void
-Details :: onDownloadLimitedToggled( bool val )
+Details :: onDownloadLimitedToggled (bool val)
{
- mySession.torrentSet( myIds, "downloadLimited", val );
- getNewData( );
+ mySession.torrentSet (myIds, TR_KEY_downloadLimited, val);
+ getNewData ();
}
void
-Details :: onSpinBoxEditingFinished( )
+Details :: onSpinBoxEditingFinished ()
{
- const QObject * spin = sender();
- const QString key = spin->property( PREF_KEY ).toString( );
- const QDoubleSpinBox * d = qobject_cast<const QDoubleSpinBox*>( spin );
- if( d )
- mySession.torrentSet( myIds, key, d->value( ) );
- else
- mySession.torrentSet( myIds, key, qobject_cast<const QSpinBox*>(spin)->value( ) );
- getNewData( );
+ const QObject * spin = sender();
+ const tr_quark key = spin->property(PREF_KEY).toInt();
+ const QDoubleSpinBox * d = qobject_cast<const QDoubleSpinBox*>( spin );
+ if (d)
+ mySession.torrentSet( myIds, key, d->value( ) );
+ else
+ mySession.torrentSet( myIds, key, qobject_cast<const QSpinBox*>(spin)->value( ) );
+ getNewData( );
}
void
-Details :: onUploadLimitedToggled( bool val )
+Details :: onUploadLimitedToggled (bool val)
{
- mySession.torrentSet( myIds, "uploadLimited", val );
- getNewData( );
+ mySession.torrentSet (myIds, TR_KEY_uploadLimited, val);
+ getNewData ();
}
void
-Details :: onIdleModeChanged( int index )
+Details :: onIdleModeChanged (int index)
{
- const int val = myIdleCombo->itemData( index ).toInt( );
- mySession.torrentSet( myIds, "seedIdleMode", val );
- getNewData( );
+ const int val = myIdleCombo->itemData(index).toInt();
+ mySession.torrentSet (myIds, TR_KEY_seedIdleMode, val);
+ getNewData ();
}
void
-Details :: onRatioModeChanged( int index )
+Details :: onRatioModeChanged (int index)
{
- const int val = myRatioCombo->itemData( index ).toInt( );
- mySession.torrentSet( myIds, "seedRatioMode", val );
+ const int val = myRatioCombo->itemData(index).toInt();
+ mySession.torrentSet (myIds, TR_KEY_seedRatioMode, val);
}
void
-Details :: onBandwidthPriorityChanged( int index )
+Details :: onBandwidthPriorityChanged (int index)
{
- if( index != -1 )
+ if( index != -1 )
{
- const int priority = myBandwidthPriorityCombo->itemData(index).toInt( );
- mySession.torrentSet( myIds, "bandwidthPriority", priority );
- getNewData( );
+ const int priority = myBandwidthPriorityCombo->itemData(index).toInt();
+ mySession.torrentSet( myIds, TR_KEY_bandwidthPriority, priority );
+ getNewData( );
}
}
void
-Details :: onTrackerSelectionChanged( )
+Details :: onTrackerSelectionChanged ()
{
- const int selectionCount = myTrackerView->selectionModel()->selectedRows().size();
- myEditTrackerButton->setEnabled( selectionCount == 1 );
- myRemoveTrackerButton->setEnabled( selectionCount > 0 );
+ const int selectionCount = myTrackerView->selectionModel()->selectedRows().size();
+ myEditTrackerButton->setEnabled (selectionCount == 1);
+ myRemoveTrackerButton->setEnabled (selectionCount > 0);
}
void
-Details :: onAddTrackerClicked( )
+Details :: onAddTrackerClicked ()
{
- bool ok = false;
- const QString url = QInputDialog::getText( this,
- tr( "Add URL " ),
- tr( "Add tracker announce URL:" ),
- QLineEdit::Normal, QString(), &ok );
- if( !ok )
+ bool ok = false;
+ const QString url = QInputDialog::getText (this,
+ tr("Add URL "),
+ tr("Add tracker announce URL:"),
+ QLineEdit::Normal, QString(), &ok);
+ if(!ok)
{
- // user pressed "cancel" -- noop
+ // user pressed "cancel" -- noop
}
- else if( !QUrl(url).isValid( ) )
+ else if (!QUrl(url).isValid())
{
- QMessageBox::warning( this, tr( "Error" ), tr( "Invalid URL \"%1\"" ).arg( url ) );
+ QMessageBox::warning( this, tr("Error"), tr("Invalid URL \"%1\"").arg(url));
}
- else
+ else
{
- QSet<int> ids;
+ QSet<int> ids;
- foreach( int id, myIds )
- if( myTrackerModel->find( id, url ) == -1 )
- ids.insert( id );
+ foreach (int id, myIds)
+ if (myTrackerModel->find(id,url) == -1)
+ ids.insert (id);
- if( ids.empty( ) ) // all the torrents already have this tracker
+ if (ids.empty()) // all the torrents already have this tracker
{
- QMessageBox::warning( this, tr( "Error" ), tr( "Tracker already exists." ) );
+ QMessageBox::warning (this, tr("Error"), tr("Tracker already exists."));
}
else
{
- QStringList urls;
- urls << url;
- mySession.torrentSet( ids, "trackerAdd", urls );
- getNewData( );
+ QStringList urls;
+ urls << url;
+ mySession.torrentSet (ids, TR_KEY_trackerAdd, urls);
+ getNewData ();
}
}
}
void
-Details :: onEditTrackerClicked( )
+Details :: onEditTrackerClicked ()
{
- QItemSelectionModel * selectionModel = myTrackerView->selectionModel( );
- QModelIndexList selectedRows = selectionModel->selectedRows( );
- assert( selectedRows.size( ) == 1 );
- QModelIndex i = selectionModel->currentIndex( );
- const TrackerInfo trackerInfo = myTrackerView->model()->data( i, TrackerModel::TrackerRole ).value<TrackerInfo>();
-
- bool ok = false;
- const QString newval = QInputDialog::getText( this,
- tr( "Edit URL " ),
- tr( "Edit tracker announce URL:" ),
- QLineEdit::Normal,
- trackerInfo.st.announce, &ok );
-
- if( !ok )
+ QItemSelectionModel * selectionModel = myTrackerView->selectionModel();
+ QModelIndexList selectedRows = selectionModel->selectedRows();
+ assert (selectedRows.size() == 1);
+ QModelIndex i = selectionModel->currentIndex();
+ const TrackerInfo trackerInfo = myTrackerView->model()->data(i, TrackerModel::TrackerRole).value<TrackerInfo>();
+
+ bool ok = false;
+ const QString newval = QInputDialog::getText (this,
+ tr("Edit URL "),
+ tr("Edit tracker announce URL:"),
+ QLineEdit::Normal,
+ trackerInfo.st.announce, &ok);
+
+ if (!ok)
{
- // user pressed "cancel" -- noop
+ // user pressed "cancel" -- noop
}
- else if( !QUrl(newval).isValid( ) )
+ else if( !QUrl(newval).isValid( ) )
{
- QMessageBox::warning( this, tr( "Error" ), tr( "Invalid URL \"%1\"" ).arg( newval ) );
+ QMessageBox::warning (this, tr("Error"), tr("Invalid URL \"%1\"").arg(newval));
}
else
{
- QSet<int> ids;
- ids << trackerInfo.torrentId;
+ QSet<int> ids;
+ ids << trackerInfo.torrentId;
- const QPair<int,QString> idUrl = qMakePair( trackerInfo.st.id, newval );
+ const QPair<int,QString> idUrl = qMakePair (trackerInfo.st.id, newval);
- mySession.torrentSet( ids, "trackerReplace", idUrl );
- getNewData( );
+ mySession.torrentSet (ids, TR_KEY_trackerReplace, idUrl);
+ getNewData ();
}
}
{
QSet<int> ids;
ids << id;
- mySession.torrentSet( ids, "trackerRemove", torrentId_to_trackerIds.values( id ) );
+ mySession.torrentSet( ids, TR_KEY_trackerRemove, torrentId_to_trackerIds.values( id ) );
}
selectionModel->clearSelection( );
c = new QCheckBox( tr( "Limit &download speed (%1):" ).arg( speed_K_str ) );
mySingleDownCheck = c;
s = new QSpinBox( );
- s->setProperty( PREF_KEY, QString( "downloadLimit" ) );
+ s->setProperty (PREF_KEY, TR_KEY_downloadLimit);
s->setSingleStep( 5 );
s->setRange( 0, INT_MAX );
mySingleDownSpin = s;
}
void
-Details :: onFilePriorityChanged( const QSet<int>& indices, int priority )
+Details :: onFilePriorityChanged (const QSet<int>& indices, int priority)
{
- QString key;
- switch( priority ) {
- case TR_PRI_LOW: key = "priority-low"; break;
- case TR_PRI_HIGH: key = "priority-high"; break;
- default: key = "priority-normal"; break;
+ tr_quark key;
+
+ switch (priority)
+ {
+ case TR_PRI_LOW:
+ key = TR_KEY_priority_low;
+ break;
+
+ case TR_PRI_HIGH:
+ key = TR_KEY_priority_high;
+ break;
+
+ default:
+ key = TR_KEY_priority_normal;
+ break;
}
- mySession.torrentSet( myIds, key, indices.toList( ) );
+
+ mySession.torrentSet (myIds, key, indices.toList());
getNewData( );
}
void
-Details :: onFileWantedChanged( const QSet<int>& indices, bool wanted )
+Details :: onFileWantedChanged (const QSet<int>& indices, bool wanted)
{
- QString key( wanted ? "files-wanted" : "files-unwanted" );
- mySession.torrentSet( myIds, key, indices.toList( ) );
- getNewData( );
+ const tr_quark key = wanted ? TR_KEY_files_wanted : TR_KEY_files_unwanted;
+ mySession.torrentSet (myIds, key, indices.toList());
+ getNewData ();
}
const int64_t tag = mySession.getUniqueTag( );
tr_variant top;
- tr_variantInitDict( &top, 3 );
- tr_variantDictAddStr( &top, "method", "torrent-add" );
- tr_variantDictAddInt( &top, "tag", tag );
- tr_variant * args( tr_variantDictAddDict( &top, "arguments", 10 ) );
+ tr_variantInitDict (&top, 3);
+ tr_variantDictAddStr (&top, TR_KEY_method, "torrent-add" );
+ tr_variantDictAddInt (&top, TR_KEY_tag, tag );
+ tr_variant * args (tr_variantDictAddDict(&top, TR_KEY_arguments, 10));
QString downloadDir;
// "download-dir"
- if( myDestinationButton )
+ if (myDestinationButton)
downloadDir = myDestination.absolutePath();
else
downloadDir = myDestinationEdit->text();
- tr_variantDictAddStr( args, "download-dir", downloadDir.toUtf8().constData() );
+ tr_variantDictAddStr (args, TR_KEY_download_dir, downloadDir.toUtf8().constData() );
// "metainfo"
switch( myAdd.type )
{
case AddData::MAGNET:
- tr_variantDictAddStr( args, "filename", myAdd.magnet.toUtf8().constData() );
+ tr_variantDictAddStr (args, TR_KEY_filename, myAdd.magnet.toUtf8().constData());
break;
case AddData::URL:
- tr_variantDictAddStr( args, "filename", myAdd.url.toString().toUtf8().constData() );
+ tr_variantDictAddStr (args, TR_KEY_filename, myAdd.url.toString().toUtf8().constData());
break;
case AddData::FILENAME:
case AddData::METAINFO: {
const QByteArray b64 = myAdd.toBase64( );
- tr_variantDictAddRaw( args, "metainfo", b64.constData(), b64.size() );
+ tr_variantDictAddRaw( args, TR_KEY_metainfo, b64.constData(), b64.size() );
break;
}
}
// paused
- tr_variantDictAddBool( args, "paused", !myStartCheck->isChecked( ) );
+ tr_variantDictAddBool( args, TR_KEY_paused, !myStartCheck->isChecked( ) );
// priority
const int index = myPriorityCombo->currentIndex( );
const int priority = myPriorityCombo->itemData(index).toInt( );
- tr_variantDictAddInt( args, "bandwidthPriority", priority );
+ tr_variantDictAddInt( args, TR_KEY_bandwidthPriority, priority );
// files-unwanted
int count = myWanted.count( false );
if( count > 0 ) {
- tr_variant * l = tr_variantDictAddList( args, "files-unwanted", count );
+ tr_variant * l = tr_variantDictAddList( args, TR_KEY_files_unwanted, count );
for( int i=0, n=myWanted.size(); i<n; ++i )
if( myWanted.at(i) == false )
tr_variantListAddInt( l, i );
// priority-low
count = myPriorities.count( TR_PRI_LOW );
if( count > 0 ) {
- tr_variant * l = tr_variantDictAddList( args, "priority-low", count );
+ tr_variant * l = tr_variantDictAddList( args, TR_KEY_priority_low, count );
for( int i=0, n=myPriorities.size(); i<n; ++i )
if( myPriorities.at(i) == TR_PRI_LOW )
tr_variantListAddInt( l, i );
// priority-high
count = myPriorities.count( TR_PRI_HIGH );
if( count > 0 ) {
- tr_variant * l = tr_variantDictAddList( args, "priority-high", count );
+ tr_variant * l = tr_variantDictAddList( args, TR_KEY_priority_high, count );
for( int i=0, n=myPriorities.size(); i<n; ++i )
if( myPriorities.at(i) == TR_PRI_HIGH )
tr_variantListAddInt( l, i );
Prefs::PrefItem Prefs::myItems[] =
{
- /* gui settings */
- { OPTIONS_PROMPT, "show-options-window", QVariant::Bool },
- { OPEN_DIALOG_FOLDER, "open-dialog-dir", QVariant::String },
- { INHIBIT_HIBERNATION, "inhibit-desktop-hibernation", QVariant::Bool },
- { DIR_WATCH, "watch-dir", QVariant::String },
- { DIR_WATCH_ENABLED, "watch-dir-enabled", QVariant::Bool },
- { SHOW_TRAY_ICON, "show-notification-area-icon", QVariant::Bool },
- { SHOW_DESKTOP_NOTIFICATION, "show-desktop-notification", QVariant::Bool },
- { ASKQUIT, "prompt-before-exit", QVariant::Bool },
- { SORT_MODE, "sort-mode", TrTypes::SortModeType },
- { SORT_REVERSED, "sort-reversed", QVariant::Bool },
- { COMPACT_VIEW, "compact-view", QVariant::Bool },
- { FILTERBAR, "show-filterbar", QVariant::Bool },
- { STATUSBAR, "show-statusbar", QVariant::Bool },
- { STATUSBAR_STATS, "statusbar-stats", QVariant::String },
- { SHOW_TRACKER_SCRAPES, "show-extra-peer-details", QVariant::Bool },
- { SHOW_BACKUP_TRACKERS, "show-backup-trackers", QVariant::Bool },
- { TOOLBAR, "show-toolbar" , QVariant::Bool },
- { BLOCKLIST_DATE, "blocklist-date", QVariant::DateTime },
- { BLOCKLIST_UPDATES_ENABLED, "blocklist-updates-enabled" , QVariant::Bool },
- { MAIN_WINDOW_LAYOUT_ORDER, "main-window-layout-order", QVariant::String },
- { MAIN_WINDOW_HEIGHT, "main-window-height", QVariant::Int },
- { MAIN_WINDOW_WIDTH, "main-window-width", QVariant::Int },
- { MAIN_WINDOW_X, "main-window-x", QVariant::Int },
- { MAIN_WINDOW_Y, "main-window-y", QVariant::Int },
- { FILTER_MODE, "filter-mode", TrTypes::FilterModeType },
- { FILTER_TRACKERS, "filter-trackers", QVariant::String },
- { FILTER_TEXT, "filter-text", QVariant::String },
- { SESSION_IS_REMOTE, "remote-session-enabled", QVariant::Bool },
- { SESSION_REMOTE_HOST, "remote-session-host", QVariant::String },
- { SESSION_REMOTE_PORT, "remote-session-port", QVariant::Int },
- { SESSION_REMOTE_AUTH, "remote-session-requres-authentication", QVariant::Bool },
- { SESSION_REMOTE_USERNAME, "remote-session-username", QVariant::String },
- { SESSION_REMOTE_PASSWORD, "remote-session-password", QVariant::String },
- { USER_HAS_GIVEN_INFORMED_CONSENT, "user-has-given-informed-consent", QVariant::Bool },
-
- /* libtransmission settings */
- { ALT_SPEED_LIMIT_UP, TR_PREFS_KEY_ALT_SPEED_UP_KBps, QVariant::Int },
- { ALT_SPEED_LIMIT_DOWN, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, QVariant::Int },
- { ALT_SPEED_LIMIT_ENABLED, TR_PREFS_KEY_ALT_SPEED_ENABLED, QVariant::Bool },
- { ALT_SPEED_LIMIT_TIME_BEGIN, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, QVariant::Int },
- { ALT_SPEED_LIMIT_TIME_END, TR_PREFS_KEY_ALT_SPEED_TIME_END, QVariant::Int },
- { ALT_SPEED_LIMIT_TIME_ENABLED, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, QVariant::Bool },
- { ALT_SPEED_LIMIT_TIME_DAY, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, QVariant::Int },
- { BLOCKLIST_ENABLED, TR_PREFS_KEY_BLOCKLIST_ENABLED, QVariant::Bool },
- { BLOCKLIST_URL, TR_PREFS_KEY_BLOCKLIST_URL, QVariant::String },
- { DSPEED, TR_PREFS_KEY_DSPEED_KBps, QVariant::Int },
- { DSPEED_ENABLED, TR_PREFS_KEY_DSPEED_ENABLED, QVariant::Bool },
- { DOWNLOAD_DIR, TR_PREFS_KEY_DOWNLOAD_DIR, QVariant::String },
- { DOWNLOAD_QUEUE_ENABLED, TR_PREFS_KEY_DOWNLOAD_QUEUE_ENABLED, QVariant::Bool },
- { DOWNLOAD_QUEUE_SIZE, TR_PREFS_KEY_DOWNLOAD_QUEUE_SIZE, QVariant::Int },
- { ENCRYPTION, TR_PREFS_KEY_ENCRYPTION, QVariant::Int },
- { IDLE_LIMIT, TR_PREFS_KEY_IDLE_LIMIT, QVariant::Int },
- { IDLE_LIMIT_ENABLED, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, QVariant::Bool },
- { INCOMPLETE_DIR, TR_PREFS_KEY_INCOMPLETE_DIR, QVariant::String },
- { INCOMPLETE_DIR_ENABLED, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, QVariant::Bool },
- { MSGLEVEL, TR_PREFS_KEY_MSGLEVEL, QVariant::Int },
- { PEER_LIMIT_GLOBAL, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, QVariant::Int },
- { PEER_LIMIT_TORRENT, TR_PREFS_KEY_PEER_LIMIT_TORRENT, QVariant::Int },
- { PEER_PORT, TR_PREFS_KEY_PEER_PORT, QVariant::Int },
- { PEER_PORT_RANDOM_ON_START, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, QVariant::Bool },
- { PEER_PORT_RANDOM_LOW, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, QVariant::Int },
- { PEER_PORT_RANDOM_HIGH, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, QVariant::Int },
- { QUEUE_STALLED_MINUTES, TR_PREFS_KEY_QUEUE_STALLED_MINUTES, QVariant::Int },
- { SCRIPT_TORRENT_DONE_ENABLED, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, QVariant::Bool },
- { SCRIPT_TORRENT_DONE_FILENAME, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, QVariant::String },
- { SOCKET_TOS, TR_PREFS_KEY_PEER_SOCKET_TOS, QVariant::Int },
- { START, TR_PREFS_KEY_START, QVariant::Bool },
- { TRASH_ORIGINAL, TR_PREFS_KEY_TRASH_ORIGINAL, QVariant::Bool },
- { PEX_ENABLED, TR_PREFS_KEY_PEX_ENABLED, QVariant::Bool },
- { DHT_ENABLED, TR_PREFS_KEY_DHT_ENABLED, QVariant::Bool },
- { UTP_ENABLED, TR_PREFS_KEY_UTP_ENABLED, QVariant::Bool },
- { LPD_ENABLED, TR_PREFS_KEY_LPD_ENABLED, QVariant::Bool },
- { PORT_FORWARDING, TR_PREFS_KEY_PORT_FORWARDING, QVariant::Bool },
- { PREALLOCATION, TR_PREFS_KEY_PREALLOCATION, QVariant::Int },
- { RATIO, TR_PREFS_KEY_RATIO, QVariant::Double },
- { RATIO_ENABLED, TR_PREFS_KEY_RATIO_ENABLED, QVariant::Bool },
- { RENAME_PARTIAL_FILES, TR_PREFS_KEY_RENAME_PARTIAL_FILES, QVariant::Bool },
- { RPC_AUTH_REQUIRED, TR_PREFS_KEY_RPC_AUTH_REQUIRED, QVariant::Bool },
- { RPC_ENABLED, TR_PREFS_KEY_RPC_ENABLED, QVariant::Bool },
- { RPC_PASSWORD, TR_PREFS_KEY_RPC_PASSWORD, QVariant::String },
- { RPC_PORT, TR_PREFS_KEY_RPC_PORT, QVariant::Int },
- { RPC_USERNAME, TR_PREFS_KEY_RPC_USERNAME, QVariant::String },
- { RPC_WHITELIST_ENABLED, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, QVariant::Bool },
- { RPC_WHITELIST, TR_PREFS_KEY_RPC_WHITELIST, QVariant::String },
- { USPEED_ENABLED, TR_PREFS_KEY_USPEED_ENABLED, QVariant::Bool },
- { USPEED, TR_PREFS_KEY_USPEED_KBps, QVariant::Int },
- { UPLOAD_SLOTS_PER_TORRENT, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, QVariant::Int }
+ /* gui settings */
+ { OPTIONS_PROMPT, TR_KEY_show_options_window, QVariant::Bool },
+ { OPEN_DIALOG_FOLDER, TR_KEY_open_dialog_dir, QVariant::String },
+ { INHIBIT_HIBERNATION, TR_KEY_inhibit_desktop_hibernation, QVariant::Bool },
+ { DIR_WATCH, TR_KEY_watch_dir, QVariant::String },
+ { DIR_WATCH_ENABLED, TR_KEY_watch_dir_enabled, QVariant::Bool },
+ { SHOW_TRAY_ICON, TR_KEY_show_notification_area_icon, QVariant::Bool },
+ { SHOW_DESKTOP_NOTIFICATION, TR_KEY_show_desktop_notification, QVariant::Bool },
+ { ASKQUIT, TR_KEY_prompt_before_exit, QVariant::Bool },
+ { SORT_MODE, TR_KEY_sort_mode, TrTypes::SortModeType },
+ { SORT_REVERSED, TR_KEY_sort_reversed, QVariant::Bool },
+ { COMPACT_VIEW, TR_KEY_compact_view, QVariant::Bool },
+ { FILTERBAR, TR_KEY_show_filterbar, QVariant::Bool },
+ { STATUSBAR, TR_KEY_show_statusbar, QVariant::Bool },
+ { STATUSBAR_STATS, TR_KEY_statusbar_stats, QVariant::String },
+ { SHOW_TRACKER_SCRAPES, TR_KEY_show_extra_peer_details, QVariant::Bool },
+ { SHOW_BACKUP_TRACKERS, TR_KEY_show_backup_trackers, QVariant::Bool },
+ { TOOLBAR, TR_KEY_show_toolbar , QVariant::Bool },
+ { BLOCKLIST_DATE, TR_KEY_blocklist_date, QVariant::DateTime },
+ { BLOCKLIST_UPDATES_ENABLED, TR_KEY_blocklist_updates_enabled , QVariant::Bool },
+ { MAIN_WINDOW_LAYOUT_ORDER, TR_KEY_main_window_layout_order, QVariant::String },
+ { MAIN_WINDOW_HEIGHT, TR_KEY_main_window_height, QVariant::Int },
+ { MAIN_WINDOW_WIDTH, TR_KEY_main_window_width, QVariant::Int },
+ { MAIN_WINDOW_X, TR_KEY_main_window_x, QVariant::Int },
+ { MAIN_WINDOW_Y, TR_KEY_main_window_y, QVariant::Int },
+ { FILTER_MODE, TR_KEY_filter_mode, TrTypes::FilterModeType },
+ { FILTER_TRACKERS, TR_KEY_filter_trackers, QVariant::String },
+ { FILTER_TEXT, TR_KEY_filter_text, QVariant::String },
+ { SESSION_IS_REMOTE, TR_KEY_remote_session_enabled, QVariant::Bool },
+ { SESSION_REMOTE_HOST, TR_KEY_remote_session_host, QVariant::String },
+ { SESSION_REMOTE_PORT, TR_KEY_remote_session_port, QVariant::Int },
+ { SESSION_REMOTE_AUTH, TR_KEY_remote_session_requres_authentication, QVariant::Bool },
+ { SESSION_REMOTE_USERNAME, TR_KEY_remote_session_username, QVariant::String },
+ { SESSION_REMOTE_PASSWORD, TR_KEY_remote_session_password, QVariant::String },
+ { USER_HAS_GIVEN_INFORMED_CONSENT, TR_KEY_user_has_given_informed_consent, QVariant::Bool },
+
+ /* libtransmission settings */
+ { ALT_SPEED_LIMIT_UP, TR_KEY_alt_speed_up, QVariant::Int },
+ { ALT_SPEED_LIMIT_DOWN, TR_KEY_alt_speed_down, QVariant::Int },
+ { ALT_SPEED_LIMIT_ENABLED, TR_KEY_alt_speed_enabled, QVariant::Bool },
+ { ALT_SPEED_LIMIT_TIME_BEGIN, TR_KEY_alt_speed_time_begin, QVariant::Int },
+ { ALT_SPEED_LIMIT_TIME_END, TR_KEY_alt_speed_time_end, QVariant::Int },
+ { ALT_SPEED_LIMIT_TIME_ENABLED, TR_KEY_alt_speed_time_enabled, QVariant::Bool },
+ { ALT_SPEED_LIMIT_TIME_DAY, TR_KEY_alt_speed_time_day, QVariant::Int },
+ { BLOCKLIST_ENABLED, TR_KEY_blocklist_enabled, QVariant::Bool },
+ { BLOCKLIST_URL, TR_KEY_blocklist_url, QVariant::String },
+ { DSPEED, TR_KEY_speed_limit_down, QVariant::Int },
+ { DSPEED_ENABLED, TR_KEY_speed_limit_down_enabled, QVariant::Bool },
+ { DOWNLOAD_DIR, TR_KEY_download_dir, QVariant::String },
+ { DOWNLOAD_QUEUE_ENABLED, TR_KEY_download_queue_enabled, QVariant::Bool },
+ { DOWNLOAD_QUEUE_SIZE, TR_KEY_download_queue_size, QVariant::Int },
+ { ENCRYPTION, TR_KEY_encryption, QVariant::Int },
+ { IDLE_LIMIT, TR_KEY_idle_seeding_limit, QVariant::Int },
+ { IDLE_LIMIT_ENABLED, TR_KEY_idle_seeding_limit_enabled, QVariant::Bool },
+ { INCOMPLETE_DIR, TR_KEY_incomplete_dir, QVariant::String },
+ { INCOMPLETE_DIR_ENABLED, TR_KEY_incomplete_dir_enabled, QVariant::Bool },
+ { MSGLEVEL, TR_KEY_message_level, QVariant::Int },
+ { PEER_LIMIT_GLOBAL, TR_KEY_peer_limit_global, QVariant::Int },
+ { PEER_LIMIT_TORRENT, TR_KEY_peer_limit_per_torrent, QVariant::Int },
+ { PEER_PORT, TR_KEY_peer_port, QVariant::Int },
+ { PEER_PORT_RANDOM_ON_START, TR_KEY_peer_port_random_on_start, QVariant::Bool },
+ { PEER_PORT_RANDOM_LOW, TR_KEY_peer_port_random_low, QVariant::Int },
+ { PEER_PORT_RANDOM_HIGH, TR_KEY_peer_port_random_high, QVariant::Int },
+ { QUEUE_STALLED_MINUTES, TR_KEY_queue_stalled_minutes, QVariant::Int },
+ { SCRIPT_TORRENT_DONE_ENABLED, TR_KEY_script_torrent_done_enabled, QVariant::Bool },
+ { SCRIPT_TORRENT_DONE_FILENAME, TR_KEY_script_torrent_done_filename, QVariant::String },
+ { SOCKET_TOS, TR_KEY_peer_socket_tos, QVariant::Int },
+ { START, TR_KEY_start_added_torrents, QVariant::Bool },
+ { TRASH_ORIGINAL, TR_KEY_trash_original_torrent_files, QVariant::Bool },
+ { PEX_ENABLED, TR_KEY_pex_enabled, QVariant::Bool },
+ { DHT_ENABLED, TR_KEY_dht_enabled, QVariant::Bool },
+ { UTP_ENABLED, TR_KEY_utp_enabled, QVariant::Bool },
+ { LPD_ENABLED, TR_KEY_lpd_enabled, QVariant::Bool },
+ { PORT_FORWARDING, TR_KEY_port, QVariant::Bool },
+ { PREALLOCATION, TR_KEY_preallocation, QVariant::Int },
+ { RATIO, TR_KEY_ratio_limit, QVariant::Double },
+ { RATIO_ENABLED, TR_KEY_ratio_limit_enabled, QVariant::Bool },
+ { RENAME_PARTIAL_FILES, TR_KEY_rename_partial_files, QVariant::Bool },
+ { RPC_AUTH_REQUIRED, TR_KEY_rpc_authentication_required, QVariant::Bool },
+ { RPC_ENABLED, TR_KEY_rpc_enabled, QVariant::Bool },
+ { RPC_PASSWORD, TR_KEY_rpc_password, QVariant::String },
+ { RPC_PORT, TR_KEY_rpc_port, QVariant::Int },
+ { RPC_USERNAME, TR_KEY_rpc_username, QVariant::String },
+ { RPC_WHITELIST_ENABLED, TR_KEY_rpc_whitelist_enabled, QVariant::Bool },
+ { RPC_WHITELIST, TR_KEY_rpc_whitelist, QVariant::String },
+ { USPEED_ENABLED, TR_KEY_speed_limit_up_enabled, QVariant::Bool },
+ { USPEED, TR_KEY_speed_limit_up, QVariant::Int },
+ { UPLOAD_SLOTS_PER_TORRENT, TR_KEY_upload_slots_per_torrent, QVariant::Int }
};
/***
****
***/
-Prefs :: Prefs( const char * configDir ):
- myConfigDir( QString::fromUtf8( configDir ) )
+Prefs :: Prefs (const char * configDir):
+ myConfigDir (QString::fromUtf8 (configDir))
{
- assert( sizeof(myItems) / sizeof(myItems[0]) == PREFS_COUNT );
- for( int i=0; i<PREFS_COUNT; ++i )
- assert( myItems[i].id == i );
-
- // these are the prefs that don't get saved to settings.json
- // when the application exits.
- myTemporaryPrefs << FILTER_TEXT;
-
- tr_variant top;
- tr_variantInitDict( &top, 0 );
- initDefaults( &top );
- tr_sessionLoadSettings( &top, configDir, NULL );
- for( int i=0; i<PREFS_COUNT; ++i )
+ assert (sizeof(myItems) / sizeof(myItems[0]) == PREFS_COUNT);
+
+#ifndef NDEBUG
+ for (int i=0; i<PREFS_COUNT; ++i)
+ assert (myItems[i].id == i);
+#endif
+
+ // these are the prefs that don't get saved to settings.json
+ // when the application exits.
+ myTemporaryPrefs << FILTER_TEXT;
+
+ tr_variant top;
+ tr_variantInitDict (&top, 0);
+ initDefaults (&top);
+ tr_sessionLoadSettings (&top, configDir, NULL);
+
+ for (int i=0; i<PREFS_COUNT; ++i)
{
- double d;
- bool boolVal;
- int64_t intVal;
- const char * str;
- size_t strLen;
- tr_variant * b( tr_variantDictFind( &top, myItems[i].key ) );
-
- switch( myItems[i].type )
+ double d;
+ bool boolVal;
+ int64_t intVal;
+ const char * str;
+ size_t strLen;
+ tr_variant * b (tr_variantDictFind (&top, myItems[i].key));
+
+ switch (myItems[i].type)
{
- case QVariant::Int:
- if( tr_variantGetInt( b, &intVal ) )
- myValues[i].setValue( qlonglong(intVal) );
- break;
- case TrTypes::SortModeType:
- if( tr_variantGetStr( b, &str, NULL ) )
- myValues[i] = QVariant::fromValue( SortMode( str ) );
- break;
- case TrTypes::FilterModeType:
- if( tr_variantGetStr( b, &str, NULL ) )
- myValues[i] = QVariant::fromValue( FilterMode( str ) );
- break;
- case QVariant::String:
- if( tr_variantGetStr( b, &str, &strLen ) )
- myValues[i].setValue( QString::fromUtf8( str, strLen ) );
- break;
- case QVariant::Bool:
- if( tr_variantGetBool( b, &boolVal ) )
- myValues[i].setValue( bool(boolVal) );
- break;
- case QVariant::Double:
- if( tr_variantGetReal( b, &d ) )
- myValues[i].setValue( d );
- break;
- case QVariant::DateTime:
- if( tr_variantGetInt( b, &intVal ) )
- myValues[i].setValue( QDateTime :: fromTime_t( intVal ) );
- break;
- default:
- assert( "unhandled type" && 0 );
- break;
+ case QVariant::Int:
+ if (tr_variantGetInt (b, &intVal))
+ myValues[i].setValue (qlonglong(intVal));
+ break;
+
+ case TrTypes::SortModeType:
+ if (tr_variantGetStr (b, &str, NULL))
+ myValues[i] = QVariant::fromValue (SortMode (str));
+ break;
+
+ case TrTypes::FilterModeType:
+ if (tr_variantGetStr (b, &str, NULL))
+ myValues[i] = QVariant::fromValue (FilterMode (str));
+ break;
+
+ case QVariant::String:
+ if (tr_variantGetStr (b, &str, &strLen))
+ myValues[i].setValue (QString::fromUtf8 (str, strLen));
+ break;
+
+ case QVariant::Bool:
+ if (tr_variantGetBool (b, &boolVal))
+ myValues[i].setValue (bool(boolVal));
+ break;
+
+ case QVariant::Double:
+ if (tr_variantGetReal (b, &d))
+ myValues[i].setValue (d);
+ break;
+
+ case QVariant::DateTime:
+ if (tr_variantGetInt (b, &intVal))
+ myValues[i].setValue (QDateTime :: fromTime_t (intVal));
+ break;
+
+ default:
+ assert ("unhandled type" && 0);
+ break;
}
}
- tr_variantFree( &top );
+ tr_variantFree (&top);
}
-Prefs :: ~Prefs( )
+Prefs :: ~Prefs ()
{
- tr_variant top;
-
- /* load in the existing preferences file */
- QFile file( QDir( myConfigDir ).absoluteFilePath( "settings.json" ) );
- file.open( QIODevice::ReadOnly | QIODevice::Text );
- const QByteArray oldPrefs = file.readAll( );
- file.close( );
- if (tr_variantFromJsonFull (&top, oldPrefs.data(), oldPrefs.length(), "settings.json", NULL))
- tr_variantInitDict( &top, PREFS_COUNT );
-
- /* merge our own settings with the ones already in the file */
- for( int i=0; i<PREFS_COUNT; ++i )
+ // make a dict from settings.json
+ tr_variant current_settings;
+ tr_variantInitDict (¤t_settings, PREFS_COUNT);
+ for (int i=0; i<PREFS_COUNT; ++i)
{
- if( myTemporaryPrefs.contains( i ) )
- continue;
+ if (myTemporaryPrefs.contains(i))
+ continue;
- const char * key = myItems[i].key;
- const QVariant& val = myValues[i];
+ const tr_quark key = myItems[i].key;
+ const QVariant& val = myValues[i];
- switch( myItems[i].type )
+ switch (myItems[i].type)
{
- case QVariant::Int:
- tr_variantDictAddInt( &top, key, val.toInt() );
- break;
- case TrTypes::SortModeType:
- tr_variantDictAddStr( &top, key, val.value<SortMode>().name().toUtf8().constData() );
- break;
- case TrTypes::FilterModeType:
- tr_variantDictAddStr( &top, key, val.value<FilterMode>().name().toUtf8().constData() );
- break;
- case QVariant::String:
- { const char * s = val.toByteArray().constData();
- if ( Utils::isValidUtf8( s ) )
- tr_variantDictAddStr( &top, key, s );
- else
- tr_variantDictAddStr( &top, key, val.toString().toUtf8().constData() );
- }
- break;
- case QVariant::Bool:
- tr_variantDictAddBool( &top, key, val.toBool() );
- break;
- case QVariant::Double:
- tr_variantDictAddReal( &top, key, val.toDouble() );
- break;
- case QVariant::DateTime:
- tr_variantDictAddInt( &top, key, val.toDateTime().toTime_t() );
- break;
- default:
- assert( "unhandled type" && 0 );
- break;
+ case QVariant::Int:
+ tr_variantDictAddInt (¤t_settings, key, val.toInt());
+ break;
+
+ case TrTypes::SortModeType:
+ tr_variantDictAddStr (¤t_settings, key, val.value<SortMode>().name().toUtf8().constData());
+ break;
+
+ case TrTypes::FilterModeType:
+ tr_variantDictAddStr (¤t_settings, key, val.value<FilterMode>().name().toUtf8().constData());
+ break;
+ case QVariant::String:
+ {
+ const char * s = val.toByteArray().constData();
+ if (Utils::isValidUtf8 (s))
+ tr_variantDictAddStr (¤t_settings, key, s);
+ else
+ tr_variantDictAddStr (¤t_settings, key, val.toString().toUtf8().constData());
+ }
+ break;
+
+ case QVariant::Bool:
+ tr_variantDictAddBool (¤t_settings, key, val.toBool());
+ break;
+
+ case QVariant::Double:
+ tr_variantDictAddReal (¤t_settings, key, val.toDouble());
+ break;
+
+ case QVariant::DateTime:
+ tr_variantDictAddInt (¤t_settings, key, val.toDateTime().toTime_t());
+ break;
+
+ default:
+ assert ("unhandled type" && 0);
+ break;
}
}
- /* write back out the serialized preferences */
- tr_variantToFile( &top, TR_VARIANT_FMT_JSON, file.fileName().toUtf8().constData() );
- tr_variantFree( &top );
+ // update settings.json with our settings
+ tr_variant file_settings;
+ const QFile file (QDir(myConfigDir).absoluteFilePath("settings.json"));
+ if (tr_variantFromFile (&file_settings, TR_VARIANT_FMT_JSON, file.fileName().toUtf8().constData()))
+ tr_variantInitDict (&file_settings, PREFS_COUNT);
+ tr_variantMergeDicts (&file_settings, ¤t_settings);
+ tr_variantToFile (&file_settings, TR_VARIANT_FMT_JSON, file.fileName().toUtf8().constData());
+ tr_variantFree (&file_settings);
+
+ // cleanup
+ tr_variantFree (¤t_settings);
}
/**
* If you add a new preferences key, you /must/ add a default value here.
*/
void
-Prefs :: initDefaults( tr_variant * d )
+Prefs :: initDefaults (tr_variant * d)
{
- tr_variantDictAddStr ( d, keyStr(DIR_WATCH), tr_getDefaultDownloadDir( ) );
- tr_variantDictAddBool( d, keyStr(DIR_WATCH_ENABLED), false );
- tr_variantDictAddBool( d, keyStr(INHIBIT_HIBERNATION), false );
- tr_variantDictAddInt ( d, keyStr(BLOCKLIST_DATE), 0 );
- tr_variantDictAddBool( d, keyStr(BLOCKLIST_UPDATES_ENABLED), true );
- tr_variantDictAddStr ( d, keyStr(OPEN_DIALOG_FOLDER), QDir::home().absolutePath().toUtf8() );
- tr_variantDictAddInt ( d, keyStr(SHOW_TRACKER_SCRAPES), false );
- tr_variantDictAddBool( d, keyStr(TOOLBAR), true );
- tr_variantDictAddBool( d, keyStr(FILTERBAR), true );
- tr_variantDictAddBool( d, keyStr(STATUSBAR), true );
- tr_variantDictAddBool( d, keyStr(SHOW_TRAY_ICON), false );
- tr_variantDictAddBool( d, keyStr(SHOW_DESKTOP_NOTIFICATION), true );
- tr_variantDictAddStr ( d, keyStr(STATUSBAR_STATS), "total-ratio" );
- tr_variantDictAddBool( d, keyStr(SHOW_TRACKER_SCRAPES), false );
- tr_variantDictAddBool( d, keyStr(SHOW_BACKUP_TRACKERS), false );
- tr_variantDictAddBool( d, keyStr(OPTIONS_PROMPT), true );
- tr_variantDictAddInt ( d, keyStr(MAIN_WINDOW_HEIGHT), 500 );
- tr_variantDictAddInt ( d, keyStr(MAIN_WINDOW_WIDTH), 300 );
- tr_variantDictAddInt ( d, keyStr(MAIN_WINDOW_X), 50 );
- tr_variantDictAddInt ( d, keyStr(MAIN_WINDOW_Y), 50 );
- tr_variantDictAddStr ( d, keyStr(FILTER_MODE), "all" );
- tr_variantDictAddStr ( d, keyStr(MAIN_WINDOW_LAYOUT_ORDER), "menu,toolbar,filter,list,statusbar" );
- tr_variantDictAddStr ( d, keyStr(DOWNLOAD_DIR), tr_getDefaultDownloadDir( ) );
- tr_variantDictAddBool( d, keyStr(ASKQUIT), true );
- tr_variantDictAddStr ( d, keyStr(SORT_MODE), "sort-by-name" );
- tr_variantDictAddBool( d, keyStr(SORT_REVERSED), false );
- tr_variantDictAddBool( d, keyStr(COMPACT_VIEW), false );
- tr_variantDictAddStr ( d, keyStr(SESSION_REMOTE_HOST), "localhost" );
- tr_variantDictAddInt ( d, keyStr(SESSION_REMOTE_PORT), atoi(TR_DEFAULT_RPC_PORT_STR) );
- tr_variantDictAddBool( d, keyStr(SESSION_IS_REMOTE), false );
- tr_variantDictAddBool( d, keyStr(SESSION_REMOTE_AUTH), false );
- tr_variantDictAddBool( d, keyStr(USER_HAS_GIVEN_INFORMED_CONSENT), false );
+ tr_variantDictAddBool (d, TR_KEY_blocklist_updates_enabled, true);
+ tr_variantDictAddBool (d, TR_KEY_compact_view, false);
+ tr_variantDictAddBool (d, TR_KEY_inhibit_desktop_hibernation, false);
+ tr_variantDictAddBool (d, TR_KEY_prompt_before_exit, true);
+ tr_variantDictAddBool (d, TR_KEY_remote_session_enabled, false);
+ tr_variantDictAddBool (d, TR_KEY_remote_session_requres_authentication, false);
+ tr_variantDictAddBool (d, TR_KEY_show_backup_trackers, false);
+ tr_variantDictAddBool (d, TR_KEY_show_desktop_notification, true);
+ tr_variantDictAddBool (d, TR_KEY_show_extra_peer_details, false),
+ tr_variantDictAddBool (d, TR_KEY_show_filterbar, true);
+ tr_variantDictAddBool (d, TR_KEY_show_notification_area_icon, false);
+ tr_variantDictAddBool (d, TR_KEY_show_options_window, true);
+ tr_variantDictAddBool (d, TR_KEY_show_statusbar, true);
+ tr_variantDictAddBool (d, TR_KEY_show_toolbar, true);
+ tr_variantDictAddBool (d, TR_KEY_show_tracker_scrapes, false);
+ tr_variantDictAddBool (d, TR_KEY_sort_reversed, false);
+ tr_variantDictAddBool (d, TR_KEY_user_has_given_informed_consent, false);
+ tr_variantDictAddBool (d, TR_KEY_watch_dir_enabled, false);
+ tr_variantDictAddInt (d, TR_KEY_blocklist_date, 0);
+ tr_variantDictAddInt (d, TR_KEY_main_window_height, 500);
+ tr_variantDictAddInt (d, TR_KEY_main_window_width, 300);
+ tr_variantDictAddInt (d, TR_KEY_main_window_x, 50);
+ tr_variantDictAddInt (d, TR_KEY_main_window_y, 50);
+ tr_variantDictAddInt (d, TR_KEY_remote_session_port, atoi(TR_DEFAULT_RPC_PORT_STR));
+ tr_variantDictAddStr (d, TR_KEY_download_dir, tr_getDefaultDownloadDir());
+ tr_variantDictAddStr (d, TR_KEY_filter_mode, "all");
+ tr_variantDictAddStr (d, TR_KEY_main_window_layout_order, "menu,toolbar,filter,list,statusbar");
+ tr_variantDictAddStr (d, TR_KEY_open_dialog_dir, QDir::home().absolutePath().toUtf8());
+ tr_variantDictAddStr (d, TR_KEY_remote_session_host, "localhost");
+ tr_variantDictAddStr (d, TR_KEY_remote_session_password, "");
+ tr_variantDictAddStr (d, TR_KEY_remote_session_username, "");
+ tr_variantDictAddStr (d, TR_KEY_sort_mode, "sort-by-name");
+ tr_variantDictAddStr (d, TR_KEY_statusbar_stats, "total-ratio");
+ tr_variantDictAddStr (d, TR_KEY_watch_dir, tr_getDefaultDownloadDir());
}
/***
***/
bool
-Prefs :: getBool( int key ) const
+Prefs :: getBool (int key) const
{
- assert( myItems[key].type == QVariant::Bool );
- return myValues[key].toBool( );
+ assert (myItems[key].type == QVariant::Bool);
+ return myValues[key].toBool();
}
QString
-Prefs :: getString( int key ) const
+Prefs :: getString (int key) const
{
- assert( myItems[key].type == QVariant::String );
- QByteArray b = myValues[key].toByteArray();
- if ( Utils::isValidUtf8( b.constData() ) )
- myValues[key].setValue( QString::fromUtf8( b.constData() ) );
- return myValues[key].toString();
+ assert (myItems[key].type == QVariant::String);
+ QByteArray b = myValues[key].toByteArray();
+ if (Utils::isValidUtf8 (b.constData()))
+ myValues[key].setValue (QString::fromUtf8 (b.constData()));
+ return myValues[key].toString();
}
int
-Prefs :: getInt( int key ) const
+Prefs :: getInt (int key) const
{
- assert( myItems[key].type == QVariant::Int );
- return myValues[key].toInt( );
+ assert (myItems[key].type == QVariant::Int);
+ return myValues[key].toInt();
}
double
-Prefs :: getDouble( int key ) const
+Prefs :: getDouble (int key) const
{
- assert( myItems[key].type == QVariant::Double );
- return myValues[key].toDouble( );
+ assert (myItems[key].type == QVariant::Double);
+ return myValues[key].toDouble();
}
QDateTime
-Prefs :: getDateTime( int key ) const
+Prefs :: getDateTime (int key) const
{
- assert( myItems[key].type == QVariant::DateTime );
- return myValues[key].toDateTime( );
+ assert (myItems[key].type == QVariant::DateTime);
+ return myValues[key].toDateTime();
}
/***
***/
void
-Prefs :: toggleBool( int key )
+Prefs :: toggleBool (int key)
{
- set( key, !getBool( key ) );
+ set (key, !getBool(key));
}
#include "filters.h"
+#include <libtransmission/quark.h>
+
extern "C"
{
struct tr_variant;
struct PrefItem {
int id;
- const char * key;
+ tr_quark key;
int type;
};
public:
bool isCore( int key ) const { return FIRST_CORE_PREF<=key && key<=LAST_CORE_PREF; }
bool isClient( int key ) const { return !isCore( key ); }
- const char * keyStr( int i ) const { return myItems[i].key; }
+ const char * keyStr( int i ) const { return tr_quark_get_string(myItems[i].key,NULL); }
+ tr_quark getKey (int i) const { return myItems[i].key; }
int type( int i ) const { return myItems[i].type; }
const QVariant& variant( int i ) const { return myValues[i]; }
namespace
{
- typedef Torrent::KeyList KeyList;
- const KeyList& getInfoKeys( ) { return Torrent::getInfoKeys( ); }
- const KeyList& getStatKeys( ) { return Torrent::getStatKeys( ); }
- const KeyList& getExtraStatKeys( ) { return Torrent::getExtraStatKeys( ); }
-
- void
- addList( tr_variant * list, const KeyList& strings )
- {
- tr_variantListReserve( list, strings.size( ) );
- foreach( const char * str, strings )
- tr_variantListAddStr( list, str );
- }
+ typedef Torrent::KeyList KeyList;
+ const KeyList& getInfoKeys() { return Torrent::getInfoKeys(); }
+ const KeyList& getStatKeys() { return Torrent::getStatKeys(); }
+ const KeyList& getExtraStatKeys() { return Torrent::getExtraStatKeys(); }
+
+ void
+ addList (tr_variant * list, const KeyList& keys)
+ {
+ tr_variantListReserve (list, keys.size());
+ foreach (tr_quark key, keys)
+ tr_variantListAddQuark (list, key);
+ }
}
/***
***/
void
-Session :: sessionSet( const char * key, const QVariant& value )
+Session :: sessionSet( const tr_quark key, const QVariant& value )
{
tr_variant top;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "session-set" );
- tr_variant * args( tr_variantDictAddDict( &top, "arguments", 1 ) );
+ tr_variantDictAddStr( &top, TR_KEY_method, "session-set" );
+ tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 1 ) );
switch( value.type( ) ) {
case QVariant::Bool: tr_variantDictAddBool ( args, key, value.toBool() ); break;
case QVariant::Int: tr_variantDictAddInt ( args, key, value.toInt() ); break;
{
tr_variant top;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "port-test" );
- tr_variantDictAddInt( &top, "tag", TAG_PORT_TEST );
+ tr_variantDictAddStr( &top, TR_KEY_method, "port-test" );
+ tr_variantDictAddInt( &top, TR_KEY_tag, TAG_PORT_TEST );
exec( &top );
tr_variantFree( &top );
}
{
tr_variant top;
tr_variantInitDict( &top, 3 );
- tr_variantDictAddStr( &top, "method", "torrent-get" );
- tr_variantDictAddInt( &top, "tag", TAG_MAGNET_LINK );
- tr_variant * args = tr_variantDictAddDict( &top, "arguments", 2 );
- tr_variantListAddInt( tr_variantDictAddList( args, "ids", 1 ), torrentId );
- tr_variantListAddStr( tr_variantDictAddList( args, "fields", 1 ), "magnetLink" );
+ tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get );
+ tr_variantDictAddInt( &top, TR_KEY_tag, TAG_MAGNET_LINK );
+ tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 );
+ tr_variantListAddInt( tr_variantDictAddList( args, TR_KEY_ids, 1 ), torrentId );
+ tr_variantListAddStr( tr_variantDictAddList( args, TR_KEY_fields, 1 ), "magnetLink" );
exec( &top );
tr_variantFree( &top );
case Prefs :: USPEED:
case Prefs :: USPEED_ENABLED:
case Prefs :: UTP_ENABLED:
- sessionSet( myPrefs.keyStr(key), myPrefs.variant(key) );
+ sessionSet( myPrefs.getKey(key), myPrefs.variant(key) );
break;
case Prefs :: RATIO:
- sessionSet( "seedRatioLimit", myPrefs.variant(key) );
+ sessionSet( TR_KEY_seedRatioLimit, myPrefs.variant(key) );
break;
case Prefs :: RATIO_ENABLED:
- sessionSet( "seedRatioLimited", myPrefs.variant(key) );
+ sessionSet( TR_KEY_seedRatioLimited, myPrefs.variant(key) );
break;
case Prefs :: ENCRYPTION:
switch( i )
{
case 0:
- sessionSet( myPrefs.keyStr(key), "tolerated" );
+ sessionSet( myPrefs.getKey(key), "tolerated" );
break;
case 1:
- sessionSet( myPrefs.keyStr(key), "preferred" );
+ sessionSet( myPrefs.getKey(key), "preferred" );
break;
case 2:
- sessionSet( myPrefs.keyStr(key), "required" );
+ sessionSet( myPrefs.getKey(key), "required" );
break;
}
break;
namespace
{
- tr_variant *
- buildRequest( const char * method, tr_variant& top, int tag=-1 )
- {
- tr_variantInitDict( &top, 3 );
- tr_variantDictAddStr( &top, "method", method );
- if( tag >= 0 )
- tr_variantDictAddInt( &top, "tag", tag );
- return tr_variantDictAddDict( &top, "arguments", 0 );
- }
-
- void
- addOptionalIds( tr_variant * args, const QSet<int>& ids )
- {
- if( !ids.isEmpty( ) )
- {
- tr_variant * idList( tr_variantDictAddList( args, "ids", ids.size( ) ) );
- foreach( int i, ids )
- tr_variantListAddInt( idList, i );
- }
- }
+ tr_variant *
+ buildRequest (const char * method, tr_variant& top, int tag=-1)
+ {
+ tr_variantInitDict (&top, 3);
+ tr_variantDictAddStr (&top, TR_KEY_method, method);
+
+ if (tag >= 0)
+ tr_variantDictAddInt (&top, TR_KEY_tag, tag);
+
+ return tr_variantDictAddDict (&top, TR_KEY_arguments, 0);
+ }
+
+ void
+ addOptionalIds( tr_variant * args, const QSet<int>& ids )
+ {
+ if (!ids.isEmpty())
+ {
+ tr_variant * idList (tr_variantDictAddList (args, TR_KEY_ids, ids.size()));
+ foreach (int i, ids)
+ tr_variantListAddInt (idList, i);
+ }
+ }
}
void
-Session :: torrentSet( const QSet<int>& ids, const QString& key, double value )
+Session :: torrentSet( const QSet<int>& ids, const tr_quark key, double value )
{
tr_variant top;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "torrent-set" );
- tr_variant * args = tr_variantDictAddDict( &top, "arguments", 2 );
- tr_variantDictAddReal( args, key.toUtf8().constData(), value );
+ tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set );
+ tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 );
+ tr_variantDictAddReal( args, key, value );
addOptionalIds( args, ids );
exec( &top );
tr_variantFree( &top );
}
void
-Session :: torrentSet( const QSet<int>& ids, const QString& key, int value )
+Session :: torrentSet( const QSet<int>& ids, const tr_quark key, int value )
{
tr_variant top;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "torrent-set" );
- tr_variant * args = tr_variantDictAddDict( &top, "arguments", 2 );
- tr_variantDictAddInt( args, key.toUtf8().constData(), value );
+ tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set );
+ tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 );
+ tr_variantDictAddInt( args, key, value );
addOptionalIds( args, ids );
exec( &top );
tr_variantFree( &top );
}
void
-Session :: torrentSet( const QSet<int>& ids, const QString& key, bool value )
+Session :: torrentSet( const QSet<int>& ids, const tr_quark key, bool value )
{
tr_variant top;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "torrent-set" );
- tr_variant * args = tr_variantDictAddDict( &top, "arguments", 2 );
- tr_variantDictAddBool( args, key.toUtf8().constData(), value );
+ tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set );
+ tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 );
+ tr_variantDictAddBool( args, key, value );
addOptionalIds( args, ids );
exec( &top );
tr_variantFree( &top );
}
void
-Session :: torrentSet( const QSet<int>& ids, const QString& key, const QStringList& value )
+Session :: torrentSet( const QSet<int>& ids, const tr_quark key, const QStringList& value )
{
tr_variant top;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "torrent-set" );
- tr_variant * args = tr_variantDictAddDict( &top, "arguments", 2 );
+ tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set );
+ tr_variant * args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 );
addOptionalIds( args, ids );
- tr_variant * list( tr_variantDictAddList( args, key.toUtf8().constData(), value.size( ) ) );
+ tr_variant * list( tr_variantDictAddList( args, key, value.size( ) ) );
foreach( const QString str, value )
tr_variantListAddStr( list, str.toUtf8().constData() );
exec( &top );
}
void
-Session :: torrentSet( const QSet<int>& ids, const QString& key, const QList<int>& value )
+Session :: torrentSet( const QSet<int>& ids, const tr_quark key, const QList<int>& value )
{
tr_variant top;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "torrent-set" );
- tr_variant * args( tr_variantDictAddDict( &top, "arguments", 2 ) );
+ tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_set );
+ tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ) );
addOptionalIds( args, ids );
- tr_variant * list( tr_variantDictAddList( args, key.toUtf8().constData(), value.size( ) ) );
+ tr_variant * list( tr_variantDictAddList( args, key, value.size( ) ) );
foreach( int i, value )
tr_variantListAddInt( list, i );
exec( &top );
}
void
-Session :: torrentSet( const QSet<int>& ids, const QString& key, const QPair<int,QString>& value )
+Session :: torrentSet( const QSet<int>& ids, const tr_quark key, const QPair<int,QString>& value )
{
- tr_variant top;
- tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "torrent-set" );
- tr_variant * args( tr_variantDictAddDict( &top, "arguments", 2 ) );
- addOptionalIds( args, ids );
- tr_variant * list( tr_variantDictAddList( args, key.toUtf8().constData(), 2 ) );
- tr_variantListAddInt( list, value.first );
- tr_variantListAddStr( list, value.second.toUtf8().constData() );
- exec( &top );
- tr_variantFree( &top );
+ tr_variant top;
+ tr_variantInitDict (&top, 2);
+ tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set);
+ tr_variant * args (tr_variantDictAddDict (&top, TR_KEY_arguments, 2));
+ addOptionalIds (args, ids);
+ tr_variant * list (tr_variantDictAddList (args, key, 2));
+ tr_variantListAddInt (list, value.first);
+ tr_variantListAddStr (list, value.second.toUtf8().constData());
+ exec (&top);
+ tr_variantFree (&top);
}
void
-Session :: torrentSetLocation( const QSet<int>& ids, const QString& location, bool doMove )
+Session :: torrentSetLocation( const QSet<int>& ids, const QString& location, bool doMove)
{
- tr_variant top;
- tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "torrent-set-location" );
- tr_variant * args( tr_variantDictAddDict( &top, "arguments", 3 ) );
- addOptionalIds( args, ids );
- tr_variantDictAddStr( args, "location", location.toUtf8().constData() );
- tr_variantDictAddBool( args, "move", doMove );
- exec( &top );
- tr_variantFree( &top );
+ tr_variant top;
+ tr_variantInitDict (&top, 2);
+ tr_variantDictAddQuark (&top, TR_KEY_method, TR_KEY_torrent_set);
+ tr_variant * args (tr_variantDictAddDict(&top, TR_KEY_arguments, 3));
+ addOptionalIds (args, ids);
+ tr_variantDictAddStr (args, TR_KEY_location, location.toUtf8().constData());
+ tr_variantDictAddBool (args, TR_KEY_move, doMove);
+ exec (&top);
+ tr_variantFree (&top);
}
void
{
tr_variant top;
tr_variantInitDict( &top, 3 );
- tr_variantDictAddStr( &top, "method", "torrent-get" );
- tr_variantDictAddInt( &top, "tag", TAG_SOME_TORRENTS );
- tr_variant * args( tr_variantDictAddDict( &top, "arguments", 2 ) );
- addList( tr_variantDictAddList( args, "fields", 0 ), getStatKeys( ) );
+ tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get );
+ tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SOME_TORRENTS );
+ tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ) );
+ addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys( ) );
addOptionalIds( args, ids );
exec( &top );
tr_variantFree( &top );
{
tr_variant top;
tr_variantInitDict( &top, 3 );
- tr_variantDictAddStr( &top, "method", "torrent-get" );
- tr_variantDictAddInt( &top, "tag", TAG_SOME_TORRENTS );
- tr_variant * args( tr_variantDictAddDict( &top, "arguments", 2 ) );
+ tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get );
+ tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SOME_TORRENTS );
+ tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ) );
addOptionalIds( args, ids );
- addList( tr_variantDictAddList( args, "fields", 0 ), getStatKeys( ) + getExtraStatKeys( ));
+ addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys( ) + getExtraStatKeys( ));
exec( &top );
tr_variantFree( &top );
}
void
-Session :: sendTorrentRequest( const char * request, const QSet<int>& ids )
+Session :: sendTorrentRequest (const char * request, const QSet<int>& ids )
{
- tr_variant top;
- tr_variant * args( buildRequest( request, top ) );
- addOptionalIds( args, ids );
- exec( &top );
- tr_variantFree( &top );
+ tr_variant top;
- refreshTorrents( ids );
+ tr_variant * args (buildRequest (request, top));
+ addOptionalIds (args, ids);
+ exec (&top);
+ tr_variantFree (&top);
+
+ refreshTorrents (ids);
}
-void Session :: pauseTorrents ( const QSet<int>& ids ) { sendTorrentRequest( "torrent-stop", ids ); }
-void Session :: startTorrents ( const QSet<int>& ids ) { sendTorrentRequest( "torrent-start", ids ); }
-void Session :: startTorrentsNow ( const QSet<int>& ids ) { sendTorrentRequest( "torrent-start-now", ids ); }
-void Session :: queueMoveTop ( const QSet<int>& ids ) { sendTorrentRequest( "queue-move-top", ids ); }
-void Session :: queueMoveUp ( const QSet<int>& ids ) { sendTorrentRequest( "queue-move-up", ids ); }
-void Session :: queueMoveDown ( const QSet<int>& ids ) { sendTorrentRequest( "queue-move-down", ids ); }
-void Session :: queueMoveBottom ( const QSet<int>& ids ) { sendTorrentRequest( "queue-move-bottom", ids ); }
+void Session :: pauseTorrents (const QSet<int>& ids) { sendTorrentRequest ("torrent-stop", ids); }
+void Session :: startTorrents (const QSet<int>& ids) { sendTorrentRequest ("torrent-start", ids); }
+void Session :: startTorrentsNow (const QSet<int>& ids) { sendTorrentRequest ("torrent-start-now", ids); }
+void Session :: queueMoveTop (const QSet<int>& ids) { sendTorrentRequest ("torrent-move-top", ids); }
+void Session :: queueMoveUp (const QSet<int>& ids) { sendTorrentRequest ("torrent-move-up", ids); }
+void Session :: queueMoveDown (const QSet<int>& ids) { sendTorrentRequest ("torrent-move-down", ids); }
+void Session :: queueMoveBottom (const QSet<int>& ids) { sendTorrentRequest ("torrent-move-bottom", ids); }
void
Session :: refreshActiveTorrents( )
{
tr_variant top;
tr_variantInitDict( &top, 3 );
- tr_variantDictAddStr( &top, "method", "torrent-get" );
- tr_variantDictAddInt( &top, "tag", TAG_SOME_TORRENTS );
- tr_variant * args( tr_variantDictAddDict( &top, "arguments", 2 ) );
- tr_variantDictAddStr( args, "ids", "recently-active" );
- addList( tr_variantDictAddList( args, "fields", 0 ), getStatKeys( ) );
+ tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get );
+ tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SOME_TORRENTS );
+ tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 2 ) );
+ tr_variantDictAddStr( args, TR_KEY_ids, "recently-active" );
+ addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys( ) );
exec( &top );
tr_variantFree( &top );
}
{
tr_variant top;
tr_variantInitDict( &top, 3 );
- tr_variantDictAddStr( &top, "method", "torrent-get" );
- tr_variantDictAddInt( &top, "tag", TAG_ALL_TORRENTS );
- tr_variant * args( tr_variantDictAddDict( &top, "arguments", 1 ) );
- addList( tr_variantDictAddList( args, "fields", 0 ), getStatKeys( ) );
+ tr_variantDictAddQuark( &top, TR_KEY_method, TR_KEY_torrent_get );
+ tr_variantDictAddInt( &top, TR_KEY_tag, TAG_ALL_TORRENTS );
+ tr_variant * args( tr_variantDictAddDict( &top, TR_KEY_arguments, 1 ) );
+ addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys( ) );
exec( &top );
tr_variantFree( &top );
}
const int tag( ids.isEmpty() ? TAG_ALL_TORRENTS : TAG_SOME_TORRENTS );
tr_variant * args( buildRequest( "torrent-get", top, tag ) );
addOptionalIds( args, ids );
- addList( tr_variantDictAddList( args, "fields", 0 ), getStatKeys()+getInfoKeys() );
+ addList( tr_variantDictAddList( args, TR_KEY_fields, 0 ), getStatKeys()+getInfoKeys() );
exec( &top );
tr_variantFree( &top );
}
{
tr_variant top;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "session-stats" );
- tr_variantDictAddInt( &top, "tag", TAG_SESSION_STATS );
+ tr_variantDictAddStr( &top, TR_KEY_method, "session-stats" );
+ tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SESSION_STATS );
exec( &top );
tr_variantFree( &top );
}
{
tr_variant top;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "session-get" );
- tr_variantDictAddInt( &top, "tag", TAG_SESSION_INFO );
+ tr_variantDictAddStr( &top, TR_KEY_method, "session-get" );
+ tr_variantDictAddInt( &top, TR_KEY_tag, TAG_SESSION_INFO );
exec( &top );
tr_variantFree( &top );
}
{
tr_variant top;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "blocklist-update" );
- tr_variantDictAddInt( &top, "tag", TAG_BLOCKLIST_UPDATE );
+ tr_variantDictAddStr( &top, TR_KEY_method, "blocklist-update" );
+ tr_variantDictAddInt( &top, TR_KEY_tag, TAG_BLOCKLIST_UPDATE );
exec( &top );
tr_variantFree( &top );
}
const char * result = NULL;
tr_variant * args = NULL;
- tr_variantDictFindInt ( &top, "tag", &tag );
- tr_variantDictFindStr ( &top, "result", &result, NULL );
- tr_variantDictFindDict( &top, "arguments", &args );
+ tr_variantDictFindInt ( &top, TR_KEY_tag, &tag );
+ tr_variantDictFindStr ( &top, TR_KEY_result, &result, NULL );
+ tr_variantDictFindDict( &top, TR_KEY_arguments, &args );
emit executed( tag, result, args );
tr_variant * torrents;
const char * str;
- if( tr_variantDictFindInt( &top, "tag", &tag ) )
+ if( tr_variantDictFindInt( &top, TR_KEY_tag, &tag ) )
{
switch( tag )
{
case TAG_SOME_TORRENTS:
case TAG_ALL_TORRENTS:
- if( tr_variantDictFindDict( &top, "arguments", &args ) ) {
- if( tr_variantDictFindList( args, "torrents", &torrents ) )
+ if( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ) ) {
+ if( tr_variantDictFindList( args, TR_KEY_torrents, &torrents ) )
emit torrentsUpdated( torrents, tag==TAG_ALL_TORRENTS );
- if( tr_variantDictFindList( args, "removed", &torrents ) )
+ if( tr_variantDictFindList( args, TR_KEY_removed, &torrents ) )
emit torrentsRemoved( torrents );
}
break;
case TAG_SESSION_STATS:
- if( tr_variantDictFindDict( &top, "arguments", &args ) )
+ if( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ) )
updateStats( args );
break;
case TAG_SESSION_INFO:
- if( tr_variantDictFindDict( &top, "arguments", &args ) )
+ if( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ) )
updateInfo( args );
break;
case TAG_BLOCKLIST_UPDATE: {
int64_t intVal = 0;
- if( tr_variantDictFindDict( &top, "arguments", &args ) )
- if( tr_variantDictFindInt( args, "blocklist-size", &intVal ) )
+ if( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ) )
+ if( tr_variantDictFindInt( args, TR_KEY_blocklist_size, &intVal ) )
setBlocklistSize( intVal );
break;
}
case TAG_PORT_TEST: {
bool isOpen = 0;
- if( tr_variantDictFindDict( &top, "arguments", &args ) )
- tr_variantDictFindBool( args, "port-is-open", &isOpen );
+ if( tr_variantDictFindDict( &top, TR_KEY_arguments, &args ) )
+ tr_variantDictFindBool( args, TR_KEY_port_is_open, &isOpen );
emit portTested( (bool)isOpen );
}
tr_variant * torrents;
tr_variant * child;
const char * str;
- if( tr_variantDictFindDict( &top, "arguments", &args )
- && tr_variantDictFindList( args, "torrents", &torrents )
+ if( tr_variantDictFindDict( &top, TR_KEY_arguments, &args )
+ && tr_variantDictFindList( args, TR_KEY_torrents, &torrents )
&& (( child = tr_variantListChild( torrents, 0 )))
- && tr_variantDictFindStr( child, "magnetLink", &str, NULL ) )
+ && tr_variantDictFindStr( child, TR_KEY_magnetLink, &str, NULL ) )
QApplication::clipboard()->setText( str );
break;
}
case TAG_ADD_TORRENT:
str = "";
- if( tr_variantDictFindStr( &top, "result", &str, NULL ) && strcmp( str, "success" ) ) {
+ if( tr_variantDictFindStr( &top, TR_KEY_result, &str, NULL ) && strcmp( str, "success" ) ) {
QMessageBox * d = new QMessageBox( QMessageBox::Information,
tr( "Add Torrent" ),
QString::fromUtf8(str),
{
int64_t i;
- if( tr_variantDictFindInt( d, "uploadedBytes", &i ) )
+ if( tr_variantDictFindInt( d, TR_KEY_uploadedBytes, &i ) )
stats->uploadedBytes = i;
- if( tr_variantDictFindInt( d, "downloadedBytes", &i ) )
+ if( tr_variantDictFindInt( d, TR_KEY_downloadedBytes, &i ) )
stats->downloadedBytes = i;
- if( tr_variantDictFindInt( d, "filesAdded", &i ) )
+ if( tr_variantDictFindInt( d, TR_KEY_filesAdded, &i ) )
stats->filesAdded = i;
- if( tr_variantDictFindInt( d, "sessionCount", &i ) )
+ if( tr_variantDictFindInt( d, TR_KEY_sessionCount, &i ) )
stats->sessionCount = i;
- if( tr_variantDictFindInt( d, "secondsActive", &i ) )
+ if( tr_variantDictFindInt( d, TR_KEY_secondsActive, &i ) )
stats->secondsActive = i;
stats->ratio = tr_getRatio( stats->uploadedBytes, stats->downloadedBytes );
{
tr_variant * c;
- if( tr_variantDictFindDict( d, "current-stats", &c ) )
+ if( tr_variantDictFindDict( d, TR_KEY_current_stats, &c ) )
updateStats( c, &myStats );
- if( tr_variantDictFindDict( d, "cumulative-stats", &c ) )
+ if( tr_variantDictFindDict( d, TR_KEY_cumulative_stats, &c ) )
updateStats( c, &myCumulativeStats );
emit statsUpdated( );
}
void
-Session :: updateInfo( tr_variant * d )
+Session :: updateInfo (tr_variant * d)
{
- int64_t i;
- const char * str;
- disconnect( &myPrefs, SIGNAL(changed(int)), this, SLOT(updatePref(int)) );
+ int64_t i;
+ const char * str;
+
+ disconnect (&myPrefs, SIGNAL(changed(int)), this, SLOT(updatePref(int)));
- for( int i=Prefs::FIRST_CORE_PREF; i<=Prefs::LAST_CORE_PREF; ++i )
+ for (int i=Prefs::FIRST_CORE_PREF; i<=Prefs::LAST_CORE_PREF; ++i)
{
- const tr_variant * b( tr_variantDictFind( d, myPrefs.keyStr( i ) ) );
+ const tr_variant * b( tr_variantDictFind (d, myPrefs.getKey(i)));
- if( !b )
- continue;
+ if (!b)
+ continue;
- if( i == Prefs :: ENCRYPTION )
+ if (i == Prefs :: ENCRYPTION)
{
- const char * val;
- if( tr_variantGetStr( b, &val, NULL ) )
+ const char * val;
+ if( tr_variantGetStr( b, &val, NULL ) )
{
- if( !qstrcmp( val , "required" ) )
- myPrefs.set( i, 2 );
- else if( !qstrcmp( val , "preferred" ) )
- myPrefs.set( i, 1 );
- else if( !qstrcmp( val , "tolerated" ) )
- myPrefs.set( i, 0 );
+ if( !qstrcmp( val , "required" ) )
+ myPrefs.set( i, 2 );
+ else if( !qstrcmp( val , "preferred" ) )
+ myPrefs.set( i, 1 );
+ else if( !qstrcmp( val , "tolerated" ) )
+ myPrefs.set( i, 0 );
}
- continue;
+ continue;
}
switch( myPrefs.type( i ) )
bool b;
double x;
- if( tr_variantDictFindBool( d, "seedRatioLimited", &b ) )
+ if( tr_variantDictFindBool( d, TR_KEY_seedRatioLimited, &b ) )
myPrefs.set( Prefs::RATIO_ENABLED, b ? true : false );
- if( tr_variantDictFindReal( d, "seedRatioLimit", &x ) )
+ if( tr_variantDictFindReal( d, TR_KEY_seedRatioLimit, &x ) )
myPrefs.set( Prefs::RATIO, x );
/* Use the C API to get settings that, for security reasons, aren't supported by RPC */
myPrefs.set( Prefs::RPC_WHITELIST, tr_sessionGetRPCWhitelist ( mySession ) );
}
- if( tr_variantDictFindInt( d, "blocklist-size", &i ) && i!=blocklistSize( ) )
+ if( tr_variantDictFindInt( d, TR_KEY_blocklist_size, &i ) && i!=blocklistSize( ) )
setBlocklistSize( i );
- if( tr_variantDictFindStr( d, "version", &str, NULL ) && ( mySessionVersion != str ) )
+ if( tr_variantDictFindStr( d, TR_KEY_version, &str, NULL ) && ( mySessionVersion != str ) )
mySessionVersion = str;
//std::cerr << "Session :: updateInfo end" << std::endl;
tr_variant top, *args;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "torrent-add" );
- args = tr_variantDictAddDict( &top, "arguments", 2 );
- tr_variantDictAddBool( args, "paused", !myPrefs.getBool( Prefs::START ) );
+ tr_variantDictAddStr( &top, TR_KEY_method, "torrent-add" );
+ args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 );
+ tr_variantDictAddBool( args, TR_KEY_paused, !myPrefs.getBool( Prefs::START ) );
switch( addMe.type ) {
- case AddData::MAGNET: tr_variantDictAddStr( args, "filename", addMe.magnet.toUtf8().constData() ); break;
- case AddData::URL: tr_variantDictAddStr( args, "filename", addMe.url.toString().toUtf8().constData() ); break;
+ case AddData::MAGNET: tr_variantDictAddStr( args, TR_KEY_filename, addMe.magnet.toUtf8().constData() ); break;
+ case AddData::URL: tr_variantDictAddStr( args, TR_KEY_filename, addMe.url.toString().toUtf8().constData() ); break;
case AddData::FILENAME: /* fall-through */
- case AddData::METAINFO: tr_variantDictAddRaw( args, "metainfo", b64.constData(), b64.size() ); break;
+ case AddData::METAINFO: tr_variantDictAddRaw( args, TR_KEY_metainfo, b64.constData(), b64.size() ); break;
default: std::cerr << "Unhandled AddData type: " << addMe.type << std::endl;
}
exec( &top );
tr_variant top, *args;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "torrent-add" );
- args = tr_variantDictAddDict( &top, "arguments", 3 );
- tr_variantDictAddStr( args, "download-dir", qPrintable(localPath) );
- tr_variantDictAddBool( args, "paused", !myPrefs.getBool( Prefs::START ) );
- tr_variantDictAddRaw( args, "metainfo", b64.constData(), b64.size() );
+ tr_variantDictAddStr( &top, TR_KEY_method, "torrent-add" );
+ args = tr_variantDictAddDict( &top, TR_KEY_arguments, 3 );
+ tr_variantDictAddStr( args, TR_KEY_download_dir, qPrintable(localPath) );
+ tr_variantDictAddBool( args, TR_KEY_paused, !myPrefs.getBool( Prefs::START ) );
+ tr_variantDictAddRaw( args, TR_KEY_metainfo, b64.constData(), b64.size() );
exec( &top );
tr_variantFree( &top );
}
{
tr_variant top, *args;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "torrent-remove" );
- args = tr_variantDictAddDict( &top, "arguments", 2 );
+ tr_variantDictAddStr( &top, TR_KEY_method, "torrent-remove" );
+ args = tr_variantDictAddDict( &top, TR_KEY_arguments, 2 );
addOptionalIds( args, ids );
- tr_variantDictAddInt( args, "delete-local-data", deleteFiles );
+ tr_variantDictAddInt( args, TR_KEY_delete_local_data, deleteFiles );
exec( &top );
tr_variantFree( &top );
}
{
tr_variant top, *args;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "torrent-verify" );
- args = tr_variantDictAddDict( &top, "arguments", 1 );
+ tr_variantDictAddStr( &top, TR_KEY_method, "torrent-verify" );
+ args = tr_variantDictAddDict( &top, TR_KEY_arguments, 1 );
addOptionalIds( args, ids );
exec( &top );
tr_variantFree( &top );
{
tr_variant top, *args;
tr_variantInitDict( &top, 2 );
- tr_variantDictAddStr( &top, "method", "torrent-reannounce" );
- args = tr_variantDictAddDict( &top, "arguments", 1 );
+ tr_variantDictAddStr( &top, TR_KEY_method, "torrent-reannounce" );
+ args = tr_variantDictAddDict( &top, TR_KEY_arguments, 1 );
addOptionalIds( args, ids );
exec( &top );
tr_variantFree( &top );
class AddData;
#include <libtransmission/transmission.h>
+#include <libtransmission/quark.h>
extern "C"
{
int64_t getUniqueTag( ) { return nextUniqueTag++; }
private:
- void sessionSet( const char * key, const QVariant& variant );
+ void sessionSet( const tr_quark key, const QVariant& variant );
void pumpRequests( );
void sendTorrentRequest( const char * request, const QSet<int>& torrentIds );
static void updateStats( struct tr_variant * d, struct tr_session_stats * stats );
QNetworkAccessManager * networkAccessManager( );
public:
- void torrentSet( const QSet<int>& ids, const QString& key, bool val );
- void torrentSet( const QSet<int>& ids, const QString& key, int val );
- void torrentSet( const QSet<int>& ids, const QString& key, double val );
- void torrentSet( const QSet<int>& ids, const QString& key, const QList<int>& val );
- void torrentSet( const QSet<int>& ids, const QString& key, const QStringList& val );
- void torrentSet( const QSet<int>& ids, const QString& key, const QPair<int,QString>& val);
+ void torrentSet( const QSet<int>& ids, const tr_quark key, bool val );
+ void torrentSet( const QSet<int>& ids, const tr_quark key, int val );
+ void torrentSet( const QSet<int>& ids, const tr_quark key, double val );
+ void torrentSet( const QSet<int>& ids, const tr_quark key, const QList<int>& val );
+ void torrentSet( const QSet<int>& ids, const tr_quark key, const QStringList& val );
+ void torrentSet( const QSet<int>& ids, const tr_quark key, const QPair<int,QString>& val);
void torrentSetLocation( const QSet<int>& ids, const QString& path, bool doMove );
while(( child = tr_variantListChild( torrents, i++ )))
{
int64_t id;
- if( tr_variantDictFindInt( child, "id", &id ) )
+ if( tr_variantDictFindInt( child, TR_KEY_id, &id ) )
{
newIds.insert( id );
#include "utils.h"
-Torrent :: Torrent( Prefs& prefs, int id ):
- magnetTorrent( false ),
- myPrefs( prefs )
+Torrent :: Torrent (Prefs& prefs, int id):
+ magnetTorrent (false),
+ myPrefs (prefs)
{
- for( int i=0; i<PROPERTY_COUNT; ++i )
- assert( myProperties[i].id == i );
+#ifndef NDEBUG
+ for (int i=0; i<PROPERTY_COUNT; ++i)
+ assert (myProperties[i].id == i);
+#endif
- setInt( ID, id );
- setIcon( MIME_ICON, QApplication::style()->standardIcon( QStyle::SP_FileIcon ) );
+ setInt (ID, id);
+ setIcon (MIME_ICON, QApplication::style()->standardIcon (QStyle::SP_FileIcon));
}
-Torrent :: ~Torrent( )
+Torrent :: ~Torrent ()
{
}
Torrent :: Property
Torrent :: myProperties[] =
{
- { ID, "id", QVariant::Int, INFO, },
- { UPLOAD_SPEED, "rateUpload", QVariant::ULongLong, STAT } /* Bps */,
- { DOWNLOAD_SPEED, "rateDownload", QVariant::ULongLong, STAT }, /* Bps */
- { DOWNLOAD_DIR, "downloadDir", QVariant::String, STAT },
- { ACTIVITY, "status", QVariant::Int, STAT },
- { NAME, "name", QVariant::String, INFO },
- { ERROR, "error", QVariant::Int, STAT },
- { ERROR_STRING, "errorString", QVariant::String, STAT },
- { SIZE_WHEN_DONE, "sizeWhenDone", QVariant::ULongLong, STAT },
- { LEFT_UNTIL_DONE, "leftUntilDone", QVariant::ULongLong, STAT },
- { HAVE_UNCHECKED, "haveUnchecked", QVariant::ULongLong, STAT },
- { HAVE_VERIFIED, "haveValid", QVariant::ULongLong, STAT },
- { DESIRED_AVAILABLE, "desiredAvailable", QVariant::ULongLong, STAT },
- { TOTAL_SIZE, "totalSize", QVariant::ULongLong, INFO },
- { PIECE_SIZE, "pieceSize", QVariant::ULongLong, INFO },
- { PIECE_COUNT, "pieceCount", QVariant::Int, INFO },
- { PEERS_GETTING_FROM_US, "peersGettingFromUs", QVariant::Int, STAT },
- { PEERS_SENDING_TO_US, "peersSendingToUs", QVariant::Int, STAT },
- { WEBSEEDS_SENDING_TO_US, "webseedsSendingToUs", QVariant::Int, STAT_EXTRA },
- { PERCENT_DONE, "percentDone", QVariant::Double, STAT },
- { METADATA_PERCENT_DONE, "metadataPercentComplete", QVariant::Double, STAT },
- { PERCENT_VERIFIED, "recheckProgress", QVariant::Double, STAT },
- { DATE_ACTIVITY, "activityDate", QVariant::DateTime, STAT_EXTRA },
- { DATE_ADDED, "addedDate", QVariant::DateTime, INFO },
- { DATE_STARTED, "startDate", QVariant::DateTime, STAT_EXTRA },
- { DATE_CREATED, "dateCreated", QVariant::DateTime, INFO },
- { PEERS_CONNECTED, "peersConnected", QVariant::Int, STAT },
- { ETA, "eta", QVariant::Int, STAT },
- { RATIO, "uploadRatio", QVariant::Double, STAT },
- { DOWNLOADED_EVER, "downloadedEver", QVariant::ULongLong, STAT },
- { UPLOADED_EVER, "uploadedEver", QVariant::ULongLong, STAT },
- { FAILED_EVER, "corruptEver", QVariant::ULongLong, STAT_EXTRA },
- { TRACKERS, "trackers", QVariant::StringList, STAT },
- { TRACKERSTATS, "trackerStats", TrTypes::TrackerStatsList, STAT_EXTRA },
- { MIME_ICON, "ccc", QVariant::Icon, DERIVED },
- { SEED_RATIO_LIMIT, "seedRatioLimit", QVariant::Double, STAT },
- { SEED_RATIO_MODE, "seedRatioMode", QVariant::Int, STAT },
- { SEED_IDLE_LIMIT, "seedIdleLimit", QVariant::Int, STAT_EXTRA },
- { SEED_IDLE_MODE, "seedIdleMode", QVariant::Int, STAT_EXTRA },
- { DOWN_LIMIT, "downloadLimit", QVariant::Int, STAT_EXTRA }, /* KB/s */
- { DOWN_LIMITED, "downloadLimited", QVariant::Bool, STAT_EXTRA },
- { UP_LIMIT, "uploadLimit", QVariant::Int, STAT_EXTRA }, /* KB/s */
- { UP_LIMITED, "uploadLimited", QVariant::Bool, STAT_EXTRA },
- { HONORS_SESSION_LIMITS, "honorsSessionLimits", QVariant::Bool, STAT_EXTRA },
- { PEER_LIMIT, "peer-limit", QVariant::Int, STAT_EXTRA },
- { HASH_STRING, "hashString", QVariant::String, INFO },
- { IS_FINISHED, "isFinished", QVariant::Bool, STAT },
- { IS_PRIVATE, "isPrivate", QVariant::Bool, INFO },
- { IS_STALLED, "isStalled", QVariant::Bool, STAT },
- { COMMENT, "comment", QVariant::String, INFO },
- { CREATOR, "creator", QVariant::String, INFO },
- { MANUAL_ANNOUNCE_TIME, "manualAnnounceTime", QVariant::DateTime, STAT_EXTRA },
- { PEERS, "peers", TrTypes::PeerList, STAT_EXTRA },
- { TORRENT_FILE, "torrentFile", QVariant::String, STAT_EXTRA },
- { BANDWIDTH_PRIORITY, "bandwidthPriority", QVariant::Int, STAT_EXTRA },
- { QUEUE_POSITION, "queuePosition", QVariant::Int, STAT },
+ { ID, TR_KEY_id, QVariant::Int, INFO, },
+ { UPLOAD_SPEED, TR_KEY_rateUpload, QVariant::ULongLong, STAT } /* Bps */,
+ { DOWNLOAD_SPEED, TR_KEY_rateDownload, QVariant::ULongLong, STAT }, /* Bps */
+ { DOWNLOAD_DIR, TR_KEY_downloadDir, QVariant::String, STAT },
+ { ACTIVITY, TR_KEY_status, QVariant::Int, STAT },
+ { NAME, TR_KEY_name, QVariant::String, INFO },
+ { ERROR, TR_KEY_error, QVariant::Int, STAT },
+ { ERROR_STRING, TR_KEY_errorString, QVariant::String, STAT },
+ { SIZE_WHEN_DONE, TR_KEY_sizeWhenDone, QVariant::ULongLong, STAT },
+ { LEFT_UNTIL_DONE, TR_KEY_leftUntilDone, QVariant::ULongLong, STAT },
+ { HAVE_UNCHECKED, TR_KEY_haveUnchecked, QVariant::ULongLong, STAT },
+ { HAVE_VERIFIED, TR_KEY_haveValid, QVariant::ULongLong, STAT },
+ { DESIRED_AVAILABLE, TR_KEY_desiredAvailable, QVariant::ULongLong, STAT },
+ { TOTAL_SIZE, TR_KEY_totalSize, QVariant::ULongLong, INFO },
+ { PIECE_SIZE, TR_KEY_pieceSize, QVariant::ULongLong, INFO },
+ { PIECE_COUNT, TR_KEY_pieceCount, QVariant::Int, INFO },
+ { PEERS_GETTING_FROM_US, TR_KEY_peersGettingFromUs, QVariant::Int, STAT },
+ { PEERS_SENDING_TO_US, TR_KEY_peersSendingToUs, QVariant::Int, STAT },
+ { WEBSEEDS_SENDING_TO_US, TR_KEY_webseedsSendingToUs, QVariant::Int, STAT_EXTRA },
+ { PERCENT_DONE, TR_KEY_percentDone, QVariant::Double, STAT },
+ { METADATA_PERCENT_DONE, TR_KEY_metadataPercentComplete, QVariant::Double, STAT },
+ { PERCENT_VERIFIED, TR_KEY_recheckProgress, QVariant::Double, STAT },
+ { DATE_ACTIVITY, TR_KEY_activityDate, QVariant::DateTime, STAT_EXTRA },
+ { DATE_ADDED, TR_KEY_addedDate, QVariant::DateTime, INFO },
+ { DATE_STARTED, TR_KEY_startDate, QVariant::DateTime, STAT_EXTRA },
+ { DATE_CREATED, TR_KEY_dateCreated, QVariant::DateTime, INFO },
+ { PEERS_CONNECTED, TR_KEY_peersConnected, QVariant::Int, STAT },
+ { ETA, TR_KEY_eta, QVariant::Int, STAT },
+ { RATIO, TR_KEY_uploadRatio, QVariant::Double, STAT },
+ { DOWNLOADED_EVER, TR_KEY_downloadedEver, QVariant::ULongLong, STAT },
+ { UPLOADED_EVER, TR_KEY_uploadedEver, QVariant::ULongLong, STAT },
+ { FAILED_EVER, TR_KEY_corruptEver, QVariant::ULongLong, STAT_EXTRA },
+ { TRACKERS, TR_KEY_trackers, QVariant::StringList, STAT },
+ { TRACKERSTATS, TR_KEY_trackerStats, TrTypes::TrackerStatsList, STAT_EXTRA },
+ { MIME_ICON, TR_KEY_NONE, QVariant::Icon, DERIVED },
+ { SEED_RATIO_LIMIT, TR_KEY_seedRatioLimit, QVariant::Double, STAT },
+ { SEED_RATIO_MODE, TR_KEY_seedRatioMode, QVariant::Int, STAT },
+ { SEED_IDLE_LIMIT, TR_KEY_seedIdleLimit, QVariant::Int, STAT_EXTRA },
+ { SEED_IDLE_MODE, TR_KEY_seedIdleMode, QVariant::Int, STAT_EXTRA },
+ { DOWN_LIMIT, TR_KEY_downloadLimit, QVariant::Int, STAT_EXTRA }, /* KB/s */
+ { DOWN_LIMITED, TR_KEY_downloadLimited, QVariant::Bool, STAT_EXTRA },
+ { UP_LIMIT, TR_KEY_uploadLimit, QVariant::Int, STAT_EXTRA }, /* KB/s */
+ { UP_LIMITED, TR_KEY_uploadLimited, QVariant::Bool, STAT_EXTRA },
+ { HONORS_SESSION_LIMITS, TR_KEY_honorsSessionLimits, QVariant::Bool, STAT_EXTRA },
+ { PEER_LIMIT, TR_KEY_peer_limit, QVariant::Int, STAT_EXTRA },
+ { HASH_STRING, TR_KEY_hashString, QVariant::String, INFO },
+ { IS_FINISHED, TR_KEY_isFinished, QVariant::Bool, STAT },
+ { IS_PRIVATE, TR_KEY_isPrivate, QVariant::Bool, INFO },
+ { IS_STALLED, TR_KEY_isStalled, QVariant::Bool, STAT },
+ { COMMENT, TR_KEY_comment, QVariant::String, INFO },
+ { CREATOR, TR_KEY_creator, QVariant::String, INFO },
+ { MANUAL_ANNOUNCE_TIME, TR_KEY_manualAnnounceTime, QVariant::DateTime, STAT_EXTRA },
+ { PEERS, TR_KEY_peers, TrTypes::PeerList, STAT_EXTRA },
+ { TORRENT_FILE, TR_KEY_torrentFile, QVariant::String, STAT_EXTRA },
+ { BANDWIDTH_PRIORITY, TR_KEY_bandwidthPriority, QVariant::Int, STAT_EXTRA },
+ { QUEUE_POSITION, TR_KEY_queuePosition, QVariant::Int, STAT },
};
Torrent :: KeyList
-Torrent :: buildKeyList( Group group )
+Torrent :: buildKeyList (Group group)
{
- KeyList keys;
+ KeyList keys;
- if( keys.empty( ) )
- for( int i=0; i<PROPERTY_COUNT; ++i )
- if( myProperties[i].id==ID || myProperties[i].group==group )
- keys << myProperties[i].key;
+ if (keys.empty())
+ for (int i=0; i<PROPERTY_COUNT; ++i)
+ if (myProperties[i].id==ID || myProperties[i].group==group)
+ keys << myProperties[i].key;
- return keys;
+ return keys;
}
const Torrent :: KeyList&
-Torrent :: getInfoKeys( )
+Torrent :: getInfoKeys ()
{
- static KeyList keys;
- if( keys.isEmpty( ) )
- keys << buildKeyList( INFO ) << "files";
- return keys;
+ static KeyList keys;
+
+ if (keys.isEmpty())
+ keys << buildKeyList(INFO) << TR_KEY_files;
+
+ return keys;
}
const Torrent :: KeyList&
-Torrent :: getStatKeys( )
+Torrent :: getStatKeys ()
{
- static KeyList keys( buildKeyList( STAT ) );
- return keys;
+ static KeyList keys (buildKeyList(STAT));
+ return keys;
}
const Torrent :: KeyList&
-Torrent :: getExtraStatKeys( )
+Torrent :: getExtraStatKeys()
{
- static KeyList keys;
- if( keys.isEmpty( ) )
- keys << buildKeyList( STAT_EXTRA ) << "fileStats";
- return keys;
-}
+ static KeyList keys;
+ if (keys.isEmpty())
+ keys << buildKeyList(STAT_EXTRA) << TR_KEY_fileStats;
+
+ return keys;
+}
bool
-Torrent :: setInt( int i, int value )
+Torrent :: setInt (int i, int value)
{
- bool changed = false;
+ bool changed = false;
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::Int );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::Int);
- if( myValues[i].isNull() || myValues[i].toInt()!=value )
+ if (myValues[i].isNull() || myValues[i].toInt()!=value)
{
- myValues[i].setValue( value );
- changed = true;
+ myValues[i].setValue (value);
+ changed = true;
}
- return changed;
+ return changed;
}
bool
-Torrent :: setBool( int i, bool value )
+Torrent :: setBool (int i, bool value)
{
- bool changed = false;
+ bool changed = false;
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::Bool );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::Bool);
- if( myValues[i].isNull() || myValues[i].toBool()!=value )
+ if (myValues[i].isNull() || myValues[i].toBool()!=value)
{
- myValues[i].setValue( value );
- changed = true;
+ myValues[i].setValue (value);
+ changed = true;
}
- return changed;
+ return changed;
}
bool
-Torrent :: setDouble( int i, double value )
+Torrent :: setDouble (int i, double value)
{
- bool changed = false;
+ bool changed = false;
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::Double );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::Double);
- if( myValues[i].isNull() || myValues[i].toDouble()!=value )
+ if (myValues[i].isNull() || myValues[i].toDouble()!=value)
{
- myValues[i].setValue( value );
- changed = true;
+ myValues[i].setValue (value);
+ changed = true;
}
- return changed;
+ return changed;
}
bool
-Torrent :: setDateTime( int i, const QDateTime& value )
+Torrent :: setDateTime (int i, const QDateTime& value)
{
- bool changed = false;
+ bool changed = false;
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::DateTime );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::DateTime);
- if( myValues[i].isNull() || myValues[i].toDateTime()!=value )
+ if (myValues[i].isNull() || myValues[i].toDateTime()!=value)
{
- myValues[i].setValue( value );
- changed = true;
+ myValues[i].setValue (value);
+ changed = true;
}
- return changed;
+ return changed;
}
bool
-Torrent :: setSize( int i, qulonglong value )
+Torrent :: setSize (int i, qulonglong value)
{
- bool changed = false;
+ bool changed = false;
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::ULongLong );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::ULongLong);
- if( myValues[i].isNull() || myValues[i].toULongLong()!=value )
+ if (myValues[i].isNull() || myValues[i].toULongLong()!=value)
{
- myValues[i].setValue( value );
- changed = true;
+ myValues[i].setValue (value);
+ changed = true;
}
- return changed;
+ return changed;
}
bool
-Torrent :: setString( int i, const char * value )
+Torrent :: setString (int i, const char * value)
{
- bool changed = false;
+ bool changed = false;
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::String );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::String);
- if( myValues[i].isNull() || myValues[i].toString()!=value )
+ if (myValues[i].isNull() || myValues[i].toString()!=value)
{
- myValues[i].setValue( QString::fromUtf8( value ) );
- changed = true;
+ myValues[i].setValue (QString::fromUtf8 (value));
+ changed = true;
}
- return changed;
+ return changed;
}
bool
-Torrent :: setIcon( int i, const QIcon& value )
+Torrent :: setIcon (int i, const QIcon& value)
{
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::Icon );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::Icon);
- myValues[i].setValue( value );
- return true;
+ myValues[i].setValue (value);
+ return true;
}
int
-Torrent :: getInt( int i ) const
+Torrent :: getInt (int i) const
{
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::Int );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::Int);
- return myValues[i].toInt( );
+ return myValues[i].toInt ();
}
QDateTime
-Torrent :: getDateTime( int i ) const
+Torrent :: getDateTime (int i) const
{
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::DateTime );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::DateTime);
- return myValues[i].toDateTime( );
+ return myValues[i].toDateTime ();
}
bool
-Torrent :: getBool( int i ) const
+Torrent :: getBool (int i) const
{
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::Bool );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::Bool);
- return myValues[i].toBool( );
+ return myValues[i].toBool ();
}
qulonglong
-Torrent :: getSize( int i ) const
+Torrent :: getSize (int i) const
{
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::ULongLong );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::ULongLong);
- return myValues[i].toULongLong( );
+ return myValues[i].toULongLong ();
}
double
-Torrent :: getDouble( int i ) const
+Torrent :: getDouble (int i) const
{
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::Double );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::Double);
- return myValues[i].toDouble( );
+ return myValues[i].toDouble ();
}
QString
-Torrent :: getString( int i ) const
+Torrent :: getString (int i) const
{
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::String );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::String);
- return myValues[i].toString( );
+ return myValues[i].toString ();
}
QIcon
-Torrent :: getIcon( int i ) const
+Torrent :: getIcon (int i) const
{
- assert( 0<=i && i<PROPERTY_COUNT );
- assert( myProperties[i].type == QVariant::Icon );
+ assert (0<=i && i<PROPERTY_COUNT);
+ assert (myProperties[i].type == QVariant::Icon);
- return myValues[i].value<QIcon>();
+ return myValues[i].value<QIcon>();
}
/***
***/
bool
-Torrent :: getSeedRatio( double& ratio ) const
+Torrent :: getSeedRatio (double& ratio) const
{
- bool isLimited;
+ bool isLimited;
- switch( seedRatioMode( ) )
+ switch (seedRatioMode ())
{
- case TR_RATIOLIMIT_SINGLE:
- isLimited = true;
- ratio = seedRatioLimit( );
- break;
-
- case TR_RATIOLIMIT_GLOBAL:
- if(( isLimited = myPrefs.getBool( Prefs :: RATIO_ENABLED )))
- ratio = myPrefs.getDouble( Prefs :: RATIO );
- break;
-
- default: // TR_RATIOLIMIT_UNLIMITED:
- isLimited = false;
- break;
+ case TR_RATIOLIMIT_SINGLE:
+ isLimited = true;
+ ratio = seedRatioLimit ();
+ break;
+
+ case TR_RATIOLIMIT_GLOBAL:
+ if ((isLimited = myPrefs.getBool (Prefs :: RATIO_ENABLED)))
+ ratio = myPrefs.getDouble (Prefs :: RATIO);
+ break;
+
+ default: // TR_RATIOLIMIT_UNLIMITED:
+ isLimited = false;
+ break;
}
- return isLimited;
+ return isLimited;
}
bool
-Torrent :: hasFileSubstring( const QString& substr ) const
+Torrent :: hasFileSubstring (const QString& substr) const
{
- foreach( const TrFile file, myFiles )
- if( file.filename.contains( substr, Qt::CaseInsensitive ) )
- return true;
- return false;
+ foreach (const TrFile file, myFiles)
+ if (file.filename.contains (substr, Qt::CaseInsensitive))
+ return true;
+
+ return false;
}
bool
-Torrent :: hasTrackerSubstring( const QString& substr ) const
+Torrent :: hasTrackerSubstring (const QString& substr) const
{
- foreach( QString s, myValues[TRACKERS].toStringList() )
- if( s.contains( substr, Qt::CaseInsensitive ) )
- return true;
- return false;
+ foreach (QString s, myValues[TRACKERS].toStringList())
+ if (s.contains (substr, Qt::CaseInsensitive))
+ return true;
+
+ return false;
}
int
-Torrent :: compareSeedRatio( const Torrent& that ) const
+Torrent :: compareSeedRatio (const Torrent& that) const
{
- double a;
- double b;
- const bool has_a = getSeedRatio( a );
- const bool has_b = that.getSeedRatio( b );
- if( !has_a && !has_b ) return 0;
- if( !has_a || !has_b ) return has_a ? -1 : 1;
- if( a < b ) return -1;
- if( a > b ) return 1;
- return 0;
+ double a;
+ double b;
+ const bool has_a = getSeedRatio (a);
+ const bool has_b = that.getSeedRatio (b);
+ if (!has_a && !has_b) return 0;
+ if (!has_a || !has_b) return has_a ? -1 : 1;
+ if (a < b) return -1;
+ if (a > b) return 1;
+ return 0;
}
int
-Torrent :: compareRatio( const Torrent& that ) const
+Torrent :: compareRatio (const Torrent& that) const
{
- const double a = ratio( );
- const double b = that.ratio( );
- if( (int)a == TR_RATIO_INF && (int)b == TR_RATIO_INF ) return 0;
- if( (int)a == TR_RATIO_INF ) return 1;
- if( (int)b == TR_RATIO_INF ) return -1;
- if( a < b ) return -1;
- if( a > b ) return 1;
- return 0;
+ const double a = ratio ();
+ const double b = that.ratio ();
+ if ((int)a == TR_RATIO_INF && (int)b == TR_RATIO_INF) return 0;
+ if ((int)a == TR_RATIO_INF) return 1;
+ if ((int)b == TR_RATIO_INF) return -1;
+ if (a < b) return -1;
+ if (a > b) return 1;
+ return 0;
}
int
-Torrent :: compareETA( const Torrent& that ) const
+Torrent :: compareETA (const Torrent& that) const
{
- const bool haveA( hasETA( ) );
- const bool haveB( that.hasETA( ) );
- if( haveA && haveB ) return getETA() - that.getETA();
- if( haveA ) return 1;
- if( haveB ) return -1;
- return 0;
+ const bool haveA (hasETA ());
+ const bool haveB (that.hasETA ());
+ if (haveA && haveB) return getETA() - that.getETA();
+ if (haveA) return 1;
+ if (haveB) return -1;
+ return 0;
}
int
-Torrent :: compareTracker( const Torrent& that ) const
+Torrent :: compareTracker (const Torrent& that) const
{
- Q_UNUSED( that );
+ Q_UNUSED (that);
- // FIXME
- return 0;
+ // FIXME
+ return 0;
}
/***
***/
void
-Torrent :: updateMimeIcon( )
+Torrent :: updateMimeIcon ()
{
- const FileList& files( myFiles );
+ const FileList& files (myFiles);
- QIcon icon;
+ QIcon icon;
- if( files.size( ) > 1 )
- icon = QFileIconProvider().icon( QFileIconProvider::Folder );
- else if( files.size( ) == 1 )
- icon = Utils :: guessMimeIcon( files.at(0).filename );
- else
- icon = QIcon( );
+ if (files.size () > 1)
+ icon = QFileIconProvider().icon (QFileIconProvider::Folder);
+ else if (files.size () == 1)
+ icon = Utils :: guessMimeIcon (files.at(0).filename);
+ else
+ icon = QIcon ();
- setIcon( MIME_ICON, icon );
+ setIcon (MIME_ICON, icon);
}
/***
***/
void
-Torrent :: notifyComplete( ) const
+Torrent :: notifyComplete () const
{
// if someone wants to implement notification, here's the hook.
}
***/
void
-Torrent :: update( tr_variant * d )
+Torrent :: update (tr_variant * d)
{
- bool changed = false;
- const bool was_seed = isSeed( );
- const uint64_t old_verified_size = haveVerified( );
+ static bool lookup_initialized = false;
+ static int key_to_property_index[TR_N_KEYS];
+ bool changed = false;
+ const bool was_seed = isSeed ();
+ const uint64_t old_verified_size = haveVerified ();
+
+ if (!lookup_initialized)
+ {
+ lookup_initialized = true;
+ for (int i=0; i<TR_N_KEYS; ++i)
+ key_to_property_index[i] = -1;
+ for (int i=0; i<PROPERTY_COUNT; i++)
+ key_to_property_index[myProperties[i].key] = i;
+ }
- for( int i=0; i<PROPERTY_COUNT; ++i )
+ tr_quark key;
+ tr_variant * child;
+ size_t pos = 0;
+ while (tr_variantDictChild (d, pos++, &key, &child))
{
- tr_variant * child = tr_variantDictFind( d, myProperties[i].key );
- if( !child )
- continue;
+ const int property_index = key_to_property_index[key];
+ if (property_index == -1) // we're not interested in this one
+ continue;
- switch( myProperties[i].type )
+ assert (myProperties[property_index].key == key);
+
+ switch (myProperties[property_index].type)
{
- case QVariant :: Int: {
- int64_t val;
- if( tr_variantGetInt( child, &val ) )
- changed |= setInt( i, val );
- break;
+ case QVariant :: Int:
+ {
+ int64_t val;
+ if (tr_variantGetInt (child, &val))
+ changed |= setInt (property_index, val);
+ break;
}
-
- case QVariant :: Bool: {
- bool val;
- if( tr_variantGetBool( child, &val ) )
- changed |= setBool( i, val );
- break;
+ case QVariant :: Bool:
+ {
+ bool val;
+ if (tr_variantGetBool (child, &val))
+ changed |= setBool (property_index, val);
+ break;
}
-
- case QVariant :: String: {
- const char * val;
- if( tr_variantGetStr( child, &val, NULL ) )
- changed |= setString( i, val );
- break;
+ case QVariant :: String:
+ {
+ const char * val;
+ if (tr_variantGetStr(child, &val, NULL))
+ changed |= setString (property_index, val);
+ break;
}
-
- case QVariant :: ULongLong: {
- int64_t val;
- if( tr_variantGetInt( child, &val ) )
- changed |= setSize( i, val );
- break;
+ case QVariant :: ULongLong:
+ {
+ int64_t val;
+ if (tr_variantGetInt (child, &val))
+ changed |= setSize (property_index, val);
+ break;
}
-
- case QVariant :: Double: {
- double val;
- if( tr_variantGetReal( child, &val ) )
- changed |= setDouble( i, val );
- break;
+ case QVariant :: Double:
+ {
+ double val;
+ if (tr_variantGetReal (child, &val))
+ changed |= setDouble (property_index, val);
+ break;
}
-
- case QVariant :: DateTime: {
- int64_t val;
- if( tr_variantGetInt( child, &val ) && val )
- changed |= setDateTime( i, QDateTime :: fromTime_t( val ) );
- break;
+ case QVariant :: DateTime:
+ {
+ int64_t val;
+ if (tr_variantGetInt (child, &val) && val)
+ changed |= setDateTime (property_index, QDateTime :: fromTime_t(val));
+ break;
}
- case QVariant :: StringList:
- case TrTypes :: PeerList:
- break;
+ case QVariant :: StringList:
+ case TrTypes :: PeerList:
+ // handled below
+ break;
- default:
- assert( 0 && "unhandled type" );
+ default:
+ std::cerr << __FILE__ << ':' << __LINE__ << "unhandled type: " << tr_quark_get_string(key,NULL) << std::endl;
+ assert (0 && "unhandled type");
}
}
- tr_variant * files;
-
- if( tr_variantDictFindList( d, "files", &files ) ) {
- const char * str;
- int64_t intVal;
- int i = 0;
- myFiles.clear( );
- tr_variant * child;
- while(( child = tr_variantListChild( files, i ))) {
- TrFile file;
- size_t len;
- file.index = i++;
- if( tr_variantDictFindStr( child, "name", &str, &len ) )
- file.filename = QString::fromUtf8( str, len );
- if( tr_variantDictFindInt( child, "length", &intVal ) )
- file.size = intVal;
- myFiles.append( file );
+ tr_variant * files;
+
+ if (tr_variantDictFindList (d, TR_KEY_files, &files))
+ {
+ const char * str;
+ int64_t intVal;
+ int i = 0;
+ tr_variant * child;
+
+ myFiles.clear ();
+
+ while ((child = tr_variantListChild (files, i)))
+ {
+ TrFile file;
+ size_t len;
+ file.index = i++;
+
+ if (tr_variantDictFindStr(child, TR_KEY_name, &str, &len))
+ file.filename = QString::fromUtf8 (str, len);
+ if (tr_variantDictFindInt (child, TR_KEY_length, &intVal))
+ file.size = intVal;
+
+ myFiles.append (file);
}
- updateMimeIcon( );
- changed = true;
+
+ updateMimeIcon ();
+ changed = true;
}
- if( tr_variantDictFindList( d, "fileStats", &files ) ) {
- const int n = tr_variantListSize( files );
- for( int i=0; i<n && i<myFiles.size(); ++i ) {
- int64_t intVal;
- bool boolVal;
- tr_variant * child = tr_variantListChild( files, i );
- TrFile& file( myFiles[i] );
- if( tr_variantDictFindInt( child, "bytesCompleted", &intVal ) )
- file.have = intVal;
- if( tr_variantDictFindBool( child, "wanted", &boolVal ) )
- file.wanted = boolVal;
- if( tr_variantDictFindInt( child, "priority", &intVal ) )
- file.priority = intVal;
+ if (tr_variantDictFindList (d, TR_KEY_fileStats, &files))
+ {
+ const int n = tr_variantListSize (files);
+
+ for (int i=0; i<n && i<myFiles.size(); ++i)
+ {
+ int64_t intVal;
+ bool boolVal;
+ tr_variant * child = tr_variantListChild (files, i);
+ TrFile& file (myFiles[i]);
+
+ if (tr_variantDictFindInt (child, TR_KEY_bytesCompleted, &intVal))
+ file.have = intVal;
+ if (tr_variantDictFindBool (child, TR_KEY_wanted, &boolVal))
+ file.wanted = boolVal;
+ if (tr_variantDictFindInt (child, TR_KEY_priority, &intVal))
+ file.priority = intVal;
}
changed = true;
}
- tr_variant * trackers;
- if( tr_variantDictFindList( d, "trackers", &trackers ) ) {
- size_t len;
- const char * str;
- int i = 0;
- QStringList list;
- tr_variant * child;
- while(( child = tr_variantListChild( trackers, i++ ))) {
- if( tr_variantDictFindStr( child, "announce", &str, &len )) {
- dynamic_cast<MyApp*>(QApplication::instance())->favicons.add( QUrl(QString::fromUtf8(str)) );
- list.append( QString::fromUtf8( str, len ) );
+ tr_variant * trackers;
+ if (tr_variantDictFindList (d, TR_KEY_trackers, &trackers))
+ {
+ size_t len;
+ const char * str;
+ int i = 0;
+ QStringList list;
+ tr_variant * child;
+
+ while ((child = tr_variantListChild (trackers, i++)))
+ {
+ if (tr_variantDictFindStr(child, TR_KEY_announce, &str, &len))
+ {
+ dynamic_cast<MyApp*>(QApplication::instance())->favicons.add (QUrl(QString::fromUtf8(str)));
+ list.append (QString::fromUtf8 (str, len));
}
}
- if( myValues[TRACKERS] != list ) {
- myValues[TRACKERS].setValue( list );
- changed = true;
+
+ if (myValues[TRACKERS] != list)
+ {
+ myValues[TRACKERS].setValue (list);
+ changed = true;
}
}
- tr_variant * trackerStats;
- if( tr_variantDictFindList( d, "trackerStats", &trackerStats ) ) {
- tr_variant * child;
- TrackerStatsList trackerStatsList;
- int childNum = 0;
- while(( child = tr_variantListChild( trackerStats, childNum++ ))) {
- bool b;
- int64_t i;
- size_t len;
- const char * str;
- TrackerStat trackerStat;
- if( tr_variantDictFindStr( child, "announce", &str, &len ) ) {
- trackerStat.announce = QString::fromUtf8( str, len );
- dynamic_cast<MyApp*>(QApplication::instance())->favicons.add( QUrl( trackerStat.announce ) );
+ tr_variant * trackerStats;
+ if (tr_variantDictFindList (d, TR_KEY_trackerStats, &trackerStats))
+ {
+ tr_variant * child;
+ TrackerStatsList trackerStatsList;
+ int childNum = 0;
+
+ while ((child = tr_variantListChild (trackerStats, childNum++)))
+ {
+ bool b;
+ int64_t i;
+ size_t len;
+ const char * str;
+ TrackerStat trackerStat;
+
+ if (tr_variantDictFindStr(child, TR_KEY_announce, &str, &len))
+ {
+ trackerStat.announce = QString::fromUtf8 (str, len);
+ dynamic_cast<MyApp*>(QApplication::instance())->favicons.add (QUrl (trackerStat.announce));
}
- if( tr_variantDictFindInt( child, "announceState", &i ) )
- trackerStat.announceState = i;
- if( tr_variantDictFindInt( child, "downloadCount", &i ) )
- trackerStat.downloadCount = i;
- if( tr_variantDictFindBool( child, "hasAnnounced", &b ) )
- trackerStat.hasAnnounced = b;
- if( tr_variantDictFindBool( child, "hasScraped", &b ) )
- trackerStat.hasScraped = b;
- if( tr_variantDictFindStr( child, "host", &str, &len ) )
- trackerStat.host = QString::fromUtf8( str, len );
- if( tr_variantDictFindInt( child, "id", &i ) )
- trackerStat.id = i;
- if( tr_variantDictFindBool( child, "isBackup", &b ) )
- trackerStat.isBackup = b;
- if( tr_variantDictFindInt( child, "lastAnnouncePeerCount", &i ) )
- trackerStat.lastAnnouncePeerCount = i;
- if( tr_variantDictFindStr( child, "lastAnnounceResult", &str, &len ) )
- trackerStat.lastAnnounceResult = QString::fromUtf8(str, len);
- if( tr_variantDictFindInt( child, "lastAnnounceStartTime", &i ) )
- trackerStat.lastAnnounceStartTime = i;
- if( tr_variantDictFindBool( child, "lastAnnounceSucceeded", &b ) )
- trackerStat.lastAnnounceSucceeded = b;
- if( tr_variantDictFindInt( child, "lastAnnounceTime", &i ) )
- trackerStat.lastAnnounceTime = i;
- if( tr_variantDictFindBool( child, "lastAnnounceTimedOut", &b ) )
- trackerStat.lastAnnounceTimedOut = b;
- if( tr_variantDictFindStr( child, "lastScrapeResult", &str, &len ) )
- trackerStat.lastScrapeResult = QString::fromUtf8( str, len );
- if( tr_variantDictFindInt( child, "lastScrapeStartTime", &i ) )
- trackerStat.lastScrapeStartTime = i;
- if( tr_variantDictFindBool( child, "lastScrapeSucceeded", &b ) )
- trackerStat.lastScrapeSucceeded = b;
- if( tr_variantDictFindInt( child, "lastScrapeTime", &i ) )
- trackerStat.lastScrapeTime = i;
- if( tr_variantDictFindBool( child, "lastScrapeTimedOut", &b ) )
- trackerStat.lastScrapeTimedOut = b;
- if( tr_variantDictFindInt( child, "leecherCount", &i ) )
- trackerStat.leecherCount = i;
- if( tr_variantDictFindInt( child, "nextAnnounceTime", &i ) )
- trackerStat.nextAnnounceTime = i;
- if( tr_variantDictFindInt( child, "nextScrapeTime", &i ) )
- trackerStat.nextScrapeTime = i;
- if( tr_variantDictFindInt( child, "scrapeState", &i ) )
- trackerStat.scrapeState = i;
- if( tr_variantDictFindInt( child, "seederCount", &i ) )
- trackerStat.seederCount = i;
- if( tr_variantDictFindInt( child, "tier", &i ) )
- trackerStat.tier = i;
- trackerStatsList << trackerStat;
+
+ if (tr_variantDictFindInt (child, TR_KEY_announceState, &i))
+ trackerStat.announceState = i;
+ if (tr_variantDictFindInt (child, TR_KEY_downloadCount, &i))
+ trackerStat.downloadCount = i;
+ if (tr_variantDictFindBool (child, TR_KEY_hasAnnounced, &b))
+ trackerStat.hasAnnounced = b;
+ if (tr_variantDictFindBool (child, TR_KEY_hasScraped, &b))
+ trackerStat.hasScraped = b;
+ if (tr_variantDictFindStr(child, TR_KEY_host, &str, &len))
+ trackerStat.host = QString::fromUtf8 (str, len);
+ if (tr_variantDictFindInt (child, TR_KEY_id, &i))
+ trackerStat.id = i;
+ if (tr_variantDictFindBool (child, TR_KEY_isBackup, &b))
+ trackerStat.isBackup = b;
+ if (tr_variantDictFindInt (child, TR_KEY_lastAnnouncePeerCount, &i))
+ trackerStat.lastAnnouncePeerCount = i;
+ if (tr_variantDictFindStr(child, TR_KEY_lastAnnounceResult, &str, &len))
+ trackerStat.lastAnnounceResult = QString::fromUtf8(str, len);
+ if (tr_variantDictFindInt (child, TR_KEY_lastAnnounceStartTime, &i))
+ trackerStat.lastAnnounceStartTime = i;
+ if (tr_variantDictFindBool (child, TR_KEY_lastAnnounceSucceeded, &b))
+ trackerStat.lastAnnounceSucceeded = b;
+ if (tr_variantDictFindInt (child, TR_KEY_lastAnnounceTime, &i))
+ trackerStat.lastAnnounceTime = i;
+ if (tr_variantDictFindBool (child, TR_KEY_lastAnnounceTimedOut, &b))
+ trackerStat.lastAnnounceTimedOut = b;
+ if (tr_variantDictFindStr(child, TR_KEY_lastScrapeResult, &str, &len))
+ trackerStat.lastScrapeResult = QString::fromUtf8 (str, len);
+ if (tr_variantDictFindInt (child, TR_KEY_lastScrapeStartTime, &i))
+ trackerStat.lastScrapeStartTime = i;
+ if (tr_variantDictFindBool (child, TR_KEY_lastScrapeSucceeded, &b))
+ trackerStat.lastScrapeSucceeded = b;
+ if (tr_variantDictFindInt (child, TR_KEY_lastScrapeTime, &i))
+ trackerStat.lastScrapeTime = i;
+ if (tr_variantDictFindBool (child, TR_KEY_lastScrapeTimedOut, &b))
+ trackerStat.lastScrapeTimedOut = b;
+ if (tr_variantDictFindInt (child, TR_KEY_leecherCount, &i))
+ trackerStat.leecherCount = i;
+ if (tr_variantDictFindInt (child, TR_KEY_nextAnnounceTime, &i))
+ trackerStat.nextAnnounceTime = i;
+ if (tr_variantDictFindInt (child, TR_KEY_nextScrapeTime, &i))
+ trackerStat.nextScrapeTime = i;
+ if (tr_variantDictFindInt (child, TR_KEY_scrapeState, &i))
+ trackerStat.scrapeState = i;
+ if (tr_variantDictFindInt (child, TR_KEY_seederCount, &i))
+ trackerStat.seederCount = i;
+ if (tr_variantDictFindInt (child, TR_KEY_tier, &i))
+ trackerStat.tier = i;
+
+ trackerStatsList << trackerStat;
}
- myValues[TRACKERSTATS].setValue( trackerStatsList );
- changed = true;
+
+ myValues[TRACKERSTATS].setValue (trackerStatsList);
+ changed = true;
}
- tr_variant * peers;
- if( tr_variantDictFindList( d, "peers", &peers ) ) {
- tr_variant * child;
- PeerList peerList;
- int childNum = 0;
- while(( child = tr_variantListChild( peers, childNum++ ))) {
- double d;
- bool b;
- int64_t i;
- size_t len;
- const char * str;
- Peer peer;
- if( tr_variantDictFindStr( child, "address", &str, &len ) )
- peer.address = QString::fromUtf8( str, len );
- if( tr_variantDictFindStr( child, "clientName", &str, &len ) )
- peer.clientName = QString::fromUtf8( str, len );
- if( tr_variantDictFindBool( child, "clientIsChoked", &b ) )
- peer.clientIsChoked = b;
- if( tr_variantDictFindBool( child, "clientIsInterested", &b ) )
- peer.clientIsInterested = b;
- if( tr_variantDictFindStr( child, "flagStr", &str, &len ) )
- peer.flagStr = QString::fromUtf8( str, len );
- if( tr_variantDictFindBool( child, "isDownloadingFrom", &b ) )
- peer.isDownloadingFrom = b;
- if( tr_variantDictFindBool( child, "isEncrypted", &b ) )
- peer.isEncrypted = b;
- if( tr_variantDictFindBool( child, "isIncoming", &b ) )
- peer.isIncoming = b;
- if( tr_variantDictFindBool( child, "isUploadingTo", &b ) )
- peer.isUploadingTo = b;
- if( tr_variantDictFindBool( child, "peerIsChoked", &b ) )
- peer.peerIsChoked = b;
- if( tr_variantDictFindBool( child, "peerIsInterested", &b ) )
- peer.peerIsInterested = b;
- if( tr_variantDictFindInt( child, "port", &i ) )
- peer.port = i;
- if( tr_variantDictFindReal( child, "progress", &d ) )
- peer.progress = d;
- if( tr_variantDictFindInt( child, "rateToClient", &i ) )
- peer.rateToClient = Speed::fromBps( i );
- if( tr_variantDictFindInt( child, "rateToPeer", &i ) )
- peer.rateToPeer = Speed::fromBps( i );
- peerList << peer;
+ tr_variant * peers;
+ if (tr_variantDictFindList (d, TR_KEY_peers, &peers))
+ {
+ tr_variant * child;
+ PeerList peerList;
+ int childNum = 0;
+ while ((child = tr_variantListChild (peers, childNum++)))
+ {
+ double d;
+ bool b;
+ int64_t i;
+ size_t len;
+ const char * str;
+ Peer peer;
+
+ if (tr_variantDictFindStr(child, TR_KEY_address, &str, &len))
+ peer.address = QString::fromUtf8 (str, len);
+ if (tr_variantDictFindStr(child, TR_KEY_clientName, &str, &len))
+ peer.clientName = QString::fromUtf8 (str, len);
+ if (tr_variantDictFindBool (child, TR_KEY_clientIsChoked, &b))
+ peer.clientIsChoked = b;
+ if (tr_variantDictFindBool (child, TR_KEY_clientIsInterested, &b))
+ peer.clientIsInterested = b;
+ if (tr_variantDictFindStr(child, TR_KEY_flagStr, &str, &len))
+ peer.flagStr = QString::fromUtf8 (str, len);
+ if (tr_variantDictFindBool (child, TR_KEY_isDownloadingFrom, &b))
+ peer.isDownloadingFrom = b;
+ if (tr_variantDictFindBool (child, TR_KEY_isEncrypted, &b))
+ peer.isEncrypted = b;
+ if (tr_variantDictFindBool (child, TR_KEY_isIncoming, &b))
+ peer.isIncoming = b;
+ if (tr_variantDictFindBool (child, TR_KEY_isUploadingTo, &b))
+ peer.isUploadingTo = b;
+ if (tr_variantDictFindBool (child, TR_KEY_peerIsChoked, &b))
+ peer.peerIsChoked = b;
+ if (tr_variantDictFindBool (child, TR_KEY_peerIsInterested, &b))
+ peer.peerIsInterested = b;
+ if (tr_variantDictFindInt (child, TR_KEY_port, &i))
+ peer.port = i;
+ if (tr_variantDictFindReal (child, TR_KEY_progress, &d))
+ peer.progress = d;
+ if (tr_variantDictFindInt (child, TR_KEY_rateToClient, &i))
+ peer.rateToClient = Speed::fromBps (i);
+ if (tr_variantDictFindInt (child, TR_KEY_rateToPeer, &i))
+ peer.rateToPeer = Speed::fromBps (i);
+ peerList << peer;
}
- myValues[PEERS].setValue( peerList );
- changed = true;
+
+ myValues[PEERS].setValue (peerList);
+ changed = true;
}
- if( changed )
- emit torrentChanged( id( ) );
+ if (changed)
+ emit torrentChanged (id ());
- if( !was_seed && isSeed() && (old_verified_size>0) )
- emit torrentCompleted( id( ) );
+ if (!was_seed && isSeed() && (old_verified_size>0))
+ emit torrentCompleted (id ());
}
QString
-Torrent :: activityString( ) const
+Torrent :: activityString () const
{
- QString str;
+ QString str;
- switch( getActivity( ) )
+ switch (getActivity ())
{
- case TR_STATUS_STOPPED: str = isFinished() ? tr( "Finished" ): tr( "Paused" ); break;
- case TR_STATUS_CHECK_WAIT: str = tr( "Queued for verification" ); break;
- case TR_STATUS_CHECK: str = tr( "Verifying local data" ); break;
- case TR_STATUS_DOWNLOAD_WAIT: str = tr( "Queued for download" ); break;
- case TR_STATUS_DOWNLOAD: str = tr( "Downloading" ); break;
- case TR_STATUS_SEED_WAIT: str = tr( "Queued for seeding" ); break;
- case TR_STATUS_SEED: str = tr( "Seeding" ); break;
+ case TR_STATUS_STOPPED: str = isFinished() ? tr("Finished"): tr("Paused"); break;
+ case TR_STATUS_CHECK_WAIT: str = tr("Queued for verification"); break;
+ case TR_STATUS_CHECK: str = tr("Verifying local data"); break;
+ case TR_STATUS_DOWNLOAD_WAIT: str = tr("Queued for download"); break;
+ case TR_STATUS_DOWNLOAD: str = tr("Downloading"); break;
+ case TR_STATUS_SEED_WAIT: str = tr("Queued for seeding"); break;
+ case TR_STATUS_SEED: str = tr("Seeding"); break;
}
- return str;
+ return str;
}
QString
-Torrent :: getError( ) const
+Torrent :: getError () const
{
- QString s = getString( ERROR_STRING );
+ QString s = getString (ERROR_STRING);
- switch( getInt( ERROR ) )
+ switch (getInt (ERROR))
{
- case TR_STAT_TRACKER_WARNING: s = tr( "Tracker gave a warning: %1" ).arg( s ); break;
- case TR_STAT_TRACKER_ERROR: s = tr( "Tracker gave an error: %1" ).arg( s ); break;
- case TR_STAT_LOCAL_ERROR: s = tr( "Error: %1" ).arg( s ); break;
- default: s.clear(); break;
+ case TR_STAT_TRACKER_WARNING: s = tr("Tracker gave a warning: %1").arg(s); break;
+ case TR_STAT_TRACKER_ERROR: s = tr("Tracker gave an error: %1").arg(s); break;
+ case TR_STAT_LOCAL_ERROR: s = tr("Error: %1").arg(s); break;
+ default: s.clear(); break;
}
- return s;
+ return s;
}
QPixmap
-TrackerStat :: getFavicon( ) const
+TrackerStat :: getFavicon () const
{
- MyApp * myApp = dynamic_cast<MyApp*>(QApplication::instance());
- return myApp->favicons.find( QUrl( announce ) );
+ MyApp * myApp = dynamic_cast<MyApp*>(QApplication::instance());
+ return myApp->favicons.find (QUrl (announce));
}
#include <QVariant>
#include <libtransmission/transmission.h>
+#include <libtransmission/quark.h>
#include "speed.h"
#include "types.h"
struct Property
{
int id;
- const char * key;
+ tr_quark key;
int type;
int group;
};
bool magnetTorrent;
public:
- typedef QList<const char*> KeyList;
+ typedef QList<tr_quark> KeyList;
static const KeyList& getInfoKeys( );
static const KeyList& getStatKeys( );
static const KeyList& getExtraStatKeys( );
tr_variant * announce_list;
bool changed = false;
- if (tr_variantDictFindStr (metainfo, "announce", &str, NULL) && !strcmp (str, url))
+ if (tr_variantDictFindStr (metainfo, TR_KEY_announce, &str, NULL) && !strcmp (str, url))
{
printf ("\tRemoved \"%s\" from \"announce\"\n", str);
- tr_variantDictRemove (metainfo, "announce");
+ tr_variantDictRemove (metainfo, TR_KEY_announce);
changed = true;
}
- if (tr_variantDictFindList (metainfo, "announce-list", &announce_list))
+ if (tr_variantDictFindList (metainfo, TR_KEY_announce_list, &announce_list))
{
tr_variant * tier;
int tierIndex = 0;
if (tr_variantListSize (announce_list) == 0)
{
printf ("\tNo tiers left... removing announce-list\n");
- tr_variantDictRemove (metainfo, "announce-list");
+ tr_variantDictRemove (metainfo, TR_KEY_announce_list);
}
}
/* if we removed the "announce" field and there's still another track left,
* use it as the "announce" field */
- if (changed && !tr_variantDictFindStr (metainfo, "announce", &str, NULL))
+ if (changed && !tr_variantDictFindStr (metainfo, TR_KEY_announce, &str, NULL))
{
tr_variant * tier;
tr_variant * node;
{
if (tr_variantGetStr (node, &str, NULL))
{
- tr_variantDictAddStr (metainfo, "announce", str);
+ tr_variantDictAddStr (metainfo, TR_KEY_announce, str);
printf ("\tAdded \"%s\" to announce\n", str);
}
}
tr_variant * announce_list;
bool changed = false;
- if (tr_variantDictFindStr (metainfo, "announce", &str, NULL) && strstr (str, in))
+ if (tr_variantDictFindStr (metainfo, TR_KEY_announce, &str, NULL) && strstr (str, in))
{
char * newstr = replaceSubstr (str, in, out);
printf ("\tReplaced in \"announce\": \"%s\" --> \"%s\"\n", str, newstr);
- tr_variantDictAddStr (metainfo, "announce", newstr);
+ tr_variantDictAddStr (metainfo, TR_KEY_announce, newstr);
tr_free (newstr);
changed = true;
}
- if (tr_variantDictFindList (metainfo, "announce-list", &announce_list))
+ if (tr_variantDictFindList (metainfo, TR_KEY_announce_list, &announce_list))
{
tr_variant * tier;
int tierCount = 0;
const char * announce = NULL;
tr_variant * announce_list = NULL;
bool changed = false;
- const bool had_announce = tr_variantDictFindStr (metainfo, "announce", &announce, NULL);
- const bool had_announce_list = tr_variantDictFindList (metainfo, "announce-list", &announce_list);
+ const bool had_announce = tr_variantDictFindStr (metainfo, TR_KEY_announce, &announce, NULL);
+ const bool had_announce_list = tr_variantDictFindList (metainfo, TR_KEY_announce_list, &announce_list);
if (!had_announce && !had_announce_list)
{
/* this new tracker is the only one, so add it to "announce"... */
printf ("\tAdded \"%s\" in \"announce\"\n", url);
- tr_variantDictAddStr (metainfo, "announce", url);
+ tr_variantDictAddStr (metainfo, TR_KEY_announce, url);
changed = true;
}
else
{
if (!had_announce_list)
{
- announce_list = tr_variantDictAddList (metainfo, "announce-list", 2);
+ announce_list = tr_variantDictAddList (metainfo, TR_KEY_announce_list, 2);
if (had_announce)
{
if (!tr_variantFromBenc (&top, begin, evbuffer_get_length(buf)))
{
- if (tr_variantDictFindDict (&top, "files", &files))
+ if (tr_variantDictFindDict (&top, TR_KEY_files, &files))
{
int i = 0;
+ tr_quark key;
tr_variant * val;
- const char * key;
while (tr_variantDictChild (files, i++, &key, &val))
{
- if (!memcmp (inf->hash, key, SHA_DIGEST_LENGTH))
+ if (!memcmp (inf->hash, tr_quark_get_string(key,NULL), SHA_DIGEST_LENGTH))
{
int64_t seeders = -1;
int64_t leechers = -1;
- tr_variantDictFindInt (val, "complete", &seeders);
- tr_variantDictFindInt (val, "incomplete", &leechers);
+ tr_variantDictFindInt (val, TR_KEY_complete, &seeders);
+ tr_variantDictFindInt (val, TR_KEY_incomplete, &leechers);
printf ("%d seeders, %d leechers\n", (int)seeders, (int)leechers);
matched = true;
}