def getringtones(self, result):
     result=com_lgvx4400.Phone.getringtones(self, result)
     if not conversions.helperavailable('pvconv'):
         return result
     media=result['ringtone']
     _qcp_file=common.gettempfilename('qcp')
     _wav_file=common.gettempfilename('wav')
     try:
         vmemo_files=self.listfiles(self.VoiceMemoDir)
         keys=vmemo_files.keys()
         for k in keys:
             if k.endswith('.qcp'):
                 key_name='VoiceMemo'+k[-8:-4]
                 file(_qcp_file, 'wb').write(self.getfilecontents(k, True))
                 conversions.convertqcptowav(_qcp_file, _wav_file)
                 media[key_name]=file(_wav_file, 'rb').read()
     except:
         if __debug__:
             raise
     try:
         os.remove(_qcp_file)
         os.remove(_wav_file)
     except:
         pass
     result['ringtone']=media
     return result
예제 #2
0
    def get_video(self, result, video_file_name):
        if not conversions.helperavailable('bmp2avi'):
            # helper not available , just bail
            self.__phone.log('Helper bmp2avi not found, cannot retrieve '+\
                             video_file_name)
            return result
        self.__phone.log('Getting video file ' + video_file_name)
        media = result.get(self.__file_type, {})
        idx = result.get(self.__index_type, {})
        tmp_avi_name = common.gettempfilename("avi")
        try:
            file_list = self.__phone.listfiles(self.__path)
        except com_brew.BrewNoSuchDirectoryException:
            file_list = {}
        except:
            file_list = {}
            if __debug__: raise

        if not len(file_list):
            # empty directory
            return result
        file_keys = file_list.keys()
        file_keys.sort()
        for k in file_keys:
            try:
                conversions.convertjpgtoavi(
                    self.__phone.getfilecontents(k, True)[96:], tmp_avi_name)
            except:
                self.__phone.log('Failed to read video files')
                if __debug__: raise
        # got the avi file, now prep to send it back
        if len(idx):
            idx_k = max(idx.keys()) + 1
        else:
            idx_k = 0
        media[video_file_name] = open(tmp_avi_name, 'rb').read()
        idx[idx_k] = {'name': video_file_name, 'origin': 'video'}
        result[self.__file_type] = media
        result[self.__index_type] = idx
        try:
            os.remove(tmp_avi_name)
        except:
            pass
        return result
예제 #3
0
    def get_video(self, result, video_file_name):
        if not conversions.helperavailable('bmp2avi'):
            # helper not available , just bail
            self.__phone.log('Helper bmp2avi not found, cannot retrieve '+\
                             video_file_name)
            return result
        self.__phone.log('Getting video file '+video_file_name)
        media=result.get(self.__file_type, {})
        idx=result.get(self.__index_type, {})
        tmp_avi_name=common.gettempfilename("avi")
        try:
            file_list=self.__phone.listfiles(self.__path)
        except com_brew.BrewNoSuchDirectoryException:
            file_list={}
        except:
            file_list={}
            if __debug__: raise

        if not len(file_list):
            # empty directory
            return result
        file_keys=file_list.keys()
        file_keys.sort();
        for k in file_keys:
            try:
                conversions.convertjpgtoavi(self.__phone.getfilecontents(k, True)[96:],
                                            tmp_avi_name)
            except:
                self.__phone.log('Failed to read video files')
                if __debug__: raise
        # got the avi file, now prep to send it back
        if len(idx):
            idx_k=max(idx.keys())+1
        else:
            idx_k=0
        media[video_file_name]=open(tmp_avi_name, 'rb').read()
        idx[idx_k]={ 'name': video_file_name, 'origin': 'video' }
        result[self.__file_type]=media
        result[self.__index_type]=idx
        try:
            os.remove(tmp_avi_name)
        except:
            pass
        return result
