1 # -*- coding: utf-8 -*-
3 # (c) Copyright 2001-2011 Hewlett-Packard Development Company, L.P.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # Author: Sarbeswar Meher
26 from ui_utils import *
27 from base import device, utils
32 DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY = 0
33 DEVICEURICOMBOBOX_TYPE_FAX_ONLY = 1
34 DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX = 2
37 class DeviceUriComboBox(QWidget):
38 def __init__(self, parent):
39 QWidget.__init__(self, parent)
41 self.initial_device = None
43 self.typ = DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY
47 self.user_settings = utils.UserSettings()
48 self.user_settings.load()
49 self.user_settings.debug()
55 HBoxLayout = QHBoxLayout(self)
56 HBoxLayout.setName("HBoxLayout")
58 self.NameLabel = QLabel(self)
59 self.NameLabel.setName("NameLabel")
60 HBoxLayout.addWidget(self.NameLabel)
62 SpacerItem = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Minimum)
63 HBoxLayout.addItem(SpacerItem)
65 self.ComboBox = QComboBox(self)
66 sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
67 sizePolicy.setHorStretch(0)
68 sizePolicy.setVerStretch(0)
69 sizePolicy.setHeightForWidth(self.ComboBox.sizePolicy().hasHeightForWidth())
70 self.ComboBox.setSizePolicy(sizePolicy)
71 self.ComboBox.setName("ComboBox")
72 HBoxLayout.addWidget(self.ComboBox)
74 self.NameLabel.setText(self.__tr("Device:"))
76 # self.connect(self.ComboBox, SIGNAL("currentIndexChanged(const QString &)"), self, self.ComboBox_currentIndexChanged)
78 self.connect(self.ComboBox, SIGNAL("highlighted(const QString &)"), self.ComboBox_currentIndexChanged)
81 def setType(self, typ):
82 if typ in (DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY,
83 DEVICEURICOMBOBOX_TYPE_FAX_ONLY,
84 DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX):
88 def setFilter(self, filter):
92 def setInitialDevice(self, device_uri):
93 self.initial_device = device_uri
95 def setParent(self, parent):
99 if self.typ == DEVICEURICOMBOBOX_TYPE_PRINTER_ONLY:
102 elif self.typ == DEVICEURICOMBOBOX_TYPE_FAX_ONLY:
103 be_filter = ['hpfax']
104 self.NameLabel.setText(self.__tr("Fax Device:"))
106 else: # DEVICEURICOMBOBOX_TYPE_PRINTER_AND_FAX
107 be_filter = ['hp', 'hpfax']
109 self.devices = device.getSupportedCUPSDevices(be_filter, self.filter)
110 return len(self.devices)
114 if self.devices is None:
115 num_devices = self.setDevices()
117 self.device_index = {}
120 if self.initial_device is None:
121 #self.initial_device = user_conf.get('last_used', 'device_uri')
122 self.initial_device = self.user_settings.last_used_device_uri
127 str_devices = self.devices.keys()
128 d = str(str_devices[0])
129 for i in range(0, num_devices):
130 self.ComboBox.insertItem(str_devices[i], i)
131 if self.initial_device is not None and d == self.initial_device:
132 self.initial_device = None
135 self.ComboBox.setCurrentItem(-1)
137 self.updating = False
139 self.ComboBox.setCurrentItem(k)
142 self.parent.DeviceUriComboBox_noDevices()
145 def ComboBox_currentIndexChanged(self, t):
149 self.device_uri = unicode(t)
151 #user_conf.set('last_used', 'device_uri', self.device_uri)
152 self.user_settings.last_used_device_uri = self.device_uri
153 self.user_settings.save()
155 self.parent.DeviceUriComboBox_currentChanged(self.device_uri)
158 def __tr(self,s,c = None):
159 return qApp.translate("DeviceUriComboBox",s,c)