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