-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtelephant.go
192 lines (166 loc) · 4.75 KB
/
telephant.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package main
import (
"flag"
"log"
"os"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/qml"
"github.com/therecipe/qt/quickcontrols2"
gap "github.com/muesli/go-app-paths"
"github.com/muesli/telephant/accounts/mastodon"
)
var (
debug = flag.Bool("debug", true, "Enable debug output")
config Config
configFile string
notificationModel = NewMessageModel(nil)
conversationModel = NewMessageModel(nil)
accountMessagesModel = NewMessageModel(nil)
attachmentModel = NewAttachmentModel(nil)
paneModel = NewPaneModel(nil)
)
// closePane closes a pane
func closePane(idx int64) {
debugln("Closing pane", idx)
paneModel.RemovePane(int(idx))
}
// runApp loads and executes the QML UI
func runApp(config Config) {
var theme string
switch config.Theme {
case "System":
theme = ""
case "Light":
theme = "Default"
default:
theme = config.Theme
}
if theme != "" {
quickcontrols2.QQuickStyle_SetStyle(theme)
}
app := qml.NewQQmlApplicationEngine(nil)
app.RootContext().SetContextProperty("uiBridge", uiBridge)
app.RootContext().SetContextProperty("accountBridge", accountBridge)
app.RootContext().SetContextProperty("profileBridge", profileBridge)
app.RootContext().SetContextProperty("settings", configBridge)
app.Load(core.NewQUrl3("qrc:/qml/telephant.qml", 0))
gui.QGuiApplication_Exec()
}
// setupMastodon starts a new Mastodon client and sets up event handling & models for it
func setupMastodon(config Account) {
tc = mastodon.NewAccount(config.Instance, config.Token, config.ClientID, config.ClientSecret)
postModel := NewMessageModel(nil)
// Notifications model must the first model to be added
// It will always be displayed right-most
paneModel.clear()
{
var pane = NewPane(nil)
pane.ID = "notifications"
pane.Name = "Notifications"
pane.Sticky = true
pane.Default = true
pane.Model = notificationModel
paneModel.AddPane(pane)
}
{
var pane = NewPane(nil)
pane.ID = "home"
pane.Name = "Messages"
pane.Default = true
pane.Model = postModel
paneModel.AddPane(pane)
}
panes := tc.Panes()
for _, p := range panes {
if !p.Default {
continue
}
model := NewMessageModel(nil)
evchan := make(chan interface{})
go handleEvents(evchan, model)
p.Stream(evchan)
var pane = NewPane(nil)
pane.ID = p.ID
pane.Name = p.Title
pane.Default = p.Default
pane.Model = model
paneModel.AddPane(pane)
}
evchan := make(chan interface{})
go handleEvents(evchan, postModel)
go tc.Run(evchan)
}
func debugln(s ...interface{}) {
if *debug {
log.Println(s...)
}
}
func main() {
flag.Parse()
core.QCoreApplication_SetApplicationName("Telephant")
core.QCoreApplication_SetOrganizationName("fribbledom.com")
core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
ga := gui.NewQGuiApplication(len(os.Args), os.Args)
ga.SetWindowIcon(gui.NewQIcon5(":/qml/images/telephant_logo.png"))
setupQmlBridges()
// load config
scope := gap.NewScope(gap.User, "telephant")
configDir, err := scope.ConfigPath("")
if err != nil {
panic(err)
}
os.MkdirAll(configDir, 0700)
configFile, err = scope.ConfigPath("telephant.conf")
if err != nil {
panic(err)
}
config = LoadConfig(configFile)
if config.Theme == "" {
config.Theme = "Material"
}
if config.Style == "" {
config.Style = "Dark"
}
if config.FontFamily == "" {
config.FontFamily = "Noto Sans"
}
if config.EmojiFont == "" {
config.EmojiFont = "Noto Color Emoji"
}
configBridge.SetTheme(config.Theme)
configBridge.SetStyle(config.Style)
configBridge.SetFirstRun(config.FirstRun)
configBridge.SetPositionX(config.PositionX)
configBridge.SetPositionY(config.PositionY)
configBridge.SetWidth(config.Width)
configBridge.SetHeight(config.Height)
configBridge.SetFontfamily(config.FontFamily)
configBridge.SetEmojifont(config.EmojiFont)
accountBridge.SetUsername("Not connected...")
accountBridge.SetNotifications(notificationModel)
accountBridge.SetAttachments(attachmentModel)
accountBridge.SetConversation(conversationModel)
accountBridge.SetAccountMessages(accountMessagesModel)
accountBridge.SetAvatar("qrc:/qml/images/telephant_logo.png")
accountBridge.SetPosts(0)
accountBridge.SetFollowCount(0)
accountBridge.SetFollowerCount(0)
accountBridge.SetPostSizeLimit(0)
accountBridge.SetPanes(paneModel)
if len(config.Account) > 0 {
setupMastodon(config.Account[0])
}
runApp(config)
// save config
config.Theme = configBridge.Theme()
config.Style = configBridge.Style()
config.PositionX = configBridge.PositionX()
config.PositionY = configBridge.PositionY()
config.Width = configBridge.Width()
config.Height = configBridge.Height()
config.FirstRun = false
config.FontFamily = configBridge.Fontfamily()
config.EmojiFont = configBridge.Emojifont()
SaveConfig(configFile, config)
}