aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/services/config.h
blob: 202120a9600b0516c117358483362b8473268f4d (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#ifndef CONFIG_H
#define CONFIG_H

#include "coreSQLiteStudio_global.h"
#include "config_builder.h"
#include "services/functionmanager.h"
#include "collationmanager.h"
#include "sqlitestudio.h"
#include "common/utils.h"
#include <QObject>
#include <QVariant>
#include <QHash>
#include <QStringList>
#include <QSharedPointer>
#include <QDateTime>

const int SQLITESTUDIO_CONFIG_VERSION = 2;

CFG_CATEGORIES(Core,
    CFG_CATEGORY(General,
        CFG_ENTRY(int,          SqlHistorySize,          10000)
        CFG_ENTRY(int,          DdlHistorySize,          1000)
        CFG_ENTRY(int,          BindParamsCacheSize,     1000)
        CFG_ENTRY(int,          PopulateHistorySize,     100)
        CFG_ENTRY(QString,      LoadedPlugins,           "")
        CFG_ENTRY(QVariantHash, ActiveCodeFormatter,     QVariantHash())
        CFG_ENTRY(bool,         CheckUpdatesOnStartup,   true)
        CFG_ENTRY(QString,      Language,                "en")
    )
    CFG_CATEGORY(Console,
        CFG_ENTRY(int,          HistorySize,             100)
    )
    CFG_CATEGORY(Internal,
        CFG_ENTRY(QVariantList, Functions,               QVariantList())
        CFG_ENTRY(QVariantList, Collations,              QVariantList())
        CFG_ENTRY(QVariantList, Extensions,              QVariantList())
        CFG_ENTRY(QString,      BugReportUser,           QString())
        CFG_ENTRY(QString,      BugReportPassword,       QString())
        CFG_ENTRY(QString,      BugReportRecentTitle,    QString())
        CFG_ENTRY(QString,      BugReportRecentContents, QString())
        CFG_ENTRY(bool,         BugReportRecentError,    false)
    )
)

#define CFG_CORE CFG_INSTANCE(Core)

class QAbstractItemModel;
class DdlHistoryModel;

class API_EXPORT Config : public QObject
{
    Q_OBJECT

    public:
        virtual ~Config();

        struct CfgDb
        {
            QString name;
            QString path;
            QHash<QString,QVariant> options;
        };

        typedef QSharedPointer<CfgDb> CfgDbPtr;

        struct DbGroup;
        typedef QSharedPointer<DbGroup> DbGroupPtr;

        struct DbGroup
        {
            qint64 id;
            QString referencedDbName;
            QString name;
            QList<DbGroupPtr> childs;
            int order;
            bool open = false;
        };

        struct SqlHistoryEntry
        {
            QString query;
            QString dbName;
            int rowsAffected;
            int unixtime;
        };

        typedef QSharedPointer<SqlHistoryEntry> SqlHistoryEntryPtr;

        struct DdlHistoryEntry
        {
            QString dbName;
            QString dbFile;
            QDateTime timestamp;
            QString queries;
        };

        typedef QSharedPointer<DdlHistoryEntry> DdlHistoryEntryPtr;

        struct ReportHistoryEntry
        {
            int id = 0;
            bool isFeatureRequest = false;
            int timestamp = 0;
            QString title;
            QString url;
        };

        typedef QSharedPointer<ReportHistoryEntry> ReportHistoryEntryPtr;

        static void setMasterConfigFile(const QString& path);
        static QString getMasterConfigFile();

        virtual void init() = 0;
        virtual void cleanUp() = 0;
        virtual const QString& getConfigDir() const = 0;
        virtual QString getConfigFilePath() const = 0;

        virtual void beginMassSave() = 0;
        virtual void commitMassSave() = 0;
        virtual void rollbackMassSave() = 0;
        virtual bool isMassSaving() const = 0;
        virtual void set(const QString& group, const QString& key, const QVariant& value) = 0;
        virtual QVariant get(const QString& group, const QString& key) = 0;
        virtual QVariant get(const QString& group, const QString& key, const QVariant& defaultValue) = 0;
        virtual QHash<QString,QVariant> getAll() = 0;

        virtual bool addDb(const QString& name, const QString& path, const QHash<QString, QVariant> &options) = 0;
        virtual bool updateDb(const QString& name, const QString &newName, const QString& path, const QHash<QString, QVariant> &options) = 0;
        virtual bool removeDb(const QString& name) = 0;
        virtual bool isDbInConfig(const QString& name) = 0;
        virtual QString getLastErrorString() const = 0;

        /**
         * @brief Provides list of all registered databases.
         * @return List of database entries.
         *
         * Registered databases are those that user added to the application. They are not necessary valid or supported.
         * They can be inexisting or unsupported, but they are kept in registry in case user fixes file path,
         * or loads plugin to support it.
         */
        virtual QList<CfgDbPtr> dbList() = 0;
        virtual CfgDbPtr getDb(const QString& dbName) = 0;

        virtual void storeGroups(const QList<DbGroupPtr>& groups) = 0;
        virtual QList<DbGroupPtr> getGroups() = 0;
        virtual DbGroupPtr getDbGroup(const QString& dbName) = 0;

        virtual qint64 addSqlHistory(const QString& sql, const QString& dbName, int timeSpentMillis, int rowsAffected) = 0;
        virtual void updateSqlHistory(qint64 id, const QString& sql, const QString& dbName, int timeSpentMillis, int rowsAffected) = 0;
        virtual void clearSqlHistory() = 0;
        virtual void deleteSqlHistory(const QList<qint64>& ids) = 0;
        virtual QAbstractItemModel* getSqlHistoryModel() = 0;

        virtual void addCliHistory(const QString& text) = 0;
        virtual void applyCliHistoryLimit() = 0;
        virtual void clearCliHistory() = 0;
        virtual QStringList getCliHistory() const = 0;

        virtual void addBindParamHistory(const QVector<QPair<QString, QVariant>>& params) = 0;
        virtual void applyBindParamHistoryLimit() = 0;
        virtual QVector<QPair<QString, QVariant>> getBindParamHistory(const QStringList& paramNames) const = 0;

        virtual void addPopulateHistory(const QString& database, const QString& table, int rows, const QHash<QString, QPair<QString, QVariant>>& columnsPluginsConfig) = 0;
        virtual void applyPopulateHistoryLimit() = 0;
        virtual QHash<QString, QPair<QString, QVariant>> getPopulateHistory(const QString& database, const QString& table, int& rows) const = 0;
        virtual QVariant getPopulateHistory(const QString& pluginName) const = 0;

        virtual void addDdlHistory(const QString& queries, const QString& dbName, const QString& dbFile) = 0;
        virtual QList<DdlHistoryEntryPtr> getDdlHistoryFor(const QString& dbName, const QString& dbFile, const QDate& date) = 0;
        virtual DdlHistoryModel* getDdlHistoryModel() = 0;
        virtual void clearDdlHistory() = 0;

        virtual void addReportHistory(bool isFeatureRequest, const QString& title, const QString& url) = 0;
        virtual QList<ReportHistoryEntryPtr> getReportHistory() = 0;
        virtual void deleteReport(int id) = 0;
        virtual void clearReportHistory() = 0;

        virtual void begin() = 0;
        virtual void commit() = 0;
        virtual void rollback() = 0;

        virtual QString getSqlite3Version() const = 0;

    signals:
        void massSaveBegins();
        void massSaveCommitted();
        void sqlHistoryRefreshNeeded();
        void ddlHistoryRefreshNeeded();
        void reportsHistoryRefreshNeeded();

    public slots:
        virtual void refreshSqlHistory() = 0;
        virtual void refreshDdlHistory() = 0;
};

#define CFG SQLITESTUDIO->getConfig()

#endif // CONFIG_H