2012-02-29 18:33:50 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2012-02-29 18:33:50 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2012-01-11 21:58:25 +01:00
|
|
|
#include "settings.h"
|
2012-08-10 21:16:43 +02:00
|
|
|
#include "qzsettings.h"
|
2012-01-11 21:58:25 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
2012-04-17 18:26:01 +02:00
|
|
|
QSettings* Settings::s_settings = 0;
|
2012-08-10 21:16:43 +02:00
|
|
|
QzSettings* Settings::s_qzSettings = 0;
|
2012-01-11 21:58:25 +01:00
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
Settings::Settings()
|
2012-01-11 21:58:25 +01:00
|
|
|
{
|
2014-11-01 17:50:26 +01:00
|
|
|
// Save currently opened group
|
2012-04-17 18:26:01 +02:00
|
|
|
if (!s_settings->group().isEmpty()) {
|
2014-11-01 17:50:26 +01:00
|
|
|
m_openedGroup = s_settings->group();
|
2012-04-17 18:26:01 +02:00
|
|
|
s_settings->endGroup();
|
2012-04-04 18:48:54 +02:00
|
|
|
}
|
2012-01-11 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::createSettings(const QString &fileName)
|
|
|
|
{
|
2012-04-17 18:26:01 +02:00
|
|
|
s_settings = new QSettings(fileName, QSettings::IniFormat);
|
2012-08-10 21:16:43 +02:00
|
|
|
s_qzSettings = new QzSettings();
|
2012-01-11 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::syncSettings()
|
|
|
|
{
|
2014-10-10 13:06:18 +02:00
|
|
|
if (!s_settings)
|
|
|
|
return;
|
|
|
|
|
2012-04-17 18:26:01 +02:00
|
|
|
s_settings->sync();
|
2012-01-11 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::setValue(const QString &key, const QVariant &defaultValue)
|
|
|
|
{
|
2012-04-17 18:26:01 +02:00
|
|
|
s_settings->setValue(key, defaultValue);
|
2012-01-11 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Settings::value(const QString &key, const QVariant &defaultValue)
|
|
|
|
{
|
2012-04-17 18:26:01 +02:00
|
|
|
return s_settings->value(key, defaultValue);
|
2012-01-11 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::beginGroup(const QString &prefix)
|
|
|
|
{
|
2012-04-17 18:26:01 +02:00
|
|
|
s_settings->beginGroup(prefix);
|
2012-01-11 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::endGroup()
|
|
|
|
{
|
2012-04-17 18:26:01 +02:00
|
|
|
s_settings->endGroup();
|
2012-01-11 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
2012-02-13 19:09:02 +01:00
|
|
|
QSettings* Settings::globalSettings()
|
|
|
|
{
|
2012-04-17 18:26:01 +02:00
|
|
|
return s_settings;
|
2012-02-13 19:09:02 +01:00
|
|
|
}
|
|
|
|
|
2012-08-13 15:41:08 +02:00
|
|
|
QzSettings* Settings::staticSettings()
|
2012-08-10 21:16:43 +02:00
|
|
|
{
|
|
|
|
return s_qzSettings;
|
|
|
|
}
|
|
|
|
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings::~Settings()
|
|
|
|
{
|
2012-04-17 18:26:01 +02:00
|
|
|
if (!s_settings->group().isEmpty()) {
|
2014-11-01 17:50:26 +01:00
|
|
|
qDebug() << "Settings: Deleting object with opened group!";
|
2012-04-17 18:26:01 +02:00
|
|
|
s_settings->endGroup();
|
2012-01-11 21:58:25 +01:00
|
|
|
}
|
2014-11-01 17:50:26 +01:00
|
|
|
|
|
|
|
// Restore opened group
|
|
|
|
if (!m_openedGroup.isEmpty())
|
|
|
|
s_settings->beginGroup(m_openedGroup);
|
2012-01-11 21:58:25 +01:00
|
|
|
}
|