Class: Sh::CoverBrowse

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

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ CoverBrowse

Returns a new instance of CoverBrowse.



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

def initialize view
  @model = ListStore.new(Gdk::Pixbuf, Object)
  @model.set_default_sort_func do |a, b|
    album_a, album_b = a[COL_ALBUM], b[COL_ALBUM]
    comparison = album_a.artist.name <=> album_b.artist.name
    if comparison == 0
      comparison = album_a.title <=> album_b.title
    end
    comparison
  end
  @model.set_sort_column_id(TreeSortable::DEFAULT_SORT_COLUMN_ID,
  	Gtk::SORT_ASCENDING)
  
  @iconview = IconView.new @model
  @iconview.pixbuf_column = COL_PIXBUF
  @iconview.signal_connect 'item_activated' do |iconview, path|
  	iter = @model.get_iter path
  	album = iter[COL_ALBUM]
  	if album
  		view.stop
      view.set_queue(album.songs.sort_by {|s| s.to_s || ''})
      view.play
  	end
  end

  GLib::Timeout.add(1000) do
    fill_model
    false
  end

  @scroll = ScrolledWindow.new(nil, nil)
  @scroll.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
  @scroll.add @iconview
end

Instance Method Details

#fill_modelObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sh_cover_browse.rb', line 40

def fill_model
  @model.clear
	Album.each do |album|
    begin
      pixbuf = Gdk::Pixbuf.new(album.image_path).scale(128, 128)
      iter = @model.append
      iter[COL_ALBUM] = album
      iter[COL_PIXBUF] = pixbuf
    rescue
      # Insufficient data about album
    end
	end
end

#widgetObject



54
55
56
# File 'lib/sh_cover_browse.rb', line 54

def widget
  return @scroll
end