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 setLanguageIndex (settings.value ("langIndex", _langIndex).toInt ());
44 void Settings::save ()
48 settings.setValue ("region", _regionID);
50 settings.setValue ("checks/light", _checks[C_ShowLight]);
51 settings.setValue ("checks/rank", _checks[C_ShowRank]);
52 settings.setValue ("checks/time", _checks[C_ShowTime]);
53 settings.setValue ("checks/hint", _checks[C_ShowHint]);
54 settings.setValue ("checks/updateOnWifi", _checks[C_UpdateOnWiFi]);
55 settings.setValue ("checks/updateOnGSM", _checks[C_UpdateOnGSM]);
56 settings.setValue ("checks/updateWhenLocked", _checks[C_UpdateWhenLocked]);
58 settings.setValue ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex));
60 settings.setValue ("langIndex", _langIndex);
64 void Settings::makeDefault ()
66 _regionID = "1"; // Default city
68 _cities["1"] = tr ("Moscow");
69 _cities["10174"] = tr ("St.Petersburg");
70 _cities["20544"] = tr ("Kiev");
71 _cities["11162"] = tr ("Ekaterinburg");
73 setCheck (C_ShowLight, true);
74 setCheck (C_ShowRank, true);
75 setCheck (C_ShowHint, true);
77 setCheck (C_UpdateOnWiFi, true);
79 setCheck (C_UpdateWhenLocked, true);
81 _updateIntervalIndex = 3;
84 _langs.append (Language (QString (""), tr ("System")));
85 _langs.append (Language (QString ("en"), tr ("English")));
86 _langs.append (Language (QString ("ru"), tr ("Russian")));
91 QStringList Settings::updateIntervals () const
95 res.append (tr ("Never"));
96 res.append (tr ("1 min"));
97 res.append (tr ("2 min"));
98 res.append (tr ("5 min"));
99 res.append (tr ("15 min"));
100 res.append (tr ("30 min"));
106 int Settings::intervalIndex2Minutes (int index) const
108 int int2min[] = { -1, 1, 2, 5, 15, 30 };
110 if (index < 0 || sizeof (int2min) / sizeof (int2min[0]) <= (unsigned int)index)
113 return int2min[index];
117 int Settings::minutes2IntervalIndex (int minutes) const
138 void Settings::setLanguageIndex (int index)
140 if (index < 0 || index >= _langs.count ())