| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2020 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef QCOREAPPLICATION_H |
| 41 | #define QCOREAPPLICATION_H |
| 42 | |
| 43 | #include <QtCore/qglobal.h> |
| 44 | #include <QtCore/qstring.h> |
| 45 | #ifndef QT_NO_QOBJECT |
| 46 | #include <QtCore/qobject.h> |
| 47 | #include <QtCore/qcoreevent.h> |
| 48 | #include <QtCore/qeventloop.h> |
| 49 | #else |
| 50 | #include <QtCore/qscopedpointer.h> |
| 51 | #endif |
| 52 | #ifndef QT_NO_DEBUGSTREAM |
| 53 | #include <QtCore/qdebug.h> |
| 54 | #endif |
| 55 | |
| 56 | #ifndef QT_NO_QOBJECT |
| 57 | #if defined(Q_OS_WIN) && !defined(tagMSG) |
| 58 | typedef struct tagMSG MSG; |
| 59 | #endif |
| 60 | #endif |
| 61 | |
| 62 | QT_BEGIN_NAMESPACE |
| 63 | |
| 64 | |
| 65 | class QCoreApplicationPrivate; |
| 66 | class QTranslator; |
| 67 | class QPostEventList; |
| 68 | class QAbstractEventDispatcher; |
| 69 | class QAbstractNativeEventFilter; |
| 70 | |
| 71 | #define qApp QCoreApplication::instance() |
| 72 | |
| 73 | class Q_CORE_EXPORT QCoreApplication |
| 74 | #ifndef QT_NO_QOBJECT |
| 75 | : public QObject |
| 76 | #endif |
| 77 | { |
| 78 | #ifndef QT_NO_QOBJECT |
| 79 | Q_OBJECT |
| 80 | Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName NOTIFY applicationNameChanged) |
| 81 | Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion NOTIFY applicationVersionChanged) |
| 82 | Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName NOTIFY organizationNameChanged) |
| 83 | Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain NOTIFY organizationDomainChanged) |
| 84 | Q_PROPERTY(bool quitLockEnabled READ isQuitLockEnabled WRITE setQuitLockEnabled) |
| 85 | #endif |
| 86 | |
| 87 | Q_DECLARE_PRIVATE(QCoreApplication) |
| 88 | public: |
| 89 | enum { ApplicationFlags = QT_VERSION |
| 90 | }; |
| 91 | |
| 92 | QCoreApplication(int &argc, char **argv |
| 93 | #ifndef Q_QDOC |
| 94 | , int = ApplicationFlags |
| 95 | #endif |
| 96 | ); |
| 97 | |
| 98 | ~QCoreApplication(); |
| 99 | |
| 100 | static QStringList arguments(); |
| 101 | |
| 102 | static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true); |
| 103 | static bool testAttribute(Qt::ApplicationAttribute attribute); |
| 104 | |
| 105 | static void setOrganizationDomain(const QString &orgDomain); |
| 106 | static QString organizationDomain(); |
| 107 | static void setOrganizationName(const QString &orgName); |
| 108 | static QString organizationName(); |
| 109 | static void setApplicationName(const QString &application); |
| 110 | static QString applicationName(); |
| 111 | static void setApplicationVersion(const QString &version); |
| 112 | static QString applicationVersion(); |
| 113 | |
| 114 | static void setSetuidAllowed(bool allow); |
| 115 | static bool isSetuidAllowed(); |
| 116 | |
| 117 | static QCoreApplication *instance() { return self; } |
| 118 | |
| 119 | #ifndef QT_NO_QOBJECT |
| 120 | static int exec(); |
| 121 | static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); |
| 122 | static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime); |
| 123 | static void exit(int retcode = 0); |
| 124 | |
| 125 | static bool sendEvent(QObject *receiver, QEvent *event); |
| 126 | static void postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority); |
| 127 | static void sendPostedEvents(QObject *receiver = nullptr, int event_type = 0); |
| 128 | static void removePostedEvents(QObject *receiver, int eventType = 0); |
| 129 | static QAbstractEventDispatcher *eventDispatcher(); |
| 130 | static void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher); |
| 131 | |
| 132 | virtual bool notify(QObject *, QEvent *); |
| 133 | |
| 134 | static bool startingUp(); |
| 135 | static bool closingDown(); |
| 136 | #endif |
| 137 | |
| 138 | static QString applicationDirPath(); |
| 139 | static QString applicationFilePath(); |
| 140 | static qint64 applicationPid() Q_DECL_CONST_FUNCTION; |
| 141 | |
| 142 | #if QT_CONFIG(library) |
| 143 | static void setLibraryPaths(const QStringList &); |
| 144 | static QStringList libraryPaths(); |
| 145 | static void addLibraryPath(const QString &); |
| 146 | static void removeLibraryPath(const QString &); |
| 147 | #endif // QT_CONFIG(library) |
| 148 | |
| 149 | #ifndef QT_NO_TRANSLATION |
| 150 | static bool installTranslator(QTranslator * messageFile); |
| 151 | static bool removeTranslator(QTranslator * messageFile); |
| 152 | #endif |
| 153 | |
| 154 | static QString translate(const char * context, |
| 155 | const char * key, |
| 156 | const char * disambiguation = nullptr, |
| 157 | int n = -1); |
| 158 | |
| 159 | #ifndef QT_NO_QOBJECT |
| 160 | void installNativeEventFilter(QAbstractNativeEventFilter *filterObj); |
| 161 | void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj); |
| 162 | |
| 163 | static bool isQuitLockEnabled(); |
| 164 | static void setQuitLockEnabled(bool enabled); |
| 165 | |
| 166 | public Q_SLOTS: |
| 167 | static void quit(); |
| 168 | |
| 169 | Q_SIGNALS: |
| 170 | void aboutToQuit(QPrivateSignal); |
| 171 | |
| 172 | void organizationNameChanged(); |
| 173 | void organizationDomainChanged(); |
| 174 | void applicationNameChanged(); |
| 175 | void applicationVersionChanged(); |
| 176 | |
| 177 | protected: |
| 178 | bool event(QEvent *) override; |
| 179 | |
| 180 | virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *); |
| 181 | #endif // QT_NO_QOBJECT |
| 182 | |
| 183 | protected: |
| 184 | QCoreApplication(QCoreApplicationPrivate &p); |
| 185 | |
| 186 | #ifdef QT_NO_QOBJECT |
| 187 | QScopedPointer<QCoreApplicationPrivate> d_ptr; |
| 188 | #endif |
| 189 | |
| 190 | private: |
| 191 | #ifndef QT_NO_QOBJECT |
| 192 | static bool sendSpontaneousEvent(QObject *receiver, QEvent *event); |
| 193 | static bool notifyInternal2(QObject *receiver, QEvent *); |
| 194 | static bool forwardEvent(QObject *receiver, QEvent *event, QEvent *originatingEvent = nullptr); |
| 195 | #endif |
| 196 | #if QT_CONFIG(library) |
| 197 | static QStringList libraryPathsLocked(); |
| 198 | #endif |
| 199 | |
| 200 | static QCoreApplication *self; |
| 201 | |
| 202 | Q_DISABLE_COPY(QCoreApplication) |
| 203 | |
| 204 | friend class QApplication; |
| 205 | friend class QApplicationPrivate; |
| 206 | friend class QGuiApplication; |
| 207 | friend class QGuiApplicationPrivate; |
| 208 | friend class QWidget; |
| 209 | friend class QWidgetWindow; |
| 210 | friend class QWidgetPrivate; |
| 211 | #ifndef QT_NO_QOBJECT |
| 212 | friend class QEventDispatcherUNIXPrivate; |
| 213 | friend class QCocoaEventDispatcherPrivate; |
| 214 | friend bool qt_sendSpontaneousEvent(QObject *, QEvent *); |
| 215 | #endif |
| 216 | friend Q_CORE_EXPORT QString qAppName(); |
| 217 | friend class QClassFactory; |
| 218 | friend class QCommandLineParserPrivate; |
| 219 | }; |
| 220 | |
| 221 | #define Q_DECLARE_TR_FUNCTIONS(context) \ |
| 222 | public: \ |
| 223 | static inline QString tr(const char *sourceText, const char *disambiguation = nullptr, int n = -1) \ |
| 224 | { return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \ |
| 225 | private: |
| 226 | |
| 227 | typedef void (*QtStartUpFunction)(); |
| 228 | typedef void (*QtCleanUpFunction)(); |
| 229 | |
| 230 | Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction); |
| 231 | Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction); |
| 232 | Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction); |
| 233 | Q_CORE_EXPORT QString qAppName(); // get application name |
| 234 | |
| 235 | #define Q_COREAPP_STARTUP_FUNCTION(AFUNC) \ |
| 236 | static void AFUNC ## _ctor_function() { \ |
| 237 | qAddPreRoutine(AFUNC); \ |
| 238 | } \ |
| 239 | Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function) |
| 240 | |
| 241 | #ifndef QT_NO_QOBJECT |
| 242 | #if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM) |
| 243 | Q_CORE_EXPORT QString decodeMSG(const MSG &); |
| 244 | Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &); |
| 245 | #endif |
| 246 | #endif |
| 247 | |
| 248 | QT_END_NAMESPACE |
| 249 | |
| 250 | #endif // QCOREAPPLICATION_H |
| 251 | |