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 "enirocoreconfig.h"
26 QString const COLUMN_PREFIX = "eniro_";
27 QString const USERNAME_COLUMN = COLUMN_PREFIX + "username";
28 QString const PASSWORD_COLUMN = COLUMN_PREFIX + "password";
29 QString const SITE_COLUMN = COLUMN_PREFIX + "site";
32 EniroCoreConfig::EniroCoreConfig(): SourceCoreConfig(), loaded_(false)
36 EniroCoreConfig::~EniroCoreConfig()
40 bool EniroCoreConfig::apply(Source* source)
42 Eniro* eniro = dynamic_cast<Eniro*>(source);
51 QString username = config_[USERNAME_COLUMN];
52 QString password = config_[PASSWORD_COLUMN];
54 if(!username.isEmpty() && !password.isEmpty())
56 eniro->login(username, password);
59 eniro->setSite(Eniro::stringToSite(config_[SITE_COLUMN]));
64 void EniroCoreConfig::getConfig(QMap<QString, QString>& config)
68 config[USERNAME_COLUMN] = config_[USERNAME_COLUMN];
69 config[PASSWORD_COLUMN] = config_[PASSWORD_COLUMN];
70 config[SITE_COLUMN] = config_[SITE_COLUMN];
73 void EniroCoreConfig::loadFromConfig(QMap<QString, QString> const& config)
75 config_[USERNAME_COLUMN] = config[USERNAME_COLUMN];
76 config_[PASSWORD_COLUMN] = config[PASSWORD_COLUMN];
77 config_[SITE_COLUMN] = config[SITE_COLUMN];
82 void EniroCoreConfig::store()
84 Settings::instance()->set(USERNAME_COLUMN, config_[USERNAME_COLUMN]);
85 Settings::instance()->set(PASSWORD_COLUMN, config_[PASSWORD_COLUMN]);
86 Settings::instance()->set(SITE_COLUMN, config_[SITE_COLUMN]);
89 bool EniroCoreConfig::readyToSearch()
93 if(config_[SITE_COLUMN] != "fi")
98 return !config_[USERNAME_COLUMN].isEmpty() && !config_[PASSWORD_COLUMN].isEmpty();
101 void EniroCoreConfig::setUsername(QString const& username)
103 config_[USERNAME_COLUMN] = username;
106 void EniroCoreConfig::setPassword(QString const& password)
108 config_[PASSWORD_COLUMN] = password;
111 void EniroCoreConfig::setSite(QString const& site)
113 config_[SITE_COLUMN] = site;
116 QString EniroCoreConfig::getUsername() const
118 return config_[USERNAME_COLUMN];
121 QString EniroCoreConfig::getPassword() const
123 return config_[PASSWORD_COLUMN];
126 QString EniroCoreConfig::getSite() const
128 return config_[SITE_COLUMN];
131 void EniroCoreConfig::load()
138 Settings::instance()->startEdit();
140 config_[USERNAME_COLUMN] = Settings::instance()->get(USERNAME_COLUMN);
141 config_[PASSWORD_COLUMN] = Settings::instance()->get(PASSWORD_COLUMN);
142 config_[SITE_COLUMN] = Settings::instance()->get(SITE_COLUMN);
144 Settings::instance()->endEdit();