Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Jenirok
Summary Tracker SCM Files
index f84f8c8..ac9d643 100644 (file)
  *
  */
 
+#include <QtCore/QDebug>
 #include <QtGui/QLabel>
 #include <QtGui/QPushButton>
 #include <QtGui/QVBoxLayout>
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QIntValidator>
 #include <QtGui/QDialogButtonBox>
+#include <QtGui/QTabWidget>
 #include <QMaemo5ValueButton>
 #include <QMaemo5InformationBox>
-#include <QDebug>
 #include "settingsdialog.h"
 #include "settings.h"
 #include "db.h"
 #include "daemon.h"
 #include "cache.h"
+#include "buttonselector.h"
+#include "connectionselector.h"
+#include "sourceguiconfig.h"
 
-QMap <Eniro::Site, Eniro::SiteDetails> SettingsDialog::sites_ = Eniro::getSites();
+QList<Source::SourceDetails> SettingsDialog::sources_;
 
 SettingsDialog::SettingsDialog(QWidget* parent): QDialog(parent),
-usernameInput_(0), passwordInput_(0), cacheInput_(0), siteSelector_(0),
-autostartSelector_(0)
+sourceConfig_(0), cacheInput_(0), sourceSelector_(0),
+autostartSelector_(0), connectionSelector_(0), tabs_(0)
 {
     setWindowTitle(tr("Settings"));
 
-    DB::connect();
-
-    QVBoxLayout* left = new QVBoxLayout;
+    QVBoxLayout* general = new QVBoxLayout;
+    QVBoxLayout* daemon = new QVBoxLayout;
     QHBoxLayout* mainLayout = new QHBoxLayout;
-    QHBoxLayout* username = new QHBoxLayout;
-    QHBoxLayout* password = new QHBoxLayout;
+
     QHBoxLayout* cache = new QHBoxLayout;
 
-    QLabel* usernameLabel = new QLabel(tr("Eniro username"));
-    usernameInput_ = new QLineEdit(Settings::instance()->get("eniro_username"));
+    currentSource_ = Settings::instance()->get("source");
+    Source::SourceId sourceId = Source::stringToId(currentSource_);
+    sourceConfig_ = SourceGuiConfig::getGuiConfig(sourceId, this);
 
-    QLabel* passwordLabel = new QLabel(tr("Eniro password"));
-    passwordInput_ = new QLineEdit(Settings::instance()->get("eniro_password"));
+    Q_ASSERT(sourceConfig_ != 0);
 
     QLabel* cacheLabel = new QLabel(tr("Cache size (numbers)"));
     cacheInput_ = new QLineEdit(Settings::instance()->get("cache_size"));
@@ -59,129 +61,160 @@ autostartSelector_(0)
     QPushButton* cacheResetButton = new QPushButton(tr("Clear"), this);
     connect(cacheResetButton, SIGNAL(pressed()), this, SLOT(resetCache()));
 
-    siteSelector_ = new ButtonSelector(tr("Eniro site"), this);
-    QString site = Settings::instance()->get("eniro_site");
-    int i = 0;
-    QMap <Eniro::Site, Eniro::SiteDetails>::const_iterator it;
-    for(it = sites_.begin(); it != sites_.end(); it++)
+    languageSelector_ = new ButtonSelector(tr("Language"), this);
+    languageSelector_->addItem(tr("Automatic"), "");
+
+    selectedLanguage_ = Settings::instance()->get("language");
+
+    QList<Settings::Language> langs;
+    Settings::getLanguages(langs);
+
+    for(int i = 0; i < langs.size(); i++)
     {
-        QString name;
+        languageSelector_->addItem(langs.at(i).name, langs.at(i).id);
 
-        switch(it.key())
+        if(langs.at(i).id == selectedLanguage_)
         {
-        case Eniro::FI:
-            name = tr("Finnish");
-            break;
-        case Eniro::SE:
-            name = tr("Swedish");
-            break;
-        case Eniro::DK:
-            name = tr("Danish");
-            break;
-        default:
-            qDebug() << "Unknown site";
-            continue;
-
+            languageSelector_->setCurrentIndex(i + 1);
         }
-        siteSelector_->addItem(name, it.value().id);
+    }
+
+    sourceSelector_ = new ButtonSelector(tr("Phonebook"), this);
+
+    if(sources_.isEmpty())
+    {
+        Source::getSources(sources_);
+    }
+
+    for(int i = 0; i < sources_.size(); i++)
+    {
+        sourceSelector_->addItem(sources_.at(i).name, sources_.at(i).id);
 
-        if(it.value().id == site)
+        if(sources_.at(i).id == currentSource_)
         {
-            siteSelector_->setCurrentIndex(i);
+            sourceSelector_->setCurrentIndex(i);
         }
-
-        i++;
     }
 
+    connect(sourceSelector_, SIGNAL(selected(unsigned int, QString const&, QVariant const&)),
+            this, SLOT(onSourceSelected(unsigned int, QString const&, QVariant const&)));
+
     autostartSelector_ = new ButtonSelector(tr("Autostart"), this);
     QString autostart = Settings::instance()->get("autostart");
     autostartSelector_->addItem(tr("Enabled"), "1");
     autostartSelector_->addItem(tr("Disabled"), "0");
     autostartSelector_->setCurrentIndex(autostart == "1" ? 0 : 1);
 
+    connectionSelector_ = new ConnectionSelector(tr("Connect automatically on"), this);
+    QString selectedConnection = Settings::instance()->get("connection");
+
+    if(connectionSelector_->selectByValue(selectedConnection) &&
+       selectedConnection == "gprs")
+    {
+        connectionSelector_->updateConnections();
+    }
+
     QPushButton* submitButton = new QPushButton(tr("Save"), this);
     connect(submitButton, SIGNAL(pressed()), this, SLOT(saveSettings()));
 
-    username->addWidget(usernameLabel);
-    username->addWidget(usernameInput_);
-    password->addWidget(passwordLabel);
-    password->addWidget(passwordInput_);
     cache->addWidget(cacheLabel);
     cache->addWidget(cacheInput_);
     cache->addWidget(cacheResetButton);
-    left->addLayout(username);
-    left->addLayout(password);
-    left->addLayout(cache);
-    left->addWidget(siteSelector_);
-    left->addWidget(autostartSelector_);
+    general->addLayout(cache);
+    general->addWidget(languageSelector_);
+    general->addWidget(sourceSelector_);
+
+    daemon->addWidget(autostartSelector_);
+    daemon->addWidget(connectionSelector_);
 
     QDialogButtonBox* buttons = new QDialogButtonBox;
     buttons->setCenterButtons(false);
     buttons->addButton(submitButton, QDialogButtonBox::AcceptRole);
 
-    mainLayout->addLayout(left);
+    tabs_ = new QTabWidget;
+
+    QWidget* generalTab = new QWidget;
+    generalTab->setLayout(general);
+
+    QWidget* daemonTab = new QWidget;
+    daemonTab->setLayout(daemon);
+
+    tabs_->addTab(generalTab, tr("General"));
+    tabs_->addTab(daemonTab, tr("Daemon"));
+    tabs_->addTab(sourceConfig_, tr("Phonebook settings"));
+
+    mainLayout->addWidget(tabs_);
     mainLayout->addWidget(buttons);
 
     setLayout(mainLayout);
 
-    DB::disconnect();
 }
 
 void SettingsDialog::saveSettings()
 {
-    DB::connect();
+    hide();
+
+    Settings::instance()->startEdit();
 
-    Settings::instance()->set("eniro_username", usernameInput_->text());
-    Settings::instance()->set("eniro_password", passwordInput_->text());
     Settings::instance()->set("cache_size", cacheInput_->text());
-    QString site = siteSelector_->value().toString();
-    Settings::instance()->set("site", site);
+    QString source = sourceSelector_->value().toString();
+    Settings::instance()->set("source", source);
     QString autostart = autostartSelector_->value().toString();
     Settings::instance()->set("autostart", autostart);
+    QString connection = connectionSelector_->value().toString();
+    Settings::instance()->set("connection", connection);
+    QString language = languageSelector_->value().toString();
+    Settings::instance()->set("language", language);
+    sourceConfig_->save();
 
-    DB::disconnect();
-
-    hide();
+    Settings::instance()->endEdit();
 
-    if(site != currentSite_ && Daemon::isRunning())
+    if(language != selectedLanguage_)
     {
-        QMaemo5InformationBox::information(this, tr("Restarting daemon..."));
-        Daemon::restart();
-        currentSite_ = site;
+        QMaemo5InformationBox::information(this, tr("You need to restart Jenirok for language change to take effect."));
+        selectedLanguage_ = language;
     }
-
-    if(autostart != currentAutostart_)
+    else if(Daemon::isRunning())
     {
-        bool value = false;
-
-        if(autostart == "1")
-        {
-            value = true;
-        }
-
-        Daemon::setAutostart(value);
+        QMaemo5InformationBox::information(this, tr("Restarting daemon..."), 1500);
+        Daemon::restart();
     }
 
 }
 
