Line data Source code
1 : /****************************************************************************
2 : **
3 : ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4 : ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 : ** conditions see http://qt.digia.com/licensing. For further information
15 : ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 : ** Foundation and appearing in the file LICENSE.LGPL included in the
21 : ** packaging of this file. Please review the following information to
22 : ** ensure the GNU Lesser General Public License version 2.1 requirements
23 : ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 : **
25 : ** In addition, as a special exception, Digia gives you certain additional
26 : ** rights. These rights are described in the Digia Qt LGPL Exception
27 : ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 : **
29 : ** GNU General Public License Usage
30 : ** Alternatively, this file may be used under the terms of the GNU
31 : ** General Public License version 3.0 as published by the Free Software
32 : ** Foundation and appearing in the file LICENSE.GPL included in the
33 : ** packaging of this file. Please review the following information to
34 : ** ensure the GNU General Public License version 3.0 requirements will be
35 : ** met: http://www.gnu.org/copyleft/gpl.html.
36 : **
37 : **
38 : ** $QT_END_LICENSE$
39 : **
40 : ****************************************************************************/
41 :
42 : #ifndef QCOREAPPLICATION_H
43 : #define QCOREAPPLICATION_H
44 :
45 : #include <QtCore/qglobal.h>
46 : #include <QtCore/qstring.h>
47 : #ifndef QT_NO_QOBJECT
48 : #include <QtCore/qobject.h>
49 : #include <QtCore/qcoreevent.h>
50 : #include <QtCore/qeventloop.h>
51 : #else
52 : #include <QtCore/qscopedpointer.h>
53 : #endif
54 :
55 : #ifndef QT_NO_QOBJECT
56 : #if defined(Q_OS_WIN) && !defined(tagMSG)
57 : typedef struct tagMSG MSG;
58 : #endif
59 : #endif
60 :
61 : QT_BEGIN_NAMESPACE
62 :
63 :
64 : class QCoreApplicationPrivate;
65 : class QTextCodec;
66 : class QTranslator;
67 : class QPostEventList;
68 : class QStringList;
69 : class QAbstractEventDispatcher;
70 : class QAbstractNativeEventFilter;
71 :
72 : #define qApp QCoreApplication::instance()
73 :
74 : class Q_CORE_EXPORT QCoreApplication
75 : #ifndef QT_NO_QOBJECT
76 : : public QObject
77 : #endif
78 : {
79 : #ifndef QT_NO_QOBJECT
80 : Q_OBJECT
81 : Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName NOTIFY applicationNameChanged)
82 : Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion NOTIFY applicationVersionChanged)
83 : Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName NOTIFY organizationNameChanged)
84 : Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain NOTIFY organizationDomainChanged)
85 : Q_PROPERTY(bool quitLockEnabled READ isQuitLockEnabled WRITE setQuitLockEnabled)
86 : #endif
87 :
88 : Q_DECLARE_PRIVATE(QCoreApplication)
89 : public:
90 : enum { ApplicationFlags = QT_VERSION
91 : };
92 :
93 : QCoreApplication(int &argc, char **argv
94 : #ifndef Q_QDOC
95 : , int = ApplicationFlags
96 : #endif
97 : );
98 :
99 : ~QCoreApplication();
100 :
101 : static QStringList arguments();
102 :
103 : static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true);
104 : static bool testAttribute(Qt::ApplicationAttribute attribute);
105 :
106 : static void setOrganizationDomain(const QString &orgDomain);
107 : static QString organizationDomain();
108 : static void setOrganizationName(const QString &orgName);
109 : static QString organizationName();
110 : static void setApplicationName(const QString &application);
111 : static QString applicationName();
112 : static void setApplicationVersion(const QString &version);
113 : static QString applicationVersion();
114 :
115 : static void setSetuidAllowed(bool allow);
116 : static bool isSetuidAllowed();
117 :
118 34 : static QCoreApplication *instance() { return self; }
119 :
120 : #ifndef QT_NO_QOBJECT
121 : static int exec();
122 : static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
123 : static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
124 : static void exit(int retcode=0);
125 :
126 : static bool sendEvent(QObject *receiver, QEvent *event);
127 : static void postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority);
128 : static void sendPostedEvents(QObject *receiver = 0, int event_type = 0);
129 : static void removePostedEvents(QObject *receiver, int eventType = 0);
130 : #if QT_DEPRECATED_SINCE(5, 3)
131 : QT_DEPRECATED static bool hasPendingEvents();
132 : #endif
133 : static QAbstractEventDispatcher *eventDispatcher();
134 : static void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
135 :
136 : virtual bool notify(QObject *, QEvent *);
137 :
138 : static bool startingUp();
139 : static bool closingDown();
140 : #endif
141 :
142 : static QString applicationDirPath();
143 : static QString applicationFilePath();
144 : static qint64 applicationPid();
145 :
146 : #ifndef QT_NO_LIBRARY
147 : static void setLibraryPaths(const QStringList &);
148 : static QStringList libraryPaths();
149 : static void addLibraryPath(const QString &);
150 : static void removeLibraryPath(const QString &);
151 : #endif // QT_NO_LIBRARY
152 :
153 : #ifndef QT_NO_TRANSLATION
154 : static bool installTranslator(QTranslator * messageFile);
155 : static bool removeTranslator(QTranslator * messageFile);
156 : #endif
157 :
158 : static QString translate(const char * context,
159 : const char * key,
160 : const char * disambiguation = 0,
161 : int n = -1);
162 : #if QT_DEPRECATED_SINCE(5, 0)
163 : enum Encoding { UnicodeUTF8, Latin1, DefaultCodec = UnicodeUTF8, CodecForTr = UnicodeUTF8 };
164 : QT_DEPRECATED static inline QString translate(const char * context, const char * key,
165 : const char * disambiguation, Encoding, int n = -1)
166 : { return translate(context, key, disambiguation, n); }
167 : #endif
168 :
169 : #ifndef QT_NO_QOBJECT
170 : static void flush();
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(
183 : #if !defined(Q_QDOC)
184 : QPrivateSignal
185 : #endif
186 : );
187 :
188 : void organizationNameChanged();
189 : void organizationDomainChanged();
190 : void applicationNameChanged();
191 : void applicationVersionChanged();
192 :
193 : protected:
194 : bool event(QEvent *);
195 :
196 : virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
197 : #endif // QT_NO_QOBJECT
198 :
199 : protected:
200 : QCoreApplication(QCoreApplicationPrivate &p);
201 :
202 : #ifdef QT_NO_QOBJECT
203 : QScopedPointer<QCoreApplicationPrivate> d_ptr;
204 : #endif
205 :
206 : private:
207 : #ifndef QT_NO_QOBJECT
208 : static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
209 : bool notifyInternal(QObject *receiver, QEvent *event);
210 : #endif
211 :
212 : void init();
213 :
214 : static QCoreApplication *self;
215 :
216 : Q_DISABLE_COPY(QCoreApplication)
217 :
218 : friend class QApplication;
219 : friend class QApplicationPrivate;
220 : friend class QGuiApplication;
221 : friend class QGuiApplicationPrivate;
222 : friend class QETWidget;
223 : friend class QWidget;
224 : friend class QWidgetWindow;
225 : friend class QWidgetPrivate;
226 : #ifndef QT_NO_QOBJECT
227 : friend class QEventDispatcherUNIXPrivate;
228 : friend class QCocoaEventDispatcherPrivate;
229 : friend bool qt_sendSpontaneousEvent(QObject*, QEvent*);
230 : #endif
231 : friend Q_CORE_EXPORT QString qAppName();
232 : friend class QClassFactory;
233 : };
234 :
235 : #ifndef QT_NO_QOBJECT
236 : inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)
237 : { if (event) event->spont = false; return self ? self->notifyInternal(receiver, event) : false; }
238 :
239 : inline bool QCoreApplication::sendSpontaneousEvent(QObject *receiver, QEvent *event)
240 : { if (event) event->spont = true; return self ? self->notifyInternal(receiver, event) : false; }
241 : #endif
242 :
243 : #ifdef QT_NO_DEPRECATED
244 : # define QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context)
245 : #else
246 : # define QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context) \
247 : QT_DEPRECATED static inline QString trUtf8(const char *sourceText, const char *disambiguation = 0, int n = -1) \
248 : { return QCoreApplication::translate(#context, sourceText, disambiguation, n); }
249 : #endif
250 :
251 : #define Q_DECLARE_TR_FUNCTIONS(context) \
252 : public: \
253 : static inline QString tr(const char *sourceText, const char *disambiguation = 0, int n = -1) \
254 : { return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \
255 : QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context) \
256 : private:
257 :
258 : typedef void (*QtStartUpFunction)();
259 : typedef void (*QtCleanUpFunction)();
260 :
261 : Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction);
262 : Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
263 : Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
264 : Q_CORE_EXPORT QString qAppName(); // get application name
265 :
266 : #define Q_COREAPP_STARTUP_FUNCTION(AFUNC) \
267 : static void AFUNC ## _ctor_function() { \
268 : qAddPreRoutine(AFUNC); \
269 : } \
270 : Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function)
271 :
272 : #ifndef QT_NO_QOBJECT
273 : #if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM)
274 : Q_CORE_EXPORT QString decodeMSG(const MSG &);
275 : Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
276 : #endif
277 : #endif
278 :
279 : QT_END_NAMESPACE
280 :
281 : #endif // QCOREAPPLICATION_H
|