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