Improvements in guided wizard to make it easier to use.
[wammu.git] / Wammu / SettingsStorage.py
blob6a3d7486c582e7831be91a3c221486e32b3a45ff
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 (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
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
31 COM_PORTS = 16
32 UNX_DEVICES = 4
35 class Settings:
36 """
37 Helper class for generating settings.
38 """
39 def __init__(self):
40 self.connection = None
41 self.driver = None
42 self.manufacturer = None
43 self.name = None
44 self.port = None
45 self.gammudriver = None
46 self.position = 0
48 def GetName(self):
49 if self.name is None:
50 if self.position == 0:
51 return 'gammu'
52 else:
53 return 'gammu%d' % self.position
54 else:
55 return self.name
57 def GetGammuDriver(self):
58 return self.gammudriver
60 def GetPort(self):
61 return self.port
63 def SetPosition(self, pos):
64 self.position = pos
66 def SetConnection(self, conn):
67 self.connection = conn
69 def SetDriver(self, driver):
70 self.driver = driver
72 def SetGammuDriver(self, driver):
73 self.gammudriver = driver
75 def SetManufacturer(self, manu):
76 self.manufacturer = manu
78 def SetPort(self, port):
79 self.port = port
81 def SetName(self, name):
82 self.name = name
84 def GetSettings(self):
85 return {'Position': self.position, 'Device': self.port, 'Connection': self.gammudriver, 'Name': self.name}
87 def GetManufacturers(self):
88 names = []
89 connections = []
90 helps = []
92 names.append('any')
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).'))
100 names.append('nota')
101 connections.append(_('Alcatel phone'))
102 helps.append(_('Alcatel phone not running Symbian.'))
104 names.append('nota')
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.'))
112 names.append('nota')
113 connections.append(_('Samsung phone'))
114 helps.append(_('Samsung phone not running Symbian.'))
116 names.append('nota')
117 connections.append(_('Sharp phone'))
118 helps.append(_('Sharp phone not running Symbian.'))
120 names.append('nota')
121 connections.append(_('Sony Ericsson phone'))
122 helps.append(_('Sony Ericsson phone not running Symbian.'))
124 names.append('nota')
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):
131 names.append('obex')
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.'))
135 else:
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):
144 names.append('fbus')
145 connections.append(_('Nokia proprietary protocol'))
146 helps.append(_('Nokia proprietary protocol FBUS.'))
147 if self.connection == 'serial':
148 names.append('mbus')
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):
153 names.append('at')
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.'))
157 else:
158 helps.append(_('Good choice for most phones except Nokia and Symbian based. Provides access to most phone features.'))
160 def GetDrivers(self):
161 names = []
162 connections = []
163 helps = []
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 [
186 'mbus',
187 'fbus',
188 'dlr3',
189 'at',
190 'at19200',
191 'at38400',
192 'at115200',
193 'obex',
194 'phonetblue',
195 'fbusblue',
196 'fbus-nodtr',
197 'dku5-nodtr']:
198 if self.connection == 'serial':
199 return 'serial'
200 elif self.connection == 'bluetooth':
201 return 'btserial'
202 elif self.connection == 'irda':
203 return 'irdaserial'
204 elif self.connection == 'usb':
205 return 'usbserial'
206 return 'serial'
207 if self.gammudriver in [
208 'blueat',
209 'bluerfat',
210 'blueobex',
211 'bluerfobex',
212 'bluerfgnapbus',
213 'bluerffbus',
214 'bluephonet',
215 'bluerfphonet']:
216 return 'bluetooth'
217 if self.gammudriver in [
218 'dku2',
219 'dku5',
220 'dku2at']:
221 return 'dku'
222 if self.gammudriver in [
223 'irdaat',
224 'irdaobex',
225 'irdagnapbus',
226 'fbusirda',
227 'irdaphonet']:
228 return 'irda'
229 if self.gammudriver is None:
230 return None
231 # fallback
232 return None
234 def GetBluezDevices(self):
235 try:
236 import bluetooth
237 return bluetooth.discover_devices()
238 except ImportError:
239 return []
240 except bluetooth.BluetoothError:
241 return []
243 def CheckDev(self, dev):
244 if sys.platform == 'win32':
245 try:
246 import win32file
247 if dev[:3] == 'COM':
248 try:
249 win32file.QueryDosDevice(dev)
250 return True
251 except:
252 pass
253 except ImportError:
254 return True
255 else:
256 if dev[0] == '/' and os.path.exists(dev):
257 return True
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 names.append('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':
364 names.append('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':
395 names.append('mbus')
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':
401 names.append('fbus')
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']:
407 names.append('dku5')
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.'))
415 names.append('dku2')
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.'))
419 names.append('dlr3')
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.') +
439 ' ' +
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.') +
446 ' ' +
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)