Debian Codegraph @

src/librssguard/miscellaneous/settings.cpp

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #include "miscellaneous/settings.h"
4
5 #include "miscellaneous/application.h"
6 #include "miscellaneous/iofactory.h"
7
8 #include <QDebug>
9 #include <QDir>
10 #include <QLocale>
11 #include <QPointer>
12
13 #if defined(NO_LITE)
14 // WebEngine.
15 DKEY WebEngineAttributes::ID = "web_engine_attributes";
16 #endif
17
18 DKEY FileDialogPaths::ID = "file_dialog_paths";
19
20 DKEY DialogGeometries::ID = "dialog_geometries";
21
22 // Media player.
23 KEY VideoPlayer::ID = "media_player";
24
25 DKEY VideoPlayer::MpvUseCustomConfigFolder = "mpv_use_custom_config_folder";
26 DVALUE(bool) VideoPlayer::MpvUseCustomConfigFolderDef = true;
27
28 DKEY VideoPlayer::MpvCustomConfigFolder = "mpv_config_folder";
29 DVALUE(QString) VideoPlayer::MpvCustomConfigFolderDef = "%data%/mpv";
30
31 // Node.js.
32 DKEY Node::ID = "nodejs";
33
34 DKEY Node::NodeJsExecutable = QSL("nodejs_executable_") + OS_ID;
35
36 #if (defined(Q_OS_WIN) && !defined(BUILD_MSYS2)) || defined(Q_OS_OS2)
37 DVALUE(QString) Node::NodeJsExecutableDef = "node.exe";
38 #else
39 DVALUE(QString) Node::NodeJsExecutableDef = "node";
40 #endif
41
42 DKEY Node::NpmExecutable = QSL("npm_executable_") + OS_ID;
43
44 #if defined(Q_OS_WIN) && !defined(BUILD_MSYS2)
45 DVALUE(QString) Node::NpmExecutableDef = "npm.cmd";
46 #elif defined(Q_OS_OS2)
47 DVALUE(QString) Node::NpmExecutableDef = "npm.exe";
48 #else
49 DVALUE(QString) Node::NpmExecutableDef = "npm";
50 #endif
51
52 DKEY Node::PackageFolder = QSL("package_folder") + OS_ID;
53 DVALUE(QString) Node::PackageFolderDef = QSL(USER_DATA_PLACEHOLDER) + "/node-packages-" + QSL(OS_ID).toLower();
54
55 // Cookies.
56 DKEY Cookies::ID = "cookies";
57
58 // Network.
59 DKEY Network::ID = "network";
60
61 DKEY Network::SendDNT = "send_dnt";
62 VALUE(bool) Network::SendDNTDef = false;
63
64 DKEY Network::EnableApiServer = "api_server";
65 VALUE(bool) Network::EnableApiServerDef = false;
66
67 DKEY Network::EnableHttp2 = "http2_enabled";
68 DVALUE(bool) Network::EnableHttp2Def = false;
69
70 DKEY Network::CustomUserAgent = "user_agent";
71 DVALUE(QString) Network::CustomUserAgentDef = QString();
72
73 DKEY Network::IgnoreAllCookies = "ignore_all_cookies";
74 DVALUE(bool) Network::IgnoreAllCookiesDef = false;
75
76 // AdBlock.
77 DKEY AdBlock::ID = "adblock";
78
79 DKEY AdBlock::AdBlockEnabled = "enabled";
80 DVALUE(bool) AdBlock::AdBlockEnabledDef = false;
81
82 DKEY AdBlock::FilterLists = "filter_lists";
83 DVALUE(QStringList)
84 AdBlock::FilterListsDef = {QSL("https://secure.fanboy.co.nz/easylist.txt"),
85 QSL("https://secure.fanboy.co.nz/easyprivacy.txt"),
86 QSL("https://secure.fanboy.co.nz/fanboy-social.txt")};
87
88 DKEY AdBlock::CustomFilters = "custom_filters";
89 DVALUE(QStringList) AdBlock::CustomFiltersDef = {};
90
91 // Feeds.
92 DKEY Feeds::ID = "feeds";
93
94 DKEY Feeds::UpdateTimeout = "feed_update_timeout";
95 DVALUE(int) Feeds::UpdateTimeoutDef = DOWNLOAD_TIMEOUT;
96
97 DKEY Feeds::CountFormat = "count_format";
98 DVALUE(char*) Feeds::CountFormatDef = "(%unread)";
99
100 DKEY Feeds::EnableTooltipsFeedsMessages = "show_tooltips";
101 DVALUE(bool) Feeds::EnableTooltipsFeedsMessagesDef = true;
102
103 DKEY Feeds::StrikethroughDisabledFeeds = "strikethrough_disabled_feeds";
104 DVALUE(bool) Feeds::StrikethroughDisabledFeedsDef = true;
105
106 DKEY Feeds::PauseFeedFetching = "pause_feed_fetching";
107 DVALUE(bool) Feeds::PauseFeedFetchingDef = false;
108
109 DKEY Feeds::AutoUpdateInterval = "auto_update_interval";
110 DVALUE(int) Feeds::AutoUpdateIntervalDef = DEFAULT_AUTO_UPDATE_INTERVAL;
111
112 DKEY Feeds::AutoUpdateEnabled = "auto_update_enabled";
113 DVALUE(bool) Feeds::AutoUpdateEnabledDef = false;
114
115 DKEY Feeds::FastAutoUpdate = "auto_update_fast";
116 DVALUE(bool) Feeds::FastAutoUpdateDef = false;
117
118 DKEY Feeds::AutoUpdateOnlyUnfocused = "auto_update_only_unfocused";
119 DVALUE(bool) Feeds::AutoUpdateOnlyUnfocusedDef = false;
120
121 DKEY Feeds::FeedsUpdateOnStartup = "feeds_update_on_startup";
122 DVALUE(bool) Feeds::FeedsUpdateOnStartupDef = false;
123
124 DKEY Feeds::FeedsUpdateStartupDelay = "feeds_update_on_startup_delay";
125 DVALUE(double) Feeds::FeedsUpdateStartupDelayDef = STARTUP_UPDATE_DELAY;
126
127 DKEY Feeds::SortAlphabetically = "sort_alphabetically";
128 DVALUE(bool) Feeds::SortAlphabeticallyDef = false;
129
130 DKEY Feeds::ShowTreeBranches = "show_tree_branches";
131 DVALUE(bool) Feeds::ShowTreeBranchesDef = true;
132
133 DKEY Feeds::HideCountsIfNoUnread = "hide_counts_if_no_unread";
134 DVALUE(bool) Feeds::HideCountsIfNoUnreadDef = false;
135
136 DKEY Feeds::UpdateFeedListDuringFetching = "update_feed_list_during_fetching";
137 DVALUE(bool) Feeds::UpdateFeedListDuringFetchingDef = false;
138
139 DKEY Feeds::AutoExpandOnSelection = "auto_expand_on_selection";
140 DVALUE(bool) Feeds::AutoExpandOnSelectionDef = false;
141
142 DKEY Feeds::OnlyBasicShortcutsInLists = "only_basic_shortcuts_in_lists";
143 DVALUE(bool) Feeds::OnlyBasicShortcutsInListsDef = false;
144
145 DKEY Feeds::CustomizeListFont = "customize_list_font";
146 DVALUE(bool) Feeds::CustomizeListFontDef = false;
147
148 DKEY Feeds::ListFont = "list_font";
149
150 // Messages.
151 DKEY Messages::ID = "messages";
152
153 DKEY Messages::LimitArticleImagesHeight = "message_head_image_height";
154 DVALUE(int) Messages::LimitArticleImagesHeightDef = 72;
155
156 DKEY Messages::UseLegacyArticleFormat = "legacy_article_format";
157 DVALUE(bool) Messages::UseLegacyArticleFormatDef = false;
158
159 DKEY Messages::DisplayEnclosuresInMessage = "show_enclosures_in_message";
160 DVALUE(bool) Messages::DisplayEnclosuresInMessageDef = false;
161
162 DKEY Messages::AvoidOldArticles = "avoid_old_articles";
163 DVALUE(bool) Messages::AvoidOldArticlesDef = false;
164
165 DKEY Messages::DateTimeToAvoidArticle = "datetime_to_avoid_article";
166 DVALUE(QDateTime) Messages::DateTimeToAvoidArticleDef = QDateTime::currentDateTime();
167
168 DKEY Messages::HoursToAvoidArticle = "hours_to_avoid_article";
169 DVALUE(int) Messages::HoursToAvoidArticleDef = 0;
170
171 DKEY Messages::LimitDoNotRemoveUnread = "limit_dont_remove_unread";
172 DVALUE(bool) Messages::LimitDoNotRemoveUnreadDef = true;
173
174 DKEY Messages::LimitDoNotRemoveStarred = "limit_dont_remove_starred";
175 DVALUE(bool) Messages::LimitDoNotRemoveStarredDef = true;
176
177 DKEY Messages::LimitRecycleInsteadOfPurging = "limit_recycle_dont_purge";
178 DVALUE(bool) Messages::LimitRecycleInsteadOfPurgingDef = false;
179
180 DKEY Messages::LimitCountOfArticles = "limit_count_of_articles";
181 DVALUE(int) Messages::LimitCountOfArticlesDef = 0;
182
183 DKEY Messages::AlwaysDisplayItemPreview = "always_display_preview";
184 DVALUE(bool) Messages::AlwaysDisplayItemPreviewDef = true;
185
186 DKEY Messages::EnableMessagePreview = "enable_message_preview";
187 DVALUE(bool) Messages::EnableMessagePreviewDef = true;
188
189 DKEY Messages::ShowResourcesInArticles = "enable_message_resources";
190 DVALUE(bool) Messages::ShowResourcesInArticlesDef = true;
191
192 DKEY Messages::Zoom = "zoom";
193 DVALUE(qreal) Messages::ZoomDef = double(1.0);
194
195 DKEY Messages::FixupFutureArticleDateTimes = "fixup_future_datetimes";
196 DVALUE(bool) Messages::FixupFutureArticleDateTimesDef = false;
197
198 DKEY Messages::UseCustomDate = "use_custom_date";
199 DVALUE(bool) Messages::UseCustomDateDef = false;
200
201 DKEY Messages::CustomDateFormat = "custom_date_format";
202 DVALUE(char*) Messages::CustomDateFormatDef = "";
203
204 DKEY Messages::CustomFormatForDatesOnly = "custom_date_format_for_dates_only";
205 DVALUE(char*) Messages::CustomFormatForDatesOnlyDef = "";
206
207 DKEY Messages::UseCustomFormatForDatesOnly = "use_custom_date_for_dates_only";
208 DVALUE(bool) Messages::UseCustomFormatForDatesOnlyDef = false;
209
210 DKEY Messages::RelativeTimeForNewerArticles = "relative_time_for_new_articles";
211 DVALUE(int) Messages::RelativeTimeForNewerArticlesDef = -1;
212
213 DKEY Messages::ArticleMarkOnSelection = "mark_message_on_selected";
214 DVALUE(int) Messages::ArticleMarkOnSelectionDef = int(MessagesView::ArticleMarkingPolicy::MarkImmediately);
215
216 DKEY Messages::ArticleMarkOnSelectionDelay = "mark_message_on_selected_delay";
217 DVALUE(int) Messages::ArticleMarkOnSelectionDelayDef = 3000;
218
219 DKEY Messages::ArticleListPadding = "article_list_padding";
220 DVALUE(int) Messages::ArticleListPaddingDef = -1;
221
222 DKEY Messages::MultilineArticleList = "multiline_article_list";
223 DVALUE(bool) Messages::MultilineArticleListDef = false;
224
225 DKEY Messages::SwitchArticleListRtl = "switch_article_list_rtl";
226 DVALUE(bool) Messages::SwitchArticleListRtlDef = true;
227
228 DKEY Messages::UseCustomTime = "use_custom_time";
229 DVALUE(bool) Messages::UseCustomTimeDef = false;
230
231 DKEY Messages::CustomTimeFormat = "custom_time_format";
232 DVALUE(QString) Messages::CustomTimeFormatDef = {};
233
234 DKEY Messages::ClearReadOnExit = "clear_read_on_exit";
235 DVALUE(bool) Messages::ClearReadOnExitDef = false;
236
237 DKEY Messages::IgnoreContentsChanges = "ignore_contents_changes";
238 DVALUE(bool) Messages::IgnoreContentsChangesDef = true;
239
240 DKEY Messages::MarkUnreadOnUpdated = "mark_unread_on_update";
241 DVALUE(bool) Messages::MarkUnreadOnUpdatedDef = false;
242
243 DKEY Messages::UnreadIconType = "unread_icons_in_message_list";
244 DVALUE(int) Messages::UnreadIconTypeDef = 1; /* MessagesModel::MessageUnreadIcon::Dot */
245
246 DKEY Messages::BringAppToFrontAfterMessageOpenedExternally = "bring_app_to_front_after_msg_opened";
247 DVALUE(bool) Messages::BringAppToFrontAfterMessageOpenedExternallyDef = false;
248
249 DKEY Messages::KeepCursorInCenter = "keep_cursor_center";
250 DVALUE(bool) Messages::KeepCursorInCenterDef = false;
251
252 DKEY Messages::ShowOnlyUnreadMessages = "show_only_unread_messages";
253 DVALUE(bool) Messages::ShowOnlyUnreadMessagesDef = false;
254
255 DKEY Messages::PreviewerFontStandard = "previewer_font_standard";
256 NON_CONST_DVALUE(QString) Messages::PreviewerFontStandardDef = QString();
257
258 DKEY Messages::CustomizeListFont = "customize_list_font";
259 DVALUE(bool) Messages::CustomizeListFontDef = false;
260
261 DKEY Messages::ListFont = "list_font";
262
263 // Custom skin colors.
264 DKEY CustomSkinColors::ID = "custom_skin_colors";
265
266 DKEY CustomSkinColors::Enabled = "enabled";
267 DVALUE(bool) CustomSkinColors::EnabledDef = false;
268
269 // GUI.
270 DKEY GUI::ID = "gui";
271
272 DKEY GUI::FeedViewState = "feed_view_state";
273 DVALUE(QString) GUI::FeedViewStateDef = QString();
274
275 DKEY GUI::MessageViewState = "msg_view_state";
276 DVALUE(QString) GUI::MessageViewStateDef = QString();
277
278 DKEY GUI::SplitterFeeds = "splitter_feeds";
279 DVALUE(QList<QVariant>) GUI::SplitterFeedsDef = {};
280
281 DKEY GUI::SplitterMessagesIsVertical = "splitter_messages_is_vertical";
282 DVALUE(bool) GUI::SplitterMessagesIsVerticalDef = true;
283
284 DKEY GUI::SplitterMessagesVertical = "splitter_messages_vertical";
285 DVALUE(QList<QVariant>) GUI::SplitterMessagesVerticalDef = {};
286
287 DKEY GUI::SplitterMessagesHorizontal = "splitter_messages_horizontal";
288 DVALUE(QList<QVariant>) GUI::SplitterMessagesHorizontalDef = {};
289
290 DKEY GUI::ToolbarIconSize = "toolbar_icon_size";
291 DVALUE(int) GUI::ToolbarIconSizeDef = 0;
292
293 DKEY GUI::ToolbarStyle = "toolbar_style";
294 DVALUE(Qt::ToolButtonStyle) GUI::ToolbarStyleDef = Qt::ToolButtonIconOnly;
295
296 DKEY GUI::HeightRowMessages = "height_row_messages";
297 DVALUE(int) GUI::HeightRowMessagesDef = -1;
298
299 DKEY GUI::HeightRowFeeds = "height_row_feeds";
300 DVALUE(int) GUI::HeightRowFeedsDef = -1;
301
302 DKEY GUI::FeedsToolbarActions = "feeds_toolbar";
303 DVALUE(char*)
304 GUI::FeedsToolbarActionsDef = "m_actionUpdateAllItems,m_actionStopRunningItemsUpdate,m_actionPauseFeedFetching,m_"
305 "actionMarkAllItemsRead,filter,spacer,search";
306
307 DKEY GUI::StatusbarActions = "status_bar";
308 DVALUE(char*)
309 GUI::StatusbarActionsDef = "m_barProgressDownloadAction,m_barProgressFeedsAction,m_actionUpdateAllItems,m_"
310 "actionUpdateSelectedItems,m_actionStopRunningItemsUpdate,m_actionFullscreen,m_actionQuit";
311
312 DKEY GUI::MainWindowInitialSize = "window_size";
313 DKEY GUI::MainWindowInitialPosition = "window_position";
314
315 DKEY GUI::IsMainWindowMaximizedBeforeFullscreen = "is_window_maximized_before_fullscreen";
316 DVALUE(bool) GUI::IsMainWindowMaximizedBeforeFullscreenDef = false;
317
318 DKEY GUI::MainWindowStartsFullscreen = "start_in_fullscreen";
319 DVALUE(bool) GUI::MainWindowStartsFullscreenDef = false;
320
321 DKEY GUI::MainWindowStartsHidden = "start_hidden";
322 DVALUE(bool) GUI::MainWindowStartsHiddenDef = false;
323
324 DKEY GUI::MainWindowStartsMaximized = "window_is_maximized";
325 DVALUE(bool) GUI::MainWindowStartsMaximizedDef = false;
326
327 DKEY GUI::AlternateRowColorsInLists = "alternate_colors_in_lists";
328 DVALUE(bool) GUI::AlternateRowColorsInListsDef = false;
329
330 DKEY GUI::MainMenuVisible = "main_menu_visible";
331 DVALUE(bool) GUI::MainMenuVisibleDef = true;
332
333 DKEY GUI::ToolbarsVisible = "enable_toolbars";
334 DVALUE(bool) GUI::ToolbarsVisibleDef = true;
335
336 DKEY GUI::ListHeadersVisible = "enable_list_headers";
337 DVALUE(bool) GUI::ListHeadersVisibleDef = true;
338
339 DKEY GUI::MessageViewerToolbarsVisible = "message_viewer_toolbars";
340 DVALUE(bool) GUI::MessageViewerToolbarsVisibleDef = true;
341
342 DKEY GUI::StatusBarVisible = "enable_status_bar";
343 DVALUE(bool) GUI::StatusBarVisibleDef = true;
344
345 DKEY GUI::EnableNotifications = "enable_notifications";
346 DVALUE(bool) GUI::EnableNotificationsDef = true;
347
348 DKEY GUI::UseToastNotifications = "use_toast_notifications";
349 DVALUE(bool) GUI::UseToastNotificationsDef = true;
350
351 DKEY GUI::ToastNotificationsPosition = "toast_notifications_position";
352 DVALUE(ToastNotificationsManager::NotificationPosition)
353 GUI::ToastNotificationsPositionDef = ToastNotificationsManager::NotificationPosition::BottomRight;
354
355 DKEY GUI::ToastNotificationsScreen = "toast_notifications_screen";
356 DVALUE(int) GUI::ToastNotificationsScreenDef = -1;
357
358 DKEY GUI::ToastNotificationsMargin = "toast_notifications_margin";
359 DVALUE(int) GUI::ToastNotificationsMarginDef = NOTIFICATIONS_MARGIN;
360
361 DKEY GUI::ToastNotificationsOpacity = "toast_notifications_opacity";
362 DVALUE(double) GUI::ToastNotificationsOpacityDef = 0.9;
363
364 DKEY GUI::ToastNotificationsWidth = "toast_notifications_width";
365 DVALUE(int) GUI::ToastNotificationsWidthDef = NOTIFICATIONS_WIDTH;
366
367 DKEY GUI::HideMainWindowWhenMinimized = "hide_when_minimized";
368 DVALUE(bool) GUI::HideMainWindowWhenMinimizedDef = false;
369
370 DKEY GUI::MonochromeTrayIcon = "monochrome_tray_icon";
371 DVALUE(bool) GUI::MonochromeTrayIconDef = false;
372
373 DKEY GUI::FontAntialiasing = "font_antialiasing";
374 DVALUE(bool) GUI::FontAntialiasingDef = true;
375
376 DKEY GUI::ColoredBusyTrayIcon = "colored_busy_tray_icon";
377 DVALUE(bool) GUI::ColoredBusyTrayIconDef = false;
378
379 DKEY GUI::ForcedSkinColors = "forced_skin_colors";
380 DVALUE(bool) GUI::ForcedSkinColorsDef = true;
381
382 DKEY GUI::UnreadNumbersInTrayIcon = "show_unread_numbers_in_tray_icon";
383 DVALUE(bool) GUI::UnreadNumbersInTrayIconDef = true;
384
385 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) || defined(Q_OS_WIN)
386 DKEY GUI::UnreadNumbersOnTaskBar = "show_unread_numbers_on_task_bar";
387 DVALUE(bool) GUI::UnreadNumbersOnTaskBarDef = true;
388 #endif
389
390 DKEY GUI::UseTrayIcon = "use_tray_icon";
391 DVALUE(bool) GUI::UseTrayIconDef = true;
392
393 DKEY GUI::TabCloseMiddleClick = "tab_close_mid_button";
394 DVALUE(bool) GUI::TabCloseMiddleClickDef = true;
395
396 DKEY GUI::TabCloseDoubleClick = "tab_close_double_button";
397 DVALUE(bool) GUI::TabCloseDoubleClickDef = true;
398
399 DKEY GUI::TabNewDoubleClick = "tab_new_double_button";
400 DVALUE(bool) GUI::TabNewDoubleClickDef = true;
401
402 DKEY GUI::HideTabBarIfOnlyOneTab = "hide_tabbar_one_tab";
403 DVALUE(bool) GUI::HideTabBarIfOnlyOneTabDef = false;
404
405 DKEY GUI::MessagesToolbarDefaultButtons = "messages_toolbar";
406 DVALUE(char*)
407 GUI::MessagesToolbarDefaultButtonsDef =
408 "m_actionMarkSelectedMessagesAsRead,m_actionMarkSelectedMessagesAsUnread,m_actionSwitchImportanceOfSelectedMessages,"
409 "separator,highlighter,filter,spacer,search";
410
411 DKEY GUI::DefaultSortColumnFeeds = "default_sort_column_feeds";
412 DVALUE(int) GUI::DefaultSortColumnFeedsDef = FDS_MODEL_TITLE_INDEX;
413
414 DKEY GUI::DefaultSortOrderFeeds = "default_sort_order_feeds";
415 DVALUE(Qt::SortOrder) GUI::DefaultSortOrderFeedsDef = Qt::AscendingOrder;
416
417 DKEY GUI::IconTheme = "icon_theme_name";
418 DVALUE(char*) GUI::IconThemeDef = APP_ICON_THEME_DEFAULT;
419
420 DKEY GUI::Skin = "skin";
421 DVALUE(char*) GUI::SkinDef = APP_SKIN_DEFAULT;
422
423 DKEY GUI::Style = "style";
424 DVALUE(char*) GUI::StyleDef = APP_STYLE_DEFAULT;
425
426 // General.
427 DKEY General::ID = "main";
428
429 DKEY General::UpdateOnStartup = "update_on_start";
430 DVALUE(bool) General::UpdateOnStartupDef = false;
431
432 DKEY General::FirstRun = "first_run";
433 DVALUE(bool) General::FirstRunDef = true;
434
435 DKEY General::Language = "language";
436 DVALUE(QString) General::LanguageDef = QLocale::system().name();
437
438 // Downloads.
439 DKEY Downloads::ID = "download_manager";
440
441 DKEY Downloads::AlwaysPromptForFilename = "prompt_for_filename";
442 DVALUE(bool) Downloads::AlwaysPromptForFilenameDef = false;
443
444 DKEY Downloads::TargetDirectory = "target_directory";
445 DVALUE(QString) Downloads::TargetDirectoryDef = IOFactory::getSystemFolder(QStandardPaths::DownloadLocation);
446
447 DKEY Downloads::RemovePolicy = "remove_policy";
448 DVALUE(int) Downloads::RemovePolicyDef = int(DownloadManager::RemovePolicy::Never);
449
450 DKEY Downloads::TargetExplicitDirectory = "target_explicit_directory";
451 DVALUE(QString) Downloads::TargetExplicitDirectoryDef = IOFactory::getSystemFolder(QStandardPaths::DownloadLocation);
452
453 DKEY Downloads::ShowDownloadsWhenNewDownloadStarts = "show_downloads_on_new_download_start";
454 DVALUE(bool) Downloads::ShowDownloadsWhenNewDownloadStartsDef = true;
455
456 DKEY Downloads::ItemUrl = "download_%1_url";
457 DKEY Downloads::ItemLocation = "download_%1_location";
458 DKEY Downloads::ItemDone = "download_%1_done";
459
460 // Proxy.
461 DKEY Proxy::ID = "proxy";
462
463 DKEY Proxy::Type = "proxy_type";
464 DVALUE(QNetworkProxy::ProxyType) Proxy::TypeDef = QNetworkProxy::NoProxy;
465
466 DKEY Proxy::Host = "host";
467 DVALUE(QString) Proxy::HostDef = QString();
468
469 DKEY Proxy::Username = "username";
470 DVALUE(QString) Proxy::UsernameDef = QString();
471
472 DKEY Proxy::Password = "password";
473 DVALUE(QString) Proxy::PasswordDef = QString();
474
475 DKEY Proxy::Port = "port";
476 DVALUE(int) Proxy::PortDef = 80;
477
478 // Database.
479 DKEY Database::ID = "database";
480
481 DKEY Database::UseInMemory = "use_in_memory_db";
482 DVALUE(bool) Database::UseInMemoryDef = false;
483
484 DKEY Database::MySQLHostname = "mysql_hostname";
485 DVALUE(QString) Database::MySQLHostnameDef = QString();
486
487 DKEY Database::MySQLUsername = "mysql_username";
488 DVALUE(QString) Database::MySQLUsernameDef = QString();
489
490 DKEY Database::MySQLPassword = "mysql_password";
491 DVALUE(QString) Database::MySQLPasswordDef = QString();
492
493 DKEY Database::MySQLDatabase = "mysql_database";
494 DVALUE(char*) Database::MySQLDatabaseDef = APP_LOW_NAME;
495
496 DKEY Database::MySQLPort = "mysql_port";
497 DVALUE(int) Database::MySQLPortDef = APP_DB_MYSQL_PORT;
498
499 DKEY Database::ActiveDriver = "database_driver";
500 DVALUE(char*) Database::ActiveDriverDef = APP_DB_SQLITE_DRIVER;
501
502 // Keyboard.
503 DKEY Keyboard::ID = "keyboard";
504
505 // Notifications.
506 DKEY Notifications::ID = "notifications";
507
508 // Web browser.
509 DKEY Browser::ID = "browser";
510
511 DKEY Browser::DisableCache = "disable_cache";
512 DVALUE(bool) Browser::DisableCacheDef = false;
513
514 DKEY Browser::WebEngineChromiumFlags = "webengine_chromium_flags";
515
516 #if defined(Q_OS_LINUX) && !defined(IS_FLATPAK_BUILD)
517 DVALUE(QString) Browser::WebEngineChromiumFlagsDef = QSL("--no-sandbox --enable-smooth-scrolling");
518 #else
519 DVALUE(QString) Browser::WebEngineChromiumFlagsDef = QSL("--enable-smooth-scrolling");
520 #endif
521
522 DKEY Browser::OpenLinksInExternalBrowserRightAway = "open_link_externally_wo_confirmation";
523 DVALUE(bool) Browser::OpenLinksInExternalBrowserRightAwayDef = false;
524
525 DKEY Browser::CustomExternalBrowserEnabled = "custom_external_browser";
526 DVALUE(bool) Browser::CustomExternalBrowserEnabledDef = false;
527
528 DKEY Browser::CustomExternalBrowserExecutable = "external_browser_executable";
529 DVALUE(QString) Browser::CustomExternalBrowserExecutableDef = QString();
530
531 DKEY Browser::CustomExternalBrowserArguments = "external_browser_arguments";
532 DVALUE(char*) Browser::CustomExternalBrowserArgumentsDef = "\"%1\"";
533
534 DKEY Browser::CustomExternalEmailEnabled = "custom_external_email";
535 DVALUE(bool) Browser::CustomExternalEmailEnabledDef = false;
536
537 DKEY Browser::CustomExternalEmailExecutable = "external_email_executable";
538 DVALUE(QString) Browser::CustomExternalEmailExecutableDef = QString();
539
540 DKEY Browser::CustomExternalEmailArguments = "external_email_arguments";
541 DVALUE(char*) Browser::CustomExternalEmailArgumentsDef = "";
542
543 DKEY Browser::ExternalTools = "external_tools";
544 DVALUE(QStringList) Browser::ExternalToolsDef = QStringList();
545
546 // Categories.
547 DKEY CategoriesExpandStates::ID = "categories_expand_states";
548
549 Settings::Settings(const QString& file_name, Format format, SettingsProperties::SettingsType type, QObject* parent)
550 : QSettings(file_name, format, parent), m_lock(QReadWriteLock(QReadWriteLock::RecursionMode::Recursive)),
551 m_initializationStatus(type) {
552 Messages::PreviewerFontStandardDef = QFont(QApplication::font().family(), 12).toString();
553 }
554
555 Settings::~Settings() = default;
556
557 QStringList Settings::allKeys(const QString& section) {
558 if (!section.isEmpty()) {
559 beginGroup(section);
560 auto keys = QSettings::allKeys();
561
562 endGroup();
563 return keys;
564 }
565 else {
566 return QSettings::allKeys();
567 }
568 }
569
570 QString Settings::pathName() const {
571 return QFileInfo(fileName()).absolutePath();
572 }
573
574 QSettings::Status Settings::checkSettings() {
575 qDebugNN << LOGSEC_CORE << "Syncing settings.";
576 sync();
577 return status();
578 }
579
580 bool Settings::initiateRestoration(const QString& settings_backup_file_path) {
581 return IOFactory::copyFile(settings_backup_file_path,
582 QFileInfo(fileName()).absolutePath() + QDir::separator() + BACKUP_NAME_SETTINGS +
583 BACKUP_SUFFIX_SETTINGS);
584 }
585
586 void Settings::finishRestoration(const QString& desired_settings_file_path) {
587 const QString backup_settings_file = QFileInfo(desired_settings_file_path).absolutePath() + QDir::separator() +
588 BACKUP_NAME_SETTINGS + BACKUP_SUFFIX_SETTINGS;
589
590 if (QFile::exists(backup_settings_file)) {
591 qWarningNN << LOGSEC_CORE << "Backup settings file" << QUOTE_W_SPACE(QDir::toNativeSeparators(backup_settings_file))
592 << "was detected. Restoring it.";
593
594 if (IOFactory::copyFile(backup_settings_file, desired_settings_file_path)) {
595 QFile::remove(backup_settings_file);
596 qDebugNN << LOGSEC_CORE << "Settings file was restored successully.";
597 }
598 else {
599 qCriticalNN << LOGSEC_CORE << "Settings file was NOT restored due to error when copying the file.";
600 }
601 }
602 }
603
604 Settings* Settings::setupSettings(QObject* parent) {
605 Settings* new_settings;
606
607 // If settings file exists (and is writable) in executable file working directory
608 // (in subdirectory APP_CFG_PATH), then use it (portable settings).
609 // Otherwise use settings file stored in home path.
610 const SettingsProperties properties = determineProperties();
611
612 finishRestoration(properties.m_absoluteSettingsFileName);
613
614 // Portable settings are available, use them.
615 new_settings = new Settings(properties.m_absoluteSettingsFileName, QSettings::IniFormat, properties.m_type, parent);
616
617 if (properties.m_type == SettingsProperties::SettingsType::Portable) {
618 qDebugNN << LOGSEC_CORE << "Initializing settings in"
619 << QUOTE_W_SPACE(QDir::toNativeSeparators(properties.m_absoluteSettingsFileName)) << "(portable way).";
620 }
621 else if (properties.m_type == SettingsProperties::SettingsType::Custom) {
622 qDebugNN << LOGSEC_CORE << "Initializing settings in"
623 << QUOTE_W_SPACE(QDir::toNativeSeparators(properties.m_absoluteSettingsFileName)) << "(custom way).";
624 }
625 else {
626 qDebugNN << LOGSEC_CORE << "Initializing settings in"
627 << QUOTE_W_SPACE(QDir::toNativeSeparators(properties.m_absoluteSettingsFileName)) << "(non-portable way).";
628 }
629
630 return new_settings;
631 }
632
633 SettingsProperties Settings::determineProperties() {
634 SettingsProperties properties;
635
636 properties.m_settingsSuffix = QDir::separator() + QSL(APP_CFG_PATH) + QDir::separator() + QSL(APP_CFG_FILE);
637
638 const QString app_path = qApp->userDataAppFolder();
639 const QString home_path = qApp->userDataHomeFolder();
640 const QString custom_path = qApp->customDataFolder();
641
642 if (!custom_path.isEmpty()) {
643 // User wants to have his user data in custom folder, okay.
644 properties.m_type = SettingsProperties::SettingsType::Custom;
645 properties.m_baseDirectory = custom_path;
646 }
647 else {
648 // We will use PORTABLE settings only if it is available and NON-PORTABLE
649 // settings was not initialized before.
650 #if defined(Q_OS_UNIX) || defined(BUILD_MSYS2)
651 // DO NOT use portable settings for *nix or MSYS2, it is really not used on those platforms.
652 const bool will_we_use_portable_settings = false;
653 #else
654 const QString exe_path = qApp->applicationDirPath();
655 const QString home_path_file = home_path + properties.m_settingsSuffix;
656 const bool portable_settings_available = IOFactory::isFolderWritable(exe_path);
657 const bool non_portable_settings_exist = QFile::exists(home_path_file);
658 const bool will_we_use_portable_settings = portable_settings_available && !non_portable_settings_exist;
659 #endif
660
661 if (will_we_use_portable_settings) {
662 properties.m_type = SettingsProperties::SettingsType::Portable;
663 properties.m_baseDirectory = QDir::toNativeSeparators(app_path);
664 }
665 else {
666 properties.m_type = SettingsProperties::SettingsType::NonPortable;
667 properties.m_baseDirectory = QDir::toNativeSeparators(home_path);
668 }
669 }
670
671 properties.m_absoluteSettingsFileName = properties.m_baseDirectory + properties.m_settingsSuffix;
672 return properties;
673 }