refactor: use nullptr instead of NULL (#1884)

* refactor: use nullptr instead of NULL.

No functional changes; just more C++ification
This commit is contained in:
Charles Kerr 2021-10-06 11:32:17 -05:00 committed by GitHub
parent cc204e0b2c
commit 003685b40a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 1453 additions and 1391 deletions

View File

@ -71,28 +71,28 @@ static bool verify = false;
static sig_atomic_t gotsig = false; static sig_atomic_t gotsig = false;
static sig_atomic_t manualUpdate = false; static sig_atomic_t manualUpdate = false;
static char const* torrentPath = NULL; static char const* torrentPath = nullptr;
static struct tr_option const options[] = { static struct tr_option const options[] = {
{ 'b', "blocklist", "Enable peer blocklists", "b", false, NULL }, { 'b', "blocklist", "Enable peer blocklists", "b", false, nullptr },
{ 'B', "no-blocklist", "Disable peer blocklists", "B", false, NULL }, { 'B', "no-blocklist", "Disable peer blocklists", "B", false, nullptr },
{ 'd', "downlimit", "Set max download speed in " SPEED_K_STR, "d", true, "<speed>" }, { 'd', "downlimit", "Set max download speed in " SPEED_K_STR, "d", true, "<speed>" },
{ 'D', "no-downlimit", "Don't limit the download speed", "D", false, NULL }, { 'D', "no-downlimit", "Don't limit the download speed", "D", false, nullptr },
{ 910, "encryption-required", "Encrypt all peer connections", "er", false, NULL }, { 910, "encryption-required", "Encrypt all peer connections", "er", false, nullptr },
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", false, NULL }, { 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", false, nullptr },
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", false, NULL }, { 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", false, nullptr },
{ 'f', "finish", "Run a script when the torrent finishes", "f", true, "<script>" }, { 'f', "finish", "Run a script when the torrent finishes", "f", true, "<script>" },
{ 'g', "config-dir", "Where to find configuration files", "g", true, "<path>" }, { 'g', "config-dir", "Where to find configuration files", "g", true, "<path>" },
{ 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", false, NULL }, { 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", false, nullptr },
{ 'M', "no-portmap", "Disable portmapping", "M", false, NULL }, { 'M', "no-portmap", "Disable portmapping", "M", false, nullptr },
{ 'p', "port", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "p", true, "<port>" }, { 'p', "port", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "p", true, "<port>" },
{ 't', "tos", "Peer socket TOS (0 to 255, default=" TR_DEFAULT_PEER_SOCKET_TOS_STR ")", "t", true, "<tos>" }, { 't', "tos", "Peer socket TOS (0 to 255, default=" TR_DEFAULT_PEER_SOCKET_TOS_STR ")", "t", true, "<tos>" },
{ 'u', "uplimit", "Set max upload speed in " SPEED_K_STR, "u", true, "<speed>" }, { 'u', "uplimit", "Set max upload speed in " SPEED_K_STR, "u", true, "<speed>" },
{ 'U', "no-uplimit", "Don't limit the upload speed", "U", false, NULL }, { 'U', "no-uplimit", "Don't limit the upload speed", "U", false, nullptr },
{ 'v', "verify", "Verify the specified torrent", "v", false, NULL }, { 'v', "verify", "Verify the specified torrent", "v", false, nullptr },
{ 'V', "version", "Show version number and exit", "V", false, NULL }, { 'V', "version", "Show version number and exit", "V", false, nullptr },
{ 'w', "download-dir", "Where to save downloaded data", "w", true, "<path>" }, { 'w', "download-dir", "Where to save downloaded data", "w", true, "<path>" },
{ 0, NULL, NULL, NULL, false, NULL } { 0, nullptr, nullptr, nullptr, false, nullptr }
}; };
static char const* getUsage(void) static char const* getUsage(void)
@ -219,7 +219,7 @@ static void getStatusStr(tr_stat const* st, char* buf, size_t buflen)
static char const* getConfigDir(int argc, char const** argv) static char const* getConfigDir(int argc, char const** argv)
{ {
int c; int c;
char const* configDir = NULL; char const* configDir = nullptr;
char const* optarg; char const* optarg;
int const ind = tr_optind; int const ind = tr_optind;
@ -234,7 +234,7 @@ static char const* getConfigDir(int argc, char const** argv)
tr_optind = ind; tr_optind = ind;
if (configDir == NULL) if (configDir == nullptr)
{ {
configDir = tr_getDefaultConfigDir(MY_CONFIG_NAME); configDir = tr_getDefaultConfigDir(MY_CONFIG_NAME);
} }
@ -246,7 +246,7 @@ int tr_main(int argc, char* argv[])
{ {
tr_session* h; tr_session* h;
tr_ctor* ctor; tr_ctor* ctor;
tr_torrent* tor = NULL; tr_torrent* tor = nullptr;
tr_variant settings; tr_variant settings;
char const* configDir; char const* configDir;
uint8_t* fileContents; uint8_t* fileContents;
@ -283,15 +283,15 @@ int tr_main(int argc, char* argv[])
} }
/* Check the options for validity */ /* Check the options for validity */
if (torrentPath == NULL) if (torrentPath == nullptr)
{ {
fprintf(stderr, "No torrent specified!\n"); fprintf(stderr, "No torrent specified!\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (tr_variantDictFindStr(&settings, TR_KEY_download_dir, &str, NULL) && !tr_sys_path_exists(str, NULL)) if (tr_variantDictFindStr(&settings, TR_KEY_download_dir, &str, nullptr) && !tr_sys_path_exists(str, nullptr))
{ {
tr_error* error = NULL; tr_error* error = nullptr;
if (!tr_sys_dir_create(str, TR_SYS_DIR_CREATE_PARENTS, 0700, &error)) if (!tr_sys_dir_create(str, TR_SYS_DIR_CREATE_PARENTS, 0700, &error))
{ {
@ -305,10 +305,10 @@ int tr_main(int argc, char* argv[])
ctor = tr_ctorNew(h); ctor = tr_ctorNew(h);
fileContents = tr_loadFile(torrentPath, &fileLength, NULL); fileContents = tr_loadFile(torrentPath, &fileLength, nullptr);
tr_ctorSetPaused(ctor, TR_FORCE, false); tr_ctorSetPaused(ctor, TR_FORCE, false);
if (fileContents != NULL) if (fileContents != nullptr)
{ {
tr_ctorSetMetainfo(ctor, fileContents, fileLength); tr_ctorSetMetainfo(ctor, fileContents, fileLength);
} }
@ -337,10 +337,10 @@ int tr_main(int argc, char* argv[])
tr_free(fileContents); tr_free(fileContents);
tor = tr_torrentNew(ctor, NULL, NULL); tor = tr_torrentNew(ctor, nullptr, nullptr);
tr_ctorFree(ctor); tr_ctorFree(ctor);
if (tor == NULL) if (tor == nullptr)
{ {
fprintf(stderr, "Failed opening torrent file `%s'\n", torrentPath); fprintf(stderr, "Failed opening torrent file `%s'\n", torrentPath);
tr_sessionClose(h); tr_sessionClose(h);
@ -356,7 +356,7 @@ int tr_main(int argc, char* argv[])
if (verify) if (verify)
{ {
verify = false; verify = false;
tr_torrentVerify(tor, NULL, NULL); tr_torrentVerify(tor, nullptr, nullptr);
} }
for (;;) for (;;)
@ -364,7 +364,7 @@ int tr_main(int argc, char* argv[])
char line[LINEWIDTH]; char line[LINEWIDTH];
tr_stat const* st; tr_stat const* st;
char const* messageName[] = { char const* messageName[] = {
NULL, nullptr,
"Tracker gave a warning:", "Tracker gave a warning:",
"Tracker gave an error:", "Tracker gave an error:",
"Error:", "Error:",
@ -507,7 +507,7 @@ static int parseCommandLine(tr_variant* d, int argc, char const** argv)
break; break;
case TR_OPT_UNK: case TR_OPT_UNK:
if (torrentPath == NULL) if (torrentPath == nullptr)
{ {
torrentPath = optarg; torrentPath = optarg;
} }

View File

@ -24,8 +24,8 @@
**** ****
***/ ***/
static dtr_callbacks const* callbacks = NULL; static dtr_callbacks const* callbacks = nullptr;
static void* callback_arg = NULL; static void* callback_arg = nullptr;
static int signal_pipe[2]; static int signal_pipe[2];
@ -83,7 +83,7 @@ static void* signal_handler_thread_main(void* arg)
handle_signal(sig); handle_signal(sig);
} }
return NULL; return nullptr;
} }
static bool create_signal_pipe(tr_error** error) static bool create_signal_pipe(tr_error** error)
@ -110,7 +110,7 @@ static bool create_signal_handler_thread(pthread_t* thread, tr_error** error)
return false; return false;
} }
if ((errno = pthread_create(thread, NULL, &signal_handler_thread_main, NULL)) != 0) if ((errno = pthread_create(thread, nullptr, &signal_handler_thread_main, nullptr)) != 0)
{ {
set_system_error(error, errno, "pthread_create() failed"); set_system_error(error, errno, "pthread_create() failed");
destroy_signal_pipe(); destroy_signal_pipe();
@ -123,7 +123,7 @@ static bool create_signal_handler_thread(pthread_t* thread, tr_error** error)
static void destroy_signal_handler_thread(pthread_t thread) static void destroy_signal_handler_thread(pthread_t thread)
{ {
send_signal_to_pipe(0); send_signal_to_pipe(0);
pthread_join(thread, NULL); pthread_join(thread, nullptr);
destroy_signal_pipe(); destroy_signal_pipe();
} }

View File

@ -29,15 +29,15 @@
#define SERVICE_CONTROL_PRESHUTDOWN 0x0000000F #define SERVICE_CONTROL_PRESHUTDOWN 0x0000000F
#endif #endif
static dtr_callbacks const* callbacks = NULL; static dtr_callbacks const* callbacks = nullptr;
static void* callback_arg = NULL; static void* callback_arg = nullptr;
static LPCWSTR const service_name = L"TransmissionDaemon"; static LPCWSTR const service_name = L"TransmissionDaemon";
static SERVICE_STATUS_HANDLE status_handle = NULL; static SERVICE_STATUS_HANDLE status_handle = nullptr;
static DWORD current_state = SERVICE_STOPPED; static DWORD current_state = SERVICE_STOPPED;
static HANDLE service_thread = NULL; static HANDLE service_thread = nullptr;
static HANDLE service_stop_thread = NULL; static HANDLE service_stop_thread = nullptr;
/*** /***
**** ****
@ -128,7 +128,7 @@ static unsigned int __stdcall service_stop_thread_main(void* param)
static void stop_service(void) static void stop_service(void)
{ {
if (service_stop_thread != NULL) if (service_stop_thread != nullptr)
{ {
return; return;
} }
@ -137,9 +137,10 @@ static void stop_service(void)
update_service_status(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, wait_time); update_service_status(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, wait_time);
service_stop_thread = (HANDLE)_beginthreadex(NULL, 0, &service_stop_thread_main, (LPVOID)(UINT_PTR)wait_time, 0, NULL); service_stop_thread = (HANDLE)
_beginthreadex(nullptr, 0, &service_stop_thread_main, (LPVOID)(UINT_PTR)wait_time, 0, nullptr);
if (service_stop_thread == NULL) if (service_stop_thread == nullptr)
{ {
log_system_error(TR_LOG_DEBUG, GetLastError(), "_beginthreadex() failed, trying to stop synchronously"); log_system_error(TR_LOG_DEBUG, GetLastError(), "_beginthreadex() failed, trying to stop synchronously");
service_stop_thread_main((LPVOID)(UINT_PTR)wait_time); service_stop_thread_main((LPVOID)(UINT_PTR)wait_time);
@ -184,9 +185,9 @@ static VOID WINAPI service_main(DWORD argc, LPWSTR* argv)
TR_UNUSED(argc); TR_UNUSED(argc);
TR_UNUSED(argv); TR_UNUSED(argv);
status_handle = RegisterServiceCtrlHandlerExW(service_name, &handle_service_ctrl, NULL); status_handle = RegisterServiceCtrlHandlerExW(service_name, &handle_service_ctrl, nullptr);
if (status_handle == NULL) if (status_handle == nullptr)
{ {
log_system_error(TR_LOG_ERROR, GetLastError(), "RegisterServiceCtrlHandlerEx() failed"); log_system_error(TR_LOG_ERROR, GetLastError(), "RegisterServiceCtrlHandlerEx() failed");
return; return;
@ -194,9 +195,9 @@ static VOID WINAPI service_main(DWORD argc, LPWSTR* argv)
update_service_status(SERVICE_START_PENDING, NO_ERROR, 0, 1, 1000); update_service_status(SERVICE_START_PENDING, NO_ERROR, 0, 1, 1000);
service_thread = (HANDLE)_beginthreadex(NULL, 0, &service_thread_main, NULL, 0, NULL); service_thread = (HANDLE)_beginthreadex(nullptr, 0, &service_thread_main, nullptr, 0, nullptr);
if (service_thread == NULL) if (service_thread == nullptr)
{ {
log_system_error(TR_LOG_ERROR, GetLastError(), "_beginthreadex() failed"); log_system_error(TR_LOG_ERROR, GetLastError(), "_beginthreadex() failed");
return; return;
@ -209,7 +210,7 @@ static VOID WINAPI service_main(DWORD argc, LPWSTR* argv)
log_system_error(TR_LOG_ERROR, GetLastError(), "WaitForSingleObject() failed"); log_system_error(TR_LOG_ERROR, GetLastError(), "WaitForSingleObject() failed");
} }
if (service_stop_thread != NULL) if (service_stop_thread != nullptr)
{ {
WaitForSingleObject(service_stop_thread, INFINITE); WaitForSingleObject(service_stop_thread, INFINITE);
CloseHandle(service_stop_thread); CloseHandle(service_stop_thread);
@ -252,7 +253,7 @@ bool dtr_daemon(dtr_callbacks const* cb, void* cb_arg, bool foreground, int* exi
{ {
SERVICE_TABLE_ENTRY const service_table[] = { SERVICE_TABLE_ENTRY const service_table[] = {
{ (LPWSTR)service_name, &service_main }, { (LPWSTR)service_name, &service_main },
{ NULL, NULL }, { nullptr, nullptr },
}; };
if (!StartServiceCtrlDispatcherW(service_table)) if (!StartServiceCtrlDispatcherW(service_table))

View File

@ -78,12 +78,12 @@ static void sd_notifyf(int status, char const* fmt, ...)
#define SPEED_T_STR "TB/s" #define SPEED_T_STR "TB/s"
static bool seenHUP = false; static bool seenHUP = false;
static char const* logfileName = NULL; static char const* logfileName = nullptr;
static tr_sys_file_t logfile = TR_BAD_SYS_FILE; static tr_sys_file_t logfile = TR_BAD_SYS_FILE;
static tr_session* mySession = NULL; static tr_session* mySession = nullptr;
static tr_quark key_pidfile = 0; static tr_quark key_pidfile = 0;
static tr_quark key_watch_dir_force_generic = 0; static tr_quark key_watch_dir_force_generic = 0;
static struct event_base* ev_base = NULL; static struct event_base* ev_base = nullptr;
/*** /***
**** Config File **** Config File
@ -106,36 +106,36 @@ static char const* getUsage(void)
static struct tr_option const options[] = { static struct tr_option const options[] = {
{ 'a', "allowed", "Allowed IP addresses. (Default: " TR_DEFAULT_RPC_WHITELIST ")", "a", true, "<list>" }, { 'a', "allowed", "Allowed IP addresses. (Default: " TR_DEFAULT_RPC_WHITELIST ")", "a", true, "<list>" },
{ 'b', "blocklist", "Enable peer blocklists", "b", false, NULL }, { 'b', "blocklist", "Enable peer blocklists", "b", false, nullptr },
{ 'B', "no-blocklist", "Disable peer blocklists", "B", false, NULL }, { 'B', "no-blocklist", "Disable peer blocklists", "B", false, nullptr },
{ 'c', "watch-dir", "Where to watch for new .torrent files", "c", true, "<directory>" }, { 'c', "watch-dir", "Where to watch for new .torrent files", "c", true, "<directory>" },
{ 'C', "no-watch-dir", "Disable the watch-dir", "C", false, NULL }, { 'C', "no-watch-dir", "Disable the watch-dir", "C", false, nullptr },
{ 941, "incomplete-dir", "Where to store new torrents until they're complete", NULL, true, "<directory>" }, { 941, "incomplete-dir", "Where to store new torrents until they're complete", nullptr, true, "<directory>" },
{ 942, "no-incomplete-dir", "Don't store incomplete torrents in a different location", NULL, false, NULL }, { 942, "no-incomplete-dir", "Don't store incomplete torrents in a different location", nullptr, false, nullptr },
{ 'd', "dump-settings", "Dump the settings and exit", "d", false, NULL }, { 'd', "dump-settings", "Dump the settings and exit", "d", false, nullptr },
{ 'e', "logfile", "Dump the log messages to this filename", "e", true, "<filename>" }, { 'e', "logfile", "Dump the log messages to this filename", "e", true, "<filename>" },
{ 'f', "foreground", "Run in the foreground instead of daemonizing", "f", false, NULL }, { 'f', "foreground", "Run in the foreground instead of daemonizing", "f", false, nullptr },
{ 'g', "config-dir", "Where to look for configuration files", "g", true, "<path>" }, { 'g', "config-dir", "Where to look for configuration files", "g", true, "<path>" },
{ 'p', "port", "RPC port (Default: " TR_DEFAULT_RPC_PORT_STR ")", "p", true, "<port>" }, { 'p', "port", "RPC port (Default: " TR_DEFAULT_RPC_PORT_STR ")", "p", true, "<port>" },
{ 't', "auth", "Require authentication", "t", false, NULL }, { 't', "auth", "Require authentication", "t", false, nullptr },
{ 'T', "no-auth", "Don't require authentication", "T", false, NULL }, { 'T', "no-auth", "Don't require authentication", "T", false, nullptr },
{ 'u', "username", "Set username for authentication", "u", true, "<username>" }, { 'u', "username", "Set username for authentication", "u", true, "<username>" },
{ 'v', "password", "Set password for authentication", "v", true, "<password>" }, { 'v', "password", "Set password for authentication", "v", true, "<password>" },
{ 'V', "version", "Show version number and exit", "V", false, NULL }, { 'V', "version", "Show version number and exit", "V", false, nullptr },
{ 810, "log-error", "Show error messages", NULL, false, NULL }, { 810, "log-error", "Show error messages", nullptr, false, nullptr },
{ 811, "log-info", "Show error and info messages", NULL, false, NULL }, { 811, "log-info", "Show error and info messages", nullptr, false, nullptr },
{ 812, "log-debug", "Show error, info, and debug messages", NULL, false, NULL }, { 812, "log-debug", "Show error, info, and debug messages", nullptr, false, nullptr },
{ 'w', "download-dir", "Where to save downloaded data", "w", true, "<path>" }, { 'w', "download-dir", "Where to save downloaded data", "w", true, "<path>" },
{ 800, "paused", "Pause all torrents on startup", NULL, false, NULL }, { 800, "paused", "Pause all torrents on startup", nullptr, false, nullptr },
{ 'o', "dht", "Enable distributed hash tables (DHT)", "o", false, NULL }, { 'o', "dht", "Enable distributed hash tables (DHT)", "o", false, nullptr },
{ 'O', "no-dht", "Disable distributed hash tables (DHT)", "O", false, NULL }, { 'O', "no-dht", "Disable distributed hash tables (DHT)", "O", false, nullptr },
{ 'y', "lpd", "Enable local peer discovery (LPD)", "y", false, NULL }, { 'y', "lpd", "Enable local peer discovery (LPD)", "y", false, nullptr },
{ 'Y', "no-lpd", "Disable local peer discovery (LPD)", "Y", false, NULL }, { 'Y', "no-lpd", "Disable local peer discovery (LPD)", "Y", false, nullptr },
{ 830, "utp", "Enable uTP for peer connections", NULL, false, NULL }, { 830, "utp", "Enable uTP for peer connections", nullptr, false, nullptr },
{ 831, "no-utp", "Disable uTP for peer connections", NULL, false, NULL }, { 831, "no-utp", "Disable uTP for peer connections", nullptr, false, nullptr },
{ 'P', "peerport", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "P", true, "<port>" }, { 'P', "peerport", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "P", true, "<port>" },
{ 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", false, NULL }, { 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", false, nullptr },
{ 'M', "no-portmap", "Disable portmapping", "M", false, NULL }, { 'M', "no-portmap", "Disable portmapping", "M", false, nullptr },
{ 'L', { 'L',
"peerlimit-global", "peerlimit-global",
"Maximum overall number of peers (Default: " TR_DEFAULT_PEER_LIMIT_GLOBAL_STR ")", "Maximum overall number of peers (Default: " TR_DEFAULT_PEER_LIMIT_GLOBAL_STR ")",
@ -148,9 +148,9 @@ static struct tr_option const options[] = {
"l", "l",
true, true,
"<limit>" }, "<limit>" },
{ 910, "encryption-required", "Encrypt all peer connections", "er", false, NULL }, { 910, "encryption-required", "Encrypt all peer connections", "er", false, nullptr },
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", false, NULL }, { 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", false, nullptr },
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", false, NULL }, { 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", false, nullptr },
{ 'i', "bind-address-ipv4", "Where to listen for peer connections", "i", true, "<ipv4 addr>" }, { 'i', "bind-address-ipv4", "Where to listen for peer connections", "i", true, "<ipv4 addr>" },
{ 'I', "bind-address-ipv6", "Where to listen for peer connections", "I", true, "<ipv6 addr>" }, { 'I', "bind-address-ipv6", "Where to listen for peer connections", "I", true, "<ipv6 addr>" },
{ 'r', "rpc-bind-address", "Where to listen for RPC connections", "r", true, "<ip addr>" }, { 'r', "rpc-bind-address", "Where to listen for RPC connections", "r", true, "<ip addr>" },
@ -165,14 +165,14 @@ static struct tr_option const options[] = {
"All torrents, unless overridden by a per-torrent setting, should seed regardless of ratio", "All torrents, unless overridden by a per-torrent setting, should seed regardless of ratio",
"GSR", "GSR",
false, false,
NULL }, nullptr },
{ 'x', "pid-file", "Enable PID file", "x", true, "<pid-file>" }, { 'x', "pid-file", "Enable PID file", "x", true, "<pid-file>" },
{ 0, NULL, NULL, NULL, false, NULL } { 0, nullptr, nullptr, nullptr, false, nullptr }
}; };
static bool reopen_log_file(char const* filename) static bool reopen_log_file(char const* filename)
{ {
tr_error* error = NULL; tr_error* error = nullptr;
tr_sys_file_t const old_log_file = logfile; tr_sys_file_t const old_log_file = logfile;
tr_sys_file_t const new_log_file = tr_sys_file_open( tr_sys_file_t const new_log_file = tr_sys_file_open(
filename, filename,
@ -191,7 +191,7 @@ static bool reopen_log_file(char const* filename)
if (old_log_file != TR_BAD_SYS_FILE) if (old_log_file != TR_BAD_SYS_FILE)
{ {
tr_sys_file_close(old_log_file, NULL); tr_sys_file_close(old_log_file, nullptr);
} }
return true; return true;
@ -200,7 +200,7 @@ static bool reopen_log_file(char const* filename)
static char const* getConfigDir(int argc, char const* const* argv) static char const* getConfigDir(int argc, char const* const* argv)
{ {
int c; int c;
char const* configDir = NULL; char const* configDir = nullptr;
char const* optstr; char const* optstr;
int const ind = tr_optind; int const ind = tr_optind;
@ -215,7 +215,7 @@ static char const* getConfigDir(int argc, char const* const* argv)
tr_optind = ind; tr_optind = ind;
if (configDir == NULL) if (configDir == nullptr)
{ {
configDir = tr_getDefaultConfigDir(MY_NAME); configDir = tr_getDefaultConfigDir(MY_NAME);
} }
@ -232,13 +232,13 @@ static tr_watchdir_status onFileAdded(tr_watchdir_t dir, char const* name, void*
return TR_WATCHDIR_IGNORE; return TR_WATCHDIR_IGNORE;
} }
char* filename = tr_buildPath(tr_watchdir_get_path(dir), name, NULL); char* filename = tr_buildPath(tr_watchdir_get_path(dir), name, nullptr);
tr_ctor* ctor = tr_ctorNew(session); tr_ctor* ctor = tr_ctorNew(session);
int err = tr_ctorSetMetainfoFromFile(ctor, filename); int err = tr_ctorSetMetainfoFromFile(ctor, filename);
if (err == 0) if (err == 0)
{ {
tr_torrentNew(ctor, &err, NULL); tr_torrentNew(ctor, &err, nullptr);
if (err == TR_PARSE_ERR) if (err == TR_PARSE_ERR)
{ {
@ -253,7 +253,7 @@ static tr_watchdir_status onFileAdded(tr_watchdir_t dir, char const* name, void*
if (test && trash) if (test && trash)
{ {
tr_error* error = NULL; tr_error* error = nullptr;
tr_logAddInfo("Deleting input .torrent file \"%s\"", name); tr_logAddInfo("Deleting input .torrent file \"%s\"", name);
@ -266,7 +266,7 @@ static tr_watchdir_status onFileAdded(tr_watchdir_t dir, char const* name, void*
else else
{ {
char* new_filename = tr_strdup_printf("%s.added", filename); char* new_filename = tr_strdup_printf("%s.added", filename);
tr_sys_path_rename(filename, new_filename, NULL); tr_sys_path_rename(filename, new_filename, nullptr);
tr_free(new_filename); tr_free(new_filename);
} }
} }
@ -289,13 +289,21 @@ static void printMessage(tr_sys_file_t file, int level, char const* name, char c
char timestr[64]; char timestr[64];
tr_logGetTimeStr(timestr, sizeof(timestr)); tr_logGetTimeStr(timestr, sizeof(timestr));
if (name != NULL) if (name != nullptr)
{ {
tr_sys_file_write_fmt(file, "[%s] %s %s (%s:%d)" TR_NATIVE_EOL_STR, NULL, timestr, name, message, filename, line); tr_sys_file_write_fmt(
file,
"[%s] %s %s (%s:%d)" TR_NATIVE_EOL_STR,
nullptr,
timestr,
name,
message,
filename,
line);
} }
else else
{ {
tr_sys_file_write_fmt(file, "[%s] %s (%s:%d)" TR_NATIVE_EOL_STR, NULL, timestr, message, filename, line); tr_sys_file_write_fmt(file, "[%s] %s (%s:%d)" TR_NATIVE_EOL_STR, nullptr, timestr, message, filename, line);
} }
} }
@ -321,7 +329,7 @@ static void printMessage(tr_sys_file_t file, int level, char const* name, char c
break; break;
} }
if (name != NULL) if (name != nullptr)
{ {
syslog(priority, "%s %s (%s:%d)", name, message, filename, line); syslog(priority, "%s %s (%s:%d)", name, message, filename, line);
} }
@ -342,14 +350,14 @@ static void pumpLogMessages(tr_sys_file_t file)
{ {
tr_log_message* list = tr_logGetQueue(); tr_log_message* list = tr_logGetQueue();
for (tr_log_message const* l = list; l != NULL; l = l->next) for (tr_log_message const* l = list; l != nullptr; l = l->next)
{ {
printMessage(file, l->level, l->name, l->message, l->file, l->line); printMessage(file, l->level, l->name, l->message, l->file, l->line);
} }
if (file != TR_BAD_SYS_FILE) if (file != TR_BAD_SYS_FILE)
{ {
tr_sys_file_flush(file, NULL); tr_sys_file_flush(file, nullptr);
} }
tr_logFreeQueue(list); tr_logFreeQueue(list);
@ -392,7 +400,7 @@ static tr_rpc_callback_status on_rpc_callback(
if (type == TR_RPC_SESSION_CLOSE) if (type == TR_RPC_SESSION_CLOSE)
{ {
event_base_loopexit(ev_base, NULL); event_base_loopexit(ev_base, nullptr);
} }
return TR_RPC_OK; return TR_RPC_OK;
@ -617,7 +625,7 @@ static void daemon_reconfigure(void* arg)
{ {
TR_UNUSED(arg); TR_UNUSED(arg);
if (mySession == NULL) if (mySession == nullptr)
{ {
tr_logAddInfo("Deferring reload until session is fully started."); tr_logAddInfo("Deferring reload until session is fully started.");
seenHUP = true; seenHUP = true;
@ -628,7 +636,7 @@ static void daemon_reconfigure(void* arg)
char const* configDir; char const* configDir;
/* reopen the logfile to allow for log rotation */ /* reopen the logfile to allow for log rotation */
if (logfileName != NULL) if (logfileName != nullptr)
{ {
reopen_log_file(logfileName); reopen_log_file(logfileName);
} }
@ -648,7 +656,7 @@ static void daemon_stop(void* arg)
{ {
TR_UNUSED(arg); TR_UNUSED(arg);
event_base_loopexit(ev_base, NULL); event_base_loopexit(ev_base, nullptr);
} }
static int daemon_start(void* varg, bool foreground) static int daemon_start(void* varg, bool foreground)
@ -660,9 +668,9 @@ static int daemon_start(void* varg, bool foreground)
bool boolVal; bool boolVal;
char const* pid_filename; char const* pid_filename;
bool pidfile_created = false; bool pidfile_created = false;
tr_session* session = NULL; tr_session* session = nullptr;
struct event* status_ev = NULL; struct event* status_ev = nullptr;
tr_watchdir_t watchdir = NULL; tr_watchdir_t watchdir = nullptr;
auto* arg = static_cast<daemon_data*>(varg); auto* arg = static_cast<daemon_data*>(varg);
tr_variant* const settings = &arg->settings; tr_variant* const settings = &arg->settings;
@ -676,7 +684,7 @@ static int daemon_start(void* varg, bool foreground)
/* setup event state */ /* setup event state */
ev_base = event_base_new(); ev_base = event_base_new();
if (ev_base == NULL) if (ev_base == nullptr)
{ {
char buf[256]; char buf[256];
tr_snprintf(buf, sizeof(buf), "Failed to init daemon event state: %s", tr_strerror(errno)); tr_snprintf(buf, sizeof(buf), "Failed to init daemon event state: %s", tr_strerror(errno));
@ -689,15 +697,15 @@ static int daemon_start(void* varg, bool foreground)
tr_formatter_size_init(DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR); tr_formatter_size_init(DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR);
tr_formatter_speed_init(SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR); tr_formatter_speed_init(SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR);
session = tr_sessionInit(configDir, true, settings); session = tr_sessionInit(configDir, true, settings);
tr_sessionSetRPCCallback(session, on_rpc_callback, NULL); tr_sessionSetRPCCallback(session, on_rpc_callback, nullptr);
tr_logAddNamedInfo(NULL, "Using settings from \"%s\"", configDir); tr_logAddNamedInfo(nullptr, "Using settings from \"%s\"", configDir);
tr_sessionSaveSettings(session, configDir, settings); tr_sessionSaveSettings(session, configDir, settings);
pid_filename = NULL; pid_filename = nullptr;
(void)tr_variantDictFindStr(settings, key_pidfile, &pid_filename, NULL); (void)tr_variantDictFindStr(settings, key_pidfile, &pid_filename, nullptr);
if (!tr_str_is_empty(pid_filename)) if (!tr_str_is_empty(pid_filename))
{ {
tr_error* error = NULL; tr_error* error = nullptr;
tr_sys_file_t fp = tr_sys_file_open( tr_sys_file_t fp = tr_sys_file_open(
pid_filename, pid_filename,
TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_TRUNCATE, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_TRUNCATE,
@ -706,8 +714,8 @@ static int daemon_start(void* varg, bool foreground)
if (fp != TR_BAD_SYS_FILE) if (fp != TR_BAD_SYS_FILE)
{ {
tr_sys_file_write_fmt(fp, "%d", NULL, (int)getpid()); tr_sys_file_write_fmt(fp, "%d", nullptr, (int)getpid());
tr_sys_file_close(fp, NULL); tr_sys_file_close(fp, nullptr);
tr_logAddInfo("Saved pidfile \"%s\"", pid_filename); tr_logAddInfo("Saved pidfile \"%s\"", pid_filename);
pidfile_created = true; pidfile_created = true;
} }
@ -742,11 +750,11 @@ static int daemon_start(void* varg, bool foreground)
force_generic = false; force_generic = false;
} }
if (tr_variantDictFindStr(settings, TR_KEY_watch_dir, &dir, NULL) && !tr_str_is_empty(dir)) if (tr_variantDictFindStr(settings, TR_KEY_watch_dir, &dir, nullptr) && !tr_str_is_empty(dir))
{ {
tr_logAddInfo("Watching \"%s\" for new .torrent files", dir); tr_logAddInfo("Watching \"%s\" for new .torrent files", dir);
if ((watchdir = tr_watchdir_new(dir, &onFileAdded, mySession, ev_base, force_generic)) == NULL) if ((watchdir = tr_watchdir_new(dir, &onFileAdded, mySession, ev_base, force_generic)) == nullptr)
{ {
goto CLEANUP; goto CLEANUP;
} }
@ -763,7 +771,7 @@ static int daemon_start(void* varg, bool foreground)
tr_ctorSetPaused(ctor, TR_FORCE, true); tr_ctorSetPaused(ctor, TR_FORCE, true);
} }
torrents = tr_sessionLoadTorrents(mySession, ctor, NULL); torrents = tr_sessionLoadTorrents(mySession, ctor, nullptr);
tr_free(torrents); tr_free(torrents);
tr_ctorFree(ctor); tr_ctorFree(ctor);
} }
@ -780,9 +788,9 @@ static int daemon_start(void* varg, bool foreground)
/* Create new timer event to report daemon status */ /* Create new timer event to report daemon status */
{ {
constexpr auto one_sec = timeval{ 1, 0 }; // 1 second constexpr auto one_sec = timeval{ 1, 0 }; // 1 second
status_ev = event_new(ev_base, -1, EV_PERSIST, &periodicUpdate, NULL); status_ev = event_new(ev_base, -1, EV_PERSIST, &periodicUpdate, nullptr);
if (status_ev == NULL) if (status_ev == nullptr)
{ {
tr_logAddError("Failed to create status event %s", tr_strerror(errno)); tr_logAddError("Failed to create status event %s", tr_strerror(errno));
goto CLEANUP; goto CLEANUP;
@ -810,7 +818,7 @@ CLEANUP:
tr_watchdir_free(watchdir); tr_watchdir_free(watchdir);
if (status_ev != NULL) if (status_ev != nullptr)
{ {
event_del(status_ev); event_del(status_ev);
event_free(status_ev); event_free(status_ev);
@ -837,7 +845,7 @@ CLEANUP:
/* cleanup */ /* cleanup */
if (pidfile_created) if (pidfile_created)
{ {
tr_sys_path_remove(pid_filename, NULL); tr_sys_path_remove(pid_filename, nullptr);
} }
sd_notify(0, "STATUS=\n"); sd_notify(0, "STATUS=\n");
@ -866,7 +874,7 @@ static bool init_daemon_data(int argc, char* argv[], struct daemon_data* data, b
if (*foreground && logfile == TR_BAD_SYS_FILE) if (*foreground && logfile == TR_BAD_SYS_FILE)
{ {
logfile = tr_sys_file_get_std(TR_STD_SYS_FILE_ERR, NULL); logfile = tr_sys_file_get_std(TR_STD_SYS_FILE_ERR, nullptr);
} }
if (!loaded) if (!loaded)
@ -878,7 +886,7 @@ static bool init_daemon_data(int argc, char* argv[], struct daemon_data* data, b
if (dumpSettings) if (dumpSettings)
{ {
char* str = tr_variantToStr(&data->settings, TR_VARIANT_FMT_JSON, NULL); char* str = tr_variantToStr(&data->settings, TR_VARIANT_FMT_JSON, nullptr);
fprintf(stderr, "%s", str); fprintf(stderr, "%s", str);
tr_free(str); tr_free(str);
goto EXIT_EARLY; goto EXIT_EARLY;
@ -911,7 +919,7 @@ int tr_main(int argc, char* argv[])
&daemon_reconfigure, &daemon_reconfigure,
}; };
tr_error* error = NULL; tr_error* error = nullptr;
if (!dtr_daemon(&cb, &data, foreground, &ret, &error)) if (!dtr_daemon(&cb, &data, foreground, &ret, &error))
{ {

View File

@ -18,8 +18,8 @@
#include "tr-core.h" #include "tr-core.h"
#include "tr-prefs.h" #include "tr-prefs.h"
static TrCore* myCore = NULL; static TrCore* myCore = nullptr;
static GtkActionGroup* myGroup = NULL; static GtkActionGroup* myGroup = nullptr;
static void action_cb(GtkAction* a, gpointer user_data) static void action_cb(GtkAction* a, gpointer user_data)
{ {
@ -27,15 +27,15 @@ static void action_cb(GtkAction* a, gpointer user_data)
} }
static GtkRadioActionEntry sort_radio_entries[] = { static GtkRadioActionEntry sort_radio_entries[] = {
{ "sort-by-activity", NULL, N_("Sort by _Activity"), NULL, NULL, 0 }, { "sort-by-activity", nullptr, N_("Sort by _Activity"), nullptr, nullptr, 0 },
{ "sort-by-name", NULL, N_("Sort by _Name"), NULL, NULL, 1 }, { "sort-by-name", nullptr, N_("Sort by _Name"), nullptr, nullptr, 1 },
{ "sort-by-progress", NULL, N_("Sort by _Progress"), NULL, NULL, 2 }, { "sort-by-progress", nullptr, N_("Sort by _Progress"), nullptr, nullptr, 2 },
{ "sort-by-queue", NULL, N_("Sort by _Queue"), NULL, NULL, 3 }, { "sort-by-queue", nullptr, N_("Sort by _Queue"), nullptr, nullptr, 3 },
{ "sort-by-ratio", NULL, N_("Sort by Rati_o"), NULL, NULL, 4 }, { "sort-by-ratio", nullptr, N_("Sort by Rati_o"), nullptr, nullptr, 4 },
{ "sort-by-state", NULL, N_("Sort by Stat_e"), NULL, NULL, 5 }, { "sort-by-state", nullptr, N_("Sort by Stat_e"), nullptr, nullptr, 5 },
{ "sort-by-age", NULL, N_("Sort by A_ge"), NULL, NULL, 6 }, { "sort-by-age", nullptr, N_("Sort by A_ge"), nullptr, nullptr, 6 },
{ "sort-by-time-left", NULL, N_("Sort by Time _Left"), NULL, NULL, 7 }, { "sort-by-time-left", nullptr, N_("Sort by Time _Left"), nullptr, nullptr, 7 },
{ "sort-by-size", NULL, N_("Sort by Si_ze"), NULL, NULL, 8 }, { "sort-by-size", nullptr, N_("Sort by Si_ze"), nullptr, nullptr, 8 },
}; };
static void sort_changed_cb(GtkAction* action, GtkRadioAction* current, gpointer user_data) static void sort_changed_cb(GtkAction* action, GtkRadioAction* current, gpointer user_data)
@ -51,8 +51,8 @@ static void sort_changed_cb(GtkAction* action, GtkRadioAction* current, gpointer
} }
static GtkToggleActionEntry show_toggle_entries[] = { static GtkToggleActionEntry show_toggle_entries[] = {
{ "toggle-main-window", NULL, N_("_Show Transmission"), NULL, NULL, G_CALLBACK(action_cb), TRUE }, { "toggle-main-window", nullptr, N_("_Show Transmission"), nullptr, nullptr, G_CALLBACK(action_cb), TRUE },
{ "toggle-message-log", NULL, N_("Message _Log"), NULL, NULL, G_CALLBACK(action_cb), FALSE }, { "toggle-message-log", nullptr, N_("Message _Log"), nullptr, nullptr, G_CALLBACK(action_cb), FALSE },
}; };
static void toggle_pref_cb(GtkToggleAction* action, gpointer user_data) static void toggle_pref_cb(GtkToggleAction* action, gpointer user_data)
@ -66,26 +66,32 @@ static void toggle_pref_cb(GtkToggleAction* action, gpointer user_data)
} }
static GtkToggleActionEntry pref_toggle_entries[] = { static GtkToggleActionEntry pref_toggle_entries[] = {
{ "alt-speed-enabled", NULL, N_("Enable Alternative Speed _Limits"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE }, { "alt-speed-enabled",
{ "compact-view", NULL, N_("_Compact View"), "<alt>C", NULL, G_CALLBACK(toggle_pref_cb), FALSE }, nullptr,
{ "sort-reversed", NULL, N_("Re_verse Sort Order"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE }, N_("Enable Alternative Speed _Limits"),
{ "show-filterbar", NULL, N_("_Filterbar"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE }, nullptr,
{ "show-statusbar", NULL, N_("_Statusbar"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE }, nullptr,
{ "show-toolbar", NULL, N_("_Toolbar"), NULL, NULL, G_CALLBACK(toggle_pref_cb), FALSE }, G_CALLBACK(toggle_pref_cb),
FALSE },
{ "compact-view", nullptr, N_("_Compact View"), "<alt>C", nullptr, G_CALLBACK(toggle_pref_cb), FALSE },
{ "sort-reversed", nullptr, N_("Re_verse Sort Order"), nullptr, nullptr, G_CALLBACK(toggle_pref_cb), FALSE },
{ "show-filterbar", nullptr, N_("_Filterbar"), nullptr, nullptr, G_CALLBACK(toggle_pref_cb), FALSE },
{ "show-statusbar", nullptr, N_("_Statusbar"), nullptr, nullptr, G_CALLBACK(toggle_pref_cb), FALSE },
{ "show-toolbar", nullptr, N_("_Toolbar"), nullptr, nullptr, G_CALLBACK(toggle_pref_cb), FALSE },
}; };
static GtkActionEntry entries[] = { static GtkActionEntry entries[] = {
{ "file-menu", NULL, N_("_File"), NULL, NULL, NULL }, { "file-menu", nullptr, N_("_File"), nullptr, nullptr, nullptr },
{ "torrent-menu", NULL, N_("_Torrent"), NULL, NULL, NULL }, { "torrent-menu", nullptr, N_("_Torrent"), nullptr, nullptr, nullptr },
{ "view-menu", NULL, N_("_View"), NULL, NULL, NULL }, { "view-menu", nullptr, N_("_View"), nullptr, nullptr, nullptr },
{ "sort-menu", NULL, N_("_Sort Torrents By"), NULL, NULL, NULL }, { "sort-menu", nullptr, N_("_Sort Torrents By"), nullptr, nullptr, nullptr },
{ "queue-menu", NULL, N_("_Queue"), NULL, NULL, NULL }, { "queue-menu", nullptr, N_("_Queue"), nullptr, nullptr, nullptr },
{ "edit-menu", NULL, N_("_Edit"), NULL, NULL, NULL }, { "edit-menu", nullptr, N_("_Edit"), nullptr, nullptr, nullptr },
{ "help-menu", NULL, N_("_Help"), NULL, NULL, NULL }, { "help-menu", nullptr, N_("_Help"), nullptr, nullptr, nullptr },
{ "copy-magnet-link-to-clipboard", "edit-copy", N_("Copy _Magnet Link to Clipboard"), "", NULL, G_CALLBACK(action_cb) }, { "copy-magnet-link-to-clipboard", "edit-copy", N_("Copy _Magnet Link to Clipboard"), "", nullptr, G_CALLBACK(action_cb) },
{ "open-torrent-from-url", "document-open", N_("Open _URL…"), "<control>U", N_("Open URL…"), G_CALLBACK(action_cb) }, { "open-torrent-from-url", "document-open", N_("Open _URL…"), "<control>U", N_("Open URL…"), G_CALLBACK(action_cb) },
{ "open-torrent-toolbar", "document-open", N_("_Open"), NULL, N_("Open a torrent"), G_CALLBACK(action_cb) }, { "open-torrent-toolbar", "document-open", N_("_Open"), nullptr, N_("Open a torrent"), G_CALLBACK(action_cb) },
{ "open-torrent-menu", "document-open", N_("_Open"), NULL, N_("Open a torrent"), G_CALLBACK(action_cb) }, { "open-torrent-menu", "document-open", N_("_Open"), nullptr, N_("Open a torrent"), G_CALLBACK(action_cb) },
{ "torrent-start", "media-playback-start", N_("_Start"), "<control>S", N_("Start torrent"), G_CALLBACK(action_cb) }, { "torrent-start", "media-playback-start", N_("_Start"), "<control>S", N_("Start torrent"), G_CALLBACK(action_cb) },
{ "torrent-start-now", { "torrent-start-now",
"media-playback-start", "media-playback-start",
@ -93,35 +99,45 @@ static GtkActionEntry entries[] = {
"<shift><control>S", "<shift><control>S",
N_("Start torrent now"), N_("Start torrent now"),
G_CALLBACK(action_cb) }, G_CALLBACK(action_cb) },
{ "show-stats", NULL, N_("_Statistics"), NULL, NULL, G_CALLBACK(action_cb) }, { "show-stats", nullptr, N_("_Statistics"), nullptr, nullptr, G_CALLBACK(action_cb) },
{ "donate", NULL, N_("_Donate"), NULL, NULL, G_CALLBACK(action_cb) }, { "donate", nullptr, N_("_Donate"), nullptr, nullptr, G_CALLBACK(action_cb) },
{ "torrent-verify", NULL, N_("_Verify Local Data"), "<control>V", NULL, G_CALLBACK(action_cb) }, { "torrent-verify", nullptr, N_("_Verify Local Data"), "<control>V", nullptr, G_CALLBACK(action_cb) },
{ "torrent-stop", "media-playback-pause", N_("_Pause"), "<control>P", N_("Pause torrent"), G_CALLBACK(action_cb) }, { "torrent-stop", "media-playback-pause", N_("_Pause"), "<control>P", N_("Pause torrent"), G_CALLBACK(action_cb) },
{ "pause-all-torrents", "media-playback-pause", N_("_Pause All"), NULL, N_("Pause all torrents"), G_CALLBACK(action_cb) }, { "pause-all-torrents",
{ "start-all-torrents", "media-playback-start", N_("_Start All"), NULL, N_("Start all torrents"), G_CALLBACK(action_cb) }, "media-playback-pause",
{ "relocate-torrent", NULL, N_("Set _Location…"), NULL, NULL, G_CALLBACK(action_cb) }, N_("_Pause All"),
{ "remove-torrent", "list-remove", N_("Remove torrent"), "Delete", NULL, G_CALLBACK(action_cb) }, nullptr,
{ "delete-torrent", "edit-delete", N_("_Delete Files and Remove"), "<shift>Delete", NULL, G_CALLBACK(action_cb) }, N_("Pause all torrents"),
{ "new-torrent", "document-new", N_("_New…"), NULL, N_("Create a torrent"), G_CALLBACK(action_cb) }, G_CALLBACK(action_cb) },
{ "quit", "application-exit", N_("_Quit"), NULL, NULL, G_CALLBACK(action_cb) }, { "start-all-torrents",
{ "select-all", "edit-select-all", N_("Select _All"), "<control>A", NULL, G_CALLBACK(action_cb) }, "media-playback-start",
{ "deselect-all", NULL, N_("Dese_lect All"), "<shift><control>A", NULL, G_CALLBACK(action_cb) }, N_("_Start All"),
{ "edit-preferences", "preferences-system", N_("_Preferences"), NULL, NULL, G_CALLBACK(action_cb) }, nullptr,
N_("Start all torrents"),
G_CALLBACK(action_cb) },
{ "relocate-torrent", nullptr, N_("Set _Location…"), nullptr, nullptr, G_CALLBACK(action_cb) },
{ "remove-torrent", "list-remove", N_("Remove torrent"), "Delete", nullptr, G_CALLBACK(action_cb) },
{ "delete-torrent", "edit-delete", N_("_Delete Files and Remove"), "<shift>Delete", nullptr, G_CALLBACK(action_cb) },
{ "new-torrent", "document-new", N_("_New…"), nullptr, N_("Create a torrent"), G_CALLBACK(action_cb) },
{ "quit", "application-exit", N_("_Quit"), nullptr, nullptr, G_CALLBACK(action_cb) },
{ "select-all", "edit-select-all", N_("Select _All"), "<control>A", nullptr, G_CALLBACK(action_cb) },
{ "deselect-all", nullptr, N_("Dese_lect All"), "<shift><control>A", nullptr, G_CALLBACK(action_cb) },
{ "edit-preferences", "preferences-system", N_("_Preferences"), nullptr, nullptr, G_CALLBACK(action_cb) },
{ "show-torrent-properties", { "show-torrent-properties",
"document-properties", "document-properties",
N_("_Properties"), N_("_Properties"),
"<alt>Return", "<alt>Return",
N_("Torrent properties"), N_("Torrent properties"),
G_CALLBACK(action_cb) }, G_CALLBACK(action_cb) },
{ "open-torrent-folder", "document-open", N_("Open Fold_er"), "<control>E", NULL, G_CALLBACK(action_cb) }, { "open-torrent-folder", "document-open", N_("Open Fold_er"), "<control>E", nullptr, G_CALLBACK(action_cb) },
{ "show-about-dialog", "help-about", N_("_About"), NULL, NULL, G_CALLBACK(action_cb) }, { "show-about-dialog", "help-about", N_("_About"), nullptr, nullptr, G_CALLBACK(action_cb) },
{ "help", "help-browser", N_("_Contents"), "F1", NULL, G_CALLBACK(action_cb) }, { "help", "help-browser", N_("_Contents"), "F1", nullptr, G_CALLBACK(action_cb) },
{ "torrent-reannounce", "network-workgroup", N_("Ask Tracker for _More Peers"), NULL, NULL, G_CALLBACK(action_cb) }, { "torrent-reannounce", "network-workgroup", N_("Ask Tracker for _More Peers"), nullptr, nullptr, G_CALLBACK(action_cb) },
{ "queue-move-top", "go-top", N_("Move to _Top"), NULL, NULL, G_CALLBACK(action_cb) }, { "queue-move-top", "go-top", N_("Move to _Top"), nullptr, nullptr, G_CALLBACK(action_cb) },
{ "queue-move-up", "go-up", N_("Move _Up"), "<control>Up", NULL, G_CALLBACK(action_cb) }, { "queue-move-up", "go-up", N_("Move _Up"), "<control>Up", nullptr, G_CALLBACK(action_cb) },
{ "queue-move-down", "go-down", N_("Move _Down"), "<control>Down", NULL, G_CALLBACK(action_cb) }, { "queue-move-down", "go-down", N_("Move _Down"), "<control>Down", nullptr, G_CALLBACK(action_cb) },
{ "queue-move-bottom", "go-bottom", N_("Move to _Bottom"), NULL, NULL, G_CALLBACK(action_cb) }, { "queue-move-bottom", "go-bottom", N_("Move to _Bottom"), nullptr, nullptr, G_CALLBACK(action_cb) },
{ "present-main-window", NULL, N_("Present Main Window"), NULL, NULL, G_CALLBACK(action_cb) }, { "present-main-window", nullptr, N_("Present Main Window"), nullptr, nullptr, G_CALLBACK(action_cb) },
}; };
typedef struct typedef struct
@ -157,11 +173,11 @@ static void register_my_icons(void)
GdkPixbuf* p; GdkPixbuf* p;
gchar* resource_path = g_strdup_printf(TR_RESOURCE_PATH "icons/%s.png", my_fallback_icons[i].filename); gchar* resource_path = g_strdup_printf(TR_RESOURCE_PATH "icons/%s.png", my_fallback_icons[i].filename);
p = gdk_pixbuf_new_from_resource(resource_path, NULL); p = gdk_pixbuf_new_from_resource(resource_path, nullptr);
g_free(resource_path); g_free(resource_path);
if (p != NULL) if (p != nullptr)
{ {
int width; int width;
GtkIconSet* icon_set; GtkIconSet* icon_set;
@ -181,7 +197,7 @@ static void register_my_icons(void)
g_object_unref(G_OBJECT(factory)); g_object_unref(G_OBJECT(factory));
} }
static GtkUIManager* myUIManager = NULL; static GtkUIManager* myUIManager = nullptr;
void gtr_actions_set_core(TrCore* core) void gtr_actions_set_core(TrCore* core)
{ {
@ -200,7 +216,7 @@ void gtr_actions_init(GtkUIManager* ui_manager, gpointer callback_user_data)
register_my_icons(); register_my_icons();
action_group = myGroup = gtk_action_group_new("Actions"); action_group = myGroup = gtk_action_group_new("Actions");
gtk_action_group_set_translation_domain(action_group, NULL); gtk_action_group_set_translation_domain(action_group, nullptr);
match = gtr_pref_string_get(TR_KEY_sort_mode); match = gtr_pref_string_get(TR_KEY_sort_mode);
@ -218,7 +234,7 @@ void gtr_actions_init(GtkUIManager* ui_manager, gpointer callback_user_data)
G_N_ELEMENTS(sort_radio_entries), G_N_ELEMENTS(sort_radio_entries),
active, active,
G_CALLBACK(sort_changed_cb), G_CALLBACK(sort_changed_cb),
NULL); nullptr);
gtk_action_group_add_toggle_actions( gtk_action_group_add_toggle_actions(
action_group, action_group,
@ -247,23 +263,23 @@ void gtr_actions_init(GtkUIManager* ui_manager, gpointer callback_user_data)
***** *****
****/ ****/
static GHashTable* key_to_action = NULL; static GHashTable* key_to_action = nullptr;
static void ensure_action_map_loaded(GtkUIManager* uim) static void ensure_action_map_loaded(GtkUIManager* uim)
{ {
if (key_to_action != NULL) if (key_to_action != nullptr)
{ {
return; return;
} }
key_to_action = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); key_to_action = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, nullptr);
for (GList* l = gtk_ui_manager_get_action_groups(uim); l != NULL; l = l->next) for (GList* l = gtk_ui_manager_get_action_groups(uim); l != nullptr; l = l->next)
{ {
GtkActionGroup* action_group = GTK_ACTION_GROUP(l->data); GtkActionGroup* action_group = GTK_ACTION_GROUP(l->data);
GList* actions = gtk_action_group_list_actions(action_group); GList* actions = gtk_action_group_list_actions(action_group);
for (GList* ait = actions; ait != NULL; ait = ait->next) for (GList* ait = actions; ait != nullptr; ait = ait->next)
{ {
GtkAction* action = GTK_ACTION(ait->data); GtkAction* action = GTK_ACTION(ait->data);
char const* name = gtk_action_get_name(action); char const* name = gtk_action_get_name(action);
@ -284,7 +300,7 @@ void gtr_action_activate(char const* name)
{ {
GtkAction* action = get_action(name); GtkAction* action = get_action(name);
g_assert(action != NULL); g_assert(action != nullptr);
gtk_action_activate(action); gtk_action_activate(action);
} }
@ -292,16 +308,16 @@ void gtr_action_set_sensitive(char const* name, gboolean b)
{ {
GtkAction* action = get_action(name); GtkAction* action = get_action(name);
g_assert(action != NULL); g_assert(action != nullptr);
g_object_set(action, "sensitive", b, NULL); g_object_set(action, "sensitive", b, nullptr);
} }
void gtr_action_set_important(char const* name, gboolean b) void gtr_action_set_important(char const* name, gboolean b)
{ {
GtkAction* action = get_action(name); GtkAction* action = get_action(name);
g_assert(action != NULL); g_assert(action != nullptr);
g_object_set(action, "is-important", b, NULL); g_object_set(action, "is-important", b, nullptr);
} }
void gtr_action_set_toggled(char const* name, gboolean b) void gtr_action_set_toggled(char const* name, gboolean b)

View File

@ -40,7 +40,7 @@
#define MY_CONFIG_NAME "transmission" #define MY_CONFIG_NAME "transmission"
static char* gl_confdir = NULL; static char* gl_confdir = nullptr;
void gtr_pref_init(char const* config_dir) void gtr_pref_init(char const* config_dir)
{ {
@ -63,12 +63,12 @@ static void tr_prefs_init_defaults(tr_variant* d)
dir = g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD); dir = g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD);
if (dir == NULL) if (dir == nullptr)
{ {
dir = g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP); dir = g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP);
} }
if (dir == NULL) if (dir == nullptr)
{ {
dir = tr_getDefaultDownloadDir(); dir = tr_getDefaultDownloadDir();
} }
@ -109,7 +109,7 @@ static void tr_prefs_init_defaults(tr_variant* d)
static void ensure_sound_cmd_is_a_list(tr_variant* dict) static void ensure_sound_cmd_is_a_list(tr_variant* dict)
{ {
tr_quark key = TR_KEY_torrent_complete_sound_command; tr_quark key = TR_KEY_torrent_complete_sound_command;
tr_variant* list = NULL; tr_variant* list = nullptr;
if (tr_variantDictFindList(dict, key, &list)) if (tr_variantDictFindList(dict, key, &list))
{ {
return; return;
@ -196,9 +196,9 @@ void gtr_pref_flag_set(tr_quark const key, gboolean value)
char** gtr_pref_strv_get(tr_quark const key) char** gtr_pref_strv_get(tr_quark const key)
{ {
char** ret = NULL; char** ret = nullptr;
tr_variant* list = NULL; tr_variant* list = nullptr;
if (tr_variantDictFindList(getPrefs(), key, &list)) if (tr_variantDictFindList(getPrefs(), key, &list))
{ {
size_t out = 0; size_t out = 0;
@ -207,7 +207,7 @@ char** gtr_pref_strv_get(tr_quark const key)
for (size_t i = 0; i < n; ++i) for (size_t i = 0; i < n; ++i)
{ {
char const* str = NULL; char const* str = nullptr;
size_t len = 0; size_t len = 0;
if (tr_variantGetStr(tr_variantListChild(list, i), &str, &len)) if (tr_variantGetStr(tr_variantListChild(list, i), &str, &len))
{ {
@ -223,7 +223,7 @@ char const* gtr_pref_string_get(tr_quark const key)
{ {
char const* str; char const* str;
return tr_variantDictFindStr(getPrefs(), key, &str, NULL) ? str : NULL; return tr_variantDictFindStr(getPrefs(), key, &str, nullptr) ? str : nullptr;
} }
void gtr_pref_string_set(tr_quark const key, char const* value) void gtr_pref_string_set(tr_quark const key, char const* value)

View File

@ -110,9 +110,9 @@ static tr_torrent** getTorrents(struct DetailsImpl* d, int* setmeCount)
int const n = g_slist_length(d->ids); int const n = g_slist_length(d->ids);
tr_torrent** torrents = g_new(tr_torrent*, n); tr_torrent** torrents = g_new(tr_torrent*, n);
for (GSList* l = d->ids; l != NULL; l = l->next) for (GSList* l = d->ids; l != nullptr; l = l->next)
{ {
if ((torrents[torrentCount] = gtr_core_find_torrent(d->core, GPOINTER_TO_INT(l->data))) != NULL) if ((torrents[torrentCount] = gtr_core_find_torrent(d->core, GPOINTER_TO_INT(l->data))) != nullptr)
{ {
++torrentCount; ++torrentCount;
} }
@ -365,7 +365,7 @@ static void torrent_set_bool(struct DetailsImpl* di, tr_quark const key, gboolea
tr_variantDictAddBool(args, key, value); tr_variantDictAddBool(args, key, value);
tr_variant* const ids = tr_variantDictAddList(args, TR_KEY_ids, g_slist_length(di->ids)); tr_variant* const ids = tr_variantDictAddList(args, TR_KEY_ids, g_slist_length(di->ids));
for (GSList* l = di->ids; l != NULL; l = l->next) for (GSList* l = di->ids; l != nullptr; l = l->next)
{ {
tr_variantListAddInt(ids, GPOINTER_TO_INT(l->data)); tr_variantListAddInt(ids, GPOINTER_TO_INT(l->data));
} }
@ -384,7 +384,7 @@ static void torrent_set_int(struct DetailsImpl* di, tr_quark const key, int valu
tr_variantDictAddInt(args, key, value); tr_variantDictAddInt(args, key, value);
tr_variant* const ids = tr_variantDictAddList(args, TR_KEY_ids, g_slist_length(di->ids)); tr_variant* const ids = tr_variantDictAddList(args, TR_KEY_ids, g_slist_length(di->ids));
for (GSList* l = di->ids; l != NULL; l = l->next) for (GSList* l = di->ids; l != nullptr; l = l->next)
{ {
tr_variantListAddInt(ids, GPOINTER_TO_INT(l->data)); tr_variantListAddInt(ids, GPOINTER_TO_INT(l->data));
} }
@ -403,7 +403,7 @@ static void torrent_set_real(struct DetailsImpl* di, tr_quark const key, double
tr_variantDictAddReal(args, key, value); tr_variantDictAddReal(args, key, value);
tr_variant* const ids = tr_variantDictAddList(args, TR_KEY_ids, g_slist_length(di->ids)); tr_variant* const ids = tr_variantDictAddList(args, TR_KEY_ids, g_slist_length(di->ids));
for (GSList* l = di->ids; l != NULL; l = l->next) for (GSList* l = di->ids; l != nullptr; l = l->next)
{ {
tr_variantListAddInt(ids, GPOINTER_TO_INT(l->data)); tr_variantListAddInt(ids, GPOINTER_TO_INT(l->data));
} }
@ -480,7 +480,7 @@ static GtkWidget* ratio_combo_new(void)
TR_ARG_TUPLE(_("Use global settings"), TR_RATIOLIMIT_GLOBAL), TR_ARG_TUPLE(_("Use global settings"), TR_RATIOLIMIT_GLOBAL),
TR_ARG_TUPLE(_("Seed regardless of ratio"), TR_RATIOLIMIT_UNLIMITED), TR_ARG_TUPLE(_("Seed regardless of ratio"), TR_RATIOLIMIT_UNLIMITED),
TR_ARG_TUPLE(_("Stop seeding at ratio:"), TR_RATIOLIMIT_SINGLE), TR_ARG_TUPLE(_("Stop seeding at ratio:"), TR_RATIOLIMIT_SINGLE),
NULL); nullptr);
g_object_set_qdata(G_OBJECT(w), ARG_KEY, GINT_TO_POINTER(TR_KEY_seedRatioMode)); g_object_set_qdata(G_OBJECT(w), ARG_KEY, GINT_TO_POINTER(TR_KEY_seedRatioMode));
return w; return w;
} }
@ -491,7 +491,7 @@ static GtkWidget* idle_combo_new(void)
TR_ARG_TUPLE(_("Use global settings"), TR_IDLELIMIT_GLOBAL), TR_ARG_TUPLE(_("Use global settings"), TR_IDLELIMIT_GLOBAL),
TR_ARG_TUPLE(_("Seed regardless of activity"), TR_IDLELIMIT_UNLIMITED), TR_ARG_TUPLE(_("Seed regardless of activity"), TR_IDLELIMIT_UNLIMITED),
TR_ARG_TUPLE(_("Stop seeding if idle for N minutes:"), TR_IDLELIMIT_SINGLE), TR_ARG_TUPLE(_("Stop seeding if idle for N minutes:"), TR_IDLELIMIT_SINGLE),
NULL); nullptr);
g_object_set_qdata(G_OBJECT(w), ARG_KEY, GINT_TO_POINTER(TR_KEY_seedIdleMode)); g_object_set_qdata(G_OBJECT(w), ARG_KEY, GINT_TO_POINTER(TR_KEY_seedIdleMode));
return w; return w;
} }
@ -525,7 +525,7 @@ static GtkWidget* options_page_new(struct DetailsImpl* d)
w = gtk_spin_button_new_with_range(0, INT_MAX, 5); w = gtk_spin_button_new_with_range(0, INT_MAX, 5);
tag = g_signal_connect(w, "value-changed", G_CALLBACK(down_speed_spun_cb), d); tag = g_signal_connect(w, "value-changed", G_CALLBACK(down_speed_spun_cb), d);
d->down_limit_spin_tag = tag; d->down_limit_spin_tag = tag;
hig_workarea_add_row_w(t, &row, tb, w, NULL); hig_workarea_add_row_w(t, &row, tb, w, nullptr);
d->down_limit_spin = w; d->down_limit_spin = w;
g_snprintf(buf, sizeof(buf), _("Limit _upload speed (%s):"), _(speed_K_str)); g_snprintf(buf, sizeof(buf), _("Limit _upload speed (%s):"), _(speed_K_str));
@ -537,11 +537,11 @@ static GtkWidget* options_page_new(struct DetailsImpl* d)
w = gtk_spin_button_new_with_range(0, INT_MAX, 5); w = gtk_spin_button_new_with_range(0, INT_MAX, 5);
tag = g_signal_connect(w, "value-changed", G_CALLBACK(up_speed_spun_cb), d); tag = g_signal_connect(w, "value-changed", G_CALLBACK(up_speed_spun_cb), d);
d->up_limit_spin_tag = tag; d->up_limit_spin_tag = tag;
hig_workarea_add_row_w(t, &row, tb, w, NULL); hig_workarea_add_row_w(t, &row, tb, w, nullptr);
d->up_limit_sping = w; d->up_limit_sping = w;
w = new_priority_combo(d); w = new_priority_combo(d);
hig_workarea_add_row(t, &row, _("Torrent _priority:"), w, NULL); hig_workarea_add_row(t, &row, _("Torrent _priority:"), w, nullptr);
d->bandwidth_combo = w; d->bandwidth_combo = w;
hig_workarea_add_section_divider(t, &row); hig_workarea_add_section_divider(t, &row);
@ -555,7 +555,7 @@ static GtkWidget* options_page_new(struct DetailsImpl* d)
gtk_entry_set_width_chars(GTK_ENTRY(w), 7); gtk_entry_set_width_chars(GTK_ENTRY(w), 7);
d->ratio_spin_tag = g_signal_connect(w, "value-changed", G_CALLBACK(ratio_spun_cb), d); d->ratio_spin_tag = g_signal_connect(w, "value-changed", G_CALLBACK(ratio_spun_cb), d);
gtk_box_pack_start(GTK_BOX(h), w, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(h), w, FALSE, FALSE, 0);
hig_workarea_add_row(t, &row, _("_Ratio:"), h, NULL); hig_workarea_add_row(t, &row, _("_Ratio:"), h, nullptr);
h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD); h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
w = d->idle_combo = idle_combo_new(); w = d->idle_combo = idle_combo_new();
@ -564,7 +564,7 @@ static GtkWidget* options_page_new(struct DetailsImpl* d)
w = d->idle_spin = gtk_spin_button_new_with_range(1, 40320, 5); w = d->idle_spin = gtk_spin_button_new_with_range(1, 40320, 5);
d->idle_spin_tag = g_signal_connect(w, "value-changed", G_CALLBACK(idle_spun_cb), d); d->idle_spin_tag = g_signal_connect(w, "value-changed", G_CALLBACK(idle_spun_cb), d);
gtk_box_pack_start(GTK_BOX(h), w, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(h), w, FALSE, FALSE, 0);
hig_workarea_add_row(t, &row, _("_Idle:"), h, NULL); hig_workarea_add_row(t, &row, _("_Idle:"), h, nullptr);
hig_workarea_add_section_divider(t, &row); hig_workarea_add_section_divider(t, &row);
hig_workarea_add_section_title(t, &row, _("Peer Connections")); hig_workarea_add_section_title(t, &row, _("Peer Connections"));
@ -617,7 +617,7 @@ static char const* activityString(int activity, bool finished)
* This way if the user has text selected, refreshing won't deselect it */ * This way if the user has text selected, refreshing won't deselect it */
static void gtr_text_buffer_set_text(GtkTextBuffer* b, char const* str) static void gtr_text_buffer_set_text(GtkTextBuffer* b, char const* str)
{ {
if (str == NULL) if (str == nullptr)
{ {
str = ""; str = "";
} }
@ -627,7 +627,7 @@ static void gtr_text_buffer_set_text(GtkTextBuffer* b, char const* str)
gtk_text_buffer_get_bounds(b, &start, &end); gtk_text_buffer_get_bounds(b, &start, &end);
char* old_str = gtk_text_buffer_get_text(b, &start, &end, FALSE); char* old_str = gtk_text_buffer_get_text(b, &start, &end, FALSE);
if (old_str == NULL || g_strcmp0(old_str, str) != 0) if (old_str == nullptr || g_strcmp0(old_str, str) != 0)
{ {
gtk_text_buffer_set_text(b, str, -1); gtk_text_buffer_set_text(b, str, -1);
} }
@ -647,7 +647,7 @@ static char* get_short_date_string(time_t t)
tr_localtime_r(&t, &tm); tr_localtime_r(&t, &tm);
strftime(buf, sizeof(buf), "%d %b %Y", &tm); strftime(buf, sizeof(buf), "%d %b %Y", &tm);
return g_locale_to_utf8(buf, -1, NULL, NULL, NULL); return g_locale_to_utf8(buf, -1, nullptr, nullptr, nullptr);
} }
static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n) static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
@ -701,7 +701,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
} }
else else
{ {
char const* creator = infos[0]->creator != NULL ? infos[0]->creator : ""; char const* creator = infos[0]->creator != nullptr ? infos[0]->creator : "";
time_t const date = infos[0]->dateCreated; time_t const date = infos[0]->dateCreated;
char* datestr = get_short_date_string(date); char* datestr = get_short_date_string(date);
gboolean mixed_creator = FALSE; gboolean mixed_creator = FALSE;
@ -709,7 +709,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
for (int i = 1; i < n; ++i) for (int i = 1; i < n; ++i)
{ {
mixed_creator |= g_strcmp0(creator, infos[i]->creator != NULL ? infos[i]->creator : "") != 0; mixed_creator |= g_strcmp0(creator, infos[i]->creator != nullptr ? infos[i]->creator : "") != 0;
mixed_date |= date != infos[i]->dateCreated; mixed_date |= date != infos[i]->dateCreated;
} }
@ -754,12 +754,12 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
} }
else else
{ {
char const* baseline = infos[0]->comment != NULL ? infos[0]->comment : ""; char const* baseline = infos[0]->comment != nullptr ? infos[0]->comment : "";
bool is_uniform = true; bool is_uniform = true;
for (int i = 1; is_uniform && i < n; ++i) for (int i = 1; is_uniform && i < n; ++i)
{ {
is_uniform = g_strcmp0(baseline, infos[i]->comment != NULL ? infos[i]->comment : "") == 0; is_uniform = g_strcmp0(baseline, infos[i]->comment != nullptr ? infos[i]->comment : "") == 0;
} }
str = is_uniform ? baseline : mixed; str = is_uniform ? baseline : mixed;
@ -839,7 +839,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
} }
else else
{ {
str = tr_strltime(buf, time(NULL) - baseline, sizeof(buf)); str = tr_strltime(buf, time(nullptr) - baseline, sizeof(buf));
} }
} }
@ -1112,7 +1112,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
} }
else else
{ {
time_t const period = time(NULL) - latest; time_t const period = time(nullptr) - latest;
if (period < 5) if (period < 5)
{ {
@ -1148,88 +1148,88 @@ static GtkWidget* info_page_new(struct DetailsImpl* di)
hig_workarea_add_section_title(t, &row, _("Activity")); hig_workarea_add_section_title(t, &row, _("Activity"));
/* size */ /* size */
l = di->size_lb = gtk_label_new(NULL); l = di->size_lb = gtk_label_new(nullptr);
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE); gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
hig_workarea_add_row(t, &row, _("Torrent size:"), l, NULL); hig_workarea_add_row(t, &row, _("Torrent size:"), l, nullptr);
/* have */ /* have */
l = di->have_lb = gtk_label_new(NULL); l = di->have_lb = gtk_label_new(nullptr);
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE); gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
hig_workarea_add_row(t, &row, _("Have:"), l, NULL); hig_workarea_add_row(t, &row, _("Have:"), l, nullptr);
/* uploaded */ /* uploaded */
l = di->ul_lb = gtk_label_new(NULL); l = di->ul_lb = gtk_label_new(nullptr);
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE); gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
hig_workarea_add_row(t, &row, _("Uploaded:"), l, NULL); hig_workarea_add_row(t, &row, _("Uploaded:"), l, nullptr);
/* downloaded */ /* downloaded */
l = di->dl_lb = gtk_label_new(NULL); l = di->dl_lb = gtk_label_new(nullptr);
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE); gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
hig_workarea_add_row(t, &row, _("Downloaded:"), l, NULL); hig_workarea_add_row(t, &row, _("Downloaded:"), l, nullptr);
/* state */ /* state */
l = di->state_lb = gtk_label_new(NULL); l = di->state_lb = gtk_label_new(nullptr);
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE); gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
hig_workarea_add_row(t, &row, _("State:"), l, NULL); hig_workarea_add_row(t, &row, _("State:"), l, nullptr);
/* running for */ /* running for */
l = di->date_started_lb = gtk_label_new(NULL); l = di->date_started_lb = gtk_label_new(nullptr);
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE); gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
hig_workarea_add_row(t, &row, _("Running time:"), l, NULL); hig_workarea_add_row(t, &row, _("Running time:"), l, nullptr);
/* eta */ /* eta */
l = di->eta_lb = gtk_label_new(NULL); l = di->eta_lb = gtk_label_new(nullptr);
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE); gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
hig_workarea_add_row(t, &row, _("Remaining time:"), l, NULL); hig_workarea_add_row(t, &row, _("Remaining time:"), l, nullptr);
/* last activity */ /* last activity */
l = di->last_activity_lb = gtk_label_new(NULL); l = di->last_activity_lb = gtk_label_new(nullptr);
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE); gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
hig_workarea_add_row(t, &row, _("Last activity:"), l, NULL); hig_workarea_add_row(t, &row, _("Last activity:"), l, nullptr);
/* error */ /* error */
l = static_cast<GtkWidget*>(g_object_new(GTK_TYPE_LABEL, "selectable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL)); l = static_cast<GtkWidget*>(g_object_new(GTK_TYPE_LABEL, "selectable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, nullptr));
hig_workarea_add_row(t, &row, _("Error:"), l, NULL); hig_workarea_add_row(t, &row, _("Error:"), l, nullptr);
di->error_lb = l; di->error_lb = l;
hig_workarea_add_section_divider(t, &row); hig_workarea_add_section_divider(t, &row);
hig_workarea_add_section_title(t, &row, _("Details")); hig_workarea_add_section_title(t, &row, _("Details"));
/* destination */ /* destination */
l = static_cast<GtkWidget*>(g_object_new(GTK_TYPE_LABEL, "selectable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL)); l = static_cast<GtkWidget*>(g_object_new(GTK_TYPE_LABEL, "selectable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, nullptr));
hig_workarea_add_row(t, &row, _("Location:"), l, NULL); hig_workarea_add_row(t, &row, _("Location:"), l, nullptr);
di->destination_lb = l; di->destination_lb = l;
/* hash */ /* hash */
l = static_cast<GtkWidget*>(g_object_new(GTK_TYPE_LABEL, "selectable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL)); l = static_cast<GtkWidget*>(g_object_new(GTK_TYPE_LABEL, "selectable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, nullptr));
hig_workarea_add_row(t, &row, _("Hash:"), l, NULL); hig_workarea_add_row(t, &row, _("Hash:"), l, nullptr);
di->hash_lb = l; di->hash_lb = l;
/* privacy */ /* privacy */
l = gtk_label_new(NULL); l = gtk_label_new(nullptr);
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE); gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
hig_workarea_add_row(t, &row, _("Privacy:"), l, NULL); hig_workarea_add_row(t, &row, _("Privacy:"), l, nullptr);
di->privacy_lb = l; di->privacy_lb = l;
/* origins */ /* origins */
l = static_cast<GtkWidget*>(g_object_new(GTK_TYPE_LABEL, "selectable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL)); l = static_cast<GtkWidget*>(g_object_new(GTK_TYPE_LABEL, "selectable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, nullptr));
hig_workarea_add_row(t, &row, _("Origin:"), l, NULL); hig_workarea_add_row(t, &row, _("Origin:"), l, nullptr);
di->origin_lb = l; di->origin_lb = l;
/* comment */ /* comment */
b = di->comment_buffer = gtk_text_buffer_new(NULL); b = di->comment_buffer = gtk_text_buffer_new(nullptr);
w = gtk_text_view_new_with_buffer(b); w = gtk_text_view_new_with_buffer(b);
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(w), GTK_WRAP_WORD); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(w), GTK_WRAP_WORD);
gtk_text_view_set_editable(GTK_TEXT_VIEW(w), FALSE); gtk_text_view_set_editable(GTK_TEXT_VIEW(w), FALSE);
sw = gtk_scrolled_window_new(NULL, NULL); sw = gtk_scrolled_window_new(nullptr, nullptr);
gtk_widget_set_size_request(sw, 350, 36); gtk_widget_set_size_request(sw, 350, 36);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(sw), w); gtk_container_add(GTK_CONTAINER(sw), w);
fr = gtk_frame_new(NULL); fr = gtk_frame_new(nullptr);
gtk_frame_set_shadow_type(GTK_FRAME(fr), GTK_SHADOW_IN); gtk_frame_set_shadow_type(GTK_FRAME(fr), GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(fr), sw); gtk_container_add(GTK_CONTAINER(fr), sw);
w = hig_workarea_add_tall_row(t, &row, _("Comment:"), fr, NULL); w = hig_workarea_add_tall_row(t, &row, _("Comment:"), fr, nullptr);
g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_START, NULL); g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_START, nullptr);
hig_workarea_add_section_divider(t, &row); hig_workarea_add_section_divider(t, &row);
return t; return t;
@ -1399,10 +1399,10 @@ static void initPeerRow(
char const* torrentName, char const* torrentName,
tr_peer_stat const* peer) tr_peer_stat const* peer)
{ {
g_return_if_fail(peer != NULL); g_return_if_fail(peer != nullptr);
char const* client = peer->client; char const* client = peer->client;
if (client == NULL || g_strcmp0(client, "Unknown Client") == 0) if (client == nullptr || g_strcmp0(client, "Unknown Client") == 0)
{ {
client = ""; client = "";
} }
@ -1424,7 +1424,7 @@ static void initPeerRow(
TR_ARG_TUPLE(PEER_COL_ADDRESS, peer->addr), TR_ARG_TUPLE(PEER_COL_ADDRESS, peer->addr),
TR_ARG_TUPLE(PEER_COL_ADDRESS_COLLATED, collated_name), TR_ARG_TUPLE(PEER_COL_ADDRESS_COLLATED, collated_name),
TR_ARG_TUPLE(PEER_COL_CLIENT, client), TR_ARG_TUPLE(PEER_COL_CLIENT, client),
TR_ARG_TUPLE(PEER_COL_ENCRYPTION_STOCK_ID, peer->isEncrypted ? "transmission-lock" : NULL), TR_ARG_TUPLE(PEER_COL_ENCRYPTION_STOCK_ID, peer->isEncrypted ? "transmission-lock" : nullptr),
TR_ARG_TUPLE(PEER_COL_KEY, key), TR_ARG_TUPLE(PEER_COL_KEY, key),
TR_ARG_TUPLE(PEER_COL_TORRENT_NAME, torrentName), TR_ARG_TUPLE(PEER_COL_TORRENT_NAME, torrentName),
-1); -1);
@ -1441,7 +1441,7 @@ static void refreshPeerRow(GtkListStore* store, GtkTreeIter* iter, tr_peer_stat
char cancelled_by_peer[64] = { '\0' }; char cancelled_by_peer[64] = { '\0' };
char cancelled_by_client[64] = { '\0' }; char cancelled_by_client[64] = { '\0' };
g_return_if_fail(peer != NULL); g_return_if_fail(peer != nullptr);
if (peer->rateToPeer_KBps > 0.01) if (peer->rateToPeer_KBps > 0.01)
{ {
@ -1526,7 +1526,7 @@ static void refreshPeerList(struct DetailsImpl* di, tr_torrent** torrents, int n
/* step 2: mark all the peers in the list as not-updated */ /* step 2: mark all the peers in the list as not-updated */
GtkTreeModel* const model = GTK_TREE_MODEL(store); GtkTreeModel* const model = GTK_TREE_MODEL(store);
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, 0))
{ {
do do
{ {
@ -1546,7 +1546,7 @@ static void refreshPeerList(struct DetailsImpl* di, tr_torrent** torrents, int n
g_snprintf(key, sizeof(key), "%d.%s", tr_torrentId(tor), s->addr); g_snprintf(key, sizeof(key), "%d.%s", tr_torrentId(tor), s->addr);
if (g_hash_table_lookup(hash, key) == NULL) if (g_hash_table_lookup(hash, key) == nullptr)
{ {
GtkTreePath* p; GtkTreePath* p;
gtk_list_store_append(store, &iter); gtk_list_store_append(store, &iter);
@ -1579,7 +1579,7 @@ static void refreshPeerList(struct DetailsImpl* di, tr_torrent** torrents, int n
} }
/* step 5: remove peers that have disappeared */ /* step 5: remove peers that have disappeared */
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, 0))
{ {
gboolean more = TRUE; gboolean more = TRUE;
@ -1622,7 +1622,7 @@ static void refreshWebseedList(struct DetailsImpl* di, tr_torrent** torrents, in
GtkTreeModel* model = GTK_TREE_MODEL(store); GtkTreeModel* model = GTK_TREE_MODEL(store);
/* step 1: mark all webseeds as not-updated */ /* step 1: mark all webseeds as not-updated */
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, 0))
{ {
do do
{ {
@ -1644,7 +1644,7 @@ static void refreshWebseedList(struct DetailsImpl* di, tr_torrent** torrents, in
char const* url = inf->webseeds[j]; char const* url = inf->webseeds[j];
g_snprintf(key, sizeof(key), "%d.%s", tr_torrentId(tor), url); g_snprintf(key, sizeof(key), "%d.%s", tr_torrentId(tor), url);
if (g_hash_table_lookup(hash, key) == NULL) if (g_hash_table_lookup(hash, key) == nullptr)
{ {
GtkTreePath* p; GtkTreePath* p;
gtk_list_store_append(store, &iter); gtk_list_store_append(store, &iter);
@ -1694,7 +1694,7 @@ static void refreshWebseedList(struct DetailsImpl* di, tr_torrent** torrents, in
} }
/* step 4: remove webseeds that have disappeared */ /* step 4: remove webseeds that have disappeared */
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, 0))
{ {
gboolean more = TRUE; gboolean more = TRUE;
@ -1712,7 +1712,7 @@ static void refreshWebseedList(struct DetailsImpl* di, tr_torrent** torrents, in
char* key; char* key;
gtk_tree_model_get(model, &iter, WEBSEED_COL_KEY, &key, -1); gtk_tree_model_get(model, &iter, WEBSEED_COL_KEY, &key, -1);
if (key != NULL) if (key != nullptr)
{ {
g_hash_table_remove(hash, key); g_hash_table_remove(hash, key);
} }
@ -1746,11 +1746,11 @@ static gboolean onPeerViewQueryTooltip(
GtkTreeModel* model; GtkTreeModel* model;
gboolean show_tip = FALSE; gboolean show_tip = FALSE;
if (gtk_tree_view_get_tooltip_context(GTK_TREE_VIEW(widget), &x, &y, keyboard_tip, &model, NULL, &iter)) if (gtk_tree_view_get_tooltip_context(GTK_TREE_VIEW(widget), &x, &y, keyboard_tip, &model, nullptr, &iter))
{ {
char* name = NULL; char* name = nullptr;
char* addr = NULL; char* addr = nullptr;
char* flagstr = NULL; char* flagstr = nullptr;
auto* di = static_cast<DetailsImpl*>(gdi); auto* di = static_cast<DetailsImpl*>(gdi);
GString* gstr = di->gstr; GString* gstr = di->gstr;
@ -1769,7 +1769,7 @@ static gboolean onPeerViewQueryTooltip(
for (char const* pch = flagstr; !tr_str_is_empty(pch); ++pch) for (char const* pch = flagstr; !tr_str_is_empty(pch); ++pch)
{ {
char const* s = NULL; char const* s = nullptr;
switch (*pch) switch (*pch)
{ {
@ -1822,7 +1822,7 @@ static gboolean onPeerViewQueryTooltip(
break; break;
} }
if (s != NULL) if (s != nullptr)
{ {
g_string_append_printf(gstr, "%c: %s\n", *pch, s); g_string_append_printf(gstr, "%c: %s\n", *pch, s);
} }
@ -1894,7 +1894,7 @@ static void setPeerViewColumns(GtkTreeView* peer_view)
view_columns[n++] = PEER_COL_CLIENT; view_columns[n++] = PEER_COL_CLIENT;
/* remove any existing columns */ /* remove any existing columns */
while ((c = gtk_tree_view_get_column(peer_view, 0)) != NULL) while ((c = gtk_tree_view_get_column(peer_view, 0)) != nullptr)
{ {
gtk_tree_view_remove_column(peer_view, c); gtk_tree_view_remove_column(peer_view, c);
} }
@ -1909,77 +1909,77 @@ static void setPeerViewColumns(GtkTreeView* peer_view)
{ {
case PEER_COL_ADDRESS: case PEER_COL_ADDRESS:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL); c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, nullptr);
sort_col = PEER_COL_ADDRESS_COLLATED; sort_col = PEER_COL_ADDRESS_COLLATED;
break; break;
case PEER_COL_PROGRESS: case PEER_COL_PROGRESS:
r = gtk_cell_renderer_progress_new(); r = gtk_cell_renderer_progress_new();
c = gtk_tree_view_column_new_with_attributes(t, r, "value", PEER_COL_PROGRESS, NULL); c = gtk_tree_view_column_new_with_attributes(t, r, "value", PEER_COL_PROGRESS, nullptr);
break; break;
case PEER_COL_ENCRYPTION_STOCK_ID: case PEER_COL_ENCRYPTION_STOCK_ID:
r = gtk_cell_renderer_pixbuf_new(); r = gtk_cell_renderer_pixbuf_new();
g_object_set(r, "xalign", (gfloat)0.0, "yalign", (gfloat)0.5, NULL); g_object_set(r, "xalign", (gfloat)0.0, "yalign", (gfloat)0.5, nullptr);
c = gtk_tree_view_column_new_with_attributes(t, r, "stock-id", PEER_COL_ENCRYPTION_STOCK_ID, NULL); c = gtk_tree_view_column_new_with_attributes(t, r, "stock-id", PEER_COL_ENCRYPTION_STOCK_ID, nullptr);
gtk_tree_view_column_set_sizing(c, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_column_set_sizing(c, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_fixed_width(c, 20); gtk_tree_view_column_set_fixed_width(c, 20);
break; break;
case PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING: case PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL); c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, nullptr);
sort_col = PEER_COL_DOWNLOAD_REQUEST_COUNT_INT; sort_col = PEER_COL_DOWNLOAD_REQUEST_COUNT_INT;
break; break;
case PEER_COL_UPLOAD_REQUEST_COUNT_STRING: case PEER_COL_UPLOAD_REQUEST_COUNT_STRING:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL); c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, nullptr);
sort_col = PEER_COL_UPLOAD_REQUEST_COUNT_INT; sort_col = PEER_COL_UPLOAD_REQUEST_COUNT_INT;
break; break;
case PEER_COL_BLOCKS_DOWNLOADED_COUNT_STRING: case PEER_COL_BLOCKS_DOWNLOADED_COUNT_STRING:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL); c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, nullptr);
sort_col = PEER_COL_BLOCKS_DOWNLOADED_COUNT_INT; sort_col = PEER_COL_BLOCKS_DOWNLOADED_COUNT_INT;
break; break;
case PEER_COL_BLOCKS_UPLOADED_COUNT_STRING: case PEER_COL_BLOCKS_UPLOADED_COUNT_STRING:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL); c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, nullptr);
sort_col = PEER_COL_BLOCKS_UPLOADED_COUNT_INT; sort_col = PEER_COL_BLOCKS_UPLOADED_COUNT_INT;
break; break;
case PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_STRING: case PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_STRING:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL); c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, nullptr);
sort_col = PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_INT; sort_col = PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_INT;
break; break;
case PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_STRING: case PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_STRING:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL); c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, nullptr);
sort_col = PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_INT; sort_col = PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_INT;
break; break;
case PEER_COL_DOWNLOAD_RATE_STRING: case PEER_COL_DOWNLOAD_RATE_STRING:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
g_object_set(G_OBJECT(r), "xalign", 1.0F, NULL); g_object_set(G_OBJECT(r), "xalign", 1.0F, nullptr);
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL); c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, nullptr);
sort_col = PEER_COL_DOWNLOAD_RATE_DOUBLE; sort_col = PEER_COL_DOWNLOAD_RATE_DOUBLE;
break; break;
case PEER_COL_UPLOAD_RATE_STRING: case PEER_COL_UPLOAD_RATE_STRING:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
g_object_set(G_OBJECT(r), "xalign", 1.0F, NULL); g_object_set(G_OBJECT(r), "xalign", 1.0F, nullptr);
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL); c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, nullptr);
sort_col = PEER_COL_UPLOAD_RATE_DOUBLE; sort_col = PEER_COL_UPLOAD_RATE_DOUBLE;
break; break;
case PEER_COL_CLIENT: case PEER_COL_CLIENT:
case PEER_COL_FLAGS: case PEER_COL_FLAGS:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL); c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, nullptr);
break; break;
default: default:
@ -2019,7 +2019,7 @@ static GtkWidget* peer_page_new(struct DetailsImpl* di)
GtkWidget* ret; GtkWidget* ret;
GtkWidget* sw; GtkWidget* sw;
GtkWidget* vbox; GtkWidget* vbox;
GtkWidget* webtree = NULL; GtkWidget* webtree = nullptr;
GtkTreeModel* m; GtkTreeModel* m;
GtkTreeViewColumn* c; GtkTreeViewColumn* c;
GtkCellRenderer* r; GtkCellRenderer* r;
@ -2028,24 +2028,24 @@ static GtkWidget* peer_page_new(struct DetailsImpl* di)
store = di->webseed_store = webseed_model_new(); store = di->webseed_store = webseed_model_new();
v = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); v = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
g_signal_connect(v, "button-release-event", G_CALLBACK(on_tree_view_button_released), NULL); g_signal_connect(v, "button-release-event", G_CALLBACK(on_tree_view_button_released), nullptr);
g_object_unref(store); g_object_unref(store);
str = getWebseedColumnNames(WEBSEED_COL_URL); str = getWebseedColumnNames(WEBSEED_COL_URL);
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
g_object_set(G_OBJECT(r), "ellipsize", PANGO_ELLIPSIZE_END, NULL); g_object_set(G_OBJECT(r), "ellipsize", PANGO_ELLIPSIZE_END, nullptr);
c = gtk_tree_view_column_new_with_attributes(str, r, "text", WEBSEED_COL_URL, NULL); c = gtk_tree_view_column_new_with_attributes(str, r, "text", WEBSEED_COL_URL, nullptr);
g_object_set(G_OBJECT(c), "expand", TRUE, NULL); g_object_set(G_OBJECT(c), "expand", TRUE, nullptr);
gtk_tree_view_column_set_sort_column_id(c, WEBSEED_COL_URL); gtk_tree_view_column_set_sort_column_id(c, WEBSEED_COL_URL);
gtk_tree_view_append_column(GTK_TREE_VIEW(v), c); gtk_tree_view_append_column(GTK_TREE_VIEW(v), c);
str = getWebseedColumnNames(WEBSEED_COL_DOWNLOAD_RATE_STRING); str = getWebseedColumnNames(WEBSEED_COL_DOWNLOAD_RATE_STRING);
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
c = gtk_tree_view_column_new_with_attributes(str, r, "text", WEBSEED_COL_DOWNLOAD_RATE_STRING, NULL); c = gtk_tree_view_column_new_with_attributes(str, r, "text", WEBSEED_COL_DOWNLOAD_RATE_STRING, nullptr);
gtk_tree_view_column_set_sort_column_id(c, WEBSEED_COL_DOWNLOAD_RATE_DOUBLE); gtk_tree_view_column_set_sort_column_id(c, WEBSEED_COL_DOWNLOAD_RATE_DOUBLE);
gtk_tree_view_append_column(GTK_TREE_VIEW(v), c); gtk_tree_view_append_column(GTK_TREE_VIEW(v), c);
w = gtk_scrolled_window_new(NULL, NULL); w = gtk_scrolled_window_new(nullptr, nullptr);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(w), GTK_SHADOW_IN); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(w), GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(w), v); gtk_container_add(GTK_CONTAINER(w), v);
@ -2058,16 +2058,16 @@ static GtkWidget* peer_page_new(struct DetailsImpl* di)
store = di->peer_store = peer_store_new(); store = di->peer_store = peer_store_new();
m = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(store)); m = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(store));
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(m), PEER_COL_PROGRESS, GTK_SORT_DESCENDING); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(m), PEER_COL_PROGRESS, GTK_SORT_DESCENDING);
v = GTK_WIDGET(g_object_new(GTK_TYPE_TREE_VIEW, "model", m, "rules-hint", TRUE, "has-tooltip", TRUE, NULL)); v = GTK_WIDGET(g_object_new(GTK_TYPE_TREE_VIEW, "model", m, "rules-hint", TRUE, "has-tooltip", TRUE, nullptr));
di->peer_view = v; di->peer_view = v;
g_signal_connect(v, "query-tooltip", G_CALLBACK(onPeerViewQueryTooltip), di); g_signal_connect(v, "query-tooltip", G_CALLBACK(onPeerViewQueryTooltip), di);
g_object_unref(store); g_object_unref(store);
g_signal_connect(v, "button-release-event", G_CALLBACK(on_tree_view_button_released), NULL); g_signal_connect(v, "button-release-event", G_CALLBACK(on_tree_view_button_released), nullptr);
setPeerViewColumns(GTK_TREE_VIEW(v)); setPeerViewColumns(GTK_TREE_VIEW(v));
w = sw = gtk_scrolled_window_new(NULL, NULL); w = sw = gtk_scrolled_window_new(nullptr, nullptr);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(w), GTK_SHADOW_IN); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(w), GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(w), v); gtk_container_add(GTK_CONTAINER(w), v);
@ -2254,14 +2254,15 @@ static void buildTrackerSummary(GString* gstr, char const* key, tr_tracker_stat
{ {
// hostname // hostname
g_string_append(gstr, st->isBackup ? "<i>" : "<b>"); g_string_append(gstr, st->isBackup ? "<i>" : "<b>");
char* const str = key != NULL ? g_markup_printf_escaped("%s - %s", st->host, key) : g_markup_printf_escaped("%s", st->host); char* const str = key != nullptr ? g_markup_printf_escaped("%s - %s", st->host, key) :
g_markup_printf_escaped("%s", st->host);
g_string_append(gstr, str); g_string_append(gstr, str);
g_free(str); g_free(str);
g_string_append(gstr, st->isBackup ? "</i>" : "</b>"); g_string_append(gstr, st->isBackup ? "</i>" : "</b>");
if (!st->isBackup) if (!st->isBackup)
{ {
time_t const now = time(NULL); time_t const now = time(nullptr);
appendAnnounceInfo(st, now, gstr); appendAnnounceInfo(st, now, gstr);
@ -2337,7 +2338,7 @@ static void favicon_ready_cb(gpointer pixbuf, gpointer vreference)
GtkTreeIter iter; GtkTreeIter iter;
auto* reference = static_cast<GtkTreeRowReference*>(vreference); auto* reference = static_cast<GtkTreeRowReference*>(vreference);
if (pixbuf != NULL) if (pixbuf != nullptr)
{ {
GtkTreePath* const path = gtk_tree_row_reference_get_path(reference); GtkTreePath* const path = gtk_tree_row_reference_get_path(reference);
GtkTreeModel* const model = gtk_tree_row_reference_get_model(reference); GtkTreeModel* const model = gtk_tree_row_reference_get_model(reference);
@ -2375,7 +2376,7 @@ static void refreshTracker(struct DetailsImpl* di, tr_torrent** torrents, int n)
/* step 2: mark all the trackers in the list as not-updated */ /* step 2: mark all the trackers in the list as not-updated */
GtkTreeModel* const model = GTK_TREE_MODEL(store); GtkTreeModel* const model = GTK_TREE_MODEL(store);
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, 0))
{ {
do do
{ {
@ -2398,7 +2399,7 @@ static void refreshTracker(struct DetailsImpl* di, tr_torrent** torrents, int n)
g_string_truncate(gstr, 0); g_string_truncate(gstr, 0);
g_string_append_printf(gstr, "%d\t%d\t%s", torrent_id, st->tier, st->announce); g_string_append_printf(gstr, "%d\t%d\t%s", torrent_id, st->tier, st->announce);
if (g_hash_table_lookup(hash, gstr->str) == NULL) if (g_hash_table_lookup(hash, gstr->str) == nullptr)
{ {
gtk_list_store_insert_with_values( gtk_list_store_insert_with_values(
store, store,
@ -2423,7 +2424,7 @@ static void refreshTracker(struct DetailsImpl* di, tr_torrent** torrents, int n)
for (int i = 0; i < n; ++i) for (int i = 0; i < n; ++i)
{ {
tr_torrent const* tor = torrents[i]; tr_torrent const* tor = torrents[i];
char const* summary_name = n > 1 ? tr_torrentName(tor) : NULL; char const* summary_name = n > 1 ? tr_torrentName(tor) : nullptr;
for (int j = 0; j < statCount[i]; ++j) for (int j = 0; j < statCount[i]; ++j)
{ {
@ -2454,7 +2455,7 @@ static void refreshTracker(struct DetailsImpl* di, tr_torrent** torrents, int n)
} }
/* step 5: remove trackers that have disappeared */ /* step 5: remove trackers that have disappeared */
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, 0))
{ {
gboolean more = TRUE; gboolean more = TRUE;
@ -2517,7 +2518,7 @@ static void on_edit_trackers_response(GtkDialog* dialog, int response, gpointer
auto* const text_buffer = static_cast<GtkTextBuffer*>(g_object_get_qdata(G_OBJECT(dialog), TEXT_BUFFER_KEY)); auto* const text_buffer = static_cast<GtkTextBuffer*>(g_object_get_qdata(G_OBJECT(dialog), TEXT_BUFFER_KEY));
tr_torrent* const tor = gtr_core_find_torrent(di->core, torrent_id); tr_torrent* const tor = gtr_core_find_torrent(di->core, torrent_id);
if (tor != NULL) if (tor != nullptr)
{ {
/* build the array of trackers */ /* build the array of trackers */
GtkTextIter start; GtkTextIter start;
@ -2530,7 +2531,7 @@ static void on_edit_trackers_response(GtkDialog* dialog, int response, gpointer
int n = 0; int n = 0;
int tier = 0; int tier = 0;
for (int i = 0; tracker_strings[i] != NULL; ++i) for (int i = 0; tracker_strings[i] != nullptr; ++i)
{ {
char* const str = tracker_strings[i]; char* const str = tracker_strings[i];
@ -2612,7 +2613,7 @@ static void on_edit_trackers(GtkButton* button, gpointer data)
auto* di = static_cast<DetailsImpl*>(data); auto* di = static_cast<DetailsImpl*>(data);
tr_torrent const* tor = tracker_list_get_current_torrent(di); tr_torrent const* tor = tracker_list_get_current_torrent(di);
if (tor != NULL) if (tor != nullptr)
{ {
guint row; guint row;
GtkWidget* w; GtkWidget* w;
@ -2633,29 +2634,29 @@ static void on_edit_trackers(GtkButton* button, gpointer data)
GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL), TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL),
TR_ARG_TUPLE(_("_Save"), GTK_RESPONSE_ACCEPT), TR_ARG_TUPLE(_("_Save"), GTK_RESPONSE_ACCEPT),
NULL); nullptr);
g_signal_connect(d, "response", G_CALLBACK(on_edit_trackers_response), data); g_signal_connect(d, "response", G_CALLBACK(on_edit_trackers_response), data);
row = 0; row = 0;
t = hig_workarea_create(); t = hig_workarea_create();
hig_workarea_add_section_title(t, &row, _("Tracker Announce URLs")); hig_workarea_add_section_title(t, &row, _("Tracker Announce URLs"));
l = gtk_label_new(NULL); l = gtk_label_new(nullptr);
gtk_label_set_markup( gtk_label_set_markup(
GTK_LABEL(l), GTK_LABEL(l),
_("To add a backup URL, add it on the line after the primary URL.\n" _("To add a backup URL, add it on the line after the primary URL.\n"
"To add another primary URL, add it after a blank line.")); "To add another primary URL, add it after a blank line."));
gtk_label_set_justify(GTK_LABEL(l), GTK_JUSTIFY_LEFT); gtk_label_set_justify(GTK_LABEL(l), GTK_JUSTIFY_LEFT);
g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
hig_workarea_add_wide_control(t, &row, l); hig_workarea_add_wide_control(t, &row, l);
w = gtk_text_view_new(); w = gtk_text_view_new();
g_string_truncate(gstr, 0); g_string_truncate(gstr, 0);
get_editable_tracker_list(gstr, tor); get_editable_tracker_list(gstr, tor);
gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(w)), gstr->str, -1); gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(w)), gstr->str, -1);
fr = gtk_frame_new(NULL); fr = gtk_frame_new(nullptr);
gtk_frame_set_shadow_type(GTK_FRAME(fr), GTK_SHADOW_IN); gtk_frame_set_shadow_type(GTK_FRAME(fr), GTK_SHADOW_IN);
sw = gtk_scrolled_window_new(NULL, NULL); sw = gtk_scrolled_window_new(nullptr, nullptr);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(sw), w); gtk_container_add(GTK_CONTAINER(sw), w);
gtk_container_add(GTK_CONTAINER(fr), sw); gtk_container_add(GTK_CONTAINER(fr), sw);
@ -2677,8 +2678,8 @@ static void on_tracker_list_selection_changed(GtkTreeSelection* sel, gpointer gd
tr_torrent const* tor = tracker_list_get_current_torrent(di); tr_torrent const* tor = tracker_list_get_current_torrent(di);
gtk_widget_set_sensitive(di->remove_tracker_button, n > 0); gtk_widget_set_sensitive(di->remove_tracker_button, n > 0);
gtk_widget_set_sensitive(di->add_tracker_button, tor != NULL); gtk_widget_set_sensitive(di->add_tracker_button, tor != nullptr);
gtk_widget_set_sensitive(di->edit_trackers_button, tor != NULL); gtk_widget_set_sensitive(di->edit_trackers_button, tor != nullptr);
} }
static void on_add_tracker_response(GtkDialog* dialog, int response, gpointer gdi) static void on_add_tracker_response(GtkDialog* dialog, int response, gpointer gdi)
@ -2736,7 +2737,7 @@ static void on_tracker_list_add_button_clicked(GtkButton const* button, gpointer
auto* di = static_cast<DetailsImpl*>(gdi); auto* di = static_cast<DetailsImpl*>(gdi);
tr_torrent const* tor = tracker_list_get_current_torrent(di); tr_torrent const* tor = tracker_list_get_current_torrent(di);
if (tor != NULL) if (tor != nullptr)
{ {
guint row; guint row;
GtkWidget* e; GtkWidget* e;
@ -2752,7 +2753,7 @@ static void on_tracker_list_add_button_clicked(GtkButton const* button, gpointer
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL), TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL),
TR_ARG_TUPLE(_("_Add"), GTK_RESPONSE_ACCEPT), TR_ARG_TUPLE(_("_Add"), GTK_RESPONSE_ACCEPT),
NULL); nullptr);
g_signal_connect(w, "response", G_CALLBACK(on_add_tracker_response), gdi); g_signal_connect(w, "response", G_CALLBACK(on_add_tracker_response), gdi);
row = 0; row = 0;
@ -2763,7 +2764,7 @@ static void on_tracker_list_add_button_clicked(GtkButton const* button, gpointer
gtr_paste_clipboard_url_into_entry(e); gtr_paste_clipboard_url_into_entry(e);
g_object_set_qdata(G_OBJECT(w), URL_ENTRY_KEY, e); g_object_set_qdata(G_OBJECT(w), URL_ENTRY_KEY, e);
g_object_set_qdata(G_OBJECT(w), TORRENT_ID_KEY, GINT_TO_POINTER(tr_torrentId(tor))); g_object_set_qdata(G_OBJECT(w), TORRENT_ID_KEY, GINT_TO_POINTER(tr_torrentId(tor)));
hig_workarea_add_row(t, &row, _("_Announce URL:"), e, NULL); hig_workarea_add_row(t, &row, _("_Announce URL:"), e, nullptr);
gtr_dialog_set_content(GTK_DIALOG(w), t); gtr_dialog_set_content(GTK_DIALOG(w), t);
gtk_widget_show_all(w); gtk_widget_show_all(w);
} }
@ -2840,16 +2841,16 @@ static GtkWidget* tracker_page_new(struct DetailsImpl* di)
(GDestroyNotify)g_free, (GDestroyNotify)g_free,
(GDestroyNotify)gtk_tree_row_reference_free); (GDestroyNotify)gtk_tree_row_reference_free);
di->trackers_filtered = gtk_tree_model_filter_new(GTK_TREE_MODEL(di->tracker_store), NULL); di->trackers_filtered = gtk_tree_model_filter_new(GTK_TREE_MODEL(di->tracker_store), nullptr);
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(di->trackers_filtered), trackerVisibleFunc, di, NULL); gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(di->trackers_filtered), trackerVisibleFunc, di, nullptr);
hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG); hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
v = di->tracker_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(di->trackers_filtered)); v = di->tracker_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(di->trackers_filtered));
g_object_unref(di->trackers_filtered); g_object_unref(di->trackers_filtered);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(v), FALSE); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(v), FALSE);
g_signal_connect(v, "button-press-event", G_CALLBACK(on_tree_view_button_pressed), NULL); g_signal_connect(v, "button-press-event", G_CALLBACK(on_tree_view_button_pressed), nullptr);
g_signal_connect(v, "button-release-event", G_CALLBACK(on_tree_view_button_released), NULL); g_signal_connect(v, "button-release-event", G_CALLBACK(on_tree_view_button_released), nullptr);
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(v)); sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(v));
g_signal_connect(sel, "changed", G_CALLBACK(on_tracker_list_selection_changed), di); g_signal_connect(sel, "changed", G_CALLBACK(on_tracker_list_selection_changed), di);
@ -2859,19 +2860,19 @@ static GtkWidget* tracker_page_new(struct DetailsImpl* di)
gtk_tree_view_append_column(GTK_TREE_VIEW(v), c); gtk_tree_view_append_column(GTK_TREE_VIEW(v), c);
r = gtk_cell_renderer_pixbuf_new(); r = gtk_cell_renderer_pixbuf_new();
g_object_set(r, "width", 20 + (GUI_PAD_SMALL * 2), "xpad", GUI_PAD_SMALL, "ypad", pad, "yalign", 0.0F, NULL); g_object_set(r, "width", 20 + (GUI_PAD_SMALL * 2), "xpad", GUI_PAD_SMALL, "ypad", pad, "yalign", 0.0F, nullptr);
gtk_tree_view_column_pack_start(c, r, FALSE); gtk_tree_view_column_pack_start(c, r, FALSE);
gtk_tree_view_column_add_attribute(c, r, "pixbuf", TRACKER_COL_FAVICON); gtk_tree_view_column_add_attribute(c, r, "pixbuf", TRACKER_COL_FAVICON);
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
g_object_set(G_OBJECT(r), "ellipsize", PANGO_ELLIPSIZE_END, "xpad", GUI_PAD_SMALL, "ypad", pad, NULL); g_object_set(G_OBJECT(r), "ellipsize", PANGO_ELLIPSIZE_END, "xpad", GUI_PAD_SMALL, "ypad", pad, nullptr);
gtk_tree_view_column_pack_start(c, r, TRUE); gtk_tree_view_column_pack_start(c, r, TRUE);
gtk_tree_view_column_add_attribute(c, r, "markup", TRACKER_COL_TEXT); gtk_tree_view_column_add_attribute(c, r, "markup", TRACKER_COL_TEXT);
sw = gtk_scrolled_window_new(NULL, NULL); sw = gtk_scrolled_window_new(nullptr, nullptr);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(sw), v); gtk_container_add(GTK_CONTAINER(sw), v);
w = gtk_frame_new(NULL); w = gtk_frame_new(nullptr);
gtk_frame_set_shadow_type(GTK_FRAME(w), GTK_SHADOW_IN); gtk_frame_set_shadow_type(GTK_FRAME(w), GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(w), sw); gtk_container_add(GTK_CONTAINER(w), sw);
@ -2989,8 +2990,8 @@ GtkWidget* gtr_torrent_details_dialog_new(GtkWindow* parent, TrCore* core)
/* create the dialog */ /* create the dialog */
di->core = core; di->core = core;
di->gstr = g_string_new(NULL); di->gstr = g_string_new(nullptr);
d = gtk_dialog_new_with_buttons(NULL, parent, {}, TR_ARG_TUPLE(_("_Close"), GTK_RESPONSE_CLOSE), NULL); d = gtk_dialog_new_with_buttons(nullptr, parent, {}, TR_ARG_TUPLE(_("_Close"), GTK_RESPONSE_CLOSE), nullptr);
di->dialog = d; di->dialog = d;
gtk_window_set_role(GTK_WINDOW(d), "tr-info"); gtk_window_set_role(GTK_WINDOW(d), "tr-info");
@ -2999,7 +3000,7 @@ GtkWidget* gtr_torrent_details_dialog_new(GtkWindow* parent, TrCore* core)
GTK_WINDOW(d), GTK_WINDOW(d),
(gint)gtr_pref_int_get(TR_KEY_details_window_width), (gint)gtr_pref_int_get(TR_KEY_details_window_width),
(gint)gtr_pref_int_get(TR_KEY_details_window_height)); (gint)gtr_pref_int_get(TR_KEY_details_window_height));
g_signal_connect(d, "size-allocate", G_CALLBACK(on_details_window_size_allocated), NULL); g_signal_connect(d, "size-allocate", G_CALLBACK(on_details_window_size_allocated), nullptr);
g_signal_connect_swapped(d, "response", G_CALLBACK(gtk_widget_destroy), d); g_signal_connect_swapped(d, "response", G_CALLBACK(gtk_widget_destroy), d);
gtk_container_set_border_width(GTK_CONTAINER(d), GUI_PAD); gtk_container_set_border_width(GTK_CONTAINER(d), GUI_PAD);

View File

@ -45,7 +45,7 @@ static void on_remove_dialog_response(GtkDialog* dialog, gint response, gpointer
if (response == GTK_RESPONSE_ACCEPT) if (response == GTK_RESPONSE_ACCEPT)
{ {
for (GSList* l = dd->torrent_ids; l != NULL; l = l->next) for (GSList* l = dd->torrent_ids; l != nullptr; l = l->next)
{ {
gtr_core_remove_torrent(dd->core, GPOINTER_TO_INT(l->data), dd->delete_files); gtr_core_remove_torrent(dd->core, GPOINTER_TO_INT(l->data), dd->delete_files);
} }
@ -76,7 +76,7 @@ void gtr_confirm_remove(GtkWindow* parent, TrCore* core, GSList* torrent_ids, gb
dd->torrent_ids = torrent_ids; dd->torrent_ids = torrent_ids;
dd->delete_files = delete_files; dd->delete_files = delete_files;
for (GSList* l = torrent_ids; l != NULL; l = l->next) for (GSList* l = torrent_ids; l != nullptr; l = l->next)
{ {
int const id = GPOINTER_TO_INT(l->data); int const id = GPOINTER_TO_INT(l->data);
tr_torrent* tor = gtr_core_find_torrent(core, id); tr_torrent* tor = gtr_core_find_torrent(core, id);
@ -93,7 +93,7 @@ void gtr_confirm_remove(GtkWindow* parent, TrCore* core, GSList* torrent_ids, gb
} }
} }
primary_text = g_string_new(NULL); primary_text = g_string_new(nullptr);
if (!delete_files) if (!delete_files)
{ {
@ -107,7 +107,7 @@ void gtr_confirm_remove(GtkWindow* parent, TrCore* core, GSList* torrent_ids, gb
count); count);
} }
secondary_text = g_string_new(NULL); secondary_text = g_string_new(nullptr);
if (incomplete == 0 && connected == 0) if (incomplete == 0 && connected == 0)
{ {
@ -175,7 +175,7 @@ void gtr_confirm_remove(GtkWindow* parent, TrCore* core, GSList* torrent_ids, gb
GTK_DIALOG(d), GTK_DIALOG(d),
TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL), TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL),
TR_ARG_TUPLE(delete_files ? _("_Delete") : _("_Remove"), GTK_RESPONSE_ACCEPT), TR_ARG_TUPLE(delete_files ? _("_Delete") : _("_Remove"), GTK_RESPONSE_ACCEPT),
NULL); nullptr);
gtk_dialog_set_default_response(GTK_DIALOG(d), GTK_RESPONSE_CANCEL); gtk_dialog_set_default_response(GTK_DIALOG(d), GTK_RESPONSE_CANCEL);
g_signal_connect(d, "response", G_CALLBACK(on_remove_dialog_response), dd); g_signal_connect(d, "response", G_CALLBACK(on_remove_dialog_response), dd);
gtk_widget_show_all(d); gtk_widget_show_all(d);

View File

@ -36,11 +36,11 @@ static char* get_url(char const* host, int image_type)
static char* favicon_get_cache_dir(void) static char* favicon_get_cache_dir(void)
{ {
static char* dir = NULL; static char* dir = nullptr;
if (dir == NULL) if (dir == nullptr)
{ {
dir = g_build_filename(g_get_user_cache_dir(), "transmission", "favicons", NULL); dir = g_build_filename(g_get_user_cache_dir(), "transmission", "favicons", nullptr);
g_mkdir_with_parents(dir, 0777); g_mkdir_with_parents(dir, 0777);
} }
@ -49,22 +49,22 @@ static char* favicon_get_cache_dir(void)
static char* favicon_get_cache_filename(char const* host) static char* favicon_get_cache_filename(char const* host)
{ {
return g_build_filename(favicon_get_cache_dir(), host, NULL); return g_build_filename(favicon_get_cache_dir(), host, nullptr);
} }
static void favicon_save_to_cache(char const* host, void const* data, size_t len) static void favicon_save_to_cache(char const* host, void const* data, size_t len)
{ {
char* filename = favicon_get_cache_filename(host); char* filename = favicon_get_cache_filename(host);
g_file_set_contents(filename, static_cast<gchar const*>(data), len, NULL); g_file_set_contents(filename, static_cast<gchar const*>(data), len, nullptr);
g_free(filename); g_free(filename);
} }
static GdkPixbuf* favicon_load_from_cache(char const* host) static GdkPixbuf* favicon_load_from_cache(char const* host)
{ {
char* filename = favicon_get_cache_filename(host); char* filename = favicon_get_cache_filename(host);
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, 16, 16, NULL); GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, 16, 16, nullptr);
if (pixbuf == NULL) /* bad file */ if (pixbuf == nullptr) /* bad file */
{ {
g_remove(filename); g_remove(filename);
} }
@ -77,7 +77,7 @@ static void favicon_web_done_cb(tr_session*, bool, bool, long, void const*, size
static gboolean favicon_web_done_idle_cb(gpointer vfav) static gboolean favicon_web_done_idle_cb(gpointer vfav)
{ {
GdkPixbuf* pixbuf = NULL; GdkPixbuf* pixbuf = nullptr;
gboolean finished = FALSE; gboolean finished = FALSE;
auto* fav = static_cast<favicon_data*>(vfav); auto* fav = static_cast<favicon_data*>(vfav);
@ -85,7 +85,7 @@ static gboolean favicon_web_done_idle_cb(gpointer vfav)
{ {
favicon_save_to_cache(fav->host, fav->contents, fav->len); favicon_save_to_cache(fav->host, fav->contents, fav->len);
pixbuf = favicon_load_from_cache(fav->host); pixbuf = favicon_load_from_cache(fav->host);
finished = pixbuf != NULL; finished = pixbuf != nullptr;
} }
if (!finished) /* no pixbuf yet... */ if (!finished) /* no pixbuf yet... */
@ -99,7 +99,7 @@ static gboolean favicon_web_done_idle_cb(gpointer vfav)
char* url = get_url(fav->host, fav->type); char* url = get_url(fav->host, fav->type);
g_free(fav->contents); g_free(fav->contents);
fav->contents = NULL; fav->contents = nullptr;
fav->len = 0; fav->len = 0;
tr_webRun(fav->session, url, favicon_web_done_cb, fav); tr_webRun(fav->session, url, favicon_web_done_cb, fav);
@ -143,7 +143,7 @@ void gtr_get_favicon(tr_session* session, char const* host, GFunc pixbuf_ready_f
{ {
GdkPixbuf* pixbuf = favicon_load_from_cache(host); GdkPixbuf* pixbuf = favicon_load_from_cache(host);
if (pixbuf != NULL) if (pixbuf != nullptr)
{ {
pixbuf_ready_func(pixbuf, pixbuf_ready_func_data); pixbuf_ready_func(pixbuf, pixbuf_ready_func_data);
} }

View File

@ -246,9 +246,9 @@ static void gtr_tree_model_foreach_postorder_subtree(
} while (gtk_tree_model_iter_next(model, &child)); } while (gtk_tree_model_iter_next(model, &child));
} }
if (parent != NULL) if (parent != nullptr)
{ {
func(model, NULL, parent, data); func(model, nullptr, parent, data);
} }
} }
@ -256,7 +256,7 @@ static void gtr_tree_model_foreach_postorder(GtkTreeModel* model, GtkTreeModelFo
{ {
GtkTreeIter iter; GtkTreeIter iter;
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, 0))
{ {
do do
{ {
@ -269,7 +269,7 @@ static void refresh(FileData* data)
{ {
tr_torrent* tor = gtr_core_find_torrent(data->core, data->torrentId); tr_torrent* tor = gtr_core_find_torrent(data->core, data->torrentId);
if (tor == NULL) if (tor == nullptr)
{ {
gtr_file_list_clear(data->top); gtr_file_list_clear(data->top);
} }
@ -455,7 +455,7 @@ static void buildTree(GNode* node, gpointer gdata)
GtkTreeIter child_iter; GtkTreeIter child_iter;
auto* build = static_cast<build_data*>(gdata); auto* build = static_cast<build_data*>(gdata);
auto* child_data = static_cast<row_struct*>(node->data); auto* child_data = static_cast<row_struct*>(node->data);
gboolean const isLeaf = node->children == NULL; gboolean const isLeaf = node->children == nullptr;
char const* mime_type = isLeaf ? gtr_get_mime_type_from_filename(child_data->name) : DIRECTORY_MIME_TYPE; char const* mime_type = isLeaf ? gtr_get_mime_type_from_filename(child_data->name) : DIRECTORY_MIME_TYPE;
GdkPixbuf* icon = gtr_get_mime_type_icon(mime_type, GTK_ICON_SIZE_MENU, build->w); GdkPixbuf* icon = gtr_get_mime_type_icon(mime_type, GTK_ICON_SIZE_MENU, build->w);
@ -500,7 +500,7 @@ static GNode* find_child(GNode* parent, char const* name)
{ {
GNode* child = parent->children; GNode* child = parent->children;
while (child != NULL) while (child != nullptr)
{ {
auto const* child_data = static_cast<row_struct const*>(child->data); auto const* child_data = static_cast<row_struct const*>(child->data);
@ -540,8 +540,8 @@ void gtr_file_list_set_torrent(GtkWidget* w, int torrentId)
data->torrentId = torrentId; data->torrentId = torrentId;
/* populate the model */ /* populate the model */
tr_torrent* const tor = torrentId > 0 ? gtr_core_find_torrent(data->core, torrentId) : NULL; tr_torrent* const tor = torrentId > 0 ? gtr_core_find_torrent(data->core, torrentId) : nullptr;
if (tor != NULL) if (tor != nullptr)
{ {
// build a GNode tree of the files // build a GNode tree of the files
struct row_struct* const root_data = g_new0(struct row_struct, 1); struct row_struct* const root_data = g_new0(struct row_struct, 1);
@ -558,13 +558,13 @@ void gtr_file_list_set_torrent(GtkWidget* w, int torrentId)
tr_file const* const file = &inf->files[i]; tr_file const* const file = &inf->files[i];
char** const tokens = g_strsplit(file->name, G_DIR_SEPARATOR_S, 0); char** const tokens = g_strsplit(file->name, G_DIR_SEPARATOR_S, 0);
for (int j = 0; tokens[j] != NULL; ++j) for (int j = 0; tokens[j] != nullptr; ++j)
{ {
gboolean const isLeaf = tokens[j + 1] == NULL; gboolean const isLeaf = tokens[j + 1] == nullptr;
char const* const name = tokens[j]; char const* const name = tokens[j];
GNode* node = find_child(parent, name); GNode* node = find_child(parent, name);
if (node == NULL) if (node == nullptr)
{ {
struct row_struct* row = g_new(struct row_struct, 1); struct row_struct* row = g_new(struct row_struct, 1);
row->name = g_strdup(name); row->name = g_strdup(name);
@ -585,7 +585,7 @@ void gtr_file_list_set_torrent(GtkWidget* w, int torrentId)
build.w = w; build.w = w;
build.tor = tor; build.tor = tor;
build.store = data->store; build.store = data->store;
build.iter = NULL; build.iter = nullptr;
g_node_children_foreach(root, G_TRAVERSE_ALL, buildTree, &build); g_node_children_foreach(root, G_TRAVERSE_ALL, buildTree, &build);
// cleanup // cleanup
@ -625,7 +625,7 @@ static void renderDownload(
gboolean enabled; gboolean enabled;
gtk_tree_model_get(model, iter, FC_ENABLED, &enabled, -1); gtk_tree_model_get(model, iter, FC_ENABLED, &enabled, -1);
g_object_set(renderer, "inconsistent", enabled == MIXED, "active", enabled == TRUE, NULL); g_object_set(renderer, "inconsistent", enabled == MIXED, "active", enabled == TRUE, nullptr);
} }
static void renderPriority( static void renderPriority(
@ -661,7 +661,7 @@ static void renderPriority(
break; break;
} }
g_object_set(renderer, "text", text, NULL); g_object_set(renderer, "text", text, nullptr);
} }
/* build a filename from tr_torrentGetCurrentDir() + the model's FC_LABELs */ /* build a filename from tr_torrentGetCurrentDir() + the model's FC_LABELs */
@ -692,7 +692,7 @@ static gboolean onRowActivated(GtkTreeView* view, GtkTreePath* path, GtkTreeView
auto* data = static_cast<FileData*>(gdata); auto* data = static_cast<FileData*>(gdata);
tr_torrent const* tor = gtr_core_find_torrent(data->core, data->torrentId); tr_torrent const* tor = gtr_core_find_torrent(data->core, data->torrentId);
if (tor != NULL) if (tor != nullptr)
{ {
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel* model = gtk_tree_view_get_model(view); GtkTreeModel* model = gtk_tree_view_get_model(view);
@ -705,7 +705,7 @@ static gboolean onRowActivated(GtkTreeView* view, GtkTreePath* path, GtkTreeView
/* if the file's not done, walk up the directory tree until we find /* if the file's not done, walk up the directory tree until we find
* an ancestor that exists, and open that instead */ * an ancestor that exists, and open that instead */
if (filename != NULL && (prog < 100 || !g_file_test(filename, G_FILE_TEST_EXISTS))) if (filename != nullptr && (prog < 100 || !g_file_test(filename, G_FILE_TEST_EXISTS)))
{ {
do do
{ {
@ -731,7 +731,7 @@ static gboolean onViewPathToggled(GtkTreeView* view, GtkTreeViewColumn* col, Gtk
tr_torrent* tor; tr_torrent* tor;
gboolean handled = FALSE; gboolean handled = FALSE;
if (col == NULL || path == NULL) if (col == nullptr || path == nullptr)
{ {
return FALSE; return FALSE;
} }
@ -739,7 +739,7 @@ static gboolean onViewPathToggled(GtkTreeView* view, GtkTreeViewColumn* col, Gtk
cid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(col), TR_COLUMN_ID_KEY)); cid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(col), TR_COLUMN_ID_KEY));
tor = gtr_core_find_torrent(data->core, data->torrentId); tor = gtr_core_find_torrent(data->core, data->torrentId);
if (tor != NULL && (cid == FC_PRIORITY || cid == FC_ENABLED)) if (tor != nullptr && (cid == FC_PRIORITY || cid == FC_ENABLED))
{ {
GtkTreeIter iter; GtkTreeIter iter;
tr_file_index_t* const indexBuf = g_new0(tr_file_index_t, tr_torrentInfo(tor)->fileCount); tr_file_index_t* const indexBuf = g_new0(tr_file_index_t, tr_torrentInfo(tor)->fileCount);
@ -788,7 +788,7 @@ static gboolean onViewPathToggled(GtkTreeView* view, GtkTreeViewColumn* col, Gtk
} }
/** /**
* @note 'col' and 'path' are assumed not to be NULL. * @note 'col' and 'path' are assumed not to be nullptr.
*/ */
static gboolean getAndSelectEventPath( static gboolean getAndSelectEventPath(
GtkTreeView* treeview, GtkTreeView* treeview,
@ -798,7 +798,7 @@ static gboolean getAndSelectEventPath(
{ {
GtkTreeSelection* sel; GtkTreeSelection* sel;
if (gtk_tree_view_get_path_at_pos(treeview, event->x, event->y, path, col, NULL, NULL)) if (gtk_tree_view_get_path_at_pos(treeview, event->x, event->y, path, col, nullptr, nullptr))
{ {
sel = gtk_tree_view_get_selection(treeview); sel = gtk_tree_view_get_selection(treeview);
@ -817,7 +817,7 @@ static gboolean getAndSelectEventPath(
static gboolean onViewButtonPressed(GtkWidget* w, GdkEventButton const* event, gpointer gdata) static gboolean onViewButtonPressed(GtkWidget* w, GdkEventButton const* event, gpointer gdata)
{ {
GtkTreeViewColumn* col; GtkTreeViewColumn* col;
GtkTreePath* path = NULL; GtkTreePath* path = nullptr;
gboolean handled = FALSE; gboolean handled = FALSE;
GtkTreeView* treeview = GTK_TREE_VIEW(w); GtkTreeView* treeview = GTK_TREE_VIEW(w);
auto* data = static_cast<FileData*>(gdata); auto* data = static_cast<FileData*>(gdata);
@ -827,7 +827,7 @@ static gboolean onViewButtonPressed(GtkWidget* w, GdkEventButton const* event, g
{ {
handled = onViewPathToggled(treeview, col, path, data); handled = onViewPathToggled(treeview, col, path, data);
if (path != NULL) if (path != nullptr)
{ {
gtk_tree_path_free(path); gtk_tree_path_free(path);
} }
@ -907,7 +907,7 @@ static void cell_edited_callback(
{ {
tr_torrent* const tor = gtr_core_find_torrent(data->core, data->torrentId); tr_torrent* const tor = gtr_core_find_torrent(data->core, data->torrentId);
if (tor == NULL) if (tor == nullptr)
{ {
return; return;
} }
@ -919,11 +919,11 @@ static void cell_edited_callback(
} }
/* build oldpath */ /* build oldpath */
GString* oldpath = g_string_new(NULL); GString* oldpath = g_string_new(nullptr);
for (;;) for (;;)
{ {
char* token = NULL; char* token = nullptr;
GtkTreeIter child; GtkTreeIter child;
gtk_tree_model_get(data->model, &iter, FC_LABEL, &token, -1); gtk_tree_model_get(data->model, &iter, FC_LABEL, &token, -1);
g_string_prepend(oldpath, token); g_string_prepend(oldpath, token);
@ -975,7 +975,7 @@ GtkWidget* gtr_file_list_new(TrCore* core, int torrentId)
gtk_container_set_border_width(GTK_CONTAINER(view), GUI_PAD_BIG); gtk_container_set_border_width(GTK_CONTAINER(view), GUI_PAD_BIG);
g_signal_connect(view, "button-press-event", G_CALLBACK(onViewButtonPressed), data); g_signal_connect(view, "button-press-event", G_CALLBACK(onViewButtonPressed), data);
g_signal_connect(view, "row_activated", G_CALLBACK(onRowActivated), data); g_signal_connect(view, "row_activated", G_CALLBACK(onRowActivated), data);
g_signal_connect(view, "button-release-event", G_CALLBACK(on_tree_view_button_released), NULL); g_signal_connect(view, "button-release-event", G_CALLBACK(on_tree_view_button_released), nullptr);
pango_context = gtk_widget_create_pango_context(view); pango_context = gtk_widget_create_pango_context(view);
pango_font_description = pango_font_description_copy(pango_context_get_font_description(pango_context)); pango_font_description = pango_font_description_copy(pango_context_get_font_description(pango_context));
@ -990,18 +990,18 @@ GtkWidget* gtr_file_list_new(TrCore* core, int torrentId)
gtk_tree_view_set_search_column(tree_view, FC_LABEL); gtk_tree_view_set_search_column(tree_view, FC_LABEL);
/* add file column */ /* add file column */
col = GTK_TREE_VIEW_COLUMN(g_object_new(GTK_TYPE_TREE_VIEW_COLUMN, "expand", TRUE, "title", _("Name"), NULL)); col = GTK_TREE_VIEW_COLUMN(g_object_new(GTK_TYPE_TREE_VIEW_COLUMN, "expand", TRUE, "title", _("Name"), nullptr));
gtk_tree_view_column_set_resizable(col, TRUE); gtk_tree_view_column_set_resizable(col, TRUE);
rend = gtk_cell_renderer_pixbuf_new(); rend = gtk_cell_renderer_pixbuf_new();
gtk_tree_view_column_pack_start(col, rend, FALSE); gtk_tree_view_column_pack_start(col, rend, FALSE);
gtk_tree_view_column_add_attribute(col, rend, "pixbuf", FC_ICON); gtk_tree_view_column_add_attribute(col, rend, "pixbuf", FC_ICON);
/* add text renderer */ /* add text renderer */
rend = gtk_cell_renderer_text_new(); rend = gtk_cell_renderer_text_new();
g_object_set(rend, "editable", TRUE, NULL); g_object_set(rend, "editable", TRUE, nullptr);
g_object_set(rend, "ellipsize", PANGO_ELLIPSIZE_END, "font-desc", pango_font_description, NULL); g_object_set(rend, "ellipsize", PANGO_ELLIPSIZE_END, "font-desc", pango_font_description, nullptr);
g_signal_connect(rend, "edited", (GCallback)cell_edited_callback, data); g_signal_connect(rend, "edited", (GCallback)cell_edited_callback, data);
gtk_tree_view_column_pack_start(col, rend, TRUE); gtk_tree_view_column_pack_start(col, rend, TRUE);
gtk_tree_view_column_set_attributes(col, rend, "text", FC_LABEL, NULL); gtk_tree_view_column_set_attributes(col, rend, "text", FC_LABEL, nullptr);
gtk_tree_view_column_set_sort_column_id(col, FC_LABEL); gtk_tree_view_column_set_sort_column_id(col, FC_LABEL);
gtk_tree_view_append_column(tree_view, col); gtk_tree_view_append_column(tree_view, col);
@ -1015,21 +1015,21 @@ GtkWidget* gtr_file_list_new(TrCore* core, int torrentId)
TR_ARG_TUPLE("xpad", GUI_PAD), TR_ARG_TUPLE("xpad", GUI_PAD),
TR_ARG_TUPLE("xalign", 1.0F), TR_ARG_TUPLE("xalign", 1.0F),
TR_ARG_TUPLE("yalign", 0.5F), TR_ARG_TUPLE("yalign", 0.5F),
NULL); nullptr);
col = gtk_tree_view_column_new_with_attributes(title, rend, NULL); col = gtk_tree_view_column_new_with_attributes(title, rend, nullptr);
gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_GROW_ONLY); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
gtk_tree_view_column_set_sort_column_id(col, FC_SIZE); gtk_tree_view_column_set_sort_column_id(col, FC_SIZE);
gtk_tree_view_column_set_attributes(col, rend, "text", FC_SIZE_STR, NULL); gtk_tree_view_column_set_attributes(col, rend, "text", FC_SIZE_STR, nullptr);
gtk_tree_view_append_column(tree_view, col); gtk_tree_view_append_column(tree_view, col);
/* add "progress" column */ /* add "progress" column */
title = _("Have"); title = _("Have");
pango_layout = gtk_widget_create_pango_layout(view, title); pango_layout = gtk_widget_create_pango_layout(view, title);
pango_layout_get_pixel_size(pango_layout, &width, NULL); pango_layout_get_pixel_size(pango_layout, &width, nullptr);
width += 30; /* room for the sort indicator */ width += 30; /* room for the sort indicator */
g_object_unref(G_OBJECT(pango_layout)); g_object_unref(G_OBJECT(pango_layout));
rend = gtk_cell_renderer_progress_new(); rend = gtk_cell_renderer_progress_new();
col = gtk_tree_view_column_new_with_attributes(title, rend, "value", FC_PROG, NULL); col = gtk_tree_view_column_new_with_attributes(title, rend, "value", FC_PROG, nullptr);
gtk_tree_view_column_set_fixed_width(col, width); gtk_tree_view_column_set_fixed_width(col, width);
gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_sort_column_id(col, FC_PROG); gtk_tree_view_column_set_sort_column_id(col, FC_PROG);
@ -1038,39 +1038,39 @@ GtkWidget* gtr_file_list_new(TrCore* core, int torrentId)
/* add "enabled" column */ /* add "enabled" column */
title = _("Download"); title = _("Download");
pango_layout = gtk_widget_create_pango_layout(view, title); pango_layout = gtk_widget_create_pango_layout(view, title);
pango_layout_get_pixel_size(pango_layout, &width, NULL); pango_layout_get_pixel_size(pango_layout, &width, nullptr);
width += 30; /* room for the sort indicator */ width += 30; /* room for the sort indicator */
g_object_unref(G_OBJECT(pango_layout)); g_object_unref(G_OBJECT(pango_layout));
rend = gtk_cell_renderer_toggle_new(); rend = gtk_cell_renderer_toggle_new();
col = gtk_tree_view_column_new_with_attributes(title, rend, NULL); col = gtk_tree_view_column_new_with_attributes(title, rend, nullptr);
g_object_set_data(G_OBJECT(col), TR_COLUMN_ID_KEY, GINT_TO_POINTER(FC_ENABLED)); g_object_set_data(G_OBJECT(col), TR_COLUMN_ID_KEY, GINT_TO_POINTER(FC_ENABLED));
gtk_tree_view_column_set_fixed_width(col, width); gtk_tree_view_column_set_fixed_width(col, width);
gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_cell_data_func(col, rend, renderDownload, NULL, NULL); gtk_tree_view_column_set_cell_data_func(col, rend, renderDownload, nullptr, nullptr);
gtk_tree_view_column_set_sort_column_id(col, FC_ENABLED); gtk_tree_view_column_set_sort_column_id(col, FC_ENABLED);
gtk_tree_view_append_column(tree_view, col); gtk_tree_view_append_column(tree_view, col);
/* add priority column */ /* add priority column */
title = _("Priority"); title = _("Priority");
pango_layout = gtk_widget_create_pango_layout(view, title); pango_layout = gtk_widget_create_pango_layout(view, title);
pango_layout_get_pixel_size(pango_layout, &width, NULL); pango_layout_get_pixel_size(pango_layout, &width, nullptr);
width += 30; /* room for the sort indicator */ width += 30; /* room for the sort indicator */
g_object_unref(G_OBJECT(pango_layout)); g_object_unref(G_OBJECT(pango_layout));
rend = gtk_cell_renderer_text_new(); rend = gtk_cell_renderer_text_new();
g_object_set(rend, "xalign", (gfloat)0.5, "yalign", (gfloat)0.5, NULL); g_object_set(rend, "xalign", (gfloat)0.5, "yalign", (gfloat)0.5, nullptr);
col = gtk_tree_view_column_new_with_attributes(title, rend, NULL); col = gtk_tree_view_column_new_with_attributes(title, rend, nullptr);
g_object_set_data(G_OBJECT(col), TR_COLUMN_ID_KEY, GINT_TO_POINTER(FC_PRIORITY)); g_object_set_data(G_OBJECT(col), TR_COLUMN_ID_KEY, GINT_TO_POINTER(FC_PRIORITY));
gtk_tree_view_column_set_fixed_width(col, width); gtk_tree_view_column_set_fixed_width(col, width);
gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_sort_column_id(col, FC_PRIORITY); gtk_tree_view_column_set_sort_column_id(col, FC_PRIORITY);
gtk_tree_view_column_set_cell_data_func(col, rend, renderPriority, NULL, NULL); gtk_tree_view_column_set_cell_data_func(col, rend, renderPriority, nullptr, nullptr);
gtk_tree_view_append_column(tree_view, col); gtk_tree_view_append_column(tree_view, col);
/* add tooltip to tree */ /* add tooltip to tree */
gtk_tree_view_set_tooltip_column(tree_view, FC_LABEL_ESC); gtk_tree_view_set_tooltip_column(tree_view, FC_LABEL_ESC);
/* create the scrolled window and stick the view in it */ /* create the scrolled window and stick the view in it */
scroll = gtk_scrolled_window_new(NULL, NULL); scroll = gtk_scrolled_window_new(nullptr, nullptr);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll), GTK_SHADOW_IN); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll), GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(scroll), view); gtk_container_add(GTK_CONTAINER(scroll), view);

View File

@ -63,7 +63,7 @@ static char* get_name_from_host(char const* host)
{ {
name = g_strdup(host); name = g_strdup(host);
} }
else if (dot != NULL) else if (dot != nullptr)
{ {
name = g_strndup(host, dot - host); name = g_strndup(host, dot - host);
} }
@ -94,7 +94,7 @@ static void favicon_ready_cb(gpointer pixbuf, gpointer vreference)
GtkTreeIter iter; GtkTreeIter iter;
auto* reference = static_cast<GtkTreeRowReference*>(vreference); auto* reference = static_cast<GtkTreeRowReference*>(vreference);
if (pixbuf != NULL) if (pixbuf != nullptr)
{ {
GtkTreePath* path = gtk_tree_row_reference_get_path(reference); GtkTreePath* path = gtk_tree_row_reference_get_path(reference);
GtkTreeModel* model = gtk_tree_row_reference_get_model(reference); GtkTreeModel* model = gtk_tree_row_reference_get_model(reference);
@ -123,10 +123,10 @@ static gboolean tracker_filter_model_update(gpointer gstore)
int num_torrents = 0; int num_torrents = 0;
GPtrArray* hosts = g_ptr_array_new(); GPtrArray* hosts = g_ptr_array_new();
GStringChunk* strings = g_string_chunk_new(4096); GStringChunk* strings = g_string_chunk_new(4096);
GHashTable* hosts_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); GHashTable* hosts_hash = g_hash_table_new_full(g_str_hash, g_str_equal, nullptr, g_free);
GtkTreeModel* tmodel = GTK_TREE_MODEL(g_object_get_qdata(o, TORRENT_MODEL_KEY)); GtkTreeModel* tmodel = GTK_TREE_MODEL(g_object_get_qdata(o, TORRENT_MODEL_KEY));
GtkTreeIter iter; GtkTreeIter iter;
if (gtk_tree_model_iter_nth_child(tmodel, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(tmodel, &iter, nullptr, 0))
{ {
do do
{ {
@ -144,7 +144,7 @@ static gboolean tracker_filter_model_update(gpointer gstore)
char* const key = g_string_chunk_insert_const(strings, name); char* const key = g_string_chunk_insert_const(strings, name);
auto* count = static_cast<int*>(g_hash_table_lookup(hosts_hash, key)); auto* count = static_cast<int*>(g_hash_table_lookup(hosts_hash, key));
if (count == NULL) if (count == nullptr)
{ {
count = tr_new0(int, 1); count = tr_new0(int, 1);
g_hash_table_insert(hosts_hash, key, count); g_hash_table_insert(hosts_hash, key, count);
@ -181,7 +181,7 @@ static gboolean tracker_filter_model_update(gpointer gstore)
// update the "all" count // update the "all" count
GtkTreeStore* store = GTK_TREE_STORE(gstore); GtkTreeStore* store = GTK_TREE_STORE(gstore);
GtkTreeModel* model = GTK_TREE_MODEL(gstore); GtkTreeModel* model = GTK_TREE_MODEL(gstore);
if (gtk_tree_model_iter_children(model, &iter, NULL)) if (gtk_tree_model_iter_children(model, &iter, nullptr))
{ {
tracker_model_update_count(store, &iter, num_torrents); tracker_model_update_count(store, &iter, num_torrents);
} }
@ -192,7 +192,7 @@ static gboolean tracker_filter_model_update(gpointer gstore)
{ {
// are we done yet? // are we done yet?
gboolean const new_hosts_done = i >= hosts->len; gboolean const new_hosts_done = i >= hosts->len;
gboolean const old_hosts_done = !gtk_tree_model_iter_nth_child(model, &iter, NULL, store_pos); gboolean const old_hosts_done = !gtk_tree_model_iter_nth_child(model, &iter, nullptr, store_pos);
if (new_hosts_done && old_hosts_done) if (new_hosts_done && old_hosts_done)
{ {
break; break;
@ -244,7 +244,7 @@ static gboolean tracker_filter_model_update(gpointer gstore)
gtk_tree_store_insert_with_values( gtk_tree_store_insert_with_values(
store, store,
&add, &add,
NULL, nullptr,
store_pos, store_pos,
TR_ARG_TUPLE(TRACKER_FILTER_COL_HOST, host), TR_ARG_TUPLE(TRACKER_FILTER_COL_HOST, host),
TR_ARG_TUPLE(TRACKER_FILTER_COL_NAME, name), TR_ARG_TUPLE(TRACKER_FILTER_COL_NAME, name),
@ -288,16 +288,16 @@ static GtkTreeModel* tracker_filter_model_new(GtkTreeModel* tmodel)
gtk_tree_store_insert_with_values( gtk_tree_store_insert_with_values(
store, store,
NULL, nullptr,
NULL, nullptr,
-1, -1,
TR_ARG_TUPLE(TRACKER_FILTER_COL_NAME, _("All")), TR_ARG_TUPLE(TRACKER_FILTER_COL_NAME, _("All")),
TR_ARG_TUPLE(TRACKER_FILTER_COL_TYPE, TRACKER_FILTER_TYPE_ALL), TR_ARG_TUPLE(TRACKER_FILTER_COL_TYPE, TRACKER_FILTER_TYPE_ALL),
-1); -1);
gtk_tree_store_insert_with_values( gtk_tree_store_insert_with_values(
store, store,
NULL, nullptr,
NULL, nullptr,
-1, -1,
TR_ARG_TUPLE(TRACKER_FILTER_COL_TYPE, TRACKER_FILTER_TYPE_SEPARATOR), TR_ARG_TUPLE(TRACKER_FILTER_COL_TYPE, TRACKER_FILTER_TYPE_SEPARATOR),
-1); -1);
@ -319,7 +319,7 @@ static gboolean is_it_a_separator(GtkTreeModel* m, GtkTreeIter* iter, gpointer d
static void tracker_model_update_idle(gpointer tracker_model) static void tracker_model_update_idle(gpointer tracker_model)
{ {
GObject* o = G_OBJECT(tracker_model); GObject* o = G_OBJECT(tracker_model);
gboolean const pending = g_object_get_qdata(o, DIRTY_KEY) != NULL; gboolean const pending = g_object_get_qdata(o, DIRTY_KEY) != nullptr;
if (!pending) if (!pending)
{ {
@ -361,7 +361,7 @@ static void render_pixbuf_func(
gtk_tree_model_get(tree_model, iter, TRACKER_FILTER_COL_TYPE, &type, -1); gtk_tree_model_get(tree_model, iter, TRACKER_FILTER_COL_TYPE, &type, -1);
width = (type == TRACKER_FILTER_TYPE_HOST) ? 20 : 0; width = (type == TRACKER_FILTER_TYPE_HOST) ? 20 : 0;
g_object_set(cell_renderer, "width", width, NULL); g_object_set(cell_renderer, "width", width, nullptr);
} }
static void render_number_func( static void render_number_func(
@ -388,7 +388,7 @@ static void render_number_func(
*buf = '\0'; *buf = '\0';
} }
g_object_set(cell_renderer, "text", buf, NULL); g_object_set(cell_renderer, "text", buf, nullptr);
} }
static GtkCellRenderer* number_renderer_new(void) static GtkCellRenderer* number_renderer_new(void)
@ -401,7 +401,7 @@ static GtkCellRenderer* number_renderer_new(void)
TR_ARG_TUPLE("weight", PANGO_WEIGHT_ULTRALIGHT), TR_ARG_TUPLE("weight", PANGO_WEIGHT_ULTRALIGHT),
TR_ARG_TUPLE("xalign", 1.0), TR_ARG_TUPLE("xalign", 1.0),
TR_ARG_TUPLE("xpad", GUI_PAD), TR_ARG_TUPLE("xpad", GUI_PAD),
NULL); nullptr);
return r; return r;
} }
@ -425,21 +425,21 @@ static GtkWidget* tracker_combo_box_new(GtkTreeModel* tmodel)
c = gtk_combo_box_new_with_model(cat_model); c = gtk_combo_box_new_with_model(cat_model);
c_combo_box = GTK_COMBO_BOX(c); c_combo_box = GTK_COMBO_BOX(c);
c_cell_layout = GTK_CELL_LAYOUT(c); c_cell_layout = GTK_CELL_LAYOUT(c);
gtk_combo_box_set_row_separator_func(c_combo_box, is_it_a_separator, NULL, NULL); gtk_combo_box_set_row_separator_func(c_combo_box, is_it_a_separator, nullptr, nullptr);
gtk_combo_box_set_active(c_combo_box, 0); gtk_combo_box_set_active(c_combo_box, 0);
r = gtk_cell_renderer_pixbuf_new(); r = gtk_cell_renderer_pixbuf_new();
gtk_cell_layout_pack_start(c_cell_layout, r, FALSE); gtk_cell_layout_pack_start(c_cell_layout, r, FALSE);
gtk_cell_layout_set_cell_data_func(c_cell_layout, r, render_pixbuf_func, NULL, NULL); gtk_cell_layout_set_cell_data_func(c_cell_layout, r, render_pixbuf_func, nullptr, nullptr);
gtk_cell_layout_set_attributes(c_cell_layout, r, "pixbuf", TRACKER_FILTER_COL_PIXBUF, NULL); gtk_cell_layout_set_attributes(c_cell_layout, r, "pixbuf", TRACKER_FILTER_COL_PIXBUF, nullptr);
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(c_cell_layout, r, FALSE); gtk_cell_layout_pack_start(c_cell_layout, r, FALSE);
gtk_cell_layout_set_attributes(c_cell_layout, r, "text", TRACKER_FILTER_COL_NAME, NULL); gtk_cell_layout_set_attributes(c_cell_layout, r, "text", TRACKER_FILTER_COL_NAME, nullptr);
r = number_renderer_new(); r = number_renderer_new();
gtk_cell_layout_pack_end(c_cell_layout, r, TRUE); gtk_cell_layout_pack_end(c_cell_layout, r, TRUE);
gtk_cell_layout_set_cell_data_func(c_cell_layout, r, render_number_func, NULL, NULL); gtk_cell_layout_set_cell_data_func(c_cell_layout, r, render_number_func, nullptr, nullptr);
g_object_weak_ref(G_OBJECT(cat_model), disconnect_cat_model_callbacks, tmodel); g_object_weak_ref(G_OBJECT(cat_model), disconnect_cat_model_callbacks, tmodel);
g_signal_connect(tmodel, "row-changed", G_CALLBACK(torrent_model_row_changed), cat_model); g_signal_connect(tmodel, "row-changed", G_CALLBACK(torrent_model_row_changed), cat_model);
@ -562,7 +562,7 @@ static gboolean activity_filter_model_update(gpointer gstore)
g_object_steal_qdata(o, DIRTY_KEY); g_object_steal_qdata(o, DIRTY_KEY);
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, 0))
{ {
do do
{ {
@ -574,7 +574,7 @@ static gboolean activity_filter_model_update(gpointer gstore)
hits = 0; hits = 0;
if (gtk_tree_model_iter_nth_child(tmodel, &torrent_iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(tmodel, &torrent_iter, nullptr, 0))
{ {
do do
{ {
@ -604,25 +604,26 @@ static GtkTreeModel* activity_filter_model_new(GtkTreeModel* tmodel)
char const* name; char const* name;
char const* icon_name; char const* icon_name;
} types[] = { } types[] = {
{ ACTIVITY_FILTER_ALL, NULL, N_("All"), NULL }, { ACTIVITY_FILTER_ALL, nullptr, N_("All"), nullptr },
{ ACTIVITY_FILTER_SEPARATOR, NULL, NULL, NULL }, { ACTIVITY_FILTER_SEPARATOR, nullptr, nullptr, nullptr },
{ ACTIVITY_FILTER_ACTIVE, NULL, N_("Active"), "system-run" }, { ACTIVITY_FILTER_ACTIVE, nullptr, N_("Active"), "system-run" },
{ ACTIVITY_FILTER_DOWNLOADING, "Verb", NC_("Verb", "Downloading"), "network-receive" }, { ACTIVITY_FILTER_DOWNLOADING, "Verb", NC_("Verb", "Downloading"), "network-receive" },
{ ACTIVITY_FILTER_SEEDING, "Verb", NC_("Verb", "Seeding"), "network-transmit" }, { ACTIVITY_FILTER_SEEDING, "Verb", NC_("Verb", "Seeding"), "network-transmit" },
{ ACTIVITY_FILTER_PAUSED, NULL, N_("Paused"), "media-playback-pause" }, { ACTIVITY_FILTER_PAUSED, nullptr, N_("Paused"), "media-playback-pause" },
{ ACTIVITY_FILTER_FINISHED, NULL, N_("Finished"), "media-playback-stop" }, { ACTIVITY_FILTER_FINISHED, nullptr, N_("Finished"), "media-playback-stop" },
{ ACTIVITY_FILTER_VERIFYING, "Verb", NC_("Verb", "Verifying"), "view-refresh" }, { ACTIVITY_FILTER_VERIFYING, "Verb", NC_("Verb", "Verifying"), "view-refresh" },
{ ACTIVITY_FILTER_ERROR, NULL, N_("Error"), "dialog-error" }, { ACTIVITY_FILTER_ERROR, nullptr, N_("Error"), "dialog-error" },
}; };
GtkListStore* store = gtk_list_store_new(ACTIVITY_FILTER_N_COLS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING); GtkListStore* store = gtk_list_store_new(ACTIVITY_FILTER_N_COLS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
for (size_t i = 0; i < G_N_ELEMENTS(types); ++i) for (size_t i = 0; i < G_N_ELEMENTS(types); ++i)
{ {
char const* name = types[i].context != NULL ? g_dpgettext2(NULL, types[i].context, types[i].name) : _(types[i].name); char const* name = types[i].context != nullptr ? g_dpgettext2(nullptr, types[i].context, types[i].name) :
_(types[i].name);
gtk_list_store_insert_with_values( gtk_list_store_insert_with_values(
store, store,
NULL, nullptr,
-1, -1,
TR_ARG_TUPLE(ACTIVITY_FILTER_COL_NAME, name), TR_ARG_TUPLE(ACTIVITY_FILTER_COL_NAME, name),
TR_ARG_TUPLE(ACTIVITY_FILTER_COL_TYPE, types[i].type), TR_ARG_TUPLE(ACTIVITY_FILTER_COL_TYPE, types[i].type),
@ -653,13 +654,13 @@ static void render_activity_pixbuf_func(
width = type == ACTIVITY_FILTER_ALL ? 0 : 20; width = type == ACTIVITY_FILTER_ALL ? 0 : 20;
ypad = type == ACTIVITY_FILTER_ALL ? 0 : 2; ypad = type == ACTIVITY_FILTER_ALL ? 0 : 2;
g_object_set(cell_renderer, "width", width, "ypad", ypad, NULL); g_object_set(cell_renderer, "width", width, "ypad", ypad, nullptr);
} }
static void activity_model_update_idle(gpointer activity_model) static void activity_model_update_idle(gpointer activity_model)
{ {
GObject* o = G_OBJECT(activity_model); GObject* o = G_OBJECT(activity_model);
gboolean const pending = g_object_get_qdata(o, DIRTY_KEY) != NULL; gboolean const pending = g_object_get_qdata(o, DIRTY_KEY) != nullptr;
if (!pending) if (!pending)
{ {
@ -708,21 +709,21 @@ static GtkWidget* activity_combo_box_new(GtkTreeModel* tmodel)
c = gtk_combo_box_new_with_model(activity_model); c = gtk_combo_box_new_with_model(activity_model);
c_combo_box = GTK_COMBO_BOX(c); c_combo_box = GTK_COMBO_BOX(c);
c_cell_layout = GTK_CELL_LAYOUT(c); c_cell_layout = GTK_CELL_LAYOUT(c);
gtk_combo_box_set_row_separator_func(c_combo_box, activity_is_it_a_separator, NULL, NULL); gtk_combo_box_set_row_separator_func(c_combo_box, activity_is_it_a_separator, nullptr, nullptr);
gtk_combo_box_set_active(c_combo_box, 0); gtk_combo_box_set_active(c_combo_box, 0);
r = gtk_cell_renderer_pixbuf_new(); r = gtk_cell_renderer_pixbuf_new();
gtk_cell_layout_pack_start(c_cell_layout, r, FALSE); gtk_cell_layout_pack_start(c_cell_layout, r, FALSE);
gtk_cell_layout_set_attributes(c_cell_layout, r, TR_ARG_TUPLE("icon-name", ACTIVITY_FILTER_COL_ICON_NAME), NULL); gtk_cell_layout_set_attributes(c_cell_layout, r, TR_ARG_TUPLE("icon-name", ACTIVITY_FILTER_COL_ICON_NAME), nullptr);
gtk_cell_layout_set_cell_data_func(c_cell_layout, r, render_activity_pixbuf_func, NULL, NULL); gtk_cell_layout_set_cell_data_func(c_cell_layout, r, render_activity_pixbuf_func, nullptr, nullptr);
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(c_cell_layout, r, TRUE); gtk_cell_layout_pack_start(c_cell_layout, r, TRUE);
gtk_cell_layout_set_attributes(c_cell_layout, r, TR_ARG_TUPLE("text", ACTIVITY_FILTER_COL_NAME), NULL); gtk_cell_layout_set_attributes(c_cell_layout, r, TR_ARG_TUPLE("text", ACTIVITY_FILTER_COL_NAME), nullptr);
r = number_renderer_new(); r = number_renderer_new();
gtk_cell_layout_pack_end(c_cell_layout, r, TRUE); gtk_cell_layout_pack_end(c_cell_layout, r, TRUE);
gtk_cell_layout_set_cell_data_func(c_cell_layout, r, render_number_func, NULL, NULL); gtk_cell_layout_set_cell_data_func(c_cell_layout, r, render_number_func, nullptr, nullptr);
g_object_weak_ref(G_OBJECT(activity_model), disconnect_activity_model_callbacks, tmodel); g_object_weak_ref(G_OBJECT(activity_model), disconnect_activity_model_callbacks, tmodel);
g_signal_connect(tmodel, "row-changed", G_CALLBACK(activity_torrent_model_row_changed), activity_model); g_signal_connect(tmodel, "row-changed", G_CALLBACK(activity_torrent_model_row_changed), activity_model);
@ -752,14 +753,14 @@ static gboolean testText(tr_torrent const* tor, char const* key)
/* test the torrent name... */ /* test the torrent name... */
char* pch = g_utf8_casefold(tr_torrentName(tor), -1); char* pch = g_utf8_casefold(tr_torrentName(tor), -1);
ret = key == NULL || strstr(pch, key) != NULL; ret = key == nullptr || strstr(pch, key) != nullptr;
g_free(pch); g_free(pch);
/* test the files... */ /* test the files... */
for (tr_file_index_t i = 0; i < inf->fileCount && !ret; ++i) for (tr_file_index_t i = 0; i < inf->fileCount && !ret; ++i)
{ {
pch = g_utf8_casefold(inf->files[i].name, -1); pch = g_utf8_casefold(inf->files[i].name, -1);
ret = key == NULL || strstr(pch, key) != NULL; ret = key == nullptr || strstr(pch, key) != nullptr;
g_free(pch); g_free(pch);
} }
} }
@ -815,7 +816,7 @@ static gboolean is_row_visible(GtkTreeModel* model, GtkTreeIter* iter, gpointer
text = (char const*)g_object_get_qdata(o, TEXT_KEY); text = (char const*)g_object_get_qdata(o, TEXT_KEY);
return tor != NULL && test_tracker(tor, data->active_tracker_type, data->active_tracker_host) && return tor != nullptr && test_tracker(tor, data->active_tracker_type, data->active_tracker_host) &&
test_torrent_activity(tor, data->active_activity_type) && testText(tor, text); test_torrent_activity(tor, data->active_activity_type) && testText(tor, text);
} }
@ -858,7 +859,7 @@ static void selection_changed_cb(GtkComboBox* combo, gpointer vdata)
else else
{ {
type = TRACKER_FILTER_TYPE_ALL; type = TRACKER_FILTER_TYPE_ALL;
host = NULL; host = nullptr;
} }
g_free(data->active_tracker_host); g_free(data->active_tracker_host);
@ -885,7 +886,7 @@ static gboolean update_count_label(gpointer gdata)
auto* data = static_cast<filter_data*>(gdata); auto* data = static_cast<filter_data*>(gdata);
/* get the visible count */ /* get the visible count */
visibleCount = gtk_tree_model_iter_n_children(data->filter_model, NULL); visibleCount = gtk_tree_model_iter_n_children(data->filter_model, nullptr);
/* get the tracker count */ /* get the tracker count */
combo = GTK_COMBO_BOX(data->tracker); combo = GTK_COMBO_BOX(data->tracker);
@ -932,7 +933,7 @@ static gboolean update_count_label(gpointer gdata)
static void update_count_label_idle(struct filter_data* data) static void update_count_label_idle(struct filter_data* data)
{ {
GObject* o = G_OBJECT(data->show_lb); GObject* o = G_OBJECT(data->show_lb);
gboolean const pending = g_object_get_qdata(o, DIRTY_KEY) != NULL; gboolean const pending = g_object_get_qdata(o, DIRTY_KEY) != nullptr;
if (!pending) if (!pending)
{ {
@ -984,14 +985,14 @@ GtkWidget* gtr_filter_bar_new(tr_session* session, GtkTreeModel* tmodel, GtkTree
TORRENT_MODEL_KEY = g_quark_from_static_string("tr-filter-torrent-model-key"); TORRENT_MODEL_KEY = g_quark_from_static_string("tr-filter-torrent-model-key");
data = g_new0(struct filter_data, 1); data = g_new0(struct filter_data, 1);
data->show_lb = gtk_label_new(NULL); data->show_lb = gtk_label_new(nullptr);
data->activity = activity = activity_combo_box_new(tmodel); data->activity = activity = activity_combo_box_new(tmodel);
data->tracker = tracker = tracker_combo_box_new(tmodel); data->tracker = tracker = tracker_combo_box_new(tmodel);
data->filter_model = gtk_tree_model_filter_new(tmodel, NULL); data->filter_model = gtk_tree_model_filter_new(tmodel, nullptr);
g_signal_connect(data->filter_model, "row-deleted", G_CALLBACK(on_filter_model_row_deleted), data); g_signal_connect(data->filter_model, "row-deleted", G_CALLBACK(on_filter_model_row_deleted), data);
g_signal_connect(data->filter_model, "row-inserted", G_CALLBACK(on_filter_model_row_inserted), data); g_signal_connect(data->filter_model, "row-inserted", G_CALLBACK(on_filter_model_row_inserted), data);
g_object_set(G_OBJECT(data->tracker), "width-request", 170, NULL); g_object_set(G_OBJECT(data->tracker), "width-request", 170, nullptr);
g_object_set_qdata(G_OBJECT(gtk_combo_box_get_model(GTK_COMBO_BOX(data->tracker))), SESSION_KEY, session); g_object_set_qdata(G_OBJECT(gtk_combo_box_get_model(GTK_COMBO_BOX(data->tracker))), SESSION_KEY, session);
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(data->filter_model), is_row_visible, data, g_free); gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(data->filter_model), is_row_visible, data, g_free);
@ -1026,11 +1027,11 @@ GtkWidget* gtr_filter_bar_new(tr_session* session, GtkTreeModel* tmodel, GtkTree
/* add the entry field */ /* add the entry field */
s = gtk_entry_new(); s = gtk_entry_new();
gtk_entry_set_icon_from_icon_name(GTK_ENTRY(s), GTK_ENTRY_ICON_SECONDARY, "edit-clear"); gtk_entry_set_icon_from_icon_name(GTK_ENTRY(s), GTK_ENTRY_ICON_SECONDARY, "edit-clear");
g_signal_connect(s, "icon-release", G_CALLBACK(entry_clear), NULL); g_signal_connect(s, "icon-release", G_CALLBACK(entry_clear), nullptr);
gtk_box_pack_start(h_box, s, TRUE, TRUE, 0); gtk_box_pack_start(h_box, s, TRUE, TRUE, 0);
g_signal_connect(s, "changed", G_CALLBACK(filter_entry_changed), data->filter_model); g_signal_connect(s, "changed", G_CALLBACK(filter_entry_changed), data->filter_model);
selection_changed_cb(NULL, data); selection_changed_cb(nullptr, data);
*filter_model = data->filter_model; *filter_model = data->filter_model;
update_count_label(data); update_count_label(data);

View File

@ -46,7 +46,7 @@ void hig_workarea_add_section_title(GtkWidget* t, guint* row, char const* sectio
g_snprintf(buf, sizeof(buf), "<b>%s</b>", section_title); g_snprintf(buf, sizeof(buf), "<b>%s</b>", section_title);
l = gtk_label_new(buf); l = gtk_label_new(buf);
g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_label_set_use_markup(GTK_LABEL(l), TRUE); gtk_label_set_use_markup(GTK_LABEL(l), TRUE);
hig_workarea_add_section_title_widget(t, row, l); hig_workarea_add_section_title_widget(t, row, l);
} }
@ -94,7 +94,7 @@ void hig_workarea_add_label_w(GtkWidget* t, guint row, GtkWidget* w)
TR_ARG_TUPLE("halign", GTK_ALIGN_START), TR_ARG_TUPLE("halign", GTK_ALIGN_START),
TR_ARG_TUPLE("valign", GTK_ALIGN_CENTER), TR_ARG_TUPLE("valign", GTK_ALIGN_CENTER),
TR_ARG_TUPLE("use-markup", TRUE), TR_ARG_TUPLE("use-markup", TRUE),
NULL); nullptr);
} }
gtk_grid_attach(GTK_GRID(t), w, 0, row, 1, 1); gtk_grid_attach(GTK_GRID(t), w, 0, row, 1, 1);
@ -104,10 +104,10 @@ static void hig_workarea_add_tall_control(GtkWidget* t, guint row, GtkWidget* co
{ {
if (GTK_IS_LABEL(control)) if (GTK_IS_LABEL(control))
{ {
g_object_set(control, TR_ARG_TUPLE("halign", GTK_ALIGN_START), TR_ARG_TUPLE("valign", GTK_ALIGN_CENTER), NULL); g_object_set(control, TR_ARG_TUPLE("halign", GTK_ALIGN_START), TR_ARG_TUPLE("valign", GTK_ALIGN_CENTER), nullptr);
} }
g_object_set(control, "expand", TRUE, NULL); g_object_set(control, "expand", TRUE, nullptr);
gtk_grid_attach(GTK_GRID(t), control, 1, row, 1, 1); gtk_grid_attach(GTK_GRID(t), control, 1, row, 1, 1);
} }
@ -115,7 +115,7 @@ static void hig_workarea_add_control(GtkWidget* t, guint row, GtkWidget* control
{ {
if (GTK_IS_LABEL(control)) if (GTK_IS_LABEL(control))
{ {
g_object_set(control, TR_ARG_TUPLE("halign", GTK_ALIGN_START), TR_ARG_TUPLE("valign", GTK_ALIGN_CENTER), NULL); g_object_set(control, TR_ARG_TUPLE("halign", GTK_ALIGN_START), TR_ARG_TUPLE("valign", GTK_ALIGN_CENTER), nullptr);
} }
gtk_widget_set_hexpand(control, TRUE); gtk_widget_set_hexpand(control, TRUE);

View File

@ -14,14 +14,14 @@
static char const* get_static_string(char const* s) static char const* get_static_string(char const* s)
{ {
static GStringChunk* static_strings = NULL; static GStringChunk* static_strings = nullptr;
if (s == NULL) if (s == nullptr)
{ {
return NULL; return nullptr;
} }
if (static_strings == NULL) if (static_strings == nullptr)
{ {
static_strings = g_string_chunk_new(1024); static_strings = g_string_chunk_new(1024);
} }
@ -36,7 +36,7 @@ typedef struct
GHashTable* cache; GHashTable* cache;
} IconCache; } IconCache;
static IconCache* icon_cache[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; static IconCache* icon_cache[7] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
static GdkPixbuf* create_void_pixbuf(int width, int height) static GdkPixbuf* create_void_pixbuf(int width, int height)
{ {
@ -58,12 +58,12 @@ static int get_size_in_pixels(GtkIconSize icon_size)
static IconCache* icon_cache_new(GtkWidget* for_widget, GtkIconSize icon_size) static IconCache* icon_cache_new(GtkWidget* for_widget, GtkIconSize icon_size)
{ {
g_return_val_if_fail(for_widget != NULL, NULL); g_return_val_if_fail(for_widget != nullptr, nullptr);
IconCache* icons = g_new0(IconCache, 1); IconCache* icons = g_new0(IconCache, 1);
icons->icon_theme = gtk_icon_theme_get_for_screen(gtk_widget_get_screen(for_widget)); icons->icon_theme = gtk_icon_theme_get_for_screen(gtk_widget_get_screen(for_widget));
icons->icon_size = get_size_in_pixels(icon_size); icons->icon_size = get_size_in_pixels(icon_size);
icons->cache = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref); icons->cache = g_hash_table_new_full(g_str_hash, g_str_equal, nullptr, g_object_unref);
g_hash_table_insert(icons->cache, (void*)VOID_PIXBUF_KEY, create_void_pixbuf(icons->icon_size, icons->icon_size)); g_hash_table_insert(icons->cache, (void*)VOID_PIXBUF_KEY, create_void_pixbuf(icons->icon_size, icons->icon_size));
@ -72,14 +72,14 @@ static IconCache* icon_cache_new(GtkWidget* for_widget, GtkIconSize icon_size)
static char const* _icon_cache_get_icon_key(GIcon* icon) static char const* _icon_cache_get_icon_key(GIcon* icon)
{ {
char const* key = NULL; char const* key = nullptr;
if (G_IS_THEMED_ICON(icon)) if (G_IS_THEMED_ICON(icon))
{ {
char** icon_names; char** icon_names;
char* name; char* name;
g_object_get(icon, "names", &icon_names, NULL); g_object_get(icon, "names", &icon_names, nullptr);
name = g_strjoinv(",", icon_names); name = g_strjoinv(",", icon_names);
key = get_static_string(name); key = get_static_string(name);
@ -106,25 +106,25 @@ static char const* _icon_cache_get_icon_key(GIcon* icon)
static GdkPixbuf* get_themed_icon_pixbuf(GThemedIcon* icon, int size, GtkIconTheme* icon_theme) static GdkPixbuf* get_themed_icon_pixbuf(GThemedIcon* icon, int size, GtkIconTheme* icon_theme)
{ {
char** icon_names = NULL; char** icon_names = nullptr;
GtkIconInfo* icon_info; GtkIconInfo* icon_info;
GdkPixbuf* pixbuf; GdkPixbuf* pixbuf;
GError* error = NULL; GError* error = nullptr;
g_object_get(icon, "names", &icon_names, NULL); g_object_get(icon, "names", &icon_names, nullptr);
icon_info = gtk_icon_theme_choose_icon(icon_theme, (char const**)icon_names, size, {}); icon_info = gtk_icon_theme_choose_icon(icon_theme, (char const**)icon_names, size, {});
if (icon_info == NULL) if (icon_info == nullptr)
{ {
icon_info = gtk_icon_theme_lookup_icon(icon_theme, "text-x-generic", size, GTK_ICON_LOOKUP_USE_BUILTIN); icon_info = gtk_icon_theme_lookup_icon(icon_theme, "text-x-generic", size, GTK_ICON_LOOKUP_USE_BUILTIN);
} }
pixbuf = gtk_icon_info_load_icon(icon_info, &error); pixbuf = gtk_icon_info_load_icon(icon_info, &error);
if (pixbuf == NULL) if (pixbuf == nullptr)
{ {
if (error != NULL && error->message != NULL) if (error != nullptr && error->message != nullptr)
{ {
g_warning("could not load icon pixbuf: %s\n", error->message); g_warning("could not load icon pixbuf: %s\n", error->message);
} }
@ -151,7 +151,7 @@ static GdkPixbuf* get_file_icon_pixbuf(GFileIcon* icon, int size)
file = g_file_icon_get_file(icon); file = g_file_icon_get_file(icon);
filename = g_file_get_path(file); filename = g_file_get_path(file);
pixbuf = gdk_pixbuf_new_from_file_at_size(filename, size, -1, NULL); pixbuf = gdk_pixbuf_new_from_file_at_size(filename, size, -1, nullptr);
g_free(filename); g_free(filename);
g_object_unref(file); g_object_unref(file);
@ -160,9 +160,9 @@ static GdkPixbuf* get_file_icon_pixbuf(GFileIcon* icon, int size)
static GdkPixbuf* _get_icon_pixbuf(GIcon* icon, int size, GtkIconTheme* theme) static GdkPixbuf* _get_icon_pixbuf(GIcon* icon, int size, GtkIconTheme* theme)
{ {
if (icon == NULL) if (icon == nullptr)
{ {
return NULL; return nullptr;
} }
if (G_IS_THEMED_ICON(icon)) if (G_IS_THEMED_ICON(icon))
@ -175,21 +175,21 @@ static GdkPixbuf* _get_icon_pixbuf(GIcon* icon, int size, GtkIconTheme* theme)
return get_file_icon_pixbuf(G_FILE_ICON(icon), size); return get_file_icon_pixbuf(G_FILE_ICON(icon), size);
} }
return NULL; return nullptr;
} }
static GdkPixbuf* icon_cache_get_mime_type_icon(IconCache* icons, char const* mime_type) static GdkPixbuf* icon_cache_get_mime_type_icon(IconCache* icons, char const* mime_type)
{ {
GIcon* icon = g_content_type_get_icon(mime_type); GIcon* icon = g_content_type_get_icon(mime_type);
char const* key = _icon_cache_get_icon_key(icon); char const* key = _icon_cache_get_icon_key(icon);
if (key == NULL) if (key == nullptr)
{ {
key = VOID_PIXBUF_KEY; key = VOID_PIXBUF_KEY;
} }
g_return_val_if_fail(icons != NULL, NULL); g_return_val_if_fail(icons != nullptr, nullptr);
auto* pixbuf = static_cast<GdkPixbuf*>(g_hash_table_lookup(icons->cache, key)); auto* pixbuf = static_cast<GdkPixbuf*>(g_hash_table_lookup(icons->cache, key));
if (pixbuf != NULL) if (pixbuf != nullptr)
{ {
g_object_ref(pixbuf); g_object_ref(pixbuf);
g_object_unref(G_OBJECT(icon)); g_object_unref(G_OBJECT(icon));
@ -198,7 +198,7 @@ static GdkPixbuf* icon_cache_get_mime_type_icon(IconCache* icons, char const* mi
pixbuf = _get_icon_pixbuf(icon, icons->icon_size, icons->icon_theme); pixbuf = _get_icon_pixbuf(icon, icons->icon_size, icons->icon_theme);
if (pixbuf != NULL) if (pixbuf != nullptr)
{ {
g_hash_table_insert(icons->cache, (gpointer)key, g_object_ref(pixbuf)); g_hash_table_insert(icons->cache, (gpointer)key, g_object_ref(pixbuf));
} }
@ -243,7 +243,7 @@ GdkPixbuf* gtr_get_mime_type_icon(char const* mime_type, GtkIconSize icon_size,
break; break;
} }
if (icon_cache[n] == NULL) if (icon_cache[n] == nullptr)
{ {
icon_cache[n] = icon_cache_new(for_widget, icon_size); icon_cache[n] = icon_cache_new(for_widget, icon_size);
} }
@ -253,7 +253,7 @@ GdkPixbuf* gtr_get_mime_type_icon(char const* mime_type, GtkIconSize icon_size,
char const* gtr_get_mime_type_from_filename(char const* file) char const* gtr_get_mime_type_from_filename(char const* file)
{ {
char* tmp = g_content_type_guess(file, NULL, 0, NULL); char* tmp = g_content_type_guess(file, nullptr, 0, nullptr);
char const* ret = get_static_string(tmp); char const* ret = get_static_string(tmp);
g_free(tmp); g_free(tmp);
return ret; return ret;

View File

@ -114,9 +114,9 @@ static int compare_integers(gconstpointer a, gconstpointer b)
static char* get_details_dialog_key(GSList* id_list) static char* get_details_dialog_key(GSList* id_list)
{ {
GSList* tmp = g_slist_sort(g_slist_copy(id_list), compare_integers); GSList* tmp = g_slist_sort(g_slist_copy(id_list), compare_integers);
GString* gstr = g_string_new(NULL); GString* gstr = g_string_new(nullptr);
for (GSList* l = tmp; l != NULL; l = l->next) for (GSList* l = tmp; l != nullptr; l = l->next)
{ {
g_string_append_printf(gstr, "%d ", GPOINTER_TO_INT(l->data)); g_string_append_printf(gstr, "%d ", GPOINTER_TO_INT(l->data));
} }
@ -137,7 +137,7 @@ static void get_selected_torrent_ids_foreach(GtkTreeModel* model, GtkTreePath* p
static GSList* get_selected_torrent_ids(struct cbdata* data) static GSList* get_selected_torrent_ids(struct cbdata* data)
{ {
GSList* ids = NULL; GSList* ids = nullptr;
gtk_tree_selection_selected_foreach(data->sel, get_selected_torrent_ids_foreach, &ids); gtk_tree_selection_selected_foreach(data->sel, get_selected_torrent_ids_foreach, &ids);
return ids; return ids;
} }
@ -151,11 +151,11 @@ static void on_details_dialog_closed(gpointer gdata, GObject* dead)
static void show_details_dialog_for_selected_torrents(struct cbdata* data) static void show_details_dialog_for_selected_torrents(struct cbdata* data)
{ {
GtkWidget* dialog = NULL; GtkWidget* dialog = nullptr;
GSList* ids = get_selected_torrent_ids(data); GSList* ids = get_selected_torrent_ids(data);
char* key = get_details_dialog_key(ids); char* key = get_details_dialog_key(ids);
for (GSList* l = data->details; dialog == NULL && l != NULL; l = l->next) for (GSList* l = data->details; dialog == nullptr && l != nullptr; l = l->next)
{ {
if (g_strcmp0(key, static_cast<char const*>(g_object_get_data(static_cast<GObject*>(l->data), "key"))) == 0) if (g_strcmp0(key, static_cast<char const*>(g_object_get_data(static_cast<GObject*>(l->data), "key"))) == 0)
{ {
@ -163,7 +163,7 @@ static void show_details_dialog_for_selected_torrents(struct cbdata* data)
} }
} }
if (dialog == NULL) if (dialog == nullptr)
{ {
dialog = gtr_torrent_details_dialog_new(GTK_WINDOW(data->wind), data->core); dialog = gtr_torrent_details_dialog_new(GTK_WINDOW(data->wind), data->core);
gtr_torrent_details_dialog_set_torrents(dialog, ids); gtr_torrent_details_dialog_set_torrents(dialog, ids);
@ -241,7 +241,7 @@ static gboolean refresh_actions(gpointer gdata)
struct counts_data sel_counts; struct counts_data sel_counts;
size_t const total = gtr_core_get_torrent_count(data->core); size_t const total = gtr_core_get_torrent_count(data->core);
size_t const active = gtr_core_get_active_torrent_count(data->core); size_t const active = gtr_core_get_active_torrent_count(data->core);
int const torrent_count = gtk_tree_model_iter_n_children(gtr_core_model(data->core), NULL); int const torrent_count = gtk_tree_model_iter_n_children(gtr_core_model(data->core), nullptr);
bool has_selection; bool has_selection;
get_selected_torrent_counts(data, &sel_counts); get_selected_torrent_counts(data, &sel_counts);
@ -300,7 +300,7 @@ static void on_selection_changed(GtkTreeSelection const* s, gpointer gdata)
static gboolean has_magnet_link_handler(void) static gboolean has_magnet_link_handler(void)
{ {
GAppInfo* app_info = g_app_info_get_default_for_uri_scheme("magnet"); GAppInfo* app_info = g_app_info_get_default_for_uri_scheme("magnet");
gboolean const has_handler = app_info != NULL; gboolean const has_handler = app_info != nullptr;
g_clear_object(&app_info); g_clear_object(&app_info);
return has_handler; return has_handler;
} }
@ -311,11 +311,11 @@ static void register_magnet_link_handler(void)
GAppInfo* app; GAppInfo* app;
char const* const content_type = "x-scheme-handler/magnet"; char const* const content_type = "x-scheme-handler/magnet";
error = NULL; error = nullptr;
app = g_app_info_create_from_commandline("transmission-gtk", "transmission-gtk", G_APP_INFO_CREATE_SUPPORTS_URIS, &error); app = g_app_info_create_from_commandline("transmission-gtk", "transmission-gtk", G_APP_INFO_CREATE_SUPPORTS_URIS, &error);
g_app_info_set_as_default_for_type(app, content_type, &error); g_app_info_set_as_default_for_type(app, content_type, &error);
if (error != NULL) if (error != nullptr)
{ {
g_warning(_("Error registering Transmission as a %s handler: %s"), content_type, error->message); g_warning(_("Error registering Transmission as a %s handler: %s"), content_type, error->message);
g_error_free(error); g_error_free(error);
@ -338,7 +338,7 @@ static void on_main_window_size_allocated(GtkWidget* gtk_window, GtkAllocation c
TR_UNUSED(gdata); TR_UNUSED(gdata);
GdkWindow* gdk_window = gtk_widget_get_window(gtk_window); GdkWindow* gdk_window = gtk_widget_get_window(gtk_window);
gboolean const isMaximized = gdk_window != NULL && (gdk_window_get_state(gdk_window) & GDK_WINDOW_STATE_MAXIMIZED) != 0; gboolean const isMaximized = gdk_window != nullptr && (gdk_window_get_state(gdk_window) & GDK_WINDOW_STATE_MAXIMIZED) != 0;
gtr_pref_int_set(TR_KEY_main_window_is_maximized, isMaximized); gtr_pref_int_set(TR_KEY_main_window_is_maximized, isMaximized);
@ -380,7 +380,7 @@ static gboolean on_rpc_changed_idle(gpointer gdata)
break; break;
case TR_RPC_TORRENT_ADDED: case TR_RPC_TORRENT_ADDED:
if ((tor = gtr_core_find_torrent(data->core, data->torrent_id)) != NULL) if ((tor = gtr_core_find_torrent(data->core, data->torrent_id)) != nullptr)
{ {
gtr_core_add_torrent(data->core, tor, true); gtr_core_add_torrent(data->core, tor, true);
} }
@ -401,7 +401,7 @@ static gboolean on_rpc_changed_idle(gpointer gdata)
tr_variant* newval; tr_variant* newval;
tr_variant* oldvals = gtr_pref_get_all(); tr_variant* oldvals = gtr_pref_get_all();
tr_quark key; tr_quark key;
GSList* changed_keys = NULL; GSList* changed_keys = nullptr;
tr_session* session = gtr_core_session(data->core); tr_session* session = gtr_core_session(data->core);
tr_variantInitDict(&tmp, 100); tr_variantInitDict(&tmp, 100);
tr_sessionGetSettings(session, &tmp); tr_sessionGetSettings(session, &tmp);
@ -411,14 +411,14 @@ static gboolean on_rpc_changed_idle(gpointer gdata)
bool changed; bool changed;
tr_variant const* oldval = tr_variantDictFind(oldvals, key); tr_variant const* oldval = tr_variantDictFind(oldvals, key);
if (oldval == NULL) if (oldval == nullptr)
{ {
changed = true; changed = true;
} }
else else
{ {
char* a = tr_variantToStr(oldval, TR_VARIANT_FMT_BENC, NULL); char* a = tr_variantToStr(oldval, TR_VARIANT_FMT_BENC, nullptr);
char* b = tr_variantToStr(newval, TR_VARIANT_FMT_BENC, NULL); char* b = tr_variantToStr(newval, TR_VARIANT_FMT_BENC, nullptr);
changed = g_strcmp0(a, b) != 0; changed = g_strcmp0(a, b) != 0;
tr_free(b); tr_free(b);
tr_free(a); tr_free(a);
@ -432,7 +432,7 @@ static gboolean on_rpc_changed_idle(gpointer gdata)
tr_sessionGetSettings(session, oldvals); tr_sessionGetSettings(session, oldvals);
for (GSList* l = changed_keys; l != NULL; l = l->next) for (GSList* l = changed_keys; l != nullptr; l = l->next)
{ {
gtr_core_pref_changed(data->core, GPOINTER_TO_INT(l->data)); gtr_core_pref_changed(data->core, GPOINTER_TO_INT(l->data));
} }
@ -516,12 +516,12 @@ static void on_startup(GApplication* application, gpointer user_data)
sighandler_cbdata = cbdata; sighandler_cbdata = cbdata;
/* ensure the directories are created */ /* ensure the directories are created */
if ((str = gtr_pref_string_get(TR_KEY_download_dir)) != NULL) if ((str = gtr_pref_string_get(TR_KEY_download_dir)) != nullptr)
{ {
g_mkdir_with_parents(str, 0777); g_mkdir_with_parents(str, 0777);
} }
if ((str = gtr_pref_string_get(TR_KEY_incomplete_dir)) != NULL) if ((str = gtr_pref_string_get(TR_KEY_incomplete_dir)) != nullptr)
{ {
g_mkdir_with_parents(str, 0777); g_mkdir_with_parents(str, 0777);
} }
@ -534,7 +534,7 @@ static void on_startup(GApplication* application, gpointer user_data)
cbdata->core = gtr_core_new(session); cbdata->core = gtr_core_new(session);
/* init the ui manager */ /* init the ui manager */
error = NULL; error = nullptr;
ui_manager = gtk_ui_manager_new(); ui_manager = gtk_ui_manager_new();
gtr_actions_init(ui_manager, cbdata); gtr_actions_init(ui_manager, cbdata);
gtk_ui_manager_add_ui_from_resource(ui_manager, TR_RESOURCE_PATH "transmission-ui.xml", &error); gtk_ui_manager_add_ui_from_resource(ui_manager, TR_RESOURCE_PATH "transmission-ui.xml", &error);
@ -554,7 +554,7 @@ static void on_startup(GApplication* application, gpointer user_data)
{ {
int64_t const last_time = gtr_pref_int_get(TR_KEY_blocklist_date); int64_t const last_time = gtr_pref_int_get(TR_KEY_blocklist_date);
int const SECONDS_IN_A_WEEK = 7 * 24 * 60 * 60; int const SECONDS_IN_A_WEEK = 7 * 24 * 60 * 60;
time_t const now = time(NULL); time_t const now = time(nullptr);
if (last_time + SECONDS_IN_A_WEEK < now) if (last_time + SECONDS_IN_A_WEEK < now)
{ {
@ -598,7 +598,7 @@ static void on_open(GApplication const* application, GFile** f, gint file_count,
TR_UNUSED(application); TR_UNUSED(application);
TR_UNUSED(hint); TR_UNUSED(hint);
GSList* files = NULL; GSList* files = nullptr;
for (gint i = 0; i < file_count; i++) for (gint i = 0; i < file_count; i++)
{ {
@ -622,15 +622,21 @@ int main(int argc, char** argv)
GtkApplication* app; GtkApplication* app;
GOptionContext* option_context; GOptionContext* option_context;
bool show_version = false; bool show_version = false;
GError* error = NULL; GError* error = nullptr;
struct cbdata cbdata; struct cbdata cbdata;
GOptionEntry option_entries[] = { GOptionEntry option_entries[] = {
{ "config-dir", 'g', 0, G_OPTION_ARG_FILENAME, &cbdata.config_dir, _("Where to look for configuration files"), NULL }, { "config-dir",
{ "paused", 'p', 0, G_OPTION_ARG_NONE, &cbdata.start_paused, _("Start with all torrents paused"), NULL }, 'g',
{ "minimized", 'm', 0, G_OPTION_ARG_NONE, &cbdata.is_iconified, _("Start minimized in notification area"), NULL }, 0,
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, _("Show version number and exit"), NULL }, G_OPTION_ARG_FILENAME,
{ NULL, 0, 0, {}, NULL, NULL, NULL } &cbdata.config_dir,
_("Where to look for configuration files"),
nullptr },
{ "paused", 'p', 0, G_OPTION_ARG_NONE, &cbdata.start_paused, _("Start with all torrents paused"), nullptr },
{ "minimized", 'm', 0, G_OPTION_ARG_NONE, &cbdata.is_iconified, _("Start minimized in notification area"), nullptr },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, _("Show version number and exit"), nullptr },
{ nullptr, 0, 0, {}, nullptr, nullptr, nullptr }
}; };
/* default settings */ /* default settings */
@ -752,7 +758,7 @@ static void app_setup(GtkWindow* wind, struct cbdata* cbdata)
} }
else else
{ {
gtk_window_set_skip_taskbar_hint(cbdata->wind, cbdata->icon != NULL); gtk_window_set_skip_taskbar_hint(cbdata->wind, cbdata->icon != nullptr);
cbdata->is_iconified = FALSE; // ensure that the next toggle iconifies cbdata->is_iconified = FALSE; // ensure that the next toggle iconifies
gtr_action_set_toggled("toggle-main-window", FALSE); gtr_action_set_toggled("toggle-main-window", FALSE);
} }
@ -844,7 +850,7 @@ static gboolean winclose(GtkWidget const* w, GdkEvent const* event, gpointer gda
auto* cbdata = static_cast<struct cbdata*>(gdata); auto* cbdata = static_cast<struct cbdata*>(gdata);
if (cbdata->icon != NULL) if (cbdata->icon != nullptr)
{ {
gtr_action_activate("toggle-main-window"); gtr_action_activate("toggle-main-window");
} }
@ -886,7 +892,7 @@ static void on_drag_data_received(
char** uris = gtk_selection_data_get_uris(selection_data); char** uris = gtk_selection_data_get_uris(selection_data);
guint const file_count = g_strv_length(uris); guint const file_count = g_strv_length(uris);
GSList* files = NULL; GSList* files = nullptr;
for (guint i = 0; i < file_count; ++i) for (guint i = 0; i < file_count; ++i)
{ {
@ -896,7 +902,7 @@ static void on_drag_data_received(
open_files(files, gdata); open_files(files, gdata);
/* cleanup */ /* cleanup */
g_slist_foreach(files, (GFunc)(GCallback)g_object_unref, NULL); g_slist_foreach(files, (GFunc)(GCallback)g_object_unref, nullptr);
g_slist_free(files); g_slist_free(files);
g_strfreev(uris); g_strfreev(uris);
@ -909,7 +915,7 @@ static void main_window_setup(struct cbdata* cbdata, GtkWindow* wind)
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeSelection* sel; GtkTreeSelection* sel;
g_assert(NULL == cbdata->wind); g_assert(nullptr == cbdata->wind);
cbdata->wind = wind; cbdata->wind = wind;
cbdata->sel = sel = GTK_TREE_SELECTION(gtr_window_get_selection(cbdata->wind)); cbdata->sel = sel = GTK_TREE_SELECTION(gtr_window_get_selection(cbdata->wind));
@ -922,7 +928,7 @@ static void main_window_setup(struct cbdata* cbdata, GtkWindow* wind)
/* register to handle URIs that get dragged onto our main window */ /* register to handle URIs that get dragged onto our main window */
w = GTK_WIDGET(wind); w = GTK_WIDGET(wind);
gtk_drag_dest_set(w, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY); gtk_drag_dest_set(w, GTK_DEST_DEFAULT_ALL, nullptr, 0, GDK_ACTION_COPY);
gtk_drag_dest_add_uri_targets(w); gtk_drag_dest_add_uri_targets(w);
g_signal_connect(w, "drag-data-received", G_CALLBACK(on_drag_data_received), cbdata); g_signal_connect(w, "drag-data-received", G_CALLBACK(on_drag_data_received), cbdata);
} }
@ -933,29 +939,29 @@ static gboolean on_session_closed(gpointer gdata)
auto* cbdata = static_cast<struct cbdata*>(gdata); auto* cbdata = static_cast<struct cbdata*>(gdata);
tmp = g_slist_copy(cbdata->details); tmp = g_slist_copy(cbdata->details);
g_slist_foreach(tmp, (GFunc)(GCallback)gtk_widget_destroy, NULL); g_slist_foreach(tmp, (GFunc)(GCallback)gtk_widget_destroy, nullptr);
g_slist_free(tmp); g_slist_free(tmp);
if (cbdata->prefs != NULL) if (cbdata->prefs != nullptr)
{ {
gtk_widget_destroy(GTK_WIDGET(cbdata->prefs)); gtk_widget_destroy(GTK_WIDGET(cbdata->prefs));
} }
if (cbdata->wind != NULL) if (cbdata->wind != nullptr)
{ {
gtk_widget_destroy(GTK_WIDGET(cbdata->wind)); gtk_widget_destroy(GTK_WIDGET(cbdata->wind));
} }
g_object_unref(cbdata->core); g_object_unref(cbdata->core);
if (cbdata->icon != NULL) if (cbdata->icon != nullptr)
{ {
g_object_unref(cbdata->icon); g_object_unref(cbdata->icon);
} }
g_slist_foreach(cbdata->error_list, (GFunc)(GCallback)g_free, NULL); g_slist_foreach(cbdata->error_list, (GFunc)(GCallback)g_free, nullptr);
g_slist_free(cbdata->error_list); g_slist_free(cbdata->error_list);
g_slist_foreach(cbdata->duplicates_list, (GFunc)(GCallback)g_free, NULL); g_slist_foreach(cbdata->duplicates_list, (GFunc)(GCallback)g_free, nullptr);
g_slist_free(cbdata->duplicates_list); g_slist_free(cbdata->duplicates_list);
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
@ -976,7 +982,7 @@ static gpointer session_close_threadfunc(gpointer gdata)
tr_sessionClose(data->session); tr_sessionClose(data->session);
gdk_threads_add_idle(on_session_closed, data->cbdata); gdk_threads_add_idle(on_session_closed, data->cbdata);
g_free(data); g_free(data);
return NULL; return nullptr;
} }
static void exit_now_cb() static void exit_now_cb()
@ -1021,24 +1027,24 @@ static void on_app_exit(gpointer vdata)
TR_ARG_TUPLE("column-spacing", GUI_PAD_BIG), TR_ARG_TUPLE("column-spacing", GUI_PAD_BIG),
TR_ARG_TUPLE("halign", GTK_ALIGN_CENTER), TR_ARG_TUPLE("halign", GTK_ALIGN_CENTER),
TR_ARG_TUPLE("valign", GTK_ALIGN_CENTER), TR_ARG_TUPLE("valign", GTK_ALIGN_CENTER),
NULL)); nullptr));
gtk_container_add(GTK_CONTAINER(c), p); gtk_container_add(GTK_CONTAINER(c), p);
w = gtk_image_new_from_icon_name("network-workgroup", GTK_ICON_SIZE_DIALOG); w = gtk_image_new_from_icon_name("network-workgroup", GTK_ICON_SIZE_DIALOG);
gtk_grid_attach(GTK_GRID(p), w, 0, 0, 1, 2); gtk_grid_attach(GTK_GRID(p), w, 0, 0, 1, 2);
w = gtk_label_new(NULL); w = gtk_label_new(nullptr);
gtk_label_set_markup(GTK_LABEL(w), _("<b>Closing Connections</b>")); gtk_label_set_markup(GTK_LABEL(w), _("<b>Closing Connections</b>"));
g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_grid_attach(GTK_GRID(p), w, 1, 0, 1, 1); gtk_grid_attach(GTK_GRID(p), w, 1, 0, 1, 1);
w = gtk_label_new(_("Sending upload/download totals to tracker…")); w = gtk_label_new(_("Sending upload/download totals to tracker…"));
g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_grid_attach(GTK_GRID(p), w, 1, 1, 1, 1); gtk_grid_attach(GTK_GRID(p), w, 1, 1, 1, 1);
w = gtk_button_new_with_mnemonic(_("_Quit Now")); w = gtk_button_new_with_mnemonic(_("_Quit Now"));
g_object_set(w, "margin-top", GUI_PAD, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_END, NULL); g_object_set(w, "margin-top", GUI_PAD, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_END, nullptr);
g_signal_connect(w, "clicked", G_CALLBACK(exit_now_cb), NULL); g_signal_connect(w, "clicked", G_CALLBACK(exit_now_cb), nullptr);
gtk_grid_attach(GTK_GRID(p), w, 1, 2, 1, 1); gtk_grid_attach(GTK_GRID(p), w, 1, 2, 1, 1);
gtk_widget_show_all(p); gtk_widget_show_all(p);
@ -1062,10 +1068,10 @@ static void on_app_exit(gpointer vdata)
static void show_torrent_errors(GtkWindow* window, char const* primary, GSList** files) static void show_torrent_errors(GtkWindow* window, char const* primary, GSList** files)
{ {
GtkWidget* w; GtkWidget* w;
GString* s = g_string_new(NULL); GString* s = g_string_new(nullptr);
char const* leader = g_slist_length(*files) > 1 ? gtr_get_unicode_string(GTR_UNICODE_BULLET) : ""; char const* leader = g_slist_length(*files) > 1 ? gtr_get_unicode_string(GTR_UNICODE_BULLET) : "";
for (GSList* l = *files; l != NULL; l = l->next) for (GSList* l = *files; l != nullptr; l = l->next)
{ {
g_string_append_printf(s, "%s %s\n", leader, (char const*)l->data); g_string_append_printf(s, "%s %s\n", leader, (char const*)l->data);
} }
@ -1076,14 +1082,14 @@ static void show_torrent_errors(GtkWindow* window, char const* primary, GSList**
gtk_widget_show(w); gtk_widget_show(w);
g_string_free(s, TRUE); g_string_free(s, TRUE);
g_slist_foreach(*files, (GFunc)(GCallback)g_free, NULL); g_slist_foreach(*files, (GFunc)(GCallback)g_free, nullptr);
g_slist_free(*files); g_slist_free(*files);
*files = NULL; *files = nullptr;
} }
static void flush_torrent_errors(struct cbdata* cbdata) static void flush_torrent_errors(struct cbdata* cbdata)
{ {
if (cbdata->error_list != NULL) if (cbdata->error_list != nullptr)
{ {
show_torrent_errors( show_torrent_errors(
cbdata->wind, cbdata->wind,
@ -1091,7 +1097,7 @@ static void flush_torrent_errors(struct cbdata* cbdata)
&cbdata->error_list); &cbdata->error_list);
} }
if (cbdata->duplicates_list != NULL) if (cbdata->duplicates_list != nullptr)
{ {
show_torrent_errors( show_torrent_errors(
cbdata->wind, cbdata->wind,
@ -1134,7 +1140,7 @@ static gboolean on_main_window_focus_in(GtkWidget const* widget, GdkEventFocus c
auto* cbdata = static_cast<struct cbdata*>(gdata); auto* cbdata = static_cast<struct cbdata*>(gdata);
if (cbdata->wind != NULL) if (cbdata->wind != nullptr)
{ {
gtk_window_set_urgency_hint(cbdata->wind, FALSE); gtk_window_set_urgency_hint(cbdata->wind, FALSE);
} }
@ -1149,7 +1155,7 @@ static void on_add_torrent(TrCore* core, tr_ctor* ctor, gpointer gdata)
g_signal_connect(w, "focus-in-event", G_CALLBACK(on_main_window_focus_in), cbdata); g_signal_connect(w, "focus-in-event", G_CALLBACK(on_main_window_focus_in), cbdata);
if (cbdata->wind != NULL) if (cbdata->wind != nullptr)
{ {
gtk_window_set_urgency_hint(cbdata->wind, TRUE); gtk_window_set_urgency_hint(cbdata->wind, TRUE);
} }
@ -1194,11 +1200,11 @@ static void on_prefs_changed(TrCore const* core, tr_quark const key, gpointer da
{ {
bool const show = gtr_pref_flag_get(key); bool const show = gtr_pref_flag_get(key);
if (show && cbdata->icon == NULL) if (show && cbdata->icon == nullptr)
{ {
cbdata->icon = gtr_icon_new(cbdata->core); cbdata->icon = gtr_icon_new(cbdata->core);
} }
else if (!show && cbdata->icon != NULL) else if (!show && cbdata->icon != nullptr)
{ {
g_clear_object(&cbdata->icon); g_clear_object(&cbdata->icon);
} }
@ -1310,7 +1316,7 @@ static void on_prefs_changed(TrCore const* core, tr_quark const key, gpointer da
{ {
bool const b = gtr_pref_flag_get(key); bool const b = gtr_pref_flag_get(key);
tr_sessionUseAltSpeed(tr, b); tr_sessionUseAltSpeed(tr, b);
gtr_action_set_toggled(tr_quark_get_string(key, NULL), b); gtr_action_set_toggled(tr_quark_get_string(key, nullptr), b);
break; break;
} }
@ -1371,7 +1377,7 @@ static gboolean update_model_once(gpointer gdata)
gtr_core_update(data->core); gtr_core_update(data->core);
/* refresh the main window's statusbar and toolbar buttons */ /* refresh the main window's statusbar and toolbar buttons */
if (data->wind != NULL) if (data->wind != nullptr)
{ {
gtr_window_refresh(data->wind); gtr_window_refresh(data->wind);
} }
@ -1380,7 +1386,7 @@ static gboolean update_model_once(gpointer gdata)
refresh_actions(data); refresh_actions(data);
/* update the status tray icon */ /* update the status tray icon */
if (data->icon != NULL) if (data->icon != nullptr)
{ {
gtr_icon_refresh(data->icon); gtr_icon_refresh(data->icon);
} }
@ -1418,7 +1424,7 @@ static void show_about_dialog(GtkWindow* parent)
"Charles Kerr (Backend; GTK+)", "Charles Kerr (Backend; GTK+)",
"Mitchell Livingston (Backend; OS X)", "Mitchell Livingston (Backend; OS X)",
"Mike Gelfand", "Mike Gelfand",
NULL, nullptr,
}; };
gtk_show_about_dialog( gtk_show_about_dialog(
@ -1439,14 +1445,14 @@ static void show_about_dialog(GtkWindow* parent)
TR_ARG_TUPLE("license", LICENSE), TR_ARG_TUPLE("license", LICENSE),
TR_ARG_TUPLE("wrap-license", TRUE), TR_ARG_TUPLE("wrap-license", TRUE),
#endif #endif
NULL); nullptr);
} }
static void append_id_to_benc_list(GtkTreeModel* m, GtkTreePath* path, GtkTreeIter* iter, gpointer list) static void append_id_to_benc_list(GtkTreeModel* m, GtkTreePath* path, GtkTreeIter* iter, gpointer list)
{ {
TR_UNUSED(path); TR_UNUSED(path);
tr_torrent* tor = NULL; tr_torrent* tor = nullptr;
gtk_tree_model_get(m, iter, MC_TORRENT, &tor, -1); gtk_tree_model_get(m, iter, MC_TORRENT, &tor, -1);
tr_variantListAddInt(static_cast<tr_variant*>(list), tr_torrentId(tor)); tr_variantListAddInt(static_cast<tr_variant*>(list), tr_torrentId(tor));
} }
@ -1468,7 +1474,7 @@ static gboolean call_rpc_for_selected_torrents(struct cbdata* data, char const*
if (tr_variantListSize(ids) != 0) if (tr_variantListSize(ids) != 0)
{ {
tr_rpc_request_exec_json(session, &top, NULL, NULL); tr_rpc_request_exec_json(session, &top, nullptr, nullptr);
invoked = TRUE; invoked = TRUE;
} }
@ -1504,11 +1510,11 @@ static void accumulate_selected_torrents(GtkTreeModel* model, GtkTreePath* path,
static void remove_selected(struct cbdata* data, gboolean delete_files) static void remove_selected(struct cbdata* data, gboolean delete_files)
{ {
GSList* l = NULL; GSList* l = nullptr;
gtk_tree_selection_selected_foreach(data->sel, accumulate_selected_torrents, &l); gtk_tree_selection_selected_foreach(data->sel, accumulate_selected_torrents, &l);
if (l != NULL) if (l != nullptr)
{ {
gtr_confirm_remove(data->wind, data->core, l, delete_files); gtr_confirm_remove(data->wind, data->core, l, delete_files);
} }
@ -1521,7 +1527,7 @@ static void start_all_torrents(struct cbdata* data)
tr_variantInitDict(&request, 1); tr_variantInitDict(&request, 1);
tr_variantDictAddStr(&request, TR_KEY_method, "torrent-start"); tr_variantDictAddStr(&request, TR_KEY_method, "torrent-start");
tr_rpc_request_exec_json(session, &request, NULL, NULL); tr_rpc_request_exec_json(session, &request, nullptr, nullptr);
tr_variantFree(&request); tr_variantFree(&request);
} }
@ -1532,17 +1538,17 @@ static void pause_all_torrents(struct cbdata* data)
tr_variantInitDict(&request, 1); tr_variantInitDict(&request, 1);
tr_variantDictAddStr(&request, TR_KEY_method, "torrent-stop"); tr_variantDictAddStr(&request, TR_KEY_method, "torrent-stop");
tr_rpc_request_exec_json(session, &request, NULL, NULL); tr_rpc_request_exec_json(session, &request, nullptr, nullptr);
tr_variantFree(&request); tr_variantFree(&request);
} }
static tr_torrent* get_first_selected_torrent(struct cbdata* data) static tr_torrent* get_first_selected_torrent(struct cbdata* data)
{ {
tr_torrent* tor = NULL; tr_torrent* tor = nullptr;
GtkTreeModel* m; GtkTreeModel* m;
GList* l = gtk_tree_selection_get_selected_rows(data->sel, &m); GList* l = gtk_tree_selection_get_selected_rows(data->sel, &m);
if (l != NULL) if (l != nullptr)
{ {
auto* p = static_cast<GtkTreePath*>(l->data); auto* p = static_cast<GtkTreePath*>(l->data);
GtkTreeIter i; GtkTreeIter i;
@ -1553,7 +1559,7 @@ static tr_torrent* get_first_selected_torrent(struct cbdata* data)
} }
} }
g_list_foreach(l, (GFunc)(GCallback)gtk_tree_path_free, NULL); g_list_foreach(l, (GFunc)(GCallback)gtk_tree_path_free, nullptr);
g_list_free(l); g_list_free(l);
return tor; return tor;
} }
@ -1615,7 +1621,7 @@ void gtr_actions_handler(char const* action_name, gpointer user_data)
{ {
tr_torrent* tor = get_first_selected_torrent(data); tr_torrent* tor = get_first_selected_torrent(data);
if (tor != NULL) if (tor != nullptr)
{ {
copy_magnet_link_to_clipboard(GTK_WIDGET(data->wind), tor); copy_magnet_link_to_clipboard(GTK_WIDGET(data->wind), tor);
} }
@ -1624,7 +1630,7 @@ void gtr_actions_handler(char const* action_name, gpointer user_data)
{ {
GSList* ids = get_selected_torrent_ids(data); GSList* ids = get_selected_torrent_ids(data);
if (ids != NULL) if (ids != nullptr)
{ {
GtkWindow* parent = data->wind; GtkWindow* parent = data->wind;
GtkWidget* w = gtr_relocate_dialog_new(parent, data->core, ids); GtkWidget* w = gtr_relocate_dialog_new(parent, data->core, ids);
@ -1675,7 +1681,7 @@ void gtr_actions_handler(char const* action_name, gpointer user_data)
} }
else if (g_strcmp0(action_name, "edit-preferences") == 0) else if (g_strcmp0(action_name, "edit-preferences") == 0)
{ {
if (data->prefs == NULL) if (data->prefs == nullptr)
{ {
data->prefs = gtr_prefs_dialog_new(data->wind, G_OBJECT(data->core)); data->prefs = gtr_prefs_dialog_new(data->wind, G_OBJECT(data->core));
g_signal_connect(data->prefs, "destroy", G_CALLBACK(gtk_widget_destroyed), &data->prefs); g_signal_connect(data->prefs, "destroy", G_CALLBACK(gtk_widget_destroyed), &data->prefs);
@ -1685,17 +1691,17 @@ void gtr_actions_handler(char const* action_name, gpointer user_data)
} }
else if (g_strcmp0(action_name, "toggle-message-log") == 0) else if (g_strcmp0(action_name, "toggle-message-log") == 0)
{ {
if (data->msgwin == NULL) if (data->msgwin == nullptr)
{ {
GtkWidget* win = gtr_message_log_window_new(data->wind, data->core); GtkWidget* win = gtr_message_log_window_new(data->wind, data->core);
g_signal_connect(win, "destroy", G_CALLBACK(on_message_window_closed), NULL); g_signal_connect(win, "destroy", G_CALLBACK(on_message_window_closed), nullptr);
data->msgwin = win; data->msgwin = win;
} }
else else
{ {
gtr_action_set_toggled("toggle-message-log", FALSE); gtr_action_set_toggled("toggle-message-log", FALSE);
gtk_widget_destroy(data->msgwin); gtk_widget_destroy(data->msgwin);
data->msgwin = NULL; data->msgwin = nullptr;
} }
} }
else if (g_strcmp0(action_name, "show-about-dialog") == 0) else if (g_strcmp0(action_name, "show-about-dialog") == 0)

View File

@ -55,7 +55,7 @@ static void freeMetaUI(gpointer p)
static gboolean onProgressDialogRefresh(gpointer data) static gboolean onProgressDialogRefresh(gpointer data)
{ {
char* str = NULL; char* str = nullptr;
auto* ui = static_cast<MakeMetaUI*>(data); auto* ui = static_cast<MakeMetaUI*>(data);
tr_metainfo_builder const* b = ui->builder; tr_metainfo_builder const* b = ui->builder;
GtkDialog* d = GTK_DIALOG(ui->progress_dialog); GtkDialog* d = GTK_DIALOG(ui->progress_dialog);
@ -93,7 +93,7 @@ static gboolean onProgressDialogRefresh(gpointer data)
g_assert_not_reached(); g_assert_not_reached();
} }
if (str != NULL) if (str != nullptr)
{ {
gtr_label_set_text(GTK_LABEL(ui->progress_label), str); gtr_label_set_text(GTK_LABEL(ui->progress_label), str);
g_free(str); g_free(str);
@ -188,18 +188,18 @@ static void makeProgressDialog(GtkWidget* parent, MakeMetaUI* ui)
TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL), TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL),
TR_ARG_TUPLE(_("_Close"), GTK_RESPONSE_CLOSE), TR_ARG_TUPLE(_("_Close"), GTK_RESPONSE_CLOSE),
TR_ARG_TUPLE(_("_Add"), GTK_RESPONSE_ACCEPT), TR_ARG_TUPLE(_("_Add"), GTK_RESPONSE_ACCEPT),
NULL); nullptr);
ui->progress_dialog = d; ui->progress_dialog = d;
g_signal_connect(d, "response", G_CALLBACK(onProgressDialogResponse), ui); g_signal_connect(d, "response", G_CALLBACK(onProgressDialogResponse), ui);
fr = gtk_frame_new(NULL); fr = gtk_frame_new(nullptr);
gtk_container_set_border_width(GTK_CONTAINER(fr), GUI_PAD_BIG); gtk_container_set_border_width(GTK_CONTAINER(fr), GUI_PAD_BIG);
gtk_frame_set_shadow_type(GTK_FRAME(fr), GTK_SHADOW_NONE); gtk_frame_set_shadow_type(GTK_FRAME(fr), GTK_SHADOW_NONE);
v = gtk_box_new(GTK_ORIENTATION_VERTICAL, GUI_PAD); v = gtk_box_new(GTK_ORIENTATION_VERTICAL, GUI_PAD);
gtk_container_add(GTK_CONTAINER(fr), v); gtk_container_add(GTK_CONTAINER(fr), v);
l = gtk_label_new(_("Creating torrent…")); l = gtk_label_new(_("Creating torrent…"));
g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_label_set_justify(GTK_LABEL(l), GTK_JUSTIFY_LEFT); gtk_label_set_justify(GTK_LABEL(l), GTK_JUSTIFY_LEFT);
ui->progress_label = l; ui->progress_label = l;
gtk_box_pack_start(GTK_BOX(v), l, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(v), l, FALSE, FALSE, 0);
@ -222,7 +222,7 @@ static void onResponse(GtkDialog* d, int response, gpointer user_data)
if (response == GTK_RESPONSE_ACCEPT) if (response == GTK_RESPONSE_ACCEPT)
{ {
if (ui->builder != NULL) if (ui->builder != nullptr)
{ {
int n; int n;
int tier; int tier;
@ -255,7 +255,7 @@ static void onResponse(GtkDialog* d, int response, gpointer user_data)
n = 0; n = 0;
tier = 0; tier = 0;
for (int i = 0; tracker_strings[i] != NULL; ++i) for (int i = 0; tracker_strings[i] != nullptr; ++i)
{ {
char* const str = tracker_strings[i]; char* const str = tracker_strings[i];
@ -273,7 +273,7 @@ static void onResponse(GtkDialog* d, int response, gpointer user_data)
/* build the .torrent */ /* build the .torrent */
makeProgressDialog(GTK_WIDGET(d), ui); makeProgressDialog(GTK_WIDGET(d), ui);
tr_makeMetaInfo(ui->builder, ui->target, trackers, n, useComment ? comment : NULL, isPrivate); tr_makeMetaInfo(ui->builder, ui->target, trackers, n, useComment ? comment : nullptr, isPrivate);
/* cleanup */ /* cleanup */
g_free(trackers); g_free(trackers);
@ -301,12 +301,12 @@ static void onSourceToggled(GtkToggleButton* tb, gpointer user_data)
static void updatePiecesLabel(MakeMetaUI* ui) static void updatePiecesLabel(MakeMetaUI* ui)
{ {
tr_metainfo_builder const* builder = ui->builder; tr_metainfo_builder const* builder = ui->builder;
char const* filename = builder != NULL ? builder->top : NULL; char const* filename = builder != nullptr ? builder->top : nullptr;
GString* gstr = g_string_new(NULL); GString* gstr = g_string_new(nullptr);
g_string_append(gstr, "<i>"); g_string_append(gstr, "<i>");
if (filename == NULL) if (filename == nullptr)
{ {
g_string_append(gstr, _("No source selected")); g_string_append(gstr, _("No source selected"));
} }
@ -336,10 +336,10 @@ static void updatePiecesLabel(MakeMetaUI* ui)
static void setFilename(MakeMetaUI* ui, char const* filename) static void setFilename(MakeMetaUI* ui, char const* filename)
{ {
if (ui->builder != NULL) if (ui->builder != nullptr)
{ {
tr_metaInfoBuilderFree(ui->builder); tr_metaInfoBuilderFree(ui->builder);
ui->builder = NULL; ui->builder = nullptr;
} }
if (filename) if (filename)
@ -366,13 +366,13 @@ static void onSourceToggled2(GtkToggleButton* tb, GtkWidget* chooser, MakeMetaUI
{ {
if (gtk_toggle_button_get_active(tb)) if (gtk_toggle_button_get_active(tb))
{ {
if (g_object_get_data(G_OBJECT(chooser), FILE_CHOSEN_KEY) != NULL) if (g_object_get_data(G_OBJECT(chooser), FILE_CHOSEN_KEY) != nullptr)
{ {
onChooserChosen(GTK_FILE_CHOOSER(chooser), ui); onChooserChosen(GTK_FILE_CHOOSER(chooser), ui);
} }
else else
{ {
setFilename(ui, NULL); setFilename(ui, nullptr);
} }
} }
} }
@ -413,10 +413,10 @@ static void on_drag_data_received(
auto* ui = static_cast<MakeMetaUI*>(user_data); auto* ui = static_cast<MakeMetaUI*>(user_data);
char** uris = gtk_selection_data_get_uris(selection_data); char** uris = gtk_selection_data_get_uris(selection_data);
if (uris != NULL && uris[0] != NULL) if (uris != nullptr && uris[0] != nullptr)
{ {
char const* uri = uris[0]; char const* uri = uris[0];
gchar* filename = g_filename_from_uri(uri, NULL, NULL); gchar* filename = g_filename_from_uri(uri, nullptr, nullptr);
if (g_file_test(filename, G_FILE_TEST_IS_DIR)) if (g_file_test(filename, G_FILE_TEST_IS_DIR))
{ {
@ -462,7 +462,7 @@ GtkWidget* gtr_torrent_creation_dialog_new(GtkWindow* parent, TrCore* core)
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
TR_ARG_TUPLE(_("_Close"), GTK_RESPONSE_CLOSE), TR_ARG_TUPLE(_("_Close"), GTK_RESPONSE_CLOSE),
TR_ARG_TUPLE(_("_New"), GTK_RESPONSE_ACCEPT), TR_ARG_TUPLE(_("_New"), GTK_RESPONSE_ACCEPT),
NULL); nullptr);
ui->dialog = d; ui->dialog = d;
g_signal_connect(d, "response", G_CALLBACK(onResponse), ui); g_signal_connect(d, "response", G_CALLBACK(onResponse), ui);
g_object_set_data_full(G_OBJECT(d), "ui", ui, freeMetaUI); g_object_set_data_full(G_OBJECT(d), "ui", ui, freeMetaUI);
@ -472,62 +472,62 @@ GtkWidget* gtr_torrent_creation_dialog_new(GtkWindow* parent, TrCore* core)
hig_workarea_add_section_title(t, &row, _("Files")); hig_workarea_add_section_title(t, &row, _("Files"));
str = _("Sa_ve to:"); str = _("Sa_ve to:");
w = gtk_file_chooser_button_new(NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); w = gtk_file_chooser_button_new(nullptr, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(w), getDefaultSavePath()); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(w), getDefaultSavePath());
ui->destination_chooser = w; ui->destination_chooser = w;
hig_workarea_add_row(t, &row, str, w, NULL); hig_workarea_add_row(t, &row, str, w, nullptr);
l = gtk_radio_button_new_with_mnemonic(NULL, _("Source F_older:")); l = gtk_radio_button_new_with_mnemonic(nullptr, _("Source F_older:"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(l), FALSE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(l), FALSE);
w = gtk_file_chooser_button_new(NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); w = gtk_file_chooser_button_new(nullptr, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
g_signal_connect(l, "toggled", G_CALLBACK(onFolderToggled), ui); g_signal_connect(l, "toggled", G_CALLBACK(onFolderToggled), ui);
g_signal_connect(l, "toggled", G_CALLBACK(onSourceToggled), w); g_signal_connect(l, "toggled", G_CALLBACK(onSourceToggled), w);
g_signal_connect(w, "selection-changed", G_CALLBACK(onChooserChosen), ui); g_signal_connect(w, "selection-changed", G_CALLBACK(onChooserChosen), ui);
ui->folder_radio = l; ui->folder_radio = l;
ui->folder_chooser = w; ui->folder_chooser = w;
gtk_widget_set_sensitive(GTK_WIDGET(w), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(w), FALSE);
hig_workarea_add_row_w(t, &row, l, w, NULL); hig_workarea_add_row_w(t, &row, l, w, nullptr);
slist = gtk_radio_button_get_group(GTK_RADIO_BUTTON(l)); slist = gtk_radio_button_get_group(GTK_RADIO_BUTTON(l));
l = gtk_radio_button_new_with_mnemonic(slist, _("Source _File:")); l = gtk_radio_button_new_with_mnemonic(slist, _("Source _File:"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(l), TRUE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(l), TRUE);
w = gtk_file_chooser_button_new(NULL, GTK_FILE_CHOOSER_ACTION_OPEN); w = gtk_file_chooser_button_new(nullptr, GTK_FILE_CHOOSER_ACTION_OPEN);
g_signal_connect(l, "toggled", G_CALLBACK(onFileToggled), ui); g_signal_connect(l, "toggled", G_CALLBACK(onFileToggled), ui);
g_signal_connect(l, "toggled", G_CALLBACK(onSourceToggled), w); g_signal_connect(l, "toggled", G_CALLBACK(onSourceToggled), w);
g_signal_connect(w, "selection-changed", G_CALLBACK(onChooserChosen), ui); g_signal_connect(w, "selection-changed", G_CALLBACK(onChooserChosen), ui);
ui->file_radio = l; ui->file_radio = l;
ui->file_chooser = w; ui->file_chooser = w;
hig_workarea_add_row_w(t, &row, l, w, NULL); hig_workarea_add_row_w(t, &row, l, w, nullptr);
w = gtk_label_new(NULL); w = gtk_label_new(nullptr);
ui->pieces_lb = w; ui->pieces_lb = w;
gtk_label_set_markup(GTK_LABEL(w), _("<i>No source selected</i>")); gtk_label_set_markup(GTK_LABEL(w), _("<i>No source selected</i>"));
hig_workarea_add_row(t, &row, NULL, w, NULL); hig_workarea_add_row(t, &row, nullptr, w, nullptr);
hig_workarea_add_section_divider(t, &row); hig_workarea_add_section_divider(t, &row);
hig_workarea_add_section_title(t, &row, _("Properties")); hig_workarea_add_section_title(t, &row, _("Properties"));
str = _("_Trackers:"); str = _("_Trackers:");
v = gtk_box_new(GTK_ORIENTATION_VERTICAL, GUI_PAD_SMALL); v = gtk_box_new(GTK_ORIENTATION_VERTICAL, GUI_PAD_SMALL);
ui->announce_text_buffer = gtk_text_buffer_new(NULL); ui->announce_text_buffer = gtk_text_buffer_new(nullptr);
w = gtk_text_view_new_with_buffer(ui->announce_text_buffer); w = gtk_text_view_new_with_buffer(ui->announce_text_buffer);
gtk_widget_set_size_request(w, -1, 80); gtk_widget_set_size_request(w, -1, 80);
sw = gtk_scrolled_window_new(NULL, NULL); sw = gtk_scrolled_window_new(nullptr, nullptr);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(sw), w); gtk_container_add(GTK_CONTAINER(sw), w);
fr = gtk_frame_new(NULL); fr = gtk_frame_new(nullptr);
gtk_frame_set_shadow_type(GTK_FRAME(fr), GTK_SHADOW_IN); gtk_frame_set_shadow_type(GTK_FRAME(fr), GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(fr), sw); gtk_container_add(GTK_CONTAINER(fr), sw);
gtk_box_pack_start(GTK_BOX(v), fr, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(v), fr, TRUE, TRUE, 0);
l = gtk_label_new(NULL); l = gtk_label_new(nullptr);
gtk_label_set_markup( gtk_label_set_markup(
GTK_LABEL(l), GTK_LABEL(l),
_("To add a backup URL, add it on the line after the primary URL.\n" _("To add a backup URL, add it on the line after the primary URL.\n"
"To add another primary URL, add it after a blank line.")); "To add another primary URL, add it after a blank line."));
gtk_label_set_justify(GTK_LABEL(l), GTK_JUSTIFY_LEFT); gtk_label_set_justify(GTK_LABEL(l), GTK_JUSTIFY_LEFT);
g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_box_pack_start(GTK_BOX(v), l, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(v), l, FALSE, FALSE, 0);
hig_workarea_add_tall_row(t, &row, str, v, NULL); hig_workarea_add_tall_row(t, &row, str, v, nullptr);
l = gtk_check_button_new_with_mnemonic(_("Co_mment:")); l = gtk_check_button_new_with_mnemonic(_("Co_mment:"));
ui->comment_check = l; ui->comment_check = l;
@ -536,14 +536,14 @@ GtkWidget* gtr_torrent_creation_dialog_new(GtkWindow* parent, TrCore* core)
ui->comment_entry = w; ui->comment_entry = w;
gtk_widget_set_sensitive(GTK_WIDGET(w), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(w), FALSE);
g_signal_connect(l, "toggled", G_CALLBACK(onSourceToggled), w); g_signal_connect(l, "toggled", G_CALLBACK(onSourceToggled), w);
hig_workarea_add_row_w(t, &row, l, w, NULL); hig_workarea_add_row_w(t, &row, l, w, nullptr);
w = hig_workarea_add_wide_checkbutton(t, &row, _("_Private torrent"), FALSE); w = hig_workarea_add_wide_checkbutton(t, &row, _("_Private torrent"), FALSE);
ui->private_check = w; ui->private_check = w;
gtr_dialog_set_content(GTK_DIALOG(d), t); gtr_dialog_set_content(GTK_DIALOG(d), t);
gtk_drag_dest_set(d, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY); gtk_drag_dest_set(d, GTK_DEST_DEFAULT_ALL, nullptr, 0, GDK_ACTION_COPY);
gtk_drag_dest_add_uri_targets(d); gtk_drag_dest_add_uri_targets(d);
g_signal_connect(d, "drag-data-received", G_CALLBACK(on_drag_data_received), ui); g_signal_connect(d, "drag-data-received", G_CALLBACK(on_drag_data_received), ui);

View File

@ -44,8 +44,8 @@ struct MsgData
guint refresh_tag; guint refresh_tag;
}; };
static struct tr_log_message* myTail = NULL; static struct tr_log_message* myTail = nullptr;
static struct tr_log_message* myHead = NULL; static struct tr_log_message* myHead = nullptr;
/**** /****
***** *****
@ -56,7 +56,7 @@ static gboolean is_pinned_to_new(struct MsgData* data)
{ {
gboolean pinned_to_new = FALSE; gboolean pinned_to_new = FALSE;
if (data->view == NULL) if (data->view == nullptr)
{ {
pinned_to_new = TRUE; pinned_to_new = TRUE;
} }
@ -64,12 +64,12 @@ static gboolean is_pinned_to_new(struct MsgData* data)
{ {
GtkTreePath* last_visible; GtkTreePath* last_visible;
if (gtk_tree_view_get_visible_range(data->view, NULL, &last_visible)) if (gtk_tree_view_get_visible_range(data->view, nullptr, &last_visible))
{ {
GtkTreeIter iter; GtkTreeIter iter;
int const row_count = gtk_tree_model_iter_n_children(data->sort, NULL); int const row_count = gtk_tree_model_iter_n_children(data->sort, nullptr);
if (gtk_tree_model_iter_nth_child(data->sort, &iter, NULL, row_count - 1)) if (gtk_tree_model_iter_nth_child(data->sort, &iter, nullptr, row_count - 1))
{ {
GtkTreePath* last_row = gtk_tree_model_get_path(data->sort, &iter); GtkTreePath* last_row = gtk_tree_model_get_path(data->sort, &iter);
pinned_to_new = !gtk_tree_path_compare(last_visible, last_row); pinned_to_new = !gtk_tree_path_compare(last_visible, last_row);
@ -85,15 +85,15 @@ static gboolean is_pinned_to_new(struct MsgData* data)
static void scroll_to_bottom(struct MsgData* data) static void scroll_to_bottom(struct MsgData* data)
{ {
if (data->sort != NULL) if (data->sort != nullptr)
{ {
GtkTreeIter iter; GtkTreeIter iter;
int const row_count = gtk_tree_model_iter_n_children(data->sort, NULL); int const row_count = gtk_tree_model_iter_n_children(data->sort, nullptr);
if (gtk_tree_model_iter_nth_child(data->sort, &iter, NULL, row_count - 1)) if (gtk_tree_model_iter_nth_child(data->sort, &iter, nullptr, row_count - 1))
{ {
GtkTreePath* last_row = gtk_tree_model_get_path(data->sort, &iter); GtkTreePath* last_row = gtk_tree_model_get_path(data->sort, &iter);
gtk_tree_view_scroll_to_cell(data->view, last_row, NULL, TRUE, 1, 0); gtk_tree_view_scroll_to_cell(data->view, last_row, nullptr, TRUE, 1, 0);
gtk_tree_path_free(last_row); gtk_tree_path_free(last_row);
} }
} }
@ -133,7 +133,7 @@ static void doSave(GtkWindow* parent, struct MsgData* data, char const* filename
{ {
FILE* fp = fopen(filename, "w+"); FILE* fp = fopen(filename, "w+");
if (fp == NULL) if (fp == nullptr)
{ {
GtkWidget* GtkWidget*
w = gtk_message_dialog_new(parent, {}, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Couldn't save \"%s\""), filename); w = gtk_message_dialog_new(parent, {}, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Couldn't save \"%s\""), filename);
@ -146,7 +146,7 @@ static void doSave(GtkWindow* parent, struct MsgData* data, char const* filename
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel* model = GTK_TREE_MODEL(data->sort); GtkTreeModel* model = GTK_TREE_MODEL(data->sort);
if (gtk_tree_model_iter_children(model, &iter, NULL)) if (gtk_tree_model_iter_children(model, &iter, nullptr))
{ {
do do
{ {
@ -176,8 +176,8 @@ static void doSave(GtkWindow* parent, struct MsgData* data, char const* filename
"%s\t%s\t%s\t%s\n", "%s\t%s\t%s\t%s\n",
date, date,
levelStr, levelStr,
node->name != NULL ? node->name : "", node->name != nullptr ? node->name : "",
node->message != NULL ? node->message : ""); node->message != nullptr ? node->message : "");
g_free(date); g_free(date);
} while (gtk_tree_model_iter_next(model, &iter)); } while (gtk_tree_model_iter_next(model, &iter));
} }
@ -207,7 +207,7 @@ static void onSaveRequest(GtkWidget* w, gpointer data)
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_SAVE,
TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL), TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL),
TR_ARG_TUPLE(_("_Save"), GTK_RESPONSE_ACCEPT), TR_ARG_TUPLE(_("_Save"), GTK_RESPONSE_ACCEPT),
NULL); nullptr);
g_signal_connect(d, "response", G_CALLBACK(onSaveDialogResponse), data); g_signal_connect(d, "response", G_CALLBACK(onSaveDialogResponse), data);
gtk_widget_show(d); gtk_widget_show(d);
@ -221,7 +221,7 @@ static void onClearRequest(GtkWidget* w, gpointer gdata)
gtk_list_store_clear(data->store); gtk_list_store_clear(data->store);
tr_logFreeQueue(myHead); tr_logFreeQueue(myHead);
myHead = myTail = NULL; myHead = myTail = nullptr;
} }
static void onPauseToggled(GtkToggleToolButton* w, gpointer gdata) static void onPauseToggled(GtkToggleToolButton* w, gpointer gdata)
@ -260,11 +260,19 @@ static void renderText(
TR_UNUSED(column); TR_UNUSED(column);
int const col = GPOINTER_TO_INT(gcol); int const col = GPOINTER_TO_INT(gcol);
char* str = NULL; char* str = nullptr;
struct tr_log_message const* node; struct tr_log_message const* node;
gtk_tree_model_get(tree_model, iter, col, &str, COL_TR_MSG, &node, -1); gtk_tree_model_get(tree_model, iter, col, &str, COL_TR_MSG, &node, -1);
g_object_set(renderer, "text", str, "foreground", getForegroundColor(node->level), "ellipsize", PANGO_ELLIPSIZE_END, NULL); g_object_set(
renderer,
"text",
str,
"foreground",
getForegroundColor(node->level),
"ellipsize",
PANGO_ELLIPSIZE_END,
nullptr);
} }
static void renderTime( static void renderTime(
@ -281,7 +289,7 @@ static void renderTime(
gtk_tree_model_get(tree_model, iter, COL_TR_MSG, &node, -1); gtk_tree_model_get(tree_model, iter, COL_TR_MSG, &node, -1);
GDateTime* date_time = g_date_time_new_from_unix_local(node->when); GDateTime* date_time = g_date_time_new_from_unix_local(node->when);
gchar* buf = g_date_time_format(date_time, "%T"); gchar* buf = g_date_time_format(date_time, "%T");
g_object_set(renderer, "text", buf, "foreground", getForegroundColor(node->level), NULL); g_object_set(renderer, "text", buf, "foreground", getForegroundColor(node->level), nullptr);
g_free(buf); g_free(buf);
g_date_time_unref(date_time); g_date_time_unref(date_time);
} }
@ -290,7 +298,7 @@ static void appendColumn(GtkTreeView* view, int col)
{ {
GtkCellRenderer* r; GtkCellRenderer* r;
GtkTreeViewColumn* c; GtkTreeViewColumn* c;
char const* title = NULL; char const* title = nullptr;
switch (col) switch (col)
{ {
@ -316,8 +324,8 @@ static void appendColumn(GtkTreeView* view, int col)
{ {
case COL_NAME: case COL_NAME:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
c = gtk_tree_view_column_new_with_attributes(title, r, NULL); c = gtk_tree_view_column_new_with_attributes(title, r, nullptr);
gtk_tree_view_column_set_cell_data_func(c, r, renderText, GINT_TO_POINTER(col), NULL); gtk_tree_view_column_set_cell_data_func(c, r, renderText, GINT_TO_POINTER(col), nullptr);
gtk_tree_view_column_set_sizing(c, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_column_set_sizing(c, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_fixed_width(c, 200); gtk_tree_view_column_set_fixed_width(c, 200);
gtk_tree_view_column_set_resizable(c, TRUE); gtk_tree_view_column_set_resizable(c, TRUE);
@ -325,8 +333,8 @@ static void appendColumn(GtkTreeView* view, int col)
case COL_MESSAGE: case COL_MESSAGE:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
c = gtk_tree_view_column_new_with_attributes(title, r, NULL); c = gtk_tree_view_column_new_with_attributes(title, r, nullptr);
gtk_tree_view_column_set_cell_data_func(c, r, renderText, GINT_TO_POINTER(col), NULL); gtk_tree_view_column_set_cell_data_func(c, r, renderText, GINT_TO_POINTER(col), nullptr);
gtk_tree_view_column_set_sizing(c, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_column_set_sizing(c, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_fixed_width(c, 500); gtk_tree_view_column_set_fixed_width(c, 500);
gtk_tree_view_column_set_resizable(c, TRUE); gtk_tree_view_column_set_resizable(c, TRUE);
@ -334,8 +342,8 @@ static void appendColumn(GtkTreeView* view, int col)
case COL_SEQUENCE: case COL_SEQUENCE:
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
c = gtk_tree_view_column_new_with_attributes(title, r, NULL); c = gtk_tree_view_column_new_with_attributes(title, r, nullptr);
gtk_tree_view_column_set_cell_data_func(c, r, renderTime, NULL, NULL); gtk_tree_view_column_set_cell_data_func(c, r, renderTime, nullptr, nullptr);
gtk_tree_view_column_set_resizable(c, TRUE); gtk_tree_view_column_set_resizable(c, TRUE);
break; break;
@ -374,13 +382,13 @@ static tr_log_message* addMessages(GtkListStore* store, struct tr_log_message* h
static unsigned int sequence = 0; static unsigned int sequence = 0;
char const* default_name = g_get_application_name(); char const* default_name = g_get_application_name();
for (i = head; i != NULL && i->next != NULL; i = i->next) for (i = head; i != nullptr && i->next != nullptr; i = i->next)
{ {
char const* name = i->name != NULL ? i->name : default_name; char const* name = i->name != nullptr ? i->name : default_name;
gtk_list_store_insert_with_values( gtk_list_store_insert_with_values(
store, store,
NULL, nullptr,
0, 0,
TR_ARG_TUPLE(COL_TR_MSG, i), TR_ARG_TUPLE(COL_TR_MSG, i),
TR_ARG_TUPLE(COL_NAME, name), TR_ARG_TUPLE(COL_NAME, name),
@ -394,7 +402,7 @@ static tr_log_message* addMessages(GtkListStore* store, struct tr_log_message* h
GString* gstr = g_string_sized_new(512); GString* gstr = g_string_sized_new(512);
g_string_append_printf(gstr, "%s:%d %s", i->file, i->line, i->message); g_string_append_printf(gstr, "%s:%d %s", i->file, i->line, i->message);
if (i->name != NULL) if (i->name != nullptr)
{ {
g_string_append_printf(gstr, " (%s)", i->name); g_string_append_printf(gstr, " (%s)", i->name);
} }
@ -416,13 +424,13 @@ static gboolean onRefresh(gpointer gdata)
{ {
tr_log_message* msgs = tr_logGetQueue(); tr_log_message* msgs = tr_logGetQueue();
if (msgs != NULL) if (msgs != nullptr)
{ {
/* add the new messages and append them to the end of /* add the new messages and append them to the end of
* our persistent list */ * our persistent list */
tr_log_message* tail = addMessages(data->store, msgs); tr_log_message* tail = addMessages(data->store, msgs);
if (myTail != NULL) if (myTail != nullptr)
{ {
myTail->next = msgs; myTail->next = msgs;
} }
@ -449,7 +457,7 @@ static GtkWidget* debug_level_combo_new(void)
TR_ARG_TUPLE(_("Error"), TR_LOG_ERROR), TR_ARG_TUPLE(_("Error"), TR_LOG_ERROR),
TR_ARG_TUPLE(_("Information"), TR_LOG_INFO), TR_ARG_TUPLE(_("Information"), TR_LOG_INFO),
TR_ARG_TUPLE(_("Debug"), TR_LOG_DEBUG), TR_ARG_TUPLE(_("Debug"), TR_LOG_DEBUG),
NULL); nullptr);
gtr_combo_box_set_active_enum(GTK_COMBO_BOX(w), gtr_pref_int_get(TR_KEY_message_level)); gtr_combo_box_set_active_enum(GTK_COMBO_BOX(w), gtr_pref_int_get(TR_KEY_message_level));
return w; return w;
} }
@ -486,25 +494,25 @@ GtkWidget* gtr_message_log_window_new(GtkWindow* parent, TrCore* core)
gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH_HORIZ); gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH_HORIZ);
gtk_style_context_add_class(gtk_widget_get_style_context(toolbar), GTK_STYLE_CLASS_PRIMARY_TOOLBAR); gtk_style_context_add_class(gtk_widget_get_style_context(toolbar), GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
item = gtk_tool_button_new(NULL, NULL); item = gtk_tool_button_new(nullptr, nullptr);
g_object_set( g_object_set(
item, item,
TR_ARG_TUPLE("icon-name", "document-save-as"), TR_ARG_TUPLE("icon-name", "document-save-as"),
TR_ARG_TUPLE("is-important", TRUE), TR_ARG_TUPLE("is-important", TRUE),
TR_ARG_TUPLE("label", _("Save _As")), TR_ARG_TUPLE("label", _("Save _As")),
TR_ARG_TUPLE("use-underline", TRUE), TR_ARG_TUPLE("use-underline", TRUE),
NULL); nullptr);
g_signal_connect(item, "clicked", G_CALLBACK(onSaveRequest), data); g_signal_connect(item, "clicked", G_CALLBACK(onSaveRequest), data);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
item = gtk_tool_button_new(NULL, NULL); item = gtk_tool_button_new(nullptr, nullptr);
g_object_set( g_object_set(
item, item,
TR_ARG_TUPLE("icon-name", "edit-clear"), TR_ARG_TUPLE("icon-name", "edit-clear"),
TR_ARG_TUPLE("is-important", TRUE), TR_ARG_TUPLE("is-important", TRUE),
TR_ARG_TUPLE("label", _("Clear")), TR_ARG_TUPLE("label", _("Clear")),
TR_ARG_TUPLE("use-underline", TRUE), TR_ARG_TUPLE("use-underline", TRUE),
NULL); nullptr);
g_signal_connect(item, "clicked", G_CALLBACK(onClearRequest), data); g_signal_connect(item, "clicked", G_CALLBACK(onClearRequest), data);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
@ -518,7 +526,7 @@ GtkWidget* gtr_message_log_window_new(GtkWindow* parent, TrCore* core)
TR_ARG_TUPLE("is-important", TRUE), TR_ARG_TUPLE("is-important", TRUE),
TR_ARG_TUPLE("label", _("P_ause")), TR_ARG_TUPLE("label", _("P_ause")),
TR_ARG_TUPLE("use-underline", TRUE), TR_ARG_TUPLE("use-underline", TRUE),
NULL); nullptr);
g_signal_connect(item, "toggled", G_CALLBACK(onPauseToggled), data); g_signal_connect(item, "toggled", G_CALLBACK(onPauseToggled), data);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
@ -526,7 +534,7 @@ GtkWidget* gtr_message_log_window_new(GtkWindow* parent, TrCore* core)
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
w = gtk_label_new(_("Level")); w = gtk_label_new(_("Level"));
g_object_set(w, "margin", GUI_PAD, NULL); g_object_set(w, "margin", GUI_PAD, nullptr);
item = gtk_tool_item_new(); item = gtk_tool_item_new();
gtk_container_add(GTK_CONTAINER(item), w); gtk_container_add(GTK_CONTAINER(item), w);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
@ -553,21 +561,21 @@ GtkWidget* gtr_message_log_window_new(GtkWindow* parent, TrCore* core)
addMessages(data->store, myHead); addMessages(data->store, myHead);
onRefresh(data); /* much faster to populate *before* it has listeners */ onRefresh(data); /* much faster to populate *before* it has listeners */
data->filter = gtk_tree_model_filter_new(GTK_TREE_MODEL(data->store), NULL); data->filter = gtk_tree_model_filter_new(GTK_TREE_MODEL(data->store), nullptr);
data->sort = gtk_tree_model_sort_new_with_model(data->filter); data->sort = gtk_tree_model_sort_new_with_model(data->filter);
g_object_unref(data->filter); g_object_unref(data->filter);
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(data->sort), COL_SEQUENCE, GTK_SORT_ASCENDING); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(data->sort), COL_SEQUENCE, GTK_SORT_ASCENDING);
data->maxLevel = static_cast<tr_log_level>(gtr_pref_int_get(TR_KEY_message_level)); data->maxLevel = static_cast<tr_log_level>(gtr_pref_int_get(TR_KEY_message_level));
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(data->filter), isRowVisible, data, NULL); gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(data->filter), isRowVisible, data, nullptr);
view = gtk_tree_view_new_with_model(data->sort); view = gtk_tree_view_new_with_model(data->sort);
g_object_unref(data->sort); g_object_unref(data->sort);
g_signal_connect(view, "button-release-event", G_CALLBACK(on_tree_view_button_released), NULL); g_signal_connect(view, "button-release-event", G_CALLBACK(on_tree_view_button_released), nullptr);
data->view = GTK_TREE_VIEW(view); data->view = GTK_TREE_VIEW(view);
appendColumn(data->view, COL_SEQUENCE); appendColumn(data->view, COL_SEQUENCE);
appendColumn(data->view, COL_NAME); appendColumn(data->view, COL_NAME);
appendColumn(data->view, COL_MESSAGE); appendColumn(data->view, COL_MESSAGE);
w = gtk_scrolled_window_new(NULL, NULL); w = gtk_scrolled_window_new(nullptr, nullptr);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(w), GTK_SHADOW_IN); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(w), GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(w), view); gtk_container_add(GTK_CONTAINER(w), view);

View File

@ -18,8 +18,8 @@
#define NOTIFICATIONS_DBUS_CORE_OBJECT "/org/freedesktop/Notifications" #define NOTIFICATIONS_DBUS_CORE_OBJECT "/org/freedesktop/Notifications"
#define NOTIFICATIONS_DBUS_CORE_INTERFACE "org.freedesktop.Notifications" #define NOTIFICATIONS_DBUS_CORE_INTERFACE "org.freedesktop.Notifications"
static GDBusProxy* proxy = NULL; static GDBusProxy* proxy = nullptr;
static GHashTable* active_notifications = NULL; static GHashTable* active_notifications = nullptr;
static gboolean server_supports_actions = FALSE; static gboolean server_supports_actions = FALSE;
typedef struct TrNotification typedef struct TrNotification
@ -32,7 +32,7 @@ static void tr_notification_free(gpointer data)
{ {
auto* n = static_cast<TrNotification*>(data); auto* n = static_cast<TrNotification*>(data);
if (n->core != NULL) if (n->core != nullptr)
{ {
g_object_unref(G_OBJECT(n->core)); g_object_unref(G_OBJECT(n->core));
} }
@ -47,11 +47,11 @@ static void get_capabilities_callback(GObject* source, GAsyncResult* res, gpoint
char** caps; char** caps;
GVariant* result; GVariant* result;
result = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, NULL); result = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, nullptr);
if (result == NULL || !g_variant_is_of_type(result, G_VARIANT_TYPE("(as)"))) if (result == nullptr || !g_variant_is_of_type(result, G_VARIANT_TYPE("(as)")))
{ {
if (result != NULL) if (result != nullptr)
{ {
g_variant_unref(result); g_variant_unref(result);
} }
@ -61,7 +61,7 @@ static void get_capabilities_callback(GObject* source, GAsyncResult* res, gpoint
g_variant_get(result, "(^a&s)", &caps); g_variant_get(result, "(^a&s)", &caps);
for (int i = 0; caps[i] != NULL; i++) for (int i = 0; caps[i] != nullptr; i++)
{ {
if (g_strcmp0(caps[i], "actions") == 0) if (g_strcmp0(caps[i], "actions") == 0)
{ {
@ -88,10 +88,10 @@ static void g_signal_callback(
g_return_if_fail(g_variant_is_of_type(params, G_VARIANT_TYPE("(u*)"))); g_return_if_fail(g_variant_is_of_type(params, G_VARIANT_TYPE("(u*)")));
guint id; guint id;
g_variant_get(params, "(u*)", &id, NULL); g_variant_get(params, "(u*)", &id, nullptr);
auto* n = static_cast<TrNotification*>(g_hash_table_lookup(active_notifications, GUINT_TO_POINTER(id))); auto* n = static_cast<TrNotification*>(g_hash_table_lookup(active_notifications, GUINT_TO_POINTER(id)));
if (n == NULL) if (n == nullptr)
{ {
return; return;
} }
@ -103,13 +103,13 @@ static void g_signal_callback(
else if (g_strcmp0(signal_name, "ActionInvoked") == 0 && g_variant_is_of_type(params, G_VARIANT_TYPE("(us)"))) else if (g_strcmp0(signal_name, "ActionInvoked") == 0 && g_variant_is_of_type(params, G_VARIANT_TYPE("(us)")))
{ {
tr_torrent const* tor = gtr_core_find_torrent(n->core, n->torrent_id); tr_torrent const* tor = gtr_core_find_torrent(n->core, n->torrent_id);
if (tor == NULL) if (tor == nullptr)
{ {
return; return;
} }
char* action = NULL; char* action = nullptr;
g_variant_get(params, "(u&s)", NULL, &action); g_variant_get(params, "(u&s)", nullptr, &action);
if (g_strcmp0(action, "folder") == 0) if (g_strcmp0(action, "folder") == 0)
{ {
@ -119,7 +119,7 @@ static void g_signal_callback(
{ {
tr_info const* inf = tr_torrentInfo(tor); tr_info const* inf = tr_torrentInfo(tor);
char const* dir = tr_torrentGetDownloadDir(tor); char const* dir = tr_torrentGetDownloadDir(tor);
char* path = g_build_filename(dir, inf->files[0].name, NULL); char* path = g_build_filename(dir, inf->files[0].name, nullptr);
gtr_open_file(path); gtr_open_file(path);
g_free(path); g_free(path);
} }
@ -131,39 +131,39 @@ static void dbus_proxy_ready_callback(GObject* source, GAsyncResult* res, gpoint
TR_UNUSED(source); TR_UNUSED(source);
TR_UNUSED(user_data); TR_UNUSED(user_data);
proxy = g_dbus_proxy_new_for_bus_finish(res, NULL); proxy = g_dbus_proxy_new_for_bus_finish(res, nullptr);
if (proxy == NULL) if (proxy == nullptr)
{ {
g_warning("Failed to create proxy for %s", NOTIFICATIONS_DBUS_NAME); g_warning("Failed to create proxy for %s", NOTIFICATIONS_DBUS_NAME);
return; return;
} }
g_signal_connect(proxy, "g-signal", G_CALLBACK(g_signal_callback), NULL); g_signal_connect(proxy, "g-signal", G_CALLBACK(g_signal_callback), nullptr);
g_dbus_proxy_call( g_dbus_proxy_call(
proxy, proxy,
"GetCapabilities", "GetCapabilities",
g_variant_new("()"), g_variant_new("()"),
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
-1, -1,
NULL, nullptr,
get_capabilities_callback, get_capabilities_callback,
NULL); nullptr);
} }
void gtr_notify_init(void) void gtr_notify_init(void)
{ {
active_notifications = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, tr_notification_free); active_notifications = g_hash_table_new_full(g_direct_hash, g_direct_equal, nullptr, tr_notification_free);
g_dbus_proxy_new_for_bus( g_dbus_proxy_new_for_bus(
G_BUS_TYPE_SESSION, G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
NULL, nullptr,
NOTIFICATIONS_DBUS_NAME, NOTIFICATIONS_DBUS_NAME,
NOTIFICATIONS_DBUS_CORE_OBJECT, NOTIFICATIONS_DBUS_CORE_OBJECT,
NOTIFICATIONS_DBUS_CORE_INTERFACE, NOTIFICATIONS_DBUS_CORE_INTERFACE,
NULL, nullptr,
dbus_proxy_ready_callback, dbus_proxy_ready_callback,
NULL); nullptr);
} }
static void notify_callback(GObject* source, GAsyncResult* res, gpointer user_data) static void notify_callback(GObject* source, GAsyncResult* res, gpointer user_data)
@ -171,11 +171,11 @@ static void notify_callback(GObject* source, GAsyncResult* res, gpointer user_da
GVariant* result; GVariant* result;
auto* n = static_cast<TrNotification*>(user_data); auto* n = static_cast<TrNotification*>(user_data);
result = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, NULL); result = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, nullptr);
if (result == NULL || !g_variant_is_of_type(result, G_VARIANT_TYPE("(u)"))) if (result == nullptr || !g_variant_is_of_type(result, G_VARIANT_TYPE("(u)")))
{ {
if (result != NULL) if (result != nullptr)
{ {
g_variant_unref(result); g_variant_unref(result);
} }
@ -197,14 +197,14 @@ void gtr_notify_torrent_completed(TrCore* core, int torrent_id)
{ {
char** argv = gtr_pref_strv_get(TR_KEY_torrent_complete_sound_command); char** argv = gtr_pref_strv_get(TR_KEY_torrent_complete_sound_command);
g_spawn_async( g_spawn_async(
NULL /*cwd*/, nullptr /*cwd*/,
argv, argv,
NULL /*envp*/, nullptr /*envp*/,
G_SPAWN_SEARCH_PATH, G_SPAWN_SEARCH_PATH,
NULL /*GSpawnChildSetupFunc*/, nullptr /*GSpawnChildSetupFunc*/,
NULL /*user_data*/, nullptr /*user_data*/,
NULL /*child_pid*/, nullptr /*child_pid*/,
NULL); nullptr);
g_strfreev(argv); g_strfreev(argv);
} }
@ -259,7 +259,7 @@ void gtr_notify_torrent_completed(TrCore* core, int torrent_id)
-1), -1),
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
-1, -1,
NULL, nullptr,
notify_callback, notify_callback,
n); n);
} }
@ -279,10 +279,10 @@ void gtr_notify_torrent_added(char const* name)
g_dbus_proxy_call( g_dbus_proxy_call(
proxy, proxy,
"Notify", "Notify",
g_variant_new("(susssasa{sv}i)", "Transmission", 0, "transmission", _("Torrent Added"), name, NULL, NULL, -1), g_variant_new("(susssasa{sv}i)", "Transmission", 0, "transmission", _("Torrent Added"), name, nullptr, nullptr, -1),
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
-1, -1,
NULL, nullptr,
notify_callback, notify_callback,
n); n);
} }

View File

@ -29,7 +29,7 @@
static GSList* get_recent_destinations(void) static GSList* get_recent_destinations(void)
{ {
GSList* list = NULL; GSList* list = nullptr;
for (int i = 0; i < N_RECENT; ++i) for (int i = 0; i < N_RECENT; ++i)
{ {
@ -37,7 +37,7 @@ static GSList* get_recent_destinations(void)
char const* val; char const* val;
g_snprintf(key, sizeof(key), "recent-download-dir-%d", i + 1); g_snprintf(key, sizeof(key), "recent-download-dir-%d", i + 1);
if ((val = gtr_pref_string_get(tr_quark_new(key, TR_BAD_SIZE))) != NULL) if ((val = gtr_pref_string_get(tr_quark_new(key, TR_BAD_SIZE))) != nullptr)
{ {
list = g_slist_append(list, (void*)val); list = g_slist_append(list, (void*)val);
} }
@ -52,13 +52,13 @@ static void save_recent_destination(TrCore* core, char const* dir)
GSList* l; GSList* l;
GSList* list = get_recent_destinations(); GSList* list = get_recent_destinations();
if (dir == NULL) if (dir == nullptr)
{ {
return; return;
} }
/* if it was already in the list, remove it */ /* if it was already in the list, remove it */
if ((l = g_slist_find_custom(list, dir, (GCompareFunc)g_strcmp0)) != NULL) if ((l = g_slist_find_custom(list, dir, (GCompareFunc)g_strcmp0)) != nullptr)
{ {
list = g_slist_delete_link(list, l); list = g_slist_delete_link(list, l);
} }
@ -68,13 +68,13 @@ static void save_recent_destination(TrCore* core, char const* dir)
/* make local copies of the strings that aren't /* make local copies of the strings that aren't
* invalidated by gtr_pref_string_set() */ * invalidated by gtr_pref_string_set() */
for (l = list; l != NULL; l = l->next) for (l = list; l != nullptr; l = l->next)
{ {
l->data = g_strdup(static_cast<char const*>(l->data)); l->data = g_strdup(static_cast<char const*>(l->data));
} }
/* save the first N_RECENT directories */ /* save the first N_RECENT directories */
for (l = list, i = 0; l != NULL && i < N_RECENT; ++i, l = l->next) for (l = list, i = 0; l != nullptr && i < N_RECENT; ++i, l = l->next)
{ {
char key[64]; char key[64];
g_snprintf(key, sizeof(key), "recent-download-dir-%d", i + 1); g_snprintf(key, sizeof(key), "recent-download-dir-%d", i + 1);
@ -84,7 +84,7 @@ static void save_recent_destination(TrCore* core, char const* dir)
gtr_pref_save(gtr_core_session(core)); gtr_pref_save(gtr_core_session(core));
/* cleanup */ /* cleanup */
g_slist_foreach(list, (GFunc)(GCallback)g_free, NULL); g_slist_foreach(list, (GFunc)(GCallback)g_free, nullptr);
g_slist_free(list); g_slist_free(list);
} }
@ -108,11 +108,11 @@ struct OpenData
static void removeOldTorrent(struct OpenData* o) static void removeOldTorrent(struct OpenData* o)
{ {
if (o->tor != NULL) if (o->tor != nullptr)
{ {
gtr_file_list_clear(o->file_list); gtr_file_list_clear(o->file_list);
tr_torrentRemove(o->tor, FALSE, NULL); tr_torrentRemove(o->tor, FALSE, nullptr);
o->tor = NULL; o->tor = nullptr;
} }
} }
@ -120,7 +120,7 @@ static void addResponseCB(GtkDialog* dialog, gint response, gpointer gdata)
{ {
auto* o = static_cast<OpenData*>(gdata); auto* o = static_cast<OpenData*>(gdata);
if (o->tor != NULL) if (o->tor != nullptr)
{ {
if (response != GTK_RESPONSE_ACCEPT) if (response != GTK_RESPONSE_ACCEPT)
{ {
@ -139,7 +139,7 @@ static void addResponseCB(GtkDialog* dialog, gint response, gpointer gdata)
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(o->trash_check))) if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(o->trash_check)))
{ {
gtr_file_trash_or_remove(o->filename, NULL); gtr_file_trash_or_remove(o->filename, nullptr);
} }
save_recent_destination(o->core, o->downloadDir); save_recent_destination(o->core, o->downloadDir);
@ -155,10 +155,10 @@ static void addResponseCB(GtkDialog* dialog, gint response, gpointer gdata)
static void updateTorrent(struct OpenData* o) static void updateTorrent(struct OpenData* o)
{ {
gboolean const isLocalFile = tr_ctorGetSourceFile(o->ctor) != NULL; gboolean const isLocalFile = tr_ctorGetSourceFile(o->ctor) != nullptr;
gtk_widget_set_sensitive(o->trash_check, isLocalFile); gtk_widget_set_sensitive(o->trash_check, isLocalFile);
if (o->tor == NULL) if (o->tor == nullptr)
{ {
gtr_file_list_clear(o->file_list); gtr_file_list_clear(o->file_list);
gtk_widget_set_sensitive(o->file_list, FALSE); gtk_widget_set_sensitive(o->file_list, FALSE);
@ -168,14 +168,14 @@ static void updateTorrent(struct OpenData* o)
tr_torrentSetDownloadDir(o->tor, o->downloadDir); tr_torrentSetDownloadDir(o->tor, o->downloadDir);
gtk_widget_set_sensitive(o->file_list, tr_torrentHasMetadata(o->tor)); gtk_widget_set_sensitive(o->file_list, tr_torrentHasMetadata(o->tor));
gtr_file_list_set_torrent(o->file_list, tr_torrentId(o->tor)); gtr_file_list_set_torrent(o->file_list, tr_torrentId(o->tor));
tr_torrentVerify(o->tor, NULL, NULL); tr_torrentVerify(o->tor, nullptr, nullptr);
} }
} }
/** /**
* When the source .torrent file is deleted * When the source .torrent file is deleted
* (such as, if it was a temp file that a web browser passed to us), * (such as, if it was a temp file that a web browser passed to us),
* gtk invokes this callback and `filename' will be NULL. * gtk invokes this callback and `filename' will be nullptr.
* The `filename' tests here are to prevent us from losing the current * The `filename' tests here are to prevent us from losing the current
* metadata when that happens. * metadata when that happens.
*/ */
@ -185,14 +185,14 @@ static void sourceChanged(GtkFileChooserButton* b, gpointer gdata)
char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(b)); char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(b));
/* maybe instantiate a torrent */ /* maybe instantiate a torrent */
if (filename != NULL || o->tor == NULL) if (filename != nullptr || o->tor == nullptr)
{ {
int err = 0; int err = 0;
bool new_file = false; bool new_file = false;
int duplicate_id = 0; int duplicate_id = 0;
tr_torrent* torrent; tr_torrent* torrent;
if (filename != NULL && (o->filename == NULL || !tr_sys_path_is_same(filename, o->filename, NULL))) if (filename != nullptr && (o->filename == nullptr || !tr_sys_path_is_same(filename, o->filename, nullptr)))
{ {
g_free(o->filename); g_free(o->filename);
o->filename = g_strdup(filename); o->filename = g_strdup(filename);
@ -204,7 +204,7 @@ static void sourceChanged(GtkFileChooserButton* b, gpointer gdata)
tr_ctorSetPaused(o->ctor, TR_FORCE, TRUE); tr_ctorSetPaused(o->ctor, TR_FORCE, TRUE);
tr_ctorSetDeleteSource(o->ctor, FALSE); tr_ctorSetDeleteSource(o->ctor, FALSE);
if ((torrent = tr_torrentNew(o->ctor, &err, &duplicate_id)) != NULL) if ((torrent = tr_torrentNew(o->ctor, &err, &duplicate_id)) != nullptr)
{ {
removeOldTorrent(o); removeOldTorrent(o);
o->tor = torrent; o->tor = torrent;
@ -219,7 +219,7 @@ static void sourceChanged(GtkFileChooserButton* b, gpointer gdata)
} }
else else
{ {
tor = NULL; tor = nullptr;
} }
gtr_add_torrent_error_dialog(GTK_WIDGET(b), err, tor, o->filename); gtr_add_torrent_error_dialog(GTK_WIDGET(b), err, tor, o->filename);
@ -236,7 +236,7 @@ static void downloadDirChanged(GtkFileChooserButton* b, gpointer gdata)
auto* data = static_cast<OpenData*>(gdata); auto* data = static_cast<OpenData*>(gdata);
char* fname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(b)); char* fname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(b));
if (fname != NULL && (data->downloadDir == NULL || !tr_sys_path_is_same(fname, data->downloadDir, NULL))) if (fname != nullptr && (data->downloadDir == nullptr || !tr_sys_path_is_same(fname, data->downloadDir, nullptr)))
{ {
g_free(data->downloadDir); g_free(data->downloadDir);
data->downloadDir = g_strdup(fname); data->downloadDir = g_strdup(fname);
@ -287,7 +287,7 @@ GtkWidget* gtr_torrent_options_dialog_new(GtkWindow* parent, TrCore* core, tr_ct
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL), TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL),
TR_ARG_TUPLE(_("_Open"), GTK_RESPONSE_ACCEPT), TR_ARG_TUPLE(_("_Open"), GTK_RESPONSE_ACCEPT),
NULL); nullptr);
gtk_dialog_set_default_response(GTK_DIALOG(d), GTK_RESPONSE_ACCEPT); gtk_dialog_set_default_response(GTK_DIALOG(d), GTK_RESPONSE_ACCEPT);
if (!tr_ctorGetDownloadDir(ctor, TR_FORCE, &str)) if (!tr_ctorGetDownloadDir(ctor, TR_FORCE, &str))
@ -321,7 +321,7 @@ GtkWidget* gtr_torrent_options_dialog_new(GtkWindow* parent, TrCore* core, tr_ct
/* "torrent file" row */ /* "torrent file" row */
l = gtk_label_new_with_mnemonic(_("_Torrent file:")); l = gtk_label_new_with_mnemonic(_("_Torrent file:"));
g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_grid_attach(grid, l, 0, row, 1, 1); gtk_grid_attach(grid, l, 0, row, 1, 1);
w = gtk_file_chooser_button_new(_("Select Source File"), GTK_FILE_CHOOSER_ACTION_OPEN); w = gtk_file_chooser_button_new(_("Select Source File"), GTK_FILE_CHOOSER_ACTION_OPEN);
source_chooser = w; source_chooser = w;
@ -334,7 +334,7 @@ GtkWidget* gtr_torrent_options_dialog_new(GtkWindow* parent, TrCore* core, tr_ct
/* "destination folder" row */ /* "destination folder" row */
row++; row++;
l = gtk_label_new_with_mnemonic(_("_Destination folder:")); l = gtk_label_new_with_mnemonic(_("_Destination folder:"));
g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_grid_attach(grid, l, 0, row, 1, 1); gtk_grid_attach(grid, l, 0, row, 1, 1);
w = gtk_file_chooser_button_new(_("Select Destination Folder"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); w = gtk_file_chooser_button_new(_("Select Destination Folder"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
@ -345,9 +345,9 @@ GtkWidget* gtr_torrent_options_dialog_new(GtkWindow* parent, TrCore* core, tr_ct
list = get_recent_destinations(); list = get_recent_destinations();
for (GSList* walk = list; walk != NULL; walk = walk->next) for (GSList* walk = list; walk != nullptr; walk = walk->next)
{ {
gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(w), static_cast<char const*>(walk->data), NULL); gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(w), static_cast<char const*>(walk->data), nullptr);
} }
g_slist_free(list); g_slist_free(list);
@ -358,7 +358,7 @@ GtkWidget* gtr_torrent_options_dialog_new(GtkWindow* parent, TrCore* core, tr_ct
row++; row++;
l = data->freespace_label = gtr_freespace_label_new(core, data->downloadDir); l = data->freespace_label = gtr_freespace_label_new(core, data->downloadDir);
gtk_widget_set_margin_bottom(l, GUI_PAD_BIG); gtk_widget_set_margin_bottom(l, GUI_PAD_BIG);
g_object_set(l, "halign", GTK_ALIGN_END, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(l, "halign", GTK_ALIGN_END, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_grid_attach(grid, l, 0, row, 2, 1); gtk_grid_attach(grid, l, 0, row, 2, 1);
/* file list row */ /* file list row */
@ -371,7 +371,7 @@ GtkWidget* gtr_torrent_options_dialog_new(GtkWindow* parent, TrCore* core, tr_ct
/* torrent priority row */ /* torrent priority row */
row++; row++;
l = gtk_label_new_with_mnemonic(_("Torrent _priority:")); l = gtk_label_new_with_mnemonic(_("Torrent _priority:"));
g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_grid_attach(grid, l, 0, row, 1, 1); gtk_grid_attach(grid, l, 0, row, 1, 1);
w = data->priority_combo; w = data->priority_combo;
gtk_label_set_mnemonic_widget(GTK_LABEL(l), w); gtk_label_set_mnemonic_widget(GTK_LABEL(l), w);
@ -405,7 +405,7 @@ GtkWidget* gtr_torrent_options_dialog_new(GtkWindow* parent, TrCore* core, tr_ct
* so that it creates the tor/gtor objects */ * so that it creates the tor/gtor objects */
w = source_chooser; w = source_chooser;
if (data->filename != NULL) if (data->filename != nullptr)
{ {
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(w), data->filename); gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(w), data->filename);
} }
@ -444,7 +444,7 @@ static void onOpenDialogResponse(GtkDialog* dialog, int response, gpointer core)
GSList* files = gtk_file_chooser_get_files(chooser); GSList* files = gtk_file_chooser_get_files(chooser);
gtr_core_add_files(static_cast<TrCore*>(core), files, do_start, do_prompt, do_notify); gtr_core_add_files(static_cast<TrCore*>(core), files, do_start, do_prompt, do_notify);
g_slist_foreach(files, (GFunc)(GCallback)g_object_unref, NULL); g_slist_foreach(files, (GFunc)(GCallback)g_object_unref, nullptr);
g_slist_free(files); g_slist_free(files);
} }
@ -463,12 +463,12 @@ GtkWidget* gtr_torrent_open_from_file_dialog_new(GtkWindow* parent, TrCore* core
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_OPEN,
TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL), TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL),
TR_ARG_TUPLE(_("_Open"), GTK_RESPONSE_ACCEPT), TR_ARG_TUPLE(_("_Open"), GTK_RESPONSE_ACCEPT),
NULL); nullptr);
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(w), TRUE); gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(w), TRUE);
addTorrentFilters(GTK_FILE_CHOOSER(w)); addTorrentFilters(GTK_FILE_CHOOSER(w));
g_signal_connect(w, "response", G_CALLBACK(onOpenDialogResponse), core); g_signal_connect(w, "response", G_CALLBACK(onOpenDialogResponse), core);
if ((folder = gtr_pref_string_get(TR_KEY_open_dialog_dir)) != NULL) if ((folder = gtr_pref_string_get(TR_KEY_open_dialog_dir)) != nullptr)
{ {
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(w), folder); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(w), folder);
} }
@ -495,7 +495,7 @@ static void onOpenURLResponse(GtkDialog* dialog, int response, gpointer user_dat
char* url = g_strdup(gtk_entry_get_text(GTK_ENTRY(e))); char* url = g_strdup(gtk_entry_get_text(GTK_ENTRY(e)));
g_strstrip(url); g_strstrip(url);
if (url != NULL) if (url != nullptr)
{ {
handled = gtr_core_add_from_url(static_cast<TrCore*>(user_data), url); handled = gtr_core_add_from_url(static_cast<TrCore*>(user_data), url);
@ -531,7 +531,7 @@ GtkWidget* gtr_torrent_open_from_url_dialog_new(GtkWindow* parent, TrCore* core)
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL), TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL),
TR_ARG_TUPLE(_("_Open"), GTK_RESPONSE_ACCEPT), TR_ARG_TUPLE(_("_Open"), GTK_RESPONSE_ACCEPT),
NULL); nullptr);
g_signal_connect(w, "response", G_CALLBACK(onOpenURLResponse), core); g_signal_connect(w, "response", G_CALLBACK(onOpenURLResponse), core);
row = 0; row = 0;
@ -541,7 +541,7 @@ GtkWidget* gtr_torrent_open_from_url_dialog_new(GtkWindow* parent, TrCore* core)
gtk_widget_set_size_request(e, 400, -1); gtk_widget_set_size_request(e, 400, -1);
gtr_paste_clipboard_url_into_entry(e); gtr_paste_clipboard_url_into_entry(e);
g_object_set_data(G_OBJECT(w), "url-entry", e); g_object_set_data(G_OBJECT(w), "url-entry", e);
hig_workarea_add_row(t, &row, _("_URL"), e, NULL); hig_workarea_add_row(t, &row, _("_URL"), e, nullptr);
gtr_dialog_set_content(GTK_DIALOG(w), t); gtr_dialog_set_content(GTK_DIALOG(w), t);

View File

@ -18,7 +18,7 @@
#define DATA_KEY "gtr-relocate-data" #define DATA_KEY "gtr-relocate-data"
static char* previousLocation = NULL; static char* previousLocation = nullptr;
struct relocate_dialog_data struct relocate_dialog_data
{ {
@ -50,9 +50,9 @@ static void startMovingNextTorrent(struct relocate_dialog_data* data)
tr_torrent* tor = gtr_core_find_torrent(data->core, id); tr_torrent* tor = gtr_core_find_torrent(data->core, id);
if (tor != NULL) if (tor != nullptr)
{ {
tr_torrentSetLocation(tor, previousLocation, data->do_move, NULL, &data->done); tr_torrentSetLocation(tor, previousLocation, data->do_move, nullptr, &data->done);
} }
data->torrent_ids = g_slist_delete_link(data->torrent_ids, data->torrent_ids); data->torrent_ids = g_slist_delete_link(data->torrent_ids, data->torrent_ids);
@ -84,7 +84,7 @@ static gboolean onTimer(gpointer gdata)
} }
else if (done == TR_LOC_DONE) else if (done == TR_LOC_DONE)
{ {
if (data->torrent_ids != NULL) if (data->torrent_ids != nullptr)
{ {
startMovingNextTorrent(data); startMovingNextTorrent(data);
} }
@ -118,7 +118,7 @@ static void onResponse(GtkDialog* dialog, int response, gconstpointer user_data)
GtkDialogFlags(GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL), GtkDialogFlags(GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL),
GTK_MESSAGE_INFO, GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE, GTK_BUTTONS_CLOSE,
NULL); nullptr);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(w), _("This may take a moment…")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(w), _("This may take a moment…"));
gtk_dialog_set_response_sensitive(GTK_DIALOG(w), GTK_RESPONSE_CLOSE, FALSE); gtk_dialog_set_response_sensitive(GTK_DIALOG(w), GTK_RESPONSE_CLOSE, FALSE);
gtk_widget_show(w); gtk_widget_show(w);
@ -153,15 +153,15 @@ GtkWidget* gtr_relocate_dialog_new(GtkWindow* parent, TrCore* core, GSList* torr
GtkDialogFlags(GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL), GtkDialogFlags(GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL),
TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL), TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL),
TR_ARG_TUPLE(_("_Apply"), GTK_RESPONSE_APPLY), TR_ARG_TUPLE(_("_Apply"), GTK_RESPONSE_APPLY),
NULL); nullptr);
gtk_dialog_set_default_response(GTK_DIALOG(d), GTK_RESPONSE_CANCEL); gtk_dialog_set_default_response(GTK_DIALOG(d), GTK_RESPONSE_CANCEL);
g_signal_connect(d, "response", G_CALLBACK(onResponse), NULL); g_signal_connect(d, "response", G_CALLBACK(onResponse), nullptr);
row = 0; row = 0;
t = hig_workarea_create(); t = hig_workarea_create();
hig_workarea_add_section_title(t, &row, _("Location")); hig_workarea_add_section_title(t, &row, _("Location"));
if (previousLocation == NULL) if (previousLocation == nullptr)
{ {
previousLocation = g_strdup(gtr_pref_string_get(TR_KEY_download_dir)); previousLocation = g_strdup(gtr_pref_string_get(TR_KEY_download_dir));
} }
@ -169,8 +169,8 @@ GtkWidget* gtr_relocate_dialog_new(GtkWindow* parent, TrCore* core, GSList* torr
w = gtk_file_chooser_button_new(_("Set Torrent Location"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); 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); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(w), previousLocation);
g_object_set_data(G_OBJECT(d), "chooser", w); g_object_set_data(G_OBJECT(d), "chooser", w);
hig_workarea_add_row(t, &row, _("Torrent _location:"), w, NULL); hig_workarea_add_row(t, &row, _("Torrent _location:"), w, nullptr);
w = gtk_radio_button_new_with_mnemonic(NULL, _("_Move from the current folder")); w = gtk_radio_button_new_with_mnemonic(nullptr, _("_Move from the current folder"));
g_object_set_data(G_OBJECT(d), "move_rb", w); g_object_set_data(G_OBJECT(d), "move_rb", w);
hig_workarea_add_wide_control(t, &row, w); hig_workarea_add_wide_control(t, &row, w);
w = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(w), _("Local data is _already there")); w = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(w), _("Local data is _already there"));

View File

@ -99,7 +99,7 @@ static void dialogResponse(GtkDialog* dialog, gint response, gpointer gdata)
GTK_DIALOG(w), GTK_DIALOG(w),
TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL), TR_ARG_TUPLE(_("_Cancel"), GTK_RESPONSE_CANCEL),
TR_ARG_TUPLE(_("_Reset"), TR_RESPONSE_RESET), TR_ARG_TUPLE(_("_Reset"), TR_RESPONSE_RESET),
NULL); nullptr);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(w), "%s", secondary); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(w), "%s", secondary);
if (gtk_dialog_run(GTK_DIALOG(w)) == TR_RESPONSE_RESET) if (gtk_dialog_run(GTK_DIALOG(w)) == TR_RESPONSE_RESET)
@ -132,28 +132,28 @@ GtkWidget* gtr_stats_dialog_new(GtkWindow* parent, TrCore* core)
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
TR_ARG_TUPLE(_("_Reset"), TR_RESPONSE_RESET), TR_ARG_TUPLE(_("_Reset"), TR_RESPONSE_RESET),
TR_ARG_TUPLE(_("_Close"), GTK_RESPONSE_CLOSE), TR_ARG_TUPLE(_("_Close"), GTK_RESPONSE_CLOSE),
NULL); nullptr);
gtk_dialog_set_default_response(GTK_DIALOG(d), GTK_RESPONSE_CLOSE); gtk_dialog_set_default_response(GTK_DIALOG(d), GTK_RESPONSE_CLOSE);
t = hig_workarea_create(); t = hig_workarea_create();
ui->core = core; ui->core = core;
hig_workarea_add_section_title(t, &row, _("Current Session")); hig_workarea_add_section_title(t, &row, _("Current Session"));
l = gtk_label_new(NULL); l = gtk_label_new(nullptr);
ui->one_up_lb = GTK_LABEL(l); ui->one_up_lb = GTK_LABEL(l);
gtk_label_set_single_line_mode(ui->one_up_lb, TRUE); gtk_label_set_single_line_mode(ui->one_up_lb, TRUE);
hig_workarea_add_row(t, &row, _("Uploaded:"), l, NULL); hig_workarea_add_row(t, &row, _("Uploaded:"), l, nullptr);
l = gtk_label_new(NULL); l = gtk_label_new(nullptr);
ui->one_down_lb = GTK_LABEL(l); ui->one_down_lb = GTK_LABEL(l);
gtk_label_set_single_line_mode(ui->one_down_lb, TRUE); gtk_label_set_single_line_mode(ui->one_down_lb, TRUE);
hig_workarea_add_row(t, &row, _("Downloaded:"), l, NULL); hig_workarea_add_row(t, &row, _("Downloaded:"), l, nullptr);
l = gtk_label_new(NULL); l = gtk_label_new(nullptr);
ui->one_ratio_lb = GTK_LABEL(l); ui->one_ratio_lb = GTK_LABEL(l);
gtk_label_set_single_line_mode(ui->one_ratio_lb, TRUE); gtk_label_set_single_line_mode(ui->one_ratio_lb, TRUE);
hig_workarea_add_row(t, &row, _("Ratio:"), l, NULL); hig_workarea_add_row(t, &row, _("Ratio:"), l, nullptr);
l = gtk_label_new(NULL); l = gtk_label_new(nullptr);
ui->one_time_lb = GTK_LABEL(l); ui->one_time_lb = GTK_LABEL(l);
gtk_label_set_single_line_mode(ui->one_time_lb, TRUE); gtk_label_set_single_line_mode(ui->one_time_lb, TRUE);
hig_workarea_add_row(t, &row, _("Duration:"), l, NULL); hig_workarea_add_row(t, &row, _("Duration:"), l, nullptr);
hig_workarea_add_section_divider(t, &row); hig_workarea_add_section_divider(t, &row);
@ -163,22 +163,22 @@ GtkWidget* gtr_stats_dialog_new(GtkWindow* parent, TrCore* core)
gtk_label_set_single_line_mode(ui->all_sessions_lb, TRUE); gtk_label_set_single_line_mode(ui->all_sessions_lb, TRUE);
hig_workarea_add_label_w(t, row, l); hig_workarea_add_label_w(t, row, l);
++row; ++row;
l = gtk_label_new(NULL); l = gtk_label_new(nullptr);
ui->all_up_lb = GTK_LABEL(l); ui->all_up_lb = GTK_LABEL(l);
gtk_label_set_single_line_mode(ui->all_up_lb, TRUE); gtk_label_set_single_line_mode(ui->all_up_lb, TRUE);
hig_workarea_add_row(t, &row, _("Uploaded:"), l, NULL); hig_workarea_add_row(t, &row, _("Uploaded:"), l, nullptr);
l = gtk_label_new(NULL); l = gtk_label_new(nullptr);
ui->all_down_lb = GTK_LABEL(l); ui->all_down_lb = GTK_LABEL(l);
gtk_label_set_single_line_mode(ui->all_down_lb, TRUE); gtk_label_set_single_line_mode(ui->all_down_lb, TRUE);
hig_workarea_add_row(t, &row, _("Downloaded:"), l, NULL); hig_workarea_add_row(t, &row, _("Downloaded:"), l, nullptr);
l = gtk_label_new(NULL); l = gtk_label_new(nullptr);
ui->all_ratio_lb = GTK_LABEL(l); ui->all_ratio_lb = GTK_LABEL(l);
gtk_label_set_single_line_mode(ui->all_ratio_lb, TRUE); gtk_label_set_single_line_mode(ui->all_ratio_lb, TRUE);
hig_workarea_add_row(t, &row, _("Ratio:"), l, NULL); hig_workarea_add_row(t, &row, _("Ratio:"), l, nullptr);
l = gtk_label_new(NULL); l = gtk_label_new(nullptr);
ui->all_time_lb = GTK_LABEL(l); ui->all_time_lb = GTK_LABEL(l);
gtk_label_set_single_line_mode(ui->all_time_lb, TRUE); gtk_label_set_single_line_mode(ui->all_time_lb, TRUE);
hig_workarea_add_row(t, &row, _("Duration:"), l, NULL); hig_workarea_add_row(t, &row, _("Duration:"), l, nullptr);
gtr_dialog_set_content(GTK_DIALOG(d), t); gtr_dialog_set_content(GTK_DIALOG(d), t);

View File

@ -255,7 +255,7 @@ static void getStatusString(
if (st->error != 0) if (st->error != 0)
{ {
char const* fmt[] = { char const* fmt[] = {
NULL, nullptr,
N_("Tracker gave a warning: \"%s\""), N_("Tracker gave a warning: \"%s\""),
N_("Tracker gave an error: \"%s\""), N_("Tracker gave an error: \"%s\""),
N_("Error: %s"), N_("Error: %s"),
@ -393,7 +393,7 @@ static GdkPixbuf* get_icon(tr_torrent const* tor, GtkIconSize icon_size, GtkWidg
{ {
mime_type = DIRECTORY_MIME_TYPE; mime_type = DIRECTORY_MIME_TYPE;
} }
else if (strchr(info->files[0].name, '/') != NULL) else if (strchr(info->files[0].name, '/') != nullptr)
{ {
mime_type = DIRECTORY_MIME_TYPE; mime_type = DIRECTORY_MIME_TYPE;
} }
@ -440,12 +440,12 @@ static void get_size_compact(TorrentCellRenderer* cell, GtkWidget* widget, gint*
gtk_cell_renderer_get_padding(GTK_CELL_RENDERER(cell), &xpad, &ypad); gtk_cell_renderer_get_padding(GTK_CELL_RENDERER(cell), &xpad, &ypad);
/* get the idealized cell dimensions */ /* get the idealized cell dimensions */
g_object_set(p->icon_renderer, "pixbuf", icon, NULL); g_object_set(p->icon_renderer, "pixbuf", icon, nullptr);
gtr_cell_renderer_get_preferred_size(p->icon_renderer, widget, NULL, &icon_size); gtr_cell_renderer_get_preferred_size(p->icon_renderer, widget, nullptr, &icon_size);
g_object_set(p->text_renderer, "text", name, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, NULL); g_object_set(p->text_renderer, "text", name, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, nullptr);
gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, NULL, &name_size); gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, nullptr, &name_size);
g_object_set(p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, NULL); g_object_set(p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, nullptr);
gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, NULL, &stat_size); gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, nullptr, &stat_size);
/** /**
*** LAYOUT *** LAYOUT
@ -453,12 +453,12 @@ static void get_size_compact(TorrentCellRenderer* cell, GtkWidget* widget, gint*
#define BAR_WIDTH 50 #define BAR_WIDTH 50
if (width != NULL) if (width != nullptr)
{ {
*width = xpad * 2 + icon_size.width + GUI_PAD + BAR_WIDTH + GUI_PAD + stat_size.width; *width = xpad * 2 + icon_size.width + GUI_PAD + BAR_WIDTH + GUI_PAD + stat_size.width;
} }
if (height != NULL) if (height != nullptr)
{ {
*height = ypad * 2 + MAX(name_size.height, p->bar_height); *height = ypad * 2 + MAX(name_size.height, p->bar_height);
} }
@ -494,31 +494,31 @@ static void get_size_full(TorrentCellRenderer* cell, GtkWidget* widget, gint* wi
gtk_cell_renderer_get_padding(GTK_CELL_RENDERER(cell), &xpad, &ypad); gtk_cell_renderer_get_padding(GTK_CELL_RENDERER(cell), &xpad, &ypad);
/* get the idealized cell dimensions */ /* get the idealized cell dimensions */
g_object_set(p->icon_renderer, "pixbuf", icon, NULL); g_object_set(p->icon_renderer, "pixbuf", icon, nullptr);
gtr_cell_renderer_get_preferred_size(p->icon_renderer, widget, NULL, &icon_size); gtr_cell_renderer_get_preferred_size(p->icon_renderer, widget, nullptr, &icon_size);
g_object_set( g_object_set(
p->text_renderer, p->text_renderer,
TR_ARG_TUPLE("text", name), TR_ARG_TUPLE("text", name),
TR_ARG_TUPLE("weight", PANGO_WEIGHT_BOLD), TR_ARG_TUPLE("weight", PANGO_WEIGHT_BOLD),
TR_ARG_TUPLE("scale", 1.0), TR_ARG_TUPLE("scale", 1.0),
TR_ARG_TUPLE("ellipsize", PANGO_ELLIPSIZE_NONE), TR_ARG_TUPLE("ellipsize", PANGO_ELLIPSIZE_NONE),
NULL); nullptr);
gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, NULL, &name_size); gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, nullptr, &name_size);
g_object_set(p->text_renderer, "text", gstr_prog->str, "weight", PANGO_WEIGHT_NORMAL, "scale", SMALL_SCALE, NULL); g_object_set(p->text_renderer, "text", gstr_prog->str, "weight", PANGO_WEIGHT_NORMAL, "scale", SMALL_SCALE, nullptr);
gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, NULL, &prog_size); gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, nullptr, &prog_size);
g_object_set(p->text_renderer, "text", gstr_stat->str, NULL); g_object_set(p->text_renderer, "text", gstr_stat->str, nullptr);
gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, NULL, &stat_size); gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, nullptr, &stat_size);
/** /**
*** LAYOUT *** LAYOUT
**/ **/
if (width != NULL) if (width != nullptr)
{ {
*width = xpad * 2 + icon_size.width + GUI_PAD + MAX(prog_size.width, stat_size.width); *width = xpad * 2 + icon_size.width + GUI_PAD + MAX(prog_size.width, stat_size.width);
} }
if (height != NULL) if (height != nullptr)
{ {
*height = ypad * 2 + name_size.height + prog_size.height + GUI_PAD_SMALL + p->bar_height + GUI_PAD_SMALL + *height = ypad * 2 + name_size.height + prog_size.height + GUI_PAD_SMALL + p->bar_height + GUI_PAD_SMALL +
stat_size.height; stat_size.height;
@ -539,7 +539,7 @@ static void torrent_cell_renderer_get_size(
{ {
TorrentCellRenderer const* const self = TORRENT_CELL_RENDERER(cell); TorrentCellRenderer const* const self = TORRENT_CELL_RENDERER(cell);
if (self != NULL && self->priv->tor != NULL) if (self != nullptr && self->priv->tor != nullptr)
{ {
int w; int w;
int h; int h;
@ -554,22 +554,22 @@ static void torrent_cell_renderer_get_size(
get_size_full(TORRENT_CELL_RENDERER(cell), widget, &w, &h); get_size_full(TORRENT_CELL_RENDERER(cell), widget, &w, &h);
} }
if (width != NULL) if (width != nullptr)
{ {
*width = w; *width = w;
} }
if (height != NULL) if (height != nullptr)
{ {
*height = h; *height = h;
} }
if (x_offset != NULL) if (x_offset != nullptr)
{ {
*x_offset = cell_area ? cell_area->x : 0; *x_offset = cell_area ? cell_area->x : 0;
} }
if (y_offset != NULL) if (y_offset != nullptr)
{ {
int xpad; int xpad;
int ypad; int ypad;
@ -676,14 +676,14 @@ static void render_compact(
fill_area.height -= ypad * 2; fill_area.height -= ypad * 2;
icon_area = name_area = stat_area = prog_area = fill_area; icon_area = name_area = stat_area = prog_area = fill_area;
g_object_set(p->icon_renderer, "pixbuf", icon, NULL); g_object_set(p->icon_renderer, "pixbuf", icon, nullptr);
gtr_cell_renderer_get_preferred_size(p->icon_renderer, widget, NULL, &size); gtr_cell_renderer_get_preferred_size(p->icon_renderer, widget, nullptr, &size);
icon_area.width = size.width; icon_area.width = size.width;
g_object_set(p->text_renderer, "text", name, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, NULL); g_object_set(p->text_renderer, "text", name, "ellipsize", PANGO_ELLIPSIZE_NONE, "scale", 1.0, nullptr);
gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, NULL, &size); gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, nullptr, &size);
name_area.width = size.width; name_area.width = size.width;
g_object_set(p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, NULL); g_object_set(p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, nullptr);
gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, NULL, &size); gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, nullptr, &size);
stat_area.width = size.width; stat_area.width = size.width;
icon_area.x = fill_area.x; icon_area.x = fill_area.x;
@ -698,9 +698,9 @@ static void render_compact(
*** RENDER *** RENDER
**/ **/
g_object_set(p->icon_renderer, "pixbuf", icon, "sensitive", sensitive, NULL); g_object_set(p->icon_renderer, "pixbuf", icon, "sensitive", sensitive, nullptr);
gtr_cell_renderer_render(p->icon_renderer, window, widget, &icon_area, flags); gtr_cell_renderer_render(p->icon_renderer, window, widget, &icon_area, flags);
g_object_set(p->progress_renderer, "value", (int)(percentDone * 100.0), "text", NULL, "sensitive", sensitive, NULL); g_object_set(p->progress_renderer, "value", (int)(percentDone * 100.0), "text", nullptr, "sensitive", sensitive, nullptr);
gtr_cell_renderer_render(p->progress_renderer, window, widget, &prog_area, flags); gtr_cell_renderer_render(p->progress_renderer, window, widget, &prog_area, flags);
g_object_set( g_object_set(
p->text_renderer, p->text_renderer,
@ -708,9 +708,9 @@ static void render_compact(
TR_ARG_TUPLE("scale", SMALL_SCALE), TR_ARG_TUPLE("scale", SMALL_SCALE),
TR_ARG_TUPLE("ellipsize", PANGO_ELLIPSIZE_END), TR_ARG_TUPLE("ellipsize", PANGO_ELLIPSIZE_END),
TR_ARG_TUPLE(FOREGROUND_COLOR_KEY, &text_color), TR_ARG_TUPLE(FOREGROUND_COLOR_KEY, &text_color),
NULL); nullptr);
gtr_cell_renderer_render(p->text_renderer, window, widget, &stat_area, flags); gtr_cell_renderer_render(p->text_renderer, window, widget, &stat_area, flags);
g_object_set(p->text_renderer, "text", name, "scale", 1.0, FOREGROUND_COLOR_KEY, &text_color, NULL); g_object_set(p->text_renderer, "text", name, "scale", 1.0, FOREGROUND_COLOR_KEY, &text_color, nullptr);
gtr_cell_renderer_render(p->text_renderer, window, widget, &name_area, flags); gtr_cell_renderer_render(p->text_renderer, window, widget, &name_area, flags);
/* cleanup */ /* cleanup */
@ -762,8 +762,8 @@ static void render_full(
get_text_color(widget, st, &text_color); get_text_color(widget, st, &text_color);
/* get the idealized cell dimensions */ /* get the idealized cell dimensions */
g_object_set(p->icon_renderer, "pixbuf", icon, NULL); g_object_set(p->icon_renderer, "pixbuf", icon, nullptr);
gtr_cell_renderer_get_preferred_size(p->icon_renderer, widget, NULL, &size); gtr_cell_renderer_get_preferred_size(p->icon_renderer, widget, nullptr, &size);
icon_area.width = size.width; icon_area.width = size.width;
icon_area.height = size.height; icon_area.height = size.height;
g_object_set( g_object_set(
@ -772,16 +772,16 @@ static void render_full(
TR_ARG_TUPLE("weight", PANGO_WEIGHT_BOLD), TR_ARG_TUPLE("weight", PANGO_WEIGHT_BOLD),
TR_ARG_TUPLE("ellipsize", PANGO_ELLIPSIZE_NONE), TR_ARG_TUPLE("ellipsize", PANGO_ELLIPSIZE_NONE),
TR_ARG_TUPLE("scale", 1.0), TR_ARG_TUPLE("scale", 1.0),
NULL); nullptr);
gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, NULL, &size); gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, nullptr, &size);
name_area.width = size.width; name_area.width = size.width;
name_area.height = size.height; name_area.height = size.height;
g_object_set(p->text_renderer, "text", gstr_prog->str, "weight", PANGO_WEIGHT_NORMAL, "scale", SMALL_SCALE, NULL); g_object_set(p->text_renderer, "text", gstr_prog->str, "weight", PANGO_WEIGHT_NORMAL, "scale", SMALL_SCALE, nullptr);
gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, NULL, &size); gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, nullptr, &size);
prog_area.width = size.width; prog_area.width = size.width;
prog_area.height = size.height; prog_area.height = size.height;
g_object_set(p->text_renderer, "text", gstr_stat->str, NULL); g_object_set(p->text_renderer, "text", gstr_stat->str, nullptr);
gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, NULL, &size); gtr_cell_renderer_get_preferred_size(p->text_renderer, widget, nullptr, &size);
stat_area.width = size.width; stat_area.width = size.width;
stat_area.height = size.height; stat_area.height = size.height;
@ -824,7 +824,7 @@ static void render_full(
*** RENDER *** RENDER
**/ **/
g_object_set(p->icon_renderer, "pixbuf", icon, "sensitive", sensitive, NULL); g_object_set(p->icon_renderer, "pixbuf", icon, "sensitive", sensitive, nullptr);
gtr_cell_renderer_render(p->icon_renderer, window, widget, &icon_area, flags); gtr_cell_renderer_render(p->icon_renderer, window, widget, &icon_area, flags);
g_object_set( g_object_set(
p->text_renderer, p->text_renderer,
@ -833,13 +833,13 @@ static void render_full(
TR_ARG_TUPLE(FOREGROUND_COLOR_KEY, &text_color), TR_ARG_TUPLE(FOREGROUND_COLOR_KEY, &text_color),
TR_ARG_TUPLE("ellipsize", PANGO_ELLIPSIZE_END), TR_ARG_TUPLE("ellipsize", PANGO_ELLIPSIZE_END),
TR_ARG_TUPLE("weight", PANGO_WEIGHT_BOLD), TR_ARG_TUPLE("weight", PANGO_WEIGHT_BOLD),
NULL); nullptr);
gtr_cell_renderer_render(p->text_renderer, window, widget, &name_area, flags); gtr_cell_renderer_render(p->text_renderer, window, widget, &name_area, flags);
g_object_set(p->text_renderer, "text", gstr_prog->str, "scale", SMALL_SCALE, "weight", PANGO_WEIGHT_NORMAL, NULL); g_object_set(p->text_renderer, "text", gstr_prog->str, "scale", SMALL_SCALE, "weight", PANGO_WEIGHT_NORMAL, nullptr);
gtr_cell_renderer_render(p->text_renderer, window, widget, &prog_area, flags); gtr_cell_renderer_render(p->text_renderer, window, widget, &prog_area, flags);
g_object_set(p->progress_renderer, "value", (int)(percentDone * 100.0), "text", "", "sensitive", sensitive, NULL); g_object_set(p->progress_renderer, "value", (int)(percentDone * 100.0), "text", "", "sensitive", sensitive, nullptr);
gtr_cell_renderer_render(p->progress_renderer, window, widget, &prct_area, flags); gtr_cell_renderer_render(p->progress_renderer, window, widget, &prct_area, flags);
g_object_set(p->text_renderer, "text", gstr_stat->str, FOREGROUND_COLOR_KEY, &text_color, NULL); g_object_set(p->text_renderer, "text", gstr_stat->str, FOREGROUND_COLOR_KEY, &text_color, nullptr);
gtr_cell_renderer_render(p->text_renderer, window, widget, &stat_area, flags); gtr_cell_renderer_render(p->text_renderer, window, widget, &stat_area, flags);
/* cleanup */ /* cleanup */
@ -861,7 +861,7 @@ static void torrent_cell_renderer_render(
gtk_widget_set_direction(widget, GTK_TEXT_DIR_RTL); gtk_widget_set_direction(widget, GTK_TEXT_DIR_RTL);
#endif #endif
if (self != NULL && self->priv->tor != NULL) if (self != nullptr && self->priv->tor != nullptr)
{ {
struct TorrentCellRendererPrivate const* const p = self->priv; struct TorrentCellRendererPrivate const* const p = self->priv;
@ -952,14 +952,14 @@ static void torrent_cell_renderer_dispose(GObject* o)
{ {
TorrentCellRenderer* r = TORRENT_CELL_RENDERER(o); TorrentCellRenderer* r = TORRENT_CELL_RENDERER(o);
if (r != NULL && r->priv != NULL) if (r != nullptr && r->priv != nullptr)
{ {
g_string_free(r->priv->gstr1, TRUE); g_string_free(r->priv->gstr1, TRUE);
g_string_free(r->priv->gstr2, TRUE); g_string_free(r->priv->gstr2, TRUE);
g_object_unref(G_OBJECT(r->priv->text_renderer)); g_object_unref(G_OBJECT(r->priv->text_renderer));
g_object_unref(G_OBJECT(r->priv->progress_renderer)); g_object_unref(G_OBJECT(r->priv->progress_renderer));
g_object_unref(G_OBJECT(r->priv->icon_renderer)); g_object_unref(G_OBJECT(r->priv->icon_renderer));
r->priv = NULL; r->priv = nullptr;
} }
G_OBJECT_CLASS(torrent_cell_renderer_parent_class)->dispose(o); G_OBJECT_CLASS(torrent_cell_renderer_parent_class)->dispose(o);
@ -979,27 +979,34 @@ static void torrent_cell_renderer_class_init(TorrentCellRendererClass* klass)
g_object_class_install_property( g_object_class_install_property(
gobject_class, gobject_class,
P_TORRENT, P_TORRENT,
g_param_spec_pointer("torrent", NULL, "tr_torrent*", G_PARAM_READWRITE)); g_param_spec_pointer("torrent", nullptr, "tr_torrent*", G_PARAM_READWRITE));
g_object_class_install_property( g_object_class_install_property(
gobject_class, gobject_class,
P_UPLOAD_SPEED, P_UPLOAD_SPEED,
g_param_spec_double("piece-upload-speed", NULL, "tr_stat.pieceUploadSpeed_KBps", 0, INT_MAX, 0, G_PARAM_READWRITE)); g_param_spec_double("piece-upload-speed", nullptr, "tr_stat.pieceUploadSpeed_KBps", 0, INT_MAX, 0, G_PARAM_READWRITE));
g_object_class_install_property( g_object_class_install_property(
gobject_class, gobject_class,
P_DOWNLOAD_SPEED, P_DOWNLOAD_SPEED,
g_param_spec_double("piece-download-speed", NULL, "tr_stat.pieceDownloadSpeed_KBps", 0, INT_MAX, 0, G_PARAM_READWRITE)); g_param_spec_double(
"piece-download-speed",
nullptr,
"tr_stat.pieceDownloadSpeed_KBps",
0,
INT_MAX,
0,
G_PARAM_READWRITE));
g_object_class_install_property( g_object_class_install_property(
gobject_class, gobject_class,
P_BAR_HEIGHT, P_BAR_HEIGHT,
g_param_spec_int("bar-height", NULL, "Bar Height", 1, INT_MAX, DEFAULT_BAR_HEIGHT, G_PARAM_READWRITE)); g_param_spec_int("bar-height", nullptr, "Bar Height", 1, INT_MAX, DEFAULT_BAR_HEIGHT, G_PARAM_READWRITE));
g_object_class_install_property( g_object_class_install_property(
gobject_class, gobject_class,
P_COMPACT, P_COMPACT,
g_param_spec_boolean("compact", NULL, "Compact Mode", FALSE, G_PARAM_READWRITE)); g_param_spec_boolean("compact", nullptr, "Compact Mode", FALSE, G_PARAM_READWRITE));
} }
static void torrent_cell_renderer_init(TorrentCellRenderer* self) static void torrent_cell_renderer_init(TorrentCellRenderer* self)
@ -1012,11 +1019,11 @@ static void torrent_cell_renderer_init(TorrentCellRenderer* self)
p = self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, TORRENT_CELL_RENDERER_TYPE, struct TorrentCellRendererPrivate); p = self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, TORRENT_CELL_RENDERER_TYPE, struct TorrentCellRendererPrivate);
#endif #endif
p->tor = NULL; p->tor = nullptr;
p->gstr1 = g_string_new(NULL); p->gstr1 = g_string_new(nullptr);
p->gstr2 = g_string_new(NULL); p->gstr2 = g_string_new(nullptr);
p->text_renderer = gtk_cell_renderer_text_new(); p->text_renderer = gtk_cell_renderer_text_new();
g_object_set(p->text_renderer, "xpad", 0, "ypad", 0, NULL); g_object_set(p->text_renderer, "xpad", 0, "ypad", 0, nullptr);
p->progress_renderer = gtk_cell_renderer_progress_new(); p->progress_renderer = gtk_cell_renderer_progress_new();
p->icon_renderer = gtk_cell_renderer_pixbuf_new(); p->icon_renderer = gtk_cell_renderer_pixbuf_new();
g_object_ref_sink(p->text_renderer); g_object_ref_sink(p->text_renderer);
@ -1028,5 +1035,5 @@ static void torrent_cell_renderer_init(TorrentCellRenderer* self)
GtkCellRenderer* torrent_cell_renderer_new(void) GtkCellRenderer* torrent_cell_renderer_new(void)
{ {
return (GtkCellRenderer*)g_object_new(TORRENT_CELL_RENDERER_TYPE, NULL); return (GtkCellRenderer*)g_object_new(TORRENT_CELL_RENDERER_TYPE, nullptr);
} }

View File

@ -83,7 +83,7 @@ typedef struct TrCorePrivate
static int core_is_disposed(TrCore const* core) static int core_is_disposed(TrCore const* core)
{ {
return core == NULL || core->priv->sorted_model == NULL; return core == nullptr || core->priv->sorted_model == nullptr;
} }
G_DEFINE_TYPE_WITH_CODE(TrCore, tr_core, G_TYPE_OBJECT, G_ADD_PRIVATE(TrCore)) G_DEFINE_TYPE_WITH_CODE(TrCore, tr_core, G_TYPE_OBJECT, G_ADD_PRIVATE(TrCore))
@ -92,11 +92,11 @@ static void core_dispose(GObject* o)
{ {
TrCore* core = TR_CORE(o); TrCore* core = TR_CORE(o);
if (core->priv->sorted_model != NULL) if (core->priv->sorted_model != nullptr)
{ {
g_object_unref(core->priv->sorted_model); g_object_unref(core->priv->sorted_model);
core->priv->sorted_model = NULL; core->priv->sorted_model = nullptr;
core->priv->raw_model = NULL; core->priv->raw_model = nullptr;
} }
G_OBJECT_CLASS(tr_core_parent_class)->dispose(o); G_OBJECT_CLASS(tr_core_parent_class)->dispose(o);
@ -125,8 +125,8 @@ static void tr_core_class_init(TrCoreClass* core_class)
core_type, core_type,
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(TrCoreClass, add_error), G_STRUCT_OFFSET(TrCoreClass, add_error),
NULL, nullptr,
NULL, nullptr,
g_cclosure_marshal_VOID__UINT_POINTER, g_cclosure_marshal_VOID__UINT_POINTER,
G_TYPE_NONE, G_TYPE_NONE,
2, 2,
@ -138,8 +138,8 @@ static void tr_core_class_init(TrCoreClass* core_class)
core_type, core_type,
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(TrCoreClass, add_prompt), G_STRUCT_OFFSET(TrCoreClass, add_prompt),
NULL, nullptr,
NULL, nullptr,
g_cclosure_marshal_VOID__POINTER, g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, G_TYPE_NONE,
1, 1,
@ -150,8 +150,8 @@ static void tr_core_class_init(TrCoreClass* core_class)
core_type, core_type,
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(TrCoreClass, busy), G_STRUCT_OFFSET(TrCoreClass, busy),
NULL, nullptr,
NULL, nullptr,
g_cclosure_marshal_VOID__BOOLEAN, g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, G_TYPE_NONE,
1, 1,
@ -162,8 +162,8 @@ static void tr_core_class_init(TrCoreClass* core_class)
core_type, core_type,
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(TrCoreClass, blocklist_updated), G_STRUCT_OFFSET(TrCoreClass, blocklist_updated),
NULL, nullptr,
NULL, nullptr,
g_cclosure_marshal_VOID__INT, g_cclosure_marshal_VOID__INT,
G_TYPE_NONE, G_TYPE_NONE,
1, 1,
@ -174,8 +174,8 @@ static void tr_core_class_init(TrCoreClass* core_class)
core_type, core_type,
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(TrCoreClass, port_tested), G_STRUCT_OFFSET(TrCoreClass, port_tested),
NULL, nullptr,
NULL, nullptr,
g_cclosure_marshal_VOID__BOOLEAN, g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, G_TYPE_NONE,
1, 1,
@ -186,8 +186,8 @@ static void tr_core_class_init(TrCoreClass* core_class)
core_type, core_type,
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(TrCoreClass, prefs_changed), G_STRUCT_OFFSET(TrCoreClass, prefs_changed),
NULL, nullptr,
NULL, nullptr,
g_cclosure_marshal_VOID__INT, g_cclosure_marshal_VOID__INT,
G_TYPE_NONE, G_TYPE_NONE,
1, 1,
@ -271,17 +271,17 @@ void gtr_core_pref_changed(TrCore* core, tr_quark const key)
static GtkTreeModel* core_raw_model(TrCore* core) static GtkTreeModel* core_raw_model(TrCore* core)
{ {
return core_is_disposed(core) ? NULL : core->priv->raw_model; return core_is_disposed(core) ? nullptr : core->priv->raw_model;
} }
GtkTreeModel* gtr_core_model(TrCore* core) GtkTreeModel* gtr_core_model(TrCore* core)
{ {
return core_is_disposed(core) ? NULL : core->priv->sorted_model; return core_is_disposed(core) ? nullptr : core->priv->sorted_model;
} }
tr_session* gtr_core_session(TrCore* core) tr_session* gtr_core_session(TrCore* core)
{ {
return core_is_disposed(core) ? NULL : core->priv->session; return core_is_disposed(core) ? nullptr : core->priv->session;
} }
/*** /***
@ -709,7 +709,7 @@ static void core_set_sort_mode(TrCore* core, char const* mode, gboolean is_rever
type = is_reversed ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING; type = is_reversed ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING;
} }
gtk_tree_sortable_set_sort_func(sortable, col, sort_func, NULL, NULL); gtk_tree_sortable_set_sort_func(sortable, col, sort_func, nullptr, nullptr);
gtk_tree_sortable_set_sort_column_id(sortable, col, type); gtk_tree_sortable_set_sort_column_id(sortable, col, type);
} }
@ -724,9 +724,9 @@ static time_t get_file_mtime(GFile* file)
GFileInfo* info; GFileInfo* info;
time_t mtime = 0; time_t mtime = 0;
info = g_file_query_info(file, G_FILE_ATTRIBUTE_TIME_MODIFIED, {}, NULL, NULL); info = g_file_query_info(file, G_FILE_ATTRIBUTE_TIME_MODIFIED, {}, nullptr, nullptr);
if (info != NULL) if (info != nullptr)
{ {
mtime = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_TIME_MODIFIED); mtime = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
g_object_unref(G_OBJECT(info)); g_object_unref(G_OBJECT(info));
@ -739,26 +739,26 @@ static void rename_torrent_and_unref_file(GFile* file)
{ {
GFileInfo* info; GFileInfo* info;
info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME, {}, NULL, NULL); info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME, {}, nullptr, nullptr);
if (info != NULL) if (info != nullptr)
{ {
GError* error = NULL; GError* error = nullptr;
char const* old_name; char const* old_name;
char* new_name; char* new_name;
GFile* new_file; GFile* new_file;
old_name = g_file_info_get_attribute_string(info, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME); old_name = g_file_info_get_attribute_string(info, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
new_name = g_strdup_printf("%s.added", old_name); new_name = g_strdup_printf("%s.added", old_name);
new_file = g_file_set_display_name(file, new_name, NULL, &error); new_file = g_file_set_display_name(file, new_name, nullptr, &error);
if (error != NULL) if (error != nullptr)
{ {
g_message("Unable to rename \"%s\" as \"%s\": %s", old_name, new_name, error->message); g_message("Unable to rename \"%s\" as \"%s\": %s", old_name, new_name, error->message);
g_error_free(error); g_error_free(error);
} }
if (new_file != NULL) if (new_file != nullptr)
{ {
g_object_unref(G_OBJECT(new_file)); g_object_unref(G_OBJECT(new_file));
} }
@ -772,14 +772,14 @@ static void rename_torrent_and_unref_file(GFile* file)
static gboolean core_watchdir_idle(gpointer gcore) static gboolean core_watchdir_idle(gpointer gcore)
{ {
GSList* changing = NULL; GSList* changing = nullptr;
GSList* unchanging = NULL; GSList* unchanging = nullptr;
TrCore* core = TR_CORE(gcore); TrCore* core = TR_CORE(gcore);
time_t const now = tr_time(); time_t const now = tr_time();
struct TrCorePrivate* p = core->priv; struct TrCorePrivate* p = core->priv;
/* separate the files into two lists: changing and unchanging */ /* separate the files into two lists: changing and unchanging */
for (GSList* l = p->monitor_files; l != NULL; l = l->next) for (GSList* l = p->monitor_files; l != nullptr; l = l->next)
{ {
auto* file = static_cast<GFile*>(l->data); auto* file = static_cast<GFile*>(l->data);
time_t const mtime = get_file_mtime(file); time_t const mtime = get_file_mtime(file);
@ -795,14 +795,14 @@ static gboolean core_watchdir_idle(gpointer gcore)
} }
/* add the files that have stopped changing */ /* add the files that have stopped changing */
if (unchanging != NULL) if (unchanging != nullptr)
{ {
gboolean const do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents); gboolean const do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents);
gboolean const do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window); gboolean const do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
core->priv->adding_from_watch_dir = TRUE; core->priv->adding_from_watch_dir = TRUE;
gtr_core_add_files(core, unchanging, do_start, do_prompt, TRUE); gtr_core_add_files(core, unchanging, do_start, do_prompt, TRUE);
g_slist_foreach(unchanging, (GFunc)(GCallback)rename_torrent_and_unref_file, NULL); g_slist_foreach(unchanging, (GFunc)(GCallback)rename_torrent_and_unref_file, nullptr);
g_slist_free(unchanging); g_slist_free(unchanging);
core->priv->adding_from_watch_dir = FALSE; core->priv->adding_from_watch_dir = FALSE;
} }
@ -833,7 +833,7 @@ static void core_watchdir_monitor_file(TrCore* core, GFile* file)
bool found = false; bool found = false;
/* if we're not already watching this file, start watching it now */ /* if we're not already watching this file, start watching it now */
for (GSList* l = p->monitor_files; !found && l != NULL; l = l->next) for (GSList* l = p->monitor_files; !found && l != nullptr; l = l->next)
{ {
found = g_file_equal(file, static_cast<GFile*>(l->data)); found = g_file_equal(file, static_cast<GFile*>(l->data));
} }
@ -874,15 +874,15 @@ static void on_file_changed_in_watchdir(
static void core_watchdir_scan(TrCore* core) static void core_watchdir_scan(TrCore* core)
{ {
char const* dirname = gtr_pref_string_get(TR_KEY_watch_dir); char const* dirname = gtr_pref_string_get(TR_KEY_watch_dir);
GDir* dir = g_dir_open(dirname, 0, NULL); GDir* dir = g_dir_open(dirname, 0, nullptr);
if (dir != NULL) if (dir != nullptr)
{ {
char const* name; char const* name;
while ((name = g_dir_read_name(dir)) != NULL) while ((name = g_dir_read_name(dir)) != nullptr)
{ {
char* filename = g_build_filename(dirname, name, NULL); char* filename = g_build_filename(dirname, name, nullptr);
GFile* file = g_file_new_for_path(filename); GFile* file = g_file_new_for_path(filename);
core_watchdir_monitor_file(core, file); core_watchdir_monitor_file(core, file);
g_object_unref(file); g_object_unref(file);
@ -899,21 +899,21 @@ static void core_watchdir_update(TrCore* core)
GFile* dir = g_file_new_for_path(gtr_pref_string_get(TR_KEY_watch_dir)); GFile* dir = g_file_new_for_path(gtr_pref_string_get(TR_KEY_watch_dir));
struct TrCorePrivate* p = core->priv; struct TrCorePrivate* p = core->priv;
if (p->monitor != NULL && (!is_enabled || !g_file_equal(dir, p->monitor_dir))) if (p->monitor != nullptr && (!is_enabled || !g_file_equal(dir, p->monitor_dir)))
{ {
g_signal_handler_disconnect(p->monitor, p->monitor_tag); g_signal_handler_disconnect(p->monitor, p->monitor_tag);
g_file_monitor_cancel(p->monitor); g_file_monitor_cancel(p->monitor);
g_object_unref(p->monitor); g_object_unref(p->monitor);
g_object_unref(p->monitor_dir); g_object_unref(p->monitor_dir);
p->monitor_dir = NULL; p->monitor_dir = nullptr;
p->monitor = NULL; p->monitor = nullptr;
p->monitor_tag = 0; p->monitor_tag = 0;
} }
if (is_enabled && p->monitor == NULL) if (is_enabled && p->monitor == nullptr)
{ {
GFileMonitor* m = g_file_monitor_directory(dir, {}, NULL, NULL); GFileMonitor* m = g_file_monitor_directory(dir, {}, nullptr, nullptr);
core_watchdir_scan(core); core_watchdir_scan(core);
g_object_ref(dir); g_object_ref(dir);
@ -972,17 +972,17 @@ static void on_pref_changed(TrCore* core, tr_quark const key, gpointer data)
TrCore* gtr_core_new(tr_session* session) TrCore* gtr_core_new(tr_session* session)
{ {
TrCore* core = TR_CORE(g_object_new(TR_CORE_TYPE, NULL)); TrCore* core = TR_CORE(g_object_new(TR_CORE_TYPE, nullptr));
core->priv->session = session; core->priv->session = session;
/* init from prefs & listen to pref changes */ /* init from prefs & listen to pref changes */
on_pref_changed(core, TR_KEY_sort_mode, NULL); on_pref_changed(core, TR_KEY_sort_mode, nullptr);
on_pref_changed(core, TR_KEY_sort_reversed, NULL); on_pref_changed(core, TR_KEY_sort_reversed, nullptr);
on_pref_changed(core, TR_KEY_watch_dir_enabled, NULL); on_pref_changed(core, TR_KEY_watch_dir_enabled, nullptr);
on_pref_changed(core, TR_KEY_peer_limit_global, NULL); on_pref_changed(core, TR_KEY_peer_limit_global, nullptr);
on_pref_changed(core, TR_KEY_inhibit_desktop_hibernation, NULL); on_pref_changed(core, TR_KEY_inhibit_desktop_hibernation, nullptr);
g_signal_connect(core, "prefs-changed", G_CALLBACK(on_pref_changed), NULL); g_signal_connect(core, "prefs-changed", G_CALLBACK(on_pref_changed), nullptr);
return core; return core;
} }
@ -991,9 +991,9 @@ tr_session* gtr_core_close(TrCore* core)
{ {
tr_session* session = gtr_core_session(core); tr_session* session = gtr_core_session(core);
if (session != NULL) if (session != nullptr)
{ {
core->priv->session = NULL; core->priv->session = nullptr;
gtr_pref_save(session); gtr_pref_save(session);
} }
@ -1059,7 +1059,7 @@ static gboolean find_row_from_torrent_id(GtkTreeModel* model, int id, GtkTreeIte
GtkTreeIter iter; GtkTreeIter iter;
gboolean match = FALSE; gboolean match = FALSE;
if (gtk_tree_model_iter_children(model, &iter, NULL)) if (gtk_tree_model_iter_children(model, &iter, nullptr))
{ {
do do
{ {
@ -1084,7 +1084,7 @@ static gboolean on_torrent_metadata_changed_idle(gpointer gdata)
tr_torrent const* const tor = tr_torrentFindFromId(session, data->torrent_id); tr_torrent const* const tor = tr_torrentFindFromId(session, data->torrent_id);
/* update the torrent's collated name */ /* update the torrent's collated name */
if (tor != NULL) if (tor != nullptr)
{ {
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel* const model = core_raw_model(data->core); GtkTreeModel* const model = core_raw_model(data->core);
@ -1143,7 +1143,7 @@ static gboolean is_torrent_active(tr_stat const* st)
void gtr_core_add_torrent(TrCore* core, tr_torrent* tor, gboolean do_notify) void gtr_core_add_torrent(TrCore* core, tr_torrent* tor, gboolean do_notify)
{ {
if (tor != NULL) if (tor != nullptr)
{ {
GtkTreeIter unused; GtkTreeIter unused;
tr_stat const* st = tr_torrentStat(tor); tr_stat const* st = tr_torrentStat(tor);
@ -1190,21 +1190,21 @@ static tr_torrent* core_create_new_torrent(TrCore* core, tr_ctor* ctor)
* doesn't have any concept of the glib trash API */ * doesn't have any concept of the glib trash API */
tr_ctorGetDeleteSource(ctor, &do_trash); tr_ctorGetDeleteSource(ctor, &do_trash);
tr_ctorSetDeleteSource(ctor, FALSE); tr_ctorSetDeleteSource(ctor, FALSE);
tr_torrent* const tor = tr_torrentNew(ctor, NULL, NULL); tr_torrent* const tor = tr_torrentNew(ctor, nullptr, nullptr);
if (tor != NULL && do_trash) if (tor != nullptr && do_trash)
{ {
char const* config = tr_sessionGetConfigDir(session); char const* config = tr_sessionGetConfigDir(session);
char const* source = tr_ctorGetSourceFile(ctor); char const* source = tr_ctorGetSourceFile(ctor);
if (source != NULL) if (source != nullptr)
{ {
/* #1294: don't delete the .torrent file if it's our internal copy */ /* #1294: don't delete the .torrent file if it's our internal copy */
bool const is_internal = strstr(source, config) == source; bool const is_internal = strstr(source, config) == source;
if (!is_internal) if (!is_internal)
{ {
gtr_file_trash_or_remove(source, NULL); gtr_file_trash_or_remove(source, nullptr);
} }
} }
} }
@ -1226,7 +1226,7 @@ static int core_add_ctor(TrCore* core, tr_ctor* ctor, gboolean do_prompt, gboole
/* don't complain about .torrent files in the watch directory /* don't complain about .torrent files in the watch directory
* that have already been added... that gets annoying and we * that have already been added... that gets annoying and we
* don't want to be nagging users to clean up their watch dirs */ * don't want to be nagging users to clean up their watch dirs */
if (tr_ctorGetSourceFile(ctor) == NULL || !core->priv->adding_from_watch_dir) if (tr_ctorGetSourceFile(ctor) == nullptr || !core->priv->adding_from_watch_dir)
{ {
core_emit_err(core, static_cast<tr_core_err>(err), inf.name); core_emit_err(core, static_cast<tr_core_err>(err), inf.name);
} }
@ -1255,22 +1255,22 @@ static int core_add_ctor(TrCore* core, tr_ctor* ctor, gboolean do_prompt, gboole
static void core_apply_defaults(tr_ctor* ctor) static void core_apply_defaults(tr_ctor* ctor)
{ {
if (!tr_ctorGetPaused(ctor, TR_FORCE, NULL)) if (!tr_ctorGetPaused(ctor, TR_FORCE, nullptr))
{ {
tr_ctorSetPaused(ctor, TR_FORCE, !gtr_pref_flag_get(TR_KEY_start_added_torrents)); tr_ctorSetPaused(ctor, TR_FORCE, !gtr_pref_flag_get(TR_KEY_start_added_torrents));
} }
if (!tr_ctorGetDeleteSource(ctor, NULL)) if (!tr_ctorGetDeleteSource(ctor, nullptr))
{ {
tr_ctorSetDeleteSource(ctor, gtr_pref_flag_get(TR_KEY_trash_original_torrent_files)); tr_ctorSetDeleteSource(ctor, gtr_pref_flag_get(TR_KEY_trash_original_torrent_files));
} }
if (!tr_ctorGetPeerLimit(ctor, TR_FORCE, NULL)) if (!tr_ctorGetPeerLimit(ctor, TR_FORCE, nullptr))
{ {
tr_ctorSetPeerLimit(ctor, TR_FORCE, gtr_pref_int_get(TR_KEY_peer_limit_per_torrent)); tr_ctorSetPeerLimit(ctor, TR_FORCE, gtr_pref_int_get(TR_KEY_peer_limit_per_torrent));
} }
if (!tr_ctorGetDownloadDir(ctor, TR_FORCE, NULL)) if (!tr_ctorGetDownloadDir(ctor, TR_FORCE, nullptr))
{ {
tr_ctorSetDownloadDir(ctor, TR_FORCE, gtr_pref_string_get(TR_KEY_download_dir)); tr_ctorSetDownloadDir(ctor, TR_FORCE, gtr_pref_string_get(TR_KEY_download_dir));
} }
@ -1300,10 +1300,10 @@ static void add_file_async_callback(GObject* file, GAsyncResult* result, gpointe
{ {
gsize length; gsize length;
char* contents; char* contents;
GError* error = NULL; GError* error = nullptr;
auto* data = static_cast<add_from_url_data*>(gdata); auto* data = static_cast<add_from_url_data*>(gdata);
if (!g_file_load_contents_finish(G_FILE(file), result, &contents, &length, NULL, &error)) if (!g_file_load_contents_finish(G_FILE(file), result, &contents, &length, nullptr, &error))
{ {
g_message(_("Couldn't read \"%s\": %s"), g_file_get_parse_name(G_FILE(file)), error->message); g_message(_("Couldn't read \"%s\": %s"), g_file_get_parse_name(G_FILE(file)), error->message);
g_error_free(error); g_error_free(error);
@ -1326,7 +1326,7 @@ static bool add_file(TrCore* core, GFile* file, gboolean do_start, gboolean do_p
bool handled = false; bool handled = false;
tr_session const* const session = gtr_core_session(core); tr_session const* const session = gtr_core_session(core);
if (session != NULL) if (session != nullptr)
{ {
tr_ctor* ctor; tr_ctor* ctor;
bool tried = false; bool tried = false;
@ -1341,7 +1341,7 @@ static bool add_file(TrCore* core, GFile* file, gboolean do_start, gboolean do_p
{ {
char* str = g_file_get_path(file); char* str = g_file_get_path(file);
if ((tried = (str != NULL) && g_file_test(str, G_FILE_TEST_EXISTS))) if ((tried = (str != nullptr) && g_file_test(str, G_FILE_TEST_EXISTS)))
{ {
loaded = !tr_ctorSetMetainfoFromFile(ctor, str); loaded = !tr_ctorSetMetainfoFromFile(ctor, str);
} }
@ -1396,7 +1396,7 @@ static bool add_file(TrCore* core, GFile* file, gboolean do_start, gboolean do_p
handled = true; handled = true;
core_inc_busy(core); core_inc_busy(core);
g_file_load_contents_async(file, NULL, add_file_async_callback, data); g_file_load_contents_async(file, nullptr, add_file_async_callback, data);
} }
else else
{ {
@ -1425,7 +1425,7 @@ bool gtr_core_add_from_url(TrCore* core, char const* uri)
void gtr_core_add_files(TrCore* core, GSList* files, gboolean do_start, gboolean do_prompt, gboolean do_notify) void gtr_core_add_files(TrCore* core, GSList* files, gboolean do_start, gboolean do_prompt, gboolean do_notify)
{ {
for (GSList* l = files; l != NULL; l = l->next) for (GSList* l = files; l != nullptr; l = l->next)
{ {
add_file(core, static_cast<GFile*>(l->data), do_start, do_prompt, do_notify); add_file(core, static_cast<GFile*>(l->data), do_start, do_prompt, do_notify);
} }
@ -1436,7 +1436,7 @@ void gtr_core_add_files(TrCore* core, GSList* files, gboolean do_start, gboolean
void gtr_core_torrents_added(TrCore* self) void gtr_core_torrents_added(TrCore* self)
{ {
gtr_core_update(self); gtr_core_update(self);
core_emit_err(self, TR_CORE_ERR_NO_MORE_TORRENTS, NULL); core_emit_err(self, TR_CORE_ERR_NO_MORE_TORRENTS, nullptr);
} }
void gtr_core_torrent_changed(TrCore* self, int id) void gtr_core_torrent_changed(TrCore* self, int id)
@ -1455,7 +1455,7 @@ void gtr_core_remove_torrent(TrCore* core, int id, gboolean delete_local_data)
{ {
tr_torrent* tor = gtr_core_find_torrent(core, id); tr_torrent* tor = gtr_core_find_torrent(core, id);
if (tor != NULL) if (tor != nullptr)
{ {
/* remove from the gui */ /* remove from the gui */
GtkTreeIter iter; GtkTreeIter iter;
@ -1632,7 +1632,7 @@ void gtr_core_update(TrCore* core)
/* update the model */ /* update the model */
model = core_raw_model(core); model = core_raw_model(core);
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, 0))
{ {
do do
{ {
@ -1657,13 +1657,13 @@ static gboolean gtr_inhibit_hibernation(guint* cookie)
gboolean success; gboolean success;
GVariant* response; GVariant* response;
GDBusConnection* connection; GDBusConnection* connection;
GError* err = NULL; GError* err = nullptr;
char const* application = "Transmission BitTorrent Client"; char const* application = "Transmission BitTorrent Client";
char const* reason = "BitTorrent Activity"; char const* reason = "BitTorrent Activity";
int const toplevel_xid = 0; int const toplevel_xid = 0;
int const flags = 4; /* Inhibit suspending the session or computer */ int const flags = 4; /* Inhibit suspending the session or computer */
connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &err); connection = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &err);
response = g_dbus_connection_call_sync( response = g_dbus_connection_call_sync(
connection, connection,
@ -1672,18 +1672,18 @@ static gboolean gtr_inhibit_hibernation(guint* cookie)
SESSION_MANAGER_INTERFACE, SESSION_MANAGER_INTERFACE,
"Inhibit", "Inhibit",
g_variant_new("(susu)", application, toplevel_xid, reason, flags), g_variant_new("(susu)", application, toplevel_xid, reason, flags),
NULL, nullptr,
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
1000, 1000,
NULL, nullptr,
&err); &err);
if (response != NULL) if (response != nullptr)
{ {
*cookie = g_variant_get_uint32(g_variant_get_child_value(response, 0)); *cookie = g_variant_get_uint32(g_variant_get_child_value(response, 0));
} }
success = response != NULL && err == NULL; success = response != nullptr && err == nullptr;
/* logging */ /* logging */
if (success) if (success)
@ -1697,12 +1697,12 @@ static gboolean gtr_inhibit_hibernation(guint* cookie)
} }
/* cleanup */ /* cleanup */
if (response != NULL) if (response != nullptr)
{ {
g_variant_unref(response); g_variant_unref(response);
} }
if (connection != NULL) if (connection != nullptr)
{ {
g_object_unref(connection); g_object_unref(connection);
} }
@ -1714,9 +1714,9 @@ static void gtr_uninhibit_hibernation(guint inhibit_cookie)
{ {
GVariant* response; GVariant* response;
GDBusConnection* connection; GDBusConnection* connection;
GError* err = NULL; GError* err = nullptr;
connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &err); connection = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &err);
response = g_dbus_connection_call_sync( response = g_dbus_connection_call_sync(
connection, connection,
@ -1725,14 +1725,14 @@ static void gtr_uninhibit_hibernation(guint inhibit_cookie)
SESSION_MANAGER_INTERFACE, SESSION_MANAGER_INTERFACE,
"Uninhibit", "Uninhibit",
g_variant_new("(u)", inhibit_cookie), g_variant_new("(u)", inhibit_cookie),
NULL, nullptr,
G_DBUS_CALL_FLAGS_NONE, G_DBUS_CALL_FLAGS_NONE,
1000, 1000,
NULL, nullptr,
&err); &err);
/* logging */ /* logging */
if (err == NULL) if (err == nullptr)
{ {
tr_logAddInfo("%s", _("Allowing desktop hibernation")); tr_logAddInfo("%s", _("Allowing desktop hibernation"));
} }
@ -1848,7 +1848,7 @@ struct pending_request_data
gpointer response_func_user_data; gpointer response_func_user_data;
}; };
static GHashTable* pendingRequests = NULL; static GHashTable* pendingRequests = nullptr;
static gboolean core_read_rpc_response_idle(void* vresponse) static gboolean core_read_rpc_response_idle(void* vresponse)
{ {
@ -1860,9 +1860,9 @@ static gboolean core_read_rpc_response_idle(void* vresponse)
int const tag = (int)intVal; int const tag = (int)intVal;
auto* data = static_cast<pending_request_data*>(g_hash_table_lookup(pendingRequests, &tag)); auto* data = static_cast<pending_request_data*>(g_hash_table_lookup(pendingRequests, &tag));
if (data != NULL) if (data != nullptr)
{ {
if (data->response_func != NULL) if (data->response_func != nullptr)
{ {
(*data->response_func)(data->core, response, data->response_func_user_data); (*data->response_func)(data->core, response, data->response_func_user_data);
} }
@ -1898,12 +1898,12 @@ static void core_send_rpc_request(
{ {
tr_session* session = gtr_core_session(core); tr_session* session = gtr_core_session(core);
if (pendingRequests == NULL) if (pendingRequests == nullptr)
{ {
pendingRequests = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free); pendingRequests = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
} }
if (session == NULL) if (session == nullptr)
{ {
g_error("GTK+ client doesn't support connections to remote servers yet."); g_error("GTK+ client doesn't support connections to remote servers yet.");
} }
@ -1960,7 +1960,7 @@ void gtr_core_port_test(TrCore* core)
tr_variantInitDict(&request, 2); tr_variantInitDict(&request, 2);
tr_variantDictAddStr(&request, TR_KEY_method, "port-test"); tr_variantDictAddStr(&request, TR_KEY_method, "port-test");
tr_variantDictAddInt(&request, TR_KEY_tag, tag); tr_variantDictAddInt(&request, TR_KEY_tag, tag);
core_send_rpc_request(core, &request, tag, on_port_test_response, NULL); core_send_rpc_request(core, &request, tag, on_port_test_response, nullptr);
tr_variantFree(&request); tr_variantFree(&request);
} }
@ -1998,7 +1998,7 @@ void gtr_core_blocklist_update(TrCore* core)
tr_variantInitDict(&request, 2); tr_variantInitDict(&request, 2);
tr_variantDictAddStr(&request, TR_KEY_method, "blocklist-update"); tr_variantDictAddStr(&request, TR_KEY_method, "blocklist-update");
tr_variantDictAddInt(&request, TR_KEY_tag, tag); tr_variantDictAddInt(&request, TR_KEY_tag, tag);
core_send_rpc_request(core, &request, tag, on_blocklist_response, NULL); core_send_rpc_request(core, &request, tag, on_blocklist_response, nullptr);
tr_variantFree(&request); tr_variantFree(&request);
} }
@ -2011,7 +2011,7 @@ void gtr_core_exec(TrCore* core, tr_variant const* top)
int const tag = nextTag; int const tag = nextTag;
++nextTag; ++nextTag;
core_send_rpc_request(core, top, tag, NULL, NULL); core_send_rpc_request(core, top, tag, nullptr, nullptr);
} }
/*** /***
@ -2020,7 +2020,7 @@ void gtr_core_exec(TrCore* core, tr_variant const* top)
size_t gtr_core_get_torrent_count(TrCore* core) size_t gtr_core_get_torrent_count(TrCore* core)
{ {
return gtk_tree_model_iter_n_children(core_raw_model(core), NULL); return gtk_tree_model_iter_n_children(core_raw_model(core), nullptr);
} }
size_t gtr_core_get_active_torrent_count(TrCore* core) size_t gtr_core_get_active_torrent_count(TrCore* core)
@ -2029,7 +2029,7 @@ size_t gtr_core_get_active_torrent_count(TrCore* core)
size_t activeCount = 0; size_t activeCount = 0;
GtkTreeModel* model = core_raw_model(core); GtkTreeModel* model = core_raw_model(core);
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, 0))
{ {
do do
{ {
@ -2049,9 +2049,9 @@ size_t gtr_core_get_active_torrent_count(TrCore* core)
tr_torrent* gtr_core_find_torrent(TrCore* core, int id) tr_torrent* gtr_core_find_torrent(TrCore* core, int id)
{ {
tr_session* session; tr_session* session;
tr_torrent* tor = NULL; tr_torrent* tor = nullptr;
if ((session = gtr_core_session(core)) != NULL) if ((session = gtr_core_session(core)) != nullptr)
{ {
tor = tr_torrentFindFromId(session, id); tor = tr_torrentFindFromId(session, id);
} }
@ -2063,7 +2063,7 @@ void gtr_core_open_folder(TrCore* core, int torrent_id)
{ {
tr_torrent const* tor = gtr_core_find_torrent(core, torrent_id); tr_torrent const* tor = gtr_core_find_torrent(core, torrent_id);
if (tor != NULL) if (tor != nullptr)
{ {
gboolean const single = tr_torrentInfo(tor)->fileCount == 1; gboolean const single = tr_torrentInfo(tor)->fileCount == 1;
char const* currentDir = tr_torrentGetCurrentDir(tor); char const* currentDir = tr_torrentGetCurrentDir(tor);
@ -2074,7 +2074,7 @@ void gtr_core_open_folder(TrCore* core, int torrent_id)
} }
else else
{ {
char* path = g_build_filename(currentDir, tr_torrentName(tor), NULL); char* path = g_build_filename(currentDir, tr_torrentName(tor), nullptr);
gtr_open_file(path); gtr_open_file(path);
g_free(path); g_free(path);
} }

View File

@ -45,13 +45,13 @@ static void popup(GtkStatusIcon* self, guint button, guint when, gpointer data)
GtkWidget* w = gtr_action_get_widget("/icon-popup"); GtkWidget* w = gtr_action_get_widget("/icon-popup");
#if GTK_CHECK_VERSION(3, 22, 0) #if GTK_CHECK_VERSION(3, 22, 0)
gtk_menu_popup_at_pointer(GTK_MENU(w), NULL); gtk_menu_popup_at_pointer(GTK_MENU(w), nullptr);
TR_UNUSED(self); TR_UNUSED(self);
TR_UNUSED(button); TR_UNUSED(button);
TR_UNUSED(when); TR_UNUSED(when);
#else #else
gtk_menu_popup(GTK_MENU(w), NULL, NULL, gtk_status_icon_position_menu, self, button, when); gtk_menu_popup(GTK_MENU(w), nullptr, nullptr, gtk_status_icon_position_menu, self, button, when);
#endif #endif
} }
@ -138,7 +138,7 @@ static char const* getIconName(void)
else else
{ {
GtkIconInfo* icon_info = gtk_icon_theme_lookup_icon(theme, TRAY_ICON, 48, GTK_ICON_LOOKUP_USE_BUILTIN); GtkIconInfo* icon_info = gtk_icon_theme_lookup_icon(theme, TRAY_ICON, 48, GTK_ICON_LOOKUP_USE_BUILTIN);
gboolean const icon_is_builtin = gtk_icon_info_get_filename(icon_info) == NULL; gboolean const icon_is_builtin = gtk_icon_info_get_filename(icon_info) == nullptr;
#if GTK_CHECK_VERSION(3, 8, 0) #if GTK_CHECK_VERSION(3, 8, 0)
g_object_unref(icon_info); g_object_unref(icon_info);
@ -170,8 +170,8 @@ gpointer gtr_icon_new(TrCore* core)
char const* icon_name = getIconName(); char const* icon_name = getIconName();
GtkStatusIcon* icon = gtk_status_icon_new_from_icon_name(icon_name); GtkStatusIcon* icon = gtk_status_icon_new_from_icon_name(icon_name);
g_signal_connect(icon, "activate", G_CALLBACK(activated), NULL); g_signal_connect(icon, "activate", G_CALLBACK(activated), nullptr);
g_signal_connect(icon, "popup-menu", G_CALLBACK(popup), NULL); g_signal_connect(icon, "popup-menu", G_CALLBACK(popup), nullptr);
g_object_set_qdata(G_OBJECT(icon), core_quark(), core); g_object_set_qdata(G_OBJECT(icon), core_quark(), core);
return icon; return icon;

View File

@ -48,7 +48,7 @@ static void response_cb(GtkDialog* dialog, int response, gpointer user_data)
if (response == GTK_RESPONSE_HELP) if (response == GTK_RESPONSE_HELP)
{ {
char* uri = g_strconcat(gtr_get_help_uri(), "/html/preferences.html", NULL); char* uri = g_strconcat(gtr_get_help_uri(), "/html/preferences.html", nullptr);
gtr_open_uri(uri); gtr_open_uri(uri);
g_free(uri); g_free(uri);
} }
@ -100,7 +100,7 @@ static gboolean spun_cb_idle(gpointer spin)
auto* data = static_cast<spin_idle_data*>(g_object_get_data(o, IDLE_DATA)); auto* data = static_cast<spin_idle_data*>(g_object_get_data(o, IDLE_DATA));
/* has the user stopped making changes? */ /* has the user stopped making changes? */
if (g_timer_elapsed(data->last_change, NULL) > 0.33) if (g_timer_elapsed(data->last_change, nullptr) > 0.33)
{ {
/* update the core */ /* update the core */
tr_quark const key = GPOINTER_TO_INT(g_object_get_data(o, PREF_KEY)); tr_quark const key = GPOINTER_TO_INT(g_object_get_data(o, PREF_KEY));
@ -117,7 +117,7 @@ static gboolean spun_cb_idle(gpointer spin)
} }
/* cleanup */ /* cleanup */
g_object_set_data(o, IDLE_DATA, NULL); g_object_set_data(o, IDLE_DATA, nullptr);
keep_waiting = FALSE; keep_waiting = FALSE;
g_object_unref(G_OBJECT(o)); g_object_unref(G_OBJECT(o));
} }
@ -132,7 +132,7 @@ static void spun_cb(GtkSpinButton* w, gpointer core, gboolean isDouble)
GObject* o = G_OBJECT(w); GObject* o = G_OBJECT(w);
auto* data = static_cast<spin_idle_data*>(g_object_get_data(o, IDLE_DATA)); auto* data = static_cast<spin_idle_data*>(g_object_get_data(o, IDLE_DATA));
if (data == NULL) if (data == nullptr)
{ {
data = g_new(struct spin_idle_data, 1); data = g_new(struct spin_idle_data, 1);
data->core = core; data->core = core;
@ -189,7 +189,7 @@ static GtkWidget* new_entry(tr_quark const key, gpointer core)
GtkWidget* w = gtk_entry_new(); GtkWidget* w = gtk_entry_new();
char const* value = gtr_pref_string_get(key); char const* value = gtr_pref_string_get(key);
if (value != NULL) if (value != nullptr)
{ {
gtk_entry_set_text(GTK_ENTRY(w), value); gtk_entry_set_text(GTK_ENTRY(w), value);
} }
@ -209,11 +209,11 @@ static void chosen_cb(GtkFileChooser* w, gpointer core)
static GtkWidget* new_path_chooser_button(tr_quark const key, gpointer core) static GtkWidget* new_path_chooser_button(tr_quark const key, gpointer core)
{ {
GtkWidget* w = gtk_file_chooser_button_new(NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); GtkWidget* w = gtk_file_chooser_button_new(nullptr, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
char const* path = gtr_pref_string_get(key); char const* path = gtr_pref_string_get(key);
g_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key)); g_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
if (path != NULL) if (path != nullptr)
{ {
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(w), path); gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(w), path);
} }
@ -224,11 +224,11 @@ static GtkWidget* new_path_chooser_button(tr_quark const key, gpointer core)
static GtkWidget* new_file_chooser_button(tr_quark const key, gpointer core) static GtkWidget* new_file_chooser_button(tr_quark const key, gpointer core)
{ {
GtkWidget* w = gtk_file_chooser_button_new(NULL, GTK_FILE_CHOOSER_ACTION_OPEN); GtkWidget* w = gtk_file_chooser_button_new(nullptr, GTK_FILE_CHOOSER_ACTION_OPEN);
char const* path = gtr_pref_string_get(key); char const* path = gtr_pref_string_get(key);
g_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key)); g_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
if (path != NULL) if (path != nullptr)
{ {
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(w), path); gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(w), path);
} }
@ -264,7 +264,7 @@ static GtkWidget* downloadingPage(GObject* core, struct prefs_dialog_data* data)
w = new_path_chooser_button(TR_KEY_watch_dir, 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)); 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); g_signal_connect(l, "toggled", G_CALLBACK(target_cb), w);
hig_workarea_add_row_w(t, &row, l, w, NULL); hig_workarea_add_row_w(t, &row, l, w, nullptr);
s = _("Show the Torrent Options _dialog"); s = _("Show the Torrent Options _dialog");
w = new_check_button(s, TR_KEY_show_options_window, core); w = new_check_button(s, TR_KEY_show_options_window, core);
@ -279,10 +279,10 @@ static GtkWidget* downloadingPage(GObject* core, struct prefs_dialog_data* data)
hig_workarea_add_wide_control(t, &row, w); hig_workarea_add_wide_control(t, &row, w);
w = new_path_chooser_button(TR_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_row(t, &row, _("Save to _Location:"), w, nullptr);
l = data->freespace_label = gtr_freespace_label_new(TR_CORE(core), NULL); l = data->freespace_label = gtr_freespace_label_new(TR_CORE(core), nullptr);
g_object_set(l, "halign", GTK_ALIGN_END, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(l, "halign", GTK_ALIGN_END, "valign", GTK_ALIGN_CENTER, nullptr);
hig_workarea_add_wide_control(t, &row, l); hig_workarea_add_wide_control(t, &row, l);
hig_workarea_add_section_divider(t, &row); hig_workarea_add_section_divider(t, &row);
@ -290,11 +290,11 @@ static GtkWidget* downloadingPage(GObject* core, struct prefs_dialog_data* data)
s = _("Ma_ximum active downloads:"); s = _("Ma_ximum active downloads:");
w = new_spin_button(TR_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); hig_workarea_add_row(t, &row, s, w, nullptr);
s = _("Downloads sharing data in the last _N minutes are active:"); s = _("Downloads sharing data in the last _N minutes are active:");
w = new_spin_button(TR_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_row(t, &row, s, w, nullptr);
hig_workarea_add_section_divider(t, &row); hig_workarea_add_section_divider(t, &row);
hig_workarea_add_section_title(t, &row, _("Incomplete")); hig_workarea_add_section_title(t, &row, _("Incomplete"));
@ -308,14 +308,14 @@ static GtkWidget* downloadingPage(GObject* core, struct prefs_dialog_data* data)
w = new_path_chooser_button(TR_KEY_incomplete_dir, 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)); 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); g_signal_connect(l, "toggled", G_CALLBACK(target_cb), w);
hig_workarea_add_row_w(t, &row, l, w, NULL); hig_workarea_add_row_w(t, &row, l, w, nullptr);
s = _("Call scrip_t when torrent is completed:"); s = _("Call scrip_t when torrent is completed:");
l = new_check_button(s, TR_KEY_script_torrent_done_enabled, core); l = new_check_button(s, TR_KEY_script_torrent_done_enabled, core);
w = new_file_chooser_button(TR_KEY_script_torrent_done_filename, 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)); 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); g_signal_connect(l, "toggled", G_CALLBACK(target_cb), w);
hig_workarea_add_row_w(t, &row, l, w, NULL); hig_workarea_add_row_w(t, &row, l, w, nullptr);
return t; return t;
} }
@ -340,14 +340,14 @@ static GtkWidget* seedingPage(GObject* core)
w2 = new_spin_button_double(TR_KEY_ratio_limit, core, 0, 1000, .05); 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)); 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); g_signal_connect(w, "toggled", G_CALLBACK(target_cb), w2);
hig_workarea_add_row_w(t, &row, w, w2, NULL); hig_workarea_add_row_w(t, &row, w, w2, nullptr);
s = _("Stop seeding if idle for _N minutes:"); s = _("Stop seeding if idle for _N minutes:");
w = new_check_button(s, TR_KEY_idle_seeding_limit_enabled, core); w = new_check_button(s, TR_KEY_idle_seeding_limit_enabled, core);
w2 = new_spin_button(TR_KEY_idle_seeding_limit, core, 1, 40320, 5); w2 = new_spin_button(TR_KEY_idle_seeding_limit, core, 1, 40320, 5);
gtk_widget_set_sensitive(GTK_WIDGET(w2), gtr_pref_flag_get(TR_KEY_idle_seeding_limit_enabled)); 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); g_signal_connect(w, "toggled", G_CALLBACK(target_cb), w2);
hig_workarea_add_row_w(t, &row, w, w2, NULL); hig_workarea_add_row_w(t, &row, w, w2, nullptr);
return t; return t;
} }
@ -439,7 +439,7 @@ static void onBlocklistUpdateResponse(GtkDialog* dialog, gint response, gpointer
auto* data = static_cast<blocklist_data*>(gdata); auto* data = static_cast<blocklist_data*>(gdata);
gtk_widget_destroy(GTK_WIDGET(dialog)); gtk_widget_destroy(GTK_WIDGET(dialog));
gtk_widget_set_sensitive(data->updateBlocklistButton, TRUE); gtk_widget_set_sensitive(data->updateBlocklistButton, TRUE);
data->updateBlocklistDialog = NULL; data->updateBlocklistDialog = nullptr;
g_signal_handler_disconnect(data->core, data->updateBlocklistTag); g_signal_handler_disconnect(data->core, data->updateBlocklistTag);
data->updateBlocklistTag = 0; data->updateBlocklistTag = 0;
} }
@ -482,7 +482,7 @@ static void onBlocklistUpdate(GtkButton* w, gpointer gdata)
static void on_blocklist_url_changed(GtkEditable* e, gpointer gbutton) static void on_blocklist_url_changed(GtkEditable* e, gpointer gbutton)
{ {
gchar* url = gtk_editable_get_chars(e, 0, -1); gchar* url = gtk_editable_get_chars(e, 0, -1);
gboolean const is_url_valid = tr_urlParse(url, TR_BAD_SIZE, NULL, NULL, NULL, NULL); gboolean const is_url_valid = tr_urlParse(url, TR_BAD_SIZE, nullptr, nullptr, nullptr, nullptr);
gtk_widget_set_sensitive(GTK_WIDGET(gbutton), is_url_valid); gtk_widget_set_sensitive(GTK_WIDGET(gbutton), is_url_valid);
g_free(url); g_free(url);
} }
@ -500,7 +500,7 @@ static GtkWidget* new_encryption_combo(GObject* core, tr_quark const key)
TR_ARG_TUPLE(_("Allow encryption"), TR_CLEAR_PREFERRED), TR_ARG_TUPLE(_("Allow encryption"), TR_CLEAR_PREFERRED),
TR_ARG_TUPLE(_("Prefer encryption"), TR_ENCRYPTION_PREFERRED), TR_ARG_TUPLE(_("Prefer encryption"), TR_ENCRYPTION_PREFERRED),
TR_ARG_TUPLE(_("Require encryption"), TR_ENCRYPTION_REQUIRED), TR_ARG_TUPLE(_("Require encryption"), TR_ENCRYPTION_REQUIRED),
NULL); nullptr);
gtr_combo_box_set_active_enum(GTK_COMBO_BOX(w), gtr_pref_int_get(key)); 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_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
g_signal_connect(w, "changed", G_CALLBACK(onIntComboChanged), core); g_signal_connect(w, "changed", G_CALLBACK(onIntComboChanged), core);
@ -526,7 +526,7 @@ static GtkWidget* privacyPage(GObject* core)
s = _("_Encryption mode:"); s = _("_Encryption mode:");
w = new_encryption_combo(core, TR_KEY_encryption); w = new_encryption_combo(core, TR_KEY_encryption);
hig_workarea_add_row(t, &row, s, w, NULL); hig_workarea_add_row(t, &row, s, w, nullptr);
hig_workarea_add_section_divider(t, &row); hig_workarea_add_section_divider(t, &row);
hig_workarea_add_section_title(t, &row, _("Blocklist")); hig_workarea_add_section_title(t, &row, _("Blocklist"));
@ -534,13 +534,13 @@ static GtkWidget* privacyPage(GObject* core)
b = new_check_button(_("Enable _blocklist:"), TR_KEY_blocklist_enabled, core); b = new_check_button(_("Enable _blocklist:"), TR_KEY_blocklist_enabled, core);
e = new_entry(TR_KEY_blocklist_url, core); e = new_entry(TR_KEY_blocklist_url, core);
gtk_widget_set_size_request(e, 300, -1); gtk_widget_set_size_request(e, 300, -1);
hig_workarea_add_row_w(t, &row, b, e, NULL); hig_workarea_add_row_w(t, &row, b, e, nullptr);
data->check = b; data->check = b;
g_signal_connect(b, "toggled", G_CALLBACK(target_cb), e); g_signal_connect(b, "toggled", G_CALLBACK(target_cb), e);
target_cb(b, e); target_cb(b, e);
w = gtk_label_new(""); w = gtk_label_new("");
g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
updateBlocklistText(w, TR_CORE(core)); updateBlocklistText(w, TR_CORE(core));
data->label = w; data->label = w;
h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG); h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
@ -584,7 +584,7 @@ static GtkTreeModel* whitelist_tree_model_new(char const* whitelist)
rules = g_strsplit(whitelist, ",", 0); rules = g_strsplit(whitelist, ",", 0);
for (int i = 0; rules != NULL && rules[i] != NULL; ++i) for (int i = 0; rules != nullptr && rules[i] != nullptr; ++i)
{ {
GtkTreeIter iter; GtkTreeIter iter;
char const* s = rules[i]; char const* s = rules[i];
@ -619,10 +619,10 @@ struct remote_page
static void refreshWhitelist(struct remote_page* page) static void refreshWhitelist(struct remote_page* page)
{ {
GtkTreeIter iter; GtkTreeIter iter;
GString* gstr = g_string_new(NULL); GString* gstr = g_string_new(nullptr);
GtkTreeModel* model = GTK_TREE_MODEL(page->store); GtkTreeModel* model = GTK_TREE_MODEL(page->store);
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, 0))
{ {
do do
{ {
@ -683,7 +683,7 @@ static void onRemoveWhitelistClicked(GtkButton const* b, gpointer gpage)
GtkTreeSelection* sel = gtk_tree_view_get_selection(page->view); GtkTreeSelection* sel = gtk_tree_view_get_selection(page->view);
GtkTreeIter iter; GtkTreeIter iter;
if (gtk_tree_selection_get_selected(sel, NULL, &iter)) if (gtk_tree_selection_get_selected(sel, nullptr, &iter))
{ {
gtk_list_store_remove(page->store, &iter); gtk_list_store_remove(page->store, &iter);
refreshWhitelist(page); refreshWhitelist(page);
@ -696,20 +696,20 @@ static void refreshRPCSensitivity(struct remote_page* page)
int const auth_active = gtk_toggle_button_get_active(page->auth_tb); int const auth_active = gtk_toggle_button_get_active(page->auth_tb);
int const whitelist_active = gtk_toggle_button_get_active(page->whitelist_tb); int const whitelist_active = gtk_toggle_button_get_active(page->whitelist_tb);
GtkTreeSelection* sel = gtk_tree_view_get_selection(page->view); GtkTreeSelection* sel = gtk_tree_view_get_selection(page->view);
int const have_addr = gtk_tree_selection_get_selected(sel, NULL, NULL); int const have_addr = gtk_tree_selection_get_selected(sel, nullptr, nullptr);
int const n_rules = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(page->store), NULL); int const n_rules = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(page->store), nullptr);
for (GSList* l = page->widgets; l != NULL; l = l->next) for (GSList* l = page->widgets; l != nullptr; l = l->next)
{ {
gtk_widget_set_sensitive(GTK_WIDGET(l->data), rpc_active); gtk_widget_set_sensitive(GTK_WIDGET(l->data), rpc_active);
} }
for (GSList* l = page->auth_widgets; l != NULL; l = l->next) for (GSList* l = page->auth_widgets; l != nullptr; l = l->next)
{ {
gtk_widget_set_sensitive(GTK_WIDGET(l->data), rpc_active && auth_active); gtk_widget_set_sensitive(GTK_WIDGET(l->data), rpc_active && auth_active);
} }
for (GSList* l = page->whitelist_widgets; l != NULL; l = l->next) for (GSList* l = page->whitelist_widgets; l != nullptr; l = l->next)
{ {
gtk_widget_set_sensitive(GTK_WIDGET(l->data), rpc_active && whitelist_active); gtk_widget_set_sensitive(GTK_WIDGET(l->data), rpc_active && whitelist_active);
} }
@ -779,14 +779,14 @@ static GtkWidget* remotePage(GObject* core)
gtk_box_pack_start(GTK_BOX(h), w, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(h), w, TRUE, TRUE, 0);
w = gtk_button_new_with_mnemonic(_("_Open web client")); w = gtk_button_new_with_mnemonic(_("_Open web client"));
page->widgets = g_slist_prepend(page->widgets, w); page->widgets = g_slist_prepend(page->widgets, w);
g_signal_connect(w, "clicked", G_CALLBACK(onLaunchClutchCB), NULL); g_signal_connect(w, "clicked", G_CALLBACK(onLaunchClutchCB), nullptr);
gtk_box_pack_start(GTK_BOX(h), w, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(h), w, FALSE, FALSE, 0);
hig_workarea_add_wide_control(t, &row, h); hig_workarea_add_wide_control(t, &row, h);
/* port */ /* port */
w = new_spin_button(TR_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); page->widgets = g_slist_prepend(page->widgets, w);
w = hig_workarea_add_row(t, &row, _("HTTP _port:"), w, NULL); w = hig_workarea_add_row(t, &row, _("HTTP _port:"), w, nullptr);
page->widgets = g_slist_prepend(page->widgets, w); page->widgets = g_slist_prepend(page->widgets, w);
/* require authentication */ /* require authentication */
@ -801,7 +801,7 @@ static GtkWidget* remotePage(GObject* core)
s = _("_Username:"); s = _("_Username:");
w = new_entry(TR_KEY_rpc_username, core); w = new_entry(TR_KEY_rpc_username, core);
page->auth_widgets = g_slist_prepend(page->auth_widgets, w); page->auth_widgets = g_slist_prepend(page->auth_widgets, w);
w = hig_workarea_add_row(t, &row, s, w, NULL); w = hig_workarea_add_row(t, &row, s, w, nullptr);
page->auth_widgets = g_slist_prepend(page->auth_widgets, w); page->auth_widgets = g_slist_prepend(page->auth_widgets, w);
/* password */ /* password */
@ -809,7 +809,7 @@ static GtkWidget* remotePage(GObject* core)
w = new_entry(TR_KEY_rpc_password, core); w = new_entry(TR_KEY_rpc_password, core);
gtk_entry_set_visibility(GTK_ENTRY(w), FALSE); gtk_entry_set_visibility(GTK_ENTRY(w), FALSE);
page->auth_widgets = g_slist_prepend(page->auth_widgets, w); page->auth_widgets = g_slist_prepend(page->auth_widgets, w);
w = hig_workarea_add_row(t, &row, s, w, NULL); w = hig_workarea_add_row(t, &row, s, w, nullptr);
page->auth_widgets = g_slist_prepend(page->auth_widgets, w); page->auth_widgets = g_slist_prepend(page->auth_widgets, w);
/* require authentication */ /* require authentication */
@ -831,7 +831,7 @@ static GtkWidget* remotePage(GObject* core)
page->store = GTK_LIST_STORE(m); page->store = GTK_LIST_STORE(m);
w = gtk_tree_view_new_with_model(m); w = gtk_tree_view_new_with_model(m);
g_signal_connect(w, "button-release-event", G_CALLBACK(on_tree_view_button_released), NULL); g_signal_connect(w, "button-release-event", G_CALLBACK(on_tree_view_button_released), nullptr);
page->whitelist_widgets = g_slist_prepend(page->whitelist_widgets, w); page->whitelist_widgets = g_slist_prepend(page->whitelist_widgets, w);
v = page->view = GTK_TREE_VIEW(w); v = page->view = GTK_TREE_VIEW(w);
@ -840,28 +840,28 @@ static GtkWidget* remotePage(GObject* core)
g_signal_connect(sel, "changed", G_CALLBACK(onWhitelistSelectionChanged), page); g_signal_connect(sel, "changed", G_CALLBACK(onWhitelistSelectionChanged), page);
g_object_unref(G_OBJECT(m)); g_object_unref(G_OBJECT(m));
gtk_tree_view_set_headers_visible(v, TRUE); gtk_tree_view_set_headers_visible(v, TRUE);
w = gtk_frame_new(NULL); w = gtk_frame_new(nullptr);
gtk_frame_set_shadow_type(GTK_FRAME(w), GTK_SHADOW_IN); gtk_frame_set_shadow_type(GTK_FRAME(w), GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(w), GTK_WIDGET(v)); gtk_container_add(GTK_CONTAINER(w), GTK_WIDGET(v));
/* ip address column */ /* ip address column */
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
g_signal_connect(r, "edited", G_CALLBACK(onAddressEdited), page); g_signal_connect(r, "edited", G_CALLBACK(onAddressEdited), page);
g_object_set(G_OBJECT(r), "editable", TRUE, NULL); g_object_set(G_OBJECT(r), "editable", TRUE, nullptr);
c = gtk_tree_view_column_new_with_attributes(NULL, r, "text", COL_ADDRESS, NULL); c = gtk_tree_view_column_new_with_attributes(nullptr, r, "text", COL_ADDRESS, nullptr);
gtk_tree_view_column_set_expand(c, TRUE); gtk_tree_view_column_set_expand(c, TRUE);
gtk_tree_view_append_column(v, c); gtk_tree_view_append_column(v, c);
gtk_tree_view_set_headers_visible(v, FALSE); gtk_tree_view_set_headers_visible(v, FALSE);
s = _("Addresses:"); s = _("Addresses:");
w = hig_workarea_add_row(t, &row, s, w, NULL); w = hig_workarea_add_row(t, &row, s, w, nullptr);
g_object_set( g_object_set(
w, w,
TR_ARG_TUPLE("halign", GTK_ALIGN_START), TR_ARG_TUPLE("halign", GTK_ALIGN_START),
TR_ARG_TUPLE("valign", GTK_ALIGN_START), TR_ARG_TUPLE("valign", GTK_ALIGN_START),
TR_ARG_TUPLE("margin-top", GUI_PAD), TR_ARG_TUPLE("margin-top", GUI_PAD),
TR_ARG_TUPLE("margin-bottom", GUI_PAD), TR_ARG_TUPLE("margin-bottom", GUI_PAD),
NULL); nullptr);
page->whitelist_widgets = g_slist_prepend(page->whitelist_widgets, w); page->whitelist_widgets = g_slist_prepend(page->whitelist_widgets, w);
h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD); h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
@ -873,7 +873,7 @@ static GtkWidget* remotePage(GObject* core)
w = gtk_button_new_with_mnemonic(_("_Add")); w = gtk_button_new_with_mnemonic(_("_Add"));
page->whitelist_widgets = g_slist_prepend(page->whitelist_widgets, w); page->whitelist_widgets = g_slist_prepend(page->whitelist_widgets, w);
g_signal_connect(w, "clicked", G_CALLBACK(onAddWhitelistClicked), page); g_signal_connect(w, "clicked", G_CALLBACK(onAddWhitelistClicked), page);
g_object_set(h, "halign", GTK_ALIGN_END, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(h, "halign", GTK_ALIGN_END, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_box_pack_start(GTK_BOX(h), w, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(h), w, TRUE, TRUE, 0);
hig_workarea_add_wide_control(t, &row, h); hig_workarea_add_wide_control(t, &row, h);
} }
@ -896,7 +896,7 @@ static void refreshSchedSensitivity(struct BandwidthPage* p)
{ {
gboolean const sched_enabled = gtr_pref_flag_get(TR_KEY_alt_speed_time_enabled); gboolean const sched_enabled = gtr_pref_flag_get(TR_KEY_alt_speed_time_enabled);
for (GSList* l = p->sched_widgets; l != NULL; l = l->next) for (GSList* l = p->sched_widgets; l != nullptr; l = l->next)
{ {
gtk_widget_set_sensitive(GTK_WIDGET(l->data), sched_enabled); gtk_widget_set_sensitive(GTK_WIDGET(l->data), sched_enabled);
} }
@ -946,7 +946,7 @@ static GtkWidget* new_time_combo(GObject* core, tr_quark const key)
gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(w), 4); gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(w), 4);
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(w), r, TRUE); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(w), r, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(w), r, "text", 1, NULL); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(w), r, "text", 1, nullptr);
g_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key)); g_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
val = gtr_pref_int_get(key); val = gtr_pref_int_get(key);
gtk_combo_box_set_active(GTK_COMBO_BOX(w), val / (15)); gtk_combo_box_set_active(GTK_COMBO_BOX(w), val / (15));
@ -970,7 +970,7 @@ static GtkWidget* new_week_combo(GObject* core, tr_quark const key)
TR_ARG_TUPLE(_("Thursday"), TR_SCHED_THURS), TR_ARG_TUPLE(_("Thursday"), TR_SCHED_THURS),
TR_ARG_TUPLE(_("Friday"), TR_SCHED_FRI), TR_ARG_TUPLE(_("Friday"), TR_SCHED_FRI),
TR_ARG_TUPLE(_("Saturday"), TR_SCHED_SAT), TR_ARG_TUPLE(_("Saturday"), TR_SCHED_SAT),
NULL); nullptr);
gtr_combo_box_set_active_enum(GTK_COMBO_BOX(w), gtr_pref_int_get(key)); 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_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
g_signal_connect(w, "changed", G_CALLBACK(onIntComboChanged), core); g_signal_connect(w, "changed", G_CALLBACK(onIntComboChanged), core);
@ -1007,20 +1007,20 @@ static GtkWidget* speedPage(GObject* core)
w2 = new_spin_button(TR_KEY_speed_limit_up, core, 0, INT_MAX, 5); 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)); 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); g_signal_connect(w, "toggled", G_CALLBACK(target_cb), w2);
hig_workarea_add_row_w(t, &row, w, w2, NULL); hig_workarea_add_row_w(t, &row, w, w2, nullptr);
g_snprintf(buf, sizeof(buf), _("_Download (%s):"), _(speed_K_str)); g_snprintf(buf, sizeof(buf), _("_Download (%s):"), _(speed_K_str));
w = new_check_button(buf, TR_KEY_speed_limit_down_enabled, core); 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); 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)); 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); g_signal_connect(w, "toggled", G_CALLBACK(target_cb), w2);
hig_workarea_add_row_w(t, &row, w, w2, NULL); hig_workarea_add_row_w(t, &row, w, w2, nullptr);
hig_workarea_add_section_divider(t, &row); hig_workarea_add_section_divider(t, &row);
h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD); h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
g_snprintf(buf, sizeof(buf), "<b>%s</b>", _("Alternative Speed Limits")); g_snprintf(buf, sizeof(buf), "<b>%s</b>", _("Alternative Speed Limits"));
w = gtk_label_new(buf); w = gtk_label_new(buf);
g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_label_set_use_markup(GTK_LABEL(w), TRUE); gtk_label_set_use_markup(GTK_LABEL(w), TRUE);
gtk_box_pack_start(GTK_BOX(h), w, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(h), w, FALSE, FALSE, 0);
w = gtk_image_new_from_icon_name("alt-speed-on", GTK_ICON_SIZE_MENU); w = gtk_image_new_from_icon_name("alt-speed-on", GTK_ICON_SIZE_MENU);
@ -1031,16 +1031,16 @@ static GtkWidget* speedPage(GObject* core)
g_snprintf(buf, sizeof(buf), "<small>%s</small>", s); g_snprintf(buf, sizeof(buf), "<small>%s</small>", s);
w = gtk_label_new(buf); w = gtk_label_new(buf);
gtk_label_set_use_markup(GTK_LABEL(w), TRUE); gtk_label_set_use_markup(GTK_LABEL(w), TRUE);
g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
hig_workarea_add_wide_control(t, &row, w); hig_workarea_add_wide_control(t, &row, w);
g_snprintf(buf, sizeof(buf), _("U_pload (%s):"), _(speed_K_str)); g_snprintf(buf, sizeof(buf), _("U_pload (%s):"), _(speed_K_str));
w = new_spin_button(TR_KEY_alt_speed_up, 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); hig_workarea_add_row(t, &row, buf, w, nullptr);
g_snprintf(buf, sizeof(buf), _("Do_wnload (%s):"), _(speed_K_str)); g_snprintf(buf, sizeof(buf), _("Do_wnload (%s):"), _(speed_K_str));
w = new_spin_button(TR_KEY_alt_speed_down, 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); hig_workarea_add_row(t, &row, buf, w, nullptr);
s = _("_Scheduled times:"); s = _("_Scheduled times:");
h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
@ -1056,12 +1056,12 @@ static GtkWidget* speedPage(GObject* core)
gtk_box_pack_start(GTK_BOX(h), w2, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(h), w2, TRUE, TRUE, 0);
w = new_check_button(s, TR_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); g_signal_connect(w, "toggled", G_CALLBACK(onSchedToggled), page);
hig_workarea_add_row_w(t, &row, w, h, NULL); hig_workarea_add_row_w(t, &row, w, h, nullptr);
s = _("_On days:"); s = _("_On days:");
w = new_week_combo(core, TR_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); page->sched_widgets = g_slist_prepend(page->sched_widgets, w);
w = hig_workarea_add_row(t, &row, s, w, NULL); w = hig_workarea_add_row(t, &row, s, w, nullptr);
page->sched_widgets = g_slist_prepend(page->sched_widgets, w); page->sched_widgets = g_slist_prepend(page->sched_widgets, w);
g_object_set_data_full(G_OBJECT(t), "page", page, speedPageFree); g_object_set_data_full(G_OBJECT(t), "page", page, speedPageFree);
@ -1165,16 +1165,16 @@ static GtkWidget* networkPage(GObject* core)
s = _("_Port used for incoming connections:"); s = _("_Port used for incoming connections:");
w = data->portSpin = new_spin_button(TR_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); hig_workarea_add_row(t, &row, s, w, nullptr);
h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG); h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
l = data->portLabel = gtk_label_new(_("Status unknown")); l = data->portLabel = gtk_label_new(_("Status unknown"));
g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_box_pack_start(GTK_BOX(h), l, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(h), l, TRUE, TRUE, 0);
w = data->portButton = gtk_button_new_with_mnemonic(_("Te_st Port")); w = data->portButton = gtk_button_new_with_mnemonic(_("Te_st Port"));
gtk_box_pack_end(GTK_BOX(h), w, FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(h), w, FALSE, FALSE, 0);
g_signal_connect(w, "clicked", G_CALLBACK(onPortTest), data); g_signal_connect(w, "clicked", G_CALLBACK(onPortTest), data);
hig_workarea_add_row(t, &row, NULL, h, NULL); hig_workarea_add_row(t, &row, nullptr, h, nullptr);
data->prefsTag = g_signal_connect(TR_CORE(core), "prefs-changed", G_CALLBACK(onCorePrefsChanged), data); data->prefsTag = g_signal_connect(TR_CORE(core), "prefs-changed", G_CALLBACK(onCorePrefsChanged), data);
g_object_weak_ref(G_OBJECT(t), networkPageDestroyed, data); g_object_weak_ref(G_OBJECT(t), networkPageDestroyed, data);
@ -1190,9 +1190,9 @@ static GtkWidget* networkPage(GObject* core)
hig_workarea_add_section_title(t, &row, _("Peer Limits")); hig_workarea_add_section_title(t, &row, _("Peer Limits"));
w = new_spin_button(TR_KEY_peer_limit_per_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); hig_workarea_add_row(t, &row, _("Maximum peers per _torrent:"), w, nullptr);
w = new_spin_button(TR_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_row(t, &row, _("Maximum peers _overall:"), w, nullptr);
hig_workarea_add_section_divider(t, &row); hig_workarea_add_section_divider(t, &row);
hig_workarea_add_section_title(t, &row, _("Options")); hig_workarea_add_section_title(t, &row, _("Options"));
@ -1281,7 +1281,7 @@ GtkWidget* gtr_prefs_dialog_new(GtkWindow* parent, GObject* core)
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
TR_ARG_TUPLE(_("_Help"), GTK_RESPONSE_HELP), TR_ARG_TUPLE(_("_Help"), GTK_RESPONSE_HELP),
TR_ARG_TUPLE(_("_Close"), GTK_RESPONSE_CLOSE), TR_ARG_TUPLE(_("_Close"), GTK_RESPONSE_CLOSE),
NULL); nullptr);
g_object_weak_ref(G_OBJECT(d), on_prefs_dialog_destroyed, data); g_object_weak_ref(G_OBJECT(d), on_prefs_dialog_destroyed, data);
gtk_window_set_role(GTK_WINDOW(d), "transmission-preferences-dialog"); gtk_window_set_role(GTK_WINDOW(d), "transmission-preferences-dialog");
gtk_container_set_border_width(GTK_CONTAINER(d), GUI_PAD); gtk_container_set_border_width(GTK_CONTAINER(d), GUI_PAD);

View File

@ -83,7 +83,14 @@ static void on_popup_menu(GtkWidget* self, GdkEventButton* event)
#if GTK_CHECK_VERSION(3, 22, 0) #if GTK_CHECK_VERSION(3, 22, 0)
gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent*)event); gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent*)event);
#else #else
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event != NULL ? event->button : 0, event != NULL ? event->time : 0); gtk_menu_popup(
GTK_MENU(menu),
nullptr,
nullptr,
nullptr,
nullptr,
event != nullptr ? event->button : 0,
event != nullptr ? event->time : 0);
#endif #endif
} }
@ -109,11 +116,11 @@ static gboolean tree_view_search_equal_func(
gboolean match; gboolean match;
char* lower; char* lower;
char const* name = NULL; char const* name = nullptr;
lower = g_strstrip(g_utf8_strdown(key, -1)); lower = g_strstrip(g_utf8_strdown(key, -1));
gtk_tree_model_get(model, iter, MC_NAME_COLLATED, &name, -1); gtk_tree_model_get(model, iter, MC_NAME_COLLATED, &name, -1);
match = strstr(name, lower) != NULL; match = strstr(name, lower) != nullptr;
g_free(lower); g_free(lower);
return !match; return !match;
@ -130,7 +137,7 @@ static GtkWidget* makeview(PrivateData* p)
view = gtk_tree_view_new(); view = gtk_tree_view_new();
tree_view = GTK_TREE_VIEW(view); tree_view = GTK_TREE_VIEW(view);
gtk_tree_view_set_search_column(tree_view, MC_NAME_COLLATED); gtk_tree_view_set_search_column(tree_view, MC_NAME_COLLATED);
gtk_tree_view_set_search_equal_func(tree_view, tree_view_search_equal_func, NULL, NULL); gtk_tree_view_set_search_equal_func(tree_view, tree_view_search_equal_func, nullptr, nullptr);
gtk_tree_view_set_headers_visible(tree_view, FALSE); gtk_tree_view_set_headers_visible(tree_view, FALSE);
gtk_tree_view_set_fixed_height_mode(tree_view, TRUE); gtk_tree_view_set_fixed_height_mode(tree_view, TRUE);
@ -141,7 +148,7 @@ static GtkWidget* makeview(PrivateData* p)
TR_ARG_TUPLE("title", _("Torrent")), TR_ARG_TUPLE("title", _("Torrent")),
TR_ARG_TUPLE("resizable", TRUE), TR_ARG_TUPLE("resizable", TRUE),
TR_ARG_TUPLE("sizing", GTK_TREE_VIEW_COLUMN_FIXED), TR_ARG_TUPLE("sizing", GTK_TREE_VIEW_COLUMN_FIXED),
NULL)); nullptr));
p->renderer = r = torrent_cell_renderer_new(); p->renderer = r = torrent_cell_renderer_new();
gtk_tree_view_column_pack_start(col, r, FALSE); gtk_tree_view_column_pack_start(col, r, FALSE);
@ -150,15 +157,15 @@ static GtkWidget* makeview(PrivateData* p)
gtk_tree_view_column_add_attribute(col, r, "piece-download-speed", MC_SPEED_DOWN); gtk_tree_view_column_add_attribute(col, r, "piece-download-speed", MC_SPEED_DOWN);
gtk_tree_view_append_column(tree_view, col); gtk_tree_view_append_column(tree_view, col);
g_object_set(r, "xpad", GUI_PAD_SMALL, "ypad", GUI_PAD_SMALL, NULL); g_object_set(r, "xpad", GUI_PAD_SMALL, "ypad", GUI_PAD_SMALL, nullptr);
sel = gtk_tree_view_get_selection(tree_view); sel = gtk_tree_view_get_selection(tree_view);
gtk_tree_selection_set_mode(GTK_TREE_SELECTION(sel), GTK_SELECTION_MULTIPLE); gtk_tree_selection_set_mode(GTK_TREE_SELECTION(sel), GTK_SELECTION_MULTIPLE);
g_signal_connect(view, "popup-menu", G_CALLBACK(on_popup_menu), NULL); g_signal_connect(view, "popup-menu", G_CALLBACK(on_popup_menu), nullptr);
g_signal_connect(view, "button-press-event", G_CALLBACK(on_tree_view_button_pressed), (void*)on_popup_menu); g_signal_connect(view, "button-press-event", G_CALLBACK(on_tree_view_button_pressed), (void*)on_popup_menu);
g_signal_connect(view, "button-release-event", G_CALLBACK(on_tree_view_button_released), NULL); g_signal_connect(view, "button-release-event", G_CALLBACK(on_tree_view_button_released), nullptr);
g_signal_connect(view, "row-activated", G_CALLBACK(view_row_activated), NULL); g_signal_connect(view, "row-activated", G_CALLBACK(view_row_activated), nullptr);
gtk_tree_view_set_model(tree_view, p->filter_model); gtk_tree_view_set_model(tree_view, p->filter_model);
g_object_unref(p->filter_model); g_object_unref(p->filter_model);
@ -178,26 +185,26 @@ static void prefsChanged(TrCore* core, tr_quark const key, gpointer wind)
switch (key) switch (key)
{ {
case TR_KEY_compact_view: case TR_KEY_compact_view:
g_object_set(p->renderer, "compact", gtr_pref_flag_get(key), NULL); g_object_set(p->renderer, "compact", gtr_pref_flag_get(key), nullptr);
/* since the cell size has changed, we need gtktreeview to revalidate /* since the cell size has changed, we need gtktreeview to revalidate
* its fixed-height mode values. Unfortunately there's not an API call * 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 */ * 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); g_signal_emit_by_name(p->view, "style-updated", nullptr, nullptr);
break; break;
case TR_KEY_show_statusbar: case TR_KEY_show_statusbar:
isEnabled = gtr_pref_flag_get(key); isEnabled = gtr_pref_flag_get(key);
g_object_set(p->status, "visible", isEnabled, NULL); g_object_set(p->status, "visible", isEnabled, nullptr);
break; break;
case TR_KEY_show_filterbar: case TR_KEY_show_filterbar:
isEnabled = gtr_pref_flag_get(key); isEnabled = gtr_pref_flag_get(key);
g_object_set(p->filter, "visible", isEnabled, NULL); g_object_set(p->filter, "visible", isEnabled, nullptr);
break; break;
case TR_KEY_show_toolbar: case TR_KEY_show_toolbar:
isEnabled = gtr_pref_flag_get(key); isEnabled = gtr_pref_flag_get(key);
g_object_set(p->toolbar, "visible", isEnabled, NULL); g_object_set(p->toolbar, "visible", isEnabled, nullptr);
break; break;
case TR_KEY_statusbar_stats: case TR_KEY_statusbar_stats:
@ -229,9 +236,9 @@ static void onYinYangClicked(GtkWidget* w, gpointer vprivate)
auto* p = static_cast<PrivateData*>(vprivate); auto* p = static_cast<PrivateData*>(vprivate);
#if GTK_CHECK_VERSION(3, 22, 0) #if GTK_CHECK_VERSION(3, 22, 0)
gtk_menu_popup_at_widget(GTK_MENU(p->status_menu), GTK_WIDGET(w), GDK_GRAVITY_NORTH_EAST, GDK_GRAVITY_SOUTH_EAST, NULL); gtk_menu_popup_at_widget(GTK_MENU(p->status_menu), GTK_WIDGET(w), GDK_GRAVITY_NORTH_EAST, GDK_GRAVITY_SOUTH_EAST, nullptr);
#else #else
gtk_menu_popup(GTK_MENU(p->status_menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time()); gtk_menu_popup(GTK_MENU(p->status_menu), nullptr, nullptr, nullptr, nullptr, 0, gtk_get_current_event_time());
#endif #endif
} }
@ -274,7 +281,7 @@ static void syncAltSpeedButton(PrivateData* p)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b);
gtk_image_set_from_stock(GTK_IMAGE(p->alt_speed_image), stock, GtkIconSize(-1)); gtk_image_set_from_stock(GTK_IMAGE(p->alt_speed_image), stock, GtkIconSize(-1));
g_object_set(w, "halign", GTK_ALIGN_CENTER, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(w, "halign", GTK_ALIGN_CENTER, "valign", GTK_ALIGN_CENTER, nullptr);
gtk_widget_set_tooltip_text(w, str); gtk_widget_set_tooltip_text(w, str);
g_free(str); g_free(str);
@ -320,7 +327,7 @@ static gboolean onAskTrackerQueryTooltip(
gboolean handled; gboolean handled;
time_t maxTime = 0; time_t maxTime = 0;
auto* p = static_cast<PrivateData*>(gdata); auto* p = static_cast<PrivateData*>(gdata);
time_t const now = time(NULL); time_t const now = time(nullptr);
gtk_tree_selection_selected_foreach(p->selection, findMaxAnnounceTime, &maxTime); gtk_tree_selection_selected_foreach(p->selection, findMaxAnnounceTime, &maxTime);
@ -409,7 +416,7 @@ static GtkWidget* createSpeedMenu(PrivateData* p, tr_direction dir)
m = gtk_menu_new(); m = gtk_menu_new();
menu_shell = GTK_MENU_SHELL(m); menu_shell = GTK_MENU_SHELL(m);
w = gtk_radio_menu_item_new_with_label(NULL, _("Unlimited")); w = gtk_radio_menu_item_new_with_label(nullptr, _("Unlimited"));
o = G_OBJECT(w); o = G_OBJECT(w);
p->speedlimit_off_item[dir] = w; p->speedlimit_off_item[dir] = w;
g_object_set_data(o, DIRECTION_KEY, GINT_TO_POINTER(dir)); g_object_set_data(o, DIRECTION_KEY, GINT_TO_POINTER(dir));
@ -480,7 +487,7 @@ static GtkWidget* createRatioMenu(PrivateData* p)
m = gtk_menu_new(); m = gtk_menu_new();
menu_shell = GTK_MENU_SHELL(m); menu_shell = GTK_MENU_SHELL(m);
w = gtk_radio_menu_item_new_with_label(NULL, _("Seed Forever")); w = gtk_radio_menu_item_new_with_label(nullptr, _("Seed Forever"));
p->ratio_off_item = w; p->ratio_off_item = w;
g_object_set_data(G_OBJECT(w), ENABLED_KEY, GINT_TO_POINTER(FALSE)); g_object_set_data(G_OBJECT(w), ENABLED_KEY, GINT_TO_POINTER(FALSE));
g_signal_connect(w, "toggled", G_CALLBACK(onRatioToggled), p); g_signal_connect(w, "toggled", G_CALLBACK(onRatioToggled), p);
@ -574,9 +581,9 @@ static void onOptionsClicked(GtkButton* button, gpointer vp)
GTK_WIDGET(button), GTK_WIDGET(button),
GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST,
GDK_GRAVITY_SOUTH_WEST, GDK_GRAVITY_SOUTH_WEST,
NULL); nullptr);
#else #else
gtk_menu_popup(GTK_MENU(p->options_menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time()); gtk_menu_popup(GTK_MENU(p->options_menu), nullptr, nullptr, nullptr, nullptr, 0, gtk_get_current_event_time());
#endif #endif
} }
@ -627,7 +634,7 @@ GtkWidget* gtr_window_new(GtkApplication* app, GtkUIManager* ui_mgr, TrCore* cor
/* Please move it to separate .css file if youre adding more styles here. */ /* Please move it to separate .css file if youre adding more styles here. */
style = ".tr-workarea.frame {border-left-width: 0; border-right-width: 0; border-radius: 0;}"; style = ".tr-workarea.frame {border-left-width: 0; border-right-width: 0; border-radius: 0;}";
css_provider = gtk_css_provider_new(); css_provider = gtk_css_provider_new();
gtk_css_provider_load_from_data(css_provider, style, strlen(style), NULL); gtk_css_provider_load_from_data(css_provider, style, strlen(style), nullptr);
gtk_style_context_add_provider_for_screen( gtk_style_context_add_provider_for_screen(
gdk_screen_get_default(), gdk_screen_get_default(),
GTK_STYLE_PROVIDER(css_provider), GTK_STYLE_PROVIDER(css_provider),
@ -654,7 +661,7 @@ GtkWidget* gtr_window_new(GtkApplication* app, GtkUIManager* ui_mgr, TrCore* cor
/* status menu */ /* status menu */
menu = p->status_menu = gtk_menu_new(); menu = p->status_menu = gtk_menu_new();
l = NULL; l = nullptr;
pch = gtr_pref_string_get(TR_KEY_statusbar_stats); pch = gtr_pref_string_get(TR_KEY_statusbar_stats);
for (size_t i = 0; i < G_N_ELEMENTS(stats_modes); ++i) for (size_t i = 0; i < G_N_ELEMENTS(stats_modes); ++i)
@ -701,21 +708,21 @@ GtkWidget* gtr_window_new(GtkApplication* app, GtkUIManager* ui_mgr, TrCore* cor
gtk_container_add(GTK_CONTAINER(grid), w); gtk_container_add(GTK_CONTAINER(grid), w);
/* download */ /* download */
w = dl_lb = gtk_label_new(NULL); w = dl_lb = gtk_label_new(nullptr);
p->dl_lb = GTK_LABEL(w); p->dl_lb = GTK_LABEL(w);
gtk_label_set_single_line_mode(p->dl_lb, TRUE); gtk_label_set_single_line_mode(p->dl_lb, TRUE);
gtk_container_add(GTK_CONTAINER(grid), w); gtk_container_add(GTK_CONTAINER(grid), w);
/* upload */ /* upload */
w = ul_lb = gtk_label_new(NULL); w = ul_lb = gtk_label_new(nullptr);
g_object_set(G_OBJECT(w), "margin-left", GUI_PAD, NULL); g_object_set(G_OBJECT(w), "margin-left", GUI_PAD, nullptr);
p->ul_lb = GTK_LABEL(w); p->ul_lb = GTK_LABEL(w);
gtk_label_set_single_line_mode(p->ul_lb, TRUE); gtk_label_set_single_line_mode(p->ul_lb, TRUE);
gtk_container_add(GTK_CONTAINER(grid), w); gtk_container_add(GTK_CONTAINER(grid), w);
/* ratio */ /* ratio */
w = gtk_label_new(NULL); w = gtk_label_new(nullptr);
g_object_set(G_OBJECT(w), "margin-left", GUI_PAD_BIG, NULL); g_object_set(G_OBJECT(w), "margin-left", GUI_PAD_BIG, nullptr);
p->stats_lb = GTK_LABEL(w); p->stats_lb = GTK_LABEL(w);
gtk_label_set_single_line_mode(p->stats_lb, TRUE); gtk_label_set_single_line_mode(p->stats_lb, TRUE);
gtk_container_add(GTK_CONTAINER(grid), w); gtk_container_add(GTK_CONTAINER(grid), w);
@ -733,7 +740,7 @@ GtkWidget* gtr_window_new(GtkApplication* app, GtkUIManager* ui_mgr, TrCore* cor
**/ **/
p->view = makeview(p); p->view = makeview(p);
w = list = p->scroll = gtk_scrolled_window_new(NULL, NULL); w = list = p->scroll = gtk_scrolled_window_new(nullptr, nullptr);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(w), GTK_SHADOW_OUT); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(w), GTK_SHADOW_OUT);
gtk_style_context_add_class(gtk_widget_get_style_context(w), "tr-workarea"); gtk_style_context_add_class(gtk_widget_get_style_context(w), "tr-workarea");
@ -755,8 +762,8 @@ GtkWidget* gtr_window_new(GtkApplication* app, GtkUIManager* ui_mgr, TrCore* cor
pango_layout_get_pixel_size(pango_layout, &width, &height); pango_layout_get_pixel_size(pango_layout, &width, &height);
gtk_widget_set_size_request(ul_lb, width, height); gtk_widget_set_size_request(ul_lb, width, height);
gtk_widget_set_size_request(dl_lb, width, height); gtk_widget_set_size_request(dl_lb, width, height);
g_object_set(ul_lb, "halign", GTK_ALIGN_END, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(ul_lb, "halign", GTK_ALIGN_END, "valign", GTK_ALIGN_CENTER, nullptr);
g_object_set(dl_lb, "halign", GTK_ALIGN_END, "valign", GTK_ALIGN_CENTER, NULL); g_object_set(dl_lb, "halign", GTK_ALIGN_END, "valign", GTK_ALIGN_CENTER, nullptr);
g_object_unref(G_OBJECT(pango_layout)); g_object_unref(G_OBJECT(pango_layout));
} }
@ -831,7 +838,7 @@ static void updateSpeeds(PrivateData* p)
{ {
tr_session const* const session = gtr_core_session(p->core); tr_session const* const session = gtr_core_session(p->core);
if (session != NULL) if (session != nullptr)
{ {
char text_str[256]; char text_str[256];
char speed_str[128]; char speed_str[128];
@ -842,7 +849,7 @@ static void updateSpeeds(PrivateData* p)
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel* model = gtr_core_model(p->core); GtkTreeModel* model = gtr_core_model(p->core);
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0)) if (gtk_tree_model_iter_nth_child(model, &iter, nullptr, 0))
{ {
do do
{ {
@ -881,7 +888,7 @@ void gtr_window_refresh(GtkWindow* self)
{ {
PrivateData* p = get_private_data(self); PrivateData* p = get_private_data(self);
if (p != NULL && p->core != NULL && gtr_core_session(p->core) != NULL) if (p != nullptr && p->core != nullptr && gtr_core_session(p->core) != nullptr)
{ {
updateSpeeds(p); updateSpeeds(p);
updateStats(p); updateStats(p);
@ -897,10 +904,10 @@ void gtr_window_set_busy(GtkWindow* win, gboolean isBusy)
{ {
GtkWidget* w = GTK_WIDGET(win); GtkWidget* w = GTK_WIDGET(win);
if (w != NULL && gtk_widget_get_realized(w)) if (w != nullptr && gtk_widget_get_realized(w))
{ {
GdkDisplay* display = gtk_widget_get_display(w); GdkDisplay* display = gtk_widget_get_display(w);
GdkCursor* cursor = isBusy ? gdk_cursor_new_for_display(display, GDK_WATCH) : NULL; GdkCursor* cursor = isBusy ? gdk_cursor_new_for_display(display, GDK_WATCH) : nullptr;
gdk_window_set_cursor(gtk_widget_get_window(w), cursor); gdk_window_set_cursor(gtk_widget_get_window(w), cursor);
gdk_display_flush(display); gdk_display_flush(display);

View File

@ -168,7 +168,7 @@ void gtr_get_host_from_url(char* buf, size_t buflen, char const* url)
char host[1024]; char host[1024];
char const* pch; char const* pch;
if ((pch = strstr(url, "://")) != NULL) if ((pch = strstr(url, "://")) != nullptr)
{ {
size_t const hostlen = strcspn(pch + 3, ":/"); size_t const hostlen = strcspn(pch + 3, ":/");
size_t const copylen = MIN(hostlen, sizeof(host) - 1); size_t const copylen = MIN(hostlen, sizeof(host) - 1);
@ -189,7 +189,7 @@ void gtr_get_host_from_url(char* buf, size_t buflen, char const* url)
char const* first_dot = strchr(host, '.'); char const* first_dot = strchr(host, '.');
char const* last_dot = strrchr(host, '.'); char const* last_dot = strrchr(host, '.');
if (first_dot != NULL && last_dot != NULL && first_dot != last_dot) if (first_dot != nullptr && last_dot != nullptr && first_dot != last_dot)
{ {
g_strlcpy(buf, first_dot + 1, buflen); g_strlcpy(buf, first_dot + 1, buflen);
} }
@ -202,18 +202,18 @@ void gtr_get_host_from_url(char* buf, size_t buflen, char const* url)
static gboolean gtr_is_supported_url(char const* str) static gboolean gtr_is_supported_url(char const* str)
{ {
return str != NULL && return str != nullptr &&
(g_str_has_prefix(str, "ftp://") || g_str_has_prefix(str, "http://") || g_str_has_prefix(str, "https://")); (g_str_has_prefix(str, "ftp://") || g_str_has_prefix(str, "http://") || g_str_has_prefix(str, "https://"));
} }
gboolean gtr_is_magnet_link(char const* str) gboolean gtr_is_magnet_link(char const* str)
{ {
return str != NULL && g_str_has_prefix(str, "magnet:?"); return str != nullptr && g_str_has_prefix(str, "magnet:?");
} }
gboolean gtr_is_hex_hashcode(char const* str) gboolean gtr_is_hex_hashcode(char const* str)
{ {
if (str == NULL || strlen(str) != 40) if (str == nullptr || strlen(str) != 40)
{ {
return FALSE; return FALSE;
} }
@ -231,9 +231,9 @@ gboolean gtr_is_hex_hashcode(char const* str)
static GtkWindow* getWindow(GtkWidget* w) static GtkWindow* getWindow(GtkWidget* w)
{ {
if (w == NULL) if (w == nullptr)
{ {
return NULL; return nullptr;
} }
if (GTK_IS_WINDOW(w)) if (GTK_IS_WINDOW(w))
@ -293,7 +293,7 @@ gboolean on_tree_view_button_pressed(GtkWidget* view, GdkEventButton* event, gpo
GtkTreePath* path; GtkTreePath* path;
GtkTreeSelection* selection = gtk_tree_view_get_selection(tv); GtkTreeSelection* selection = gtk_tree_view_get_selection(tv);
if (gtk_tree_view_get_path_at_pos(tv, (gint)event->x, (gint)event->y, &path, NULL, NULL, NULL)) if (gtk_tree_view_get_path_at_pos(tv, (gint)event->x, (gint)event->y, &path, nullptr, nullptr, nullptr))
{ {
if (!gtk_tree_selection_path_is_selected(selection, path)) if (!gtk_tree_selection_path_is_selected(selection, path))
{ {
@ -304,7 +304,7 @@ gboolean on_tree_view_button_pressed(GtkWidget* view, GdkEventButton* event, gpo
gtk_tree_path_free(path); gtk_tree_path_free(path);
} }
if (func != NULL) if (func != nullptr)
{ {
(*(PopupFunc)func)(view, event); (*(PopupFunc)func)(view, event);
} }
@ -323,7 +323,7 @@ gboolean on_tree_view_button_released(GtkWidget* view, GdkEventButton* event, gp
GtkTreeView* tv = GTK_TREE_VIEW(view); GtkTreeView* tv = GTK_TREE_VIEW(view);
if (!gtk_tree_view_get_path_at_pos(tv, (gint)event->x, (gint)event->y, NULL, NULL, NULL, NULL)) if (!gtk_tree_view_get_path_at_pos(tv, (gint)event->x, (gint)event->y, nullptr, nullptr, nullptr, nullptr))
{ {
GtkTreeSelection* selection = gtk_tree_view_get_selection(tv); GtkTreeSelection* selection = gtk_tree_view_get_selection(tv);
gtk_tree_selection_unselect_all(selection); gtk_tree_selection_unselect_all(selection);
@ -344,10 +344,10 @@ bool gtr_file_trash_or_remove(char const* filename, tr_error** error)
if (gtr_pref_flag_get(TR_KEY_trash_can_enabled)) if (gtr_pref_flag_get(TR_KEY_trash_can_enabled))
{ {
GError* err = NULL; GError* err = nullptr;
trashed = g_file_trash(file, NULL, &err); trashed = g_file_trash(file, nullptr, &err);
if (err != NULL) if (err != nullptr)
{ {
g_message("Unable to trash file \"%s\": %s", filename, err->message); g_message("Unable to trash file \"%s\": %s", filename, err->message);
tr_error_set_literal(error, err->code, err->message); tr_error_set_literal(error, err->code, err->message);
@ -357,10 +357,10 @@ bool gtr_file_trash_or_remove(char const* filename, tr_error** error)
if (!trashed) if (!trashed)
{ {
GError* err = NULL; GError* err = nullptr;
g_file_delete(file, NULL, &err); g_file_delete(file, nullptr, &err);
if (err != NULL) if (err != nullptr)
{ {
g_message("Unable to delete file \"%s\": %s", filename, err->message); g_message("Unable to delete file \"%s\": %s", filename, err->message);
tr_error_clear(error); tr_error_clear(error);
@ -376,9 +376,9 @@ bool gtr_file_trash_or_remove(char const* filename, tr_error** error)
char const* gtr_get_help_uri(void) char const* gtr_get_help_uri(void)
{ {
static char const* uri = NULL; static char const* uri = nullptr;
if (uri == NULL) if (uri == nullptr)
{ {
uri = g_strdup_printf("https://transmissionbt.com/help/gtk/%d.%dx", MAJOR_VERSION, MINOR_VERSION / 10); uri = g_strdup_printf("https://transmissionbt.com/help/gtk/%d.%dx", MAJOR_VERSION, MINOR_VERSION / 10);
} }
@ -397,28 +397,28 @@ void gtr_open_file(char const* path)
void gtr_open_uri(char const* uri) void gtr_open_uri(char const* uri)
{ {
if (uri != NULL) if (uri != nullptr)
{ {
gboolean opened = FALSE; gboolean opened = FALSE;
if (!opened) if (!opened)
{ {
#if GTK_CHECK_VERSION(3, 22, 0) #if GTK_CHECK_VERSION(3, 22, 0)
opened = gtk_show_uri_on_window(NULL, uri, GDK_CURRENT_TIME, NULL); opened = gtk_show_uri_on_window(nullptr, uri, GDK_CURRENT_TIME, nullptr);
#else #else
opened = gtk_show_uri(NULL, uri, GDK_CURRENT_TIME, NULL); opened = gtk_show_uri(nullptr, uri, GDK_CURRENT_TIME, nullptr);
#endif #endif
} }
if (!opened) if (!opened)
{ {
opened = g_app_info_launch_default_for_uri(uri, NULL, NULL); opened = g_app_info_launch_default_for_uri(uri, nullptr, nullptr);
} }
if (!opened) if (!opened)
{ {
char* argv[] = { (char*)"xdg-open", (char*)uri, NULL }; char* argv[] = { (char*)"xdg-open", (char*)uri, nullptr };
opened = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); opened = g_spawn_async(nullptr, argv, nullptr, G_SPAWN_SEARCH_PATH, nullptr, nullptr, nullptr, nullptr);
} }
if (!opened) if (!opened)
@ -454,7 +454,7 @@ void gtr_combo_box_set_active_enum(GtkComboBox* combo_box, int value)
/* find the one to select */ /* find the one to select */
i = 0; i = 0;
while (gtk_tree_model_iter_nth_child(model, &iter, NULL, i)) while (gtk_tree_model_iter_nth_child(model, &iter, nullptr, i))
{ {
gtk_tree_model_get(model, &iter, column, &currentValue, -1); gtk_tree_model_get(model, &iter, column, &currentValue, -1);
@ -479,7 +479,7 @@ GtkWidget* gtr_combo_box_new_enum(char const* text_1, ...)
text = text_1; text = text_1;
if (text != NULL) if (text != nullptr)
{ {
va_list vl; va_list vl;
@ -488,9 +488,9 @@ GtkWidget* gtr_combo_box_new_enum(char const* text_1, ...)
do do
{ {
int const val = va_arg(vl, int); int const val = va_arg(vl, int);
gtk_list_store_insert_with_values(store, NULL, INT_MAX, 0, val, 1, text, -1); gtk_list_store_insert_with_values(store, nullptr, INT_MAX, 0, val, 1, text, -1);
text = va_arg(vl, char const*); text = va_arg(vl, char const*);
} while (text != NULL); } while (text != nullptr);
va_end(vl); va_end(vl);
} }
@ -498,7 +498,7 @@ GtkWidget* gtr_combo_box_new_enum(char const* text_1, ...)
w = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); w = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
r = gtk_cell_renderer_text_new(); r = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(w), r, TRUE); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(w), r, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(w), r, "text", 1, NULL); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(w), r, "text", 1, nullptr);
/* cleanup */ /* cleanup */
g_object_unref(store); g_object_unref(store);
@ -524,7 +524,7 @@ GtkWidget* gtr_priority_combo_new(void)
TR_ARG_TUPLE(_("High"), TR_PRI_HIGH), TR_ARG_TUPLE(_("High"), TR_PRI_HIGH),
TR_ARG_TUPLE(_("Normal"), TR_PRI_NORMAL), TR_ARG_TUPLE(_("Normal"), TR_PRI_NORMAL),
TR_ARG_TUPLE(_("Low"), TR_PRI_LOW), TR_ARG_TUPLE(_("Low"), TR_PRI_LOW),
NULL); nullptr);
} }
/*** /***
@ -541,7 +541,7 @@ void gtr_widget_set_visible(GtkWidget* w, gboolean b)
GList* windows = gtk_window_list_toplevels(); GList* windows = gtk_window_list_toplevels();
GtkWindow const* const window = GTK_WINDOW(w); GtkWindow const* const window = GTK_WINDOW(w);
for (GList* l = windows; l != NULL; l = l->next) for (GList* l = windows; l != nullptr; l = l->next)
{ {
if (!GTK_IS_WINDOW(l->data)) if (!GTK_IS_WINDOW(l->data))
{ {
@ -558,7 +558,7 @@ void gtr_widget_set_visible(GtkWidget* w, gboolean b)
continue; continue;
} }
if (b && g_object_get_data(G_OBJECT(l->data), GTR_CHILD_HIDDEN) != NULL) if (b && g_object_get_data(G_OBJECT(l->data), GTR_CHILD_HIDDEN) != nullptr)
{ {
g_object_steal_data(G_OBJECT(l->data), GTR_CHILD_HIDDEN); g_object_steal_data(G_OBJECT(l->data), GTR_CHILD_HIDDEN);
gtr_widget_set_visible(GTK_WIDGET(l->data), TRUE); gtr_widget_set_visible(GTK_WIDGET(l->data), TRUE);
@ -593,13 +593,13 @@ void gtr_unrecognized_url_dialog(GtkWidget* parent, char const* url)
GtkWindow* window = getWindow(parent); GtkWindow* window = getWindow(parent);
GString* gstr = g_string_new(NULL); GString* gstr = g_string_new(nullptr);
GtkWidget* w = gtk_message_dialog_new(window, {}, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", _("Unrecognized URL")); GtkWidget* w = gtk_message_dialog_new(window, {}, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", _("Unrecognized URL"));
g_string_append_printf(gstr, _("Transmission doesn't know how to use \"%s\""), url); g_string_append_printf(gstr, _("Transmission doesn't know how to use \"%s\""), url);
if (gtr_is_magnet_link(url) && strstr(url, xt) == NULL) if (gtr_is_magnet_link(url) && strstr(url, xt) == nullptr)
{ {
g_string_append_printf(gstr, "\n \n"); g_string_append_printf(gstr, "\n \n");
g_string_append_printf( g_string_append_printf(
@ -630,7 +630,7 @@ void gtr_paste_clipboard_url_into_entry(GtkWidget* e)
{ {
char const* const s = text[i]; char const* const s = text[i];
if (s != NULL && (gtr_is_supported_url(s) || gtr_is_magnet_link(s) || gtr_is_hex_hashcode(s))) if (s != nullptr && (gtr_is_supported_url(s) || gtr_is_magnet_link(s) || gtr_is_hex_hashcode(s)))
{ {
gtk_entry_set_text(GTK_ENTRY(e), s); gtk_entry_set_text(GTK_ENTRY(e), s);
break; break;
@ -676,12 +676,12 @@ static void freespace_label_data_free(gpointer gdata)
{ {
auto* data = static_cast<freespace_label_data*>(gdata); auto* data = static_cast<freespace_label_data*>(gdata);
if (data->core != NULL) if (data->core != nullptr)
{ {
g_object_weak_unref(G_OBJECT(data->core), on_freespace_label_core_destroyed, data); g_object_weak_unref(G_OBJECT(data->core), on_freespace_label_core_destroyed, data);
} }
if (data->label != NULL) if (data->label != nullptr)
{ {
g_object_weak_ref(G_OBJECT(data->label), on_freespace_label_destroyed, data); g_object_weak_ref(G_OBJECT(data->label), on_freespace_label_destroyed, data);
} }
@ -696,14 +696,14 @@ static TR_DEFINE_QUARK(freespace_label_data, freespace_label_data)
static void on_freespace_label_core_destroyed(gpointer gdata, GObject* dead_core G_GNUC_UNUSED) static void on_freespace_label_core_destroyed(gpointer gdata, GObject* dead_core G_GNUC_UNUSED)
{ {
auto* data = static_cast<freespace_label_data*>(gdata); auto* data = static_cast<freespace_label_data*>(gdata);
data->core = NULL; data->core = nullptr;
freespace_label_data_free(data); freespace_label_data_free(data);
} }
static void on_freespace_label_destroyed(gpointer gdata, GObject* dead_label G_GNUC_UNUSED) static void on_freespace_label_destroyed(gpointer gdata, GObject* dead_label G_GNUC_UNUSED)
{ {
auto* data = static_cast<freespace_label_data*>(gdata); auto* data = static_cast<freespace_label_data*>(gdata);
data->label = NULL; data->label = nullptr;
freespace_label_data_free(data); freespace_label_data_free(data);
} }
@ -742,7 +742,7 @@ GtkWidget* gtr_freespace_label_new(struct _TrCore* core, char const* dir)
data = g_new0(struct freespace_label_data, 1); data = g_new0(struct freespace_label_data, 1);
data->timer_id = g_timeout_add_seconds(3, on_freespace_timer, data); data->timer_id = g_timeout_add_seconds(3, on_freespace_timer, data);
data->core = core; data->core = core;
data->label = GTK_LABEL(gtk_label_new(NULL)); data->label = GTK_LABEL(gtk_label_new(nullptr));
data->dir = g_strdup(dir); data->dir = g_strdup(dir);
/* when either the core or the label is destroyed, stop updating */ /* when either the core or the label is destroyed, stop updating */

View File

@ -84,7 +84,7 @@ struct tr_scrape_response
/* the raw scrape url */ /* the raw scrape url */
std::string url; std::string url;
/* human-readable error string on failure, or NULL */ /* human-readable error string on failure, or nullptr */
std::string errmsg; std::string errmsg;
/* minimum interval (in seconds) allowed between scrapes. /* minimum interval (in seconds) allowed between scrapes.
@ -209,10 +209,10 @@ struct tr_announce_response
/* IPv6 peers that we acquired from the tracker */ /* IPv6 peers that we acquired from the tracker */
struct tr_pex* pex6; struct tr_pex* pex6;
/* human-readable error string on failure, or NULL */ /* human-readable error string on failure, or nullptr */
char* errmsg; char* errmsg;
/* human-readable warning string or NULL */ /* human-readable warning string or nullptr */
char* warning; char* warning;
/* key generated by and returned from an http tracker. /* key generated by and returned from an http tracker.

View File

@ -193,8 +193,8 @@ static void openssl_evp_cipher_context_free(EVP_CIPHER_CTX* handle)
static inline int DH_set0_pqg(DH* dh, BIGNUM* p, BIGNUM* q, BIGNUM* g) static inline int DH_set0_pqg(DH* dh, BIGNUM* p, BIGNUM* q, BIGNUM* g)
{ {
/* If the fields p and g in d are NULL, the corresponding input /* If the fields p and g in d are nullptr, the corresponding input
* parameters MUST be non-NULL. q may remain NULL. * parameters MUST be non-nullptr. q may remain nullptr.
*/ */
if ((dh->p == nullptr && p == nullptr) || (dh->g == nullptr && g == nullptr)) if ((dh->p == nullptr && p == nullptr) || (dh->g == nullptr && g == nullptr))
{ {

View File

@ -32,7 +32,7 @@ struct tr_error
* @param[in] code Error code (platform-specific). * @param[in] code Error code (platform-specific).
* @param[in] message Error message. * @param[in] message Error message.
* *
* @return Newly allocated error object on success, `NULL` otherwise. * @return Newly allocated error object on success, `nullptr` otherwise.
*/ */
tr_error* tr_error_new_literal(int code, char const* message); tr_error* tr_error_new_literal(int code, char const* message);
@ -43,7 +43,7 @@ tr_error* tr_error_new_literal(int code, char const* message);
* @param[in] message_format Error message format string. * @param[in] message_format Error message format string.
* @param[in] args Format arguments. * @param[in] args Format arguments.
* *
* @return Newly allocated error object on success, `NULL` otherwise. * @return Newly allocated error object on success, `nullptr` otherwise.
*/ */
tr_error* tr_error_new_valist(int code, char const* message_format, va_list args) TR_GNUC_PRINTF(2, 0); tr_error* tr_error_new_valist(int code, char const* message_format, va_list args) TR_GNUC_PRINTF(2, 0);
@ -57,7 +57,7 @@ void tr_error_free(tr_error* error);
/** /**
* @brief Create and set new error object using `printf`-style formatting. * @brief Create and set new error object using `printf`-style formatting.
* *
* If passed pointer to error object is `NULL`, do nothing. * If passed pointer to error object is `nullptr`, do nothing.
* *
* @param[in,out] error Pointer to error object to be set. * @param[in,out] error Pointer to error object to be set.
* @param[in] code Error code (platform-specific). * @param[in] code Error code (platform-specific).
@ -69,7 +69,7 @@ void tr_error_set(tr_error** error, int code, char const* message_format, ...) T
/** /**
* @brief Create and set new error object using literal error message. * @brief Create and set new error object using literal error message.
* *
* If passed pointer to error object is `NULL`, do nothing. * If passed pointer to error object is `nullptr`, do nothing.
* *
* @param[in,out] error Pointer to error object to be set. * @param[in,out] error Pointer to error object to be set.
* @param[in] code Error code (platform-specific). * @param[in] code Error code (platform-specific).
@ -80,8 +80,8 @@ void tr_error_set_literal(tr_error** error, int code, char const* message);
/** /**
* @brief Propagate existing error object upwards. * @brief Propagate existing error object upwards.
* *
* If passed pointer to new error object is not `NULL`, copy old error object to * If passed pointer to new error object is not `nullptr`, copy old error object
* new error object and free old error object. Otherwise, just free old error * to new error object and free old error object. Otherwise, just free old error
* object. * object.
* *
* @param[in,out] new_error Pointer to error object to be set. * @param[in,out] new_error Pointer to error object to be set.
@ -92,8 +92,8 @@ void tr_error_propagate(tr_error** new_error, tr_error** old_error);
/** /**
* @brief Clear error object. * @brief Clear error object.
* *
* Free error object being pointed and set pointer to `NULL`. If passed pointer * Free error object being pointed and set pointer to `nullptr`. If passed
* is `NULL`, do nothing. * pointer is `nullptr`, do nothing.
* *
* @param[in,out] error Pointer to error object to be cleared. * @param[in,out] error Pointer to error object to be cleared.
*/ */
@ -102,7 +102,7 @@ void tr_error_clear(tr_error** error);
/** /**
* @brief Prefix message of exising error object. * @brief Prefix message of exising error object.
* *
* If passed pointer to error object is not `NULL`, prefix its message with * If passed pointer to error object is not `nullptr`, prefix its message with
* `printf`-style formatted text. Otherwise, do nothing. * `printf`-style formatted text. Otherwise, do nothing.
* *
* @param[in,out] error Pointer to error object to be set. * @param[in,out] error Pointer to error object to be set.
@ -114,9 +114,9 @@ void tr_error_prefix(tr_error** error, char const* prefix_format, ...) TR_GNUC_P
/** /**
* @brief Prefix message and propagate existing error object upwards. * @brief Prefix message and propagate existing error object upwards.
* *
* If passed pointer to new error object is not `NULL`, copy old error object to * If passed pointer to new error object is not `nullptr`, copy old error object
* new error object, prefix its message with `printf`-style formatted text, and * to new error object, prefix its message with `printf`-style formatted text,
* free old error object. Otherwise, just free old error object. * and free old error object. Otherwise, just free old error object.
* *
* @param[in,out] new_error Pointer to error object to be set. * @param[in,out] new_error Pointer to error object to be set.
* @param[in,out] old_error Error object to be propagated. Cleared on return. * @param[in,out] old_error Error object to be propagated. Cleared on return.

View File

@ -139,8 +139,8 @@ struct tr_sys_path_info
* *
* @param[in] src_path Path to source file. * @param[in] src_path Path to source file.
* @param[in] dst_path Path to destination file. * @param[in] dst_path Path to destination file.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you * @param[out] error Pointer to error object. Optional, pass `nullptr` if
* are not interested in error details. * you are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -152,8 +152,8 @@ bool tr_sys_path_copy(char const* src_path, char const* dst_path, struct tr_erro
* @param[in] path Path to file or directory. * @param[in] path Path to file or directory.
* @param[in] flags Combination of @ref tr_sys_path_get_info_flags_t values. * @param[in] flags Combination of @ref tr_sys_path_get_info_flags_t values.
* @param[out] info Result buffer. * @param[out] info Result buffer.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -163,12 +163,12 @@ bool tr_sys_path_get_info(char const* path, int flags, tr_sys_path_info* info, s
* @brief Portability wrapper for `access()`. * @brief Portability wrapper for `access()`.
* *
* @param[in] path Path to file or directory. * @param[in] path Path to file or directory.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return `True` if path exists, `false` otherwise. Note that `false` will also * @return `True` if path exists, `false` otherwise. Note that `false` will also
* be returned in case of error; if you need to distinguish the two, * be returned in case of error; if you need to distinguish the two,
* check if `error` is `NULL` afterwards. * check if `error` is `nullptr` afterwards.
*/ */
bool tr_sys_path_exists(char const* path, struct tr_error** error); bool tr_sys_path_exists(char const* path, struct tr_error** error);
@ -186,14 +186,14 @@ bool tr_sys_path_is_relative(char const* path);
/** /**
* @brief Test to see if the two filenames point to the same file. * @brief Test to see if the two filenames point to the same file.
* *
* @param[in] path1 Path to first file or directory. * @param[in] path1 Path to first file or directory.
* @param[in] path2 Path to second file or directory. * @param[in] path2 Path to second file or directory.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if
* not interested in error details. * you are not interested in error details.
* *
* @return `True` if two paths point to the same file or directory, `false` * @return `True` if two paths point to the same file or directory, `false`
* otherwise. Note that `false` will also be returned in case of error; * otherwise. Note that `false` will also be returned in case of error;
* if you need to distinguish the two, check if `error` is `NULL` * if you need to distinguish the two, check if `error` is `nullptr`
* afterwards. * afterwards.
*/ */
bool tr_sys_path_is_same(char const* path1, char const* path2, struct tr_error** error); bool tr_sys_path_is_same(char const* path1, char const* path2, struct tr_error** error);
@ -202,12 +202,12 @@ bool tr_sys_path_is_same(char const* path1, char const* path2, struct tr_error**
* @brief Portability wrapper for `realpath()`. * @brief Portability wrapper for `realpath()`.
* *
* @param[in] path Path to file or directory. * @param[in] path Path to file or directory.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return Pointer to newly allocated buffer containing full path (with symbolic * @return Pointer to newly allocated buffer containing full path (with symbolic
* links, `.` and `..` resolved) on success (use @ref tr_free to free it * links, `.` and `..` resolved) on success (use @ref tr_free to free it
* when no longer needed), `NULL` otherwise (with `error` set * when no longer needed), `nullptr` otherwise (with `error` set
* accordingly). * accordingly).
*/ */
char* tr_sys_path_resolve(char const* path, struct tr_error** error); char* tr_sys_path_resolve(char const* path, struct tr_error** error);
@ -216,12 +216,12 @@ char* tr_sys_path_resolve(char const* path, struct tr_error** error);
* @brief Portability wrapper for `basename()`. * @brief Portability wrapper for `basename()`.
* *
* @param[in] path Path to file or directory. * @param[in] path Path to file or directory.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return Pointer to newly allocated buffer containing base name (last path * @return Pointer to newly allocated buffer containing base name (last path
* component; parent path removed) on success (use @ref tr_free to free * component; parent path removed) on success (use @ref tr_free to free
* it when no longer needed), `NULL` otherwise (with `error` set * it when no longer needed), `nullptr` otherwise (with `error` set
* accordingly). * accordingly).
*/ */
char* tr_sys_path_basename(char const* path, struct tr_error** error); char* tr_sys_path_basename(char const* path, struct tr_error** error);
@ -230,12 +230,12 @@ char* tr_sys_path_basename(char const* path, struct tr_error** error);
* @brief Portability wrapper for `dirname()`. * @brief Portability wrapper for `dirname()`.
* *
* @param[in] path Path to file or directory. * @param[in] path Path to file or directory.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return Pointer to newly allocated buffer containing directory (parent path; * @return Pointer to newly allocated buffer containing directory (parent path;
* last path component removed) on success (use @ref tr_free to free it * last path component removed) on success (use @ref tr_free to free it
* when no longer needed), `NULL` otherwise (with `error` set * when no longer needed), `nullptr` otherwise (with `error` set
* accordingly). * accordingly).
*/ */
char* tr_sys_path_dirname(char const* path, struct tr_error** error); char* tr_sys_path_dirname(char const* path, struct tr_error** error);
@ -245,7 +245,7 @@ char* tr_sys_path_dirname(char const* path, struct tr_error** error);
* *
* @param[in] src_path Path to source file or directory. * @param[in] src_path Path to source file or directory.
* @param[in] dst_path Path to destination file or directory. * @param[in] dst_path Path to destination file or directory.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* are not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
@ -258,8 +258,8 @@ bool tr_sys_path_rename(char const* src_path, char const* dst_path, struct tr_er
* @brief Portability wrapper for `remove()`. * @brief Portability wrapper for `remove()`.
* *
* @param[in] path Path to file or directory. * @param[in] path Path to file or directory.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
* Directory removal will only succeed if it is empty (contains no other * Directory removal will only succeed if it is empty (contains no other
@ -282,7 +282,7 @@ char* tr_sys_path_native_separators(char* path);
* @brief Get handle to one of standard I/O files. * @brief Get handle to one of standard I/O files.
* *
* @param[in] std_file Standard file identifier. * @param[in] std_file Standard file identifier.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* are not interested in error details. * are not interested in error details.
* *
* @return Opened file descriptor on success, `TR_BAD_SYS_FILE` otherwise (with * @return Opened file descriptor on success, `TR_BAD_SYS_FILE` otherwise (with
@ -298,8 +298,8 @@ tr_sys_file_t tr_sys_file_get_std(tr_std_sys_file_t std_file, struct tr_error**
* @param[in] flags Combination of @ref tr_sys_file_open_flags_t values. * @param[in] flags Combination of @ref tr_sys_file_open_flags_t values.
* @param[in] permissions Permissions to create file with (in case * @param[in] permissions Permissions to create file with (in case
@ref TR_SYS_FILE_CREATE is used). Not used on Windows. @ref TR_SYS_FILE_CREATE is used). Not used on Windows.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you * @param[out] error Pointer to error object. Optional, pass `nullptr` if
* are not interested in error details. * you are not interested in error details.
* *
* @return Opened file descriptor on success, `TR_BAD_SYS_FILE` otherwise (with * @return Opened file descriptor on success, `TR_BAD_SYS_FILE` otherwise (with
* `error` set accordingly). * `error` set accordingly).
@ -314,7 +314,7 @@ tr_sys_file_t tr_sys_file_open(char const* path, int flags, int permissions, str
* characters are replaced with actual random * characters are replaced with actual random
* characters used to form a unique path to * characters used to form a unique path to
* temporary file. * temporary file.
* @param[out] error Pointer to error object. Optional, pass `NULL` * @param[out] error Pointer to error object. Optional, pass `nullptr`
* if you are not interested in error details. * if you are not interested in error details.
* *
* @return Opened file descriptor on success, `TR_BAD_SYS_FILE` otherwise (with * @return Opened file descriptor on success, `TR_BAD_SYS_FILE` otherwise (with
@ -326,8 +326,8 @@ tr_sys_file_t tr_sys_file_open_temp(char* path_template, struct tr_error** error
* @brief Portability wrapper for `close()`. * @brief Portability wrapper for `close()`.
* *
* @param[in] handle Valid file descriptor. * @param[in] handle Valid file descriptor.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -338,8 +338,8 @@ bool tr_sys_file_close(tr_sys_file_t handle, struct tr_error** error);
* *
* @param[in] handle Valid file descriptor. * @param[in] handle Valid file descriptor.
* @param[out] info Result buffer. * @param[out] info Result buffer.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -352,9 +352,9 @@ bool tr_sys_file_get_info(tr_sys_file_t handle, tr_sys_path_info* info, struct t
* @param[in] offset Relative file offset in bytes to seek to. * @param[in] offset Relative file offset in bytes to seek to.
* @param[in] origin Offset origin. * @param[in] origin Offset origin.
* @param[out] new_offset New offset in bytes from beginning of file. Optional, * @param[out] new_offset New offset in bytes from beginning of file. Optional,
* pass `NULL` if you are not interested. * pass `nullptr` if you are not interested.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you * @param[out] error Pointer to error object. Optional, pass `nullptr` if
* are not interested in error details. * you are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -371,10 +371,10 @@ bool tr_sys_file_seek(
* @param[in] handle Valid file descriptor. * @param[in] handle Valid file descriptor.
* @param[out] buffer Buffer to store read data to. * @param[out] buffer Buffer to store read data to.
* @param[in] size Number of bytes to read. * @param[in] size Number of bytes to read.
* @param[out] bytes_read Number of bytes actually read. Optional, pass `NULL` * @param[out] bytes_read Number of bytes actually read. Optional, pass `nullptr`
* if you are not interested. * if you are not interested.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you * @param[out] error Pointer to error object. Optional, pass `nullptr` if
* are not interested in error details. * you are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -388,10 +388,10 @@ bool tr_sys_file_read(tr_sys_file_t handle, void* buffer, uint64_t size, uint64_
* @param[out] buffer Buffer to store read data to. * @param[out] buffer Buffer to store read data to.
* @param[in] size Number of bytes to read. * @param[in] size Number of bytes to read.
* @param[in] offset File offset in bytes to start reading from. * @param[in] offset File offset in bytes to start reading from.
* @param[out] bytes_read Number of bytes actually read. Optional, pass `NULL` * @param[out] bytes_read Number of bytes actually read. Optional, pass `nullptr`
* if you are not interested. * if you are not interested.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you * @param[out] error Pointer to error object. Optional, pass `nullptr` if
* are not interested in error details. * you are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -410,8 +410,8 @@ bool tr_sys_file_read_at(
* @param[in] buffer Buffer to get data being written from. * @param[in] buffer Buffer to get data being written from.
* @param[in] size Number of bytes to write. * @param[in] size Number of bytes to write.
* @param[out] bytes_written Number of bytes actually written. Optional, pass * @param[out] bytes_written Number of bytes actually written. Optional, pass
* `NULL` if you are not interested. * `nullptr` if you are not interested.
* @param[out] error Pointer to error object. Optional, pass `NULL` if * @param[out] error Pointer to error object. Optional, pass `nullptr` if
* you are not interested in error details. * you are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
@ -432,9 +432,9 @@ bool tr_sys_file_write(
* @param[in] size Number of bytes to write. * @param[in] size Number of bytes to write.
* @param[in] offset File offset in bytes to start writing from. * @param[in] offset File offset in bytes to start writing from.
* @param[out] bytes_written Number of bytes actually written. Optional, pass * @param[out] bytes_written Number of bytes actually written. Optional, pass
* `NULL` if you are not interested. * `nullptr` if you are not interested.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you * @param[out] error Pointer to error object. Optional, pass `nullptr`
* are not interested in error details. * if you are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -450,8 +450,8 @@ bool tr_sys_file_write_at(
* @brief Portability wrapper for `fsync()`. * @brief Portability wrapper for `fsync()`.
* *
* @param[in] handle Valid file descriptor. * @param[in] handle Valid file descriptor.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -462,8 +462,8 @@ bool tr_sys_file_flush(tr_sys_file_t handle, struct tr_error** error);
* *
* @param[in] handle Valid file descriptor. * @param[in] handle Valid file descriptor.
* @param[in] size Number of bytes to truncate (or extend) file to. * @param[in] size Number of bytes to truncate (or extend) file to.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -475,8 +475,8 @@ bool tr_sys_file_truncate(tr_sys_file_t handle, uint64_t size, struct tr_error**
* @param[in] handle Valid file descriptor. * @param[in] handle Valid file descriptor.
* @param[in] offset Offset in file to prefetch from. * @param[in] offset Offset in file to prefetch from.
* @param[in] size Number of bytes to prefetch. * @param[in] size Number of bytes to prefetch.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -493,8 +493,8 @@ bool tr_sys_file_advise(
* @param[in] handle Valid file descriptor. * @param[in] handle Valid file descriptor.
* @param[in] size Number of bytes to preallocate file to. * @param[in] size Number of bytes to preallocate file to.
* @param[in] flags Combination of @ref tr_sys_file_preallocate_flags_t values. * @param[in] flags Combination of @ref tr_sys_file_preallocate_flags_t values.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -506,10 +506,10 @@ bool tr_sys_file_preallocate(tr_sys_file_t handle, uint64_t size, int flags, str
* @param[in] handle Valid file descriptor. * @param[in] handle Valid file descriptor.
* @param[in] offset Offset in file to map from. * @param[in] offset Offset in file to map from.
* @param[in] size Number of bytes to map. * @param[in] size Number of bytes to map.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return Pointer to mapped file data on success, `NULL` otherwise (with * @return Pointer to mapped file data on success, `nullptr` otherwise (with
* `error` set accordingly). * `error` set accordingly).
*/ */
void* tr_sys_file_map_for_reading(tr_sys_file_t handle, uint64_t offset, uint64_t size, struct tr_error** error); void* tr_sys_file_map_for_reading(tr_sys_file_t handle, uint64_t offset, uint64_t size, struct tr_error** error);
@ -519,8 +519,8 @@ void* tr_sys_file_map_for_reading(tr_sys_file_t handle, uint64_t offset, uint64_
* *
* @param[in] address Pointer to mapped file data. * @param[in] address Pointer to mapped file data.
* @param[in] size Size of mapped data in bytes. * @param[in] size Size of mapped data in bytes.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -534,7 +534,7 @@ bool tr_sys_file_unmap(void const* address, uint64_t size, struct tr_error** err
* *
* @param[in] handle Valid file descriptor. * @param[in] handle Valid file descriptor.
* @param[in] operation Combination of @ref tr_sys_file_lock_flags_t values. * @param[in] operation Combination of @ref tr_sys_file_lock_flags_t values.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* are not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
@ -556,12 +556,12 @@ bool tr_sys_file_lock(tr_sys_file_t handle, int operation, struct tr_error** err
* @param[out] buffer Buffer to store read zero-terminated string to. * @param[out] buffer Buffer to store read zero-terminated string to.
* @param[in] buffer_size Buffer size in bytes, taking '\0' character into * @param[in] buffer_size Buffer size in bytes, taking '\0' character into
* account. * account.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you * @param[out] error Pointer to error object. Optional, pass `nullptr` if
* are not interested in error details. * you are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
* Note that `false` will also be returned in case of end of file; if * Note that `false` will also be returned in case of end of file; if
* you need to distinguish the two, check if `error` is `NULL` * you need to distinguish the two, check if `error` is `nullptr`
* afterwards. * afterwards.
*/ */
bool tr_sys_file_read_line(tr_sys_file_t handle, char* buffer, size_t buffer_size, struct tr_error** error); bool tr_sys_file_read_line(tr_sys_file_t handle, char* buffer, size_t buffer_size, struct tr_error** error);
@ -577,8 +577,8 @@ bool tr_sys_file_read_line(tr_sys_file_t handle, char* buffer, size_t buffer_siz
* *
* @param[in] handle Valid file descriptor. * @param[in] handle Valid file descriptor.
* @param[in] buffer Zero-terminated string to write. * @param[in] buffer Zero-terminated string to write.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -595,8 +595,8 @@ bool tr_sys_file_write_line(tr_sys_file_t handle, char const* buffer, struct tr_
* *
* @param[in] handle Valid file descriptor. * @param[in] handle Valid file descriptor.
* @param[in] format String format to write. * @param[in] format String format to write.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* @param[in] ... Format arguments. * @param[in] ... Format arguments.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
@ -608,12 +608,12 @@ bool tr_sys_file_write_fmt(tr_sys_file_t handle, char const* format, struct tr_e
/** /**
* @brief Portability wrapper for `getcwd()`. * @brief Portability wrapper for `getcwd()`.
* *
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you are
* not interested in error details. * not interested in error details.
* *
* @return Pointer to newly allocated buffer containing path to current * @return Pointer to newly allocated buffer containing path to current
* directory (use @ref tr_free to free it when no longer needed) on * directory (use @ref tr_free to free it when no longer needed) on
* success, `NULL` otherwise (with `error` set accordingly). * success, `nullptr` otherwise (with `error` set accordingly).
*/ */
char* tr_sys_dir_get_current(struct tr_error** error); char* tr_sys_dir_get_current(struct tr_error** error);
@ -624,8 +624,8 @@ char* tr_sys_dir_get_current(struct tr_error** error);
* @param[in] flags Combination of @ref tr_sys_dir_create_flags_t values. * @param[in] flags Combination of @ref tr_sys_dir_create_flags_t values.
* @param[in] permissions Permissions to create directory with. Not used on * @param[in] permissions Permissions to create directory with. Not used on
Windows. Windows.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you * @param[out] error Pointer to error object. Optional, pass `nullptr` if
* are not interested in error details. * you are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */
@ -639,7 +639,7 @@ bool tr_sys_dir_create(char const* path, int flags, int permissions, struct tr_e
* 'X' characters are replaced with actual random * 'X' characters are replaced with actual random
* characters used to form a unique path to * characters used to form a unique path to
* temporary directory. * temporary directory.
* @param[out] error Pointer to error object. Optional, pass `NULL` * @param[out] error Pointer to error object. Optional, pass `nullptr`
* if you are not interested in error details. * if you are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
@ -650,7 +650,7 @@ bool tr_sys_dir_create_temp(char* path_template, struct tr_error** error);
* @brief Portability wrapper for `opendir()`. * @brief Portability wrapper for `opendir()`.
* *
* @param[in] path Path to directory. * @param[in] path Path to directory.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you are
* not interested in error details. * not interested in error details.
* *
* @return Opened directory descriptor on success, `TR_BAD_SYS_DIR` otherwise * @return Opened directory descriptor on success, `TR_BAD_SYS_DIR` otherwise
@ -662,14 +662,14 @@ tr_sys_dir_t tr_sys_dir_open(char const* path, struct tr_error** error);
* @brief Portability wrapper for `readdir()`. * @brief Portability wrapper for `readdir()`.
* *
* @param[in] handle Valid directory descriptor. * @param[in] handle Valid directory descriptor.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return Pointer to next directory entry name (stored internally, DO NOT pass * @return Pointer to next directory entry name (stored internally, DO NOT pass
* it to @ref tr_free) on success, `NULL` otherwise (with `error` set * it to @ref tr_free) on success, `nullptr` otherwise (with `error` set
* accordingly). Note that `NULL` will also be returned in case of end * accordingly). Note that `nullptr` will also be returned in case of end
* of directory; if you need to distinguish the two, check if `error` * of directory; if you need to distinguish the two, check if `error`
* is `NULL` afterwards. * is `nullptr` afterwards.
*/ */
char const* tr_sys_dir_read_name(tr_sys_dir_t handle, struct tr_error** error); char const* tr_sys_dir_read_name(tr_sys_dir_t handle, struct tr_error** error);
@ -677,8 +677,8 @@ char const* tr_sys_dir_read_name(tr_sys_dir_t handle, struct tr_error** error);
* @brief Portability wrapper for `closedir()`. * @brief Portability wrapper for `closedir()`.
* *
* @param[in] handle Valid directory descriptor. * @param[in] handle Valid directory descriptor.
* @param[out] error Pointer to error object. Optional, pass `NULL` if you are * @param[out] error Pointer to error object. Optional, pass `nullptr` if you
* not interested in error details. * are not interested in error details.
* *
* @return `True` on success, `false` otherwise (with `error` set accordingly). * @return `True` on success, `false` otherwise (with `error` set accordingly).
*/ */

View File

@ -45,7 +45,7 @@ void tr_logAddMessage(char const* file, int line, tr_log_level level, char const
#define tr_logAddTorInfo(tor, ...) tr_logAddTor(TR_LOG_INFO, tor, __VA_ARGS__) #define tr_logAddTorInfo(tor, ...) tr_logAddTor(TR_LOG_INFO, tor, __VA_ARGS__)
#define tr_logAddTorDbg(tor, ...) tr_logAddTor(TR_LOG_DEBUG, tor, __VA_ARGS__) #define tr_logAddTorDbg(tor, ...) tr_logAddTor(TR_LOG_DEBUG, tor, __VA_ARGS__)
#define tr_logAdd(level, ...) tr_logAddNamed(level, NULL, __VA_ARGS__) #define tr_logAdd(level, ...) tr_logAddNamed(level, nullptr, __VA_ARGS__)
#define tr_logAddError(...) tr_logAdd(TR_LOG_ERROR, __VA_ARGS__) #define tr_logAddError(...) tr_logAdd(TR_LOG_ERROR, __VA_ARGS__)
#define tr_logAddInfo(...) tr_logAdd(TR_LOG_INFO, __VA_ARGS__) #define tr_logAddInfo(...) tr_logAdd(TR_LOG_INFO, __VA_ARGS__)

View File

@ -102,7 +102,7 @@ void tr_metaInfoBuilderFree(tr_metainfo_builder*);
* from time to time! When the worker thread sets that flag, * from time to time! When the worker thread sets that flag,
* the caller must pass the builder to tr_metaInfoBuilderFree(). * the caller must pass the builder to tr_metaInfoBuilderFree().
* *
* @param outputFile if NULL, builder->top + ".torrent" will be used. * @param outputFile if nullptr, builder->top + ".torrent" will be used.
* @param trackers An array of trackers, sorted by tier from first to last. * @param trackers An array of trackers, sorted by tier from first to last.
* NOTE: only the `tier' and `announce' fields are used. * NOTE: only the `tier' and `announce' fields are used.

View File

@ -117,7 +117,7 @@ struct peer_atom
/* similar to a TTL field, but less rigid -- /* similar to a TTL field, but less rigid --
* if the swarm is small, the atom will be kept past this date. */ * if the swarm is small, the atom will be kept past this date. */
time_t shelf_date; time_t shelf_date;
tr_peer* peer; /* will be NULL if not connected */ tr_peer* peer; /* will be nullptr if not connected */
tr_address addr; tr_address addr;
}; };
@ -175,7 +175,7 @@ struct tr_swarm
tr_torrent* tor; tr_torrent* tor;
struct tr_peerMgr* manager; struct tr_peerMgr* manager;
tr_peerMsgs* optimistic; /* the optimistic peer, or NULL if none */ tr_peerMsgs* optimistic; /* the optimistic peer, or nullptr if none */
int optimisticUnchokeTimeScaler; int optimisticUnchokeTimeScaler;
bool poolIsAllSeeds; bool poolIsAllSeeds;
@ -193,7 +193,7 @@ struct tr_swarm
/* An array of pieceCount items stating how many peers have each piece. /* An array of pieceCount items stating how many peers have each piece.
This is used to help us for downloading pieces "rarest first." This is used to help us for downloading pieces "rarest first."
This may be NULL if we don't have metainfo yet, or if we're not This may be nullptr if we don't have metainfo yet, or if we're not
downloading and don't care about rarity */ downloading and don't care about rarity */
uint16_t* pieceReplication; uint16_t* pieceReplication;
size_t pieceReplicationSize; size_t pieceReplicationSize;
@ -733,7 +733,7 @@ static auto getBlockRequestPeers(tr_swarm* s, tr_block_index_t block)
bool exact; bool exact;
int const pos = tr_lowerBound(&key, s->requests, s->requestCount, sizeof(struct block_request), compareReqByBlock, &exact); int const pos = tr_lowerBound(&key, s->requests, s->requestCount, sizeof(struct block_request), compareReqByBlock, &exact);
TR_ASSERT(!exact); /* shouldn't have a request with .peer == NULL */ TR_ASSERT(!exact); /* shouldn't have a request with .peer == nullptr */
for (int i = pos; i < s->requestCount; ++i) for (int i = pos; i < s->requestCount; ++i)
{ {

View File

@ -57,7 +57,7 @@ static inline void* tr_ptrArrayNth(tr_ptrArray* array, int i)
void* tr_ptrArrayPop(tr_ptrArray* array); void* tr_ptrArrayPop(tr_ptrArray* array);
/** @brief Return the last item in a tr_ptrArray /** @brief Return the last item in a tr_ptrArray
@return the last item in a tr_ptrArray, or NULL if the array is empty @return the last item in a tr_ptrArray, or nullptr if the array is empty
@see tr_ptrArrayPop() */ @see tr_ptrArrayPop() */
static inline void* tr_ptrArrayBack(tr_ptrArray* array) static inline void* tr_ptrArrayBack(tr_ptrArray* array)
{ {
@ -118,7 +118,7 @@ int tr_ptrArrayInsertSorted(tr_ptrArray* array, void* value, tr_voidptr_compare_
void tr_ptrArrayRemoveSortedPointer(tr_ptrArray* t, void const* ptr, tr_voidptr_compare_func compare); void tr_ptrArrayRemoveSortedPointer(tr_ptrArray* t, void const* ptr, tr_voidptr_compare_func compare);
/** @brief Find a pointer from an array sorted by the specified sort function /** @brief Find a pointer from an array sorted by the specified sort function
@return the matching pointer, or NULL if no match was found */ @return the matching pointer, or nullptr if no match was found */
void* tr_ptrArrayFindSorted(tr_ptrArray* array, void const* key, tr_voidptr_compare_func compare); void* tr_ptrArrayFindSorted(tr_ptrArray* array, void const* key, tr_voidptr_compare_func compare);
/* @} */ /* @} */

View File

@ -380,7 +380,7 @@ void tr_torrentGotBlock(tr_torrent* tor, tr_block_index_t blockIndex);
/** /**
* @brief Like tr_torrentFindFile(), but splits the filename into base and subpath. * @brief Like tr_torrentFindFile(), but splits the filename into base and subpath.
* *
* If the file is found, "tr_buildPath(base, subpath, NULL)" * If the file is found, "tr_buildPath(base, subpath, nullptr)"
* will generate the complete filename. * will generate the complete filename.
* *
* @return true if the file is found, false otherwise. * @return true if the file is found, false otherwise.

View File

@ -156,17 +156,17 @@ static int lpd_unsolicitedMsgCounter;
/** /**
* @brief Checks for BT-SEARCH method and separates the parameter section * @brief Checks for BT-SEARCH method and separates the parameter section
* @param[in] s The request string * @param[in] s The request string
* @param[out] ver If non-NULL, gets filled with protocol info from the request * @param[out] ver If non-nullptr, gets filled with protocol info from the request
* @return Returns a relative pointer to the beginning of the parameter section. * @return Returns a relative pointer to the beginning of the parameter section.
* If result is NULL, s was invalid and no information will be returned * If result is nullptr, s was invalid and no information will be returned
* @remark Note that the returned pointer is only usable as long as the given * @remark Note that the returned pointer is only usable as long as the given
* pointer s is valid; that is, return storage is temporary. * pointer s is valid; that is, return storage is temporary.
* *
* Determines whether the given string checks out to be a valid BT-SEARCH message. * Determines whether the given string checks out to be a valid BT-SEARCH message.
* If so, the return value points to the beginning of the parameter section (note: * If so, the return value points to the beginning of the parameter section (note:
* in this case the function returns a character sequence beginning with CRLF). * in this case the function returns a character sequence beginning with CRLF).
* If parameter is not NULL, the declared protocol version is returned as part of * If parameter is not nullptr, the declared protocol version is returned as part
* the lpd_protocolVersion structure. * of the lpd_protocolVersion structure.
*/ */
static char const* lpd_extractHeader(char const* s, struct lpd_protocolVersion* const ver) static char const* lpd_extractHeader(char const* s, struct lpd_protocolVersion* const ver)
{ {

View File

@ -741,7 +741,7 @@ struct tr_log_message
/* The torrent associated with this message, /* The torrent associated with this message,
* or a module name such as "Port Forwarding" for non-torrent messages, * or a module name such as "Port Forwarding" for non-torrent messages,
* or NULL. */ * or nullptr. */
char* name; char* name;
/* The message */ /* The message */
@ -776,7 +776,7 @@ void tr_logFreeQueue(tr_log_message* freeme);
* The caller only needs to invoke this when the blocklist * The caller only needs to invoke this when the blocklist
* has changed. * has changed.
* *
* Passing NULL for a filename will clear the blocklist. * Passing nullptr for a filename will clear the blocklist.
*/ */
int tr_blocklistSetContent(tr_session* session, char const* filename); int tr_blocklistSetContent(tr_session* session, char const* filename);
@ -833,11 +833,11 @@ enum tr_ctorMode
}; };
/** @brief Create a torrent constructor object used to instantiate a tr_torrent /** @brief Create a torrent constructor object used to instantiate a tr_torrent
@param session_or_NULL the tr_session. @param session_or_nullptr the tr_session.
This is required if you're going to call tr_torrentNew(), This is required if you're going to call tr_torrentNew(),
but you can use NULL for tr_torrentParse(). but you can use nullptr for tr_torrentParse().
@see tr_torrentNew(), tr_torrentParse() */ @see tr_torrentNew(), tr_torrentParse() */
tr_ctor* tr_ctorNew(tr_session const* session_or_NULL); tr_ctor* tr_ctorNew(tr_session const* session_or_nullptr);
/** @brief Free a torrent constructor object */ /** @brief Free a torrent constructor object */
void tr_ctorFree(tr_ctor* ctor); void tr_ctorFree(tr_ctor* ctor);
@ -913,7 +913,7 @@ bool tr_ctorGetDeleteSource(tr_ctor const* ctor, bool* setmeDoDelete);
tr_session* tr_ctorGetSession(tr_ctor const* ctor); tr_session* tr_ctorGetSession(tr_ctor const* ctor);
/** @brief Get the .torrent file that this ctor's metainfo came from, /** @brief Get the .torrent file that this ctor's metainfo came from,
or NULL if tr_ctorSetMetainfoFromFile() wasn't used */ or nullptr if tr_ctorSetMetainfoFromFile() wasn't used */
char const* tr_ctorGetSourceFile(tr_ctor const* ctor); char const* tr_ctorGetSourceFile(tr_ctor const* ctor);
enum tr_parse_result enum tr_parse_result
@ -930,9 +930,9 @@ enum tr_parse_result
* TR_PARSE_OK if parsing succeeded and it's not a duplicate; * TR_PARSE_OK if parsing succeeded and it's not a duplicate;
* TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate. * TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate.
* *
* @param setme_info_or_NULL If parsing is successful and setme_info is non-NULL, * @param setme_info_or_nullptr If parsing is successful and setme_info is non-nullptr,
* the parsed metainfo is stored there and sould be freed * the parsed metainfo is stored there and sould be freed
* by calling tr_metainfoFree() when no longer needed. * by calling tr_metainfoFree() when no longer needed.
* *
* Notes: * Notes:
* *
@ -943,7 +943,7 @@ enum tr_parse_result
* 2. setme_info->torrent's value can't be set unless ctor's session variable * 2. setme_info->torrent's value can't be set unless ctor's session variable
* is set. * is set.
*/ */
tr_parse_result tr_torrentParse(tr_ctor const* ctor, tr_info* setme_info_or_NULL); tr_parse_result tr_torrentParse(tr_ctor const* ctor, tr_info* setme_info_or_nullptr);
/** @brief free a metainfo /** @brief free a metainfo
@see tr_torrentParse */ @see tr_torrentParse */
@ -952,7 +952,7 @@ void tr_metainfoFree(tr_info* inf);
/** /**
* Instantiate a single torrent. * Instantiate a single torrent.
* *
* Returns a pointer to the torrent on success, or NULL on failure. * Returns a pointer to the torrent on success, or nullptr on failure.
* *
* @param ctor the builder struct * @param ctor the builder struct
* @param setme_error TR_PARSE_ERR if the parsing failed. * @param setme_error TR_PARSE_ERR if the parsing failed.
@ -997,7 +997,7 @@ using tr_torrent_rename_done_func = void (*)( //
* @param tor the torrent whose path will be renamed * @param tor the torrent whose path will be renamed
* @param oldpath the path to the file or folder that will be renamed * @param oldpath the path to the file or folder that will be renamed
* @param newname the file or folder's new name * @param newname the file or folder's new name
* @param callback the callback invoked when the renaming finishes, or NULL * @param callback the callback invoked when the renaming finishes, or nullptr
* @param callback_data the pointer to pass in the callback's user_data arg * @param callback_data the pointer to pass in the callback's user_data arg
* *
* As a special case, renaming the root file in a torrent will also * As a special case, renaming the root file in a torrent will also
@ -1021,12 +1021,12 @@ using tr_torrent_rename_done_func = void (*)( //
* *
* Changing tr_info's contents requires a session lock, so this function * Changing tr_info's contents requires a session lock, so this function
* returns asynchronously to avoid blocking. If you don't want to be notified * returns asynchronously to avoid blocking. If you don't want to be notified
* when the function has finished, you can pass NULL as the callback arg. * when the function has finished, you can pass nullptr as the callback arg.
* *
* On success, the callback's error argument will be 0. * On success, the callback's error argument will be 0.
* *
* If oldpath can't be found in files[*].name, or if newname is already * If oldpath can't be found in files[*].name, or if newname is already
* in files[*].name, or contains a directory separator, or is NULL, "", * in files[*].name, or contains a directory separator, or is nullptr, "",
* ".", or "..", the error argument will be EINVAL. * ".", or "..", the error argument will be EINVAL.
* *
* If the path exists on disk but can't be renamed, the error argument * If the path exists on disk but can't be renamed, the error argument
@ -1088,7 +1088,7 @@ char const* tr_torrentName(tr_torrent const*);
* the ".part" suffix, looking in downloadDir and incompleteDir, etc. * the ".part" suffix, looking in downloadDir and incompleteDir, etc.
* @return a newly-allocated string (that must be tr_free()d by the caller * @return a newly-allocated string (that must be tr_free()d by the caller
* when done) that gives the location of this file on disk, * when done) that gives the location of this file on disk,
* or NULL if no file exists yet. * or nullptr if no file exists yet.
* @param tor the torrent whose file we're looking for * @param tor the torrent whose file we're looking for
* @param fileNum the fileIndex, in [0...tr_info.fileCount) * @param fileNum the fileIndex, in [0...tr_info.fileCount)
*/ */
@ -1564,11 +1564,11 @@ using tr_verify_done_func = void (*)(tr_torrent* torrent, bool aborted, void* us
/** /**
* Queue a torrent for verification. * Queue a torrent for verification.
* *
* If callback_func is non-NULL, it will be called from the libtransmission * If callback_func is non-nullptr, it will be called from the libtransmission
* thread after the torrent's completness state is updated after the * thread after the torrent's completness state is updated after the
* file verification pass. * file verification pass.
*/ */
void tr_torrentVerify(tr_torrent* torrent, tr_verify_done_func callback_func_or_NULL, void* callback_data_or_NULL); void tr_torrentVerify(tr_torrent* torrent, tr_verify_done_func callback_func_or_nullptr, void* callback_data_or_nullptr);
/*********************************************************************** /***********************************************************************
* tr_info * tr_info
@ -1643,7 +1643,7 @@ struct tr_info
static inline bool tr_torrentHasMetadata(tr_torrent const* tor) static inline bool tr_torrentHasMetadata(tr_torrent const* tor)
{ {
tr_info const* const inf = tr_torrentInfo(tor); tr_info const* const inf = tr_torrentInfo(tor);
return (inf != NULL) && (inf->fileCount > 0); return (inf != nullptr) && (inf->fileCount > 0);
} }
/** /**

View File

@ -1419,7 +1419,7 @@ static bool parseNumberSection(char const* str, char const* const end, number_ra
* array of setmeCount ints of all the values in the array. * array of setmeCount ints of all the values in the array.
* For example, "5-8" will return [ 5, 6, 7, 8 ] and setmeCount will be 4. * For example, "5-8" will return [ 5, 6, 7, 8 ] and setmeCount will be 4.
* It's the caller's responsibility to call tr_free () on the returned array. * It's the caller's responsibility to call tr_free () on the returned array.
* If a fragment of the string can't be parsed, NULL is returned. * If a fragment of the string can't be parsed, nullptr is returned.
*/ */
std::vector<int> tr_parseNumberRange(char const* str, size_t len) // TODO: string_view std::vector<int> tr_parseNumberRange(char const* str, size_t len) // TODO: string_view
{ {

View File

@ -162,10 +162,10 @@ void* tr_malloc0(size_t size);
/** @brief Portability wrapper around reallocf() in which `0' is a safe argument */ /** @brief Portability wrapper around reallocf() in which `0' is a safe argument */
void* tr_realloc(void* p, size_t size); void* tr_realloc(void* p, size_t size);
/** @brief Portability wrapper around free() in which `NULL' is a safe argument */ /** @brief Portability wrapper around free() in which `nullptr' is a safe argument */
void tr_free(void* p); void tr_free(void* p);
/** @brief Free pointers in a NULL-terminated array (the array itself is not freed) */ /** @brief Free pointers in a nullptr-terminated array (the array itself is not freed) */
void tr_free_ptrv(void* const* p); void tr_free_ptrv(void* const* p);
/** /**
@ -198,13 +198,13 @@ char* tr_strndup(void const* in, size_t len) TR_GNUC_MALLOC;
char* tr_strdup(void const* in); char* tr_strdup(void const* in);
/** /**
* @brief like strcmp() but gracefully handles NULL strings * @brief like strcmp() but gracefully handles nullptr strings
*/ */
int tr_strcmp0(char const* str1, char const* str2); int tr_strcmp0(char const* str1, char const* str2);
static inline bool tr_str_is_empty(char const* value) static inline bool tr_str_is_empty(char const* value)
{ {
return value == NULL || *value == '\0'; return value == nullptr || *value == '\0';
} }
char* evbuffer_free_to_str(struct evbuffer* buf, size_t* result_len); char* evbuffer_free_to_str(struct evbuffer* buf, size_t* result_len);
@ -231,7 +231,7 @@ size_t tr_strlcpy(void* dst, void const* src, size_t siz);
/** @brief Portability wrapper for snprintf() that uses the system implementation if available */ /** @brief Portability wrapper for snprintf() that uses the system implementation if available */
int tr_snprintf(void* buf, size_t buflen, char const* fmt, ...) TR_GNUC_PRINTF(3, 4) TR_GNUC_NONNULL(1, 3); int tr_snprintf(void* buf, size_t buflen, char const* fmt, ...) TR_GNUC_PRINTF(3, 4) TR_GNUC_NONNULL(1, 3);
/** @brief Convenience wrapper around strerorr() guaranteed to not return NULL /** @brief Convenience wrapper around strerorr() guaranteed to not return nullptr
@param errnum the error number to describe */ @param errnum the error number to describe */
char const* tr_strerror(int errnum); char const* tr_strerror(int errnum);
@ -280,7 +280,7 @@ double tr_getRatio(uint64_t numerator, uint64_t denominator);
* @brief Given a string like "1-4" or "1-4,6,9,14-51", this returns a * @brief Given a string like "1-4" or "1-4,6,9,14-51", this returns a
* newly-allocated array of all the integers in the set. * newly-allocated array of all the integers in the set.
* @return a newly-allocated array of integers that must be freed with tr_free(), * @return a newly-allocated array of integers that must be freed with tr_free(),
* or NULL if a fragment of the string can't be parsed. * or nullptr if a fragment of the string can't be parsed.
* *
* For example, "5-8" will return [ 5, 6, 7, 8 ] and setmeCount will be 4. * For example, "5-8" will return [ 5, 6, 7, 8 ] and setmeCount will be 4.
*/ */
@ -339,7 +339,7 @@ void tr_removeElementFromArray(void* array, size_t index_to_remove, size_t sizeo
extern time_t __tr_current_time; extern time_t __tr_current_time;
/** /**
* @brief very inexpensive form of time(NULL) * @brief very inexpensive form of time(nullptr)
* @return the current epoch time in seconds * @return the current epoch time in seconds
* *
* This function returns a second counter that is updated once per second. * This function returns a second counter that is updated once per second.

View File

@ -208,7 +208,7 @@ static void tr_variant_string_set_string(struct tr_variant_string* str, char con
} }
else else
{ {
char* tmp = tr_new(char, len + 1); auto* tmp = tr_new(char, len + 1);
memcpy(tmp, bytes, len); memcpy(tmp, bytes, len);
tmp[len] = '\0'; tmp[len] = '\0';
str->type = TR_STRING_TYPE_HEAP; str->type = TR_STRING_TYPE_HEAP;

View File

@ -124,7 +124,7 @@ int tr_variantFromBuf(
static inline int tr_variantFromBenc(tr_variant* setme, void const* buf, size_t buflen) static inline int tr_variantFromBenc(tr_variant* setme, void const* buf, size_t buflen)
{ {
return tr_variantFromBuf(setme, TR_VARIANT_FMT_BENC, buf, buflen, NULL, NULL); return tr_variantFromBuf(setme, TR_VARIANT_FMT_BENC, buf, buflen, nullptr, nullptr);
} }
static inline int tr_variantFromBencFull( static inline int tr_variantFromBencFull(
@ -149,12 +149,12 @@ static inline int tr_variantFromJsonFull(
static inline int tr_variantFromJson(tr_variant* setme, void const* buf, size_t buflen) static inline int tr_variantFromJson(tr_variant* setme, void const* buf, size_t buflen)
{ {
return tr_variantFromBuf(setme, TR_VARIANT_FMT_JSON, buf, buflen, NULL, NULL); return tr_variantFromBuf(setme, TR_VARIANT_FMT_JSON, buf, buflen, nullptr, nullptr);
} }
static inline bool tr_variantIsType(tr_variant const* b, int type) static inline bool tr_variantIsType(tr_variant const* b, int type)
{ {
return b != NULL && b->type == type; return b != nullptr && b->type == type;
} }
/*** /***
@ -163,7 +163,7 @@ static inline bool tr_variantIsType(tr_variant const* b, int type)
static inline bool tr_variantIsString(tr_variant const* b) static inline bool tr_variantIsString(tr_variant const* b)
{ {
return b != NULL && b->type == TR_VARIANT_TYPE_STR; return b != nullptr && b->type == TR_VARIANT_TYPE_STR;
} }
bool tr_variantGetStr(tr_variant const* variant, char const** setme_str, size_t* setme_len); bool tr_variantGetStr(tr_variant const* variant, char const** setme_str, size_t* setme_len);
@ -180,7 +180,7 @@ bool tr_variantGetRaw(tr_variant const* variant, uint8_t const** raw_setme, size
static inline bool tr_variantIsReal(tr_variant const* v) static inline bool tr_variantIsReal(tr_variant const* v)
{ {
return v != NULL && v->type == TR_VARIANT_TYPE_REAL; return v != nullptr && v->type == TR_VARIANT_TYPE_REAL;
} }
void tr_variantInitReal(tr_variant* initme, double value); void tr_variantInitReal(tr_variant* initme, double value);
@ -192,7 +192,7 @@ bool tr_variantGetReal(tr_variant const* variant, double* value_setme);
static inline bool tr_variantIsBool(tr_variant const* v) static inline bool tr_variantIsBool(tr_variant const* v)
{ {
return v != NULL && v->type == TR_VARIANT_TYPE_BOOL; return v != nullptr && v->type == TR_VARIANT_TYPE_BOOL;
} }
void tr_variantInitBool(tr_variant* initme, bool value); void tr_variantInitBool(tr_variant* initme, bool value);
@ -204,7 +204,7 @@ bool tr_variantGetBool(tr_variant const* variant, bool* setme);
static inline bool tr_variantIsInt(tr_variant const* v) static inline bool tr_variantIsInt(tr_variant const* v)
{ {
return v != NULL && v->type == TR_VARIANT_TYPE_INT; return v != nullptr && v->type == TR_VARIANT_TYPE_INT;
} }
void tr_variantInitInt(tr_variant* variant, int64_t value); void tr_variantInitInt(tr_variant* variant, int64_t value);
@ -216,7 +216,7 @@ bool tr_variantGetInt(tr_variant const* val, int64_t* setme);
static inline bool tr_variantIsList(tr_variant const* v) static inline bool tr_variantIsList(tr_variant const* v)
{ {
return v != NULL && v->type == TR_VARIANT_TYPE_LIST; return v != nullptr && v->type == TR_VARIANT_TYPE_LIST;
} }
void tr_variantInitList(tr_variant* list, size_t reserve_count); void tr_variantInitList(tr_variant* list, size_t reserve_count);
@ -242,7 +242,7 @@ size_t tr_variantListSize(tr_variant const* list);
static inline bool tr_variantIsDict(tr_variant const* v) static inline bool tr_variantIsDict(tr_variant const* v)
{ {
return v != NULL && v->type == TR_VARIANT_TYPE_DICT; return v != nullptr && v->type == TR_VARIANT_TYPE_DICT;
} }
void tr_variantInitDict(tr_variant* initme, size_t reserve_count); void tr_variantInitDict(tr_variant* initme, size_t reserve_count);

View File

@ -33,7 +33,7 @@ public:
using Key = QString; using Key = QString;
using Keys = std::vector<Key>; using Keys = std::vector<Key>;
// returns a cached pixmap, or a NULL pixmap if there's no match in the cache // returns a cached pixmap, or a nullptr pixmap if there's no match in the cache
QPixmap find(Key const& key); QPixmap find(Key const& key);
static Key getKey(QString const& display_name); static Key getKey(QString const& display_name);

View File

@ -28,19 +28,19 @@ static tr_tracker_info trackers[MAX_TRACKERS];
static int trackerCount = 0; static int trackerCount = 0;
static bool isPrivate = false; static bool isPrivate = false;
static bool showVersion = false; static bool showVersion = false;
static char const* comment = NULL; static char const* comment = nullptr;
static char const* outfile = NULL; static char const* outfile = nullptr;
static char const* infile = NULL; static char const* infile = nullptr;
static uint32_t piecesize_kib = 0; static uint32_t piecesize_kib = 0;
static tr_option options[] = { static tr_option options[] = {
{ 'p', "private", "Allow this torrent to only be used with the specified tracker(s)", "p", false, NULL }, { 'p', "private", "Allow this torrent to only be used with the specified tracker(s)", "p", false, nullptr },
{ 'o', "outfile", "Save the generated .torrent to this filename", "o", true, "<file>" }, { 'o', "outfile", "Save the generated .torrent to this filename", "o", true, "<file>" },
{ 's', "piecesize", "Set how many KiB each piece should be, overriding the preferred default", "s", true, "<size in KiB>" }, { 's', "piecesize", "Set how many KiB each piece should be, overriding the preferred default", "s", true, "<size in KiB>" },
{ 'c', "comment", "Add a comment", "c", true, "<comment>" }, { 'c', "comment", "Add a comment", "c", true, "<comment>" },
{ 't', "tracker", "Add a tracker's announce URL", "t", true, "<url>" }, { 't', "tracker", "Add a tracker's announce URL", "t", true, "<url>" },
{ 'V', "version", "Show version number and exit", "V", false, NULL }, { 'V', "version", "Show version number and exit", "V", false, nullptr },
{ 0, NULL, NULL, NULL, false, NULL } { 0, nullptr, nullptr, nullptr, false, nullptr }
}; };
static char const* getUsage(void) static char const* getUsage(void)
@ -84,12 +84,12 @@ static int parseCommandLine(int argc, char const* const* argv)
break; break;
case 's': case 's':
if (optarg != NULL) if (optarg != nullptr)
{ {
char* endptr = NULL; char* endptr = nullptr;
piecesize_kib = strtoul(optarg, &endptr, 10); piecesize_kib = strtoul(optarg, &endptr, 10);
if (endptr != NULL && *endptr == 'M') if (endptr != nullptr && *endptr == 'M')
{ {
piecesize_kib *= KiB; piecesize_kib *= KiB;
} }
@ -112,11 +112,11 @@ static int parseCommandLine(int argc, char const* const* argv)
static char* tr_getcwd(void) static char* tr_getcwd(void)
{ {
char* result; char* result;
tr_error* error = NULL; tr_error* error = nullptr;
result = tr_sys_dir_get_current(&error); result = tr_sys_dir_get_current(&error);
if (result == NULL) if (result == nullptr)
{ {
fprintf(stderr, "getcwd error: \"%s\"", error->message); fprintf(stderr, "getcwd error: \"%s\"", error->message);
tr_error_free(error); tr_error_free(error);
@ -128,8 +128,8 @@ static char* tr_getcwd(void)
int tr_main(int argc, char* argv[]) int tr_main(int argc, char* argv[])
{ {
char* out2 = NULL; char* out2 = nullptr;
tr_metainfo_builder* b = NULL; tr_metainfo_builder* b = nullptr;
tr_logSetLevel(TR_LOG_ERROR); tr_logSetLevel(TR_LOG_ERROR);
tr_formatter_mem_init(MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR); tr_formatter_mem_init(MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR);
@ -147,7 +147,7 @@ int tr_main(int argc, char* argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if (infile == NULL) if (infile == nullptr)
{ {
fprintf(stderr, "ERROR: No input file or directory specified.\n"); fprintf(stderr, "ERROR: No input file or directory specified.\n");
tr_getopt_usage(MY_NAME, getUsage(), options); tr_getopt_usage(MY_NAME, getUsage(), options);
@ -155,12 +155,12 @@ int tr_main(int argc, char* argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (outfile == NULL) if (outfile == nullptr)
{ {
tr_error* error = NULL; tr_error* error = nullptr;
char* base = tr_sys_path_basename(infile, &error); char* base = tr_sys_path_basename(infile, &error);
if (base == NULL) if (base == nullptr)
{ {
fprintf(stderr, "ERROR: Cannot deduce output path from input path: %s\n", error->message); fprintf(stderr, "ERROR: Cannot deduce output path from input path: %s\n", error->message);
return EXIT_FAILURE; return EXIT_FAILURE;
@ -168,7 +168,7 @@ int tr_main(int argc, char* argv[])
char* end = tr_strdup_printf("%s.torrent", base); char* end = tr_strdup_printf("%s.torrent", base);
char* cwd = tr_getcwd(); char* cwd = tr_getcwd();
outfile = out2 = tr_buildPath(cwd, end, NULL); outfile = out2 = tr_buildPath(cwd, end, nullptr);
tr_free(cwd); tr_free(cwd);
tr_free(end); tr_free(end);
tr_free(base); tr_free(base);
@ -191,7 +191,7 @@ int tr_main(int argc, char* argv[])
b = tr_metaInfoBuilderCreate(infile); b = tr_metaInfoBuilderCreate(infile);
if (b == NULL) if (b == nullptr)
{ {
fprintf(stderr, "ERROR: Cannot find specified input file or directory.\n"); fprintf(stderr, "ERROR: Cannot find specified input file or directory.\n");
return EXIT_FAILURE; return EXIT_FAILURE;

View File

@ -23,17 +23,17 @@
static int fileCount = 0; static int fileCount = 0;
static bool showVersion = false; static bool showVersion = false;
static char const** files = NULL; static char const** files = nullptr;
static char const* add = NULL; static char const* add = nullptr;
static char const* deleteme = NULL; static char const* deleteme = nullptr;
static char const* replace[2] = { NULL, NULL }; static char const* replace[2] = { nullptr, nullptr };
static tr_option options[] = { static tr_option options[] = {
{ 'a', "add", "Add a tracker's announce URL", "a", true, "<url>" }, { 'a', "add", "Add a tracker's announce URL", "a", true, "<url>" },
{ 'd', "delete", "Delete a tracker's announce URL", "d", true, "<url>" }, { 'd', "delete", "Delete a tracker's announce URL", "d", true, "<url>" },
{ 'r', "replace", "Search and replace a substring in the announce URLs", "r", true, "<old> <new>" }, { 'r', "replace", "Search and replace a substring in the announce URLs", "r", true, "<old> <new>" },
{ 'V', "version", "Show version number and exit", "V", false, NULL }, { 'V', "version", "Show version number and exit", "V", false, nullptr },
{ 0, NULL, NULL, NULL, false, NULL } { 0, nullptr, nullptr, nullptr, false, nullptr }
}; };
static char const* getUsage(void) static char const* getUsage(void)
@ -92,7 +92,7 @@ static bool removeURL(tr_variant* metainfo, char const* url)
tr_variant* announce_list; tr_variant* announce_list;
bool changed = false; bool changed = false;
if (tr_variantDictFindStr(metainfo, TR_KEY_announce, &str, NULL) && strcmp(str, url) == 0) if (tr_variantDictFindStr(metainfo, TR_KEY_announce, &str, nullptr) && strcmp(str, url) == 0)
{ {
printf("\tRemoved \"%s\" from \"announce\"\n", str); printf("\tRemoved \"%s\" from \"announce\"\n", str);
tr_variantDictRemove(metainfo, TR_KEY_announce); tr_variantDictRemove(metainfo, TR_KEY_announce);
@ -104,13 +104,13 @@ static bool removeURL(tr_variant* metainfo, char const* url)
tr_variant* tier; tr_variant* tier;
int tierIndex = 0; int tierIndex = 0;
while ((tier = tr_variantListChild(announce_list, tierIndex)) != NULL) while ((tier = tr_variantListChild(announce_list, tierIndex)) != nullptr)
{ {
int nodeIndex = 0; int nodeIndex = 0;
tr_variant const* node; tr_variant const* node;
while ((node = tr_variantListChild(tier, nodeIndex)) != NULL) while ((node = tr_variantListChild(tier, nodeIndex)) != nullptr)
{ {
if (tr_variantGetStr(node, &str, NULL) && strcmp(str, url) == 0) if (tr_variantGetStr(node, &str, nullptr) && strcmp(str, url) == 0)
{ {
printf("\tRemoved \"%s\" from \"announce-list\" tier #%d\n", str, tierIndex + 1); printf("\tRemoved \"%s\" from \"announce-list\" tier #%d\n", str, tierIndex + 1);
tr_variantListRemove(tier, nodeIndex); tr_variantListRemove(tier, nodeIndex);
@ -142,13 +142,13 @@ static bool removeURL(tr_variant* metainfo, char const* url)
/* if we removed the "announce" field and there's still another track left, /* if we removed the "announce" field and there's still another track left,
* use it as the "announce" field */ * use it as the "announce" field */
if (changed && !tr_variantDictFindStr(metainfo, TR_KEY_announce, &str, NULL)) if (changed && !tr_variantDictFindStr(metainfo, TR_KEY_announce, &str, nullptr))
{ {
tr_variant* const tier = tr_variantListChild(announce_list, 0); tr_variant* const tier = tr_variantListChild(announce_list, 0);
if (tier != NULL) if (tier != nullptr)
{ {
tr_variant const* const node = tr_variantListChild(tier, 0); tr_variant const* const node = tr_variantListChild(tier, 0);
if ((node != NULL) && tr_variantGetStr(node, &str, NULL)) if ((node != nullptr) && tr_variantGetStr(node, &str, nullptr))
{ {
tr_variantDictAddStr(metainfo, TR_KEY_announce, str); tr_variantDictAddStr(metainfo, TR_KEY_announce, str);
printf("\tAdded \"%s\" to announce\n", str); printf("\tAdded \"%s\" to announce\n", str);
@ -166,7 +166,7 @@ static char* replaceSubstr(char const* str, char const* in, char const* out)
size_t const inlen = strlen(in); size_t const inlen = strlen(in);
size_t const outlen = strlen(out); size_t const outlen = strlen(out);
while ((walk = strstr(str, in)) != NULL) while ((walk = strstr(str, in)) != nullptr)
{ {
evbuffer_add(buf, str, walk - str); evbuffer_add(buf, str, walk - str);
evbuffer_add(buf, out, outlen); evbuffer_add(buf, out, outlen);
@ -175,7 +175,7 @@ static char* replaceSubstr(char const* str, char const* in, char const* out)
evbuffer_add(buf, str, strlen(str)); evbuffer_add(buf, str, strlen(str));
return evbuffer_free_to_str(buf, NULL); return evbuffer_free_to_str(buf, nullptr);
} }
static bool replaceURL(tr_variant* metainfo, char const* in, char const* out) static bool replaceURL(tr_variant* metainfo, char const* in, char const* out)
@ -184,7 +184,7 @@ static bool replaceURL(tr_variant* metainfo, char const* in, char const* out)
tr_variant* announce_list; tr_variant* announce_list;
bool changed = false; bool changed = false;
if (tr_variantDictFindStr(metainfo, TR_KEY_announce, &str, NULL) && strstr(str, in) != NULL) if (tr_variantDictFindStr(metainfo, TR_KEY_announce, &str, nullptr) && strstr(str, in) != nullptr)
{ {
char* newstr = replaceSubstr(str, in, out); char* newstr = replaceSubstr(str, in, out);
printf("\tReplaced in \"announce\": \"%s\" --> \"%s\"\n", str, newstr); printf("\tReplaced in \"announce\": \"%s\" --> \"%s\"\n", str, newstr);
@ -198,14 +198,14 @@ static bool replaceURL(tr_variant* metainfo, char const* in, char const* out)
tr_variant* tier; tr_variant* tier;
int tierCount = 0; int tierCount = 0;
while ((tier = tr_variantListChild(announce_list, tierCount)) != NULL) while ((tier = tr_variantListChild(announce_list, tierCount)) != nullptr)
{ {
tr_variant* node; tr_variant* node;
int nodeCount = 0; int nodeCount = 0;
while ((node = tr_variantListChild(tier, nodeCount)) != NULL) while ((node = tr_variantListChild(tier, nodeCount)) != nullptr)
{ {
if (tr_variantGetStr(node, &str, NULL) && strstr(str, in) != NULL) if (tr_variantGetStr(node, &str, nullptr) && strstr(str, in) != nullptr)
{ {
char* newstr = replaceSubstr(str, in, out); char* newstr = replaceSubstr(str, in, out);
printf("\tReplaced in \"announce-list\" tier %d: \"%s\" --> \"%s\"\n", tierCount + 1, str, newstr); printf("\tReplaced in \"announce-list\" tier %d: \"%s\" --> \"%s\"\n", tierCount + 1, str, newstr);
@ -230,15 +230,15 @@ static bool announce_list_has_url(tr_variant* announce_list, char const* url)
int tierCount = 0; int tierCount = 0;
tr_variant* tier; tr_variant* tier;
while ((tier = tr_variantListChild(announce_list, tierCount)) != NULL) while ((tier = tr_variantListChild(announce_list, tierCount)) != nullptr)
{ {
int nodeCount = 0; int nodeCount = 0;
tr_variant const* node; tr_variant const* node;
while ((node = tr_variantListChild(tier, nodeCount)) != NULL) while ((node = tr_variantListChild(tier, nodeCount)) != nullptr)
{ {
char const* str = NULL; char const* str = nullptr;
if (tr_variantGetStr(node, &str, NULL) && strcmp(str, url) == 0) if (tr_variantGetStr(node, &str, nullptr) && strcmp(str, url) == 0)
{ {
return true; return true;
} }
@ -254,10 +254,10 @@ static bool announce_list_has_url(tr_variant* announce_list, char const* url)
static bool addURL(tr_variant* metainfo, char const* url) static bool addURL(tr_variant* metainfo, char const* url)
{ {
char const* announce = NULL; char const* announce = nullptr;
tr_variant* announce_list = NULL; tr_variant* announce_list = nullptr;
bool changed = false; bool changed = false;
bool const had_announce = tr_variantDictFindStr(metainfo, TR_KEY_announce, &announce, NULL); bool const had_announce = tr_variantDictFindStr(metainfo, TR_KEY_announce, &announce, nullptr);
bool const had_announce_list = tr_variantDictFindList(metainfo, TR_KEY_announce_list, &announce_list); bool const had_announce_list = tr_variantDictFindList(metainfo, TR_KEY_announce_list, &announce_list);
if (!had_announce && !had_announce_list) if (!had_announce && !had_announce_list)
@ -323,7 +323,7 @@ int tr_main(int argc, char* argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (add == NULL && deleteme == NULL && replace[0] == 0) if (add == nullptr && deleteme == nullptr && replace[0] == 0)
{ {
fprintf(stderr, "ERROR: Must specify -a, -d or -r\n"); fprintf(stderr, "ERROR: Must specify -a, -d or -r\n");
tr_getopt_usage(MY_NAME, getUsage(), options); tr_getopt_usage(MY_NAME, getUsage(), options);
@ -336,7 +336,7 @@ int tr_main(int argc, char* argv[])
tr_variant top; tr_variant top;
bool changed = false; bool changed = false;
char const* filename = files[i]; char const* filename = files[i];
tr_error* error = NULL; tr_error* error = nullptr;
printf("%s\n", filename); printf("%s\n", filename);
@ -347,17 +347,17 @@ int tr_main(int argc, char* argv[])
continue; continue;
} }
if (deleteme != NULL) if (deleteme != nullptr)
{ {
changed |= removeURL(&top, deleteme); changed |= removeURL(&top, deleteme);
} }
if (add != NULL) if (add != nullptr)
{ {
changed = addURL(&top, add); changed = addURL(&top, add);
} }
if (replace[0] != NULL && replace[1] != NULL) if (replace[0] != nullptr && replace[1] != nullptr)
{ {
changed |= replaceURL(&top, replace[0], replace[1]); changed |= replaceURL(&top, replace[0], replace[1]);
} }

View File

@ -257,72 +257,77 @@ static char const* getUsage(void)
***/ ***/
static tr_option opts[] = { static tr_option opts[] = {
{ 'a', "add", "Add torrent files by filename or URL", "a", false, NULL }, { 'a', "add", "Add torrent files by filename or URL", "a", false, nullptr },
{ 970, "alt-speed", "Use the alternate Limits", "as", false, NULL }, { 970, "alt-speed", "Use the alternate Limits", "as", false, nullptr },
{ 971, "no-alt-speed", "Don't use the alternate Limits", "AS", false, NULL }, { 971, "no-alt-speed", "Don't use the alternate Limits", "AS", false, nullptr },
{ 972, "alt-speed-downlimit", "max alternate download speed (in " SPEED_K_STR ")", "asd", true, "<speed>" }, { 972, "alt-speed-downlimit", "max alternate download speed (in " SPEED_K_STR ")", "asd", true, "<speed>" },
{ 973, "alt-speed-uplimit", "max alternate upload speed (in " SPEED_K_STR ")", "asu", true, "<speed>" }, { 973, "alt-speed-uplimit", "max alternate upload speed (in " SPEED_K_STR ")", "asu", true, "<speed>" },
{ 974, "alt-speed-scheduler", "Use the scheduled on/off times", "asc", false, NULL }, { 974, "alt-speed-scheduler", "Use the scheduled on/off times", "asc", false, nullptr },
{ 975, "no-alt-speed-scheduler", "Don't use the scheduled on/off times", "ASC", false, NULL }, { 975, "no-alt-speed-scheduler", "Don't use the scheduled on/off times", "ASC", false, nullptr },
{ 976, "alt-speed-time-begin", "Time to start using the alt speed limits (in hhmm)", NULL, true, "<time>" }, { 976, "alt-speed-time-begin", "Time to start using the alt speed limits (in hhmm)", nullptr, true, "<time>" },
{ 977, "alt-speed-time-end", "Time to stop using the alt speed limits (in hhmm)", NULL, true, "<time>" }, { 977, "alt-speed-time-end", "Time to stop using the alt speed limits (in hhmm)", nullptr, true, "<time>" },
{ 978, "alt-speed-days", "Numbers for any/all days of the week - eg. \"1-7\"", NULL, true, "<days>" }, { 978, "alt-speed-days", "Numbers for any/all days of the week - eg. \"1-7\"", nullptr, true, "<days>" },
{ 963, "blocklist-update", "Blocklist update", NULL, false, NULL }, { 963, "blocklist-update", "Blocklist update", nullptr, false, nullptr },
{ 'c', "incomplete-dir", "Where to store new torrents until they're complete", "c", true, "<dir>" }, { 'c', "incomplete-dir", "Where to store new torrents until they're complete", "c", true, "<dir>" },
{ 'C', "no-incomplete-dir", "Don't store incomplete torrents in a different location", "C", false, NULL }, { 'C', "no-incomplete-dir", "Don't store incomplete torrents in a different location", "C", false, nullptr },
{ 'b', "debug", "Print debugging information", "b", false, NULL }, { 'b', "debug", "Print debugging information", "b", false, nullptr },
{ 'd', { 'd',
"downlimit", "downlimit",
"Set the max download speed in " SPEED_K_STR " for the current torrent(s) or globally", "Set the max download speed in " SPEED_K_STR " for the current torrent(s) or globally",
"d", "d",
true, true,
"<speed>" }, "<speed>" },
{ 'D', "no-downlimit", "Disable max download speed for the current torrent(s) or globally", "D", false, NULL }, { 'D', "no-downlimit", "Disable max download speed for the current torrent(s) or globally", "D", false, nullptr },
{ 'e', "cache", "Set the maximum size of the session's memory cache (in " MEM_M_STR ")", "e", true, "<size>" }, { 'e', "cache", "Set the maximum size of the session's memory cache (in " MEM_M_STR ")", "e", true, "<size>" },
{ 910, "encryption-required", "Encrypt all peer connections", "er", false, NULL }, { 910, "encryption-required", "Encrypt all peer connections", "er", false, nullptr },
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", false, NULL }, { 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", false, nullptr },
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", false, NULL }, { 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", false, nullptr },
{ 850, "exit", "Tell the transmission session to shut down", NULL, false, NULL }, { 850, "exit", "Tell the transmission session to shut down", nullptr, false, nullptr },
{ 940, "files", "List the current torrent(s)' files", "f", false, NULL }, { 940, "files", "List the current torrent(s)' files", "f", false, nullptr },
{ 'g', "get", "Mark files for download", "g", true, "<files>" }, { 'g', "get", "Mark files for download", "g", true, "<files>" },
{ 'G', "no-get", "Mark files for not downloading", "G", true, "<files>" }, { 'G', "no-get", "Mark files for not downloading", "G", true, "<files>" },
{ 'i', "info", "Show the current torrent(s)' details", "i", false, NULL }, { 'i', "info", "Show the current torrent(s)' details", "i", false, nullptr },
{ 940, "info-files", "List the current torrent(s)' files", "if", false, NULL }, { 940, "info-files", "List the current torrent(s)' files", "if", false, nullptr },
{ 941, "info-peers", "List the current torrent(s)' peers", "ip", false, NULL }, { 941, "info-peers", "List the current torrent(s)' peers", "ip", false, nullptr },
{ 942, "info-pieces", "List the current torrent(s)' pieces", "ic", false, NULL }, { 942, "info-pieces", "List the current torrent(s)' pieces", "ic", false, nullptr },
{ 943, "info-trackers", "List the current torrent(s)' trackers", "it", false, NULL }, { 943, "info-trackers", "List the current torrent(s)' trackers", "it", false, nullptr },
{ 920, "session-info", "Show the session's details", "si", false, NULL }, { 920, "session-info", "Show the session's details", "si", false, nullptr },
{ 921, "session-stats", "Show the session's statistics", "st", false, NULL }, { 921, "session-stats", "Show the session's statistics", "st", false, nullptr },
{ 'l', "list", "List all torrents", "l", false, NULL }, { 'l', "list", "List all torrents", "l", false, nullptr },
{ 'L', "labels", "Set the current torrents' labels", "L", true, "<label[,label...]>" }, { 'L', "labels", "Set the current torrents' labels", "L", true, "<label[,label...]>" },
{ 960, "move", "Move current torrent's data to a new folder", NULL, true, "<path>" }, { 960, "move", "Move current torrent's data to a new folder", nullptr, true, "<path>" },
{ 961, "find", "Tell Transmission where to find a torrent's data", NULL, true, "<path>" }, { 961, "find", "Tell Transmission where to find a torrent's data", nullptr, true, "<path>" },
{ 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", false, NULL }, { 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", false, nullptr },
{ 'M', "no-portmap", "Disable portmapping", "M", false, NULL }, { 'M', "no-portmap", "Disable portmapping", "M", false, nullptr },
{ 'n', "auth", "Set username and password", "n", true, "<user:pw>" }, { 'n', "auth", "Set username and password", "n", true, "<user:pw>" },
{ 810, "authenv", "Set authentication info from the TR_AUTH environment variable (user:pw)", "ne", false, NULL }, { 810, "authenv", "Set authentication info from the TR_AUTH environment variable (user:pw)", "ne", false, nullptr },
{ 'N', "netrc", "Set authentication info from a .netrc file", "N", true, "<file>" }, { 'N', "netrc", "Set authentication info from a .netrc file", "N", true, "<file>" },
{ 820, "ssl", "Use SSL when talking to daemon", NULL, false, NULL }, { 820, "ssl", "Use SSL when talking to daemon", nullptr, false, nullptr },
{ 'o', "dht", "Enable distributed hash tables (DHT)", "o", false, NULL }, { 'o', "dht", "Enable distributed hash tables (DHT)", "o", false, nullptr },
{ 'O', "no-dht", "Disable distributed hash tables (DHT)", "O", false, NULL }, { 'O', "no-dht", "Disable distributed hash tables (DHT)", "O", false, nullptr },
{ 'p', "port", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "p", true, "<port>" }, { 'p', "port", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "p", true, "<port>" },
{ 962, "port-test", "Port testing", "pt", false, NULL }, { 962, "port-test", "Port testing", "pt", false, nullptr },
{ 'P', "random-port", "Random port for incoming peers", "P", false, NULL }, { 'P', "random-port", "Random port for incoming peers", "P", false, nullptr },
{ 900, "priority-high", "Try to download these file(s) first", "ph", true, "<files>" }, { 900, "priority-high", "Try to download these file(s) first", "ph", true, "<files>" },
{ 901, "priority-normal", "Try to download these file(s) normally", "pn", true, "<files>" }, { 901, "priority-normal", "Try to download these file(s) normally", "pn", true, "<files>" },
{ 902, "priority-low", "Try to download these file(s) last", "pl", true, "<files>" }, { 902, "priority-low", "Try to download these file(s) last", "pl", true, "<files>" },
{ 700, "bandwidth-high", "Give this torrent first chance at available bandwidth", "Bh", false, NULL }, { 700, "bandwidth-high", "Give this torrent first chance at available bandwidth", "Bh", false, nullptr },
{ 701, "bandwidth-normal", "Give this torrent bandwidth left over by high priority torrents", "Bn", false, NULL }, { 701, "bandwidth-normal", "Give this torrent bandwidth left over by high priority torrents", "Bn", false, nullptr },
{ 702, "bandwidth-low", "Give this torrent bandwidth left over by high and normal priority torrents", "Bl", false, NULL }, { 702,
{ 600, "reannounce", "Reannounce the current torrent(s)", NULL, false, NULL }, "bandwidth-low",
{ 'r', "remove", "Remove the current torrent(s)", "r", false, NULL }, "Give this torrent bandwidth left over by high and normal priority torrents",
"Bl",
false,
nullptr },
{ 600, "reannounce", "Reannounce the current torrent(s)", nullptr, false, nullptr },
{ 'r', "remove", "Remove the current torrent(s)", "r", false, nullptr },
{ 930, "peers", "Set the maximum number of peers for the current torrent(s) or globally", "pr", true, "<max>" }, { 930, "peers", "Set the maximum number of peers for the current torrent(s) or globally", "pr", true, "<max>" },
{ 840, "remove-and-delete", "Remove the current torrent(s) and delete local data", "rad", false, NULL }, { 840, "remove-and-delete", "Remove the current torrent(s) and delete local data", "rad", false, nullptr },
{ 800, "torrent-done-script", "Specify a script to run when a torrent finishes", NULL, true, "<file>" }, { 800, "torrent-done-script", "Specify a script to run when a torrent finishes", nullptr, true, "<file>" },
{ 801, "no-torrent-done-script", "Don't run a script when torrents finish", NULL, false, NULL }, { 801, "no-torrent-done-script", "Don't run a script when torrents finish", nullptr, false, nullptr },
{ 950, "seedratio", "Let the current torrent(s) seed until a specific ratio", "sr", true, "ratio" }, { 950, "seedratio", "Let the current torrent(s) seed until a specific ratio", "sr", true, "ratio" },
{ 951, "seedratio-default", "Let the current torrent(s) use the global seedratio settings", "srd", false, NULL }, { 951, "seedratio-default", "Let the current torrent(s) use the global seedratio settings", "srd", false, nullptr },
{ 952, "no-seedratio", "Let the current torrent(s) seed regardless of ratio", "SR", false, NULL }, { 952, "no-seedratio", "Let the current torrent(s) seed regardless of ratio", "SR", false, nullptr },
{ 953, { 953,
"global-seedratio", "global-seedratio",
"All torrents, unless overridden by a per-torrent setting, should seed until a specific ratio", "All torrents, unless overridden by a per-torrent setting, should seed until a specific ratio",
@ -334,29 +339,29 @@ static tr_option opts[] = {
"All torrents, unless overridden by a per-torrent setting, should seed regardless of ratio", "All torrents, unless overridden by a per-torrent setting, should seed regardless of ratio",
"GSR", "GSR",
false, false,
NULL }, nullptr },
{ 710, "tracker-add", "Add a tracker to a torrent", "td", true, "<tracker>" }, { 710, "tracker-add", "Add a tracker to a torrent", "td", true, "<tracker>" },
{ 712, "tracker-remove", "Remove a tracker from a torrent", "tr", true, "<trackerId>" }, { 712, "tracker-remove", "Remove a tracker from a torrent", "tr", true, "<trackerId>" },
{ 's', "start", "Start the current torrent(s)", "s", false, NULL }, { 's', "start", "Start the current torrent(s)", "s", false, nullptr },
{ 'S', "stop", "Stop the current torrent(s)", "S", false, NULL }, { 'S', "stop", "Stop the current torrent(s)", "S", false, nullptr },
{ 't', "torrent", "Set the current torrent(s)", "t", true, "<torrent>" }, { 't', "torrent", "Set the current torrent(s)", "t", true, "<torrent>" },
{ 990, "start-paused", "Start added torrents paused", NULL, false, NULL }, { 990, "start-paused", "Start added torrents paused", nullptr, false, nullptr },
{ 991, "no-start-paused", "Start added torrents unpaused", NULL, false, NULL }, { 991, "no-start-paused", "Start added torrents unpaused", nullptr, false, nullptr },
{ 992, "trash-torrent", "Delete torrents after adding", NULL, false, NULL }, { 992, "trash-torrent", "Delete torrents after adding", nullptr, false, nullptr },
{ 993, "no-trash-torrent", "Do not delete torrents after adding", NULL, false, NULL }, { 993, "no-trash-torrent", "Do not delete torrents after adding", nullptr, false, nullptr },
{ 984, "honor-session", "Make the current torrent(s) honor the session limits", "hl", false, NULL }, { 984, "honor-session", "Make the current torrent(s) honor the session limits", "hl", false, nullptr },
{ 985, "no-honor-session", "Make the current torrent(s) not honor the session limits", "HL", false, NULL }, { 985, "no-honor-session", "Make the current torrent(s) not honor the session limits", "HL", false, nullptr },
{ 'u', { 'u',
"uplimit", "uplimit",
"Set the max upload speed in " SPEED_K_STR " for the current torrent(s) or globally", "Set the max upload speed in " SPEED_K_STR " for the current torrent(s) or globally",
"u", "u",
true, true,
"<speed>" }, "<speed>" },
{ 'U', "no-uplimit", "Disable max upload speed for the current torrent(s) or globally", "U", false, NULL }, { 'U', "no-uplimit", "Disable max upload speed for the current torrent(s) or globally", "U", false, nullptr },
{ 830, "utp", "Enable uTP for peer connections", NULL, false, NULL }, { 830, "utp", "Enable uTP for peer connections", nullptr, false, nullptr },
{ 831, "no-utp", "Disable uTP for peer connections", NULL, false, NULL }, { 831, "no-utp", "Disable uTP for peer connections", nullptr, false, nullptr },
{ 'v', "verify", "Verify the current torrent(s)", "v", false, NULL }, { 'v', "verify", "Verify the current torrent(s)", "v", false, nullptr },
{ 'V', "version", "Show version number and exit", "V", false, NULL }, { 'V', "version", "Show version number and exit", "V", false, nullptr },
{ 'w', { 'w',
"download-dir", "download-dir",
"When used in conjunction with --add, set the new torrent's download folder. " "When used in conjunction with --add, set the new torrent's download folder. "
@ -364,12 +369,12 @@ static tr_option opts[] = {
"w", "w",
true, true,
"<path>" }, "<path>" },
{ 'x', "pex", "Enable peer exchange (PEX)", "x", false, NULL }, { 'x', "pex", "Enable peer exchange (PEX)", "x", false, nullptr },
{ 'X', "no-pex", "Disable peer exchange (PEX)", "X", false, NULL }, { 'X', "no-pex", "Disable peer exchange (PEX)", "X", false, nullptr },
{ 'y', "lpd", "Enable local peer discovery (LPD)", "y", false, NULL }, { 'y', "lpd", "Enable local peer discovery (LPD)", "y", false, nullptr },
{ 'Y', "no-lpd", "Disable local peer discovery (LPD)", "Y", false, NULL }, { 'Y', "no-lpd", "Disable local peer discovery (LPD)", "Y", false, nullptr },
{ 941, "peer-info", "List the current torrent(s)' peers", "pi", false, NULL }, { 941, "peer-info", "List the current torrent(s)' peers", "pi", false, nullptr },
{ 0, NULL, NULL, NULL, false, NULL } { 0, nullptr, nullptr, nullptr, false, nullptr }
}; };
static void showUsage(void) static void showUsage(void)
@ -379,7 +384,7 @@ static void showUsage(void)
static int numarg(char const* arg) static int numarg(char const* arg)
{ {
char* end = NULL; char* end = nullptr;
long const num = strtol(arg, &end, 10); long const num = strtol(arg, &end, 10);
if (*end != '\0') if (*end != '\0')
@ -547,20 +552,20 @@ static int getOptMode(int val)
} }
static bool debug = false; static bool debug = false;
static char* auth = NULL; static char* auth = nullptr;
static char* netrc = NULL; static char* netrc = nullptr;
static char* sessionId = NULL; static char* sessionId = nullptr;
static bool UseSSL = false; static bool UseSSL = false;
static char* getEncodedMetainfo(char const* filename) static char* getEncodedMetainfo(char const* filename)
{ {
size_t len = 0; size_t len = 0;
char* b64 = NULL; char* b64 = nullptr;
uint8_t* buf = tr_loadFile(filename, &len, NULL); uint8_t* buf = tr_loadFile(filename, &len, nullptr);
if (buf != NULL) if (buf != nullptr)
{ {
b64 = static_cast<char*>(tr_base64_encode(buf, len, NULL)); b64 = static_cast<char*>(tr_base64_encode(buf, len, nullptr));
tr_free(buf); tr_free(buf);
} }
@ -586,7 +591,7 @@ static void addIdArg(tr_variant* args, char const* id_str, char const* fallback)
} }
else if (strcmp(id_str, "all") != 0) else if (strcmp(id_str, "all") != 0)
{ {
bool isList = strchr(id_str, ',') != NULL || strchr(id_str, '-') != NULL; bool isList = strchr(id_str, ',') != nullptr || strchr(id_str, '-') != nullptr;
bool isNum = true; bool isNum = true;
for (char const* pch = id_str; isNum && *pch != '\0'; ++pch) for (char const* pch = id_str; isNum && *pch != '\0'; ++pch)
@ -610,7 +615,7 @@ static void addTime(tr_variant* args, tr_quark const key, char const* arg)
int time = 0; int time = 0;
bool success = false; bool success = false;
if (arg != NULL && strlen(arg) == 4) if (arg != nullptr && strlen(arg) == 4)
{ {
char const hh[3] = { arg[0], arg[1], '\0' }; char const hh[3] = { arg[0], arg[1], '\0' };
char const mm[3] = { arg[2], arg[3], '\0' }; char const mm[3] = { arg[2], arg[3], '\0' };
@ -638,7 +643,7 @@ static void addDays(tr_variant* args, tr_quark const key, char const* arg)
{ {
int days = 0; int days = 0;
if (arg != NULL) if (arg != nullptr)
{ {
for (int& day : tr_parseNumberRange(arg, TR_BAD_SIZE)) for (int& day : tr_parseNumberRange(arg, TR_BAD_SIZE))
{ {
@ -677,7 +682,7 @@ static void addLabels(tr_variant* args, char const* arg)
char* argcpy = tr_strdup(arg); char* argcpy = tr_strdup(arg);
char* const tmp = argcpy; /* save copied string start pointer to free later */ char* const tmp = argcpy; /* save copied string start pointer to free later */
char* token; char* token;
while ((token = tr_strsep(&argcpy, ",")) != NULL) while ((token = tr_strsep(&argcpy, ",")) != nullptr)
{ {
tr_strstrip(token); tr_strstrip(token);
if (!tr_str_is_empty(token)) if (!tr_str_is_empty(token))
@ -821,7 +826,7 @@ static size_t parseResponseHeader(void* ptr, size_t size, size_t nmemb, void* st
static long getTimeoutSecs(char const* req) static long getTimeoutSecs(char const* req)
{ {
if (strstr(req, "\"method\":\"blocklist-update\"") != NULL) if (strstr(req, "\"method\":\"blocklist-update\"") != nullptr)
{ {
return 300L; return 300L;
} }
@ -966,17 +971,17 @@ static void printDetails(tr_variant* top)
printf(" Id: %" PRId64 "\n", i); printf(" Id: %" PRId64 "\n", i);
} }
if (tr_variantDictFindStr(t, TR_KEY_name, &str, NULL)) if (tr_variantDictFindStr(t, TR_KEY_name, &str, nullptr))
{ {
printf(" Name: %s\n", str); printf(" Name: %s\n", str);
} }
if (tr_variantDictFindStr(t, TR_KEY_hashString, &str, NULL)) if (tr_variantDictFindStr(t, TR_KEY_hashString, &str, nullptr))
{ {
printf(" Hash: %s\n", str); printf(" Hash: %s\n", str);
} }
if (tr_variantDictFindStr(t, TR_KEY_magnetLink, &str, NULL)) if (tr_variantDictFindStr(t, TR_KEY_magnetLink, &str, nullptr))
{ {
printf(" Magnet: %s\n", str); printf(" Magnet: %s\n", str);
} }
@ -987,7 +992,7 @@ static void printDetails(tr_variant* top)
tr_variant const* child; tr_variant const* child;
while ((child = tr_variantListChild(l, child_pos++))) while ((child = tr_variantListChild(l, child_pos++)))
{ {
if (tr_variantGetStr(child, &str, NULL)) if (tr_variantGetStr(child, &str, nullptr))
{ {
printf(i == 0 ? "%s" : ", %s", str); printf(i == 0 ? "%s" : ", %s", str);
} }
@ -1002,7 +1007,7 @@ static void printDetails(tr_variant* top)
getStatusString(t, buf, sizeof(buf)); getStatusString(t, buf, sizeof(buf));
printf(" State: %s\n", buf); printf(" State: %s\n", buf);
if (tr_variantDictFindStr(t, TR_KEY_downloadDir, &str, NULL)) if (tr_variantDictFindStr(t, TR_KEY_downloadDir, &str, nullptr))
{ {
printf(" Location: %s\n", str); printf(" Location: %s\n", str);
} }
@ -1073,7 +1078,7 @@ static void printDetails(tr_variant* top)
printf(" Corrupt DL: %s\n", buf); printf(" Corrupt DL: %s\n", buf);
} }
if (tr_variantDictFindStr(t, TR_KEY_errorString, &str, NULL) && !tr_str_is_empty(str) && if (tr_variantDictFindStr(t, TR_KEY_errorString, &str, nullptr) && !tr_str_is_empty(str) &&
tr_variantDictFindInt(t, TR_KEY_error, &i) && i != 0) tr_variantDictFindInt(t, TR_KEY_error, &i) && i != 0)
{ {
switch (i) switch (i)
@ -1160,12 +1165,12 @@ static void printDetails(tr_variant* top)
printf(" Public torrent: %s\n", (boolVal ? "No" : "Yes")); printf(" Public torrent: %s\n", (boolVal ? "No" : "Yes"));
} }
if (tr_variantDictFindStr(t, TR_KEY_comment, &str, NULL) && !tr_str_is_empty(str)) if (tr_variantDictFindStr(t, TR_KEY_comment, &str, nullptr) && !tr_str_is_empty(str))
{ {
printf(" Comment: %s\n", str); printf(" Comment: %s\n", str);
} }
if (tr_variantDictFindStr(t, TR_KEY_creator, &str, NULL) && !tr_str_is_empty(str)) if (tr_variantDictFindStr(t, TR_KEY_creator, &str, nullptr) && !tr_str_is_empty(str))
{ {
printf(" Creator: %s\n", str); printf(" Creator: %s\n", str);
} }
@ -1273,7 +1278,7 @@ static void printFileList(tr_variant* top)
tr_variant* wanteds; tr_variant* wanteds;
char const* name; char const* name;
if (tr_variantDictFindStr(d, TR_KEY_name, &name, NULL) && tr_variantDictFindList(d, TR_KEY_files, &files) && if (tr_variantDictFindStr(d, TR_KEY_name, &name, nullptr) && tr_variantDictFindList(d, TR_KEY_files, &files) &&
tr_variantDictFindList(d, TR_KEY_priorities, &priorities) && tr_variantDictFindList(d, TR_KEY_wanted, &wanteds)) tr_variantDictFindList(d, TR_KEY_priorities, &priorities) && tr_variantDictFindList(d, TR_KEY_wanted, &wanteds))
{ {
int const jn = tr_variantListSize(files); int const jn = tr_variantListSize(files);
@ -1290,7 +1295,7 @@ static void printFileList(tr_variant* top)
tr_variant* file = tr_variantListChild(files, j); tr_variant* file = tr_variantListChild(files, j);
if (tr_variantDictFindInt(file, TR_KEY_length, &length) && if (tr_variantDictFindInt(file, TR_KEY_length, &length) &&
tr_variantDictFindStr(file, TR_KEY_name, &filename, NULL) && tr_variantDictFindStr(file, TR_KEY_name, &filename, nullptr) &&
tr_variantDictFindInt(file, TR_KEY_bytesCompleted, &have) && tr_variantDictFindInt(file, TR_KEY_bytesCompleted, &have) &&
tr_variantGetInt(tr_variantListChild(priorities, j), &priority) && tr_variantGetInt(tr_variantListChild(priorities, j), &priority) &&
tr_variantGetBool(tr_variantListChild(wanteds, j), &wanted)) tr_variantGetBool(tr_variantListChild(wanteds, j), &wanted))
@ -1344,9 +1349,10 @@ static void printPeersImpl(tr_variant* peers)
int64_t rateToPeer; int64_t rateToPeer;
tr_variant* d = tr_variantListChild(peers, i); tr_variant* d = tr_variantListChild(peers, i);
if (tr_variantDictFindStr(d, TR_KEY_address, &address, NULL) && if (tr_variantDictFindStr(d, TR_KEY_address, &address, nullptr) &&
tr_variantDictFindStr(d, TR_KEY_clientName, &client, NULL) && tr_variantDictFindStr(d, TR_KEY_clientName, &client, nullptr) &&
tr_variantDictFindReal(d, TR_KEY_progress, &progress) && tr_variantDictFindStr(d, TR_KEY_flagStr, &flagstr, NULL) && tr_variantDictFindReal(d, TR_KEY_progress, &progress) &&
tr_variantDictFindStr(d, TR_KEY_flagStr, &flagstr, nullptr) &&
tr_variantDictFindInt(d, TR_KEY_rateToClient, &rateToClient) && tr_variantDictFindInt(d, TR_KEY_rateToClient, &rateToClient) &&
tr_variantDictFindInt(d, TR_KEY_rateToPeer, &rateToPeer)) tr_variantDictFindInt(d, TR_KEY_rateToPeer, &rateToPeer))
{ {
@ -1497,7 +1503,7 @@ static void printTorrentList(tr_variant* top)
if (tr_variantDictFindInt(d, TR_KEY_eta, &eta) && tr_variantDictFindInt(d, TR_KEY_id, &torId) && if (tr_variantDictFindInt(d, TR_KEY_eta, &eta) && tr_variantDictFindInt(d, TR_KEY_id, &torId) &&
tr_variantDictFindInt(d, TR_KEY_leftUntilDone, &leftUntilDone) && tr_variantDictFindInt(d, TR_KEY_leftUntilDone, &leftUntilDone) &&
tr_variantDictFindStr(d, TR_KEY_name, &name, NULL) && tr_variantDictFindInt(d, TR_KEY_rateDownload, &down) && tr_variantDictFindStr(d, TR_KEY_name, &name, nullptr) && tr_variantDictFindInt(d, TR_KEY_rateDownload, &down) &&
tr_variantDictFindInt(d, TR_KEY_rateUpload, &up) && tr_variantDictFindInt(d, TR_KEY_rateUpload, &up) &&
tr_variantDictFindInt(d, TR_KEY_sizeWhenDone, &sizeWhenDone) && tr_variantDictFindInt(d, TR_KEY_sizeWhenDone, &sizeWhenDone) &&
tr_variantDictFindInt(d, TR_KEY_status, &status) && tr_variantDictFindReal(d, TR_KEY_uploadRatio, &ratio)) tr_variantDictFindInt(d, TR_KEY_status, &status) && tr_variantDictFindReal(d, TR_KEY_uploadRatio, &ratio))
@ -1599,17 +1605,18 @@ static void printTrackersImpl(tr_variant* trackerStats)
if (tr_variantDictFindInt(t, TR_KEY_downloadCount, &downloadCount) && if (tr_variantDictFindInt(t, TR_KEY_downloadCount, &downloadCount) &&
tr_variantDictFindBool(t, TR_KEY_hasAnnounced, &hasAnnounced) && tr_variantDictFindBool(t, TR_KEY_hasAnnounced, &hasAnnounced) &&
tr_variantDictFindBool(t, TR_KEY_hasScraped, &hasScraped) && tr_variantDictFindStr(t, TR_KEY_host, &host, NULL) && tr_variantDictFindBool(t, TR_KEY_hasScraped, &hasScraped) &&
tr_variantDictFindInt(t, TR_KEY_id, &trackerId) && tr_variantDictFindBool(t, TR_KEY_isBackup, &isBackup) && tr_variantDictFindStr(t, TR_KEY_host, &host, nullptr) && tr_variantDictFindInt(t, TR_KEY_id, &trackerId) &&
tr_variantDictFindBool(t, TR_KEY_isBackup, &isBackup) &&
tr_variantDictFindInt(t, TR_KEY_announceState, &announceState) && tr_variantDictFindInt(t, TR_KEY_announceState, &announceState) &&
tr_variantDictFindInt(t, TR_KEY_scrapeState, &scrapeState) && tr_variantDictFindInt(t, TR_KEY_scrapeState, &scrapeState) &&
tr_variantDictFindInt(t, TR_KEY_lastAnnouncePeerCount, &lastAnnouncePeerCount) && tr_variantDictFindInt(t, TR_KEY_lastAnnouncePeerCount, &lastAnnouncePeerCount) &&
tr_variantDictFindStr(t, TR_KEY_lastAnnounceResult, &lastAnnounceResult, NULL) && tr_variantDictFindStr(t, TR_KEY_lastAnnounceResult, &lastAnnounceResult, nullptr) &&
tr_variantDictFindInt(t, TR_KEY_lastAnnounceStartTime, &lastAnnounceStartTime) && tr_variantDictFindInt(t, TR_KEY_lastAnnounceStartTime, &lastAnnounceStartTime) &&
tr_variantDictFindBool(t, TR_KEY_lastAnnounceSucceeded, &lastAnnounceSucceeded) && tr_variantDictFindBool(t, TR_KEY_lastAnnounceSucceeded, &lastAnnounceSucceeded) &&
tr_variantDictFindInt(t, TR_KEY_lastAnnounceTime, &lastAnnounceTime) && tr_variantDictFindInt(t, TR_KEY_lastAnnounceTime, &lastAnnounceTime) &&
tr_variantDictFindBool(t, TR_KEY_lastAnnounceTimedOut, &lastAnnounceTimedOut) && tr_variantDictFindBool(t, TR_KEY_lastAnnounceTimedOut, &lastAnnounceTimedOut) &&
tr_variantDictFindStr(t, TR_KEY_lastScrapeResult, &lastScrapeResult, NULL) && tr_variantDictFindStr(t, TR_KEY_lastScrapeResult, &lastScrapeResult, nullptr) &&
tr_variantDictFindInt(t, TR_KEY_lastScrapeStartTime, &lastScrapeStartTime) && tr_variantDictFindInt(t, TR_KEY_lastScrapeStartTime, &lastScrapeStartTime) &&
tr_variantDictFindBool(t, TR_KEY_lastScrapeSucceeded, &lastScrapeSucceeded) && tr_variantDictFindBool(t, TR_KEY_lastScrapeSucceeded, &lastScrapeSucceeded) &&
tr_variantDictFindInt(t, TR_KEY_lastScrapeTime, &lastScrapeTime) && tr_variantDictFindInt(t, TR_KEY_lastScrapeTime, &lastScrapeTime) &&
@ -1619,7 +1626,7 @@ static void printTrackersImpl(tr_variant* trackerStats)
tr_variantDictFindInt(t, TR_KEY_nextScrapeTime, &nextScrapeTime) && tr_variantDictFindInt(t, TR_KEY_nextScrapeTime, &nextScrapeTime) &&
tr_variantDictFindInt(t, TR_KEY_seederCount, &seederCount) && tr_variantDictFindInt(t, TR_KEY_tier, &tier)) tr_variantDictFindInt(t, TR_KEY_seederCount, &seederCount) && tr_variantDictFindInt(t, TR_KEY_tier, &tier))
{ {
time_t const now = time(NULL); time_t const now = time(nullptr);
printf("\n"); printf("\n");
printf(" Tracker %d: %s\n", (int)trackerId, host); printf(" Tracker %d: %s\n", (int)trackerId, host);
@ -1754,7 +1761,7 @@ static void printSession(tr_variant* top)
printf("VERSION\n"); printf("VERSION\n");
if (tr_variantDictFindStr(args, TR_KEY_version, &str, NULL)) if (tr_variantDictFindStr(args, TR_KEY_version, &str, nullptr))
{ {
printf(" Daemon version: %s\n", str); printf(" Daemon version: %s\n", str);
} }
@ -1773,12 +1780,12 @@ static void printSession(tr_variant* top)
printf("CONFIG\n"); printf("CONFIG\n");
if (tr_variantDictFindStr(args, TR_KEY_config_dir, &str, NULL)) if (tr_variantDictFindStr(args, TR_KEY_config_dir, &str, nullptr))
{ {
printf(" Configuration directory: %s\n", str); printf(" Configuration directory: %s\n", str);
} }
if (tr_variantDictFindStr(args, TR_KEY_download_dir, &str, NULL)) if (tr_variantDictFindStr(args, TR_KEY_download_dir, &str, nullptr))
{ {
printf(" Download directory: %s\n", str); printf(" Download directory: %s\n", str);
} }
@ -1813,7 +1820,7 @@ static void printSession(tr_variant* top)
printf(" Peer exchange allowed: %s\n", boolVal ? "Yes" : "No"); printf(" Peer exchange allowed: %s\n", boolVal ? "Yes" : "No");
} }
if (tr_variantDictFindStr(args, TR_KEY_encryption, &str, NULL)) if (tr_variantDictFindStr(args, TR_KEY_encryption, &str, nullptr))
{ {
printf(" Encryption: %s\n", str); printf(" Encryption: %s\n", str);
} }
@ -2046,7 +2053,7 @@ static int processResponse(char const* rpcurl, void const* response, size_t len)
int64_t tag = -1; int64_t tag = -1;
char const* str; char const* str;
if (tr_variantDictFindStr(&top, TR_KEY_result, &str, NULL)) if (tr_variantDictFindStr(&top, TR_KEY_result, &str, nullptr))
{ {
if (strcmp(str, "success") != 0) if (strcmp(str, "success") != 0)
{ {
@ -2111,7 +2118,7 @@ static int processResponse(char const* rpcurl, void const* response, size_t len)
} }
default: default:
if (!tr_variantDictFindStr(&top, TR_KEY_result, &str, NULL)) if (!tr_variantDictFindStr(&top, TR_KEY_result, &str, nullptr))
{ {
status |= EXIT_FAILURE; status |= EXIT_FAILURE;
} }
@ -2151,12 +2158,12 @@ static CURL* tr_curl_easy_init(struct evbuffer* writebuf)
curl_easy_setopt(curl, CURLOPT_VERBOSE, debug); curl_easy_setopt(curl, CURLOPT_VERBOSE, debug);
curl_easy_setopt(curl, CURLOPT_ENCODING, ""); /* "" tells curl to fill in the blanks with what it was compiled to support */ curl_easy_setopt(curl, CURLOPT_ENCODING, ""); /* "" tells curl to fill in the blanks with what it was compiled to support */
if (netrc != NULL) if (netrc != nullptr)
{ {
curl_easy_setopt(curl, CURLOPT_NETRC_FILE, netrc); curl_easy_setopt(curl, CURLOPT_NETRC_FILE, netrc);
} }
if (auth != NULL) if (auth != nullptr)
{ {
curl_easy_setopt(curl, CURLOPT_USERPWD, auth); curl_easy_setopt(curl, CURLOPT_USERPWD, auth);
} }
@ -2167,10 +2174,10 @@ static CURL* tr_curl_easy_init(struct evbuffer* writebuf)
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); /* since most certs will be self-signed, do not verify against CA */ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); /* since most certs will be self-signed, do not verify against CA */
} }
if (sessionId != NULL) if (sessionId != nullptr)
{ {
char* h = tr_strdup_printf("%s: %s", TR_RPC_SESSION_ID_HEADER, sessionId); char* h = tr_strdup_printf("%s: %s", TR_RPC_SESSION_ID_HEADER, sessionId);
struct curl_slist* custom_headers = curl_slist_append(NULL, h); struct curl_slist* custom_headers = curl_slist_append(nullptr, h);
tr_free(h); tr_free(h);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, custom_headers); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, custom_headers);
@ -2182,12 +2189,12 @@ static CURL* tr_curl_easy_init(struct evbuffer* writebuf)
static void tr_curl_easy_cleanup(CURL* curl) static void tr_curl_easy_cleanup(CURL* curl)
{ {
struct curl_slist* custom_headers = NULL; struct curl_slist* custom_headers = nullptr;
curl_easy_getinfo(curl, CURLINFO_PRIVATE, &custom_headers); curl_easy_getinfo(curl, CURLINFO_PRIVATE, &custom_headers);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
if (custom_headers != NULL) if (custom_headers != nullptr)
{ {
curl_slist_free_all(custom_headers); curl_slist_free_all(custom_headers);
} }
@ -2199,7 +2206,7 @@ static int flush(char const* rpcurl, tr_variant** benc)
CURL* curl; CURL* curl;
int status = EXIT_SUCCESS; int status = EXIT_SUCCESS;
struct evbuffer* buf = evbuffer_new(); struct evbuffer* buf = evbuffer_new();
char* json = tr_variantToStr(*benc, TR_VARIANT_FMT_JSON_LEAN, NULL); char* json = tr_variantToStr(*benc, TR_VARIANT_FMT_JSON_LEAN, nullptr);
char* rpcurl_http = tr_strdup_printf(UseSSL ? "https://%s" : "http://%s", rpcurl); char* rpcurl_http = tr_strdup_printf(UseSSL ? "https://%s" : "http://%s", rpcurl);
curl = tr_curl_easy_init(buf); curl = tr_curl_easy_init(buf);
@ -2233,9 +2240,9 @@ static int flush(char const* rpcurl, tr_variant** benc)
* pulled the new session id from this response's headers, * pulled the new session id from this response's headers,
* build a new CURL* and try again */ * build a new CURL* and try again */
tr_curl_easy_cleanup(curl); tr_curl_easy_cleanup(curl);
curl = NULL; curl = nullptr;
status |= flush(rpcurl, benc); status |= flush(rpcurl, benc);
benc = NULL; benc = nullptr;
break; break;
default: default:
@ -2251,16 +2258,16 @@ static int flush(char const* rpcurl, tr_variant** benc)
tr_free(json); tr_free(json);
evbuffer_free(buf); evbuffer_free(buf);
if (curl != NULL) if (curl != nullptr)
{ {
tr_curl_easy_cleanup(curl); tr_curl_easy_cleanup(curl);
} }
if (benc != NULL) if (benc != nullptr)
{ {
tr_variantFree(*benc); tr_variantFree(*benc);
tr_free(*benc); tr_free(*benc);
*benc = NULL; *benc = nullptr;
} }
return status; return status;
@ -2270,7 +2277,7 @@ static tr_variant* ensure_sset(tr_variant** sset)
{ {
tr_variant* args; tr_variant* args;
if (*sset != NULL) if (*sset != nullptr)
{ {
args = tr_variantDictFind(*sset, ARGUMENTS); args = tr_variantDictFind(*sset, ARGUMENTS);
} }
@ -2289,7 +2296,7 @@ static tr_variant* ensure_tset(tr_variant** tset)
{ {
tr_variant* args; tr_variant* args;
if (*tset != NULL) if (*tset != nullptr)
{ {
args = tr_variantDictFind(*tset, ARGUMENTS); args = tr_variantDictFind(*tset, ARGUMENTS);
} }
@ -2309,9 +2316,9 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
int c; int c;
int status = EXIT_SUCCESS; int status = EXIT_SUCCESS;
char const* optarg; char const* optarg;
tr_variant* sset = NULL; tr_variant* sset = nullptr;
tr_variant* tset = NULL; tr_variant* tset = nullptr;
tr_variant* tadd = NULL; tr_variant* tadd = nullptr;
*id = '\0'; *id = '\0';
@ -2324,19 +2331,19 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
switch (c) switch (c)
{ {
case 'a': /* add torrent */ case 'a': /* add torrent */
if (sset != NULL) if (sset != nullptr)
{ {
status |= flush(rpcurl, &sset); status |= flush(rpcurl, &sset);
} }
if (tadd != NULL) if (tadd != nullptr)
{ {
status |= flush(rpcurl, &tadd); status |= flush(rpcurl, &tadd);
} }
if (tset != NULL) if (tset != nullptr)
{ {
addIdArg(tr_variantDictFind(tset, ARGUMENTS), id, NULL); addIdArg(tr_variantDictFind(tset, ARGUMENTS), id, nullptr);
status |= flush(rpcurl, &tset); status |= flush(rpcurl, &tset);
} }
@ -2356,9 +2363,9 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
break; break;
case 810: /* authenv */ case 810: /* authenv */
auth = tr_env_get_string("TR_AUTH", NULL); auth = tr_env_get_string("TR_AUTH", nullptr);
if (auth == NULL) if (auth == nullptr)
{ {
fprintf(stderr, "The TR_AUTH environment variable is not set\n"); fprintf(stderr, "The TR_AUTH environment variable is not set\n");
exit(0); exit(0);
@ -2375,14 +2382,14 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
break; break;
case 't': /* set current torrent */ case 't': /* set current torrent */
if (tadd != NULL) if (tadd != nullptr)
{ {
status |= flush(rpcurl, &tadd); status |= flush(rpcurl, &tadd);
} }
if (tset != NULL) if (tset != nullptr)
{ {
addIdArg(tr_variantDictFind(tset, ARGUMENTS), id, NULL); addIdArg(tr_variantDictFind(tset, ARGUMENTS), id, nullptr);
status |= flush(rpcurl, &tset); status |= flush(rpcurl, &tset);
} }
@ -2400,12 +2407,12 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
break; break;
case TR_OPT_UNK: case TR_OPT_UNK:
if (tadd != NULL) if (tadd != nullptr)
{ {
tr_variant* args = tr_variantDictFind(tadd, ARGUMENTS); tr_variant* args = tr_variantDictFind(tadd, ARGUMENTS);
char* tmp = getEncodedMetainfo(optarg); char* tmp = getEncodedMetainfo(optarg);
if (tmp != NULL) if (tmp != nullptr)
{ {
tr_variantDictAddStr(args, TR_KEY_metainfo, tmp); tr_variantDictAddStr(args, TR_KEY_metainfo, tmp);
} }
@ -2435,9 +2442,9 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
args = tr_variantDictAddDict(top, ARGUMENTS, 0); args = tr_variantDictAddDict(top, ARGUMENTS, 0);
fields = tr_variantDictAddList(args, TR_KEY_fields, 0); fields = tr_variantDictAddList(args, TR_KEY_fields, 0);
if (tset != NULL) if (tset != nullptr)
{ {
addIdArg(tr_variantDictFind(tset, ARGUMENTS), id, NULL); addIdArg(tr_variantDictFind(tset, ARGUMENTS), id, nullptr);
status |= flush(rpcurl, &tset); status |= flush(rpcurl, &tset);
} }
@ -2451,7 +2458,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
tr_variantListAddQuark(fields, details_keys[i]); tr_variantListAddQuark(fields, details_keys[i]);
} }
addIdArg(args, id, NULL); addIdArg(args, id, nullptr);
break; break;
case 'l': case 'l':
@ -2473,26 +2480,26 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
tr_variantListAddQuark(fields, files_keys[i]); tr_variantListAddQuark(fields, files_keys[i]);
} }
addIdArg(args, id, NULL); addIdArg(args, id, nullptr);
break; break;
case 941: case 941:
tr_variantDictAddInt(top, TR_KEY_tag, TAG_PEERS); tr_variantDictAddInt(top, TR_KEY_tag, TAG_PEERS);
tr_variantListAddStr(fields, "peers"); tr_variantListAddStr(fields, "peers");
addIdArg(args, id, NULL); addIdArg(args, id, nullptr);
break; break;
case 942: case 942:
tr_variantDictAddInt(top, TR_KEY_tag, TAG_PIECES); tr_variantDictAddInt(top, TR_KEY_tag, TAG_PIECES);
tr_variantListAddStr(fields, "pieces"); tr_variantListAddStr(fields, "pieces");
tr_variantListAddStr(fields, "pieceCount"); tr_variantListAddStr(fields, "pieceCount");
addIdArg(args, id, NULL); addIdArg(args, id, nullptr);
break; break;
case 943: case 943:
tr_variantDictAddInt(top, TR_KEY_tag, TAG_TRACKERS); tr_variantDictAddInt(top, TR_KEY_tag, TAG_TRACKERS);
tr_variantListAddStr(fields, "trackerStats"); tr_variantListAddStr(fields, "trackerStats");
addIdArg(args, id, NULL); addIdArg(args, id, nullptr);
break; break;
default: default:
@ -2657,8 +2664,8 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
} }
else if (stepMode == (MODE_SESSION_SET | MODE_TORRENT_SET)) else if (stepMode == (MODE_SESSION_SET | MODE_TORRENT_SET))
{ {
tr_variant* targs = NULL; tr_variant* targs = nullptr;
tr_variant* sargs = NULL; tr_variant* sargs = nullptr;
if (!tr_str_is_empty(id)) if (!tr_str_is_empty(id))
{ {
@ -2672,7 +2679,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
switch (c) switch (c)
{ {
case 'd': case 'd':
if (targs != NULL) if (targs != nullptr)
{ {
tr_variantDictAddInt(targs, TR_KEY_downloadLimit, numarg(optarg)); tr_variantDictAddInt(targs, TR_KEY_downloadLimit, numarg(optarg));
tr_variantDictAddBool(targs, TR_KEY_downloadLimited, true); tr_variantDictAddBool(targs, TR_KEY_downloadLimited, true);
@ -2686,7 +2693,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
break; break;
case 'D': case 'D':
if (targs != NULL) if (targs != nullptr)
{ {
tr_variantDictAddBool(targs, TR_KEY_downloadLimited, false); tr_variantDictAddBool(targs, TR_KEY_downloadLimited, false);
} }
@ -2698,7 +2705,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
break; break;
case 'u': case 'u':
if (targs != NULL) if (targs != nullptr)
{ {
tr_variantDictAddInt(targs, TR_KEY_uploadLimit, numarg(optarg)); tr_variantDictAddInt(targs, TR_KEY_uploadLimit, numarg(optarg));
tr_variantDictAddBool(targs, TR_KEY_uploadLimited, true); tr_variantDictAddBool(targs, TR_KEY_uploadLimited, true);
@ -2712,7 +2719,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
break; break;
case 'U': case 'U':
if (targs != NULL) if (targs != nullptr)
{ {
tr_variantDictAddBool(targs, TR_KEY_uploadLimited, false); tr_variantDictAddBool(targs, TR_KEY_uploadLimited, false);
} }
@ -2724,7 +2731,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
break; break;
case 930: case 930:
if (targs != NULL) if (targs != nullptr)
{ {
tr_variantDictAddInt(targs, TR_KEY_peer_limit, atoi(optarg)); tr_variantDictAddInt(targs, TR_KEY_peer_limit, atoi(optarg));
} }
@ -2784,7 +2791,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
{ {
tr_variant* args; tr_variant* args;
if (tadd != NULL) if (tadd != nullptr)
{ {
args = tr_variantDictFind(tadd, ARGUMENTS); args = tr_variantDictFind(tadd, ARGUMENTS);
} }
@ -2838,7 +2845,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
} }
else if (c == 961) /* set location */ else if (c == 961) /* set location */
{ {
if (tadd != NULL) if (tadd != nullptr)
{ {
tr_variant* args = tr_variantDictFind(tadd, ARGUMENTS); tr_variant* args = tr_variantDictFind(tadd, ARGUMENTS);
tr_variantDictAddStr(args, TR_KEY_download_dir, optarg); tr_variantDictAddStr(args, TR_KEY_download_dir, optarg);
@ -2852,7 +2859,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
args = tr_variantDictAddDict(top, ARGUMENTS, 3); args = tr_variantDictAddDict(top, ARGUMENTS, 3);
tr_variantDictAddStr(args, TR_KEY_location, optarg); tr_variantDictAddStr(args, TR_KEY_location, optarg);
tr_variantDictAddBool(args, TR_KEY_move, false); tr_variantDictAddBool(args, TR_KEY_move, false);
addIdArg(args, id, NULL); addIdArg(args, id, nullptr);
status |= flush(rpcurl, &top); status |= flush(rpcurl, &top);
break; break;
} }
@ -2873,7 +2880,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
case 's': /* start */ case 's': /* start */
{ {
if (tadd != NULL) if (tadd != nullptr)
{ {
tr_variantDictAddBool(tr_variantDictFind(tadd, TR_KEY_arguments), TR_KEY_paused, false); tr_variantDictAddBool(tr_variantDictFind(tadd, TR_KEY_arguments), TR_KEY_paused, false);
} }
@ -2882,7 +2889,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
tr_variant* top = tr_new0(tr_variant, 1); tr_variant* top = tr_new0(tr_variant, 1);
tr_variantInitDict(top, 2); tr_variantInitDict(top, 2);
tr_variantDictAddStr(top, TR_KEY_method, "torrent-start"); tr_variantDictAddStr(top, TR_KEY_method, "torrent-start");
addIdArg(tr_variantDictAddDict(top, ARGUMENTS, 1), id, NULL); addIdArg(tr_variantDictAddDict(top, ARGUMENTS, 1), id, nullptr);
status |= flush(rpcurl, &top); status |= flush(rpcurl, &top);
} }
@ -2891,7 +2898,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
case 'S': /* stop */ case 'S': /* stop */
{ {
if (tadd != NULL) if (tadd != nullptr)
{ {
tr_variantDictAddBool(tr_variantDictFind(tadd, TR_KEY_arguments), TR_KEY_paused, true); tr_variantDictAddBool(tr_variantDictFind(tadd, TR_KEY_arguments), TR_KEY_paused, true);
} }
@ -2900,7 +2907,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
tr_variant* top = tr_new0(tr_variant, 1); tr_variant* top = tr_new0(tr_variant, 1);
tr_variantInitDict(top, 2); tr_variantInitDict(top, 2);
tr_variantDictAddStr(top, TR_KEY_method, "torrent-stop"); tr_variantDictAddStr(top, TR_KEY_method, "torrent-stop");
addIdArg(tr_variantDictAddDict(top, ARGUMENTS, 1), id, NULL); addIdArg(tr_variantDictAddDict(top, ARGUMENTS, 1), id, nullptr);
status |= flush(rpcurl, &top); status |= flush(rpcurl, &top);
} }
@ -2909,7 +2916,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
case 'w': case 'w':
{ {
tr_variant* args = tadd != NULL ? tr_variantDictFind(tadd, TR_KEY_arguments) : ensure_sset(&sset); tr_variant* args = tadd != nullptr ? tr_variantDictFind(tadd, TR_KEY_arguments) : ensure_sset(&sset);
tr_variantDictAddStr(args, TR_KEY_download_dir, optarg); tr_variantDictAddStr(args, TR_KEY_download_dir, optarg);
break; break;
} }
@ -2956,16 +2963,16 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
{ {
tr_variant* top; tr_variant* top;
if (tset != NULL) if (tset != nullptr)
{ {
addIdArg(tr_variantDictFind(tset, ARGUMENTS), id, NULL); addIdArg(tr_variantDictFind(tset, ARGUMENTS), id, nullptr);
status |= flush(rpcurl, &tset); status |= flush(rpcurl, &tset);
} }
top = tr_new0(tr_variant, 1); top = tr_new0(tr_variant, 1);
tr_variantInitDict(top, 2); tr_variantInitDict(top, 2);
tr_variantDictAddStr(top, TR_KEY_method, "torrent-reannounce"); tr_variantDictAddStr(top, TR_KEY_method, "torrent-reannounce");
addIdArg(tr_variantDictAddDict(top, ARGUMENTS, 1), id, NULL); addIdArg(tr_variantDictAddDict(top, ARGUMENTS, 1), id, nullptr);
status |= flush(rpcurl, &top); status |= flush(rpcurl, &top);
break; break;
} }
@ -2974,16 +2981,16 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
{ {
tr_variant* top; tr_variant* top;
if (tset != NULL) if (tset != nullptr)
{ {
addIdArg(tr_variantDictFind(tset, ARGUMENTS), id, NULL); addIdArg(tr_variantDictFind(tset, ARGUMENTS), id, nullptr);
status |= flush(rpcurl, &tset); status |= flush(rpcurl, &tset);
} }
top = tr_new0(tr_variant, 1); top = tr_new0(tr_variant, 1);
tr_variantInitDict(top, 2); tr_variantInitDict(top, 2);
tr_variantDictAddStr(top, TR_KEY_method, "torrent-verify"); tr_variantDictAddStr(top, TR_KEY_method, "torrent-verify");
addIdArg(tr_variantDictAddDict(top, ARGUMENTS, 1), id, NULL); addIdArg(tr_variantDictAddDict(top, ARGUMENTS, 1), id, nullptr);
status |= flush(rpcurl, &top); status |= flush(rpcurl, &top);
break; break;
} }
@ -2997,7 +3004,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
tr_variantDictAddStr(top, TR_KEY_method, "torrent-remove"); tr_variantDictAddStr(top, TR_KEY_method, "torrent-remove");
args = tr_variantDictAddDict(top, ARGUMENTS, 2); args = tr_variantDictAddDict(top, ARGUMENTS, 2);
tr_variantDictAddBool(args, TR_KEY_delete_local_data, c == 840); tr_variantDictAddBool(args, TR_KEY_delete_local_data, c == 840);
addIdArg(args, id, NULL); addIdArg(args, id, nullptr);
status |= flush(rpcurl, &top); status |= flush(rpcurl, &top);
break; break;
} }
@ -3011,7 +3018,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
args = tr_variantDictAddDict(top, ARGUMENTS, 3); args = tr_variantDictAddDict(top, ARGUMENTS, 3);
tr_variantDictAddStr(args, TR_KEY_location, optarg); tr_variantDictAddStr(args, TR_KEY_location, optarg);
tr_variantDictAddBool(args, TR_KEY_move, true); tr_variantDictAddBool(args, TR_KEY_move, true);
addIdArg(args, id, NULL); addIdArg(args, id, nullptr);
status |= flush(rpcurl, &top); status |= flush(rpcurl, &top);
break; break;
} }
@ -3026,18 +3033,18 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
} }
} }
if (tadd != NULL) if (tadd != nullptr)
{ {
status |= flush(rpcurl, &tadd); status |= flush(rpcurl, &tadd);
} }
if (tset != NULL) if (tset != nullptr)
{ {
addIdArg(tr_variantDictFind(tset, ARGUMENTS), id, NULL); addIdArg(tr_variantDictFind(tset, ARGUMENTS), id, nullptr);
status |= flush(rpcurl, &tset); status |= flush(rpcurl, &tset);
} }
if (sset != NULL) if (sset != nullptr)
{ {
status |= flush(rpcurl, &sset); status |= flush(rpcurl, &sset);
} }
@ -3050,9 +3057,9 @@ static bool parsePortString(char const* s, int* port)
int const errno_stack = errno; int const errno_stack = errno;
errno = 0; errno = 0;
char* end = NULL; char* end = nullptr;
int const i = (int)strtol(s, &end, 10); int const i = (int)strtol(s, &end, 10);
bool const ok = (end != NULL) && (*end == '\0') && (errno == 0); bool const ok = (end != nullptr) && (*end == '\0') && (errno == 0);
if (ok) if (ok)
{ {
*port = i; *port = i;
@ -3086,7 +3093,7 @@ static void getHostAndPortAndRpcUrl(int* argc, char** argv, char** host, int* po
{ {
// it was just a port // it was just a port
} }
else if (last_colon == NULL) else if (last_colon == nullptr)
{ {
// it was a non-ipv6 host with no port // it was a non-ipv6 host with no port
*host = tr_strdup(s); *host = tr_strdup(s);
@ -3105,7 +3112,7 @@ static void getHostAndPortAndRpcUrl(int* argc, char** argv, char** host, int* po
hend = s + strlen(s); hend = s + strlen(s);
} }
bool const is_unbracketed_ipv6 = (*s != '[') && (memchr(s, ':', hend - s) != NULL); bool const is_unbracketed_ipv6 = (*s != '[') && (memchr(s, ':', hend - s) != nullptr);
*host = is_unbracketed_ipv6 ? tr_strdup_printf("[%*s]", TR_ARG_TUPLE((int)(hend - s), s)) : tr_strndup(s, hend - s); *host = is_unbracketed_ipv6 ? tr_strdup_printf("[%*s]", TR_ARG_TUPLE((int)(hend - s), s)) : tr_strndup(s, hend - s);
} }
@ -3121,8 +3128,8 @@ static void getHostAndPortAndRpcUrl(int* argc, char** argv, char** host, int* po
int tr_main(int argc, char* argv[]) int tr_main(int argc, char* argv[])
{ {
int port = DEFAULT_PORT; int port = DEFAULT_PORT;
char* host = NULL; char* host = nullptr;
char* rpcurl = NULL; char* rpcurl = nullptr;
int exit_status = EXIT_SUCCESS; int exit_status = EXIT_SUCCESS;
if (argc < 2) if (argc < 2)
@ -3137,12 +3144,12 @@ int tr_main(int argc, char* argv[])
getHostAndPortAndRpcUrl(&argc, argv, &host, &port, &rpcurl); getHostAndPortAndRpcUrl(&argc, argv, &host, &port, &rpcurl);
if (host == NULL) if (host == nullptr)
{ {
host = tr_strdup(DEFAULT_HOST); host = tr_strdup(DEFAULT_HOST);
} }
if (rpcurl == NULL) if (rpcurl == nullptr)
{ {
rpcurl = tr_strdup_printf("%s:%d%s", host, port, DEFAULT_URL); rpcurl = tr_strdup_printf("%s:%d%s", host, port, DEFAULT_URL);
} }

View File

@ -28,11 +28,11 @@
#define TIMEOUT_SECS 30 #define TIMEOUT_SECS 30
static tr_option options[] = { static tr_option options[] = {
{ 'm', "magnet", "Give a magnet link for the specified torrent", "m", false, NULL }, { 'm', "magnet", "Give a magnet link for the specified torrent", "m", false, nullptr },
{ 's', "scrape", "Ask the torrent's trackers how many peers are in the torrent's swarm", "s", false, NULL }, { 's', "scrape", "Ask the torrent's trackers how many peers are in the torrent's swarm", "s", false, nullptr },
{ 'u', "unsorted", "Do not sort files by name", "u", false, NULL }, { 'u', "unsorted", "Do not sort files by name", "u", false, nullptr },
{ 'V', "version", "Show version number and exit", "V", false, NULL }, { 'V', "version", "Show version number and exit", "V", false, nullptr },
{ 0, NULL, NULL, NULL, false, NULL } { 0, nullptr, nullptr, nullptr, false, nullptr }
}; };
static char const* getUsage(void) static char const* getUsage(void)
@ -44,7 +44,7 @@ static bool magnetFlag = false;
static bool scrapeFlag = false; static bool scrapeFlag = false;
static bool unsorted = false; static bool unsorted = false;
static bool showVersion = false; static bool showVersion = false;
char const* filename = NULL; char const* filename = nullptr;
static int parseCommandLine(int argc, char const* const* argv) static int parseCommandLine(int argc, char const* const* argv)
{ {
@ -224,14 +224,14 @@ static void doScrape(tr_info const* inf)
char* url; char* url;
char escaped[SHA_DIGEST_LENGTH * 3 + 1]; char escaped[SHA_DIGEST_LENGTH * 3 + 1];
if (scrape == NULL) if (scrape == nullptr)
{ {
continue; continue;
} }
tr_http_escape_sha1(escaped, inf->hash); tr_http_escape_sha1(escaped, inf->hash);
url = tr_strdup_printf("%s%cinfo_hash=%s", scrape, strchr(scrape, '?') != NULL ? '&' : '?', escaped); url = tr_strdup_printf("%s%cinfo_hash=%s", scrape, strchr(scrape, '?') != nullptr ? '&' : '?', escaped);
printf("%s ... ", url); printf("%s ... ", url);
fflush(stdout); fflush(stdout);
@ -271,7 +271,7 @@ static void doScrape(tr_info const* inf)
while (tr_variantDictChild(files, child_pos, &key, &val)) while (tr_variantDictChild(files, child_pos, &key, &val))
{ {
if (memcmp(inf->hash, tr_quark_get_string(key, NULL), SHA_DIGEST_LENGTH) == 0) if (memcmp(inf->hash, tr_quark_get_string(key, nullptr), SHA_DIGEST_LENGTH) == 0)
{ {
int64_t seeders; int64_t seeders;
if (!tr_variantDictFindInt(val, TR_KEY_complete, &seeders)) if (!tr_variantDictFindInt(val, TR_KEY_complete, &seeders))
@ -332,7 +332,7 @@ int tr_main(int argc, char* argv[])
} }
/* make sure the user specified a filename */ /* make sure the user specified a filename */
if (filename == NULL) if (filename == nullptr)
{ {
fprintf(stderr, "ERROR: No .torrent file specified.\n"); fprintf(stderr, "ERROR: No .torrent file specified.\n");
tr_getopt_usage(MY_NAME, getUsage(), options); tr_getopt_usage(MY_NAME, getUsage(), options);
@ -341,7 +341,7 @@ int tr_main(int argc, char* argv[])
} }
/* try to parse the .torrent file */ /* try to parse the .torrent file */
ctor = tr_ctorNew(NULL); ctor = tr_ctorNew(nullptr);
tr_ctorSetMetainfoFromFile(ctor, filename); tr_ctorSetMetainfoFromFile(ctor, filename);
err = tr_torrentParse(ctor, &inf); err = tr_torrentParse(ctor, &inf);
tr_ctorFree(ctor); tr_ctorFree(ctor);