From 0a5d62208b7e8e58010d8e8ada95927579cc1ff1 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 25 Feb 2016 17:02:29 +0100 Subject: added treeview for pools diff --git a/src/rhlibrary/pool_selector_widget.go b/src/rhlibrary/pool_selector_widget.go index cc01fcc..850a685 100644 --- a/src/rhlibrary/pool_selector_widget.go +++ b/src/rhlibrary/pool_selector_widget.go @@ -25,6 +25,7 @@ package main import ( + "fmt" "sort" "sync" @@ -34,11 +35,19 @@ import ( "github.com/gotk3/gotk3/gtk" ) +const ( + POOLS_COL_CART = iota + POOLS_COL_ARTIST + POOLS_COL_TITLE + POOLS_COL_ALBUM +) + var ( - poolsMutex sync.Mutex - pools rddb.PoolList - poolsComboBox *gtk.ComboBoxText - poolsCurrentGroup string + poolsMutex sync.Mutex + pools rddb.PoolList + poolsComboBox *gtk.ComboBoxText + poolsCurrentGroup string + PoolsCartListStore *gtk.ListStore ) func fetchPools(db *rddb.DBChan) (err error) { @@ -132,10 +141,51 @@ func updatePoolCartListRows(pool rddb.PoolListEntry, db *rddb.DBChan, p *player. return err } + PoolsCartListStore.Clear() for num, cart := range carts { - rhdl.Printf("Pool Cart [%d]: %+v", num, cart) + iter := PoolsCartListStore.Append() + err = PoolsCartListStore.Set(iter, + []int{POOLS_COL_CART, POOLS_COL_ARTIST, POOLS_COL_TITLE, POOLS_COL_ALBUM}, + []interface{}{fmt.Sprintf("%d", num), cart.Artist, cart.Title, cart.Album}) + if err != nil { + return + } + } + + return +} + +func appendPoolCartListColumn(tree *gtk.TreeView, title string, id int) (err error) { + var cell *gtk.CellRendererText + if cell, err = gtk.CellRendererTextNew(); err != nil { + return + } + + var col *gtk.TreeViewColumn + if col, err = gtk.TreeViewColumnNewWithAttribute(title, cell, "text", id); err != nil { + return + } + tree.AppendColumn(col) + return +} + +func addPoolCartList(grid *gtk.Grid, db *rddb.DBChan, p *player.PlayerChan) (err error) { + var tree *gtk.TreeView + if tree, err = gtk.TreeViewNew(); err != nil { + return } + appendPoolCartListColumn(tree, "#Cart", POOLS_COL_CART) + appendPoolCartListColumn(tree, "Interpret", POOLS_COL_ARTIST) + appendPoolCartListColumn(tree, "Titel", POOLS_COL_TITLE) + appendPoolCartListColumn(tree, "Album", POOLS_COL_ALBUM) + + if PoolsCartListStore, err = gtk.ListStoreNew(glib.TYPE_STRING, glib.TYPE_STRING, glib.TYPE_STRING, glib.TYPE_STRING); err != nil { + return + } + tree.SetModel(PoolsCartListStore) + + grid.Attach(tree, 1, 2, 1, 1) return } @@ -151,9 +201,9 @@ func getPoolsSelectorWidget(db *rddb.DBChan, p *player.PlayerChan) (gtk.IWidget, if err = addPoolComboBox(grid, db, p); err != nil { return nil, err } - // if err = addPoolCartList(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 { -- cgit v0.10.2