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 bool Settings::set(QString const& name, QString const& value)
38 bool connected = DB::connected();
48 QSqlQuery deleteQuery;
49 deleteQuery.prepare("DELETE FROM settings WHERE name = :name");
50 deleteQuery.bindValue(":name", QVariant(name));
54 query.prepare("INSERT INTO settings(name, value) VALUES(:name, :value)");
55 query.bindValue(":name", QVariant(name));
56 query.bindValue(":value", QVariant(value));
58 bool returnValue = query.exec();
68 QString Settings::get(QString const& name)
72 bool connected = DB::connected();
84 query.prepare("SELECT value FROM settings WHERE name = :name");
85 query.bindValue(":name", name);
87 if(query.exec() && query.next())
89 result = query.value(0).toString();
93 result = getDefaultValue(name);
105 QString Settings::getDefaultValue(QString const& name)
107 static bool defaultValuesLoaded = false;
108 static QMap <QString, QString> defaultValues;
110 if(!defaultValuesLoaded)
112 defaultValues["autostart"] = "1";
113 defaultValues["eniro_site"] = tr("fi");
114 defaultValues["cache_size"] = "200";
115 defaultValuesLoaded = true;
118 QMap<QString, QString>::const_iterator it = defaultValues.find(name);
120 if(it != defaultValues.end())
129 bool Settings::reset()
131 bool connected = DB::connected();
143 bool ret = query.exec("DELETE FROM settings");