Implemented the setLineText helper function
[resumebuilder.git] / resumebuilder.go
index 88fe6a6..79d821f 100644 (file)
@@ -3,27 +3,40 @@ package main
 import (
        "fmt"
        "os"
 import (
        "fmt"
        "os"
+       "strconv"
 
        "github.com/gotk3/gotk3/gtk"
 )
 
 type Applicant struct {
 
        "github.com/gotk3/gotk3/gtk"
 )
 
 type Applicant struct {
-       FirstName string
-       LastName  string
-       Age       int
-       Sex       Sex
-       Education []Education
+       FirstName   string
+       LastName    string
+       DateOfBirth Date
+       Sex         Sex
+       Address     string
+       ContactNo   string
+       Email       string
+       Education   []Education
+}
+
+type Date struct {
+       Year  uint
+       Month uint
+       Day   uint
 }
 
 type Education struct {
 }
 
 type Education struct {
-       SchoolName     string
-       YearOfPassing  int
-       PassPercentage float32
+       Qualification     string
+       Institution       string
+       YearOfPassing     uint
+       GradeOrPercentage string
 }
 
 type Sex int
 
 var ui *gtk.Builder
 }
 
 type Sex int
 
 var ui *gtk.Builder
+var selectedsex Sex
+var selecteddate Date
 
 const (
        Male   Sex = 1
 
 const (
        Male   Sex = 1
@@ -45,36 +58,91 @@ const (
        }
 } */
 
        }
 } */
 
-func getBasicDetails() (*Applicant, error) {
-       obj, err := ui.GetObject("FirstName")
+func setLineText(fieldname string, buf string) {
+       obj, err := ui.GetObject(fieldname)
        if err != nil {
        if err != nil {
-               return nil, err
+               return
        }
        }
-       fsname, ok := obj.(*gtk.Entry)
+       field, ok := obj.(*gtk.Entry)
        if !ok {
        if !ok {
+               return
+       }
+       field.SetText(buf)
+}
+
+func getLineText(fieldname string) (string, error) {
+       obj, err := ui.GetObject(fieldname)
+       if err != nil {
+               return "", err
+       }
+       field, ok := obj.(*gtk.Entry)
+       if !ok {
+               return "", err
+       }
+       fieldstr, err := field.GetText()
+       if err != nil {
+               return "", err
+       }
+       return fieldstr, nil
+}
+
+func getMultilineText(fieldname string) (string, error) {
+       obj, err := ui.GetObject(fieldname)
+       if err != nil {
+               return "", err
+       }
+       fieldctl, ok := obj.(*gtk.TextView)
+       if !ok {
+               return "", err
+       }
+       textbuf, err := fieldctl.GetBuffer()
+       if err != nil {
+               return "", err
+       }
+       start, end := textbuf.GetBounds()
+       textstr, err := textbuf.GetText(start, end, true)
+       if err != nil {
+               return "", err
+       }
+       return textstr, nil
+}
+
+func getBasicDetails() (*Applicant, error) {
+       // Retrieve all the fields.
+
+       firstname, err := getLineText("FirstName")
+       if err != nil {
                return nil, err
        }
                return nil, err
        }
-       firstname, err := fsname.GetText()
+       lastname, err := getLineText("LastName")
        if err != nil {
                return nil, err
        }
        if err != nil {
                return nil, err
        }
-       obj, err = ui.GetObject("LastName")
+
+       address, err := getMultilineText("Address")
        if err != nil {
                return nil, err
        }
        if err != nil {
                return nil, err
        }
-       lsname, ok := obj.(*gtk.Entry)
-       if !ok {
+
+       contact, err := getLineText("ContactNumber")
+       if err != nil {
                return nil, err
        }
                return nil, err
        }
-       lastname, err := lsname.GetText()
+       email, err := getLineText("Email")
        if err != nil {
                return nil, err
        }
 
        if err != nil {
                return nil, err
        }
 
+       // Store the contents in Applicant object
        var applicant = new(Applicant)
 
        applicant.FirstName = firstname
        applicant.LastName = lastname
        var applicant = new(Applicant)
 
        applicant.FirstName = firstname
        applicant.LastName = lastname
+       applicant.DateOfBirth = selecteddate
+       applicant.Sex = selectedsex
+       applicant.Address = address
+       applicant.ContactNo = contact
+       applicant.Email = email
 
        return applicant, nil
 }
 
        return applicant, nil
 }
@@ -92,20 +160,7 @@ func getWindow() (*gtk.Window, error) {
        return wnd, nil
 }
 
        return wnd, nil
 }
 
