Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpcs
dfss
Commits
d93fd42f
Commit
d93fd42f
authored
Apr 12, 2016
by
Loïck Bonniot
Browse files
[gui] Add logic for new contract form
parent
bae90ef4
Pipeline
#578
passed with stage
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
gui/config/pwddialog.go
0 → 100644
View file @
d93fd42f
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
()
}
gui/contractform/contractform.go
View file @
d93fd42f
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
{
...
...
@@ -14,5 +19,70 @@ func NewWidget(conf *config.Config) *Widget {
loader
:=
ui
.
NewUiLoader
()
form
:=
loader
.
Load
(
file
)
return
&
Widget
{
QWidget
:
form
}
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
}
gui/contractform/contractform.ui
View file @
d93fd42f
...
...
@@ -68,6 +68,9 @@
<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>
...
...
@@ -88,7 +91,7 @@
<item
row=
"1"
column=
"0"
>
<widget
class=
"QLabel"
name=
"signersLabel"
>
<property
name=
"text"
>
<string>
<
html
><
head/
><
body
><
p
><
span style=
"
font-weight:600;
">
Signers
<
br/
><
/span
><
span style=
"
font-size:8pt; font-style:italic;
">
Space-separated
<
/span
><
/p
><
/body
><
/html
>
</string>
<string>
<
html
><
head/
><
body
><
p
><
span style=
"
font-weight:600;
">
Signers
<
br/
><
/span
><
span style=
"
font-size:8pt; font-style:italic;
">
One per line
<
/span
><
/p
><
/body
><
/html
>
</string>
</property>
</widget>
</item>
...
...
@@ -115,7 +118,7 @@
</property>
</widget>
</item>
<item
row=
"
4
"
column=
"1"
>
<item
row=
"
3
"
column=
"1"
>
<widget
class=
"QLabel"
name=
"feedbackLabel"
>
<property
name=
"text"
>
<string/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment