1 # -*- coding: utf-8 -*-
3 # (c) Copyright 2003-2009 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
25 from faxsettingsform_base import FaxSettingsForm_base
27 from base import device, pml, utils
29 class PhoneNumValidator(QValidator):
30 def __init__(self, parent=None, name=None):
31 QValidator.__init__(self, parent, name)
33 def validate(self, input, pos):
34 input = unicode(input)
36 input = input.encode('ascii')
37 except UnicodeEncodeError:
38 return QValidator.Invalid, pos
41 return QValidator.Acceptable, pos
42 elif input[pos-1] not in '0123456789-(+) ':
43 return QValidator.Invalid, pos
45 return QValidator.Invalid, pos
47 return QValidator.Acceptable, pos
50 class StationNameValidator(QValidator):
51 def __init__(self, parent=None, name=None):
52 QValidator.__init__(self, parent, name)
54 def validate(self, input, pos):
55 input = unicode(input)
58 input = input.encode('ascii')
59 except UnicodeEncodeError:
60 return QValidator.Invalid, pos
63 return QValidator.Acceptable, pos
64 # TODO: Find valid chars for this field
65 elif input != utils.printable(input):
66 return QValidator.Invalid, pos
68 return QValidator.Invalid, pos
70 return QValidator.Acceptable, pos
74 class FaxSettingsForm(FaxSettingsForm_base):
76 def __init__(self, dev, fax_num, name_co, parent = None,name = None,modal = 0,fl = 0):
77 FaxSettingsForm_base.__init__(self,parent,name,modal,fl)
79 self.faxEdit.setValidator(PhoneNumValidator(self.faxEdit))
80 self.nameEdit.setValidator(StationNameValidator(self.nameEdit))
81 self.voiceEdit.setValidator(PhoneNumValidator(self.voiceEdit))
82 self.faxEdit.setText(fax_num)
83 self.nameEdit.setText(name_co)
84 self.setOKButton(fax_num and name_co)
85 self.voiceEdit.setText(QString(user_conf.get('fax', 'voice_phone')))
86 self.emailEdit.setText(QString(user_conf.get('fax', 'email_address')))
88 def faxEdit_textChanged(self,a0):
91 def nameEdit_textChanged(self,a0):
94 def setOKButton(self, toggle=None):
95 if toggle is not None:
96 self.pushButtonOK.setEnabled(bool(toggle))
98 name = unicode(self.nameEdit.text())
99 fax_num = unicode(self.faxEdit.text())
100 self.pushButtonOK.setEnabled(bool(name and fax_num))
103 # str() is OK here since the validators removed any non-ascii chars
104 fax = str(self.faxEdit.text())
106 name = str(self.nameEdit.text())
109 self.dev.setPML(pml.OID_FAX_LOCAL_PHONE_NUM, fax)
110 self.dev.setPML(pml.OID_FAX_STATION_NAME, name)
112 log.error("Error setting fax settings to device.")
114 # TODO: This is a problem - user can enter non-ascii chars...
115 # user config needs to be in utf-8 encoding (but its not right now)
116 user_conf.set('fax', 'voice_phone', unicode(self.voiceEdit.text()).encode('utf-8'))
117 user_conf.set('fax', 'email_address', unicode(self.emailEdit.text()).encode('utf-8'))
118 FaxSettingsForm_base.accept(self)