Language settings continued.
[yandex-traffic] / settings.cpp
index 973e6d6..995aa05 100644 (file)
@@ -2,6 +2,17 @@
 #include <settings.hpp>
 
 
+static Settings* _settings;
+
+
+Settings* Settings::instance ()
+{
+    if (!_settings)
+        _settings = new Settings;
+    return _settings;
+}
+
+
 Settings::Settings ()
 {
     load ();
@@ -22,10 +33,11 @@ void Settings::load ()
     _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 ();
-
-    loadCities (&settings);
+    _checks[C_UpdateWhenLocked] = settings.value ("checks/updateWhenLocked", _checks[C_UpdateWhenLocked]).toBool ();
 
     _updateIntervalIndex = minutes2IntervalIndex (settings.value ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex)).toInt ());
+
+    setLanguageIndex (settings.value ("langIndex", _langIndex).toInt ());
 }
 
 
@@ -41,46 +53,11 @@ void Settings::save ()
     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]);
 
     settings.setValue ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex));
 
-    saveCities (&settings);
-}
-
-
-void Settings::loadCities (QSettings *settings)
-{
-    QMap<QString, QVariant> v;
-    QMap<QString, QVariant>::const_iterator it;
-
-    v = settings->value ("cities", v).toMap ();
-
-    if (v.size () == 0)
-        return;
-
-    it = v.begin ();
-    _cities.clear ();
-
-    while (it != v.end ()) {
-        _cities[it.key ()] = it.value ().toString ();
-        it++;
-    }
-}
-
-
-void Settings::saveCities (QSettings *settings)
-{
-    QMap<QString, QVariant> v;
-    QMap<QString, QString>::const_iterator it;
-
-    it = _cities.begin ();
-
-    while (it != _cities.end ()) {
-        v[it.key ()] = it.value ();
-        it++;
-    }
-
-    settings->setValue ("cities", v);
+    settings.setValue ("langIndex", _langIndex);
 }
 
 
@@ -99,7 +76,15 @@ void Settings::makeDefault ()
 
     setCheck (C_UpdateOnWiFi, true);
 
+    setCheck (C_UpdateWhenLocked, true);
+
     _updateIntervalIndex = 3;
+
+    // languages
+    _langs.append (Language (QString (""),   tr ("System")));
+    _langs.append (Language (QString ("en"), tr ("English")));
+    _langs.append (Language (QString ("ru"), tr ("Russian")));
+    setLanguageIndex (0);
 }
 
 
@@ -148,3 +133,12 @@ int Settings::minutes2IntervalIndex (int minutes) const
             return 0;
     }
 }
+
+
+void Settings::setLanguageIndex (int index)
+{
+    if (index < 0 || index >= _langs.count ())
+        _langIndex = 0;
+    else
+        _langIndex = index;
+}