mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-26 00:23:55 -07:00
Refactred settings to use settingscache & ini files
This commit is contained in:
parent
9c28cdd1f5
commit
c8d59eec5e
29 changed files with 780 additions and 241 deletions
36
cockatrice/src/settings/carddatabasesettings.cpp
Normal file
36
cockatrice/src/settings/carddatabasesettings.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#include "carddatabasesettings.h"
|
||||
|
||||
CardDatabaseSettings::CardDatabaseSettings(QString settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath+"cardDatabase.ini", parent)
|
||||
{
|
||||
}
|
||||
|
||||
void CardDatabaseSettings::setSortKey(QString shortName, unsigned int sortKey)
|
||||
{
|
||||
setValue(sortKey,"sortkey", "sets", shortName);
|
||||
}
|
||||
|
||||
void CardDatabaseSettings::setEnabled(QString shortName, bool enabled)
|
||||
{
|
||||
setValue(enabled, "enabled", "sets", shortName);
|
||||
}
|
||||
|
||||
void CardDatabaseSettings::setIsKnown(QString shortName, bool isknown)
|
||||
{
|
||||
setValue(isknown, "isknown", "sets", shortName);
|
||||
}
|
||||
|
||||
unsigned int CardDatabaseSettings::getSortKey(QString shortName)
|
||||
{
|
||||
return getValue("sortkey", "sets", shortName).toUInt();
|
||||
}
|
||||
|
||||
bool CardDatabaseSettings::isEnabled(QString shortName)
|
||||
{
|
||||
return getValue("enabled", "sets", shortName).toBool();
|
||||
}
|
||||
|
||||
bool CardDatabaseSettings::isKnown(QString shortName)
|
||||
{
|
||||
return getValue("isknown", "sets", shortName).toBool();
|
||||
}
|
||||
34
cockatrice/src/settings/carddatabasesettings.h
Normal file
34
cockatrice/src/settings/carddatabasesettings.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef CARDDATABASESETTINGS_H
|
||||
#define CARDDATABASESETTINGS_H
|
||||
|
||||
#include "settingsmanager.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
#include <QSettings>
|
||||
|
||||
class CardDatabaseSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
public:
|
||||
void setSortKey(QString shortName, unsigned int sortKey);
|
||||
void setEnabled(QString shortName, bool enabled);
|
||||
void setIsKnown(QString shortName, bool isknown);
|
||||
|
||||
unsigned int getSortKey(QString shortName);
|
||||
bool isEnabled(QString shortName);
|
||||
bool isKnown(QString shortName);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
CardDatabaseSettings(QString settingPath, QObject *parent = 0);
|
||||
CardDatabaseSettings( const CardDatabaseSettings& /*other*/ );
|
||||
CardDatabaseSettings( CardDatabaseSettings& /*other*/ );
|
||||
CardDatabaseSettings( volatile const CardDatabaseSettings& /*other*/ );
|
||||
CardDatabaseSettings( volatile CardDatabaseSettings& /*other*/ );
|
||||
};
|
||||
|
||||
#endif // CARDDATABASESETTINGS_H
|
||||
88
cockatrice/src/settings/gamefilterssettings.cpp
Normal file
88
cockatrice/src/settings/gamefilterssettings.cpp
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
#include "gamefilterssettings.h"
|
||||
#include <QCryptographicHash>
|
||||
|
||||
GameFiltersSettings::GameFiltersSettings(QString settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath+"gamefilters.ini", parent)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* The game type might contain special characters, so to use it in
|
||||
* QSettings we just hash it.
|
||||
*/
|
||||
QString GameFiltersSettings::hashGameType(const QString &gameType) const
|
||||
{
|
||||
return QCryptographicHash::hash(gameType.toUtf8(), QCryptographicHash::Md5).toHex();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setUnavailableGamesVisible(bool enabled)
|
||||
{
|
||||
setValue(enabled, "unavailable_games_visible","filter_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isUnavailableGamesVisible()
|
||||
{
|
||||
QVariant previous = getValue("unavailable_games_visible","filter_games");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setShowPasswordProtectedGames(bool show)
|
||||
{
|
||||
setValue(show, "show_password_protected_games","filter_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isShowPasswordProtectedGames()
|
||||
{
|
||||
QVariant previous = getValue("show_password_protected_games","filter_games");
|
||||
return previous == QVariant() ? true : previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setGameNameFilter(QString gameName)
|
||||
{
|
||||
setValue(gameName, "game_name_filter","filter_games");
|
||||
}
|
||||
|
||||
QString GameFiltersSettings::getGameNameFilter()
|
||||
{
|
||||
return getValue("game_name_filter","filter_games").toString();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setMinPlayers(int min)
|
||||
{
|
||||
setValue(min, "min_players","filter_games");
|
||||
}
|
||||
|
||||
int GameFiltersSettings::getMinPlayers()
|
||||
{
|
||||
QVariant previous = getValue("min_players","filter_games");
|
||||
return previous == QVariant() ? 1 : previous.toInt();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setMaxPlayers(int max)
|
||||
{
|
||||
setValue(max, "max_players","filter_games");
|
||||
}
|
||||
|
||||
int GameFiltersSettings::getMaxPlayers()
|
||||
{
|
||||
QVariant previous = getValue("max_players","filter_games");
|
||||
return previous == QVariant() ? 99 : previous.toInt();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setGameTypeEnabled(QString gametype, bool enabled)
|
||||
{
|
||||
setValue(enabled, "game_type/"+hashGameType(gametype),"filter_games");
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setGameHashedTypeEnabled(QString gametypeHASHED, bool enabled)
|
||||
{
|
||||
setValue(enabled, gametypeHASHED,"filter_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isGameTypeEnabled(QString gametype)
|
||||
{
|
||||
QVariant previous = getValue("game_type/"+hashGameType(gametype),"filter_games");
|
||||
return previous == QVariant() ? false : previous.toBool();
|
||||
}
|
||||
|
||||
|
||||
39
cockatrice/src/settings/gamefilterssettings.h
Normal file
39
cockatrice/src/settings/gamefilterssettings.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef GAMEFILTERSSETTINGS_H
|
||||
#define GAMEFILTERSSETTINGS_H
|
||||
|
||||
#include "settingsmanager.h"
|
||||
|
||||
class GameFiltersSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
public:
|
||||
bool isUnavailableGamesVisible();
|
||||
bool isShowPasswordProtectedGames();
|
||||
QString getGameNameFilter();
|
||||
int getMinPlayers();
|
||||
int getMaxPlayers();
|
||||
bool isGameTypeEnabled(QString gametype);
|
||||
|
||||
void setUnavailableGamesVisible(bool enabled);
|
||||
void setShowPasswordProtectedGames(bool show);
|
||||
void setGameNameFilter(QString gameName);
|
||||
void setMinPlayers(int min);
|
||||
void setMaxPlayers(int max);
|
||||
void setGameTypeEnabled(QString gametype, bool enabled);
|
||||
void setGameHashedTypeEnabled(QString gametypeHASHED, bool enabled);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
GameFiltersSettings(QString settingPath,QObject *parent = 0);
|
||||
GameFiltersSettings( const GameFiltersSettings& /*other*/ );
|
||||
GameFiltersSettings( GameFiltersSettings& /*other*/ );
|
||||
GameFiltersSettings( volatile const GameFiltersSettings& /*other*/ );
|
||||
GameFiltersSettings( volatile GameFiltersSettings& /*other*/ );
|
||||
|
||||
QString hashGameType(const QString &gameType) const;
|
||||
};
|
||||
|
||||
#endif // GAMEFILTERSSETTINGS_H
|
||||
59
cockatrice/src/settings/layoutssettings.cpp
Normal file
59
cockatrice/src/settings/layoutssettings.cpp
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#include "layoutssettings.h"
|
||||
|
||||
LayoutsSettings::LayoutsSettings(QString settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath+"layouts.ini", parent)
|
||||
{
|
||||
}
|
||||
|
||||
const QByteArray LayoutsSettings::getDeckEditorLayoutState()
|
||||
{
|
||||
return getValue("layouts/deckEditor_state").toByteArray();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setDeckEditorLayoutState(const QByteArray &value)
|
||||
{
|
||||
setValue(value,"layouts/deckEditor_state");
|
||||
}
|
||||
|
||||
const QByteArray LayoutsSettings::getDeckEditorGeometry()
|
||||
{
|
||||
return getValue("layouts/deckEditor_geometry").toByteArray();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setDeckEditorGeometry(const QByteArray &value)
|
||||
{
|
||||
setValue(value,"layouts/deckEditor_geometry");
|
||||
}
|
||||
|
||||
const QSize LayoutsSettings::getDeckEditorCardSize()
|
||||
{
|
||||
QVariant previous = getValue("layouts/deckEditor_CardSize");
|
||||
return previous == QVariant() ? QSize(250,500) : previous.toSize();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setDeckEditorCardSize(const QSize &value)
|
||||
{
|
||||
setValue(value,"layouts/deckEditor_CardSize");
|
||||
}
|
||||
|
||||
const QSize LayoutsSettings::getDeckEditorDeckSize()
|
||||
{
|
||||
QVariant previous = getValue("layouts/deckEditor_DeckSize");
|
||||
return previous == QVariant() ? QSize(250,360) : previous.toSize();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setDeckEditorDeckSize(const QSize &value)
|
||||
{
|
||||
setValue(value,"layouts/deckEditor_DeckSize");
|
||||
}
|
||||
|
||||
const QSize LayoutsSettings::getDeckEditorFilterSize()
|
||||
{
|
||||
QVariant previous = getValue("layouts/deckEditor_FilterSize");
|
||||
return previous == QVariant() ? QSize(250,250) : previous.toSize();
|
||||
}
|
||||
|
||||
void LayoutsSettings::setDeckEditorFilterSize(const QSize &value)
|
||||
{
|
||||
setValue(value,"layouts/deckEditor_FilterSize");
|
||||
}
|
||||
36
cockatrice/src/settings/layoutssettings.h
Normal file
36
cockatrice/src/settings/layoutssettings.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#ifndef LAYOUTSSETTINGS_H
|
||||
#define LAYOUTSSETTINGS_H
|
||||
|
||||
#include "settingsmanager.h"
|
||||
#include <QSize>
|
||||
|
||||
class LayoutsSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
public:
|
||||
|
||||
void setDeckEditorLayoutState(const QByteArray &value);
|
||||
void setDeckEditorGeometry(const QByteArray &value);
|
||||
void setDeckEditorCardSize(const QSize &value);
|
||||
void setDeckEditorDeckSize(const QSize &value);
|
||||
void setDeckEditorFilterSize(const QSize &value);
|
||||
|
||||
const QByteArray getDeckEditorLayoutState();
|
||||
const QByteArray getDeckEditorGeometry();
|
||||
const QSize getDeckEditorCardSize();
|
||||
const QSize getDeckEditorDeckSize();
|
||||
const QSize getDeckEditorFilterSize();
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
LayoutsSettings(QString settingPath,QObject *parent = 0);
|
||||
LayoutsSettings( const LayoutsSettings& /*other*/ );
|
||||
LayoutsSettings( LayoutsSettings& /*other*/ );
|
||||
LayoutsSettings( volatile const LayoutsSettings& /*other*/ );
|
||||
LayoutsSettings( volatile LayoutsSettings& /*other*/ );
|
||||
};
|
||||
|
||||
#endif // LAYOUTSSETTINGS_H
|
||||
26
cockatrice/src/settings/messagesettings.cpp
Normal file
26
cockatrice/src/settings/messagesettings.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include "messagesettings.h"
|
||||
|
||||
MessageSettings::MessageSettings(QString settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath+"messages.ini",parent)
|
||||
{
|
||||
}
|
||||
|
||||
QString MessageSettings::getMessageAt(int index)
|
||||
{
|
||||
return getValue(QString("msg%1").arg(index),"messages").toString();
|
||||
}
|
||||
|
||||
int MessageSettings::getCount()
|
||||
{
|
||||
return getValue("count", "messages").toInt();
|
||||
}
|
||||
|
||||
void MessageSettings::setCount(int count)
|
||||
{
|
||||
setValue(count,"count","messages");
|
||||
}
|
||||
|
||||
void MessageSettings::setMessageAt(int index, QString message)
|
||||
{
|
||||
setValue(message,QString("msg%1").arg(index),"messages");
|
||||
}
|
||||
29
cockatrice/src/settings/messagesettings.h
Normal file
29
cockatrice/src/settings/messagesettings.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef MESSAGESETTINGS_H
|
||||
#define MESSAGESETTINGS_H
|
||||
|
||||
#include "settingsmanager.h"
|
||||
|
||||
class MessageSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
|
||||
public:
|
||||
int getCount();
|
||||
QString getMessageAt(int index);
|
||||
|
||||
void setCount(int count);
|
||||
void setMessageAt(int index, QString message);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
MessageSettings(QString settingPath, QObject *parent = 0);
|
||||
MessageSettings( const MessageSettings& /*other*/ );
|
||||
MessageSettings( MessageSettings& /*other*/ );
|
||||
MessageSettings( volatile const MessageSettings& /*other*/ );
|
||||
MessageSettings( volatile MessageSettings& /*other*/ );
|
||||
};
|
||||
|
||||
#endif // MESSAGESETTINGS_H
|
||||
102
cockatrice/src/settings/serverssettings.cpp
Normal file
102
cockatrice/src/settings/serverssettings.cpp
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
#include "serverssettings.h"
|
||||
|
||||
ServersSettings::ServersSettings(QString settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath+"servers.ini", parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ServersSettings::setPreviousHostLogin(int previous)
|
||||
{
|
||||
setValue(previous, "previoushostlogin", "server");
|
||||
}
|
||||
|
||||
int ServersSettings::getPreviousHostLogin()
|
||||
{
|
||||
QVariant previous = getValue("previoushostlogin", "server");
|
||||
return previous == QVariant() ? 1 : previous.toInt();
|
||||
}
|
||||
|
||||
void ServersSettings::setPreviousHostList(QStringList list)
|
||||
{
|
||||
setValue(list, "previoushosts", "server");
|
||||
}
|
||||
|
||||
QStringList ServersSettings::getPreviousHostList()
|
||||
{
|
||||
return getValue("previoushosts", "server").toStringList();
|
||||
}
|
||||
|
||||
void ServersSettings::setPrevioushostindex(int index)
|
||||
{
|
||||
setValue(index, "previoushostindex", "server");
|
||||
}
|
||||
|
||||
int ServersSettings::getPrevioushostindex()
|
||||
{
|
||||
return getValue("previoushostindex", "server").toInt();
|
||||
}
|
||||
|
||||
void ServersSettings::setHostName(QString hostname)
|
||||
{
|
||||
setValue(hostname, "hostname", "server");
|
||||
}
|
||||
|
||||
QString ServersSettings::getHostname(QString defaultHost)
|
||||
{
|
||||
QVariant hostname = getValue("hostname","server");
|
||||
return hostname == QVariant() ? defaultHost : hostname.toString();
|
||||
}
|
||||
|
||||
void ServersSettings::setPort(QString port)
|
||||
{
|
||||
setValue(port, "port", "server");
|
||||
}
|
||||
|
||||
QString ServersSettings::getPort(QString defaultPort)
|
||||
{
|
||||
QVariant port = getValue("port","server");
|
||||
return port == QVariant() ? defaultPort : port.toString();
|
||||
}
|
||||
|
||||
void ServersSettings::setPlayerName(QString playerName)
|
||||
{
|
||||
setValue(playerName, "playername", "server");
|
||||
}
|
||||
|
||||
QString ServersSettings::getPlayerName(QString defaultName)
|
||||
{
|
||||
QVariant name = getValue("playername", "server");
|
||||
return name == QVariant() ? defaultName : name.toString();
|
||||
}
|
||||
|
||||
void ServersSettings::setPassword(QString password)
|
||||
{
|
||||
setValue(password, "password", "server");
|
||||
}
|
||||
|
||||
QString ServersSettings::getPassword()
|
||||
{
|
||||
return getValue("password", "server").toString();
|
||||
}
|
||||
|
||||
void ServersSettings::setSavePassword(int save)
|
||||
{
|
||||
setValue(save, "save_password", "server");
|
||||
}
|
||||
|
||||
int ServersSettings::getSavePassword()
|
||||
{
|
||||
QVariant save = getValue("save_password", "server");
|
||||
return save == QVariant() ? 1 : save.toInt();
|
||||
}
|
||||
|
||||
void ServersSettings::setAutoConnect(int autoconnect)
|
||||
{
|
||||
setValue(autoconnect, "auto_connect", "server");
|
||||
}
|
||||
|
||||
int ServersSettings::getAutoConnect()
|
||||
{
|
||||
QVariant autoconnect = getValue("auto_connect", "server");
|
||||
return autoconnect == QVariant() ? 0 : autoconnect.toInt();
|
||||
}
|
||||
44
cockatrice/src/settings/serverssettings.h
Normal file
44
cockatrice/src/settings/serverssettings.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef SERVERSSETTINGS_H
|
||||
#define SERVERSSETTINGS_H
|
||||
|
||||
#include "settingsmanager.h"
|
||||
#include <QObject>
|
||||
|
||||
class ServersSettings : public SettingsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SettingsCache;
|
||||
|
||||
public:
|
||||
int getPreviousHostLogin();
|
||||
QStringList getPreviousHostList();
|
||||
int getPrevioushostindex();
|
||||
QString getHostname(QString defaultHost = "");
|
||||
QString getPort(QString defaultPort = "");
|
||||
QString getPlayerName(QString defaultName = "");
|
||||
QString getPassword();
|
||||
int getSavePassword();
|
||||
int getAutoConnect();
|
||||
|
||||
void setPreviousHostLogin(int previous);
|
||||
void setPreviousHostList(QStringList list);
|
||||
void setPrevioushostindex(int index);
|
||||
void setHostName(QString hostname);
|
||||
void setPort(QString port);
|
||||
void setPlayerName(QString playerName);
|
||||
void setPassword(QString password);
|
||||
void setSavePassword(int save);
|
||||
void setAutoConnect(int autoconnect);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
ServersSettings(QString settingPath,QObject *parent = 0);
|
||||
ServersSettings( const ServersSettings& /*other*/ );
|
||||
ServersSettings( ServersSettings& /*other*/ );
|
||||
ServersSettings( volatile const ServersSettings& /*other*/ );
|
||||
ServersSettings( volatile ServersSettings& /*other*/ );
|
||||
};
|
||||
|
||||
#endif // SERVERSSETTINGS_H
|
||||
43
cockatrice/src/settings/settingsmanager.cpp
Normal file
43
cockatrice/src/settings/settingsmanager.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include "settingsmanager.h"
|
||||
|
||||
SettingsManager::SettingsManager(QString settingPath, QObject *parent)
|
||||
: QObject(parent),
|
||||
settings(settingPath, QSettings::IniFormat)
|
||||
{
|
||||
}
|
||||
|
||||
void SettingsManager::setValue(QVariant value, QString name, QString group, QString subGroup)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
QVariant SettingsManager::getValue(QString name, QString group, QString subGroup)
|
||||
{
|
||||
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;
|
||||
}
|
||||
25
cockatrice/src/settings/settingsmanager.h
Normal file
25
cockatrice/src/settings/settingsmanager.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef SETTINGSMANAGER_H
|
||||
#define SETTINGSMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
class SettingsManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SettingsManager(QString settingPath, QObject *parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
protected:
|
||||
QSettings settings;
|
||||
QVariant getValue(QString name, QString group = "", QString subGroup = "" );
|
||||
void setValue(QVariant value, QString name, QString group = "", QString subGroup = "" );
|
||||
};
|
||||
|
||||
#endif // SETTINGSMANAGER_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue