summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHendrik Jaeger <henk@frustcomp>2011-08-09 09:17:00 +0200
committerHendrik Jaeger <henk@frustcomp>2011-08-09 09:17:00 +0200
commit848818d0b8b0d240b9cd86d077e0f5e0ddff5797 (patch)
treea9e2f554b13f4c91d42e356f5f3fbf847cdc2439
parent0dbc5232d356dc29592eb5bbd60130d969e27190 (diff)
On branch master
Changes to be committed: modified: bin/grux.rb
-rwxr-xr-xbin/grux.rb414
1 files changed, 286 insertions, 128 deletions
diff --git a/bin/grux.rb b/bin/grux.rb
index faf07fe..3583f3d 100755
--- a/bin/grux.rb
+++ b/bin/grux.rb
@@ -11,75 +11,155 @@ class Grux
end
class Grux::ClientWin < Gtk::VBox
+ attr_reader :status
+
def initialize
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
- @infoBoxWin = Gtk::ScrolledWindow.new
- @upperBox = Gtk::HBox.new
- @leftUpperBox = Gtk::VBox.new
- @infoBox = Gtk::VBox.new
- @cntrlBtnBox = Gtk::VButtonBox.new
- @statusLblBoxWin = Gtk::ScrolledWindow.new
- @statusLblBox = Gtk::VBox.new
- @playlistViewWin = Gtk::ScrolledWindow.new
+
+ @statusBox = Gtk::HBox.new
+ @mainBox = Gtk::VPaned.new
@statusBar = Gtk::Statusbar.new
+ self.pack_start @statusBox, false
+ self.pack_start @mainBox
+ self.pack_end @statusBar, false
+
+
+ @statusWdgts = [
+ @currentartistFrame = Gtk::Frame.new( "Artist" ).add( @currentartistLabel = Gtk::Label.new ),
+ @currenttitleFrame = Gtk::Frame.new( "Title" ).add( @currenttitleLabel = Gtk::Label.new ),
+ @currentalbumFrame = Gtk::Frame.new( "Album" ).add( @currentalbumLabel = Gtk::Label.new )
+ ]
+ @statusWdgts.each { |frame| @statusBox.pack_start frame }
+
+
+ @mainWdgts = [
+ @cntrlBox = Gtk::HBox.new,
+ @medialistsWin = Gtk::Notebook.new
+ ]
+ @mainBox.pack1 @cntrlBox, true, false
+ @mainBox.pack2 @medialistsWin, true, false
+
+
+ @toolWdgts = [
+ @cntrlBtnBox = Gtk::VButtonBox.new.set_layout_style( Gtk::ButtonBox::CENTER ),
+ @toolChsr = Gtk::Notebook.new
+ ]
+ @cntrlBox.pack_start @cntrlBtnBox, false
+ @cntrlBox.pack_start @toolChsr
+
+
@cntrlbtns = [
- @playBtn = Gtk::Button.new('_Play/Pause'),
- @stopBtn = Gtk::Button.new('_Stop'),
+ @playBtn = Gtk::ToggleButton.new('_Play', true),
+ @pauseBtn = Gtk::ToggleButton.new('Pa_use', true),
+ @stopBtn = Gtk::ToggleButton.new('_Stop', true),
@nextBtn = Gtk::Button.new('_Next'),
- @prevBtn = Gtk::Button.new('Pre_vious'),
- @rndmBtn = Gtk::Button.new('_Random'),
+ @prevBtn = Gtk::Button.new('P_revious'),
+ @rndmBtn = Gtk::Button.new('Randomi_ze'),
@rptBtn = Gtk::ToggleButton.new('Repeat _All', true),
@rpt1Btn = Gtk::ToggleButton.new('Repeat _One', true)
]
- @statusLbls = [
- @stateLbl = Gtk::Label.new,
- @playbackLbl = Gtk::Label.new,
- @nextSongLbl = Gtk::Label.new
- ]
-
@cntrlbtns.each do |button|
@cntrlBtnBox.pack_start button
end
- @cntrlBtnBox.layout_style = Gtk::ButtonBox::START
- @statusLbls.each do |label|
- @statusLblBox.pack_start label, false
+
+
+ @toolTabs = [
+ [ @extinfoTab = Gtk::VBox.new,
+ @extinfoTabLbl = Gtk::Label.new( "Status" ) ],
+ [ @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 )
end
- @infoBoxWin.add_with_viewport @infoBox
- @statusLblBoxWin.add_with_viewport @statusLblBox
- @upperBox.pack_start @cntrlBtnBox, false
- @upperBox.pack_start @infoBoxWin
- @upperBox.pack_start @statusLblBoxWin
- @playlistTextRenderer = Gtk::CellRendererText.new
- @playlistView = Gtk::TreeView.new
- @playlistList = Gtk::ListStore.new( String, String, String )
- @playlistColumns = [ 'id', 'artist', 'title' ]
- @playlistColumns.each_with_index do |tag, index|
- @playlistView.append_column Gtk::TreeViewColumn.new( tag, @playlistTextRenderer, :text => index )
+ @medialistTextRenderer = Gtk::CellRendererText.new
+ @medialistColumns = [ 'id', 'artist', 'title' ]
+
+ @medialists = [
+ [ @plalistViewLbl = Gtk::Label.new( "Current Playlist" ),
+ @playlistViewWin = Gtk::ScrolledWindow.new,
+ @playlistView = Gtk::TreeView.new,
+ @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 )
+ ]
+ ]
+
+ @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
+ @medialistsWin.append_page( window.add( view ), label )
end
- @playlistViewWin.add @playlistView
- self.pack_start @upperBox
- self.pack_start @playlistViewWin
- self.pack_end @statusBar, false
+
self.show_all
- begin
- @server.connect( ENV['XMMS_PATH'] )
- @server.add_to_glib_mainloop
- rescue
- @statusBar.push( @statusBar.get_context_id( "connection" ), "Failed to connect to #{ENV['XMMS_PATH']}" )
+
+ @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
+
- @playBtn.signal_connect :clicked do
- self.toggle_playback
+ @playBtnClkdHndlr = @playBtn.signal_connect :clicked do
+ self.start_playback
end
- @stopBtn.signal_connect :clicked do
+ @pauseBtnClkdHndlr = @pauseBtn.signal_connect :clicked do
+ self.pause_playback
+ end
+ @stopBtnClkdHndlr = @stopBtn.signal_connect :clicked do
self.stop_playback
end
@nextBtn.signal_connect :clicked do
@@ -88,6 +168,9 @@ class Grux::ClientWin < Gtk::VBox
@prevBtn.signal_connect :clicked do
self.step_in_playlist -1
end
+ @rndmBtn.signal_connect :clicked do
+ self.randomize_playlist
+ end
@rptBtnClkdHndlr = @rptBtn.signal_connect :clicked do
self.toggle_repeat_all
end
@@ -95,47 +178,139 @@ class Grux::ClientWin < Gtk::VBox
self.toggle_repeat_one
end
+
@playlistView.signal_connect :row_activated do |view, path, column|
@server.playlist_set_next( path.to_str.to_i ).notifier do
@server.playback_tickle.notifier do
+ self.start_playback
true
end
true
end
end
- @server.broadcast_coll_changed do
- end
- @server.broadcast_config_value_changed do |*foo|
- p foo
- end
- @server.broadcast_mediainfo_reader_status do
- end
- @server.broadcast_medialib_entry_added do
- end
- @server.broadcast_medialib_entry_changed do
- end
- @server.broadcast_playback_current_id.notifier do |id|
- self.handle_current_song id
- end
- @server.broadcast_playback_status.notifier do |playing|
- self.handle_playback_status playing
- end
- @server.broadcast_playback_volume_changed do
+
+ @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
+ @server.playback_tickle.notifier do
+ self.start_playback
+ true
+ end
+ true
+ end
+ end
end
- @server.broadcast_playlist_changed do
+
+
+ self.resync_complete
+
+ 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
end
- @server.broadcast_playlist_current_pos.notifier do |pos|
- self.handle_current_pos pos
+ store
+ end
+
+
+ def handle_current_id( 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 = ""
+ @currentalbumLabel.text = ""
+
+ @extinfoTab.each do |child| @extinfoTab.remove child end
+
+ songinfo[:artist] && songinfo[:artist].each_pair do |src, value|
+ @currentartistLabel.text += @currentartistLabel.text.empty? ? value : "\n#{value}"
+ end
+ songinfo[:title] && songinfo[:title].each_pair do |src, value|
+ @currenttitleLabel.text += @currenttitleLabel.text.empty? ? value : "\n#{value}"
+ end
+ songinfo[:album] && songinfo[:album].each_pair do |src, value|
+ @currentalbumLabel.text += @currentalbumLabel.text.empty? ? value : "\n#{value}"
+ end
+ 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
+ @extinfoTab.pack_end( Gtk::Frame.new( key.to_s ).add( Gtk::Label.new( infos ) ) )
+ end
+ @extinfoTab.show_all
+ true
end
- @server.broadcast_playlist_loaded do
+ true
+ end
+
+
+
+ def start_playback
+ @server.playback_start.notifier do |res|
+ @playBtn.signal_handler_block( @playBtnClkdHndlr ) do
+ @playBtn.active = true
+ end
+ @pauseBtn.signal_handler_block( @pauseBtnClkdHndlr ) do
+ @pauseBtn.active = false
+ end
+ @stopBtn.signal_handler_block( @stopBtnClkdHndlr ) do
+ @stopBtn.active = false
+ end
+ @statusBar.push( @statusBar.get_context_id( "playback" ), "Started playback" )
+ true
end
- @server.broadcast_quit do
+ end
+
+
+ def pause_playback
+ @server.playback_pause.notifier do |res|
+ @playBtn.signal_handler_block( @playBtnClkdHndlr ) do
+ @playBtn.active = false
+ end
+ @pauseBtn.signal_handler_block( @pauseBtnClkdHndlr ) do
+ @pauseBtn.active = true
+ end
+ @stopBtn.signal_handler_block( @stopBtnClkdHndlr ) do
+ @stopBtn.active = false
+ end
+ @statusBar.push( @statusBar.get_context_id( "playback" ), "Paused playback" )
+ true
end
+ end
- self.resync_state
+
+ def stop_playback
+ @server.playback_stop.notifier do |res|
+ @playBtn.signal_handler_block( @playBtnClkdHndlr ) do
+ @playBtn.active = false
+ end
+ @pauseBtn.signal_handler_block( @pauseBtnClkdHndlr ) do
+ @pauseBtn.active = false
+ end
+ @stopBtn.signal_handler_block( @stopBtnClkdHndlr ) do
+ @stopBtn.active = true
+ end
+ @statusBar.push( @statusBar.get_context_id( "playback" ), "Stopped playback" )
+ true
+ end
end
+
def toggle_playback
if @playbackState == 1
@server.playback_pause.notifier do |res|
@@ -156,12 +331,6 @@ class Grux::ClientWin < Gtk::VBox
end
end
- def stop_playback
- @server.playback_stop.notifier do |res|
- @statusBar.push( @statusBar.get_context_id( "playback" ), "Stopped playback" )
- true
- end
- end
def step_in_playlist( offset = 1 )
@server.playlist_set_next_rel( offset ).notifier do
@@ -173,47 +342,12 @@ class Grux::ClientWin < Gtk::VBox
end
end
+
def handle_playback_status( status )
@playbackState = status
- @stateLbl.text = case status
- when 0 then "stopped"
- when 1 then "playing"
- when 2 then "paused"
- else "unknown"
- end
true
end
- def handle_current_song( id )
- songpath = Gtk::TreePath.new( @currentPlaylist.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|
- infos = {}
- @playbackLbl.text = ""
- @infoBox.each { |child| @infoBox.remove child }
- self.show_all
- songinfo.each_key do |key|
- songinfo[key].each_pair do |src,value|
- @playbackLbl.text += "[#{src}] #{key} = #{value}\n"
- infos[key] = ( ( infos[key] ? infos[key] + "\n" : "" ) + "#{value} (#{src})" )
- end
- end
- [ :artist, :title, :album ].each do |key|
- @infoBox.pack_start( Gtk::Frame.new( key.to_s ).add( Gtk::Label.new( infos.delete( key ) ) ) )
- end
- infos.each_pair do |key, value|
- if key == :artist
- @infoBox.pack_start( Gtk::Frame.new( key.to_s ).add( Gtk::Label.new( value ) ) )
- next
- end
- @infoBox.pack_end( Gtk::Frame.new( key.to_s ).add( Gtk::Label.new( value ) ) )
- end
- @infoBox.show_all
- true
- end
- true
- end
def handle_current_pos( pos )
#@server.playlist.entries.notifier do |playlist|
@@ -231,20 +365,6 @@ class Grux::ClientWin < Gtk::VBox
true
end
- def handle_playlist( playlist )
- @currentPlaylist = playlist
- playlist.each_with_index do |id, index|
- current_row = @playlistList.append
- current_row[0] = index.to_s
- @server.medialib_get_info( id ).notifier do |songinfo|
- current_row[1] = songinfo[:artist] ? songinfo[:artist].first[1] : "NONE"
- current_row[2] = songinfo[:title] ? songinfo[:title].first[1] : "NONE"
- true
- end
- end
- @playlistView.model = @playlistList
- true
- end
def handle_repeat_all_state( state )
@currentconfig[:"playlist.repeat_all"] = ( state ? "1" : "0" )
@@ -253,6 +373,7 @@ class Grux::ClientWin < Gtk::VBox
end
end
+
def handle_repeat_one_state( state )
@currentconfig[:"playlist.repeat_one"] = ( state ? "1" : "0" )
@rpt1Btn.signal_handler_block( @rpt1BtnClkdHndlr ) do
@@ -260,6 +381,7 @@ class Grux::ClientWin < Gtk::VBox
end
end
+
def toggle_repeat_all
if @currentconfig[:"playlist.repeat_all"] == "1"
@server.config_set_value( "playlist.repeat_all", "0" ).notifier do |res|
@@ -283,6 +405,7 @@ class Grux::ClientWin < Gtk::VBox
true
end
+
def toggle_repeat_one
if @currentconfig[:"playlist.repeat_one"] == "1"
@server.config_set_value( "playlist.repeat_one", "0" ).notifier do |res|
@@ -306,14 +429,15 @@ class Grux::ClientWin < Gtk::VBox
true
end
- def resync_state
+
+ def resync_complete
@server.playlist.entries.notifier do |playlist|
- self.handle_playlist playlist
+ @playlistView.model = self.xmmspls_to_lststor( playlist, @playlistStore )
true
end
@server.playback_current_id.notifier do |id|
- self.handle_current_song id
+ self.handle_current_id id
end
@server.config_list_values.notifier do |res|
@@ -338,10 +462,30 @@ class Grux::ClientWin < Gtk::VBox
end
true
end
+
+ @server.coll_list.notifier do |colls|
+ colls.each do |collname|
+ @server.coll_get( collname ).notifier do |coll|
+ @server.coll_query_ids( coll ).notifier do |ids|
+ p collname
+ p ids.join( "', '" )
+ true
+ end
+ true
+ end
+ end
+ true
+ end
+
+ @server.coll_query_ids( Xmms::Collection.universe ).notifier do |medialibids|
+ p medialibids.join( ", " )
+ true
+ end
true
end
end
+
class Grux::MainWin < Gtk::Window
def initialize
super
@@ -360,7 +504,11 @@ class Grux::MainWin < Gtk::Window
end
@cnnctBtnHndlr = @cnnctBtn.signal_connect :clicked do
- @clntCont.append_page( Grux::ClientWin.new, Gtk::Label.new( "Client" ) )
+ begin
+ @clntCont.append_page( Grux::ClientWin.new, Gtk::Label.new( "Client" ) )
+ rescue Xmms::Client::ClientError => ex
+ warn ex
+ end
end
@quitBtnHndlr = @quitBtn.signal_connect :clicked do
Gtk.main_quit
@@ -377,6 +525,16 @@ class Grux::MainWin < Gtk::Window
end
end
+
gruxWin = Grux::MainWin.new
Gtk.main
+
+#:added
+#:chain
+#:id
+#:laststarted
+#:status
+#:timesplayed
+#:url
+