summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorHendrik Jaeger <henk@frustcomp>2012-01-04 23:30:52 +0100
committerHendrik Jaeger <henk@frustcomp>2012-01-04 23:30:52 +0100
commit8f35b373ae5d8c47322568affffc38c4b319bb64 (patch)
tree68e673e17cb8845cdcf44b5e4fb79a37cce28a16 /bin
parent4906a782ab9ca2246fe46263e8c1c2b2d06b6218 (diff)
On branch masterHEADmaster
Changes to be committed: modified: bin/grux.rb * CHANGED: interpreter is now /usr/bin/ruby because of the -w argument * ADDED: debug output function * ADDED: debug output in several places * CHANGED: server_address is now an instance variable * CHANGED: searching now switches to the results * ADDED: proper handler for playback state changes * ADDED: proper handler for playlist changes * ADDED: check if songinfo is set before using it * CHANGED: resync_complete is now resync_completely and has been split * up in several more specific functions
Diffstat (limited to 'bin')
-rwxr-xr-xbin/grux.rb174
1 files changed, 134 insertions, 40 deletions
diff --git a/bin/grux.rb b/bin/grux.rb
index 954ea5f..308a645 100755
--- a/bin/grux.rb
+++ b/bin/grux.rb
@@ -1,8 +1,5 @@
-#!/usr/bin/env ruby -w
+#!/usr/bin/ruby -w
-#$: << File.expand_path(File.dirname(FILE) + “/../lib”))
-
-#require 'libgruxclient'
require 'gtk2'
require 'xmmsclient'
require 'xmmsclient_glib'
@@ -13,15 +10,22 @@ end
class Grux::ClientWin < Gtk::VBox
attr_reader :status
- def initialize( server_address )
+ def initialize( address )
+ @server_address = address
+ grux_debug "Initializing window..."
super()
+ grux_debug "Done"
-
+ grux_debug "Creating connection handle..."
@server = Xmms::Client.new( 'Grux' )
+ grux_debug "Done"
+ grux_debug "Connecting to server..."
@status = Hash.new
- @status[:connected] = self.connect( server_address )
+ @status[:connected] = self.connect( @server_address )
+ grux_debug "Done"
+ grux_debug "Creating and placing child widgets..."
@statusBox = Gtk::HBox.new
@mainBox = Gtk::VPaned.new
@statusBar = Gtk::Statusbar.new
@@ -122,6 +126,7 @@ class Grux::ClientWin < Gtk::VBox
self.show_all
+ grux_debug "Done"
@playBtnClkdHndlr = @playBtn.signal_connect :clicked do
@@ -164,6 +169,7 @@ class Grux::ClientWin < Gtk::VBox
end
searchResultIds, searchResult = self.xmmspls_to_lststor( results.uniq!, @searchResultStore )
@searchResultView.model = searchResult
+ @medialistsWin.page = 2
end
@@ -200,19 +206,24 @@ class Grux::ClientWin < Gtk::VBox
if @status[:connected]
- p "connected"
- self.resync_complete
+ grux_debug "Connected to server."
+ self.resync_completely
end
end
+ def grux_debug( message )
+ exit 1 unless @server_address
+ STDERR.puts "#{@server_address}: #{message}"
+ 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
+ grux_debug "Connection failed. Error Code:"
+ grux_debug ex
return false
end
@@ -270,29 +281,29 @@ class Grux::ClientWin < Gtk::VBox
def handle_coll_changed( *foo )
- p "Collection changed: #{foo}"
+ grux_debug "Collection changed: #{foo}"
true
end
def handle_config_value_changed( *foo )
- p "Config changed: #{foo}"
+ grux_debug "Config changed: #{foo}"
true
end
def handle_mediainfo_reader_status( *foo )
- p "Mediainfo reader status changed: #{foo}"
+ grux_debug "Mediainfo reader status changed: #{foo}"
true
end
def handle_medialib_entry_added( *foo )
- p "Medialib entry added: #{foo}"
+ grux_debug "Medialib entry added: #{foo}"
true
end
def handle_medialib_entry_changed( *foo )
- p "Medialib entry changed: #{foo}"
+ grux_debug "Medialib entry changed: #{foo}"
true
end
def handle_playback_current_id( id )
- p "Current playback ID changed: #{id}"
+ grux_debug "Current playback ID changed: #{id}"
songpath = Gtk::TreePath.new( @status[:playlistids].index id )
@playlistView.scroll_to_cell( songpath, nil, true, 0.5, 0.5 )
@@ -330,24 +341,61 @@ class Grux::ClientWin < Gtk::VBox
def handle_playback_status( status )
- p "Current playback status changed: #{status}"
+ grux_debug "Current playback status changed: #{status}"
@playbackState = status
+ if status == 2
+ @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" ), "Playback paused" )
+ elsif status == 1
+ @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" ), "Playback started" )
+ elsif status == 0
+ @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" ), "Playback stopped" )
+ else
+ grux_debug "Unknown status #{status}"
+ end
true
end
def handle_playback_volume_changed( *foo )
- p "Playback volume changed: #{foo}"
+ grux_debug "Playback volume changed: #{foo}"
true
end
def handle_playlist_changed( *foo )
- p "Playlist changed: #{foo}"
+ grux_debug "Playlist changed: #{foo}"
+ self.get_playlist
true
end
def handle_playlist_current_pos( pos )
- p "Current pos changed: #{pos}"
+ grux_debug "Current pos changed: #{pos}"
#@server.playlist.entries.notifier do |playlist|
# @server.medialib_get_info( playlist[pos[:position]] ).notifier do |songinfo|
# @nextSongLbl.text = ""
@@ -365,25 +413,28 @@ class Grux::ClientWin < Gtk::VBox
def handle_playlist_loaded( *foo )
- p "Playlist loaded: #{foo}"
+ grux_debug "Playlist loaded: #{foo}"
true
end
def handle_quit( *foo )
- p "Server quit: #{foo}"
+ grux_debug "Server quit: #{foo}"
true
end
def xmmspls_to_lststor( songids, store )
+ grux_debug "Processing songids: #{songids.join(' ')}."
songinfos = []
store.clear
songids.each do |id|
current_row = store.append
@server.medialib_get_info( id ).notifier do |songinfo|
- songinfos[id] = 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] : ""
+ if songinfo
+ songinfos[id] = songinfo
+ current_row[1] = songinfo[:artist] ? songinfo[:artist].first[1] : ""
+ current_row[2] = songinfo[:title] ? songinfo[:title].first[1] : ""
+ end
true
end
end
@@ -391,7 +442,6 @@ class Grux::ClientWin < Gtk::VBox
end
-
def start_playback
@server.playback_start.notifier do |res|
@playBtn.signal_handler_block( @playBtnClkdHndlr ) do
@@ -455,7 +505,7 @@ class Grux::ClientWin < Gtk::VBox
true
end
else
- warn "Playbackstate unknown"
+ grux_debug "Playbackstate unknown"
@server.playback_start.notifier do |res|
@statusBar.push( @statusBar.get_context_id( "playback" ), "Started playback" )
true
@@ -509,7 +559,7 @@ class Grux::ClientWin < Gtk::VBox
true
end
else
- warn "Unknown state: #{@currentconfig[:"playlist.repeat_all"]}"
+ grux_debug "Unknown state: #{@currentconfig[:"playlist.repeat_all"]}"
end
true
end
@@ -533,30 +583,49 @@ class Grux::ClientWin < Gtk::VBox
true
end
else
- warn "Unknown state: #{@currentconfig[:"playlist.repeat_one"]}"
+ grux_debug "Unknown state: #{@currentconfig[:"playlist.repeat_one"]}"
end
true
end
- def resync_complete
+ def get_playlist
+ grux_debug "Retrieving playlist..."
@server.playlist.entries.notifier do |playlistids|
+ grux_debug "Playlist-IDs: #{playlistids.join(' ')}"
@status[:playlistids] = playlistids
@status[:playlist], @playlistView.model = self.xmmspls_to_lststor( playlistids, @playlistStore )
true
end
+ grux_debug "Done"
+ end
+ def get_medialib
+ grux_debug "Retrieving medialib..."
@server.coll_query_ids( Xmms::Collection.universe ).notifier do |medialibids|
+ grux_debug "Medialib-IDs: #{medialibids.join(' ')}"
@status[:medialibids] = medialibids
@status[:medialib], @medialibView.model = self.xmmspls_to_lststor( medialibids, @medialibStore )
true
end
+ grux_debug "Done"
+ end
+ def get_current_song
+ grux_debug "Retrieving currently playing song..."
@server.playback_current_id.notifier do |id|
- self.handle_playback_current_id id
+ if id == 0
+ grux_debug "XXX-UNCLEAR: Songid is 0, playlist may be empty?"
+ else
+ self.handle_playback_current_id id
+ end
true
end
+ grux_debug "Done"
+ end
+ def get_config
+ grux_debug "Retrieving configuration..."
@server.config_list_values.notifier do |res|
@currentconfig = {}
res.each_pair do |key, value|
@@ -579,13 +648,17 @@ class Grux::ClientWin < Gtk::VBox
end
true
end
+ grux_debug "Done"
+ end
+ def get_collections
+ grux_debug "Retrieving collections..."
@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( "', '" )
+ grux_debug collname
+ grux_debug ids.join(' ')
true
end
true
@@ -593,16 +666,28 @@ class Grux::ClientWin < Gtk::VBox
end
true
end
+ grux_debug "Done"
+ end
- true
+ def resync_completely
+ grux_debug "Doing a complete resync:"
+ self.get_playlist
+ self.get_medialib
+ self.get_current_song
+ self.get_config
+ self.get_collections
+ grux_debug "Complete resync done."
end
end
class Grux::MainWin < Gtk::Window
def initialize
+ STDERR.puts "Main: Initializing window..."
super
+ STDERR.puts "Main: Done"
+ STDERR.puts "Main: Populating window..."
@mainCont = Gtk::VBox.new
@btnCont = Gtk::HBox.new
@clntCont = Gtk::Notebook.new
@@ -612,26 +697,32 @@ class Grux::MainWin < Gtk::Window
@quitBtn = Gtk::Button.new "_Quit"
self.title = "Grux"
+ STDERR.puts "Main: Done"
- @winDstryHndlr = self.signal_connect :destroy do
- Gtk.main_quit
- end
-
+ STDERR.puts "Main: XXX-FEATURE: load (and save) previously used entries for: "
+ STDERR.puts "Main: Populating server list..."
@cnnctInput.append_text 'tcp://127.0.0.1:9667'
+ STDERR.puts "Main: Done"
+ STDERR.puts "Main: Trying to connect..."
@cnnctBtnHndlr = @cnnctBtn.signal_connect :clicked do
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
+ STDERR.puts "Main: Done"
+
+ @winDstryHndlr = self.signal_connect :destroy do
+ Gtk.main_quit
+ end
@quitBtnHndlr = @quitBtn.signal_connect :clicked do
Gtk.main_quit
end
+ STDERR.puts "Main: Packing and showing window content..."
@btnCont.pack_start @cnnctInput
@btnCont.pack_start @cnnctBtn
@btnCont.pack_end @quitBtn
@@ -641,11 +732,14 @@ class Grux::MainWin < Gtk::Window
self.add @mainCont
self.show_all
+ STDERR.puts "Main: Done"
end
end
+STDERR.puts "Creating main client window:"
gruxWin = Grux::MainWin.new
+STDERR.puts "Starting GTK main loop."
Gtk.main