Debian Codegraph @

Dekko/backend/settings/SettingsFileBase.h

raw symbols SCIP
1 /* Copyright (C) 2014-2016 Dan Chapman <[email protected]>
2
3 This file is part of Dekko email client for Ubuntu Devices/
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
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 #ifndef SETTINGSFILEBASE_H
19 #define SETTINGSFILEBASE_H
20
21 #include <QObject>
22 #include <QStringList>
23 #include <QJsonObject>
24 #include <QJsonValue>
25 #include <QTimer>
26 #include "SettingsObjectBase.h"
27
28 class SettingsObjectBase;
29 class SettingsFileBase : public QObject
30 {
31 Q_OBJECT
32
33 Q_PROPERTY(SettingsObjectBase *object READ object CONSTANT)
34 Q_PROPERTY(QString errorString READ errorString NOTIFY error)
35 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
36
37 public:
38 explicit SettingsFileBase(QObject *parent = 0);
39 ~SettingsFileBase();
40 QString path() const;
41 bool setPath(const QString &path);
42 SettingsObjectBase *object();
43 const SettingsObjectBase *object() const;
44
45 QString errorString() const;
46 QJsonValue read(const QJsonObject &obj, const QStringList &path);
47 bool write(const QStringList &path, const QJsonValue &value);
48 bool readFile();
49 bool writeFile();
50
51 static QStringList splitPath(const QString &input, bool &ok);
52
53 signals:
54 void error();
55 void pathChanged();
56 void modified(const QStringList &path, const QJsonValue &value);
57
58 protected:
59 void reset();
60 void setErrorString(const QString &msg);
61 bool checkDirPermissions(const QString &path);
62
63 private slots:
64 void sync();
65
66 private:
67 QString m_path;
68 QString m_errorString;
69 SettingsObjectBase *m_rootObject;
70 // This is the root jsonobject inside the AbstractSettingsObject
71 QJsonObject m_jsonObject;
72 QTimer m_syncTimer;
73 friend class SettingsObjectBase;
74 };
75
76 #endif