예제 #4
0
 def getringtones(self, result):
     result=com_lgvx4400.Phone.getringtones(self, result)
     if not conversions.helperavailable('pvconv'):
         return result
     media=result['ringtone']
     # get& convert the voice memo files
     with contextlib.nested(common.usetempfile('qcp'),
                            common.usetempfile('wav')) as (_qcp_file, _wav_file):
         try:
             vmemo_files=self.listfiles(self.VoiceMemoDir)
             keys=vmemo_files.keys()
             for k in keys:
                 if k.endswith('.qcp'):
                     key_name='VoiceMemo'+k[-8:-4]
                     file(_qcp_file, 'wb').write(self.getfilecontents(k, True))
                     conversions.convertqcptowav(_qcp_file, _wav_file)
                     media[key_name]=file(_wav_file, 'rb').read()
         except:
             if __debug__:
                 raise
     result['ringtone']=media
     return result
	def getringtones(self, result):

        result=com_lgvx4400.Phone.getringtones(self, result)

        if not conversions.helperavailable('pvconv'):

            return result

        media=result['ringtone']

        _qcp_file=common.gettempfilename('qcp')

        _wav_file=common.gettempfilename('wav')

        try:

            vmemo_files=self.listfiles(self.VoiceMemoDir)

            keys=vmemo_files.keys()

            for k in keys:

                if k.endswith('.qcp'):

                    key_name='VoiceMemo'+k[-8:-4]

                    file(_qcp_file, 'wb').write(self.getfilecontents(k, True))

                    conversions.convertqcptowav(_qcp_file, _wav_file)

                    media[key_name]=file(_wav_file, 'rb').read()

        except:

            if __debug__:

                raise

        try:

            os.remove(_qcp_file)

            os.remove(_wav_file)

        except:

            pass

        result['ringtone']=media

        return result

	def saveringtones(self, results, merge):

        _new_ringtones=results.get('ringtone', {})

        _rt_index=results.get('ringtone-index', {})

        _voice_memo_l=[x['name'] for k,x in _rt_index.items() \
                       if x.get('origin', '')=='voicememo']

        _del_keys=[k for k,x in _new_ringtones.items() \
                   if x.get('name', None) in _voice_memo_l]

        for k in _del_keys:

            del _new_ringtones[k]

        results['ringtone']=_new_ringtones

        return com_lgvx4400.Phone.saveringtones(self, results, merge)

	def savephonebook(self, data):

        "Saves out the phonebook"

        res=com_lgvx4400.Phone.savephonebook(self, data)

        pbook=res.get('phonebook', {})

        wallpaper_index=res.get('wallpaper-index', {})

        r1={}

        for k,e in pbook.items():

            r1[e['bitpimserial']['id']]={ 'wallpaper': \
                                          self._findmediainindex(wallpaper_index,
                                                                 e['wallpaper'],
                                                                 e['name'],
                                                                 'wallpaper'),
                                          'group': e['group'] }

        serialupdates=data.get("serialupdates", [])

        r2={}

        for bps, serials in serialupdates:

            r2[serials['serial1']]=r1[bps['id']]

        if self._update_wallpaper_index(r2):

            data["rebootphone"]=True

        return res

	def _update_wallpaper_index(self, wpi):

        buf=prototypes.buffer(self.getfilecontents(
            self.protocolclass.pb_file_name))

        pb=self.protocolclass.pbfile()

        pb.readfrombuffer(buf)

        update_flg=False

        for e in pb.items:

            _info=wpi.get(e.serial1, None)

            if _info:

                wp=_info.get('wallpaper', None)

                if wp is not None and wp!=e.wallpaper:

                    update_flg=True

                    e.wallpaper=wp

                gr=_info.get('group', None)

                if gr is not None and gr!=e.group:

                    update_flg=True

                    e.group=gr

        if update_flg:

            self.log('Updating wallpaper index')

            buf=prototypes.buffer()

            pb.writetobuffer(buf)

            self.writefile(self.protocolclass.pb_file_name, buf.getvalue())

        return update_flg

	_call_history_info={
        call_history.CallHistoryEntry.Folder_Incoming: protocolclass.incoming_call_file,
        call_history.CallHistoryEntry.Folder_Outgoing: protocolclass.outgoing_call_file,
        call_history.CallHistoryEntry.Folder_Missed: protocolclass.missed_call_file
        }
	    def getcallhistory(self, result):

        res={}

        for _folder, _file_name in Phone._call_history_info.items():

            try:

                buf=prototypes.buffer(self.getfilecontents(_file_name))

                hist_file=self.protocolclass.callhistoryfile()

                hist_file.readfrombuffer(buf)

                for i in range(hist_file.itemcount):

                    hist_call=hist_file.items[i]

                    entry=call_history.CallHistoryEntry()

                    entry.folder=_folder

                    entry.datetime=hist_call.datetime

                    entry.number=hist_call.number

                    entry.name=hist_call.name

                    if _folder!=call_history.CallHistoryEntry.Folder_Missed:

                        entry.duration=hist_call.duration

                    res[entry.id]=entry

            except com_brew.BrewNoSuchFileException:

                pass

        result['call_history']=res

        return result

	def _setquicktext(self, result):

        canned_file=Phone.SMSCannedFile()

        canned_file.set_sms_canned_data(result.get('canned_msg', []))

        buf=prototypes.buffer()

        canned_file.writetobuffer(buf)

        self.writefile(self.protocolclass.sms_canned_file, buf.getvalue())

	def _getquicktext(self):

        try:

            buf=prototypes.buffer(self.getfilecontents(
                self.protocolclass.sms_canned_file))

            canned_file=Phone.SMSCannedFile()

            canned_file.readfrombuffer(buf)

            return canned_file.get_sms_canned_data()

        except:

            if __debug__:

                raise

            return []

	my_model='VX4650'
	class  SMSCannedFile (protocolclass.SMSCannedFile) :
		def __init__(self, *args, **kwargs):

            Phone.protocolclass.SMSCannedFile.__init__(self, *args, **kwargs)

		def get_sms_canned_data(self):

            return [{ 'text': e.text,
                      'type': sms.CannedMsgEntry.user_type } for e in self.items]

		def set_sms_canned_data(self, canned_list):

            msg_lst=[x['text'] for x in canned_list \
                     if x['type']==sms.CannedMsgEntry.user_type]

            item_count=min(Phone.protocolclass.SMS_CANNED_MAX_ITEMS, len(msg_lst))

            for i in range(item_count):

                entry=Phone.protocolclass.SMSCannedMsg()

                entry.text=msg_lst[i]

                self.items.append(entry)

            entry=Phone.protocolclass.SMSCannedMsg()

            entry.text=''

            for i in range(item_count, Phone.protocolclass.SMS_CANNED_MAX_ITEMS):

                self.items.append(entry)


	def _get_phone_number(self):

        s=''

        try:

            buf=self.getfilecontents('nvm/nvm/nvm_0000')

            ofs=0x240

            if buf[ofs]=='\x01':

                ofs+=1

                while buf[ofs]!='\x01':

                    s+=buf[ofs]

                    ofs+=1

        except:

            if __debug__:

                raise

        return s

	def getphoneinfo(self, phone_info):

        try:

            if self.getfilecontents(self.brew_version_file)[:len(self.my_model)]==self.my_model:

                phone_info.model=self.my_model

                phone_info.manufacturer=Profile.phone_manufacturer

                phone_info.phone_number=self._get_phone_number()

                phone_info.firmware_version=self.getfirmwareinformation().firmwareversion

                phone_info.esn=self.get_esn()

        except:

            if __debug__:

                raise

	"Talk to the LG VX4650 cell phone"
