From 460ce7c302c154d78f9537d078a3b81a40a56c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C5=93ur?= Date: Sun, 31 Mar 2024 05:39:44 +0800 Subject: [PATCH] Add start_paused to settings file and daemon (#6728) * Add daemon-startPaused to settings file * code review: naming * "Predefined quarks must be sorted by their string value" * code review: replacing paused_ with tr_variantDictAddBool/tr_variantDictFindBool * code review: doc * Update docs/Editing-Configuration-Files.md Co-authored-by: Yat Ho --------- Co-authored-by: Eugen Beck Co-authored-by: Yat Ho --- daemon/daemon.cc | 8 ++++---- daemon/daemon.h | 1 - docs/Editing-Configuration-Files.md | 9 +++++---- libtransmission/quark.cc | 1 + libtransmission/quark.h | 1 + 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/daemon/daemon.cc b/daemon/daemon.cc index 8c82e09ff..6de4f584f 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -370,6 +370,7 @@ tr_variant load_settings(char const* config_dir) tr_variantDictAddBool(&app_defaults, TR_KEY_watch_dir_enabled, false); tr_variantDictAddBool(&app_defaults, TR_KEY_watch_dir_force_generic, false); tr_variantDictAddBool(&app_defaults, TR_KEY_rpc_enabled, true); + tr_variantDictAddBool(&app_defaults, TR_KEY_start_paused, false); return tr_sessionLoadSettings(&app_defaults, config_dir, MyName); } @@ -428,7 +429,6 @@ bool tr_daemon::parse_args(int argc, char const* const* argv, bool* dump_setting int c; char const* optstr; - paused_ = false; *dump_settings = false; *foreground = false; @@ -562,7 +562,7 @@ bool tr_daemon::parse_args(int argc, char const* const* argv, bool* dump_setting break; case 800: - paused_ = true; + tr_variantDictAddBool(&settings_, TR_KEY_start_paused, true); break; case 910: @@ -768,7 +768,7 @@ int tr_daemon::start([[maybe_unused]] bool foreground) auto watchdir = std::unique_ptr{}; if (auto tmp_bool = false; tr_variantDictFindBool(&settings_, TR_KEY_watch_dir_enabled, &tmp_bool) && tmp_bool) { - auto force_generic = bool{ false }; + auto force_generic = false; (void)tr_variantDictFindBool(&settings_, TR_KEY_watch_dir_force_generic, &force_generic); auto dir = std::string_view{}; @@ -792,7 +792,7 @@ int tr_daemon::start([[maybe_unused]] bool foreground) { tr_ctor* ctor = tr_ctorNew(my_session_); - if (paused_) + if (auto paused = false; tr_variantDictFindBool(&settings_, TR_KEY_start_paused, &paused) && paused) { tr_ctorSetPaused(ctor, TR_FORCE, true); } diff --git a/daemon/daemon.h b/daemon/daemon.h index a25eea529..b679cc6dd 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -46,7 +46,6 @@ private: #ifdef HAVE_SYS_SIGNALFD_H int sigfd_ = -1; #endif /* signalfd API */ - bool paused_ = false; bool seen_hup_ = false; std::string config_dir_; tr_variant settings_ = {}; diff --git a/docs/Editing-Configuration-Files.md b/docs/Editing-Configuration-Files.md index bb6d4a7ed..37c6962fb 100644 --- a/docs/Editing-Configuration-Files.md +++ b/docs/Editing-Configuration-Files.md @@ -79,14 +79,15 @@ Here is a sample of the three basic types: respectively Boolean, Number and Stri * **lpd-enabled:** Boolean (default = false) Enable [Local Peer Discovery (LPD)](https://en.wikipedia.org/wiki/Local_Peer_Discovery). * **message-level:** Number (0 = None, 1 = Critical, 2 = Error, 3 = Warn, 4 = Info, 5 = Debug, 6 = Trace; default = 2) Set verbosity of Transmission's log messages. * **pex-enabled:** Boolean (default = true) Enable [Peer Exchange (PEX)](https://en.wikipedia.org/wiki/Peer_exchange). - * **pidfile:** String Path to file in which daemon PID will be stored (transmission-daemon only) + * **pidfile:** String Path to file in which daemon PID will be stored (_transmission-daemon only_) * **scrape-paused-torrents-enabled:** Boolean (default = true) - * **script-torrent-added-enabled:** Boolean (default = false) Run a script when a torrent is added to Transmission. Environmental variables are passed in as detailed on the [Scripts](./Scripts.md) page + * **script-torrent-added-enabled:** Boolean (default = false) Run a script when a torrent is added to Transmission. Environmental variables are passed in as detailed on the [Scripts](./Scripts.md) page. * **script-torrent-added-filename:** String (default = "") Path to script. - * **script-torrent-done-enabled:** Boolean (default = false) Run a script when a torrent is done downloading. Environmental variables are passed in as detailed on the [Scripts](./Scripts.md) page + * **script-torrent-done-enabled:** Boolean (default = false) Run a script when a torrent is done downloading. Environmental variables are passed in as detailed on the [Scripts](./Scripts.md) page. * **script-torrent-done-filename:** String (default = "") Path to script. - * **script-torrent-done-seeding-enabled:** Boolean (default = false) Run a script when a torrent is done seeding. Environmental variables are passed in as detailed on the [Scripts](./Scripts.md) page + * **script-torrent-done-seeding-enabled:** Boolean (default = false) Run a script when a torrent is done seeding. Environmental variables are passed in as detailed on the [Scripts](./Scripts.md) page. * **script-torrent-done-seeding-filename:** String (default = "") Path to script. + * **start_paused**: Boolean (default = false) Pause the torrents when daemon starts. _Note: transmission-daemon only._ * **tcp-enabled:** Boolean (default = true) Optionally disable TCP connection to other peers. Never disable TCP when you also disable µTP, because then your client would not be able to communicate. Disabling TCP might also break webseeds. Unless you have a good reason, you should not set this to false. * **torrent-added-verify-mode:** String ("fast", "full", default: "fast") Whether newly-added torrents' local data should be fully verified when added, or wait and verify them on-demand later. See [#2626](https://github.com/transmission/transmission/pull/2626) for more discussion. * **utp-enabled:** Boolean (default = true) Enable [Micro Transport Protocol (µTP)](https://en.wikipedia.org/wiki/Micro_Transport_Protocol) diff --git a/libtransmission/quark.cc b/libtransmission/quark.cc index d98546ead..5c8468ffc 100644 --- a/libtransmission/quark.cc +++ b/libtransmission/quark.cc @@ -367,6 +367,7 @@ auto constexpr MyStatic = std::array{ "start-added-torrents"sv, "start-minimized"sv, "startDate"sv, + "start_paused"sv, "status"sv, "statusbar-stats"sv, "tag"sv, diff --git a/libtransmission/quark.h b/libtransmission/quark.h index 3280a8b9b..2ed31649c 100644 --- a/libtransmission/quark.h +++ b/libtransmission/quark.h @@ -368,6 +368,7 @@ enum TR_KEY_start_added_torrents, TR_KEY_start_minimized, TR_KEY_startDate, + TR_KEY_start_paused, TR_KEY_status, TR_KEY_statusbar_stats, TR_KEY_tag,