Files
transmission/qt/Torrent.cc
Yat Ho 05aef3e787 refactor: unify quarks and strings to snake_case (#7108)
* refactor: change `leftUntilDone` to `left_until_done`

* refactor: change `magnetLink` to `magnet_link`

* refactor: change `manualAnnounceTime` to `manual_announce_time`

* refactor: change `maxConnectedPeers` to `max_connected_peers`

* refactor: change `metadataPercentComplete` to `metadata_percent_complete`

* refactor: change `peersConnected` to `peers_connected`

* refactor: change `peersFrom` to `peers_from`

* refactor: change `peersGettingFromUs` to `peers_getting_from_us`

* refactor: change `peersSendingToUs` to `peers_sending_to_us`

* refactor: change `percentComplete` to `percent_complete`

* refactor: change `percentDone` to `percent_done`

* refactor: change `pieceCount` to `piece_count`

* refactor: use quark when possible

* refactor: change `pieceSize` to `piece_size`

* refactor: change `primary-mime-type` to `primary_mime_type`

* refactor: change `rateDownload` to `rate_download`

* refactor: change `rateUpload` to `rate_upload`

* refactor: change `recheckProgress` to `recheck_progress`

* refactor: change `secondsDownloading` to `seconds_downloading`

* refactor: change `secondsSeeding` to `seconds_seeding`

* refactor: change `sizeWhenDone` to `size_when_done`

* refactor: change `startDate` to `start_date`

* refactor: change `trackerStats` to `tracker_stats`

* refactor: change `totalSize` to `total_size`

* refactor: change `torrentFile` to `torrent_file`

* refactor: change `uploadedEver` to `uploaded_ever`

* refactor: change `uploadRatio` to `upload_ratio`

* refactor: change `webseedsSendingToUs` to `webseeds_sending_to_us`

* refactor: change `bytesCompleted` to `bytes_completed`

* refactor: change `clientName` to `client_name`

* refactor: change `clientIsChoked` to `client_is_choked`

* refactor: change `clientIsInterested` to `client_is_interested`

* refactor: change `flagStr` to `flag_str`

* refactor: change `isDownloadingFrom` to `is_downloading_from`

* refactor: change `isEncrypted` to `is_encrypted`

* refactor: change `isIncoming` to `is_incoming`

* refactor: change `isUploadingTo` to `is_uploading_to`

* refactor: change `isUTP` to `is_utp`

* refactor: change `peerIsChoked` to `peer_is_choked`

* refactor: change `peerIsInterested` to `peer_is_interested`

* refactor: change `rateToClient` to `rate_to_client`

* refactor: change `rateToPeer` to `rate_to_peer`

* refactor: change `fromCache` to `from_cache`

* refactor: change `fromDht` to `from_dht`

* refactor: change `fromIncoming` to `from_incoming`

* refactor: change `fromLpd` to `from_lpd`

* refactor: change `fromLtep` to `from_ltep`

* refactor: change `fromPex` to `from_pex`

* refactor: change `fromTracker` to `from_tracker`

* refactor: change `announceState` to `announce_state`

* refactor: change `downloadCount` to `download_count`

* refactor: change `hasAnnounced` to `has_announced`

* refactor: change `hasScraped` to `has_scraped`

* refactor: change `isBackup` to `is_backup`

* refactor: change `lastAnnouncePeerCount` to `last_announce_peer_count`

* refactor: change `lastAnnounceResult` to `last_announce_result`

* refactor: change `lastAnnounceStartTime` to `last_announce_start_time`

* refactor: change `lastAnnounceSucceeded` to `last_announce_succeeded`

* refactor: change `lastAnnounceTime` to `last_announce_time`

* refactor: change `lastAnnounceTimedOut` to `last_announce_timed_out`

* refactor: change `lastScrapeResult` to `last_scrape_result`

* refactor: change `lastScrapeStartTime` to `last_scrape_start_time`

* refactor: change `lastScrapeSucceeded` to `last_scrape_succeeded`

* refactor: change `lastScrapeTime` to `last_scrape_time`

* refactor: change `lastScrapeTimedOut` to `last_scrape_timed_out`

* refactor: change `leecherCount` to `leecher_count`

* refactor: change `nextAnnounceTime` to `next_announce_time`

* refactor: change `nextScrapeTime` to `next_scrape_time`

* refactor: change `scrapeState` to `scrape_state`

* refactor: change `seederCount` to `seeder_count`

* refactor: change `torrent-added` to `torrent_added`

* refactor: change `torrent-duplicate` to `torrent_duplicate`

* refactor: change `torrent-remove` to `torrent_remove`

* refactor: change `delete-local-data` to `delete_local_data`

* refactor: change `torrent-rename-path` to `torrent_rename_path`

* refactor: change `alt-speed-down` to `alt_speed_down`

* refactor: convert `pref_toggle_entries` to quark array

* refactor: change `alt-speed-enabled` to `alt_speed_enabled`

* refactor: change `compact-view` to `compact_view`

* refactor: change `sort-reversed` to `sort_reversed`

* refactor: change `show-filterbar` to `show_filterbar`

* refactor: change `show-statusbar` to `show_statusbar`

* refactor: change `show-toolbar` to `show_toolbar`

* refactor: change `alt-speed-time-begin` to `alt_speed_time_begin`

* refactor: change `alt-speed-time-day` to `alt_speed_time_day`

* refactor: change `alt-speed-time-end` to `alt_speed_time_end`

* refactor: change `alt-speed-up` to `alt_speed_up`

* refactor: change `alt-speed-time-enabled` to `alt_speed_time_enabled`

* refactor: change `blocklist-enabled` to `blocklist_enabled`

* refactor: change `blocklist-size` to `blocklist_size`

* refactor: change `blocklist-url` to `blocklist_url`

* refactor: change `cache-size-mb` to `cache_size_mb`

* refactor: change `config-dir` to `config_dir`

* refactor: change `default-trackers` to `default_trackers`

* refactor: change `dht-enabled` to `dht_enabled`

* refactor: change `download-dir-free-space` to `download_dir_free_space`

* refactor: change `download-queue-enabled` to `download_queue_enabled`

* refactor: change `download-queue-size` to `download_queue_size`

* refactor: change `idle-seeding-limit-enabled` to `idle_seeding_limit_enabled`

* refactor: change `idle-seeding-limit` to `idle_seeding_limit`

* refactor: change `incomplete-dir-enabled` to `incomplete_dir_enabled`

* refactor: change `incomplete-dir` to `incomplete_dir`

* refactor: change `lpd-enabled` to `lpd_enabled`

* refactor: change `peer-limit-global` to `peer_limit_global`

* refactor: change `peer-limit-per-torrent` to `peer_limit_per_torrent`

* refactor: change `peer-port-random-on-start` to `peer_port_random_on_start`

* refactor: change `peer-port` to `peer_port`

* refactor: change `pex-enabled` to `pex_enabled`

* refactor: change `port-forwarding-enabled` to `port_forwarding_enabled`

* refactor: change `queue-stalled-enabled` to `queue_stalled_enabled`

* refactor: change `queue-stalled-minutes` to `queue_stalled_minutes`

* refactor: change `rename-partial-files` to `rename_partial_files`

* refactor: change `rpc-version-minimum` to `rpc_version_minimum`

* refactor: change `rpc-version-semver` to `rpc_version_semver`

* refactor: change `rpc-version` to `rpc_version`

* refactor: change `script-torrent-added-enabled` to `script_torrent_added_enabled`

* refactor: change `script-torrent-added-filename` to `script_torrent_added_filename`

* refactor: change `script-torrent-done-enabled` to `script_torrent_done_enabled`

* refactor: change `script-torrent-done-filename` to `script_torrent_done_filename`

* refactor: change `script-torrent-done-seeding-enabled` to `script_torrent_done_seeding_enabled`

* refactor: change `script-torrent-done-seeding-filename` to `script_torrent_done_seeding_filename`

* refactor: change `seed-queue-enabled` to `seed_queue_enabled`

* refactor: change `seed-queue-size` to `seed_queue_size`

* refactor: change `seedRatioLimited` to `seed_ratio_limited`

* refactor: change `session-id` to `session_id`

* refactor: change `speed-limit-down-enabled` to `speed_limit_down_enabled`

* refactor: change `speed-limit-down` to `speed_limit_down`

* refactor: change `speed-limit-up-enabled` to `speed_limit_up_enabled`

* refactor: change `speed-limit-up` to `speed_limit_up`

* refactor: change `start-added-torrents` to `start_added_torrents`

* refactor: change `trash-original-torrent-files` to `trash_original_torrent_files`

* refactor: change `utp-enabled` to `utp_enabled`

* refactor: change `tcp-enabled` to `tcp_enabled`

* docs: add missing docs for RPC `tcp_enabled`

* refactor: change `speed-units` to `speed_units`

* refactor: change `speed-bytes` to `speed_bytes`

* refactor: change `size-units` to `size_units`

* refactor: change `size-bytes` to `size_bytes`

* refactor: change `memory-units` to `memory_units`

* refactor: change `memory-bytes` to `memory_bytes`

* refactor: change `session-set` to `session_set`

* refactor: change `session-get` to `session_get`

* refactor: change `session-stats` to `session_stats`

* refactor: change `activeTorrentCount` to `active_torrent_count`

* refactor: change `downloadSpeed` to `download_speed`

* refactor: change `pausedTorrentCount` to `paused_torrent_count`

* refactor: change `torrentCount` to `torrent_count`

* refactor: change `uploadSpeed` to `upload_speed`

* refactor: change `cumulative-stats` to `cumulative_stats`

* refactor: change `current-stats` to `current_stats`

* refactor: change `uploadedBytes` and `uploaded-bytes` to `uploaded_bytes`

* refactor: change `downloadedBytes` and `downloaded-bytes` to `downloaded_bytes`

* refactor: change `filesAdded` and `files-added` to `files_added`

* refactor: change `sessionCount` and `session-count` to `session_count`

* refactor: change `secondsActive` and `seconds-active` to `seconds_active`

* refactor: change `blocklist-update` to `blocklist_update`

* refactor: change `port-test` to `port_test`

* refactor: change `session-close` to `session_close`

* refactor: change `queue-move-top` to `queue_move_top`

* refactor: change `queue-move-up` to `queue_move_up`

* refactor: change `queue-move-down` to `queue_move_down`

* refactor: change `queue-move-bottom` to `queue_move_bottom`

* refactor: change `free-space` to `free_space`

* refactor: change `group-set` to `group_set`

* refactor: change `group-get` to `group_get`

* refactor: change `announce-ip` to `announce_ip`

* refactor: change `announce-ip-enabled` to `announce_ip_enabled`

* refactor: change `upload-slots-per-torrent` to `upload_slots_per_torrent`

* refactor: change `trash-can-enabled` to `trash_can_enabled`

* refactor: change `watch-dir-enabled` to `watch_dir_enabled`

* refactor: change `watch-dir-force-generic` to `watch_dir_force_generic`

* refactor: change `watch-dir` to `watch_dir`

* refactor: change `message-level` to `message_level`

* refactor: change `scrape-paused-torrents-enabled` to `scrape_paused_torrents_enabled`

* refactor: change `torrent-added-verify-mode` to `torrent_added_verify_mode`

* refactor: change `sleep-per-seconds-during-verify` to `sleep_per_seconds_during_verify`

* refactor: change `bind-address-ipv4` to `bind_address_ipv4`

* refactor: change `bind-address-ipv6` to `bind_address_ipv6`

* refactor: change `peer-congestion-algorithm` to `peer_congestion_algorithm`

* refactor: change `peer-socket-tos` to `peer_socket_tos`

* refactor: change `peer-port-random-high` to `peer_port_random_high`

* refactor: change `peer-port-random-low` to `peer_port_random_low`

* refactor: change `anti-brute-force-enabled` to `anti_brute_force_enabled`

* refactor: change `rpc-authentication-required` to `rpc_authentication_required`

* refactor: change `rpc-bind-address` to `rpc_bind_address`

* refactor: change `rpc-enabled` to `rpc_enabled`

* refactor: change `rpc-host-whitelist` to `rpc_host_whitelist`

* refactor: change `rpc-host-whitelist-enabled` to `rpc_host_whitelist_enabled`

* refactor: change `rpc-password` to `rpc_password`

* refactor: change `rpc-port` to `rpc_port`

* refactor: change `rpc-socket-mode` to `rpc_socket_mode`

* refactor: change `rpc-url` to `rpc_url`

* refactor: change `rpc-username` to `rpc_username`

* refactor: change `rpc-whitelist` to `rpc_whitelist`

* refactor: change `rpc-whitelist-enabled` to `rpc_whitelist_enabled`

* refactor: change `ratio-limit-enabled` to `ratio_limit_enabled`

* refactor: change `ratio-limit` to `ratio_limit`

* refactor: change `show-options-window` to `show_options_window`

* refactor: change `open-dialog-dir` to `open_dialog_dir`

* refactor: change `inhibit-desktop-hibernation` to `inhibit_desktop_hibernation`

* refactor: change `show-notification-area-icon` to `show_notification_area_icon`

* refactor: change `start-minimized` to `start_minimized`

* refactor: change `torrent-added-notification-enabled` to `torrent_added_notification_enabled`

* refactor: change `anti-brute-force-threshold` to `anti_brute_force_threshold`

* refactor: change `torrent-complete-notification-enabled` to `torrent_complete_notification_enabled`

* refactor: change `prompt-before-exit` to `prompt_before_exit`

* refactor: change `sort-mode` to `sort_mode`

* refactor: change `statusbar-stats` to `statusbar_stats`

* refactor: change `show-extra-peer-details` to `show_extra_peer_details`

* refactor: change `show-backup-trackers` to `show_backup_trackers`

* refactor: change `blocklist-date` to `blocklist_date`

* refactor: change `blocklist-updates-enabled` to `blocklist_updates_enabled`

* refactor: change `main-window-layout-order` to `main_window_layout_order`

* refactor: change `main-window-height` to `main_window_height`

* refactor: change `main-window-width` to `main_window_width`

* refactor: change `main-window-x` to `main_window_x`

* refactor: change `main-window-y` to `main_window_y`

* refactor: change `filter-mode` to `filter_mode`

* refactor: change `filter-trackers` to `filter_trackers`

* refactor: change `filter-text` to `filter_text`

* refactor: change `remote-session-enabled` to `remote_session_enabled`

* refactor: change `remote-session-host` to `remote_session_host`

* refactor: change `remote-session-https` to `remote_session_https`

* refactor: change `remote-session-password` to `remote_session_password`

* refactor: change `remote-session-port` to `remote_session_port`

* refactor: change `remote-session-requres-authentication` to `remote_session_requires_authentication`

* refactor: change `remote-session-username` to `remote_session_username`

* refactor: change `torrent-complete-sound-command` to `torrent_complete_sound_command`

* refactor: change `torrent-complete-sound-enabled` to `torrent_complete_sound_enabled`

* refactor: change `user-has-given-informed-consent` to `user_has_given_informed_consent`

* refactor: change `read-clipboard` to `read_clipboard`

* refactor: change `details-window-height` to `details_window_height`

* refactor: change `details-window-width` to `details_window_width`

* refactor: change `main-window-is-maximized` to `main_window_is_maximized`

* refactor: change `port-is-open` to `port_is_open`

* refactor: change `show-tracker-scrapes` to `show_tracker_scrapes`

* refactor: change `max-peers` to `max_peers`

* refactor: change `peers2-6` to `peers2_6`

* refactor: change `seeding-time-seconds` to `seeding_time_seconds`

* refactor: change `downloading-time-seconds` to `downloading_time_seconds`

* refactor: change `ratio-mode` to `ratio_mode`

* refactor: change `idle-limit` to `idle_limit`

* refactor: change `idle-mode` to `idle_mode`

* refactor: change `speed-Bps` to `speed_Bps`

* refactor: change `use-global-speed-limit` to `use_global_speed_limit`

* refactor: change `use-speed-limit` to `use_speed_limit`

* chore: remove TODO comment

* docs: add upgrade instructions to `5.0.0`

* chore: bump rpc semver major version

* chore: housekeeping
2025-12-01 16:08:18 -06:00

397 lines
13 KiB
C++

// This file Copyright © Mnemosyne LLC.
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#include <algorithm>
#include <set>
#include <QApplication>
#include <QString>
#include <QUrl>
#include <libtransmission/transmission.h>
#include <libtransmission/quark.h>
#include <libtransmission/variant.h>
#include "Application.h"
#include "IconCache.h"
#include "Prefs.h"
#include "Torrent.h"
#include "Utils.h"
#include "VariantHelpers.h"
using ::trqt::variant_helpers::change;
Torrent::Torrent(Prefs const& prefs, int id)
: id_{ id }
, prefs_{ prefs }
{
}
/***
****
***/
std::optional<double> Torrent::getSeedRatioLimit() const
{
auto const mode = seedRatioMode();
if (mode == TR_RATIOLIMIT_SINGLE)
{
return seedRatioLimit();
}
if (mode == TR_RATIOLIMIT_GLOBAL && prefs_.getBool(Prefs::RATIO_ENABLED))
{
return prefs_.getDouble(Prefs::RATIO);
}
return {};
}
bool Torrent::includesTracker(QString const& sitename) const
{
return std::binary_search(std::begin(sitenames_), std::end(sitenames_), sitename);
}
int Torrent::compareSeedProgress(Torrent const& that) const
{
auto const a_ratio_limit = getSeedRatioLimit();
auto const b_ratio_limit = that.getSeedRatioLimit();
if (!a_ratio_limit && !b_ratio_limit)
{
return compareRatio(that);
}
auto const a_ratio = ratio();
auto const b_ratio = that.ratio();
if (!a_ratio_limit)
{
return b_ratio < *b_ratio_limit ? 1 : -1;
}
if (!b_ratio_limit)
{
return a_ratio < *a_ratio_limit ? -1 : 1;
}
if (!(*a_ratio_limit > 0) && !(*b_ratio_limit > 0))
{
return compareRatio(that);
}
if (!(*a_ratio_limit > 0))
{
return 1;
}
if (!(*b_ratio_limit > 0))
{
return -1;
}
double const a_progress = a_ratio / *a_ratio_limit;
double const b_progress = b_ratio / *b_ratio_limit;
return tr_compare_3way(a_progress, b_progress);
}
int Torrent::compareRatio(Torrent const& that) const
{
double const a = ratio();
double const b = that.ratio();
if (static_cast<int>(a) == TR_RATIO_INF && static_cast<int>(b) == TR_RATIO_INF)
{
return 0;
}
if (static_cast<int>(a) == TR_RATIO_INF)
{
return 1;
}
if (static_cast<int>(b) == TR_RATIO_INF)
{
return -1;
}
return tr_compare_3way(a, b);
}
int Torrent::compareETA(Torrent const& that) const
{
bool const have_a(hasETA());
bool const have_b(that.hasETA());
if (have_a && have_b)
{
return getETA() - that.getETA();
}
if (have_a)
{
return 1;
}
if (have_b)
{
return -1;
}
return 0;
}
/***
****
***/
QIcon Torrent::getMimeTypeIcon() const
{
if (icon_.isNull())
{
icon_ = IconCache::get().getMimeTypeIcon(primary_mime_type_, file_count_ > 1);
}
return icon_;
}
/***
****
***/
Torrent::fields_t Torrent::update(tr_quark const* keys, tr_variant const* const* values, size_t n)
{
auto changed = fields_t{};
for (size_t pos = 0; pos < n; ++pos)
{
tr_quark const key = keys[pos];
tr_variant const* child = values[pos];
bool field_changed = false;
switch (key)
{
#define HANDLE_KEY(key, field, bit) \
case TR_KEY_##key: \
field_changed = change(field##_, child); \
changed.set(bit, field_changed); \
break;
HANDLE_KEY(activity_date, activity_date, ACTIVITY_DATE)
HANDLE_KEY(activity_date_camel, activity_date, ACTIVITY_DATE)
HANDLE_KEY(added_date, added_date, ADDED_DATE)
HANDLE_KEY(added_date_camel, added_date, ADDED_DATE)
HANDLE_KEY(bandwidth_priority, bandwidth_priority, BANDWIDTH_PRIORITY)
HANDLE_KEY(bandwidth_priority_camel, bandwidth_priority, BANDWIDTH_PRIORITY)
HANDLE_KEY(corrupt_ever, failed_ever, FAILED_EVER)
HANDLE_KEY(corrupt_ever_camel, failed_ever, FAILED_EVER)
HANDLE_KEY(date_created, date_created, DATE_CREATED)
HANDLE_KEY(date_created_camel, date_created, DATE_CREATED)
HANDLE_KEY(desired_available, desired_available, DESIRED_AVAILABLE)
HANDLE_KEY(desired_available_camel, desired_available, DESIRED_AVAILABLE)
HANDLE_KEY(download_limit, download_limit, DOWNLOAD_LIMIT) // KB/s
HANDLE_KEY(download_limit_camel, download_limit, DOWNLOAD_LIMIT) // KB/s
HANDLE_KEY(download_limited, download_limited, DOWNLOAD_LIMITED)
HANDLE_KEY(download_limited_camel, download_limited, DOWNLOAD_LIMITED)
HANDLE_KEY(downloaded_ever, downloaded_ever, DOWNLOADED_EVER)
HANDLE_KEY(downloaded_ever_camel, downloaded_ever, DOWNLOADED_EVER)
HANDLE_KEY(edit_date, edit_date, EDIT_DATE)
HANDLE_KEY(error, error, TORRENT_ERROR)
HANDLE_KEY(eta, eta, ETA)
HANDLE_KEY(file_stats, files, FILES)
HANDLE_KEY(file_stats_camel, files, FILES)
HANDLE_KEY(files, files, FILES)
HANDLE_KEY(file_count, file_count, FILE_COUNT)
HANDLE_KEY(file_count_kebab, file_count, FILE_COUNT)
HANDLE_KEY(hash_string, hash, HASH)
HANDLE_KEY(hash_string_camel, hash, HASH)
HANDLE_KEY(have_unchecked, have_unchecked, HAVE_UNCHECKED)
HANDLE_KEY(have_unchecked_camel, have_unchecked, HAVE_UNCHECKED)
HANDLE_KEY(have_valid, have_verified, HAVE_VERIFIED)
HANDLE_KEY(have_valid_camel, have_verified, HAVE_VERIFIED)
HANDLE_KEY(honors_session_limits, honors_session_limits, HONORS_SESSION_LIMITS)
HANDLE_KEY(honors_session_limits_camel, honors_session_limits, HONORS_SESSION_LIMITS)
HANDLE_KEY(is_finished, is_finished, IS_FINISHED)
HANDLE_KEY(is_finished_camel, is_finished, IS_FINISHED)
HANDLE_KEY(is_private, is_private, IS_PRIVATE)
HANDLE_KEY(is_private_camel, is_private, IS_PRIVATE)
HANDLE_KEY(is_stalled, is_stalled, IS_STALLED)
HANDLE_KEY(is_stalled_camel, is_stalled, IS_STALLED)
HANDLE_KEY(labels, labels, LABELS)
HANDLE_KEY(left_until_done, left_until_done, LEFT_UNTIL_DONE)
HANDLE_KEY(left_until_done_camel, left_until_done, LEFT_UNTIL_DONE)
HANDLE_KEY(manual_announce_time, manual_announce_time, MANUAL_ANNOUNCE_TIME)
HANDLE_KEY(manual_announce_time_camel, manual_announce_time, MANUAL_ANNOUNCE_TIME)
HANDLE_KEY(metadata_percent_complete, metadata_percent_complete, METADATA_PERCENT_COMPLETE)
HANDLE_KEY(metadata_percent_complete_camel, metadata_percent_complete, METADATA_PERCENT_COMPLETE)
HANDLE_KEY(name, name, NAME)
HANDLE_KEY(peer_limit, peer_limit, PEER_LIMIT)
HANDLE_KEY(peers, peers, PEERS)
HANDLE_KEY(peers_connected, peers_connected, PEERS_CONNECTED)
HANDLE_KEY(peers_connected_camel, peers_connected, PEERS_CONNECTED)
HANDLE_KEY(peers_getting_from_us, peers_getting_from_us, PEERS_GETTING_FROM_US)
HANDLE_KEY(peers_getting_from_us_camel, peers_getting_from_us, PEERS_GETTING_FROM_US)
HANDLE_KEY(peers_sending_to_us, peers_sending_to_us, PEERS_SENDING_TO_US)
HANDLE_KEY(peers_sending_to_us_camel, peers_sending_to_us, PEERS_SENDING_TO_US)
HANDLE_KEY(percent_done, percent_done, PERCENT_DONE)
HANDLE_KEY(percent_done_camel, percent_done, PERCENT_DONE)
HANDLE_KEY(piece_count, piece_count, PIECE_COUNT)
HANDLE_KEY(piece_count_camel, piece_count, PIECE_COUNT)
HANDLE_KEY(piece_size, piece_size, PIECE_SIZE)
HANDLE_KEY(piece_size_camel, piece_size, PIECE_SIZE)
HANDLE_KEY(primary_mime_type, primary_mime_type, PRIMARY_MIME_TYPE)
HANDLE_KEY(primary_mime_type_kebab, primary_mime_type, PRIMARY_MIME_TYPE)
HANDLE_KEY(queue_position, queue_position, QUEUE_POSITION)
HANDLE_KEY(queue_position_camel, queue_position, QUEUE_POSITION)
HANDLE_KEY(rate_download, download_speed, DOWNLOAD_SPEED)
HANDLE_KEY(rate_download_camel, download_speed, DOWNLOAD_SPEED)
HANDLE_KEY(rate_upload, upload_speed, UPLOAD_SPEED)
HANDLE_KEY(rate_upload_camel, upload_speed, UPLOAD_SPEED)
HANDLE_KEY(recheck_progress, recheck_progress, RECHECK_PROGRESS)
HANDLE_KEY(recheck_progress_camel, recheck_progress, RECHECK_PROGRESS)
HANDLE_KEY(seed_idle_limit, seed_idle_limit, SEED_IDLE_LIMIT)
HANDLE_KEY(seed_idle_limit_camel, seed_idle_limit, SEED_IDLE_LIMIT)
HANDLE_KEY(seed_idle_mode, seed_idle_mode, SEED_IDLE_MODE)
HANDLE_KEY(seed_idle_mode_camel, seed_idle_mode, SEED_IDLE_MODE)
HANDLE_KEY(seed_ratio_limit, seed_ratio_limit, SEED_RATIO_LIMIT)
HANDLE_KEY(seed_ratio_limit_camel, seed_ratio_limit, SEED_RATIO_LIMIT)
HANDLE_KEY(seed_ratio_mode, seed_ratio_mode, SEED_RATIO_MODE)
HANDLE_KEY(seed_ratio_mode_camel, seed_ratio_mode, SEED_RATIO_MODE)
HANDLE_KEY(size_when_done, size_when_done, SIZE_WHEN_DONE)
HANDLE_KEY(size_when_done_camel, size_when_done, SIZE_WHEN_DONE)
HANDLE_KEY(start_date, start_date, START_DATE)
HANDLE_KEY(start_date_camel, start_date, START_DATE)
HANDLE_KEY(status, status, STATUS)
HANDLE_KEY(total_size, total_size, TOTAL_SIZE)
HANDLE_KEY(total_size_camel, total_size, TOTAL_SIZE)
HANDLE_KEY(tracker_list, tracker_list, TRACKER_LIST)
HANDLE_KEY(tracker_list_camel, tracker_list, TRACKER_LIST)
HANDLE_KEY(tracker_stats, tracker_stats, TRACKER_STATS)
HANDLE_KEY(tracker_stats_camel, tracker_stats, TRACKER_STATS)
HANDLE_KEY(trackers, tracker_stats, TRACKER_STATS)
HANDLE_KEY(upload_limit, upload_limit, UPLOAD_LIMIT) // KB/s
HANDLE_KEY(upload_limit_camel, upload_limit, UPLOAD_LIMIT) // KB/s
HANDLE_KEY(upload_limited, upload_limited, UPLOAD_LIMITED)
HANDLE_KEY(upload_limited_camel, upload_limited, UPLOAD_LIMITED)
HANDLE_KEY(uploaded_ever, uploaded_ever, UPLOADED_EVER)
HANDLE_KEY(uploaded_ever_camel, uploaded_ever, UPLOADED_EVER)
HANDLE_KEY(webseeds_sending_to_us, webseeds_sending_to_us, WEBSEEDS_SENDING_TO_US)
HANDLE_KEY(webseeds_sending_to_us_camel, webseeds_sending_to_us, WEBSEEDS_SENDING_TO_US)
#undef HANDLE_KEY
#define HANDLE_KEY(key, field, bit) \
case TR_KEY_##key: \
field_changed = change(field##_, child); \
if (field_changed) \
{ \
field##_ = trApp->intern(field##_); \
} \
changed.set(bit, field_changed); \
break;
HANDLE_KEY(comment, comment, COMMENT)
HANDLE_KEY(creator, creator, CREATOR)
HANDLE_KEY(download_dir, download_dir, DOWNLOAD_DIR)
HANDLE_KEY(download_dir_camel, download_dir, DOWNLOAD_DIR)
HANDLE_KEY(error_string, error_string, TORRENT_ERROR_STRING)
HANDLE_KEY(error_string_camel, error_string, TORRENT_ERROR_STRING)
#undef HANDLE_KEY
default:
break;
}
if (field_changed)
{
switch (key)
{
case TR_KEY_file_count:
case TR_KEY_file_count_kebab:
case TR_KEY_primary_mime_type:
case TR_KEY_primary_mime_type_kebab:
icon_ = {};
break;
case TR_KEY_files:
for (size_t i = 0; i < files_.size(); ++i)
{
files_[i].index = i;
}
break;
case TR_KEY_trackers:
{
auto tmp = std::set<QString>{};
for (auto const& ts : tracker_stats_)
{
tmp.insert(ts.sitename);
}
sitenames_ = std::vector<QString>{ std::begin(tmp), std::end(tmp) };
break;
}
default:
break;
}
}
}
return changed;
}
QString Torrent::activityString() const
{
switch (getActivity())
{
case TR_STATUS_STOPPED:
return isFinished() ? tr("Finished") : tr("Paused");
case TR_STATUS_CHECK_WAIT:
return tr("Queued for verification");
case TR_STATUS_CHECK:
return tr("Verifying local data");
case TR_STATUS_DOWNLOAD_WAIT:
return tr("Queued for download");
case TR_STATUS_DOWNLOAD:
return tr("Downloading");
case TR_STATUS_SEED_WAIT:
return tr("Queued for seeding");
case TR_STATUS_SEED:
return tr("Seeding");
default:
return {};
}
}
QString Torrent::getError() const
{
switch (error_)
{
case TR_STAT_TRACKER_WARNING:
return tr("Tracker gave a warning: %1").arg(error_string_);
case TR_STAT_TRACKER_ERROR:
return tr("Tracker gave an error: %1").arg(error_string_);
case TR_STAT_LOCAL_ERROR:
return tr("Error: %1").arg(error_string_);
default:
return {};
}
}
QPixmap TrackerStat::getFavicon() const
{
return trApp->find_favicon(sitename);
}