Class: Sh::Playlists

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ Playlists

Returns a new instance of Playlists.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/sh_playlist.rb', line 63

def initialize view
  @tree = TreeView.new
  @tree.selection.mode = Gtk::SELECTION_MULTIPLE

  renderer = CellRendererText.new
  column = TreeViewColumn.new('Playlists',
    renderer,
    'text' => 0)
  @tree.append_column column

  @model = TreeStore.new(String, Array)
  @tree.model = @model

  @tree.signal_connect('row_activated') do |widget, path, col|
    iter = @tree.model.get_iter(path)
		view.stop
    view.queue = iter[1].dup
    view.play
  end

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

Class Method Details

.load_playlistsObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/sh_playlist.rb', line 88

def self.load_playlists
	playlists = []
	if File.exists? Sh::Global::PATHS[:playlists_file]
		arr = YAML.load_file Sh::Global::PATHS[:playlists_file]
	arr.sort_by {|a| (a.first || '')}.each do |name, paths|
    playlist = Playlist.new name
    paths.each do |path|
    	if File.exists? path
        if Global::SUPPORTED_EXTENSIONS.include? File.extname(path)
          song = (Song.first(:path => path) || Database.add_song(path))
    			playlist << song
        end
      else
        Sh::Log.info "File at #{ref} not found"
      end
    end
    playlists << playlist
  end
  end
  return playlists
end

Instance Method Details

#fill_modelObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/sh_playlist.rb', line 110

def fill_model
	@model.clear
  Playlists.load_playlists.each do |playlist|
    parent_node = @model.append nil
    parent_node[0] = playlist.name
    parent_node[1] = []
    playlist.songs.each do |song|
    	node = @model.append parent_node
			node[0] = song.title
			node[1] = [song]
			parent_node[1] << song
    end
    Kelp.process_events
  end
end

#widgetObject



126
127
128
129
# File 'lib/sh_playlist.rb', line 126

def widget
	fill_model
  return @scroll
end