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 | void init(); |
68 | |
69 | QString appName() const; |
70 | QString appVersion() const; |
71 | |
72 | #ifdef Q_OS_DARWIN |
73 | static QString infoDictionaryStringProperty(const QString &propertyName); |
74 | #endif |
75 | |
76 | void initConsole(); |
77 | static void initLocale(); |
78 | |
79 | static bool checkInstance(const char *method); |
80 | |
81 | #if QT_CONFIG(commandlineparser) |
82 | virtual void addQtOptions(QList<QCommandLineOption> *options); |
83 | #endif |
84 | |
85 | #ifndef QT_NO_QOBJECT |
86 | bool sendThroughApplicationEventFilters(QObject *, QEvent *); |
87 | static bool sendThroughObjectEventFilters(QObject *, QEvent *); |
88 | static bool notify_helper(QObject *, QEvent *); |
89 | static inline void setEventSpontaneous(QEvent *e, bool spontaneous) { e->m_spont = spontaneous; } |
90 | |
91 | virtual void createEventDispatcher(); |
92 | virtual void eventDispatcherReady(); |
93 | static void removePostedEvent(QEvent *); |
94 | #ifdef Q_OS_WIN |
95 | static void removePostedTimerEvent(QObject *object, int timerId); |
96 | #endif |
97 | |
98 | QAtomicInt quitLockRef; |
99 | void ref(); |
100 | void deref(); |
101 | virtual bool canQuitAutomatically(); |
102 | void quitAutomatically(); |
103 | virtual void quit(); |
104 | |
105 | static QBasicAtomicPointer<QThread> theMainThread; |
106 | static QThread *mainThread(); |
107 | static bool threadRequiresCoreApplication(); |
108 | |
109 | static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data); |
110 | |
111 | static void checkReceiverThread(QObject *receiver); |
112 | void cleanupThreadData(); |
113 | |
114 | struct QPostEventListLocker |
115 | { |
116 | QThreadData *threadData; |
117 | std::unique_lock<QMutex> locker; |
118 | |
119 | void unlock() { locker.unlock(); } |
120 | }; |
121 | static QPostEventListLocker lockThreadPostEventList(QObject *object); |
122 | #endif // QT_NO_QOBJECT |
123 | |
124 | int &argc; |
125 | char **argv; |
126 | #if defined(Q_OS_WIN) |
127 | int origArgc; |
128 | char **origArgv; // store unmodified arguments for QCoreApplication::arguments() |
129 | bool consoleAllocated = false; |
130 | #endif |
131 | void appendApplicationPathToLibraryPaths(void); |
132 | |
133 | #ifndef QT_NO_TRANSLATION |
134 | QTranslatorList translators; |
135 | QReadWriteLock translateMutex; |
136 | static bool isTranslatorInstalled(QTranslator *translator); |
137 | #endif |
138 | |
139 | QCoreApplicationPrivate::Type application_type; |
140 | |
141 | QString cachedApplicationDirPath; |
142 | static QString *cachedApplicationFilePath; |
143 | static void setApplicationFilePath(const QString &path); |
144 | static inline void clearApplicationFilePath() { delete cachedApplicationFilePath; cachedApplicationFilePath = nullptr; } |
145 | |
146 | #ifndef QT_NO_QOBJECT |
147 | void execCleanup(); |
148 | |
149 | bool in_exec; |
150 | bool aboutToQuitEmitted; |
151 | bool threadData_clean; |
152 | |
153 | static QAbstractEventDispatcher *eventDispatcher; |
154 | static bool is_app_running; |
155 | static bool is_app_closing; |
156 | #endif |
157 | |
158 | static bool setuidAllowed; |
159 | static uint attribs; |
160 | static inline bool testAttribute(uint flag) { return attribs & (1 << flag); } |
161 | |
162 | void processCommandLineArguments(); |
163 | QString qmljs_debug_arguments; // a string containing arguments for js/qml debugging. |
164 | inline QString qmljsDebugArgumentsString() const { return qmljs_debug_arguments; } |
165 | |
166 | #ifdef QT_NO_QOBJECT |
167 | QCoreApplication *q_ptr; |
168 | #endif |
169 | }; |
170 | |
171 | QT_END_NAMESPACE |
172 | |
173 | #endif // QCOREAPPLICATION_P_H |
174 | |