mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 12:28:52 +00:00
* 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
529 lines
21 KiB
C++
529 lines
21 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 <array>
|
|
#include <cassert>
|
|
#include <string_view>
|
|
#include <utility>
|
|
|
|
#include <QDateTime>
|
|
#include <QDir>
|
|
#include <QFile>
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
#include <QStringDecoder>
|
|
#else
|
|
#include <QTextCodec>
|
|
#endif
|
|
|
|
#include <libtransmission/transmission.h>
|
|
#include <libtransmission/variant.h>
|
|
|
|
#include "CustomVariantType.h"
|
|
#include "Filters.h"
|
|
#include "Prefs.h"
|
|
#include "VariantHelpers.h"
|
|
|
|
using ::trqt::variant_helpers::dictAdd;
|
|
using ::trqt::variant_helpers::getValue;
|
|
|
|
// ---
|
|
|
|
namespace
|
|
{
|
|
|
|
void ensureSoundCommandIsAList(tr_variant* dict)
|
|
{
|
|
tr_quark const key = TR_KEY_torrent_complete_sound_command;
|
|
|
|
if (tr_variant* list = nullptr; tr_variantDictFindList(dict, key, &list))
|
|
{
|
|
return;
|
|
}
|
|
|
|
tr_variantDictRemove(dict, key);
|
|
dictAdd(
|
|
dict,
|
|
key,
|
|
std::array<std::string_view, 5>{
|
|
"canberra-gtk-play",
|
|
"-i",
|
|
"complete-download",
|
|
"-d",
|
|
"transmission torrent downloaded",
|
|
});
|
|
}
|
|
|
|
} // namespace
|
|
|
|
std::array<Prefs::PrefItem, Prefs::PREFS_COUNT> const Prefs::Items{
|
|
/* gui settings */
|
|
PrefItem{ OPTIONS_PROMPT, TR_KEY_show_options_window_kebab, QMetaType::Bool },
|
|
{ OPEN_DIALOG_FOLDER, TR_KEY_open_dialog_dir_kebab, QMetaType::QString },
|
|
{ INHIBIT_HIBERNATION, TR_KEY_inhibit_desktop_hibernation_kebab, QMetaType::Bool },
|
|
{ DIR_WATCH, TR_KEY_watch_dir_kebab, QMetaType::QString },
|
|
{ DIR_WATCH_ENABLED, TR_KEY_watch_dir_enabled_kebab, QMetaType::Bool },
|
|
{ SHOW_TRAY_ICON, TR_KEY_show_notification_area_icon_kebab, QMetaType::Bool },
|
|
{ START_MINIMIZED, TR_KEY_start_minimized_kebab, QMetaType::Bool },
|
|
{ SHOW_NOTIFICATION_ON_ADD, TR_KEY_torrent_added_notification_enabled_kebab, QMetaType::Bool },
|
|
{ SHOW_NOTIFICATION_ON_COMPLETE, TR_KEY_torrent_complete_notification_enabled_kebab, QMetaType::Bool },
|
|
{ ASKQUIT, TR_KEY_prompt_before_exit_kebab, QMetaType::Bool },
|
|
{ SORT_MODE, TR_KEY_sort_mode_kebab, CustomVariantType::SortModeType },
|
|
{ SORT_REVERSED, TR_KEY_sort_reversed_kebab, QMetaType::Bool },
|
|
{ COMPACT_VIEW, TR_KEY_compact_view_kebab, QMetaType::Bool },
|
|
{ FILTERBAR, TR_KEY_show_filterbar_kebab, QMetaType::Bool },
|
|
{ STATUSBAR, TR_KEY_show_statusbar_kebab, QMetaType::Bool },
|
|
{ STATUSBAR_STATS, TR_KEY_statusbar_stats_kebab, QMetaType::QString },
|
|
{ SHOW_TRACKER_SCRAPES, TR_KEY_show_tracker_scrapes_kebab, QMetaType::Bool },
|
|
{ SHOW_BACKUP_TRACKERS, TR_KEY_show_backup_trackers_kebab, QMetaType::Bool },
|
|
{ TOOLBAR, TR_KEY_show_toolbar_kebab, QMetaType::Bool },
|
|
{ BLOCKLIST_DATE, TR_KEY_blocklist_date_kebab, QMetaType::QDateTime },
|
|
{ BLOCKLIST_UPDATES_ENABLED, TR_KEY_blocklist_updates_enabled_kebab, QMetaType::Bool },
|
|
{ MAIN_WINDOW_LAYOUT_ORDER, TR_KEY_main_window_layout_order_kebab, QMetaType::QString },
|
|
{ MAIN_WINDOW_HEIGHT, TR_KEY_main_window_height_kebab, QMetaType::Int },
|
|
{ MAIN_WINDOW_WIDTH, TR_KEY_main_window_width_kebab, QMetaType::Int },
|
|
{ MAIN_WINDOW_X, TR_KEY_main_window_x_kebab, QMetaType::Int },
|
|
{ MAIN_WINDOW_Y, TR_KEY_main_window_y_kebab, QMetaType::Int },
|
|
{ FILTER_MODE, TR_KEY_filter_mode_kebab, CustomVariantType::FilterModeType },
|
|
{ FILTER_TRACKERS, TR_KEY_filter_trackers_kebab, QMetaType::QString },
|
|
{ FILTER_TEXT, TR_KEY_filter_text_kebab, QMetaType::QString },
|
|
{ SESSION_IS_REMOTE, TR_KEY_remote_session_enabled_kebab, QMetaType::Bool },
|
|
{ SESSION_REMOTE_HOST, TR_KEY_remote_session_host_kebab, QMetaType::QString },
|
|
{ SESSION_REMOTE_HTTPS, TR_KEY_remote_session_https_kebab, QMetaType::Bool },
|
|
{ SESSION_REMOTE_PASSWORD, TR_KEY_remote_session_password_kebab, QMetaType::QString },
|
|
{ SESSION_REMOTE_PORT, TR_KEY_remote_session_port_kebab, QMetaType::Int },
|
|
{ SESSION_REMOTE_AUTH, TR_KEY_remote_session_requres_authentication_kebab, QMetaType::Bool },
|
|
{ SESSION_REMOTE_USERNAME, TR_KEY_remote_session_username_kebab, QMetaType::QString },
|
|
{ SESSION_REMOTE_RPC_URL_PATH, TR_KEY_remote_session_rpc_url_path, QMetaType::QString },
|
|
{ COMPLETE_SOUND_COMMAND, TR_KEY_torrent_complete_sound_command_kebab, QMetaType::QStringList },
|
|
{ COMPLETE_SOUND_ENABLED, TR_KEY_torrent_complete_sound_enabled_kebab, QMetaType::Bool },
|
|
{ USER_HAS_GIVEN_INFORMED_CONSENT, TR_KEY_user_has_given_informed_consent_kebab, QMetaType::Bool },
|
|
{ READ_CLIPBOARD, TR_KEY_read_clipboard_kebab, QMetaType::Bool },
|
|
|
|
/* libtransmission settings */
|
|
{ ALT_SPEED_LIMIT_UP, TR_KEY_alt_speed_up_kebab, QMetaType::Int },
|
|
{ ALT_SPEED_LIMIT_DOWN, TR_KEY_alt_speed_down_kebab, QMetaType::Int },
|
|
{ ALT_SPEED_LIMIT_ENABLED, TR_KEY_alt_speed_enabled_kebab, QMetaType::Bool },
|
|
{ ALT_SPEED_LIMIT_TIME_BEGIN, TR_KEY_alt_speed_time_begin_kebab, QMetaType::Int },
|
|
{ ALT_SPEED_LIMIT_TIME_END, TR_KEY_alt_speed_time_end_kebab, QMetaType::Int },
|
|
{ ALT_SPEED_LIMIT_TIME_ENABLED, TR_KEY_alt_speed_time_enabled_kebab, QMetaType::Bool },
|
|
{ ALT_SPEED_LIMIT_TIME_DAY, TR_KEY_alt_speed_time_day_kebab, QMetaType::Int },
|
|
{ BLOCKLIST_ENABLED, TR_KEY_blocklist_enabled_kebab, QMetaType::Bool },
|
|
{ BLOCKLIST_URL, TR_KEY_blocklist_url_kebab, QMetaType::QString },
|
|
{ DEFAULT_TRACKERS, TR_KEY_default_trackers_kebab, QMetaType::QString },
|
|
{ DSPEED, TR_KEY_speed_limit_down_kebab, QMetaType::Int },
|
|
{ DSPEED_ENABLED, TR_KEY_speed_limit_down_enabled_kebab, QMetaType::Bool },
|
|
{ DOWNLOAD_DIR, TR_KEY_download_dir_kebab, QMetaType::QString },
|
|
{ DOWNLOAD_QUEUE_ENABLED, TR_KEY_download_queue_enabled_kebab, QMetaType::Bool },
|
|
{ DOWNLOAD_QUEUE_SIZE, TR_KEY_download_queue_size_kebab, QMetaType::Int },
|
|
{ ENCRYPTION, TR_KEY_encryption, QMetaType::Int },
|
|
{ IDLE_LIMIT, TR_KEY_idle_seeding_limit_kebab, QMetaType::Int },
|
|
{ IDLE_LIMIT_ENABLED, TR_KEY_idle_seeding_limit_enabled_kebab, QMetaType::Bool },
|
|
{ INCOMPLETE_DIR, TR_KEY_incomplete_dir_kebab, QMetaType::QString },
|
|
{ INCOMPLETE_DIR_ENABLED, TR_KEY_incomplete_dir_enabled_kebab, QMetaType::Bool },
|
|
{ MSGLEVEL, TR_KEY_message_level_kebab, QMetaType::Int },
|
|
{ PEER_LIMIT_GLOBAL, TR_KEY_peer_limit_global_kebab, QMetaType::Int },
|
|
{ PEER_LIMIT_TORRENT, TR_KEY_peer_limit_per_torrent_kebab, QMetaType::Int },
|
|
{ PEER_PORT, TR_KEY_peer_port_kebab, QMetaType::Int },
|
|
{ PEER_PORT_RANDOM_ON_START, TR_KEY_peer_port_random_on_start_kebab, QMetaType::Bool },
|
|
{ PEER_PORT_RANDOM_LOW, TR_KEY_peer_port_random_low_kebab, QMetaType::Int },
|
|
{ PEER_PORT_RANDOM_HIGH, TR_KEY_peer_port_random_high_kebab, QMetaType::Int },
|
|
{ QUEUE_STALLED_MINUTES, TR_KEY_queue_stalled_minutes_kebab, QMetaType::Int },
|
|
{ SCRIPT_TORRENT_DONE_ENABLED, TR_KEY_script_torrent_done_enabled_kebab, QMetaType::Bool },
|
|
{ SCRIPT_TORRENT_DONE_FILENAME, TR_KEY_script_torrent_done_filename_kebab, QMetaType::QString },
|
|
{ SCRIPT_TORRENT_DONE_SEEDING_ENABLED, TR_KEY_script_torrent_done_seeding_enabled_kebab, QMetaType::Bool },
|
|
{ SCRIPT_TORRENT_DONE_SEEDING_FILENAME, TR_KEY_script_torrent_done_seeding_filename_kebab, QMetaType::QString },
|
|
{ SOCKET_TOS, TR_KEY_peer_socket_tos_kebab, QMetaType::QString },
|
|
{ START, TR_KEY_start_added_torrents_kebab, QMetaType::Bool },
|
|
{ TRASH_ORIGINAL, TR_KEY_trash_original_torrent_files_kebab, QMetaType::Bool },
|
|
{ PEX_ENABLED, TR_KEY_pex_enabled_kebab, QMetaType::Bool },
|
|
{ DHT_ENABLED, TR_KEY_dht_enabled_kebab, QMetaType::Bool },
|
|
{ UTP_ENABLED, TR_KEY_utp_enabled_kebab, QMetaType::Bool },
|
|
{ LPD_ENABLED, TR_KEY_lpd_enabled_kebab, QMetaType::Bool },
|
|
{ PORT_FORWARDING, TR_KEY_port_forwarding_enabled_kebab, QMetaType::Bool },
|
|
{ PREALLOCATION, TR_KEY_preallocation, QMetaType::Int },
|
|
{ RATIO, TR_KEY_ratio_limit_kebab, QMetaType::Double },
|
|
{ RATIO_ENABLED, TR_KEY_ratio_limit_enabled_kebab, QMetaType::Bool },
|
|
{ RENAME_PARTIAL_FILES, TR_KEY_rename_partial_files_kebab, QMetaType::Bool },
|
|
{ RPC_AUTH_REQUIRED, TR_KEY_rpc_authentication_required_kebab, QMetaType::Bool },
|
|
{ RPC_ENABLED, TR_KEY_rpc_enabled_kebab, QMetaType::Bool },
|
|
{ RPC_PASSWORD, TR_KEY_rpc_password_kebab, QMetaType::QString },
|
|
{ RPC_PORT, TR_KEY_rpc_port_kebab, QMetaType::Int },
|
|
{ RPC_USERNAME, TR_KEY_rpc_username_kebab, QMetaType::QString },
|
|
{ RPC_WHITELIST_ENABLED, TR_KEY_rpc_whitelist_enabled_kebab, QMetaType::Bool },
|
|
{ RPC_WHITELIST, TR_KEY_rpc_whitelist_kebab, QMetaType::QString },
|
|
{ USPEED_ENABLED, TR_KEY_speed_limit_up_enabled_kebab, QMetaType::Bool },
|
|
{ USPEED, TR_KEY_speed_limit_up_kebab, QMetaType::Int },
|
|
{ UPLOAD_SLOTS_PER_TORRENT, TR_KEY_upload_slots_per_torrent_kebab, QMetaType::Int },
|
|
};
|
|
|
|
namespace
|
|
{
|
|
|
|
auto constexpr FilterModes = std::array<std::pair<int, std::string_view>, FilterMode::NUM_MODES>{ {
|
|
{ FilterMode::SHOW_ALL, "show-all" },
|
|
{ FilterMode::SHOW_ACTIVE, "show-active" },
|
|
{ FilterMode::SHOW_DOWNLOADING, "show-downloading" },
|
|
{ FilterMode::SHOW_SEEDING, "show-seeding" },
|
|
{ FilterMode::SHOW_PAUSED, "show-paused" },
|
|
{ FilterMode::SHOW_FINISHED, "show-finished" },
|
|
{ FilterMode::SHOW_VERIFYING, "show-verifying" },
|
|
{ FilterMode::SHOW_ERROR, "show-error" },
|
|
} };
|
|
|
|
auto constexpr SortModes = std::array<std::pair<int, std::string_view>, SortMode::NUM_MODES>{ {
|
|
{ SortMode::SORT_BY_NAME, "sort-by-name" },
|
|
{ SortMode::SORT_BY_ACTIVITY, "sort-by-activity" },
|
|
{ SortMode::SORT_BY_AGE, "sort-by-age" },
|
|
{ SortMode::SORT_BY_ETA, "sort-by-eta" },
|
|
{ SortMode::SORT_BY_PROGRESS, "sort-by-progress" },
|
|
{ SortMode::SORT_BY_QUEUE, "sort-by-queue" },
|
|
{ SortMode::SORT_BY_RATIO, "sort-by-ratio" },
|
|
{ SortMode::SORT_BY_SIZE, "sort-by-size" },
|
|
{ SortMode::SORT_BY_STATE, "sort-by-state" },
|
|
{ SortMode::SORT_BY_ID, "sort-by-id" },
|
|
} };
|
|
|
|
bool isValidUtf8(QByteArray const& byteArray)
|
|
{
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
auto decoder = QStringDecoder{ QStringConverter::Utf8, QStringConverter::Flag::Stateless };
|
|
auto const text = QString{ decoder.decode(byteArray) };
|
|
return !decoder.hasError() && !text.contains(QChar::ReplacementCharacter);
|
|
|
|
#else
|
|
|
|
auto const* const codec = QTextCodec::codecForName("UTF-8");
|
|
auto state = QTextCodec::ConverterState{};
|
|
codec->toUnicode(byteArray.constData(), byteArray.size(), &state);
|
|
return state.invalidChars == 0;
|
|
|
|
#endif
|
|
}
|
|
|
|
[[nodiscard]] constexpr auto prefIsSavable(int pref)
|
|
{
|
|
switch (pref)
|
|
{
|
|
// these are the prefs that don't get saved to settings.json
|
|
// when the application exits.
|
|
case Prefs::FILTER_TEXT:
|
|
return false;
|
|
|
|
default:
|
|
return true;
|
|
}
|
|
}
|
|
} // namespace
|
|
|
|
/***
|
|
****
|
|
***/
|
|
|
|
Prefs::Prefs(QString config_dir)
|
|
: config_dir_{ std::move(config_dir) }
|
|
{
|
|
static_assert(sizeof(Items) / sizeof(Items[0]) == PREFS_COUNT);
|
|
|
|
#ifndef NDEBUG
|
|
for (int i = 0; i < PREFS_COUNT; ++i)
|
|
{
|
|
assert(Items[i].id == i);
|
|
}
|
|
|
|
#endif
|
|
|
|
auto const app_defaults = get_default_app_settings();
|
|
auto settings = tr_sessionLoadSettings(&app_defaults, config_dir_.toUtf8().constData(), nullptr);
|
|
ensureSoundCommandIsAList(&settings);
|
|
|
|
for (int i = 0; i < PREFS_COUNT; ++i)
|
|
{
|
|
tr_variant const* b = tr_variantDictFind(&settings, tr_quark_convert(getKey(i)));
|
|
|
|
switch (Items[i].type)
|
|
{
|
|
case QMetaType::Int:
|
|
if (auto const value = getValue<int64_t>(b); value)
|
|
{
|
|
values_[i].setValue(*value);
|
|
}
|
|
break;
|
|
|
|
case CustomVariantType::SortModeType:
|
|
if (auto const value = getValue<std::string_view>(b); value)
|
|
{
|
|
auto const test = [&value](auto const& item)
|
|
{
|
|
return item.second == *value;
|
|
};
|
|
// NOLINTNEXTLINE(readability-qualified-auto)
|
|
auto const it = std::find_if(std::cbegin(SortModes), std::cend(SortModes), test);
|
|
auto const& [mode, mode_str] = it == std::end(SortModes) ? SortModes.front() : *it;
|
|
values_[i] = QVariant::fromValue(SortMode{ mode });
|
|
}
|
|
break;
|
|
|
|
case CustomVariantType::FilterModeType:
|
|
if (auto const value = getValue<std::string_view>(b); value)
|
|
{
|
|
auto const test = [&value](auto const& item)
|
|
{
|
|
return item.second == *value;
|
|
};
|
|
// NOLINTNEXTLINE(readability-qualified-auto)
|
|
auto const it = std::find_if(std::cbegin(FilterModes), std::cend(FilterModes), test);
|
|
auto const& [mode, mode_str] = it == std::end(FilterModes) ? FilterModes.front() : *it;
|
|
values_[i] = QVariant::fromValue(FilterMode{ mode });
|
|
}
|
|
break;
|
|
|
|
case QMetaType::QString:
|
|
if (auto const value = getValue<QString>(b); value)
|
|
{
|
|
values_[i].setValue(*value);
|
|
}
|
|
break;
|
|
|
|
case QMetaType::QStringList:
|
|
if (auto const value = getValue<QStringList>(b); value)
|
|
{
|
|
values_[i].setValue(*value);
|
|
}
|
|
break;
|
|
|
|
case QMetaType::Bool:
|
|
if (auto const value = getValue<bool>(b); value)
|
|
{
|
|
values_[i].setValue(*value);
|
|
}
|
|
break;
|
|
|
|
case QMetaType::Double:
|
|
if (auto const value = getValue<double>(b); value)
|
|
{
|
|
values_[i].setValue(*value);
|
|
}
|
|
break;
|
|
|
|
case QMetaType::QDateTime:
|
|
if (auto const value = getValue<time_t>(b); value)
|
|
{
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
|
|
values_[i].setValue(QDateTime::fromSecsSinceEpoch(*value));
|
|
#else
|
|
values_[i].setValue(QDateTime::fromTime_t(*value));
|
|
#endif
|
|
}
|
|
break;
|
|
|
|
default:
|
|
assert(false && "unhandled type");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
Prefs::~Prefs()
|
|
{
|
|
// make a dict from settings.json
|
|
tr_variant current_settings;
|
|
tr_variantInitDict(¤t_settings, PREFS_COUNT);
|
|
|
|
for (int i = 0; i < PREFS_COUNT; ++i)
|
|
{
|
|
if (!prefIsSavable(i))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
tr_quark const key = tr_quark_convert(getKey(i));
|
|
QVariant const& val = values_[i];
|
|
|
|
switch (Items[i].type)
|
|
{
|
|
case QMetaType::Int:
|
|
dictAdd(¤t_settings, key, val.toInt());
|
|
break;
|
|
|
|
case CustomVariantType::SortModeType:
|
|
{
|
|
auto const mode = val.value<SortMode>().mode();
|
|
auto const test = [&mode](auto const& item)
|
|
{
|
|
return item.first == mode;
|
|
};
|
|
// NOLINTNEXTLINE(readability-qualified-auto)
|
|
auto const it = std::find_if(std::cbegin(SortModes), std::cend(SortModes), test);
|
|
auto const& [mode_val, mode_str] = it == std::end(SortModes) ? SortModes.front() : *it;
|
|
dictAdd(¤t_settings, key, mode_str);
|
|
break;
|
|
}
|
|
|
|
case CustomVariantType::FilterModeType:
|
|
{
|
|
auto const mode = val.value<FilterMode>().mode();
|
|
auto const test = [&mode](auto const& item)
|
|
{
|
|
return item.first == mode;
|
|
};
|
|
// NOLINTNEXTLINE(readability-qualified-auto)
|
|
auto const it = std::find_if(std::cbegin(FilterModes), std::cend(FilterModes), test);
|
|
auto const& [mode_val, mode_str] = it == std::end(FilterModes) ? FilterModes.front() : *it;
|
|
dictAdd(¤t_settings, key, mode_str);
|
|
break;
|
|
}
|
|
|
|
case QMetaType::QString:
|
|
dictAdd(¤t_settings, key, val.toString());
|
|
break;
|
|
|
|
case QMetaType::QStringList:
|
|
dictAdd(¤t_settings, key, val.toStringList());
|
|
break;
|
|
|
|
case QMetaType::Bool:
|
|
dictAdd(¤t_settings, key, val.toBool());
|
|
break;
|
|
|
|
case QMetaType::Double:
|
|
dictAdd(¤t_settings, key, val.toDouble());
|
|
break;
|
|
|
|
case QMetaType::QDateTime:
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
|
|
dictAdd(¤t_settings, key, int64_t{ val.toDateTime().toSecsSinceEpoch() });
|
|
#else
|
|
dictAdd(¤t_settings, key, val.toDateTime().toTime_t());
|
|
#endif
|
|
break;
|
|
|
|
default:
|
|
assert(false && "unhandled type");
|
|
break;
|
|
}
|
|
}
|
|
|
|
// update settings.json with our settings
|
|
auto serde = tr_variant_serde::json();
|
|
auto const file = QFile{ QDir{ config_dir_ }.absoluteFilePath(QStringLiteral("settings.json")) };
|
|
auto const filename = file.fileName().toStdString();
|
|
auto settings = tr_variant::make_map(PREFS_COUNT);
|
|
if (auto const file_settings = serde.parse_file(filename); file_settings)
|
|
{
|
|
settings.merge(*file_settings);
|
|
}
|
|
|
|
settings.merge(current_settings);
|
|
serde.to_file(settings, filename);
|
|
}
|
|
|
|
/**
|
|
* This is where we initialize the preferences file with the default values.
|
|
* If you add a new preferences key, you /must/ add a default value here.
|
|
*/
|
|
tr_variant Prefs::get_default_app_settings()
|
|
{
|
|
auto constexpr FilterMode = std::string_view{ "all" };
|
|
auto constexpr SessionHost = std::string_view{ "localhost" };
|
|
auto constexpr SessionPassword = std::string_view{};
|
|
auto constexpr SessionUsername = std::string_view{};
|
|
auto constexpr SortMode = std::string_view{ "sort-by-name" };
|
|
auto constexpr StatsMode = std::string_view{ "total-ratio" };
|
|
auto constexpr WindowLayout = std::string_view{ "menu,toolbar,filter,list,statusbar" };
|
|
|
|
auto const download_dir = tr_getDefaultDownloadDir();
|
|
|
|
auto settings = tr_variant::Map{};
|
|
settings.try_emplace(TR_KEY_blocklist_updates_enabled, true);
|
|
settings.try_emplace(TR_KEY_compact_view, false);
|
|
settings.try_emplace(TR_KEY_inhibit_desktop_hibernation, false);
|
|
settings.try_emplace(TR_KEY_prompt_before_exit, true);
|
|
settings.try_emplace(TR_KEY_remote_session_enabled, false);
|
|
settings.try_emplace(TR_KEY_remote_session_requires_authentication, false);
|
|
settings.try_emplace(TR_KEY_show_backup_trackers, false);
|
|
settings.try_emplace(TR_KEY_show_filterbar, true);
|
|
settings.try_emplace(TR_KEY_show_notification_area_icon, false);
|
|
settings.try_emplace(TR_KEY_start_minimized, false);
|
|
settings.try_emplace(TR_KEY_show_options_window, true);
|
|
settings.try_emplace(TR_KEY_show_statusbar, true);
|
|
settings.try_emplace(TR_KEY_show_toolbar, true);
|
|
settings.try_emplace(TR_KEY_show_tracker_scrapes, false);
|
|
settings.try_emplace(TR_KEY_sort_reversed, false);
|
|
settings.try_emplace(TR_KEY_torrent_added_notification_enabled, true);
|
|
settings.try_emplace(TR_KEY_torrent_complete_notification_enabled, true);
|
|
settings.try_emplace(TR_KEY_torrent_complete_sound_enabled, true);
|
|
settings.try_emplace(TR_KEY_user_has_given_informed_consent, false);
|
|
settings.try_emplace(TR_KEY_watch_dir_enabled, false);
|
|
settings.try_emplace(TR_KEY_blocklist_date, 0);
|
|
settings.try_emplace(TR_KEY_main_window_height, 500);
|
|
settings.try_emplace(TR_KEY_main_window_width, 300);
|
|
settings.try_emplace(TR_KEY_main_window_x, 50);
|
|
settings.try_emplace(TR_KEY_main_window_y, 50);
|
|
settings.try_emplace(TR_KEY_remote_session_port, TrDefaultRpcPort);
|
|
settings.try_emplace(TR_KEY_download_dir, download_dir);
|
|
settings.try_emplace(TR_KEY_filter_mode, FilterMode);
|
|
settings.try_emplace(TR_KEY_main_window_layout_order, WindowLayout);
|
|
settings.try_emplace(TR_KEY_open_dialog_dir, QDir::home().absolutePath().toStdString());
|
|
settings.try_emplace(TR_KEY_remote_session_https, false);
|
|
settings.try_emplace(TR_KEY_remote_session_host, SessionHost);
|
|
settings.try_emplace(TR_KEY_remote_session_password, SessionPassword);
|
|
settings.try_emplace(TR_KEY_remote_session_username, SessionUsername);
|
|
settings.try_emplace(TR_KEY_sort_mode, SortMode);
|
|
settings.try_emplace(TR_KEY_statusbar_stats, StatsMode);
|
|
settings.try_emplace(TR_KEY_watch_dir, download_dir);
|
|
settings.try_emplace(TR_KEY_read_clipboard, false);
|
|
settings.try_emplace(TR_KEY_remote_session_rpc_url_path, TR_DEFAULT_RPC_URL_STR "rpc");
|
|
return tr_variant{ std::move(settings) };
|
|
}
|
|
|
|
/***
|
|
****
|
|
***/
|
|
|
|
bool Prefs::getBool(int key) const
|
|
{
|
|
assert(Items[key].type == QMetaType::Bool);
|
|
return values_[key].toBool();
|
|
}
|
|
|
|
QString Prefs::getString(int key) const
|
|
{
|
|
assert(Items[key].type == QMetaType::QString);
|
|
|
|
if (auto const b = values_[key].toByteArray(); isValidUtf8(b.constData()))
|
|
{
|
|
values_[key].setValue(QString::fromUtf8(b.constData()));
|
|
}
|
|
|
|
return values_[key].toString();
|
|
}
|
|
|
|
int Prefs::getInt(int key) const
|
|
{
|
|
assert(Items[key].type == QMetaType::Int);
|
|
return values_[key].toInt();
|
|
}
|
|
|
|
double Prefs::getDouble(int key) const
|
|
{
|
|
assert(Items[key].type == QMetaType::Double);
|
|
return values_[key].toDouble();
|
|
}
|
|
|
|
QDateTime Prefs::getDateTime(int key) const
|
|
{
|
|
assert(Items[key].type == QMetaType::QDateTime);
|
|
return values_[key].toDateTime();
|
|
}
|
|
|
|
// ---
|
|
|
|
void Prefs::toggleBool(int key)
|
|
{
|
|
set(key, !getBool(key));
|
|
}
|