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
71QT_BEGIN_NAMESPACE
72
73typedef QList<QTranslator*> QTranslatorList;
74
75class QAbstractEventDispatcher;
76
77#ifndef QT_NO_QOBJECT
78class QEvent;
79#endif
80
81class Q_CORE_EXPORT QCoreApplicationPrivate
82#ifndef QT_NO_QOBJECT
83 : public QObjectPrivate
84#endif
85{
86 Q_DECLARE_PUBLIC(QCoreApplication)
87
88public:
89 enum Type {
90 Tty,
91 Gui
92 };
93
94 QCoreApplicationPrivate(int &aargc, char **aargv, uint flags);
95
96 // If not inheriting from QObjectPrivate: force this class to be polymorphic
97#ifdef QT_NO_QOBJECT
98 virtual
99#endif
100 ~QCoreApplicationPrivate();
101
102 void init();
103
104 QString appName() const;
105 QString appVersion() const;
106
107#ifdef Q_OS_DARWIN
108 static QString infoDictionaryStringProperty(const QString &propertyName);
109#endif
110
111 static void initLocale();
112
113 static bool checkInstance(const char *method);
114
115#if QT_CONFIG(commandlineparser)
116 virtual void addQtOptions(QList<QCommandLineOption> *options);
117#endif
118
119#ifndef QT_NO_QOBJECT
120 bool sendThroughApplicationEventFilters(QObject *, QEvent *);
121 static bool sendThroughObjectEventFilters(QObject *, QEvent *);
122 static bool notify_helper(QObject *, QEvent *);
123 static inline void setEventSpontaneous(QEvent *e, bool spontaneous) { e->spont = spontaneous; }
124
125 virtual void createEventDispatcher();
126 virtual void eventDispatcherReady();
127 static void removePostedEvent(QEvent *);
128#ifdef Q_OS_WIN
129 static void removePostedTimerEvent(QObject *object, int timerId);
130#endif
131
132 QAtomicInt quitLockRef;
133 void ref();
134 void deref();
135 virtual bool shouldQuit() {
136 return true;
137 }
138
139 virtual void quit();
140 void maybeQuit();
141
142 static QBasicAtomicPointer<QThread> theMainThread;
143 static QThread *mainThread();
144 static bool threadRequiresCoreApplication();
145
146 static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data);
147
148 static void checkReceiverThread(QObject *receiver);
149 void cleanupThreadData();
150
151 struct QPostEventListLocker
152 {
153 QThreadData *threadData;
154 std::unique_lock<QMutex> locker;
155
156 void unlock() { locker.unlock(); }
157 };
158 static QPostEventListLocker lockThreadPostEventList(QObject *object);
159#endif // QT_NO_QOBJECT
160
161 int &argc;
162 char **argv;
163#if defined(Q_OS_WIN)
164 int origArgc;
165 char **origArgv; // store unmodified arguments for QCoreApplication::arguments()
166#endif
167 void appendApplicationPathToLibraryPaths(void);
168
169#ifndef QT_NO_TRANSLATION
170 QTranslatorList translators;
171 QReadWriteLock translateMutex;
172 static bool isTranslatorInstalled(QTranslator *translator);
173#endif
174
175 QCoreApplicationPrivate::Type application_type;
176
177 QString cachedApplicationDirPath;
178 static QString *cachedApplicationFilePath;
179 static void setApplicationFilePath(const QString &path);
180 static inline void clearApplicationFilePath() { delete cachedApplicationFilePath; cachedApplicationFilePath = nullptr; }
181
182#ifndef QT_NO_QOBJECT
183 void execCleanup();
184
185 bool in_exec;
186 bool aboutToQuitEmitted;
187 bool threadData_clean;
188
189 static QAbstractEventDispatcher *eventDispatcher;
190 static bool is_app_running;
191 static bool is_app_closing;
192#endif
193
194 static bool setuidAllowed;
195 static uint attribs;
196 static inline bool testAttribute(uint flag) { return attribs & (1 << flag); }
197 static int app_compile_version;
198
199 void processCommandLineArguments();
200 QString qmljs_debug_arguments; // a string containing arguments for js/qml debugging.
201 inline QString qmljsDebugArgumentsString() { return qmljs_debug_arguments; }
202
203#ifdef QT_NO_QOBJECT
204 QCoreApplication *q_ptr;
205#endif
206
207#ifndef QT_NO_QOBJECT
208 virtual QEvent *cloneEvent(QEvent *e);
209#endif
210};
211
212QT_END_NAMESPACE
213
214#endif // QCOREAPPLICATION_P_H
215