diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-02-25 16:02:29 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-02-25 16:02:29 (GMT) |
commit | 0a5d62208b7e8e58010d8e8ada95927579cc1ff1 (patch) | |
tree | 0aba9104a25e96f8c0420fe75ce7d626ab6c25f6 /src | |
parent | 4bfb03ad2b14f5aaa149f471dff13a75ecb22a8c (diff) |
added treeview for pools
Diffstat (limited to 'src')
-rw-r--r-- | src/rhlibrary/pool_selector_widget.go | 66 |
1 files changed, 58 insertions, 8 deletions
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 { |