-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchesssetting.cpp
More file actions
58 lines (48 loc) · 1.32 KB
/
chesssetting.cpp
File metadata and controls
58 lines (48 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "chesssetting.h"
#include "chesslog.h"
#include <QSettings>
#include <QCoreApplication>
ChessSetting * ChessSetting::INSTANCE = 0;
ChessSetting * ChessSetting::instance()
{
if(!INSTANCE)
{
INSTANCE = new ChessSetting;
}
return INSTANCE;
}
ChessSetting::ChessSetting()
{
iniFileName = QCoreApplication::applicationDirPath() + QLatin1String("/chess.ini");
Chess_Trace(QObject::tr("new ChessSetting"));
}
ChessSetting::~ChessSetting()
{
Chess_Trace(QObject::tr("delete ChessSetting"));
}
QString ChessSetting::get(const QString &key) const
{
return setting.value(key.toLower(), QString()).toLower();
}
void ChessSetting::set(const QString &key, const QString &value)
{
setting.insert(key.toLower(), value.toLower());
}
void ChessSetting::saveSetting()
{
QSettings conf(iniFileName, QSettings::IniFormat);
conf.setIniCodec("UTF-8");
conf.beginGroup(QLatin1String("chess"));
QHash<QString, QString>::const_iterator it = setting.constBegin();
while (it != setting.constEnd())
{
conf.setValue(it.key().toLower(), it.value().toLower());
++it;
}
conf.endGroup();
}
void ChessSetting::readSetting()
{
QSettings conf(iniFileName, QSettings::IniFormat);
conf.setIniCodec("UTF-8");
}