home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / hplip / ui / faxsettingsform.py < prev    next >
Encoding:
Python Source  |  2006-08-30  |  4.0 KB  |  119 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2003-2006 Hewlett-Packard Development Company, L.P.
  4. #
  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.
  9. #
  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.
  14. #
  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
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22.  
  23.  
  24. from qt import *
  25. from faxsettingsform_base import FaxSettingsForm_base
  26. from base.g import *
  27. from base import device, pml, utils
  28.  
  29. class PhoneNumValidator(QValidator):
  30.     def __init__(self, parent=None, name=None):
  31.         QValidator.__init__(self, parent, name)
  32.  
  33.     def validate(self, input, pos):
  34.         input = str(input)
  35.         if not input:
  36.             return QValidator.Acceptable, pos
  37.         elif input[pos-1] not in '0123456789-(+) ':
  38.             return QValidator.Invalid, pos
  39.         elif len(input) > 50:
  40.             return QValidator.Invalid, pos
  41.         else:
  42.             return QValidator.Acceptable, pos
  43.             
  44.             
  45. class StationNameValidator(QValidator):
  46.     def __init__(self, parent=None, name=None):
  47.         QValidator.__init__(self, parent, name)
  48.  
  49.     def validate(self, input, pos):
  50.         input = str(input)
  51.         if not input:
  52.             return QValidator.Acceptable, pos
  53.         # TODO: Find valid chars for this field
  54.         elif input != utils.printable(input): 
  55.             return QValidator.Invalid, pos
  56.         elif len(input) > 50:
  57.             return QValidator.Invalid, pos
  58.         else:
  59.             return QValidator.Acceptable, pos
  60.             
  61.     
  62.  
  63. class FaxSettingsForm(FaxSettingsForm_base):
  64.  
  65.     def __init__(self, dev, fax_num, name_co, parent = None,name = None,modal = 0,fl = 0):
  66.         FaxSettingsForm_base.__init__(self,parent,name,modal,fl)
  67.         self.dev = dev
  68.         
  69.         self.faxEdit.setValidator(PhoneNumValidator(self.faxEdit))
  70.         self.nameEdit.setValidator(StationNameValidator(self.nameEdit))
  71.         self.voiceEdit.setValidator(PhoneNumValidator(self.voiceEdit))
  72.         
  73. ##        try:
  74. ##            result_code, fax_num = dev.getPML(pml.OID_FAX_LOCAL_PHONE_NUM)
  75. ##        except Error:
  76. ##            log.error("PML failure.")
  77. ##        else:
  78. ##            fax_num = str(fax_num)
  79.         self.faxEdit.setText(fax_num)
  80. ##            
  81. ##        try:
  82. ##            result_code, name = dev.getPML(pml.OID_FAX_STATION_NAME)
  83. ##        except Error:
  84. ##            log.error("PML failure.")
  85. ##            name = str(name)
  86.         self.nameEdit.setText(name_co)
  87.         
  88.         self.setOKButton(fax_num and name_co)
  89.         
  90.         self.voiceEdit.setText(user_cfg.fax.voice_phone or '')
  91.         self.emailEdit.setText(user_cfg.fax.email_address or user_cfg.alerts.email_address or '')
  92.         
  93.     def faxEdit_textChanged(self,a0):
  94.         self.setOKButton()
  95.         
  96.     def nameEdit_textChanged(self,a0):
  97.         self.setOKButton()
  98.         
  99.     def setOKButton(self, toggle=None):
  100.         if toggle is not None:
  101.             self.pushButtonOK.setEnabled(bool(toggle))
  102.         else:
  103.             name = str(self.nameEdit.text())
  104.             fax_num = str(self.faxEdit.text())
  105.             self.pushButtonOK.setEnabled(bool(name and fax_num))
  106.         
  107.         
  108.     def accept(self):
  109.         try:
  110.             self.dev.setPML(pml.OID_FAX_LOCAL_PHONE_NUM, str(self.faxEdit.text()))
  111.             self.dev.setPML(pml.OID_FAX_STATION_NAME, str(self.nameEdit.text()))
  112.         except Error:
  113.             log.error("Error setting fax settings to device.")
  114.             
  115.         user_cfg.fax.voice_phone = str(self.voiceEdit.text())
  116.         user_cfg.fax.email_address = str(self.emailEdit.text())
  117.         FaxSettingsForm_base.accept(self)
  118.         
  119.