From 06e3c9cd349fbeb0ab9be97146bd8498feacdc26 Mon Sep 17 00:00:00 2001 From: Sebastien Estienne Date: Tue, 30 Aug 2005 22:55:02 +0000 Subject: * added support for libnotify * add 24x24 and 48x48 icons git-svn-id: file:///home/lennart/svn/public/service-discovery-applet/trunk@6 3be567f1-68ff-0310-b24a-ad7cc433fd2f --- src/service-discovery-applet.in | 92 +++++++++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/service-discovery-applet.in b/src/service-discovery-applet.in index 8270c08..bb71b9d 100755 --- a/src/service-discovery-applet.in +++ b/src/service-discovery-applet.in @@ -87,16 +87,16 @@ def menuitem_response(widget, interface, protocol, name, type, domain): server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC, reply_handler=service_resolved, error_handler=print_error) def new_service(interface, protocol, name, type, domain): - global server, service_menu, zc_types, zc_pretty_name, zc_services + global server, service_menu, zc_types, zc_pretty_name, zc_services, notif print "Found service '%s' of type '%s' in domain '%s' on %s.%i." % (name, type, domain, siocgifname(interface), protocol) - + if zc_types.has_key(type) == False: menuitem = gtk.ImageMenuItem() if zc_pretty_name.has_key(type): menuitem.add(gtk.Label(zc_pretty_name[type])) img = gtk.Image() - iconfile = "@iconsdir@/%s.png" % (type) + iconfile = "@iconsdir@/24x24/%s.png" % (type) img.set_from_file(iconfile) menuitem.set_image(img) else: @@ -113,11 +113,20 @@ def new_service(interface, protocol, name, type, domain): menuitem.connect("activate", menuitem_response,interface, protocol, name, type, domain) menuitem.show_all() - # Asynchronous resolving - #server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC, reply_handler=service_resolved, error_handler=print_error) + iconfile = "@iconsdir@/48x48/%s.png" % (type) + message = "Name : %s\nType : %s (%s)" % (name,zc_pretty_name[type], type) + try: + notif.Notify("Service Discovery Applet", + iconfile, dbus.UInt32(0),"",dbus.Byte(0), + "New Service found",message, + [iconfile],[""],[""],True,dbus.UInt32(3)) + except: + print "can't use notification daemon" + pass + def remove_service(interface, protocol, name, type, domain): - global zc_services + global zc_services,notif print "Service '%s' of type '%s' in domain '%s' on %s.%i disappeared." % (name, type, domain, siocgifname(interface), protocol) @@ -126,9 +135,20 @@ def remove_service(interface, protocol, name, type, domain): if zc_types[type].get_children() == []: service_menu.remove(zc_types[type].get_attach_widget()) del zc_types[type] + + iconfile = "@iconsdir@/48x48/%s.png" % (type) + message = "Name : %s\nType : %s (%s)" % (name,zc_pretty_name[type], type) + try: + notif.Notify("Service Discovery Applet", + iconfile, dbus.UInt32(0),"",dbus.Byte(0), + "Service disappeared",message, + [iconfile],[""],[""],True,dbus.UInt32(3)) + except: + print "can't use notification daemon" + pass def new_service_type(interface, protocol, type, domain): - global server, service_browsers + global server, service_browsers, system_bus # Are we already browsing this domain for this type? if service_browsers.has_key((interface, protocol, type, domain)): @@ -136,7 +156,7 @@ def new_service_type(interface, protocol, type, domain): print "Browsing for services of type '%s' in domain '%s' on %s.%i ..." % (type, domain, siocgifname(interface), protocol) - b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceBrowserNew(interface, protocol, type, domain)), avahi.DBUS_INTERFACE_SERVICE_BROWSER) + b = dbus.Interface(system_bus.get_object(avahi.DBUS_NAME, server.ServiceBrowserNew(interface, protocol, type, domain)), avahi.DBUS_INTERFACE_SERVICE_BROWSER) b.connect_to_signal('ItemNew', new_service) b.connect_to_signal('ItemRemove', remove_service) @@ -155,21 +175,6 @@ def new_domain(interface, protocol, domain): browse_domain(interface, protocol, domain) -bus = dbus.SystemBus() -server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER) - -if domain is None: - # Explicitly browse .local - browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "local") - - # Browse for other browsable domains - db = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE)), avahi.DBUS_INTERFACE_DOMAIN_BROWSER) - db.connect_to_signal('ItemNew', new_domain) - -else: - # Just browse the domain the user wants us to browse - browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, domain) - def on_menubar_click(widget, event): # allow Middle- and Right-Mouse-Button to go through to the applet window if event.button != 1: @@ -179,7 +184,8 @@ def on_menubar_click(widget, event): def ServiceDiscoveryApplet_factory(applet, iid): - global menuZC + global menuZC, system_bus, server, session_bus, domain, notif + print "Creating new applet instance" menubar = gtk.MenuBar() menubar.connect("button-press-event", on_menubar_click) @@ -187,7 +193,7 @@ def ServiceDiscoveryApplet_factory(applet, iid): menuZC = gtk.ImageMenuItem() menuZC.add(gtk.Label('ZeroConf')) img = gtk.Image() - img.set_from_file("@iconsdir@/service-discovery-applet-mini.png") + img.set_from_file("@iconsdir@/24x24/service-discovery-applet.png") menuZC.set_image(img) menuZC.set_right_justified(True) menubar.add(menuZC) @@ -197,11 +203,43 @@ def ServiceDiscoveryApplet_factory(applet, iid): applet.add(menubar) applet.show_all() + + + system_bus = dbus.SystemBus() + server = dbus.Interface(system_bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), + avahi.DBUS_INTERFACE_SERVER) + + if domain is None: + # Explicitly browse .local + try: + browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "local") + except: + print "Can't connect to Avahi." + sys.exit(0) + + # Browse for other browsable domains + sdb = server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE) + obj = system_bus.get_object(avahi.DBUS_NAME, sdb) + db = dbus.Interface(obj, avahi.DBUS_INTERFACE_DOMAIN_BROWSER) + db.connect_to_signal('ItemNew', new_domain) + + else: + # Just browse the domain the user wants us to browse + try: + browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, domain) + except: + print "Can't connect to Avahi." + sys.exit(0) + + session_bus = dbus.SessionBus() + obj = session_bus.get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications") + notif = dbus.Interface(obj, "org.freedesktop.Notifications") return True -print "Starting factory" +print "Starting Service Discovery Applet" + if __name__ == '__main__': if len(sys.argv) == 2 and sys.argv[1] == "-window": main_window = gtk.Window(gtk.WINDOW_TOPLEVEL) @@ -218,4 +256,4 @@ if __name__ == '__main__': gnomeapplet.Applet.__gtype__, "Service discovery applet", "0", ServiceDiscoveryApplet_factory) -print "Factory ended" +print "Service Discovery Applet ended" -- cgit