summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/service-discovery-applet.in71
1 files changed, 36 insertions, 35 deletions
diff --git a/src/service-discovery-applet.in b/src/service-discovery-applet.in
index 5feaa2b..088d14b 100755
--- a/src/service-discovery-applet.in
+++ b/src/service-discovery-applet.in
@@ -73,8 +73,8 @@ 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 = self.gc_client.get_bool ("%s/%s" % (self.gc_options,"show_notifications"))
+
self.gc_client.add_dir (self.gc_services, gconf.CLIENT_PRELOAD_NONE)
self.gc_client.notify_add (self.gc_services, self.gc_services_cb)
self.gc_client.notify_add (self.gc_options, self.gc_options_cb)
@@ -120,16 +120,14 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet):
self.server = dbus.Interface(self.system_bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER),
avahi.DBUS_INTERFACE_SERVER)
- self.start_service_discovery(None, None, None)
-
self.session_bus = dbus.SessionBus()
obj = self.session_bus.get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
self.notif = dbus.Interface(obj, "org.freedesktop.Notifications")
+ self.start_service_discovery(None, None, None)
+
self.applet.show_all()
-
-
def start_notifying_cb(self):
print "start notifying"
self.show_notifications = self.gc_client.get_bool ("%s/%s" % (self.gc_options,"show_notifications"))
@@ -196,53 +194,51 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet):
menuitem.connect("activate", self.menuitem_response,interface, protocol, name, type, domain)
menuitem.show_all()
- iconfile = "@iconsdir@/48x48/%s.png" % (type)
- if not os.path.exists(iconfile):
- iconfile = "@iconsdir@/48x48/service-discovery-applet.png"
-
- pretty_name = type
- if self.zc_pretty_name.has_key(type):
- pretty_name = self.zc_pretty_name[type]
-
- message = "<b>Name :</b> %s\n<b>Type : </b> %s <i>(%s)</i>" % (name,pretty_name, type)
- try:
- if self.show_notifications == True:
- self.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
+ self.display_service_notification(True, name, type)
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)
+ if self.show_local_services == False:
+ if self.server.IsServiceLocal( interface, protocol, name, type, domain) == True:
+ return
+
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())
del self.zc_types[type]
- iconfile = "@iconsdir@/48x48/%s.png" % (type)
- if not os.path.exists(iconfile):
- iconfile = "@iconsdir@/48x48/service-discovery-applet.png"
+ self.display_service_notification(False, name, type)
- pretty_name = type
+ def display_service_notification(self, new, name, type):
+ # FIXME handle this in avahi.ServiceTypeDatabase
if self.zc_pretty_name.has_key(type):
pretty_name = self.zc_pretty_name[type]
+ else:
+ pretty_name = type
+
+ iconfile = "@iconsdir@/48x48/%s.png" % (type)
+ if not os.path.exists(iconfile):
+ iconfile = "@iconsdir@/48x48/service-discovery-applet.png"
message = "<b>Name :</b> %s\n<b>Type : </b> %s <i>(%s)</i>" % (name, pretty_name, type)
+
+ if new == True:
+ title = "New service found."
+ else:
+ title = "Service disappeared."
+
+ self.display_notification(title, message, iconfile)
+
+ def display_notification(self, title, message, iconfile = "@iconsdir@/48x48/service-discovery-applet.png"):
try:
if self.show_notifications == True:
self.notif.Notify("Service Discovery Applet",
iconfile, dbus.UInt32(0),"",dbus.Byte(0),
- "Service disappeared",message,
+ title,message,
[iconfile],[""],[""],True,dbus.UInt32(3))
except:
print "can't use notification daemon"
@@ -335,14 +331,16 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet):
def start_service_discovery(self, component, verb, applet):
if len(self.domain) != 0:
print "domain not null %s" % (self.domain)
+ self.display_notification("Already running","")
return
-
try:
self.domain = self.server.GetDomainName()
except:
- print "Check that Avahi daemon is running!"
+ self.display_notification("Error Detected!","Check that Avahi daemon is running!")
return
-
+
+ self.display_notification("Starting discovery","")
+
self.interface = avahi.IF_UNSPEC
self.protocol = avahi.PROTO_INET
@@ -357,11 +355,13 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet):
def stop_service_discovery(self, component, verb, applet):
if len(self.domain) == 0:
+ self.display_notification("Already stopped","")
return
for service in self.service_browsers.copy():
self.del_service_type(service[0],service[1],service[2],service[3])
self.domain = ""
+ self.display_notification("Discovery stopped","")
# Callback called when a service is added/removed/enabled/disabled in gconf
def gc_services_cb (self, client, cnxn_id, gc_entry, data):
@@ -382,6 +382,7 @@ 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)
+ self.show_notifications = False
status = self.domain
self.stop_service_discovery(None,None,None)
# only start if it was running before