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 © 2003 - 2009 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
38 Helper class for generating settings.
41 self
.connection
= None
43 self
.manufacturer
= None
46 self
.gammudriver
= None
51 if self
.position
== 0:
54 return 'gammu%d' % self
.position
58 def GetGammuDriver(self
):
59 return self
.gammudriver
64 def GetConnection(self
):
65 return self
.connection
67 def SetPosition(self
, pos
):
70 def SetConnection(self
, conn
):
71 self
.connection
= conn
73 def SetDriver(self
, driver
):
76 def SetGammuDriver(self
, driver
):
77 self
.gammudriver
= driver
79 def SetManufacturer(self
, manu
):
80 self
.manufacturer
= manu
82 def SetPort(self
, port
):
85 def SetName(self
, name
):
88 def GetSettings(self
):
89 return {'Position': self
.position
, 'Device': self
.port
, 'Connection': self
.gammudriver
, 'Name': self
.name
}
91 def GetManufacturers(self
):
97 connections
.append(_('I don\'t know'))
98 helps
.append(_('Select this option only if really necessary. You will be provided with too much options in next step.'))
100 names
.append('symbian')
101 connections
.append(_('Symbian based phone'))
102 helps
.append(_('Go on if your phone uses Symbian OS (regardless of manufacturer).'))
105 connections
.append(_('Alcatel phone'))
106 helps
.append(_('Alcatel phone not running Symbian.'))
109 connections
.append(_('BenQ/Siemens phone'))
110 helps
.append(_('BenQ or Siemens phone not running Symbian.'))
113 connections
.append(_('Motorola phone'))
114 helps
.append(_('Motorola phone not running Symbian.'))
116 names
.append('nokia')
117 connections
.append(_('Nokia phone'))
118 helps
.append(_('Nokia phone not running Symbian.'))
121 connections
.append(_('Samsung phone'))
122 helps
.append(_('Samsung phone not running Symbian.'))
125 connections
.append(_('Sharp phone'))
126 helps
.append(_('Sharp phone not running Symbian.'))
129 connections
.append(_('Sony Ericsson phone'))
130 helps
.append(_('Sony Ericsson phone not running Symbian.'))
133 connections
.append(_('None of the above'))
134 helps
.append(_('Select this option if nothing above matches.'))
136 return (names
, connections
, helps
)
138 def AddOBEX(self
, names
, connections
, helps
):
140 connections
.append(_('OBEX and IrMC protocols'))
141 if self
.manufacturer
in ['symbian', 'nokia']:
142 helps
.append(_('Standard access to filesystem. Not a good choice for Nokia if you want to access data.'))
144 helps
.append(_('Standard access to filesystem and sometimes also to phone data. Good choice for recent phones.'))
146 def AddSymbian(self
, names
, connections
, helps
):
147 names
.append('symbian')
148 connections
.append(_('Symbian using Gnapplet'))
149 helps
.append(_('You have to install Gnapplet into phone before using this connection. You can find it in Gammu sources.'))
151 def AddNokia(self
, names
, connections
, helps
):
153 connections
.append(_('Nokia proprietary protocol'))
154 helps
.append(_('Nokia proprietary protocol FBUS.'))
155 if self
.connection
== 'serial':
157 connections
.append(_('Nokia proprietary service protocol'))
158 helps
.append(_('Nokia proprietary protocol MBUS. Older version, use FBUS if possible.'))
160 def AddAT(self
, names
, connections
, helps
):
162 connections
.append(_('AT based'))
163 if self
.manufacturer
in ['symbian', 'nokia']:
164 helps
.append(_('This provides minimal access to phone features. It is recommended to use other connection type.'))
166 helps
.append(_('Good choice for most phones except Nokia and Symbian based. Provides access to most phone features.'))
168 def GetDrivers(self
):
173 if self
.manufacturer
== 'nokia':
174 self
.AddNokia(names
, connections
, helps
)
175 self
.AddAT(names
, connections
, helps
)
176 self
.AddOBEX(names
, connections
, helps
)
177 elif self
.manufacturer
== 'symbian':
178 self
.AddSymbian(names
, connections
, helps
)
179 self
.AddAT(names
, connections
, helps
)
180 self
.AddOBEX(names
, connections
, helps
)
181 elif self
.manufacturer
== 'nota':
182 self
.AddAT(names
, connections
, helps
)
183 self
.AddOBEX(names
, connections
, helps
)
184 elif self
.manufacturer
== 'any':
185 self
.AddAT(names
, connections
, helps
)
186 self
.AddOBEX(names
, connections
, helps
)
187 self
.AddNokia(names
, connections
, helps
)
188 self
.AddSymbian(names
, connections
, helps
)
190 return (names
, connections
, helps
)
192 def GetPortType(self
):
193 if self
.gammudriver
in [
206 if self
.connection
== 'serial':
208 elif self
.connection
== 'bluetooth':
210 elif self
.connection
== 'irda':
212 elif self
.connection
== 'usb':
215 if self
.gammudriver
in [
225 if self
.gammudriver
in [
230 if self
.gammudriver
in [
237 if self
.gammudriver
is None:
242 def GetBluezDevices(self
):
245 return bluetooth
.discover_devices()
248 except bluetooth
.BluetoothError
:
253 def CheckDev(self
, dev
):
254 res
= Wammu
.Utils
.CheckDeviceNode(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':
334 if self
.connection
!= 'bluetooth':
336 connections
.append(_('Generic AT over serial line or it\'s emulation'))
337 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.).'))
339 if self
.connection
== 'serial':
340 for rate
in [19200, 38400, 115200]:
341 names
.append('at%d' % rate
)
342 connections
.append(_('Generic AT at %d bps') % rate
)
343 helps
.append(_('Select this if your phone requires transfer speed %d bps.') % rate
)
345 elif self
.connection
== 'bluetooth':
346 names
.append('blueat')
347 connections
.append(_('AT over Bluetooth'))
348 helps
.append(_('Select this if your phone is connected over Bluetooth and you want to use native Bluetooth connection.'))
351 connections
.append(_('Generic AT over serial line or it\'s emulation'))
352 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.).'))
354 names
.append('bluerfat')
355 connections
.append(_('AT over Bluetooth with RF searching'))
356 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,..)'))
358 elif self
.connection
== 'irda':
359 names
.append('irdaat')
360 connections
.append(_('AT over IrDA'))
361 helps
.append(_('Select this if your phone is connected over IrDA and you want to use native IrDA connection.'))
363 elif self
.manufacturer
== 'nokia':
364 names
.append('dku2at')
365 connections
.append(_('AT over DKU2'))
366 helps
.append(_('Select this if your phone is connected using DKU2 cable.'))
368 elif self
.driver
== 'obex':
370 connections
.append(_('Generic OBEX over serial line or it\'s emulation'))
371 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.).'))
373 if self
.connection
== 'bluetooth':
374 names
.append('blueobex')
375 connections
.append(_('OBEX over Bluetooth'))
376 helps
.append(_('Select this if your phone is connected over Bluetooth and you want to use native Bluetooth connection.'))
378 names
.append('bluerfobex')
379 connections
.append(_('OBEX over Bluetooth with RF searching'))
380 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,..)'))
382 elif self
.connection
== 'irda':
383 names
.append('irdaobex')
384 connections
.append(_('OBEX over IrDA'))
385 helps
.append(_('Select this if your phone is connected over IrDA and you want to use native IrDA connection.'))
387 elif self
.driver
== 'symbian':
388 if self
.connection
== 'bluetooth':
389 names
.append('bluerfgnapbus')
390 connections
.append(_('Gnapplet over Bluetooth'))
391 helps
.append(_('Select this if your phone is connected over Bluetooth and you want to use native Bluetooth connection.'))
393 elif self
.connection
== 'irda':
394 names
.append('irdagnapbus')
395 connections
.append(_('Gnapplet over IrDA'))
396 helps
.append(_('Select this if your phone is connected over IrDA and you want to use native IrDA connection.'))
398 elif self
.driver
== 'mbus':
399 if self
.connection
== 'serial':
401 connections
.append(_('MBUS proprietary protocol'))
402 helps
.append(_('Protocol used in older Nokia phones.'))
404 elif self
.driver
== 'fbus':
405 if self
.connection
== 'serial':
407 connections
.append(_('FBUS proprietary protocol'))
408 helps
.append(_('Protocol used in Nokia phones. Please try selecting more specific options first.'))
410 # Serial should not be here, but we do not trust people they really have serial :-)
411 if self
.connection
in ['serial', 'usb']:
413 connections
.append(_('DKU5 cable'))
414 helps
.append(_('Nokia Connectivity Adapter Cable DKU-5 (original cable or compatible), for phones with USB chip like Nokia 5100.'))
416 names
.append('fbuspl2303')
417 connections
.append(_('PL2303 cable'))
418 helps
.append(_('New Nokia protocol for PL2303 USB cable (usually third party cables), for phones with USB chip like Nokia 5100.'))
421 connections
.append(_('DKU2 cable'))
422 helps
.append(_('Nokia Connectivity Cable DKU-2 (original cable or compatible), for phones without USB chip like Nokia 6230.'))
425 connections
.append(_('DLR3-3P/CA-42 cable'))
426 helps
.append(_('Nokia RS-232 Adapter Cable DLR-3P (original cable or compatible), usually with phones like Nokia 7110/6210/6310.'))
428 names
.append('fbus-nodtr')
429 connections
.append(_('FBUS proprietary protocol using ARK cable'))
430 helps
.append(_('ARK cable (third party cable) for phones not supporting AT commands like Nokia 6020.'))
432 names
.append('dku5-nodtr')
433 connections
.append(_('DKU5 phone with ARK cable'))
434 helps
.append(_('ARK cable (third party cable) for phones with USB chip like Nokia 5100.'))
436 elif self
.connection
== 'bluetooth':
437 names
.append('bluephonet')
438 connections
.append(_('Phonet over Bluetooth'))
439 helps
.append(_('Nokia protocol for Bluetooth stack with other DCT4 Nokia models.'))
441 names
.append('fbusblue')
442 connections
.append(_('FBUS over Bluetooth (emulated serial port)'))
443 helps
.append(_('Nokia protocol for Bluetooth stack with Nokia 6210.') +
445 _('Using emulated serial port.')
448 names
.append('phonetblue')
449 connections
.append(_('Phonet over Bluetooth (emulated serial port)'))
450 helps
.append(_('Nokia protocol for Bluetooth stack with other DCT4 Nokia models.') +
452 _('Using emulated serial port.')
455 names
.append('bluerffbus')
456 connections
.append(_('FBUS over Bluetooth'))
457 helps
.append(_('Nokia protocol for Bluetooth stack with Nokia 6210.'))
459 names
.append('bluerfphonet')
460 connections
.append(_('Phonet over Bluetooth with RF searching'))
461 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,..).'))
463 elif self
.connection
== 'irda':
464 names
.append('irdaphonet')
465 connections
.append(_('Phonet over IrDA'))
466 helps
.append(_('Nokia protocol for infrared with other Nokia models.'))
468 names
.append('fbusirda')
469 connections
.append(_('FBUS over IrDA'))
470 helps
.append(_('Nokia protocol for infrared with Nokia 6110/6130/6150.'))
472 return (names
, connections
, helps
)