summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/sqlitestudio.h
blob: c2841330865a507a587e528b81d6ff5959568a2e (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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#ifndef SQLITESTUDIO_H
#define SQLITESTUDIO_H

#include "coreSQLiteStudio_global.h"
#include "common/global.h"
#include "services/config.h"
#include <QString>
#include <QStringList>
#include <QObject>

class DbManager;
class Config;
class CollationManager;
class QProcessEnvironment;
class PluginManager;
class QThreadPool;
class NotifyManager;
class CodeFormatter;
class Plugin;
class PluginType;
class FunctionManager;
class DbAttacherFactory;
class DbAttacher;
class ExportManager;
class ImportManager;
class PopulateManager;
class PluginLoadingHandler;
#ifdef PORTABLE_CONFIG
class UpdateManager;
#endif
class ExtraLicenseManager;
class SqliteExtensionManager;
class Db;
class CodeSnippetManager;

/** @file */

/**
 * @mainpage
 * SQLiteStudio is SQLite 3 manager for Windows, MacOS X and Linux.
 *
 * Global variables and macros:
 * <ul>
 * <li>#SQLITESTUDIO - access point to all services (singleton instance of SQLiteStudio)</li>
 * <li>#PLUGINS - quick access to PluginManager</li>
 * <li>#DBLIST - quick access to DbManager</li>
 * <li>#FUNCTIONS - quick access to FunctionManager</li>
 * <li>#CFG - quick access to Config</li>
 * </ul>
 */


/**
 * @brief Main application class.
 * This is an entry point for all services.
 * Get all managers, services, etc from this class.
 * It is a singleton.
 */
class API_EXPORT SQLiteStudio : public QObject
{
        Q_OBJECT

        DECLARE_SINGLETON(SQLiteStudio)

    public:
        typedef std::function<void()> CrashHandler;

        /**
         * @brief Initializes SQLiteStudio object.
         * @param cmdListArguments Command line arguments.
         * @param pluginLoadingHandler Factory for producing plugin loader.
         *
         * Initialization process involves creating of all internal objects (managers, etc.)
         * and reading necessary configuration. It also interpreted command line arguments
         * and applies them.
         *
         * The plugin loader factory (handler) is used to solve issue with GUI symbols visibility. while loading code being placed in the core shared library.
         * It should be null when starting SQLiteStudio in CLI mode and not null when starting GUI client. See PluginLoadingHandler for more details on that.
         *
         * See parseCmdLineArgs() for details on supported options.
         */
        void init(const QStringList& cmdListArguments, bool guiAvailable);

        void initPlugins();

        /**
         * @brief Gets environment variable value.
         * @param name Name of the environment variable.
         * @param defaultValue Default value to be returned if the environment variable is not defined.
         * @return Either value of the environment variable - if defined - or the value passed as defaultValue.
         *
         * This method provides cross-platform way to get environment variable value.
         * Internally it uses QProcessEnvironment, but while it's expensive to initialize it every time you access environment,
         * it keeps the single instance of that object and lets you query variables by name.
         */
        QString getEnv(const QString& name, const QString& defaultValue = QString());

        /**
         * @brief Creates new DbAttacher instance for given database.
         * @param db Database to create attacher for.
         * @return Attacher instance.
         */
        DbAttacher* createDbAttacher(Db* db);

        bool isGuiAvailable() const;

        Config* getConfig() const;
        void setConfig(Config* value);

        DbManager* getDbManager() const;
        void setDbManager(DbManager* value);

        FunctionManager* getFunctionManager() const;
        void setFunctionManager(FunctionManager* value);

        PluginManager* getPluginManager() const;
        void setPluginManager(PluginManager* value);

        DbAttacherFactory* getDbAttacherFactory() const;
        void setDbAttacherFactory(DbAttacherFactory* value);

        CollationManager* getCollationManager() const;
        void setCollationManager(CollationManager* value);

        SqliteExtensionManager* getSqliteExtensionManager() const;
        void setSqliteExtensionManager(SqliteExtensionManager* value);

        ExportManager* getExportManager() const;
        void setExportManager(ExportManager* value);

        CodeSnippetManager* getCodeSnippetManager() const;
        void setCodeSnippetManager(CodeSnippetManager* newCodeSnippetManager);

        int getVersion() const;
        QString getVersionString() const;

        ImportManager* getImportManager() const;
        void setImportManager(ImportManager* value);

        PopulateManager* getPopulateManager() const;
        void setPopulateManager(PopulateManager* value);

        CodeFormatter* getCodeFormatter() const;
        void setCodeFormatter(CodeFormatter* codeFormatter);

        QString getHomePage() const;
        QString getGitHubReleases() const;
        QString getUserManualPage() const;
        QString getSqliteDocsPage() const;
        QString getIssuesPage() const;
        QString getDonatePage() const;
        QString getNewIssuePage() const;

#ifdef PORTABLE_CONFIG
        UpdateManager* getUpdateManager() const;
        void setUpdateManager(UpdateManager* value);
#endif

        bool getImmediateQuit() const;
        void setImmediateQuit(bool value);

        ExtraLicenseManager* getExtraLicenseManager() const;
        void setExtraLicenseManager(ExtraLicenseManager* value);

        QString getCurrentLang() const;

        QStringList getInitialTranslationFiles() const;
        void setInitialTranslationFiles(const QStringList& value);

        void installCrashHandler(CrashHandler handler);

    private:
        /**
         * @brief Creates singleton instance.
         *
         * It doesn't initialize anything, just constructs object.
         * Initialization of member data is done by init() method.
         */
        SQLiteStudio();

        /**
         * @brief Deinitializes object.
         *
         * Calls cleanUp().
         */
        ~SQLiteStudio();

        void setupCrashHandler();

        QList<CrashHandler> crashHandlers;

        /**
         * @brief Code formatter service.
         */
        CodeFormatter* codeFormatter = nullptr;

        /**
         * @brief The application environment.
         *
         * This variable represents environment of the application.
         * It provides access to environment variables.
         */
        QProcessEnvironment* env = nullptr;

        /**
         * @brief List of command line arguments.
         *
         * It's a copy of arguments passed to application in command line.
         */
        QStringList cmdLineArgs;

        bool guiAvailable = false;
        bool immediateQuit = false;
        Config* config = nullptr;
        DbManager* dbManager = nullptr;
        FunctionManager* functionManager = nullptr;
        PluginManager* pluginManager = nullptr;
        DbAttacherFactory* dbAttacherFactory = nullptr;
        CollationManager* collationManager = nullptr;
        SqliteExtensionManager* extensionManager = nullptr;
        ExportManager* exportManager = nullptr;
        ImportManager* importManager = nullptr;
        PopulateManager* populateManager = nullptr;
        CodeSnippetManager* codeSnippetManager = nullptr;
#ifdef PORTABLE_CONFIG
        UpdateManager* updateManager = nullptr;
#endif
        ExtraLicenseManager* extraLicenseManager = nullptr;
        QString currentLang;
        QStringList initialTranslationFiles;
        bool finalCleanupDone = false;

    private slots:
        void pluginLoaded(Plugin* plugin,PluginType* pluginType);
        void pluginToBeUnloaded(Plugin* plugin,PluginType* pluginType);
        void pluginUnloaded(const QString& pluginName,PluginType* pluginType);

    public slots:
        /**
         * @brief Cleans up all internal objects.
         *
         * Deletes all internal objects. It's called from qApp signal or from UI window closing event.
         */
        void cleanUp();

        /**
         * @brief Updates code formatter with available plugins.
         *
         * Calls CodeFormatter's fullUpdate() method to read available formatters.
         * This also reads formatters selected in config.
         */
        void updateCodeFormatter();

        /**
         * @brief Updates code formater with selected plugins.
         *
         * Doesn't change list of available formatters, but reads new selected formatters from config.
         */
        void updateCurrentCodeFormatter();

    signals:
        void aboutToQuit();
};

/**
 * @def SQLITESTUDIO
 * @brief Global entry point for application services.
 *
 * This macro actually calls SQLiteStudio::getInstance(), which returns singleton instance
 * of the main class, which is SQLiteStudio. Use this class as starting point
 * to access all services of the application (database manager, plugins manager, etc).
 * This singleton instance is created at the very begining of application start (in main())
 * and so can be used from pretty much everywhere in the code.
 *
 * Quick example of getting all databases registered in the application, iterating through them and printing
 * their name to standard output:
 * @code
   #include "qio.h"
   #include "sqlitestudio.h"

   void someFunction()
   {
       QList<Db*> dblist = SQLITESTUDIO->getDbManager()->getDbList();
       for (Db* db : dblist)
       {
           qOut << db->getName();
       }
   }
   @endcode
 */
#define SQLITESTUDIO SQLiteStudio::getInstance()

#endif // SQLITESTUDIO_H