0001 #!/usr/bin/env python 0002 0003 ### BITPIM 0004 ### 0005 ### Copyright (C) 2007 Nathan Hjelm <hjelmn@users.sourceforge.net> 0006 ### 0007 ### This program is free software; you can redistribute it and/or modify 0008 ### it under the terms of the BitPim license as detailed in the LICENSE file. 0009 ### 0010 0011 """ 0012 Communicate with the LG VX8700 cell phone 0013 """ 0014 0015 # BitPim modules 0016 import common 0017 import com_phone 0018 import com_brew 0019 import prototypes 0020 import commport 0021 import p_brew 0022 import helpids 0023 import com_lgvx8300 0024 import com_lgvx8500 0025 import p_lgvx8700 0026 0027 DEBUG1=False 0028 #------------------------------------------------------------------------------- 0029 parentphone=com_lgvx8500.Phone 0030 class Phone(com_brew.RealBrewProtocol2, parentphone): 0031 "Talk to LG VX-8700 cell phone" 0032 0033 desc="LG-VX8700" 0034 helpid=helpids.ID_PHONE_LGVX8700 0035 protocolclass=p_lgvx8700 0036 serialsname='lgvx8700' 0037 0038 my_model='VX8700' 0039 builtinringtones= ('Low Beep Once', 'Low Beeps', 'Loud Beep Once', 'Loud Beeps', 'Door Bell', 'VZW Default Ringtone') + \ 0040 tuple(['Ringtone '+`n` for n in range(1,12)]) + \ 0041 ('No Ring',) 0042 0043 ringtonelocations= ( 0044 # type index file default dir external dir max type index 0045 ('ringers', 'dload/myringtone.dat','brew/mod/10889/ringtones', '', 100, 0x01, 100), 0046 ( 'sounds', 'dload/mysound.dat', 'brew/mod/18067', '', 100, 0x02, None), 0047 ( 'sounds(sd)', 'dload/sd_sound.dat', 'mmc1/my_sounds', '', 100, 0x02, None), 0048 ( 'music', 'dload/efs_music.dat', 'my_music', '', 100, 0x104, None), 0049 ( 'music(sd)', 'dload/sd_music.dat', 'mmc1/my_music', '', 100, 0x14, None), 0050 ) 0051 0052 wallpaperlocations= ( 0053 # type index file default dir external dir max type Index 0054 ( 'images', 'dload/image.dat', 'brew/mod/10888', '', 100, 0x00, 100), 0055 ( 'images(sd)', 'dload/sd_image.dat', 'mmc1/my_pix', '', 100, 0x10, None), 0056 ( 'video', 'dload/video.dat', 'brew/mod/10890', '', 100, 0x03, None), 0057 ( 'video(sd)', 'dload/sd_video.dat', 'mmc1/my_flix', '', 100, 0x13, None), 0058 ) 0059 0060 0061 def __init__(self, logtarget, commport): 0062 parentphone.__init__(self, logtarget, commport) 0063 0064 def setDMversion(self): 0065 self._DMv5=True 0066 0067 # Fundamentals: 0068 # - get_esn - same as LG VX-8300 0069 # - getringtoneindices - LGUncountedIndexedMedia 0070 # - getwallpaperindices - LGUncountedIndexedMedia 0071 0072 # phonebook 0073 def _update_pb_file(self, pb, fundamentals, pbinfo): 0074 # update the pbentry file 0075 update_flg=False 0076 for e in pb.items: 0077 _info=pbinfo.get(e.serial1, None) 0078 if _info: 0079 wp=_info.get('wallpaper', None) 0080 if wp is not None and wp!=e.wallpaper: 0081 update_flg=True 0082 e.wallpaper=wp 0083 if update_flg: 0084 self.log('Updating wallpaper index') 0085 buf=prototypes.buffer() 0086 pb.writetobuffer(buf, logtitle="Updated index "+self.protocolclass.pb_file_name) 0087 self.writefile(self.protocolclass.pb_file_name, buf.getvalue()) 0088 0089 def savephonebook(self, data): 0090 "Saves out the phonebook" 0091 res=com_lgvx8300.Phone.savephonebook(self, data) 0092 # retrieve the phonebook entries 0093 _buf=prototypes.buffer(self.getfilecontents(self.protocolclass.pb_file_name)) 0094 _pb_entries=self.protocolclass.pbfile() 0095 _pb_entries.readfrombuffer(_buf, logtitle="Read phonebook file "+self.protocolclass.pb_file_name) 0096 _rt_index=data.get('ringtone-index', {}) 0097 _wp_index=data.get('wallpaper-index', {}) 0098 # update info that the phone software failed to do!! 0099 self._update_pb_info(_pb_entries, data) 0100 # fix up ringtone index 0101 self._write_path_index(_pb_entries, 'ringtone', 0102 _rt_index, 0103 self.protocolclass.RTPathIndexFile, 0104 (0xffff,)) 0105 # fix up wallpaer index 0106 self._write_path_index(_pb_entries, 'wallpaper', 0107 _wp_index, 0108 self.protocolclass.WPPathIndexFile, 0109 (0, 0xffff,)) 0110 return res 0111 0112 # groups 0113 def getgroups(self, results): 0114 "Read groups" 0115 # Reads groups that use explicit IDs 0116 self.log("Reading group information") 0117 g=self.readobject(self.protocolclass.pb_group_filename, 0118 self.protocolclass.pbgroups, 0119 'Reading groups data') 0120 groups={} 0121 for _group in g.groups: 0122 if _group.name: 0123 groups[_group.groupid]= { 'name': _group.name, 0124 'user_added': _group.user_added } 0125 results['groups'] = groups 0126 return groups 0127 0128 def savegroups(self, data): 0129 groups=data.get('groups', {}) 0130 keys=groups.keys() 0131 keys.sort() 0132 keys.reverse() 0133 g=self.protocolclass.pbgroups() 0134 # write the No Group entry first 0135 g.groups.append(self.protocolclass.pbgroup(name='No Group')) 0136 # now write the rest in reverse ID order 0137 for k in keys: 0138 if not k: 0139 # already wrote this one out 0140 continue 0141 g.groups.append(self.protocolclass.pbgroup(name=groups[k]['name'], 0142 groupid=k, 0143 user_added=groups[k].get('user_added', 1))) 0144 self.writeobject(self.protocolclass.pb_group_filename, g, 0145 logtitle='Writing phonebook groups', 0146 uselocalfs=DEBUG1) 0147 0148 def listsubdirs(self, dir='', recurse=0): 0149 return com_brew.RealBrewProtocol2.getfilesystem(self, dir, recurse, directories=1, files=0) 0150 0151 0152 # ringtones and wallpapers stuff-------------------------------------------- 0153 def savewallpapers(self, results, merge): 0154 results['rebootphone']=True 0155 return self.savemedia('wallpapers', 'wallpaper-index', 0156 self.wallpaperlocations, results, merge, 0157 self.getwallpaperindices, True) 0158 0159 def saveringtones(self, results, merge): 0160 # Let the phone rebuild the index file, just need to reboot 0161 results['rebootphone']=True 0162 return self.savemedia('ringtone', 'ringtone-index', 0163 self.ringtonelocations, results, merge, 0164 self.getringtoneindices, True) 0165 0166 #------------------------------------------------------------------------------- 0167 parentprofile=com_lgvx8500.Profile 0168 class Profile(parentprofile): 0169 protocolclass=Phone.protocolclass 0170 serialsname=Phone.serialsname 0171 0172 BP_Calendar_Version=3 0173 phone_manufacturer='LG Electronics Inc' 0174 phone_model='VX8700' 0175 # inside screen resoluation 0176 WALLPAPER_WIDTH=240 0177 WALLPAPER_HEIGHT=320 0178 0179 imageorigins={} 0180 imageorigins.update(common.getkv(parentprofile.stockimageorigins, "images")) 0181 imageorigins.update(common.getkv(parentprofile.stockimageorigins, "video")) 0182 imageorigins.update(common.getkv(parentprofile.stockimageorigins, "images(sd)")) 0183 imageorigins.update(common.getkv(parentprofile.stockimageorigins, "video(sd)")) 0184 0185 # our targets are the same for all origins 0186 imagetargets={} 0187 imagetargets.update(common.getkv(parentprofile.stockimagetargets, "fullscreen", 0188 {'width': 238, 'height': 246, 'format': "JPEG"})) 0189 imagetargets.update(common.getkv(parentprofile.stockimagetargets, "wallpaper", 0190 {'width': 240, 'height': 274, 'format': "JPEG"})) 0191 imagetargets.update(common.getkv(parentprofile.stockimagetargets, "pictureid", 0192 {'width': 120, 'height': 100, 'format': "JPEG"})) 0193 0194 _supportedsyncs=( 0195 ('phonebook', 'read', None), # all phonebook reading 0196 ('calendar', 'read', None), # all calendar reading 0197 ('wallpaper', 'read', None), # all wallpaper reading 0198 ('ringtone', 'read', None), # all ringtone reading 0199 ('call_history', 'read', None),# all call history list reading 0200 ('sms', 'read', None), # all SMS list reading 0201 ('memo', 'read', None), # all memo list reading 0202 ('phonebook', 'write', 'OVERWRITE'), # only overwriting phonebook 0203 ('calendar', 'write', 'OVERWRITE'), # only overwriting calendar 0204 ('wallpaper', 'write', 'MERGE'), # merge and overwrite wallpaper 0205 ('wallpaper', 'write', 'OVERWRITE'), 0206 ('ringtone', 'write', 'MERGE'), # merge and overwrite ringtone 0207 ('ringtone', 'write', 'OVERWRITE'), 0208 ('sms', 'write', 'OVERWRITE'), # all SMS list writing 0209 ('memo', 'write', 'OVERWRITE'), # all memo list writing 0210 ('t9_udb', 'write', 'OVERWRITE'), 0211 ) 0212 if __debug__: 0213 _supportedsyncs+=( 0214 ('t9_udb', 'read', 'OVERWRITE'), 0215 ) 0216 0217 # new group file format requires a new normalization routine 0218 def normalisegroups(self, helper, data): 0219 self.normalizegroups(helper, data) 0220 0221 def normalizegroups(self, helper, data): 0222 "Assigns groups based on category data" 0223 0224 pad=[] 0225 keys=data['groups'].keys() 0226 keys.sort() 0227 for k in keys: 0228 if k: # ignore key 0 which is 'No Group' 0229 name=data['groups'][k]['name'] 0230 pad.append(name) 0231 0232 groups=helper.getmostpopularcategories(self.protocolclass.MAX_PHONEBOOK_GROUPS, data['phonebook'], ["No Group"], 32, pad) 0233 0234 # alpha sort 0235 groups.sort() 0236 0237 # newgroups 0238 newgroups={} 0239 0240 # put in No group 0241 newgroups[0]={'name': 'No Group', 'user_added': 0} 0242 0243 # populate 0244 for name in groups: 0245 # existing entries remain unchanged 0246 if name=="No Group": continue 0247 key,value=self._getgroup(name, data['groups']) 0248 if key is not None and key!=0: 0249 newgroups[key]=value 0250 # new entries get whatever numbers are free 0251 for name in groups: 0252 key,value=self._getgroup(name, newgroups) 0253 if key is None: 0254 for key in range(1,100000): 0255 if key not in newgroups: 0256 newgroups[key]={'name': name, 'user_added': 1} 0257 break 0258 0259 # yay, done 0260 if data['groups']!=newgroups: 0261 data['groups']=newgroups 0262 data['rebootphone']=True 0263
Generated by PyXR 0.9.4