summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-02-04 15:19:28 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-02-04 15:19:28 (GMT)
commit7dde603888aad233531f2592f190a671e47dbed3 (patch)
tree71392302bce00f6b6219b7644ff6a5cdd40f066c
parent6eeca14c50f16ae0aed7ea8f8f501134dbad3c6a (diff)
show list can now be updated
-rw-r--r--src/rhlibrary/show_selector_widget.go61
1 files changed, 45 insertions, 16 deletions
diff --git a/src/rhlibrary/show_selector_widget.go b/src/rhlibrary/show_selector_widget.go
index da121bd..45b706d 100644
--- a/src/rhlibrary/show_selector_widget.go
+++ b/src/rhlibrary/show_selector_widget.go
@@ -25,13 +25,20 @@
package main
import (
+ "sort"
"strconv"
+ "sync"
"code.helsinki.at/rhrd-go/player"
"code.helsinki.at/rhrd-go/rddb"
"github.com/gotk3/gotk3/gtk"
)
+var (
+ showsMutex sync.Mutex
+ shows rddb.ShowList
+)
+
// carts, err := db.GetShowCartList(show)
// if err != nil {
// return err
@@ -50,6 +57,41 @@ import (
// return nil
// }
+func updateShows(box *gtk.ComboBoxText, db *rddb.DBChan) (err error) {
+ showsMutex.Lock()
+ defer showsMutex.Unlock()
+
+ if shows, err = db.GetShowList(rhuser.Username); err != nil {
+ return err
+ }
+
+ var keys []int
+ for k, _ := range shows {
+ keys = append(keys, int(k))
+ }
+ sort.Ints(keys)
+
+ box.RemoveAll()
+ for _, showid := range keys {
+ box.Append(strconv.FormatUint(uint64(showid), 10), shows[uint(showid)].Title)
+ }
+ return
+}
+
+func selectShow(box *gtk.ComboBoxText) {
+ showid64, err := strconv.ParseUint(box.GetActiveID(), 10, 32)
+ if err != nil {
+ rhdl.Printf("invalid show-id in combo box: %v", err)
+ return
+ }
+ showid := uint(showid64)
+
+ showsMutex.Lock()
+ defer showsMutex.Unlock()
+
+ rhdl.Printf("show %d is now selected: %s", showid, shows[showid].Title)
+}
+
func addShowComboBox(grid *gtk.Grid, db *rddb.DBChan) (err error) {
var label *gtk.Label
if label, err = gtk.LabelNew("Sendung auswählen"); err != nil {
@@ -62,26 +104,13 @@ func addShowComboBox(grid *gtk.Grid, db *rddb.DBChan) (err error) {
return
}
- shows, err := db.GetShowList(rhuser.Username)
- if err != nil {
- rhdl.Println(err) // TODO: feedback at GUI?
+ if err = updateShows(box, db); err != nil {
return err
}
- for _, show := range shows {
- box.Append(strconv.FormatUint(uint64(show.ID), 10), show.Title)
- }
- box.SetActive(0)
-
- box.Connect("changed", func(_ *gtk.ComboBoxText) {
- idx, err := strconv.ParseUint(box.GetActiveID(), 10, 32)
- if err != nil {
- rhdl.Printf("invalid show-id in combo box: %v", err)
- return
- }
+ box.Connect("changed", func(_ *gtk.ComboBoxText) { selectShow(box) })
- rhdl.Printf("show %d is now selected", idx)
- })
+ box.SetActive(0)
grid.Attach(box, 2, 1, 1, 1)
return