Class: Sh::Queue

Inherits:
Object show all
Defined in:
lib/sh_queue.rb

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ Queue

Returns a new instance of Queue.



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
# File 'lib/sh_queue.rb', line 3

def initialize view
  @view = view
  sw = ScrolledWindow.new(nil, nil)
  @widget = sw
  sw.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
  @sto_tabs = ListStore.new(String, Song)
  lst_tabs = TreeView.new @sto_tabs
  renderer = CellRendererText.new
  column = TreeViewColumn.new('Artist',
    renderer,
    'text' => 0)
  lst_tabs.append_column column
  renderer = CellRendererText.new
  column = TreeViewColumn.new('Song', renderer)
  column.set_cell_data_func(renderer) do |tvc, cell, model, iter|
    cell.text = ''
    data = iter[1]
    if data.title
      cell.text = sprintf("%.2d\t%s", data.track_num, data.title)
    else
      cell.text = data.path.split('/').last
    end
  end
  lst_tabs.append_column column
  sw.add lst_tabs

  lst_tabs.signal_connect('row_activated') do |widget, path, col|
    iter = lst_tabs.model.get_iter(path)
    song = iter[1]
    view.stop
    view.set_queue_pos path.indices.first
    view.play
  end
end

Instance Method Details

#updateObject



38
39
40
41
42
43
44
45
# File 'lib/sh_queue.rb', line 38

def update
  @sto_tabs.clear
  @view.queue.each do |song|
    iter = @sto_tabs.append
    iter[0] = song.artist.name
    iter[1] = song
  end if @view.queue
end

#widgetObject



47
48
49
# File 'lib/sh_queue.rb', line 47

def widget
  return @widget
end