telephant/bridges.go

66 lines
1.6 KiB
Go
Raw Normal View History

2017-08-29 05:09:17 +00:00
package main
import (
2019-05-01 15:15:56 +00:00
"github.com/muesli/chirp/accounts/mastodon"
2017-08-29 05:09:17 +00:00
"github.com/therecipe/qt/core"
)
// UIBridge lets us trigger Go methods from QML
type UIBridge struct {
core.QObject
_ func(replyid string, message string) `slot:"postButton"`
_ func(id string) `slot:"shareButton"`
2017-08-29 05:09:17 +00:00
_ func(id string) `slot:"likeButton"`
_ 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:"avatar"`
2019-05-02 08:37:29 +00:00
_ string `property:"profileURL"`
2017-08-29 05:09:17 +00:00
_ *core.QAbstractListModel `property:"messages"`
_ *core.QAbstractListModel `property:"notifications"`
}
// ConfigBridge allows QML to access the app's config
type ConfigBridge struct {
core.QObject
_ string `property:"style"`
}
var (
// qmlObjects = make(map[string]*core.QObject)
uiBridge *UIBridge
accountBridge *AccountBridge
configBridge *ConfigBridge
2019-05-01 15:15:56 +00:00
tc *mastodon.Account
2017-08-29 05:09:17 +00:00
)
// setupQmlBridges initializes the QML bridges
func setupQmlBridges() {
configBridge = NewConfigBridge(nil)
accountBridge = NewAccountBridge(nil)
accountBridge.SetUsername("Chirp!")
uiBridge = NewUIBridge(nil)
uiBridge.ConnectPostButton(reply)
uiBridge.ConnectShareButton(share)
2017-08-29 05:09:17 +00:00
uiBridge.ConnectLikeButton(like)
/* uiBridge.ConnectRegisterToGo(func(object *core.QObject) {
qmlObjects[object.ObjectName()] = object
})
uiBridge.ConnectDeregisterToGo(func(objectName string) {
qmlObjects[objectName] = nil
}) */
}