0001 ### BITPIM 0002 ### 0003 ### Copyright (C) 2006 Joe Pham <djpham@bitpim.org> 0004 ### 0005 ### This program is free software; you can redistribute it and/or modify 0006 ### it under the terms of the BitPim license as detailed in the LICENSE file. 0007 ### 0008 ### $Id: com_motok1m.py 4529 2007-12-26 18:38:19Z djpham $ 0009 0010 """Communicate with Motorola K1m phones using AT commands""" 0011 0012 # BitPim modules 0013 import common 0014 import com_motov710m 0015 import prototypes 0016 import p_motok1m 0017 import helpids 0018 0019 parentphone=com_motov710m.Phone 0020 class Phone(parentphone): 0021 desc='Moto-K1m' 0022 helpid=helpids.ID_PHONE_MOTOK1M 0023 serialsname='motok1m' 0024 protocolclass=p_motok1m 0025 0026 builtinringtones=( 0027 (0, ('No Ring',)), 0028 ) 0029 0030 def __init__(self, logtarget, commport): 0031 parentphone.__init__(self, logtarget, commport) 0032 0033 # Ringtones stuff---------------------------------------------------------- 0034 def _get_ringtone_index(self): 0035 res={} 0036 # first the builtin ones 0037 for _l in self.builtinringtones: 0038 _idx=_l[0] 0039 for _e in _l[1]: 0040 res[_idx]={ 'name': _e, 'origin': 'builtin' } 0041 _idx+=1 0042 # now the custome one 0043 _buf=prototypes.buffer(self.getfilecontents( 0044 self.protocolclass.RT_INDEX_FILE)) 0045 _idx_file=self.protocolclass.ringtone_index_file() 0046 _idx_file.readfrombuffer(_buf, logtitle='Read ringtone index file') 0047 for _entry in _idx_file.items: 0048 _filename=self.decode_utf16(_entry.name) 0049 if _filename.startswith(self.protocolclass.RT_PATH): 0050 _origin='ringers' 0051 elif _filename.startswith(self.protocolclass.SND_PATH): 0052 _origin='sounds' 0053 else: 0054 # neither ringtone nor sounds, can't use this 0055 continue 0056 res[_entry.index]={ 'name': common.basename(_filename), 0057 'filename': _filename, 0058 'type': _entry.ringtone_type, 0059 'origin': _origin } 0060 return res 0061 0062 def getringtones(self, fundamentals): 0063 """Retrieve ringtones data""" 0064 self.log('Reading ringtones') 0065 self.setmode(self.MODEOBEX) 0066 _res={} 0067 _rt_index=fundamentals.get('ringtone-index', {}) 0068 for _entry in _rt_index.values(): 0069 if _entry.has_key('filename'): 0070 try: 0071 _res[_entry['name']]=self.obex.getfilecontents( 0072 self.protocolclass.OBEXName(_entry['filename'])) 0073 except: 0074 self.log('Failed to read media file %s'%_entry['filename']) 0075 fundamentals['ringtone']=_res 0076 self.setmode(self.MODEMODEM) 0077 return fundamentals 0078 0079 def saveringtones(self, fundamentals, merge): 0080 """Save ringtones to the phone""" 0081 self.log('Writing ringtones to the phone') 0082 self.setmode(self.MODEPHONEBOOK) 0083 self.setmode(self.MODEBREW) 0084 try: 0085 _del_list, _new_list=self._get_del_new_list('ringtone-index', 0086 'ringtone', 0087 merge, 0088 fundamentals, 0089 frozenset(['sounds'])) 0090 # replace files, need to be in BREW mode 0091 self._replace_files('ringtone-index', 'ringtone', 0092 _new_list, fundamentals) 0093 # delete files, need to be in OBEX mode 0094 self.setmode(self.MODEOBEX) 0095 self._del_files('ringtone-index', 'audio', 0096 _del_list, fundamentals) 0097 # and add new files, need to be in OBEX mode 0098 self._add_files('ringtone-index', 'ringtone', 'audio', 0099 _new_list, fundamentals) 0100 except: 0101 if __debug__: 0102 self.setmode(self.MODEMODEM) 0103 raise 0104 self.setmode(self.MODEMODEM) 0105 return fundamentals 0106 0107 0108 #------------------------------------------------------------------------------ 0109 parentprofile=com_motov710m.Profile 0110 class Profile(parentprofile): 0111 serialsname=Phone.serialsname 0112 usbids=( ( 0x22B8, 0x2A64, 1),) 0113 0114 # fill in the list of ringtone/sound origins on your phone 0115 ringtoneorigins=('ringers', 'sounds') 0116 # ringtone origins that are not available for the contact assignment 0117 excluded_ringtone_origins=() 0118 imageorigins={} 0119 imageorigins.update(common.getkv(parentprofile.stockimageorigins, "images")) 0120 excluded_wallpaper_origins=() 0121 # use for auto-detection 0122 phone_manufacturer='Motorola' 0123 phone_model='K1m' 0124 common_model_name='K1m' 0125 generic_phone_model='Motorola CDMA K1m phone' 0126 0127 # our targets are the same for all origins 0128 imagetargets={} 0129 imagetargets.update(common.getkv(parentprofile.stockimagetargets, "wallpaper", 0130 {'width': 176, 'height': 184, 'format': "JPEG"})) 0131 imagetargets.update(common.getkv(parentprofile.stockimagetargets, "outsidelcd", 0132 {'width': 96, 'height': 67, 'format': "JPEG"})) 0133 imagetargets.update(common.getkv(parentprofile.stockimagetargets, "fullscreen", 0134 {'width': 176, 'height': 220, 'format': "JPEG"})) 0135 0136 field_color_data=parentprofile.field_color_data 0137 field_color_data.update({ 0138 'phonebook': { 0139 'name': { 0140 'first': 1, 'middle': 1, 'last': 1, 'full': 1, 0141 'nickname': 0, 'details': 1 }, 0142 'number': { 0143 'type': 5, 'speeddial': 5, 'number': 5, 0144 'details': 5, 0145 'ringtone': 5, 'wallpaper': 5 }, 0146 'email': 2, 0147 'email_details': { 0148 'emailspeeddial': 2, 'emailringtone': 2, 0149 'emailwallpaper': 2 }, 0150 'address': { 0151 'type': 0, 'company': 0, 'street': 0, 'street2': 0, 0152 'city': 0, 'state': 0, 'postalcode': 0, 'country': 0, 0153 'details': 0 }, 0154 'url': 0, 0155 'memo': 0, 0156 'category': 1, 0157 'wallpaper': 1, 0158 'ringtone': 1, 0159 'storage': 0, 0160 }}) 0161
Generated by PyXR 0.9.4