summaryrefslogtreecommitdiff
path: root/src/rhlibrary
diff options
context:
space:
mode:
Diffstat (limited to 'src/rhlibrary')
-rw-r--r--src/rhlibrary/show_selector_widget.go144
1 files changed, 99 insertions, 45 deletions
diff --git a/src/rhlibrary/show_selector_widget.go b/src/rhlibrary/show_selector_widget.go
index b32ac6a..c0a8c8e 100644
--- a/src/rhlibrary/show_selector_widget.go
+++ b/src/rhlibrary/show_selector_widget.go
@@ -25,21 +25,23 @@
package main
import (
- "fmt"
"sort"
"strconv"
"sync"
"code.helsinki.at/rhrd-go/player"
"code.helsinki.at/rhrd-go/rddb"
+ "github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
)
var (
- showsMutex sync.Mutex
- shows rddb.ShowList
- showsComboBox *gtk.ComboBoxText
- showsCurrentID uint
+ showsMutex sync.Mutex
+ shows rddb.ShowList
+ showsComboBox *gtk.ComboBoxText
+ showsCurrentID uint
+ showsCartListBin *gtk.Bin
+ showsCartList *gtk.Grid
)
func fetchShows(db *rddb.DBChan) (err error) {
@@ -74,25 +76,25 @@ func updateShows(db *rddb.DBChan) (err error) {
return
}
-func selectShow() {
+func selectShow() rddb.ShowListEntry {
id := showsComboBox.GetActiveID()
if id == "" {
- return
+ return rddb.ShowListEntry{}
}
showid64, err := strconv.ParseUint(id, 10, 32)
if err != nil {
rhdl.Printf("invalid show-id in combo box: %v", err)
- return
+ return rddb.ShowListEntry{}
}
showsCurrentID = uint(showid64)
showsMutex.Lock()
defer showsMutex.Unlock()
- rhdl.Printf("show %d is now selected: %s", showsCurrentID, shows[showsCurrentID].Title)
+ return shows[showsCurrentID]
}
-func addShowComboBox(grid *gtk.Grid, db *rddb.DBChan) (err error) {
+func addShowComboBox(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 {
return
@@ -110,7 +112,20 @@ func addShowComboBox(grid *gtk.Grid, db *rddb.DBChan) (err error) {
if err = updateShows(db); err != nil {
return err
}
- showsComboBox.Connect("changed", func(_ *gtk.ComboBoxText) { selectShow() })
+ showsComboBox.Connect("changed", func(_ *gtk.ComboBoxText) {
+ show := selectShow()
+ if show.ID == 0 {
+ return
+ }
+
+ glib.IdleAdd(func() {
+ if err = updateShowCartListRows(show, db, p); err != nil {
+ rhdl.Printf("error loading show carts for %d", show.ID)
+ return
+ }
+ })
+ rhdl.Printf("show %d is now selected: %s", show.ID, show.Title)
+ })
box.PackStart(showsComboBox, true, true, 0)
box.SetHExpand(true)
@@ -119,51 +134,90 @@ func addShowComboBox(grid *gtk.Grid, db *rddb.DBChan) (err error) {
return
}
-// carts, err := db.GetShowCartList(show)
-// if err != nil {
-// return err
-// }
+func addShowCartListEntry(idx int, cart rddb.CartListEntry, p *player.PlayerChan) (err error) {
+ var lcart *gtk.Label
+ if lcart, err = gtk.LabelNew(strconv.FormatUint(uint64(cart.Number), 10)); err != nil {
+ return
+ }
+ showsCartList.Attach(lcart, 1, idx+1, 1, 1)
-// for _, cart := range carts {
-// rhdl.Printf(" [%d]: %s\n", cart.Number, cart.Title)
-// for _, cut := range cart.Cuts {
-// rhdl.Printf(" %+v", cut)
-// }
-// }
+ var ltitle *gtk.Label
+ if ltitle, err = gtk.LabelNew(cart.Title); err != nil {
+ return
+ }
+ ltitle.SetHExpand(true)
+ showsCartList.Attach(ltitle, 2, idx+1, 1, 1)
-// func appendShowListEntry(grid *gtk.Grid, show rddb.ShowListEntry, db *rddb.DBChan, p *player.PlayerChan) error {
-// rhdl.Printf("Show: %d, %s\n", show.ID, show.Title)
+ var btn *gtk.Button
+ if btn, err = gtk.ButtonNewWithLabel("play"); err != nil {
+ return
+ }
+ if len(cart.Cuts) < 1 {
+ btn.SetSensitive(false)
+ } else {
+ btn.Connect("clicked", func(_ *gtk.Button) {
+ if err := p.Load(cart.Number, cart.Cuts[0].Number); err != nil {
+ rhdl.Println(err) // TODO: feedback at GUI?
+ return
+ }
+ if err := p.Play(); err != nil {
+ rhdl.Println(err) // TODO: feedback at GUI?
+ }
+ })
+ if len(cart.Cuts) > 1 {
+ rhl.Println("ingoring additionla cuts for show cart %d", cart.Number)
+ }
+ }
+ showsCartList.Attach(btn, 3, idx+1, 1, 1)
-// return nil
-// }
+ return
+}
-func addShowListRows(box *gtk.ListBox, db *rddb.DBChan, p *player.PlayerChan) (err error) {
- for i := 0; i < 25; i++ {
- var row *gtk.ListBoxRow
- if row, err = gtk.ListBoxRowNew(); err != nil {
- return
- }
+func updateShowCartListRows(show rddb.ShowListEntry, db *rddb.DBChan, p *player.PlayerChan) (err error) {
+ if showsCartList != nil {
+ showsCartListBin.Remove(showsCartList)
+ }
- var label *gtk.Label
- if label, err = gtk.LabelNew(fmt.Sprintf("Row %d", i)); err != nil {
- return
- }
- row.Add(label)
- box.Add(row)
+ if showsCartList, err = gtk.GridNew(); err != nil {
+ return
+ }
+ showsCartList.SetHExpand(true)
+ showsCartList.SetVExpand(true)
+ showsCartList.SetColumnSpacing(10)
+
+ carts, err := db.GetShowCartList(show)
+ if err != nil {
+ return err
}
+
+ for idx, cart := range carts {
+ addShowCartListEntry(idx, cart, p)
+ }
+
+ showsCartListBin.Add(showsCartList)
+ showsCartList.ShowAll()
return
}
-func addShowListBox(grid *gtk.Grid, db *rddb.DBChan, p *player.PlayerChan) (err error) {
- var box *gtk.ListBox
- if box, err = gtk.ListBoxNew(); err != nil {
+func addShowCartList(grid *gtk.Grid, db *rddb.DBChan, p *player.PlayerChan) (err error) {
+ var frame *gtk.Frame
+ if frame, err = gtk.FrameNew(""); err != nil {
return
}
- box.SetSelectionMode(gtk.SELECTION_NONE)
+ showsCartListBin = &frame.Bin
+ var cp *gtk.CssProvider
- if err = addShowListRows(box, db, p); err != nil {
+ if cp, err = gtk.CssProviderNew(); err != nil {
return
}
+ if err = cp.LoadFromData(".frame { border: 0; }"); err != nil {
+ return
+ }
+ var sc *gtk.StyleContext
+ if sc, err = frame.GetStyleContext(); err != nil {
+ return
+ }
+ sc.AddProvider(cp, 600) // TOOD: hardcoded value
var sw *gtk.ScrolledWindow
if sw, err = gtk.ScrolledWindowNew(nil, nil); err != nil {
@@ -171,7 +225,7 @@ func addShowListBox(grid *gtk.Grid, db *rddb.DBChan, p *player.PlayerChan) (err
}
sw.SetHExpand(true)
sw.SetVExpand(true)
- sw.Add(box)
+ sw.Add(frame)
grid.Attach(sw, 1, 2, 1, 1)
return
@@ -186,10 +240,10 @@ func getShowsSelectorWidget(db *rddb.DBChan, p *player.PlayerChan) (gtk.IWidget,
grid.SetHExpand(true)
grid.SetVExpand(true)
- if err = addShowComboBox(grid, db); err != nil {
+ if err = addShowComboBox(grid, db, p); err != nil {
return nil, err
}
- if err = addShowListBox(grid, db, p); err != nil {
+ if err = addShowCartList(grid, db, p); err != nil {
return nil, err
}