src/corelib/kernel/qcoreapplication.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtCore module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QCOREAPPLICATION_H
00025 #define QCOREAPPLICATION_H
00026 
00027 #include <QtCore/qobject.h>
00028 #include <QtCore/qcoreevent.h>
00029 #include <QtCore/qeventloop.h>
00030 
00031 #ifdef QT_INCLUDE_COMPAT
00032 #include <QtCore/qstringlist.h>
00033 #endif
00034 
00035 QT_BEGIN_HEADER
00036 
00037 QT_MODULE(Core)
00038 
00039 #if defined(Q_WS_WIN) && !defined(tagMSG)
00040 typedef struct tagMSG MSG;
00041 #endif
00042 
00043 class QCoreApplicationPrivate;
00044 class QTextCodec;
00045 class QTranslator;
00046 class QPostEventList;
00047 class QStringList;
00048 
00049 class Q_CORE_EXPORT QCoreApplication : public QObject
00050 {
00051     Q_OBJECT
00052     Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName)
00053     Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName)
00054     Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain)
00055 
00056     Q_DECLARE_PRIVATE(QCoreApplication)
00057 public:
00058     QCoreApplication(int &argc, char **argv);
00059     ~QCoreApplication();
00060 
00061 #ifdef QT_DEPRECATED
00062     static int argc() QT_DEPRECATED;
00063     static char **argv() QT_DEPRECATED;
00064 #endif
00065     static QStringList arguments();
00066 
00067     static void setAttribute(Qt::ApplicationAttribute attribute, bool on = true);
00068     static bool testAttribute(Qt::ApplicationAttribute attribute);
00069 
00070     static void setOrganizationDomain(const QString &orgDomain);
00071     static QString organizationDomain();
00072     static void setOrganizationName(const QString &orgName);
00073     static QString organizationName();
00074     static void setApplicationName(const QString &application);
00075     static QString applicationName();
00076 
00077     static QCoreApplication *instance() { return self; }
00078 
00079     static int exec();
00080     static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
00081     static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
00082     static void exit(int retcode=0);
00083 
00084     static bool sendEvent(QObject *receiver, QEvent *event);
00085     static void postEvent(QObject *receiver, QEvent *event);
00086     static void sendPostedEvents(QObject *receiver, int event_type);
00087     static void sendPostedEvents();
00088     static void removePostedEvents(QObject *receiver);
00089     static bool hasPendingEvents();
00090 
00091     virtual bool notify(QObject *, QEvent *);
00092 
00093     static bool startingUp();
00094     static bool closingDown();
00095 
00096     static QString applicationDirPath();
00097     static QString applicationFilePath();
00098 
00099 #ifndef QT_NO_LIBRARY
00100     static void setLibraryPaths(const QStringList &);
00101     static QStringList libraryPaths();
00102     static void addLibraryPath(const QString &);
00103     static void removeLibraryPath(const QString &);
00104 #endif // QT_NO_LIBRARY
00105 
00106 #ifndef QT_NO_TRANSLATION
00107     static void installTranslator(QTranslator * messageFile);
00108     static void removeTranslator(QTranslator * messageFile);
00109 #endif
00110     enum Encoding { CodecForTr, UnicodeUTF8, DefaultCodec = CodecForTr };
00111     // ### merge in Qt 5
00112     static QString translate(const char * context,
00113                              const char * key,
00114                              const char * comment = 0,
00115                              Encoding encoding = CodecForTr);
00116     static QString translate(const char * context,
00117                              const char * key,
00118                              const char * comment,
00119                              Encoding encoding, int n);
00120 
00121     static void flush();
00122 
00123 #if defined(QT3_SUPPORT)
00124     inline QT3_SUPPORT void lock() {}
00125     inline QT3_SUPPORT void unlock(bool = true) {}
00126     inline QT3_SUPPORT bool locked() { return false; }
00127     inline QT3_SUPPORT bool tryLock() { return false; }
00128 
00129     static inline QT3_SUPPORT void processOneEvent()
00130     { processEvents(QEventLoop::WaitForMoreEvents); }
00131     static QT3_SUPPORT int enter_loop();
00132     static QT3_SUPPORT void exit_loop();
00133     static QT3_SUPPORT int loopLevel();
00134 #endif
00135 
00136 #if defined(Q_WS_WIN)
00137     virtual bool winEventFilter(MSG *message, long *result);
00138 #endif
00139 
00140 #ifdef Q_OS_UNIX
00141     static void watchUnixSignal(int signal, bool watch);
00142 #endif
00143 
00144     typedef bool (*EventFilter)(void *message, long *result);
00145     EventFilter setEventFilter(EventFilter filter);
00146     bool filterEvent(void *message, long *result);
00147 
00148 public Q_SLOTS:
00149     static void quit();
00150 
00151 Q_SIGNALS:
00152     void aboutToQuit();
00153     void unixSignal(int);
00154 
00155 protected:
00156     bool event(QEvent *);
00157 
00158     virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
00159 
00160 protected:
00161     QCoreApplication(QCoreApplicationPrivate &p);
00162 
00163 private:
00164     static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
00165 
00166     void init();
00167 
00168     static QCoreApplication *self;
00169 
00170     friend class QEventDispatcherUNIXPrivate;
00171     friend class QApplication;
00172     friend class QApplicationPrivate;
00173     friend class QETWidget;
00174     friend class Q3AccelManager;
00175     friend class QShortcutMap;
00176     friend class QWidget;
00177     friend class QWidgetPrivate;
00178     friend bool qt_sendSpontaneousEvent(QObject*, QEvent*);
00179     friend Q_CORE_EXPORT QString qAppName();
00180 };
00181 
00182 inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)
00183 {  if (event) event->spont = false; return self ? self->notify(receiver, event) : false; }
00184 
00185 inline bool QCoreApplication::sendSpontaneousEvent(QObject *receiver, QEvent *event)
00186 { if (event) event->spont = true; return self ? self->notify(receiver, event) : false; }
00187 
00188 inline void QCoreApplication::sendPostedEvents() { sendPostedEvents(0, 0); }
00189 
00190 #ifdef QT_NO_TRANSLATION
00191 // Simple versions
00192 inline QString QCoreApplication::translate(const char *, const char *sourceText,
00193                                            const char *, Encoding encoding)
00194 {
00195 #ifndef QT_NO_TEXTCODEC
00196     if (encoding == UnicodeUTF8)
00197         return QString::fromUtf8(sourceText);
00198 #else
00199     Q_UNUSED(encoding)
00200 #endif
00201     return QString::fromLatin1(sourceText);
00202 }
00203 
00204 // Simple versions
00205 inline QString QCoreApplication::translate(const char *, const char *sourceText,
00206                                            const char *, Encoding encoding, int)
00207 {
00208 #ifndef QT_NO_TEXTCODEC
00209     if (encoding == UnicodeUTF8)
00210         return QString::fromUtf8(sourceText);
00211 #else
00212     Q_UNUSED(encoding)
00213 #endif
00214     return QString::fromLatin1(sourceText);
00215 }
00216 #endif
00217 
00218 // ### merge the four functions into two (using "int n = -1")
00219 #define Q_DECLARE_TR_FUNCTIONS(context) \
00220 public: \
00221     static inline QString tr(const char *sourceText, const char *comment = 0) \
00222         { return QCoreApplication::translate(#context, sourceText, comment); } \
00223     static inline QString trUtf8(const char *sourceText, const char *comment = 0) \
00224         { return QCoreApplication::translate(#context, sourceText, comment, \
00225                                              QCoreApplication::UnicodeUTF8); } \
00226     static inline QString tr(const char *sourceText, const char *comment, int n) \
00227         { return QCoreApplication::translate(#context, sourceText, comment, \
00228                                              QCoreApplication::CodecForTr, n); } \
00229     static inline QString trUtf8(const char *sourceText, const char *comment, int n) \
00230         { return QCoreApplication::translate(#context, sourceText, comment, \
00231                                              QCoreApplication::UnicodeUTF8, n); } \
00232 private:
00233 
00234 typedef void (*QtCleanUpFunction)();
00235 
00236 Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
00237 Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
00238 Q_CORE_EXPORT QString qAppName();                // get application name
00239 
00240 #if defined(Q_WS_WIN) && !defined(QT_NO_DEBUG_STREAM)
00241 Q_CORE_EXPORT QString decodeMSG(const MSG &);
00242 Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
00243 #endif
00244 
00245 QT_END_HEADER
00246 
00247 #endif // QCOREAPPLICATION_H

Generated on Thu Mar 15 11:53:24 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1