1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QCOREAPPLICATION_P_H |
5 | #define QCOREAPPLICATION_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "QtCore/qcoreapplication.h" |
19 | #if QT_CONFIG(commandlineparser) |
20 | #include "QtCore/qcommandlineoption.h" |
21 | #endif |
22 | #include "QtCore/qreadwritelock.h" |
23 | #include "QtCore/qtranslator.h" |
24 | #if QT_CONFIG(settings) |
25 | #include "QtCore/qsettings.h" |
26 | #endif |
27 | #ifndef QT_NO_QOBJECT |
28 | #include <qloggingcategory.h> |
29 | #include "private/qobject_p.h" |
30 | #include "private/qlocking_p.h" |
31 | #endif |
32 | |
33 | #ifdef Q_OS_MACOS |
34 | #include "private/qcore_mac_p.h" |
35 | #endif |
36 | |
37 | QT_BEGIN_NAMESPACE |
38 | |
39 | #ifndef QT_NO_QOBJECT |
40 | Q_DECLARE_LOGGING_CATEGORY(lcDeleteLater) |
41 | #endif |
42 | |
43 | typedef QList<QTranslator*> QTranslatorList; |
44 | |
45 | class QAbstractEventDispatcher; |
46 | |
47 | #ifndef QT_NO_QOBJECT |
48 | class QEvent; |
49 | #endif |
50 | |
51 | class Q_CORE_EXPORT QCoreApplicationPrivate |
52 | #ifndef QT_NO_QOBJECT |
53 | : public QObjectPrivate |
54 | #endif |
55 | { |
56 | Q_DECLARE_PUBLIC(QCoreApplication) |
57 | |
58 | public: |
59 | enum Type { |
60 | Tty, |
61 | Gui |
62 | }; |
63 | |
64 | QCoreApplicationPrivate(int &aargc, char **aargv); |
65 | |
66 | // If not inheriting from QObjectPrivate: force this class to be polymorphic |
67 | #ifdef QT_NO_QOBJECT |
68 | virtual |
69 | #endif |
70 | ~QCoreApplicationPrivate(); |
71 | |
72 | void init(); |
73 | |
74 | QString appName() const; |
75 | QString appVersion() const; |
76 | |
77 | #ifdef Q_OS_DARWIN |
78 | static QString infoDictionaryStringProperty(const QString &propertyName); |
79 | #endif |
80 | |
81 | void initConsole(); |
82 | static void initLocale(); |
83 | |
84 | static bool checkInstance(const char *method); |
85 | |
86 | #if QT_CONFIG(commandlineparser) |
87 | virtual void addQtOptions(QList<QCommandLineOption> *options); |
88 | #endif |
89 | |
90 | #ifndef QT_NO_QOBJECT |
91 | bool sendThroughApplicationEventFilters(QObject *, QEvent *); |
92 | static bool sendThroughObjectEventFilters(QObject *, QEvent *); |
93 | static bool notify_helper(QObject *, QEvent *); |
94 | static inline void setEventSpontaneous(QEvent *e, bool spontaneous) { e->m_spont = spontaneous; } |
95 | |
96 | virtual void createEventDispatcher(); |
97 | virtual void eventDispatcherReady(); |
98 | static void removePostedEvent(QEvent *); |
99 | #ifdef Q_OS_WIN |
100 | static void removePostedTimerEvent(QObject *object, int timerId); |
101 | #endif |
102 | |
103 | QAtomicInt quitLockRef; |
104 | void ref(); |
105 | void deref(); |
106 | virtual bool canQuitAutomatically(); |
107 | void quitAutomatically(); |
108 | virtual void quit(); |
109 | |
110 | static QBasicAtomicPointer<QThread> theMainThread; |
111 | static QBasicAtomicPointer<void> theMainThreadId; |
112 | static QThread *mainThread(); |
113 | static bool threadRequiresCoreApplication(); |
114 | |
115 | static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data); |
116 | |
117 | static void checkReceiverThread(QObject *receiver); |
118 | void cleanupThreadData(); |
119 | |
120 | struct QPostEventListLocker |
121 | { |
122 | QThreadData *threadData; |
123 | std::unique_lock<QMutex> locker; |
124 | |
125 | void unlock() { locker.unlock(); } |
126 | }; |
127 | static QPostEventListLocker lockThreadPostEventList(QObject *object); |
128 | #endif // QT_NO_QOBJECT |
129 | |
130 | int &argc; |
131 | char **argv; |
132 | #if defined(Q_OS_WIN) |
133 | int origArgc; |
134 | char **origArgv; // store unmodified arguments for QCoreApplication::arguments() |
135 | bool consoleAllocated = false; |
136 | #endif |
137 | void appendApplicationPathToLibraryPaths(void); |
138 | |
139 | #ifndef QT_NO_TRANSLATION |
140 | QTranslatorList translators; |
141 | QReadWriteLock translateMutex; |
142 | static bool isTranslatorInstalled(QTranslator *translator); |
143 | #endif |
144 | |
145 | QCoreApplicationPrivate::Type application_type; |
146 | |
147 | QString cachedApplicationDirPath; |
148 | static QString *cachedApplicationFilePath; |
149 | static void setApplicationFilePath(const QString &path); |
150 | static inline void clearApplicationFilePath() { delete cachedApplicationFilePath; cachedApplicationFilePath = nullptr; } |
151 | |
152 | #ifndef QT_NO_QOBJECT |
153 | void execCleanup(); |
154 | |
155 | bool in_exec; |
156 | bool aboutToQuitEmitted; |
157 | bool threadData_clean; |
158 | |
159 | static QAbstractEventDispatcher *eventDispatcher; |
160 | static bool is_app_running; |
161 | static bool is_app_closing; |
162 | #endif |
163 | |
164 | static bool setuidAllowed; |
165 | static uint attribs; |
166 | static inline bool testAttribute(uint flag) { return attribs & (1 << flag); } |
167 | |
168 | void processCommandLineArguments(); |
169 | QString qmljs_debug_arguments; // a string containing arguments for js/qml debugging. |
170 | inline QString qmljsDebugArgumentsString() const { return qmljs_debug_arguments; } |
171 | |
172 | #ifdef QT_NO_QOBJECT |
173 | QCoreApplication *q_ptr; |
174 | #endif |
175 | }; |
176 | |
177 | QT_END_NAMESPACE |
178 | |
179 | #endif // QCOREAPPLICATION_P_H |
180 | |