diff options
-rw-r--r-- | src/rhlibrary/pool_selector_widget.go | 106 | ||||
-rw-r--r-- | src/rhlibrary/selector_widget.go | 2 |
2 files changed, 105 insertions, 3 deletions
diff --git a/src/rhlibrary/pool_selector_widget.go b/src/rhlibrary/pool_selector_widget.go index d03f475..aa33e2f 100644 --- a/src/rhlibrary/pool_selector_widget.go +++ b/src/rhlibrary/pool_selector_widget.go @@ -25,16 +25,118 @@ package main import ( + "sort" + "sync" + "code.helsinki.at/rhrd-go/player" "code.helsinki.at/rhrd-go/rddb" "github.com/gotk3/gotk3/gtk" ) +var ( + poolsMutex sync.Mutex + pools rddb.PoolList + poolsComboBox *gtk.ComboBoxText + poolsCurrentGroup string +) + +func fetchPools(db *rddb.DBChan) (err error) { + poolsMutex.Lock() + defer poolsMutex.Unlock() + + if pools, err = db.GetPoolList(rhuser.Username); err != nil { + return err + } + return +} + +func updatePools(db *rddb.DBChan) (err error) { + if err = fetchPools(db); err != nil { + return + } + + var keys []string + for k, _ := range pools { + keys = append(keys, k) + } + sort.Strings(keys) + + poolsComboBox.RemoveAll() + for _, group := range keys { + poolsComboBox.Append(group, pools[group].Description) + } + + if !poolsComboBox.SetActiveID(poolsCurrentGroup) { + poolsComboBox.SetActive(0) + } + return +} + +func addPoolComboBox(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 + } + + var label *gtk.Label + if label, err = gtk.LabelNew("Musik-Pool auswählen"); err != nil { + return + } + box.PackStart(label, false, false, 0) + + if poolsComboBox, err = gtk.ComboBoxTextNew(); err != nil { + return + } + if err = updatePools(db); err != nil { + return err + } + poolsComboBox.Connect("changed", func(_ *gtk.ComboBoxText) { + // pool := selectPool() + // if pool.Group == "" { + // return + // } + + // glib.IdleAdd(func() { + // if err = updatePoolCartListRows(pool, db, p); err != nil { + // rhdl.Printf("error loading pool carts for %s", pool.Group) + // return + // } + // }) + // rhdl.Printf("pool %s is now selected: %s", pool.Group, pool.Description) + }) + + box.PackStart(poolsComboBox, true, true, 0) + box.SetHExpand(true) + + grid.Attach(box, 1, 1, 1, 1) + return +} + func getPoolsSelectorWidget(db *rddb.DBChan, p *player.PlayerChan) (gtk.IWidget, error) { - page, err := gtk.LabelNew("MUSIC POOLS") + grid, err := gtk.GridNew() if err != nil { return nil, err } + grid.SetRowSpacing(25) + grid.SetHExpand(true) + grid.SetVExpand(true) + + if err = addPoolComboBox(grid, db, p); err != nil { + return nil, err + } + // if err = addPoolCartList(grid, db, p); err != nil { + // return nil, err + // } + + var frame *gtk.Frame + if frame, err = gtk.FrameNew(""); err != nil { + return nil, err + } + if err = setCssStyle(&frame.Widget, ".frame { border: 0; padding: 25px 42px; }"); err != nil { + return nil, err + } + + frame.Add(grid) - return page, nil + return frame, nil } diff --git a/src/rhlibrary/selector_widget.go b/src/rhlibrary/selector_widget.go index 3ab52d0..1eec520 100644 --- a/src/rhlibrary/selector_widget.go +++ b/src/rhlibrary/selector_widget.go @@ -139,7 +139,7 @@ func getSelectorWidget(db *rddb.DBChan, p *player.PlayerChan) (gtk.IWidget, erro case 1: updateJingles(db) case 2: - // updatePools(db) + updatePools(db) case 3: // nothing to do here default: |