2 # -*- coding: utf-8 -*-
4 # (c) Copyright 2003-2007 Hewlett-Packard Development Company, L.P.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 __mod__ = 'hp-systray'
24 __title__ = 'System Tray Status Service'
35 from base import utils, module
40 if __name__ == '__main__':
42 # Create a new session ID for the tray. This disassociates the
43 # tray from the controlling terminal so that it cannot receive
44 # keyboard interrupts.
46 # Only do this if we aren't already a session leader. This test
47 # only succeeds if we are executed from hp-toolbox.
48 if os.getpgid(os.getpid()) != os.getpid():
51 mod = module.Module(__mod__, __title__, __version__, __doc__, None,
52 (GUI_MODE,), (UI_TOOLKIT_QT4, UI_TOOLKIT_QT3))
54 mod.setUsage(module.USAGE_FLAG_NONE,
55 extra_options=[("Startup even if no hplip CUPS queues are present:", "-x or --force-startup", "option", False)])
57 opts, device_uri, printer_name, mode, ui_toolkit, lang = \
58 mod.parseStdOpts('x', ['force-startup'], False)
62 if o in ('-x', '--force-startup'):
66 log.error("hp-systray cannot be run as root. Exiting.")
69 if ui_toolkit == 'qt3':
70 if not utils.canEnterGUIMode():
71 log.error("%s requires Qt3 GUI and DBus support. Exiting." % __mod__)
75 if not utils.canEnterGUIMode4():
76 log.error("%s requires Qt4 GUI and DBus support. Exiting." % __mod__)
80 # Check for any hp: or hpfax: queues. If none, exit
81 if not utils.any([p.device_uri for p in cups.getPrinters()], lambda x : x.startswith('hp')):
82 log.warn("No hp: or hpfax: devices found in any installed CUPS queue. Exiting.")
88 log.debug("Creating pipe: hpssd (%d) ==> systemtray (%d)" % (w1, r1))
90 parent_pid = os.getpid()
91 child_pid1 = os.fork()
97 if ui_toolkit == 'qt3':
99 import ui.systemtray as systray
101 log.error("Unable to load Qt3 support. Is it installed?")
106 import ui4.systemtray as systray
108 log.error("Unable to load Qt4 support. Is it installed?")
118 # child (dbus & device i/o [qt4] or dbus [qt3])
121 if ui_toolkit == 'qt4':
125 log.debug("Creating pipe: hpssd (%d) ==> hpdio (%d)" % (w2, r2))
126 log.debug("Creating pipe: hpdio (%d) ==> hpssd (%d)" % (w3, r3))
128 child_pid2 = os.fork()
134 hpssd.run(w1, w2, r3)