-func getSaveButton() (*gtk.Button, error) {
-       btnobj, err := ui.GetObject("SaveButton")
-       if err != nil {
-               fmt.Println(err.Error())
-               return nil, err
-       }
-       btn, ok := btnobj.(*gtk.Button)
-       if !ok {
-               return nil, err
-       }
-       return btn, nil
-}
-
-func LoadMain() {
+func loadMain() {
        gtk.Init(nil)
        var err error
        ui, err = gtk.BuilderNew()
        gtk.Init(nil)
        var err error
        ui, err = gtk.BuilderNew()
@@ -119,19 +174,19 @@ func LoadMain() {
                os.Exit(1)
        }
        ui.AddFromString(string(asset))
                os.Exit(1)
        }
        ui.AddFromString(string(asset))
+       ui.ConnectSignals(map[string]interface{}{"SexMaleSelected": sexMaleSelected,
+               "SexFemaleSelected": sexFemaleSelected, "SexOtherSelected": sexOtherSelected,
+               "SaveButtonClicked": saveButtonClicked, "DoBSelected": doBSelected,
+               "AddEducationClicked": addEducationClicked})
 
        wnd, err := getWindow()
        if err != nil {
                os.Exit(1)
        }
 
 
        wnd, err := getWindow()
        if err != nil {
                os.Exit(1)
        }
 
-       btn, err := getSaveButton()
-       if err != nil {
-               os.Exit(1)
-       }
-       btn.Connect("clicked", SaveButtonClicked)
        wnd.SetTitle("Resume Builder")
        wnd.ShowAll()
        wnd.SetTitle("Resume Builder")
        wnd.ShowAll()
+       selectedsex = Male
 
        wnd.Connect("destroy", func() {
                gtk.MainQuit()
 
        wnd.Connect("destroy", func() {
                gtk.MainQuit()
@@ -139,7 +194,84 @@ func LoadMain() {
        gtk.Main()
 }
 
        gtk.Main()
 }
 
-func SaveButtonClicked() {
+func sexMaleSelected(male *gtk.RadioButton) {
+       if male.GetActive() {
+               selectedsex = Male
+       }
+}
+
+func sexFemaleSelected(female *gtk.RadioButton) {
+       if female.GetActive() {
+               selectedsex = Female
+       }
+}
+
+func sexOtherSelected(other *gtk.RadioButton) {
+       if other.GetActive() {
+               selectedsex = Other
+       }
+}
+
+func doBSelected(dob *gtk.Calendar) {
+       selecteddate.Year, selecteddate.Month, selecteddate.Day = dob.GetDate()
+}
+
+func getEducationFields() (*Education, error) {
+       ed := new(Education)
+       qual, err := getLineText("QualificationTitle")
+       if err != nil {
+               return nil, err
+       }
+       inst, err := getLineText("InstitutionName")
+       if err != nil {
+               return nil, err
+       }
+       yearp, err := getLineText("YearPassing")
+       if err != nil {
+               return nil, err
+       }
+       year, err := strconv.Atoi(yearp)
+       if err != nil {
+               return nil, err
+       }
+       gradep, err := getLineText("GradeOrPercentag")
+       if err != nil {
+               return nil, err
+       }
+       ed.Qualification = qual
+       ed.Institution = inst
+       ed.YearOfPassing = uint(year)
+       ed.GradeOrPercentage = gradep
+
+       return ed, nil
+}
+
+func addEducationClicked() {
+       ed, err := getEducationFields()
+       if err != nil {
+               return
+       }
+       lstore, err := ui.GetObject("EducationStore")
+       if err != nil {
+               return
+       }
+       edustore, ok := lstore.(*gtk.ListStore)
+       if !ok {
+               return
+       }
+       iter := edustore.Append()
+       edustore.SetValue(iter, 0, ed.Qualification)
+       edustore.SetValue(iter, 1, ed.Institution)
+       edustore.SetValue(iter, 2, ed.YearOfPassing)
+       edustore.SetValue(iter, 3, ed.GradeOrPercentage)
+
+       setLineText("QualificationTitle", "")
+       setLineText("InstitutionName", "")
+       setLineText("YearPassing", "")
+       setLineText("GradeOrPercentag", "")
+}
+
+func saveButtonClicked() {
        a, err := getBasicDetails()
        if err != nil {
                fmt.Println(err.Error())
        a, err := getBasicDetails()
        if err != nil {
                fmt.Println(err.Error())
@@ -149,5 +281,5 @@ func SaveButtonClicked() {
 }
 
 func main() {
 }
 
 func main() {
-       LoadMain()
+       loadMain()
 }
 }