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.url; 13 extern(C++): 14 15 import qt.config; 16 import qt.core.bytearray; 17 import qt.core.flags; 18 import qt.core.list; 19 import qt.core.string; 20 import qt.core.stringlist; 21 import qt.core.typeinfo; 22 import qt.helpers; 23 24 /+ #if defined(Q_OS_DARWIN) || defined(Q_QDOC) 25 Q_FORWARD_DECLARE_CF_TYPE(CFURL); 26 Q_FORWARD_DECLARE_OBJC_CLASS(NSURL); 27 #endif +/ 28 29 30 31 extern(C++, class) struct QUrlQuery; 32 extern(C++, class) struct QUrlPrivate; 33 34 extern(C++, class) struct QUrlTwoFlags(E1, E2) 35 { 36 private: 37 int i = 0; 38 public: 39 @disable this(); 40 /+pragma(inline, true) this() 41 { 42 this.i = 0; 43 }+/ 44 pragma(inline, true) this(E1 f) 45 { 46 this.i = f; 47 } 48 pragma(inline, true) this(E2 f) 49 { 50 this.i = f; 51 } 52 pragma(inline, true) this(QFlag f) 53 { 54 this.i = f; 55 } 56 /+pragma(inline, true) this(QFlags!(E1) f) 57 { 58 this.i = f.operatortypenameQFlags<E1E1>::Int (); 59 } 60 pragma(inline, true) this(QFlags!(E2) f) 61 { 62 this.i = f.operatortypenameQFlags<E2E2>::Int (); 63 }+/ 64 65 pragma(inline, true) ref QUrlTwoFlags opOpAssign(string op)(int mask) if(op == "&") { i &= mask; return this; } 66 pragma(inline, true) ref QUrlTwoFlags opOpAssign(string op)(uint mask) if(op == "&") { i &= mask; return this; } 67 pragma(inline, true) ref QUrlTwoFlags opOpAssign(string op)(QFlags!(E1) mask) if(op == "&") { i &= mask.toInt(); return this; } 68 pragma(inline, true) ref QUrlTwoFlags opOpAssign(string op)(QFlags!(E2) mask) if(op == "&") { i &= mask.toInt(); return this; } 69 pragma(inline, true) ref QUrlTwoFlags opOpAssign(string op)(QUrlTwoFlags f) if(op == "|") { i |= f.i; return this; } 70 pragma(inline, true) ref QUrlTwoFlags opOpAssign(string op)(E1 f) if(op == "|") { i |= f; return this; } 71 pragma(inline, true) ref QUrlTwoFlags opOpAssign(string op)(E2 f) if(op == "|") { i |= f; return this; } 72 pragma(inline, true) ref QUrlTwoFlags opOpAssign(string op)(QFlags!(E1) mask) if(op == "|") { i |= mask.toInt(); return this; } 73 pragma(inline, true) ref QUrlTwoFlags opOpAssign(string op)(QFlags!(E2) mask) if(op == "|") { i |= mask.toInt(); return this; } 74 /+pragma(inline, true) ref QUrlTwoFlags operator ^=(QUrlTwoFlags f) { i ^= f.i; return this; }+/ 75 /+pragma(inline, true) ref QUrlTwoFlags operator ^=(E1 f) { i ^= f; return this; }+/ 76 /+pragma(inline, true) ref QUrlTwoFlags operator ^=(E2 f) { i ^= f; return this; }+/ 77 /+pragma(inline, true) ref QUrlTwoFlags operator ^=(QFlags!(E1) mask) { i ^= mask.toInt(); return this; }+/ 78 /+pragma(inline, true) ref QUrlTwoFlags operator ^=(QFlags!(E2) mask) { i ^= mask.toInt(); return this; }+/ 79 80 /+pragma(inline, true) auto opCast(T : QFlags!(E1))() const { return QFlag(i); }+/ 81 /+pragma(inline, true) auto opCast(T : QFlags!(E2))() const { return QFlag(i); }+/ 82 /+pragma(inline, true) auto opCast(T : int)() const { return i; }+/ 83 /+pragma(inline, true) bool operator !() const { return !i; }+/ 84 85 pragma(inline, true) QUrlTwoFlags opBinary(string op)(QUrlTwoFlags f) const if(op == "|") 86 { return QUrlTwoFlags(QFlag(i | f.i)); } 87 pragma(inline, true) QUrlTwoFlags opBinary(string op)(E1 f) const if(op == "|") 88 { return QUrlTwoFlags(QFlag(i | f)); } 89 pragma(inline, true) QUrlTwoFlags opBinary(string op)(E2 f) const if(op == "|") 90 { return QUrlTwoFlags(QFlag(i | f)); } 91 /+pragma(inline, true) QUrlTwoFlags operator ^(QUrlTwoFlags f) const 92 { return QUrlTwoFlags(QFlag(i ^ f.i)); }+/ 93 /+pragma(inline, true) QUrlTwoFlags operator ^(E1 f) const 94 { return QUrlTwoFlags(QFlag(i ^ f)); }+/ 95 /+pragma(inline, true) QUrlTwoFlags operator ^(E2 f) const 96 { return QUrlTwoFlags(QFlag(i ^ f)); }+/ 97 pragma(inline, true) QUrlTwoFlags opBinary(string op)(int mask) const if(op == "&") 98 { return QUrlTwoFlags(QFlag(i & mask)); } 99 pragma(inline, true) QUrlTwoFlags opBinary(string op)(uint mask) const if(op == "&") 100 { return QUrlTwoFlags(QFlag(i & mask)); } 101 pragma(inline, true) QUrlTwoFlags opBinary(string op)(E1 f) const if(op == "&") 102 { return QUrlTwoFlags(QFlag(i & f)); } 103 pragma(inline, true) QUrlTwoFlags opBinary(string op)(E2 f) const if(op == "&") 104 { return QUrlTwoFlags(QFlag(i & f)); } 105 /+pragma(inline, true) QUrlTwoFlags operator ~() const 106 { return QUrlTwoFlags(QFlag(~i)); }+/ 107 108 pragma(inline, true) bool testFlag(E1 f) const { return (i & f) == f && (f != 0 || i == int(f)); } 109 pragma(inline, true) bool testFlag(E2 f) const { return (i & f) == f && (f != 0 || i == int(f)); } 110 } 111 112 /+ template<typename E1, typename E2> 113 class QTypeInfo<QUrlTwoFlags<E1, E2> > : public QTypeInfoMerger<QUrlTwoFlags<E1, E2>, E1, E2> {}; 114 115 // qHash is a friend, but we can't use default arguments for friends (§8.3.6.4) 116 Q_CORE_EXPORT size_t qHash(const QUrl &url, size_t seed = 0) noexcept; +/ 117 118 /// Binding for C++ class [QUrl](https://doc.qt.io/qt-6/qurl.html). 119 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QUrl 120 { 121 public: 122 enum ParsingMode { 123 TolerantMode, 124 StrictMode, 125 DecodedMode 126 } 127 128 // encoding / toString values 129 enum UrlFormattingOption : uint { 130 None = 0x0, 131 RemoveScheme = 0x1, 132 RemovePassword = 0x2, 133 RemoveUserInfo = UrlFormattingOption.RemovePassword | 0x4, 134 RemovePort = 0x8, 135 RemoveAuthority = UrlFormattingOption.RemoveUserInfo | UrlFormattingOption.RemovePort | 0x10, 136 RemovePath = 0x20, 137 RemoveQuery = 0x40, 138 RemoveFragment = 0x80, 139 // 0x100 was a private code in Qt 4, keep unused for a while 140 PreferLocalFile = 0x200, 141 StripTrailingSlash = 0x400, 142 RemoveFilename = 0x800, 143 NormalizePathSegments = 0x1000 144 } 145 146 enum ComponentFormattingOption : uint { 147 PrettyDecoded = 0x000000, 148 EncodeSpaces = 0x100000, 149 EncodeUnicode = 0x200000, 150 EncodeDelimiters = 0x400000 | 0x800000, 151 EncodeReserved = 0x1000000, 152 DecodeReserved = 0x2000000, 153 // 0x4000000 used to indicate full-decode mode 154 155 FullyEncoded = ComponentFormattingOption.EncodeSpaces | ComponentFormattingOption.EncodeUnicode | ComponentFormattingOption.EncodeDelimiters | ComponentFormattingOption.EncodeReserved, 156 FullyDecoded = ComponentFormattingOption.FullyEncoded | ComponentFormattingOption.DecodeReserved | 0x4000000 157 } 158 /+ Q_DECLARE_FLAGS(ComponentFormattingOptions, ComponentFormattingOption) +/ 159 alias ComponentFormattingOptions = QFlags!(ComponentFormattingOption);/+ #ifdef Q_QDOC 160 private: 161 // We need to let qdoc think that FormattingOptions is a normal QFlags, but 162 // it needs to be a QUrlTwoFlags for compiling default arguments of some functions. 163 template<typename T> struct QFlags : QUrlTwoFlags<T, ComponentFormattingOption> 164 { using QUrlTwoFlags<T, ComponentFormattingOption>::QUrlTwoFlags; }; 165 public: 166 Q_DECLARE_FLAGS(FormattingOptions, UrlFormattingOption) 167 #else +/ 168 alias FormattingOptions = QUrlTwoFlags!(UrlFormattingOption, ComponentFormattingOption); 169 /+ #endif +/ 170 171 /+this();+/ 172 173 @disable this(this); 174 this(ref const(QUrl) copy); 175 /+ref QUrl operator =(ref const(QUrl) copy);+/ 176 version(QT_NO_URL_CAST_FROM_STRING) 177 { 178 /+ explicit +/this(ref const(QString) url, ParsingMode mode = ParsingMode.TolerantMode); 179 } 180 else 181 { 182 this(ref const(QString) url, ParsingMode mode = ParsingMode.TolerantMode); 183 /+ref QUrl operator =(ref const(QString) url);+/ 184 } 185 /+ QUrl(QUrl &&other) noexcept : d(other.d) 186 { other.d = nullptr; } +/ 187 /+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QUrl) +/ 188 ~this(); 189 190 /+ inline void swap(QUrl &other) noexcept { qSwap(d, other.d); } +/ 191 192 void setUrl(ref const(QString) url, ParsingMode mode = ParsingMode.TolerantMode); 193 // QString url(FormattingOptions options = FormattingOptions(ComponentFormattingOption.PrettyDecoded)) const; 194 // QString toString(FormattingOptions options = FormattingOptions(ComponentFormattingOption.PrettyDecoded)) const; 195 // QString toDisplayString(FormattingOptions options = FormattingOptions(ComponentFormattingOption.PrettyDecoded)) const; 196 /+ [[nodiscard]] +/ QUrl adjusted(FormattingOptions options) const; 197 198 // QByteArray toEncoded(FormattingOptions options = ComponentFormattingOption.FullyEncoded) const; 199 static QUrl fromEncoded(ref const(QByteArray) url, ParsingMode mode = ParsingMode.TolerantMode); 200 201 enum UserInputResolutionOption { 202 DefaultResolution, 203 AssumeLocalFile 204 } 205 /+ Q_DECLARE_FLAGS(UserInputResolutionOptions, UserInputResolutionOption) +/ 206 alias UserInputResolutionOptions = QFlags!(UserInputResolutionOption); 207 static QUrl fromUserInput(ref const(QString) userInput, ref const(QString) workingDirectory = globalInitVar!QString, 208 UserInputResolutionOptions options = UserInputResolutionOption.DefaultResolution); 209 210 bool isValid() const; 211 QString errorString() const; 212 213 bool isEmpty() const; 214 void clear(); 215 216 void setScheme(ref const(QString) scheme); 217 QString scheme() const; 218 219 void setAuthority(ref const(QString) authority, ParsingMode mode = ParsingMode.TolerantMode); 220 QString authority(ComponentFormattingOptions options = ComponentFormattingOption.PrettyDecoded) const; 221 222 void setUserInfo(ref const(QString) userInfo, ParsingMode mode = ParsingMode.TolerantMode); 223 QString userInfo(ComponentFormattingOptions options = ComponentFormattingOption.PrettyDecoded) const; 224 225 void setUserName(ref const(QString) userName, ParsingMode mode = ParsingMode.DecodedMode); 226 QString userName(ComponentFormattingOptions options = ComponentFormattingOption.FullyDecoded) const; 227 228 void setPassword(ref const(QString) password, ParsingMode mode = ParsingMode.DecodedMode); 229 QString password(ComponentFormattingOptions /+ = FullyDecoded +/) const; 230 231 void setHost(ref const(QString) host, ParsingMode mode = ParsingMode.DecodedMode); 232 QString host(ComponentFormattingOptions /+ = FullyDecoded +/) const; 233 234 void setPort(int port); 235 int port(int defaultPort = -1) const; 236 237 void setPath(ref const(QString) path, ParsingMode mode = ParsingMode.DecodedMode); 238 QString path(ComponentFormattingOptions options = ComponentFormattingOption.FullyDecoded) const; 239 QString fileName(ComponentFormattingOptions options = ComponentFormattingOption.FullyDecoded) const; 240 241 bool hasQuery() const; 242 void setQuery(ref const(QString) query, ParsingMode mode = ParsingMode.TolerantMode); 243 void setQuery(ref const(QUrlQuery) query); 244 QString query(ComponentFormattingOptions /+ = PrettyDecoded +/) const; 245 246 bool hasFragment() const; 247 QString fragment(ComponentFormattingOptions options = ComponentFormattingOption.PrettyDecoded) const; 248 void setFragment(ref const(QString) fragment, ParsingMode mode = ParsingMode.TolerantMode); 249 250 /+ [[nodiscard]] +/ QUrl resolved(ref const(QUrl) relative) const; 251 252 bool isRelative() const; 253 bool isParentOf(ref const(QUrl) url) const; 254 255 bool isLocalFile() const; 256 static QUrl fromLocalFile(ref const(QString) localfile); 257 QString toLocalFile() const; 258 259 void detach(); 260 bool isDetached() const; 261 262 /+bool operator <(ref const(QUrl) url) const;+/ 263 /+bool operator ==(ref const(QUrl) url) const;+/ 264 /+bool operator !=(ref const(QUrl) url) const;+/ 265 266 bool matches(ref const(QUrl) url, FormattingOptions options) const; 267 268 static QString fromPercentEncoding(ref const(QByteArray) ); 269 static QByteArray toPercentEncoding(ref const(QString) , 270 ref const(QByteArray) exclude = globalInitVar!QByteArray, 271 ref const(QByteArray) include = globalInitVar!QByteArray); 272 static if((versionIsSet!("OSX") || versionIsSet!("iOS") || versionIsSet!("TVOS") || versionIsSet!("WatchOS"))) 273 { 274 /+ static QUrl fromCFURL(CFURLRef url); +/ 275 /+ CFURLRef toCFURL() const Q_DECL_CF_RETURNS_RETAINED; +/ 276 /+ static QUrl fromNSURL(const NSURL *url); +/ 277 /+ NSURL *toNSURL() const Q_DECL_NS_RETURNS_AUTORELEASED; +/ 278 } 279 280 static QString fromAce(ref const(QByteArray) ); 281 static QByteArray toAce(ref const(QString) ); 282 static QStringList idnWhitelist(); 283 static QStringList toStringList(ref const(QList!(QUrl)) uris, FormattingOptions options = FormattingOptions(ComponentFormattingOption.PrettyDecoded)); 284 static QList!(QUrl) fromStringList(ref const(QStringList) uris, ParsingMode mode = ParsingMode.TolerantMode); 285 286 static void setIdnWhitelist(ref const(QStringList) ); 287 /+ friend Q_CORE_EXPORT size_t qHash(const QUrl &url, size_t seed) noexcept; +/ 288 289 private: 290 QUrlPrivate* d; 291 /+ friend class QUrlQuery; +/ 292 293 public: 294 alias DataPtr = QUrlPrivate*; 295 pragma(inline, true) ref DataPtr data_ptr() return { return d; } 296 mixin(CREATE_CONVENIENCE_WRAPPERS); 297 } 298 /+pragma(inline, true) QFlags!(QUrl.ComponentFormattingOptions.enum_type) operator |(QUrl.ComponentFormattingOptions.enum_type f1, QUrl.ComponentFormattingOptions.enum_type f2)/+noexcept+/{return QFlags!(QUrl.ComponentFormattingOptions.enum_type)(f1)|f2;}+/ 299 /+pragma(inline, true) QFlags!(QUrl.ComponentFormattingOptions.enum_type) operator |(QUrl.ComponentFormattingOptions.enum_type f1, QFlags!(QUrl.ComponentFormattingOptions.enum_type) f2)/+noexcept+/{return f2|f1;}+/ 300 /+pragma(inline, true) QFlags!(QUrl.ComponentFormattingOptions.enum_type) operator &(QUrl.ComponentFormattingOptions.enum_type f1, QUrl.ComponentFormattingOptions.enum_type f2)/+noexcept+/{return QFlags!(QUrl.ComponentFormattingOptions.enum_type)(f1)&f2;}+/ 301 /+pragma(inline, true) QFlags!(QUrl.ComponentFormattingOptions.enum_type) operator &(QUrl.ComponentFormattingOptions.enum_type f1, QFlags!(QUrl.ComponentFormattingOptions.enum_type) f2)/+noexcept+/{return f2&f1;}+/ 302 /+pragma(inline, true) void operator +(QUrl.ComponentFormattingOptions.enum_type f1, QUrl.ComponentFormattingOptions.enum_type f2)/+noexcept+/;+/ 303 /+pragma(inline, true) void operator +(QUrl.ComponentFormattingOptions.enum_type f1, QFlags!(QUrl.ComponentFormattingOptions.enum_type) f2)/+noexcept+/;+/ 304 /+pragma(inline, true) void operator +(int f1, QFlags!(QUrl.ComponentFormattingOptions.enum_type) f2)/+noexcept+/;+/ 305 /+pragma(inline, true) void operator -(QUrl.ComponentFormattingOptions.enum_type f1, QUrl.ComponentFormattingOptions.enum_type f2)/+noexcept+/;+/ 306 /+pragma(inline, true) void operator -(QUrl.ComponentFormattingOptions.enum_type f1, QFlags!(QUrl.ComponentFormattingOptions.enum_type) f2)/+noexcept+/;+/ 307 /+pragma(inline, true) void operator -(int f1, QFlags!(QUrl.ComponentFormattingOptions.enum_type) f2)/+noexcept+/;+/ 308 /+pragma(inline, true) QIncompatibleFlag operator |(QUrl.ComponentFormattingOptions.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/ 309 /+pragma(inline, true) void operator +(int f1, QUrl.ComponentFormattingOptions.enum_type f2)/+noexcept+/;+/ 310 /+pragma(inline, true) void operator +(QUrl.ComponentFormattingOptions.enum_type f1, int f2)/+noexcept+/;+/ 311 /+pragma(inline, true) void operator -(int f1, QUrl.ComponentFormattingOptions.enum_type f2)/+noexcept+/;+/ 312 /+pragma(inline, true) void operator -(QUrl.ComponentFormattingOptions.enum_type f1, int f2)/+noexcept+/;+/ 313 314 /+ Q_DECLARE_SHARED(QUrl) 315 Q_DECLARE_OPERATORS_FOR_FLAGS(QUrl::ComponentFormattingOptions)//Q_DECLARE_OPERATORS_FOR_FLAGS(QUrl::FormattingOptions) 316 317 #ifndef Q_QDOC +/ 318 /+pragma(inline, true) QUrl.FormattingOptions operator |(QUrl.UrlFormattingOption f1, QUrl.UrlFormattingOption f2) 319 { return QUrl.FormattingOptions(f1) | f2; }+/ 320 /+pragma(inline, true) QUrl.FormattingOptions operator |(QUrl.UrlFormattingOption f1, QUrl.FormattingOptions f2) 321 { return f2 | f1; }+/ 322 /+pragma(inline, true) QIncompatibleFlag operator |(QUrl.UrlFormattingOption f1, int f2) 323 { return QIncompatibleFlag(uint(f1) | f2); }+/ 324 325 // add operators for OR'ing the two types of flags 326 /+pragma(inline, true) ref QUrl.FormattingOptions operator |=(ref QUrl.FormattingOptions i, QUrl.ComponentFormattingOptions f) 327 { i |= QUrl.UrlFormattingOption(f.toInt()); return i; }+/ 328 /+pragma(inline, true) QUrl.FormattingOptions operator |(QUrl.UrlFormattingOption i, QUrl.ComponentFormattingOption f) 329 { return i | QUrl.UrlFormattingOption(qToUnderlying(f)); }+/ 330 /+pragma(inline, true) QUrl.FormattingOptions operator |(QUrl.UrlFormattingOption i, QUrl.ComponentFormattingOptions f) 331 { return i | QUrl.UrlFormattingOption(f.toInt()); }+/ 332 /+pragma(inline, true) QUrl.FormattingOptions operator |(QUrl.ComponentFormattingOption f, QUrl.UrlFormattingOption i) 333 { return i | QUrl.UrlFormattingOption(qToUnderlying(f)); }+/ 334 /+pragma(inline, true) QUrl.FormattingOptions operator |(QUrl.ComponentFormattingOptions f, QUrl.UrlFormattingOption i) 335 { return i | QUrl.UrlFormattingOption(f.toInt()); }+/ 336 /+pragma(inline, true) QUrl.FormattingOptions operator |(QUrl.FormattingOptions i, QUrl.ComponentFormattingOptions f) 337 { return i | QUrl.UrlFormattingOption(f.toInt()); }+/ 338 /+pragma(inline, true) QUrl.FormattingOptions operator |(QUrl.ComponentFormattingOption f, QUrl.FormattingOptions i) 339 { return i | QUrl.UrlFormattingOption(qToUnderlying(f)); }+/ 340 /+pragma(inline, true) QUrl.FormattingOptions operator |(QUrl.ComponentFormattingOptions f, QUrl.FormattingOptions i) 341 { return i | QUrl.UrlFormattingOption(f.toInt()); }+/ 342 343 //inline QUrl::UrlFormattingOption &operator=(const QUrl::UrlFormattingOption &i, QUrl::ComponentFormattingOptions f) 344 //{ i = int(f); f; } 345 /+ #endif // Q_QDOC 346 347 #ifndef QT_NO_DATASTREAM 348 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QUrl &); 349 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUrl &); 350 #endif 351 352 #ifndef QT_NO_DEBUG_STREAM 353 Q_CORE_EXPORT QDebug operator<<(QDebug, const QUrl &); 354 #endif +/ 355