- setWindowTitle(tr("Settings"));
-
- DB::connect();
-
- QVBoxLayout* left = 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"));
-
- QLabel* passwordLabel = new QLabel(tr("Eniro password"));
- passwordInput_ = new QLineEdit(Settings::instance()->get("eniro_password"));
-
- QLabel* cacheLabel = new QLabel(tr("Cache size (numbers)"));
- cacheInput_ = new QLineEdit(Settings::instance()->get("cache_size"));
- cacheInput_->setValidator(new QIntValidator(0, 10000, this));
-
- 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++)
- {
- siteSelector_->addItem(it.value().name, it.value().id);
-
- if(it.value().id == site)
- {
- siteSelector_->setCurrentIndex(i);
- }
-
- i++;
- }
-
- 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);
-
- QPushButton* submitButton = new QPushButton(tr("Save"));
- 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_);
- left->addLayout(username);
- left->addLayout(password);
- left->addLayout(cache);
- left->addWidget(siteSelector_);
- left->addWidget(autostartSelector_);
-
- mainLayout->addLayout(left);
- mainLayout->addWidget(submitButton);
-
- setLayout(mainLayout);
-
- DB::disconnect();
+ setWindowTitle(tr("Settings"));
+
+ DB::connect();
+
+ 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"));
+
+ QLabel* passwordLabel = new QLabel(tr("Eniro password"));
+ passwordInput_ = new QLineEdit(Settings::instance()->get("eniro_password"));
+ passwordInput_->setEchoMode(QLineEdit::PasswordEchoOnEdit);
+
+ QLabel* cacheLabel = new QLabel(tr("Cache size (numbers)"));
+ cacheInput_ = new QLineEdit(Settings::instance()->get("cache_size"));
+ cacheInput_->setValidator(new QIntValidator(0, 10000, this));
+ 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;
+
+ if(sites_.empty())
+ {
+ sites_ = Eniro::getSites();
+ }
+
+ QMap <Eniro::Site, Eniro::SiteDetails>::const_iterator it;
+ for(it = sites_.begin(); it != sites_.end(); it++)
+ {
+ QString name;
+
+ switch(it.key())
+ {
+ 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;
+
+ }
+ siteSelector_->addItem(name, it.value().id);
+
+ if(it.value().id == site)
+ {
+ siteSelector_->setCurrentIndex(i);
+ }
+
+ i++;
+ }
+
+ 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);
+
+ 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()));
+
+ username->addWidget(usernameLabel);
+ username->addWidget(usernameInput_);
+ password->addWidget(passwordLabel);
+ password->addWidget(passwordInput_);
+ cache->addWidget(cacheLabel);
+ cache->addWidget(cacheInput_);
+ cache->addWidget(cacheResetButton);
+ 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);
+
+ 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);
+
+ DB::disconnect();