/usr/include/QtCore/qcoreapplication.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (C) 2021 The Qt Company Ltd. |
2 | | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | | |
4 | | #ifndef QCOREAPPLICATION_H |
5 | | #define QCOREAPPLICATION_H |
6 | | |
7 | | #include <QtCore/qglobal.h> |
8 | | #include <QtCore/qstring.h> |
9 | | #ifndef QT_NO_QOBJECT |
10 | | #include <QtCore/qcoreevent.h> |
11 | | #include <QtCore/qdeadlinetimer.h> |
12 | | #include <QtCore/qeventloop.h> |
13 | | #include <QtCore/qobject.h> |
14 | | #else |
15 | | #include <QtCore/qscopedpointer.h> |
16 | | #endif |
17 | | #include <QtCore/qnativeinterface.h> |
18 | | |
19 | | #ifndef QT_NO_QOBJECT |
20 | | #if defined(Q_OS_WIN) && !defined(tagMSG) |
21 | | typedef struct tagMSG MSG; |
22 | | #endif |
23 | | #endif |
24 | | |
25 | | QT_BEGIN_NAMESPACE |
26 | | |
27 | | class QAbstractEventDispatcher; |
28 | | class QAbstractNativeEventFilter; |
29 | | class QDebug; |
30 | | class QEventLoopLocker; |
31 | | class QPermission; |
32 | | #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) |
33 | | class QPostEventList; |
34 | | #endif |
35 | | class QTranslator; |
36 | | |
37 | | #define qApp QCoreApplication::instance() |
38 | | |
39 | | class QCoreApplicationPrivate; |
40 | | class Q_CORE_EXPORT QCoreApplication |
41 | | #ifndef QT_NO_QOBJECT |
42 | | : public QObject |
43 | | #endif |
44 | | { |
45 | | #ifndef QT_NO_QOBJECT |
46 | | Q_OBJECT |
47 | | Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName |
48 | | NOTIFY applicationNameChanged) |
49 | | Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion |
50 | | NOTIFY applicationVersionChanged) |
51 | | Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName |
52 | | NOTIFY organizationNameChanged) |
53 | | Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain |
54 | | NOTIFY organizationDomainChanged) |
55 | | Q_PROPERTY(bool quitLockEnabled READ isQuitLockEnabled WRITE setQuitLockEnabled) |
56 | | #endif |
57 | | |
58 | | Q_DECLARE_PRIVATE(QCoreApplication) |
59 | | friend class QEventLoopLocker; |
60 | | #if QT_CONFIG(permissions) |
61 | | using RequestPermissionPrototype = void(*)(QPermission); |
62 | | #endif |
63 | | |
64 | | public: |
65 | | enum { ApplicationFlags = QT_VERSION |
66 | | }; |
67 | | |
68 | | QCoreApplication(int &argc, char **argv |
69 | | #ifndef Q_QDOC |
70 | | , int = ApplicationFlags |
71 | | #endif |
72 | | ); |
73 | | |
74 | | ~QCoreApplication(); |
75 | | |
76 | | static QStringList arguments(); |
77 | | |
78 | | static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true); |
79 | | static bool testAttribute(Qt::ApplicationAttribute attribute); |
80 | | |
81 | | static void setOrganizationDomain(const QString &orgDomain); |
82 | | static QString organizationDomain(); |
83 | | static void setOrganizationName(const QString &orgName); |
84 | | static QString organizationName(); |
85 | | static void setApplicationName(const QString &application); |
86 | | static QString applicationName(); |
87 | | static void setApplicationVersion(const QString &version); |
88 | | static QString applicationVersion(); |
89 | | |
90 | | static void setSetuidAllowed(bool allow); |
91 | | static bool isSetuidAllowed(); |
92 | | |
93 | | #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) |
94 | | static QCoreApplication *instance() noexcept { return self.loadRelaxed(); } |
95 | | static bool instanceExists() noexcept { return instance() != nullptr; } |
96 | | #else |
97 | 0 | static QCoreApplication *instance() noexcept { return self; } |
98 | | static bool instanceExists() noexcept; |
99 | | #endif |
100 | | |
101 | | #ifndef QT_NO_QOBJECT |
102 | | static int exec(); |
103 | | static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); |
104 | | static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime); |
105 | | static void processEvents(QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline); |
106 | | |
107 | | static bool sendEvent(QObject *receiver, QEvent *event); |
108 | | static void postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority); |
109 | | static void sendPostedEvents(QObject *receiver = nullptr, int event_type = 0); |
110 | | static void removePostedEvents(QObject *receiver, int eventType = 0); |
111 | | static QAbstractEventDispatcher *eventDispatcher(); |
112 | | static void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher); |
113 | | |
114 | | virtual bool notify(QObject *, QEvent *); |
115 | | |
116 | | static bool startingUp(); |
117 | | static bool closingDown(); |
118 | | #endif |
119 | | |
120 | | static QString applicationDirPath(); |
121 | | static QString applicationFilePath(); |
122 | | static qint64 applicationPid() Q_DECL_CONST_FUNCTION; |
123 | | |
124 | | #if QT_CONFIG(permissions) || defined(Q_QDOC) |
125 | | Qt::PermissionStatus checkPermission(const QPermission &permission); |
126 | | |
127 | | # ifdef Q_QDOC |
128 | | template <typename Functor> |
129 | | void requestPermission(const QPermission &permission, const QObject *context, Functor functor); |
130 | | # else |
131 | | // requestPermission with context or receiver object; need to require here that receiver is the |
132 | | // right type to avoid ambiguity with the private implementation function. |
133 | | template <typename Functor, |
134 | | std::enable_if_t< |
135 | | QtPrivate::AreFunctionsCompatible<RequestPermissionPrototype, Functor>::value, |
136 | | bool> = true> |
137 | | void requestPermission(const QPermission &permission, |
138 | | const typename QtPrivate::ContextTypeForFunctor<Functor>::ContextType *receiver, |
139 | | Functor &&func) |
140 | | { |
141 | | requestPermissionImpl(permission, |
142 | | QtPrivate::makeCallableObject<RequestPermissionPrototype>(std::forward<Functor>(func)), |
143 | | receiver); |
144 | | } |
145 | | # endif // Q_QDOC |
146 | | |
147 | | #ifndef QT_NO_CONTEXTLESS_CONNECT |
148 | | #ifdef Q_QDOC |
149 | | template <typename Functor> |
150 | | #else |
151 | | // requestPermission to a functor or function pointer (without context) |
152 | | template <typename Functor, |
153 | | std::enable_if_t< |
154 | | QtPrivate::AreFunctionsCompatible<RequestPermissionPrototype, Functor>::value, |
155 | | bool> = true> |
156 | | #endif |
157 | | void requestPermission(const QPermission &permission, Functor &&func) |
158 | | { |
159 | | requestPermission(permission, nullptr, std::forward<Functor>(func)); |
160 | | } |
161 | | #endif // QT_NO_CONTEXTLESS_CONNECT |
162 | | |
163 | | #if QT_CORE_REMOVED_SINCE(6, 10) |
164 | | private: |
165 | | void requestPermission(const QPermission &permission, |
166 | | QtPrivate::QSlotObjectBase *slotObj, const QObject *context); |
167 | | public: |
168 | | #endif |
169 | | |
170 | | #endif // QT_CONFIG(permission) |
171 | | |
172 | | #if QT_CONFIG(library) |
173 | | static void setLibraryPaths(const QStringList &); |
174 | | static QStringList libraryPaths(); |
175 | | static void addLibraryPath(const QString &); |
176 | | static void removeLibraryPath(const QString &); |
177 | | #endif // QT_CONFIG(library) |
178 | | |
179 | | #ifndef QT_NO_TRANSLATION |
180 | | static bool installTranslator(QTranslator * messageFile); |
181 | | static bool removeTranslator(QTranslator * messageFile); |
182 | | #endif |
183 | | |
184 | | static QString translate(const char * context, |
185 | | const char * key, |
186 | | const char * disambiguation = nullptr, |
187 | | int n = -1); |
188 | | |
189 | | QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QCoreApplication) |
190 | | |
191 | | #ifndef QT_NO_QOBJECT |
192 | | void installNativeEventFilter(QAbstractNativeEventFilter *filterObj); |
193 | | void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj); |
194 | | |
195 | | static bool isQuitLockEnabled(); |
196 | | static void setQuitLockEnabled(bool enabled); |
197 | | |
198 | | public Q_SLOTS: |
199 | | static void quit(); |
200 | | static void exit(int retcode = 0); |
201 | | |
202 | | Q_SIGNALS: |
203 | | void aboutToQuit(QPrivateSignal); |
204 | | |
205 | | void organizationNameChanged(); |
206 | | void organizationDomainChanged(); |
207 | | void applicationNameChanged(); |
208 | | void applicationVersionChanged(); |
209 | | |
210 | | protected: |
211 | | bool event(QEvent *) override; |
212 | | |
213 | | # if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) |
214 | | virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *); |
215 | | # endif |
216 | | #endif // QT_NO_QOBJECT |
217 | | |
218 | | protected: |
219 | | QCoreApplication(QCoreApplicationPrivate &p); |
220 | | |
221 | | #ifdef QT_NO_QOBJECT |
222 | | std::unique_ptr<QCoreApplicationPrivate> d_ptr; |
223 | | #endif |
224 | | |
225 | | private: |
226 | | #ifndef QT_NO_QOBJECT |
227 | | static bool sendSpontaneousEvent(QObject *receiver, QEvent *event); |
228 | | static bool notifyInternal2(QObject *receiver, QEvent *); |
229 | | static bool forwardEvent(QObject *receiver, QEvent *event, QEvent *originatingEvent = nullptr); |
230 | | |
231 | | void requestPermissionImpl(const QPermission &permission, QtPrivate::QSlotObjectBase *slotObj, |
232 | | const QObject *context); |
233 | | #endif |
234 | | |
235 | | #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) |
236 | | static QBasicAtomicPointer<QCoreApplication> self; |
237 | | #else |
238 | | static QCoreApplication *self; |
239 | | #endif |
240 | | |
241 | | Q_DISABLE_COPY(QCoreApplication) |
242 | | |
243 | | friend class QApplication; |
244 | | friend class QApplicationPrivate; |
245 | | friend class QGuiApplication; |
246 | | friend class QGuiApplicationPrivate; |
247 | | friend class QWidget; |
248 | | friend class QWidgetWindow; |
249 | | friend class QWidgetPrivate; |
250 | | friend class QWindowPrivate; |
251 | | #ifndef QT_NO_QOBJECT |
252 | | friend class QEventDispatcherUNIXPrivate; |
253 | | friend class QCocoaEventDispatcherPrivate; |
254 | | friend bool qt_sendSpontaneousEvent(QObject *, QEvent *); |
255 | | #endif |
256 | | friend Q_CORE_EXPORT QString qAppName(); |
257 | | friend class QCommandLineParserPrivate; |
258 | | }; |
259 | | |
260 | | #define Q_DECLARE_TR_FUNCTIONS(context) \ |
261 | | public: \ |
262 | | static inline QString tr(const char *sourceText, const char *disambiguation = nullptr, int n = -1) \ |
263 | | { return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \ |
264 | | private: |
265 | | |
266 | | typedef void (*QtStartUpFunction)(); |
267 | | typedef void (*QtCleanUpFunction)(); |
268 | | |
269 | | Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction); |
270 | | Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction); |
271 | | Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction); |
272 | | Q_CORE_EXPORT QString qAppName(); // get application name |
273 | | |
274 | | #define Q_COREAPP_STARTUP_FUNCTION(AFUNC) \ |
275 | | static void AFUNC ## _ctor_function() { \ |
276 | | qAddPreRoutine(AFUNC); \ |
277 | | } \ |
278 | | Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function) |
279 | | |
280 | | #ifndef QT_NO_QOBJECT |
281 | | #if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM) |
282 | | Q_CORE_EXPORT QString decodeMSG(const MSG &); |
283 | | Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &); |
284 | | #endif |
285 | | #endif |
286 | | |
287 | | QT_END_NAMESPACE |
288 | | |
289 | | #include <QtCore/qcoreapplication_platform.h> |
290 | | |
291 | | #endif // QCOREAPPLICATION_H |