aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-03-22 23:03:45 +0200
committerTulir Asokan <tulir@maunium.net>2018-03-22 23:03:45 +0200
commit497ae566c0fdc3583272a49798d190ebca99e02b (patch)
tree49261a7c977c3c8c6db6995dfaf204699e709ea2
parentb93dea2e1c18752b89b09790b390e54c33dda1bf (diff)
Move LoginView to own struct
-rw-r--r--interface/ui.go5
-rw-r--r--ui/ui.go6
-rw-r--r--ui/view-login.go57
3 files changed, 51 insertions, 17 deletions
diff --git a/interface/ui.go b/interface/ui.go
index 9b2d0f1..ada1cc0 100644
--- a/interface/ui.go
+++ b/interface/ui.go
@@ -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 {
+
+}
diff --git a/ui/ui.go b/ui/ui.go
index 131a8c1..16321b8 100644
--- a/ui/ui.go
+++ b/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
+}
diff --git a/ui/view-login.go b/ui/view-login.go
index 4ae673c..0707b2d 100644
--- a/ui/view-login.go
+++ b/ui/view-login.go
@@ -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))
}