mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +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
1108 lines
36 KiB
C++
1108 lines
36 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 "PrefsDialog.h"
|
|
|
|
#include "FreeSpaceLabel.h"
|
|
#include "GtkCompat.h"
|
|
#include "PathButton.h"
|
|
#include "Prefs.h"
|
|
#include "Session.h"
|
|
#include "SystemTrayIcon.h"
|
|
#include "Utils.h"
|
|
|
|
#include <libtransmission/transmission.h>
|
|
#include <libtransmission/web-utils.h>
|
|
|
|
#include <glibmm/date.h>
|
|
#include <glibmm/i18n.h>
|
|
#include <glibmm/main.h>
|
|
#include <glibmm/timer.h>
|
|
#include <glibmm/ustring.h>
|
|
#include <gtkmm/adjustment.h>
|
|
#include <gtkmm/box.h>
|
|
#include <gtkmm/button.h>
|
|
#include <gtkmm/cellrenderertext.h>
|
|
#include <gtkmm/checkbutton.h>
|
|
#include <gtkmm/combobox.h>
|
|
#include <gtkmm/editable.h>
|
|
#include <gtkmm/entry.h>
|
|
#include <gtkmm/label.h>
|
|
#include <gtkmm/liststore.h>
|
|
#include <gtkmm/spinbutton.h>
|
|
#include <gtkmm/textview.h>
|
|
#include <gtkmm/treemodelcolumn.h>
|
|
#include <gtkmm/widget.h>
|
|
|
|
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
|
#include <gtkmm/eventcontrollerfocus.h>
|
|
#endif
|
|
|
|
#include <fmt/format.h>
|
|
|
|
#include <array>
|
|
#include <limits>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
using namespace libtransmission::Values;
|
|
|
|
/**
|
|
***
|
|
**/
|
|
|
|
class PrefsDialog::Impl
|
|
{
|
|
public:
|
|
Impl(PrefsDialog& dialog, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core);
|
|
Impl(Impl&&) = delete;
|
|
Impl(Impl const&) = delete;
|
|
Impl& operator=(Impl&&) = delete;
|
|
Impl& operator=(Impl const&) = delete;
|
|
~Impl() = default;
|
|
|
|
private:
|
|
void response_cb(int response);
|
|
|
|
private:
|
|
PrefsDialog& dialog_;
|
|
Glib::RefPtr<Session> const core_;
|
|
};
|
|
|
|
/**
|
|
***
|
|
**/
|
|
|
|
void PrefsDialog::Impl::response_cb(int response)
|
|
{
|
|
if (response == TR_GTK_RESPONSE_TYPE(HELP))
|
|
{
|
|
gtr_open_uri(gtr_get_help_uri() + "/html/preferences.html");
|
|
}
|
|
|
|
if (response == TR_GTK_RESPONSE_TYPE(CLOSE))
|
|
{
|
|
dialog_.close();
|
|
}
|
|
}
|
|
|
|
namespace
|
|
{
|
|
|
|
class PageBase : public Gtk::Box
|
|
{
|
|
public:
|
|
PageBase(BaseObjectType* cast_item, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core);
|
|
PageBase(PageBase&&) = delete;
|
|
PageBase(PageBase const&) = delete;
|
|
PageBase& operator=(PageBase&&) = delete;
|
|
PageBase& operator=(PageBase const&) = delete;
|
|
~PageBase() override;
|
|
|
|
Gtk::CheckButton* init_check_button(Glib::ustring const& name, tr_quark key);
|
|
Gtk::SpinButton* init_spin_button(Glib::ustring const& name, tr_quark key, int low, int high, int step);
|
|
Gtk::SpinButton* init_spin_button_double(Glib::ustring const& name, tr_quark key, double low, double high, double step);
|
|
Gtk::Entry* init_entry(Glib::ustring const& name, tr_quark key);
|
|
Gtk::TextView* init_text_view(Glib::ustring const& name, tr_quark key);
|
|
PathButton* init_chooser_button(Glib::ustring const& name, tr_quark key);
|
|
Gtk::ComboBox* init_encryption_combo(Glib::ustring const& name, tr_quark key);
|
|
Gtk::ComboBox* init_time_combo(Glib::ustring const& name, tr_quark key);
|
|
Gtk::ComboBox* init_week_combo(Glib::ustring const& name, tr_quark key);
|
|
|
|
template<typename T>
|
|
T* get_widget(Glib::ustring const& name) const
|
|
{
|
|
return gtr_get_widget<T>(builder_, name);
|
|
}
|
|
|
|
template<typename T, typename... ArgTs>
|
|
T* get_widget_derived(Glib::ustring const& name, ArgTs&&... args) const
|
|
{
|
|
return gtr_get_widget_derived<T>(builder_, name, std::forward<ArgTs>(args)...);
|
|
}
|
|
|
|
template<typename T, typename... ArgTs>
|
|
static void localize_label(T& widget, ArgTs&&... args)
|
|
{
|
|
widget.set_label(fmt::format(fmt::runtime(widget.get_label().raw()), std::forward<ArgTs>(args)...));
|
|
}
|
|
|
|
private:
|
|
bool spun_cb_idle(Gtk::SpinButton& spin, tr_quark key, bool isDouble);
|
|
void spun_cb(Gtk::SpinButton& w, tr_quark key, bool isDouble);
|
|
|
|
void entry_changed_cb(Gtk::Entry& w, tr_quark key);
|
|
|
|
void chosen_cb(PathButton& w, tr_quark key);
|
|
|
|
void onIntComboChanged(Gtk::ComboBox& combo_box, tr_quark key);
|
|
|
|
static auto get_weekday_string(Glib::Date::Weekday weekday);
|
|
|
|
private:
|
|
Glib::RefPtr<Gtk::Builder> const builder_;
|
|
Glib::RefPtr<Session> const core_;
|
|
|
|
std::map<tr_quark, std::pair<std::unique_ptr<Glib::Timer>, sigc::connection>> spin_timers_;
|
|
};
|
|
|
|
PageBase::PageBase(BaseObjectType* cast_item, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core)
|
|
: Gtk::Box(cast_item)
|
|
, builder_(builder)
|
|
, core_(core)
|
|
{
|
|
}
|
|
|
|
PageBase::~PageBase()
|
|
{
|
|
for (auto& [key, info] : spin_timers_)
|
|
{
|
|
info.second.disconnect();
|
|
}
|
|
}
|
|
|
|
Gtk::CheckButton* PageBase::init_check_button(Glib::ustring const& name, tr_quark const key)
|
|
{
|
|
auto* button = get_widget<Gtk::CheckButton>(name);
|
|
button->set_active(gtr_pref_flag_get(key));
|
|
button->signal_toggled().connect([this, button, key]() { core_->set_pref(key, button->get_active()); });
|
|
return button;
|
|
}
|
|
|
|
bool PageBase::spun_cb_idle(Gtk::SpinButton& spin, tr_quark const key, bool isDouble)
|
|
{
|
|
auto const last_change_it = spin_timers_.find(key);
|
|
g_assert(last_change_it != spin_timers_.end());
|
|
|
|
/* has the user stopped making changes? */
|
|
if (last_change_it->second.first->elapsed() < 0.33)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/* update the core */
|
|
if (isDouble)
|
|
{
|
|
core_->set_pref(key, spin.get_value());
|
|
}
|
|
else
|
|
{
|
|
core_->set_pref(key, spin.get_value_as_int());
|
|
}
|
|
|
|
/* cleanup */
|
|
spin_timers_.erase(last_change_it);
|
|
return false;
|
|
}
|
|
|
|
void PageBase::spun_cb(Gtk::SpinButton& w, tr_quark const key, bool isDouble)
|
|
{
|
|
/* user may be spinning through many values, so let's hold off
|
|
for a moment to keep from flooding the core with changes */
|
|
auto last_change_it = spin_timers_.find(key);
|
|
if (last_change_it == spin_timers_.end())
|
|
{
|
|
auto timeout_tag = Glib::signal_timeout().connect_seconds(
|
|
[this, &w, key, isDouble]() { return spun_cb_idle(w, key, isDouble); },
|
|
1);
|
|
last_change_it = spin_timers_.emplace(key, std::pair(std::make_unique<Glib::Timer>(), timeout_tag)).first;
|
|
}
|
|
|
|
last_change_it->second.first->start();
|
|
}
|
|
|
|
Gtk::SpinButton* PageBase::init_spin_button(Glib::ustring const& name, tr_quark const key, int low, int high, int step)
|
|
{
|
|
auto* button = get_widget<Gtk::SpinButton>(name);
|
|
button->set_adjustment(Gtk::Adjustment::create(gtr_pref_int_get(key), low, high, step));
|
|
button->set_digits(0);
|
|
button->signal_value_changed().connect([this, button, key]() { spun_cb(*button, key, false); });
|
|
return button;
|
|
}
|
|
|
|
Gtk::SpinButton* PageBase::init_spin_button_double(
|
|
Glib::ustring const& name,
|
|
tr_quark const key,
|
|
double low,
|
|
double high,
|
|
double step)
|
|
{
|
|
auto* button = get_widget<Gtk::SpinButton>(name);
|
|
button->set_adjustment(Gtk::Adjustment::create(gtr_pref_double_get(key), low, high, step));
|
|
button->set_digits(2);
|
|
button->signal_value_changed().connect([this, button, key]() { spun_cb(*button, key, true); });
|
|
return button;
|
|
}
|
|
|
|
void PageBase::entry_changed_cb(Gtk::Entry& w, tr_quark const key)
|
|
{
|
|
core_->set_pref(key, w.get_text());
|
|
}
|
|
|
|
Gtk::Entry* PageBase::init_entry(Glib::ustring const& name, tr_quark const key)
|
|
{
|
|
auto* const entry = get_widget<Gtk::Entry>(name);
|
|
|
|
if (auto const value = gtr_pref_string_get(key); !value.empty())
|
|
{
|
|
entry->set_text(value);
|
|
}
|
|
|
|
entry->signal_changed().connect([this, entry, key]() { entry_changed_cb(*entry, key); });
|
|
return entry;
|
|
}
|
|
|
|
Gtk::TextView* PageBase::init_text_view(Glib::ustring const& name, tr_quark const key)
|
|
{
|
|
auto* const view = get_widget<Gtk::TextView>(name);
|
|
|
|
auto buffer = view->get_buffer();
|
|
buffer->set_text(gtr_pref_string_get(key));
|
|
|
|
auto const save_buffer = [this, buffer, key]()
|
|
{
|
|
core_->set_pref(key, buffer->get_text());
|
|
};
|
|
|
|
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
|
auto focus_controller = Gtk::EventControllerFocus::create();
|
|
focus_controller->signal_leave().connect(save_buffer);
|
|
view->add_controller(focus_controller);
|
|
#else
|
|
view->add_events(Gdk::FOCUS_CHANGE_MASK);
|
|
view->signal_focus_out_event().connect_notify(sigc::hide<0>(save_buffer));
|
|
#endif
|
|
|
|
return view;
|
|
}
|
|
|
|
void PageBase::chosen_cb(PathButton& w, tr_quark const key)
|
|
{
|
|
core_->set_pref(key, w.get_filename());
|
|
}
|
|
|
|
PathButton* PageBase::init_chooser_button(Glib::ustring const& name, tr_quark const key)
|
|
{
|
|
auto* const button = get_widget_derived<PathButton>(name);
|
|
|
|
if (auto const path = gtr_pref_string_get(key); !path.empty())
|
|
{
|
|
button->set_filename(path);
|
|
}
|
|
|
|
button->signal_selection_changed().connect([this, button, key]() { chosen_cb(*button, key); });
|
|
return button;
|
|
}
|
|
|
|
void PageBase::onIntComboChanged(Gtk::ComboBox& combo_box, tr_quark const key)
|
|
{
|
|
core_->set_pref(key, gtr_combo_box_get_active_enum(combo_box));
|
|
}
|
|
|
|
Gtk::ComboBox* PageBase::init_encryption_combo(Glib::ustring const& name, tr_quark const key)
|
|
{
|
|
auto* const combo = get_widget<Gtk::ComboBox>(name);
|
|
gtr_combo_box_set_enum(
|
|
*combo,
|
|
{
|
|
{ _("Allow encryption"), TR_CLEAR_PREFERRED },
|
|
{ _("Prefer encryption"), TR_ENCRYPTION_PREFERRED },
|
|
{ _("Require encryption"), TR_ENCRYPTION_REQUIRED },
|
|
});
|
|
gtr_combo_box_set_active_enum(*combo, gtr_pref_int_get(key));
|
|
combo->signal_changed().connect([this, combo, key]() { onIntComboChanged(*combo, key); });
|
|
return combo;
|
|
}
|
|
|
|
Gtk::ComboBox* PageBase::init_time_combo(Glib::ustring const& name, tr_quark const key)
|
|
{
|
|
class TimeModelColumns : public Gtk::TreeModelColumnRecord
|
|
{
|
|
public:
|
|
TimeModelColumns() noexcept
|
|
{
|
|
add(offset);
|
|
add(title);
|
|
}
|
|
|
|
Gtk::TreeModelColumn<int> offset;
|
|
Gtk::TreeModelColumn<Glib::ustring> title;
|
|
};
|
|
|
|
static TimeModelColumns const time_cols;
|
|
|
|
/* build a store at 15 minute intervals */
|
|
auto store = Gtk::ListStore::create(time_cols);
|
|
|
|
for (int i = 0; i < 60 * 24; i += 15)
|
|
{
|
|
auto const iter = store->append();
|
|
(*iter)[time_cols.offset] = i;
|
|
(*iter)[time_cols.title] = fmt::format("{:02}:{:02}", i / 60, i % 60);
|
|
}
|
|
|
|
/* build the widget */
|
|
auto* const combo = get_widget<Gtk::ComboBox>(name);
|
|
combo->set_model(store);
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
combo->pack_start(*r, true);
|
|
combo->add_attribute(r->property_text(), time_cols.title);
|
|
combo->set_active(gtr_pref_int_get(key) / 15);
|
|
combo->signal_changed().connect(
|
|
[this, combo, key]()
|
|
{
|
|
if (auto const iter = combo->get_active(); iter)
|
|
{
|
|
core_->set_pref(key, iter->get_value(time_cols.offset));
|
|
}
|
|
});
|
|
return combo;
|
|
}
|
|
|
|
auto PageBase::get_weekday_string(Glib::Date::Weekday weekday)
|
|
{
|
|
auto date = Glib::Date{};
|
|
date.set_time_current();
|
|
date.add_days(static_cast<int>(weekday) - static_cast<int>(date.get_weekday()));
|
|
return date.format_string("%A");
|
|
}
|
|
|
|
Gtk::ComboBox* PageBase::init_week_combo(Glib::ustring const& name, tr_quark const key)
|
|
{
|
|
auto* const combo = get_widget<Gtk::ComboBox>(name);
|
|
gtr_combo_box_set_enum(
|
|
*combo,
|
|
{
|
|
{ _("Every Day"), TR_SCHED_ALL },
|
|
{ _("Weekdays"), TR_SCHED_WEEKDAY },
|
|
{ _("Weekends"), TR_SCHED_WEEKEND },
|
|
{ get_weekday_string(Glib::Date::Weekday::MONDAY), TR_SCHED_MON },
|
|
{ get_weekday_string(Glib::Date::Weekday::TUESDAY), TR_SCHED_TUES },
|
|
{ get_weekday_string(Glib::Date::Weekday::WEDNESDAY), TR_SCHED_WED },
|
|
{ get_weekday_string(Glib::Date::Weekday::THURSDAY), TR_SCHED_THURS },
|
|
{ get_weekday_string(Glib::Date::Weekday::FRIDAY), TR_SCHED_FRI },
|
|
{ get_weekday_string(Glib::Date::Weekday::SATURDAY), TR_SCHED_SAT },
|
|
{ get_weekday_string(Glib::Date::Weekday::SUNDAY), TR_SCHED_SUN },
|
|
});
|
|
gtr_combo_box_set_active_enum(*combo, gtr_pref_int_get(key));
|
|
combo->signal_changed().connect([this, combo, key]() { onIntComboChanged(*combo, key); });
|
|
return combo;
|
|
}
|
|
|
|
/****
|
|
***** Download Tab
|
|
****/
|
|
|
|
class DownloadingPage : public PageBase
|
|
{
|
|
public:
|
|
DownloadingPage(BaseObjectType* cast_item, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core);
|
|
DownloadingPage(DownloadingPage&&) = delete;
|
|
DownloadingPage(DownloadingPage const&) = delete;
|
|
DownloadingPage& operator=(DownloadingPage&&) = delete;
|
|
DownloadingPage& operator=(DownloadingPage const&) = delete;
|
|
~DownloadingPage() override;
|
|
|
|
private:
|
|
void on_core_prefs_changed(tr_quark key);
|
|
|
|
private:
|
|
Glib::RefPtr<Session> const core_;
|
|
|
|
FreeSpaceLabel* freespace_label_ = nullptr;
|
|
|
|
sigc::connection core_prefs_tag_;
|
|
};
|
|
|
|
void DownloadingPage::on_core_prefs_changed(tr_quark const key)
|
|
{
|
|
if (key == TR_KEY_download_dir)
|
|
{
|
|
char const* downloadDir = tr_sessionGetDownloadDir(core_->get_session());
|
|
freespace_label_->set_dir(downloadDir);
|
|
}
|
|
}
|
|
|
|
DownloadingPage::~DownloadingPage()
|
|
{
|
|
core_prefs_tag_.disconnect();
|
|
}
|
|
|
|
DownloadingPage::DownloadingPage(
|
|
BaseObjectType* cast_item,
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
Glib::RefPtr<Session> const& core)
|
|
: PageBase(cast_item, builder, core)
|
|
, core_(core)
|
|
, freespace_label_(get_widget_derived<FreeSpaceLabel>("download_dir_stats_label", core))
|
|
{
|
|
core_prefs_tag_ = core_->signal_prefs_changed().connect(sigc::mem_fun(*this, &DownloadingPage::on_core_prefs_changed));
|
|
|
|
init_check_button("watch_dir_check", TR_KEY_watch_dir_enabled);
|
|
init_chooser_button("watch_dir_chooser", TR_KEY_watch_dir);
|
|
init_check_button("show_options_dialog_check", TR_KEY_show_options_window);
|
|
init_check_button("start_on_add_check", TR_KEY_start_added_torrents);
|
|
init_check_button("trash_on_add_check", TR_KEY_trash_original_torrent_files);
|
|
init_chooser_button("download_dir_chooser", TR_KEY_download_dir);
|
|
init_spin_button("max_active_downloads_spin", TR_KEY_download_queue_size, 0, std::numeric_limits<int>::max(), 1);
|
|
init_spin_button("max_inactive_time_spin", TR_KEY_queue_stalled_minutes, 1, std::numeric_limits<int>::max(), 15);
|
|
init_check_button("append_suffix_to_incomplete_check", TR_KEY_rename_partial_files);
|
|
init_check_button("incomplete_dir_check", TR_KEY_incomplete_dir_enabled);
|
|
init_chooser_button("incomplete_dir_chooser", TR_KEY_incomplete_dir);
|
|
init_check_button("download_done_script_check", TR_KEY_script_torrent_done_enabled);
|
|
init_chooser_button("download_done_script_chooser", TR_KEY_script_torrent_done_filename);
|
|
|
|
on_core_prefs_changed(TR_KEY_download_dir);
|
|
}
|
|
|
|
/****
|
|
***** Torrent Tab
|
|
****/
|
|
|
|
class SeedingPage : public PageBase
|
|
{
|
|
public:
|
|
SeedingPage(BaseObjectType* cast_item, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core);
|
|
SeedingPage(SeedingPage&&) = delete;
|
|
SeedingPage(SeedingPage const&) = delete;
|
|
SeedingPage& operator=(SeedingPage&&) = delete;
|
|
SeedingPage& operator=(SeedingPage const&) = delete;
|
|
~SeedingPage() override = default;
|
|
};
|
|
|
|
SeedingPage::SeedingPage(
|
|
BaseObjectType* cast_item,
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
Glib::RefPtr<Session> const& core)
|
|
: PageBase(cast_item, builder, core)
|
|
{
|
|
init_check_button("stop_seeding_ratio_check", TR_KEY_ratio_limit_enabled);
|
|
init_spin_button_double("stop_seeding_ratio_spin", TR_KEY_ratio_limit, 0, 1000, 0.05);
|
|
init_check_button("stop_seeding_timeout_check", TR_KEY_idle_seeding_limit_enabled);
|
|
init_spin_button("stop_seeding_timeout_spin", TR_KEY_idle_seeding_limit, 1, 40320, 5);
|
|
init_check_button("seeding_done_script_check", TR_KEY_script_torrent_done_seeding_enabled);
|
|
init_chooser_button("seeding_done_script_chooser", TR_KEY_script_torrent_done_seeding_filename);
|
|
}
|
|
|
|
/****
|
|
***** Desktop Tab
|
|
****/
|
|
|
|
class DesktopPage : public PageBase
|
|
{
|
|
public:
|
|
DesktopPage(BaseObjectType* cast_item, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core);
|
|
DesktopPage(DesktopPage&&) = delete;
|
|
DesktopPage(DesktopPage const&) = delete;
|
|
DesktopPage& operator=(DesktopPage&&) = delete;
|
|
DesktopPage& operator=(DesktopPage const&) = delete;
|
|
~DesktopPage() override = default;
|
|
};
|
|
|
|
DesktopPage::DesktopPage(
|
|
BaseObjectType* cast_item,
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
Glib::RefPtr<Session> const& core)
|
|
: PageBase(cast_item, builder, core)
|
|
{
|
|
init_check_button("inhibit_hibernation_check", TR_KEY_inhibit_desktop_hibernation);
|
|
|
|
if (SystemTrayIcon::is_available())
|
|
{
|
|
init_check_button("show_systray_icon_check", TR_KEY_show_notification_area_icon);
|
|
}
|
|
else
|
|
{
|
|
get_widget<Gtk::CheckButton>("show_systray_icon_check")->hide();
|
|
}
|
|
|
|
init_check_button("notify_on_torrent_add_check", TR_KEY_torrent_added_notification_enabled);
|
|
init_check_button("notify_on_torrent_finish_check", TR_KEY_torrent_complete_notification_enabled);
|
|
init_check_button("ding_no_torrent_finish_check", TR_KEY_torrent_complete_sound_enabled);
|
|
}
|
|
|
|
/****
|
|
***** Peer Tab
|
|
****/
|
|
|
|
class PrivacyPage : public PageBase
|
|
{
|
|
static auto const BlocklistUpdateResultDisplayTimeoutInSeconds = 3U;
|
|
|
|
public:
|
|
PrivacyPage(BaseObjectType* cast_item, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core);
|
|
PrivacyPage(PrivacyPage&&) = delete;
|
|
PrivacyPage(PrivacyPage const&) = delete;
|
|
PrivacyPage& operator=(PrivacyPage&&) = delete;
|
|
PrivacyPage& operator=(PrivacyPage const&) = delete;
|
|
~PrivacyPage() override;
|
|
|
|
private:
|
|
void updateBlocklistText();
|
|
void onBlocklistUpdated(bool success);
|
|
void onBlocklistUpdate();
|
|
void on_blocklist_url_changed(Gtk::Editable* e);
|
|
|
|
private:
|
|
Glib::RefPtr<Session> core_;
|
|
|
|
Gtk::Button* updateBlocklistButton_ = nullptr;
|
|
Gtk::Label* label_ = nullptr;
|
|
Gtk::CheckButton* check_ = nullptr;
|
|
|
|
sigc::connection updateBlocklistTag_;
|
|
sigc::connection blocklist_update_result_tag_;
|
|
};
|
|
|
|
void PrivacyPage::updateBlocklistText()
|
|
{
|
|
int const n = tr_blocklistGetRuleCount(core_->get_session());
|
|
auto const msg = fmt::format(
|
|
fmt::runtime(ngettext("Blocklist has {count:L} entry", "Blocklist has {count:L} entries", n)),
|
|
fmt::arg("count", n));
|
|
label_->set_text(msg);
|
|
}
|
|
|
|
/* prefs dialog is being destroyed, so stop listening to blocklist updates */
|
|
PrivacyPage::~PrivacyPage()
|
|
{
|
|
blocklist_update_result_tag_.disconnect();
|
|
updateBlocklistTag_.disconnect();
|
|
}
|
|
|
|
/* core says the blocklist was updated */
|
|
void PrivacyPage::onBlocklistUpdated(bool success)
|
|
{
|
|
updateBlocklistButton_->set_sensitive(true);
|
|
label_->set_text(success ? _("Blocklist updated!") : _("Couldn't update blocklist"));
|
|
|
|
blocklist_update_result_tag_ = Glib::signal_timeout().connect_seconds(
|
|
sigc::bind_return(sigc::mem_fun(*this, &PrivacyPage::updateBlocklistText), false),
|
|
BlocklistUpdateResultDisplayTimeoutInSeconds);
|
|
}
|
|
|
|
/* user pushed a button to update the blocklist */
|
|
void PrivacyPage::onBlocklistUpdate()
|
|
{
|
|
updateBlocklistButton_->set_sensitive(false);
|
|
|
|
label_->set_text(_("Getting new blocklist…"));
|
|
blocklist_update_result_tag_.disconnect();
|
|
|
|
core_->blocklist_update();
|
|
}
|
|
|
|
void PrivacyPage::on_blocklist_url_changed(Gtk::Editable* e)
|
|
{
|
|
auto const url = e->get_chars(0, -1);
|
|
updateBlocklistButton_->set_sensitive(tr_urlIsValid(url.c_str()));
|
|
}
|
|
|
|
PrivacyPage::PrivacyPage(
|
|
BaseObjectType* cast_item,
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
Glib::RefPtr<Session> const& core)
|
|
: PageBase(cast_item, builder, core)
|
|
, core_(core)
|
|
, updateBlocklistButton_(get_widget<Gtk::Button>("update_blocklist_button"))
|
|
, label_(get_widget<Gtk::Label>("blocklist_stats_label"))
|
|
, check_(init_check_button("blocklist_check", TR_KEY_blocklist_enabled))
|
|
{
|
|
init_encryption_combo("encryption_mode_combo", TR_KEY_encryption);
|
|
|
|
auto* const blocklist_url_entry = init_entry("blocklist_url_entry", TR_KEY_blocklist_url);
|
|
|
|
updateBlocklistText();
|
|
updateBlocklistButton_->signal_clicked().connect([this]() { onBlocklistUpdate(); });
|
|
updateBlocklistButton_->set_sensitive(check_->get_active());
|
|
blocklist_url_entry->signal_changed().connect([this, blocklist_url_entry]()
|
|
{ on_blocklist_url_changed(blocklist_url_entry); });
|
|
on_blocklist_url_changed(blocklist_url_entry);
|
|
|
|
init_check_button("blocklist_autoupdate_check", TR_KEY_blocklist_updates_enabled);
|
|
|
|
updateBlocklistTag_ = core_->signal_blocklist_updated().connect(sigc::mem_fun(*this, &PrivacyPage::onBlocklistUpdated));
|
|
}
|
|
|
|
/****
|
|
***** Remote Tab
|
|
****/
|
|
|
|
class RemotePage : public PageBase
|
|
{
|
|
class WhitelistModelColumns : public Gtk::TreeModelColumnRecord
|
|
{
|
|
public:
|
|
WhitelistModelColumns() noexcept
|
|
{
|
|
add(address);
|
|
}
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> address;
|
|
};
|
|
|
|
static WhitelistModelColumns const whitelist_cols;
|
|
|
|
public:
|
|
RemotePage(BaseObjectType* cast_item, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core);
|
|
RemotePage(RemotePage&&) = delete;
|
|
RemotePage(RemotePage const&) = delete;
|
|
RemotePage& operator=(RemotePage&&) = delete;
|
|
RemotePage& operator=(RemotePage const&) = delete;
|
|
~RemotePage() override = default;
|
|
|
|
private:
|
|
void refreshWhitelist();
|
|
void onAddressEdited(Glib::ustring const& path, Glib::ustring const& address);
|
|
void onAddWhitelistClicked();
|
|
void onRemoveWhitelistClicked();
|
|
void refreshRPCSensitivity();
|
|
|
|
static void onLaunchClutchCB();
|
|
|
|
static Glib::RefPtr<Gtk::ListStore> whitelist_tree_model_new(std::string const& whitelist);
|
|
|
|
private:
|
|
Glib::RefPtr<Session> core_;
|
|
|
|
Gtk::TreeView* view_;
|
|
Gtk::Button* remove_button_;
|
|
Gtk::CheckButton* rpc_tb_;
|
|
Gtk::CheckButton* auth_tb_;
|
|
Gtk::CheckButton* whitelist_tb_;
|
|
|
|
Glib::RefPtr<Gtk::ListStore> store_;
|
|
std::vector<Gtk::Widget*> auth_widgets_;
|
|
std::vector<Gtk::Widget*> whitelist_widgets_;
|
|
};
|
|
|
|
RemotePage::WhitelistModelColumns const RemotePage::whitelist_cols;
|
|
|
|
Glib::RefPtr<Gtk::ListStore> RemotePage::whitelist_tree_model_new(std::string const& whitelist)
|
|
{
|
|
auto store = Gtk::ListStore::create(whitelist_cols);
|
|
|
|
std::istringstream stream(whitelist);
|
|
std::string s;
|
|
|
|
while (std::getline(stream, s, ','))
|
|
{
|
|
s = gtr_str_strip(s);
|
|
|
|
if (s.empty())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
auto const iter = store->append();
|
|
(*iter)[whitelist_cols.address] = s;
|
|
}
|
|
|
|
return store;
|
|
}
|
|
|
|
void RemotePage::refreshWhitelist()
|
|
{
|
|
std::ostringstream gstr;
|
|
|
|
for (auto const& row : store_->children())
|
|
{
|
|
gstr << row.get_value(whitelist_cols.address) << ",";
|
|
}
|
|
|
|
auto str = gstr.str();
|
|
if (!str.empty())
|
|
{
|
|
str.resize(str.size() - 1); /* remove the trailing comma */
|
|
}
|
|
|
|
core_->set_pref(TR_KEY_rpc_whitelist, str);
|
|
}
|
|
|
|
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
|
void RemotePage::onAddressEdited(Glib::ustring const& path, Glib::ustring const& address)
|
|
{
|
|
if (auto const iter = store_->get_iter(path); iter)
|
|
{
|
|
(*iter)[whitelist_cols.address] = address;
|
|
}
|
|
|
|
refreshWhitelist();
|
|
}
|
|
|
|
void RemotePage::onAddWhitelistClicked()
|
|
{
|
|
auto const iter = store_->append();
|
|
(*iter)[whitelist_cols.address] = "0.0.0.0";
|
|
|
|
view_->set_cursor(store_->get_path(iter), *view_->get_column(0), true);
|
|
}
|
|
|
|
void RemotePage::onRemoveWhitelistClicked()
|
|
{
|
|
auto const sel = view_->get_selection();
|
|
|
|
if (auto const iter = sel->get_selected(); iter)
|
|
{
|
|
store_->erase(iter);
|
|
refreshWhitelist();
|
|
}
|
|
}
|
|
|
|
void RemotePage::refreshRPCSensitivity()
|
|
{
|
|
bool const rpc_active = rpc_tb_->get_active();
|
|
bool const auth_active = auth_tb_->get_active();
|
|
bool const whitelist_active = whitelist_tb_->get_active();
|
|
auto const sel = view_->get_selection();
|
|
auto const have_addr = sel->get_selected();
|
|
auto const n_rules = store_->children().size();
|
|
|
|
for (auto* const widget : auth_widgets_)
|
|
{
|
|
widget->set_sensitive(rpc_active && auth_active);
|
|
}
|
|
|
|
for (auto* const widget : whitelist_widgets_)
|
|
{
|
|
widget->set_sensitive(rpc_active && whitelist_active);
|
|
}
|
|
|
|
remove_button_->set_sensitive(rpc_active && whitelist_active && have_addr && n_rules > 1);
|
|
}
|
|
|
|
void RemotePage::onLaunchClutchCB()
|
|
{
|
|
gtr_open_uri(fmt::format("http://localhost:{}/", gtr_pref_int_get(TR_KEY_rpc_port)));
|
|
}
|
|
|
|
RemotePage::RemotePage(BaseObjectType* cast_item, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core)
|
|
: PageBase(cast_item, builder, core)
|
|
, core_(core)
|
|
, view_(get_widget<Gtk::TreeView>("rpc_whitelist_view"))
|
|
, remove_button_(get_widget<Gtk::Button>("remove_from_rpc_whistlist_button"))
|
|
, rpc_tb_(init_check_button("enable_rpc_check", TR_KEY_rpc_enabled))
|
|
, auth_tb_(init_check_button("enable_rpc_auth_check", TR_KEY_rpc_authentication_required))
|
|
, whitelist_tb_(init_check_button("rpc_whitelist_check", TR_KEY_rpc_whitelist_enabled))
|
|
{
|
|
rpc_tb_->signal_toggled().connect([this]() { refreshRPCSensitivity(); });
|
|
auto* const open_button = get_widget<Gtk::Button>("open_web_client_button");
|
|
open_button->signal_clicked().connect(&RemotePage::onLaunchClutchCB);
|
|
|
|
init_spin_button("rpc_port_spin", TR_KEY_rpc_port, 0, std::numeric_limits<uint16_t>::max(), 1);
|
|
|
|
auth_tb_->signal_toggled().connect([this]() { refreshRPCSensitivity(); });
|
|
|
|
auto* const username_entry = init_entry("rpc_username_entry", TR_KEY_rpc_username);
|
|
auth_widgets_.push_back(username_entry);
|
|
auth_widgets_.push_back(get_widget<Gtk::Label>("rpc_username_label"));
|
|
|
|
auto* const password_entry = init_entry("rpc_password_entry", TR_KEY_rpc_password);
|
|
auth_widgets_.push_back(password_entry);
|
|
auth_widgets_.push_back(get_widget<Gtk::Label>("rpc_password_label"));
|
|
|
|
whitelist_tb_->signal_toggled().connect([this]() { refreshRPCSensitivity(); });
|
|
|
|
{
|
|
store_ = whitelist_tree_model_new(gtr_pref_string_get(TR_KEY_rpc_whitelist));
|
|
|
|
view_->set_model(store_);
|
|
setup_item_view_button_event_handling(
|
|
*view_,
|
|
{},
|
|
[this](double view_x, double view_y) { return on_item_view_button_released(*view_, view_x, view_y); });
|
|
|
|
whitelist_widgets_.push_back(view_);
|
|
auto const sel = view_->get_selection();
|
|
sel->signal_changed().connect([this]() { refreshRPCSensitivity(); });
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
r->signal_edited().connect(sigc::mem_fun(*this, &RemotePage::onAddressEdited));
|
|
r->property_editable() = true;
|
|
auto* c = Gtk::make_managed<Gtk::TreeViewColumn>("", *r);
|
|
c->add_attribute(r->property_text(), whitelist_cols.address);
|
|
c->set_expand(true);
|
|
view_->append_column(*c);
|
|
|
|
whitelist_widgets_.push_back(get_widget<Gtk::Label>("rpc_whitelist_label"));
|
|
|
|
remove_button_->signal_clicked().connect([this]() { onRemoveWhitelistClicked(); });
|
|
refreshRPCSensitivity();
|
|
auto* add_button = get_widget<Gtk::Button>("add_to_rpc_whitelist_button");
|
|
whitelist_widgets_.push_back(add_button);
|
|
add_button->signal_clicked().connect([this]() { onAddWhitelistClicked(); });
|
|
}
|
|
|
|
refreshRPCSensitivity();
|
|
}
|
|
|
|
/****
|
|
***** Bandwidth Tab
|
|
****/
|
|
|
|
class SpeedPage : public PageBase
|
|
{
|
|
public:
|
|
SpeedPage(BaseObjectType* cast_item, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core);
|
|
SpeedPage(SpeedPage&&) = delete;
|
|
SpeedPage(SpeedPage const&) = delete;
|
|
SpeedPage& operator=(SpeedPage&&) = delete;
|
|
SpeedPage& operator=(SpeedPage const&) = delete;
|
|
~SpeedPage() override = default;
|
|
};
|
|
|
|
SpeedPage::SpeedPage(BaseObjectType* cast_item, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core)
|
|
: PageBase(cast_item, builder, core)
|
|
{
|
|
auto const speed_units_kbyps_str = Speed::units().display_name(Speed::Units::KByps);
|
|
|
|
localize_label(
|
|
*init_check_button("upload_limit_check", TR_KEY_speed_limit_up_enabled),
|
|
fmt::arg("speed_units", speed_units_kbyps_str));
|
|
init_spin_button("upload_limit_spin", TR_KEY_speed_limit_up, 0, std::numeric_limits<int>::max(), 5);
|
|
|
|
localize_label(
|
|
*init_check_button("download_limit_check", TR_KEY_speed_limit_down_enabled),
|
|
fmt::arg("speed_units", speed_units_kbyps_str));
|
|
init_spin_button("download_limit_spin", TR_KEY_speed_limit_down, 0, std::numeric_limits<int>::max(), 5);
|
|
|
|
localize_label(*get_widget<Gtk::Label>("alt_upload_limit_label"), fmt::arg("speed_units", speed_units_kbyps_str));
|
|
init_spin_button("alt_upload_limit_spin", TR_KEY_alt_speed_up, 0, std::numeric_limits<int>::max(), 5);
|
|
|
|
localize_label(*get_widget<Gtk::Label>("alt_download_limit_label"), fmt::arg("speed_units", speed_units_kbyps_str));
|
|
init_spin_button("alt_download_limit_spin", TR_KEY_alt_speed_down, 0, std::numeric_limits<int>::max(), 5);
|
|
|
|
init_time_combo("alt_speed_start_time_combo", TR_KEY_alt_speed_time_begin);
|
|
init_time_combo("alt_speed_end_time_combo", TR_KEY_alt_speed_time_end);
|
|
init_check_button("alt_schedule_time_check", TR_KEY_alt_speed_time_enabled);
|
|
init_week_combo("alt_speed_days_combo", TR_KEY_alt_speed_time_day);
|
|
}
|
|
|
|
/****
|
|
***** Network Tab
|
|
****/
|
|
|
|
class NetworkPage : public PageBase
|
|
{
|
|
public:
|
|
NetworkPage(BaseObjectType* cast_item, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core);
|
|
NetworkPage(NetworkPage&&) = delete;
|
|
NetworkPage(NetworkPage const&) = delete;
|
|
NetworkPage& operator=(NetworkPage&&) = delete;
|
|
NetworkPage& operator=(NetworkPage const&) = delete;
|
|
~NetworkPage() override;
|
|
|
|
private:
|
|
enum PortTestStatus : uint8_t
|
|
{
|
|
PORT_TEST_UNKNOWN = 0U,
|
|
PORT_TEST_CHECKING,
|
|
PORT_TEST_OPEN,
|
|
PORT_TEST_CLOSED,
|
|
PORT_TEST_ERROR
|
|
};
|
|
|
|
void portTestSetSensitive();
|
|
void updatePortStatusText();
|
|
void onCorePrefsChanged(tr_quark key);
|
|
void onPortTested(std::optional<bool> result, Session::PortTestIpProtocol ip_protocol);
|
|
void onPortTest();
|
|
|
|
static std::string_view getPortStatusText(PortTestStatus status) noexcept;
|
|
|
|
private:
|
|
Glib::RefPtr<Session> core_;
|
|
|
|
Gtk::Label* portLabel_ = nullptr;
|
|
Gtk::Button* portButton_ = nullptr;
|
|
Gtk::SpinButton* portSpin_ = nullptr;
|
|
|
|
sigc::connection portTag_;
|
|
sigc::connection prefsTag_;
|
|
|
|
std::array<PortTestStatus, Session::NUM_PORT_TEST_IP_PROTOCOL> portTestStatus_ = {};
|
|
};
|
|
|
|
void NetworkPage::onCorePrefsChanged(tr_quark const key)
|
|
{
|
|
if (key == TR_KEY_peer_port)
|
|
{
|
|
portTestStatus_[Session::PORT_TEST_IPV4] = PORT_TEST_UNKNOWN;
|
|
portTestStatus_[Session::PORT_TEST_IPV6] = PORT_TEST_UNKNOWN;
|
|
updatePortStatusText();
|
|
portTestSetSensitive();
|
|
}
|
|
}
|
|
|
|
NetworkPage::~NetworkPage()
|
|
{
|
|
prefsTag_.disconnect();
|
|
portTag_.disconnect();
|
|
}
|
|
|
|
std::string_view NetworkPage::getPortStatusText(PortTestStatus const status) noexcept
|
|
{
|
|
switch (status)
|
|
{
|
|
case PORT_TEST_UNKNOWN:
|
|
return C_("Port test status", "unknown");
|
|
case PORT_TEST_CHECKING:
|
|
return C_("Port test status", "checking…");
|
|
case PORT_TEST_OPEN:
|
|
return C_("Port test status", "open");
|
|
case PORT_TEST_CLOSED:
|
|
return C_("Port test status", "closed");
|
|
case PORT_TEST_ERROR:
|
|
return C_("Port test status", "error");
|
|
default:
|
|
return {};
|
|
}
|
|
}
|
|
|
|
void NetworkPage::updatePortStatusText()
|
|
{
|
|
auto const status_ipv4 = getPortStatusText(portTestStatus_[Session::PORT_TEST_IPV4]);
|
|
auto const status_ipv6 = getPortStatusText(portTestStatus_[Session::PORT_TEST_IPV6]);
|
|
|
|
portLabel_->set_markup(
|
|
portTestStatus_[Session::PORT_TEST_IPV4] == portTestStatus_[Session::PORT_TEST_IPV6] ?
|
|
fmt::format(fmt::runtime(_("Status: <b>{status}</b>")), fmt::arg("status", status_ipv4)) :
|
|
fmt::format(
|
|
fmt::runtime(_("Status: <b>{status_ipv4}</b> (IPv4), <b>{status_ipv6}</b> (IPv6)")),
|
|
fmt::arg("status_ipv4", status_ipv4),
|
|
fmt::arg("status_ipv6", status_ipv6)));
|
|
}
|
|
|
|
void NetworkPage::portTestSetSensitive()
|
|
{
|
|
// Depend on the RPC call status instead of the UI status, so that the widgets
|
|
// won't be enabled even if the port peer port changed while we have port_test
|
|
// RPC call(s) in-flight.
|
|
auto const sensitive = !core_->port_test_pending(Session::PORT_TEST_IPV4) &&
|
|
!core_->port_test_pending(Session::PORT_TEST_IPV6);
|
|
portButton_->set_sensitive(sensitive);
|
|
portSpin_->set_sensitive(sensitive);
|
|
}
|
|
|
|
void NetworkPage::onPortTested(std::optional<bool> const result, Session::PortTestIpProtocol const ip_protocol)
|
|
{
|
|
auto constexpr ResultToStatus = [](std::optional<bool> const res)
|
|
{
|
|
if (!res)
|
|
{
|
|
return PORT_TEST_ERROR;
|
|
}
|
|
if (!*res)
|
|
{
|
|
return PORT_TEST_CLOSED;
|
|
}
|
|
return PORT_TEST_OPEN;
|
|
};
|
|
|
|
// Only update the UI if the current status is "checking", so that
|
|
// we won't show the port test results for the old peer port if it
|
|
// changed while we have port_test RPC call(s) in-flight.
|
|
if (auto& status = portTestStatus_[ip_protocol]; status == PORT_TEST_CHECKING)
|
|
{
|
|
status = ResultToStatus(result);
|
|
updatePortStatusText();
|
|
}
|
|
portTestSetSensitive();
|
|
}
|
|
|
|
void NetworkPage::onPortTest()
|
|
{
|
|
portTestStatus_[Session::PORT_TEST_IPV4] = PORT_TEST_CHECKING;
|
|
portTestStatus_[Session::PORT_TEST_IPV6] = PORT_TEST_CHECKING;
|
|
updatePortStatusText();
|
|
|
|
if (!portTag_.connected())
|
|
{
|
|
portTag_ = core_->signal_port_tested().connect(
|
|
[this](std::optional<bool> status, Session::PortTestIpProtocol ip_protocol) { onPortTested(status, ip_protocol); });
|
|
}
|
|
|
|
core_->port_test(Session::PORT_TEST_IPV4);
|
|
core_->port_test(Session::PORT_TEST_IPV6);
|
|
|
|
portTestSetSensitive();
|
|
}
|
|
|
|
NetworkPage::NetworkPage(
|
|
BaseObjectType* cast_item,
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
Glib::RefPtr<Session> const& core)
|
|
: PageBase(cast_item, builder, core)
|
|
, core_(core)
|
|
, portLabel_(get_widget<Gtk::Label>("listening_port_status_label"))
|
|
, portButton_(get_widget<Gtk::Button>("test_listening_port_button"))
|
|
, portSpin_(init_spin_button("listening_port_spin", TR_KEY_peer_port, 1, std::numeric_limits<uint16_t>::max(), 1))
|
|
{
|
|
portButton_->signal_clicked().connect([this]() { onPortTest(); });
|
|
updatePortStatusText();
|
|
|
|
prefsTag_ = core_->signal_prefs_changed().connect([this](auto key) { onCorePrefsChanged(key); });
|
|
|
|
init_check_button("pick_random_listening_port_at_start_check", TR_KEY_peer_port_random_on_start);
|
|
init_check_button("enable_listening_port_forwarding_check", TR_KEY_port_forwarding_enabled);
|
|
init_spin_button("max_torrent_peers_spin", TR_KEY_peer_limit_per_torrent, 1, INT_MAX, 5);
|
|
init_spin_button("max_total_peers_spin", TR_KEY_peer_limit_global, 1, INT_MAX, 5);
|
|
|
|
#ifdef WITH_UTP
|
|
init_check_button("enable_utp_check", TR_KEY_utp_enabled);
|
|
#else
|
|
get_widget<Gtk::CheckButton>("enable_utp_check")->hide();
|
|
#endif
|
|
|
|
init_check_button("enable_pex_check", TR_KEY_pex_enabled);
|
|
init_check_button("enable_dht_check", TR_KEY_dht_enabled);
|
|
init_check_button("enable_lpd_check", TR_KEY_lpd_enabled);
|
|
init_text_view("default_trackers_view", TR_KEY_default_trackers);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
/****
|
|
*****
|
|
****/
|
|
|
|
std::unique_ptr<PrefsDialog> PrefsDialog::create(Gtk::Window& parent, Glib::RefPtr<Session> const& core)
|
|
{
|
|
auto const builder = Gtk::Builder::create_from_resource(gtr_get_full_resource_path("PrefsDialog.ui"));
|
|
return std::unique_ptr<PrefsDialog>(gtr_get_widget_derived<PrefsDialog>(builder, "PrefsDialog", parent, core));
|
|
}
|
|
|
|
PrefsDialog::PrefsDialog(
|
|
BaseObjectType* cast_item,
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
Gtk::Window& parent,
|
|
Glib::RefPtr<Session> const& core)
|
|
: Gtk::Dialog(cast_item)
|
|
, impl_(std::make_unique<Impl>(*this, builder, core))
|
|
{
|
|
set_transient_for(parent);
|
|
}
|
|
|
|
PrefsDialog::~PrefsDialog() = default;
|
|
|
|
PrefsDialog::Impl::Impl(PrefsDialog& dialog, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core)
|
|
: dialog_(dialog)
|
|
, core_(core)
|
|
{
|
|
gtr_get_widget_derived<SpeedPage>(builder, "speed_page_layout", core_);
|
|
gtr_get_widget_derived<DownloadingPage>(builder, "downloading_page_layout", core_);
|
|
gtr_get_widget_derived<SeedingPage>(builder, "seeding_page_layout", core_);
|
|
gtr_get_widget_derived<PrivacyPage>(builder, "privacy_page_layout", core_);
|
|
gtr_get_widget_derived<NetworkPage>(builder, "network_page_layout", core_);
|
|
gtr_get_widget_derived<DesktopPage>(builder, "desktop_page_layout", core_);
|
|
gtr_get_widget_derived<RemotePage>(builder, "remote_page_layout", core_);
|
|
|
|
dialog_.signal_response().connect(sigc::mem_fun(*this, &Impl::response_cb));
|
|
}
|