From 1cf15abd6edb4579a811230f9a3e053b34ab78e2 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 11 Feb 2016 18:02:51 +0100 Subject: jingle listings work now diff --git a/src/rhlibrary/jingle_selector_widget.go b/src/rhlibrary/jingle_selector_widget.go index fe169c1..d709d57 100644 --- a/src/rhlibrary/jingle_selector_widget.go +++ b/src/rhlibrary/jingle_selector_widget.go @@ -25,11 +25,14 @@ package main import ( + "fmt" "sort" "sync" + "time" "code.helsinki.at/rhrd-go/player" "code.helsinki.at/rhrd-go/rddb" + "github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/gtk" ) @@ -111,12 +114,12 @@ func addJingleComboBox(grid *gtk.Grid, db *rddb.DBChan, p *player.PlayerChan) (e return } - // glib.IdleAdd(func() { - // if err = updateJingleCutListRows(jingle, db, p); err != nil { - // rhdl.Printf("error loading jingle cuts for %d", jingle.ID) - // return - // } - // }) + glib.IdleAdd(func() { + if err = updateJingleCutListRows(jingle, db, p); err != nil { + rhdl.Printf("error loading jingle cuts for %s", jingle.Group) + return + } + }) rhdl.Printf("jingle group %s is now selected: %s", jingle.Group, jingle.Description) }) @@ -127,6 +130,189 @@ func addJingleComboBox(grid *gtk.Grid, db *rddb.DBChan, p *player.PlayerChan) (e return } +func getJingleCutListLabel(caption, css string) (label *gtk.Label, err error) { + if label, err = gtk.LabelNew(caption); err != nil { + return + } + if err = setCssStyle(&label.Widget, css); err != nil { + return + } + + return +} + +func getJingleCutListEntryLabel(caption string, idx int) (label *gtk.Label, err error) { + if (idx & 1) == 1 { + return getJingleCutListLabel(caption, ".label { background-color: #D2D2D2; padding: 7px 15px; }") + } else { + return getJingleCutListLabel(caption, ".label { padding: 7px 15px; }") + } +} + +func getJingleCutListHeadLabel(caption string) (label *gtk.Label, err error) { + return getJingleCutListLabel(caption, ` + .label { + border-bottom: 2px solid; + padding: 8px 15px; + font-weight: bold; + }`) +} + +func addJingleCutListHead(idx int) (err error) { + var lcut *gtk.Label + if lcut, err = getJingleCutListHeadLabel("Cut #"); err != nil { + return + } + jinglesCutList.Attach(lcut, 1, idx, 1, 1) + + var ltitle *gtk.Label + if ltitle, err = getJingleCutListHeadLabel("Titel"); err != nil { + return + } + ltitle.SetHExpand(true) + jinglesCutList.Attach(ltitle, 2, idx, 1, 1) + + var lduration *gtk.Label + if lduration, err = getJingleCutListHeadLabel("Länge"); err != nil { + return + } + jinglesCutList.Attach(lduration, 3, idx, 1, 1) + + var limported *gtk.Label + if limported, err = getJingleCutListHeadLabel("importiert"); err != nil { + return + } + jinglesCutList.Attach(limported, 4, idx, 1, 1) + + var lplay *gtk.Label + if lplay, err = getJingleCutListHeadLabel("Play"); err != nil { + return + } + jinglesCutList.Attach(lplay, 5, idx, 1, 1) + return +} + +func getJingleCutListEntryPlayButton(cart uint, cut rddb.CutListEntry, 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 + } + btn.SetSizeRequest(35, 35) + + var frame *gtk.Frame + if frame, err = gtk.FrameNew(""); 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 = setCssStyle(&frame.Widget, css); err != nil { + return nil, err + } + frame.Add(btn) + + btn.Connect("clicked", func(_ *gtk.Button) { + if err := p.Load(cart, cut.Number); err != nil { + rhdl.Println(err) // TODO: feedback at GUI? + return + } + if err := p.Play(); err != nil { + rhdl.Println(err) // TODO: feedback at GUI? + } + }) + + return frame, nil +} + +func addJingleCutListEntry(idx int, cart uint, cut rddb.CutListEntry, p *player.PlayerChan) (err error) { + var lcut *gtk.Label + if lcut, err = getJingleCutListEntryLabel(fmt.Sprintf("%06d_%03d", cart, cut.Number), idx); err != nil { + return + } + jinglesCutList.Attach(lcut, 1, idx, 1, 1) + + var ltitle *gtk.Label + if ltitle, err = getJingleCutListEntryLabel(cut.Description, idx); err != nil { + return + } + ltitle.SetHExpand(true) + jinglesCutList.Attach(ltitle, 2, idx, 1, 1) + + duration := time.Unix(0, 0).UTC().Add(cut.Duration).Format("15:04:05.0") + imported := "-" + if cut.Imported.Valid { + imported = cut.Imported.Time.Format("Mon 02.01.2006 15:04:05") + } + + var lduration *gtk.Label + if lduration, err = getJingleCutListEntryLabel(duration, idx); err != nil { + return + } + jinglesCutList.Attach(lduration, 3, idx, 1, 1) + + var limported *gtk.Label + if limported, err = getJingleCutListEntryLabel(imported, idx); err != nil { + return + } + jinglesCutList.Attach(limported, 4, idx, 1, 1) + + var btn gtk.IWidget + if btn, err = getJingleCutListEntryPlayButton(cart, cut, p, idx); err != nil { + return + } + jinglesCutList.Attach(btn, 5, idx, 1, 1) + return +} + +func addJingleCutListSpacer(idx int) (err error) { + var ltitle *gtk.Label + if ltitle, err = getJingleCutListHeadLabel("deaktivirt"); err != nil { + return + } + ltitle.SetHExpand(true) + jinglesCutList.Attach(ltitle, 1, idx, 5, 1) + + return +} + +func updateJingleCutListRows(jingle rddb.JingleListEntry, db *rddb.DBChan, p *player.PlayerChan) (err error) { + if jinglesCutList != nil { + jinglesCutListBin.Remove(jinglesCutList) + } + + if jinglesCutList, err = gtk.GridNew(); err != nil { + return + } + jinglesCutList.SetHExpand(true) + jinglesCutList.SetVExpand(true) + + activeCart, inactiveCart, err := db.GetJingleCutList(jingle) + if err != nil { + return err + } + + idx := 1 + addJingleCutListHead(idx) + for _, cut := range activeCart.Cuts { + idx++ + addJingleCutListEntry(idx, activeCart.Number, cut, p) + } + if len(inactiveCart.Cuts) > 0 { + idx++ + addJingleCutListSpacer(idx) + for _, cut := range inactiveCart.Cuts { + idx++ + addJingleCutListEntry(idx, inactiveCart.Number, cut, p) + } + } + + jinglesCutListBin.Add(jinglesCutList) + jinglesCutList.ShowAll() + return +} + func addJingleCutList(grid *gtk.Grid, db *rddb.DBChan, p *player.PlayerChan) (err error) { var frame *gtk.Frame if frame, err = gtk.FrameNew(""); err != nil { -- cgit v0.10.2