diff --git a/src/nimqml.nim b/src/nimqml.nim index 033fe9b..013e606 100644 --- a/src/nimqml.nim +++ b/src/nimqml.nim @@ -32,6 +32,7 @@ include "nimqml/private/qabstracttablemodel.nim" include "nimqml/private/qresource.nim" include "nimqml/private/qdeclarative.nim" include "nimqml/private/nimqmlmacros.nim" +include "nimqml/private/singleinstance.nim" proc signal_handler*(receiver: pointer, signal: cstring, slot: cstring) = diff --git a/src/nimqml/private/dotherside.nim b/src/nimqml/private/dotherside.nim index 2beb56a..1098380 100644 --- a/src/nimqml/private/dotherside.nim +++ b/src/nimqml/private/dotherside.nim @@ -332,3 +332,8 @@ proc dos_escape_html(input: cstring): cstring {.cdecl, dynlib: dynLibName, impor proc dos_qurl_fromUserInput(input: cstring): cstring {.cdecl, dynlib: dynLibName, importc.} proc dos_qurl_host(host: cstring): cstring {.cdecl, dynlib: dynLibName, importc.} proc dos_qurl_replaceHostAndAddPath(url: cstring, newScheme: cstring, newHost: cstring, pathPrefix: cstring): cstring {.cdecl, dynlib: dynLibName, importc.} + +# SingleInstance +proc dos_singleinstance_create(uniqueName: cstring): DosQObject {.cdecl, dynlib: dynLibName, importc.} +proc dos_singleinstance_isfirst(vptr: DosQObject): bool {.cdecl, dynlib: dynLibName, importc.} +proc dos_singleinstance_delete(vptr: DosQObject) {.cdecl, dynlib: dynLibName, importc.} diff --git a/src/nimqml/private/nimqmltypes.nim b/src/nimqml/private/nimqmltypes.nim index 5950a7c..142d3c5 100644 --- a/src/nimqml/private/nimqmltypes.nim +++ b/src/nimqml/private/nimqmltypes.nim @@ -130,5 +130,7 @@ type Take, # The ownership is passed to the wrapper Clone # The node should be cloned + SingleInstance* = ref object of QObject + const UserRole* = 0x100 diff --git a/src/nimqml/private/singleinstance.nim b/src/nimqml/private/singleinstance.nim new file mode 100644 index 0000000..9c75059 --- /dev/null +++ b/src/nimqml/private/singleinstance.nim @@ -0,0 +1,17 @@ +proc setup*(self: SingleInstance, uniqueName: string) = + ## Setup a new SingleInstance + self.vptr = dos_singleinstance_create(uniqueName) + +proc delete*(self: SingleInstance) = + ## Delete the given SingleInstance + if self.vptr.isNil: + return + dos_singleinstance_delete(self.vptr) + self.vptr.resetToNil + +proc newSingleInstance*(uniqueName: string): SingleInstance = + new(result, delete) + result.setup(uniqueName) + +proc secondInstance*(self: SingleInstance): bool = + return not dos_singleinstance_isfirst(self.vptr)