Commit 1aa3b4c6 authored by Richer Maximilien's avatar Richer Maximilien

Merge branch '199_gui_new_contract' into 'master'

199 gui new contract



See merge request !50
parents 8b0be187 c3c0a8f9
Pipeline #617 failed with stages
......@@ -2,5 +2,6 @@
<qresource prefix="/">
<file>userform/userform.ui</file>
<file>authform/authform.ui</file>
<file>contractform/contractform.ui</file>
</qresource>
</RCC>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CalculatorForm</class>
<widget class="QWidget" name="CalculatorForm">
<class>AuthForm</class>
<widget class="QWidget" name="AuthForm">
<property name="enabled">
<bool>true</bool>
</property>
......@@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>592</width>
<height>340</height>
<width>776</width>
<height>353</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -19,6 +19,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>650</width>
<height>350</height>
</size>
</property>
<property name="windowTitle">
<string>Calculator Builder</string>
</property>
......
package config
import (
"errors"
"io/ioutil"
"dfss/auth"
"github.com/visualfc/goqt/ui"
)
// 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.
//
// The callback is always called, even when an error occurs.
func PasswordDialog(callback func(err error, pwd string)) {
// Try to get private key
path := GetHomeDir() + KeyFile
data, err := ioutil.ReadFile(path)
if err != nil {
callback(err, "")
return
}
if !auth.IsPEMEncrypted(data) {
callback(nil, "")
return
}
dialog := ui.NewInputDialog()
dialog.SetWindowTitle("Encrypted private key")
dialog.SetLabelText("Please type your password to proceed:")
dialog.SetTextEchoMode(ui.QLineEdit_Password)
dialog.OnRejected(func() {
callback(errors.New("user rejected"), "")
})
dialog.OnAccepted(func() {
pwd := dialog.TextValue()
if pwd == "" {
pwd = " " // doing this to force the "wrong password" error msg
}
callback(nil, pwd)
})
dialog.Open()
}
package contractform
import (
"strings"
"dfss/dfssc/sign"
"dfss/gui/config"
"github.com/visualfc/goqt/ui"
)
type Widget struct {
*ui.QWidget
signers *ui.QPlainTextEdit
}
func NewWidget(conf *config.Config) *Widget {
file := ui.NewFileWithName(":/contractform/contractform.ui")
loader := ui.NewUiLoader()
form := loader.Load(file)
fileField := ui.NewLineEditFromDriver(form.FindChild("fileField"))
commentField := ui.NewPlainTextEditFromDriver(form.FindChild("commentField"))
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,
signers: signersField,
}
signersField.SetPlainText(conf.Email + "\n")
fileButton.OnClicked(func() {
filter := "Any (*.*)"
filename := ui.QFileDialogGetOpenFileNameWithParentCaptionDirFilterSelectedfilterOptions(form, "Select contract file", config.GetHomeDir(), filter, &filter, 0)
fileField.SetText(filename)
})
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
}
home := config.GetHomeDir()
err = sign.SendNewContract(
home+config.CAFile,
home+config.CertFile,
home+config.KeyFile,
conf.Platform,
pwd,
fileField.Text(),
commentField.ToPlainText(),
w.SignersList(),
)
if err != nil {
feedbackLabel.SetText(err.Error())
} else {
feedbackLabel.SetText("Contract successfully sent to signers!")
fileField.SetText("")
}
form.SetDisabled(false)
})
})
return w
}
func (w *Widget) SignersList() (list []string) {
rawList := strings.Split(w.signers.ToPlainText(), "\n")
for _, e := range rawList {
clean := strings.TrimSpace(e)
if clean != "" {
list = append(list, clean)
}
}
return
}
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ContractForm</class>
<widget class="QWidget" name="ContractForm">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>802</width>
<height>457</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>650</width>
<height>350</height>
</size>
</property>
<property name="windowTitle">
<string>Calculator Builder</string>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<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>
<property name="verticalSpacing">
<number>10</number>
</property>
<property name="leftMargin">
<number>50</number>
</property>
<property name="rightMargin">
<number>50</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="fileLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Contract file&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="fileField">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>(none)</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="fileButton">
<property name="text">
<string>Select</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="signersLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Signers&lt;br/&gt;&lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-style:italic;&quot;&gt;One per line&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPlainTextEdit" name="signersField"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="commentLabel">
<property name="text">
<string>Comment</string>
</property>
</widget>
</item>
<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>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -4,47 +4,42 @@ import (
"dfss"
"dfss/gui/authform"
"dfss/gui/config"
"dfss/gui/contractform"
"dfss/gui/userform"
"github.com/visualfc/goqt/ui"
)
const WIDTH = 650
const HEIGHT = 350
func main() {
// Load configuration
conf := config.Load()
// Start first window
ui.Run(func() {
layout := ui.NewVBoxLayout()
window := ui.NewMainWindow()
var newuser *userform.Widget
var newauth *authform.Widget
var newcontract *contractform.Widget
newauth = authform.NewWidget(&conf, func() {
layout.RemoveWidget(newauth)
newauth.Hide()
window.SetCentralWidget(newcontract)
})
newuser = userform.NewWidget(&conf, func(pwd string) {
layout.RemoveWidget(newuser)
newuser.Hide()
layout.AddWidget(newauth)
window.SetCentralWidget(newauth)
})
newcontract = contractform.NewWidget(&conf)
if conf.Authenticated {
// TODO
window.SetCentralWidget(newcontract)
} else if conf.Registered {
layout.AddWidget(newauth)
window.SetCentralWidget(newauth)
} else {
layout.AddWidget(newuser)
window.SetCentralWidget(newuser)
}
w := ui.NewWidget()
w.SetLayout(layout)
w.SetWindowTitle("DFSS Client v" + dfss.Version)
w.SetFixedSizeWithWidthHeight(WIDTH, HEIGHT)
w.Show()
window.SetWindowTitle("DFSS Client v" + dfss.Version)
window.Show()
})
}
......@@ -26,20 +26,16 @@ func NewWidget(conf *config.Config, onRegistered func(pw string)) *Widget {
registerButton := ui.NewPushButtonFromDriver(form.FindChild("registerButton"))
home := config.GetHomeDir()
fileDialog := ui.NewFileDialogWithParentCaptionDirectoryFilter(nil, "Select the CA file for the platform", home, "Root Certificates (*.pem);;Any (*.*)")
// Events
registerButton.OnClicked(func() {
form.SetDisabled(true)
feedbackLabel.SetText("Registration in progress...")
fileDialog.Open()
})
fileDialog.OnFileSelected(func(ca string) {
fileDialog.Hide()
filter := "Root Certificates (*.pem);;Any (*.*)"
caFilename := ui.QFileDialogGetOpenFileNameWithParentCaptionDirFilterSelectedfilterOptions(form, "Select the CA file for the platform", home, filter, &filter, 0)
caDest := home + config.CAFile
_ = copyCA(ca, caDest)
_ = copyCA(caFilename, caDest)
err := user.Register(
caDest,
......@@ -60,11 +56,6 @@ func NewWidget(conf *config.Config, onRegistered func(pw string)) *Widget {
form.SetDisabled(false)
})
fileDialog.OnRejected(func() {
form.SetDisabled(false)
feedbackLabel.SetText("Registration aborted.")
})
return &Widget{QWidget: form}
}
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CalculatorForm</class>
<widget class="QWidget" name="CalculatorForm">
<class>UserForm</class>
<widget class="QWidget" name="UserForm">
<property name="enabled">
<bool>true</bool>
</property>
......@@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>408</width>
<height>316</height>
<width>731</width>
<height>446</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -19,6 +19,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>650</width>
<height>350</height>
</size>
</property>
<property name="windowTitle">
<string>Calculator Builder</string>
</property>
......
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