1 #ifndef SETTINGSCACHE_H 2 #define SETTINGSCACHE_H 3 4 #include "settings/carddatabasesettings.h" 5 #include "settings/downloadsettings.h" 6 #include "settings/gamefilterssettings.h" 7 #include "settings/layoutssettings.h" 8 #include "settings/messagesettings.h" 9 #include "settings/serverssettings.h" 10 #include "shortcutssettings.h" 11 12 #include <QObject> 13 #include <QSize> 14 #include <QStringList> 15 16 class ReleaseChannel; 17 18 // size should be a multiple of 64 19 #define PIXMAPCACHE_SIZE_DEFAULT 2047 20 #define PIXMAPCACHE_SIZE_MIN 64 21 #define PIXMAPCACHE_SIZE_MAX 2047 22 23 #define DEFAULT_LANG_CODE "en" 24 #define DEFAULT_LANG_NAME "English" 25 #define CLIENT_INFO_NOT_SET "notset" 26 27 #define DEFAULT_FONT_SIZE 12 28 29 class QSettings; 30 31 class SettingsCache : public QObject 32 { 33 Q_OBJECT 34 signals: 35 void langChanged(); 36 void picsPathChanged(); 37 void cardDatabasePathChanged(); 38 void themeChanged(); 39 void picDownloadChanged(); 40 void displayCardNamesChanged(); 41 void horizontalHandChanged(); 42 void handJustificationChanged(); 43 void invertVerticalCoordinateChanged(); 44 void minPlayersForMultiColumnLayoutChanged(); 45 void soundEnabledChanged(); 46 void soundThemeChanged(); 47 void ignoreUnregisteredUsersChanged(); 48 void ignoreUnregisteredUserMessagesChanged(); 49 void pixmapCacheSizeChanged(int newSizeInMBs); 50 void masterVolumeChanged(int value); 51 void chatMentionCompleterChanged(); 52 void downloadSpoilerTimeIndexChanged(); 53 void downloadSpoilerStatusChanged(); 54 void useTearOffMenusChanged(bool state); 55 56 private: 57 QSettings *settings; 58 ShortcutsSettings *shortcutsSettings; 59 CardDatabaseSettings *cardDatabaseSettings; 60 ServersSettings *serversSettings; 61 MessageSettings *messageSettings; 62 GameFiltersSettings *gameFiltersSettings; 63 LayoutsSettings *layoutsSettings; 64 DownloadSettings *downloadSettings; 65 66 QByteArray mainWindowGeometry; 67 QByteArray tokenDialogGeometry; 68 QString lang; 69 QString deckPath, replaysPath, picsPath, customPicsPath, cardDatabasePath, customCardDatabasePath, 70 spoilerDatabasePath, tokenDatabasePath, themeName; 71 bool notifyAboutUpdates; 72 bool notifyAboutNewVersion; 73 bool showTipsOnStartup; 74 QList<int> seenTips; 75 bool mbDownloadSpoilers; 76 int updateReleaseChannel; 77 int maxFontSize; 78 bool picDownload; 79 bool notificationsEnabled; 80 bool spectatorNotificationsEnabled; 81 bool buddyConnectNotificationsEnabled; 82 bool doubleClickToPlay; 83 bool playToStack; 84 int startingHandSize; 85 bool annotateTokens; 86 QByteArray tabGameSplitterSizes; 87 bool displayCardNames; 88 bool horizontalHand; 89 bool invertVerticalCoordinate; 90 int minPlayersForMultiColumnLayout; 91 bool tapAnimation; 92 bool chatMention; 93 bool chatMentionCompleter; 94 QString chatMentionColor; 95 QString chatHighlightColor; 96 bool chatMentionForeground; 97 bool chatHighlightForeground; 98 bool zoneViewSortByName, zoneViewSortByType, zoneViewPileView; 99 bool soundEnabled; 100 QString soundThemeName; 101 bool ignoreUnregisteredUsers; 102 bool ignoreUnregisteredUserMessages; 103 QString picUrl; 104 QString picUrlFallback; 105 QString clientID; 106 QString clientVersion; 107 QString knownMissingFeatures; 108 bool useTearOffMenus; 109 int pixmapCacheSize; 110 bool scaleCards; 111 bool showMessagePopups; 112 bool showMentionPopups; 113 bool roomHistory; 114 bool leftJustified; 115 int masterVolume; 116 int cardInfoViewMode; 117 QString highlightWords; 118 QString gameDescription; 119 int maxPlayers; 120 QString gameTypes; 121 bool onlyBuddies; 122 bool onlyRegistered; 123 bool spectatorsAllowed; 124 bool spectatorsNeedPassword; 125 bool spectatorsCanTalk; 126 bool spectatorsCanSeeEverything; 127 int keepalive; 128 void translateLegacySettings(); 129 QString getSafeConfigPath(QString configEntry, QString defaultPath) const; 130 QString getSafeConfigFilePath(QString configEntry, QString defaultPath) const; 131 bool rememberGameSettings; 132 QList<ReleaseChannel *> releaseChannels; 133 bool isPortableBuild; 134 135 public: 136 SettingsCache(); 137 QString getDataPath(); 138 QString getSettingsPath(); getMainWindowGeometry()139 const QByteArray &getMainWindowGeometry() const 140 { 141 return mainWindowGeometry; 142 } getTokenDialogGeometry()143 const QByteArray &getTokenDialogGeometry() const 144 { 145 return tokenDialogGeometry; 146 } getLang()147 QString getLang() const 148 { 149 return lang; 150 } getDeckPath()151 QString getDeckPath() const 152 { 153 return deckPath; 154 } getReplaysPath()155 QString getReplaysPath() const 156 { 157 return replaysPath; 158 } getPicsPath()159 QString getPicsPath() const 160 { 161 return picsPath; 162 } getCustomPicsPath()163 QString getCustomPicsPath() const 164 { 165 return customPicsPath; 166 } getCustomCardDatabasePath()167 QString getCustomCardDatabasePath() const 168 { 169 return customCardDatabasePath; 170 } getCardDatabasePath()171 QString getCardDatabasePath() const 172 { 173 return cardDatabasePath; 174 } getSpoilerCardDatabasePath()175 QString getSpoilerCardDatabasePath() const 176 { 177 return spoilerDatabasePath; 178 } getTokenDatabasePath()179 QString getTokenDatabasePath() const 180 { 181 return tokenDatabasePath; 182 } getThemeName()183 QString getThemeName() const 184 { 185 return themeName; 186 } getChatMentionColor()187 QString getChatMentionColor() const 188 { 189 return chatMentionColor; 190 } getChatHighlightColor()191 QString getChatHighlightColor() const 192 { 193 return chatHighlightColor; 194 } getPicDownload()195 bool getPicDownload() const 196 { 197 return picDownload; 198 } getNotificationsEnabled()199 bool getNotificationsEnabled() const 200 { 201 return notificationsEnabled; 202 } getSpectatorNotificationsEnabled()203 bool getSpectatorNotificationsEnabled() const 204 { 205 return spectatorNotificationsEnabled; 206 } getBuddyConnectNotificationsEnabled()207 bool getBuddyConnectNotificationsEnabled() const 208 { 209 return buddyConnectNotificationsEnabled; 210 } getNotifyAboutUpdates()211 bool getNotifyAboutUpdates() const 212 { 213 return notifyAboutUpdates; 214 } getNotifyAboutNewVersion()215 bool getNotifyAboutNewVersion() const 216 { 217 return notifyAboutNewVersion; 218 } getShowTipsOnStartup()219 bool getShowTipsOnStartup() const 220 { 221 return showTipsOnStartup; 222 } getSeenTips()223 QList<int> getSeenTips() const 224 { 225 return seenTips; 226 } getUpdateReleaseChannel()227 ReleaseChannel *getUpdateReleaseChannel() const 228 { 229 return releaseChannels.at(updateReleaseChannel); 230 } getUpdateReleaseChannels()231 QList<ReleaseChannel *> getUpdateReleaseChannels() const 232 { 233 return releaseChannels; 234 } 235 getDoubleClickToPlay()236 bool getDoubleClickToPlay() const 237 { 238 return doubleClickToPlay; 239 } getPlayToStack()240 bool getPlayToStack() const 241 { 242 return playToStack; 243 } getStartingHandSize()244 int getStartingHandSize() const 245 { 246 return startingHandSize; 247 } getAnnotateTokens()248 bool getAnnotateTokens() const 249 { 250 return annotateTokens; 251 } getTabGameSplitterSizes()252 QByteArray getTabGameSplitterSizes() const 253 { 254 return tabGameSplitterSizes; 255 } getDisplayCardNames()256 bool getDisplayCardNames() const 257 { 258 return displayCardNames; 259 } getHorizontalHand()260 bool getHorizontalHand() const 261 { 262 return horizontalHand; 263 } getInvertVerticalCoordinate()264 bool getInvertVerticalCoordinate() const 265 { 266 return invertVerticalCoordinate; 267 } getMinPlayersForMultiColumnLayout()268 int getMinPlayersForMultiColumnLayout() const 269 { 270 return minPlayersForMultiColumnLayout; 271 } getTapAnimation()272 bool getTapAnimation() const 273 { 274 return tapAnimation; 275 } getChatMention()276 bool getChatMention() const 277 { 278 return chatMention; 279 } getChatMentionCompleter()280 bool getChatMentionCompleter() const 281 { 282 return chatMentionCompleter; 283 } getChatMentionForeground()284 bool getChatMentionForeground() const 285 { 286 return chatMentionForeground; 287 } getChatHighlightForeground()288 bool getChatHighlightForeground() const 289 { 290 return chatHighlightForeground; 291 } getZoneViewSortByName()292 bool getZoneViewSortByName() const 293 { 294 return zoneViewSortByName; 295 } getZoneViewSortByType()296 bool getZoneViewSortByType() const 297 { 298 return zoneViewSortByType; 299 } 300 /** 301 Returns if the view should be sorted into pile view. 302 @return zoneViewPileView if the view should be sorted into pile view. 303 */ getZoneViewPileView()304 bool getZoneViewPileView() const 305 { 306 return zoneViewPileView; 307 } getSoundEnabled()308 bool getSoundEnabled() const 309 { 310 return soundEnabled; 311 } getSoundThemeName()312 QString getSoundThemeName() const 313 { 314 return soundThemeName; 315 } getIgnoreUnregisteredUsers()316 bool getIgnoreUnregisteredUsers() const 317 { 318 return ignoreUnregisteredUsers; 319 } getIgnoreUnregisteredUserMessages()320 bool getIgnoreUnregisteredUserMessages() const 321 { 322 return ignoreUnregisteredUserMessages; 323 } getPixmapCacheSize()324 int getPixmapCacheSize() const 325 { 326 return pixmapCacheSize; 327 } getScaleCards()328 bool getScaleCards() const 329 { 330 return scaleCards; 331 } getShowMessagePopup()332 bool getShowMessagePopup() const 333 { 334 return showMessagePopups; 335 } getShowMentionPopup()336 bool getShowMentionPopup() const 337 { 338 return showMentionPopups; 339 } getRoomHistory()340 bool getRoomHistory() const 341 { 342 return roomHistory; 343 } getLeftJustified()344 bool getLeftJustified() const 345 { 346 return leftJustified; 347 } getMasterVolume()348 int getMasterVolume() const 349 { 350 return masterVolume; 351 } getCardInfoViewMode()352 int getCardInfoViewMode() const 353 { 354 return cardInfoViewMode; 355 } 356 QStringList getCountries() const; getHighlightWords()357 QString getHighlightWords() const 358 { 359 return highlightWords; 360 } getGameDescription()361 QString getGameDescription() const 362 { 363 return gameDescription; 364 } getMaxPlayers()365 int getMaxPlayers() const 366 { 367 return maxPlayers; 368 } getGameTypes()369 QString getGameTypes() const 370 { 371 return gameTypes; 372 } getOnlyBuddies()373 bool getOnlyBuddies() const 374 { 375 return onlyBuddies; 376 } getOnlyRegistered()377 bool getOnlyRegistered() const 378 { 379 return onlyRegistered; 380 } getSpectatorsAllowed()381 bool getSpectatorsAllowed() const 382 { 383 return spectatorsAllowed; 384 } getSpectatorsNeedPassword()385 bool getSpectatorsNeedPassword() const 386 { 387 return spectatorsNeedPassword; 388 } getSpectatorsCanTalk()389 bool getSpectatorsCanTalk() const 390 { 391 return spectatorsCanTalk; 392 } getSpectatorsCanSeeEverything()393 bool getSpectatorsCanSeeEverything() const 394 { 395 return spectatorsCanSeeEverything; 396 } getRememberGameSettings()397 bool getRememberGameSettings() const 398 { 399 return rememberGameSettings; 400 } getKeepAlive()401 int getKeepAlive() const 402 { 403 return keepalive; 404 } getMaxFontSize()405 int getMaxFontSize() const 406 { 407 return maxFontSize; 408 } 409 void setClientID(const QString &clientID); 410 void setClientVersion(const QString &clientVersion); 411 void setKnownMissingFeatures(const QString &_knownMissingFeatures); 412 void setUseTearOffMenus(bool _useTearOffMenus); getClientID()413 QString getClientID() 414 { 415 return clientID; 416 } getClientVersion()417 QString getClientVersion() 418 { 419 return clientVersion; 420 } getKnownMissingFeatures()421 QString getKnownMissingFeatures() 422 { 423 return knownMissingFeatures; 424 } getUseTearOffMenus()425 bool getUseTearOffMenus() 426 { 427 return useTearOffMenus; 428 } shortcuts()429 ShortcutsSettings &shortcuts() const 430 { 431 return *shortcutsSettings; 432 } cardDatabase()433 CardDatabaseSettings &cardDatabase() const 434 { 435 return *cardDatabaseSettings; 436 } servers()437 ServersSettings &servers() const 438 { 439 return *serversSettings; 440 } messages()441 MessageSettings &messages() const 442 { 443 return *messageSettings; 444 } gameFilters()445 GameFiltersSettings &gameFilters() const 446 { 447 return *gameFiltersSettings; 448 } layouts()449 LayoutsSettings &layouts() const 450 { 451 return *layoutsSettings; 452 } downloads()453 DownloadSettings &downloads() const 454 { 455 return *downloadSettings; 456 } getIsPortableBuild()457 bool getIsPortableBuild() const 458 { 459 return isPortableBuild; 460 } getDownloadSpoilersStatus()461 bool getDownloadSpoilersStatus() const 462 { 463 return mbDownloadSpoilers; 464 } 465 466 static SettingsCache &instance(); 467 public slots: 468 void setDownloadSpoilerStatus(bool _spoilerStatus); 469 470 void setMainWindowGeometry(const QByteArray &_mainWindowGeometry); 471 void setTokenDialogGeometry(const QByteArray &_tokenDialog); 472 void setLang(const QString &_lang); 473 void setShowTipsOnStartup(bool _showTipsOnStartup); 474 void setSeenTips(const QList<int> &_seenTips); 475 void setDeckPath(const QString &_deckPath); 476 void setReplaysPath(const QString &_replaysPath); 477 void setCustomCardDatabasePath(const QString &_customCardDatabasePath); 478 void setPicsPath(const QString &_picsPath); 479 void setCardDatabasePath(const QString &_cardDatabasePath); 480 void setSpoilerDatabasePath(const QString &_spoilerDatabasePath); 481 void setTokenDatabasePath(const QString &_tokenDatabasePath); 482 void setThemeName(const QString &_themeName); 483 void setChatMentionColor(const QString &_chatMentionColor); 484 void setChatHighlightColor(const QString &_chatHighlightColor); 485 void setPicDownload(int _picDownload); 486 void setNotificationsEnabled(int _notificationsEnabled); 487 void setSpectatorNotificationsEnabled(int _spectatorNotificationsEnabled); 488 void setBuddyConnectNotificationsEnabled(int _buddyConnectNotificationsEnabled); 489 void setDoubleClickToPlay(int _doubleClickToPlay); 490 void setPlayToStack(int _playToStack); 491 void setStartingHandSize(int _startingHandSize); 492 void setAnnotateTokens(int _annotateTokens); 493 void setTabGameSplitterSizes(const QByteArray &_tabGameSplitterSizes); 494 void setDisplayCardNames(int _displayCardNames); 495 void setHorizontalHand(int _horizontalHand); 496 void setInvertVerticalCoordinate(int _invertVerticalCoordinate); 497 void setMinPlayersForMultiColumnLayout(int _minPlayersForMultiColumnLayout); 498 void setTapAnimation(int _tapAnimation); 499 void setChatMention(int _chatMention); 500 void setChatMentionCompleter(int _chatMentionCompleter); 501 void setChatMentionForeground(int _chatMentionForeground); 502 void setChatHighlightForeground(int _chatHighlightForeground); 503 void setZoneViewSortByName(int _zoneViewSortByName); 504 void setZoneViewSortByType(int _zoneViewSortByType); 505 void setZoneViewPileView(int _zoneViewPileView); 506 void setSoundEnabled(int _soundEnabled); 507 void setSoundThemeName(const QString &_soundThemeName); 508 void setIgnoreUnregisteredUsers(int _ignoreUnregisteredUsers); 509 void setIgnoreUnregisteredUserMessages(int _ignoreUnregisteredUserMessages); 510 void setPixmapCacheSize(const int _pixmapCacheSize); 511 void setCardScaling(const int _scaleCards); 512 void setShowMessagePopups(const int _showMessagePopups); 513 void setShowMentionPopups(const int _showMentionPopups); 514 void setRoomHistory(const int _roomHistory); 515 void setLeftJustified(const int _leftJustified); 516 void setMasterVolume(const int _masterVolume); 517 void setCardInfoViewMode(const int _viewMode); 518 void setHighlightWords(const QString &_highlightWords); 519 void setGameDescription(const QString _gameDescription); 520 void setMaxPlayers(const int _maxPlayers); 521 void setGameTypes(const QString _gameTypes); 522 void setOnlyBuddies(const bool _onlyBuddies); 523 void setOnlyRegistered(const bool _onlyRegistered); 524 void setSpectatorsAllowed(const bool _spectatorsAllowed); 525 void setSpectatorsNeedPassword(const bool _spectatorsNeedPassword); 526 void setSpectatorsCanTalk(const bool _spectatorsCanTalk); 527 void setSpectatorsCanSeeEverything(const bool _spectatorsCanSeeEverything); 528 void setRememberGameSettings(const bool _rememberGameSettings); 529 void setNotifyAboutUpdate(int _notifyaboutupdate); 530 void setNotifyAboutNewVersion(int _notifyaboutnewversion); 531 void setUpdateReleaseChannel(int _updateReleaseChannel); 532 void setMaxFontSize(int _max); 533 }; 534 535 #endif 536