-
Notifications
You must be signed in to change notification settings - Fork 14
/
mynaqt.go
164 lines (144 loc) · 4.51 KB
/
mynaqt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package main
import (
_ "bytes"
_ "errors"
"fmt"
"github.com/jpki/myna/libmyna"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/widgets"
"github.com/urfave/cli"
"os"
)
func main() {
app := cli.NewApp()
app.Name = "mynaqt"
app.Description = "マイナクライアント(GUI)"
app.Author = "HAMANO Tsukasa"
app.Email = "hamano@osstech.co.jp"
app.Version = libmyna.Version
app.Action = mynaqt
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug, d",
Usage: "詳細出力",
},
}
app.Run(os.Args)
}
var ctx *cli.Context
func mynaqt(c *cli.Context) error {
ctx = c
app := widgets.NewQApplication(len(os.Args), os.Args)
core.QCoreApplication_SetApplicationName(c.App.Name)
core.QCoreApplication_SetApplicationVersion(c.App.Version)
window := widgets.NewQMainWindow(nil, 0)
window.SetWindowTitle(c.App.Description)
window.SetMinimumSize2(500, 0)
menu := window.MenuBar().AddMenu2("Menu")
actionAbout := menu.AddAction("About")
actionAbout.ConnectTriggered(func(checked bool) {
NewAboutDialog().Show()
})
actionQuit := menu.AddAction("終了")
actionQuit.ConnectTriggered(func(checked bool) {
window.Close()
})
hBox := widgets.NewQHBoxLayout()
vBox := widgets.NewQVBoxLayout()
logoLabel := widgets.NewQLabel(nil, 0)
logoData, err := Asset("usagi.png")
if err != nil {
return err
}
pixmap := gui.NewQPixmap()
pixmap.LoadFromData(string(logoData), uint(len(logoData)),
"PNG", core.Qt__AutoColor)
logoLabel.SetPixmap(pixmap)
hBox.AddWidget(logoLabel, 0, 0)
hBox.AddLayout(vBox, 1)
widget := widgets.NewQWidget(nil, 0)
widget.SetLayout(hBox)
buttonCardCheck := widgets.NewQPushButton2("動作確認", widget)
buttonCardCheck.ConnectClicked(onCardCheck)
vBox.AddWidget(buttonCardCheck, 0, 0)
buttonCardInfo := widgets.NewQPushButton2("券面事項確認", widget)
buttonCardInfo.ConnectClicked(onCardInfo)
vBox.AddWidget(buttonCardInfo, 0, 0)
buttonShowCert := widgets.NewQPushButton2("証明書表示", widget)
buttonShowCert.ConnectClicked(onShowCert)
vBox.AddWidget(buttonShowCert, 0, 0)
buttonCmsSign := widgets.NewQPushButton2("CMS署名", widget)
buttonCmsSign.ConnectClicked(onCmsSign)
vBox.AddWidget(buttonCmsSign, 0, 0)
buttonPinStatus := widgets.NewQPushButton2("PINステータス", widget)
buttonPinStatus.ConnectClicked(onPinStatus)
vBox.AddWidget(buttonPinStatus, 0, 0)
window.SetCentralWidget(widget)
window.Show()
app.Exec()
return nil
}
func onCardCheck(checked bool) {
err := libmyna.CheckCard(ctx)
if err != nil {
widgets.QMessageBox_Warning(nil, "エラー", err.Error(),
widgets.QMessageBox__Ok, 0)
} else {
widgets.QMessageBox_Information(nil, "動作確認", "正常です",
widgets.QMessageBox__Close, 0)
}
}
func onCardInfo(checked bool) {
prompt := NewPinPromptDialog()
rc := prompt.Exec()
if rc != int(widgets.QDialog__Accepted) {
return
}
pin := prompt.GetPin()
info, err := libmyna.GetCardInfo(ctx, pin)
if err != nil {
widgets.QMessageBox_Warning(nil, "エラー", err.Error(),
widgets.QMessageBox__Ok, 0)
return
}
var msg string
msg += fmt.Sprintf("個人番号: %s\n", info["number"])
msg += fmt.Sprintf("氏名: %s\n", info["name"])
msg += fmt.Sprintf("住所: %s\n", info["address"])
msg += fmt.Sprintf("生年月日: %s\n", info["birth"])
msg += fmt.Sprintf("性別: %s", libmyna.ToISO5218String(info["sex"]))
widgets.QMessageBox_Information(nil, "券面事項確認", msg,
widgets.QMessageBox__Close, 0)
}
func onShowCert(checked bool) {
dialog := NewSelectCertDialog()
dialog.Show()
}
func onPinStatus(checked bool) {
status, err := libmyna.GetPinStatus(ctx)
if err != nil {
widgets.QMessageBox_Warning(nil, "エラー", err.Error(),
widgets.QMessageBox__Ok, 0)
return
}
var msg string
msg += fmt.Sprintf("券面事項PIN(A): のこり%2d回\n",
status["card_info_pin_a"])
msg += fmt.Sprintf("券面事項PIN(B): のこり%2d回\n",
status["card_info_pin_b"])
msg += fmt.Sprintf("入力補助PIN: のこり%2d回\n",
status["card_input_helper_pin"])
msg += fmt.Sprintf("入力補助PIN(A): のこり%2d回\n",
status["card_input_helper_pin_a"])
msg += fmt.Sprintf("入力補助PIN(B): のこり%2d回\n",
status["card_input_helper_pin_b"])
msg += fmt.Sprintf("JPKI認証用PIN: のこり%2d回\n", status["jpki_auth"])
msg += fmt.Sprintf("JPKI署名用PIN: のこり%2d回\n", status["jpki_sign"])
widgets.QMessageBox_Information(nil, "PINステータス", msg,
widgets.QMessageBox__Ok, 0)
}
func onCmsSign(checked bool) {
dialog := NewCmsSignDialog()
dialog.Show()
}