Commit 6e5356ea authored by Loïck Bonniot's avatar Loïck Bonniot

[gui] Add check local file feature

parent 18230908
Pipeline #1734 passed with stage
......@@ -5,12 +5,17 @@ import (
"io/ioutil"
"dfss/dfssc/common"
"dfss/dfssc/sign"
"dfss/dfssp/contract"
dialog "dfss/gui/common"
"github.com/spf13/viper"
"github.com/visualfc/goqt/ui"
)
type Widget struct {
*ui.QWidget
checked bool
}
func NewWidget(contract *contract.JSON, onSign func()) *Widget {
......@@ -23,17 +28,59 @@ func NewWidget(contract *contract.JSON, onSign func()) *Widget {
signersField := ui.NewLabelFromDriver(form.FindChild("signersField"))
informationField := ui.NewLabelFromDriver(form.FindChild("informationField"))
signButton := ui.NewPushButtonFromDriver(form.FindChild("signButton"))
fileButton := ui.NewPushButtonFromDriver(form.FindChild("fileButton"))
fileField.SetText(contract.File.Name)
commentField.SetText(contract.Comment)
signersField.SetText(getSignersString(contract))
informationField.SetText("Contract #" + contract.UUID + "\nCreated on " + contract.Date.Format("2006-01-02 15:04:05 MST") + ".")
signButton.OnClicked(onSign)
return &Widget{
w := &Widget{
QWidget: form,
checked: false,
}
fileButton.OnClicked(func() {
home := viper.GetString("home_dir")
filter := "Any (*.*)"
filename := ui.QFileDialogGetOpenFileNameWithParentCaptionDirFilterSelectedfilterOptions(nil, "Select the local contract to compare to "+contract.File.Name, home, filter, &filter, 0)
if filename == "" {
return
}
ok, err := sign.CheckContractHash(filename, contract.File.Hash)
if err != nil {
dialog.ShowMsgBox(err.Error(), true)
} else if !ok {
dialog.ShowMsgBox("The provided file is not the one hashed during contract creation, beware!", true)
} else {
dialog.ShowMsgBox("The provided file is correct for this contract!", false)
w.checked = true
}
})
signButton.OnClicked(func() {
if !w.checked { // If the contract file has not been checked locally
box := ui.NewMessageBox()
box.SetWindowTitle("Warning")
box.SetText("Do you want to check your local contract file before signing this DFSS contract?")
box.SetIcon(ui.QMessageBox_Question)
box.AddButton(ui.QMessageBox_Yes)
box.AddButton(ui.QMessageBox_No)
box.OnButtonClicked(func(b *ui.QAbstractButton) {
if box.ButtonRole(b) == ui.QMessageBox_YesRole {
fileButton.Click()
} else {
onSign()
}
})
box.Show()
} else {
onSign()
}
})
return w
}
func (w *Widget) Q() *ui.QWidget {
......
......@@ -106,9 +106,6 @@
</item>
<item>
<widget class="QToolButton" name="fileButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Check with local</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