summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-02-06 05:47:26 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-02-06 05:47:26 (GMT)
commit19325b246ad32046be6ce50216f6f7f4de9984df (patch)
treee2d51c791ea68fb695e8f5867c4708d3ae60b3b3 /src
parentf4f8c243337a2d1b4a8175e9bad894929e8ba20a (diff)
beatify show listing
Diffstat (limited to 'src')
-rw-r--r--src/rhlibrary/main.go3
-rw-r--r--src/rhlibrary/show_selector_widget.go211
2 files changed, 188 insertions, 26 deletions
diff --git a/src/rhlibrary/main.go b/src/rhlibrary/main.go
index 91e5790..1f6900d 100644
--- a/src/rhlibrary/main.go
+++ b/src/rhlibrary/main.go
@@ -99,13 +99,12 @@ func main() {
return
}
- mw, err := NewAppWindow(db.GetInterface(), p.GetInterface(), 800, 600)
+ mw, err := NewAppWindow(db.GetInterface(), p.GetInterface(), 1200, 800)
if err != nil {
rhl.Println("Error initializing Main Window:", err)
return
}
-
rhl.Printf("rhlibrary started as user: %s", rhuser.Username)
mw.ShowAndRun()
diff --git a/src/rhlibrary/show_selector_widget.go b/src/rhlibrary/show_selector_widget.go
index c0a8c8e..d1390f7 100644
--- a/src/rhlibrary/show_selector_widget.go
+++ b/src/rhlibrary/show_selector_widget.go
@@ -28,6 +28,7 @@ import (
"sort"
"strconv"
"sync"
+ "time"
"code.helsinki.at/rhrd-go/player"
"code.helsinki.at/rhrd-go/rddb"
@@ -134,42 +135,204 @@ func addShowComboBox(grid *gtk.Grid, db *rddb.DBChan, p *player.PlayerChan) (err
return
}
+func getShowCartListLabel(caption, css string) (label *gtk.Label, err error) {
+ if label, err = gtk.LabelNew(caption); err != nil {
+ return
+ }
+
+ var cp *gtk.CssProvider
+ if cp, err = gtk.CssProviderNew(); err != nil {
+ return
+ }
+ if err = cp.LoadFromData(css); err != nil {
+ return
+ }
+ var sc *gtk.StyleContext
+ if sc, err = label.GetStyleContext(); err != nil {
+ return
+ }
+ sc.AddProvider(cp, 600) // TOOD: hardcoded value
+
+ return
+}
+
+func getShowCartListEntryLabel(caption string, idx int) (label *gtk.Label, err error) {
+ if (idx & 1) == 1 {
+ return getShowCartListLabel(caption, ".label { background-color: #D2D2D2; padding: 7px 15px; }")
+ } else {
+ return getShowCartListLabel(caption, ".label { padding: 7px 15px; }")
+ }
+}
+
+func getShowCartListHeadLabel(caption string) (label *gtk.Label, err error) {
+ return getShowCartListLabel(caption, `
+ .label {
+ border-bottom: 2px solid;
+ padding: 8px 15px;
+ font-weight: bold;
+ }`)
+}
+
+func getShowCartListEntryPlayButton(cart rddb.CartListEntry, p *player.PlayerChan, idx int) (gtk.IWidget, error) {
+ btn, err := gtk.ButtonNewFromIconName("media-playback-start", gtk.ICON_SIZE_SMALL_TOOLBAR)
+ if err != nil {
+ return nil, err
+ }
+
+ var frame *gtk.Frame
+ if frame, err = gtk.FrameNew(""); err != nil {
+ return nil, err
+ }
+
+ var cp *gtk.CssProvider
+ if cp, err = gtk.CssProviderNew(); err != nil {
+ return nil, err
+ }
+ css := ".frame { border: 0; padding: 4px 15px; }"
+ if (idx & 1) == 1 {
+ css = ".frame { border: 0; background-color: #D2D2D2; padding: 4px 15px; }"
+ }
+ if err = cp.LoadFromData(css); err != nil {
+ return nil, err
+ }
+ var sc *gtk.StyleContext
+ if sc, err = frame.GetStyleContext(); err != nil {
+ return nil, err
+ }
+ sc.AddProvider(cp, 600) // TOOD: hardcoded value
+ frame.Add(btn)
+
+ if len(cart.Cuts) < 1 {
+ btn.SetSensitive(false)
+ return frame, nil
+ }
+
+ 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 additional cuts for show cart %d", cart.Number)
+ }
+
+ return frame, nil
+}
+
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 {
+ if lcart, err = getShowCartListEntryLabel(strconv.FormatUint(uint64(cart.Number), 10), idx); err != nil {
return
}
- showsCartList.Attach(lcart, 1, idx+1, 1, 1)
+ showsCartList.Attach(lcart, 1, idx, 1, 1)
+ title := "-"
+ if cart.Exists {
+ title = cart.Title
+ }
var ltitle *gtk.Label
- if ltitle, err = gtk.LabelNew(cart.Title); err != nil {
+ if ltitle, err = getShowCartListEntryLabel(title, idx); err != nil {
return
}
ltitle.SetHExpand(true)
- showsCartList.Attach(ltitle, 2, idx+1, 1, 1)
+ showsCartList.Attach(ltitle, 2, idx, 1, 1)
+
+ duration := "-"
+ imported := "-"
+ numplayed := "-"
+ lastplayed := "-"
+ if len(cart.Cuts) >= 1 {
+ duration = time.Unix(0, 0).UTC().Add(cart.Cuts[0].Duration).Format("15:04:05.0")
+ if cart.Cuts[0].Imported.Valid {
+ imported = cart.Cuts[0].Imported.Time.Format("Mon 02.01.2006 15:04:05")
+ }
- var btn *gtk.Button
- if btn, err = gtk.ButtonNewWithLabel("play"); err != nil {
+ numplayed = strconv.FormatUint(uint64(cart.Cuts[0].NumPlayed), 10)
+ if cart.Cuts[0].LastPlayed.Valid {
+ lastplayed = cart.Cuts[0].LastPlayed.Time.Format("Mon 02.01.2006 15:04:05")
+ }
+ }
+
+ var lduration *gtk.Label
+ if lduration, err = getShowCartListEntryLabel(duration, idx); 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(lduration, 3, idx, 1, 1)
+
+ var limported *gtk.Label
+ if limported, err = getShowCartListEntryLabel(imported, idx); err != nil {
+ return
+ }
+ showsCartList.Attach(limported, 4, idx, 1, 1)
+
+ var lnumplayed *gtk.Label
+ if lnumplayed, err = getShowCartListEntryLabel(numplayed, idx); err != nil {
+ return
+ }
+ showsCartList.Attach(lnumplayed, 5, idx, 1, 1)
+
+ var llastplayed *gtk.Label
+ if llastplayed, err = getShowCartListEntryLabel(lastplayed, idx); err != nil {
+ return
+ }
+ showsCartList.Attach(llastplayed, 6, idx, 1, 1)
+
+ var btn gtk.IWidget
+ if btn, err = getShowCartListEntryPlayButton(cart, p, idx); err != nil {
+ return
+ }
+ showsCartList.Attach(btn, 7, idx, 1, 1)
+ return
+}
+
+func addShowCartListHead(idx int) (err error) {
+ var lcart *gtk.Label
+ if lcart, err = getShowCartListHeadLabel("Cart #"); err != nil {
+ return
}
- showsCartList.Attach(btn, 3, idx+1, 1, 1)
+ showsCartList.Attach(lcart, 1, idx, 1, 1)
+ var ltitle *gtk.Label
+ if ltitle, err = getShowCartListHeadLabel("Titel"); err != nil {
+ return
+ }
+ ltitle.SetHExpand(true)
+ showsCartList.Attach(ltitle, 2, idx, 1, 1)
+
+ var lduration *gtk.Label
+ if lduration, err = getShowCartListHeadLabel("Länge"); err != nil {
+ return
+ }
+ showsCartList.Attach(lduration, 3, idx, 1, 1)
+
+ var limported *gtk.Label
+ if limported, err = getShowCartListHeadLabel("importiert"); err != nil {
+ return
+ }
+ showsCartList.Attach(limported, 4, idx, 1, 1)
+
+ var lnumplayed *gtk.Label
+ if lnumplayed, err = getShowCartListHeadLabel("# gespielt"); err != nil {
+ return
+ }
+ showsCartList.Attach(lnumplayed, 5, idx, 1, 1)
+
+ var llastplayed *gtk.Label
+ if llastplayed, err = getShowCartListHeadLabel("zuletzt gespielt"); err != nil {
+ return
+ }
+ showsCartList.Attach(llastplayed, 6, idx, 1, 1)
+
+ var lplay *gtk.Label
+ if lplay, err = getShowCartListHeadLabel("Play"); err != nil {
+ return
+ }
+ showsCartList.Attach(lplay, 7, idx, 1, 1)
return
}
@@ -183,15 +346,15 @@ func updateShowCartListRows(show rddb.ShowListEntry, db *rddb.DBChan, p *player.
}
showsCartList.SetHExpand(true)
showsCartList.SetVExpand(true)
- showsCartList.SetColumnSpacing(10)
carts, err := db.GetShowCartList(show)
if err != nil {
return err
}
+ addShowCartListHead(1)
for idx, cart := range carts {
- addShowCartListEntry(idx, cart, p)
+ addShowCartListEntry(idx+2, cart, p)
}
showsCartListBin.Add(showsCartList)