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

Source Code for Module phones.com_motok1m

  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_motok1m.py 4529 2007-12-26 18:38:19Z djpham $ 
  9   
 10  """Communicate with Motorola K1m phones using AT commands""" 
 11   
 12  # BitPim modules 
 13  import common 
 14  import com_motov710m 
 15  import prototypes 
 16  import p_motok1m 
 17  import helpids 
 18   
 19  parentphone=com_motov710m.Phone 
20 -class Phone(parentphone):
21 desc='Moto-K1m' 22 helpid=helpids.ID_PHONE_MOTOK1M 23 serialsname='motok1m' 24 protocolclass=p_motok1m 25 26 builtinringtones=( 27 (0, ('No Ring',)), 28 ) 29
30 - def __init__(self, logtarget, commport):
31 parentphone.__init__(self, logtarget, commport)
32 33 # Ringtones stuff----------------------------------------------------------
34 - def _get_ringtone_index(self):
35 res={} 36 # first the builtin ones 37 for _l in self.builtinringtones: 38 _idx=_l[0] 39 for _e in _l[1]: 40 res[_idx]={ 'name': _e, 'origin': 'builtin' } 41 _idx+=1 42 # now the custome one 43 _buf=prototypes.buffer(self.getfilecontents( 44 self.protocolclass.RT_INDEX_FILE)) 45 _idx_file=self.protocolclass.ringtone_index_file() 46 _idx_file.readfrombuffer(_buf, logtitle='Read ringtone index file') 47 for _entry in _idx_file.items: 48 _filename=self.decode_utf16(_entry.name) 49 if _filename.startswith(self.protocolclass.RT_PATH): 50 _origin='ringers' 51 elif _filename.startswith(self.protocolclass.SND_PATH): 52 _origin='sounds' 53 else: 54 # neither ringtone nor sounds, can't use this 55 continue 56 res[_entry.index]={ 'name': common.basename(_filename), 57 'filename': _filename, 58 'type': _entry.ringtone_type, 59 'origin': _origin } 60 return res
61
62 - def getringtones(self, fundamentals):
63 """Retrieve ringtones data""" 64 self.log('Reading ringtones') 65 self.setmode(self.MODEOBEX) 66 _res={} 67 _rt_index=fundamentals.get('ringtone-index', {}) 68 for _entry in _rt_index.values(): 69 if _entry.has_key('filename'): 70 try: 71 _res[_entry['name']]=self.obex.getfilecontents( 72 self.protocolclass.OBEXName(_entry['filename'])) 73 except: 74 self.log('Failed to read media file %s'%_entry['filename']) 75 fundamentals['ringtone']=_res 76 self.setmode(self.MODEMODEM) 77 return fundamentals
78
79 - def saveringtones(self, fundamentals, merge):
80 """Save ringtones to the phone""" 81 self.log('Writing ringtones to the phone') 82 self.setmode(self.MODEPHONEBOOK) 83 self.setmode(self.MODEBREW) 84 try: 85 _del_list, _new_list=self._get_del_new_list('ringtone-index', 86 'ringtone', 87 merge, 88 fundamentals, 89 frozenset(['sounds'])) 90 # replace files, need to be in BREW mode 91 self._replace_files('ringtone-index', 'ringtone', 92 _new_list, fundamentals) 93 # delete files, need to be in OBEX mode 94 self.setmode(self.MODEOBEX) 95 self._del_files('ringtone-index', 'audio', 96 _del_list, fundamentals) 97 # and add new files, need to be in OBEX mode 98 self._add_files('ringtone-index', 'ringtone', 'audio', 99 _new_list, fundamentals) 100 except: 101 if __debug__: 102 self.setmode(self.MODEMODEM) 103 raise 104 self.setmode(self.MODEMODEM) 105 return fundamentals
106 107 108 #------------------------------------------------------------------------------ 109 parentprofile=com_motov710m.Profile
110 -class Profile(parentprofile):
111 serialsname=Phone.serialsname 112 usbids=( ( 0x22B8, 0x2A64, 1),) 113 114 # fill in the list of ringtone/sound origins on your phone 115 ringtoneorigins=('ringers', 'sounds') 116 # ringtone origins that are not available for the contact assignment 117 excluded_ringtone_origins=() 118 imageorigins={} 119 imageorigins.update(common.getkv(parentprofile.stockimageorigins, "images")) 120 excluded_wallpaper_origins=() 121 # use for auto-detection 122 phone_manufacturer='Motorola' 123 phone_model='K1m' 124 common_model_name='K1m' 125 generic_phone_model='Motorola CDMA K1m phone' 126 127 # our targets are the same for all origins 128 imagetargets={} 129 imagetargets.update(common.getkv(parentprofile.stockimagetargets, "wallpaper", 130 {'width': 176, 'height': 184, 'format': "JPEG"})) 131 imagetargets.update(common.getkv(parentprofile.stockimagetargets, "outsidelcd", 132 {'width': 96, 'height': 67, 'format': "JPEG"})) 133 imagetargets.update(common.getkv(parentprofile.stockimagetargets, "fullscreen", 134 {'width': 176, 'height': 220, 'format': "JPEG"})) 135 136 field_color_data=parentprofile.field_color_data 137 field_color_data.update({ 138 'phonebook': { 139 'name': { 140 'first': 1, 'middle': 1, 'last': 1, 'full': 1, 141 'nickname': 0, 'details': 1 }, 142 'number': { 143 'type': 5, 'speeddial': 5, 'number': 5, 144 'details': 5, 145 'ringtone': 5, 'wallpaper': 5 }, 146 'email': 2, 147 'email_details': { 148 'emailspeeddial': 2, 'emailringtone': 2, 149 'emailwallpaper': 2 }, 150 'address': { 151 'type': 0, 'company': 0, 'street': 0, 'street2': 0, 152 'city': 0, 'state': 0, 'postalcode': 0, 'country': 0, 153 'details': 0 }, 154 'url': 0, 155 'memo': 0, 156 'category': 1, 157 'wallpaper': 1, 158 'ringtone': 1, 159 'storage': 0, 160 }})
161