forked from therecipe/qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqt.go
executable file
·93 lines (79 loc) · 1.88 KB
/
qt.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
package qt
import (
"encoding/hex"
"fmt"
"runtime"
"strings"
"sync"
_ "github.com/therecipe/qt/internal/android"
)
var (
signals = make(map[string]interface{})
signalsMutex = new(sync.Mutex)
ids int
)
func init() { runtime.LockOSThread() }
func ExistsSignal(name, signal string) bool {
signalsMutex.Lock()
var _, exists = signals[fmt.Sprintf("%v:%v", name, signal)]
signalsMutex.Unlock()
return exists
}
func GetSignal(name, signal string) interface{} {
if strings.HasSuffix(signal, ":destroyed") || strings.HasSuffix(signal, ":deleteLater") || strings.Contains(signal, ":~") {
defer DisconnectAllSignals(name)
}
var s interface{}
signalsMutex.Lock()
s = signals[fmt.Sprintf("%v:%v", name, signal)]
signalsMutex.Unlock()
return s
}
func ConnectSignal(name, signal string, function interface{}) {
signalsMutex.Lock()
signals[fmt.Sprintf("%v:%v", name, signal)] = function
signalsMutex.Unlock()
}
func DisconnectSignal(name, signal string) {
signalsMutex.Lock()
delete(signals, fmt.Sprintf("%v:%v", name, signal))
signalsMutex.Unlock()
}
func DisconnectAllSignals(name string) {
for entry := range signals {
if strings.HasPrefix(entry, fmt.Sprintf("%v:", name)) {
signalsMutex.Lock()
delete(signals, entry)
signalsMutex.Unlock()
}
}
}
func Identifier() string {
ids++
return fmt.Sprint(ids)
}
func DumpSignals() {
println("##############################\tDUMP_SIGNALTABLE_START\t##############################")
for entry := range signals {
println(entry)
}
println("##############################\tDUMP_SIGNALTABLE_END\t##############################")
}
func GoBoolToInt(b bool) int {
if b {
return 1
}
return 0
}
func Recovering(fn string) {
if recover() != nil {
println("recovered in:", fn)
}
}
func HexDecodeToString(in string) string {
var out, err = hex.DecodeString(in)
if err != nil {
return ""
}
return string(out)
}