2 #include <settings.hpp>
5 static Settings* _settings;
8 Settings* Settings::instance ()
11 _settings = new Settings;
22 void Settings::load ()
28 _regionID = settings.value ("region", _regionID).toString ();
30 _checks[C_ShowLight] = settings.value ("checks/light", _checks[C_ShowLight]).toBool ();
31 _checks[C_ShowRank] = settings.value ("checks/rank", _checks[C_ShowRank]).toBool ();
32 _checks[C_ShowTime] = settings.value ("checks/time", _checks[C_ShowTime]).toBool ();
33 _checks[C_ShowHint] = settings.value ("checks/hint", _checks[C_ShowHint]).toBool ();
34 _checks[C_UpdateOnWiFi] = settings.value ("checks/updateOnWifi", _checks[C_UpdateOnWiFi]).toBool ();
35 _checks[C_UpdateOnGSM] = settings.value ("checks/updateOnGSM", _checks[C_UpdateOnGSM]).toBool ();
36 _checks[C_UpdateWhenLocked] = settings.value ("checks/updateWhenLocked", _checks[C_UpdateWhenLocked]).toBool ();
38 _updateIntervalIndex = minutes2IntervalIndex (settings.value ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex)).toInt ());
40 _langIndex = settings.value ("langIndex", _langIndex).toInt ();
41 if (_langIndex < 0 || _langIndex >= _langs.count ())
46 void Settings::save ()
50 settings.setValue ("region", _regionID);
52 settings.setValue ("checks/light", _checks[C_ShowLight]);
53 settings.setValue ("checks/rank", _checks[C_ShowRank]);
54 settings.setValue ("checks/time", _checks[C_ShowTime]);
55 settings.setValue ("checks/hint", _checks[C_ShowHint]);
56 settings.setValue ("checks/updateOnWifi", _checks[C_UpdateOnWiFi]);
57 settings.setValue ("checks/updateOnGSM", _checks[C_UpdateOnGSM]);
58 settings.setValue ("checks/updateWhenLocked", _checks[C_UpdateWhenLocked]);
60 settings.setValue ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex));
62 settings.setValue ("langIndex", _langIndex);
66 void Settings::makeDefault ()
68 _regionID = "1"; // Default city
70 _cities["1"] = tr ("Moscow");
71 _cities["10174"] = tr ("St.Petersburg");
72 _cities["20544"] = tr ("Kiev");
73 _cities["11162"] = tr ("Ekaterinburg");
75 setCheck (C_ShowLight, true);
76 setCheck (C_ShowRank, true);
77 setCheck (C_ShowHint, true);
79 setCheck (C_UpdateOnWiFi, true);
81 setCheck (C_UpdateWhenLocked, true);
83 _updateIntervalIndex = 3;
87 _langs.append (Language (QString (""), tr ("System")));
88 _langs.append (Language (QString ("en"), tr ("English")));
89 _langs.append (Language (QString ("ru"), tr ("Russian")));
93 QStringList Settings::updateIntervals () const
97 res.append (tr ("Never"));
98 res.append (tr ("1 min"));
99 res.append (tr ("2 min"));
100 res.append (tr ("5 min"));
101 res.append (tr ("15 min"));
102 res.append (tr ("30 min"));
108 int Settings::intervalIndex2Minutes (int index) const
110 int int2min[] = { -1, 1, 2, 5, 15, 30 };
112 if (index < 0 || sizeof (int2min) / sizeof (int2min[0]) <= (unsigned int)index)
115 return int2min[index];
119 int Settings::minutes2IntervalIndex (int minutes) const