1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 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_P_H 41 #define QCOREAPPLICATION_P_H 42 43 // 44 // W A R N I N G 45 // ------------- 46 // 47 // This file is not part of the Qt API. It exists purely as an 48 // implementation detail. This header file may change from version to 49 // version without notice, or even be removed. 50 // 51 // We mean it. 52 // 53 54 #include "QtCore/qcoreapplication.h" 55 #if QT_CONFIG(commandlineparser) 56 #include "QtCore/qcommandlineoption.h" 57 #endif 58 #include "QtCore/qtranslator.h" 59 #if QT_CONFIG(settings) 60 #include "QtCore/qsettings.h" 61 #endif 62 #ifndef QT_NO_QOBJECT 63 #include "private/qobject_p.h" 64 #include "private/qlocking_p.h" 65 #endif 66 67 #ifdef Q_OS_MACOS 68 #include "private/qcore_mac_p.h" 69 #endif 70 71 QT_BEGIN_NAMESPACE 72 73 typedef QList<QTranslator*> QTranslatorList; 74 75 class QAbstractEventDispatcher; 76 77 class Q_CORE_EXPORT QCoreApplicationPrivate 78 #ifndef QT_NO_QOBJECT 79 : public QObjectPrivate 80 #endif 81 { 82 Q_DECLARE_PUBLIC(QCoreApplication) 83 84 public: 85 enum Type { 86 Tty, 87 Gui 88 }; 89 90 QCoreApplicationPrivate(int &aargc, char **aargv, uint flags); 91 92 // If not inheriting from QObjectPrivate: force this class to be polymorphic 93 #ifdef QT_NO_QOBJECT 94 virtual 95 #endif 96 ~QCoreApplicationPrivate(); 97 98 void init(); 99 100 QString appName() const; 101 QString appVersion() const; 102 103 #ifdef Q_OS_DARWIN 104 static QString infoDictionaryStringProperty(const QString &propertyName); 105 #endif 106 107 static void initLocale(); 108 109 static bool checkInstance(const char *method); 110 111 #if QT_CONFIG(commandlineparser) 112 virtual void addQtOptions(QList<QCommandLineOption> *options); 113 #endif 114 115 #ifndef QT_NO_QOBJECT 116 bool sendThroughApplicationEventFilters(QObject *, QEvent *); 117 static bool sendThroughObjectEventFilters(QObject *, QEvent *); 118 static bool notify_helper(QObject *, QEvent *); setEventSpontaneous(QEvent * e,bool spontaneous)119 static inline void setEventSpontaneous(QEvent *e, bool spontaneous) { e->spont = spontaneous; } 120 121 virtual void createEventDispatcher(); 122 virtual void eventDispatcherReady(); 123 static void removePostedEvent(QEvent *); 124 #ifdef Q_OS_WIN 125 static void removePostedTimerEvent(QObject *object, int timerId); 126 #endif 127 128 QAtomicInt quitLockRef; 129 void ref(); 130 void deref(); shouldQuit()131 virtual bool shouldQuit() { 132 return true; 133 } 134 void maybeQuit(); 135 136 static QBasicAtomicPointer<QThread> theMainThread; 137 static QThread *mainThread(); 138 static bool threadRequiresCoreApplication(); 139 140 static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data); 141 142 static void checkReceiverThread(QObject *receiver); 143 void cleanupThreadData(); 144 145 struct QPostEventListLocker 146 { 147 QThreadData *threadData; 148 std::unique_lock<QMutex> locker; 149 unlockQPostEventListLocker150 void unlock() { locker.unlock(); } 151 }; 152 static QPostEventListLocker lockThreadPostEventList(QObject *object); 153 #endif // QT_NO_QOBJECT 154 155 int &argc; 156 char **argv; 157 #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) 158 int origArgc; 159 char **origArgv; // store unmodified arguments for QCoreApplication::arguments() 160 #endif 161 void appendApplicationPathToLibraryPaths(void); 162 163 #ifndef QT_NO_TRANSLATION 164 QTranslatorList translators; 165 QReadWriteLock translateMutex; 166 static bool isTranslatorInstalled(QTranslator *translator); 167 #endif 168 169 QCoreApplicationPrivate::Type application_type; 170 171 QString cachedApplicationDirPath; 172 static QString *cachedApplicationFilePath; 173 static void setApplicationFilePath(const QString &path); clearApplicationFilePath()174 static inline void clearApplicationFilePath() { delete cachedApplicationFilePath; cachedApplicationFilePath = nullptr; } 175 176 #ifndef QT_NO_QOBJECT 177 void execCleanup(); 178 179 bool in_exec; 180 bool aboutToQuitEmitted; 181 bool threadData_clean; 182 183 static QAbstractEventDispatcher *eventDispatcher; 184 static bool is_app_running; 185 static bool is_app_closing; 186 #endif 187 188 static bool setuidAllowed; 189 static uint attribs; testAttribute(uint flag)190 static inline bool testAttribute(uint flag) { return attribs & (1 << flag); } 191 static int app_compile_version; 192 193 void processCommandLineArguments(); 194 QString qmljs_debug_arguments; // a string containing arguments for js/qml debugging. qmljsDebugArgumentsString()195 inline QString qmljsDebugArgumentsString() { return qmljs_debug_arguments; } 196 197 #ifdef QT_NO_QOBJECT 198 QCoreApplication *q_ptr; 199 #endif 200 }; 201 202 QT_END_NAMESPACE 203 204 #endif // QCOREAPPLICATION_P_H 205