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 <QtCore/QDebug>
20 #include <QtGui/QVBoxLayout>
21 #include <QtGui/QHBoxLayout>
22 #include <QtGui/QLabel>
23 #include "eniroguiconfig.h"
26 EniroGuiConfig::EniroGuiConfig(QWidget* parent):
27 SourceGuiConfig(parent), EniroCoreConfig(), layout_(0), usernameInput_(0),
28 passwordInput_(0), siteSelector_(0), usernameLabel_(0), passwordLabel_(0)
31 loadLayout(getSite());
34 EniroGuiConfig::~EniroGuiConfig()
38 void EniroGuiConfig::save()
40 if(usernameInput_ && passwordInput_)
42 setUsername(usernameInput_->text());
43 setPassword(passwordInput_->text());
46 setSite(siteSelector_->value().toString());
51 void EniroGuiConfig::loadLayout(QString const& site)
55 siteSelector_->hide();
58 if(usernameLabel_ && passwordLabel_)
60 usernameLabel_->hide();
62 usernameInput_->hide();
64 passwordLabel_->hide();
66 passwordInput_->hide();
75 layout_ = new QVBoxLayout;
77 QMap <Eniro::Site, Eniro::SiteDetails> sites = Eniro::getSites();
79 siteSelector_ = new ButtonSelector(tr("Eniro site"), this);
82 QMap <Eniro::Site, Eniro::SiteDetails>::const_iterator it;
83 for(it = sites.begin(); it != sites.end(); it++)
99 qDebug() << "Unknown site";
103 siteSelector_->addItem(name, it.value().id);
105 if(it.value().id == site)
107 siteSelector_->setCurrentIndex(i);
113 connect(siteSelector_, SIGNAL(selected(unsigned int, QString const&, QVariant const&)),
114 this, SLOT(siteChanged(unsigned int, QString const&, QVariant const&)));
116 layout_->addWidget(siteSelector_);
120 QHBoxLayout* username = new QHBoxLayout;
121 QHBoxLayout* password = new QHBoxLayout;
123 usernameLabel_ = new QLabel(tr("Eniro username"));
124 usernameInput_ = new QLineEdit(getUsername());
126 passwordLabel_ = new QLabel(tr("Eniro password"));
127 passwordInput_ = new QLineEdit(getPassword());
128 passwordInput_->setEchoMode(QLineEdit::PasswordEchoOnEdit);
130 username->addWidget(usernameLabel_);
131 username->addWidget(usernameInput_);
132 password->addWidget(passwordLabel_);
133 password->addWidget(passwordInput_);
135 layout_->addLayout(username);
136 layout_->addLayout(password);
142 void EniroGuiConfig::siteChanged(unsigned int index,
144 QVariant const& value)
148 loadLayout(value.toString());