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 <QtSql/QSqlQuery>
20 #include <QtCore/QVariant>
24 Settings* Settings::instance_ = 0;
26 Settings* Settings::instance()
30 instance_ = new Settings;
36 void Settings::close()
42 bool Settings::set(QString const& name, QString const& value)
44 bool connected = DB::connected();
54 QSqlQuery deleteQuery;
55 deleteQuery.prepare("DELETE FROM settings WHERE name = :name");
56 deleteQuery.bindValue(":name", QVariant(name));
60 query.prepare("INSERT INTO settings(name, value) VALUES(:name, :value)");
61 query.bindValue(":name", QVariant(name));
62 query.bindValue(":value", QVariant(value));
64 bool returnValue = query.exec();
74 QString Settings::get(QString const& name)
78 bool connected = DB::connected();
90 query.prepare("SELECT value FROM settings WHERE name = :name");
91 query.bindValue(":name", name);
93 if(query.exec() && query.next())
95 result = query.value(0).toString();
99 result = getDefaultValue(name);
111 QString Settings::getDefaultValue(QString const& name)
113 static bool defaultValuesLoaded = false;
114 static QMap <QString, QString> defaultValues;
116 if(!defaultValuesLoaded)
118 defaultValues["autostart"] = "1";
119 defaultValues["eniro_site"] = tr("fi");
120 defaultValues["cache_size"] = "200";
121 defaultValuesLoaded = true;
124 QMap<QString, QString>::const_iterator it = defaultValues.find(name);
126 if(it != defaultValues.end())
135 bool Settings::reset()
137 bool connected = DB::connected();
149 bool ret = query.exec("DELETE FROM settings");