diff options
Diffstat (limited to 'bin/grux.rb')
-rwxr-xr-x | bin/grux.rb | 303 |
1 files changed, 193 insertions, 110 deletions
diff --git a/bin/grux.rb b/bin/grux.rb index 3583f3d..ea75e69 100755 --- a/bin/grux.rb +++ b/bin/grux.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/usr/bin/env ruby -w #$: << File.expand_path(File.dirname(FILE) + “/../lib”)) @@ -13,21 +13,14 @@ end class Grux::ClientWin < Gtk::VBox attr_reader :status - def initialize - super + def initialize( server_address ) + super() - @status = Hash.new @server = Xmms::Client.new( 'Grux' ) - begin - @server.connect( ENV['XMMS_PATH'] ) - @server.add_to_glib_mainloop - rescue Xmms::Client::ClientError => ex - warn "Connection failed. Error Code:" - warn ex - raise - end + @status = Hash.new + @status[:connected] = self.connect( server_address ) @statusBox = Gtk::HBox.new @mainBox = Gtk::VPaned.new @@ -80,8 +73,8 @@ class Grux::ClientWin < Gtk::VBox @toolTabs = [ [ @extinfoTab = Gtk::VBox.new, @extinfoTabLbl = Gtk::Label.new( "Status" ) ], - [ @tageditorTab = Gtk::VBox.new, - @tageditorTabLbl = Gtk::Label.new( "Tag Editor" ) ] + [ @tageditorTab = Gtk::VBox.new, + @tageditorTabLbl = Gtk::Label.new( "Tag Editor" ) ] ] @toolTabs.each do |content, label| @toolChsr.append_page( Gtk::ScrolledWindow.new.add_with_viewport( content ), label ) @@ -92,22 +85,23 @@ class Grux::ClientWin < Gtk::VBox @medialistColumns = [ 'id', 'artist', 'title' ] @medialists = [ - [ @plalistViewLbl = Gtk::Label.new( "Current Playlist" ), + [ @playlistViewLbl = Gtk::Label.new( "Current Playlist" ), @playlistViewWin = Gtk::ScrolledWindow.new, @playlistView = Gtk::TreeView.new, - @playlistStore = Gtk::ListStore.new( String, String, String ) - ], + @playlistStore = Gtk::ListStore.new( String, String, String ) + ], [ @medialibViewLbl = Gtk::Label.new( "Medialib" ), @medialibViewWin = Gtk::ScrolledWindow.new, @medialibView = Gtk::TreeView.new, - @medialibList = Gtk::ListStore.new( String, String, String ) - ] + @medialibStore = Gtk::ListStore.new( String, String, String ) + ] ] @medialists.each do |label, window, view, store| @medialistColumns.each_with_index do |tag, index| view.append_column Gtk::TreeViewColumn.new( tag, @medialistTextRenderer, :text => index ) end + view.search_column = 2 @medialistsWin.append_page( window.add( view ), label ) end @@ -115,44 +109,6 @@ class Grux::ClientWin < Gtk::VBox self.show_all - @server.broadcast_coll_changed do |*foo| - p foo - end - @server.broadcast_config_value_changed do |*foo| - p foo - end - @server.broadcast_mediainfo_reader_status do |*foo| - p foo - end - @server.broadcast_medialib_entry_added do |*foo| - p foo - end - @server.broadcast_medialib_entry_changed do |*foo| - p foo - end - @server.broadcast_playback_current_id.notifier do |id| - self.handle_current_id id - end - @server.broadcast_playback_status.notifier do |playing| - self.handle_playback_status playing - end - @server.broadcast_playback_volume_changed do |*foo| - p foo - end - @server.broadcast_playlist_changed do |*foo| - p foo - end - @server.broadcast_playlist_current_pos.notifier do |pos| - self.handle_current_pos pos - end - @server.broadcast_playlist_loaded do |*foo| - p foo - end - @server.broadcast_quit do |*foo| - p foo - end - - @playBtnClkdHndlr = @playBtn.signal_connect :clicked do self.start_playback end @@ -163,10 +119,10 @@ class Grux::ClientWin < Gtk::VBox self.stop_playback end @nextBtn.signal_connect :clicked do - self.step_in_playlist 1 + self.step_in_playlist( 1 ) end @prevBtn.signal_connect :clicked do - self.step_in_playlist -1 + self.step_in_playlist( -1 ) end @rndmBtn.signal_connect :clicked do self.randomize_playlist @@ -191,8 +147,16 @@ class Grux::ClientWin < Gtk::VBox @medialibView.signal_connect :row_activated do |view, path, column| - @server.playlist.add_entry( path.to_str.to_i ).notifier do - @server.playlist_set_next( path.to_str.to_i ).notifier do + songid = @medialibStore.get_iter( path )[0].to_i + @server.playlist.add_entry( songid ).notifier do + current_row = @playlistStore.append + @server.medialib_get_info( songid ).notifier do |songinfo| + current_row[0] = songid.to_s + current_row[1] = songinfo[:artist] ? songinfo[:artist].first[1] : "" + current_row[2] = songinfo[:title] ? songinfo[:title].first[1] : "" + true + end + @server.playlist_set_next( current_row.to_s.to_i ).notifier do @server.playback_tickle.notifier do self.start_playback true @@ -203,30 +167,105 @@ class Grux::ClientWin < Gtk::VBox end - self.resync_complete - + if @status[:connected] + p "connected" + self.resync_complete + end end - def xmmspls_to_lststor( playlist, store ) - @status[:playlist] = playlist - playlist.each_with_index do |id, index| - current_row = store.append - @server.medialib_get_info( id ).notifier do |songinfo| - current_row[0] = index.to_s - current_row[1] = songinfo[:artist] ? songinfo[:artist].first[1] : "" - current_row[2] = songinfo[:title] ? songinfo[:title].first[1] : "" - true - end + def connect( address ) + begin + @server.connect( address ) + @server.add_to_glib_mainloop + rescue Xmms::Client::ClientError => ex + warn "Connection failed. Error Code:" + warn ex + return false end - store + + + @server.broadcast_coll_changed.notifier do |*foo| + self.handle_coll_changed foo + true + end + @server.broadcast_config_value_changed.notifier do |*foo| + self.handle_config_value_changed foo + true + end + @server.broadcast_mediainfo_reader_status.notifier do |*foo| + self.handle_mediainfo_reader_status foo + true + end + @server.broadcast_medialib_entry_added.notifier do |*foo| + self.handle_medialib_entry_added foo + true + end + @server.broadcast_medialib_entry_changed.notifier do |*foo| + self.handle_medialib_entry_changed foo + true + end + @server.broadcast_playback_current_id.notifier do |id| + self.handle_playback_current_id id + true + end + @server.broadcast_playback_status.notifier do |status| + self.handle_playback_status status + true + end + @server.broadcast_playback_volume_changed.notifier do |*foo| + self.handle_playback_volume_changed foo + true + end + @server.broadcast_playlist_changed.notifier do |*foo| + self.handle_playlist_changed foo + true + end + @server.broadcast_playlist_current_pos.notifier do |pos| + self.handle_playlist_current_pos pos + true + end + @server.broadcast_playlist_loaded.notifier do |*foo| + self.handle_playlist_loaded foo + true + end + @server.broadcast_quit.notifier do |*foo| + self.handle_quit foo + true + end + true end - def handle_current_id( id ) + def handle_coll_changed( *foo ) + p "Collection changed: #{foo}" + true + end + def handle_config_value_changed( *foo ) + p "Config changed: #{foo}" + true + end + def handle_mediainfo_reader_status( *foo ) + p "Mediainfo reader status changed: #{foo}" + true + end + def handle_medialib_entry_added( *foo ) + p "Medialib entry added: #{foo}" + true + end + def handle_medialib_entry_changed( *foo ) + p "Medialib entry changed: #{foo}" + true + end + + + def handle_playback_current_id( id ) + p "Current playback ID changed: #{id}" songpath = Gtk::TreePath.new( @status[:playlist].index id ) + @playlistView.scroll_to_cell( songpath, nil, true, 0.5, 0.5 ) @playlistView.set_cursor( songpath, nil, false ) + @server.medialib_get_info( id ).notifier do |songinfo| @currentartistLabel.text = "" @currenttitleLabel.text = "" @@ -246,7 +285,6 @@ class Grux::ClientWin < Gtk::VBox songinfo.each_key do |key| infos = String.new songinfo[key].each_pair do |src,value| - p key, value if src == :server infos.empty? || infos += "\n" infos += "#{value} (#{src})" end @@ -259,6 +297,65 @@ class Grux::ClientWin < Gtk::VBox end + def handle_playback_status( status ) + p "Current playback status changed: #{status}" + @playbackState = status + true + end + + + def handle_playback_volume_changed( *foo ) + p "Playback volume changed: #{foo}" + true + end + def handle_playlist_changed( *foo ) + p "Playlist changed: #{foo}" + true + end + + + def handle_playlist_current_pos( pos ) + p "Current pos changed: #{pos}" + #@server.playlist.entries.notifier do |playlist| + # @server.medialib_get_info( playlist[pos[:position]] ).notifier do |songinfo| + # @nextSongLbl.text = "" + # songinfo.each_pair do |key, info| + # info.each_pair do |src, value| + # @nextSongLbl.text += "[#{src}] #{key} = #{value}\n" + # end + # end + # true + # end + # true + #end + true + end + + + def handle_playlist_loaded( *foo ) + p "Playlist loaded: #{foo}" + true + end + def handle_quit( *foo ) + p "Server quit: #{foo}" + true + end + + + def xmmspls_to_lststor( songids, store ) + songids.each do |id| + current_row = store.append + @server.medialib_get_info( id ).notifier do |songinfo| + current_row[0] = id.to_s + current_row[1] = songinfo[:artist] ? songinfo[:artist].first[1] : "" + current_row[2] = songinfo[:title] ? songinfo[:title].first[1] : "" + true + end + end + store + end + + def start_playback @server.playback_start.notifier do |res| @@ -317,7 +414,7 @@ class Grux::ClientWin < Gtk::VBox @statusBar.push( @statusBar.get_context_id( "playback" ), "Paused playback" ) true end - elsif @playbackState == 0 || 2 + elsif @playbackState == ( 0 || 2 ) @server.playback_start.notifier do |res| @statusBar.push( @statusBar.get_context_id( "playback" ), "Started playback" ) true @@ -343,29 +440,6 @@ class Grux::ClientWin < Gtk::VBox end - def handle_playback_status( status ) - @playbackState = status - true - end - - - def handle_current_pos( pos ) - #@server.playlist.entries.notifier do |playlist| - # @server.medialib_get_info( playlist[pos[:position]] ).notifier do |songinfo| - # @nextSongLbl.text = "" - # songinfo.each_pair do |key, info| - # info.each_pair do |src, value| - # @nextSongLbl.text += "[#{src}] #{key} = #{value}\n" - # end - # end - # true - # end - # true - #end - true - end - - def handle_repeat_all_state( state ) @currentconfig[:"playlist.repeat_all"] = ( state ? "1" : "0" ) @rptBtn.signal_handler_block( @rptBtnClkdHndlr ) do @@ -432,12 +506,19 @@ class Grux::ClientWin < Gtk::VBox def resync_complete @server.playlist.entries.notifier do |playlist| + @status[:playlist] = playlist @playlistView.model = self.xmmspls_to_lststor( playlist, @playlistStore ) true end + @server.coll_query_ids( Xmms::Collection.universe ).notifier do |medialibids| + @medialibView.model = self.xmmspls_to_lststor( medialibids, @medialibStore ) + true + end + @server.playback_current_id.notifier do |id| - self.handle_current_id id + self.handle_playback_current_id id + true end @server.config_list_values.notifier do |res| @@ -471,16 +552,12 @@ class Grux::ClientWin < Gtk::VBox p ids.join( "', '" ) true end - true + true end end true end - @server.coll_query_ids( Xmms::Collection.universe ).notifier do |medialibids| - p medialibids.join( ", " ) - true - end true end end @@ -494,6 +571,7 @@ class Grux::MainWin < Gtk::Window @btnCont = Gtk::HBox.new @clntCont = Gtk::Notebook.new + @cnnctInput = Gtk::ComboBoxEntry.new @cnnctBtn = Gtk::Button.new "_Connect" @quitBtn = Gtk::Button.new "_Quit" @@ -503,17 +581,22 @@ class Grux::MainWin < Gtk::Window Gtk.main_quit end + @cnnctInput.append_text 'tcp://127.0.0.1:9667' + @cnnctBtnHndlr = @cnnctBtn.signal_connect :clicked do - begin - @clntCont.append_page( Grux::ClientWin.new, Gtk::Label.new( "Client" ) ) - rescue Xmms::Client::ClientError => ex - warn ex + if not @cnnctInput.active_text.empty? + server_address = @cnnctInput.active_text + else + server_address = ENV['XMMS_PATH'] end + + @clntCont.append_page( Grux::ClientWin.new( server_address ), Gtk::Label.new( server_address ) ) end @quitBtnHndlr = @quitBtn.signal_connect :clicked do Gtk.main_quit end + @btnCont.pack_start @cnnctInput @btnCont.pack_start @cnnctBtn @btnCont.pack_end @quitBtn |