diff options
author | Hendrik Jaeger <henk@frustcomp> | 2011-08-01 22:19:59 +0200 |
---|---|---|
committer | Hendrik Jaeger <henk@frustcomp> | 2011-08-01 22:19:59 +0200 |
commit | b4f04f8a091e31c7e2f28f311ce9423364c3663f (patch) | |
tree | f22fea38f62d40919aa69b4fff25b67412b08964 | |
parent | d39015899d9a692f72e13c91d87863ff17b0b1fa (diff) |
On branch master
Changes to be committed:
modified: bin/grux.rb
-rwxr-xr-x | bin/grux.rb | 194 |
1 files changed, 123 insertions, 71 deletions
diff --git a/bin/grux.rb b/bin/grux.rb index e400690..cf6c34d 100755 --- a/bin/grux.rb +++ b/bin/grux.rb @@ -14,21 +14,17 @@ class Grux::ClientWin < Gtk::VBox def initialize super - @server = Xmms::Client.new( 'Grux' ) - - @cntrlBtnBox = Gtk::HButtonBox.new - @statusLblBox = Gtk::VBox.new - @playlistViewWin = Gtk::ScrolledWindow.new - - @playlistTextRenderer = Gtk::CellRendererText.new - @playlistView = Gtk::TreeView.new - @playlistList = Gtk::ListStore.new( String, String ) - @playlistColumns = [ 'artist', 'title' ] - @playlistColumns.each_with_index do |tag, index| - @playlistView.append_column Gtk::TreeViewColumn.new( tag, @playlistTextRenderer, :text => index ) - end - @playlistViewWin << @playlistView - @statusBar = Gtk::Statusbar.new + @server = Xmms::Client.new( 'Grux' ) + + @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 + @statusBar = Gtk::Statusbar.new @cntrlbtns = [ @playBtn = Gtk::Button.new('_Play/Pause'), @@ -36,11 +32,11 @@ class Grux::ClientWin < Gtk::VBox @nextBtn = Gtk::Button.new('_Next'), @prevBtn = Gtk::Button.new('Pre_vious'), @rndmBtn = Gtk::Button.new('_Random'), - @rptBtn = Gtk::Button.new('Re_peat') + @rptBtn = Gtk::ToggleButton.new('Repeat _All', true), + @rpt1Btn = Gtk::ToggleButton.new('Repeat _One', true) ] @statusLbls = [ @stateLbl = Gtk::Label.new, - @repeatLbl = Gtk::Label.new, @playbackLbl = Gtk::Label.new, @nextSongLbl = Gtk::Label.new ] @@ -48,12 +44,27 @@ class Grux::ClientWin < Gtk::VBox @cntrlbtns.each do |button| @cntrlBtnBox.pack_start button end + @cntrlBtnBox.layout_style = Gtk::ButtonBox::START @statusLbls.each do |label| @statusLblBox.pack_start label, false end - self.pack_start @cntrlBtnBox, false - self.pack_start @statusLblBox + @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 ) + end + @playlistViewWin.add @playlistView + + self.pack_start @upperBox self.pack_start @playlistViewWin self.pack_end @statusBar, false self.show_all @@ -77,8 +88,11 @@ class Grux::ClientWin < Gtk::VBox @prevBtn.signal_connect :clicked do self.step_in_playlist -1 end - @rptBtn.signal_connect :clicked do - self.toggle_repeat + @rptBtnClkdHndlr = @rptBtn.signal_connect :clicked do + self.toggle_repeat_all + end + @rpt1BtnClkdHndlr = @rpt1Btn.signal_connect :clicked do + self.toggle_repeat_one end @playlistView.signal_connect :row_activated do |view, path, column| @@ -171,14 +185,31 @@ class Grux::ClientWin < Gtk::VBox 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| -# info.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 @@ -201,11 +232,13 @@ class Grux::ClientWin < Gtk::VBox 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[0] = songinfo[:artist] ? songinfo[:artist].first[1] : "NONE" - current_row[1] = songinfo[:title] ? songinfo[:title].first[1] : "NONE" + current_row[1] = songinfo[:artist] ? songinfo[:artist].first[1] : "NONE" + current_row[2] = songinfo[:title] ? songinfo[:title].first[1] : "NONE" true end end @@ -213,80 +246,99 @@ class Grux::ClientWin < Gtk::VBox true end - def toggle_repeat + def handle_repeat_all_state( state ) + @currentconfig[:"playlist.repeat_all"] = ( state ? "1" : "0" ) + @rptBtn.signal_handler_block( @rptBtnClkdHndlr ) do + @rptBtn.active = state + end + end + + def handle_repeat_one_state( state ) + @currentconfig[:"playlist.repeat_one"] = ( state ? "1" : "0" ) + @rpt1Btn.signal_handler_block( @rpt1BtnClkdHndlr ) do + @rpt1Btn.active = state + end + end + + def toggle_repeat_all if @currentconfig[:"playlist.repeat_all"] == "1" - if @currentconfig[:"playlist.repeat_one"] == "1" - @repeatLbl.text = "none" - @server.config_set_value( "playlist.repeat_all", "0" ).notifier do |res| - @server.config_get_value( "playlist.repeat_all" ).notifier do |value| - @currentconfig[:"playlist.repeat_all"] = value - true - end - true - end - @server.config_set_value( "playlist.repeat_one", "0" ).notifier do |res| - @server.config_get_value( "playlist.repeat_one" ).notifier do |value| - @currentconfig[:"playlist.repeat_one"] = value - true - end + @server.config_set_value( "playlist.repeat_all", "0" ).notifier do |res| + @server.config_get_value( "playlist.repeat_all" ).notifier do |value| + self.handle_repeat_all_state( value == "1" ? true : false ) true end - elsif @currentconfig[:"playlist.repeat_one"] == "0" - @repeatLbl.text = "one" - @server.config_set_value( "playlist.repeat_one", "1" ).notifier do |res| - @server.config_get_value( "playlist.repeat_one" ).notifier do |value| - @currentconfig[:"playlist.repeat_one"] = value - true - end + true + end + elsif @currentconfig[:"playlist.repeat_all"] == "0" + @server.config_set_value( "playlist.repeat_all", "1" ).notifier do |res| + @server.config_get_value( "playlist.repeat_all" ).notifier do |value| + self.handle_repeat_all_state( value == "1" ? true : false ) true end - else - warn "Unknown state" + true end - elsif @currentconfig[:"playlist.repeat_all"] == "0" - @repeatLbl.text = "all" + else + warn "Unknown state: #{@currentconfig[:"playlist.repeat_all"]}" + end + true + end + + def toggle_repeat_one + if @currentconfig[:"playlist.repeat_one"] == "1" @server.config_set_value( "playlist.repeat_one", "0" ).notifier do |res| - @server.config_get_value( "playlist.repeat_one" ).notifier do |value| - @currentconfig[:"playlist.repeat_one"] = value - true - end + @server.config_get_value( "playlist.repeat_one" ).notifier do |value| + self.handle_repeat_one_state( value == "1" ? true : false ) + true + end true end - @server.config_set_value( "playlist.repeat_all", "1" ).notifier do |res| - @server.config_get_value( "playlist.repeat_all" ).notifier do |value| - @currentconfig[:"playlist.repeat_all"] = value - true - end + elsif @currentconfig[:"playlist.repeat_one"] == "0" + @server.config_set_value( "playlist.repeat_one", "1" ).notifier do |res| + @server.config_get_value( "playlist.repeat_one" ).notifier do |value| + self.handle_repeat_one_state( value == "1" ? true : false ) + true + end true end else - warn "Unknown state" + warn "Unknown state: #{@currentconfig[:"playlist.repeat_one"]}" end true end def resync_state + @server.playlist.entries.notifier do |playlist| + self.handle_playlist playlist + true + end + + @server.playback_current_id.notifier do |id| + self.handle_current_song id + end + @server.config_list_values.notifier do |res| @currentconfig = {} res.each_pair do |key, value| @currentconfig[key] = value end - @repeatLbl.text = if( @currentconfig[:"playlist.repeat_one"] == "1" ) - "one" - elsif @currentconfig[:"playlist.repeat_all"] == "1" - "all" - else - "none" + @rpt1Btn.signal_handler_block( @rpt1BtnClkdHndlr ) do + @rpt1Btn.active = if( @currentconfig[:"playlist.repeat_one"] == "1" ) + true + else + false + end + end + @rptBtn.signal_handler_block( @rptBtnClkdHndlr ) do + @rptBtn.active = if @currentconfig[:"playlist.repeat_all"] == "1" + true + else + false + end end true end true - - @server.playlist.entries.notifier do |playlist| - self.handle_playlist playlist - true - end end end |