#include <settings.hpp>
+static Settings* _settings;
+
+
+Settings* Settings::instance ()
+{
+ if (!_settings)
+ _settings = new Settings;
+ return _settings;
+}
+
+
Settings::Settings ()
{
load ();
_regionID = settings.value ("region", _regionID).toString ();
- _checks[C_Light] = settings.value ("checks/light", _checks[C_Light]).toBool ();
- _checks[C_Rank] = settings.value ("checks/rank", _checks[C_Rank]).toBool ();
- _checks[C_Time] = settings.value ("checks/time", _checks[C_Time]).toBool ();
- _checks[C_Hint] = settings.value ("checks/hint", _checks[C_Hint]).toBool ();
+ _checks[C_ShowLight] = settings.value ("checks/light", _checks[C_ShowLight]).toBool ();
+ _checks[C_ShowRank] = settings.value ("checks/rank", _checks[C_ShowRank]).toBool ();
+ _checks[C_ShowTime] = settings.value ("checks/time", _checks[C_ShowTime]).toBool ();
+ _checks[C_ShowHint] = settings.value ("checks/hint", _checks[C_ShowHint]).toBool ();
+ _checks[C_UpdateOnWiFi] = settings.value ("checks/updateOnWifi", _checks[C_UpdateOnWiFi]).toBool ();
+ _checks[C_UpdateOnGSM] = settings.value ("checks/updateOnGSM", _checks[C_UpdateOnGSM]).toBool ();
+ _checks[C_UpdateWhenLocked] = settings.value ("checks/updateWhenLocked", _checks[C_UpdateWhenLocked]).toBool ();
+
+ _updateIntervalIndex = minutes2IntervalIndex (settings.value ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex)).toInt ());
- loadCities (&settings);
+ _langIndex = settings.value ("langIndex", _langIndex).toInt ();
+ if (_langIndex < 0 || _langIndex >= _langs.count ())
+ _langIndex = 0;
}
settings.setValue ("region", _regionID);
- settings.setValue ("checks/light", _checks[C_Light]);
- settings.setValue ("checks/rank", _checks[C_Rank]);
- settings.setValue ("checks/time", _checks[C_Time]);
- settings.setValue ("checks/hint", _checks[C_Hint]);
+ settings.setValue ("checks/light", _checks[C_ShowLight]);
+ settings.setValue ("checks/rank", _checks[C_ShowRank]);
+ settings.setValue ("checks/time", _checks[C_ShowTime]);
+ settings.setValue ("checks/hint", _checks[C_ShowHint]);
+ settings.setValue ("checks/updateOnWifi", _checks[C_UpdateOnWiFi]);
+ settings.setValue ("checks/updateOnGSM", _checks[C_UpdateOnGSM]);
+ settings.setValue ("checks/updateWhenLocked", _checks[C_UpdateWhenLocked]);
- saveCities (&settings);
+ settings.setValue ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex));
+
+ settings.setValue ("langIndex", _langIndex);
}
-void Settings::loadCities (QSettings *settings)
+void Settings::makeDefault ()
{
- QMap<QString, QVariant> v;
- QMap<QString, QVariant>::const_iterator it;
+ _regionID = "1"; // Default city
- v = settings->value ("cities", v).toMap ();
+ _cities["1"] = tr ("Moscow");
+ _cities["10174"] = tr ("St.Petersburg");
+ _cities["20544"] = tr ("Kiev");
+ _cities["11162"] = tr ("Ekaterinburg");
- if (v.size () == 0)
- return;
+ setCheck (C_ShowLight, true);
+ setCheck (C_ShowRank, true);
+ setCheck (C_ShowHint, true);
- it = v.begin ();
- _cities.clear ();
+ setCheck (C_UpdateOnWiFi, true);
- while (it != v.end ()) {
- _cities[it.key ()] = it.value ().toString ();
- it++;
- }
+ setCheck (C_UpdateWhenLocked, true);
+
+ _updateIntervalIndex = 3;
+
+ // languages
+ _langIndex = 0;
+ _langs.append (Language (QString (""), tr ("System")));
+ _langs.append (Language (QString ("en"), tr ("English")));
+ _langs.append (Language (QString ("ru"), tr ("Russian")));
}
-void Settings::saveCities (QSettings *settings)
+QStringList Settings::updateIntervals () const
{
- QMap<QString, QVariant> v;
- QMap<QString, QString>::const_iterator it;
+ QStringList res;
- it = _cities.begin ();
-
- while (it != _cities.end ()) {
- v[it.key ()] = it.value ();
- it++;
- }
+ res.append (tr ("Never"));
+ res.append (tr ("1 min"));
+ res.append (tr ("2 min"));
+ res.append (tr ("5 min"));
+ res.append (tr ("15 min"));
+ res.append (tr ("30 min"));
- settings->setValue ("cities", v);
+ return res;
}
-void Settings::makeDefault ()
+int Settings::intervalIndex2Minutes (int index) const
{
- _regionID = "1"; // Default city
+ int int2min[] = { -1, 1, 2, 5, 15, 30 };
- _cities["1"] = tr ("Moscow");
- _cities["10174"] = tr ("Kiev");
- _cities["11162"] = tr ("Ekaterinburg");
- _cities["11079"] = tr ("N.Novgorod");
+ if (index < 0 || sizeof (int2min) / sizeof (int2min[0]) <= (unsigned int)index)
+ return -1;
+
+ return int2min[index];
+}
- setCheck (C_Light, true);
- setCheck (C_Rank, true);
- setCheck (C_Hint, true);
+
+int Settings::minutes2IntervalIndex (int minutes) const
+{
+ switch (minutes) {
+ case -1:
+ return 0;
+ case 1:
+ return 1;
+ case 2:
+ return 2;
+ case 5:
+ return 3;
+ case 15:
+ return 4;
+ case 30:
+ return 5;
+ default:
+ return 0;
+ }
}