Update data when device unlocked.
[yandex-traffic] / settingsDialog.cpp
index 629bcb8..ca73077 100644 (file)
@@ -21,21 +21,51 @@ SettingsDialog::SettingsDialog (Settings *settings)
     QVBoxLayout *layout = new QVBoxLayout (this);
 
     _displayButton = new QMaemo5ValueButton (tr ("Display"), this);
+    _displayButton->setValueLayout (QMaemo5ValueButton::ValueUnderText);
+    updateDisplayButtonValue ();
     layout->addWidget (_displayButton);
     _updateButton = new QMaemo5ValueButton (tr ("Update"), this);
+    _updateButton->setValueLayout (QMaemo5ValueButton::ValueUnderText);
+    updateUpdateButtonValue ();
     layout->addWidget (_updateButton);
-    _alertsButton = new QMaemo5ValueButton (tr ("Alerts"), this);
-    layout->addWidget (_alertsButton);
+
+    createLanguageButton (layout);
 
     connect (_displayButton, SIGNAL (clicked ()), SLOT (displayClicked ()));
     connect (_updateButton, SIGNAL (clicked ()), SLOT (updateClicked ()));
 }
 
 
+void SettingsDialog::createLanguageButton (QBoxLayout *layout)
+{
+    _languageButton = new QMaemo5ValueButton (tr ("Language"), this);
+    layout->addWidget (_languageButton);
+
+#ifdef Q_WS_MAEMO_5
+    QMaemo5ListPickSelector *selector = new QMaemo5ListPickSelector;
+    QStandardItemModel *model = new QStandardItemModel (0, 1);
+    QList<Language>::const_iterator it = _settings->languages ().begin ();
+
+    while (it != _settings->languages ().end ()) {
+        QStandardItem *item = new QStandardItem (it->title ());
+        item->setData (it->alias ());
+        model->appendRow (item);
+        it++;
+    }
+
+    selector->setModel (model);
+    selector->setCurrentIndex (_settings->languages ().indexOf (_settings->language ()));
+
+    _languageButton->setPickSelector (selector);
+#endif
+}
+
+
 void SettingsDialog::displayClicked ()
 {
     DisplaySettingsDialog dlg (_settings);
     dlg.exec ();
+    updateDisplayButtonValue ();
 }
 
 
@@ -43,6 +73,65 @@ void SettingsDialog::updateClicked ()
 {
     UpdateSettingsDialog dlg (_settings);
     dlg.exec ();
+    updateUpdateButtonValue ();
+}
+
+
+void SettingsDialog::languageChanged (const QString&)
+{
+#ifdef Q_WS_MAEMO_5
+    QMaemo5ListPickSelector *model = static_cast<QMaemo5ListPickSelector*> (_languageButton->pickSelector ());
+
+    if (!model)
+        return;
+
+    const Language &lang = _settings->languages ()[model->currentIndex ()];
+    if (lang != _settings->language ())
+        _settings->setLanguage (lang);
+#endif
+}
+
+
+void SettingsDialog::updateDisplayButtonValue ()
+{
+    QString val;
+    QStringList list;
+
+    val = tr ("City:") + " " + _settings->cities ()[_settings->regionID ()] + ", " + tr ("Display:") + " ";
+
+    if (_settings->check (Settings::C_ShowLight))
+        list.append (tr ("lights"));
+    if (_settings->check (Settings::C_ShowRank))
+        list.append (tr ("rank"));
+    if (_settings->check (Settings::C_ShowTime))
+        list.append (tr ("time"));
+    if (_settings->check (Settings::C_ShowHint))
+        list.append (tr ("hint"));
+
+    _displayButton->setValueText (val + list.join (", "));
+}
+
+
+void SettingsDialog::updateUpdateButtonValue ()
+{
+    QStringList list, intervals = _settings->updateIntervals ();
+    QString val;
+
+    val = tr ("Interval:") + " " + intervals[_settings->getUpdateIntervalIndex ()] + ", " + tr ("Update via:") + " ";
+
+    if (_settings->check (Settings::C_UpdateOnWiFi))
+        list.append (tr ("WiFi"));
+    if (_settings->check (Settings::C_UpdateOnGSM))
+        list.append (tr ("GSM"));
+
+    val += list.join (", ");
+
+    if (_settings->check (Settings::C_UpdateWhenLocked))
+        val += ", " + tr ("Update when locked");
+    else
+        val += ", " + tr ("Not update when locked");
+
+    _updateButton->setValueText (val);
 }
 
 
@@ -162,15 +251,18 @@ UpdateSettingsDialog::UpdateSettingsDialog (Settings *_settings)
 {
     setWindowTitle (tr ("Update settings"));
 
-    _wifiUpdate = new QCheckBox (tr ("Update on WiFi connection"), this);
+    _wifiUpdate = new QCheckBox (tr ("Update via WiFi"), this);
     _wifiUpdate->setChecked (settings ()->check (Settings::C_UpdateOnWiFi));
-    _gsmUpdate  = new QCheckBox (tr ("Update on GSM connection"), this);
+    _gsmUpdate  = new QCheckBox (tr ("Update via GSM"), this);
     _gsmUpdate->setChecked (settings ()->check (Settings::C_UpdateOnGSM));
+    _lockedUpdate  = new QCheckBox (tr ("Update when device locked"), this);
+    _lockedUpdate->setChecked (settings ()->check (Settings::C_UpdateWhenLocked));
 
     initUpdateInterval (layout ());
 
     layout ()->addWidget (_wifiUpdate);
     layout ()->addWidget (_gsmUpdate);
+    layout ()->addWidget (_lockedUpdate);
 }
 
 
@@ -184,6 +276,7 @@ void UpdateSettingsDialog::saveSettings ()
 #endif
     settings ()->setCheck (Settings::C_UpdateOnWiFi, _wifiUpdate->isChecked ());
     settings ()->setCheck (Settings::C_UpdateOnGSM,  _gsmUpdate->isChecked ());
+    settings ()->setCheck (Settings::C_UpdateWhenLocked,  _lockedUpdate->isChecked ());
 }