source: trunk/src/corelib/kernel/qcoreapplication.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 10.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QCOREAPPLICATION_H
43#define QCOREAPPLICATION_H
44
45#include <QtCore/qobject.h>
46#include <QtCore/qcoreevent.h>
47#include <QtCore/qeventloop.h>
48
49#ifdef QT_INCLUDE_COMPAT
50#include <QtCore/qstringlist.h>
51#endif
52
53#if defined(Q_WS_WIN) && !defined(tagMSG)
54typedef struct tagMSG MSG;
55#endif
56
57#if defined(Q_WS_PM)
58typedef struct _QMSG QMSG;
59typedef void *MRESULT;
60#endif
61
62QT_BEGIN_HEADER
63
64QT_BEGIN_NAMESPACE
65
66QT_MODULE(Core)
67
68class QCoreApplicationPrivate;
69class QTextCodec;
70class QTranslator;
71class QPostEventList;
72class QStringList;
73
74#define qApp QCoreApplication::instance()
75
76class Q_CORE_EXPORT QCoreApplication : public QObject
77{
78 Q_OBJECT
79 Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName)
80 Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion)
81 Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName)
82 Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain)
83
84 Q_DECLARE_PRIVATE(QCoreApplication)
85public:
86 QCoreApplication(int &argc, char **argv);
87 ~QCoreApplication();
88
89#ifdef QT_DEPRECATED
90 QT_DEPRECATED static int argc();
91 QT_DEPRECATED static char **argv();
92#endif
93 static QStringList arguments();
94
95 static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true);
96 static bool testAttribute(Qt::ApplicationAttribute attribute);
97
98 static void setOrganizationDomain(const QString &orgDomain);
99 static QString organizationDomain();
100 static void setOrganizationName(const QString &orgName);
101 static QString organizationName();
102 static void setApplicationName(const QString &application);
103 static QString applicationName();
104 static void setApplicationVersion(const QString &version);
105 static QString applicationVersion();
106
107 static QCoreApplication *instance() { return self; }
108
109 static int exec();
110 static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
111 static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
112 static void exit(int retcode=0);
113
114 static bool sendEvent(QObject *receiver, QEvent *event);
115 static void postEvent(QObject *receiver, QEvent *event);
116 static void postEvent(QObject *receiver, QEvent *event, int priority);
117 static void sendPostedEvents(QObject *receiver, int event_type);
118 static void sendPostedEvents();
119 static void removePostedEvents(QObject *receiver);
120 static void removePostedEvents(QObject *receiver, int eventType);
121 static bool hasPendingEvents();
122
123 virtual bool notify(QObject *, QEvent *);
124
125 static bool startingUp();
126 static bool closingDown();
127
128 static QString applicationDirPath();
129 static QString applicationFilePath();
130 static qint64 applicationPid();
131
132#ifndef QT_NO_LIBRARY
133 static void setLibraryPaths(const QStringList &);
134 static QStringList libraryPaths();
135 static void addLibraryPath(const QString &);
136 static void removeLibraryPath(const QString &);
137#endif // QT_NO_LIBRARY
138
139#ifndef QT_NO_TRANSLATION
140 static void installTranslator(QTranslator * messageFile);
141 static void removeTranslator(QTranslator * messageFile);
142#endif
143 enum Encoding { CodecForTr, UnicodeUTF8, DefaultCodec = CodecForTr };
144 // ### Qt 5: merge
145 static QString translate(const char * context,
146 const char * key,
147 const char * disambiguation = 0,
148 Encoding encoding = CodecForTr);
149 static QString translate(const char * context,
150 const char * key,
151 const char * disambiguation,
152 Encoding encoding, int n);
153
154 static void flush();
155
156#if defined(QT3_SUPPORT)
157 inline QT3_SUPPORT void lock() {}
158 inline QT3_SUPPORT void unlock(bool = true) {}
159 inline QT3_SUPPORT bool locked() { return false; }
160 inline QT3_SUPPORT bool tryLock() { return false; }
161
162 static inline QT3_SUPPORT void processOneEvent()
163 { processEvents(QEventLoop::WaitForMoreEvents); }
164 static QT3_SUPPORT int enter_loop();
165 static QT3_SUPPORT void exit_loop();
166 static QT3_SUPPORT int loopLevel();
167#endif
168
169#if defined(Q_WS_WIN)
170 virtual bool winEventFilter(MSG *message, long *result);
171#endif
172
173#if defined(Q_WS_PM)
174 virtual bool pmEventFilter(QMSG *message, MRESULT *result);
175#endif
176
177#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
178 static void watchUnixSignal(int signal, bool watch);
179#endif
180
181 typedef bool (*EventFilter)(void *message, long *result);
182 EventFilter setEventFilter(EventFilter filter);
183 bool filterEvent(void *message, long *result);
184
185public Q_SLOTS:
186 static void quit();
187
188Q_SIGNALS:
189 void aboutToQuit();
190 void unixSignal(int);
191
192protected:
193 bool event(QEvent *);
194
195 virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
196
197protected:
198 QCoreApplication(QCoreApplicationPrivate &p);
199
200private:
201 static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
202 bool notifyInternal(QObject *receiver, QEvent *event);
203
204 void init();
205
206 static QCoreApplication *self;
207
208 Q_DISABLE_COPY(QCoreApplication)
209
210 friend class QEventDispatcherUNIXPrivate;
211 friend class QEventDispatcherPM;
212 friend class QApplication;
213 friend class QApplicationPrivate;
214 friend class QETWidget;
215 friend class Q3AccelManager;
216 friend class QShortcutMap;
217 friend class QWidget;
218 friend class QWidgetPrivate;
219 friend bool qt_sendSpontaneousEvent(QObject*, QEvent*);
220 friend Q_CORE_EXPORT QString qAppName();
221 friend class QClassFactory;
222};
223
224inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)
225{ if (event) event->spont = false; return self ? self->notifyInternal(receiver, event) : false; }
226
227inline bool QCoreApplication::sendSpontaneousEvent(QObject *receiver, QEvent *event)
228{ if (event) event->spont = true; return self ? self->notifyInternal(receiver, event) : false; }
229
230inline void QCoreApplication::sendPostedEvents() { sendPostedEvents(0, 0); }
231
232#ifdef QT_NO_TRANSLATION
233// Simple versions
234inline QString QCoreApplication::translate(const char *, const char *sourceText,
235 const char *, Encoding encoding)
236{
237#ifndef QT_NO_TEXTCODEC
238 if (encoding == UnicodeUTF8)
239 return QString::fromUtf8(sourceText);
240#else
241 Q_UNUSED(encoding)
242#endif
243 return QString::fromLatin1(sourceText);
244}
245
246// Simple versions
247inline QString QCoreApplication::translate(const char *, const char *sourceText,
248 const char *, Encoding encoding, int)
249{
250#ifndef QT_NO_TEXTCODEC
251 if (encoding == UnicodeUTF8)
252 return QString::fromUtf8(sourceText);
253#else
254 Q_UNUSED(encoding)
255#endif
256 return QString::fromLatin1(sourceText);
257}
258#endif
259
260// ### merge the four functions into two (using "int n = -1")
261#define Q_DECLARE_TR_FUNCTIONS(context) \
262public: \
263 static inline QString tr(const char *sourceText, const char *disambiguation = 0) \
264 { return QCoreApplication::translate(#context, sourceText, disambiguation); } \
265 static inline QString trUtf8(const char *sourceText, const char *disambiguation = 0) \
266 { return QCoreApplication::translate(#context, sourceText, disambiguation, \
267 QCoreApplication::UnicodeUTF8); } \
268 static inline QString tr(const char *sourceText, const char *disambiguation, int n) \
269 { return QCoreApplication::translate(#context, sourceText, disambiguation, \
270 QCoreApplication::CodecForTr, n); } \
271 static inline QString trUtf8(const char *sourceText, const char *disambiguation, int n) \
272 { return QCoreApplication::translate(#context, sourceText, disambiguation, \
273 QCoreApplication::UnicodeUTF8, n); } \
274private:
275
276typedef void (*QtCleanUpFunction)();
277
278Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
279Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
280Q_CORE_EXPORT QString qAppName(); // get application name
281
282#if defined(Q_WS_WIN) && !defined(QT_NO_DEBUG_STREAM)
283Q_CORE_EXPORT QString decodeMSG(const MSG &);
284Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
285#endif
286
287QT_END_NAMESPACE
288
289QT_END_HEADER
290
291#endif // QCOREAPPLICATION_H
Note: See TracBrowser for help on using the repository browser.