1 /* 2 Copyright (C) 2014 Aseman 3 http://aseman.co 4 5 This project is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This project 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 19 #ifndef ASEMANAPPLICATION_H 20 #define ASEMANAPPLICATION_H 21 22 #include "aseman_macros.h" 23 24 #include <QFont> 25 #include <QVariant> 26 #include <QCoreApplication> 27 #include <QClipboard> 28 29 #ifdef QT_GUI_LIB 30 #include <QIcon> 31 #endif 32 33 #if defined(QT_WIDGETS_LIB) && defined(DESKTOP_DEVICE) 34 #define DEFAULT_AAPP_TYPE AsemanApplication::WidgetApplication 35 #else 36 #if defined(QT_GUI_LIB) 37 #define DEFAULT_AAPP_TYPE AsemanApplication::GuiApplication 38 #else 39 #if defined(QT_CORE_LIB) 40 #define DEFAULT_AAPP_TYPE AsemanApplication::CoreApplication 41 #endif 42 #endif 43 #endif 44 45 class QSettings; 46 class AsemanApplicationPrivate; 47 class AsemanApplication : public QObject 48 { 49 Q_OBJECT 50 Q_ENUMS(ApplicationType) 51 Q_ENUMS(ApplicationState) 52 53 Q_PROPERTY(QString homePath READ homePath NOTIFY homePathChanged) 54 Q_PROPERTY(QString startPath READ startPath NOTIFY fakeSignal) 55 Q_PROPERTY(QString appPath READ appPath NOTIFY fakeSignal) 56 Q_PROPERTY(QString appFilePath READ appFilePath NOTIFY fakeSignal) 57 Q_PROPERTY(QString logPath READ logPath WRITE setLogPath NOTIFY logPathChanged) 58 Q_PROPERTY(QString confsPath READ confsPath NOTIFY confsPathChanged) 59 Q_PROPERTY(QString tempPath READ tempPath NOTIFY fakeSignal) 60 Q_PROPERTY(QString backupsPath READ backupsPath NOTIFY backupsPathChanged) 61 Q_PROPERTY(QString cameraPath READ cameraPath NOTIFY fakeSignal) 62 63 Q_PROPERTY(int appType READ appType NOTIFY fakeSignal) 64 Q_PROPERTY(bool isDebug READ isDebug NOTIFY fakeSignal) 65 66 Q_PROPERTY(QFont globalFont READ globalFont WRITE setGlobalFont NOTIFY globalFontChanged) 67 68 Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName NOTIFY applicationNameChanged) 69 Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion NOTIFY applicationVersionChanged) 70 Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName NOTIFY organizationNameChanged) 71 Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain NOTIFY organizationDomainChanged) 72 Q_PROPERTY(QString applicationAbout READ applicationAbout WRITE setApplicationAbout NOTIFY applicationAboutChanged) 73 74 Q_PROPERTY(int applicationState READ applicationState NOTIFY applicationStateChanged) 75 76 Q_PROPERTY(QString applicationDisplayName READ applicationDisplayName WRITE setApplicationDisplayName NOTIFY fakeSignal) 77 Q_PROPERTY(QString platformName READ platformName STORED false) 78 Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed) 79 80 public: 81 enum ApplicationType { 82 NoneApplication, 83 #ifdef QT_GUI_LIB 84 GuiApplication, 85 #endif 86 #ifdef QT_CORE_LIB 87 CoreApplication, 88 #endif 89 #ifdef QT_WIDGETS_LIB 90 WidgetApplication 91 #endif 92 }; 93 94 enum ApplicationState { 95 ApplicationSuspended = Qt::ApplicationSuspended, 96 ApplicationHidden = Qt::ApplicationHidden, 97 ApplicationInactive = Qt::ApplicationInactive, 98 ApplicationActive = Qt::ApplicationActive 99 }; 100 101 AsemanApplication(); 102 AsemanApplication(int &argc, char **argv, ApplicationType appType = DEFAULT_AAPP_TYPE); 103 ~AsemanApplication(); 104 105 static QString homePath(); 106 static void setHomePath(const QString &path); 107 108 static QString startPath(); 109 static QString appPath(); 110 static QString appFilePath(); 111 static QString confsPath(); 112 static QString tempPath(); 113 static QString backupsPath(); 114 static QString cameraPath(); 115 116 static QString applicationDirPath(); 117 static QString applicationFilePath(); 118 static qint64 applicationPid(); 119 120 static QString logPath(); 121 static void setLogPath(const QString &path); 122 123 static void setOrganizationDomain(const QString &orgDomain); 124 static QString organizationDomain(); 125 static void setOrganizationName(const QString &orgName); 126 static QString organizationName(); 127 static void setApplicationName(const QString &application); 128 static QString applicationName(); 129 static void setApplicationVersion(const QString &version); 130 static QString applicationVersion(); 131 static void setApplicationDisplayName(const QString &name); 132 static QString applicationDisplayName(); 133 static void setApplicationAbout(const QString &desc); 134 static QString applicationAbout(); 135 136 static QString platformName(); 137 138 static QStringList arguments(); 139 140 static void setQuitOnLastWindowClosed(bool quit); 141 static bool quitOnLastWindowClosed(); 142 143 static QClipboard *clipboard(); 144 145 #ifdef QT_GUI_LIB 146 static void setWindowIcon(const QIcon &icon); 147 static QIcon windowIcon(); 148 #endif 149 150 static bool isRunning(); 151 static int appType(); 152 static bool isDebug(); 153 154 static AsemanApplication *instance(); 155 static QCoreApplication *qapp(); 156 157 void setGlobalFont(const QFont &font); 158 QFont globalFont() const; 159 160 static QFont font(); 161 static void setFont(const QFont &f); 162 163 #ifdef QT_GUI_LIB 164 static QPalette palette(); 165 static void setPalette(const QPalette &pal); 166 167 static int applicationState(); 168 #endif 169 170 static QSettings *settings(); 171 172 inline operator QCoreApplication*() const { return qapp(); } 173 174 public slots: 175 void refreshTranslations(); 176 void back(); 177 int exec(); 178 static void exit(int retcode = 0); 179 180 void sleep(quint64 ms); 181 void sendMessage(const QString &msg); 182 183 void setSetting( const QString & key, const QVariant & value ); 184 QVariant readSetting( const QString & key, const QVariant & defaultValue = QVariant() ); 185 186 signals: 187 void fakeSignal(); 188 void globalFontFamilyChanged(); 189 void globalMonoFontFamilyChanged(); 190 void globalFontChanged(); 191 void languageUpdated(); 192 void backRequest(); 193 void clickedOnDock(); 194 195 void homePathChanged(); 196 void logPathChanged(); 197 void confsPathChanged(); 198 void backupsPathChanged(); 199 200 void organizationNameChanged(); 201 void organizationDomainChanged(); 202 void applicationNameChanged(); 203 void applicationVersionChanged(); 204 void applicationStateChanged(); 205 void applicationAboutChanged(); 206 207 void lastWindowClosed(); 208 void messageReceived(const QString &msg); 209 210 protected: 211 bool eventFilter(QObject *o, QEvent *e); 212 213 private: 214 void init(); 215 216 private: 217 AsemanApplicationPrivate *p; 218 }; 219 220 #endif // ASEMANAPPLICATION_H 221