diff options
Diffstat (limited to 'src/rhlibrary')
-rw-r--r-- | src/rhlibrary/jingle_selector_widget.go | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/rhlibrary/jingle_selector_widget.go b/src/rhlibrary/jingle_selector_widget.go index 85cb741..fe169c1 100644 --- a/src/rhlibrary/jingle_selector_widget.go +++ b/src/rhlibrary/jingle_selector_widget.go @@ -25,6 +25,7 @@ package main import ( + "sort" "sync" "code.helsinki.at/rhrd-go/player" @@ -56,9 +57,15 @@ func updateJingles(db *rddb.DBChan) (err error) { return } + var keys []string + for k, _ := range jingles { + keys = append(keys, k) + } + sort.Strings(keys) + jinglesComboBox.RemoveAll() - for group, jingle := range jingles { - jinglesComboBox.Append(group, jingle.Description) + for _, group := range keys { + jinglesComboBox.Append(group, jingles[group].Description) } if !jinglesComboBox.SetActiveID(jinglesCurrentGroup) { @@ -67,6 +74,19 @@ func updateJingles(db *rddb.DBChan) (err error) { return } +func selectJingle() rddb.JingleListEntry { + id := jinglesComboBox.GetActiveID() + if id == "" { + return rddb.JingleListEntry{} + } + jinglesCurrentGroup = id + + jinglesMutex.Lock() + defer jinglesMutex.Unlock() + + return jingles[jinglesCurrentGroup] +} + func addJingleComboBox(grid *gtk.Grid, db *rddb.DBChan, p *player.PlayerChan) (err error) { var box *gtk.Box if box, err = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 10); err != nil { @@ -86,10 +106,10 @@ func addJingleComboBox(grid *gtk.Grid, db *rddb.DBChan, p *player.PlayerChan) (e return err } jinglesComboBox.Connect("changed", func(_ *gtk.ComboBoxText) { - // jingle := selectJingle() - // if jingle.ID == 0 { - // return - // } + jingle := selectJingle() + if jingle.Group == "" { + return + } // glib.IdleAdd(func() { // if err = updateJingleCutListRows(jingle, db, p); err != nil { @@ -97,7 +117,7 @@ func addJingleComboBox(grid *gtk.Grid, db *rddb.DBChan, p *player.PlayerChan) (e // return // } // }) - // rhdl.Printf("jingle %d is now selected: %s", jingle.ID, jingle.Title) + rhdl.Printf("jingle group %s is now selected: %s", jingle.Group, jingle.Description) }) box.PackStart(jinglesComboBox, true, true, 0) |