1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-10-31 19:44:23 +00:00
cchat-gtk/internal/ui/ui.go

81 lines
1.9 KiB
Go
Raw Normal View History

2020-05-26 06:51:06 +00:00
package ui
import (
"github.com/diamondburned/cchat"
"github.com/diamondburned/cchat-gtk/internal/gts"
2020-06-04 23:00:41 +00:00
"github.com/diamondburned/cchat-gtk/internal/keyring"
"github.com/diamondburned/cchat-gtk/internal/log"
"github.com/diamondburned/cchat-gtk/internal/ui/service"
"github.com/diamondburned/cchat-gtk/internal/ui/service/auth"
"github.com/diamondburned/cchat-gtk/internal/ui/service/session"
2020-05-28 19:26:55 +00:00
"github.com/diamondburned/cchat-gtk/internal/ui/service/session/server"
2020-05-26 06:51:06 +00:00
"github.com/gotk3/gotk3/gtk"
)
const LeftWidth = 220
2020-06-04 23:00:41 +00:00
type App struct {
2020-05-26 06:51:06 +00:00
window *window
header *header
2020-06-04 23:00:41 +00:00
// used to keep track of what row to highlight and unhighlight
lastRowHighlighter func(bool)
2020-05-26 06:51:06 +00:00
}
var (
2020-06-04 23:00:41 +00:00
_ gts.Windower = (*App)(nil)
_ gts.Headerer = (*App)(nil)
_ service.Controller = (*App)(nil)
2020-05-26 06:51:06 +00:00
)
2020-06-04 23:00:41 +00:00
func NewApplication() *App {
app := &App{
2020-05-26 06:51:06 +00:00
window: newWindow(),
header: newHeader(),
}
return app
}
2020-06-04 23:00:41 +00:00
func (app *App) AddService(svc cchat.Service) {
var container = app.window.Services.AddService(svc, app)
// Attempt to restore sessions asynchronously.
keyring.RestoreSessions(svc, container.AddSession)
2020-05-28 19:26:55 +00:00
}
2020-06-04 23:00:41 +00:00
func (app *App) MessageRowSelected(ses *session.Row, srv *server.Row, smsg cchat.ServerMessage) {
// Is there an old row that we should unhighlight?
if app.lastRowHighlighter != nil {
app.lastRowHighlighter(false)
}
// Set the new row and highlight it.
app.lastRowHighlighter = srv.Button.SetActive
app.lastRowHighlighter(true)
log.Println("Breadcrumb:")
// Show the messages.
app.window.MessageView.JoinServer(ses.Session, smsg)
}
func (app *App) AuthenticateSession(container *service.Container, svc cchat.Service) {
auth.NewDialog(svc.Name(), svc.Authenticate(), func(ses cchat.Session) {
container.AddSession(ses)
// Save all sessions.
for _, err := range keyring.SaveSessions(svc, container.Sessions()) {
log.Error(err)
}
})
2020-05-26 06:51:06 +00:00
}
2020-06-04 23:00:41 +00:00
func (app *App) Header() gtk.IWidget {
2020-05-26 06:51:06 +00:00
return app.header
}
2020-06-04 23:00:41 +00:00
func (app *App) Window() gtk.IWidget {
2020-05-26 06:51:06 +00:00
return app.window
}