[Xfce4-commits] <eatmonkey:aria2-xml-rpc> Implement a better InfoBar class

Mike Massonnet noreply at xfce.org
Sun Feb 28 16:32:02 CET 2010


Updating branch refs/heads/aria2-xml-rpc
         to 9af840799e10a5c3d437caa2ceb69b6e830b1b3c (commit)
       from 517ee4991c800b827527f0c120ef5796ae4e7c06 (commit)

commit 9af840799e10a5c3d437caa2ceb69b6e830b1b3c
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Sun Feb 28 15:37:19 2010 +0100

    Implement a better InfoBar class
    
    Update the current code that used the info bar. The class has a method
    that accepts a label for the message and the button and an optional
    callback for the button.

 src/eatmanager.rb |   69 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 52 insertions(+), 17 deletions(-)

diff --git a/src/eatmanager.rb b/src/eatmanager.rb
index 7b2139e..d9ff429 100755
--- a/src/eatmanager.rb
+++ b/src/eatmanager.rb
@@ -54,14 +54,12 @@ class Eat::Manager
 			@removed_downloads.clear
 			update_newdl_dialog
 			set_sensitive(true)
-			@infobar.hide_all
-			@infobar.set_no_show_all(true)
+			@infobar.hide
 		}
 		@aria2.signal_connect("disconnected") {
 			set_sensitive(false)
 			if !@aria2.use_local_server?
-				@infobar.set_no_show_all(false)
-				@infobar.show_all
+				@infobar.show_error("Unable to connect to aria2", "Reconnect", lambda { @aria2.connect(true) })
 			end
 		}
 		@aria2.signal_connect("download_status") { |this, gid| update_row(gid) }
@@ -81,20 +79,8 @@ class Eat::Manager
 		@window.signal_connect('delete-event') { action_quit }
 
 		# Setup info bar
-=begin
 		# ruby-gnome2-0.19.3 doesn't know about Gtk::InfoBar
-		@infobar = InfoBar.new
-=end
-		@infobar = HBox.new(false, 4)
-		@infobar.set_no_show_all(true)
-		@infobar.set_border_width(2)
-		infobutton = Button.new("Reconnect")
-		infobutton.signal_connect('clicked') { @aria2.connect(true) }
-		@infobar.pack_end(infobutton, false, false, 0)
-		infoimg = Image.new(Stock::DIALOG_ERROR, IconSize::MENU)
-		@infobar.pack_start(infoimg, false, false, 0)
-		infolabel = Label.new("Disconnected from aria2")
-		@infobar.pack_start(infolabel, false, false, 0)
+		@infobar = Eat::ManagerInfoBar.new
 		hbox = builder["hbox-info-bar"]
 		hbox.add(@infobar)
 
@@ -460,6 +446,55 @@ end
 
 
 
+class Eat::ManagerInfoBar < HBox
+
+	private
+
+	def initialize()
+		super
+		set_homogeneous(false)
+		set_spacing(4)
+		set_no_show_all(true)
+		set_border_width(2)
+
+		@callback_id = 0
+		@button = Button.new
+		@button.signal_connect_after('clicked') do
+			hide
+		end
+		pack_end(@button, false, false, 0)
+
+		img = Image.new(Stock::DIALOG_ERROR, IconSize::MENU)
+		pack_start(img, false, false, 0)
+
+		@label = Label.new
+		@label.set_use_markup(true)
+		pack_start(@label, false, false, 0)
+
+		signal_connect("hide") do
+			if @button.signal_handler_is_connected?(@callback_id)
+				@button.signal_handler_disconnect(@callback_id)
+			end
+			set_no_show_all(true)
+		end
+	end
+
+	public
+
+	def show_error(message, button_label, button_callback = nil)
+		set_no_show_all(false)
+		show_all
+
+		@label.label = message
+		@button.label = button_label
+
+		@callback_id = @button.signal_connect('clicked') { button_callback.call } if button_callback != nil
+	end
+
+end
+
+
+
 if __FILE__ == $0
 	aria2 = Eat::Aria2Listener.instance
 	aria2.connect



More information about the Xfce4-commits mailing list