File system-config-printer-cups-autoconfig-notifications.patch of Package system-config-printer

diff --git a/applet.py b/applet.py
index 8cb90ab..1b27654 100644
--- a/applet.py
+++ b/applet.py
@@ -220,6 +220,101 @@ class NewPrinterNotification(dbus.service.Object):
 
         return False
 
+####
+#### Integration with cups-autoconfig
+####
+#### Based on code from http://redclay.altervista.org/wiki/doku.php?id=projects:hal-automount
+
+class NewPrinterNotificationCupsAutoconfig:
+
+    def __init__ (self, bus):
+        self.bus = bus
+        self.bus.add_signal_receiver(self.device_added,
+                        'DeviceAdded',
+                        'org.freedesktop.Hal.Manager',
+                        'org.freedesktop.Hal',
+                        '/org/freedesktop/Hal/Manager')
+
+    def udi_to_device (self, udi):
+        device_obj = self.bus.get_object('org.freedesktop.Hal', udi)
+        return dbus.Interface (device_obj, 'org.freedesktop.Hal.Device')
+
+    def device_added (self, udi):
+        try:
+            properties = self.udi_to_device(udi).GetAllProperties()
+            capabilities = properties.get('info.capabilities')
+            if not capabilities:
+                return
+
+            for capability in capabilities:
+                if capability == u'printer':
+                    self.printer_added (udi, properties)
+                    break
+
+        except Exception, e:
+            print >> sys.stderr, "Error in cups-autoconfig integration: %s" % e
+
+    def printer_added (self, udi, properties):
+        if properties.get('printer.configured_existing'):
+            return
+
+        if properties.get('printer.configured'):
+            title = _("Printer added")
+            name = properties.get('printer.display_name')
+            text = _("`%s' is ready for printing.") % name
+
+            n = pynotify.Notification (title, text, 'printer')
+            n.set_urgency (pynotify.URGENCY_NORMAL)
+            n.add_action ("configure", _("Configure"),
+                          lambda x, y: self.configure (x, y, name))
+
+        else:
+            title = _("Printer plugged")
+            text = _("The printer could not be automatically configured.") % name
+
+            n = pynotify.Notification (title, text, 'printer')
+            n.set_urgency (pynotify.URGENCY_NORMAL)
+            n.add_action ("configure", _("Configure"),
+                          lambda x, y: self.launch (x, y))
+
+        n.show ()
+
+    def configure (self, notification, action, name):
+        self.run_config_tool (["--configure-printer", name])
+
+    def launch (self, notification, action):
+        self.run_config_tool ([])
+
+    def run_config_tool (self, argv):
+        import os
+        pid = os.fork ()
+        if pid == 0:
+            # Child.
+            cmd = "/usr/bin/system-config-printer"
+            argv.insert (0, cmd)
+            os.execvp (cmd, argv)
+            sys.exit (1)
+        elif pid == -1:
+            print "Error forking process"
+        else:
+            gobject.timeout_add (60 * 1000, self.collect_exit_code, pid)
+
+    def collect_exit_code (self, pid):
+        # We do this with timers instead of signals because we already
+        # have gobject imported, but don't (yet) import signal;
+        # let's try not to inflate the process size.
+        import os
+        try:
+            print "Waiting for child %d" % pid
+            (pid, status) = os.waitpid (pid, os.WNOHANG)
+            if pid == 0:
+                # Run this timer again.
+                return True
+        except OSError:
+            pass
+
+        return False
+
 PROGRAM_NAME="system-config-printer-applet"
 def show_help ():
     print "usage: %s [--no-tray-icon]" % PROGRAM_NAME
@@ -303,6 +398,17 @@ if __name__ == '__main__':
             except:
                 pass
 
+        try:
+            NewPrinterNotificationCupsAutoconfig(bus)
+            service_running = True
+        except:
+            try:
+                print >> sys.stderr, \
+                    "%s: failed to start NewPrinterNotificationCupsAutoconfig service" % \
+                    PROGRAM_NAME
+            except:
+                pass
+
     if trayicon and get_debugging () == False:
         # Start off just waiting for print jobs.
         def any_jobs ():
openSUSE Build Service is sponsored by