def __init__(self,
                 bus=None,
                 my_jobs=True,
                 specific_dests=None,
                 monitor_jobs=True,
                 host=None,
                 port=None,
                 encryption=None):
        GObject.GObject.__init__(self)
        self.my_jobs = my_jobs
        self.specific_dests = specific_dests
        self.monitor_jobs = monitor_jobs
        self.jobs = {}
        self.printer_state_reasons = {}
        self.printers = set()
        self.process_pending_events = True
        self.fetch_jobs_timer = None
        self.cups_connection_in_error = False

        if host:
            cups.setServer(host)
        if port:
            cups.setPort(port)
        if encryption:
            cups.setEncryption(encryption)
        self.user = cups.getUser()
        self.host = cups.getServer()
        self.port = cups.getPort()
        self.encryption = cups.getEncryption()
        self.ppdcache = ppdcache.PPDCache(host=self.host,
                                          port=self.port,
                                          encryption=self.encryption)

        self.which_jobs = "not-completed"
        self.reasons_seen = {}
        self.connecting_timers = {}
        self.still_connecting = set()
        self.connecting_to_device = {}
        self.received_any_dbus_signals = False
        self.update_timer = None

        if bus is None:
            try:
                bus = dbus.SystemBus()
            except dbus.exceptions.DBusException:
                # System bus not running.
                pass

        self.bus = bus
        if bus is not None:
            bus.add_signal_receiver(self.handle_dbus_signal,
                                    path=self.DBUS_PATH,
                                    dbus_interface=self.DBUS_IFACE)
        self.sub_id = -1
 def __init__(self, bus, path, cupsconn):
     bus_name = dbus.service.BusName(CONFIG_BUS, bus=bus)
     dbus.service.Object.__init__(self, bus_name, path)
     self.dialog = newprinter.NewPrinterGUI()
     self.dialog.NewPrinterWindow.set_modal(False)
     self.handles = [
         self.dialog.connect('dialog-canceled', self.on_dialog_canceled),
         self.dialog.connect('printer-added', self.on_printer_added),
         self.dialog.connect('printer-modified', self.on_printer_modified),
         self.dialog.connect('driver-download-checked',
                             self.on_driver_download_checked)
     ]
     self._ppdcache = ppdcache.PPDCache()
     self._cupsconn = cupsconn
     debugprint("+%s" % self)
    def display (self):
        troubleshooter = self.troubleshooter
        try:
            queue = troubleshooter.answers['cups_queue']
        except KeyError:
            return False

        parent = self.troubleshooter.get_window ()
        cups.setServer ('')
        self.op = TimedOperation (cups.Connection, parent=parent)
        c = self.op.run ()
        self.op = TimedOperation (c.getPrinterAttributes,
                                  args=(queue,),
                                  parent=parent)
        dict = self.op.run ()

        the_ppdcache = ppdcache.PPDCache ()

        text = ''
        state_message = dict['printer-state-message']
        if state_message:
            text += _("The printer's state message is: '%s'.") % state_message
            text += '\n\n'

        state_reasons_list = dict['printer-state-reasons']
        if type (state_reasons_list) == unicode:
            state_reasons_list = [state_reasons_list]

        self.state_message = state_message
        self.state_reasons = state_reasons_list

        human_readable_errors = []
        human_readable_warnings = []
        for reason in state_reasons_list:
            if reason == "none":
                continue

            r = statereason.StateReason (queue, reason, the_ppdcache)
            (title, description) = r.get_description ()
            level = r.get_level ()
            if level == statereason.StateReason.ERROR:
                human_readable_errors.append (description)
            elif level == statereason.StateReason.WARNING:
                human_readable_warnings.append (description)

        if human_readable_errors:
            text += _("Errors are listed below:") + '\n'
            text += reduce (lambda x, y: x + "\n" + y, human_readable_errors)
            text += '\n\n'

        if human_readable_warnings:
            text += _("Warnings are listed below:") + '\n'
            text += reduce (lambda x, y: x + "\n" + y, human_readable_warnings)

        self.label.set_text (text)
        if (state_message == '' and
            len (human_readable_errors) == 0 and
            len (human_readable_warnings) == 0):
            return False

        # If this screen has been show before, don't show it again if
        # nothing changed.
        if troubleshooter.answers.has_key ('printer-state-message'):
            if (troubleshooter.answers['printer-state-message'] ==
                self.state_message and
                troubleshooter.answers['printer-state-reasons'] ==
                self.state_reasons):
                return False

        return True