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