-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
147 lines (118 loc) · 4.7 KB
/
main.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
package main
import (
"github.com/gotk3/gotk3/gtk"
"github.com/sqweek/dialog"
)
func dirpicker(checkbutton *gtk.CheckButton) string {
bool := checkbutton.GetActive()
filename := ""
if bool {
filename, _ := dialog.Directory().Title("Pick folder").Browse()
return filename
} else {
filename, _ := dialog.File().Load()
return filename
}
return filename
}
func main() {
// Initialize GTK without parsing any command line arguments.
gtk.Init(nil)
// Create a new toplevel window, set its title, and connect it to the
// "destroy" signal to exit the GTK main loop when it is destroyed.
win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
check(err)
win.SetTitle("Neko Vault")
win.Connect("destroy", func() {
gtk.MainQuit()
})
// Create a box containing the widgets of the window.
box, err := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
check(err)
// Create a new label widget to show in the window.
hintlabel, err := gtk.LabelNew("Click the buttons below to start encrypting/decrypting files.")
check(err)
// Create a new image widget to show cute catgirls.
image, err := gtk.ImageNew()
check(err)
// Create a new image widget to show cute catgirls.
checkbutton, err := gtk.CheckButtonNewWithLabel("Folder?")
check(err)
checkbutton.SetHAlign(3)
// Create a new label widget to show status of program.
statuslabel, err := gtk.LabelNew("Status: Idle")
check(err)
// Create an entry widget to enter key.
entry, err := gtk.EntryNew()
check(err)
// Create an entry widget to verify key entry.
entryverify, err := gtk.EntryNew()
check(err)
// Make entry widget hide text and set placeholder text.
entry.SetVisibility(false)
entry.SetPlaceholderText("Enter a key...")
// Make verify entry widget hide text and set placeholder text.
entryverify.SetVisibility(false)
entryverify.SetPlaceholderText("Verify key...")
// Create progress bar to show encryption status.
progressbar, err := gtk.ProgressBarNew()
check(err)
// Create button to encrypt files
btnenc, err := gtk.ButtonNewWithLabel("Encrypt")
check(err)
btnenc.Connect("clicked", func() {
entrytext, err := entry.GetText()
check(err)
entryverifytext, err := entryverify.GetText()
check(err)
if entrytext != entryverifytext {
hintlabel.SetMarkup("<span color='red'>Error: The two keys do not match...</span>")
return
}
filename := dirpicker(checkbutton)
encryptfile(filename, entrytext, progressbar, statuslabel, hintlabel, image)
})
// Create button to decrypt files
btndec, err := gtk.ButtonNewWithLabel("Decrypt")
check(err)
btndec.Connect("clicked", func() {
entrytext, err := entry.GetText()
check(err)
entryverifytext, err := entryverify.GetText()
check(err)
if entrytext != entryverifytext {
hintlabel.SetMarkup("<span color='red'>Error: The two keys do not match...</span>")
return
}
filename := dirpicker(checkbutton)
decryptfile(filename, entrytext, progressbar, statuslabel, hintlabel, image)
})
// Add the box to the window.
win.Add(box)
// Start adding widgets to the box while have the hint label as a parent.
box.PackStart(hintlabel, true, true, 0)
// Add the image widget.
box.Add(image)
image.SetFromFile("./Assets/idle.gif")
// Add the check button widget.
box.Add(checkbutton)
// Add the status label widget.
box.Add(statuslabel)
// Add the entry widget.
box.Add(entry)
// Add the verify entry widget.
box.Add(entryverify)
// Add the encrypt button to the box.
box.Add(btnenc)
// Add the decrypt button to the box.
box.Add(btndec)
// Add the progress bar to the box.
box.Add(progressbar)
// Set the default window size.
win.SetDefaultSize(800, 600)
// Recursively show all widgets contained in this window.
win.ShowAll()
// Begin executing the GTK main loop. This blocks until
// gtk.MainQuit() is run.
gtk.Main()
}