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