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 - 2008 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.'))
112 names
.append('nokia')
113 connections
.append(_('Nokia phone'))
114 helps
.append(_('Nokia phone not running Symbian.'))
117 connections
.append(_('Samsung phone'))
118 helps
.append(_('Samsung phone not running Symbian.'))
121 connections
.append(_('Sharp phone'))
122 helps
.append(_('Sharp phone not running Symbian.'))
125 connections
.append(_('Sony Ericsson phone'))
126 helps
.append(_('Sony Ericsson phone not running Symbian.'))
129 connections
.append(_('None of the above'))
130 helps
.append(_('Select this option if nothing above matches.'))
132 return (names
, connections
, helps
)
134 def AddOBEX(self
, names
, connections
, helps
):
136 connections
.append(_('OBEX and IrMC protocols'))
137 if self
.manufacturer
in ['symbian', 'nokia']:
138 helps
.append(_('Standard access to filesystem. Not a good choice for Nokia if you want to access data.'))
140 helps
.append(_('Standard access to filesystem and sometimes also to phone data. Good choice for recent phones.'))
142 def AddSymbian(self
, names
, connections
, helps
):
143 names
.append('symbian')
144 connections
.append(_('Symbian using Gnapplet'))
145 helps
.append(_('You have to install Gnapplet into phone before using this connection. You can find it in Gammu sources.'))
147 def AddNokia(self
, names
, connections
, helps
):
149 connections
.append(_('Nokia proprietary protocol'))
150 helps
.append(_('Nokia proprietary protocol FBUS.'))
151 if self
.connection
== 'serial':
153 connections
.append(_('Nokia proprietary service protocol'))
154 helps
.append(_('Nokia proprietary protocol MBUS. Older version, use FBUS if possible.'))
156 def AddAT(self
, names
, connections
, helps
):
158 connections
.append(_('AT based'))
159 if self
.manufacturer
in ['symbian', 'nokia']:
160 helps
.append(_('This provides minimal access to phone features. It is recommended to use other connection type.'))
162 helps
.append(_('Good choice for most phones except Nokia and Symbian based. Provides access to most phone features.'))
164 def GetDrivers(self
):
169 if self
.manufacturer
== 'nokia':
170 self
.AddNokia(names
, connections
, helps
)
171 self
.AddAT(names
, connections
, helps
)
172 self
.AddOBEX(names
, connections
, helps
)
173 elif self
.manufacturer
== 'symbian':
174 self
.AddSymbian(names
, connections
, helps
)
175 self
.AddAT(names
, connections
, helps
)
176 self
.AddOBEX(names
, connections
, helps
)
177 elif self
.manufacturer
== 'nota':
178 self
.AddAT(names
, connections
, helps
)
179 self
.AddOBEX(names
, connections
, helps
)
180 elif self
.manufacturer
== 'any':
181 self
.AddAT(names
, connections
, helps
)
182 self
.AddOBEX(names
, connections
, helps
)
183 self
.AddNokia(names
, connections
, helps
)
184 self
.AddSymbian(names
, connections
, helps
)
186 return (names
, connections
, helps
)
188 def GetPortType(self
):
189 if self
.gammudriver
in [
202 if self
.connection
== 'serial':
204 elif self
.connection
== 'bluetooth':
206 elif self
.connection
== 'irda':
208 elif self
.connection
== 'usb':
211 if self
.gammudriver
in [
221 if self
.gammudriver
in [
226 if self
.gammudriver
in [
233 if self
.gammudriver
is None:
238 def GetBluezDevices(self
):
241 return bluetooth
.discover_devices()
244 except bluetooth
.BluetoothError
:
249 def CheckDev(self
, dev
):
250 res
= Wammu
.Utils
.CheckDeviceNode(dev
)
256 def AddDevs(self
, lst
, format
, limit
):
257 for x
in range(limit
):
259 if self
.CheckDev(name
):
263 def GetDevicesWindows(self
):
264 type = self
.GetPortType()
266 if type in ['serial', 'btserial', 'irdaserial', 'usbserial', None]:
267 self
.AddDevs(result
, 'COM%d', COM_PORTS
)
268 if type in ['bluetooth', None]:
269 result
+= self
.GetBluezDevices()
273 help = _('Enter device name of serial port.')
274 elif type in ['btserial', 'irdaserial', 'usbserial']:
275 help = _('Enter device name of emulated serial port.')
276 elif type == 'bluetooth':
277 help = _('Enter Bluetooth address of your phone.')
278 elif type in ['irda', 'dku']:
279 help = _('You don\'t have to enter anything for this settings.')
283 def GetDevicesUNIX(self
):
284 type = self
.GetPortType()
286 if type in ['serial', None]:
287 self
.AddDevs(result
, '/dev/cua%d', UNX_DEVICES
)
288 self
.AddDevs(result
, '/dev/ttyS%d', UNX_DEVICES
)
289 self
.AddDevs(result
, '/dev/tts/%d', UNX_DEVICES
)
290 if type in ['btserial', None]:
291 self
.AddDevs(result
, '/dev/rfcomm%d', UNX_DEVICES
)
292 if type in ['irdaserial', None]:
293 self
.AddDevs(result
, '/dev/ircomm%d', UNX_DEVICES
)
294 if type in ['usbserial', 'dku', None]:
295 self
.AddDevs(result
, '/dev/ttyACM%d', UNX_DEVICES
)
296 self
.AddDevs(result
, '/dev/ttyUSB0%d', UNX_DEVICES
)
297 self
.AddDevs(result
, '/dev/usb/tts/%d', UNX_DEVICES
)
298 self
.AddDevs(result
, '/dev/usb/acm/%d', UNX_DEVICES
)
299 self
.AddDevs(result
, '/dev/input/ttyACM%d', UNX_DEVICES
)
300 if type in ['bluetooth', None]:
301 result
+= self
.GetBluezDevices()
305 help = _('Enter device name of serial port.')
306 elif type in ['btserial', 'irdaserial']:
307 help = _('Enter device name of emulated serial port.')
308 elif type == 'bluetooth':
309 help = _('Enter Bluetooth address of your phone.')
310 elif type in ['usbserial', 'dku']:
311 help = _('Enter device name of USB port.')
312 elif type in ['irda', 'dku']:
313 help = _('You don\'t have to enter anything for this settings.')
318 def GetDevices(self
):
319 if sys
.platform
== 'win32':
320 return self
.GetDevicesWindows()
322 return self
.GetDevicesUNIX()
324 def GetGammuDrivers(self
):
329 if self
.driver
== 'at':
331 connections
.append(_('Generic AT over serial line or it\'s emulation'))
332 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.).'))
334 if self
.connection
== 'serial':
335 for rate
in [19200, 38400, 115200]:
336 names
.append('at%d' % rate
)
337 connections
.append(_('Generic AT at %d bps') % rate
)
338 helps
.append(_('Select this if your phone requires transfer speed %d bps.') % rate
)
340 elif self
.connection
== 'bluetooth':
341 names
.append('blueat')
342 connections
.append(_('AT over Bluetooth'))
343 helps
.append(_('Select this if your phone is connected over Bluetooth and you want to use native Bluetooth connection.'))
345 names
.append('bluerfat')
346 connections
.append(_('AT over Bluetooth with RF searching'))
347 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,..)'))
349 elif self
.connection
== 'irda':
350 names
.append('irdaat')
351 connections
.append(_('AT over IrDA'))
352 helps
.append(_('Select this if your phone is connected over IrDA and you want to use native IrDA connection.'))
354 elif self
.manufacturer
== 'nokia':
355 names
.append('dku2at')
356 connections
.append(_('AT over DKU2'))
357 helps
.append(_('Select this if your phone is connected using DKU2 cable.'))
359 elif self
.driver
== 'obex':
361 connections
.append(_('Generic OBEX over serial line or it\'s emulation'))
362 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.).'))
364 if self
.connection
== 'bluetooth':
365 names
.append('blueobex')
366 connections
.append(_('OBEX over Bluetooth'))
367 helps
.append(_('Select this if your phone is connected over Bluetooth and you want to use native Bluetooth connection.'))
369 names
.append('bluerfobex')
370 connections
.append(_('OBEX over Bluetooth with RF searching'))
371 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,..)'))
373 elif self
.connection
== 'irda':
374 names
.append('irdaobex')
375 connections
.append(_('OBEX over IrDA'))
376 helps
.append(_('Select this if your phone is connected over IrDA and you want to use native IrDA connection.'))
378 elif self
.driver
== 'symbian':
379 if self
.connection
== 'bluetooth':
380 names
.append('bluerfgnapbus')
381 connections
.append(_('Gnapplet over Bluetooth'))
382 helps
.append(_('Select this if your phone is connected over Bluetooth and you want to use native Bluetooth connection.'))
384 elif self
.connection
== 'irda':
385 names
.append('irdagnapbus')
386 connections
.append(_('Gnapplet over IrDA'))
387 helps
.append(_('Select this if your phone is connected over IrDA and you want to use native IrDA connection.'))
389 elif self
.driver
== 'mbus':
390 if self
.connection
== 'serial':
392 connections
.append(_('MBUS proprietary protocol'))
393 helps
.append(_('Protocol used in older Nokia phones.'))
395 elif self
.driver
== 'fbus':
396 if self
.connection
== 'serial':
398 connections
.append(_('FBUS proprietary protocol'))
399 helps
.append(_('Protocol used in Nokia phones. Please try selecting more specific options first.'))
401 # Serial should not be here, but we do not trust people they really have serial :-)
402 if self
.connection
in ['serial', 'usb']:
404 connections
.append(_('DKU5 cable'))
405 helps
.append(_('Nokia Connectivity Adapter Cable DKU-5 (original cable or compatible), for phones with USB chip like Nokia 5100.'))
407 names
.append('fbuspl2303')
408 connections
.append(_('PL2303 cable'))
409 helps
.append(_('New Nokia protocol for PL2303 USB cable (usually third party cables), for phones with USB chip like Nokia 5100.'))
412 connections
.append(_('DKU2 cable'))
413 helps
.append(_('Nokia Connectivity Cable DKU-2 (original cable or compatible), for phones without USB chip like Nokia 6230.'))
416 connections
.append(_('DLR3-3P/CA-42 cable'))
417 helps
.append(_('Nokia RS-232 Adapter Cable DLR-3P (original cable or compatible), usually with phones like Nokia 7110/6210/6310.'))
419 names
.append('fbus-nodtr')
420 connections
.append(_('FBUS proprietary protocol using ARK cable'))
421 helps
.append(_('ARK cable (third party cable) for phones not supporting AT commands like Nokia 6020.'))
423 names
.append('dku5-nodtr')
424 connections
.append(_('DKU5 phone with ARK cable'))
425 helps
.append(_('ARK cable (third party cable) for phones with USB chip like Nokia 5100.'))
427 elif self
.connection
== 'bluetooth':
428 names
.append('bluephonet')
429 connections
.append(_('Phonet over Bluetooth'))
430 helps
.append(_('Nokia protocol for Bluetooth stack with other DCT4 Nokia models.'))
432 names
.append('fbusblue')
433 connections
.append(_('FBUS over Bluetooth (emulated serial port)'))
434 helps
.append(_('Nokia protocol for Bluetooth stack with Nokia 6210.') +
436 _('Using emulated serial port.')
439 names
.append('phonetblue')
440 connections
.append(_('Phonet over Bluetooth (emulated serial port)'))
441 helps
.append(_('Nokia protocol for Bluetooth stack with other DCT4 Nokia models.') +
443 _('Using emulated serial port.')
446 names
.append('bluerffbus')
447 connections
.append(_('FBUS over Bluetooth'))
448 helps
.append(_('Nokia protocol for Bluetooth stack with Nokia 6210.'))
450 names
.append('bluerfphonet')
451 connections
.append(_('Phonet over Bluetooth with RF searching'))
452 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,..).'))
454 elif self
.connection
== 'irda':
455 names
.append('irdaphonet')
456 connections
.append(_('Phonet over IrDA'))
457 helps
.append(_('Nokia protocol for infrared with other Nokia models.'))
459 names
.append('fbusirda')
460 connections
.append(_('FBUS over IrDA'))
461 helps
.append(_('Nokia protocol for infrared with Nokia 6110/6130/6150.'))
463 return (names
, connections
, helps
)