Package phones :: Module com_samsungspha790
[hide private]
[frames] | no frames]

Source Code for Module phones.com_samsungspha790

  1  ### BITPIM 
  2  ### 
  3  ### Copyright (C) 2006 Joe Pham <djpham@bitpim.org> 
  4  ### 
  5  ### This program is free software; you can redistribute it and/or modify 
  6  ### it under the terms of the BitPim license as detailed in the LICENSE file. 
  7  ### 
  8  ### $Id: com_samsungspha790.py 4365 2007-08-17 21:11:59Z djpham $ 
  9   
 10  """Communicate with a Samsung SPH-A790""" 
 11  # System modules 
 12  import sha 
 13   
 14  # BitPim modules 
 15  import common 
 16  import com_samsung_packet 
 17  import p_samsungspha790 
 18   
 19   
 20  parentphone=com_samsung_packet.Phone 
21 -class Phone(parentphone):
22 desc='SPH-A790' 23 protocolclass=p_samsungspha790 24 serialsname='spha790' 25 26 builtin_ringtones=( 27 (0, ['Default Tone']), 28 (68, ['Tone %d'%x for x in range(1, 10)]), 29 (95, ['Ring %d'%x for x in range(1, 16)]), 30 (110, ['Melody %d'%x for x in range(1, 21)]), 31 ) 32 builtin_pictures=( 33 (1, ['People %d'%x for x in range(1, 22)]), 34 (23, ['Animal %d'%x for x in range(1, 16)]), 35 (38, ['Other %d'%x for x in range(1, 10)]), 36 ) 37 38 camera_picture_index=100 # starting index of camera picture 39
40 - def getfundamentals(self, results):
41 42 """Gets information fundamental to interopating with the phone and UI. 43 44 Currently this is: 45 46 - 'uniqueserial' a unique serial number representing the phone 47 - 'groups' the phonebook groups 48 - 'wallpaper-index' map index numbers to names 49 - 'ringtone-index' map index numbers to ringtone names 50 51 This method is called before we read the phonebook data or before we 52 write phonebook data. 53 """ 54 self.setmode(self.MODEPHONEBOOK) 55 56 # use a hash of ESN and other stuff (being paranoid) 57 self.log("Retrieving fundamental phone information") 58 self.log("Reading phone serial number") 59 results['uniqueserial']=sha.new(self.get_esn()).hexdigest() 60 61 # now read groups 62 self.log("Reading group information") 63 results['groups']=self.read_groups() 64 65 # getting rintone-index 66 results['ringtone-index']=self._get_builtin_index(self.builtin_ringtones) 67 68 # getting wallpaper-index 69 results['wallpaper-index']=self.get_wallpaper_index() 70 71 self.setmode(self.MODEMODEM) 72 self.log("Fundamentals retrieved") 73 74 return results
75
76 - def _get_builtin_index(self, builtin_list):
77 _res={} 78 for _starting_idx,_list in builtin_list: 79 _idx=_starting_idx 80 for _entry in _list: 81 _res[_idx]={ 'name': _entry, 82 'origin': 'builtin' } 83 _idx+=1 84 return _res
85
86 - def read_groups(self):
87 g={} 88 # Don't crash if phone doesn't accept #PMODE=1 (Canadian phones) 89 try: 90 self.setmode(self.MODEPHONEBOOK) 91 except: 92 return g 93 req=self.protocolclass.groupnamerequest() 94 for i in range(self.protocolclass.NUMGROUPS): 95 req.gid=i 96 # Don't crash if phone doesn't support groups 97 try: 98 res=self.sendpbcommand(req, self.protocolclass.groupnameresponse) 99 if res[0].entry.groupname and \ 100 res[0].entry.groupname!='Empty': 101 g[i]={'name': res[0].entry.groupname} 102 except Exception,e: 103 return g 104 return g
105 106 # phonebook stuff----------------------------------------------------------
107 - def _extract_misc(self, res, entry, fundamentals):
108 _name={ 'full': entry.name } 109 if entry.nick: 110 _name['nickname']=entry.nick 111 res['names']=[_name] 112 _grp=fundamentals.get('groups', {}).get(entry.group, None) 113 if _grp.get('name', None): 114 res['categories']=[{ 'category': _grp['name'] }] 115 if entry.email: 116 res['emails']=[{ 'email': entry.email }] 117 if entry.url: 118 res['urls']=[{ 'url': entry.url }] 119 if entry.memo: 120 res['memos']=[{ 'memo': entry.memo }]
121
122 - def _extract_wallpaper(self, res, entry, fundamentals):
123 _wp_index=fundamentals.get('wallpaper-index', {}) 124 _wp_name=_wp_index.get(entry.wallpaper, {}).get('name', None) 125 if _wp_name: 126 res['wallpapers']=[{ 'wallpaper': _wp_name, 'use': 'call' }]
127
128 - def _extract_ringtone(self, res, entry, fundamentals):
129 _rt_index=fundamentals.get('ringtone-index', {}) 130 _rt_name=_rt_index.get(entry.ringtone, {}).get('name', None) 131 if _rt_name: 132 res['ringtones']=[{ 'ringtone': _rt_name, 'use': 'call' }]
133 134 number_type_dict={ 135 0: 'cell', 1: 'home', 2: 'office', 3: 'pager', 4: 'fax' }
136 - def _extract_number(self, res, entry, idx, fundamentals):
137 _item=entry.numbers[idx] 138 if not _item.number: 139 return None 140 _res={ 'number': _item.number, 141 'type': self.number_type_dict.get(idx, 'none') } 142 # TODO: speed dial 143 return _res
144 - def _extract_numbers(self, res, entry, fundamentals):
145 _primary=entry.primary-1 146 _numbers=[self._extract_number(res, entry, _primary, fundamentals)] 147 for i in range(self.protocolclass.NUMPHONENUMBERS): 148 if i==_primary: 149 continue 150 _number=self._extract_number(res, entry, i, fundamentals) 151 if _number: 152 _numbers.append(_number) 153 res['numbers']=_numbers
154
155 - def extractphonebookentry(self, entry, fundamentals):
156 res={} 157 res['serials']=[ { 'sourcetype': self.serialsname, 158 'sourceuniqueid': fundamentals['uniqueserial'], 159 'slot': entry.slot, 160 'uslsot': entry.uslot }] 161 _args=(res, entry, fundamentals) 162 self._extract_misc(*_args) 163 self._extract_wallpaper(*_args) 164 self._extract_ringtone(*_args) 165 self._extract_numbers(*_args) 166 return res
167
168 - def getphonebook(self, result):
169 """Read the phonebook data.""" 170 pbook={} 171 self.setmode(self.MODEPHONEBOOK) 172 173 req=self.protocolclass.phonebookslotrequest() 174 lastname="" 175 for slot in range(1,self.protocolclass.NUMPHONEBOOKENTRIES+1): 176 req.slot=slot 177 res=self.sendpbcommand(req, self.protocolclass.phonebookslotresponse, fixup=self.pblinerepair) 178 if res: 179 self.log(`slot`+": "+res[0].entry.name) 180 entry=self.extractphonebookentry(res[0].entry, result) 181 pbook[res[0].entry.uslot]=entry 182 self.progress(slot, self.protocolclass.NUMPHONEBOOKENTRIES, lastname) 183 184 result['phonebook']=pbook 185 ## cats=[] 186 ## for i in result['groups']: 187 ## if result['groups'][i]['name']!='Unassigned': 188 ## cats.append(result['groups'][i]['name']) 189 ## result['categories']=cats 190 print "returning keys",result.keys() 191 192 return pbook
193 194 195 # wallpaper stuff----------------------------------------------------------
196 - def get_wallpaper_index(self):
197 _res=self._get_builtin_index(self.builtin_pictures) 198 self.setmode(self.MODEBREW) 199 _files=self.listfiles(self.protocolclass.WP_CAMERA_PATH) 200 _idx=self.camera_picture_index 201 for _pathname in _files: 202 _res[_idx]={ 'name': common.basename(_pathname)+'.jpg', 203 'origin': 'camera' } 204 _idx+=1 205 self.setmode(self.MODEMODEM) 206 return _res
207
208 - def getwallpapers(self, fundamentals):
209 """Read camera pictures from the phone""" 210 self.log('Reading Camera Pictures') 211 self.setmode(self.MODEBREW) 212 _files=self.listfiles(self.protocolclass.WP_CAMERA_PATH) 213 _media={} 214 for _pathname in _files: 215 _filename=common.basename(_pathname)+'.jpg' 216 try: 217 _media[_filename]=self.getfilecontents(_pathname, True) 218 except Exception,e: 219 self.log('Failed to read file %s due to: %s'%(_pathname, str(e))) 220 self.setmode(self.MODEMODEM) 221 fundamentals['wallpapers']=_media 222 return fundamentals
223 224 getringtones=NotImplemented 225 226 @classmethod
227 - def detectphone(_, coms, likely_ports, res, _module, _log):
228 pass
229 230 #------------------------------------------------------------------------------- 231 parentprofile=com_samsung_packet.Profile
232 -class Profile(parentprofile):
233 protocolclass=Phone.protocolclass 234 serialsname=Phone.serialsname 235 # for phone detection 236 phone_manufacturer='SAMSUNG' 237 phone_model='SPH-A790/118' 238 239 WALLPAPER_WIDTH=176 240 WALLPAPER_HEIGHT=220 241 # Outside LCD: 128x96 242
243 - def __init__(self):
244 parentprofile.__init__(self)
245
246 - def convertphonebooktophone(self, helper, data):
247 return data
248 249 _supportedsyncs=( 250 ('phonebook', 'read', None), # all phonebook reading 251 ## ('phonebook', 'write', 'OVERWRITE'), # only overwriting phonebook 252 ('wallpaper', 'read', None), # all wallpaper reading 253 ## ('wallpaper', 'write', None), # Image conversion needs work 254 ## ('ringtone', 'read', None), # all ringtone reading 255 ## ('ringtone', 'write', None), 256 ## ('calendar', 'read', None), # all calendar reading 257 ## ('calendar', 'write', 'OVERWRITE'), # only overwriting calendar 258 ## ('todo', 'read', None), # all todo list reading 259 ## ('todo', 'write', 'OVERWRITE'), # all todo list writing 260 ## ('memo', 'read', None), # all memo list reading 261 ## ('memo', 'write', 'OVERWRITE'), # all memo list writing 262 )
263