| 1 |
#!/usr/bin/python3 |
| 2 |
|
| 3 |
## system-config-printer |
| 4 |
|
| 5 |
## Copyright (C) 2010, 2011, 2012, 2013, 2014 Red Hat, Inc. |
| 6 |
## Authors: |
| 7 |
## Tim Waugh <[email protected]> |
| 8 |
|
| 9 |
## This program is free software; you can redistribute it and/or modify |
| 10 |
## it under the terms of the GNU General Public License as published by |
| 11 |
## the Free Software Foundation; either version 2 of the License, or |
| 12 |
## (at your option) any later version. |
| 13 |
|
| 14 |
## This program is distributed in the hope that it will be useful, |
| 15 |
## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
## GNU General Public License for more details. |
| 18 |
|
| 19 |
## You should have received a copy of the GNU General Public License |
| 20 |
## along with this program; if not, write to the Free Software |
| 21 |
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 |
|
| 23 |
import gi |
| 24 |
import dbus.service |
| 25 |
from gi.repository import GObject |
| 26 |
from gi.repository import GLib |
| 27 |
gi.require_version('Gdk', '3.0') |
| 28 |
from gi.repository import Gdk |
| 29 |
gi.require_version('Gtk', '3.0') |
| 30 |
from gi.repository import Gtk |
| 31 |
import sys |
| 32 |
|
| 33 |
from debug import * |
| 34 |
import asyncconn |
| 35 |
import config |
| 36 |
import cups |
| 37 |
import cupshelpers |
| 38 |
import dnssdresolve |
| 39 |
import jobviewer |
| 40 |
import killtimer |
| 41 |
import newprinter |
| 42 |
import PhysicalDevice |
| 43 |
import ppdcache |
| 44 |
import printerproperties |
| 45 |
|
| 46 |
cups.require ("1.9.52") |
| 47 |
|
| 48 |
CONFIG_BUS='org.fedoraproject.Config.Printing' |
| 49 |
CONFIG_PATH='/org/fedoraproject/Config/Printing' |
| 50 |
CONFIG_IFACE='org.fedoraproject.Config.Printing' |
| 51 |
CONFIG_NEWPRINTERDIALOG_IFACE=CONFIG_IFACE + ".NewPrinterDialog" |
| 52 |
CONFIG_PRINTERPROPERTIESDIALOG_IFACE=CONFIG_IFACE + ".PrinterPropertiesDialog" |
| 53 |
CONFIG_JOBVIEWER_IFACE=CONFIG_IFACE + ".JobViewer" |
| 54 |
|
| 55 |
g_ppds = None |
| 56 |
g_killtimer = None |
| 57 |
|
| 58 |
#set program name |
| 59 |
GLib.set_prgname("system-config-printer") |
| 60 |
|
| 61 |
class FetchedPPDs(GObject.GObject): |
| 62 |
__gsignals__ = { |
| 63 |
'ready': (GObject.SignalFlags.RUN_LAST, None, ()), |
| 64 |
'error': (GObject.SignalFlags.RUN_LAST, None, |
| 65 |
(GObject.TYPE_PYOBJECT,)) |
| 66 |
} |
| 67 |
|
| 68 |
def __init__ (self, cupsconn, language): |
| 69 |
GObject.GObject.__init__ (self) |
| 70 |
self._cupsconn = cupsconn |
| 71 |
self._language = language |
| 72 |
self._ppds = None |
| 73 |
|
| 74 |
def is_ready (self): |
| 75 |
return self._ppds is not None |
| 76 |
|
| 77 |
def get_ppds (self): |
| 78 |
return self._ppds |
| 79 |
|
| 80 |
def run (self): |
| 81 |
debugprint ("FetchPPDs: running") |
| 82 |
self._ppds = None |
| 83 |
self._cupsconn.getPPDs2 (reply_handler=self._cups_getppds_reply, |
| 84 |
error_handler=self._cups_error) |
| 85 |
|
| 86 |
def _cups_error (self, conn, exc): |
| 87 |
debugprint ("FetchPPDs: error: %s" % repr (exc)) |
| 88 |
self.emit ('error', exc) |
| 89 |
|
| 90 |
def _cups_getppds_reply (self, conn, result): |
| 91 |
debugprint ("FetchPPDs: success") |
| 92 |
self._ppds = cupshelpers.ppds.PPDs (result, language=self._language) |
| 93 |
self.emit ('ready') |
| 94 |
|
| 95 |
class GetBestDriversRequest: |
| 96 |
def __init__ (self, device_id, device_make_and_model, device_uri, |
| 97 |
cupsconn, language, reply_handler, error_handler): |
| 98 |
self.device_id = device_id |
| 99 |
self.device_make_and_model = device_make_and_model |
| 100 |
self.device_uri = device_uri |
| 101 |
self.cupsconn = cupsconn |
| 102 |
self.language = language |
| 103 |
self.reply_handler = reply_handler |
| 104 |
self.error_handler = error_handler |
| 105 |
self._signals = [] |
| 106 |
self.installed_files = [] |
| 107 |
self.download_tried = False |
| 108 |
debugprint ("+%s" % self) |
| 109 |
|
| 110 |
g_killtimer.add_hold () |
| 111 |
global g_ppds |
| 112 |
if g_ppds is None: |
| 113 |
debugprint ("GetBestDrivers request: need to fetch PPDs") |
| 114 |
g_ppds = FetchedPPDs (self.cupsconn, self.language) |
| 115 |
self._signals.append (g_ppds.connect ('ready', self._ppds_ready)) |
| 116 |
self._signals.append (g_ppds.connect ('error', self._ppds_error)) |
| 117 |
g_ppds.run () |
| 118 |
else: |
| 119 |
if g_ppds.is_ready (): |
| 120 |
debugprint ("GetBestDrivers request: PPDs already fetched") |
| 121 |
self._ppds_ready (g_ppds) |
| 122 |
else: |
| 123 |
debugprint ("GetBestDrivers request: waiting for PPDs") |
| 124 |
self._signals.append (g_ppds.connect ('ready', |
| 125 |
self._ppds_ready)) |
| 126 |
self._signals.append (g_ppds.connect ('error', |
| 127 |
self._ppds_error)) |
| 128 |
|
| 129 |
def __del__ (self): |
| 130 |
debugprint ("-%s" % self) |
| 131 |
|
| 132 |
def _disconnect_signals (self): |
| 133 |
for s in self._signals: |
| 134 |
g_ppds.disconnect (s) |
| 135 |
|
| 136 |
def _ppds_error (self, fetchedppds, exc): |
| 137 |
self._disconnect_signals () |
| 138 |
self.error_handler (exc) |
| 139 |
|
| 140 |
def _ppds_ready (self, fetchedppds): |
| 141 |
if not fetchedppds.is_ready (): |
| 142 |
# PPDs being reloaded. Wait for next 'ready' signal. |
| 143 |
return |
| 144 |
|
| 145 |
self._disconnect_signals () |
| 146 |
ppds = fetchedppds.get_ppds () |
| 147 |
|
| 148 |
try: |
| 149 |
if self.device_id: |
| 150 |
id_dict = cupshelpers.parseDeviceID (self.device_id) |
| 151 |
else: |
| 152 |
id_dict = {} |
| 153 |
(mfg, |
| 154 |
mdl) = cupshelpers.ppds.ppdMakeModelSplit (self.device_make_and_model) |
| 155 |
id_dict["MFG"] = mfg |
| 156 |
id_dict["MDL"] = mdl |
| 157 |
id_dict["DES"] = "" |
| 158 |
id_dict["CMD"] = [] |
| 159 |
self.device_id = "MFG:%s;MDL:%s;" % (mfg, mdl) |
| 160 |
|
| 161 |
fit = ppds.getPPDNamesFromDeviceID (id_dict["MFG"], |
| 162 |
id_dict["MDL"], |
| 163 |
id_dict["DES"], |
| 164 |
id_dict["CMD"], |
| 165 |
self.device_uri, |
| 166 |
self.device_make_and_model) |
| 167 |
|
| 168 |
ppdnamelist = ppds.orderPPDNamesByPreference (fit.keys (), |
| 169 |
self.installed_files, |
| 170 |
devid=id_dict, |
| 171 |
fit=fit) |
| 172 |
ppdname = ppdnamelist[0] |
| 173 |
status = fit[ppdname] |
| 174 |
|
| 175 |
try: |
| 176 |
if status != "exact" and not self.download_tried: |
| 177 |
self.download_tried = True |
| 178 |
self.dialog = newprinter.NewPrinterGUI() |
| 179 |
self.dialog.NewPrinterWindow.set_modal (False) |
| 180 |
self.handles = \ |
| 181 |
[self.dialog.connect ('dialog-canceled', |
| 182 |
self.on_dialog_canceled), |
| 183 |
self.dialog.connect ('driver-download-checked', |
| 184 |
self.on_driver_download_checked)] |
| 185 |
|
| 186 |
self.reply_if_fail = [(x, fit[x]) for x in ppdnamelist] |
| 187 |
if not self.dialog.init ('download_driver', |
| 188 |
devid=self.device_id): |
| 189 |
try: |
| 190 |
g_killtimer.remove_hold () |
| 191 |
finally: |
| 192 |
e = RuntimeError ("Failed to launch dialog") |
| 193 |
self.error_handler (e) |
| 194 |
|
| 195 |
return |
| 196 |
except: |
| 197 |
# Ignore driver download if packages needed for the GUI are not |
| 198 |
# installed or if no windows can be opened |
| 199 |
pass |
| 200 |
|
| 201 |
g_killtimer.remove_hold () |
| 202 |
self.reply_handler ([(x, fit[x]) for x in ppdnamelist]) |
| 203 |
except Exception as e: |
| 204 |
try: |
| 205 |
g_killtimer.remove_hold () |
| 206 |
except: |
| 207 |
pass |
| 208 |
|
| 209 |
self.error_handler (e) |
| 210 |
|
| 211 |
def _destroy_dialog (self): |
| 212 |
for handle in self.handles: |
| 213 |
self.dialog.disconnect (handle) |
| 214 |
|
| 215 |
self.dialog.destroy () |
| 216 |
del self.dialog |
| 217 |
|
| 218 |
def on_driver_download_checked(self, obj, installed_files): |
| 219 |
if len (installed_files) > 0: |
| 220 |
debugprint ("GetBestDrivers request: Re-fetch PPDs after driver download") |
| 221 |
self._signals.append (g_ppds.connect ('ready', self._ppds_ready)) |
| 222 |
self._signals.append (g_ppds.connect ('error', self._ppds_error)) |
| 223 |
g_ppds.run () |
| 224 |
return |
| 225 |
|
| 226 |
g_killtimer.remove_hold () |
| 227 |
self._destroy_dialog () |
| 228 |
self.reply_handler (self.reply_if_fail) |
| 229 |
|
| 230 |
def on_dialog_canceled(self, obj): |
| 231 |
g_killtimer.remove_hold () |
| 232 |
self._destroy_dialog () |
| 233 |
self.reply_handler (self.reply_if_fail) |
| 234 |
|
| 235 |
class GroupPhysicalDevicesRequest: |
| 236 |
def __init__ (self, devices, reply_handler, error_handler): |
| 237 |
self.devices = devices |
| 238 |
self.reply_handler = reply_handler |
| 239 |
self.error_handler = error_handler |
| 240 |
debugprint ("+%s" % self) |
| 241 |
|
| 242 |
try: |
| 243 |
g_killtimer.add_hold () |
| 244 |
need_resolving = {} |
| 245 |
self.deviceobjs = {} |
| 246 |
for device_uri, device_dict in self.devices.items (): |
| 247 |
deviceobj = cupshelpers.Device (device_uri, **device_dict) |
| 248 |
self.deviceobjs[device_uri] = deviceobj |
| 249 |
if device_uri.startswith ("dnssd://"): |
| 250 |
need_resolving[device_uri] = deviceobj |
| 251 |
|
| 252 |
if len (need_resolving) > 0: |
| 253 |
resolver = dnssdresolve.DNSSDHostNamesResolver (need_resolving) |
| 254 |
resolver.resolve (reply_handler=self._group) |
| 255 |
else: |
| 256 |
self._group () |
| 257 |
except Exception as e: |
| 258 |
g_killtimer.remove_hold () |
| 259 |
self.error_handler (e) |
| 260 |
|
| 261 |
def __del__ (self): |
| 262 |
debugprint ("-%s" % self) |
| 263 |
|
| 264 |
def _group (self, resolved_devices=None): |
| 265 |
# We can ignore resolved_devices because the actual objects |
| 266 |
# (in self.devices) have been modified. |
| 267 |
try: |
| 268 |
self.physdevs = [] |
| 269 |
for device_uri, deviceobj in self.deviceobjs.items (): |
| 270 |
newphysicaldevice = PhysicalDevice.PhysicalDevice (deviceobj) |
| 271 |
matched = False |
| 272 |
try: |
| 273 |
i = self.physdevs.index (newphysicaldevice) |
| 274 |
self.physdevs[i].add_device (deviceobj) |
| 275 |
except ValueError: |
| 276 |
self.physdevs.append (newphysicaldevice) |
| 277 |
|
| 278 |
uris_by_phys = [] |
| 279 |
for physdev in self.physdevs: |
| 280 |
uris_by_phys.append ([x.uri for x in physdev.get_devices ()]) |
| 281 |
|
| 282 |
g_killtimer.remove_hold () |
| 283 |
self.reply_handler (uris_by_phys) |
| 284 |
except Exception as e: |
| 285 |
g_killtimer.remove_hold () |
| 286 |
self.error_handler (e) |
| 287 |
|
| 288 |
class ConfigPrintingNewPrinterDialog(dbus.service.Object): |
| 289 |
def __init__ (self, bus, path, cupsconn): |
| 290 |
bus_name = dbus.service.BusName (CONFIG_BUS, bus=bus) |
| 291 |
dbus.service.Object.__init__ (self, bus_name, path) |
| 292 |
self.dialog = newprinter.NewPrinterGUI() |
| 293 |
self.dialog.NewPrinterWindow.set_modal (False) |
| 294 |
self.handles = [self.dialog.connect ('dialog-canceled', |
| 295 |
self.on_dialog_canceled), |
| 296 |
self.dialog.connect ('printer-added', |
| 297 |
self.on_printer_added), |
| 298 |
self.dialog.connect ('printer-modified', |
| 299 |
self.on_printer_modified), |
| 300 |
self.dialog.connect ('driver-download-checked', |
| 301 |
self.on_driver_download_checked)] |
| 302 |
self._ppdcache = ppdcache.PPDCache () |
| 303 |
self._cupsconn = cupsconn |
| 304 |
debugprint ("+%s" % self) |
| 305 |
|
| 306 |
def __del__ (self): |
| 307 |
self.dialog.destroy () |
| 308 |
debugprint ("-%s" % self) |
| 309 |
|
| 310 |
@dbus.service.method(dbus_interface=CONFIG_NEWPRINTERDIALOG_IFACE, |
| 311 |
in_signature='uss', out_signature='') |
| 312 |
def NewPrinterFromDevice(self, xid, device_uri, device_id): |
| 313 |
g_killtimer.add_hold () |
| 314 |
self.dialog.init ('printer_with_uri', device_uri=device_uri, |
| 315 |
devid=device_id, xid=xid) |
| 316 |
|
| 317 |
@dbus.service.method(dbus_interface=CONFIG_NEWPRINTERDIALOG_IFACE, |
| 318 |
in_signature='us', out_signature='') |
| 319 |
def DownloadDriverForDeviceID(self, xid, device_id): |
| 320 |
g_killtimer.add_hold () |
| 321 |
self.dialog.init ('download_driver', devid=device_id, xid=xid) |
| 322 |
|
| 323 |
@dbus.service.method(dbus_interface=CONFIG_NEWPRINTERDIALOG_IFACE, |
| 324 |
in_signature='uss', out_signature='') |
| 325 |
def ChangePPD(self, xid, name, device_id): |
| 326 |
g_killtimer.add_hold () |
| 327 |
self.xid = xid |
| 328 |
self.name = name |
| 329 |
self.device_id = device_id |
| 330 |
self._ppdcache.fetch_ppd (name, self._change_ppd_got_ppd) |
| 331 |
|
| 332 |
def _change_ppd_got_ppd(self, name, ppd, exc): |
| 333 |
# Got PPD; now find device URI. |
| 334 |
self.ppd = ppd |
| 335 |
self._cupsconn.getPrinters (reply_handler=self._change_ppd_with_dev, |
| 336 |
error_handler=self._do_change_ppd) |
| 337 |
|
| 338 |
def _change_ppd_with_dev (self, conn, result): |
| 339 |
self.device_uri = result.get (self.name, {}).get ('device-uri', None) |
| 340 |
self._do_change_ppd (conn) |
| 341 |
|
| 342 |
def _do_change_ppd(self, conn, exc=None): |
| 343 |
self.dialog.init ('ppd', device_uri=self.device_uri, name=self.name, |
| 344 |
ppd=self.ppd, devid=self.device_id, xid=self.xid) |
| 345 |
|
| 346 |
@dbus.service.signal(dbus_interface=CONFIG_NEWPRINTERDIALOG_IFACE, |
| 347 |
signature='') |
| 348 |
def DialogCanceled(self): |
| 349 |
pass |
| 350 |
|
| 351 |
@dbus.service.signal(dbus_interface=CONFIG_NEWPRINTERDIALOG_IFACE, |
| 352 |
signature='s') |
| 353 |
def PrinterAdded(self, name): |
| 354 |
pass |
| 355 |
|
| 356 |
@dbus.service.signal(dbus_interface=CONFIG_NEWPRINTERDIALOG_IFACE, |
| 357 |
signature='sb') |
| 358 |
def PrinterModified(self, name, ppd_has_changed): |
| 359 |
pass |
| 360 |
|
| 361 |
@dbus.service.signal(dbus_interface=CONFIG_NEWPRINTERDIALOG_IFACE, |
| 362 |
signature='a(s)') |
| 363 |
def DriverDownloadChecked(self, installed_files): |
| 364 |
pass |
| 365 |
|
| 366 |
def on_dialog_canceled(self, obj): |
| 367 |
debugprint ("%s: dialog canceled" % self) |
| 368 |
g_killtimer.remove_hold () |
| 369 |
self.DialogCanceled () |
| 370 |
self.remove_handles () |
| 371 |
self.remove_from_connection () |
| 372 |
|
| 373 |
def on_printer_added(self, obj, name): |
| 374 |
debugprint ("%s: printer added" % self) |
| 375 |
g_killtimer.remove_hold () |
| 376 |
self.PrinterAdded (name) |
| 377 |
self.remove_handles () |
| 378 |
self.remove_from_connection () |
| 379 |
|
| 380 |
def on_printer_modified(self, obj, name, ppd_has_changed): |
| 381 |
debugprint ("%s: printer modified" % self) |
| 382 |
g_killtimer.remove_hold () |
| 383 |
self.PrinterModified (name, ppd_has_changed) |
| 384 |
self.remove_handles () |
| 385 |
self.remove_from_connection () |
| 386 |
|
| 387 |
def on_driver_download_checked(self, obj, installed_files): |
| 388 |
debugprint ("%s: driver download checked" % self) |
| 389 |
g_killtimer.remove_hold () |
| 390 |
self.DriverDownloadChecked (installed_files) |
| 391 |
self.remove_handles () |
| 392 |
self.remove_from_connection () |
| 393 |
|
| 394 |
def remove_handles (self): |
| 395 |
for handle in self.handles: |
| 396 |
self.dialog.disconnect (handle) |
| 397 |
|
| 398 |
class ConfigPrintingPrinterPropertiesDialog(dbus.service.Object): |
| 399 |
def __init__ (self, bus, path, xid, name): |
| 400 |
bus_name = dbus.service.BusName (CONFIG_BUS, bus=bus) |
| 401 |
dbus.service.Object.__init__ (self, bus_name=bus_name, object_path=path) |
| 402 |
self.dialog = printerproperties.PrinterPropertiesDialog () |
| 403 |
self.dialog.dialog.set_modal (False) |
| 404 |
handle = self.dialog.connect ('dialog-closed', self.on_dialog_closed) |
| 405 |
self.closed_handle = handle |
| 406 |
self.dialog.show (name) |
| 407 |
self.dialog.dialog.set_modal (False) |
| 408 |
g_killtimer.add_hold () |
| 409 |
|
| 410 |
@dbus.service.method(dbus_interface=CONFIG_PRINTERPROPERTIESDIALOG_IFACE, |
| 411 |
in_signature='', out_signature='') |
| 412 |
def PrintTestPage (self): |
| 413 |
debugprint ("Printing test page") |
| 414 |
return self.dialog.printTestPage () |
| 415 |
|
| 416 |
@dbus.service.signal(dbus_interface=CONFIG_PRINTERPROPERTIESDIALOG_IFACE, |
| 417 |
signature='') |
| 418 |
def Finished (self): |
| 419 |
pass |
| 420 |
|
| 421 |
def on_dialog_closed (self, dialog): |
| 422 |
dialog.destroy () |
| 423 |
g_killtimer.remove_hold () |
| 424 |
self.Finished () |
| 425 |
self.dialog.disconnect (self.closed_handle) |
| 426 |
self.remove_from_connection () |
| 427 |
|
| 428 |
class ConfigPrintingJobApplet(dbus.service.Object): |
| 429 |
def __init__ (self, bus, path): |
| 430 |
bus_name = dbus.service.BusName (CONFIG_BUS, bus=bus) |
| 431 |
dbus.service.Object.__init__ (self, bus_name=bus_name, object_path=path) |
| 432 |
Gdk.threads_enter () |
| 433 |
self.jobapplet = jobviewer.JobViewer(bus=dbus.SystemBus (), |
| 434 |
applet=True, my_jobs=True) |
| 435 |
self.jobapplet.set_process_pending (False) |
| 436 |
Gdk.threads_leave () |
| 437 |
handle = self.jobapplet.connect ('finished', self.on_jobapplet_finished) |
| 438 |
self.finished_handle = handle |
| 439 |
self.has_finished = False |
| 440 |
g_killtimer.add_hold () |
| 441 |
debugprint ("+%s" % self) |
| 442 |
|
| 443 |
def __del__ (self): |
| 444 |
debugprint ("-%s" % self) |
| 445 |
|
| 446 |
@dbus.service.method(dbus_interface=CONFIG_JOBVIEWER_IFACE, |
| 447 |
in_signature='', out_signature='') |
| 448 |
def Quit(self): |
| 449 |
if not self.has_finished: |
| 450 |
self.jobapplet.cleanup () |
| 451 |
|
| 452 |
@dbus.service.signal(dbus_interface=CONFIG_JOBVIEWER_IFACE, signature='') |
| 453 |
def Finished(self): |
| 454 |
pass |
| 455 |
|
| 456 |
def on_jobapplet_finished (self, jobapplet): |
| 457 |
self.Finished () |
| 458 |
g_killtimer.remove_hold () |
| 459 |
self.has_finished = True |
| 460 |
self.jobapplet.disconnect (self.finished_handle) |
| 461 |
self.remove_from_connection () |
| 462 |
|
| 463 |
class ConfigPrinting(dbus.service.Object): |
| 464 |
def __init__ (self): |
| 465 |
self.bus = dbus.SessionBus () |
| 466 |
bus_name = dbus.service.BusName (CONFIG_BUS, bus=self.bus) |
| 467 |
dbus.service.Object.__init__ (self, bus_name, CONFIG_PATH) |
| 468 |
self._cupsconn = asyncconn.Connection () |
| 469 |
self._pathn = 0 |
| 470 |
self._jobapplet = None |
| 471 |
self._jobappletpath = None |
| 472 |
self._ppds = None |
| 473 |
self._language = locale.getlocale (locale.LC_MESSAGES)[0] |
| 474 |
if not self._language: |
| 475 |
self._language = locale.getlocale (locale.LC_CTYPE)[0] |
| 476 |
|
| 477 |
def destroy (self): |
| 478 |
self._cupsconn.destroy () |
| 479 |
|
| 480 |
@dbus.service.method(dbus_interface=CONFIG_IFACE, |
| 481 |
in_signature='', out_signature='s') |
| 482 |
def NewPrinterDialog(self): |
| 483 |
self._pathn += 1 |
| 484 |
path = "%s/NewPrinterDialog/%s" % (CONFIG_PATH, self._pathn) |
| 485 |
ConfigPrintingNewPrinterDialog (self.bus, path, |
| 486 |
self._cupsconn) |
| 487 |
g_killtimer.alive () |
| 488 |
return path |
| 489 |
|
| 490 |
@dbus.service.method(dbus_interface=CONFIG_IFACE, |
| 491 |
in_signature='us', out_signature='s') |
| 492 |
def PrinterPropertiesDialog(self, xid, name): |
| 493 |
self._pathn += 1 |
| 494 |
path = "%s/PrinterPropertiesDialog/%s" % (CONFIG_PATH, self._pathn) |
| 495 |
ConfigPrintingPrinterPropertiesDialog (self.bus, path, xid, name) |
| 496 |
g_killtimer.alive () |
| 497 |
return path |
| 498 |
|
| 499 |
@dbus.service.method(dbus_interface=CONFIG_IFACE, |
| 500 |
in_signature='', out_signature='s') |
| 501 |
def JobApplet(self): |
| 502 |
if self._jobapplet is None or self._jobapplet.has_finished: |
| 503 |
self._pathn += 1 |
| 504 |
path = "%s/JobApplet/%s" % (CONFIG_PATH, self._pathn) |
| 505 |
self._jobapplet = ConfigPrintingJobApplet (self.bus, path) |
| 506 |
self._jobappletpath = path |
| 507 |
|
| 508 |
return self._jobappletpath |
| 509 |
|
| 510 |
@dbus.service.method(dbus_interface=CONFIG_IFACE, |
| 511 |
in_signature='sss', out_signature='a(ss)', |
| 512 |
async_callbacks=('reply_handler', 'error_handler')) |
| 513 |
def GetBestDrivers(self, device_id, device_make_and_model, device_uri, |
| 514 |
reply_handler, error_handler): |
| 515 |
GetBestDriversRequest (device_id, device_make_and_model, device_uri, |
| 516 |
self._cupsconn, self._language, |
| 517 |
reply_handler, error_handler) |
| 518 |
|
| 519 |
@dbus.service.method(dbus_interface=CONFIG_IFACE, |
| 520 |
in_signature='s', out_signature='as') |
| 521 |
def MissingExecutables(self, ppd_filename): |
| 522 |
ppd = cups.PPD (ppd_filename) |
| 523 |
return cupshelpers.missingExecutables (ppd) |
| 524 |
|
| 525 |
@dbus.service.method(dbus_interface=CONFIG_IFACE, |
| 526 |
in_signature='a{sa{ss}}', out_signature='aas', |
| 527 |
async_callbacks=('reply_handler', 'error_handler')) |
| 528 |
def GroupPhysicalDevices(self, devices, reply_handler, error_handler): |
| 529 |
GroupPhysicalDevicesRequest (devices, reply_handler, error_handler) |
| 530 |
|
| 531 |
def _client_demo (): |
| 532 |
# Client demo |
| 533 |
if len (sys.argv) > 2: |
| 534 |
device_uri = sys.argv[2] |
| 535 |
device_id = '' |
| 536 |
if (len (sys.argv) > 4 and |
| 537 |
sys.argv[3] == '--devid'): |
| 538 |
device_id = sys.argv[4] |
| 539 |
else: |
| 540 |
print ("Device URI required") |
| 541 |
return |
| 542 |
|
| 543 |
from gi.repository import Gtk |
| 544 |
bus = dbus.SessionBus () |
| 545 |
obj = bus.get_object (CONFIG_BUS, CONFIG_PATH) |
| 546 |
iface = dbus.Interface (obj, CONFIG_IFACE) |
| 547 |
path = iface.NewPrinterDialog () |
| 548 |
debugprint (path) |
| 549 |
|
| 550 |
obj = bus.get_object (CONFIG_BUS, path) |
| 551 |
iface = dbus.Interface (obj, CONFIG_NEWPRINTERDIALOG_IFACE) |
| 552 |
loop = GObject.MainLoop () |
| 553 |
def on_canceled(path=None): |
| 554 |
print ("%s: Dialog canceled" % path) |
| 555 |
loop.quit () |
| 556 |
|
| 557 |
def on_added(name, path=None): |
| 558 |
print ("%s: Printer '%s' added" % (path, name)) |
| 559 |
loop.quit () |
| 560 |
|
| 561 |
iface.connect_to_signal ("DialogCanceled", on_canceled, |
| 562 |
path_keyword="path") |
| 563 |
iface.connect_to_signal ("PrinterAdded", on_added, |
| 564 |
path_keyword="path") |
| 565 |
|
| 566 |
iface.NewPrinterFromDevice (0, device_uri, device_id) |
| 567 |
loop.run () |
| 568 |
|
| 569 |
if __name__ == '__main__': |
| 570 |
import ppdippstr |
| 571 |
import config |
| 572 |
import gettext |
| 573 |
gettext.install(domain=config.PACKAGE, localedir=config.localedir) |
| 574 |
|
| 575 |
import locale |
| 576 |
try: |
| 577 |
locale.setlocale (locale.LC_ALL, "") |
| 578 |
except: |
| 579 |
pass |
| 580 |
|
| 581 |
ppdippstr.init () |
| 582 |
Gdk.threads_init () |
| 583 |
from dbus.glib import DBusGMainLoop |
| 584 |
DBusGMainLoop (set_as_default=True) |
| 585 |
|
| 586 |
client_demo = False |
| 587 |
if len (sys.argv) > 1: |
| 588 |
for opt in sys.argv[1:]: |
| 589 |
if opt == "--debug": |
| 590 |
set_debugging (True) |
| 591 |
cupshelpers.set_debugprint_fn (debugprint) |
| 592 |
elif opt == "--client": |
| 593 |
client_demo = True |
| 594 |
|
| 595 |
if client_demo: |
| 596 |
_client_demo () |
| 597 |
sys.exit (0) |
| 598 |
|
| 599 |
debugprint ("Service running...") |
| 600 |
g_killtimer = killtimer.KillTimer (killfunc=Gtk.main_quit) |
| 601 |
cp = ConfigPrinting () |
| 602 |
Gdk.threads_enter () |
| 603 |
Gtk.main () |
| 604 |
Gdk.threads_leave () |
| 605 |
cp.destroy () |