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 ();
26 loadCities (&settings);
28 _updateIntervalIndex = minutes2IntervalIndex (settings.value ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex)).toInt ());
32 void Settings::save ()
36 settings.setValue ("region", _regionID);
38 settings.setValue ("checks/light", _checks[C_ShowLight]);
39 settings.setValue ("checks/rank", _checks[C_ShowRank]);
40 settings.setValue ("checks/time", _checks[C_ShowTime]);
41 settings.setValue ("checks/hint", _checks[C_ShowHint]);
42 settings.setValue ("checks/updateOnWifi", _checks[C_UpdateOnWiFi]);
43 settings.setValue ("checks/updateOnGSM", _checks[C_UpdateOnGSM]);
45 settings.setValue ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex));
47 saveCities (&settings);
51 void Settings::loadCities (QSettings *settings)
53 QMap<QString, QVariant> v;
54 QMap<QString, QVariant>::const_iterator it;
56 v = settings->value ("cities", v).toMap ();
64 while (it != v.end ()) {
65 _cities[it.key ()] = it.value ().toString ();
71 void Settings::saveCities (QSettings *settings)
73 QMap<QString, QVariant> v;
74 QMap<QString, QString>::const_iterator it;
76 it = _cities.begin ();
78 while (it != _cities.end ()) {
79 v[it.key ()] = it.value ();
83 settings->setValue ("cities", v);
87 void Settings::makeDefault ()
89 _regionID = "1"; // Default city
91 _cities["1"] = tr ("Moscow");
92 _cities["10174"] = tr ("St.Petersburg");
93 _cities["20544"] = tr ("Kiev");
94 _cities["11162"] = tr ("Ekaterinburg");
96 setCheck (C_ShowLight, true);
97 setCheck (C_ShowRank, true);
98 setCheck (C_ShowHint, true);
100 setCheck (C_UpdateOnWiFi, true);
102 _updateIntervalIndex = 3;
106 QStringList Settings::updateIntervals () const
110 res.append (tr ("Never"));
111 res.append (tr ("1 min"));
112 res.append (tr ("2 min"));
113 res.append (tr ("5 min"));
114 res.append (tr ("15 min"));
115 res.append (tr ("30 min"));
121 int Settings::intervalIndex2Minutes (int index) const
123 int int2min[] = { -1, 1, 2, 5, 15, 30 };
125 if (index < 0 || sizeof (int2min) / sizeof (int2min[0]) <= index)
128 return int2min[index];
132 int Settings::minutes2IntervalIndex (int minutes) const