PyXR

c:\projects\bitpim\src \ phones \ com_samsungschu470.py



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_samsungschu470.py 4521 2007-12-24 05:03:56Z djpham $
0009 
0010 """Communicate with the Samsung SCH-U470 (Juke) Phone"""
0011 
0012 import common
0013 import com_samsungschu740 as u740
0014 import p_samsungschu470 as p_u470
0015 import helpids
0016 
0017 parentphone=u740.Phone
0018 class Phone(parentphone):
0019     desc='SCH-U470'
0020     helpid=helpids.ID_PHONE_SAMSUNGSCHU470
0021     protocolclass=p_u470
0022     serialsname='schu470'
0023 
0024     ringtone_noring_range='range_tones_preloaded_el_no_rings'
0025     ringtone_default_range='range_tones_preloaded_el_01'
0026     builtin_ringtones={
0027         'VZW Default Tone': ringtone_default_range,
0028         'Bell 1': 'range_tones_preloaded_el_02',
0029         'Bell 2': 'range_tones_preloaded_el_03',
0030         'Bell 3': 'range_tones_preloaded_el_04',
0031         'Melody 1': 'range_tones_preloaded_el_05',
0032         'Melody 2': 'range_tones_preloaded_el_06',
0033         'Melody 3': 'range_tones_preloaded_el_07',
0034         'Melody 4': 'range_tones_preloaded_el_08',
0035         'Melody 5': 'range_tones_preloaded_el_09',
0036         'Melody 6': 'range_tones_preloaded_el_10',
0037         'Beep Once': 'range_tones_preloaded_el_11',
0038         'No Ring': ringtone_noring_range,
0039         }
0040     # can we use Sounds as ringtones?
0041     builtin_sounds={}
0042 ##    builtin_sounds={
0043 ##        'Clapping': 'range_sound_preloaded_el_clapping',
0044 ##        'Crowd Roar': 'range_sound_preloaded_el_crowed_roar',
0045 ##        'Happy Birthday': 'range_sound_preloaded_el_birthday',
0046 ##        'Rainforest': 'range_sound_preloaded_el_rainforest',
0047 ##        'Train': 'range_sound_preloaded_el_train',
0048 ##        # same as ringtones ??
0049 ##        'Sound Beep Once': 'range_sound_preloaded_el_beep_once',
0050 ##        'Sound No Ring': 'range_sound_preloaded_el_no_rings',
0051 ##        }
0052     builtin_wallpapers={
0053         'Preloaded1': 'range_f_wallpaper_preloaded_el_01',
0054         'Preloaded2': 'range_f_wallpaper_preloaded_el_02',
0055         'Preloaded3': 'range_f_wallpaper_preloaded_el_03',
0056         'Preloaded4': 'range_f_wallpaper_preloaded_el_04',
0057         'Preloaded5': 'range_f_wallpaper_preloaded_el_05',
0058         }
0059     builtin_groups={
0060         1: 'Business',
0061         2: 'Colleague',
0062         3: 'Family',
0063         4: 'Friends'
0064         }
0065 
0066     my_model='SCH-U470/Juke'
0067     my_manufacturer='SAMSUNG'
0068     detected_model='U470'
0069 
0070     def __init__(self, logtarget, commport):
0071         "Calls all the constructors and sets initial modes"
0072         parentphone.__init__(self, logtarget, commport)
0073         global PBEntry
0074         self.pbentryclass=PBEntry
0075 
0076     def _read_ringtone_range(self, fundamentals):
0077         fundamentals['ringtone-range']={}
0078 
0079     def get_ringtone_range(self, name, fundamentals):
0080         if not name:
0081             # return No Rings
0082             return self.ringtone_default_range
0083         # check the builtin ringtones
0084         if self.builtin_ringtones.has_key(name):
0085             return self.builtin_ringtones[name]
0086         if self.builtin_sounds.has_key(name):
0087             return self.builtin_sounds[name]
0088         # check for custom ringtones,
0089         # this model does not use ranges for custom ringtones, just straight
0090         # file names instead.
0091         _rt_index=fundamentals.get('ringtone-index', {})
0092         for _entry in _rt_index.values():
0093             if _entry['name']==name:
0094                 _filename=_entry.get('filename', None)
0095                 if _filename:
0096                     return '/ff/'+_filename
0097 
0098     def ringtone_name_from_range(self, range, fundamentals):
0099         # check for builtin ringtones
0100         for _key,_value in self.builtin_ringtones.items():
0101             if range==_value:
0102                 return _key
0103         # check for builtin sounds
0104         for _key,_value in self.builtin_sounds.items():
0105             if range==_value:
0106                 return _key
0107         # now check for the "custom" ones
0108         # Again, this model does not use ringtone ranges, just filename
0109         if range.startswith('/ff/'):
0110             return common.basename(range)
0111 
0112     # Wallpaper stuff-----------------------------------------------------------
0113     def _get_file_wallpaper_index(self, idx, result,
0114                                   path, origin):
0115         for _filename in self.listfiles(path):
0116             result[idx]={ 'name': self.basename(_filename),
0117                           'filename': _filename,
0118                           'origin': origin }
0119             idx+=1
0120         return idx
0121 
0122     def get_wallpaper_index(self):
0123         _res={}
0124         _idx=self._get_builtin_wallpaper_index(0, _res)
0125         _idx=self._get_file_wallpaper_index(_idx, _res,
0126                                             self.protocolclass.PIC_PATH,
0127                                             'images')
0128         return _res
0129 
0130     def savewallpapers(self, fundamentals, merge):
0131         # send wallpapers to the phone
0132         """Save wallpapers to the phone"""
0133         self.log('Writing wallpapers to the phone')
0134         try:
0135             _del_list, _new_list=self._get_del_new_list('wallpaper-index',
0136                                                         'wallpapers',
0137                                                         merge,
0138                                                         fundamentals,
0139                                                         frozenset(['video']))
0140             if __debug__:
0141                 self.log('Delete list: '+','.join(_del_list))
0142                 self.log('New list: '+','.join(_new_list))
0143             self._add_files('wallpaper-index', 'wallpapers',
0144                             _new_list, fundamentals)
0145             fundamentals['rebootphone']=True
0146         except:
0147             if __debug__:
0148                 raise
0149         return fundamentals
0150 
0151 
0152 # PBEntry class-----------------------------------------------------------------
0153 parentpbentry=u740.PBEntry
0154 class PBEntry(parentpbentry):
0155 
0156     def _extract_wallpaper(self, entry, p_class):
0157         if not self.pb.info2 & p_class.PB_FLG2_WP:
0158             return
0159         entry['wallpapers']=[{ 'wallpaper': common.basename(self.pb.wallpaper2),
0160                                'use': 'call' }]
0161 
0162     def _extract_ringtone(self, entry, p_class):
0163         if  self.pb.info2 & p_class.PB_FLG2_RINGTONE and \
0164            self.pb.ringtone:
0165             if self.pb.ringtone.startswith('/ff/'):
0166                 # user's ringtone
0167                 _ringtone=common.basename(self.pb.ringtone)
0168             else:
0169                 # built-in ringtone
0170                 _ringtone=self.phone.ringtone_name_from_range(
0171                     self.pb.ringtone, self.fundamentals)
0172             if _ringtone:
0173                 entry['ringtones']=[{ 'ringtone': _ringtone,
0174                                       'use': 'call' }]
0175 
0176     def getvalue(self):
0177         _entry=parentpbentry.getvalue(self)
0178         self._extract_ringtone(_entry, self.phone.protocolclass)
0179         return _entry
0180 
0181 # Profile class-----------------------------------------------------------------
0182 parentprofile=u740.Profile
0183 class Profile(parentprofile):
0184     serialsname=Phone.serialsname
0185     WALLPAPER_WIDTH=176
0186     WALLPAPER_HEIGHT=220
0187     autodetect_delay=3
0188     usbids=( ( 0x04e8, 0x6640, 2),)
0189     deviceclasses=("serial",)
0190     BP_Calendar_Version=3
0191     # For phone detection
0192     phone_manufacturer=Phone.my_manufacturer
0193     phone_model=Phone.my_model
0194 
0195     # our targets are the same for all origins
0196     imagetargets={}
0197     imagetargets.update(common.getkv(parentprofile.stockimagetargets, "wallpaper",
0198                                       {'width': 128, 'height': 164, 'format': "JPEG"}))
0199     imagetargets.update(common.getkv(parentprofile.stockimagetargets, "pictureid",
0200                                       {'width': 112, 'height': 84, 'format': "JPEG"}))
0201     imagetargets.update(common.getkv(parentprofile.stockimagetargets, "fullscreen",
0202                                       {'width': 128, 'height': 220, 'format': "JPEG"}))
0203     imageorigins={}
0204     imageorigins.update(common.getkv(parentprofile.stockimageorigins, "images"))
0205 

Generated by PyXR 0.9.4