diff --git a/cli/cli.c b/cli/cli.c index 8a44bfab6..35431fbdd 100644 --- a/cli/cli.c +++ b/cli/cli.c @@ -262,18 +262,16 @@ int tr_main(int argc, char* argv[]) return EXIT_FAILURE; } - if (tr_variantDictFindStr(&settings, TR_KEY_download_dir, &str, NULL)) + if (tr_variantDictFindStr(&settings, TR_KEY_download_dir, &str, NULL) && + !tr_sys_path_exists(str, NULL)) { - if (!tr_sys_path_exists(str, NULL)) - { - tr_error* error = NULL; + tr_error* error = NULL; - if (!tr_sys_dir_create(str, TR_SYS_DIR_CREATE_PARENTS, 0700, &error)) - { - fprintf(stderr, "Unable to create download directory \"%s\": %s\n", str, error->message); - tr_error_free(error); - return EXIT_FAILURE; - } + if (!tr_sys_dir_create(str, TR_SYS_DIR_CREATE_PARENTS, 0700, &error)) + { + fprintf(stderr, "Unable to create download directory \"%s\": %s\n", str, error->message); + tr_error_free(error); + return EXIT_FAILURE; } } diff --git a/gtk/details.c b/gtk/details.c index a9a2d30ba..6cdba06f3 100644 --- a/gtk/details.c +++ b/gtk/details.c @@ -1430,6 +1430,8 @@ static void refreshPeerRow(GtkListStore* store, GtkTreeIter* iter, tr_peer_stat char cancelled_by_peer[64] = { '\0' }; char cancelled_by_client[64] = { '\0' }; + g_return_if_fail(peer != NULL); + if (peer->rateToPeer_KBps > 0.01) { tr_formatter_speed_KBps(up_speed, peer->rateToPeer_KBps, sizeof(up_speed)); @@ -2906,7 +2908,8 @@ static void on_details_window_size_allocated(GtkWidget* gtk_window, GtkAllocatio TR_UNUSED(alloc); TR_UNUSED(gdata); - int w, h; + int w = 0; + int h = 0; gtk_window_get_size(GTK_WINDOW(gtk_window), &w, &h); gtr_pref_int_set(TR_KEY_details_window_width, w); gtr_pref_int_set(TR_KEY_details_window_height, h); diff --git a/gtk/file-list.c b/gtk/file-list.c index b22c34a54..2140b5c28 100644 --- a/gtk/file-list.c +++ b/gtk/file-list.c @@ -129,15 +129,14 @@ static gboolean refreshFilesForeach(GtkTreeModel* model, GtkTreePath* path, GtkT * which breaks this foreach () call. (See #3529) * As a workaround: if that's about to happen, temporarily disable * sorting until we finish walking the tree. */ - if (!refresh_data->resort_needed) + if (!refresh_data->resort_needed && + (((refresh_data->sort_column_id == FC_PRIORITY) && (priority != old_priority)) || + ((refresh_data->sort_column_id == FC_ENABLED) && (enabled != old_enabled)))) { - if ((refresh_data->resort_needed = (refresh_data->sort_column_id == FC_PRIORITY && priority != old_priority) || - (refresh_data->sort_column_id == FC_ENABLED && enabled != old_enabled))) - { - refresh_data->resort_needed = TRUE; - gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(data->model), - GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, GTK_SORT_ASCENDING); - } + refresh_data->resort_needed = TRUE; + + gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(data->model), + GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, GTK_SORT_ASCENDING); } gtk_tree_store_set(data->store, iter, diff --git a/gtk/main.c b/gtk/main.c index a3066fed3..cbb3c97ed 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -547,18 +547,16 @@ static void on_startup(GApplication* application, gpointer user_data) tr_sessionSetRPCCallback(session, on_rpc_changed, cbdata); /* check & see if it's time to update the blocklist */ - if (gtr_pref_flag_get(TR_KEY_blocklist_enabled)) + if (gtr_pref_flag_get(TR_KEY_blocklist_enabled) && + gtr_pref_flag_get(TR_KEY_blocklist_updates_enabled)) { - if (gtr_pref_flag_get(TR_KEY_blocklist_updates_enabled)) - { - int64_t const last_time = gtr_pref_int_get(TR_KEY_blocklist_date); - int const SECONDS_IN_A_WEEK = 7 * 24 * 60 * 60; - time_t const now = time(NULL); + int64_t const last_time = gtr_pref_int_get(TR_KEY_blocklist_date); + int const SECONDS_IN_A_WEEK = 7 * 24 * 60 * 60; + time_t const now = time(NULL); - if (last_time + SECONDS_IN_A_WEEK < now) - { - gtr_core_blocklist_update(cbdata->core); - } + if (last_time + SECONDS_IN_A_WEEK < now) + { + gtr_core_blocklist_update(cbdata->core); } } diff --git a/gtk/stats.c b/gtk/stats.c index bbe902d97..24d27bcb2 100644 --- a/gtk/stats.c +++ b/gtk/stats.c @@ -52,7 +52,6 @@ static void setLabelFromRatio(GtkLabel* l, double d) static gboolean updateStats(gpointer gdata) { char buf[128]; - char const* fmt; tr_session_stats one; tr_session_stats all; size_t const buflen = sizeof(buf); @@ -66,7 +65,7 @@ static gboolean updateStats(gpointer gdata) setLabel(ui->one_time_lb, tr_strltime(buf, one.secondsActive, buflen)); setLabelFromRatio(ui->one_ratio_lb, one.ratio); - fmt = ngettext("Started %'d time", "Started %'d times", (int)all.sessionCount); + char const* const fmt = ngettext("Started %'d time", "Started %'d times", (int)all.sessionCount); g_snprintf(buf, buflen, fmt, (int)all.sessionCount); setLabel(ui->all_sessions_lb, buf); setLabel(ui->all_up_lb, tr_strlsize(buf, all.uploadedBytes, buflen)); diff --git a/gtk/tr-prefs.c b/gtk/tr-prefs.c index e0c2ae41f..3b18f8199 100644 --- a/gtk/tr-prefs.c +++ b/gtk/tr-prefs.c @@ -449,12 +449,12 @@ static void onBlocklistUpdated(TrCore* core, int n, gpointer gdata) { bool const success = n >= 0; int const count = n >= 0 ? n : tr_blocklistGetRuleCount(gtr_core_session(core)); - char const* s = ngettext("Blocklist has %'d rule.", "Blocklist has %'d rules.", count); struct blocklist_data* data = gdata; GtkMessageDialog* d = GTK_MESSAGE_DIALOG(data->updateBlocklistDialog); gtk_widget_set_sensitive(data->updateBlocklistButton, TRUE); gtk_message_dialog_set_markup(d, success ? _("Update succeeded!") : _("Unable to update.")); - gtk_message_dialog_format_secondary_text(d, s, count); + char const* const fmt = ngettext("Blocklist has %'d rule.", "Blocklist has %'d rules.", count); + gtk_message_dialog_format_secondary_text(d, fmt, count); updateBlocklistText(data->label, core); } diff --git a/gtk/tr-window.c b/gtk/tr-window.c index 41d429b71..eb0417143 100644 --- a/gtk/tr-window.c +++ b/gtk/tr-window.c @@ -255,19 +255,18 @@ static void status_menu_toggled_cb(GtkCheckMenuItem* menu_item, gpointer vprivat static void syncAltSpeedButton(PrivateData* p) { - char u[32]; - char d[32]; - char* str; - char const* fmt; gboolean const b = gtr_pref_flag_get(TR_KEY_alt_speed_enabled); - char const* stock = b ? "alt-speed-on" : "alt-speed-off"; - GtkWidget* w = p->alt_speed_button; + char const* const stock = b ? "alt-speed-on" : "alt-speed-off"; + GtkWidget* const w = p->alt_speed_button; + char u[32]; tr_formatter_speed_KBps(u, gtr_pref_int_get(TR_KEY_alt_speed_up), sizeof(u)); + char d[32]; tr_formatter_speed_KBps(d, gtr_pref_int_get(TR_KEY_alt_speed_down), sizeof(d)); - fmt = b ? _("Click to disable Alternative Speed Limits\n (%1$s down, %2$s up)") : - _("Click to enable Alternative Speed Limits\n (%1$s down, %2$s up)"); - str = g_strdup_printf(fmt, d, u); + + char* const str = b ? + g_strdup_printf(_("Click to disable Alternative Speed Limits\n (%1$s down, %2$s up)"), d, u) : + g_strdup_printf(_("Click to enable Alternative Speed Limits\n (%1$s down, %2$s up)"), d, u); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b); gtk_image_set_from_stock(GTK_IMAGE(p->alt_speed_image), stock, -1); diff --git a/libtransmission/announcer-http.c b/libtransmission/announcer-http.c index 5a34cf70a..8f99dfce6 100644 --- a/libtransmission/announcer-http.c +++ b/libtransmission/announcer-http.c @@ -36,15 +36,9 @@ static char const* get_event_string(tr_announce_request const* req) { - if (req->partial_seed) - { - if (req->event != TR_ANNOUNCE_EVENT_STOPPED) - { - return "paused"; - } - } - - return tr_announce_event_get_string(req->event); + return req->partial_seed && (req->event != TR_ANNOUNCE_EVENT_STOPPED) ? + "paused" : + tr_announce_event_get_string(req->event); } static char* announce_url_new(tr_session const* session, tr_announce_request const* req) @@ -429,12 +423,10 @@ static void on_scrape_done(tr_session* session, bool did_connect, bool did_timeo response->errmsg = tr_strndup(str, len); } - if (tr_variantDictFindDict(&top, TR_KEY_flags, &flags)) + if (tr_variantDictFindDict(&top, TR_KEY_flags, + &flags) && tr_variantDictFindInt(flags, TR_KEY_min_request_interval, &intVal)) { - if (tr_variantDictFindInt(flags, TR_KEY_min_request_interval, &intVal)) - { - response->min_request_interval = intVal; - } + response->min_request_interval = intVal; } if (tr_variantDictFindDict(&top, TR_KEY_files, &files)) diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index 8d12ce3b8..2da91a536 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -522,13 +522,12 @@ tr_socket_t tr_fdSocketCreate(tr_session* session, int domain, int type) if (gFd->peerCount < session->peerLimit) { - if ((s = socket(domain, type, 0)) == TR_BAD_SOCKET) + s = socket(domain, type, 0); + + if ((s == TR_BAD_SOCKET) && (sockerrno != EAFNOSUPPORT)) { - if (sockerrno != EAFNOSUPPORT) - { - char err_buf[512]; - tr_logAddError(_("Couldn't create socket: %s"), tr_net_strerror(err_buf, sizeof(err_buf), sockerrno)); - } + char err_buf[512]; + tr_logAddError(_("Couldn't create socket: %s"), tr_net_strerror(err_buf, sizeof(err_buf), sockerrno)); } } diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index 56fa9e1b1..e298661f4 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -172,24 +172,12 @@ static void setReadState(tr_handshake* handshake, handshake_state_t state) static bool buildHandshakeMessage(tr_handshake* handshake, uint8_t* buf) { - unsigned char const* peer_id = NULL; - uint8_t const* torrentHash; - tr_torrent* tor; - bool success; + uint8_t const* const torrent_hash = tr_cryptoGetTorrentHash(handshake->crypto); + tr_torrent* const tor = torrent_hash == NULL ? NULL : tr_torrentFindFromHash(handshake->session, torrent_hash); + unsigned char const* const peer_id = tor == NULL ? NULL : tr_torrentGetPeerId(tor); + bool const success = peer_id != NULL; - if ((torrentHash = tr_cryptoGetTorrentHash(handshake->crypto)) != NULL) - { - if ((tor = tr_torrentFindFromHash(handshake->session, torrentHash)) != NULL) - { - peer_id = tr_torrentGetPeerId(tor); - } - } - - if (peer_id == NULL) - { - success = false; - } - else + if (success) { uint8_t* walk = buf; @@ -208,13 +196,12 @@ static bool buildHandshakeMessage(tr_handshake* handshake, uint8_t* buf) } walk += HANDSHAKE_FLAGS_LEN; - memcpy(walk, torrentHash, SHA_DIGEST_LENGTH); + memcpy(walk, torrent_hash, SHA_DIGEST_LENGTH); walk += SHA_DIGEST_LENGTH; memcpy(walk, peer_id, PEER_ID_LEN); walk += PEER_ID_LEN; TR_ASSERT(walk - buf == HANDSHAKE_SIZE); - success = true; } return success; diff --git a/libtransmission/makemeta.c b/libtransmission/makemeta.c index e9a316451..48af46d03 100644 --- a/libtransmission/makemeta.c +++ b/libtransmission/makemeta.c @@ -490,14 +490,13 @@ static void tr_realMakeMetaInfo(tr_metainfo_builder* builder) } /* save the file */ - if (builder->result == TR_MAKEMETA_OK && !builder->abortFlag) + if ((builder->result == TR_MAKEMETA_OK) && + (!builder->abortFlag) && + (tr_variantToFile(&top, TR_VARIANT_FMT_BENC, builder->outputFile) != 0)) { - if (tr_variantToFile(&top, TR_VARIANT_FMT_BENC, builder->outputFile) != 0) - { - builder->my_errno = errno; - tr_strlcpy(builder->errfile, builder->outputFile, sizeof(builder->errfile)); - builder->result = TR_MAKEMETA_IO_WRITE; - } + builder->my_errno = errno; + tr_strlcpy(builder->errfile, builder->outputFile, sizeof(builder->errfile)); + builder->result = TR_MAKEMETA_IO_WRITE; } /* cleanup */ diff --git a/libtransmission/metainfo.c b/libtransmission/metainfo.c index 8f00e4388..7009acd72 100644 --- a/libtransmission/metainfo.c +++ b/libtransmission/metainfo.c @@ -265,13 +265,11 @@ static char const* parseFiles(tr_info* inf, tr_variant* files, tr_variant const* break; } - if (!tr_variantDictFindList(file, TR_KEY_path_utf_8, &path)) + if (!tr_variantDictFindList(file, TR_KEY_path_utf_8, &path) && + !tr_variantDictFindList(file, TR_KEY_path, &path)) { - if (!tr_variantDictFindList(file, TR_KEY_path, &path)) - { - result = "path"; - break; - } + result = "path"; + break; } bool is_file_adjusted; @@ -613,12 +611,10 @@ static char const* tr_metainfoParseImpl(tr_session const* session, tr_info* inf, { len = 0; - if (!tr_variantDictFindStr(infoDict, TR_KEY_name_utf_8, &str, &len)) + if (!tr_variantDictFindStr(infoDict, TR_KEY_name_utf_8, &str, &len) && + !tr_variantDictFindStr(infoDict, TR_KEY_name, &str, &len)) { - if (!tr_variantDictFindStr(infoDict, TR_KEY_name, &str, &len)) - { - str = ""; - } + str = ""; } if (tr_str_is_empty(str)) @@ -635,12 +631,10 @@ static char const* tr_metainfoParseImpl(tr_session const* session, tr_info* inf, /* comment */ len = 0; - if (!tr_variantDictFindStr(meta, TR_KEY_comment_utf_8, &str, &len)) + if (!tr_variantDictFindStr(meta, TR_KEY_comment_utf_8, &str, &len) && + !tr_variantDictFindStr(meta, TR_KEY_comment, &str, &len)) { - if (!tr_variantDictFindStr(meta, TR_KEY_comment, &str, &len)) - { - str = ""; - } + str = ""; } tr_free(inf->comment); @@ -649,12 +643,10 @@ static char const* tr_metainfoParseImpl(tr_session const* session, tr_info* inf, /* created by */ len = 0; - if (!tr_variantDictFindStr(meta, TR_KEY_created_by_utf_8, &str, &len)) + if (!tr_variantDictFindStr(meta, TR_KEY_created_by_utf_8, &str, &len) && + !tr_variantDictFindStr(meta, TR_KEY_created_by, &str, &len)) { - if (!tr_variantDictFindStr(meta, TR_KEY_created_by, &str, &len)) - { - str = ""; - } + str = ""; } tr_free(inf->creator); @@ -669,12 +661,10 @@ static char const* tr_metainfoParseImpl(tr_session const* session, tr_info* inf, inf->dateCreated = i; /* private */ - if (!tr_variantDictFindInt(infoDict, TR_KEY_private, &i)) + if (!tr_variantDictFindInt(infoDict, TR_KEY_private, &i) && + !tr_variantDictFindInt(meta, TR_KEY_private, &i)) { - if (!tr_variantDictFindInt(meta, TR_KEY_private, &i)) - { - i = 0; - } + i = 0; } inf->isPrivate = i != 0; diff --git a/libtransmission/natpmp.c b/libtransmission/natpmp.c index d466bef55..62abbfde8 100644 --- a/libtransmission/natpmp.c +++ b/libtransmission/natpmp.c @@ -144,12 +144,11 @@ int tr_natpmpPulse(struct tr_natpmp* nat, tr_port private_port, bool is_enabled, } } - if (nat->state == TR_NATPMP_IDLE || nat->state == TR_NATPMP_ERR) + if ((nat->state == TR_NATPMP_IDLE || nat->state == TR_NATPMP_ERR) && + (nat->is_mapped) && + (!is_enabled || nat->private_port != private_port)) { - if (nat->is_mapped && (!is_enabled || nat->private_port != private_port)) - { - nat->state = TR_NATPMP_SEND_UNMAP; - } + nat->state = TR_NATPMP_SEND_UNMAP; } if (nat->state == TR_NATPMP_SEND_UNMAP && canSendCommand(nat)) diff --git a/libtransmission/net.c b/libtransmission/net.c index a9816a924..16a193781 100644 --- a/libtransmission/net.c +++ b/libtransmission/net.c @@ -418,17 +418,13 @@ static tr_socket_t tr_netBindTCPImpl(tr_address const* addr, tr_port port, bool #ifdef IPV6_V6ONLY - if (addr->type == TR_AF_INET6) + if ((addr->type == TR_AF_INET6) && + (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void const*)&optval, sizeof(optval)) == -1) && + (sockerrno != ENOPROTOOPT)) // if the kernel doesn't support it, ignore it { - if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void const*)&optval, sizeof(optval)) == -1) - { - if (sockerrno != ENOPROTOOPT) /* if the kernel doesn't support it, ignore it */ - { - *errOut = sockerrno; - tr_netCloseSocket(fd); - return TR_BAD_SOCKET; - } - } + *errOut = sockerrno; + tr_netCloseSocket(fd); + return TR_BAD_SOCKET; } #endif diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 1c1a1e3e6..c8e41c441 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -790,12 +790,10 @@ static void getBlockRequestPeers(tr_swarm* s, tr_block_index_t block, tr_ptrArra static void decrementPendingReqCount(struct block_request const* b) { - if (b->peer != NULL) + if ((b->peer != NULL) && + (b->peer->pendingReqsToPeer > 0)) { - if (b->peer->pendingReqsToPeer > 0) - { - --b->peer->pendingReqsToPeer; - } + --b->peer->pendingReqsToPeer; } } @@ -1100,12 +1098,9 @@ static void pieceListRebuild(tr_swarm* s) for (tr_piece_index_t i = 0; i < inf->pieceCount; ++i) { - if (!inf->pieces[i].dnd) + if (!inf->pieces[i].dnd && !tr_torrentPieceIsComplete(tor, i)) { - if (!tr_torrentPieceIsComplete(tor, i)) - { - pool[poolCount++] = i; - } + pool[poolCount++] = i; } } @@ -2207,12 +2202,10 @@ void tr_peerMgrAddPex(tr_torrent* tor, uint8_t from, tr_pex const* pex, int8_t s tr_swarm* s = tor->swarm; managerLock(s->manager); - if (!tr_sessionIsAddressBlocked(s->manager->session, &pex->addr)) + if (!tr_sessionIsAddressBlocked(s->manager->session, &pex->addr) && + tr_address_is_valid_for_peers(&pex->addr, pex->port)) { - if (tr_address_is_valid_for_peers(&pex->addr, pex->port)) - { - ensureAtomExists(s, &pex->addr, pex->port, pex->flags, seedProbability, from); - } + ensureAtomExists(s, &pex->addr, pex->port, pex->flags, seedProbability, from); } managerUnlock(s->manager); diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 1637d7f3d..315ec588e 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -865,7 +865,6 @@ static void sendLtepHandshake(tr_peerMsgs* msgs) { tr_variant val; bool allow_pex; - bool allow_metadata_xfer; struct evbuffer* payload; struct evbuffer* out = msgs->outMessages; unsigned char const* ipv6 = tr_globalIPv6(); @@ -885,14 +884,7 @@ static void sendLtepHandshake(tr_peerMsgs* msgs) msgs->clientSentLtepHandshake = true; /* decide if we want to advertise metadata xfer support (BEP 9) */ - if (tr_torrentIsPrivate(msgs->torrent)) - { - allow_metadata_xfer = false; - } - else - { - allow_metadata_xfer = true; - } + bool const allow_metadata_xfer = !tr_torrentIsPrivate(msgs->torrent); /* decide if we want to advertise pex support */ if (!tr_torrentAllowsPex(msgs->torrent)) @@ -1028,12 +1020,10 @@ static void parseLtepHandshake(tr_peerMsgs* msgs, uint32_t len, struct evbuffer* } /* look for metainfo size (BEP 9) */ - if (tr_variantDictFindInt(&val, TR_KEY_metadata_size, &i)) + if (tr_variantDictFindInt(&val, TR_KEY_metadata_size, &i) && + tr_torrentSetMetadataSizeHint(msgs->torrent, i)) { - if (tr_torrentSetMetadataSizeHint(msgs->torrent, i)) - { - msgs->metadata_size_hint = (size_t)i; - } + msgs->metadata_size_hint = (size_t)i; } /* look for upload_only (BEP 21) */ @@ -1050,14 +1040,18 @@ static void parseLtepHandshake(tr_peerMsgs* msgs, uint32_t len, struct evbuffer* dbgmsg(msgs, "peer's port is now %d", (int)i); } - if (tr_peerIoIsIncoming(msgs->io) && tr_variantDictFindRaw(&val, TR_KEY_ipv4, &addr, &addr_len) && addr_len == 4) + if (tr_peerIoIsIncoming(msgs->io) && + tr_variantDictFindRaw(&val, TR_KEY_ipv4, &addr, &addr_len) && + addr_len == 4) { pex.addr.type = TR_AF_INET; memcpy(&pex.addr.addr.addr4, addr, 4); tr_peerMgrAddPex(msgs->torrent, TR_PEER_FROM_LTEP, &pex, seedProbability); } - if (tr_peerIoIsIncoming(msgs->io) && tr_variantDictFindRaw(&val, TR_KEY_ipv6, &addr, &addr_len) && addr_len == 16) + if (tr_peerIoIsIncoming(msgs->io) && + tr_variantDictFindRaw(&val, TR_KEY_ipv6, &addr, &addr_len) && + addr_len == 16) { pex.addr.type = TR_AF_INET6; memcpy(&pex.addr.addr.addr6, addr, 16); @@ -1933,12 +1927,9 @@ static void updateDesiredRequestCount(tr_peerMsgs* msgs) msgs->desiredRequestCount = MAX(floor, estimatedBlocksInPeriod); /* honor the peer's maximum request count, if specified */ - if (msgs->reqq > 0) + if ((msgs->reqq > 0) && (msgs->desiredRequestCount > msgs->reqq)) { - if (msgs->desiredRequestCount > msgs->reqq) - { - msgs->desiredRequestCount = msgs->reqq; - } + msgs->desiredRequestCount = msgs->reqq; } } } diff --git a/libtransmission/resume.c b/libtransmission/resume.c index 0e1b624ac..3bf59e57b 100644 --- a/libtransmission/resume.c +++ b/libtransmission/resume.c @@ -1012,12 +1012,9 @@ static uint64_t setFromCtor(tr_torrent* tor, uint64_t fields, tr_ctor const* cto } } - if ((fields & TR_FR_MAX_PEERS) != 0) + if (((fields & TR_FR_MAX_PEERS) != 0) && tr_ctorGetPeerLimit(ctor, mode, &tor->maxConnectedPeers)) { - if (tr_ctorGetPeerLimit(ctor, mode, &tor->maxConnectedPeers)) - { - ret |= TR_FR_MAX_PEERS; - } + ret |= TR_FR_MAX_PEERS; } if ((fields & TR_FR_DOWNLOAD_DIR) != 0) diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 560c2e6a3..92420673a 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -1407,9 +1407,11 @@ static char const* torrentSet(tr_session* session, tr_variant* args_in, tr_varia if (tr_variantDictFindInt(args_in, TR_KEY_bandwidthPriority, &tmp)) { - if (tr_isPriority(tmp)) + tr_priority_t const priority = (tr_priority_t)tmp; + + if (tr_isPriority(priority)) { - tr_torrentSetPriority(tor, tmp); + tr_torrentSetPriority(tor, priority); } } @@ -1712,14 +1714,12 @@ static void gotNewBlocklist(tr_session* session, bool did_connect, bool did_time stream.avail_out = buflen; err = inflate(&stream, Z_NO_FLUSH); - if (stream.avail_out < buflen) + if ((stream.avail_out < buflen) && + (!tr_sys_file_write(fd, buf, buflen - stream.avail_out, NULL, &error))) { - if (!tr_sys_file_write(fd, buf, buflen - stream.avail_out, NULL, &error)) - { - tr_snprintf(result, sizeof(result), _("Couldn't save file \"%1$s\": %2$s"), filename, error->message); - tr_error_clear(&error); - break; - } + tr_snprintf(result, sizeof(result), _("Couldn't save file \"%1$s\": %2$s"), filename, error->message); + tr_error_clear(&error); + break; } if (err != Z_OK) @@ -1735,13 +1735,11 @@ static void gotNewBlocklist(tr_session* session, bool did_connect, bool did_time inflateEnd(&stream); - if (err == Z_DATA_ERROR) /* couldn't inflate it... it's probably already uncompressed */ + if ((err == Z_DATA_ERROR) && // couldn't inflate it... it's probably already uncompressed + !tr_sys_file_write(fd, response, response_byte_count, NULL, &error)) { - if (!tr_sys_file_write(fd, response, response_byte_count, NULL, &error)) - { - tr_snprintf(result, sizeof(result), _("Couldn't save file \"%1$s\": %2$s"), filename, error->message); - tr_error_clear(&error); - } + tr_snprintf(result, sizeof(result), _("Couldn't save file \"%1$s\": %2$s"), filename, error->message); + tr_error_clear(&error); } tr_sys_file_close(fd, NULL); @@ -1916,12 +1914,10 @@ static char const* torrentAdd(tr_session* session, tr_variant* args_in, tr_varia char const* download_dir = NULL; - if (tr_variantDictFindStr(args_in, TR_KEY_download_dir, &download_dir, NULL)) + if (tr_variantDictFindStr(args_in, TR_KEY_download_dir, &download_dir, NULL) && + tr_sys_path_is_relative(download_dir)) { - if (tr_sys_path_is_relative(download_dir)) - { - return "download directory path is not absolute"; - } + return "download directory path is not absolute"; } int64_t i; @@ -2046,20 +2042,16 @@ static char const* sessionSet(tr_session* session, tr_variant* args_in, tr_varia char const* download_dir = NULL; char const* incomplete_dir = NULL; - if (tr_variantDictFindStr(args_in, TR_KEY_download_dir, &download_dir, NULL)) + if (tr_variantDictFindStr(args_in, TR_KEY_download_dir, &download_dir, NULL) && + tr_sys_path_is_relative(download_dir)) { - if (tr_sys_path_is_relative(download_dir)) - { - return "download directory path is not absolute"; - } + return "download directory path is not absolute"; } - if (tr_variantDictFindStr(args_in, TR_KEY_incomplete_dir, &incomplete_dir, NULL)) + if (tr_variantDictFindStr(args_in, TR_KEY_incomplete_dir, &incomplete_dir, NULL) && + tr_sys_path_is_relative(incomplete_dir)) { - if (tr_sys_path_is_relative(incomplete_dir)) - { - return "incomplete torrents directory path is not absolute"; - } + return "incomplete torrents directory path is not absolute"; } int64_t i; diff --git a/libtransmission/session-id.c b/libtransmission/session-id.c index 032febfd8..fdf8af9bb 100644 --- a/libtransmission/session-id.c +++ b/libtransmission/session-id.c @@ -184,17 +184,15 @@ bool tr_session_id_is_local(char const* session_id) } else { - if (!tr_sys_file_lock(lock_file, TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_NB, &error)) - { + if (!tr_sys_file_lock(lock_file, TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_NB, &error) && #ifndef _WIN32 - if (error->code == EWOULDBLOCK) + (error->code == EWOULDBLOCK)) #else - if (error->code == ERROR_LOCK_VIOLATION) + (error->code == ERROR_LOCK_VIOLATION)) #endif - { - ret = true; - tr_error_clear(&error); - } + { + ret = true; + tr_error_clear(&error); } tr_sys_file_close(lock_file, NULL); diff --git a/libtransmission/session.c b/libtransmission/session.c index 60c3dc140..0e083cf40 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -3042,12 +3042,9 @@ int tr_sessionCountQueueFreeSlots(tr_session* session, tr_direction dir) while ((tor = tr_torrentNext(session, tor)) != NULL) { - if (!tr_torrentIsStalled(tor)) + if (!tr_torrentIsStalled(tor) && (tr_torrentGetActivity(tor) == activity)) { - if (tr_torrentGetActivity(tor) == activity) - { - ++active_count; - } + ++active_count; } } diff --git a/libtransmission/torrent-ctor.c b/libtransmission/torrent-ctor.c index bb0f48170..979844f5d 100644 --- a/libtransmission/torrent-ctor.c +++ b/libtransmission/torrent-ctor.c @@ -151,12 +151,10 @@ int tr_ctorSetMetainfoFromFile(tr_ctor* ctor, char const* filename) { char const* name; - if (!tr_variantDictFindStr(info, TR_KEY_name_utf_8, &name, NULL)) + if (!tr_variantDictFindStr(info, TR_KEY_name_utf_8, &name, NULL) && + !tr_variantDictFindStr(info, TR_KEY_name, &name, NULL)) { - if (!tr_variantDictFindStr(info, TR_KEY_name, &name, NULL)) - { - name = NULL; - } + name = NULL; } if (tr_str_is_empty(name)) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 408404d30..d956531b3 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -109,12 +109,9 @@ tr_torrent* tr_torrentFindFromHash(tr_session* session, uint8_t const* torrentHa while ((tor = tr_torrentNext(session, tor)) != NULL) { - if (*tor->info.hash == *torrentHash) + if ((*tor->info.hash == *torrentHash) && (memcmp(tor->info.hash, torrentHash, SHA_DIGEST_LENGTH) == 0)) { - if (memcmp(tor->info.hash, torrentHash, SHA_DIGEST_LENGTH) == 0) - { - return tor; - } + return tor; } } @@ -157,24 +154,18 @@ bool tr_torrentIsPieceTransferAllowed(tr_torrent const* tor, tr_direction direct bool allowed = true; - if (tr_torrentUsesSpeedLimit(tor, direction)) + if (tr_torrentUsesSpeedLimit(tor, direction) && + tr_torrentGetSpeedLimit_Bps(tor, direction) <= 0) { - if (tr_torrentGetSpeedLimit_Bps(tor, direction) <= 0) - { - allowed = false; - } + allowed = false; } if (tr_torrentUsesSessionLimits(tor)) { - unsigned int limit; - - if (tr_sessionGetActiveSpeedLimit_Bps(tor->session, direction, &limit)) + unsigned int limit = 0; + if (tr_sessionGetActiveSpeedLimit_Bps(tor->session, direction, &limit) && (limit <= 0)) { - if (limit <= 0) - { - allowed = false; - } + allowed = false; } } @@ -209,23 +200,9 @@ static int peerIdTTL(tr_torrent const* tor) unsigned char const* tr_torrentGetPeerId(tr_torrent* tor) { - bool needs_new_peer_id = false; - - if (*tor->peer_id == '\0') - { - needs_new_peer_id = true; - } - - if (!needs_new_peer_id) - { - if (!tr_torrentIsPrivate(tor)) - { - if (peerIdTTL(tor) <= 0) - { - needs_new_peer_id = true; - } - } - } + bool const needs_new_peer_id = + (*tor->peer_id == '\0') || // doesn't have one + (!tr_torrentIsPrivate(tor) && (peerIdTTL(tor) <= 0)); // has one but it's expired if (needs_new_peer_id) { @@ -722,12 +699,9 @@ static tr_priority_t calculatePiecePriority(tr_torrent const* tor, tr_piece_inde /* when dealing with multimedia files, getting the first and last pieces can sometimes allow you to preview it a bit before it's fully downloaded... */ - if (file->priority >= TR_PRI_NORMAL) + if ((file->priority >= TR_PRI_NORMAL) && (file->firstPiece == piece || file->lastPiece == piece)) { - if (file->firstPiece == piece || file->lastPiece == piece) - { - priority = TR_PRI_HIGH; - } + priority = TR_PRI_HIGH; } } @@ -2774,12 +2748,10 @@ bool tr_torrentPieceNeedsCheck(tr_torrent const* tor, tr_piece_index_t p) for (tr_file_index_t i = f; i < inf->fileCount && pieceHasFile(p, &inf->files[i]); ++i) { - if (tr_cpFileIsComplete(&tor->completion, i)) + if (tr_cpFileIsComplete(&tor->completion, i) && + (tr_torrentGetFileMTime(tor, i) > inf->pieces[p].timeChecked)) { - if (tr_torrentGetFileMTime(tor, i) > inf->pieces[p].timeChecked) - { - return true; - } + return true; } } @@ -3485,12 +3457,11 @@ static void tr_torrentPieceCompleted(tr_torrent* tor, tr_piece_index_t pieceInde { tr_file const* file = &tor->info.files[i]; - if (file->firstPiece <= pieceIndex && pieceIndex <= file->lastPiece) + if ((file->firstPiece <= pieceIndex) && + (pieceIndex <= file->lastPiece) && + tr_cpFileIsComplete(&tor->completion, i)) { - if (tr_cpFileIsComplete(&tor->completion, i)) - { - tr_torrentFileCompleted(tor, i); - } + tr_torrentFileCompleted(tor, i); } } } @@ -3736,22 +3707,20 @@ void tr_torrentSetQueuePosition(tr_torrent* tor, int pos) while ((walk = tr_torrentNext(tor->session, walk)) != NULL) { - if (old_pos < pos) + if ((old_pos < pos) && + (old_pos <= walk->queuePosition) && + (walk->queuePosition <= pos)) { - if (old_pos <= walk->queuePosition && walk->queuePosition <= pos) - { - walk->queuePosition--; - walk->anyDate = now; - } + walk->queuePosition--; + walk->anyDate = now; } - if (old_pos > pos) + if ((old_pos > pos) && + (pos <= walk->queuePosition) && + (walk->queuePosition < old_pos)) { - if (pos <= walk->queuePosition && walk->queuePosition < old_pos) - { - walk->queuePosition++; - walk->anyDate = now; - } + walk->queuePosition++; + walk->anyDate = now; } if (back < walk->queuePosition) diff --git a/libtransmission/tr-dht.c b/libtransmission/tr-dht.c index 67938e2b9..95960a51b 100644 --- a/libtransmission/tr-dht.c +++ b/libtransmission/tr-dht.c @@ -583,12 +583,9 @@ bool tr_dhtAddNode(tr_session* ss, tr_address const* address, tr_port port, bool /* Since we don't want to abuse our bootstrap nodes, * we don't ping them if the DHT is in a good state. */ - if (bootstrap) + if (bootstrap && (tr_dhtStatus(ss, af, NULL) >= TR_DHT_FIREWALLED)) { - if (tr_dhtStatus(ss, af, NULL) >= TR_DHT_FIREWALLED) - { - return false; - } + return false; } if (address->type == TR_AF_INET) diff --git a/libtransmission/upnp.c b/libtransmission/upnp.c index c9e248a37..20b7e0bda 100644 --- a/libtransmission/upnp.c +++ b/libtransmission/upnp.c @@ -182,7 +182,7 @@ enum UPNP_IGD_INVALID = 3 }; -int tr_upnpPulse(tr_upnp* handle, int port, bool isEnabled, bool doPortCheck) +int tr_upnpPulse(tr_upnp* handle, tr_port port, bool isEnabled, bool doPortCheck) { int ret; @@ -212,22 +212,21 @@ int tr_upnpPulse(tr_upnp* handle, int port, bool isEnabled, bool doPortCheck) freeUPNPDevlist(devlist); } - if (handle->state == TR_UPNP_IDLE) + if ((handle->state == TR_UPNP_IDLE) && + (handle->isMapped) && + (!isEnabled || handle->port != port)) { - if (handle->isMapped && (!isEnabled || handle->port != port)) - { - handle->state = TR_UPNP_UNMAP; - } + handle->state = TR_UPNP_UNMAP; } - if (isEnabled && handle->isMapped && doPortCheck) + if (isEnabled && + handle->isMapped && + doPortCheck && + ((tr_upnpGetSpecificPortMappingEntry(handle, "TCP") != UPNPCOMMAND_SUCCESS) || + (tr_upnpGetSpecificPortMappingEntry(handle, "UDP") != UPNPCOMMAND_SUCCESS))) { - if (tr_upnpGetSpecificPortMappingEntry(handle, "TCP") != UPNPCOMMAND_SUCCESS || - tr_upnpGetSpecificPortMappingEntry(handle, "UDP") != UPNPCOMMAND_SUCCESS) - { - tr_logAddNamedInfo(getKey(), _("Port %d isn't forwarded"), handle->port); - handle->isMapped = false; - } + tr_logAddNamedInfo(getKey(), _("Port %d isn't forwarded"), handle->port); + handle->isMapped = false; } if (handle->state == TR_UPNP_UNMAP) @@ -243,18 +242,13 @@ int tr_upnpPulse(tr_upnp* handle, int port, bool isEnabled, bool doPortCheck) handle->port = -1; } - if (handle->state == TR_UPNP_IDLE) + if ((handle->state == TR_UPNP_IDLE) && isEnabled && !handle->isMapped) { - if (isEnabled && !handle->isMapped) - { - handle->state = TR_UPNP_MAP; - } + handle->state = TR_UPNP_MAP; } if (handle->state == TR_UPNP_MAP) { - int err_tcp = -1; - int err_udp = -1; errno = 0; if (handle->urls.controlURL == NULL) @@ -266,8 +260,8 @@ int tr_upnpPulse(tr_upnp* handle, int port, bool isEnabled, bool doPortCheck) char desc[64]; tr_snprintf(desc, sizeof(desc), "%s at %d", TR_NAME, port); - err_tcp = tr_upnpAddPortMapping(handle, "TCP", port, desc); - err_udp = tr_upnpAddPortMapping(handle, "UDP", port, desc); + int const err_tcp = tr_upnpAddPortMapping(handle, "TCP", port, desc); + int const err_udp = tr_upnpAddPortMapping(handle, "UDP", port, desc); handle->isMapped = err_tcp == 0 || err_udp == 0; } diff --git a/libtransmission/upnp.h b/libtransmission/upnp.h index f5dcf6a42..7fefe6afc 100644 --- a/libtransmission/upnp.h +++ b/libtransmission/upnp.h @@ -23,6 +23,6 @@ tr_upnp* tr_upnpInit(void); void tr_upnpClose(tr_upnp*); -int tr_upnpPulse(tr_upnp*, int port, bool isEnabled, bool doPortCheck); +int tr_upnpPulse(tr_upnp*, tr_port port, bool isEnabled, bool doPortCheck); /* @} */ diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 2362b0ca2..86381441f 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -1877,12 +1877,9 @@ void* tr_valloc(size_t bufLen) #ifdef HAVE_POSIX_MEMALIGN - if (buf == NULL) + if ((buf == NULL) && (posix_memalign(&buf, pageSize, allocLen) != 0)) { - if (posix_memalign(&buf, pageSize, allocLen) != 0) - { - buf = NULL; /* just retry with valloc/malloc */ - } + buf = NULL; /* just retry with valloc/malloc */ } #endif diff --git a/libtransmission/variant.c b/libtransmission/variant.c index 7e9de8ef0..58b0cd1f1 100644 --- a/libtransmission/variant.c +++ b/libtransmission/variant.c @@ -357,22 +357,20 @@ bool tr_variantGetBool(tr_variant const* v, bool* setme) success = true; } - if (!success && tr_variantIsInt(v)) + if ((!success) && + tr_variantIsInt(v) && + (v->val.i == 0 || v->val.i == 1)) { - if (v->val.i == 0 || v->val.i == 1) - { - *setme = v->val.i != 0; - success = true; - } + *setme = v->val.i != 0; + success = true; } - if (!success && tr_variantGetStr(v, &str, NULL)) + if ((!success) && + tr_variantGetStr(v, &str, NULL) && + (strcmp(str, "true") == 0 || strcmp(str, "false") == 0)) { - if (strcmp(str, "true") == 0 || strcmp(str, "false") == 0) - { - *setme = strcmp(str, "true") == 0; - success = true; - } + *setme = strcmp(str, "true") == 0; + success = true; } return success; diff --git a/libtransmission/watchdir.c b/libtransmission/watchdir.c index 7014b861d..ba7e77c7f 100644 --- a/libtransmission/watchdir.c +++ b/libtransmission/watchdir.c @@ -234,33 +234,14 @@ tr_watchdir_t tr_watchdir_new(char const* path, tr_watchdir_cb callback, void* c handle->event_base = event_base; tr_watchdir_retries_init(&handle->active_retries); - if (!force_generic) + if (!force_generic && (handle->backend == NULL)) { -#ifdef WITH_INOTIFY - - if (handle->backend == NULL) - { - handle->backend = tr_watchdir_inotify_new(handle); - } - -#endif - -#ifdef WITH_KQUEUE - - if (handle->backend == NULL) - { - handle->backend = tr_watchdir_kqueue_new(handle); - } - -#endif - -#ifdef _WIN32 - - if (handle->backend == NULL) - { - handle->backend = tr_watchdir_win32_new(handle); - } - +#if defined(WITH_INOTIFY) + handle->backend = tr_watchdir_inotify_new(handle); +#elif defined(WITH_KQUEUE) + handle->backend = tr_watchdir_kqueue_new(handle); +#elif defined(_WIN32) + handle->backend = tr_watchdir_win32_new(handle); #endif } diff --git a/macosx/TransmissionHelp/html/Index2.html b/macosx/TransmissionHelp/html/Index2.html index bbdf556f0..cbcee9ceb 100644 --- a/macosx/TransmissionHelp/html/Index2.html +++ b/macosx/TransmissionHelp/html/Index2.html @@ -11,8 +11,6 @@

- - -
- Index -
-
- - - +
- + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ Index

Firewall

-

 

-
+

Frequently Asked Questions

-

 

-
+

Getting Started

-

 

-
+

Managing your transfers

-

 

-
+

Manual torrent verification

-

 

-
+

Maximizing download speed

-

 

-
+

Network preferences

-

 

-
+

Peer preferences

-

 

-
+

Port Forwarding FAQ

-

 

-
+

Remote

-

 

-
+

Running Scripts

-

 

-
+

Router

-

 

-
+

Tracker information

-

 

-
+

Troubleshooting port issues

-

 

-
diff --git a/macosx/TransmissionHelp/html/gettingstarted.html b/macosx/TransmissionHelp/html/gettingstarted.html index fe10e1241..c2bced5b6 100644 --- a/macosx/TransmissionHelp/html/gettingstarted.html +++ b/macosx/TransmissionHelp/html/gettingstarted.html @@ -21,7 +21,7 @@
- Transmission Icon + Transmission Logo  
@@ -37,7 +37,7 @@ - + adding a torrent

Download your file's associated 'torrent file' (extension .torrent). These are commonly found at 'tracker' websites.

Once you have the torrent file, drag it into Transmission - downloading should start immediately. @@ -58,7 +58,7 @@ - + creating a torrent

Yes, you can share a file or folder by dragging it into Transmission. Alternatively, click 'Create' in the toolbar, and choose your file.

When the dialog box appears, enter your tracker address (or addresses), comments, and private status. @@ -75,7 +75,7 @@ - + scheduler

Yes, by using 'Speed Limit Mode'. Simply go to Preferences -> Bandwidth, and then set both the speed you would like Transmission to be limited to, as well as the period of time you would like the limits applied.

When Speed Limit Mode is enabled, the turtle will be illuminated in blue.

@@ -90,7 +90,7 @@ - + queue

Yes, you can queue seeding and/or downloading transfers via Preferences -> Transfers -> Management.

The queue system is very simple: You start and pause transfers as usual, but if you're over the queue limit starting a transfer will instead make it "Waiting to download..." @@ -107,7 +107,7 @@ - + groups

Transmission allows you to sort your torrents by various criteria. Choose "Sort Transfers By" in the View menu, as well as the Action menu.

You can also filter your torrents by their activity state. Simply enable the Filter bar in the View menu. @@ -125,7 +125,7 @@ - + inspector

Click the Inspector icon, or simply double-click any transfer in the main window.

The inspector gives you: @@ -147,7 +147,7 @@ - + file selection

Yes, either upon opening a torrent, or once it has started. When you open a multi-file torrent, a detailed Open window will appear, allowing you to select specific files.

For transfers which are already running, double click them to open the Inspector, and then click the 'Files' tab. Simply check the boxes next to the files you want to download (the default is all of them). diff --git a/macosx/TransmissionHelp/index.html b/macosx/TransmissionHelp/index.html index 74f5dd16e..a4635c4a4 100644 --- a/macosx/TransmissionHelp/index.html +++ b/macosx/TransmissionHelp/index.html @@ -1,4 +1,5 @@ - + + @@ -11,12 +12,12 @@

-
+
Image of Transmission window

Transmission icon Transmission Help

transmissionbt.com

-
+
@@ -40,4 +41,4 @@
- \ No newline at end of file + diff --git a/qt/AboutDialog.h b/qt/AboutDialog.h index 0a3d9815e..df19ef454 100644 --- a/qt/AboutDialog.h +++ b/qt/AboutDialog.h @@ -22,7 +22,7 @@ class AboutDialog : public BaseDialog TR_DISABLE_COPY_MOVE(AboutDialog) public: - AboutDialog(QWidget* parent = nullptr); + explicit AboutDialog(QWidget* parent = nullptr); private slots: void showCredits(); diff --git a/qt/AddData.h b/qt/AddData.h index 9f6084a14..5d437d206 100644 --- a/qt/AddData.h +++ b/qt/AddData.h @@ -27,7 +27,7 @@ public: public: AddData() = default; - AddData(QString const& str) + explicit AddData(QString const& str) { set(str); } diff --git a/qt/Application.cc b/qt/Application.cc index 37bc83bfd..17861e588 100644 --- a/qt/Application.cc +++ b/qt/Application.cc @@ -185,10 +185,9 @@ Application::Application(int& argc, char** argv) : for (QString const& filename : filenames) { + auto const a = AddData(filename); QString metainfo; - AddData a(filename); - switch (a.type) { case AddData::URL: @@ -290,7 +289,7 @@ Application::Application(int& argc, char** argv) : connect(session_, &Session::sourceChanged, this, &Application::onSessionSourceChanged); connect(session_, &Session::torrentsRemoved, model_, &TorrentModel::removeTorrents); connect(session_, &Session::torrentsUpdated, model_, &TorrentModel::updateTorrents); - connect(watch_dir_, &WatchDir::torrentFileAdded, this, &Application::addTorrent); + connect(watch_dir_, &WatchDir::torrentFileAdded, this, qOverload(&Application::addTorrent)); // init from preferences for (auto const key : { Prefs::DIR_WATCH }) @@ -550,6 +549,11 @@ void Application::refreshTorrents() **** ***/ +void Application::addTorrent(QString const& addme) +{ + addTorrent(AddData(addme)); +} + void Application::addTorrent(AddData const& addme) { if (addme.type == addme.NONE) diff --git a/qt/Application.h b/qt/Application.h index 55b20d890..6fc3ac1ce 100644 --- a/qt/Application.h +++ b/qt/Application.h @@ -44,6 +44,7 @@ public: public slots: void addTorrent(AddData const&); + void addTorrent(QString const&); private slots: void consentGiven(int result); diff --git a/qt/ColumnResizer.h b/qt/ColumnResizer.h index 320f74821..1f656ddc7 100644 --- a/qt/ColumnResizer.h +++ b/qt/ColumnResizer.h @@ -22,7 +22,7 @@ class ColumnResizer : public QObject TR_DISABLE_COPY_MOVE(ColumnResizer) public: - ColumnResizer(QObject* parent = nullptr); + explicit ColumnResizer(QObject* parent = nullptr); void addLayout(QGridLayout* layout); diff --git a/qt/FileTreeDelegate.h b/qt/FileTreeDelegate.h index 4dc1af4f6..8d4ac79b7 100644 --- a/qt/FileTreeDelegate.h +++ b/qt/FileTreeDelegate.h @@ -18,7 +18,7 @@ class FileTreeDelegate : public QItemDelegate TR_DISABLE_COPY_MOVE(FileTreeDelegate) public: - FileTreeDelegate(QObject* parent = nullptr) : + explicit FileTreeDelegate(QObject* parent = nullptr) : QItemDelegate(parent) { } diff --git a/qt/FileTreeView.cc b/qt/FileTreeView.cc index 35b03cdc4..f78faaa2c 100644 --- a/qt/FileTreeView.cc +++ b/qt/FileTreeView.cc @@ -129,26 +129,23 @@ void FileTreeView::resizeEvent(QResizeEvent* event) void FileTreeView::keyPressEvent(QKeyEvent* event) { - if (state() != EditingState) + if ((state() != EditingState) && (event->key() == Qt::Key_Space)) { - if (event->key() == Qt::Key_Space) + // handle using the keyboard to toggle the + // wanted/unwanted state or the file priority + + Qt::KeyboardModifiers const modifiers = event->modifiers(); + + if (modifiers == Qt::NoModifier) { - // handle using the keyboard to toggle the - // wanted/unwanted state or the file priority + model_->twiddleWanted(selectedSourceRows()); + return; + } - Qt::KeyboardModifiers const modifiers = event->modifiers(); - - if (modifiers == Qt::NoModifier) - { - model_->twiddleWanted(selectedSourceRows()); - return; - } - - if (modifiers == Qt::ShiftModifier) - { - model_->twiddlePriority(selectedSourceRows()); - return; - } + if (modifiers == Qt::ShiftModifier) + { + model_->twiddlePriority(selectedSourceRows()); + return; } } diff --git a/qt/FilterBar.cc b/qt/FilterBar.cc index eb4f3532c..066e3bf74 100644 --- a/qt/FilterBar.cc +++ b/qt/FilterBar.cc @@ -343,7 +343,7 @@ void FilterBar::onActivityIndexChanged(int i) { if (!is_bootstrapping_) { - FilterMode const mode = activity_combo_->itemData(i, ACTIVITY_ROLE).toInt(); + auto const mode = FilterMode(activity_combo_->itemData(i, ACTIVITY_ROLE).toInt()); prefs_.set(Prefs::FILTER_MODE, mode); } } diff --git a/qt/FilterBarComboBox.h b/qt/FilterBarComboBox.h index 109853d27..52bf30516 100644 --- a/qt/FilterBarComboBox.h +++ b/qt/FilterBarComboBox.h @@ -26,7 +26,7 @@ public: }; public: - FilterBarComboBox(QWidget* parent = nullptr); + explicit FilterBarComboBox(QWidget* parent = nullptr); // QWidget QSize minimumSizeHint() const override; diff --git a/qt/Filters.h b/qt/Filters.h index 3c3b0b102..5af2a41c5 100644 --- a/qt/Filters.h +++ b/qt/Filters.h @@ -29,7 +29,7 @@ public: }; public: - FilterMode(int mode = SHOW_ALL) : + explicit FilterMode(int mode = SHOW_ALL) : mode_(mode) { } @@ -77,7 +77,7 @@ public: }; public: - SortMode(int mode = SORT_BY_ID) : + explicit SortMode(int mode = SORT_BY_ID) : mode_(mode) { } diff --git a/qt/IconToolButton.h b/qt/IconToolButton.h index 70e985ca3..d55f9380a 100644 --- a/qt/IconToolButton.h +++ b/qt/IconToolButton.h @@ -18,7 +18,7 @@ class IconToolButton : public QToolButton TR_DISABLE_COPY_MOVE(IconToolButton) public: - IconToolButton(QWidget* parent = nullptr); + explicit IconToolButton(QWidget* parent = nullptr); // QWidget QSize sizeHint() const override; diff --git a/qt/InteropObject.h b/qt/InteropObject.h index 141fb8fd2..8b2872fa9 100644 --- a/qt/InteropObject.h +++ b/qt/InteropObject.h @@ -30,7 +30,7 @@ class InteropObject : public QObject #endif public: - InteropObject(QObject* parent = nullptr); + explicit InteropObject(QObject* parent = nullptr); public slots: bool PresentWindow(); diff --git a/qt/LicenseDialog.h b/qt/LicenseDialog.h index b9c4434df..5686e7dba 100644 --- a/qt/LicenseDialog.h +++ b/qt/LicenseDialog.h @@ -18,7 +18,7 @@ class LicenseDialog : public BaseDialog TR_DISABLE_COPY_MOVE(LicenseDialog) public: - LicenseDialog(QWidget* parent = nullptr); + explicit LicenseDialog(QWidget* parent = nullptr); private: Ui::LicenseDialog ui_ = {}; diff --git a/qt/MainWindow.cc b/qt/MainWindow.cc index df646d350..4c39d09d6 100644 --- a/qt/MainWindow.cc +++ b/qt/MainWindow.cc @@ -1295,7 +1295,7 @@ void MainWindow::openURL() str.clear(); } - addTorrent(str, true); + addTorrent(AddData(str), true); } void MainWindow::addTorrents(QStringList const& filenames) @@ -1316,7 +1316,7 @@ void MainWindow::addTorrents(QStringList const& filenames) for (QString const& filename : filenames) { - addTorrent(filename, show_options); + addTorrent(AddData(filename), show_options); } } @@ -1589,7 +1589,7 @@ void MainWindow::dropEvent(QDropEvent* event) key = url.toLocalFile(); } - qApp->addTorrent(key); + qApp->addTorrent(AddData(key)); } } } diff --git a/qt/PathButton.h b/qt/PathButton.h index 42b80ab7f..5a2ade317 100644 --- a/qt/PathButton.h +++ b/qt/PathButton.h @@ -25,7 +25,7 @@ public: }; public: - PathButton(QWidget* parent = nullptr); + explicit PathButton(QWidget* parent = nullptr); void setMode(Mode mode); void setTitle(QString const& title); diff --git a/qt/Prefs.h b/qt/Prefs.h index 6e6450eac..755c4c8bf 100644 --- a/qt/Prefs.h +++ b/qt/Prefs.h @@ -133,7 +133,7 @@ public: }; public: - Prefs(QString config_dir); + explicit Prefs(QString config_dir); ~Prefs() override; bool isCore(int key) const diff --git a/qt/PrefsDialog.cc b/qt/PrefsDialog.cc index ea7e9b082..a457cd746 100644 --- a/qt/PrefsDialog.cc +++ b/qt/PrefsDialog.cc @@ -209,35 +209,35 @@ void PrefsDialog::linkWidgetToPref(QWidget* widget, int pref_key) updateWidgetValue(widget, pref_key); widgets_.insert(pref_key, widget); - auto* check_box = qobject_cast(widget); + auto const* check_box = qobject_cast(widget); if (check_box != nullptr) { connect(check_box, &QAbstractButton::toggled, this, &PrefsDialog::checkBoxToggled); return; } - auto* time_edit = qobject_cast(widget); + auto const* time_edit = qobject_cast(widget); if (time_edit != nullptr) { connect(time_edit, &QAbstractSpinBox::editingFinished, this, &PrefsDialog::timeEditingFinished); return; } - auto* line_edit = qobject_cast(widget); + auto const* line_edit = qobject_cast(widget); if (line_edit != nullptr) { connect(line_edit, &QLineEdit::editingFinished, this, &PrefsDialog::lineEditingFinished); return; } - auto* path_button = qobject_cast(widget); + auto const* path_button = qobject_cast(widget); if (path_button != nullptr) { connect(path_button, &PathButton::pathChanged, this, &PrefsDialog::pathChanged); return; } - auto* spin_box = qobject_cast(widget); + auto const* spin_box = qobject_cast(widget); if (spin_box != nullptr) { connect(spin_box, &QAbstractSpinBox::editingFinished, this, &PrefsDialog::spinBoxEditingFinished); @@ -762,14 +762,11 @@ void PrefsDialog::refreshPref(int key) { QWidget* w(it.value()); - if (!updateWidgetValue(w, key)) + if (!updateWidgetValue(w, key) && (key == Prefs::ENCRYPTION)) { - if (key == Prefs::ENCRYPTION) - { - auto* combo_box = qobject_cast(w); - int const index = combo_box->findData(prefs_.getInt(key)); - combo_box->setCurrentIndex(index); - } + auto* combo_box = qobject_cast(w); + int const index = combo_box->findData(prefs_.getInt(key)); + combo_box->setCurrentIndex(index); } } } diff --git a/qt/RpcClient.h b/qt/RpcClient.h index 57ce98ca4..f6f51ef34 100644 --- a/qt/RpcClient.h +++ b/qt/RpcClient.h @@ -58,7 +58,7 @@ class RpcClient : public QObject TR_DISABLE_COPY_MOVE(RpcClient) public: - RpcClient(QObject* parent = nullptr); + explicit RpcClient(QObject* parent = nullptr); void stop(); void start(tr_session* session); diff --git a/qt/SqueezeLabel.h b/qt/SqueezeLabel.h index ba6fed41c..0113cfe5b 100644 --- a/qt/SqueezeLabel.h +++ b/qt/SqueezeLabel.h @@ -51,8 +51,8 @@ class SqueezeLabel : public QLabel TR_DISABLE_COPY_MOVE(SqueezeLabel) public: - SqueezeLabel(QWidget* parent = nullptr); - SqueezeLabel(QString const& text, QWidget* parent = nullptr); + explicit SqueezeLabel(QWidget* parent = nullptr); + explicit SqueezeLabel(QString const& text, QWidget* parent = nullptr); protected: // QWidget diff --git a/qt/Torrent.h b/qt/Torrent.h index ec0b75b2f..f0587a742 100644 --- a/qt/Torrent.h +++ b/qt/Torrent.h @@ -112,12 +112,12 @@ private: public: TorrentHash() {} - TorrentHash(char const* str) + explicit TorrentHash(char const* str) { tr_hex_to_sha1(data_.data(), str); } - TorrentHash(QString const& str) + explicit TorrentHash(QString const& str) { tr_hex_to_sha1(data_.data(), str.toUtf8().constData()); } diff --git a/qt/TorrentView.h b/qt/TorrentView.h index 68666892b..59e20d1cc 100644 --- a/qt/TorrentView.h +++ b/qt/TorrentView.h @@ -18,7 +18,7 @@ class TorrentView : public QListView TR_DISABLE_COPY_MOVE(TorrentView) public: - TorrentView(QWidget* parent = nullptr); + explicit TorrentView(QWidget* parent = nullptr); public slots: void setHeaderText(QString const& text); diff --git a/qt/TrackerDelegate.h b/qt/TrackerDelegate.h index 63d5ad727..a3404b949 100644 --- a/qt/TrackerDelegate.h +++ b/qt/TrackerDelegate.h @@ -23,7 +23,7 @@ class TrackerDelegate : public QItemDelegate TR_DISABLE_COPY_MOVE(TrackerDelegate) public: - TrackerDelegate(QObject* parent = nullptr) : + explicit TrackerDelegate(QObject* parent = nullptr) : QItemDelegate(parent) { } diff --git a/qt/WatchDir.h b/qt/WatchDir.h index 9178556da..03b650219 100644 --- a/qt/WatchDir.h +++ b/qt/WatchDir.h @@ -25,7 +25,7 @@ class WatchDir : public QObject TR_DISABLE_COPY_MOVE(WatchDir) public: - WatchDir(TorrentModel const&); + explicit WatchDir(TorrentModel const&); void setPath(QString const& path, bool is_enabled); diff --git a/utils/edit.c b/utils/edit.c index 161db9f96..75994494c 100644 --- a/utils/edit.c +++ b/utils/edit.c @@ -146,18 +146,14 @@ static bool removeURL(tr_variant* metainfo, char const* url) * use it as the "announce" field */ if (changed && !tr_variantDictFindStr(metainfo, TR_KEY_announce, &str, NULL)) { - tr_variant* tier; - tr_variant* node; - - if ((tier = tr_variantListChild(announce_list, 0)) != NULL) + tr_variant* const tier = tr_variantListChild(announce_list, 0); + if (tier != NULL) { - if ((node = tr_variantListChild(tier, 0)) != NULL) + tr_variant const* const node = tr_variantListChild(tier, 0); + if ((node != NULL) && tr_variantGetStr(node, &str, NULL)) { - if (tr_variantGetStr(node, &str, NULL)) - { - tr_variantDictAddStr(metainfo, TR_KEY_announce, str); - printf("\tAdded \"%s\" to announce\n", str); - } + tr_variantDictAddStr(metainfo, TR_KEY_announce, str); + printf("\tAdded \"%s\" to announce\n", str); } } } diff --git a/utils/remote.c b/utils/remote.c index 0f11edbfa..a6fe58e0f 100644 --- a/utils/remote.c +++ b/utils/remote.c @@ -2339,7 +2339,6 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) case 'V': /* show version number */ fprintf(stderr, "%s %s\n", MY_NAME, LONG_VERSION_STRING); exit(0); - break; case TR_OPT_ERR: fprintf(stderr, "invalid option\n");