-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbridges.go
134 lines (113 loc) · 4.28 KB
/
bridges.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"github.com/muesli/telephant/accounts/mastodon"
"github.com/therecipe/qt/core"
)
// UIBridge lets us trigger Go methods from QML
type UIBridge struct {
core.QObject
_ func(instance string) bool `slot:"connectButton"`
_ func(code string, redirectURI string) bool `slot:"authButton"`
_ func(body string) int `slot:"postLimitCount"`
_ func(replyid string, message string, visibility string) `slot:"postButton"`
_ func(id string) `slot:"deleteButton"`
_ func(id string) `slot:"shareButton"`
_ func(id string) `slot:"unshareButton"`
_ func(id string) `slot:"likeButton"`
_ func(id string) `slot:"unlikeButton"`
_ func(id string, follow bool) `slot:"followButton"`
_ func(url string) `slot:"uploadAttachment"`
_ func(id string) `slot:"loadConversation"`
_ func(id string) `slot:"loadAccount"`
_ func(token string) `slot:"search"`
_ func(token string) `slot:"tag"`
_ func(idx int64) `slot:"closePane"`
_ func(object *core.QObject) `slot:"registerToGo"`
_ func(objectName string) `slot:"deregisterToGo"`
}
// AccountBridge makes an account plugin available in QML
type AccountBridge struct {
core.QObject
_ string `property:"username"`
_ string `property:"name"`
_ string `property:"avatar"`
_ string `property:"profileURL"`
_ string `property:"profileID"`
_ int64 `property:"posts"`
_ int64 `property:"followCount"`
_ int64 `property:"followerCount"`
_ int64 `property:"postSizeLimit"`
_ string `property:"error"`
_ *core.QAbstractListModel `property:"panes"`
_ *core.QAbstractListModel `property:"notifications"`
_ *core.QAbstractListModel `property:"attachments"`
_ *core.QAbstractListModel `property:"conversation"`
_ *core.QAbstractListModel `property:"accountMessages"`
}
// ProfileBridge allows QML to access profile data
type ProfileBridge struct {
core.QObject
_ string `property:"username"`
_ string `property:"name"`
_ string `property:"avatar"`
_ string `property:"profileURL"`
_ string `property:"profileID"`
_ int64 `property:"posts"`
_ int64 `property:"followCount"`
_ int64 `property:"followerCount"`
_ bool `property:"following"`
_ bool `property:"followedBy"`
}
// ConfigBridge allows QML to access the app's config
type ConfigBridge struct {
core.QObject
_ bool `property:"firstRun"`
_ string `property:"authURL"`
_ string `property:"redirectURL"`
_ string `property:"theme"`
_ string `property:"style"`
_ int `property:"positionX"`
_ int `property:"positionY"`
_ int `property:"width"`
_ int `property:"height"`
_ string `property:"fontfamily"`
_ string `property:"emojifont"`
}
var (
// qmlObjects = make(map[string]*core.QObject)
uiBridge *UIBridge
accountBridge *AccountBridge
configBridge *ConfigBridge
profileBridge *ProfileBridge
tc *mastodon.Account
)
// setupQmlBridges initializes the QML bridges
func setupQmlBridges() {
configBridge = NewConfigBridge(nil)
accountBridge = NewAccountBridge(nil)
accountBridge.SetUsername("Telephant!")
uiBridge = NewUIBridge(nil)
uiBridge.ConnectConnectButton(connectToInstance)
uiBridge.ConnectAuthButton(authInstance)
uiBridge.ConnectPostLimitCount(postLimitCount)
uiBridge.ConnectPostButton(reply)
uiBridge.ConnectDeleteButton(deletePost)
uiBridge.ConnectShareButton(share)
uiBridge.ConnectUnshareButton(unshare)
uiBridge.ConnectLikeButton(like)
uiBridge.ConnectUnlikeButton(unlike)
uiBridge.ConnectFollowButton(follow)
uiBridge.ConnectUploadAttachment(uploadAttachment)
uiBridge.ConnectLoadConversation(loadConversation)
uiBridge.ConnectLoadAccount(loadAccount)
uiBridge.ConnectSearch(search)
uiBridge.ConnectTag(tag)
uiBridge.ConnectClosePane(closePane)
profileBridge = NewProfileBridge(nil)
/* uiBridge.ConnectRegisterToGo(func(object *core.QObject) {
qmlObjects[object.ObjectName()] = object
})
uiBridge.ConnectDeregisterToGo(func(objectName string) {
qmlObjects[objectName] = nil
}) */
}