00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QCOREAPPLICATION_H
00043 #define QCOREAPPLICATION_H
00044
00045 #include <QtCore/qobject.h>
00046 #include <QtCore/qcoreevent.h>
00047 #include <QtCore/qeventloop.h>
00048
00049 #ifdef QT_INCLUDE_COMPAT
00050 #include <QtCore/qstringlist.h>
00051 #endif
00052
00053 #if defined(Q_WS_WIN) && !defined(tagMSG)
00054 typedef struct tagMSG MSG;
00055 #endif
00056
00057 QT_BEGIN_HEADER
00058
00059 QT_BEGIN_NAMESPACE
00060
00061 QT_MODULE(Core)
00062
00063 class QCoreApplicationPrivate;
00064 class QTextCodec;
00065 class QTranslator;
00066 class QPostEventList;
00067 class QStringList;
00068
00069 #define qApp QCoreApplication::instance()
00070
00071 class Q_CORE_EXPORT QCoreApplication : public QObject
00072 {
00073 Q_OBJECT
00074 Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName)
00075 Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion)
00076 Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName)
00077 Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain)
00078
00079 Q_DECLARE_PRIVATE(QCoreApplication)
00080 public:
00081 QCoreApplication(int &argc, char **argv);
00082 ~QCoreApplication();
00083
00084 #ifdef QT_DEPRECATED
00085 QT_DEPRECATED static int argc();
00086 QT_DEPRECATED static char **argv();
00087 #endif
00088 static QStringList arguments();
00089
00090 static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true);
00091 static bool testAttribute(Qt::ApplicationAttribute attribute);
00092
00093 static void setOrganizationDomain(const QString &orgDomain);
00094 static QString organizationDomain();
00095 static void setOrganizationName(const QString &orgName);
00096 static QString organizationName();
00097 static void setApplicationName(const QString &application);
00098 static QString applicationName();
00099 static void setApplicationVersion(const QString &version);
00100 static QString applicationVersion();
00101
00102 static QCoreApplication *instance() { return self; }
00103
00104 static int exec();
00105 static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
00106 static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
00107 static void exit(int retcode=0);
00108
00109 static bool sendEvent(QObject *receiver, QEvent *event);
00110 static void postEvent(QObject *receiver, QEvent *event);
00111 static void postEvent(QObject *receiver, QEvent *event, int priority);
00112 static void sendPostedEvents(QObject *receiver, int event_type);
00113 static void sendPostedEvents();
00114 static void removePostedEvents(QObject *receiver);
00115 static void removePostedEvents(QObject *receiver, int eventType);
00116 static bool hasPendingEvents();
00117
00118 virtual bool notify(QObject *, QEvent *);
00119
00120 static bool startingUp();
00121 static bool closingDown();
00122
00123 static QString applicationDirPath();
00124 static QString applicationFilePath();
00125 static qint64 applicationPid();
00126
00127 #ifndef QT_NO_LIBRARY
00128 static void setLibraryPaths(const QStringList &);
00129 static QStringList libraryPaths();
00130 static void addLibraryPath(const QString &);
00131 static void removeLibraryPath(const QString &);
00132 #endif // QT_NO_LIBRARY
00133
00134 #ifndef QT_NO_TRANSLATION
00135 static void installTranslator(QTranslator * messageFile);
00136 static void removeTranslator(QTranslator * messageFile);
00137 #endif
00138 enum Encoding { CodecForTr, UnicodeUTF8, DefaultCodec = CodecForTr };
00139
00140 static QString translate(const char * context,
00141 const char * key,
00142 const char * disambiguation = 0,
00143 Encoding encoding = CodecForTr);
00144 static QString translate(const char * context,
00145 const char * key,
00146 const char * disambiguation,
00147 Encoding encoding, int n);
00148
00149 static void flush();
00150
00151 #if defined(QT3_SUPPORT)
00152 inline QT3_SUPPORT void lock() {}
00153 inline QT3_SUPPORT void unlock(bool = true) {}
00154 inline QT3_SUPPORT bool locked() { return false; }
00155 inline QT3_SUPPORT bool tryLock() { return false; }
00156
00157 static inline QT3_SUPPORT void processOneEvent()
00158 { processEvents(QEventLoop::WaitForMoreEvents); }
00159 static QT3_SUPPORT int enter_loop();
00160 static QT3_SUPPORT void exit_loop();
00161 static QT3_SUPPORT int loopLevel();
00162 #endif
00163
00164 #if defined(Q_WS_WIN)
00165 virtual bool winEventFilter(MSG *message, long *result);
00166 #endif
00167
00168 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
00169 static void watchUnixSignal(int signal, bool watch);
00170 #endif
00171
00172 typedef bool (*EventFilter)(void *message, long *result);
00173 EventFilter setEventFilter(EventFilter filter);
00174 bool filterEvent(void *message, long *result);
00175
00176 public Q_SLOTS:
00177 static void quit();
00178
00179 Q_SIGNALS:
00180 void aboutToQuit();
00181 void unixSignal(int);
00182
00183 protected:
00184 bool event(QEvent *);
00185
00186 virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
00187
00188 protected:
00189 QCoreApplication(QCoreApplicationPrivate &p);
00190
00191 private:
00192 static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
00193 bool notifyInternal(QObject *receiver, QEvent *event);
00194
00195 void init();
00196
00197 static QCoreApplication *self;
00198
00199 Q_DISABLE_COPY(QCoreApplication)
00200
00201 friend class QEventDispatcherUNIXPrivate;
00202 friend class QApplication;
00203 friend class QApplicationPrivate;
00204 friend class QETWidget;
00205 friend class Q3AccelManager;
00206 friend class QShortcutMap;
00207 friend class QWidget;
00208 friend class QWidgetPrivate;
00209 friend bool qt_sendSpontaneousEvent(QObject*, QEvent*);
00210 friend Q_CORE_EXPORT QString qAppName();
00211 friend class QClassFactory;
00212 };
00213
00214 inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)
00215 { if (event) event->spont = false; return self ? self->notifyInternal(receiver, event) : false; }
00216
00217 inline bool QCoreApplication::sendSpontaneousEvent(QObject *receiver, QEvent *event)
00218 { if (event) event->spont = true; return self ? self->notifyInternal(receiver, event) : false; }
00219
00220 inline void QCoreApplication::sendPostedEvents() { sendPostedEvents(0, 0); }
00221
00222 #ifdef QT_NO_TRANSLATION
00223
00224 inline QString QCoreApplication::translate(const char *, const char *sourceText,
00225 const char *, Encoding encoding)
00226 {
00227 #ifndef QT_NO_TEXTCODEC
00228 if (encoding == UnicodeUTF8)
00229 return QString::fromUtf8(sourceText);
00230 #else
00231 Q_UNUSED(encoding)
00232 #endif
00233 return QString::fromLatin1(sourceText);
00234 }
00235
00236
00237 inline QString QCoreApplication::translate(const char *, const char *sourceText,
00238 const char *, Encoding encoding, int)
00239 {
00240 #ifndef QT_NO_TEXTCODEC
00241 if (encoding == UnicodeUTF8)
00242 return QString::fromUtf8(sourceText);
00243 #else
00244 Q_UNUSED(encoding)
00245 #endif
00246 return QString::fromLatin1(sourceText);
00247 }
00248 #endif
00249
00250
00251 #define Q_DECLARE_TR_FUNCTIONS(context) \
00252 public: \
00253 static inline QString tr(const char *sourceText, const char *disambiguation = 0) \
00254 { return QCoreApplication::translate(#context, sourceText, disambiguation); } \
00255 static inline QString trUtf8(const char *sourceText, const char *disambiguation = 0) \
00256 { return QCoreApplication::translate(#context, sourceText, disambiguation, \
00257 QCoreApplication::UnicodeUTF8); } \
00258 static inline QString tr(const char *sourceText, const char *disambiguation, int n) \
00259 { return QCoreApplication::translate(#context, sourceText, disambiguation, \
00260 QCoreApplication::CodecForTr, n); } \
00261 static inline QString trUtf8(const char *sourceText, const char *disambiguation, int n) \
00262 { return QCoreApplication::translate(#context, sourceText, disambiguation, \
00263 QCoreApplication::UnicodeUTF8, n); } \
00264 private:
00265
00266 typedef void (*QtCleanUpFunction)();
00267
00268 Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
00269 Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
00270 Q_CORE_EXPORT QString qAppName();
00271
00272 #if defined(Q_WS_WIN) && !defined(QT_NO_DEBUG_STREAM)
00273 Q_CORE_EXPORT QString decodeMSG(const MSG &);
00274 Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
00275 #endif
00276
00277 QT_END_NAMESPACE
00278
00279 QT_END_HEADER
00280
00281 #endif // QCOREAPPLICATION_H