647703f7846e7cf58e05c72d9ba9e17ae50abdb0
[chessclock] / classes / settings.cpp
1 #include "settings.h"
2 #include <QSettings>
3
4
5 Settings::Settings(QObject *parent) :
6     QObject(parent)
7 {
8 }
9
10
11
12 QString Settings::getGroupName(WrappedClocksWidget::TimeControlType timeControl)
13 {
14     //Using same groups and keys in QSettings as the maemo version
15     //just in case Maemo version would move to use QML someday
16
17
18    QString groupString;
19
20    switch (timeControl)
21    {
22
23     case WrappedClocksWidget::NormalClock:
24
25        groupString = "Normal clock";
26        break;
27
28     case WrappedClocksWidget::AdditionBefore:
29
30        groupString = "Addition before";
31        break;
32
33     case WrappedClocksWidget::AdditionAfter:
34            groupString = "Addition after";
35            break;
36
37     case WrappedClocksWidget::Delay:
38        groupString = "Delay";
39        break;
40
41    case WrappedClocksWidget::DelayAfter:
42        groupString = "Delay after";
43        break;
44
45
46     case WrappedClocksWidget::HourGlass:
47        groupString = "Hour glass";
48        break;
49
50     default: //If QML sends an invalid value give the value for normal clock
51
52        groupString = "Normal Clock";
53        break;
54
55     }
56 return groupString;
57
58 }
59
60    int Settings::getTurnsPerAddition(WrappedClocksWidget::TimeControlType timeControl, bool isWhite)
61    {
62
63        QSettings settings;
64        settings.beginGroup(getGroupName(timeControl));
65
66        if (isWhite)
67            return settings.value("WhitePerTurns",1).toInt();
68
69        else
70            return settings.value("BlackPerTurns",1).toInt();
71
72     }
73
74    int Settings::getInitialTime(WrappedClocksWidget::TimeControlType timeControl, bool isWhite)
75    {
76        QSettings settings;
77        settings.beginGroup(getGroupName(timeControl));
78
79        int defaultTime;
80
81        if (timeControl == WrappedClocksWidget::HourGlass)
82            defaultTime = 60*1000; // 1 min
83        else
84            defaultTime = 30*60*1000; //30 min
85
86        if (isWhite)
87            return settings.value("WhiteInitial",defaultTime).toInt();
88         else
89            return settings.value("BlackInitial",defaultTime).toInt();
90    }
91
92    int Settings::getAdditionalTime(WrappedClocksWidget::TimeControlType timeControl, bool isWhite)
93    {
94        QSettings settings;
95        settings.beginGroup(getGroupName(timeControl));
96
97        if (isWhite)
98            return settings.value("WhiteAddition",30*1000).toInt();
99        else
100            return settings.value("BlackAddition",30*100).toInt();
101    }
102
103    bool Settings::isEqualTimes(WrappedClocksWidget::TimeControlType timeControl)
104    {
105        QSettings settings;
106        settings.beginGroup(getGroupName(timeControl));
107
108        return settings.value("Equals",false).toBool();
109    }
110
111    void Settings::setTurnsPerAddition(WrappedClocksWidget::TimeControlType timeControl, bool isWhite, int turns)
112    {
113         QSettings settings;
114         settings.beginGroup(getGroupName(timeControl));
115
116         if (isWhite)
117             settings.setValue("WhitePerTurns",turns);
118         else
119             settings.setValue("BlackPerTurns",turns);
120    }
121
122    void Settings::setInitialTime(WrappedClocksWidget::TimeControlType timeControl, bool isWhite, int time)
123    {
124        QSettings settings;
125        settings.beginGroup(getGroupName(timeControl));
126
127        if (isWhite)
128            settings.setValue("WhiteInitial",time);
129        else
130            settings.setValue("BlackItnitial",time);
131    }
132
133    void Settings::setAdditionalTime(WrappedClocksWidget::TimeControlType timeControl, bool isWhite, int time)
134    {
135        QSettings settings;
136        settings.beginGroup(getGroupName(timeControl));
137
138        if (isWhite)
139            settings.setValue("WhiteAddition",time);
140        else
141            settings.setValue("BlackAddition",time);
142    }
143
144     void Settings::setEqualTimes(WrappedClocksWidget::TimeControlType timeControl, bool on)
145     {
146         QSettings settings;
147         settings.beginGroup(getGroupName(timeControl));
148
149         settings.setValue("Equals",on);
150     }
151
152