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