Commit 44734fb9 authored by Loïck Bonniot's avatar Loïck Bonniot

[gui] Improve feedbacks and submits

parent 3676530b
......@@ -2,7 +2,7 @@ package authform
import (
"dfss/dfssc/user"
"dfss/gui/config"
"github.com/spf13/viper"
"github.com/visualfc/goqt/ui"
)
......@@ -17,7 +17,6 @@ func NewWidget(onAuth func()) *Widget {
form := loader.Load(file)
tokenField := ui.NewLineEditFromDriver(form.FindChild("tokenField"))
feedbackLabel := ui.NewLabelFromDriver(form.FindChild("feedbackLabel"))
authButton := ui.NewPushButtonFromDriver(form.FindChild("authButton"))
authButton.OnClicked(func() {
......@@ -28,7 +27,7 @@ func NewWidget(onAuth func()) *Widget {
)
form.SetDisabled(false)
if err != nil {
feedbackLabel.SetText(err.Error())
config.ShowMsgBox(err.Error(), true)
tokenField.SetFocus()
tokenField.SelectAll()
} else {
......
......@@ -93,33 +93,26 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="authButton">
<property name="text">
<string>Authenticate</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="feedbackLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="authButton">
<property name="text">
<string>Authenticate</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
......
package config
// This file handles basic feedback messages.
import (
"errors"
"io/ioutil"
......@@ -10,6 +12,20 @@ import (
"github.com/visualfc/goqt/ui"
)
// ShowMsgBox pops a new Qt Msg Box containing the appropriate message regarding the critical flag.
func ShowMsgBox(content string, critical bool) {
m := ui.NewMessageBox()
m.SetText(content)
if critical {
m.SetWindowTitle("Error")
m.SetIcon(ui.QMessageBox_Critical)
} else {
m.SetWindowTitle("Information")
m.SetIcon(ui.QMessageBox_Information)
}
m.Exec()
}
// PasswordDialog checks the current private key for any passphrase.
// If the key is protected, it spawns an inputDialog window to ask the user's passphrase,
// and then calls the callback function with the result.
......
......@@ -26,7 +26,6 @@ func NewWidget() *Widget {
signersField := ui.NewPlainTextEditFromDriver(form.FindChild("signersField"))
fileButton := ui.NewPushButtonFromDriver(form.FindChild("fileButton"))
createButton := ui.NewPushButtonFromDriver(form.FindChild("createButton"))
feedbackLabel := ui.NewLabelFromDriver(form.FindChild("feedbackLabel"))
w := &Widget{
QWidget: form,
......@@ -43,11 +42,9 @@ func NewWidget() *Widget {
createButton.OnClicked(func() {
form.SetDisabled(true)
feedbackLabel.SetText("Please wait...")
config.PasswordDialog(func(err error, pwd string) {
if err != nil {
form.SetDisabled(false)
feedbackLabel.SetText("Aborted.")
return // wrong key or rejection, aborting
}
......@@ -59,9 +56,9 @@ func NewWidget() *Widget {
)
if err != nil {
feedbackLabel.SetText(err.Error())
config.ShowMsgBox(err.Error(), true)
} else {
feedbackLabel.SetText("Contract successfully sent to signers!")
config.ShowMsgBox("Contract successfully sent to signers!", false)
fileField.SetText("")
}
form.SetDisabled(false)
......
......@@ -108,27 +108,20 @@
<item row="2" column="1">
<widget class="QPlainTextEdit" name="commentField"/>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="createButton">
<property name="text">
<string>Create contract</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="feedbackLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="createButton">
<property name="text">
<string>Create contract</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
......
......@@ -33,8 +33,9 @@ func main() {
// Start first window
ui.Run(func() {
qw := ui.NewMainWindow()
w := &window{
QMainWindow: ui.NewMainWindow(),
QMainWindow: qw,
}
if viper.GetBool("authenticated") {
......@@ -82,6 +83,9 @@ func (w *window) addActions() {
ui.QApplicationAboutQt()
})
userAct := ui.NewActionWithTextParent("Authenticated as "+viper.GetString("email")+" ("+viper.GetString("platform")+")", w)
userAct.SetDisabled(true)
fileMenu := w.MenuBar().AddMenuWithTitle("&File")
fileMenu.AddAction(newAct)
fileMenu.AddAction(openAct)
......@@ -92,6 +96,8 @@ func (w *window) addActions() {
helpMenu.AddAction(aboutAct)
helpMenu.AddSeparator()
helpMenu.AddAction(aboutQtAct)
w.MenuBar().AddAction(userAct)
}
func (w *window) setScreen(wi widget) {
......
......@@ -41,7 +41,7 @@ func (w *window) showShowContract(filename string) {
w.contract = showcontract.Load(filename)
if w.contract == nil {
w.showMsgBox("Unable to load file", true)
config.ShowMsgBox("Unable to load file", true)
return
}
w.setScreen(showcontract.NewWidget(w.contract, w.showSignForm))
......@@ -51,7 +51,7 @@ func (w *window) showSignForm() {
config.PasswordDialog(func(err error, pwd string) {
widget := signform.NewWidget(w.contract, pwd)
if widget == nil {
w.showMsgBox("Unable to start the signing procedure", true)
config.ShowMsgBox("Unable to start the signing procedure", true)
return
}
w.setScreen(widget)
......@@ -78,11 +78,11 @@ func (w *window) showFetchForm() {
err := sign.FetchContract(pwd, uuid, path)
if err != nil {
w.showMsgBox(err.Error(), true)
config.ShowMsgBox(err.Error(), true)
return
}
w.showMsgBox("Contract stored as "+path, false)
w.showShowContract(path)
config.ShowMsgBox("Contract stored as "+path, false)
})
dialog.OnFinished(func(_ int32) {
......@@ -90,16 +90,3 @@ func (w *window) showFetchForm() {
})
})
}
func (w *window) showMsgBox(content string, critical bool) {
m := ui.NewMessageBoxWithParent(w)
m.SetText(content)
if critical {
m.SetWindowTitle("Error")
m.SetIcon(ui.QMessageBox_Critical)
} else {
m.SetWindowTitle("Information")
m.SetIcon(ui.QMessageBox_Information)
}
m.Exec()
}
......@@ -23,8 +23,6 @@ func NewWidget(onRegistered func(pw string)) *Widget {
hostField := ui.NewLineEditFromDriver(form.FindChild("hostField"))
passwordField := ui.NewLineEditFromDriver(form.FindChild("passwordField"))
passwordField.SetEchoMode(ui.QLineEdit_Password)
feedbackLabel := ui.NewLabelFromDriver(form.FindChild("feedbackLabel"))
registerButton := ui.NewPushButtonFromDriver(form.FindChild("registerButton"))
home := viper.GetString("home_dir")
......@@ -33,7 +31,6 @@ func NewWidget(onRegistered func(pw string)) *Widget {
registerButton.OnClicked(func() {
form.SetDisabled(true)
feedbackLabel.SetText("Registration in progress...")
filter := "Root Certificates (*.pem);;Any (*.*)"
caFilename := ui.QFileDialogGetOpenFileNameWithParentCaptionDirFilterSelectedfilterOptions(form, "Select the CA file for the platform", home, filter, &filter, 0)
_ = copyCA(caFilename)
......@@ -44,7 +41,7 @@ func NewWidget(onRegistered func(pw string)) *Widget {
"", "", "", emailField.Text(), 2048,
)
if err != nil {
feedbackLabel.SetText(err.Error())
config.ShowMsgBox(err.Error(), true)
} else {
viper.Set("email", emailField.Text())
onRegistered(passwordField.Text())
......
......@@ -41,52 +41,35 @@
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>30</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>30</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>30</number>
</property>
<item>
<widget class="QLabel" name="welcomeLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:20pt; font-weight:600;&quot;&gt;Welcome on DFSS Client!&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-size:14pt;&quot;&gt;Please tell us some information to start.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
<height>100</height>
</size>
</property>
</spacer>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
</size>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:20pt; font-weight:600;&quot;&gt;Welcome on DFSS Client!&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-size:14pt;&quot;&gt;Please tell us some information to start.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="formAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="horizontalSpacing">
<number>30</number>
</property>
......@@ -153,30 +136,23 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="registerButton">
<property name="text">
<string>Register</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="feedbackLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="registerButton">
<property name="text">
<string>Register</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment