Tizen 2.1 base
[platform/upstream/hplip.git] / fax / faxdevice.py
1 # -*- coding: utf-8 -*-
2 #
3 # (c) Copyright 2010 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 # Local
23 from base.g import *
24 from prnt import cups
25 from base import device, codes
26 from soapfax import SOAPFaxDevice
27 from pmlfax import PMLFaxDevice
28 from marvellfax import MarvellFaxDevice
29
30 def FaxDevice(device_uri=None, printer_name=None,
31               callback=None, 
32               fax_type=FAX_TYPE_NONE,
33               disable_dbus=False):
34                  
35     if fax_type == FAX_TYPE_NONE:
36         if device_uri is None and printer_name is not None:
37             printers = cups.getPrinters()
38     
39             for p in printers:
40                 if p.name.lower() == printer_name.lower():
41                     device_uri = p.device_uri
42                     break
43             else:
44                 raise Error(ERROR_DEVICE_NOT_FOUND)
45                 
46         if device_uri is not None:
47             mq = device.queryModelByURI(device_uri)
48             fax_type = mq['fax-type']
49             
50     log.debug("fax-type=%d" % fax_type)
51                     
52     if fax_type in (FAX_TYPE_BLACK_SEND_EARLY_OPEN, FAX_TYPE_BLACK_SEND_LATE_OPEN):
53         return PMLFaxDevice(device_uri, printer_name, callback, fax_type, disable_dbus)
54
55     elif fax_type == FAX_TYPE_SOAP:
56         return SOAPFaxDevice(device_uri, printer_name, callback, fax_type, disable_dbus)
57
58     elif fax_type == FAX_TYPE_LEDMSOAP:
59         return LEDMSOAPFaxDevice(device_uri, printer_name, callback, fax_type, disable_dbus)
60
61     elif fax_type == FAX_TYPE_MARVELL:
62         return MarvellFaxDevice(device_uri, printer_name, callback, fax_type, disable_dbus)
63         
64     elif fax_type == FAX_TYPE_LEDM:
65         from ledmfax import LEDMFaxDevice
66         return LEDMFaxDevice(device_uri, printer_name, callback, fax_type, disable_dbus)
67         
68
69     else:
70         raise Error(ERROR_DEVICE_DOES_NOT_SUPPORT_OPERATION)