diff --git a/src/nimqml.nim b/src/nimqml.nim index 203feeb..21cb2ba 100644 --- a/src/nimqml.nim +++ b/src/nimqml.nim @@ -18,6 +18,7 @@ include private/qvariant.nim include private/qobject.nim include private/qqmlapplicationengine.nim include private/qapplication.nim +include private/qurl.nim #include private.nimqmltypes #var qobjectRegistry = initTable[ptr QObjectObj, bool]() #include private/qvariant.nim diff --git a/src/private/dotherside.nim b/src/private/dotherside.nim index 51b50f1..c696bcf 100644 --- a/src/private/dotherside.nim +++ b/src/private/dotherside.nim @@ -8,6 +8,7 @@ type DosQVariantArray* {.unchecked.} = array[0..0, DosQVariant] DosQMetaType = cint DosQMetaTypeArray* {.unchecked.} = array[0..0, DosQMetaType] + DosQUrl* = distinct pointer DosSignalDefinition* = object name*: cstring @@ -107,3 +108,8 @@ proc dos_qmetaobject_create*(vptr: var DosQmetaObject, slotDefinitions: DosSlotDefinitions, propertyDefinitions: DosPropertyDefinitions) {.cdecl, importc.} proc dos_qmetaobject_delete*(vptr: DosQmetaObject) {.cdecl, importc.} + +# QUrl +proc dos_qurl_create(vptr: var DosQUrl, url: cstring, parsingMode: cint) {.cdecl, importc.} +proc dos_qurl_delete(vptr: DosQUrl) {.cdecl, importc.} +proc dos_qurl_to_string(vptr: DosQUrl, str: var cstring) {.cdecl, importc.} diff --git a/src/private/nimqmltypes.nim b/src/private/nimqmltypes.nim index 62a11da..555b02e 100644 --- a/src/private/nimqmltypes.nim +++ b/src/private/nimqmltypes.nim @@ -71,3 +71,10 @@ type signals: seq[SignalDefinition] slots: seq[SlotDefinition] properties: seq[PropertyDefinition] + + QUrl* = ref object of RootObj + vptr: DosQUrl + + QUrlParsingMode {.pure.} = enum + Tolerant = 0.cint + Strict = 1.cint diff --git a/src/private/qurl.nim b/src/private/qurl.nim new file mode 100644 index 0000000..6d97a8b --- /dev/null +++ b/src/private/qurl.nim @@ -0,0 +1,23 @@ +proc setup*(self: QUrl, url: string, mode: QUrlParsingMode) = + ## Setup a new QUrl + dos_qurl_create(self.vptr, url.cstring, mode.cint) + +proc delete(self: QUrl) = + ## Delete a QUrl + if self.vptr.isNil: + return + debugMsg("QUrl", "delete") + dos_qurl_delete(self.vptr) + self.vptr.resetToNil + +proc newQUrl(url: string, mode: QUrlParsingMode = QUrlParsingMode.Tolerant): QUrl = + ## Create a new QUrl + new(result, delete) + result.setup(url, mode) + +proc toString(self: QUrl): string = + ## Return the url string + var str: cstring + dos_qurl_to_string(self.vptr, str) + result = $str + dos_chararray_delete(str)