1 #ifndef SQLITESTUDIO_H 2 #define SQLITESTUDIO_H 3 4 #include "coreSQLiteStudio_global.h" 5 #include "common/global.h" 6 #include "services/config.h" 7 #include <QString> 8 #include <QStringList> 9 #include <QObject> 10 11 class DbManager; 12 class Config; 13 class QProcessEnvironment; 14 class PluginManager; 15 class QThreadPool; 16 class NotifyManager; 17 class CodeFormatter; 18 class Plugin; 19 class PluginType; 20 class FunctionManager; 21 class DbAttacherFactory; 22 class DbAttacher; 23 class ExportManager; 24 class ImportManager; 25 class PopulateManager; 26 class PluginLoadingHandler; 27 #ifdef PORTABLE_CONFIG 28 class UpdateManager; 29 #endif 30 class ExtraLicenseManager; 31 class SqliteExtensionManager; 32 33 /** @file */ 34 35 /** 36 * @mainpage 37 * SQLiteStudio is SQLite 3 manager for Windows, MacOS X and Linux. 38 * 39 * Global variables and macros: 40 * <ul> 41 * <li>#SQLITESTUDIO - access point to all services (singleton instance of SQLiteStudio)</li> 42 * <li>#PLUGINS - quick access to PluginManager</li> 43 * <li>#DBLIST - quick access to DbManager</li> 44 * <li>#FUNCTIONS - quick access to FunctionManager</li> 45 * <li>#CFG - quick access to Config</li> 46 * </ul> 47 */ 48 49 50 /** 51 * @brief Main application class. 52 * This is an entry point for all services. 53 * Get all managers, services, etc from this class. 54 * It is a singleton. 55 */ 56 class API_EXPORT SQLiteStudio : public QObject 57 { 58 Q_OBJECT 59 60 DECLARE_SINGLETON(SQLiteStudio) 61 62 public: 63 /** 64 * @brief Initializes SQLiteStudio object. 65 * @param cmdListArguments Command line arguments. 66 * @param pluginLoadingHandler Factory for producing plugin loader. 67 * 68 * Initialization process involves creating of all internal objects (managers, etc.) 69 * and reading necessary configuration. It also interpreted command line arguments 70 * and applies them. 71 * 72 * The plugin loader factory (handler) is used to solve issue with GUI symbols visibility. while loading code being placed in the core shared library. 73 * It should be null when starting SQLiteStudio in CLI mode and not null when starting GUI client. See PluginLoadingHandler for more details on that. 74 * 75 * See parseCmdLineArgs() for details on supported options. 76 */ 77 void init(const QStringList& cmdListArguments, bool guiAvailable); 78 79 void initPlugins(); 80 81 /** 82 * @brief Gets environment variable value. 83 * @param name Name of the environment variable. 84 * @param defaultValue Default value to be returned if the environment variable is not defined. 85 * @return Either value of the environment variable - if defined - or the value passed as defaultValue. 86 * 87 * This method provides cross-platform way to get environment variable value. 88 * Internally it uses QProcessEnvironment, but while it's expensive to initialize it every time you access environment, 89 * it keeps the single instance of that object and lets you query variables by name. 90 */ 91 QString getEnv(const QString& name, const QString& defaultValue = QString()); 92 93 /** 94 * @brief Creates new DbAttacher instance for given database. 95 * @param db Database to create attacher for. 96 * @return Attacher instance. 97 */ 98 DbAttacher* createDbAttacher(Db* db); 99 100 bool isGuiAvailable() const; 101 102 Config* getConfig() const; 103 void setConfig(Config* value); 104 105 DbManager* getDbManager() const; 106 void setDbManager(DbManager* value); 107 108 FunctionManager* getFunctionManager() const; 109 void setFunctionManager(FunctionManager* value); 110 111 PluginManager* getPluginManager() const; 112 void setPluginManager(PluginManager* value); 113 114 DbAttacherFactory* getDbAttacherFactory() const; 115 void setDbAttacherFactory(DbAttacherFactory* value); 116 117 CollationManager* getCollationManager() const; 118 void setCollationManager(CollationManager* value); 119 120 SqliteExtensionManager* getSqliteExtensionManager() const; 121 void setSqliteExtensionManager(SqliteExtensionManager* value); 122 123 ExportManager* getExportManager() const; 124 void setExportManager(ExportManager* value); 125 126 int getVersion() const; 127 QString getVersionString() const; 128 129 ImportManager* getImportManager() const; 130 void setImportManager(ImportManager* value); 131 132 PopulateManager* getPopulateManager() const; 133 void setPopulateManager(PopulateManager* value); 134 135 CodeFormatter* getCodeFormatter() const; 136 void setCodeFormatter(CodeFormatter* codeFormatter); 137 138 QString getHomePage() const; 139 QString getGitHubReleases() const; 140 QString getUserManualPage() const; 141 QString getSqliteDocsPage() const; 142 QString getIssuesPage() const; 143 QString getDonatePage() const; 144 QString getNewIssuePage() const; 145 146 #ifdef PORTABLE_CONFIG 147 UpdateManager* getUpdateManager() const; 148 void setUpdateManager(UpdateManager* value); 149 #endif 150 151 bool getImmediateQuit() const; 152 void setImmediateQuit(bool value); 153 154 ExtraLicenseManager* getExtraLicenseManager() const; 155 void setExtraLicenseManager(ExtraLicenseManager* value); 156 157 QString getCurrentLang() const; 158 159 QStringList getInitialTranslationFiles() const; 160 void setInitialTranslationFiles(const QStringList& value); 161 162 private: 163 /** 164 * @brief Creates singleton instance. 165 * 166 * It doesn't initialize anything, just constructs object. 167 * Initialization of member data is done by init() method. 168 */ 169 SQLiteStudio(); 170 171 /** 172 * @brief Deinitializes object. 173 * 174 * Calls cleanUp(). 175 */ 176 ~SQLiteStudio(); 177 178 /** 179 * @brief Code formatter service. 180 */ 181 CodeFormatter* codeFormatter = nullptr; 182 183 /** 184 * @brief The application environment. 185 * 186 * This variable represents environment of the application. 187 * It provides access to environment variables. 188 */ 189 QProcessEnvironment* env = nullptr; 190 191 /** 192 * @brief List of command line arguments. 193 * 194 * It's a copy of arguments passed to application in command line. 195 */ 196 QStringList cmdLineArgs; 197 198 bool guiAvailable = false; 199 bool immediateQuit = false; 200 Config* config = nullptr; 201 DbManager* dbManager = nullptr; 202 FunctionManager* functionManager = nullptr; 203 PluginManager* pluginManager = nullptr; 204 DbAttacherFactory* dbAttacherFactory = nullptr; 205 CollationManager* collationManager = nullptr; 206 SqliteExtensionManager* extensionManager = nullptr; 207 ExportManager* exportManager = nullptr; 208 ImportManager* importManager = nullptr; 209 PopulateManager* populateManager = nullptr; 210 #ifdef PORTABLE_CONFIG 211 UpdateManager* updateManager = nullptr; 212 #endif 213 ExtraLicenseManager* extraLicenseManager = nullptr; 214 QString currentLang; 215 QStringList initialTranslationFiles; 216 217 private slots: 218 void pluginLoaded(Plugin* plugin,PluginType* pluginType); 219 void pluginToBeUnloaded(Plugin* plugin,PluginType* pluginType); 220 void pluginUnloaded(const QString& pluginName,PluginType* pluginType); 221 222 /** 223 * @brief Cleans up all internal objects. 224 * 225 * Deletes all internal objects. It's called from destructor. 226 */ 227 void cleanUp(); 228 229 public slots: 230 /** 231 * @brief Updates code formatter with available plugins. 232 * 233 * Calls CodeFormatter's fullUpdate() method to read available formatters. 234 * This also reads formatters selected in config. 235 */ 236 void updateCodeFormatter(); 237 238 /** 239 * @brief Updates code formater with selected plugins. 240 * 241 * Doesn't change list of available formatters, but reads new selected formatters from config. 242 */ 243 void updateCurrentCodeFormatter(); 244 245 signals: 246 void aboutToQuit(); 247 }; 248 249 /** 250 * @def SQLITESTUDIO 251 * @brief Global entry point for application services. 252 * 253 * This macro actually calls SQLiteStudio::getInstance(), which returns singleton instance 254 * of the main class, which is SQLiteStudio. Use this class as starting point 255 * to access all services of the application (database manager, plugins manager, etc). 256 * This singleton instance is created at the very begining of application start (in main()) 257 * and so can be used from pretty much everywhere in the code. 258 * 259 * Quick example of getting all databases registered in the application, iterating through them and printing 260 * their name to standard output: 261 * @code 262 #include "qio.h" 263 #include "sqlitestudio.h" 264 265 void someFunction() 266 { 267 QList<Db*> dblist = SQLITESTUDIO->getDbManager()->getDbList(); 268 for (Db* db : dblist) 269 { 270 qOut << db->getName(); 271 } 272 } 273 @endcode 274 */ 275 #define SQLITESTUDIO SQLiteStudio::getInstance() 276 277 #endif // SQLITESTUDIO_H 278