Connection handling in daemon improved. Added settings to allow automatic connection...
[jenirok] / src / gui / settingsdialog.cpp
index 9b9ed10..f9dd623 100644 (file)
@@ -22,6 +22,7 @@
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QIntValidator>
 #include <QtGui/QDialogButtonBox>
+#include <QtGui/QTabWidget>
 #include <QMaemo5ValueButton>
 #include <QMaemo5InformationBox>
 #include <QDebug>
@@ -41,7 +42,8 @@ autostartSelector_(0)
 
     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;
@@ -52,7 +54,7 @@ autostartSelector_(0)
 
     QLabel* passwordLabel = new QLabel(tr("Eniro password"));
     passwordInput_ = new QLineEdit(Settings::instance()->get("eniro_password"));
-    passwordInput_->setEchoMode(QLineEdit::Password);
+    passwordInput_->setEchoMode(QLineEdit::PasswordEchoOnEdit);
 
     QLabel* cacheLabel = new QLabel(tr("Cache size (numbers)"));
     cacheInput_ = new QLineEdit(Settings::instance()->get("cache_size"));
@@ -106,6 +108,19 @@ autostartSelector_(0)
     autostartSelector_->addItem(tr("Disabled"), "0");
     autostartSelector_->setCurrentIndex(autostart == "1" ? 0 : 1);
 
+    autoconnectCheck_ = new QCheckBox(tr("Allow daemon to connect automatically"));
+    QString autoconnect = Settings::instance()->get("autoconnect");
+    autoconnectCheck_->setChecked(autoconnect == "1");
+
+    connectionSelector_ = new ConnectionSelector(tr("Connection to use"), this);
+    QString selectedConnection = Settings::instance()->get("connection");
+
+    if(selectedConnection != "0")
+    {
+        connectionSelector_->addItem(Settings::instance()->get("connection_name"), selectedConnection);
+        connectionSelector_->selectByValue(selectedConnection);
+    }
+
     QPushButton* submitButton = new QPushButton(tr("Save"), this);
     connect(submitButton, SIGNAL(pressed()), this, SLOT(saveSettings()));
 
@@ -116,17 +131,31 @@ autostartSelector_(0)
     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(username);
+    general->addLayout(password);
+    general->addLayout(cache);
+    general->addWidget(siteSelector_);
+
+    daemon->addWidget(autostartSelector_);
+    daemon->addWidget(autoconnectCheck_);
+    daemon->addWidget(connectionSelector_);
 
     QDialogButtonBox* buttons = new QDialogButtonBox;
     buttons->setCenterButtons(false);
     buttons->addButton(submitButton, QDialogButtonBox::AcceptRole);
 
-    mainLayout->addLayout(left);
+    QTabWidget* 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"));
+
+    mainLayout->addWidget(tabs);
     mainLayout->addWidget(buttons);
 
     setLayout(mainLayout);
@@ -136,6 +165,8 @@ autostartSelector_(0)
 
 void SettingsDialog::saveSettings()
 {
+    hide();
+
     DB::connect();
 
     Settings::instance()->set("eniro_username", usernameInput_->text());
@@ -145,12 +176,17 @@ void SettingsDialog::saveSettings()
     Settings::instance()->set("site", site);
     QString autostart = autostartSelector_->value().toString();
     Settings::instance()->set("autostart", autostart);
+    bool autoconnect = autoconnectCheck_->isChecked();
+    Settings::instance()->set("autoconnect", autoconnect ? "1" : "0");
+    QString connection = connectionSelector_->value().toString();
+    Settings::instance()->set("connection", connection);
+    Settings::instance()->set("connection_name", connectionSelector_->text());
 
     DB::disconnect();
 
-    hide();
-
-    if(site != currentSite_ && Daemon::isRunning())
+    if((site != currentSite_ ||
+        autoconnect != currentAutoconnect_ ||
+        connection != currentConnection_) && Daemon::isRunning())
     {
         QMaemo5InformationBox::information(this, tr("Restarting daemon..."));
         Daemon::restart();
@@ -166,6 +202,8 @@ void SettingsDialog::setVisible(bool visible)
     if(visible)
     {
         currentSite_ = siteSelector_->value().toString();
+        currentConnection_ = connectionSelector_->value().toString();
+        currentAutoconnect_ = autoconnectCheck_->isChecked();
     }
 
 }