2 #include <settings.hpp>
11 void Settings::load ()
17 _regionID = settings.value ("region", _regionID).toString ();
19 _checks[C_ShowLight] = settings.value ("checks/light", _checks[C_ShowLight]).toBool ();
20 _checks[C_ShowRank] = settings.value ("checks/rank", _checks[C_ShowRank]).toBool ();
21 _checks[C_ShowTime] = settings.value ("checks/time", _checks[C_ShowTime]).toBool ();
22 _checks[C_ShowHint] = settings.value ("checks/hint", _checks[C_ShowHint]).toBool ();
23 _checks[C_UpdateOnWiFi] = settings.value ("checks/updateOnWifi", _checks[C_UpdateOnWiFi]).toBool ();
24 _checks[C_UpdateOnGSM] = settings.value ("checks/updateOnGSM", _checks[C_UpdateOnGSM]).toBool ();
25 _checks[C_UpdateWhenLocked] = settings.value ("checks/updateWhenLocked", _checks[C_UpdateWhenLocked]).toBool ();
27 // Do we really need to cache cities?
28 // loadCities (&settings);
30 _updateIntervalIndex = minutes2IntervalIndex (settings.value ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex)).toInt ());
32 _langIndex = settings.value ("langIndex", _langIndex).toInt ();
33 if (_langIndex < 0 || _langIndex >= _langs.count ())
38 void Settings::save ()
42 settings.setValue ("region", _regionID);
44 settings.setValue ("checks/light", _checks[C_ShowLight]);
45 settings.setValue ("checks/rank", _checks[C_ShowRank]);
46 settings.setValue ("checks/time", _checks[C_ShowTime]);
47 settings.setValue ("checks/hint", _checks[C_ShowHint]);
48 settings.setValue ("checks/updateOnWifi", _checks[C_UpdateOnWiFi]);
49 settings.setValue ("checks/updateOnGSM", _checks[C_UpdateOnGSM]);
50 settings.setValue ("checks/updateWhenLocked", _checks[C_UpdateWhenLocked]);
52 settings.setValue ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex));
54 settings.setValue ("langIndex", _langIndex);
56 // saveCities (&settings);
60 void Settings::loadCities (QSettings *settings)
62 QMap<QString, QVariant> v;
63 QMap<QString, QVariant>::const_iterator it;
65 v = settings->value ("cities", v).toMap ();
73 while (it != v.end ()) {
74 _cities[it.key ()] = it.value ().toString ();
80 void Settings::saveCities (QSettings *settings)
82 QMap<QString, QVariant> v;
83 QMap<QString, QString>::const_iterator it;
85 it = _cities.begin ();
87 while (it != _cities.end ()) {
88 v[it.key ()] = it.value ();
92 settings->setValue ("cities", v);
96 void Settings::makeDefault ()
98 _regionID = "1"; // Default city
100 _cities["1"] = tr ("Moscow");
101 _cities["10174"] = tr ("St.Petersburg");
102 _cities["20544"] = tr ("Kiev");
103 _cities["11162"] = tr ("Ekaterinburg");
105 setCheck (C_ShowLight, true);
106 setCheck (C_ShowRank, true);
107 setCheck (C_ShowHint, true);
109 setCheck (C_UpdateOnWiFi, true);
111 setCheck (C_UpdateWhenLocked, true);
113 _updateIntervalIndex = 3;
117 _langs.append (Language (QString (""), tr ("System")));
118 _langs.append (Language (QString ("en"), tr ("English")));
119 _langs.append (Language (QString ("ru"), tr ("Russian")));
123 QStringList Settings::updateIntervals () const
127 res.append (tr ("Never"));
128 res.append (tr ("1 min"));
129 res.append (tr ("2 min"));
130 res.append (tr ("5 min"));
131 res.append (tr ("15 min"));
132 res.append (tr ("30 min"));
138 int Settings::intervalIndex2Minutes (int index) const
140 int int2min[] = { -1, 1, 2, 5, 15, 30 };
142 if (index < 0 || sizeof (int2min) / sizeof (int2min[0]) <= (unsigned int)index)
145 return int2min[index];
149 int Settings::minutes2IntervalIndex (int minutes) const