transmission/qt/Prefs.cc

528 lines
20 KiB
C++
Raw Permalink Normal View History

// 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.
2009-04-09 18:55:47 +00:00
2022-07-26 02:45:54 +00:00
#include <algorithm>
#include <array>
2009-04-09 18:55:47 +00:00
#include <cassert>
#include <string_view>
2022-08-17 16:08:36 +00:00
#include <utility>
2009-04-09 18:55:47 +00:00
2015-06-12 22:12:12 +00:00
#include <QDateTime>
2009-04-09 18:55:47 +00:00
#include <QDir>
#include <QFile>
Qt 6 support (#2069) * Bump minimum Qt version to 5.6 * Switch from QRegExp to QRegularExpression While still available, QRegExp has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Use qIsEffectiveTLD instead of QUrl::topLevelDomain The latter is not part of Qt6::Core. The former is a private utility in Qt6::Network; using it for now, until (and if) we switch to something non-Qt-specific. * Use QStyle::State_Horizontal state when drawing progress bars Although available for a long time, this state either didn't apply to progress bars before Qt 6, or was deduced based on bar size. With Qt 6, failing to specify it results in bad rendering. * Don't use QStringRef (and associated methods) While still available, QStringRef has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. Related method (e.g. QString::midRef) have been removed in Qt 6. * Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate The latter was deprecated and replaced with the former in Qt 5.6. * Don't use QApplication::globalStrut This property has been deprecated in Qt 5.15 and removed in Qt 6. * Use QImage::fromHICON instead of QtWin::fromHICON WinExtras module (providind the latter helper) has been removed in Qt 6. * Use QStringDecoder instead of QTextCodec While still available, QTextCodec has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Don't forward-declare QStringList Instead of being a standalone class, its definition has changed to QList<QString> template specialization in Qt 6. * Use explicit (since Qt 6) QFileInfo constructor * Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t The latter was deprecated in Qt 5.8 and removed in Qt 6. * Don't use QFuture<>'s operator== It has been removed in Qt 6. Since the original issue this code was solving was caused by future reuse, just don't reuse futures and create new finished ones when necessary. * Use std::vector<> instead of QVector<> The latter has been changed to a typedef for QList<>, which might not be what one wants, and which also changed behavior a bit leading to compilation errors. * Don't use + for flags, cast to int explicitly Operator+ for enum values has been deleted in Qt 6, so using operator| instead. Then, there's no conversion from QFlags<> to QVariant, so need to cast to int. * Support Qt 6 in CMake and for MSI packaging * Remove extra (empty) CMake variable use when constructing Qt target names * Simplify logic in tr_qt_add_translation CMake helper Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QStringDecoder>
#else
#include <QTextCodec>
Qt 6 support (#2069) * Bump minimum Qt version to 5.6 * Switch from QRegExp to QRegularExpression While still available, QRegExp has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Use qIsEffectiveTLD instead of QUrl::topLevelDomain The latter is not part of Qt6::Core. The former is a private utility in Qt6::Network; using it for now, until (and if) we switch to something non-Qt-specific. * Use QStyle::State_Horizontal state when drawing progress bars Although available for a long time, this state either didn't apply to progress bars before Qt 6, or was deduced based on bar size. With Qt 6, failing to specify it results in bad rendering. * Don't use QStringRef (and associated methods) While still available, QStringRef has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. Related method (e.g. QString::midRef) have been removed in Qt 6. * Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate The latter was deprecated and replaced with the former in Qt 5.6. * Don't use QApplication::globalStrut This property has been deprecated in Qt 5.15 and removed in Qt 6. * Use QImage::fromHICON instead of QtWin::fromHICON WinExtras module (providind the latter helper) has been removed in Qt 6. * Use QStringDecoder instead of QTextCodec While still available, QTextCodec has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Don't forward-declare QStringList Instead of being a standalone class, its definition has changed to QList<QString> template specialization in Qt 6. * Use explicit (since Qt 6) QFileInfo constructor * Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t The latter was deprecated in Qt 5.8 and removed in Qt 6. * Don't use QFuture<>'s operator== It has been removed in Qt 6. Since the original issue this code was solving was caused by future reuse, just don't reuse futures and create new finished ones when necessary. * Use std::vector<> instead of QVector<> The latter has been changed to a typedef for QList<>, which might not be what one wants, and which also changed behavior a bit leading to compilation errors. * Don't use + for flags, cast to int explicitly Operator+ for enum values has been deleted in Qt 6, so using operator| instead. Then, there's no conversion from QFlags<> to QVariant, so need to cast to int. * Support Qt 6 in CMake and for MSI packaging * Remove extra (empty) CMake variable use when constructing Qt target names * Simplify logic in tr_qt_add_translation CMake helper Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
#endif
2009-04-09 18:55:47 +00:00
#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;
2009-04-09 18:55:47 +00:00
// ---
2009-04-09 18:55:47 +00:00
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",
TR_ARG_TUPLE("-i", "complete-download"),
TR_ARG_TUPLE("-d", "transmission torrent downloaded"),
});
}
} // namespace
std::array<Prefs::PrefItem, Prefs::PREFS_COUNT> const Prefs::Items{
/* gui settings */
2023-02-10 17:58:43 +00:00
PrefItem{ OPTIONS_PROMPT, TR_KEY_show_options_window, QMetaType::Bool },
{ OPEN_DIALOG_FOLDER, TR_KEY_open_dialog_dir, QMetaType::QString },
{ INHIBIT_HIBERNATION, TR_KEY_inhibit_desktop_hibernation, QMetaType::Bool },
{ DIR_WATCH, TR_KEY_watch_dir, QMetaType::QString },
{ DIR_WATCH_ENABLED, TR_KEY_watch_dir_enabled, QMetaType::Bool },
{ SHOW_TRAY_ICON, TR_KEY_show_notification_area_icon, QMetaType::Bool },
{ START_MINIMIZED, TR_KEY_start_minimized, QMetaType::Bool },
{ SHOW_NOTIFICATION_ON_ADD, TR_KEY_torrent_added_notification_enabled, QMetaType::Bool },
{ SHOW_NOTIFICATION_ON_COMPLETE, TR_KEY_torrent_complete_notification_enabled, QMetaType::Bool },
{ ASKQUIT, TR_KEY_prompt_before_exit, QMetaType::Bool },
{ SORT_MODE, TR_KEY_sort_mode, CustomVariantType::SortModeType },
2023-02-10 17:58:43 +00:00
{ SORT_REVERSED, TR_KEY_sort_reversed, QMetaType::Bool },
{ COMPACT_VIEW, TR_KEY_compact_view, QMetaType::Bool },
{ FILTERBAR, TR_KEY_show_filterbar, QMetaType::Bool },
{ STATUSBAR, TR_KEY_show_statusbar, QMetaType::Bool },
{ STATUSBAR_STATS, TR_KEY_statusbar_stats, QMetaType::QString },
{ SHOW_TRACKER_SCRAPES, TR_KEY_show_extra_peer_details, QMetaType::Bool },
{ SHOW_BACKUP_TRACKERS, TR_KEY_show_backup_trackers, QMetaType::Bool },
{ TOOLBAR, TR_KEY_show_toolbar, QMetaType::Bool },
{ BLOCKLIST_DATE, TR_KEY_blocklist_date, QMetaType::QDateTime },
{ BLOCKLIST_UPDATES_ENABLED, TR_KEY_blocklist_updates_enabled, QMetaType::Bool },
{ MAIN_WINDOW_LAYOUT_ORDER, TR_KEY_main_window_layout_order, QMetaType::QString },
{ MAIN_WINDOW_HEIGHT, TR_KEY_main_window_height, QMetaType::Int },
{ MAIN_WINDOW_WIDTH, TR_KEY_main_window_width, QMetaType::Int },
{ MAIN_WINDOW_X, TR_KEY_main_window_x, QMetaType::Int },
{ MAIN_WINDOW_Y, TR_KEY_main_window_y, QMetaType::Int },
{ FILTER_MODE, TR_KEY_filter_mode, CustomVariantType::FilterModeType },
2023-02-10 17:58:43 +00:00
{ FILTER_TRACKERS, TR_KEY_filter_trackers, QMetaType::QString },
{ FILTER_TEXT, TR_KEY_filter_text, QMetaType::QString },
{ SESSION_IS_REMOTE, TR_KEY_remote_session_enabled, QMetaType::Bool },
{ SESSION_REMOTE_HOST, TR_KEY_remote_session_host, QMetaType::QString },
{ SESSION_REMOTE_HTTPS, TR_KEY_remote_session_https, QMetaType::Bool },
{ SESSION_REMOTE_PASSWORD, TR_KEY_remote_session_password, QMetaType::QString },
{ SESSION_REMOTE_PORT, TR_KEY_remote_session_port, QMetaType::Int },
{ SESSION_REMOTE_AUTH, TR_KEY_remote_session_requres_authentication, QMetaType::Bool },
{ SESSION_REMOTE_USERNAME, TR_KEY_remote_session_username, QMetaType::QString },
{ COMPLETE_SOUND_COMMAND, TR_KEY_torrent_complete_sound_command, QMetaType::QStringList },
{ COMPLETE_SOUND_ENABLED, TR_KEY_torrent_complete_sound_enabled, QMetaType::Bool },
{ USER_HAS_GIVEN_INFORMED_CONSENT, TR_KEY_user_has_given_informed_consent, QMetaType::Bool },
{ READ_CLIPBOARD, TR_KEY_read_clipboard, QMetaType::Bool },
/* libtransmission settings */
2023-02-10 17:58:43 +00:00
{ ALT_SPEED_LIMIT_UP, TR_KEY_alt_speed_up, QMetaType::Int },
{ ALT_SPEED_LIMIT_DOWN, TR_KEY_alt_speed_down, QMetaType::Int },
{ ALT_SPEED_LIMIT_ENABLED, TR_KEY_alt_speed_enabled, QMetaType::Bool },
{ ALT_SPEED_LIMIT_TIME_BEGIN, TR_KEY_alt_speed_time_begin, QMetaType::Int },
{ ALT_SPEED_LIMIT_TIME_END, TR_KEY_alt_speed_time_end, QMetaType::Int },
{ ALT_SPEED_LIMIT_TIME_ENABLED, TR_KEY_alt_speed_time_enabled, QMetaType::Bool },
{ ALT_SPEED_LIMIT_TIME_DAY, TR_KEY_alt_speed_time_day, QMetaType::Int },
{ BLOCKLIST_ENABLED, TR_KEY_blocklist_enabled, QMetaType::Bool },
{ BLOCKLIST_URL, TR_KEY_blocklist_url, QMetaType::QString },
{ DEFAULT_TRACKERS, TR_KEY_default_trackers, QMetaType::QString },
{ DSPEED, TR_KEY_speed_limit_down, QMetaType::Int },
{ DSPEED_ENABLED, TR_KEY_speed_limit_down_enabled, QMetaType::Bool },
{ DOWNLOAD_DIR, TR_KEY_download_dir, QMetaType::QString },
{ DOWNLOAD_QUEUE_ENABLED, TR_KEY_download_queue_enabled, QMetaType::Bool },
{ DOWNLOAD_QUEUE_SIZE, TR_KEY_download_queue_size, QMetaType::Int },
{ ENCRYPTION, TR_KEY_encryption, QMetaType::Int },
{ IDLE_LIMIT, TR_KEY_idle_seeding_limit, QMetaType::Int },
{ IDLE_LIMIT_ENABLED, TR_KEY_idle_seeding_limit_enabled, QMetaType::Bool },
{ INCOMPLETE_DIR, TR_KEY_incomplete_dir, QMetaType::QString },
{ INCOMPLETE_DIR_ENABLED, TR_KEY_incomplete_dir_enabled, QMetaType::Bool },
{ MSGLEVEL, TR_KEY_message_level, QMetaType::Int },
{ PEER_LIMIT_GLOBAL, TR_KEY_peer_limit_global, QMetaType::Int },
{ PEER_LIMIT_TORRENT, TR_KEY_peer_limit_per_torrent, QMetaType::Int },
{ PEER_PORT, TR_KEY_peer_port, QMetaType::Int },
{ PEER_PORT_RANDOM_ON_START, TR_KEY_peer_port_random_on_start, QMetaType::Bool },
{ PEER_PORT_RANDOM_LOW, TR_KEY_peer_port_random_low, QMetaType::Int },
{ PEER_PORT_RANDOM_HIGH, TR_KEY_peer_port_random_high, QMetaType::Int },
{ QUEUE_STALLED_MINUTES, TR_KEY_queue_stalled_minutes, QMetaType::Int },
{ SCRIPT_TORRENT_DONE_ENABLED, TR_KEY_script_torrent_done_enabled, QMetaType::Bool },
{ SCRIPT_TORRENT_DONE_FILENAME, TR_KEY_script_torrent_done_filename, QMetaType::QString },
{ SCRIPT_TORRENT_DONE_SEEDING_ENABLED, TR_KEY_script_torrent_done_seeding_enabled, QMetaType::Bool },
{ SCRIPT_TORRENT_DONE_SEEDING_FILENAME, TR_KEY_script_torrent_done_seeding_filename, QMetaType::QString },
{ SOCKET_TOS, TR_KEY_peer_socket_tos, QMetaType::QString },
{ START, TR_KEY_start_added_torrents, QMetaType::Bool },
{ TRASH_ORIGINAL, TR_KEY_trash_original_torrent_files, QMetaType::Bool },
{ PEX_ENABLED, TR_KEY_pex_enabled, QMetaType::Bool },
{ DHT_ENABLED, TR_KEY_dht_enabled, QMetaType::Bool },
{ UTP_ENABLED, TR_KEY_utp_enabled, QMetaType::Bool },
{ LPD_ENABLED, TR_KEY_lpd_enabled, QMetaType::Bool },
{ PORT_FORWARDING, TR_KEY_port_forwarding_enabled, QMetaType::Bool },
{ PREALLOCATION, TR_KEY_preallocation, QMetaType::Int },
{ RATIO, TR_KEY_ratio_limit, QMetaType::Double },
{ RATIO_ENABLED, TR_KEY_ratio_limit_enabled, QMetaType::Bool },
{ RENAME_PARTIAL_FILES, TR_KEY_rename_partial_files, QMetaType::Bool },
{ RPC_AUTH_REQUIRED, TR_KEY_rpc_authentication_required, QMetaType::Bool },
{ RPC_ENABLED, TR_KEY_rpc_enabled, QMetaType::Bool },
{ RPC_PASSWORD, TR_KEY_rpc_password, QMetaType::QString },
{ RPC_PORT, TR_KEY_rpc_port, QMetaType::Int },
{ RPC_USERNAME, TR_KEY_rpc_username, QMetaType::QString },
{ RPC_WHITELIST_ENABLED, TR_KEY_rpc_whitelist_enabled, QMetaType::Bool },
{ RPC_WHITELIST, TR_KEY_rpc_whitelist, QMetaType::QString },
{ USPEED_ENABLED, TR_KEY_speed_limit_up_enabled, QMetaType::Bool },
{ USPEED, TR_KEY_speed_limit_up, QMetaType::Int },
{ UPLOAD_SLOTS_PER_TORRENT, TR_KEY_upload_slots_per_torrent, QMetaType::Int },
2009-04-09 18:55:47 +00:00
};
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)
{
Qt 6 support (#2069) * Bump minimum Qt version to 5.6 * Switch from QRegExp to QRegularExpression While still available, QRegExp has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Use qIsEffectiveTLD instead of QUrl::topLevelDomain The latter is not part of Qt6::Core. The former is a private utility in Qt6::Network; using it for now, until (and if) we switch to something non-Qt-specific. * Use QStyle::State_Horizontal state when drawing progress bars Although available for a long time, this state either didn't apply to progress bars before Qt 6, or was deduced based on bar size. With Qt 6, failing to specify it results in bad rendering. * Don't use QStringRef (and associated methods) While still available, QStringRef has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. Related method (e.g. QString::midRef) have been removed in Qt 6. * Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate The latter was deprecated and replaced with the former in Qt 5.6. * Don't use QApplication::globalStrut This property has been deprecated in Qt 5.15 and removed in Qt 6. * Use QImage::fromHICON instead of QtWin::fromHICON WinExtras module (providind the latter helper) has been removed in Qt 6. * Use QStringDecoder instead of QTextCodec While still available, QTextCodec has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Don't forward-declare QStringList Instead of being a standalone class, its definition has changed to QList<QString> template specialization in Qt 6. * Use explicit (since Qt 6) QFileInfo constructor * Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t The latter was deprecated in Qt 5.8 and removed in Qt 6. * Don't use QFuture<>'s operator== It has been removed in Qt 6. Since the original issue this code was solving was caused by future reuse, just don't reuse futures and create new finished ones when necessary. * Use std::vector<> instead of QVector<> The latter has been changed to a typedef for QList<>, which might not be what one wants, and which also changed behavior a bit leading to compilation errors. * Don't use + for flags, cast to int explicitly Operator+ for enum values has been deleted in Qt 6, so using operator| instead. Then, there's no conversion from QFlags<> to QVariant, so need to cast to int. * Support Qt 6 in CMake and for MSI packaging * Remove extra (empty) CMake variable use when constructing Qt target names * Simplify logic in tr_qt_add_translation CMake helper Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
auto decoder = QStringDecoder{ QStringConverter::Utf8, QStringConverter::Flag::Stateless };
auto const text = QString{ decoder.decode(byteArray) };
Qt 6 support (#2069) * Bump minimum Qt version to 5.6 * Switch from QRegExp to QRegularExpression While still available, QRegExp has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Use qIsEffectiveTLD instead of QUrl::topLevelDomain The latter is not part of Qt6::Core. The former is a private utility in Qt6::Network; using it for now, until (and if) we switch to something non-Qt-specific. * Use QStyle::State_Horizontal state when drawing progress bars Although available for a long time, this state either didn't apply to progress bars before Qt 6, or was deduced based on bar size. With Qt 6, failing to specify it results in bad rendering. * Don't use QStringRef (and associated methods) While still available, QStringRef has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. Related method (e.g. QString::midRef) have been removed in Qt 6. * Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate The latter was deprecated and replaced with the former in Qt 5.6. * Don't use QApplication::globalStrut This property has been deprecated in Qt 5.15 and removed in Qt 6. * Use QImage::fromHICON instead of QtWin::fromHICON WinExtras module (providind the latter helper) has been removed in Qt 6. * Use QStringDecoder instead of QTextCodec While still available, QTextCodec has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Don't forward-declare QStringList Instead of being a standalone class, its definition has changed to QList<QString> template specialization in Qt 6. * Use explicit (since Qt 6) QFileInfo constructor * Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t The latter was deprecated in Qt 5.8 and removed in Qt 6. * Don't use QFuture<>'s operator== It has been removed in Qt 6. Since the original issue this code was solving was caused by future reuse, just don't reuse futures and create new finished ones when necessary. * Use std::vector<> instead of QVector<> The latter has been changed to a typedef for QList<>, which might not be what one wants, and which also changed behavior a bit leading to compilation errors. * Don't use + for flags, cast to int explicitly Operator+ for enum values has been deleted in Qt 6, so using operator| instead. Then, there's no conversion from QFlags<> to QVariant, so need to cast to int. * Support Qt 6 in CMake and for MSI packaging * Remove extra (empty) CMake variable use when constructing Qt target names * Simplify logic in tr_qt_add_translation CMake helper Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
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;
Qt 6 support (#2069) * Bump minimum Qt version to 5.6 * Switch from QRegExp to QRegularExpression While still available, QRegExp has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Use qIsEffectiveTLD instead of QUrl::topLevelDomain The latter is not part of Qt6::Core. The former is a private utility in Qt6::Network; using it for now, until (and if) we switch to something non-Qt-specific. * Use QStyle::State_Horizontal state when drawing progress bars Although available for a long time, this state either didn't apply to progress bars before Qt 6, or was deduced based on bar size. With Qt 6, failing to specify it results in bad rendering. * Don't use QStringRef (and associated methods) While still available, QStringRef has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. Related method (e.g. QString::midRef) have been removed in Qt 6. * Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate The latter was deprecated and replaced with the former in Qt 5.6. * Don't use QApplication::globalStrut This property has been deprecated in Qt 5.15 and removed in Qt 6. * Use QImage::fromHICON instead of QtWin::fromHICON WinExtras module (providind the latter helper) has been removed in Qt 6. * Use QStringDecoder instead of QTextCodec While still available, QTextCodec has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Don't forward-declare QStringList Instead of being a standalone class, its definition has changed to QList<QString> template specialization in Qt 6. * Use explicit (since Qt 6) QFileInfo constructor * Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t The latter was deprecated in Qt 5.8 and removed in Qt 6. * Don't use QFuture<>'s operator== It has been removed in Qt 6. Since the original issue this code was solving was caused by future reuse, just don't reuse futures and create new finished ones when necessary. * Use std::vector<> instead of QVector<> The latter has been changed to a typedef for QList<>, which might not be what one wants, and which also changed behavior a bit leading to compilation errors. * Don't use + for flags, cast to int explicitly Operator+ for enum values has been deleted in Qt 6, so using operator| instead. Then, there's no conversion from QFlags<> to QVariant, so need to cast to int. * Support Qt 6 in CMake and for MSI packaging * Remove extra (empty) CMake variable use when constructing Qt target names * Simplify logic in tr_qt_add_translation CMake helper Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
#endif
}
fix: more clang-tidy warnings (#6608) * fix: readability-redundant-casting warnings in gtk * fix: bugprone-move-forwarding-reference warnings in gtk * fix: readability-redundant-casting warnings in qt * fix: bugprone-switch-missing-default-case warnings in qt * fix: readability-use-std-min-max warning in qt client * fix: readability-static-accessed-through-instance warning in qt client * fix: cppcoreguidelines-avoid-const-or-ref-data-members warning in qt client * fix: readability-avoid-nested-conditional-operator warning in qt client * fixup! fix: readability-use-std-min-max warning in qt client * fix: readability-redundant-member-init warnings in gtk client * fix: performance-avoid-endl warnings in gtk client * chore: disable readability-qualified-auto too many false warnings * chore: disable cppcoreguidelines-avoid-const-or-ref-data-members * chore: fix readability-duplicate-include warning in gtk client * chore: fix modernize-use-nodiscard warning in gtk client * chore: fix readability-convert-member-functions-to-static warning in gtk client * fixup! fix: bugprone-move-forwarding-reference warnings in gtk * chore: fix performance-enum-size warning in gtk client * fix: cppcoreguidelines-prefer-member-initializer warning in gtk client * fix: readability-identifier-naming warning in qt client * Revert "chore: fix performance-enum-size warning in gtk client" This reverts commit 5ce6b562f849c2499fa34f4d903234f1945f9c3e. * fix: readability-redundant-member-init warning in move tests * fix: readability-redundant-casting warnings in tests * fixup! fix: readability-identifier-naming warning in qt client * fixup! fix: readability-avoid-nested-conditional-operator warning in qt client * fix: readability-static-accessed-through-instance warning in qt client * fix: readability-redundant-casting warning in watchdir tests
2024-02-17 19:31:49 +00:00
[[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
2009-04-09 18:55:47 +00:00
/***
****
***/
Prefs::Prefs(QString config_dir)
: config_dir_{ std::move(config_dir) }
2009-04-09 18:55:47 +00:00
{
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)
2009-04-09 18:55:47 +00:00
{
tr_variant const* b = tr_variantDictFind(&settings, Items[i].key);
switch (Items[i].type)
2009-04-09 18:55:47 +00:00
{
2023-02-10 17:58:43 +00:00
case QMetaType::Int:
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
if (auto const value = getValue<int64_t>(b); value)
{
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
values_[i].setValue(*value);
}
break;
case CustomVariantType::SortModeType:
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
if (auto const value = getValue<std::string_view>(b); value)
{
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
auto const test = [&value](auto const& item)
{
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
return item.second == *value;
};
// NOLINTNEXTLINE(readability-qualified-auto)
auto const it = std::find_if(std::cbegin(SortModes), std::cend(SortModes), test);
2022-11-29 00:26:03 +00:00
auto const& [mode, mode_str] = it == std::end(SortModes) ? SortModes.front() : *it;
values_[i] = QVariant::fromValue(SortMode{ mode });
}
break;
case CustomVariantType::FilterModeType:
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
if (auto const value = getValue<std::string_view>(b); value)
{
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
auto const test = [&value](auto const& item)
{
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
return item.second == *value;
};
// NOLINTNEXTLINE(readability-qualified-auto)
auto const it = std::find_if(std::cbegin(FilterModes), std::cend(FilterModes), test);
2022-11-29 00:26:03 +00:00
auto const& [mode, mode_str] = it == std::end(FilterModes) ? FilterModes.front() : *it;
values_[i] = QVariant::fromValue(FilterMode{ mode });
}
break;
2023-02-10 17:58:43 +00:00
case QMetaType::QString:
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
if (auto const value = getValue<QString>(b); value)
{
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
values_[i].setValue(*value);
}
break;
2023-02-10 17:58:43 +00:00
case QMetaType::QStringList:
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
if (auto const value = getValue<QStringList>(b); value)
{
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
values_[i].setValue(*value);
}
break;
2023-02-10 17:58:43 +00:00
case QMetaType::Bool:
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
if (auto const value = getValue<bool>(b); value)
{
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
values_[i].setValue(*value);
}
break;
2023-02-10 17:58:43 +00:00
case QMetaType::Double:
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
if (auto const value = getValue<double>(b); value)
{
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
values_[i].setValue(*value);
}
break;
2023-02-10 17:58:43 +00:00
case QMetaType::QDateTime:
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
if (auto const value = getValue<time_t>(b); value)
{
Qt 6 support (#2069) * Bump minimum Qt version to 5.6 * Switch from QRegExp to QRegularExpression While still available, QRegExp has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Use qIsEffectiveTLD instead of QUrl::topLevelDomain The latter is not part of Qt6::Core. The former is a private utility in Qt6::Network; using it for now, until (and if) we switch to something non-Qt-specific. * Use QStyle::State_Horizontal state when drawing progress bars Although available for a long time, this state either didn't apply to progress bars before Qt 6, or was deduced based on bar size. With Qt 6, failing to specify it results in bad rendering. * Don't use QStringRef (and associated methods) While still available, QStringRef has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. Related method (e.g. QString::midRef) have been removed in Qt 6. * Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate The latter was deprecated and replaced with the former in Qt 5.6. * Don't use QApplication::globalStrut This property has been deprecated in Qt 5.15 and removed in Qt 6. * Use QImage::fromHICON instead of QtWin::fromHICON WinExtras module (providind the latter helper) has been removed in Qt 6. * Use QStringDecoder instead of QTextCodec While still available, QTextCodec has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Don't forward-declare QStringList Instead of being a standalone class, its definition has changed to QList<QString> template specialization in Qt 6. * Use explicit (since Qt 6) QFileInfo constructor * Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t The latter was deprecated in Qt 5.8 and removed in Qt 6. * Don't use QFuture<>'s operator== It has been removed in Qt 6. Since the original issue this code was solving was caused by future reuse, just don't reuse futures and create new finished ones when necessary. * Use std::vector<> instead of QVector<> The latter has been changed to a typedef for QList<>, which might not be what one wants, and which also changed behavior a bit leading to compilation errors. * Don't use + for flags, cast to int explicitly Operator+ for enum values has been deleted in Qt 6, so using operator| instead. Then, there's no conversion from QFlags<> to QVariant, so need to cast to int. * Support Qt 6 in CMake and for MSI packaging * Remove extra (empty) CMake variable use when constructing Qt target names * Simplify logic in tr_qt_add_translation CMake helper Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
values_[i].setValue(QDateTime::fromSecsSinceEpoch(*value));
Qt 6 support (#2069) * Bump minimum Qt version to 5.6 * Switch from QRegExp to QRegularExpression While still available, QRegExp has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Use qIsEffectiveTLD instead of QUrl::topLevelDomain The latter is not part of Qt6::Core. The former is a private utility in Qt6::Network; using it for now, until (and if) we switch to something non-Qt-specific. * Use QStyle::State_Horizontal state when drawing progress bars Although available for a long time, this state either didn't apply to progress bars before Qt 6, or was deduced based on bar size. With Qt 6, failing to specify it results in bad rendering. * Don't use QStringRef (and associated methods) While still available, QStringRef has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. Related method (e.g. QString::midRef) have been removed in Qt 6. * Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate The latter was deprecated and replaced with the former in Qt 5.6. * Don't use QApplication::globalStrut This property has been deprecated in Qt 5.15 and removed in Qt 6. * Use QImage::fromHICON instead of QtWin::fromHICON WinExtras module (providind the latter helper) has been removed in Qt 6. * Use QStringDecoder instead of QTextCodec While still available, QTextCodec has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Don't forward-declare QStringList Instead of being a standalone class, its definition has changed to QList<QString> template specialization in Qt 6. * Use explicit (since Qt 6) QFileInfo constructor * Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t The latter was deprecated in Qt 5.8 and removed in Qt 6. * Don't use QFuture<>'s operator== It has been removed in Qt 6. Since the original issue this code was solving was caused by future reuse, just don't reuse futures and create new finished ones when necessary. * Use std::vector<> instead of QVector<> The latter has been changed to a typedef for QList<>, which might not be what one wants, and which also changed behavior a bit leading to compilation errors. * Don't use + for flags, cast to int explicitly Operator+ for enum values has been deleted in Qt 6, so using operator| instead. Then, there's no conversion from QFlags<> to QVariant, so need to cast to int. * Support Qt 6 in CMake and for MSI packaging * Remove extra (empty) CMake variable use when constructing Qt target names * Simplify logic in tr_qt_add_translation CMake helper Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
#else
fix: sonarcloud (#2865) * refactor: implement FileTreeItem::children_ with a std::vector * fix: std::move should not be called on forwarding reference * fix: uninitialized scalar variable * fix: unchecked return value from library * fix: dereference before null check * fix: unchecked return value from library * fix: unchecked return value from library * fixup! refactor: implement FileTreeItem::children_ with a std::vector * fix: signed-unsigned comparison in libtransmission tests * fix: avoid unnecessary copy by using const reference * fix: function should be declared const * refactor: use fmt::format to build log timestamps * fix: use init-statement to reduce variable scope * fixup! refactor: use fmt::format to build log timestamps * fix: remove tau_tracker destructor for rule-of-zero * fix: remove tr_peerIo destructor for rule-of-zero * Revert "fix: dereference before null check" This reverts commit cd789678156bb987a8dc6b2eb49cb1db4195d441. * fix: signed-unsigned comparison in libtransmission tests * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: extract nested code block into separate method * fix: use init-statement to reduce variable scope * fix: extract nested code block into separate method * fix: signed-unsigned comparison in libtransmission tests * fixup! fix: extract nested code block into separate method * fix: mark possibly-unused as [[maybe_unused]] * fix: invalid stack memory reference in tr_found_file_t * fix: signed-unsigned comparison in libtransmission tests
2022-04-02 14:06:02 +00:00
values_[i].setValue(QDateTime::fromTime_t(*value));
Qt 6 support (#2069) * Bump minimum Qt version to 5.6 * Switch from QRegExp to QRegularExpression While still available, QRegExp has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Use qIsEffectiveTLD instead of QUrl::topLevelDomain The latter is not part of Qt6::Core. The former is a private utility in Qt6::Network; using it for now, until (and if) we switch to something non-Qt-specific. * Use QStyle::State_Horizontal state when drawing progress bars Although available for a long time, this state either didn't apply to progress bars before Qt 6, or was deduced based on bar size. With Qt 6, failing to specify it results in bad rendering. * Don't use QStringRef (and associated methods) While still available, QStringRef has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. Related method (e.g. QString::midRef) have been removed in Qt 6. * Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate The latter was deprecated and replaced with the former in Qt 5.6. * Don't use QApplication::globalStrut This property has been deprecated in Qt 5.15 and removed in Qt 6. * Use QImage::fromHICON instead of QtWin::fromHICON WinExtras module (providind the latter helper) has been removed in Qt 6. * Use QStringDecoder instead of QTextCodec While still available, QTextCodec has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Don't forward-declare QStringList Instead of being a standalone class, its definition has changed to QList<QString> template specialization in Qt 6. * Use explicit (since Qt 6) QFileInfo constructor * Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t The latter was deprecated in Qt 5.8 and removed in Qt 6. * Don't use QFuture<>'s operator== It has been removed in Qt 6. Since the original issue this code was solving was caused by future reuse, just don't reuse futures and create new finished ones when necessary. * Use std::vector<> instead of QVector<> The latter has been changed to a typedef for QList<>, which might not be what one wants, and which also changed behavior a bit leading to compilation errors. * Don't use + for flags, cast to int explicitly Operator+ for enum values has been deleted in Qt 6, so using operator| instead. Then, there's no conversion from QFlags<> to QVariant, so need to cast to int. * Support Qt 6 in CMake and for MSI packaging * Remove extra (empty) CMake variable use when constructing Qt target names * Simplify logic in tr_qt_add_translation CMake helper Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
#endif
}
break;
default:
assert(false && "unhandled type");
break;
2009-04-09 18:55:47 +00:00
}
}
}
Prefs::~Prefs()
2009-04-09 18:55:47 +00:00
{
// make a dict from settings.json
tr_variant current_settings;
tr_variantInitDict(&current_settings, PREFS_COUNT);
for (int i = 0; i < PREFS_COUNT; ++i)
{
fix: more clang-tidy warnings (#6608) * fix: readability-redundant-casting warnings in gtk * fix: bugprone-move-forwarding-reference warnings in gtk * fix: readability-redundant-casting warnings in qt * fix: bugprone-switch-missing-default-case warnings in qt * fix: readability-use-std-min-max warning in qt client * fix: readability-static-accessed-through-instance warning in qt client * fix: cppcoreguidelines-avoid-const-or-ref-data-members warning in qt client * fix: readability-avoid-nested-conditional-operator warning in qt client * fixup! fix: readability-use-std-min-max warning in qt client * fix: readability-redundant-member-init warnings in gtk client * fix: performance-avoid-endl warnings in gtk client * chore: disable readability-qualified-auto too many false warnings * chore: disable cppcoreguidelines-avoid-const-or-ref-data-members * chore: fix readability-duplicate-include warning in gtk client * chore: fix modernize-use-nodiscard warning in gtk client * chore: fix readability-convert-member-functions-to-static warning in gtk client * fixup! fix: bugprone-move-forwarding-reference warnings in gtk * chore: fix performance-enum-size warning in gtk client * fix: cppcoreguidelines-prefer-member-initializer warning in gtk client * fix: readability-identifier-naming warning in qt client * Revert "chore: fix performance-enum-size warning in gtk client" This reverts commit 5ce6b562f849c2499fa34f4d903234f1945f9c3e. * fix: readability-redundant-member-init warning in move tests * fix: readability-redundant-casting warnings in tests * fixup! fix: readability-identifier-naming warning in qt client * fixup! fix: readability-avoid-nested-conditional-operator warning in qt client * fix: readability-static-accessed-through-instance warning in qt client * fix: readability-redundant-casting warning in watchdir tests
2024-02-17 19:31:49 +00:00
if (!prefIsSavable(i))
{
continue;
}
tr_quark const key = Items[i].key;
QVariant const& val = values_[i];
switch (Items[i].type)
{
2023-02-10 17:58:43 +00:00
case QMetaType::Int:
dictAdd(&current_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);
2022-11-29 00:26:03 +00:00
auto const& [mode_val, mode_str] = it == std::end(SortModes) ? SortModes.front() : *it;
dictAdd(&current_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);
2022-11-29 00:26:03 +00:00
auto const& [mode_val, mode_str] = it == std::end(FilterModes) ? FilterModes.front() : *it;
dictAdd(&current_settings, key, mode_str);
break;
}
2023-02-10 17:58:43 +00:00
case QMetaType::QString:
dictAdd(&current_settings, key, val.toString());
break;
2023-02-10 17:58:43 +00:00
case QMetaType::QStringList:
dictAdd(&current_settings, key, val.toStringList());
break;
2023-02-10 17:58:43 +00:00
case QMetaType::Bool:
dictAdd(&current_settings, key, val.toBool());
break;
2023-02-10 17:58:43 +00:00
case QMetaType::Double:
dictAdd(&current_settings, key, val.toDouble());
break;
2023-02-10 17:58:43 +00:00
case QMetaType::QDateTime:
Qt 6 support (#2069) * Bump minimum Qt version to 5.6 * Switch from QRegExp to QRegularExpression While still available, QRegExp has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Use qIsEffectiveTLD instead of QUrl::topLevelDomain The latter is not part of Qt6::Core. The former is a private utility in Qt6::Network; using it for now, until (and if) we switch to something non-Qt-specific. * Use QStyle::State_Horizontal state when drawing progress bars Although available for a long time, this state either didn't apply to progress bars before Qt 6, or was deduced based on bar size. With Qt 6, failing to specify it results in bad rendering. * Don't use QStringRef (and associated methods) While still available, QStringRef has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. Related method (e.g. QString::midRef) have been removed in Qt 6. * Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate The latter was deprecated and replaced with the former in Qt 5.6. * Don't use QApplication::globalStrut This property has been deprecated in Qt 5.15 and removed in Qt 6. * Use QImage::fromHICON instead of QtWin::fromHICON WinExtras module (providind the latter helper) has been removed in Qt 6. * Use QStringDecoder instead of QTextCodec While still available, QTextCodec has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Don't forward-declare QStringList Instead of being a standalone class, its definition has changed to QList<QString> template specialization in Qt 6. * Use explicit (since Qt 6) QFileInfo constructor * Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t The latter was deprecated in Qt 5.8 and removed in Qt 6. * Don't use QFuture<>'s operator== It has been removed in Qt 6. Since the original issue this code was solving was caused by future reuse, just don't reuse futures and create new finished ones when necessary. * Use std::vector<> instead of QVector<> The latter has been changed to a typedef for QList<>, which might not be what one wants, and which also changed behavior a bit leading to compilation errors. * Don't use + for flags, cast to int explicitly Operator+ for enum values has been deleted in Qt 6, so using operator| instead. Then, there's no conversion from QFlags<> to QVariant, so need to cast to int. * Support Qt 6 in CMake and for MSI packaging * Remove extra (empty) CMake variable use when constructing Qt target names * Simplify logic in tr_qt_add_translation CMake helper Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
dictAdd(&current_settings, key, int64_t{ val.toDateTime().toSecsSinceEpoch() });
#else
dictAdd(&current_settings, key, val.toDateTime().toTime_t());
Qt 6 support (#2069) * Bump minimum Qt version to 5.6 * Switch from QRegExp to QRegularExpression While still available, QRegExp has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Use qIsEffectiveTLD instead of QUrl::topLevelDomain The latter is not part of Qt6::Core. The former is a private utility in Qt6::Network; using it for now, until (and if) we switch to something non-Qt-specific. * Use QStyle::State_Horizontal state when drawing progress bars Although available for a long time, this state either didn't apply to progress bars before Qt 6, or was deduced based on bar size. With Qt 6, failing to specify it results in bad rendering. * Don't use QStringRef (and associated methods) While still available, QStringRef has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. Related method (e.g. QString::midRef) have been removed in Qt 6. * Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate The latter was deprecated and replaced with the former in Qt 5.6. * Don't use QApplication::globalStrut This property has been deprecated in Qt 5.15 and removed in Qt 6. * Use QImage::fromHICON instead of QtWin::fromHICON WinExtras module (providind the latter helper) has been removed in Qt 6. * Use QStringDecoder instead of QTextCodec While still available, QTextCodec has been moved to Qt6::Core5Compat module and is not part of Qt6::Core. * Don't forward-declare QStringList Instead of being a standalone class, its definition has changed to QList<QString> template specialization in Qt 6. * Use explicit (since Qt 6) QFileInfo constructor * Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t The latter was deprecated in Qt 5.8 and removed in Qt 6. * Don't use QFuture<>'s operator== It has been removed in Qt 6. Since the original issue this code was solving was caused by future reuse, just don't reuse futures and create new finished ones when necessary. * Use std::vector<> instead of QVector<> The latter has been changed to a typedef for QList<>, which might not be what one wants, and which also changed behavior a bit leading to compilation errors. * Don't use + for flags, cast to int explicitly Operator+ for enum values has been deleted in Qt 6, so using operator| instead. Then, there's no conversion from QFlags<> to QVariant, so need to cast to int. * Support Qt 6 in CMake and for MSI packaging * Remove extra (empty) CMake variable use when constructing Qt target names * Simplify logic in tr_qt_add_translation CMake helper Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
#endif
break;
default:
assert(false && "unhandled type");
break;
2009-04-09 18:55:47 +00:00
}
}
// update settings.json with our settings
2023-08-17 16:02:45 +00:00
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 = serde.parse_file(filename);
if (!settings)
{
2023-08-17 16:02:45 +00:00
auto empty_dict = tr_variant{};
tr_variantInitDict(&empty_dict, PREFS_COUNT);
settings = std::move(empty_dict);
}
2023-08-17 16:02:45 +00:00
tr_variantMergeDicts(&*settings, &current_settings);
serde.to_file(*settings, filename);
2009-04-09 18:55:47 +00:00
}
/**
* 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()
2009-04-09 18:55:47 +00:00
{
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_requres_authentication, false);
settings.try_emplace(TR_KEY_show_backup_trackers, false);
settings.try_emplace(TR_KEY_show_extra_peer_details, 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, TR_DEFAULT_RPC_PORT);
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);
return tr_variant{ std::move(settings) };
2009-04-09 18:55:47 +00:00
}
/***
****
***/
bool Prefs::getBool(int key) const
2009-04-09 18:55:47 +00:00
{
2023-02-10 17:58:43 +00:00
assert(Items[key].type == QMetaType::Bool);
return values_[key].toBool();
2009-04-09 18:55:47 +00:00
}
QString Prefs::getString(int key) const
2009-04-09 18:55:47 +00:00
{
2023-02-10 17:58:43 +00:00
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();
2009-04-09 18:55:47 +00:00
}
int Prefs::getInt(int key) const
2009-04-09 18:55:47 +00:00
{
2023-02-10 17:58:43 +00:00
assert(Items[key].type == QMetaType::Int);
return values_[key].toInt();
2009-04-09 18:55:47 +00:00
}
double Prefs::getDouble(int key) const
2009-04-09 18:55:47 +00:00
{
2023-02-10 17:58:43 +00:00
assert(Items[key].type == QMetaType::Double);
return values_[key].toDouble();
2009-04-09 18:55:47 +00:00
}
QDateTime Prefs::getDateTime(int key) const
2009-04-09 18:55:47 +00:00
{
2023-02-10 17:58:43 +00:00
assert(Items[key].type == QMetaType::QDateTime);
return values_[key].toDateTime();
2009-04-09 18:55:47 +00:00
}
// ---
2009-04-09 18:55:47 +00:00
void Prefs::toggleBool(int key)
2009-04-09 18:55:47 +00:00
{
set(key, !getBool(key));
2009-04-09 18:55:47 +00:00
}