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