1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
//
// rhlibrary
//
// The Radio Helsinki Rivendell Library
//
//
// Copyright (C) 2016 Christian Pointner <equinox@helsinki.at>
//
// This file is part of rhlibrary.
//
// rhlibrary is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// rhlibrary is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with rhlibrary. If not, see <http://www.gnu.org/licenses/>.
//
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 selectPool() rddb.PoolListEntry {
id := poolsComboBox.GetActiveID()
if id == "" {
return rddb.PoolListEntry{}
}
poolsCurrentGroup = id
poolsMutex.Lock()
defer poolsMutex.Unlock()
return pools[poolsCurrentGroup]
}
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) {
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 frame, nil
}
|