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 --- configure.ac | 4 +- icons/24x24/Makefile.am | 9 +++ icons/24x24/_ftp._tcp.png | Bin 0 -> 1283 bytes icons/24x24/_http._tcp.png | Bin 0 -> 1580 bytes icons/24x24/_ipp._tcp.png | Bin 0 -> 1015 bytes icons/24x24/_ssh._tcp.png | Bin 0 -> 1077 bytes icons/24x24/_workstation._tcp.png | Bin 0 -> 887 bytes icons/24x24/service-discovery-applet.png | Bin 0 -> 1615 bytes icons/48x48/Makefile.am | 8 +++ icons/48x48/_ftp._tcp.png | Bin 0 -> 3252 bytes icons/48x48/_http._tcp.png | Bin 0 -> 2647 bytes icons/48x48/_ssh._tcp.png | Bin 0 -> 2847 bytes icons/48x48/service-discovery-applet.png | Bin 0 -> 4314 bytes icons/Makefile.am | 12 +--- icons/_ftp._tcp.png | Bin 1283 -> 0 bytes icons/_http._tcp.png | Bin 1580 -> 0 bytes icons/_ipp._tcp.png | Bin 1015 -> 0 bytes icons/_ssh._tcp.png | Bin 1077 -> 0 bytes icons/_workstation._tcp.png | Bin 887 -> 0 bytes icons/service-discovery-applet-mini.png | Bin 1615 -> 0 bytes icons/service-discovery-applet.png | Bin 4314 -> 0 bytes src/service-discovery-applet.in | 92 ++++++++++++++++++++++--------- 22 files changed, 88 insertions(+), 37 deletions(-) create mode 100644 icons/24x24/Makefile.am create mode 100644 icons/24x24/_ftp._tcp.png create mode 100644 icons/24x24/_http._tcp.png create mode 100644 icons/24x24/_ipp._tcp.png create mode 100644 icons/24x24/_ssh._tcp.png create mode 100644 icons/24x24/_workstation._tcp.png create mode 100644 icons/24x24/service-discovery-applet.png create mode 100644 icons/48x48/Makefile.am create mode 100644 icons/48x48/_ftp._tcp.png create mode 100644 icons/48x48/_http._tcp.png create mode 100644 icons/48x48/_ssh._tcp.png create mode 100644 icons/48x48/service-discovery-applet.png delete mode 100644 icons/_ftp._tcp.png delete mode 100644 icons/_http._tcp.png delete mode 100644 icons/_ipp._tcp.png delete mode 100644 icons/_ssh._tcp.png delete mode 100644 icons/_workstation._tcp.png delete mode 100644 icons/service-discovery-applet-mini.png delete mode 100644 icons/service-discovery-applet.png diff --git a/configure.ac b/configure.ac index 859badc..3d9ad87 100644 --- a/configure.ac +++ b/configure.ac @@ -22,8 +22,10 @@ AC_CONFIG_FILES([ Makefile common/Makefile src/Makefile - icons/Makefile scripts/Makefile servers/Makefile + icons/Makefile + icons/24x24/Makefile + icons/48x48/Makefile ]) AC_OUTPUT diff --git a/icons/24x24/Makefile.am b/icons/24x24/Makefile.am new file mode 100644 index 0000000..ba674c8 --- /dev/null +++ b/icons/24x24/Makefile.am @@ -0,0 +1,9 @@ +iconsdir = $(ICONSDIR)/24x24 +icons_DATA = \ + _http._tcp.png \ + _ftp._tcp.png \ + _ssh._tcp.png \ + service-discovery-applet.png + + +EXTRA_DIST = $(icons_DATA) diff --git a/icons/24x24/_ftp._tcp.png b/icons/24x24/_ftp._tcp.png new file mode 100644 index 0000000..05dbdd2 Binary files /dev/null and b/icons/24x24/_ftp._tcp.png differ diff --git a/icons/24x24/_http._tcp.png b/icons/24x24/_http._tcp.png new file mode 100644 index 0000000..a16d002 Binary files /dev/null and b/icons/24x24/_http._tcp.png differ diff --git a/icons/24x24/_ipp._tcp.png b/icons/24x24/_ipp._tcp.png new file mode 100644 index 0000000..dd814d6 Binary files /dev/null and b/icons/24x24/_ipp._tcp.png differ diff --git a/icons/24x24/_ssh._tcp.png b/icons/24x24/_ssh._tcp.png new file mode 100644 index 0000000..2fe2d14 Binary files /dev/null and b/icons/24x24/_ssh._tcp.png differ diff --git a/icons/24x24/_workstation._tcp.png b/icons/24x24/_workstation._tcp.png new file mode 100644 index 0000000..da2896e Binary files /dev/null and b/icons/24x24/_workstation._tcp.png differ diff --git a/icons/24x24/service-discovery-applet.png b/icons/24x24/service-discovery-applet.png new file mode 100644 index 0000000..bbda895 Binary files /dev/null and b/icons/24x24/service-discovery-applet.png differ diff --git a/icons/48x48/Makefile.am b/icons/48x48/Makefile.am new file mode 100644 index 0000000..35a9583 --- /dev/null +++ b/icons/48x48/Makefile.am @@ -0,0 +1,8 @@ +iconsdir = $(ICONSDIR)/48x48 +icons_DATA = \ + _http._tcp.png \ + _ftp._tcp.png \ + _ssh._tcp.png \ + service-discovery-applet.png + +EXTRA_DIST = $(icons_DATA) diff --git a/icons/48x48/_ftp._tcp.png b/icons/48x48/_ftp._tcp.png new file mode 100644 index 0000000..dfce09a Binary files /dev/null and b/icons/48x48/_ftp._tcp.png differ diff --git a/icons/48x48/_http._tcp.png b/icons/48x48/_http._tcp.png new file mode 100644 index 0000000..a2e157a Binary files /dev/null and b/icons/48x48/_http._tcp.png differ diff --git a/icons/48x48/_ssh._tcp.png b/icons/48x48/_ssh._tcp.png new file mode 100644 index 0000000..e56fa2e Binary files /dev/null and b/icons/48x48/_ssh._tcp.png differ diff --git a/icons/48x48/service-discovery-applet.png b/icons/48x48/service-discovery-applet.png new file mode 100644 index 0000000..2876b96 Binary files /dev/null and b/icons/48x48/service-discovery-applet.png differ diff --git a/icons/Makefile.am b/icons/Makefile.am index 3ee98ee..17b6cb6 100644 --- a/icons/Makefile.am +++ b/icons/Makefile.am @@ -1,9 +1,3 @@ -iconsdir = $(ICONSDIR) -icons_DATA = \ - _http._tcp.png \ - _ftp._tcp.png \ - _ssh._tcp.png \ - service-discovery-applet.png \ - service-discovery-applet-mini.png - -EXTRA_DIST = $(icons_DATA) +SUBDIRS = \ + 24x24 \ + 48x48 diff --git a/icons/_ftp._tcp.png b/icons/_ftp._tcp.png deleted file mode 100644 index 05dbdd2..0000000 Binary files a/icons/_ftp._tcp.png and /dev/null differ diff --git a/icons/_http._tcp.png b/icons/_http._tcp.png deleted file mode 100644 index a16d002..0000000 Binary files a/icons/_http._tcp.png and /dev/null differ diff --git a/icons/_ipp._tcp.png b/icons/_ipp._tcp.png deleted file mode 100644 index dd814d6..0000000 Binary files a/icons/_ipp._tcp.png and /dev/null differ diff --git a/icons/_ssh._tcp.png b/icons/_ssh._tcp.png deleted file mode 100644 index 2fe2d14..0000000 Binary files a/icons/_ssh._tcp.png and /dev/null differ diff --git a/icons/_workstation._tcp.png b/icons/_workstation._tcp.png deleted file mode 100644 index da2896e..0000000 Binary files a/icons/_workstation._tcp.png and /dev/null differ diff --git a/icons/service-discovery-applet-mini.png b/icons/service-discovery-applet-mini.png deleted file mode 100644 index bbda895..0000000 Binary files a/icons/service-discovery-applet-mini.png and /dev/null differ diff --git a/icons/service-discovery-applet.png b/icons/service-discovery-applet.png deleted file mode 100644 index 2876b96..0000000 Binary files a/icons/service-discovery-applet.png and /dev/null differ 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