summaryrefslogtreecommitdiff
path: root/src/rhlibrary
diff options
context:
space:
mode:
Diffstat (limited to 'src/rhlibrary')
-rw-r--r--src/rhlibrary/selector_widget.go15
-rw-r--r--src/rhlibrary/show_selector_widget.go46
2 files changed, 45 insertions, 16 deletions
diff --git a/src/rhlibrary/selector_widget.go b/src/rhlibrary/selector_widget.go
index 405171c..59f59f8 100644
--- a/src/rhlibrary/selector_widget.go
+++ b/src/rhlibrary/selector_widget.go
@@ -127,6 +127,21 @@ func getSelectorWidget(db *rddb.DBChan, p *player.PlayerChan) (gtk.IWidget, erro
return nil, err
}
+ nb.Connect("switch-page", func(_ *gtk.Notebook, _ gtk.IWidget, pagenum uint) {
+ switch pagenum {
+ case 0:
+ updateShows(db)
+ case 1:
+ // updateJingles(db)
+ case 2:
+ // updatePools(db)
+ case 3:
+ // nothing to do here
+ default:
+ rhl.Printf("selector error invalid page: %d", pagenum)
+ }
+ })
+
var cp *gtk.CssProvider
if cp, err = gtk.CssProviderNew(); err != nil {
return nil, err
diff --git a/src/rhlibrary/show_selector_widget.go b/src/rhlibrary/show_selector_widget.go
index 45b706d..ee49e57 100644
--- a/src/rhlibrary/show_selector_widget.go
+++ b/src/rhlibrary/show_selector_widget.go
@@ -35,8 +35,10 @@ import (
)
var (
- showsMutex sync.Mutex
- shows rddb.ShowList
+ showsMutex sync.Mutex
+ shows rddb.ShowList
+ showsComboBox *gtk.ComboBoxText
+ showsCurrentID uint
)
// carts, err := db.GetShowCartList(show)
@@ -57,13 +59,20 @@ var (
// return nil
// }
-func updateShows(box *gtk.ComboBoxText, db *rddb.DBChan) (err error) {
+func fetchShows(db *rddb.DBChan) (err error) {
showsMutex.Lock()
defer showsMutex.Unlock()
if shows, err = db.GetShowList(rhuser.Username); err != nil {
return err
}
+ return
+}
+
+func updateShows(db *rddb.DBChan) (err error) {
+ if err = fetchShows(db); err != nil {
+ return
+ }
var keys []int
for k, _ := range shows {
@@ -71,25 +80,33 @@ func updateShows(box *gtk.ComboBoxText, db *rddb.DBChan) (err error) {
}
sort.Ints(keys)
- box.RemoveAll()
+ showsComboBox.RemoveAll()
for _, showid := range keys {
- box.Append(strconv.FormatUint(uint64(showid), 10), shows[uint(showid)].Title)
+ showsComboBox.Append(strconv.FormatUint(uint64(showid), 10), shows[uint(showid)].Title)
+ }
+
+ if !showsComboBox.SetActiveID(strconv.FormatUint(uint64(showsCurrentID), 10)) {
+ showsComboBox.SetActive(0)
}
return
}
-func selectShow(box *gtk.ComboBoxText) {
- showid64, err := strconv.ParseUint(box.GetActiveID(), 10, 32)
+func selectShow() {
+ id := showsComboBox.GetActiveID()
+ if id == "" {
+ return
+ }
+ showid64, err := strconv.ParseUint(id, 10, 32)
if err != nil {
rhdl.Printf("invalid show-id in combo box: %v", err)
return
}
- showid := uint(showid64)
+ showsCurrentID = uint(showid64)
showsMutex.Lock()
defer showsMutex.Unlock()
- rhdl.Printf("show %d is now selected: %s", showid, shows[showid].Title)
+ rhdl.Printf("show %d is now selected: %s", showsCurrentID, shows[showsCurrentID].Title)
}
func addShowComboBox(grid *gtk.Grid, db *rddb.DBChan) (err error) {
@@ -99,20 +116,17 @@ func addShowComboBox(grid *gtk.Grid, db *rddb.DBChan) (err error) {
}
grid.Attach(label, 1, 1, 1, 1)
- var box *gtk.ComboBoxText
- if box, err = gtk.ComboBoxTextNew(); err != nil {
+ if showsComboBox, err = gtk.ComboBoxTextNew(); err != nil {
return
}
- if err = updateShows(box, db); err != nil {
+ if err = updateShows(db); err != nil {
return err
}
- box.Connect("changed", func(_ *gtk.ComboBoxText) { selectShow(box) })
-
- box.SetActive(0)
+ showsComboBox.Connect("changed", func(_ *gtk.ComboBoxText) { selectShow() })
- grid.Attach(box, 2, 1, 1, 1)
+ grid.Attach(showsComboBox, 2, 1, 1, 1)
return
}