Class: PlayList
Instance Attribute Summary collapse
-
#listview ⇒ Object
Returns the value of attribute listview.
Instance Method Summary collapse
- #add(entry, position = "append") ⇒ Object
- #call_browser ⇒ Object
- #clear_list ⇒ Object
- #close_window ⇒ Object
- #init_ui ⇒ Object
-
#initialize ⇒ PlayList
constructor
A new instance of PlayList.
- #load_list ⇒ Object
- #on_browser_signals(signal) ⇒ Object
- #on_list_signals(*signal) ⇒ Object
- #remove_tracks ⇒ Object
- #save_list ⇒ Object
- #show_list ⇒ Object
Constructor Details
Instance Attribute Details
#listview ⇒ Object
Returns the value of attribute listview.
12 13 14 |
# File 'lib/gswax/playlist.rb', line 12 def listview @listview end |
Instance Method Details
#add(entry, position = "append") ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/gswax/playlist.rb', line 78 def add(entry, position = "append") if entry.class == String @listview.add_to_list(entry, position) elsif entry.class == Array entry.each{|e| @listview.add_to_list(e, position)} end @clear_list_btn.sensitive = true @save_list_btn.sensitive = true end |
#call_browser ⇒ Object
111 112 113 |
# File 'lib/gswax/playlist.rb', line 111 def call_browser changed; notify_observers("BROWSER") end |
#clear_list ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/gswax/playlist.rb', line 127 def clear_list if confirm("clear playlist?") @listview.store.clear @clear_list_btn.sensitive = false @save_list_btn.sensitive = false changed; notify_observers("CLEAR_LIST") end end |
#close_window ⇒ Object
178 179 180 |
# File 'lib/gswax/playlist.rb', line 178 def close_window @win.destroy end |
#init_ui ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gswax/playlist.rb', line 22 def init_ui @win = Gtk::Window.new @win.set_size_request(500, 500) @win.icon = Gdk::Pixbuf.new File.join(DIR, '../static/gshoes-icon.png') @win.title = 'Playlist' @win.signal_connect("destroy"){changed; notify_observers("PLAYLIST_CLOSED")} @main = Gtk::VBox.new(false, 5) show_list @win.add(@main) @win.show_all end |
#load_list ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/gswax/playlist.rb', line 136 def load_list list = [] playlist_dir = File.join(Settings.brains_dir, "playlists") unless Dir.exists?(playlist_dir) Dir.mkdir(playlist_dir) end Dir.chdir(playlist_dir){ @openfile = ask_open_file } if @openfile File.open(@openfile, "r"){|file| file.each_line{|line| list << line.chomp} } end @listview.store.clear add(list) list.insert(0, @openfile) list.insert(0, "LOAD_LIST") changed; notify_observers(list) end |
#on_browser_signals(signal) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/gswax/playlist.rb', line 99 def on_browser_signals(signal) case signal[0] when "PREPEND" add(signal[1..-1], "prepend") when "APPEND" add(signal[1..-1]) when "PLAY_NOW" add(signal[1]) end changed; notify_observers(signal) end |
#on_list_signals(*signal) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gswax/playlist.rb', line 88 def on_list_signals(*signal) case signal[0] when "changed" @remove_tracks_btn.sensitive = true when "row-activated" iter = @listview.store.get_iter(signal[2]) entry = iter[1] changed; notify_observers(["PLAY_NOW", entry]) end end |
#remove_tracks ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/gswax/playlist.rb', line 115 def remove_tracks tracks = [] @listview.list_selection.selected_rows.each{|path| iter = @listview.store.get_iter(path) tracks << iter[1] @listview.store.remove(iter) } tracks.insert(0, "REMOVE") changed; notify_observers(tracks) end |
#save_list ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/gswax/playlist.rb', line 159 def save_list unless Dir.exists?(File.dirname(File.(__FILE__)) + "/playlists/") Dir.mkdir(File.dirname(File.(__FILE__)) + "/playlists/") end Dir.chdir(File.dirname(File.(__FILE__)) + "/playlists/"){ @savefile = ask_save_file } if @savefile @listview.list_selection.select_all File.open(@savefile, "w+"){|file| @listview.list_selection.selected_each{|mod, path, iter| file.puts iter[1]} } @listview.list_selection.unselect_all changed; notify_observers(["SAVE_LIST", @savefile]) end end |
#show_list ⇒ Object
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 |
# File 'lib/gswax/playlist.rb', line 37 def show_list list_panel = Gtk::ScrolledWindow.new list_panel.set_size_request(500, 460) hadjust = list_panel.hadjustment vadjust = list_panel.vadjustment = Gtk::Viewport.new(hadjust, vadjust) list_panel.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS) list_panel.(@listview.list) btn_panel = Gtk::HBox.new(true, 2) add_tracks_btn = Gtk::Button.new("add tracks") add_tracks_btn.signal_connect("clicked"){call_browser} @remove_tracks_btn = Gtk::Button.new("remove tracks") @remove_tracks_btn.signal_connect("clicked"){remove_tracks} @remove_tracks_btn.sensitive = false @clear_list_btn = Gtk::Button.new("clear list") @clear_list_btn.signal_connect("clicked"){clear_list} @clear_list_btn.sensitive = false load_list_btn = Gtk::Button.new("load list") load_list_btn.signal_connect("clicked"){load_list} @save_list_btn = Gtk::Button.new("save list") @save_list_btn.signal_connect("clicked"){save_list} @save_list_btn.sensitive = false btn_panel.pack_start(add_tracks_btn, true, true, 1) btn_panel.pack_start(@remove_tracks_btn, true, true, 1) btn_panel.pack_start(@clear_list_btn, true, true, 1) btn_panel.pack_start(load_list_btn, true, true, 1) btn_panel.pack_start(@save_list_btn, true, true, 1) @main.pack_start(list_panel, true, true, 0) @main.pack_end(btn_panel, true, true, 0) end |