1/****************************************************************************
2**
3** Copyright (C) 2021 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_H
41#define QCOREAPPLICATION_H
42
43#include <QtCore/qglobal.h>
44#include <QtCore/qstring.h>
45#ifndef QT_NO_QOBJECT
46#include <QtCore/qobject.h>
47#include <QtCore/qcoreevent.h>
48#include <QtCore/qeventloop.h>
49#else
50#include <QtCore/qscopedpointer.h>
51#endif
52#ifndef QT_NO_DEBUGSTREAM
53#include <QtCore/qdebug.h>
54#endif
55
56#ifndef QT_NO_QOBJECT
57#if defined(Q_OS_WIN) && !defined(tagMSG)
58typedef struct tagMSG MSG;
59#endif
60#endif
61
62QT_BEGIN_NAMESPACE
63
64
65class QCoreApplicationPrivate;
66class QTranslator;
67class QPostEventList;
68class QAbstractEventDispatcher;
69class QAbstractNativeEventFilter;
70
71#define qApp QCoreApplication::instance()
72
73class Q_CORE_EXPORT QCoreApplication
74#ifndef QT_NO_QOBJECT
75 : public QObject
76#endif
77{
78#ifndef QT_NO_QOBJECT
79 Q_OBJECT
80 Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName NOTIFY applicationNameChanged)
81 Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion NOTIFY applicationVersionChanged)
82 Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName NOTIFY organizationNameChanged)
83 Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain NOTIFY organizationDomainChanged)
84 Q_PROPERTY(bool quitLockEnabled READ isQuitLockEnabled WRITE setQuitLockEnabled)
85#endif
86
87 Q_DECLARE_PRIVATE(QCoreApplication)
88public:
89 enum { ApplicationFlags = QT_VERSION
90 };
91
92 QCoreApplication(int &argc, char **argv
93#ifndef Q_QDOC
94 , int = ApplicationFlags
95#endif
96 );
97
98 ~QCoreApplication();
99
100 static QStringList arguments();
101
102 static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true);
103 static bool testAttribute(Qt::ApplicationAttribute attribute);
104
105 static void setOrganizationDomain(const QString &orgDomain);
106 static QString organizationDomain();
107 static void setOrganizationName(const QString &orgName);
108 static QString organizationName();
109 static void setApplicationName(const QString &application);
110 static QString applicationName();
111 static void setApplicationVersion(const QString &version);
112 static QString applicationVersion();
113
114 static void setSetuidAllowed(bool allow);
115 static bool isSetuidAllowed();
116
117 static QCoreApplication *instance() { return self; }
118
119#ifndef QT_NO_QOBJECT
120 static int exec();
121 static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
122 static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
123
124 static bool sendEvent(QObject *receiver, QEvent *event);
125 static void postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority);
126 static void sendPostedEvents(QObject *receiver = nullptr, int event_type = 0);
127 static void removePostedEvents(QObject *receiver, int eventType = 0);
128 static QAbstractEventDispatcher *eventDispatcher();
129 static void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
130
131 virtual bool notify(QObject *, QEvent *);
132
133 static bool startingUp();
134 static bool closingDown();
135#endif
136
137 static QString applicationDirPath();
138 static QString applicationFilePath();
139 static qint64 applicationPid() Q_DECL_CONST_FUNCTION;
140
141#if QT_CONFIG(library)
142 static void setLibraryPaths(const QStringList &);
143 static QStringList libraryPaths();
144 static void addLibraryPath(const QString &);
145 static void removeLibraryPath(const QString &);
146#endif // QT_CONFIG(library)
147
148#ifndef QT_NO_TRANSLATION
149 static bool installTranslator(QTranslator * messageFile);
150 static bool removeTranslator(QTranslator * messageFile);
151#endif
152
153 static QString translate(const char * context,
154 const char * key,
155 const char * disambiguation = nullptr,
156 int n = -1);
157
158#ifndef QT_NO_QOBJECT
159 void installNativeEventFilter(QAbstractNativeEventFilter *filterObj);
160 void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj);
161
162 static bool isQuitLockEnabled();
163 static void setQuitLockEnabled(bool enabled);
164
165public Q_SLOTS:
166 static void quit();
167 static void exit(int retcode = 0);
168
169Q_SIGNALS:
170 void aboutToQuit(QPrivateSignal);
171
172 void organizationNameChanged();
173 void organizationDomainChanged();
174 void applicationNameChanged();
175 void applicationVersionChanged();
176
177protected:
178 bool event(QEvent *) override;
179
180 virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
181#endif // QT_NO_QOBJECT
182
183protected:
184 QCoreApplication(QCoreApplicationPrivate &p);
185
186#ifdef QT_NO_QOBJECT
187 QScopedPointer<QCoreApplicationPrivate> d_ptr;
188#endif
189
190private:
191#ifndef QT_NO_QOBJECT
192 static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
193 static bool notifyInternal2(QObject *receiver, QEvent *);
194 static bool forwardEvent(QObject *receiver, QEvent *event, QEvent *originatingEvent = nullptr);
195#endif
196#if QT_CONFIG(library)
197 static QStringList libraryPathsLocked();
198#endif
199
200 static QCoreApplication *self;
201
202 Q_DISABLE_COPY(QCoreApplication)
203
204 friend class QApplication;
205 friend class QApplicationPrivate;
206 friend class QGuiApplication;
207 friend class QGuiApplicationPrivate;
208 friend class QWidget;
209 friend class QWidgetWindow;
210 friend class QWidgetPrivate;
211#ifndef QT_NO_QOBJECT
212 friend class QEventDispatcherUNIXPrivate;
213 friend class QCocoaEventDispatcherPrivate;
214 friend bool qt_sendSpontaneousEvent(QObject *, QEvent *);
215#endif
216 friend Q_CORE_EXPORT QString qAppName();
217 friend class QCommandLineParserPrivate;
218};
219
220#define Q_DECLARE_TR_FUNCTIONS(context) \
221public: \
222 static inline QString tr(const char *sourceText, const char *disambiguation = nullptr, int n = -1) \
223 { return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \
224private:
225
226typedef void (*QtStartUpFunction)();
227typedef void (*QtCleanUpFunction)();
228
229Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction);
230Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
231Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
232Q_CORE_EXPORT QString qAppName(); // get application name
233
234#define Q_COREAPP_STARTUP_FUNCTION(AFUNC) \
235 static void AFUNC ## _ctor_function() { \
236 qAddPreRoutine(AFUNC); \
237 } \
238 Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function)
239
240#ifndef QT_NO_QOBJECT
241#if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM)
242Q_CORE_EXPORT QString decodeMSG(const MSG &);
243Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
244#endif
245#endif
246
247QT_END_NAMESPACE
248
249#include <QtCore/qcoreapplication_platform.h>
250
251#endif // QCOREAPPLICATION_H
252