⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmibookutils.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
        for ( i =0; i < PHB_name_len; i+=2 ) //work out string length
        {
            if ( phbk->edt_buf_name[i] == 0 && phbk->edt_buf_name[i+1] == 0 )
            {
                if ( i== 0 )
                    actual_length =0;
                else
                    actual_length = i -2;
                break;
            }
        }
        phbk->edt_buf_name[0] = (UBYTE)(actual_length/2);//add string length to beginning of string
        phbk->edt_buf_name[1] = 0x00;

        memset(phbk->newEntry.name.data, 0, PHB_name_len);
        //convert to SIM string
        mfw_Ucs2SIMStr( MFW_DCS_UCS2 , (U16*)phbk->edt_buf_name, PHB_name_len,
                        phbk->newEntry.name.data, &phbk->newEntry.name.len );
        TRACE_EVENT(    (char*)phbk->newEntry.name.data);
        //phbk->newEntry.name.len = actual_length;
        sprintf(debug, "length:%d", phbk->newEntry.name.len);
        TRACE_EVENT(debug);
    }
    else
#endif
        mfw_Gsm2SIMStr( MFW_DCS_7bits, (U16*)phbk->edt_buf_name, PHB_name_len,
                        phbk->newEntry.name.data, &phbk->newEntry.name.len );   

#else

    strncpy( (char *)phbk->newEntry.name, (char *)phbk->edt_buf_name, PHB_name_len );

#endif


    // update the number
    if ( phbk->edt_buf_name[0]==0x80 )
    {
        wstrncpy( (char *) phbk->newEntry.name.data,(char *) phbk->edt_buf_name,PHB_name_len);
        phbk->newEntry.name.len=wstrlen((char *) phbk->edt_buf_name);
    }
    else
    {
        strncpy( (char *) phbk->newEntry.name.data,(char *) phbk->edt_buf_name, PHB_name_len );
        phbk->newEntry.name.len=wstrlen((char *)phbk->edt_buf_name);
        sprintf(temp,"Store Name:%s",phbk->newEntry.name.data);
        TRACE_EVENT(temp);
    }

    strncpy( (char *) phbk->newEntry.number, (char *) phbk->edt_buf_number, PHB_number_len );
    //phbk->newEntry.book = phbk->current.status.book; //JVJE We can only store in ADN/FDN 
    phbk->newEntry.book = bookActiveBook(WRITE);
    phbk->newEntry.index = 0;

    /* Add the name/number combination to the phone book and setup
       the current text status string
    */
    switch ( addName( phbk->newEntry.book, &phbk->newEntry, &phbk->current.status ) )
    {
    case MFW_PHB_OK :
        {
            /* Entry saved okay
            */
            MmiBookSetCurrentText( TxtAddSucceed);
            GetSIMData();           
        }
        break;

    case MFW_PHB_FULL :
        {
            /* Phone book full
            */
            MmiBookSetCurrentText( TxtPhbkFull  );
        }
        break;

    case MFW_PHB_FAIL :
        {
            /* Write failure
            */
            MmiBookSetCurrentText( TxtWriteError  );
        }
        break;

    default:
        {
            /* No other returns possible
            */
        }
        break;
    }
}


/*******************************************************************************

 $Function:    	changeInFile

 $Description:	change the phone book entry
 
 $Returns:		none

 $Arguments:	phbk, pointer to phonebook structure
 
*******************************************************************************/

