Prepare for release, mention why there is still no Windows version.
[wammu.git] / Wammu / SettingsStorage.py
blob47a9ee8b8eb0f54aa9ef34ff6197d9e9815519df
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 - 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
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('nokia')
113 connections.append(_('Nokia phone'))
114 helps.append(_('Nokia phone not running Symbian.'))
116 names.append('nota')
117 connections.append(_('Samsung phone'))
118 helps.append(_('Samsung phone not running Symbian.'))
120 names.append('nota')
121 connections.append(_('Sharp phone'))
122 helps.append(_('Sharp phone not running Symbian.'))
124 names.append('nota')
125 connections.append(_('Sony Ericsson phone'))
126 helps.append(_('Sony Ericsson phone not running Symbian.'))
128 names.append('nota')
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):
135 names.append('obex')
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.'))
139 else:
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):
148 names.append('fbus')
149 connections.append(_('Nokia proprietary protocol'))
150 helps.append(_('Nokia proprietary protocol FBUS.'))
151 if self.connection == 'serial':
152 names.append('mbus')
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):
157 names.append('at')
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.'))
161 else:
162 helps.append(_('Good choice for most phones except Nokia and Symbian based. Provides access to most phone features.'))
164 def GetDrivers(self):
165 names = []
166 connections = []
167 helps = []
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 [
190 'mbus',
191 'fbus',
192 'dlr3',
193 'at',
194 'at19200',
195 'at38400',
196 'at115200',
197 'obex',
198 'phonetblue',
199 'fbusblue',
200 'fbus-nodtr',
201 'dku5-nodtr']:
202 if self.connection == 'serial':
203 return 'serial'
204 elif self.connection == 'bluetooth':
205 return 'btserial'
206 elif self.connection == 'irda':
207 return 'irdaserial'
208 elif self.connection == 'usb':
209 return 'usbserial'
210 return 'serial'
211 if self.gammudriver in [
212 'blueat',
213 'bluerfat',
214 'blueobex',
215 'bluerfobex',
216 'bluerfgnapbus',
217 'bluerffbus',
218 'bluephonet',
219 'bluerfphonet']:
220 return 'bluetooth'
221 if self.gammudriver in [
222 'dku2',
223 'dku5',
224 'dku2at']:
225 return 'dku'
226 if self.gammudriver in [
227 'irdaat',
228 'irdaobex',
229 'irdagnapbus',
230 'fbusirda',
231 'irdaphonet']:
232 return 'irda'
233 if self.gammudriver is None:
234 return None
235 # fallback
236 return None
238 def GetBluezDevices(self):
239 try:
240 import bluetooth
241 return bluetooth.discover_devices()
242 except ImportError:
243 return []
244 except bluetooth.BluetoothError:
245 return []
246 except IOError:
247 return []
249 def CheckDev(self, dev):
250 res = Wammu.Utils.CheckDeviceNode(dev)
251 if res[0] == 0:
252 return True
253 else:
254 return False
256 def AddDevs(self, lst, format, limit):
257 for x in range(limit):
258 name = format % x
259 if self.CheckDev(name):
260 lst.append(name)
263 def GetDevicesWindows(self):
264 type = self.GetPortType()
265 result = []
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()
271 help = ''
272 if type == 'serial':
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.')
281 return result, help
283 def GetDevicesUNIX(self):
284 type = self.GetPortType()
285 result = []
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()
303 help = ''
304 if type == 'serial':
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.')
315 return result, help
318 def GetDevices(self):
319 if sys.platform == 'win32':
320 return self.GetDevicesWindows()
321 else:
322 return self.GetDevicesUNIX()
324 def GetGammuDrivers(self):
325 names = []
326 connections = []
327 helps = []
329 if self.driver == 'at':
330 names.append('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':
360 names.append('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':
391 names.append('mbus')
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':
397 names.append('fbus')
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']:
403 names.append('dku5')
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.'))
411 names.append('dku2')
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.'))
415 names.append('dlr3')
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.') +
435 ' ' +
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.') +
442 ' ' +
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)