| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef SETTINGS_H |
| 4 | #define SETTINGS_H |
| 5 | |
| 6 | #include "definitions/definitions.h" |
| 7 | #include "gui/messagesview.h" |
| 8 | #include "gui/notifications/toastnotificationsmanager.h" |
| 9 | #include "miscellaneous/settingsproperties.h" |
| 10 | #include "miscellaneous/textfactory.h" |
| 11 | |
| 12 | #include <QByteArray> |
| 13 | #include <QColor> |
| 14 | #include <QDateTime> |
| 15 | #include <QNetworkProxy> |
| 16 | #include <QReadWriteLock> |
| 17 | #include <QSettings> |
| 18 | #include <QStringList> |
| 19 | #include <QWriteLocker> |
| 20 | |
| 21 | #define KEY RSSGUARD_DLLSPEC extern const QString |
| 22 | #define DKEY const QString |
| 23 | |
| 24 | #define VALUE(x) RSSGUARD_DLLSPEC extern const x |
| 25 | #define NON_CONST_VALUE(x) extern x |
| 26 | |
| 27 | #define DVALUE(x) const x |
| 28 | #define NON_CONST_DVALUE(x) x |
| 29 | |
| 30 | #define SETTING(x) x, x##Def |
| 31 | #define DEFAULT_VALUE(x) x##Def |
| 32 | #define GROUP(x) x::ID |
| 33 | |
| 34 | #if defined(NO_LITE) |
| 35 | namespace WebEngineAttributes { |
| 36 | KEY ID; |
| 37 | } |
| 38 | #endif |
| 39 | |
| 40 | namespace Cookies { |
| 41 | KEY ID; |
| 42 | } |
| 43 | |
| 44 | namespace DialogGeometries { |
| 45 | KEY ID; |
| 46 | } |
| 47 | |
| 48 | namespace FileDialogPaths { |
| 49 | KEY ID; |
| 50 | } |
| 51 | |
| 52 | namespace Node { |
| 53 | KEY ID; |
| 54 | |
| 55 | KEY NodeJsExecutable; |
| 56 | VALUE(QString) NodeJsExecutableDef; |
| 57 | |
| 58 | KEY NpmExecutable; |
| 59 | VALUE(QString) NpmExecutableDef; |
| 60 | |
| 61 | KEY PackageFolder; |
| 62 | VALUE(QString) PackageFolderDef; |
| 63 | } // namespace Node |
| 64 | |
| 65 | namespace VideoPlayer { |
| 66 | KEY ID; |
| 67 | |
| 68 | KEY MpvUseCustomConfigFolder; |
| 69 | VALUE(bool) MpvUseCustomConfigFolderDef; |
| 70 | |
| 71 | KEY MpvCustomConfigFolder; |
| 72 | VALUE(QString) MpvCustomConfigFolderDef; |
| 73 | } // namespace VideoPlayer |
| 74 | |
| 75 | namespace AdBlock { |
| 76 | KEY ID; |
| 77 | |
| 78 | KEY AdBlockEnabled; |
| 79 | VALUE(bool) AdBlockEnabledDef; |
| 80 | |
| 81 | KEY FilterLists; |
| 82 | VALUE(QStringList) FilterListsDef; |
| 83 | |
| 84 | KEY CustomFilters; |
| 85 | VALUE(QStringList) CustomFiltersDef; |
| 86 | } // namespace AdBlock |
| 87 | |
| 88 | // Feeds. |
| 89 | namespace Feeds { |
| 90 | KEY ID; |
| 91 | |
| 92 | KEY UpdateTimeout; |
| 93 | VALUE(int) UpdateTimeoutDef; |
| 94 | |
| 95 | KEY CountFormat; |
| 96 | VALUE(char*) CountFormatDef; |
| 97 | |
| 98 | KEY EnableTooltipsFeedsMessages; |
| 99 | VALUE(bool) EnableTooltipsFeedsMessagesDef; |
| 100 | |
| 101 | KEY StrikethroughDisabledFeeds; |
| 102 | VALUE(bool) StrikethroughDisabledFeedsDef; |
| 103 | |
| 104 | KEY PauseFeedFetching; |
| 105 | VALUE(bool) PauseFeedFetchingDef; |
| 106 | |
| 107 | KEY AutoUpdateInterval; |
| 108 | VALUE(int) AutoUpdateIntervalDef; |
| 109 | |
| 110 | KEY AutoUpdateEnabled; |
| 111 | VALUE(bool) AutoUpdateEnabledDef; |
| 112 | |
| 113 | KEY FastAutoUpdate; |
| 114 | VALUE(bool) FastAutoUpdateDef; |
| 115 | |
| 116 | KEY AutoUpdateOnlyUnfocused; |
| 117 | VALUE(bool) AutoUpdateOnlyUnfocusedDef; |
| 118 | |
| 119 | KEY FeedsUpdateOnStartup; |
| 120 | VALUE(bool) FeedsUpdateOnStartupDef; |
| 121 | |
| 122 | KEY FeedsUpdateStartupDelay; |
| 123 | VALUE(double) FeedsUpdateStartupDelayDef; |
| 124 | |
| 125 | KEY SortAlphabetically; |
| 126 | VALUE(bool) SortAlphabeticallyDef; |
| 127 | |
| 128 | KEY ShowTreeBranches; |
| 129 | VALUE(bool) ShowTreeBranchesDef; |
| 130 | |
| 131 | KEY HideCountsIfNoUnread; |
| 132 | VALUE(bool) HideCountsIfNoUnreadDef; |
| 133 | |
| 134 | KEY UpdateFeedListDuringFetching; |
| 135 | VALUE(bool) UpdateFeedListDuringFetchingDef; |
| 136 | |
| 137 | KEY AutoExpandOnSelection; |
| 138 | VALUE(bool) AutoExpandOnSelectionDef; |
| 139 | |
| 140 | KEY OnlyBasicShortcutsInLists; |
| 141 | VALUE(bool) OnlyBasicShortcutsInListsDef; |
| 142 | |
| 143 | KEY CustomizeListFont; |
| 144 | VALUE(bool) CustomizeListFontDef; |
| 145 | |
| 146 | KEY ListFont; |
| 147 | } // namespace Feeds |
| 148 | |
| 149 | // Messages. |
| 150 | namespace Messages { |
| 151 | KEY ID; |
| 152 | |
| 153 | KEY LimitArticleImagesHeight; |
| 154 | VALUE(int) LimitArticleImagesHeightDef; |
| 155 | |
| 156 | KEY UseLegacyArticleFormat; |
| 157 | VALUE(bool) UseLegacyArticleFormatDef; |
| 158 | |
| 159 | KEY DisplayEnclosuresInMessage; |
| 160 | VALUE(bool) DisplayEnclosuresInMessageDef; |
| 161 | |
| 162 | KEY AvoidOldArticles; |
| 163 | VALUE(bool) AvoidOldArticlesDef; |
| 164 | |
| 165 | KEY ArticleMarkOnSelection; |
| 166 | VALUE(int) ArticleMarkOnSelectionDef; |
| 167 | |
| 168 | KEY ArticleMarkOnSelectionDelay; |
| 169 | VALUE(int) ArticleMarkOnSelectionDelayDef; |
| 170 | |
| 171 | KEY DateTimeToAvoidArticle; |
| 172 | VALUE(QDateTime) DateTimeToAvoidArticleDef; |
| 173 | |
| 174 | KEY HoursToAvoidArticle; |
| 175 | VALUE(int) HoursToAvoidArticleDef; |
| 176 | |
| 177 | KEY LimitDoNotRemoveUnread; |
| 178 | VALUE(bool) LimitDoNotRemoveUnreadDef; |
| 179 | |
| 180 | KEY LimitDoNotRemoveStarred; |
| 181 | VALUE(bool) LimitDoNotRemoveStarredDef; |
| 182 | |
| 183 | KEY LimitRecycleInsteadOfPurging; |
| 184 | VALUE(bool) LimitRecycleInsteadOfPurgingDef; |
| 185 | |
| 186 | KEY LimitCountOfArticles; |
| 187 | VALUE(int) LimitCountOfArticlesDef; |
| 188 | |
| 189 | KEY AlwaysDisplayItemPreview; |
| 190 | VALUE(bool) AlwaysDisplayItemPreviewDef; |
| 191 | |
| 192 | KEY EnableMessagePreview; |
| 193 | VALUE(bool) EnableMessagePreviewDef; |
| 194 | |
| 195 | KEY ShowResourcesInArticles; |
| 196 | VALUE(bool) ShowResourcesInArticlesDef; |
| 197 | |
| 198 | KEY Zoom; |
| 199 | VALUE(qreal) ZoomDef; |
| 200 | |
| 201 | KEY FixupFutureArticleDateTimes; |
| 202 | VALUE(bool) FixupFutureArticleDateTimesDef; |
| 203 | |
| 204 | KEY UseCustomDate; |
| 205 | VALUE(bool) UseCustomDateDef; |
| 206 | |
| 207 | KEY CustomDateFormat; |
| 208 | VALUE(char*) CustomDateFormatDef; |
| 209 | |
| 210 | KEY UseCustomTime; |
| 211 | VALUE(bool) UseCustomTimeDef; |
| 212 | |
| 213 | KEY CustomFormatForDatesOnly; |
| 214 | VALUE(char*) CustomFormatForDatesOnlyDef; |
| 215 | |
| 216 | KEY UseCustomFormatForDatesOnly; |
| 217 | VALUE(bool) UseCustomFormatForDatesOnlyDef; |
| 218 | |
| 219 | KEY RelativeTimeForNewerArticles; |
| 220 | VALUE(int) RelativeTimeForNewerArticlesDef; |
| 221 | |
| 222 | KEY ArticleListPadding; |
| 223 | VALUE(int) ArticleListPaddingDef; |
| 224 | |
| 225 | KEY MultilineArticleList; |
| 226 | VALUE(bool) MultilineArticleListDef; |
| 227 | |
| 228 | KEY SwitchArticleListRtl; |
| 229 | VALUE(bool) SwitchArticleListRtlDef; |
| 230 | |
| 231 | KEY CustomTimeFormat; |
| 232 | VALUE(QString) CustomTimeFormatDef; |
| 233 | |
| 234 | KEY ClearReadOnExit; |
| 235 | VALUE(bool) ClearReadOnExitDef; |
| 236 | |
| 237 | KEY IgnoreContentsChanges; |
| 238 | VALUE(bool) IgnoreContentsChangesDef; |
| 239 | |
| 240 | KEY MarkUnreadOnUpdated; |
| 241 | VALUE(bool) MarkUnreadOnUpdatedDef; |
| 242 | |
| 243 | KEY UnreadIconType; |
| 244 | VALUE(int) UnreadIconTypeDef; |
| 245 | |
| 246 | KEY BringAppToFrontAfterMessageOpenedExternally; |
| 247 | VALUE(bool) BringAppToFrontAfterMessageOpenedExternallyDef; |
| 248 | |
| 249 | KEY KeepCursorInCenter; |
| 250 | VALUE(bool) KeepCursorInCenterDef; |
| 251 | |
| 252 | KEY ShowOnlyUnreadMessages; |
| 253 | VALUE(bool) ShowOnlyUnreadMessagesDef; |
| 254 | |
| 255 | KEY PreviewerFontStandard; |
| 256 | NON_CONST_VALUE(QString) PreviewerFontStandardDef; |
| 257 | |
| 258 | KEY CustomizeListFont; |
| 259 | VALUE(bool) CustomizeListFontDef; |
| 260 | |
| 261 | KEY ListFont; |
| 262 | } // namespace Messages |
| 263 | |
| 264 | // Custom skin colors. |
| 265 | namespace CustomSkinColors { |
| 266 | KEY ID; |
| 267 | |
| 268 | KEY Enabled; |
| 269 | VALUE(bool) EnabledDef; |
| 270 | |
| 271 | KEY CustomSkinColors; |
| 272 | } // namespace CustomSkinColors |
| 273 | |
| 274 | // GUI. |
| 275 | namespace GUI { |
| 276 | KEY ID; |
| 277 | |
| 278 | KEY EnableNotifications; |
| 279 | VALUE(bool) EnableNotificationsDef; |
| 280 | |
| 281 | KEY UseToastNotifications; |
| 282 | VALUE(bool) UseToastNotificationsDef; |
| 283 | |
| 284 | KEY ToastNotificationsPosition; |
| 285 | VALUE(ToastNotificationsManager::NotificationPosition) ToastNotificationsPositionDef; |
| 286 | |
| 287 | KEY ToastNotificationsScreen; |
| 288 | VALUE(int) ToastNotificationsScreenDef; |
| 289 | |
| 290 | KEY ToastNotificationsMargin; |
| 291 | VALUE(int) ToastNotificationsMarginDef; |
| 292 | |
| 293 | KEY ToastNotificationsOpacity; |
| 294 | VALUE(double) ToastNotificationsOpacityDef; |
| 295 | |
| 296 | KEY ToastNotificationsWidth; |
| 297 | VALUE(int) ToastNotificationsWidthDef; |
| 298 | |
| 299 | KEY FeedViewState; |
| 300 | VALUE(QString) FeedViewStateDef; |
| 301 | |
| 302 | KEY MessageViewState; |
| 303 | VALUE(QString) MessageViewStateDef; |
| 304 | |
| 305 | KEY SplitterFeeds; |
| 306 | VALUE(QList<QVariant>) SplitterFeedsDef; |
| 307 | |
| 308 | KEY SplitterMessagesIsVertical; |
| 309 | VALUE(bool) SplitterMessagesIsVerticalDef; |
| 310 | |
| 311 | KEY SplitterMessagesVertical; |
| 312 | VALUE(QList<QVariant>) SplitterMessagesVerticalDef; |
| 313 | |
| 314 | KEY SplitterMessagesHorizontal; |
| 315 | VALUE(QList<QVariant>) SplitterMessagesHorizontalDef; |
| 316 | |
| 317 | KEY ToolbarIconSize; |
| 318 | VALUE(int) ToolbarIconSizeDef; |
| 319 | |
| 320 | KEY ToolbarStyle; |
| 321 | VALUE(Qt::ToolButtonStyle) ToolbarStyleDef; |
| 322 | |
| 323 | KEY FeedsToolbarActions; |
| 324 | VALUE(char*) FeedsToolbarActionsDef; |
| 325 | |
| 326 | KEY StatusbarActions; |
| 327 | VALUE(char*) StatusbarActionsDef; |
| 328 | |
| 329 | KEY MainWindowInitialSize; |
| 330 | KEY MainWindowInitialPosition; |
| 331 | |
| 332 | KEY IsMainWindowMaximizedBeforeFullscreen; |
| 333 | VALUE(bool) IsMainWindowMaximizedBeforeFullscreenDef; |
| 334 | |
| 335 | KEY MainWindowStartsFullscreen; |
| 336 | VALUE(bool) MainWindowStartsFullscreenDef; |
| 337 | |
| 338 | KEY MainWindowStartsHidden; |
| 339 | VALUE(bool) MainWindowStartsHiddenDef; |
| 340 | |
| 341 | KEY MainWindowStartsMaximized; |
| 342 | VALUE(bool) MainWindowStartsMaximizedDef; |
| 343 | |
| 344 | KEY MainMenuVisible; |
| 345 | VALUE(bool) MainMenuVisibleDef; |
| 346 | |
| 347 | KEY ToolbarsVisible; |
| 348 | VALUE(bool) ToolbarsVisibleDef; |
| 349 | |
| 350 | KEY ListHeadersVisible; |
| 351 | VALUE(bool) ListHeadersVisibleDef; |
| 352 | |
| 353 | KEY MessageViewerToolbarsVisible; |
| 354 | VALUE(bool) MessageViewerToolbarsVisibleDef; |
| 355 | |
| 356 | KEY StatusBarVisible; |
| 357 | VALUE(bool) StatusBarVisibleDef; |
| 358 | |
| 359 | KEY HideMainWindowWhenMinimized; |
| 360 | VALUE(bool) HideMainWindowWhenMinimizedDef; |
| 361 | |
| 362 | KEY ForcedSkinColors; |
| 363 | VALUE(bool) ForcedSkinColorsDef; |
| 364 | |
| 365 | KEY AlternateRowColorsInLists; |
| 366 | VALUE(bool) AlternateRowColorsInListsDef; |
| 367 | |
| 368 | KEY UseTrayIcon; |
| 369 | VALUE(bool) UseTrayIconDef; |
| 370 | |
| 371 | KEY MonochromeTrayIcon; |
| 372 | VALUE(bool) MonochromeTrayIconDef; |
| 373 | |
| 374 | KEY FontAntialiasing; |
| 375 | VALUE(bool) FontAntialiasingDef; |
| 376 | |
| 377 | KEY ColoredBusyTrayIcon; |
| 378 | VALUE(bool) ColoredBusyTrayIconDef; |
| 379 | |
| 380 | KEY UnreadNumbersInTrayIcon; |
| 381 | VALUE(bool) UnreadNumbersInTrayIconDef; |
| 382 | |
| 383 | #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) || defined(Q_OS_WIN) |
| 384 | KEY UnreadNumbersOnTaskBar; |
| 385 | VALUE(bool) UnreadNumbersOnTaskBarDef; |
| 386 | #endif |
| 387 | |
| 388 | KEY TabCloseMiddleClick; |
| 389 | VALUE(bool) TabCloseMiddleClickDef; |
| 390 | |
| 391 | KEY TabCloseDoubleClick; |
| 392 | VALUE(bool) TabCloseDoubleClickDef; |
| 393 | |
| 394 | KEY TabNewDoubleClick; |
| 395 | VALUE(bool) TabNewDoubleClickDef; |
| 396 | |
| 397 | KEY HideTabBarIfOnlyOneTab; |
| 398 | VALUE(bool) HideTabBarIfOnlyOneTabDef; |
| 399 | |
| 400 | KEY MessagesToolbarDefaultButtons; |
| 401 | VALUE(char*) MessagesToolbarDefaultButtonsDef; |
| 402 | |
| 403 | KEY DefaultSortColumnFeeds; |
| 404 | VALUE(int) DefaultSortColumnFeedsDef; |
| 405 | |
| 406 | KEY HeightRowMessages; |
| 407 | VALUE(int) HeightRowMessagesDef; |
| 408 | |
| 409 | KEY HeightRowFeeds; |
| 410 | VALUE(int) HeightRowFeedsDef; |
| 411 | |
| 412 | KEY DefaultSortOrderFeeds; |
| 413 | VALUE(Qt::SortOrder) DefaultSortOrderFeedsDef; |
| 414 | |
| 415 | KEY IconTheme; |
| 416 | VALUE(char*) IconThemeDef; |
| 417 | |
| 418 | KEY Skin; |
| 419 | VALUE(char*) SkinDef; |
| 420 | |
| 421 | KEY Style; |
| 422 | VALUE(char*) StyleDef; |
| 423 | } // namespace GUI |
| 424 | |
| 425 | // Network. |
| 426 | namespace Network { |
| 427 | KEY ID; |
| 428 | |
| 429 | KEY SendDNT; |
| 430 | VALUE(bool) SendDNTDef; |
| 431 | |
| 432 | KEY EnableApiServer; |
| 433 | VALUE(bool) EnableApiServerDef; |
| 434 | |
| 435 | KEY EnableHttp2; |
| 436 | VALUE(bool) EnableHttp2Def; |
| 437 | |
| 438 | KEY CustomUserAgent; |
| 439 | VALUE(QString) CustomUserAgentDef; |
| 440 | |
| 441 | KEY IgnoreAllCookies; |
| 442 | VALUE(bool) IgnoreAllCookiesDef; |
| 443 | } // namespace Network |
| 444 | |
| 445 | // General. |
| 446 | namespace General { |
| 447 | KEY ID; |
| 448 | |
| 449 | KEY UpdateOnStartup; |
| 450 | VALUE(bool) UpdateOnStartupDef; |
| 451 | |
| 452 | KEY FirstRun; |
| 453 | VALUE(bool) FirstRunDef; |
| 454 | |
| 455 | KEY Language; |
| 456 | VALUE(QString) LanguageDef; |
| 457 | } // namespace General |
| 458 | |
| 459 | // Downloads. |
| 460 | namespace Downloads { |
| 461 | KEY ID; |
| 462 | KEY AlwaysPromptForFilename; |
| 463 | |
| 464 | VALUE(bool) AlwaysPromptForFilenameDef; |
| 465 | |
| 466 | KEY TargetDirectory; |
| 467 | |
| 468 | VALUE(QString) TargetDirectoryDef; |
| 469 | |
| 470 | KEY RemovePolicy; |
| 471 | |
| 472 | VALUE(int) RemovePolicyDef; |
| 473 | |
| 474 | KEY TargetExplicitDirectory; |
| 475 | |
| 476 | VALUE(QString) TargetExplicitDirectoryDef; |
| 477 | |
| 478 | KEY ShowDownloadsWhenNewDownloadStarts; |
| 479 | |
| 480 | VALUE(bool) ShowDownloadsWhenNewDownloadStartsDef; |
| 481 | |
| 482 | KEY ItemUrl; |
| 483 | KEY ItemLocation; |
| 484 | KEY ItemDone; |
| 485 | } // namespace Downloads |
| 486 | |
| 487 | // Proxy. |
| 488 | namespace Proxy { |
| 489 | KEY ID; |
| 490 | KEY Type; |
| 491 | |
| 492 | VALUE(QNetworkProxy::ProxyType) TypeDef; |
| 493 | |
| 494 | KEY Host; |
| 495 | |
| 496 | VALUE(QString) HostDef; |
| 497 | |
| 498 | KEY Username; |
| 499 | |
| 500 | VALUE(QString) UsernameDef; |
| 501 | |
| 502 | KEY Password; |
| 503 | |
| 504 | VALUE(QString) PasswordDef; |
| 505 | |
| 506 | KEY Port; |
| 507 | |
| 508 | VALUE(int) PortDef; |
| 509 | } // namespace Proxy |
| 510 | |
| 511 | // Database. |
| 512 | namespace Database { |
| 513 | KEY ID; |
| 514 | |
| 515 | KEY UseInMemory; |
| 516 | |
| 517 | VALUE(bool) UseInMemoryDef; |
| 518 | |
| 519 | KEY MySQLHostname; |
| 520 | |
| 521 | VALUE(QString) MySQLHostnameDef; |
| 522 | |
| 523 | KEY MySQLUsername; |
| 524 | |
| 525 | VALUE(QString) MySQLUsernameDef; |
| 526 | |
| 527 | KEY MySQLPassword; |
| 528 | |
| 529 | VALUE(QString) MySQLPasswordDef; |
| 530 | |
| 531 | KEY MySQLPort; |
| 532 | |
| 533 | VALUE(int) MySQLPortDef; |
| 534 | |
| 535 | KEY MySQLDatabase; |
| 536 | |
| 537 | VALUE(char*) MySQLDatabaseDef; |
| 538 | |
| 539 | KEY ActiveDriver; |
| 540 | |
| 541 | VALUE(char*) ActiveDriverDef; |
| 542 | } // namespace Database |
| 543 | |
| 544 | // Keyboard. |
| 545 | namespace Keyboard { |
| 546 | KEY ID; |
| 547 | } |
| 548 | |
| 549 | // Notifications. |
| 550 | namespace Notifications { |
| 551 | KEY ID; |
| 552 | } |
| 553 | |
| 554 | // Web browser. |
| 555 | namespace Browser { |
| 556 | KEY ID; |
| 557 | |
| 558 | KEY DisableCache; |
| 559 | VALUE(bool) DisableCacheDef; |
| 560 | |
| 561 | KEY WebEngineChromiumFlags; |
| 562 | VALUE(QString) WebEngineChromiumFlagsDef; |
| 563 | |
| 564 | KEY OpenLinksInExternalBrowserRightAway; |
| 565 | VALUE(bool) OpenLinksInExternalBrowserRightAwayDef; |
| 566 | |
| 567 | KEY CustomExternalBrowserEnabled; |
| 568 | VALUE(bool) CustomExternalBrowserEnabledDef; |
| 569 | |
| 570 | KEY CustomExternalBrowserExecutable; |
| 571 | VALUE(QString) CustomExternalBrowserExecutableDef; |
| 572 | |
| 573 | KEY CustomExternalBrowserArguments; |
| 574 | VALUE(char*) CustomExternalBrowserArgumentsDef; |
| 575 | |
| 576 | KEY CustomExternalEmailEnabled; |
| 577 | VALUE(bool) CustomExternalEmailEnabledDef; |
| 578 | |
| 579 | KEY CustomExternalEmailExecutable; |
| 580 | VALUE(QString) CustomExternalEmailExecutableDef; |
| 581 | |
| 582 | KEY ExternalTools; |
| 583 | VALUE(QStringList) ExternalToolsDef; |
| 584 | |
| 585 | KEY CustomExternalEmailArguments; |
| 586 | VALUE(char*) CustomExternalEmailArgumentsDef; |
| 587 | } // namespace Browser |
| 588 | |
| 589 | // Categories. |
| 590 | namespace CategoriesExpandStates { |
| 591 | KEY ID; |
| 592 | } |
| 593 | |
| 594 | class Settings : public QSettings { |
| 595 | Q_OBJECT |
| 596 | |
| 597 | public: |
| 598 | // Destructor. |
| 599 | virtual ~Settings(); |
| 600 | |
| 601 | // Type of used settings. |
| 602 | SettingsProperties::SettingsType type() const; |
| 603 | |
| 604 | // Getters/setters for settings values. |
| 605 | QVariant password(const QString& section, const QString& key, const QVariant& default_value = QVariant()) const; |
| 606 | void setPassword(const QString& section, const QString& key, const QVariant& value); |
| 607 | |
| 608 | QStringList allKeys(const QString& section); |
| 609 | |
| 610 | QVariant value(const QString& section, const QString& key, const QVariant& default_value = QVariant()) const; |
| 611 | void setValue(const QString& section, const QString& key, const QVariant& value); |
| 612 | void setValue(const QString& key, const QVariant& value); |
| 613 | |
| 614 | bool contains(const QString& section, const QString& key) const; |
| 615 | void remove(const QString& section, const QString& key = {}); |
| 616 | |
| 617 | // Returns the path which contains the settings. |
| 618 | QString pathName() const; |
| 619 | |
| 620 | // Synchronizes settings. |
| 621 | QSettings::Status checkSettings(); |
| 622 | |
| 623 | bool initiateRestoration(const QString& settings_backup_file_path); |
| 624 | static void finishRestoration(const QString& desired_settings_file_path); |
| 625 | |
| 626 | // Creates settings file in correct location. |
| 627 | static Settings* setupSettings(QObject* parent); |
| 628 | |
| 629 | // Returns properties of the actual application-wide settings. |
| 630 | static SettingsProperties determineProperties(); |
| 631 | |
| 632 | private: |
| 633 | explicit Settings(const QString& file_name, |
| 634 | Format format, |
| 635 | SettingsProperties::SettingsType type, |
| 636 | QObject* parent = nullptr); |
| 637 | |
| 638 | private: |
| 639 | mutable QReadWriteLock m_lock; |
| 640 | SettingsProperties::SettingsType m_initializationStatus; |
| 641 | }; |
| 642 | |
| 643 | inline SettingsProperties::SettingsType Settings::type() const { |
| 644 | return m_initializationStatus; |
| 645 | } |
| 646 | |
| 647 | // Getters/setters for settings values. |
| 648 | inline QVariant Settings::password(const QString& section, const QString& key, const QVariant& default_value) const { |
| 649 | return TextFactory::decrypt(value(section, key, default_value).toString()); |
| 650 | } |
| 651 | |
| 652 | inline void Settings::setPassword(const QString& section, const QString& key, const QVariant& value) { |
| 653 | setValue(section, key, TextFactory::encrypt(value.toString())); |
| 654 | } |
| 655 | |
| 656 | inline QVariant Settings::value(const QString& section, const QString& key, const QVariant& default_value) const { |
| 657 | return QSettings::value(QString(QSL("%1/%2")).arg(section, key), default_value); |
| 658 | } |
| 659 | |
| 660 | inline void Settings::setValue(const QString& section, const QString& key, const QVariant& value) { |
| 661 | QWriteLocker lck(&m_lock); |
| 662 | QSettings::setValue(QString(QSL("%1/%2")).arg(section, key), value); |
| 663 | } |
| 664 | |
| 665 | inline void Settings::setValue(const QString& key, const QVariant& value) { |
| 666 | QWriteLocker lck(&m_lock); |
| 667 | QSettings::setValue(key, value); |
| 668 | } |
| 669 | |
| 670 | inline bool Settings::contains(const QString& section, const QString& key) const { |
| 671 | return QSettings::contains(QString(QSL("%1/%2")).arg(section, key)); |
| 672 | } |
| 673 | |
| 674 | inline void Settings::remove(const QString& section, const QString& key) { |
| 675 | QWriteLocker lck(&m_lock); |
| 676 | |
| 677 | if (key.isEmpty()) { |
| 678 | beginGroup(section); |
| 679 | QSettings::remove({}); |
| 680 | endGroup(); |
| 681 | } |
| 682 | else { |
| 683 | QSettings::remove(QString(QSL("%1/%2")).arg(section, key)); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | #endif // SETTINGS_H |