int changeInFile( T_phbk *phbk )
{   
    char temp[100];
    int NewIndex,i;

    NewIndex=-1;
    TRACE_FUNCTION( "changeInFile()" );

    if ( phbk->current.status.book == PHB_ADN_FDN )
        phbk->current.status.book = PHB_ADN;    //JVJE We can only store in ADN/FDN 
    else
        phbk->current.status.book = phbk->current.status.book;

    TRACE_EVENT_P1("Current Book = %d", phbk->current.status.book);
    TRACE_EVENT_P1("Current Name = %s",  phbk->current.selectedName);
    TRACE_EVENT_P1("Current Buf Name = %s", phbk->edt_buf_name);

// update the number        
    strncpy( (char *) phbk->current.entry[ phbk->current.selectedName ].number,
             (char *) phbk->edt_buf_number, PHB_name_len );

    if ( phbk->edt_buf_name[0] == 0x80 )
    {
        wstrncpy( (char *) phbk->current.entry[ phbk->current.selectedName].name.data,        
                  (char *) phbk->edt_buf_name,PHB_name_len);
        phbk->current.entry[phbk->current.selectedName].name.len=wstrlen((char *) phbk->edt_buf_name);
    }
    else
    {
        strncpy( (char *) phbk->current.entry[ phbk->current.selectedName ].name.data,
                 (char *) phbk->edt_buf_name, PHB_name_len );
        phbk->current.entry[phbk->current.selectedName].name.len=strlen((char *)phbk->edt_buf_name);      
    }

    // Add the name/number combination to the phone book and setup the current text status string   


    if ( phbk->BufferTable==GlobalTable )
    {
        TRACE_EVENT("GlobalTable");
        phbk->current.entry[phbk->current.selectedName].index=l_phb_index[l_phb_sort_index[phbk->phbk->select_index].index].index;
    }
    else if ( phbk->BufferTable==SearchTable )
    {
        TRACE_EVENT("SearchTable");
        phbk->current.entry[phbk->current.selectedName].index=l_phb_index[bookname[phbk->phbk->select_index].index].index;
    }

    switch ( changeName( phbk->current.status.book,&phbk->current.entry[ phbk->current.selectedName ], 
                         &phbk->current.status ) )
    {
    case MFW_PHB_OK :
        {
            // Entry saved okay            
            MmiBookSetCurrentText( TxtEditSucceed );

            if ( phbk->BufferTable==GlobalTable )
            {
                if ( phbk->edt_buf_name[0] == 0x80 )
                {
                    wstrncpy( (char *) l_phb_index[l_phb_sort_index[phbk->phbk->select_index].index].name,        
                              (char *) phbk->edt_buf_name,PHB_name_len);
                    l_phb_index[l_phb_sort_index[phbk->phbk->select_index].index].number[0]=GetShortNumber((char *) phbk->edt_buf_number);
                    CompressNum((char *) phbk->edt_buf_number,SimNumber[l_phb_sort_index[phbk->phbk->select_index].index-ALL_NVM_LIST]);
                    l_phb_sort_index[phbk->phbk->select_index].name=GetShortName(phbk->edt_buf_name);
                }
                else
                {
                    strncpy( (char *) l_phb_index[l_phb_sort_index[phbk->phbk->select_index].index].name,
                             (char *) phbk->edt_buf_name, PHB_name_len );
                    l_phb_index[l_phb_sort_index[phbk->phbk->select_index].index].number[0]=GetShortNumber((char *) phbk->edt_buf_number);
                    CompressNum((char *) phbk->edt_buf_number,SimNumber[l_phb_sort_index[phbk->phbk->select_index].index-ALL_NVM_LIST]);
                    l_phb_sort_index[phbk->phbk->select_index].name=GetShortName(phbk->edt_buf_name);
                }
                NewIndex=SetLocation(l_phb_sort_index,phbk->phbk->select_index);//reset location
                sprintf(temp,"NewIndex:%d",NewIndex);
                TRACE_EVENT(temp);
                sprintf(temp,"Search_win:%d;%d",(int *)phbk->search_win,(int *)phbk->phbk->search_win);
                TRACE_EVENT(temp);
            }
            else if ( phbk->BufferTable==SearchTable )
            {
                if ( phbk->edt_buf_name[0] == 0x80 )
                {
                    wstrncpy( (char *) l_phb_index[bookname[phbk->phbk->select_index].index].name,        
                              (char *) phbk->edt_buf_name,PHB_name_len);
                    l_phb_index[bookname[phbk->phbk->select_index].index].number[0]=GetShortNumber((char *) phbk->edt_buf_number);
                    CompressNum((char *) phbk->edt_buf_number,SimNumber[bookname[phbk->phbk->select_index].index-ALL_NVM_LIST]);
                    //bookname[phbk->phbk->select_index].name=GetShortName(phbk->edt_buf_name);
                    for ( i=0;i<ALL_NUMBER_LIST;i++ )
                    {
                        if ( l_phb_sort_index[i].index==bookname[phbk->phbk->select_index].index )
                        {
                            l_phb_sort_index[i].name=GetShortName(phbk->edt_buf_name);
                            break;
                        }
                    }
                }
                else
                {
                    strncpy( (char *) l_phb_index[bookname[phbk->phbk->select_index].index].name,
                             (char *) phbk->edt_buf_name, PHB_name_len );
                    l_phb_index[bookname[phbk->phbk->select_index].index].number[0]=GetShortNumber((char *) phbk->edt_buf_number);
                    CompressNum((char *) phbk->edt_buf_number,SimNumber[bookname[phbk->phbk->select_index].index-ALL_NVM_LIST]);
                    //bookname[phbk->phbk->select_index].name=GetShortName(phbk->edt_buf_name);
                    for ( i=0;i<ALL_NUMBER_LIST;i++ )
                    {
                        if ( l_phb_sort_index[i].index==bookname[phbk->phbk->select_index].index )
                        {
                            l_phb_sort_index[i].name=GetShortName(phbk->edt_buf_name);
                            break;
                        }
                    }
                }
                NewIndex=SetSearchLocation(bookname,phbk->phbk->select_index);//reset location
                sprintf(temp,"NewIndex:%d",NewIndex);
                TRACE_EVENT(temp);
                sprintf(temp,"Search_win:%d;%d",(int *)phbk->search_win,(int *)phbk->phbk->search_win);
                TRACE_EVENT(temp);
            }
        }
        break;
    case MFW_PHB_FAIL :
        {
            // Write failure            
            MmiBookSetCurrentText(  TxtWriteError );
        }
        break;

    default: break;
    }

    return NewIndex;    
}

