From 24a821aaed91d5b1ed90ecb6c8bb46eba2c4c0ba Mon Sep 17 00:00:00 2001 From: Belac Darkstorm Date: Wed, 31 Aug 2016 08:52:37 -0500 Subject: [PATCH] Added strList adap. Fix name get from AppInfo.ini --- main.go | 17 ++++++---- prtapAdap.go | 2 +- strList.go | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ui.go | 3 +- 4 files changed, 109 insertions(+), 9 deletions(-) create mode 100755 strList.go diff --git a/main.go b/main.go index bc7655d..3d4fd9e 100644 --- a/main.go +++ b/main.go @@ -59,8 +59,10 @@ func processApp(fi *os.File) (out prtap) { fmt.Println(fi.Name() + "/App/AppInfo/appinfo.ini") if err == nil { fmt.Println("working!") - out.cat = getCat(fild) - out.name = getName(fild) + out.name = getName(*fild) + fild, _ = os.Open(fi.Name() + "/App/AppInfo/appinfo.ini") + out.cat = getCat(*fild) + fmt.Println("Name:", out.name) } } else if !v.IsDir() { //do os check here @@ -79,14 +81,15 @@ func processApp(fi *os.File) (out prtap) { return prtap{} } -func getCat(fi *os.File) (out string) { - rdr := bufio.NewReader(fi) +func getCat(fi os.File) (out string) { + rdr := bufio.NewReader(&fi) var err error var ln []byte for err == nil { ln, _, err = rdr.ReadLine() str := string(ln) if strings.HasPrefix(str, "Category=") { + fmt.Println(str) out = strings.TrimPrefix(str, "Category=") return } @@ -94,13 +97,15 @@ func getCat(fi *os.File) (out string) { return } -func getName(fi *os.File) (out string) { - rdr := bufio.NewReader(fi) +func getName(fi os.File) (out string) { + rdr := bufio.NewReader(&fi) var err error var ln []byte for err == nil { ln, _, err = rdr.ReadLine() + str := string(ln) + fmt.Println(str) if strings.HasPrefix(str, "Name=") { out = strings.TrimPrefix(str, "Name=") return diff --git a/prtapAdap.go b/prtapAdap.go index 4a0a53b..39d92eb 100644 --- a/prtapAdap.go +++ b/prtapAdap.go @@ -22,9 +22,9 @@ func (p *prtapAdap) Count() int { func (p *prtapAdap) Create(th gxui.Theme, index int) gxui.Control { box := th.CreateLinearLayout() box.SetDirection(gxui.LeftToRight) + //add image support // pic := th.CreateImage() // dr.CreateTexture() - //add image support lbl := th.CreateLabel() lbl.SetText(p.apps[index].name) // box.AddChild(pic) diff --git a/strList.go b/strList.go new file mode 100755 index 0000000..40490cc --- /dev/null +++ b/strList.go @@ -0,0 +1,96 @@ +package main + +import ( + "encoding/gob" + "os" + + "github.com/nelsam/gxui" + "github.com/nelsam/gxui/math" +) + +//StrList TODO +type StrList struct { + gxui.AdapterBase + strs []string +} + +//AddString TODO +func (s *StrList) AddString(add string) { + s.strs = append(s.strs, add) + s.DataChanged(false) +} + +//Remove TODO +func (s *StrList) Remove(index int) { + s.strs = append(s.strs[:index], s.strs[index+1:]...) + s.DataChanged(false) +} + +//SetStrings TODO +func (s *StrList) SetStrings(strs []string) { + s.strs = strs + s.DataChanged(false) +} + +func (s *StrList) Save(filename string) { + os.Remove(filename) + fi, err := os.Create(filename) + if err != nil { + panic(err) + } + e := gob.NewEncoder(fi) + err = e.Encode(s.strs) + if err != nil { + panic(err) + } + fi.Close() +} + +func (s *StrList) Load(filename string) { + fi, err := os.Open(filename) + if err != nil { + return + } + d := gob.NewDecoder(fi) + err = d.Decode(&s.strs) + if err != nil { + panic(err) + } + fi.Close() + s.DataChanged(false) +} + +//Count TODO +func (s *StrList) Count() int { + return len(s.strs) +} + +//ItemAt TODO +func (s *StrList) ItemAt(index int) gxui.AdapterItem { + return s.strs[index] +} + +//ItemIndex TODO +func (s *StrList) ItemIndex(item gxui.AdapterItem) int { + for i, v := range s.strs { + if v == item { + return i + } + } + return -1 +} + +//Create TODO +func (s *StrList) Create(th gxui.Theme, index int) gxui.Control { + box := th.CreateLinearLayout() + box.SetDirection(gxui.LeftToRight) + lbl := th.CreateLabel() + lbl.SetText(s.strs[index]) + box.AddChild(lbl) + return box +} + +//Size TODO +func (s *StrList) Size(gxui.Theme) math.Size { + return math.Size{W: math.MaxSize.W, H: 20} +} diff --git a/ui.go b/ui.go index bf72990..49c3ddb 100644 --- a/ui.go +++ b/ui.go @@ -1,7 +1,6 @@ package main import ( - "gxuiCustom" "os" "os/exec" "path" @@ -16,7 +15,7 @@ var ( func uiMain(dri gxui.Driver) { dr = dri - catAdap := &gxuiCustom.StrList{} + catAdap := &StrList{} catAdap.SetStrings(cats) appAdap := &prtapAdap{} th := dark.CreateTheme(dr)