From 46a1f18d6dc85add11abd9d5b65213e7ec02efaf Mon Sep 17 00:00:00 2001 From: Sebastien Estienne Date: Tue, 4 Oct 2005 00:18:44 +0000 Subject: * add support for avahi.ServiceTypeDatabase * allow to browse or not for local service git-svn-id: file:///home/lennart/svn/public/service-discovery-applet/trunk@31 3be567f1-68ff-0310-b24a-ad7cc433fd2f --- src/service-discovery-applet.in | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/service-discovery-applet.in b/src/service-discovery-applet.in index 69cf1c1..5feaa2b 100755 --- a/src/service-discovery-applet.in +++ b/src/service-discovery-applet.in @@ -40,6 +40,7 @@ try: import gnomeapplet import gnome.ui import gconf + import avahi.ServiceTypeDatabase except ImportError, e: error_msg("A python module is missing.\n%s" % (e)) sys.exit() @@ -49,9 +50,6 @@ try: except ImportError, e: pass - - - #from gettext import gettext as _ class ServiceDiscoveryApplet(gnomeapplet.Applet): @@ -63,12 +61,7 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): self.service_menu = gtk.Menu() self.zc_types = {} self.zc_services = {} - self.zc_pretty_name = {'_ssh._tcp' : 'SSH Servers', - '_http._tcp' : 'Web Servers', - '_ftp._tcp' : 'Ftp Servers', - '_workstation._tcp': 'Workstations' - } - + self.zc_pretty_name = avahi.ServiceTypeDatabase.ServiceTypeDatabase() # Gconf Paths self.gc_options = "/apps/service-discovery-applet/options" @@ -80,7 +73,7 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): self.gc_client.add_dir (self.gc_options, gconf.CLIENT_PRELOAD_NONE) self.show_local_services = self.gc_client.get_bool ("%s/%s" % (self.gc_options,"show_local_services")) - self.show_notifications = False + self.gc_client.add_dir (self.gc_services, gconf.CLIENT_PRELOAD_NONE) self.gc_client.notify_add (self.gc_services, self.gc_services_cb) @@ -135,7 +128,7 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): self.applet.show_all() - gobject.timeout_add(1000, self.start_notifying_cb) + def start_notifying_cb(self): print "start notifying" @@ -174,7 +167,11 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): def new_service(self, interface, protocol, name, type, domain): print "Found service '%s' of type '%s' in domain '%s' on %s.%i." % (name, type, domain, self.siocgifname(interface), protocol) - if self.zc_types.has_key(type) == False: + if self.show_local_services == False: + if self.server.IsServiceLocal( interface, protocol, name, type, domain) == True: + return + + if self.zc_types.has_key(type) == False: menuitem = gtk.ImageMenuItem() if self.zc_pretty_name.has_key(type): pretty_name = self.zc_pretty_name[type] @@ -222,7 +219,11 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): def remove_service(self, interface, protocol, name, type, domain): print "Service '%s' of type '%s' in domain '%s' on %s.%i disappeared." % (name, type, domain, self.siocgifname(interface), protocol) - self.zc_types[type].remove(self.zc_services[(interface, protocol, name, type, domain)]) + if self.zc_services.has_key((interface, protocol, name, type, domain)): + self.zc_types[type].remove(self.zc_services[(interface, protocol, name, type, domain)]) +# else: +# # if the key wasn't present it certainly means the service is local and we disable browsing localy +# return if self.zc_types[type].get_children() == []: self.service_menu.remove(self.zc_types[type].get_attach_widget()) @@ -333,7 +334,8 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): #FIXME replace with gconf key def start_service_discovery(self, component, verb, applet): if len(self.domain) != 0: - return + print "domain not null %s" % (self.domain) + return try: self.domain = self.server.GetDomainName() @@ -349,6 +351,9 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): if self.gc_client.get_bool(gc_entry.key) == True: service_type = os.path.basename(gc_entry.key) self.add_service_type(self.interface, self.protocol, service_type, self.domain) + # Wait one second before displaying notifications + self.show_notifications = False + gobject.timeout_add(1000, self.start_notifying_cb) def stop_service_discovery(self, component, verb, applet): if len(self.domain) == 0: @@ -356,7 +361,7 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): for service in self.service_browsers.copy(): self.del_service_type(service[0],service[1],service[2],service[3]) - domain = "" + self.domain = "" # Callback called when a service is added/removed/enabled/disabled in gconf def gc_services_cb (self, client, cnxn_id, gc_entry, data): @@ -377,6 +382,11 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): self.show_notifications = client.get_bool(gc_entry.key) if key == "show_local_services": self.show_local_services = client.get_bool(gc_entry.key) + status = self.domain + self.stop_service_discovery(None,None,None) + # only start if it was running before + if len(status) != 0: + self.start_service_discovery(None,None,None) def applet_factory(applet, iid): #service-discovery-applet = -- cgit