Started work on the Education page
[resumebuilder.git] / resumebuilder.go
1 package main
2
3 import (
4 "fmt"
5 "os"
6
7 "github.com/gotk3/gotk3/gtk"
8 )
9
10 type Applicant struct {
11 FirstName string
12 LastName string
13 DateOfBirth Date
14 Sex Sex
15 Address string
16 ContactNo string
17 Email string
18 Education []Education
19 }
20
21 type Date struct {
22 Year uint
23 Month uint
24 Day uint
25 }
26
27 type Education struct {
28 Qualification string
29 Institution string
30 YearOfPassing uint
31 GradeOrPercentage string
32 }
33
34 type Sex int
35
36 var ui *gtk.Builder
37 var selectedsex Sex
38 var selecteddate Date
39
40 const (
41 Male Sex = 1
42 Female = 2
43 Other = 3
44 )
45
46 /* func SaveToJson(a *Applicant) {
47 b, err := json.Marshal(a)
48
49 if err != nil {
50 fmt.Println(err.Error())
51 os.Exit(2)
52 }
53 err = ioutil.WriteFile("test.json", b, 0644)
54 if err != nil {
55 fmt.Println(err.Error())
56 os.Exit(3)
57 }
58 } */
59
60 func getLineText(fieldname string) (string, error) {
61 obj, err := ui.GetObject(fieldname)
62 if err != nil {
63 return "", err
64 }
65 field, ok := obj.(*gtk.Entry)
66 if !ok {
67 return "", err
68 }
69 fieldstr, err := field.GetText()
70 if err != nil {
71 return "", err
72 }
73 return fieldstr, nil
74 }
75
76 func getMultilineText(fieldname string) (string, error) {
77 obj, err := ui.GetObject(fieldname)
78 if err != nil {
79 return "", err
80 }
81 fieldctl, ok := obj.(*gtk.TextView)
82 if !ok {
83 return "", err
84 }
85 textbuf, err := fieldctl.GetBuffer()
86 if err != nil {
87 return "", err
88 }
89 start, end := textbuf.GetBounds()
90 textstr, err := textbuf.GetText(start, end, true)
91 if err != nil {
92 return "", err
93 }
94 return textstr, nil
95 }
96
97 func getBasicDetails() (*Applicant, error) {
98 // Retrieve all the fields.
99
100 firstname, err := getLineText("FirstName")
101 if err != nil {
102 return nil, err
103 }
104 lastname, err := getLineText("LastName")
105 if err != nil {
106 return nil, err
107 }
108
109 address, err := getMultilineText("Address")
110 if err != nil {
111 return nil, err
112 }
113
114 contact, err := getLineText("ContactNumber")
115 if err != nil {
116 return nil, err
117 }
118 email, err := getLineText("Email")
119 if err != nil {
120 return nil, err
121 }
122
123 // Store the contents in Applicant object
124 var applicant = new(Applicant)
125
126 applicant.FirstName = firstname
127 applicant.LastName = lastname
128 applicant.DateOfBirth = selecteddate
129 applicant.Sex = selectedsex
130 applicant.Address = address
131 applicant.ContactNo = contact
132 applicant.Email = email
133
134 return applicant, nil
135 }
136
137 func getWindow() (*gtk.Window, error) {
138 obj, err := ui.GetObject("MainWindow")
139 if err != nil {
140 fmt.Println(err.Error())
141 return nil, err
142 }
143 wnd, ok := obj.(*gtk.Window)
144 if !ok {
145 return nil, err
146 }
147 return wnd, nil
148 }
149
150 func LoadMain() {
151 gtk.Init(nil)
152 var err error
153 ui, err = gtk.BuilderNew()
154 if err != nil {
155 fmt.Println(err.Error())
156 os.Exit(1)
157 }
158 asset, err := Asset("resources/resumebuilder.glade")
159 if err != nil {
160 fmt.Println(err.Error())
161 os.Exit(1)
162 }
163 ui.AddFromString(string(asset))
164 ui.ConnectSignals(map[string]interface{}{"SexMaleSelected": sexMaleSelected,
165 "SexFemaleSelected": sexFemaleSelected, "SexOtherSelected": sexOtherSelected,
166 "SaveButtonClicked": SaveButtonClicked, "DoBSelected": doBSelected})
167
168 wnd, err := getWindow()
169 if err != nil {
170 os.Exit(1)
171 }
172
173 wnd.SetTitle("Resume Builder")
174 wnd.ShowAll()
175 selectedsex = Male
176
177 wnd.Connect("destroy", func() {
178 gtk.MainQuit()
179 })
180 gtk.Main()
181 }
182
183 func sexMaleSelected(male *gtk.RadioButton) {
184 if male.GetActive() {
185 selectedsex = Male
186 }
187 }
188
189 func sexFemaleSelected(female *gtk.RadioButton) {
190 if female.GetActive() {
191 selectedsex = Female
192 }
193 }
194
195 func sexOtherSelected(other *gtk.RadioButton) {
196 if other.GetActive() {
197 selectedsex = Other
198 }
199 }
200
201 func doBSelected(dob *gtk.Calendar) {
202 selecteddate.Year, selecteddate.Month, selecteddate.Day = dob.GetDate()
203 }
204
205 func SaveButtonClicked() {
206 a, err := getBasicDetails()
207 if err != nil {
208 fmt.Println(err.Error())
209 os.Exit(1)
210 }
211 fmt.Println(*a)
212 }
213
214 func main() {
215 LoadMain()
216 }