/*******************************************************************************

 $Function:    	deleteFromFile

 $Description:	delete an entry from a phone book
 
 $Returns:		None

 $Arguments:	phbk, phone book handle,
                book, book to update,
 
*******************************************************************************/

void deleteFromFile( T_phbk *phbk, UBYTE book )
{
    int index;
    TRACE_FUNCTION( "deleteFromFile()" );

    index = phbk->current.selectedName - phbk->current.missedCallsOffset;
    switch ( deleteName( book,
                         phbk->current.entry[index].index, &phbk->current.status ) )
    {
    case MFW_PHB_OK :
        {
            /* Entry saved okay
            */
            MmiBookSetCurrentText(  TxtEntryDeleted  );

#ifdef NO_ASCIIZ
            phbk->current.entry[index].name.len = 0;
            memset((char*)phbk->current.entry[index].number, '\0', PHB_name_len); 

#else
            memset((char*)phbk->current.entry[index].name, '\0', PHB_name_len);
            memset((char*)phbk->current.entry[index].number, '\0', PHB_number_len); 
#endif
            /* Move the current index to the next valid entry
            */
            if ( phbk->current.selectedName > 0 )
                phbk->current.selectedName --;
            else
                phbk->current.selectedName = 0;

            if ( phbk->current.index > 1 )
                phbk->current.index--;
            else
                phbk->current.index = 1;

            /* And if we have a search window, perform the search to
               update the current valid entry
            */
            if ( phbk->search_win )
            {
                bookGetCurrentStatus( &phbk->current.status );
                if ( ! phbk->current.status.used_entries )
                {
                    /* empty phone book
                    */
                    bookSearchDestroy( phbk->search_win );
                    phbk->search_win = 0;
                }
                else
                {
                    /* perform the search
                    */
                    SEND_EVENT( phbk->search_win, SEARCH_UPDATE, 0, 0 );
                }
            }
        }
        break;

    case MFW_PHB_FAIL :
        {
            /* Write failure
            */
            MmiBookSetCurrentText(  TxtWriteError );
        }
        break;

    default:
        {
            /* No other action required
            */
        }
        break;
    }
}

/*******************************************************************************
                                                                              
                                Public Methods
                                                                              
*******************************************************************************/




/*******************************************************************************

 $Function:    	bookCurrentWindow

 $Description:

   This returns the window handle associated with the current
   MFW element
 
 $Returns:		window handle of current MFW item

 $Arguments:	none.
 
*******************************************************************************/

tBookMfwHnd bookCurrentWindow( void )
{
    return mfwParent( mfwHeader() );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -