summaryrefslogtreecommitdiffstats
path: root/src/service-discovery-applet.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/service-discovery-applet.in')
-rwxr-xr-xsrc/service-discovery-applet.in100
1 files changed, 47 insertions, 53 deletions
diff --git a/src/service-discovery-applet.in b/src/service-discovery-applet.in
index e9b5955..55655c1 100755
--- a/src/service-discovery-applet.in
+++ b/src/service-discovery-applet.in
@@ -134,51 +134,6 @@ class SDAGconf:
###############################################################################
#
-# NOTIFICATIONS
-#
-class Notifications:
- def __init__(self, applet):
- if not pynotify.init(_("Zeroconf Service Discovery")):
- print "Notification disable."
- self.applet.show_notifications = False
- self.applet = applet
-
-
- def display_service_notification(self, new, name, type):
- iconfile_path = "@iconsdir@/48x48/%s.png" % (type)
- print iconfile_path
- if not os.path.exists(iconfile_path):
- iconfile = "file://@iconsdir@/48x48/service-discovery-applet.png"
- else:
- iconfile ="file://%s" % iconfile_path
-
- stdb = ServiceTypeDatabase()
- h_type = stdb.get_human_type(type)
- message = _("<b>Name :</b> %s\n<b>Type : </b> %s <i>(%s)</i>") % (name, h_type, 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 = "file://@iconsdir@/48x48/service-discovery-applet.png"):
- try:
- if self.applet.show_notifications == True:
- n = pynotify.Notification(title, message, iconfile)
-# x, y = self.applet.window.get_origin()
-# n.set_hint("x",x)
-# n.set_hint("y",y)
-# n.attach_to_widget(self.applet.window)
- n.show()
- except:
- print "can't use notification daemon"
- raise
-
-
-###############################################################################
-#
# SERVIDE DISCOVERY APPLET MAIN CLASS
#
class ServiceDiscoveryApplet(gnomeapplet.Applet):
@@ -249,7 +204,9 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet):
except:
self.use_host_names = False
- self.sdaNotifications = Notifications(self)
+ if not pynotify.init(_("Zeroconf Service Discovery")):
+ error_msg(_("<b>Notification Daemon Error:</b>\n Notifications won't work."))
+ self.applet.show_notifications = False
self.start_service_discovery(None, None, None)
@@ -271,6 +228,43 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet):
###############################################################################
#
+# NOTIFICATIONS
+#
+ def display_service_notification(self, new, name, type):
+ iconfile_path = "@iconsdir@/48x48/%s.png" % (type)
+ print iconfile_path
+ if not os.path.exists(iconfile_path):
+ iconfile = "file://@iconsdir@/48x48/service-discovery-applet.png"
+ else:
+ iconfile ="file://%s" % iconfile_path
+
+ stdb = ServiceTypeDatabase()
+ h_type = stdb.get_human_type(type)
+ message = _("<b>Name :</b> %s\n<b>Type : </b> %s <i>(%s)</i>") % (name, h_type, 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 = "file://@iconsdir@/48x48/service-discovery-applet.png"):
+ try:
+ if self.show_notifications == True:
+ n = pynotify.Notification(title, message, iconfile)
+# x,y = self.applet.window.get_origin()
+# n.set_hint("x",x)
+# n.set_hint("y",y)
+# n.attach_to_widget(self.applet.window)
+ n.show()
+ except:
+ print "can't use notification daemon"
+ pass
+
+
+###############################################################################
+#
# AVAHI
#
def siocgifname(self, interface):
@@ -333,14 +327,14 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet):
menuitem.connect("activate", self.menuitem_response,interface, protocol, name, type, domain)
menuitem.show_all()
- self.sdaNotifications.display_service_notification(True, name, type)
+ self.display_service_notification(True, name, type)
def remove_service(self, interface, protocol, name, type, domain, flags):
print "Service '%s' of type '%s' in domain '%s' on %s.%i disappeared." % (name, type, domain, self.siocgifname(interface), protocol)
if self.zc_services.has_key((interface, protocol, name, type, domain)):
self.zc_types[type].remove(self.zc_services[(interface, protocol, name, type, domain)])
- self.sdaNotifications.display_service_notification(False, name, type)
+ self.display_service_notification(False, name, type)
if self.zc_types[type].get_children() == []:
self.service_menu.remove(self.zc_types[type].get_attach_widget())
@@ -416,15 +410,15 @@ 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.sdaNotifications.display_notification(_("Already Discovering"),"")
+ self.display_notification(_("Already Discovering"),"")
return
try:
self.domain = self.server.GetDomainName()
except:
- self.sdaNotifications.display_notification(_("Error Detected!"),_("Check that the Avahi daemon is running!"))
+ self.display_notification(_("Error Detected!"),_("Check that the Avahi daemon is running!"))
return
- self.sdaNotifications.display_notification(_("Starting discovery"),"")
+ self.display_notification(_("Starting discovery"),"")
self.interface = avahi.IF_UNSPEC
self.protocol = avahi.PROTO_INET
@@ -439,13 +433,13 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet):
def stop_service_discovery(self, component, verb, applet):
if len(self.domain) == 0:
- self.sdaNotifications.display_notification(_("Discovery already stopped"),"")
+ self.display_notification(_("Discovery 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.sdaNotifications.display_notification(_("Discovery stopped"),"")
+ self.display_notification(_("Discovery stopped"),"")
###############################################################################