1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the core module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#ifndef QCOREAPPLICATION_H
30
#define QCOREAPPLICATION_H
32
#include <QtCore/qobject.h>
33
#include <QtCore/qcoreevent.h>
34
#include <QtCore/qeventloop.h>
36
#ifdef QT_INCLUDE_COMPAT
37
#include <QtCore/qstringlist.h>
40
#if defined(Q_WS_WIN) && !defined(tagMSG)
41
typedef struct tagMSG MSG;
44
class QCoreApplicationPrivate;
50
class Q_CORE_EXPORT QCoreApplication : public QObject
53
Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName)
54
Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName)
55
Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain)
57
Q_DECLARE_PRIVATE(QCoreApplication)
59
QCoreApplication(int &argc, char **argv);
65
static void setOrganizationDomain(const QString &orgDomain);
66
static QString organizationDomain();
67
static void setOrganizationName(const QString &orgName);
68
static QString organizationName();
69
static void setApplicationName(const QString &application);
70
static QString applicationName();
72
static QCoreApplication *instance() { return self; }
75
static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
76
static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
77
static void exit(int retcode=0);
79
static bool sendEvent(QObject *receiver, QEvent *event);
80
static void postEvent(QObject *receiver, QEvent *event);
81
static void sendPostedEvents(QObject *receiver, int event_type);
82
static void sendPostedEvents();
83
static void removePostedEvents(QObject *receiver);
84
static bool hasPendingEvents();
86
virtual bool notify(QObject *, QEvent *);
88
static bool startingUp();
89
static bool closingDown();
92
static QString applicationDirPath();
93
static QString applicationFilePath();
96
#ifndef QT_NO_COMPONENT
97
static void setLibraryPaths(const QStringList &);
98
static QStringList libraryPaths();
99
static void addLibraryPath(const QString &);
100
static void removeLibraryPath(const QString &);
101
#endif // QT_NO_COMPONENT
103
#ifndef QT_NO_TRANSLATION
104
static void installTranslator(QTranslator *);
105
static void removeTranslator(QTranslator *);
107
enum Encoding { DefaultCodec, UnicodeUTF8 };
108
static QString translate(const char * context,
110
const char * comment = 0,
111
Encoding encoding = DefaultCodec);
115
#if defined(QT3_SUPPORT)
116
inline QT3_SUPPORT void lock() {}
117
inline QT3_SUPPORT void unlock(bool = true) {}
118
inline QT3_SUPPORT bool locked() { return false; }
119
inline QT3_SUPPORT bool tryLock() { return false; }
121
static inline QT3_SUPPORT void processOneEvent()
122
{ processEvents(QEventLoop::WaitForMoreEvents); }
123
static QT3_SUPPORT int enter_loop();
124
static QT3_SUPPORT void exit_loop();
125
static QT3_SUPPORT int loopLevel();
128
#if defined(Q_WS_WIN)
129
virtual bool winEventFilter(MSG *message, long *result);
133
static void watchUnixSignal(int signal, bool watch);
136
typedef bool (*EventFilter)(void *message, long *result);
137
EventFilter setEventFilter(EventFilter filter);
138
bool filterEvent(void *message, long *result);
145
void unixSignal(int);
148
bool event(QEvent *);
150
virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
153
QCoreApplication(QCoreApplicationPrivate &p);
156
static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
160
static QCoreApplication *self;
162
friend class QEventDispatcherUNIXPrivate;
163
friend class QApplication;
164
friend class QApplicationPrivate;
165
friend class QETWidget;
166
friend class Q3AccelManager;
167
friend class QShortcutMap;
168
friend class QWidget;
169
friend class QWidgetPrivate;
170
#if defined(Q_WS_WIN) || defined (Q_WS_MAC) || defined (Q_WS_QWS)
171
friend bool qt_sendSpontaneousEvent(QObject*, QEvent*);
175
inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)
176
{ if (event) event->spont = false; return self ? self->notify(receiver, event) : false; }
178
inline bool QCoreApplication::sendSpontaneousEvent(QObject *receiver, QEvent *event)
179
{ if (event) event->spont = true; return self ? self->notify(receiver, event) : false; }
181
inline void QCoreApplication::sendPostedEvents() { sendPostedEvents(0, 0); }
183
#ifdef QT_NO_TRANSLATION
185
inline QString QCoreApplication::translate(const char *, const char *sourceText,
186
const char *, Encoding encoding)
188
#ifndef QT_NO_TEXTCODEC
189
if (encoding == UnicodeUTF8)
190
return QString::fromUtf8(sourceText);
194
return QString::fromLatin1(sourceText);
198
typedef void (*QtCleanUpFunction)();
200
Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
201
Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
202
Q_CORE_EXPORT QString qAppName(); // get application name
204
#if defined(Q_WS_WIN) && !defined(QT_NO_DEBUG_STREAM)
205
Q_CORE_EXPORT QString decodeMSG(const MSG &);
206
Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
209
#endif // QCOREAPPLICATION_H