Initial commit of mtgonline project
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#include "card_database_settings.h"
|
||||
|
||||
CardDatabaseSettings::CardDatabaseSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "cardDatabase.ini", QString(), QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
void CardDatabaseSettings::setSortKey(QString shortName, unsigned int sortKey)
|
||||
{
|
||||
setValue(sortKey, "sortkey", "sets", std::move(shortName));
|
||||
}
|
||||
|
||||
void CardDatabaseSettings::setEnabled(QString shortName, bool enabled)
|
||||
{
|
||||
setValue(enabled, "enabled", "sets", std::move(shortName));
|
||||
}
|
||||
|
||||
void CardDatabaseSettings::setIsKnown(QString shortName, bool isknown)
|
||||
{
|
||||
setValue(isknown, "isknown", "sets", std::move(shortName));
|
||||
}
|
||||
|
||||
unsigned int CardDatabaseSettings::getSortKey(QString shortName) const
|
||||
{
|
||||
return getValue("sortkey", "sets", std::move(shortName)).toUInt();
|
||||
}
|
||||
|
||||
bool CardDatabaseSettings::isEnabled(QString shortName) const
|
||||
{
|
||||
return getValue("enabled", "sets", std::move(shortName)).toBool();
|
||||
}
|
||||
|
||||
bool CardDatabaseSettings::isKnown(QString shortName) const
|
||||
{
|
||||
return getValue("isknown", "sets", std::move(shortName)).toBool();
|
||||
}
|
||||
|
||||
void CardDatabaseSettings::saveSets(const QVector<ICardSetPriorityController::SetSaveData> &data)
|
||||
{
|
||||
batchWrite([&](QSettings &s) {
|
||||
s.beginGroup("sets");
|
||||
for (const auto &entry : data) {
|
||||
s.beginGroup(entry.shortName);
|
||||
s.setValue("sortkey", entry.sortKey);
|
||||
s.setValue("enabled", entry.enabled);
|
||||
s.endGroup();
|
||||
}
|
||||
s.endGroup();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @file card_database_settings.h
|
||||
* @ingroup CardDatabase
|
||||
* @ingroup CardSettings
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef CARDDATABASESETTINGS_H
|
||||
#define CARDDATABASESETTINGS_H
|
||||
|
||||
#include "settings_manager.h"
|
||||
|
||||
#include <libcockatrice/interfaces/interface_card_set_priority_controller.h>
|
||||
|
||||
class CardDatabaseSettings : public SettingsManager, public ICardSetPriorityController
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
|
||||
public:
|
||||
void setSortKey(QString shortName, unsigned int sortKey) override;
|
||||
void setEnabled(QString shortName, bool enabled) override;
|
||||
void setIsKnown(QString shortName, bool isknown) override;
|
||||
|
||||
unsigned int getSortKey(QString shortName) const override;
|
||||
bool isEnabled(QString shortName) const override;
|
||||
bool isKnown(QString shortName) const override;
|
||||
|
||||
void saveSets(const QVector<SetSaveData> &data) override;
|
||||
|
||||
private:
|
||||
explicit CardDatabaseSettings(const QString &settingPath, QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
#endif // CARDDATABASESETTINGS_H
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "card_override_settings.h"
|
||||
|
||||
CardOverrideSettings::CardOverrideSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "cardPreferenceOverrides.ini", "cards", QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
void CardOverrideSettings::setCardPreferenceOverride(const CardRef &cardRef)
|
||||
{
|
||||
setValue(cardRef.providerId, cardRef.name);
|
||||
}
|
||||
|
||||
void CardOverrideSettings::deleteCardPreferenceOverride(const QString &cardName)
|
||||
{
|
||||
deleteValue(cardName);
|
||||
}
|
||||
|
||||
QString CardOverrideSettings::getCardPreferenceOverride(const QString &cardName) const
|
||||
{
|
||||
return getValue(cardName).toString();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @file card_override_settings.h
|
||||
* @ingroup CardSettings
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_CARD_OVERRIDE_SETTINGS_H
|
||||
#define COCKATRICE_CARD_OVERRIDE_SETTINGS_H
|
||||
|
||||
#include "settings_manager.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <libcockatrice/utility/card_ref.h>
|
||||
|
||||
class CardOverrideSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
|
||||
public:
|
||||
void setCardPreferenceOverride(const CardRef &cardRef);
|
||||
|
||||
void deleteCardPreferenceOverride(const QString &cardName);
|
||||
|
||||
QString getCardPreferenceOverride(const QString &cardName) const;
|
||||
|
||||
private:
|
||||
explicit CardOverrideSettings(const QString &settingPath, QObject *parent = nullptr);
|
||||
CardOverrideSettings(const CardOverrideSettings & /*other*/);
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_CARD_OVERRIDE_SETTINGS_H
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "debug_settings.h"
|
||||
|
||||
#include <QtCore/QFile>
|
||||
|
||||
DebugSettings::DebugSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "debug.ini", "debug", QString(), parent)
|
||||
{
|
||||
// Create the default debug.ini if it doesn't exist yet
|
||||
if (!QFile(settingPath + "debug.ini").exists()) {
|
||||
QFile::copy(":/resources/config/debug.ini", settingPath + "debug.ini");
|
||||
}
|
||||
}
|
||||
|
||||
bool DebugSettings::getShowCardId() const
|
||||
{
|
||||
return getValue("showCardId").toBool();
|
||||
}
|
||||
|
||||
bool DebugSettings::getLocalGameOnStartup() const
|
||||
{
|
||||
return getValue("onStartup", "localgame").toBool();
|
||||
}
|
||||
|
||||
int DebugSettings::getLocalGamePlayerCount() const
|
||||
{
|
||||
return getValue("playerCount", "localgame").toInt();
|
||||
}
|
||||
|
||||
QString DebugSettings::getDeckPathForPlayer(const QString &playerName) const
|
||||
{
|
||||
return getValue(playerName, "localgame", "deck").toString();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @file debug_settings.h
|
||||
* @ingroup CoreSettings
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef DEBUG_SETTINGS_H
|
||||
#define DEBUG_SETTINGS_H
|
||||
#include "settings_manager.h"
|
||||
|
||||
class DebugSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
|
||||
explicit DebugSettings(const QString &settingPath, QObject *parent = nullptr);
|
||||
DebugSettings(const DebugSettings & /*other*/);
|
||||
|
||||
public:
|
||||
bool getShowCardId() const;
|
||||
|
||||
bool getLocalGameOnStartup() const;
|
||||
int getLocalGamePlayerCount() const;
|
||||
|
||||
QString getDeckPathForPlayer(const QString &playerName) const;
|
||||
};
|
||||
|
||||
#endif // DEBUG_SETTINGS_H
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "download_settings.h"
|
||||
|
||||
#include "settings_manager.h"
|
||||
|
||||
const QStringList DownloadSettings::DEFAULT_DOWNLOAD_URLS = {
|
||||
"https://api.scryfall.com/cards/!set:uuid!?format=image&face=!prop:side!",
|
||||
"https://api.scryfall.com/cards/multiverse/!set:muid!?format=image",
|
||||
"https://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=!set:muid!&type=card",
|
||||
"https://gatherer.wizards.com/Handlers/Image.ashx?name=!name!&type=card"};
|
||||
|
||||
DownloadSettings::DownloadSettings(const QString &settingPath, QObject *parent = nullptr)
|
||||
: SettingsManager(settingPath + "downloads.ini", "downloads", QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
void DownloadSettings::setDownloadUrls(const QStringList &downloadURLs)
|
||||
{
|
||||
setValue(QVariant::fromValue(downloadURLs), "urls");
|
||||
}
|
||||
|
||||
QStringList DownloadSettings::getAllURLs() const
|
||||
{
|
||||
return getValue("urls").toStringList();
|
||||
}
|
||||
|
||||
void DownloadSettings::resetToDefaultURLs()
|
||||
{
|
||||
setValue(QVariant::fromValue(DEFAULT_DOWNLOAD_URLS), "urls");
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @file download_settings.h
|
||||
* @ingroup NetworkSettings
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef COCKATRICE_DOWNLOADSETTINGS_H
|
||||
#define COCKATRICE_DOWNLOADSETTINGS_H
|
||||
|
||||
#include "settings_manager.h"
|
||||
|
||||
class DownloadSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
|
||||
static const QStringList DEFAULT_DOWNLOAD_URLS;
|
||||
|
||||
public:
|
||||
explicit DownloadSettings(const QString &, QObject *);
|
||||
|
||||
QStringList getAllURLs() const;
|
||||
void setDownloadUrls(const QStringList &downloadURLs);
|
||||
void resetToDefaultURLs();
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_DOWNLOADSETTINGS_H
|
||||
@@ -0,0 +1,208 @@
|
||||
#include "game_filters_settings.h"
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QTime>
|
||||
|
||||
GameFiltersSettings::GameFiltersSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "gamefilters.ini", "filter_games", QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* The game type might contain special characters, so to use it in
|
||||
* QSettings we just hash it.
|
||||
*/
|
||||
static QString hashGameType(const QString &gameType)
|
||||
{
|
||||
return QCryptographicHash::hash(gameType.toUtf8(), QCryptographicHash::Md5).toHex();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHideBuddiesOnlyGames(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_buddies_only_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHideBuddiesOnlyGames() const
|
||||
{
|
||||
QVariant previous = getValue("hide_buddies_only_games");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHideFullGames(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_full_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHideFullGames() const
|
||||
{
|
||||
QVariant previous = getValue("hide_full_games");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHideGamesThatStarted(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_games_that_started");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHideGamesThatStarted() const
|
||||
{
|
||||
QVariant previous = getValue("hide_games_that_started");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHidePasswordProtectedGames(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_password_protected_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHidePasswordProtectedGames() const
|
||||
{
|
||||
QVariant previous = getValue("hide_password_protected_games");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHideIgnoredUserGames(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_ignored_user_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHideIgnoredUserGames() const
|
||||
{
|
||||
QVariant previous = getValue("hide_ignored_user_games");
|
||||
return previous == QVariant() ? true : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHideNotBuddyCreatedGames(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_not_buddy_created_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHideNotBuddyCreatedGames() const
|
||||
{
|
||||
QVariant previous = getValue("hide_not_buddy_created_games");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHideOpenDecklistGames(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_open_decklist_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHideOpenDecklistGames() const
|
||||
{
|
||||
QVariant previous = getValue("hide_open_decklist_games");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setGameNameFilter(QString gameName)
|
||||
{
|
||||
setValue(gameName, "game_name_filter");
|
||||
}
|
||||
|
||||
QString GameFiltersSettings::getGameNameFilter() const
|
||||
{
|
||||
return getValue("game_name_filter").toString();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setCreatorNameFilters(QStringList creatorName)
|
||||
{
|
||||
setValue(creatorName, "creator_name_filter");
|
||||
}
|
||||
|
||||
QStringList GameFiltersSettings::getCreatorNameFilters() const
|
||||
{
|
||||
return getValue("creator_name_filter").toStringList();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setMinPlayers(int min)
|
||||
{
|
||||
setValue(min, "min_players");
|
||||
}
|
||||
|
||||
int GameFiltersSettings::getMinPlayers() const
|
||||
{
|
||||
QVariant previous = getValue("min_players");
|
||||
return previous == QVariant() ? 1 : previous.toInt();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setMaxPlayers(int max)
|
||||
{
|
||||
setValue(max, "max_players");
|
||||
}
|
||||
|
||||
int GameFiltersSettings::getMaxPlayers() const
|
||||
{
|
||||
QVariant previous = getValue("max_players");
|
||||
return previous == QVariant() ? 99 : previous.toInt();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setMaxGameAge(const QTime &maxGameAge)
|
||||
{
|
||||
setValue(maxGameAge, "max_game_age_time");
|
||||
}
|
||||
|
||||
QTime GameFiltersSettings::getMaxGameAge() const
|
||||
{
|
||||
QVariant previous = getValue("max_game_age_time");
|
||||
return previous.toTime();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setGameTypeEnabled(QString gametype, bool enabled)
|
||||
{
|
||||
setValue(enabled, "game_type/" + hashGameType(gametype));
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setGameHashedTypeEnabled(QString gametypeHASHED, bool enabled)
|
||||
{
|
||||
setValue(enabled, gametypeHASHED);
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isGameTypeEnabled(QString gametype) const
|
||||
{
|
||||
QVariant previous = getValue("game_type/" + hashGameType(gametype));
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setShowOnlyIfSpectatorsCanWatch(bool show)
|
||||
{
|
||||
setValue(show, "show_only_if_spectators_can_watch");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isShowOnlyIfSpectatorsCanWatch() const
|
||||
{
|
||||
QVariant previous = getValue("show_only_if_spectators_can_watch");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setShowSpectatorPasswordProtected(bool show)
|
||||
{
|
||||
setValue(show, "show_spectator_password_protected");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isShowSpectatorPasswordProtected() const
|
||||
{
|
||||
QVariant previous = getValue("show_spectator_password_protected");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setShowOnlyIfSpectatorsCanChat(bool show)
|
||||
{
|
||||
setValue(show, "show_only_if_spectators_can_chat");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isShowOnlyIfSpectatorsCanChat() const
|
||||
{
|
||||
QVariant previous = getValue("show_only_if_spectators_can_chat");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setShowOnlyIfSpectatorsCanSeeHands(bool show)
|
||||
{
|
||||
setValue(show, "show_only_if_spectators_can_see_hands");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isShowOnlyIfSpectatorsCanSeeHands() const
|
||||
{
|
||||
QVariant previous = getValue("show_only_if_spectators_can_see_hands");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @file game_filters_settings.h
|
||||
* @ingroup Lobby
|
||||
* @ingroup GameSettings
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef GAMEFILTERSSETTINGS_H
|
||||
#define GAMEFILTERSSETTINGS_H
|
||||
|
||||
#include "settings_manager.h"
|
||||
|
||||
class GameFiltersSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
|
||||
public:
|
||||
bool isHideBuddiesOnlyGames() const;
|
||||
bool isHideFullGames() const;
|
||||
bool isHideGamesThatStarted() const;
|
||||
bool isHidePasswordProtectedGames() const;
|
||||
bool isHideIgnoredUserGames() const;
|
||||
bool isHideNotBuddyCreatedGames() const;
|
||||
bool isHideOpenDecklistGames() const;
|
||||
QString getGameNameFilter() const;
|
||||
QStringList getCreatorNameFilters() const;
|
||||
int getMinPlayers() const;
|
||||
int getMaxPlayers() const;
|
||||
QTime getMaxGameAge() const;
|
||||
bool isGameTypeEnabled(QString gametype) const;
|
||||
bool isShowOnlyIfSpectatorsCanWatch() const;
|
||||
bool isShowSpectatorPasswordProtected() const;
|
||||
bool isShowOnlyIfSpectatorsCanChat() const;
|
||||
bool isShowOnlyIfSpectatorsCanSeeHands() const;
|
||||
|
||||
void setHideBuddiesOnlyGames(bool hide);
|
||||
void setHideIgnoredUserGames(bool hide);
|
||||
void setHideOpenDecklistGames(bool hide);
|
||||
void setHideFullGames(bool hide);
|
||||
void setHideGamesThatStarted(bool hide);
|
||||
void setHidePasswordProtectedGames(bool hide);
|
||||
void setHideNotBuddyCreatedGames(bool hide);
|
||||
void setGameNameFilter(QString gameName);
|
||||
void setCreatorNameFilters(QStringList creatorName);
|
||||
void setMinPlayers(int min);
|
||||
void setMaxPlayers(int max);
|
||||
void setMaxGameAge(const QTime &maxGameAge);
|
||||
void setGameTypeEnabled(QString gametype, bool enabled);
|
||||
void setGameHashedTypeEnabled(QString gametypeHASHED, bool enabled);
|
||||
void setShowOnlyIfSpectatorsCanWatch(bool show);
|
||||
void setShowSpectatorPasswordProtected(bool show);
|
||||
void setShowOnlyIfSpectatorsCanChat(bool show);
|
||||
void setShowOnlyIfSpectatorsCanSeeHands(bool show);
|
||||
|
||||
private:
|
||||
explicit GameFiltersSettings(const QString &settingPath, QObject *parent = nullptr);
|
||||
GameFiltersSettings(const GameFiltersSettings & /*other*/);
|
||||
};
|
||||
|
||||
#endif // GAMEFILTERSSETTINGS_H
|
||||
@@ -0,0 +1,149 @@
|
||||
#include "layouts_settings.h"
|
||||
|
||||
const static QString STATE_PROP = "state";
|
||||
const static QString GEOMETRY_PROP = "geometry";
|
||||
const static QString SIZE_PROP = "widgetSize";
|
||||
|
||||
const static QString GROUP_MAIN_WINDOW = "mainWindow";
|
||||
const static QString GROUP_DECK_EDITOR = "deckEditor";
|
||||
const static QString GROUP_VISUAL_DECK_EDITOR = "visualDeckEditor";
|
||||
const static QString GROUP_DECK_EDITOR_DB = "deckEditorDb";
|
||||
const static QString GROUP_SETS_DIALOG = "setsDialog";
|
||||
const static QString GROUP_TOKEN_DIALOG = "tokenDialog";
|
||||
const static QString GROUP_GAME_PLAY_AREA = "gamePlayArea";
|
||||
const static QString GROUP_REPLAY_PLAY_AREA = "replayPlayArea";
|
||||
|
||||
LayoutsSettings::LayoutsSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "layouts.ini", QString(), QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
void LayoutsSettings::setMainWindowGeometry(const QByteArray &value)
|
||||
{
|
||||
setValue(value, GEOMETRY_PROP, GROUP_MAIN_WINDOW);
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getMainWindowGeometry() const
|
||||
{
|
||||
return getValue(GEOMETRY_PROP, GROUP_MAIN_WINDOW).toByteArray();
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getDeckEditorLayoutState() const
|
||||
{
|
||||
return getValue(STATE_PROP, GROUP_DECK_EDITOR).toByteArray();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setDeckEditorLayoutState(const QByteArray &value)
|
||||
{
|
||||
setValue(value, STATE_PROP, GROUP_DECK_EDITOR);
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getDeckEditorGeometry() const
|
||||
{
|
||||
return getValue(GEOMETRY_PROP, GROUP_DECK_EDITOR).toByteArray();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setDeckEditorGeometry(const QByteArray &value)
|
||||
{
|
||||
setValue(value, GEOMETRY_PROP, GROUP_DECK_EDITOR);
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getVisualDeckEditorLayoutState() const
|
||||
{
|
||||
return getValue(STATE_PROP, GROUP_VISUAL_DECK_EDITOR).toByteArray();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setVisualDeckEditorLayoutState(const QByteArray &value)
|
||||
{
|
||||
setValue(value, STATE_PROP, GROUP_VISUAL_DECK_EDITOR);
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getVisualDeckEditorGeometry() const
|
||||
{
|
||||
return getValue(GEOMETRY_PROP, GROUP_VISUAL_DECK_EDITOR).toByteArray();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setVisualDeckEditorGeometry(const QByteArray &value)
|
||||
{
|
||||
setValue(value, GEOMETRY_PROP, GROUP_VISUAL_DECK_EDITOR);
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getDeckEditorDbHeaderState() const
|
||||
{
|
||||
return getValue(STATE_PROP, GROUP_DECK_EDITOR_DB, "header").toByteArray();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setDeckEditorDbHeaderState(const QByteArray &value)
|
||||
{
|
||||
setValue(value, STATE_PROP, GROUP_DECK_EDITOR_DB, "header");
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getSetsDialogHeaderState() const
|
||||
{
|
||||
return getValue(STATE_PROP, GROUP_SETS_DIALOG, "header").toByteArray();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setSetsDialogHeaderState(const QByteArray &value)
|
||||
{
|
||||
setValue(value, STATE_PROP, GROUP_SETS_DIALOG, "header");
|
||||
}
|
||||
|
||||
void LayoutsSettings::setSetsDialogGeometry(const QByteArray &value)
|
||||
{
|
||||
setValue(value, GEOMETRY_PROP, GROUP_SETS_DIALOG);
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getSetsDialogGeometry() const
|
||||
{
|
||||
return getValue(GEOMETRY_PROP, GROUP_SETS_DIALOG).toByteArray();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setTokenDialogGeometry(const QByteArray &value)
|
||||
{
|
||||
setValue(value, GEOMETRY_PROP, GROUP_TOKEN_DIALOG);
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getTokenDialogGeometry() const
|
||||
{
|
||||
return getValue(GEOMETRY_PROP, GROUP_TOKEN_DIALOG).toByteArray();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setGamePlayAreaGeometry(const QByteArray &value)
|
||||
{
|
||||
setValue(value, GEOMETRY_PROP, GROUP_GAME_PLAY_AREA);
|
||||
}
|
||||
|
||||
void LayoutsSettings::setGamePlayAreaState(const QByteArray &value)
|
||||
{
|
||||
setValue(value, STATE_PROP, GROUP_GAME_PLAY_AREA);
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getGamePlayAreaLayoutState() const
|
||||
{
|
||||
return getValue(STATE_PROP, GROUP_GAME_PLAY_AREA).toByteArray();
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getGamePlayAreaGeometry() const
|
||||
{
|
||||
return getValue(GEOMETRY_PROP, GROUP_GAME_PLAY_AREA).toByteArray();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setReplayPlayAreaGeometry(const QByteArray &value)
|
||||
{
|
||||
setValue(value, GEOMETRY_PROP, GROUP_REPLAY_PLAY_AREA);
|
||||
}
|
||||
|
||||
void LayoutsSettings::setReplayPlayAreaState(const QByteArray &value)
|
||||
{
|
||||
setValue(value, STATE_PROP, GROUP_REPLAY_PLAY_AREA);
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getReplayPlayAreaLayoutState() const
|
||||
{
|
||||
return getValue(STATE_PROP, GROUP_REPLAY_PLAY_AREA).toByteArray();
|
||||
}
|
||||
|
||||
QByteArray LayoutsSettings::getReplayPlayAreaGeometry() const
|
||||
{
|
||||
return getValue(GEOMETRY_PROP, GROUP_REPLAY_PLAY_AREA).toByteArray();
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* @file layouts_settings.h
|
||||
* @ingroup CoreSettings
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef LAYOUTSSETTINGS_H
|
||||
#define LAYOUTSSETTINGS_H
|
||||
|
||||
#include "settings_manager.h"
|
||||
|
||||
#include <QSize>
|
||||
|
||||
class LayoutsSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
|
||||
public:
|
||||
void setMainWindowGeometry(const QByteArray &value);
|
||||
|
||||
void setDeckEditorLayoutState(const QByteArray &value);
|
||||
void setDeckEditorGeometry(const QByteArray &value);
|
||||
|
||||
void setVisualDeckEditorLayoutState(const QByteArray &value);
|
||||
void setVisualDeckEditorGeometry(const QByteArray &value);
|
||||
|
||||
void setDeckEditorDbHeaderState(const QByteArray &value);
|
||||
void setSetsDialogHeaderState(const QByteArray &value);
|
||||
void setSetsDialogGeometry(const QByteArray &value);
|
||||
void setTokenDialogGeometry(const QByteArray &value);
|
||||
|
||||
void setGamePlayAreaGeometry(const QByteArray &value);
|
||||
void setGamePlayAreaState(const QByteArray &value);
|
||||
|
||||
void setReplayPlayAreaGeometry(const QByteArray &value);
|
||||
void setReplayPlayAreaState(const QByteArray &value);
|
||||
|
||||
QByteArray getMainWindowGeometry() const;
|
||||
|
||||
QByteArray getDeckEditorLayoutState() const;
|
||||
QByteArray getDeckEditorGeometry() const;
|
||||
|
||||
QByteArray getVisualDeckEditorLayoutState() const;
|
||||
QByteArray getVisualDeckEditorGeometry() const;
|
||||
|
||||
QByteArray getDeckEditorDbHeaderState() const;
|
||||
QByteArray getSetsDialogHeaderState() const;
|
||||
QByteArray getSetsDialogGeometry() const;
|
||||
QByteArray getTokenDialogGeometry() const;
|
||||
|
||||
QByteArray getGamePlayAreaLayoutState() const;
|
||||
QByteArray getGamePlayAreaGeometry() const;
|
||||
|
||||
QByteArray getReplayPlayAreaLayoutState() const;
|
||||
QByteArray getReplayPlayAreaGeometry() const;
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
explicit LayoutsSettings(const QString &settingPath, QObject *parent = nullptr);
|
||||
LayoutsSettings(const LayoutsSettings & /*other*/);
|
||||
};
|
||||
|
||||
#endif // LAYOUTSSETTINGS_H
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "message_settings.h"
|
||||
|
||||
MessageSettings::MessageSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "messages.ini", "messages", QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
QString MessageSettings::getMessageAt(int index) const
|
||||
{
|
||||
return getValue(QString("msg%1").arg(index)).toString();
|
||||
}
|
||||
|
||||
int MessageSettings::getCount() const
|
||||
{
|
||||
return getValue("count").toInt();
|
||||
}
|
||||
|
||||
void MessageSettings::setCount(int count)
|
||||
{
|
||||
setValue(count, "count");
|
||||
}
|
||||
|
||||
void MessageSettings::setMessageAt(int index, QString message)
|
||||
{
|
||||
setValue(message, QString("msg%1").arg(index));
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @file message_settings.h
|
||||
* @ingroup NetworkSettings
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef MESSAGESETTINGS_H
|
||||
#define MESSAGESETTINGS_H
|
||||
|
||||
#include "settings_manager.h"
|
||||
|
||||
class MessageSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
|
||||
public:
|
||||
int getCount() const;
|
||||
QString getMessageAt(int index) const;
|
||||
|
||||
void setCount(int count);
|
||||
void setMessageAt(int index, QString message);
|
||||
signals:
|
||||
void messageMacrosChanged();
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
explicit MessageSettings(const QString &settingPath, QObject *parent = nullptr);
|
||||
MessageSettings(const MessageSettings & /*other*/);
|
||||
};
|
||||
|
||||
#endif // MESSAGESETTINGS_H
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "recents_settings.h"
|
||||
|
||||
#define MAX_RECENT_DECK_COUNT 10
|
||||
|
||||
RecentsSettings::RecentsSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "recents.ini", "deckbuilder", QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
QStringList RecentsSettings::getRecentlyOpenedDeckPaths() const
|
||||
{
|
||||
return getValue("deckpaths").toStringList();
|
||||
}
|
||||
void RecentsSettings::clearRecentlyOpenedDeckPaths()
|
||||
{
|
||||
deleteValue("deckpaths");
|
||||
emit recentlyOpenedDeckPathsChanged();
|
||||
}
|
||||
void RecentsSettings::updateRecentlyOpenedDeckPaths(const QString &deckPath)
|
||||
{
|
||||
auto deckPaths = getValue("deckpaths").toStringList();
|
||||
deckPaths.removeAll(deckPath);
|
||||
|
||||
deckPaths.prepend(deckPath);
|
||||
|
||||
while (deckPaths.size() > MAX_RECENT_DECK_COUNT) {
|
||||
deckPaths.removeLast();
|
||||
}
|
||||
|
||||
setValue(deckPaths, "deckpaths");
|
||||
emit recentlyOpenedDeckPathsChanged();
|
||||
}
|
||||
|
||||
QString RecentsSettings::getLatestDeckDirPath() const
|
||||
{
|
||||
return getValue("latestDeckDir", "dirs").toString();
|
||||
}
|
||||
|
||||
void RecentsSettings::setLatestDeckDirPath(const QString &dirPath)
|
||||
{
|
||||
setValue(dirPath, "latestDeckDir", "dirs");
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @file recents_settings.h
|
||||
* @ingroup DeckSettings
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef RECENTS_SETTINGS_H
|
||||
#define RECENTS_SETTINGS_H
|
||||
|
||||
#include "settings_manager.h"
|
||||
|
||||
class RecentsSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
|
||||
explicit RecentsSettings(const QString &settingPath, QObject *parent = nullptr);
|
||||
RecentsSettings(const RecentsSettings & /*other*/);
|
||||
|
||||
public:
|
||||
QStringList getRecentlyOpenedDeckPaths() const;
|
||||
void clearRecentlyOpenedDeckPaths();
|
||||
void updateRecentlyOpenedDeckPaths(const QString &deckPath);
|
||||
|
||||
QString getLatestDeckDirPath() const;
|
||||
void setLatestDeckDirPath(const QString &dirPath);
|
||||
|
||||
signals:
|
||||
void recentlyOpenedDeckPathsChanged();
|
||||
};
|
||||
|
||||
#endif // RECENTS_SETTINGS_H
|
||||
@@ -0,0 +1,295 @@
|
||||
#include "servers_settings.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <utility>
|
||||
|
||||
ServersSettings::ServersSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "servers.ini", "server", QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ServersSettings::setPreviousHostLogin(int previous)
|
||||
{
|
||||
setValue(previous, "previoushostlogin");
|
||||
}
|
||||
|
||||
int ServersSettings::getPreviousHostLogin() const
|
||||
{
|
||||
QVariant previous = getValue("previoushostlogin");
|
||||
return previous == QVariant() ? 1 : previous.toInt();
|
||||
}
|
||||
|
||||
void ServersSettings::setPreviousHostList(QStringList list)
|
||||
{
|
||||
setValue(list, "previoushosts");
|
||||
}
|
||||
|
||||
QStringList ServersSettings::getPreviousHostList() const
|
||||
{
|
||||
return getValue("previoushosts").toStringList();
|
||||
}
|
||||
|
||||
void ServersSettings::setPrevioushostName(const QString &name)
|
||||
{
|
||||
setValue(name, "previoushostName");
|
||||
}
|
||||
|
||||
QString ServersSettings::getSaveName(QString defaultname)
|
||||
{
|
||||
int index = getPrevioushostindex(getPrevioushostName());
|
||||
QVariant saveName = getValue(QString("saveName%1").arg(index), "server", "server_details");
|
||||
return saveName == QVariant() ? std::move(defaultname) : saveName.toString();
|
||||
}
|
||||
|
||||
QString ServersSettings::getSite(QString defaultSite)
|
||||
{
|
||||
int index = getPrevioushostindex(getPrevioushostName());
|
||||
QVariant site = getValue(QString("site%1").arg(index), "server", "server_details");
|
||||
return site == QVariant() ? std::move(defaultSite) : site.toString();
|
||||
}
|
||||
|
||||
QString ServersSettings::getPrevioushostName() const
|
||||
{
|
||||
QVariant value = getValue("previoushostName");
|
||||
return value == QVariant() ? "Rooster Ranges" : value.toString();
|
||||
}
|
||||
|
||||
int ServersSettings::getPrevioushostindex(const QString &saveName) const
|
||||
{
|
||||
int size = getValue("totalServers", "server", "server_details").toInt();
|
||||
|
||||
for (int i = 0; i <= size; ++i) {
|
||||
if (saveName == getValue(QString("saveName%1").arg(i), "server", "server_details").toString()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
QString ServersSettings::getHostname(QString defaultHost) const
|
||||
{
|
||||
int index = getPrevioushostindex(getPrevioushostName());
|
||||
QVariant hostname = getValue(QString("server%1").arg(index), "server", "server_details");
|
||||
return hostname == QVariant() ? std::move(defaultHost) : hostname.toString();
|
||||
}
|
||||
|
||||
QString ServersSettings::getPort(QString defaultPort) const
|
||||
{
|
||||
int index = getPrevioushostindex(getPrevioushostName());
|
||||
QVariant port = getValue(QString("port%1").arg(index), "server", "server_details");
|
||||
qCDebug(ServersSettingsLog) << "getPort() index = " << index << " port.val = " << port.toString();
|
||||
return port == QVariant() ? std::move(defaultPort) : port.toString();
|
||||
}
|
||||
|
||||
QString ServersSettings::getPlayerName(QString defaultName) const
|
||||
{
|
||||
int index = getPrevioushostindex(getPrevioushostName());
|
||||
QVariant name = getValue(QString("username%1").arg(index), "server", "server_details");
|
||||
qCDebug(ServersSettingsLog) << "getPlayerName() index = " << index << " name.val = " << name.toString();
|
||||
return name == QVariant() ? std::move(defaultName) : name.toString();
|
||||
}
|
||||
|
||||
QString ServersSettings::getPassword()
|
||||
{
|
||||
int index = getPrevioushostindex(getPrevioushostName());
|
||||
|
||||
if (getSavePassword()) {
|
||||
return getValue(QString("password%1").arg(index), "server", "server_details").toString();
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool ServersSettings::getSavePassword() const
|
||||
{
|
||||
int index = getPrevioushostindex(getPrevioushostName());
|
||||
bool save = getValue(QString("savePassword%1").arg(index), "server", "server_details").toBool();
|
||||
return save;
|
||||
}
|
||||
|
||||
void ServersSettings::setAutoConnect(int autoconnect)
|
||||
{
|
||||
setValue(autoconnect, "auto_connect");
|
||||
}
|
||||
|
||||
int ServersSettings::getAutoConnect() const
|
||||
{
|
||||
QVariant autoconnect = getValue("auto_connect");
|
||||
return autoconnect == QVariant() ? 0 : autoconnect.toInt();
|
||||
}
|
||||
|
||||
void ServersSettings::setFPHostName(QString hostname)
|
||||
{
|
||||
setValue(hostname, "fphostname");
|
||||
}
|
||||
|
||||
QString ServersSettings::getFPHostname(QString defaultHost) const
|
||||
{
|
||||
QVariant hostname = getValue("fphostname");
|
||||
return hostname == QVariant() ? std::move(defaultHost) : hostname.toString();
|
||||
}
|
||||
|
||||
void ServersSettings::setFPPort(QString port)
|
||||
{
|
||||
setValue(port, "fpport");
|
||||
}
|
||||
|
||||
QString ServersSettings::getFPPort(QString defaultPort) const
|
||||
{
|
||||
QVariant port = getValue("fpport");
|
||||
return port == QVariant() ? std::move(defaultPort) : port.toString();
|
||||
}
|
||||
|
||||
void ServersSettings::setFPPlayerName(QString playerName)
|
||||
{
|
||||
setValue(playerName, "fpplayername");
|
||||
}
|
||||
|
||||
QString ServersSettings::getFPPlayerName(QString defaultName) const
|
||||
{
|
||||
QVariant name = getValue("fpplayername");
|
||||
return name == QVariant() ? std::move(defaultName) : name.toString();
|
||||
}
|
||||
|
||||
void ServersSettings::setClearDebugLogStatus(bool abIsChecked)
|
||||
{
|
||||
setValue(abIsChecked, "save_debug_log");
|
||||
}
|
||||
|
||||
bool ServersSettings::getClearDebugLogStatus(bool abDefaultValue) const
|
||||
{
|
||||
QVariant cbFlushLog = getValue("save_debug_log");
|
||||
return cbFlushLog == QVariant() ? abDefaultValue : cbFlushLog.toBool();
|
||||
}
|
||||
|
||||
void ServersSettings::addNewServer(const QString &saveName,
|
||||
const QString &serv,
|
||||
const QString &port,
|
||||
const QString &username,
|
||||
const QString &password,
|
||||
bool savePassword,
|
||||
const QString &site)
|
||||
{
|
||||
if (updateExistingServer(saveName, serv, port, username, password, savePassword, site)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int index = getValue("totalServers", "server", "server_details").toInt() + 1;
|
||||
|
||||
setValue(saveName, QString("saveName%1").arg(index), "server", "server_details");
|
||||
setValue(serv, QString("server%1").arg(index), "server", "server_details");
|
||||
setValue(port, QString("port%1").arg(index), "server", "server_details");
|
||||
setValue(username, QString("username%1").arg(index), "server", "server_details");
|
||||
setValue(savePassword, QString("savePassword%1").arg(index), "server", "server_details");
|
||||
setValue(index, "totalServers", "server", "server_details");
|
||||
setValue(password, QString("password%1").arg(index), "server", "server_details");
|
||||
setValue(site, QString("site%1").arg(index), "server", "server_details");
|
||||
}
|
||||
|
||||
void ServersSettings::removeServer(QString servAddr)
|
||||
{
|
||||
int size = getValue("totalServers", "server", "server_details").toInt();
|
||||
|
||||
bool found = false;
|
||||
for (int i = 0; i <= size; ++i) {
|
||||
if (!found) {
|
||||
// find entry and overwrite it
|
||||
if (servAddr == getValue(QString("server%1").arg(i), "server", "server_details").toString()) {
|
||||
found = true;
|
||||
}
|
||||
} else {
|
||||
// move all other entries after it one back, overwriting the previous one
|
||||
int previous = i - 1; // we delete only one entry
|
||||
setValue(getValue(QString("server%1").arg(i), "server", "server_details"),
|
||||
QString("server%1").arg(previous), "server", "server_details");
|
||||
setValue(getValue(QString("port%1").arg(i), "server", "server_details"), QString("port%1").arg(previous),
|
||||
"server", "server_details");
|
||||
setValue(getValue(QString("username%1").arg(i), "server", "server_details"),
|
||||
QString("username%1").arg(previous), "server", "server_details");
|
||||
setValue(getValue(QString("savePassword%1").arg(i), "server", "server_details"),
|
||||
QString("savePassword%1").arg(previous), "server", "server_details");
|
||||
setValue(getValue(QString("password%1").arg(i), "server", "server_details"),
|
||||
QString("password%1").arg(previous), "server", "server_details");
|
||||
setValue(getValue(QString("saveName%1").arg(i), "server", "server_details"),
|
||||
QString("saveName%1").arg(previous), "server", "server_details");
|
||||
setValue(getValue(QString("site%1").arg(i), "server", "server_details"), QString("site%1").arg(previous),
|
||||
"server", "server_details");
|
||||
}
|
||||
}
|
||||
|
||||
// if we have deleted an entry, adjust the total
|
||||
if (found) {
|
||||
setValue(size - 1, "totalServers", "server", "server_details");
|
||||
|
||||
// delete last value
|
||||
deleteValue(QString("server%1").arg(size), "server", "server_details");
|
||||
deleteValue(QString("port%1").arg(size), "server", "server_details");
|
||||
deleteValue(QString("username%1").arg(size), "server", "server_details");
|
||||
deleteValue(QString("savePassword%1").arg(size), "server", "server_details");
|
||||
deleteValue(QString("password%1").arg(size), "server", "server_details");
|
||||
deleteValue(QString("saveName%1").arg(size), "server", "server_details");
|
||||
deleteValue(QString("site%1").arg(size), "server", "server_details");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will only update fields with new values, ignores empty values
|
||||
*/
|
||||
bool ServersSettings::updateExistingServerWithoutLoss(QString saveName, QString serv, QString port, QString site)
|
||||
{
|
||||
int size = getValue("totalServers", "server", "server_details").toInt();
|
||||
|
||||
for (int i = 0; i <= size; ++i) {
|
||||
if (serv == getValue(QString("server%1").arg(i), "server", "server_details").toString()) {
|
||||
if (!port.isEmpty()) {
|
||||
setValue(port, QString("port%1").arg(i), "server", "server_details");
|
||||
}
|
||||
|
||||
if (!site.isEmpty()) {
|
||||
setValue(site, QString("site%1").arg(i), "server", "server_details");
|
||||
}
|
||||
|
||||
setValue(saveName, QString("saveName%1").arg(i), "server", "server_details");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServersSettings::updateExistingServer(QString saveName,
|
||||
QString serv,
|
||||
QString port,
|
||||
QString username,
|
||||
QString password,
|
||||
bool savePassword,
|
||||
QString site)
|
||||
{
|
||||
int size = getValue("totalServers", "server", "server_details").toInt();
|
||||
|
||||
for (int i = 0; i <= size; ++i) {
|
||||
if (serv == getValue(QString("server%1").arg(i), "server", "server_details").toString()) {
|
||||
setValue(port, QString("port%1").arg(i), "server", "server_details");
|
||||
if (!username.isEmpty()) {
|
||||
setValue(username, QString("username%1").arg(i), "server", "server_details");
|
||||
}
|
||||
|
||||
if (savePassword && !password.isEmpty()) {
|
||||
setValue(password, QString("password%1").arg(i), "server", "server_details");
|
||||
} else {
|
||||
setValue(QString(), QString("password%1").arg(i), "server", "server_details");
|
||||
}
|
||||
|
||||
if (!site.isEmpty()) {
|
||||
setValue(site, QString("site%1").arg(i), "server", "server_details");
|
||||
}
|
||||
|
||||
setValue(savePassword, QString("savePassword%1").arg(i), "server", "server_details");
|
||||
setValue(saveName, QString("saveName%1").arg(i), "server", "server_details");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @file servers_settings.h
|
||||
* @ingroup NetworkSettings
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef SERVERSSETTINGS_H
|
||||
#define SERVERSSETTINGS_H
|
||||
|
||||
#include "settings_manager.h"
|
||||
|
||||
#include <QLoggingCategory>
|
||||
#include <QObject>
|
||||
#define SERVERSETTINGS_DEFAULT_HOST "server.cockatrice.us"
|
||||
#define SERVERSETTINGS_DEFAULT_PORT "4748"
|
||||
|
||||
inline Q_LOGGING_CATEGORY(ServersSettingsLog, "servers_settings");
|
||||
|
||||
class ServersSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
|
||||
public:
|
||||
int getPreviousHostLogin() const;
|
||||
int getPrevioushostindex(const QString &) const;
|
||||
QStringList getPreviousHostList() const;
|
||||
QString getPrevioushostName() const;
|
||||
QString getHostname(QString defaultHost = SERVERSETTINGS_DEFAULT_HOST) const;
|
||||
QString getPort(QString defaultPort = SERVERSETTINGS_DEFAULT_PORT) const;
|
||||
QString getPlayerName(QString defaultName = "") const;
|
||||
QString getFPHostname(QString defaultHost = SERVERSETTINGS_DEFAULT_HOST) const;
|
||||
QString getFPPort(QString defaultPort = SERVERSETTINGS_DEFAULT_PORT) const;
|
||||
QString getFPPlayerName(QString defaultName = "") const;
|
||||
QString getPassword();
|
||||
QString getSaveName(QString defaultname = "");
|
||||
QString getSite(QString defaultName = "");
|
||||
bool getSavePassword() const;
|
||||
int getAutoConnect() const;
|
||||
|
||||
void setPreviousHostLogin(int previous);
|
||||
void setPrevioushostName(const QString &);
|
||||
void setPreviousHostList(QStringList list);
|
||||
void setAutoConnect(int autoconnect);
|
||||
void setSite(QString site);
|
||||
void setFPHostName(QString hostname);
|
||||
void setFPPort(QString port);
|
||||
void setFPPlayerName(QString playerName);
|
||||
void addNewServer(const QString &saveName,
|
||||
const QString &serv,
|
||||
const QString &port,
|
||||
const QString &username,
|
||||
const QString &password,
|
||||
bool savePassword,
|
||||
const QString &site = QString());
|
||||
void removeServer(QString servAddr);
|
||||
bool updateExistingServer(QString saveName,
|
||||
QString serv,
|
||||
QString port,
|
||||
QString username,
|
||||
QString password,
|
||||
bool savePassword,
|
||||
QString site = QString());
|
||||
|
||||
bool updateExistingServerWithoutLoss(QString saveName,
|
||||
QString serv = QString(),
|
||||
QString port = QString(),
|
||||
QString site = QString());
|
||||
void setClearDebugLogStatus(bool abIsChecked);
|
||||
bool getClearDebugLogStatus(bool abDefaultValue) const;
|
||||
|
||||
private:
|
||||
explicit ServersSettings(const QString &settingPath, QObject *parent = nullptr);
|
||||
ServersSettings(const ServersSettings & /*other*/);
|
||||
};
|
||||
|
||||
#endif // SERVERSSETTINGS_H
|
||||
@@ -0,0 +1,179 @@
|
||||
#include "settings_manager.h"
|
||||
|
||||
SettingsManager::SettingsManager(const QString &_settingPath,
|
||||
const QString &_defaultGroup,
|
||||
const QString &_defaultSubGroup,
|
||||
QObject *parent)
|
||||
: QObject(parent), settingPath(_settingPath), defaultGroup(_defaultGroup), defaultSubGroup(_defaultSubGroup)
|
||||
{
|
||||
}
|
||||
|
||||
QSettings SettingsManager::getSettings() const
|
||||
{
|
||||
// Do not store the QSettings instance in a field, as that is not threadsafe (see #6747)
|
||||
return QSettings(settingPath, QSettings::IniFormat);
|
||||
}
|
||||
|
||||
void SettingsManager::setValue(const QVariant &value, const QString &name)
|
||||
{
|
||||
auto settings = getSettings();
|
||||
|
||||
if (!defaultGroup.isEmpty()) {
|
||||
settings.beginGroup(defaultGroup);
|
||||
}
|
||||
|
||||
if (!defaultSubGroup.isEmpty()) {
|
||||
settings.beginGroup(defaultSubGroup);
|
||||
}
|
||||
|
||||
settings.setValue(name, value);
|
||||
|
||||
if (!defaultSubGroup.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
if (!defaultGroup.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsManager::setValue(const QVariant &value,
|
||||
const QString &name,
|
||||
const QString &group,
|
||||
const QString &subGroup)
|
||||
{
|
||||
auto settings = getSettings();
|
||||
|
||||
if (!group.isEmpty()) {
|
||||
settings.beginGroup(group);
|
||||
}
|
||||
|
||||
if (!subGroup.isEmpty()) {
|
||||
settings.beginGroup(subGroup);
|
||||
}
|
||||
|
||||
settings.setValue(name, value);
|
||||
|
||||
if (!subGroup.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
if (!group.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsManager::deleteValue(const QString &name)
|
||||
{
|
||||
auto settings = getSettings();
|
||||
|
||||
if (!defaultGroup.isEmpty()) {
|
||||
settings.beginGroup(defaultGroup);
|
||||
}
|
||||
|
||||
if (!defaultSubGroup.isEmpty()) {
|
||||
settings.beginGroup(defaultSubGroup);
|
||||
}
|
||||
|
||||
settings.remove(name);
|
||||
|
||||
if (!defaultSubGroup.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
if (!defaultGroup.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsManager::deleteValue(const QString &name, const QString &group, const QString &subGroup)
|
||||
{
|
||||
auto settings = getSettings();
|
||||
|
||||
if (!group.isEmpty()) {
|
||||
settings.beginGroup(group);
|
||||
}
|
||||
|
||||
if (!subGroup.isEmpty()) {
|
||||
settings.beginGroup(subGroup);
|
||||
}
|
||||
|
||||
settings.remove(name);
|
||||
|
||||
if (!subGroup.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
if (!group.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant SettingsManager::getValue(const QString &name) const
|
||||
{
|
||||
auto settings = getSettings();
|
||||
|
||||
if (!defaultGroup.isEmpty()) {
|
||||
settings.beginGroup(defaultGroup);
|
||||
}
|
||||
|
||||
if (!defaultSubGroup.isEmpty()) {
|
||||
settings.beginGroup(defaultSubGroup);
|
||||
}
|
||||
|
||||
QVariant value = settings.value(name);
|
||||
|
||||
if (!defaultSubGroup.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
if (!defaultGroup.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
QVariant SettingsManager::getValue(const QString &name, const QString &group, const QString &subGroup) const
|
||||
{
|
||||
auto settings = getSettings();
|
||||
|
||||
if (!group.isEmpty()) {
|
||||
settings.beginGroup(group);
|
||||
}
|
||||
|
||||
if (!subGroup.isEmpty()) {
|
||||
settings.beginGroup(subGroup);
|
||||
}
|
||||
|
||||
QVariant value = settings.value(name);
|
||||
|
||||
if (!subGroup.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
if (!group.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void SettingsManager::batchWrite(std::function<void(QSettings &)> batchWriteFunction)
|
||||
{
|
||||
auto settings = getSettings();
|
||||
settings.setAtomicSyncRequired(false);
|
||||
batchWriteFunction(settings);
|
||||
settings.sync(); // single flush
|
||||
settings.setAtomicSyncRequired(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls sync on the underlying QSettings object
|
||||
*/
|
||||
void SettingsManager::sync()
|
||||
{
|
||||
auto settings = getSettings();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file settings_manager.h
|
||||
* @ingroup Settings
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef SETTINGSMANAGER_H
|
||||
#define SETTINGSMANAGER_H
|
||||
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
class SettingsManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SettingsManager(const QString &settingPath,
|
||||
const QString &defaultGroup = QString(),
|
||||
const QString &defaultSubGroup = QString(),
|
||||
QObject *parent = nullptr);
|
||||
|
||||
QVariant getValue(const QString &name) const;
|
||||
QVariant getValue(const QString &name, const QString &group, const QString &subGroup = QString()) const;
|
||||
void batchWrite(std::function<void(QSettings &)> batchWriteFunction);
|
||||
|
||||
void sync();
|
||||
|
||||
protected:
|
||||
QString settingPath;
|
||||
QString defaultGroup;
|
||||
QString defaultSubGroup;
|
||||
|
||||
QSettings getSettings() const;
|
||||
|
||||
void setValue(const QVariant &value, const QString &name);
|
||||
|
||||
void
|
||||
setValue(const QVariant &value, const QString &name, const QString &group, const QString &subGroup = QString());
|
||||
|
||||
void deleteValue(const QString &name);
|
||||
|
||||
void deleteValue(const QString &name, const QString &group, const QString &subGroup = QString());
|
||||
};
|
||||
|
||||
#endif // SETTINGSMANAGER_H
|
||||
Reference in New Issue
Block a user