1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
5 Settings storage and configuration manager
7 __author__
= 'Michal Čihař'
8 __email__
= 'michal@cihar.com'
10 Copyright (c) 2003 - 2007 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
37 Helper class for generating settings.
40 self
.connection
= None
42 self
.manufacturer
= None
45 self
.gammudriver
= None
50 if self
.position
== 0:
53 return 'gammu%d' % self
.position
57 def GetGammuDriver(self
):
58 return self
.gammudriver
63 def SetPosition(self
, pos
):
66 def SetConnection(self
, conn
):
67 self
.connection
= conn
69 def SetDriver(self
, driver
):
72 def SetGammuDriver(self
, driver
):
73 self
.gammudriver
= driver
75 def SetManufacturer(self
, manu
):
76 self
.manufacturer
= manu
78 def SetPort(self
, port
):
81 def SetName(self
, name
):
84 def GetSettings(self
):
85 return {'Position': self
.position
, 'Device': self
.port
, 'Connection': self
.gammudriver
, 'Name': self
.name
}
87 def GetManufacturers(self
):
93 connections
.append(_('I don\'t know'))
94 helps
.append(_('Select this option only if really necessary. You will be provided with too much options in next step.'))
96 names
.append('symbian')
97 connections
.append(_('Symbian based phone'))
98 helps
.append(_('Go on if your phone uses Symbian OS (regardless of manufacturer).'))
101 connections
.append(_('Alcatel phone'))
102 helps
.append(_('Alcatel phone not running Symbian.'))
105 connections
.append(_('BenQ/Siemens phone'))
106 helps
.append(_('BenQ or Siemens phone not running Symbian.'))
108 names
.append('nokia')
109 connections
.append(_('Nokia phone'))
110 helps
.append(_('Nokia phone not running Symbian.'))
113 connections
.append(_('Samsung phone'))
114 helps
.append(_('Samsung phone not running Symbian.'))
117 connections
.append(_('Sharp phone'))
118 helps
.append(_('Sharp phone not running Symbian.'))
121 connections
.append(_('Sony Ericsson phone'))
122 helps
.append(_('Sony Ericsson phone not running Symbian.'))
125 connections
.append(_('None of the above'))
126 helps
.append(_('Select this option if nothing above matches.'))
128 return (names
, connections
, helps
)
130 def AddOBEX(self
, names
, connections
, helps
):
132 connections
.append(_('OBEX and IrMC protocols'))
133 if self
.manufacturer
in ['symbian', 'nokia']:
134 helps
.append(_('Standard access to filesystem. Not a good choice for Nokia if you want to access data.'))
136 helps
.append(_('Standard access to filesystem and sometimes also to phone data. Good choice for recent phones.'))
138 def AddSymbian(self
, names
, connections
, helps
):
139 names
.append('symbian')
140 connections
.append(_('Symbian using Gnapplet'))
141 helps
.append(_('You have to install Gnapplet into phone before using this connection. You can find it in Gammu sources.'))
143 def AddNokia(self
, names
, connections
, helps
):
145 connections
.append(_('Nokia proprietary protocol'))
146 helps
.append(_('Nokia proprietary protocol FBUS.'))
147 if self
.connection
== 'serial':
149 connections
.append(_('Nokia proprietary service protocol'))
150 helps
.append(_('Nokia proprietary protocol MBUS. Older version, use FBUS if possible.'))
152 def AddAT(self
, names
, connections
, helps
):
154 connections
.append(_('AT based'))
155 if self
.manufacturer
in ['symbian', 'nokia']:
156 helps
.append(_('This provides minimal access to phone features. It is recommended to use other connection type.'))
158 helps
.append(_('Good choice for most phones except Nokia and Symbian based. Provides access to most phone features.'))
160 def GetDrivers(self
):
165 if self
.manufacturer
== 'nokia':
166 self
.AddNokia(names
, connections
, helps
)
167 self
.AddAT(names
, connections
, helps
)
168 self
.AddOBEX(names
, connections
, helps
)
169 elif self
.manufacturer
== 'symbian':
170 self
.AddSymbian(names
, connections
, helps
)
171 self
.AddAT(names
, connections
, helps
)
172 self
.AddOBEX(names
, connections
, helps
)
173 elif self
.manufacturer
== 'nota':
174 self
.AddAT(names
, connections
, helps
)
175 self
.AddOBEX(names
, connections
, helps
)
176 elif self
.manufacturer
== 'any':
177 self
.AddAT(names
, connections
, helps
)
178 self
.AddOBEX(names
, connections
, helps
)
179 self
.AddNokia(names
, connections
, helps
)
180 self
.AddSymbian(names
, connections
, helps
)
182 return (names
, connections
, helps
)
184 def GetPortType(self
):
185 if self
.gammudriver
in [
198 if self
.connection
== 'serial':
200 elif self
.connection
== 'bluetooth':
202 elif self
.connection
== 'irda':
204 elif self
.connection
== 'usb':
207 if self
.gammudriver
in [
217 if self
.gammudriver
in [
222 if self
.gammudriver
in [
229 if self
.gammudriver
is None:
234 def GetBluezDevices(self
):
237 return bluetooth
.discover_devices()
240 except bluetooth
.BluetoothError
:
243 def CheckDev(self
, dev
):
244 if sys
.platform
== 'win32':
249 win32file
.QueryDosDevice(dev
)
256 if dev
[0] == '/' and os
.path
.exists(dev
):
260 def AddDevs(self
, lst
, format
, limit
):
261 for x
in range(limit
):
263 if self
.CheckDev(name
):
267 def GetDevicesWindows(self
):
268 type = self
.GetPortType()
270 if type in ['serial', 'btserial', 'irdaserial', 'usbserial', None]:
271 self
.AddDevs(result
, 'COM%d', COM_PORTS
)
272 if type in ['bluetooth', None]:
273 result
+= self
.GetBluezDevices()
277 help = _('Enter device name of serial port.')
278 elif type in ['btserial', 'irdaserial', 'usbserial']:
279 help = _('Enter device name of emulated serial port.')
280 elif type == 'bluetooth':
281 help = _('Enter Bluetooth address of your phone.')
282 elif type in ['irda', 'dku']:
283 help = _('You don\'t have to enter anything for this settings.')
287 def GetDevicesUNIX(self
):
288 type = self
.GetPortType()
290 if type in ['serial', None]:
291 self
.AddDevs(result
, '/dev/cua%d', UNX_DEVICES
)
292 self
.AddDevs(result
, '/dev/ttyS%d', UNX_DEVICES
)
293 self
.AddDevs(result
, '/dev/tts/%d', UNX_DEVICES
)
294 if type in ['btserial', None]:
295 self
.AddDevs(result
, '/dev/rfcomm%d', UNX_DEVICES
)
296 if type in ['irdaserial', None]:
297 self
.AddDevs(result
, '/dev/ircomm%d', UNX_DEVICES
)
298 if type in ['usbserial', 'dku', None]:
299 self
.AddDevs(result
, '/dev/ttyACM%d', UNX_DEVICES
)
300 self
.AddDevs(result
, '/dev/ttyUSB0%d', UNX_DEVICES
)
301 self
.AddDevs(result
, '/dev/usb/tts/%d', UNX_DEVICES
)
302 self
.AddDevs(result
, '/dev/usb/acm/%d', UNX_DEVICES
)
303 self
.AddDevs(result
, '/dev/input/ttyACM%d', UNX_DEVICES
)
304 if type in ['bluetooth', None]:
305 result
+= self
.GetBluezDevices()
309 help = _('Enter device name of serial port.')
310 elif type in ['btserial', 'irdaserial']:
311 help = _('Enter device name of emulated serial port.')
312 elif type == 'bluetooth':
313 help = _('Enter Bluetooth address of your phone.')
314 elif type in ['usbserial', 'dku']:
315 help = _('Enter device name of USB port.')
316 elif type in ['irda', 'dku']:
317 help = _('You don\'t have to enter anything for this settings.')
322 def GetDevices(self
):
323 if sys
.platform
== 'win32':
324 return self
.GetDevicesWindows()
326 return self
.GetDevicesUNIX()
328 def GetGammuDrivers(self
):
333 if self
.driver
== 'at':
335 connections
.append(_('Generic AT over serial line or it\'s emulation'))
336 helps
.append(_('Select this if you have real serial port or it is emulated by phone driver (eg. virtual COM port, /dev/rfcomm, /dev/ircomm, etc.).'))
338 if self
.connection
== 'serial':
339 for rate
in [19200, 38400, 115200]:
340 names
.append('at%d' % rate
)
341 connections
.append(_('Generic AT at %d bps') % rate
)
342 helps
.append(_('Select this if your phone requires transfer speed %d bps.') % rate
)
344 elif self
.connection
== 'bluetooth':
345 names
.append('blueat')
346 connections
.append(_('AT over Bluetooth'))
347 helps
.append(_('Select this if your phone is connected over Bluetooth and you want to use native Bluetooth connection.'))
349 names
.append('bluerfat')
350 connections
.append(_('AT over Bluetooth with RF searching'))
351 helps
.append(_('Use for Bluetooth stack and 6210 / DCT4 Nokia models, which don\'t inform about Bluetooth services correctly (6310, 6310i with firmware lower than 5.50, 8910,..)'))
353 elif self
.connection
== 'irda':
354 names
.append('irdaat')
355 connections
.append(_('AT over IrDA'))
356 helps
.append(_('Select this if your phone is connected over IrDA and you want to use native IrDA connection.'))
358 elif self
.manufacturer
== 'nokia':
359 names
.append('dku2at')
360 connections
.append(_('AT over DKU2'))
361 helps
.append(_('Select this if your phone is connected using DKU2 cable.'))
363 elif self
.driver
== 'obex':
365 connections
.append(_('Generic OBEX over serial line or it\'s emulation'))
366 helps
.append(_('Select this if you have real serial port or it is emulated by phone driver (eg. virtual COM port, /dev/rfcomm, /dev/ircomm, etc.).'))
368 if self
.connection
== 'bluetooth':
369 names
.append('blueobex')
370 connections
.append(_('OBEX over Bluetooth'))
371 helps
.append(_('Select this if your phone is connected over Bluetooth and you want to use native Bluetooth connection.'))
373 names
.append('bluerfobex')
374 connections
.append(_('OBEX over Bluetooth with RF searching'))
375 helps
.append(_('Use for Bluetooth stack and 6210 / DCT4 Nokia models, which don\'t inform about Bluetooth services correctly (6310, 6310i with firmware lower than 5.50, 8910,..)'))
377 elif self
.connection
== 'irda':
378 names
.append('irdaobex')
379 connections
.append(_('OBEX over IrDA'))
380 helps
.append(_('Select this if your phone is connected over IrDA and you want to use native IrDA connection.'))
382 elif self
.driver
== 'symbian':
383 if self
.connection
== 'bluetooth':
384 names
.append('bluerfgnapbus')
385 connections
.append(_('Gnapplet over Bluetooth'))
386 helps
.append(_('Select this if your phone is connected over Bluetooth and you want to use native Bluetooth connection.'))
388 elif self
.connection
== 'irda':
389 names
.append('irdagnapbus')
390 connections
.append(_('Gnapplet over IrDA'))
391 helps
.append(_('Select this if your phone is connected over IrDA and you want to use native IrDA connection.'))
393 elif self
.driver
== 'mbus':
394 if self
.connection
== 'serial':
396 connections
.append(_('MBUS proprietary protocol'))
397 helps
.append(_('Protocol used in older Nokia phones.'))
399 elif self
.driver
== 'fbus':
400 if self
.connection
== 'serial':
402 connections
.append(_('FBUS proprietary protocol'))
403 helps
.append(_('Protocol used in Nokia phones. Please try selecting more specific options first.'))
405 # Serial should not be here, but we do not trust people they really have serial :-)
406 if self
.connection
in ['serial', 'usb']:
408 connections
.append(_('DKU5 cable'))
409 helps
.append(_('Nokia Connectivity Adapter Cable DKU-5 (original cable or compatible), for phones with USB chip like Nokia 5100.'))
411 names
.append('fbuspl2303')
412 connections
.append(_('PL2303 cable'))
413 helps
.append(_('New Nokia protocol for PL2303 USB cable (usually third party cables), for phones with USB chip like Nokia 5100.'))
416 connections
.append(_('DKU2 cable'))
417 helps
.append(_('Nokia Connectivity Cable DKU-2 (original cable or compatible), for phones without USB chip like Nokia 6230.'))
420 connections
.append(_('DLR3-3P/CA-42 cable'))
421 helps
.append(_('Nokia RS-232 Adapter Cable DLR-3P (original cable or compatible), usually with phones like Nokia 7110/6210/6310.'))
423 names
.append('fbus-nodtr')
424 connections
.append(_('FBUS proprietary protocol using ARK cable'))
425 helps
.append(_('ARK cable (third party cable) for phones not supporting AT commands like Nokia 6020.'))
427 names
.append('dku5-nodtr')
428 connections
.append(_('DKU5 phone with ARK cable'))
429 helps
.append(_('ARK cable (third party cable) for phones with USB chip like Nokia 5100.'))
431 elif self
.connection
== 'bluetooth':
432 names
.append('bluephonet')
433 connections
.append(_('Phonet over Bluetooth'))
434 helps
.append(_('Nokia protocol for Bluetooth stack with other DCT4 Nokia models.'))
436 names
.append('fbusblue')
437 connections
.append(_('FBUS over Bluetooth (emulated serial port)'))
438 helps
.append(_('Nokia protocol for Bluetooth stack with Nokia 6210.') +
440 _('Using emulated serial port.')
443 names
.append('phonetblue')
444 connections
.append(_('Phonet over Bluetooth (emulated serial port)'))
445 helps
.append(_('Nokia protocol for Bluetooth stack with other DCT4 Nokia models.') +
447 _('Using emulated serial port.')
450 names
.append('bluerffbus')
451 connections
.append(_('FBUS over Bluetooth'))
452 helps
.append(_('Nokia protocol for Bluetooth stack with Nokia 6210.'))
454 names
.append('bluerfphonet')
455 connections
.append(_('Phonet over Bluetooth with RF searching'))
456 helps
.append(_('Nokia protocol for Bluetooth stack with DCT4 Nokia models, which don\'t inform about services correctly (6310, 6310i with firmware lower than 5.50, 8910,..).'))
458 elif self
.connection
== 'irda':
459 names
.append('irdaphonet')
460 connections
.append(_('Phonet over IrDA'))
461 helps
.append(_('Nokia protocol for infrared with other Nokia models.'))
463 names
.append('fbusirda')
464 connections
.append(_('FBUS over IrDA'))
465 helps
.append(_('Nokia protocol for infrared with Nokia 6110/6130/6150.'))
467 return (names
, connections
, helps
)