Falkon Develop
Cross-platform Qt-based web browser
gm_jsobject.cpp
Go to the documentation of this file.
1/* ============================================================
2* GreaseMonkey plugin for Falkon
3* Copyright (C) 2013-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "gm_jsobject.h"
19
20#include "qzcommon.h"
21
22#include <QApplication>
23#include <QClipboard>
24
26 : QObject(parent)
27 , m_settings(nullptr)
28{
29}
30
31void GM_JSObject::setSettingsFile(const QString &name)
32{
33 if (m_settings) {
34 m_settings->sync();
35 delete m_settings;
36 }
37
38 m_settings = new QSettings(name, QSettings::IniFormat);
39}
40
41QString GM_JSObject::getValue(const QString &nspace, const QString &name, const QString &dValue)
42{
43 QString valueName = QSL("GreaseMonkey-%1/%2").arg(nspace, name);
44 QString savedValue = m_settings->value(valueName, dValue).toString();
45
46 if (savedValue.isEmpty()) {
47 return dValue;
48 }
49
50 return savedValue;
51}
52
53bool GM_JSObject::setValue(const QString &nspace, const QString &name, const QString &value)
54{
55 QString valueName = QSL("GreaseMonkey-%1/%2").arg(nspace, name);
56 m_settings->setValue(valueName, value);
57 return true;
58}
59
60bool GM_JSObject::deleteValue(const QString &nspace, const QString &name)
61{
62 QString valueName = QSL("GreaseMonkey-%1/%2").arg(nspace, name);
63 m_settings->remove(valueName);
64 return true;
65}
66
67QStringList GM_JSObject::listValues(const QString &nspace)
68{
69 QString nspaceName = QSL("GreaseMonkey-%1").arg(nspace);
70
71 m_settings->beginGroup(nspaceName);
72 QStringList keys = m_settings->allKeys();
73 m_settings->endGroup();
74
75 return keys;
76}
77
78void GM_JSObject::setClipboard(const QString &text)
79{
80 QApplication::clipboard()->setText(text);
81}
82
84{
85 if (m_settings) {
86 m_settings->sync();
87 delete m_settings;
88 }
89}
void setSettingsFile(const QString &name)
Definition: gm_jsobject.cpp:31
GM_JSObject(QObject *parent=nullptr)
Definition: gm_jsobject.cpp:25
void setClipboard(const QString &text)
Definition: gm_jsobject.cpp:78
bool deleteValue(const QString &nspace, const QString &name)
Definition: gm_jsobject.cpp:60
QStringList listValues(const QString &nspace)
Definition: gm_jsobject.cpp:67
bool setValue(const QString &nspace, const QString &name, const QString &value)
Definition: gm_jsobject.cpp:53
QString getValue(const QString &nspace, const QString &name, const QString &dValue)
Definition: gm_jsobject.cpp:41
int value(const QColor &c)
Definition: colors.cpp:238
#define QSL(x)
Definition: qzcommon.h:40