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

Source Code for Module phones.com_lgvx8700

  1  #!/usr/bin/env python 
  2   
  3  ### BITPIM 
  4  ### 
  5  ### Copyright (C) 2007 Nathan Hjelm <hjelmn@users.sourceforge.net> 
  6  ### 
  7  ### This program is free software; you can redistribute it and/or modify 
  8  ### it under the terms of the BitPim license as detailed in the LICENSE file. 
  9  ### 
 10   
 11  """ 
 12  Communicate with the LG VX8700 cell phone 
 13  """ 
 14   
 15  # BitPim modules 
 16  import common 
 17  import com_phone 
 18  import com_brew 
 19  import prototypes 
 20  import commport 
 21  import p_brew 
 22  import helpids 
 23  import com_lgvx8300 
 24  import com_lgvx8500 
 25  import p_lgvx8700 
 26   
 27  DEBUG1=False 
 28  #------------------------------------------------------------------------------- 
 29  parentphone=com_lgvx8500.Phone 
30 -class Phone(com_brew.RealBrewProtocol2, parentphone):
31 "Talk to LG VX-8700 cell phone" 32 33 desc="LG-VX8700" 34 helpid=helpids.ID_PHONE_LGVX8700 35 protocolclass=p_lgvx8700 36 serialsname='lgvx8700' 37 38 my_model='VX8700' 39 builtinringtones= ('Low Beep Once', 'Low Beeps', 'Loud Beep Once', 'Loud Beeps', 'Door Bell', 'VZW Default Ringtone') + \ 40 tuple(['Ringtone '+`n` for n in range(1,12)]) + \ 41 ('No Ring',) 42 43 ringtonelocations= ( 44 # type index file default dir external dir max type index 45 ('ringers', 'dload/myringtone.dat','brew/mod/10889/ringtones', '', 100, 0x01, 100), 46 ( 'sounds', 'dload/mysound.dat', 'brew/mod/18067', '', 100, 0x02, None), 47 ( 'sounds(sd)', 'dload/sd_sound.dat', 'mmc1/my_sounds', '', 100, 0x02, None), 48 ( 'music', 'dload/efs_music.dat', 'my_music', '', 100, 0x104, None), 49 ( 'music(sd)', 'dload/sd_music.dat', 'mmc1/my_music', '', 100, 0x14, None), 50 ) 51 52 wallpaperlocations= ( 53 # type index file default dir external dir max type Index 54 ( 'images', 'dload/image.dat', 'brew/mod/10888', '', 100, 0x00, 100), 55 ( 'images(sd)', 'dload/sd_image.dat', 'mmc1/my_pix', '', 100, 0x10, None), 56 ( 'video', 'dload/video.dat', 'brew/mod/10890', '', 100, 0x03, None), 57 ( 'video(sd)', 'dload/sd_video.dat', 'mmc1/my_flix', '', 100, 0x13, None), 58 ) 59 60
61 - def __init__(self, logtarget, commport):
62 parentphone.__init__(self, logtarget, commport)
63
64 - def setDMversion(self):
65 self._DMv5=True
66 67 # Fundamentals: 68 # - get_esn - same as LG VX-8300 69 # - getringtoneindices - LGUncountedIndexedMedia 70 # - getwallpaperindices - LGUncountedIndexedMedia 71 72 # phonebook
73 - def _update_pb_file(self, pb, fundamentals, pbinfo):
74 # update the pbentry file 75 update_flg=False 76 for e in pb.items: 77 _info=pbinfo.get(e.serial1, None) 78 if _info: 79 wp=_info.get('wallpaper', None) 80 if wp is not None and wp!=e.wallpaper: 81 update_flg=True 82 e.wallpaper=wp 83 if update_flg: 84 self.log('Updating wallpaper index') 85 buf=prototypes.buffer() 86 pb.writetobuffer(buf, logtitle="Updated index "+self.protocolclass.pb_file_name) 87 self.writefile(self.protocolclass.pb_file_name, buf.getvalue())
88
89 - def savephonebook(self, data):
90 "Saves out the phonebook" 91 res=com_lgvx8300.Phone.savephonebook(self, data) 92 # retrieve the phonebook entries 93 _buf=prototypes.buffer(self.getfilecontents(self.protocolclass.pb_file_name)) 94 _pb_entries=self.protocolclass.pbfile() 95 _pb_entries.readfrombuffer(_buf, logtitle="Read phonebook file "+self.protocolclass.pb_file_name) 96 _rt_index=data.get('ringtone-index', {}) 97 _wp_index=data.get('wallpaper-index', {}) 98 # update info that the phone software failed to do!! 99 self._update_pb_info(_pb_entries, data) 100 # fix up ringtone index 101 self._write_path_index(_pb_entries, 'ringtone', 102 _rt_index, 103 self.protocolclass.RTPathIndexFile, 104 (0xffff,)) 105 # fix up wallpaer index 106 self._write_path_index(_pb_entries, 'wallpaper', 107 _wp_index, 108 self.protocolclass.WPPathIndexFile, 109 (0, 0xffff,)) 110 return res
111 112 # groups
113 - def getgroups(self, results):
114 "Read groups" 115 # Reads groups that use explicit IDs 116 self.log("Reading group information") 117 g=self.readobject(self.protocolclass.pb_group_filename, 118 self.protocolclass.pbgroups, 119 'Reading groups data') 120 groups={} 121 for _group in g.groups: 122 if _group.name: 123 groups[_group.groupid]= { 'name': _group.name, 124 'user_added': _group.user_added } 125 results['groups'] = groups 126 return groups
127
128 - def savegroups(self, data):
129 groups=data.get('groups', {}) 130 keys=groups.keys() 131 keys.sort() 132 keys.reverse() 133 g=self.protocolclass.pbgroups() 134 # write the No Group entry first 135 g.groups.append(self.protocolclass.pbgroup(name='No Group')) 136 # now write the rest in reverse ID order 137 for k in keys: 138 if not k: 139 # already wrote this one out 140 continue 141 g.groups.append(self.protocolclass.pbgroup(name=groups[k]['name'], 142 groupid=k, 143 user_added=groups[k].get('user_added', 1))) 144 self.writeobject(self.protocolclass.pb_group_filename, g, 145 logtitle='Writing phonebook groups', 146 uselocalfs=DEBUG1)
147
148 - def listsubdirs(self, dir='', recurse=0):
149 return com_brew.RealBrewProtocol2.getfilesystem(self, dir, recurse, directories=1, files=0)
150 151 152 # ringtones and wallpapers stuff--------------------------------------------
153 - def savewallpapers(self, results, merge):
154 results['rebootphone']=True 155 return self.savemedia('wallpapers', 'wallpaper-index', 156 self.wallpaperlocations, results, merge, 157 self.getwallpaperindices, True)
158
159 - def saveringtones(self, results, merge):
160 # Let the phone rebuild the index file, just need to reboot 161 results['rebootphone']=True 162 return self.savemedia('ringtone', 'ringtone-index', 163 self.ringtonelocations, results, merge, 164 self.getringtoneindices, True)
165 166 #------------------------------------------------------------------------------- 167 parentprofile=com_lgvx8500.Profile
168 -class Profile(parentprofile):
169 protocolclass=Phone.protocolclass 170 serialsname=Phone.serialsname 171 172 BP_Calendar_Version=3 173 phone_manufacturer='LG Electronics Inc' 174 phone_model='VX8700' 175 # inside screen resoluation 176 WALLPAPER_WIDTH=240 177 WALLPAPER_HEIGHT=320 178 179 imageorigins={} 180 imageorigins.update(common.getkv(parentprofile.stockimageorigins, "images")) 181 imageorigins.update(common.getkv(parentprofile.stockimageorigins, "video")) 182 imageorigins.update(common.getkv(parentprofile.stockimageorigins, "images(sd)")) 183 imageorigins.update(common.getkv(parentprofile.stockimageorigins, "video(sd)")) 184 185 # our targets are the same for all origins 186 imagetargets={} 187 imagetargets.update(common.getkv(parentprofile.stockimagetargets, "fullscreen", 188 {'width': 238, 'height': 246, 'format': "JPEG"})) 189 imagetargets.update(common.getkv(parentprofile.stockimagetargets, "wallpaper", 190 {'width': 240, 'height': 274, 'format': "JPEG"})) 191 imagetargets.update(common.getkv(parentprofile.stockimagetargets, "pictureid", 192 {'width': 120, 'height': 100, 'format': "JPEG"})) 193 194 _supportedsyncs=( 195 ('phonebook', 'read', None), # all phonebook reading 196 ('calendar', 'read', None), # all calendar reading 197 ('wallpaper', 'read', None), # all wallpaper reading 198 ('ringtone', 'read', None), # all ringtone reading 199 ('call_history', 'read', None),# all call history list reading 200 ('sms', 'read', None), # all SMS list reading 201 ('memo', 'read', None), # all memo list reading 202 ('phonebook', 'write', 'OVERWRITE'), # only overwriting phonebook 203 ('calendar', 'write', 'OVERWRITE'), # only overwriting calendar 204 ('wallpaper', 'write', 'MERGE'), # merge and overwrite wallpaper 205 ('wallpaper', 'write', 'OVERWRITE'), 206 ('ringtone', 'write', 'MERGE'), # merge and overwrite ringtone 207 ('ringtone', 'write', 'OVERWRITE'), 208 ('sms', 'write', 'OVERWRITE'), # all SMS list writing 209 ('memo', 'write', 'OVERWRITE'), # all memo list writing 210 ('t9_udb', 'write', 'OVERWRITE'), 211 ) 212 if __debug__: 213 _supportedsyncs+=( 214 ('t9_udb', 'read', 'OVERWRITE'), 215 ) 216 217 # new group file format requires a new normalization routine
218 - def normalisegroups(self, helper, data):
219 self.normalizegroups(helper, data)
220
221 - def normalizegroups(self, helper, data):
222 "Assigns groups based on category data" 223 224 pad=[] 225 keys=data['groups'].keys() 226 keys.sort() 227 for k in keys: 228 if k: # ignore key 0 which is 'No Group' 229 name=data['groups'][k]['name'] 230 pad.append(name) 231 232 groups=helper.getmostpopularcategories(self.protocolclass.MAX_PHONEBOOK_GROUPS, data['phonebook'], ["No Group"], 32, pad) 233 234 # alpha sort 235 groups.sort() 236 237 # newgroups 238 newgroups={} 239 240 # put in No group 241 newgroups[0]={'name': 'No Group', 'user_added': 0} 242 243 # populate 244 for name in groups: 245 # existing entries remain unchanged 246 if name=="No Group": continue 247 key,value=self._getgroup(name, data['groups']) 248 if key is not None and key!=0: 249 newgroups[key]=value 250 # new entries get whatever numbers are free 251 for name in groups: 252 key,value=self._getgroup(name, newgroups) 253 if key is None: 254 for key in range(1,100000): 255 if key not in newgroups: 256 newgroups[key]={'name': name, 'user_added': 1} 257 break 258 259 # yay, done 260 if data['groups']!=newgroups: 261 data['groups']=newgroups 262 data['rebootphone']=True
263