forked from go-qml/qml
-
Notifications
You must be signed in to change notification settings - Fork 7
/
qml.go
116 lines (100 loc) · 3.19 KB
/
qml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package qml
// #include <stdlib.h>
//
// #include "capi.h"
//
import "C"
import (
"errors"
"unsafe"
"github.com/limetext/qml-go/internal/util"
)
func AddLibraryPath(path string) {
cpath, cpathLen := util.UnsafeStringData(path)
RunMain(func() {
C.coreAddLibraryPath((*C.char)(cpath), C.int(cpathLen))
})
}
func SetApplicationName(name string) {
cname, cnameLen := util.UnsafeStringData(name)
RunMain(func() {
C.coreSetApplicationName((*C.char)(cname), C.int(cnameLen))
})
}
func SetApplicationVersion(version string) {
cversion, cversionLen := util.UnsafeStringData(version)
RunMain(func() {
C.coreSetApplicationVersion((*C.char)(cversion), C.int(cversionLen))
})
}
func SetOrganizationDomain(domain string) {
cdomain, cdomainLen := util.UnsafeStringData(domain)
RunMain(func() {
C.coreSetOrganizationDomain((*C.char)(cdomain), C.int(cdomainLen))
})
}
func SetOrganizationName(name string) {
cname, cnameLen := util.UnsafeStringData(name)
RunMain(func() {
C.coreSetOrganizationName((*C.char)(cname), C.int(cnameLen))
})
}
func SetApplicationDisplayName(name string) {
cname, cnameLen := util.UnsafeStringData(name)
RunMain(func() {
C.guiappSetApplicationDisplayName((*C.char)(cname), C.int(cnameLen))
})
}
// Qt 5.7
// func SetDesktopFileName(path string) {
// cpath, cpathLen := util.UnsafeStringData(path)
// RunMain(func() {
// C.guiappSetDesktopFileName((*C.char)(cpath), C.int(cpathLen))
// })
// }
func SetWindowIcon(path string) {
cpath, cpathLen := util.UnsafeStringData(path)
RunMain(func() {
C.guiappSetWindowIcon((*C.char)(cpath), C.int(cpathLen))
})
}
func cerror(cerr *C.error) error {
err := errors.New(C.GoString((*C.char)(unsafe.Pointer(cerr))))
C.free(unsafe.Pointer(cerr))
return err
}
func cmust(cerr *C.error) {
if cerr != nil {
panic(cerror(cerr).Error())
}
}
// TODO Signal emitting support for go values.
// LoadResources registers all resources in the provided resources collection,
// making them available to be loaded by any Engine and QML file.
// Registered resources are made available under "qrc:///some/path", where
// "some/path" is the path the resource was added with.
func LoadResources(r *Resources) {
var base unsafe.Pointer
if len(r.sdata) > 0 {
base = *(*unsafe.Pointer)(unsafe.Pointer(&r.sdata))
} else if len(r.bdata) > 0 {
base = *(*unsafe.Pointer)(unsafe.Pointer(&r.bdata))
}
tree := (*C.char)(unsafe.Pointer(uintptr(base) + uintptr(r.treeOffset)))
name := (*C.char)(unsafe.Pointer(uintptr(base) + uintptr(r.nameOffset)))
data := (*C.char)(unsafe.Pointer(uintptr(base) + uintptr(r.dataOffset)))
C.registerResourceData(C.int(r.version), tree, name, data)
}
// UnloadResources unregisters all previously registered resources from r.
func UnloadResources(r *Resources) {
var base unsafe.Pointer
if len(r.sdata) > 0 {
base = *(*unsafe.Pointer)(unsafe.Pointer(&r.sdata))
} else if len(r.bdata) > 0 {
base = *(*unsafe.Pointer)(unsafe.Pointer(&r.bdata))
}
tree := (*C.char)(unsafe.Pointer(uintptr(base) + uintptr(r.treeOffset)))
name := (*C.char)(unsafe.Pointer(uintptr(base) + uintptr(r.nameOffset)))
data := (*C.char)(unsafe.Pointer(uintptr(base) + uintptr(r.dataOffset)))
C.unregisterResourceData(C.int(r.version), tree, name, data)
}