1 /**************************************************************************** 2 ** 3 ** DQt - D bindings for the Qt Toolkit 4 ** 5 ** GNU Lesser General Public License Usage 6 ** This file may be used under the terms of the GNU Lesser 7 ** General Public License version 3 as published by the Free Software 8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 9 ** packaging of this file. Please review the following information to 10 ** ensure the GNU Lesser General Public License version 3 requirements 11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 12 ** 13 ****************************************************************************/ 14 module qt.core.coreapplication; 15 extern(C++): 16 17 import qt.config; 18 import qt.core.coreevent; 19 import qt.core.eventloop; 20 import qt.core.global; 21 import qt.core.namespace; 22 import qt.core.object; 23 import qt.core.string; 24 import qt.core.stringlist; 25 import qt.helpers; 26 27 /+ #ifndef QT_NO_QOBJECT 28 #else 29 #endif 30 31 #ifndef QT_NO_QOBJECT +/ 32 version(Cygwin){}else 33 version(Windows) 34 { 35 struct tagMSG; 36 alias MSG = tagMSG; 37 } 38 /+ #endif +/ 39 40 41 42 extern(C++, class) struct QCoreApplicationPrivate; 43 /+ class QTextCodec; +/ 44 extern(C++, class) struct QTranslator; 45 extern(C++, class) struct QPostEventList; 46 /+ class QStringList; +/ 47 extern(C++, class) struct QAbstractEventDispatcher; 48 extern(C++, class) struct QAbstractNativeEventFilter; 49 50 /+ #define qApp QCoreApplication::instance() +/ 51 52 class /+ Q_CORE_EXPORT +/ QCoreApplication 53 /+ #ifndef QT_NO_QOBJECT +/ 54 : QObject 55 /+ #endif +/ 56 { 57 /+ #ifndef QT_NO_QOBJECT +/ 58 mixin(Q_OBJECT); 59 /+ Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName NOTIFY applicationNameChanged) 60 Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion NOTIFY applicationVersionChanged) 61 Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName NOTIFY organizationNameChanged) 62 Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain NOTIFY organizationDomainChanged) 63 Q_PROPERTY(bool quitLockEnabled READ isQuitLockEnabled WRITE setQuitLockEnabled) 64 #endif 65 66 Q_DECLARE_PRIVATE(QCoreApplication) +/ 67 public: 68 enum { ApplicationFlags = QT_VERSION 69 } 70 71 this(ref int argc, char** argv 72 /+ #ifndef Q_QDOC +/ 73 , int = ApplicationFlags 74 /+ #endif +/ 75 ); 76 77 ~this(); 78 79 static QStringList arguments(); 80 81 static void setAttribute(/+ Qt:: +/qt.core.namespace.ApplicationAttribute attribute, bool on = true); 82 static bool testAttribute(/+ Qt:: +/qt.core.namespace.ApplicationAttribute attribute); 83 84 static void setOrganizationDomain(ref const(QString) orgDomain); 85 static QString organizationDomain(); 86 static void setOrganizationName(ref const(QString) orgName); 87 static QString organizationName(); 88 static void setApplicationName(ref const(QString) application); 89 static QString applicationName(); 90 static void setApplicationVersion(ref const(QString) version_); 91 static QString applicationVersion(); 92 93 static void setSetuidAllowed(bool allow); 94 static bool isSetuidAllowed(); 95 96 static QCoreApplication instance() { return self; } 97 98 /+ #ifndef QT_NO_QOBJECT +/ 99 static int exec(); 100 static void processEvents(QEventLoop.ProcessEventsFlags flags = QEventLoop.ProcessEventsFlag.AllEvents); 101 static void processEvents(QEventLoop.ProcessEventsFlags flags, int maxtime); 102 static void exit(int retcode=0); 103 104 static bool sendEvent(QObject receiver, QEvent event); 105 static void postEvent(QObject receiver, QEvent event, int priority = /+ Qt:: +/qt.core.namespace.EventPriority.NormalEventPriority); 106 static void sendPostedEvents(QObject receiver = null, int event_type = 0); 107 static void removePostedEvents(QObject receiver, int eventType = 0); 108 /+ #if QT_DEPRECATED_SINCE(5, 3) +/ 109 /+ QT_DEPRECATED +/ static bool hasPendingEvents(); 110 /+ #endif +/ 111 static QAbstractEventDispatcher* eventDispatcher(); 112 static void setEventDispatcher(QAbstractEventDispatcher* eventDispatcher); 113 114 /+ virtual +/ bool notify(QObject , QEvent ); 115 116 static bool startingUp(); 117 static bool closingDown(); 118 /+ #endif +/ 119 120 static QString applicationDirPath(); 121 static QString applicationFilePath(); 122 static qint64 applicationPid()/+ /+ Q_DECL_CONST_FUNCTION +/__attribute__((const))+/; 123 124 /+ #if QT_CONFIG(library) +/ 125 static void setLibraryPaths(ref const(QStringList) ); 126 static QStringList libraryPaths(); 127 static void addLibraryPath(ref const(QString) ); 128 static void removeLibraryPath(ref const(QString) ); 129 /+ #endif // QT_CONFIG(library) 130 131 #ifndef QT_NO_TRANSLATION +/ 132 version(QT_NO_TRANSLATION){}else 133 { 134 static bool installTranslator(QTranslator* messageFile); 135 static bool removeTranslator(QTranslator* messageFile); 136 } 137 /+ #endif +/ 138 139 static QString translate(const(char)* context, 140 const(char)* key, 141 const(char)* disambiguation = null, 142 int n = -1); 143 /+ #if QT_DEPRECATED_SINCE(5, 0) 144 enum Encoding { UnicodeUTF8, Latin1, DefaultCodec = UnicodeUTF8, CodecForTr = UnicodeUTF8 }; 145 QT_DEPRECATED static inline QString translate(const char * context, const char * key, 146 const char * disambiguation, Encoding, int n = -1) 147 { return translate(context, key, disambiguation, n); } 148 #endif 149 150 #ifndef QT_NO_QOBJECT 151 # if QT_DEPRECATED_SINCE(5, 9) +/ 152 /+ QT_DEPRECATED +/ static void flush(); 153 /+ # endif +/ 154 155 final void installNativeEventFilter(QAbstractNativeEventFilter* filterObj); 156 final void removeNativeEventFilter(QAbstractNativeEventFilter* filterObj); 157 158 static bool isQuitLockEnabled(); 159 static void setQuitLockEnabled(bool enabled); 160 161 public /+ Q_SLOTS +/: 162 @QSlot static void quit(); 163 164 /+ Q_SIGNALS +/public: 165 @QSignal final void aboutToQuit(QPrivateSignal); 166 167 @QSignal final void organizationNameChanged(); 168 @QSignal final void organizationDomainChanged(); 169 @QSignal final void applicationNameChanged(); 170 @QSignal final void applicationVersionChanged(); 171 172 protected: 173 override bool event(QEvent ); 174 175 /+ virtual +/ bool compressEvent(QEvent , QObject receiver, QPostEventList* ); 176 /+ #endif +/ // QT_NO_QOBJECT 177 178 protected: 179 this(ref QCoreApplicationPrivate p); 180 181 /+ #ifdef QT_NO_QOBJECT 182 QScopedPointer<QCoreApplicationPrivate> d_ptr; 183 #endif +/ 184 185 private: 186 /+ #ifndef QT_NO_QOBJECT +/ 187 static bool sendSpontaneousEvent(QObject receiver, QEvent event); 188 /+ # if QT_DEPRECATED_SINCE(5,6) +/ 189 /+ QT_DEPRECATED +/ final bool notifyInternal(QObject receiver, QEvent event); // ### Qt6 BIC: remove me 190 /+ # endif +/ 191 static bool notifyInternal2(QObject receiver, QEvent ); 192 static bool forwardEvent(QObject receiver, QEvent event, QEvent originatingEvent = null); 193 /+ #endif 194 #if QT_CONFIG(library) +/ 195 static QStringList libraryPathsLocked(); 196 /+ #endif +/ 197 198 mixin(mangleWindows("?self@QCoreApplication@@0PEAV1@EA", q{ 199 extern export static __gshared QCoreApplication self; 200 })); 201 202 /+ Q_DISABLE_COPY(QCoreApplication) +/ 203 204 /+ friend class QApplication; +/ 205 /+ friend class QApplicationPrivate; +/ 206 /+ friend class QGuiApplication; +/ 207 /+ friend class QGuiApplicationPrivate; +/ 208 /+ friend class QWidget; +/ 209 /+ friend class QWidgetWindow; +/ 210 /+ friend class QWidgetPrivate; +/ 211 /+ #ifndef QT_NO_QOBJECT +/ 212 /+ friend class QEventDispatcherUNIXPrivate; +/ 213 /+ friend class QCocoaEventDispatcherPrivate; +/ 214 /+ friend bool qt_sendSpontaneousEvent(QObject*, QEvent*); +/ 215 /+ #endif +/ 216 /+ friend Q_CORE_EXPORT QString qAppName(); +/ 217 /+ friend class QClassFactory; +/ 218 /+ friend class QCommandLineParserPrivate; +/ 219 } 220 221 /+ #ifdef QT_NO_DEPRECATED 222 # define QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context) 223 #else +/ 224 /+ # define QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context) \ 225 QT_DEPRECATED static inline QString trUtf8(const char *sourceText, const char *disambiguation = nullptr, int n = -1) \ 226 { return QCoreApplication::translate(#context, sourceText, disambiguation, n); } +/ 227 extern(D) alias QT_DECLARE_DEPRECATED_TR_FUNCTIONS = function string(string context) 228 { 229 return 230 mixin(interpolateMixin(q{/+ QT_DEPRECATED +/ pragma(inline, true) static QString trUtf8(const(char)* sourceText, const(char)* disambiguation = null, int n = -1) 231 { return QCoreApplication.translate($(stringifyMacroParameter(context)), sourceText, disambiguation, n); }})); 232 }; 233 /+ #endif 234 235 #define Q_DECLARE_TR_FUNCTIONS(context) \ 236 public: \ 237 static inline QString tr(const char *sourceText, const char *disambiguation = nullptr, int n = -1) \ 238 { return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \ 239 QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context) \ 240 private: +/ 241 242 alias QtStartUpFunction = ExternCPPFunc!(void function()); 243 alias QtCleanUpFunction = ExternCPPFunc!(void function()); 244 245 /+ Q_CORE_EXPORT +/ void qAddPreRoutine(QtStartUpFunction); 246 /+ Q_CORE_EXPORT +/ void qAddPostRoutine(QtCleanUpFunction); 247 /+ Q_CORE_EXPORT +/ void qRemovePostRoutine(QtCleanUpFunction); 248 /+ Q_CORE_EXPORT +/ QString qAppName(); // get application name 249 250 /+ #define Q_COREAPP_STARTUP_FUNCTION(AFUNC) \ 251 static void AFUNC ## _ctor_function() { \ 252 qAddPreRoutine(AFUNC); \ 253 } \ 254 Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function) 255 256 #ifndef QT_NO_QOBJECT 257 #if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM) 258 Q_CORE_EXPORT QString decodeMSG(const MSG &); 259 Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &); 260 #endif 261 #endif +/ 262 static if(!versionIsSet!("Windows") || versionIsSet!("Cygwin")) 263 { 264 struct tagMSG; 265 } 266 267 static if(!versionIsSet!("Windows") || versionIsSet!("Cygwin")) 268 { 269 alias MSG = tagMSG; 270 } 271 272