Update changelog.
[wammu.git] / Wammu / SettingsStorage.py
blob24a48592112421737c385a695e37b22c2a322ebf
1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
3 '''
4 Wammu - Phone manager
5 Settings storage and configuration manager
6 '''
7 __author__ = 'Michal Čihař'
8 __email__ = 'michal@cihar.com'
9 __license__ = '''
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
19 more details.
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
24 '''
26 import sys
27 import os
28 import Wammu.Paths
29 import Wammu.Data
30 import Wammu.Utils
32 COM_PORTS = 16
33 UNX_DEVICES = 4
36 class Settings:
37 """
38 Helper class for generating settings.
39 """
40 def __init__(self):
41 self.connection = None
42 self.driver = None
43 self.manufacturer = None
44 self.name = None
45 self.port = None
46 self.gammudriver = None
47 self.position = 0
49 def GetName(self):
50 if self.name is None:
51 if self.position == 0:
52 return 'gammu'
53 else:
54 return 'gammu%d' % self.position
55 else:
56 return self.name
58 def GetGammuDriver(self):
59 return self.gammudriver
61 def GetPort(self):
62 return self.port
64 def GetConnection(self):
65 return self.connection
67 def SetPosition(self, pos):
68 self.position = pos
70 def SetConnection(self, conn):
71 self.connection = conn
73 def SetDriver(self, driver):
74 self.driver = driver
76 def SetGammuDriver(self, driver):
77 self.gammudriver = driver
79 def SetManufacturer(self, manu):
80 self.manufacturer = manu
82 def SetPort(self, port):
83 self.port = port
85 def SetName(self, name):
86 self.name = name
88 def GetSettings(self):
89 return {'Position': self.position, 'Device': self.port, 'Connection': self.gammudriver, 'Name': self.name}
91 def GetManufacturers(self):
92 names = []
93 connections = []
94 helps = []
96 names.append('any')
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).'))
104 names.append('nota')
105 connections.append(_('Alcatel phone'))
106 helps.append(_('Alcatel phone not running Symbian.'))
108 names.append('nota')
109 connections.append(_('BenQ/Siemens phone'))
110 helps.append(_('BenQ or Siemens phone not running Symbian.'))
112 names.append('nota')
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.'))
120 names.append('nota')
121 connections.append(_('Samsung phone'))
122 helps.append(_('Samsung phone not running Symbian.'))
124 names.append('nota')
125 connections.append(_('Sharp phone'))
126 helps.append(_('Sharp phone not running Symbian.'))
128 names.append('nota')
129 connections.append(_('Sony Ericsson phone'))
130 helps.append(_('Sony Ericsson phone not running Symbian.'))
132 names.append('nota')
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):
139 names.append('obex')
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.'))
143 else:
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):
152 names.append('fbus')
153 connections.append(_('Nokia proprietary protocol'))
154 helps.append(_('Nokia proprietary protocol FBUS.'))
155 if self.connection == 'serial':
156 names.append('mbus')
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):
161 names.append('at')
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.'))
165 else:
166 helps.append(_('Good choice for most phones except Nokia and Symbian based. Provides access to most phone features.'))
168 def GetDrivers(self):
169 names = []
170 connections = []
171 helps = []
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 [
194 'mbus',
195 'fbus',
196 'dlr3',
197 'at',
198 'at19200',
199 'at38400',
200 'at115200',
201 'obex',
202 'phonetblue',
203 'fbusblue',
204 'fbus-nodtr',
205 'dku5-nodtr']:
206 if self.connection == 'serial':
207 return 'serial'
208 elif self.connection == 'bluetooth':
209 return 'btserial'
210 elif self.connection == 'irda':
211 return 'irdaserial'
212 elif self.connection == 'usb':
213 return 'usbserial'
214 return 'serial'
215 if self.gammudriver in [
216 'blueat',
217 'bluerfat',
218 'blueobex',
219 'bluerfobex',
220 'bluerfgnapbus',
221 'bluerffbus',
222 'bluephonet',
223 'bluerfphonet']:
224 return 'bluetooth'
225 if self.gammudriver in [
226 'dku2',
227 'dku5',
228 'dku2at']:
229 return 'dku'
230 if self.gammudriver in [
231 'irdaat',
232 'irdaobex',
233 'irdagnapbus',
234 'fbusirda',
235 'irdaphonet']:
236 return 'irda'
237 if self.gammudriver is None:
238 return None
239 # fallback
240 return None
242 def GetBluezDevices(self):
243 try:
244 import bluetooth
245 return bluetooth.discover_devices()
246 except ImportError:
247 return []
248 except bluetooth.BluetoothError:
249 return []
250 except IOError:
251 return []
253 def CheckDev(self, dev):
254 res = Wammu.Utils.CheckDeviceNode(dev)
255 if res[0] == 0:
256 return True
257 else:
258 return False
260 def AddDevs(self, lst, format, limit):
261 for x in range(limit):
262 name = format % x
263 if self.CheckDev(name):
264 lst.append(name)
267 def GetDevicesWindows(self):
268 type = self.GetPortType()
269 result = []
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()
275 help = ''
276 if type == 'serial':
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.')
285 return result, help
287 def GetDevicesUNIX(self):
288 type = self.GetPortType()
289 result = []
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()
307 help = ''
308 if type == 'serial':
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.')
319 return result, help
322 def GetDevices(self):
323 if sys.platform == 'win32':
324 return self.GetDevicesWindows()
325 else:
326 return self.GetDevicesUNIX()
328 def GetGammuDrivers(self):
329 names = []
330 connections = []
331 helps = []
333 if self.driver == 'at':
334 if self.connection != 'bluetooth':
335 names.append('at')
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.'))
350 names.append('at')
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':
369 names.append('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':
400 names.append('mbus')
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':
406 names.append('fbus')
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']:
412 names.append('dku5')
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.'))
420 names.append('dku2')
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.'))
424 names.append('dlr3')
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.') +
444 ' ' +
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.') +
451 ' ' +
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)