#include <QtGui/QVBoxLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QIntValidator>
+#include <QtGui/QDialogButtonBox>
+#include <QtGui/QTabWidget>
#include <QMaemo5ValueButton>
#include <QMaemo5InformationBox>
#include <QDebug>
#include "settings.h"
#include "db.h"
#include "daemon.h"
+#include "cache.h"
-QMap <Eniro::Site, Eniro::SiteDetails> SettingsDialog::sites_ = Eniro::getSites();
+QMap <Eniro::Site, Eniro::SiteDetails> SettingsDialog::sites_;
SettingsDialog::SettingsDialog(QWidget* parent): QDialog(parent),
usernameInput_(0), passwordInput_(0), cacheInput_(0), siteSelector_(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;
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++)
{
- siteSelector_->addItem(it.value().name, it.value().id);
+ 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)
{
autostartSelector_->addItem(tr("Disabled"), "0");
autostartSelector_->setCurrentIndex(autostart == "1" ? 0 : 1);
- QPushButton* submitButton = new QPushButton(tr("Save"));
+ connectionSelector_ = new ConnectionSelector(tr("Connect automatically on"), this);
+ QString selectedConnection = Settings::instance()->get("connection");
+ connectionSelector_->selectByValue(selectedConnection);
+
+ QPushButton* submitButton = new QPushButton(tr("Save"), this);
connect(submitButton, SIGNAL(pressed()), this, SLOT(saveSettings()));
username->addWidget(usernameLabel);
password->addWidget(passwordInput_);
cache->addWidget(cacheLabel);
cache->addWidget(cacheInput_);
- left->addLayout(username);
- left->addLayout(password);
- left->addLayout(cache);
- left->addWidget(siteSelector_);
- left->addWidget(autostartSelector_);
+ cache->addWidget(cacheResetButton);
+ general->addLayout(username);
+ general->addLayout(password);
+ general->addLayout(cache);
+ general->addWidget(siteSelector_);
+
+ daemon->addWidget(autostartSelector_);
+ daemon->addWidget(connectionSelector_);
+
+ QDialogButtonBox* buttons = new QDialogButtonBox;
+ buttons->setCenterButtons(false);
+ buttons->addButton(submitButton, QDialogButtonBox::AcceptRole);
+
+ QTabWidget* tabs = new QTabWidget;
- mainLayout->addLayout(left);
- mainLayout->addWidget(submitButton);
+ 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);
void SettingsDialog::saveSettings()
{
+ hide();
+
DB::connect();
Settings::instance()->set("eniro_username", usernameInput_->text());
Settings::instance()->set("site", site);
QString autostart = autostartSelector_->value().toString();
Settings::instance()->set("autostart", autostart);
+ 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())
{
QMaemo5InformationBox::information(this, tr("Restarting daemon..."));
currentSite_ = site;
}
- if(autostart != currentAutostart_)
- {
- bool value = false;
-
- if(autostart == "1")
- {
- value = true;
- }
-
- Daemon::setAutostart(value);
- }
-
}
void SettingsDialog::setVisible(bool visible)
if(visible)
{
currentSite_ = siteSelector_->value().toString();
- currentAutostart_ = autostartSelector_->value().toString();
+ currentConnection_ = connectionSelector_->value().toString();
}
}
+
+void SettingsDialog::resetCache()
+{
+ int ret = Cache::instance().clear();
+
+ if(ret >= 0)
+ {
+ QMaemo5InformationBox::information(this, tr("%n number(s) were deleted from cache", "", ret));
+ }
+}