2 * This file is part of Jenirok.
4 * Jenirok is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Jenirok is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Jenirok. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtGui/QLabel>
20 #include <QtGui/QPushButton>
21 #include <QtGui/QVBoxLayout>
22 #include <QtGui/QHBoxLayout>
23 #include <QtGui/QIntValidator>
24 #include <QMaemo5ValueButton>
25 #include <QMaemo5InformationBox>
27 #include "settingsdialog.h"
32 QMap <Eniro::Site, Eniro::SiteDetails> SettingsDialog::sites_ = Eniro::getSites();
34 SettingsDialog::SettingsDialog(QWidget* parent): QDialog(parent),
35 usernameInput_(0), passwordInput_(0), cacheInput_(0), siteSelector_(0),
38 setWindowTitle(tr("Settings"));
42 QVBoxLayout* left = new QVBoxLayout;
43 QHBoxLayout* mainLayout = new QHBoxLayout;
44 QHBoxLayout* username = new QHBoxLayout;
45 QHBoxLayout* password = new QHBoxLayout;
46 QHBoxLayout* cache = new QHBoxLayout;
48 QLabel* usernameLabel = new QLabel(tr("Eniro username"));
49 usernameInput_ = new QLineEdit(Settings::instance()->get("eniro_username"));
51 QLabel* passwordLabel = new QLabel(tr("Eniro password"));
52 passwordInput_ = new QLineEdit(Settings::instance()->get("eniro_password"));
54 QLabel* cacheLabel = new QLabel(tr("Cache size (numbers)"));
55 cacheInput_ = new QLineEdit(Settings::instance()->get("cache_size"));
56 cacheInput_->setValidator(new QIntValidator(0, 10000, this));
58 siteSelector_ = new ButtonSelector(tr("Eniro site"), this);
59 QString site = Settings::instance()->get("eniro_site");
61 QMap <Eniro::Site, Eniro::SiteDetails>::const_iterator it;
62 for(it = sites_.begin(); it != sites_.end(); it++)
64 siteSelector_->addItem(it.value().name, it.value().id);
66 if(it.value().id == site)
68 siteSelector_->setCurrentIndex(i);
74 autostartSelector_ = new ButtonSelector(tr("Autostart"), this);
75 QString autostart = Settings::instance()->get("autostart");
76 autostartSelector_->addItem(tr("Enabled"), "1");
77 autostartSelector_->addItem(tr("Disabled"), "0");
78 autostartSelector_->setCurrentIndex(autostart == "1" ? 0 : 1);
80 QPushButton* submitButton = new QPushButton(tr("Save"));
81 connect(submitButton, SIGNAL(pressed()), this, SLOT(saveSettings()));
83 username->addWidget(usernameLabel);
84 username->addWidget(usernameInput_);
85 password->addWidget(passwordLabel);
86 password->addWidget(passwordInput_);
87 cache->addWidget(cacheLabel);
88 cache->addWidget(cacheInput_);
89 left->addLayout(username);
90 left->addLayout(password);
91 left->addLayout(cache);
92 left->addWidget(siteSelector_);
93 left->addWidget(autostartSelector_);
95 mainLayout->addLayout(left);
96 mainLayout->addWidget(submitButton);
98 setLayout(mainLayout);
103 void SettingsDialog::saveSettings()
107 Settings::instance()->set("eniro_username", usernameInput_->text());
108 Settings::instance()->set("eniro_password", passwordInput_->text());
109 Settings::instance()->set("cache_size", cacheInput_->text());
110 QString site = siteSelector_->value().toString();
111 Settings::instance()->set("site", site);
112 QString autostart = autostartSelector_->value().toString();
113 Settings::instance()->set("autostart", autostart);
119 if(site != currentSite_ && Daemon::isRunning())
121 QMaemo5InformationBox::information(this, tr("Restarting daemon..."));
126 if(autostart != currentAutostart_)
135 Daemon::setAutostart(value);
140 void SettingsDialog::setVisible(bool visible)
142 QDialog::setVisible(visible);
146 currentSite_ = siteSelector_->value().toString();
147 currentAutostart_ = autostartSelector_->value().toString();