aboutsummaryrefslogtreecommitdiffstats
path: root/src/settings_interface.h
blob: e3935d0bda58072b99ff3aaa9b609c9efe5375fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once

#include <QString>
#include <QVariant>
#include <QSettings>

/* struct AppSettings {
    enum {LOCALTIME, UTC} ui_timezone = LOCALTIME;
    bool can_access_internet = true;
    bool can_download_emoji = true;
    bool can_download_attachments = true;
    struct {
        enum {MASTODON} type = MASTODON;
        QString address;
        QString token;
    } instance;
}; */

namespace AppSettingsTypes {
    enum Timezone {LOCALTIME = 0, UTC};
    enum InstanceType {MASTODON = 0};
}
// Declare metatypes for use with QVariant
Q_DECLARE_METATYPE(AppSettingsTypes::Timezone);
Q_DECLARE_METATYPE(AppSettingsTypes::InstanceType);

class SettingsInterface {
public:
    ~SettingsInterface();
    const QVariant read_setting(const QString &key);
    void write_setting(const QString &key, const QVariant &value);
    void clear_setting(const QString &key);
    void clear_all();
    bool commit();
    bool is_default(const QString &key);
    bool is_uncommited(const QString &key);

private:
    QSettings qt_settings;
    QHash<QString, QVariant>* modified = nullptr;

    // Optimization to commit a clear_all() faster
    bool must_clear_all = false;
    // List of keys to remove from the QSettings
    QStringList must_clear;
};