diff --git a/cockatrice/src/client/settings/cache_settings.cpp b/cockatrice/src/client/settings/cache_settings.cpp index 9ab3173e5..47ca8a340 100644 --- a/cockatrice/src/client/settings/cache_settings.cpp +++ b/cockatrice/src/client/settings/cache_settings.cpp @@ -222,15 +222,15 @@ void SettingsCache::loadPaths() // customPicsPath derived from picsPath QString picsPath = pathsIni.value("paths/pics").toString(); if (picsPath.endsWith("/")) { - computePath("custompics", picsPath + "CUSTOM/"); + computePath("customPics", picsPath + "CUSTOM/"); } else { - computePath("custompics", picsPath + "/CUSTOM/"); + computePath("customPics", picsPath + "/CUSTOM/"); } - computePath("customsets", dataPath + "/customsets/"); - computeFilePath("carddatabase", dataPath + "/cards.xml"); - computeFilePath("tokendatabase", dataPath + "/tokens.xml"); - computeFilePath("spoilerdatabase", dataPath + "/spoiler.xml"); + computePath("customSets", dataPath + "/customsets/"); + computeFilePath("cardDatabase", dataPath + "/cards.xml"); + computeFilePath("tokenDatabase", dataPath + "/tokens.xml"); + computeFilePath("spoilerDatabase", dataPath + "/spoiler.xml"); } void SettingsCache::resetPaths() diff --git a/libcockatrice_settings/libcockatrice/settings/card_database_settings.cpp b/libcockatrice_settings/libcockatrice/settings/card_database_settings.cpp index 219c79c34..b55c97909 100644 --- a/libcockatrice_settings/libcockatrice/settings/card_database_settings.cpp +++ b/libcockatrice_settings/libcockatrice/settings/card_database_settings.cpp @@ -9,7 +9,7 @@ CardDatabaseSettings::CardDatabaseSettings(const QString &settingPath, QObject * void CardDatabaseSettings::setSortKey(QString shortName, unsigned int sortKey) { - setValue(sortKey, "sortkey", "sets", shortName); + setValue(sortKey, "sortKey", "sets", shortName); QMutexLocker lock(&setOptionsMutex); ensureSetOptionsLoaded(); setOptionsCache[shortName].sortKey = sortKey; @@ -25,7 +25,7 @@ void CardDatabaseSettings::setEnabled(QString shortName, bool enabled) void CardDatabaseSettings::setIsKnown(QString shortName, bool isknown) { - setValue(isknown, "isknown", "sets", shortName); + setValue(isknown, "isKnown", "sets", shortName); QMutexLocker lock(&setOptionsMutex); ensureSetOptionsLoaded(); setOptionsCache[shortName].isKnown = isknown; @@ -42,9 +42,9 @@ void CardDatabaseSettings::ensureSetOptionsLoaded() const for (const QString &group : groups) { settings.beginGroup(group); SetOptions &o = setOptionsCache[group]; - o.sortKey = settings.value("sortkey", 0).toUInt(); + o.sortKey = settings.value("sortKey", 0).toUInt(); o.enabled = settings.value("enabled", true).toBool(); - o.isKnown = settings.value("isknown", true).toBool(); + o.isKnown = settings.value("isKnown", true).toBool(); settings.endGroup(); } setOptionsLoaded = true; @@ -84,7 +84,7 @@ void CardDatabaseSettings::saveSets(const QVector gameKeyMap = { + {"game/maxplayers", "game/maxPlayers"}, + {"game/gamedescription", "game/gameDescription"}, + {"game/gametypes", "game/gameTypes"}, + {"game/onlybuddies", "game/onlyBuddies"}, + {"game/onlyregistered", "game/onlyRegistered"}, + {"game/spectatorsallowed", "game/spectatorsAllowed"}, + {"game/spectatorsneedpassword", "game/spectatorsNeedPassword"}, + {"game/spectatorscantalk", "game/spectatorsCanTalk"}, + {"game/spectatorscanseeeverything", "game/spectatorsCanSeeEverything"}, + {"game/creategameasspectator", "game/createGameAsSpectator"}, + {"game/defaultstartinglifetotal", "game/defaultStartingLifeTotal"}, + {"game/sharedecklistsonload", "game/shareDecklistsOnLoad"}, + {"game/remembergamesettings", "game/rememberGameSettings"}, + {"localgameoptions/maxplayers", "localgameoptions/maxPlayers"}, + {"localgameoptions/startinglifetotal", "localgameoptions/startingLifeTotal"}, + {"localgameoptions/remembersettings", "localgameoptions/rememberSettings"}, + }; - globalIni.beginGroup("localgameoptions"); - if (!globalIni.childKeys().isEmpty()) { - hasGameKeys = true; + bool hasAny = false; + for (auto it = gameKeyMap.constBegin(); it != gameKeyMap.constEnd(); ++it) { + if (globalIni.contains(it.key())) { + hasAny = true; + break; + } } - QStringList localGameKeys = globalIni.childKeys(); - globalIni.endGroup(); - - if (!hasGameKeys) { + if (!hasAny) { return; } QSettings gameIni(settingsPath + "game.ini", QSettings::IniFormat); - for (const auto &key : gameKeys) { - if (key == "maxfontsize") { - continue; + for (auto it = gameKeyMap.constBegin(); it != gameKeyMap.constEnd(); ++it) { + if (globalIni.contains(it.key())) { + gameIni.setValue(it.value(), globalIni.value(it.key())); } - gameIni.setValue("game/" + key, globalIni.value("game/" + key)); - } - for (const auto &key : localGameKeys) { - gameIni.setValue("localgameoptions/" + key, globalIni.value("localgameoptions/" + key)); } } static void migrateChatSettings(const QString &settingsPath, QSettings &globalIni) { - globalIni.beginGroup("chat"); - QStringList chatKeys = globalIni.childKeys(); - globalIni.endGroup(); - - // Legacy highlight words lived under [personal], but the chat settings - // class reads them from [chat] - bool hasHighlightWords = globalIni.contains("personal/highlightWords"); - if (chatKeys.isEmpty() && !hasHighlightWords) { + const QMap chatKeyMap = { + {"chat/mention", "chat/mention"}, + {"chat/mentioncompleter", "chat/mentionCompleter"}, + {"chat/mentioncolor", "chat/mentionColor"}, + {"chat/highlightcolor", "chat/highlightColor"}, + {"chat/mentionforeground", "chat/mentionForeground"}, + {"chat/highlightforeground", "chat/highlightForeground"}, + {"chat/ignore_unregistered", "chat/ignoreUnregistered"}, + {"chat/ignore_unregistered_messages", "chat/ignoreUnregisteredMessages"}, + {"chat/ignore_nonbuddy_messages", "chat/ignoreNonBuddyMessages"}, + {"chat/showmessagepopups", "chat/showMessagePopups"}, + {"chat/showmentionpopups", "chat/showMentionPopups"}, + {"chat/roomhistory", "chat/roomHistory"}, + {"chat/highlightwords", "chat/highlightWords"}, + // Legacy highlight words lived under [personal], but the chat settings + // class reads them from [chat] + {"personal/highlightWords", "chat/highlightWords"}, + }; + bool hasAny = false; + for (auto it = chatKeyMap.constBegin(); it != chatKeyMap.constEnd(); ++it) { + if (globalIni.contains(it.key())) { + hasAny = true; + break; + } + } + if (!hasAny) { return; } QSettings chatIni(settingsPath + "chat.ini", QSettings::IniFormat); - for (const auto &key : chatKeys) { - chatIni.setValue("chat/" + key, globalIni.value("chat/" + key)); - } - if (hasHighlightWords) { - chatIni.setValue("chat/highlightwords", globalIni.value("personal/highlightWords")); + for (auto it = chatKeyMap.constBegin(); it != chatKeyMap.constEnd(); ++it) { + if (globalIni.contains(it.key())) { + chatIni.setValue(it.value(), globalIni.value(it.key())); + } } } @@ -130,9 +154,9 @@ static void migrateUpdatesSettings(const QString &settingsPath, QSettings &globa {"personal/cardUpdateCheckInterval", "updates/cardUpdateCheckInterval"}, {"personal/lastCardUpdateCheck", "updates/lastCardUpdateCheck"}, {"personal/alwaysEnableNewSets", "updates/alwaysEnableNewSets"}, - {"personal/updatenotification", "updates/updatenotification"}, - {"personal/newversionnotification", "updates/newversionnotification"}, - {"personal/updatereleasechannel", "updates/updatereleasechannel"}, + {"personal/updatenotification", "updates/updateNotification"}, + {"personal/newversionnotification", "updates/newVersionNotification"}, + {"personal/updatereleasechannel", "updates/updateReleaseChannel"}, }; bool hasAny = false; for (auto it = updateKeyMap.constBegin(); it != updateKeyMap.constEnd(); ++it) { @@ -188,19 +212,17 @@ static void migratePersonalSettings(const QString &settingsPath, QSettings &glob static void migrateCardsDisplaySettings(const QString &settingsPath, QSettings &globalIni) { - const QStringList cardsRootKeys = { - "cards/displaycardnames", - "cards/roundcardcorners", - "cards/overrideallcardartwithpersonalpreference", - "cards/bumpsetswithcardsindecktotop", - "cards/includerebalancedcards", - "cards/tapanimation", - "cards/autorotatesidewayslayoutcards", - "cards/scaleCards", - "cards/verticalCardOverlapPercent", - "cards/cardinfoviewmode", - }; const QMap cardsKeyMap = { + {"cards/displaycardnames", "cards/displayCardNames"}, + {"cards/roundcardcorners", "cards/roundCardCorners"}, + {"cards/overrideallcardartwithpersonalpreference", "cards/overrideAllCardArtWithPersonalPreference"}, + {"cards/bumpsetswithcardsindecktotop", "cards/bumpSetsWithCardsInDeckToTop"}, + {"cards/includerebalancedcards", "cards/includerebalancedcards"}, + {"cards/tapanimation", "cards/tapAnimation"}, + {"cards/autorotatesidewayslayoutcards", "cards/autoRotateSidewaysLayoutCards"}, + {"cards/scaleCards", "cards/scaleCards"}, + {"cards/verticalCardOverlapPercent", "cards/verticalCardOverlapPercent"}, + {"cards/cardinfoviewmode", "cards/cardInfoViewMode"}, {"cards/printingselectorsortorder", "cards/printingSelector/sortOrder"}, {"cards/printingselectornavigationbuttonsvisible", "cards/printingSelector/navigationButtonsVisible"}, {"cards/printingselectorcardsize", "cards/cardSize/printingSelector"}, @@ -213,14 +235,10 @@ static void migrateCardsDisplaySettings(const QString &settingsPath, QSettings & }; bool hasAny = false; - for (const auto &key : cardsRootKeys) { - if (globalIni.contains(key)) { - hasAny = true; - } - } for (auto it = cardsKeyMap.constBegin(); it != cardsKeyMap.constEnd(); ++it) { if (globalIni.contains(it.key())) { hasAny = true; + break; } } if (!hasAny) { @@ -228,11 +246,6 @@ static void migrateCardsDisplaySettings(const QString &settingsPath, QSettings & } QSettings cardsIni(settingsPath + "cards_display.ini", QSettings::IniFormat); - for (const auto &key : cardsRootKeys) { - if (globalIni.contains(key)) { - cardsIni.setValue(key, globalIni.value(key)); - } - } for (auto it = cardsKeyMap.constBegin(); it != cardsKeyMap.constEnd(); ++it) { if (globalIni.contains(it.key())) { cardsIni.setValue(it.value(), globalIni.value(it.key())); @@ -242,29 +255,31 @@ static void migrateCardsDisplaySettings(const QString &settingsPath, QSettings & static void migrateInterfaceSettings(const QString &settingsPath, QSettings &globalIni) { - const QStringList interfaceRootKeys = { - "interface/usetearoffmenus", - "interface/cardViewInitialRowsMax", - "interface/cardViewExpandedRowsMax", - "interface/closeEmptyCardView", - "interface/focusCardViewSearchBar", - "interface/keepGameChatFocus", - "interface/doubleclicktoplay", - "interface/clickPlaysAllSelected", - "interface/playtostack", - "interface/doNotDeleteArrowsInSubPhases", - "interface/startinghandsize", - "interface/annotatetokens", - "interface/showlassoselectioncount", - "interface/showpersistentselectioncount", - "interface/tallyType", - "interface/leftjustified", - "interface/min_players_multicolumn", - }; - const QStringList interfaceSubKeys = { - "hand/horizontal", "table/invert_vertical", "replay/rewindBufferingMs", "replay/fastForwardSpeed", - "zoneview/groupby", "zoneview/sortby", "zoneview/pileview"}; const QMap interfaceKeyMap = { + {"interface/usetearoffmenus", "interface/useTearOffMenus"}, + {"interface/cardViewInitialRowsMax", "interface/cardViewInitialRowsMax"}, + {"interface/cardViewExpandedRowsMax", "interface/cardViewExpandedRowsMax"}, + {"interface/closeEmptyCardView", "interface/closeEmptyCardView"}, + {"interface/focusCardViewSearchBar", "interface/focusCardViewSearchBar"}, + {"interface/keepGameChatFocus", "interface/keepGameChatFocus"}, + {"interface/doubleclicktoplay", "interface/doubleClickToPlay"}, + {"interface/clickPlaysAllSelected", "interface/clickPlaysAllSelected"}, + {"interface/playtostack", "interface/playToStack"}, + {"interface/doNotDeleteArrowsInSubPhases", "interface/doNotDeleteArrowsInSubPhases"}, + {"interface/startinghandsize", "interface/startingHandSize"}, + {"interface/annotatetokens", "interface/annotateTokens"}, + {"interface/showlassoselectioncount", "interface/showLassoSelectionCount"}, + {"interface/showpersistentselectioncount", "interface/showPersistentSelectionCount"}, + {"interface/tallyType", "interface/tallyType"}, + {"interface/leftjustified", "interface/leftJustified"}, + {"interface/min_players_multicolumn", "interface/minPlayersMulticolumn"}, + {"hand/horizontal", "hand/horizontal"}, + {"table/invert_vertical", "table/invertVertical"}, + {"replay/rewindBufferingMs", "replay/rewindBufferingMs"}, + {"replay/fastForwardSpeed", "replay/fastForwardSpeed"}, + {"zoneview/groupby", "zoneview/groupBy"}, + {"zoneview/sortby", "zoneview/sortBy"}, + {"zoneview/pileview", "zoneview/pileView"}, {"personal/showStatusBar", "interface/showStatusBar"}, {"menu/showshortcuts", "interface/showShortcuts"}, {"menu/showgameselectorfiltertoolbar", "interface/showGameSelectorFilterToolbar"}, @@ -273,19 +288,10 @@ static void migrateInterfaceSettings(const QString &settingsPath, QSettings &glo {"interface/buddyconnectnotificationsenabled", "interface/notifications/buddyConnectEnabled"}, }; bool hasAny = false; - for (const auto &key : interfaceRootKeys) { - if (globalIni.contains(key)) { - hasAny = true; - } - } - for (const auto &key : interfaceSubKeys) { - if (globalIni.contains(key)) { - hasAny = true; - } - } for (auto it = interfaceKeyMap.constBegin(); it != interfaceKeyMap.constEnd(); ++it) { if (globalIni.contains(it.key())) { hasAny = true; + break; } } if (!hasAny) { @@ -293,16 +299,6 @@ static void migrateInterfaceSettings(const QString &settingsPath, QSettings &glo } QSettings interfaceIni(settingsPath + "interface.ini", QSettings::IniFormat); - for (const auto &key : interfaceRootKeys) { - if (globalIni.contains(key)) { - interfaceIni.setValue(key, globalIni.value(key)); - } - } - for (const auto &key : interfaceSubKeys) { - if (globalIni.contains(key)) { - interfaceIni.setValue(key, globalIni.value(key)); - } - } for (auto it = interfaceKeyMap.constBegin(); it != interfaceKeyMap.constEnd(); ++it) { if (globalIni.contains(it.key())) { interfaceIni.setValue(it.value(), globalIni.value(it.key())); @@ -313,8 +309,8 @@ static void migrateInterfaceSettings(const QString &settingsPath, QSettings &glo static void migrateDownloadSettings(const QString &settingsPath, QSettings &globalIni) { const QMap downloadKeyMap = { - {"personal/picturedownload", "downloads/picturedownload"}, - {"personal/downloadspoilers", "downloads/downloadspoilers"}, + {"personal/picturedownload", "downloads/pictureDownload"}, + {"personal/downloadspoilers", "downloads/downloadSpoilers"}, }; bool hasAny = false; for (auto it = downloadKeyMap.constBegin(); it != downloadKeyMap.constEnd(); ++it) { @@ -367,11 +363,11 @@ static void migrateAppearanceSettings(const QString &settingsPath, QSettings &gl static void migrateNetworkSettings(const QString &settingsPath, QSettings &globalIni) { const QMap networkKeyMap = { - {"personal/clientid", "network/clientid"}, - {"personal/clientversion", "network/clientversion"}, - {"personal/keepalive", "network/keepalive"}, + {"personal/clientid", "network/clientId"}, + {"personal/clientversion", "network/clientVersion"}, + {"personal/keepalive", "network/keepAlive"}, {"personal/timeout", "network/timeout"}, - {"interface/knownmissingfeatures", "network/knownmissingfeatures"}, + {"interface/knownmissingfeatures", "network/knownMissingFeatures"}, }; bool hasAny = false; for (auto it = networkKeyMap.constBegin(); it != networkKeyMap.constEnd(); ++it) { @@ -394,16 +390,35 @@ static void migrateNetworkSettings(const QString &settingsPath, QSettings &globa static void migratePathsSettings(const QString &settingsPath, QSettings &globalIni) { - globalIni.beginGroup("paths"); - QStringList pathsKeys = globalIni.childKeys(); - globalIni.endGroup(); - if (pathsKeys.isEmpty()) { + const QMap pathsKeyMap = { + {"paths/decks", "paths/decks"}, + {"paths/filters", "paths/filters"}, + {"paths/replays", "paths/replays"}, + {"paths/pics", "paths/pics"}, + {"paths/custompics", "paths/customPics"}, + {"paths/themes", "paths/themes"}, + {"paths/carddatabase", "paths/cardDatabase"}, + {"paths/customsets", "paths/customSets"}, + {"paths/tokendatabase", "paths/tokenDatabase"}, + {"paths/spoilerdatabase", "paths/spoilerDatabase"}, + {"paths/redirects", "paths/redirects"}, + }; + bool hasAny = false; + for (auto it = pathsKeyMap.constBegin(); it != pathsKeyMap.constEnd(); ++it) { + if (globalIni.contains(it.key())) { + hasAny = true; + break; + } + } + if (!hasAny) { return; } QSettings pathsIni(settingsPath + "paths.ini", QSettings::IniFormat); - for (const auto &key : pathsKeys) { - pathsIni.setValue("paths/" + key, globalIni.value("paths/" + key)); + for (auto it = pathsKeyMap.constBegin(); it != pathsKeyMap.constEnd(); ++it) { + if (globalIni.contains(it.key())) { + pathsIni.setValue(it.value(), globalIni.value(it.key())); + } } } @@ -490,9 +505,9 @@ static void migrateLegacySets(const QString &settingsPath) QSettings cardDbIni(settingsPath + "cardDatabase.ini", QSettings::IniFormat); for (const auto &shortName : groups) { legacySetting.beginGroup(shortName); - cardDbIni.setValue("sets/" + shortName + "/sortkey", legacySetting.value("sortkey")); + cardDbIni.setValue("sets/" + shortName + "/sortKey", legacySetting.value("sortkey")); cardDbIni.setValue("sets/" + shortName + "/enabled", legacySetting.value("enabled")); - cardDbIni.setValue("sets/" + shortName + "/isknown", legacySetting.value("isknown")); + cardDbIni.setValue("sets/" + shortName + "/isKnown", legacySetting.value("isknown")); legacySetting.endGroup(); } legacySetting.endGroup(); @@ -508,13 +523,30 @@ static void migrateLegacyServers(const QString &settingsPath) return; } + const QMap serverKeyMap = { + {"previoushostlogin", "previousHostLogin"}, + {"previoushosts", "previousHosts"}, + {"previoushostName", "previousHostName"}, + {"auto_connect", "autoConnect"}, + {"fphostname", "fpHostName"}, + {"fpport", "fpPort"}, + {"fpplayername", "fpPlayerName"}, + {"save_debug_log", "saveDebugLog"}, + }; + QSettings serversIni(settingsPath + "servers.ini", QSettings::IniFormat); - serversIni.setValue("server/previoushostlogin", legacySetting.value("previoushostlogin")); - serversIni.setValue("server/previoushosts", legacySetting.value("previoushosts")); - serversIni.setValue("server/auto_connect", legacySetting.value("auto_connect")); - serversIni.setValue("server/fphostname", legacySetting.value("fphostname")); - serversIni.setValue("server/fpport", legacySetting.value("fpport")); - serversIni.setValue("server/fpplayername", legacySetting.value("fpplayername")); + for (auto it = serverKeyMap.constBegin(); it != serverKeyMap.constEnd(); ++it) { + if (legacySetting.contains(it.key())) { + serversIni.setValue("server/" + it.value(), legacySetting.value(it.key())); + } + } + + legacySetting.beginGroup("server_details"); + const QStringList detailsKeys = legacySetting.allKeys(); + for (const auto &key : detailsKeys) { + serversIni.setValue("server/server_details/" + key, legacySetting.value(key)); + } + legacySetting.endGroup(); legacySetting.endGroup(); } @@ -549,9 +581,36 @@ static void migrateLegacyGameFilters(const QString &settingsPath) return; } + const QMap filterKeyMap = { + {"hide_buddies_only_games", "hideBuddiesOnlyGames"}, + {"hide_full_games", "hideFullGames"}, + {"hide_games_that_started", "hideGamesThatStarted"}, + {"hide_password_protected_games", "hidePasswordProtectedGames"}, + {"hide_ignored_user_games", "hideIgnoredUserGames"}, + {"hide_not_buddy_created_games", "hideNotBuddyCreatedGames"}, + {"hide_open_decklist_games", "hideOpenDecklistGames"}, + {"game_name_filter", "gameNameFilter"}, + {"creator_name_filter", "creatorNameFilter"}, + {"min_players", "minPlayers"}, + {"max_players", "maxPlayers"}, + {"max_game_age_time", "maxGameAgeTime"}, + {"show_only_if_spectators_can_watch", "showOnlyIfSpectatorsCanWatch"}, + {"show_spectator_password_protected", "showSpectatorPasswordProtected"}, + {"show_only_if_spectators_can_chat", "showOnlyIfSpectatorsCanChat"}, + {"show_only_if_spectators_can_see_hands", "showOnlyIfSpectatorsCanSeeHands"}, + }; + QSettings filtersIni(settingsPath + "gamefilters.ini", QSettings::IniFormat); + for (auto it = filterKeyMap.constBegin(); it != filterKeyMap.constEnd(); ++it) { + if (legacySetting.contains(it.key())) { + filtersIni.setValue("filter_games/" + it.value(), legacySetting.value(it.key())); + } + } + const QString gameTypePrefix = "game_type/"; for (const auto &key : keys) { - filtersIni.setValue("filter_games/" + key, legacySetting.value(key)); + if (key.startsWith(gameTypePrefix)) { + filtersIni.setValue("filter_games/gameType/" + key.mid(gameTypePrefix.size()), legacySetting.value(key)); + } } legacySetting.endGroup(); } diff --git a/libcockatrice_settings/libcockatrice/settings/sound_settings.cpp b/libcockatrice_settings/libcockatrice/settings/sound_settings.cpp index 7fd61d263..82b724a07 100644 --- a/libcockatrice_settings/libcockatrice/settings/sound_settings.cpp +++ b/libcockatrice_settings/libcockatrice/settings/sound_settings.cpp @@ -17,7 +17,7 @@ QString SoundSettings::getSoundThemeName() const int SoundSettings::getMasterVolume() const { - return getValue("mastervolume", QString(), QString(), 100).toInt(); + return getValue("masterVolume", QString(), QString(), 100).toInt(); } void SoundSettings::setSoundEnabled(bool _soundEnabled) @@ -34,6 +34,6 @@ void SoundSettings::setSoundThemeName(const QString &_soundThemeName) void SoundSettings::setMasterVolume(int _masterVolume) { - setValue(_masterVolume, "mastervolume"); + setValue(_masterVolume, "masterVolume"); emit masterVolumeChanged(_masterVolume); } diff --git a/libcockatrice_settings/libcockatrice/settings/updates_settings.cpp b/libcockatrice_settings/libcockatrice/settings/updates_settings.cpp index 3d6d77e53..166bc0aa8 100644 --- a/libcockatrice_settings/libcockatrice/settings/updates_settings.cpp +++ b/libcockatrice_settings/libcockatrice/settings/updates_settings.cpp @@ -45,17 +45,17 @@ bool UpdatesSettings::getAlwaysEnableNewSets() const bool UpdatesSettings::getNotifyAboutUpdates() const { - return getValue("updatenotification", QString(), QString(), true).toBool(); + return getValue("updateNotification", QString(), QString(), true).toBool(); } bool UpdatesSettings::getNotifyAboutNewVersion() const { - return getValue("newversionnotification", QString(), QString(), true).toBool(); + return getValue("newVersionNotification", QString(), QString(), true).toBool(); } int UpdatesSettings::getUpdateReleaseChannelIndex() const { - return getValue("updatereleasechannel", QString(), QString(), 0).toInt(); + return getValue("updateReleaseChannel", QString(), QString(), 0).toInt(); } void UpdatesSettings::setCheckUpdatesOnStartup(bool value) @@ -90,15 +90,15 @@ void UpdatesSettings::setAlwaysEnableNewSets(bool value) void UpdatesSettings::setNotifyAboutUpdates(bool _notifyaboutupdate) { - setValue(_notifyaboutupdate, "updatenotification"); + setValue(_notifyaboutupdate, "updateNotification"); } void UpdatesSettings::setNotifyAboutNewVersion(bool _notifyaboutnewversion) { - setValue(_notifyaboutnewversion, "newversionnotification"); + setValue(_notifyaboutnewversion, "newVersionNotification"); } void UpdatesSettings::setUpdateReleaseChannelIndex(int value) { - setValue(value, "updatereleasechannel"); + setValue(value, "updateReleaseChannel"); } diff --git a/tests/settings/settings_migration_test.cpp b/tests/settings/settings_migration_test.cpp index 272318090..a004cd9e6 100644 --- a/tests/settings/settings_migration_test.cpp +++ b/tests/settings/settings_migration_test.cpp @@ -273,25 +273,25 @@ TEST_F(SettingsMigrationTest, MigratesAllSettingsGroups) ASSERT_TRUE(fileExists("sound.ini")); ASSERT_EQ(readFromIni("sound.ini", "sound/enabled"), QVariant(true)); ASSERT_EQ(readFromIni("sound.ini", "sound/theme"), QVariant("custom_theme")); - ASSERT_EQ(readFromIni("sound.ini", "sound/mastervolume"), QVariant(75)); + ASSERT_EQ(readFromIni("sound.ini", "sound/masterVolume"), QVariant(75)); ASSERT_TRUE(fileExists("game.ini")); - ASSERT_EQ(readFromIni("game.ini", "game/maxplayers"), QVariant(4)); - ASSERT_EQ(readFromIni("game.ini", "game/gamedescription"), QVariant("test game")); - ASSERT_EQ(readFromIni("game.ini", "game/remembergamesettings"), QVariant(false)); - ASSERT_EQ(readFromIni("game.ini", "game/gametypes"), QVariant("commander")); - ASSERT_EQ(readFromIni("game.ini", "game/onlybuddies"), QVariant(true)); - ASSERT_EQ(readFromIni("game.ini", "localgameoptions/maxplayers"), QVariant(2)); - ASSERT_EQ(readFromIni("game.ini", "localgameoptions/startinglifetotal"), QVariant(40)); + ASSERT_EQ(readFromIni("game.ini", "game/maxPlayers"), QVariant(4)); + ASSERT_EQ(readFromIni("game.ini", "game/gameDescription"), QVariant("test game")); + ASSERT_EQ(readFromIni("game.ini", "game/rememberGameSettings"), QVariant(false)); + ASSERT_EQ(readFromIni("game.ini", "game/gameTypes"), QVariant("commander")); + ASSERT_EQ(readFromIni("game.ini", "game/onlyBuddies"), QVariant(true)); + ASSERT_EQ(readFromIni("game.ini", "localgameoptions/maxPlayers"), QVariant(2)); + ASSERT_EQ(readFromIni("game.ini", "localgameoptions/startingLifeTotal"), QVariant(40)); ASSERT_TRUE(fileExists("chat.ini")); ASSERT_EQ(readFromIni("chat.ini", "chat/mention"), QVariant(false)); - ASSERT_EQ(readFromIni("chat.ini", "chat/mentioncolor"), QVariant("FF0000")); - ASSERT_EQ(readFromIni("chat.ini", "chat/showmessagepopups"), QVariant(false)); - ASSERT_EQ(readFromIni("chat.ini", "chat/mentioncompleter"), QVariant(false)); - ASSERT_EQ(readFromIni("chat.ini", "chat/roomhistory"), QVariant(false)); - ASSERT_EQ(readFromIni("chat.ini", "chat/highlightcolor"), QVariant("00FF00")); - ASSERT_EQ(readFromIni("chat.ini", "chat/highlightwords"), QVariant("alpha beta")); + ASSERT_EQ(readFromIni("chat.ini", "chat/mentionColor"), QVariant("FF0000")); + ASSERT_EQ(readFromIni("chat.ini", "chat/showMessagePopups"), QVariant(false)); + ASSERT_EQ(readFromIni("chat.ini", "chat/mentionCompleter"), QVariant(false)); + ASSERT_EQ(readFromIni("chat.ini", "chat/roomHistory"), QVariant(false)); + ASSERT_EQ(readFromIni("chat.ini", "chat/highlightColor"), QVariant("00FF00")); + ASSERT_EQ(readFromIni("chat.ini", "chat/highlightWords"), QVariant("alpha beta")); ASSERT_TRUE(fileExists("cache_storage.ini")); ASSERT_EQ(readFromIni("cache_storage.ini", "cache_storage/pixmapCacheSize"), QVariant(1024)); @@ -307,8 +307,8 @@ TEST_F(SettingsMigrationTest, MigratesAllSettingsGroups) ASSERT_EQ(readFromIni("updates.ini", "updates/cardUpdateCheckInterval"), QVariant(14)); ASSERT_EQ(readFromIni("updates.ini", "updates/lastCardUpdateCheck"), QVariant(QDate(2024, 1, 1))); ASSERT_EQ(readFromIni("updates.ini", "updates/alwaysEnableNewSets"), QVariant(true)); - ASSERT_EQ(readFromIni("updates.ini", "updates/updatenotification"), QVariant(false)); - ASSERT_EQ(readFromIni("updates.ini", "updates/newversionnotification"), QVariant(false)); + ASSERT_EQ(readFromIni("updates.ini", "updates/updateNotification"), QVariant(false)); + ASSERT_EQ(readFromIni("updates.ini", "updates/newVersionNotification"), QVariant(false)); ASSERT_TRUE(fileExists("personal.ini")); ASSERT_EQ(readFromIni("personal.ini", "personal/lang"), QVariant("de")); @@ -316,8 +316,8 @@ TEST_F(SettingsMigrationTest, MigratesAllSettingsGroups) ASSERT_EQ(readFromIni("personal.ini", "tipOfDay/seenTips"), QVariant(QStringList{"1", "2", "3"})); ASSERT_TRUE(fileExists("downloads.ini")); - ASSERT_EQ(readFromIni("downloads.ini", "downloads/picturedownload"), QVariant(true)); - ASSERT_EQ(readFromIni("downloads.ini", "downloads/downloadspoilers"), QVariant(true)); + ASSERT_EQ(readFromIni("downloads.ini", "downloads/pictureDownload"), QVariant(true)); + ASSERT_EQ(readFromIni("downloads.ini", "downloads/downloadSpoilers"), QVariant(true)); ASSERT_TRUE(fileExists("appearance.ini")); ASSERT_EQ(readFromIni("appearance.ini", "appearance/themeName"), QVariant("custom_theme")); @@ -328,23 +328,23 @@ TEST_F(SettingsMigrationTest, MigratesAllSettingsGroups) ASSERT_EQ(readFromIni("appearance.ini", "appearance/homeTabDisplayCardName"), QVariant(false)); ASSERT_TRUE(fileExists("network.ini")); - ASSERT_EQ(readFromIni("network.ini", "network/keepalive"), QVariant(10)); + ASSERT_EQ(readFromIni("network.ini", "network/keepAlive"), QVariant(10)); ASSERT_EQ(readFromIni("network.ini", "network/timeout"), QVariant(30)); - ASSERT_EQ(readFromIni("network.ini", "network/clientid"), QVariant("test-client-id")); - ASSERT_EQ(readFromIni("network.ini", "network/clientversion"), QVariant("test-client-version")); - ASSERT_EQ(readFromIni("network.ini", "network/knownmissingfeatures"), QVariant("feature1,feature2")); + ASSERT_EQ(readFromIni("network.ini", "network/clientId"), QVariant("test-client-id")); + ASSERT_EQ(readFromIni("network.ini", "network/clientVersion"), QVariant("test-client-version")); + ASSERT_EQ(readFromIni("network.ini", "network/knownMissingFeatures"), QVariant("feature1,feature2")); ASSERT_TRUE(fileExists("cards_display.ini")); - ASSERT_EQ(readFromIni("cards_display.ini", "cards/displaycardnames"), QVariant(false)); - ASSERT_EQ(readFromIni("cards_display.ini", "cards/roundcardcorners"), QVariant(false)); - ASSERT_EQ(readFromIni("cards_display.ini", "cards/overrideallcardartwithpersonalpreference"), QVariant(true)); - ASSERT_EQ(readFromIni("cards_display.ini", "cards/bumpsetswithcardsindecktotop"), QVariant(false)); + ASSERT_EQ(readFromIni("cards_display.ini", "cards/displayCardNames"), QVariant(false)); + ASSERT_EQ(readFromIni("cards_display.ini", "cards/roundCardCorners"), QVariant(false)); + ASSERT_EQ(readFromIni("cards_display.ini", "cards/overrideAllCardArtWithPersonalPreference"), QVariant(true)); + ASSERT_EQ(readFromIni("cards_display.ini", "cards/bumpSetsWithCardsInDeckToTop"), QVariant(false)); ASSERT_EQ(readFromIni("cards_display.ini", "cards/includerebalancedcards"), QVariant(false)); - ASSERT_EQ(readFromIni("cards_display.ini", "cards/autorotatesidewayslayoutcards"), QVariant(false)); - ASSERT_EQ(readFromIni("cards_display.ini", "cards/tapanimation"), QVariant(true)); + ASSERT_EQ(readFromIni("cards_display.ini", "cards/autoRotateSidewaysLayoutCards"), QVariant(false)); + ASSERT_EQ(readFromIni("cards_display.ini", "cards/tapAnimation"), QVariant(true)); ASSERT_EQ(readFromIni("cards_display.ini", "cards/scaleCards"), QVariant(false)); ASSERT_EQ(readFromIni("cards_display.ini", "cards/verticalCardOverlapPercent"), QVariant(42)); - ASSERT_EQ(readFromIni("cards_display.ini", "cards/cardinfoviewmode"), QVariant(1)); + ASSERT_EQ(readFromIni("cards_display.ini", "cards/cardInfoViewMode"), QVariant(1)); ASSERT_EQ(readFromIni("cards_display.ini", "cards/cardSize/printingSelector"), QVariant(90)); ASSERT_EQ(readFromIni("cards_display.ini", "cards/printingSelector/sortOrder"), QVariant(3)); ASSERT_EQ(readFromIni("cards_display.ini", "cards/printingSelector/navigationButtonsVisible"), QVariant(false)); @@ -356,7 +356,7 @@ TEST_F(SettingsMigrationTest, MigratesAllSettingsGroups) ASSERT_EQ(readFromIni("cards_display.ini", "cards/cardSize/sampleHandSize"), QVariant(5)); ASSERT_TRUE(fileExists("interface.ini")); - ASSERT_EQ(readFromIni("interface.ini", "interface/usetearoffmenus"), QVariant(true)); + ASSERT_EQ(readFromIni("interface.ini", "interface/useTearOffMenus"), QVariant(true)); ASSERT_EQ(readFromIni("interface.ini", "interface/cardViewInitialRowsMax"), QVariant(8)); ASSERT_EQ(readFromIni("interface.ini", "interface/cardViewExpandedRowsMax"), QVariant(12)); ASSERT_EQ(readFromIni("interface.ini", "interface/closeEmptyCardView"), QVariant(false)); @@ -365,27 +365,27 @@ TEST_F(SettingsMigrationTest, MigratesAllSettingsGroups) ASSERT_EQ(readFromIni("interface.ini", "interface/notifications/enabled"), QVariant(false)); ASSERT_EQ(readFromIni("interface.ini", "interface/notifications/spectatorsEnabled"), QVariant(true)); ASSERT_EQ(readFromIni("interface.ini", "interface/notifications/buddyConnectEnabled"), QVariant(false)); - ASSERT_EQ(readFromIni("interface.ini", "interface/doubleclicktoplay"), QVariant(false)); + ASSERT_EQ(readFromIni("interface.ini", "interface/doubleClickToPlay"), QVariant(false)); ASSERT_EQ(readFromIni("interface.ini", "interface/clickPlaysAllSelected"), QVariant(false)); - ASSERT_EQ(readFromIni("interface.ini", "interface/playtostack"), QVariant(false)); + ASSERT_EQ(readFromIni("interface.ini", "interface/playToStack"), QVariant(false)); ASSERT_EQ(readFromIni("interface.ini", "interface/doNotDeleteArrowsInSubPhases"), QVariant(false)); - ASSERT_EQ(readFromIni("interface.ini", "interface/startinghandsize"), QVariant(5)); - ASSERT_EQ(readFromIni("interface.ini", "interface/annotatetokens"), QVariant(true)); - ASSERT_EQ(readFromIni("interface.ini", "interface/showlassoselectioncount"), QVariant(false)); - ASSERT_EQ(readFromIni("interface.ini", "interface/showpersistentselectioncount"), QVariant(false)); + ASSERT_EQ(readFromIni("interface.ini", "interface/startingHandSize"), QVariant(5)); + ASSERT_EQ(readFromIni("interface.ini", "interface/annotateTokens"), QVariant(true)); + ASSERT_EQ(readFromIni("interface.ini", "interface/showLassoSelectionCount"), QVariant(false)); + ASSERT_EQ(readFromIni("interface.ini", "interface/showPersistentSelectionCount"), QVariant(false)); ASSERT_EQ(readFromIni("interface.ini", "interface/tallyType"), QVariant(2)); - ASSERT_EQ(readFromIni("interface.ini", "interface/leftjustified"), QVariant(true)); - ASSERT_EQ(readFromIni("interface.ini", "interface/min_players_multicolumn"), QVariant(6)); + ASSERT_EQ(readFromIni("interface.ini", "interface/leftJustified"), QVariant(true)); + ASSERT_EQ(readFromIni("interface.ini", "interface/minPlayersMulticolumn"), QVariant(6)); ASSERT_EQ(readFromIni("interface.ini", "interface/showStatusBar"), QVariant(true)); ASSERT_EQ(readFromIni("interface.ini", "interface/showShortcuts"), QVariant(false)); ASSERT_EQ(readFromIni("interface.ini", "interface/showGameSelectorFilterToolbar"), QVariant(false)); ASSERT_EQ(readFromIni("interface.ini", "hand/horizontal"), QVariant(true)); - ASSERT_EQ(readFromIni("interface.ini", "table/invert_vertical"), QVariant(true)); + ASSERT_EQ(readFromIni("interface.ini", "table/invertVertical"), QVariant(true)); ASSERT_EQ(readFromIni("interface.ini", "replay/rewindBufferingMs"), QVariant(6000)); ASSERT_EQ(readFromIni("interface.ini", "replay/fastForwardSpeed"), QVariant(5)); - ASSERT_EQ(readFromIni("interface.ini", "zoneview/groupby"), QVariant(2)); - ASSERT_EQ(readFromIni("interface.ini", "zoneview/sortby"), QVariant(1)); - ASSERT_EQ(readFromIni("interface.ini", "zoneview/pileview"), QVariant(false)); + ASSERT_EQ(readFromIni("interface.ini", "zoneview/groupBy"), QVariant(2)); + ASSERT_EQ(readFromIni("interface.ini", "zoneview/sortBy"), QVariant(1)); + ASSERT_EQ(readFromIni("interface.ini", "zoneview/pileView"), QVariant(false)); ASSERT_TRUE(fileExists("deck_editor.ini")); ASSERT_EQ(readFromIni("deck_editor.ini", "deckeditor/openDeckInNewTab"), QVariant(false)); @@ -434,6 +434,25 @@ TEST_F(SettingsMigrationTest, MigratesAllSettingsGroups) ASSERT_FALSE(readFromIni("cards_display.ini", "cards/printingselectorsortorder").isValid()); ASSERT_FALSE(readFromIni("cards_display.ini", "cards/visualDeckStorage/cardSize").isValid()); + // No legacy non-camelCase keys should remain in the per-file INIs + ASSERT_FALSE(readFromIni("game.ini", "game/gamedescription").isValid()); + ASSERT_FALSE(readFromIni("game.ini", "localgameoptions/maxplayers").isValid()); + ASSERT_FALSE(readFromIni("chat.ini", "chat/roomhistory").isValid()); + ASSERT_FALSE(readFromIni("chat.ini", "chat/highlightwords").isValid()); + ASSERT_FALSE(readFromIni("sound.ini", "sound/mastervolume").isValid()); + ASSERT_FALSE(readFromIni("downloads.ini", "downloads/picturedownload").isValid()); + ASSERT_FALSE(readFromIni("network.ini", "network/keepalive").isValid()); + ASSERT_FALSE(readFromIni("network.ini", "network/knownmissingfeatures").isValid()); + ASSERT_FALSE(readFromIni("updates.ini", "updates/updatenotification").isValid()); + ASSERT_FALSE(readFromIni("cards_display.ini", "cards/displaycardnames").isValid()); + ASSERT_FALSE(readFromIni("cards_display.ini", "cards/cardinfoviewmode").isValid()); + ASSERT_FALSE(readFromIni("interface.ini", "interface/usetearoffmenus").isValid()); + ASSERT_FALSE(readFromIni("interface.ini", "interface/doubleclicktoplay").isValid()); + ASSERT_FALSE(readFromIni("interface.ini", "interface/min_players_multicolumn").isValid()); + ASSERT_FALSE(readFromIni("interface.ini", "table/invert_vertical").isValid()); + ASSERT_FALSE(readFromIni("interface.ini", "zoneview/groupby").isValid()); + ASSERT_FALSE(readFromIni("interface.ini", "zoneview/pileview").isValid()); + // Verify sentinel was written ASSERT_EQ(readFromIni("global.ini", "migration/perfile_complete"), QVariant(true)); } @@ -512,7 +531,7 @@ TEST_F(SettingsMigrationTest, KeyMapTranslationIsCorrect) ASSERT_TRUE(fileExists("updates.ini")); // The key should be translated from "personal/cardUpdateCheckInterval" to "updates/cardUpdateCheckInterval" ASSERT_EQ(readFromIni("updates.ini", "updates/cardUpdateCheckInterval"), QVariant(30)); - ASSERT_EQ(readFromIni("updates.ini", "updates/updatereleasechannel"), QVariant(1)); + ASSERT_EQ(readFromIni("updates.ini", "updates/updateReleaseChannel"), QVariant(1)); } TEST_F(SettingsMigrationTest, CardsKeysKeepGroupPrefix) @@ -530,7 +549,7 @@ TEST_F(SettingsMigrationTest, CardsKeysKeepGroupPrefix) ASSERT_TRUE(fileExists("cards_display.ini")); ASSERT_TRUE(fileExists("deck_editor.ini")); // "cards/displaycardnames" should be stored with its group prefix - ASSERT_EQ(readFromIni("cards_display.ini", "cards/displaycardnames"), QVariant(false)); + ASSERT_EQ(readFromIni("cards_display.ini", "cards/displayCardNames"), QVariant(false)); // deck editor keys belong to the deck editor settings now ASSERT_EQ(readFromIni("deck_editor.ini", "deckeditor/bannerCardComboBoxVisible"), QVariant(true)); } @@ -553,17 +572,68 @@ TEST_F(SettingsMigrationTest, LegacyMigrationIsIdempotent) // Change the migrated value { QSettings serversIni(settingsPath + "servers.ini", QSettings::IniFormat); - serversIni.setValue("server/previoushostlogin", "modified_user"); + serversIni.setValue("server/previousHostLogin", "modified_user"); serversIni.sync(); } // Second migration should NOT overwrite the change ASSERT_FALSE(SettingsMigration::migrateLegacySettings(settingsPath)); - ASSERT_EQ(readFromIni("servers.ini", "server/previoushostlogin"), QVariant("modified_user")); + ASSERT_EQ(readFromIni("servers.ini", "server/previousHostLogin"), QVariant("modified_user")); +} + +TEST_F(SettingsMigrationTest, LegacyMigrationCamelCasesKeys) +{ + if (!nativeSettingsAvailable()) { + GTEST_SKIP() << "NativeFormat QSettings not available in this environment"; + } + + { + QSettings nativeSettings; + nativeSettings.setValue("sets/AAA/sortkey", 2); + nativeSettings.setValue("sets/AAA/enabled", false); + nativeSettings.setValue("sets/AAA/isknown", false); + nativeSettings.setValue("server/previoushostlogin", "legacy_user"); + nativeSettings.setValue("server/auto_connect", 1); + nativeSettings.setValue("server/fpport", "5080"); + nativeSettings.setValue("messages/count", 1); + nativeSettings.setValue("messages/msg0", "hello"); + nativeSettings.setValue("filter_games/hide_full_games", true); + nativeSettings.setValue("filter_games/min_players", 3); + nativeSettings.setValue("filter_games/max_players", 5); + nativeSettings.setValue("filter_games/game_type/deadbeef", true); + nativeSettings.sync(); + } + + ASSERT_TRUE(SettingsMigration::migrateLegacySettings(settingsPath)); + + ASSERT_TRUE(fileExists("cardDatabase.ini")); + ASSERT_EQ(readFromIni("cardDatabase.ini", "sets/AAA/sortKey"), QVariant(2)); + ASSERT_EQ(readFromIni("cardDatabase.ini", "sets/AAA/enabled"), QVariant(false)); + ASSERT_EQ(readFromIni("cardDatabase.ini", "sets/AAA/isKnown"), QVariant(false)); + + ASSERT_TRUE(fileExists("servers.ini")); + ASSERT_EQ(readFromIni("servers.ini", "server/previousHostLogin"), QVariant("legacy_user")); + ASSERT_EQ(readFromIni("servers.ini", "server/autoConnect"), QVariant(1)); + ASSERT_EQ(readFromIni("servers.ini", "server/fpPort"), QVariant("5080")); + + ASSERT_TRUE(fileExists("messages.ini")); + ASSERT_EQ(readFromIni("messages.ini", "messages/count"), QVariant(1)); + ASSERT_EQ(readFromIni("messages.ini", "messages/msg0"), QVariant("hello")); + + ASSERT_TRUE(fileExists("gamefilters.ini")); + ASSERT_EQ(readFromIni("gamefilters.ini", "filter_games/hideFullGames"), QVariant(true)); + ASSERT_EQ(readFromIni("gamefilters.ini", "filter_games/minPlayers"), QVariant(3)); + ASSERT_EQ(readFromIni("gamefilters.ini", "filter_games/maxPlayers"), QVariant(5)); + ASSERT_EQ(readFromIni("gamefilters.ini", "filter_games/gameType/deadbeef"), QVariant(true)); } TEST_F(SettingsMigrationTest, LegacyMigrationEmptyNativeFormatWritesSentinel) { + if (nativeSettingsAvailable()) { + QSettings().clear(); + QSettings().sync(); + } + ASSERT_TRUE(SettingsMigration::migrateLegacySettings(settingsPath)); ASSERT_TRUE(fileExists("personal.ini")); ASSERT_EQ(readFromIni("personal.ini", "migration/legacy_complete"), QVariant(true));