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