-void SettingsDialog::setVisible(bool visible)
+void SettingsDialog::resetCache()
 {
-    QDialog::setVisible(visible);
+    int ret = Cache::instance().clear();
 
-    if(visible)
+    if(ret >= 0)
     {
-        currentSite_ = siteSelector_->value().toString();
-        currentAutostart_ = autostartSelector_->value().toString();
+        QMaemo5InformationBox::information(this, tr("%n number(s) were deleted from cache", "", ret));
     }
-
 }
 
-void SettingsDialog::resetCache()
+void SettingsDialog::onSourceSelected(unsigned int index,
+                                      QString const& text,
+                                      QVariant const& value)
 {
-    int ret = Cache::instance().clear();
+    Q_UNUSED(index);
+    Q_UNUSED(text);
 
-    if(ret >= 0)
+    QString source = value.toString();
+
+    if(source != currentSource_)
     {
-        QMaemo5InformationBox::information(this, tr("%n number(s) were deleted from cache", "", ret));
+        int tabId = tabs_->indexOf(sourceConfig_);
+
+        if(tabId >= 0)
+        {
+            tabs_->removeTab(tabId);
+        }
+
+        delete sourceConfig_;
+        Source::SourceId sourceId = Source::stringToId(value.toString());
+        sourceConfig_ = SourceGuiConfig::getGuiConfig(sourceId, this);
+        Q_ASSERT(sourceConfig_ != 0);
+        tabs_->addTab(sourceConfig_, tr("Phonebook settings"));
+        currentSource_ = source;
     }
 }

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment