Move LoginView to own struct
This commit is contained in:
parent
b93dea2e1c
commit
497ae566c0
@ -36,6 +36,7 @@ type GomuksUI interface {
|
||||
SetView(name View)
|
||||
InitViews() tview.Primitive
|
||||
MainView() MainView
|
||||
LoginView() LoginView
|
||||
}
|
||||
|
||||
type MainView interface {
|
||||
@ -51,3 +52,7 @@ type MainView interface {
|
||||
ProcessMessageEvent(evt *gomatrix.Event) (*widget.RoomView, *types.Message)
|
||||
ProcessMembershipEvent(evt *gomatrix.Event, new bool) (*widget.RoomView, *types.Message)
|
||||
}
|
||||
|
||||
type LoginView interface {
|
||||
|
||||
}
|
||||
|
6
ui/ui.go
6
ui/ui.go
@ -28,7 +28,7 @@ type GomuksUI struct {
|
||||
views *tview.Pages
|
||||
|
||||
mainView *MainView
|
||||
loginView *tview.Form
|
||||
loginView *LoginView
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -63,3 +63,7 @@ func (ui *GomuksUI) InitViews() tview.Primitive {
|
||||
func (ui *GomuksUI) MainView() ifc.MainView {
|
||||
return ui.mainView
|
||||
}
|
||||
|
||||
func (ui *GomuksUI) LoginView() ifc.LoginView {
|
||||
return ui.loginView
|
||||
}
|
||||
|
@ -17,39 +17,64 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"maunium.net/go/gomuks/config"
|
||||
"maunium.net/go/gomuks/interface"
|
||||
"maunium.net/go/gomuks/ui/debug"
|
||||
"maunium.net/go/gomuks/ui/widget"
|
||||
"maunium.net/go/tview"
|
||||
)
|
||||
|
||||
type LoginView struct {
|
||||
*tview.Form
|
||||
|
||||
homeserver *widget.AdvancedInputField
|
||||
username *widget.AdvancedInputField
|
||||
password *widget.AdvancedInputField
|
||||
|
||||
matrix ifc.MatrixContainer
|
||||
config *config.Config
|
||||
parent *GomuksUI
|
||||
}
|
||||
|
||||
func (ui *GomuksUI) NewLoginView() tview.Primitive {
|
||||
view := &LoginView{
|
||||
Form: tview.NewForm(),
|
||||
|
||||
homeserver: widget.NewAdvancedInputField(),
|
||||
username: widget.NewAdvancedInputField(),
|
||||
password: widget.NewAdvancedInputField(),
|
||||
|
||||
matrix: ui.gmx.MatrixContainer(),
|
||||
config: ui.gmx.Config(),
|
||||
parent: ui,
|
||||
}
|
||||
hs := ui.gmx.Config().HS
|
||||
if len(hs) == 0 {
|
||||
hs = "https://matrix.org"
|
||||
}
|
||||
view.homeserver.SetLabel("Homeserver").SetText(hs).SetFieldWidth(30)
|
||||
view.username.SetLabel("Username").SetText(ui.gmx.Config().UserID).SetFieldWidth(30)
|
||||
view.password.SetLabel("Password").SetMaskCharacter('*').SetFieldWidth(30)
|
||||
|
||||
homeserver := widget.NewAdvancedInputField().SetLabel("Homeserver").SetText(hs).SetFieldWidth(30)
|
||||
username := widget.NewAdvancedInputField().SetLabel("Username").SetText(ui.gmx.Config().UserID).SetFieldWidth(30)
|
||||
password := widget.NewAdvancedInputField().SetLabel("Password").SetMaskCharacter('*').SetFieldWidth(30)
|
||||
|
||||
ui.loginView = tview.NewForm()
|
||||
ui.loginView.
|
||||
AddFormItem(homeserver).AddFormItem(username).AddFormItem(password).
|
||||
AddButton("Log in", ui.login).
|
||||
view.
|
||||
AddFormItem(view.homeserver).AddFormItem(view.username).AddFormItem(view.password).
|
||||
AddButton("Log in", view.Login).
|
||||
AddButton("Quit", ui.gmx.Stop).
|
||||
SetButtonsAlign(tview.AlignCenter).
|
||||
SetBorder(true).SetTitle("Log in to Matrix")
|
||||
|
||||
ui.loginView = view
|
||||
|
||||
return widget.Center(45, 11, ui.loginView)
|
||||
}
|
||||
|
||||
func (ui *GomuksUI) login() {
|
||||
hs := ui.loginView.GetFormItem(0).(*widget.AdvancedInputField).GetText()
|
||||
mxid := ui.loginView.GetFormItem(1).(*widget.AdvancedInputField).GetText()
|
||||
password := ui.loginView.GetFormItem(2).(*widget.AdvancedInputField).GetText()
|
||||
func (view *LoginView) Login() {
|
||||
hs := view.homeserver.GetText()
|
||||
mxid := view.username.GetText()
|
||||
password := view.password.GetText()
|
||||
|
||||
debug.Printf("Logging into %s as %s...", hs, mxid)
|
||||
ui.gmx.Config().HS = hs
|
||||
mx := ui.gmx.MatrixContainer()
|
||||
debug.Print("Connect result:", mx.InitClient())
|
||||
debug.Print("Login result:", mx.Login(mxid, password))
|
||||
view.config.HS = hs
|
||||
debug.Print("Connect result:", view.matrix.InitClient())
|
||||
debug.Print("Login result:", view.matrix.Login(mxid, password))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user