-
Notifications
You must be signed in to change notification settings - Fork 1
/
tab_server.go
123 lines (110 loc) · 3.37 KB
/
tab_server.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
package main
import (
"fmt"
"github.com/lxn/walk"
"github.com/lxn/win"
)
type tabServer struct {
tabChatbox
}
// FIXME(tso): having these here just to satisfy the interface seems wrong.
func (t *tabServer) NickColor(nick string) int { return Black }
func (t *tabServer) Send(message string) {}
func (t *tabServer) Update(servState *serverState) {
if t.tabTitle != servState.networkName {
t.tabTitle = servState.networkName
}
mw.WindowBase.Synchronize(func() {
t.tabPage.SetTitle(t.Title())
if t.HasFocus() {
SetStatusBarIcon(t.statusIcon)
SetStatusBarText(t.statusText)
}
})
switch servState.connState {
case CONNECTION_EMPTY:
t.disconnected = true
t.statusIcon = "chopsuey.ico"
t.statusText = "not connected to any network"
case DISCONNECTED:
t.disconnected = true
t.statusIcon = "res/conn_pcs_no_network.ico"
t.statusText = "disconnected x_x"
Println(CLIENT_ERROR, T(servState.AllTabs()...), now(), t.statusText)
case CONNECTING:
t.disconnected = true
t.statusIcon = "res/conn_pcs_off_on.ico"
t.statusText = "connecting to " + servState.networkName + "..."
Println(CLIENT_MESSAGE, T(servState.AllTabs()...), now(), t.statusText)
case CONNECTION_ERROR:
t.disconnected = true
t.statusIcon = "res/conn_pcs_no_network.ico"
t.statusText = "couldn't connect: " + servState.lastError.Error()
Println(CLIENT_ERROR, T(servState.AllTabs()...), now(), t.statusText)
case CONNECTION_START:
t.disconnected = false
t.statusIcon = "res/conn_pcs_on_off.ico"
t.statusText = "connected to " + servState.networkName
Println(CLIENT_MESSAGE, T(servState.AllTabs()...), now(), t.statusText)
case CONNECTED:
t.statusIcon = "res/network_three_pcs.ico"
t.statusText = fmt.Sprintf("%s connected to %s", servState.user.nick, servState.networkName)
t.disconnected = false
}
for _, chanState := range servState.channels {
chanState.tab.Update(servState, chanState)
}
for _, pmState := range servState.privmsgs {
pmState.tab.Update(servState, pmState)
}
if servState.channelList != nil {
servState.channelList.Update(servState)
}
SetSystrayContextMenu()
}
func newServerTab(servConn *serverConnection, servState *serverState) *tabServer {
t := &tabServer{}
t.tabTitle = servState.networkName
t.chatlogger = NewChatLogger(servState.networkName)
mw.WindowBase.Synchronize(func() {
var err error
t.tabPage, err = walk.NewTabPage()
checkErr(err)
t.tabPage.SetTitle(t.tabTitle)
t.tabPage.SetLayout(walk.NewVBoxLayout())
t.textBuffer, err = NewRichEdit(t.tabPage)
checkErr(err)
t.textBuffer.KeyPress().Attach(globalKeyHandler)
t.textInput = NewTextInput(t)
checkErr(t.tabPage.Children().Add(t.textInput))
// remove borders
win.SetWindowLong(t.textInput.Handle(), win.GWL_EXSTYLE, 0)
servState.tab = t
checkErr(tabWidget.Pages().Add(t.tabPage))
index := tabWidget.Pages().Index(t.tabPage)
checkErr(tabWidget.SetCurrentIndex(index))
tabWidget.SaveState()
t.Focus()
})
mw.Synchronize(func() {
applyThemeToTab(t)
})
return t
}
func newEmptyServerTab() *tabWithContext {
empty := &tabContext{}
servState := &serverState{
connState: CONNECTION_EMPTY,
user: &userState{
nick: "nobody",
},
channels: map[string]*channelState{},
privmsgs: map[string]*privmsgState{},
}
empty.servState = servState
ctx := tabMan.Create(empty, tabMan.Len())
tab := newServerTab(nil, servState)
ctx.tab = tab
servState.tab = tab
return ctx
}