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 "private/qobject_p.h" |
29 | #include "private/qlocking_p.h" |
30 | #endif |
31 | |
32 | #ifdef Q_OS_MACOS |
33 | #include "private/qcore_mac_p.h" |
34 | #endif |
35 | |
36 | QT_BEGIN_NAMESPACE |
37 | |
38 | typedef QList<QTranslator*> QTranslatorList; |
39 | |
40 | class QAbstractEventDispatcher; |
41 | |
42 | #ifndef QT_NO_QOBJECT |
43 | class QEvent; |
44 | #endif |
45 | |
46 | class Q_CORE_EXPORT QCoreApplicationPrivate |
47 | #ifndef QT_NO_QOBJECT |
48 | : public QObjectPrivate |
49 | #endif |
50 | { |
51 | Q_DECLARE_PUBLIC(QCoreApplication) |
52 | |
53 | public: |
54 | enum Type { |
55 | Tty, |
56 | Gui |
57 | }; |
58 | |
59 | QCoreApplicationPrivate(int &aargc, char **aargv); |
60 | |
61 | // If not inheriting from QObjectPrivate: force this class to be polymorphic |
62 | #ifdef QT_NO_QOBJECT |
63 | virtual |
64 | #endif |
65 | ~QCoreApplicationPrivate(); |
66 | |
67 | static bool isAlive() noexcept; |
68 | void init(); |
69 | |
70 | QString appName() const; |
71 | QString appVersion() const; |
72 | |
73 | #ifdef Q_OS_DARWIN |
74 | static QString infoDictionaryStringProperty(const QString &propertyName); |
75 | #endif |
76 | |
77 | void initConsole(); |
78 | static void initLocale(); |
79 | |
80 | static bool checkInstance(const char *method); |
81 | |
82 | #if QT_CONFIG(commandlineparser) |
83 | virtual void addQtOptions(QList<QCommandLineOption> *options); |
84 | #endif |
85 | |
86 | #ifndef QT_NO_QOBJECT |
87 | bool sendThroughApplicationEventFilters(QObject *, QEvent *); |
88 | static bool sendThroughObjectEventFilters(QObject *, QEvent *); |
89 | static bool notify_helper(QObject *, QEvent *); |
90 | static inline void setEventSpontaneous(QEvent *e, bool spontaneous) { e->m_spont = spontaneous; } |
91 | |
92 | virtual void createEventDispatcher(); |
93 | virtual void eventDispatcherReady(); |
94 | static void removePostedEvent(QEvent *); |
95 | #ifdef Q_OS_WIN |
96 | static void removePostedTimerEvent(QObject *object, int timerId); |
97 | #endif |
98 | |
99 | QAtomicInt quitLockRef; |
100 | void ref(); |
101 | void deref(); |
102 | virtual bool canQuitAutomatically(); |
103 | void quitAutomatically(); |
104 | virtual void quit(); |
105 | |
106 | static QBasicAtomicPointer<QThread> theMainThread; |
107 | static QBasicAtomicPointer<void> theMainThreadId; |
108 | static QThread *mainThread(); |
109 | static bool threadRequiresCoreApplication(); |
110 | |
111 | static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data); |
112 | |
113 | static void checkReceiverThread(QObject *receiver); |
114 | void cleanupThreadData(); |
115 | |
116 | struct QPostEventListLocker |
117 | { |
118 | QThreadData *threadData; |
119 | std::unique_lock<QMutex> locker; |
120 | |
121 | void unlock() { locker.unlock(); } |
122 | }; |
123 | static QPostEventListLocker lockThreadPostEventList(QObject *object); |
124 | #endif // QT_NO_QOBJECT |
125 | |
126 | int &argc; |
127 | char **argv; |
128 | #if defined(Q_OS_WIN) |
129 | int origArgc; |
130 | char **origArgv; // store unmodified arguments for QCoreApplication::arguments() |
131 | bool consoleAllocated = false; |
132 | #endif |
133 | void appendApplicationPathToLibraryPaths(void); |
134 | |
135 | #ifndef QT_NO_TRANSLATION |
136 | QTranslatorList translators; |
137 | QReadWriteLock translateMutex; |
138 | static bool isTranslatorInstalled(QTranslator *translator); |
139 | #endif |
140 | |
141 | QCoreApplicationPrivate::Type application_type; |
142 | |
143 | QString cachedApplicationDirPath; |
144 | static QString *cachedApplicationFilePath; |
145 | static void setApplicationFilePath(const QString &path); |
146 | static inline void clearApplicationFilePath() { delete cachedApplicationFilePath; cachedApplicationFilePath = nullptr; } |
147 | |
148 | #ifndef QT_NO_QOBJECT |
149 | void execCleanup(); |
150 | |
151 | bool in_exec; |
152 | bool aboutToQuitEmitted; |
153 | bool threadData_clean; |
154 | |
155 | static QAbstractEventDispatcher *eventDispatcher; |
156 | static bool is_app_running; |
157 | static bool is_app_closing; |
158 | #endif |
159 | |
160 | static bool setuidAllowed; |
161 | static uint attribs; |
162 | static inline bool testAttribute(uint flag) { return attribs & (1 << flag); } |
163 | |
164 | void processCommandLineArguments(); |
165 | QString qmljs_debug_arguments; // a string containing arguments for js/qml debugging. |
166 | inline QString qmljsDebugArgumentsString() const { return qmljs_debug_arguments; } |
167 | |
168 | #ifdef QT_NO_QOBJECT |
169 | QCoreApplication *q_ptr; |
170 | #endif |
171 | }; |
172 | |
173 | QT_END_NAMESPACE |
174 | |
175 | #endif // QCOREAPPLICATION_P_H |
176 | |