2 #include <settings.hpp>
7 static Settings* _settings;
10 Settings* Settings::instance ()
13 _settings = new Settings;
25 void Settings::load ()
31 _regionID = settings.value ("region", _regionID).toString ();
33 _checks[C_ShowLight] = settings.value ("checks/light", _checks[C_ShowLight]).toBool ();
34 _checks[C_ShowRank] = settings.value ("checks/rank", _checks[C_ShowRank]).toBool ();
35 _checks[C_ShowTime] = settings.value ("checks/time", _checks[C_ShowTime]).toBool ();
36 _checks[C_ShowHint] = settings.value ("checks/hint", _checks[C_ShowHint]).toBool ();
37 _checks[C_UpdateOnWiFi] = settings.value ("checks/updateOnWifi", _checks[C_UpdateOnWiFi]).toBool ();
38 _checks[C_UpdateOnGSM] = settings.value ("checks/updateOnGSM", _checks[C_UpdateOnGSM]).toBool ();
39 _checks[C_UpdateWhenLocked] = settings.value ("checks/updateWhenLocked", _checks[C_UpdateWhenLocked]).toBool ();
41 _updateIntervalIndex = minutes2IntervalIndex (settings.value ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex)).toInt ());
43 setLanguageIndex (settings.value ("langIndex", _langIndex).toInt ());
47 void Settings::save ()
51 settings.setValue ("region", _regionID);
53 settings.setValue ("checks/light", _checks[C_ShowLight]);
54 settings.setValue ("checks/rank", _checks[C_ShowRank]);
55 settings.setValue ("checks/time", _checks[C_ShowTime]);
56 settings.setValue ("checks/hint", _checks[C_ShowHint]);
57 settings.setValue ("checks/updateOnWifi", _checks[C_UpdateOnWiFi]);
58 settings.setValue ("checks/updateOnGSM", _checks[C_UpdateOnGSM]);
59 settings.setValue ("checks/updateWhenLocked", _checks[C_UpdateWhenLocked]);
61 settings.setValue ("updateInterval", intervalIndex2Minutes (_updateIntervalIndex));
63 settings.setValue ("langIndex", _langIndex);
67 // This routine called before any translations loaded, so strings must be translated explicitly.
68 void Settings::makeDefault ()
70 _regionID = "1"; // Default city
72 _cities["1"] = tr ("Moscow");
73 _cities["10174"] = tr ("St.Petersburg");
74 _cities["20544"] = tr ("Kiev");
75 _cities["11162"] = tr ("Ekaterinburg");
77 setCheck (C_ShowLight, true);
78 setCheck (C_ShowRank, true);
79 setCheck (C_ShowHint, true);
81 setCheck (C_UpdateOnWiFi, true);
83 setCheck (C_UpdateWhenLocked, true);
85 _updateIntervalIndex = 3;
88 _langs.append (Language (QString (""), tr ("System")));
89 _langs.append (Language (QString ("en"), tr ("English")));
90 _langs.append (Language (QString ("ru"), tr ("Russian")));
95 QStringList Settings::updateIntervals () const
99 res.append (tr ("Never"));
100 res.append (tr ("1 min"));
101 res.append (tr ("2 min"));
102 res.append (tr ("5 min"));
103 res.append (tr ("15 min"));
104 res.append (tr ("30 min"));
110 int Settings::intervalIndex2Minutes (int index) const
112 int int2min[] = { -1, 1, 2, 5, 15, 30 };
114 if (index < 0 || sizeof (int2min) / sizeof (int2min[0]) <= (unsigned int)index)
117 return int2min[index];
121 int Settings::minutes2IntervalIndex (int minutes) const
142 void Settings::setLanguageIndex (int index)
144 if (index < 0 || index >= _langs.count ())
151 QCoreApplication::removeTranslator (_ts);
155 QString alias = _langs[_langIndex].alias ();
156 QString fileName = QString (APPLICATION_NAME) + "_";
158 _ts = new QTranslator;
160 if (alias.isEmpty ())
161 fileName += QLocale::system ().name ();
165 if (_ts->load (fileName, TRANSLATION_PATH)) {
166 QCoreApplication::installTranslator (_ts);
167 translationsUpdated ();
176 QString Settings::regionName (const QString &id) const
178 return Settings::tr (_cities[id].toUtf8 ());