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>
22 #include <gconf/gconf-client.h>
26 Settings* Settings::instance_ = 0;
28 Settings* Settings::instance()
32 instance_ = new Settings;
38 void Settings::close()
44 bool Settings::set(QString const& name, QString const& value)
46 bool connected = DB::connected();
56 QSqlQuery deleteQuery;
57 deleteQuery.prepare("DELETE FROM settings WHERE name = :name");
58 deleteQuery.bindValue(":name", QVariant(name));
62 query.prepare("INSERT INTO settings(name, value) VALUES(:name, :value)");
63 query.bindValue(":name", QVariant(name));
64 query.bindValue(":value", QVariant(value));
66 bool returnValue = query.exec();
76 QString Settings::get(QString const& name)
80 bool connected = DB::connected();
92 query.prepare("SELECT value FROM settings WHERE name = :name");
93 query.bindValue(":name", name);
95 if(query.exec() && query.next())
97 result = query.value(0).toString();
101 result = getDefaultValue(name);
113 QString Settings::getDefaultValue(QString const& name)
115 static bool defaultValuesLoaded = false;
116 static QMap <QString, QString> defaultValues;
118 if(!defaultValuesLoaded)
120 defaultValues["autostart"] = "1";
121 defaultValues["eniro_site"] = tr("fi");
122 defaultValues["cache_size"] = "200";
123 defaultValues["connection"] = "global";
124 defaultValuesLoaded = true;
127 QMap<QString, QString>::const_iterator it = defaultValues.find(name);
129 if(it != defaultValues.end())
138 bool Settings::reset()
140 bool connected = DB::connected();
152 bool ret = query.exec("DELETE FROM settings");
162 Settings::ConnectionType Settings::getConnectionType()
164 QString value = get("connection");
170 else if(value == "wlan")
174 else if(value == "gprs")
180 if(value != "global")
182 qDebug() << "Unknown connection type in settings, using default";
185 QList<QString> values;
187 GConfClient* gcClient = NULL;
188 gcClient = gconf_client_get_default();
190 g_assert(GCONF_IS_CLIENT(gcClient));
192 GError* error = NULL;
194 list = gconf_client_get_list(gcClient,
195 "/system/osso/connectivity/network_type/auto_connect",
201 qDebug() << "Error: " << error->message;
208 values.push_back((char *)list->data);
214 g_object_unref(gcClient);
216 if(values.size() == 0)
222 QString value = values.at(0);
228 else if(value == "GPRS")
232 else if(value == "WLAN_INFRA" || value == "WLAN_ADHOC" || value == "WLAN")
238 qDebug() << "Unknown connection type: " << value;