parentprofile=com_lgvx4400.Profile
class  Profile (parentprofile) :
	protocolclass=Phone.protocolclass
	    serialsname=Phone.serialsname
	    WALLPAPER_WIDTH=128
	    WALLPAPER_HEIGHT=128
	    MAX_WALLPAPER_BASENAME_LENGTH=19
	    WALLPAPER_FILENAME_CHARS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ."
	    WALLPAPER_CONVERT_FORMAT="bmp"
	    MAX_RINGTONE_BASENAME_LENGTH=19
	    RINGTONE_FILENAME_CHARS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ."
	    BP_Calendar_Version=3
	    phone_manufacturer='LG Electronics Inc'
	    phone_model='VX4650'
	    imageorigins={}
	    imageorigins.update(common.getkv(parentprofile.stockimageorigins, "images"))
	    def GetImageOrigins(self):

        return self.imageorigins

	imagetargets={}
	    imagetargets.update(common.getkv(parentprofile.stockimagetargets, "wallpaper",
                                      {'width': 128, 'height': 114, 'format': "JPEG"}))
	    imagetargets.update(common.getkv(parentprofile.stockimagetargets, "fullscreen",
                                      {'width': 128, 'height': 128, 'format': "JPEG"}))
	    def GetTargetsForImageOrigin(self, origin):

        return self.imagetargets

	_supportedsyncs=(
        ('phonebook', 'read', None),  
        ('calendar', 'read', None),   
        ('wallpaper', 'read', None),  
        ('ringtone', 'read', None),   
        ('phonebook', 'write', 'OVERWRITE'),  
        ('calendar', 'write', 'OVERWRITE'),   
        ('wallpaper', 'write', 'MERGE'),      
        ('wallpaper', 'write', 'OVERWRITE'),
        ('ringtone', 'write', 'MERGE'),      
        ('ringtone', 'write', 'OVERWRITE'),
        ('memo', 'read', None),     
        ('memo', 'write', 'OVERWRITE'),  
        ('call_history', 'read', None),
        ('sms', 'read', None),
        ('sms', 'write', 'OVERWRITE'),
       )
	    def __init__(self):

        parentprofile.__init__(self)

	    imageorigins.update(common.getkv(parentprofile.stockimageorigins, "images"))
	    imagetargets.update(common.getkv(parentprofile.stockimagetargets, "wallpaper",
                                      {'width': 128, 'height': 114, 'format': "JPEG"}))
	    imagetargets.update(common.getkv(parentprofile.stockimagetargets, "fullscreen",
                                      {'width': 128, 'height': 128, 'format': "JPEG"}))