📄 mmibookutils.c
字号:
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_MAX_LEN);
#else
/*MC SPR 1257, replacing PHB_MAX_LEN with MAX_ALPHA_LEN for name strings*/
memset((char*)phbk->current.entry[index].name, '\0', MAX_ALPHA_LEN);
memset((char*)phbk->current.entry[index].number, '\0', PHB_MAX_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;
}
}
/* SPR#1112 - SH - Internal phonebook use */
#ifdef INT_PHONEBOOK
/*******************************************************************************
$Function: bookChangePB
$Description: Change the phonebook
$Returns: None
$Arguments: None.
*******************************************************************************/
void bookChangePB(T_MFW_HND win, UBYTE identifier, UBYTE reason)
{
T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data;
T_phbk *Phbk = (T_phbk *) win_data->user;
GI_pb_SetPhonebook(identifier);
bookShowInfoScreen( Phbk->win, TxtPhonebook, TxtChanged, NULL, NULL, 3000);
return;
}
/*******************************************************************************
$Function: bookCopy
$Description: Copy or move a phonebook entry from one book to another
$Returns: status of change, or MWB_PHB_FAIL if an error occurs
$Arguments: entry - the entry to be moved or copied
srcStatus - Status information about the source phonebook
destStatus - Status information about the destination phonebook
move - TRUE if the original record is to be deleted
*******************************************************************************/
UBYTE bookCopy( T_MFW_PHB_ENTRY *entry, T_MFW_PHB_STATUS *destStatus, T_MFW_PHB_STATUS *srcStatus, UBYTE move )
{
T_MFW ret;
UBYTE srcIndex;
UBYTE srcBook;
TRACE_FUNCTION("bookCopy");
if (!destStatus->avail_entries)
{
/* There's no room in the destination phonebook to add the entry */
TRACE_EVENT("bookCopy: dest phonebook full");
return MFW_PHB_FULL;
}
srcIndex = entry->index;
entry->index = 0;
if (entry->name.len>destStatus->tag_len)
{
TRACE_EVENT("bookCopy: Alpha tag cropped");
entry->name.len = destStatus->tag_len;
entry->name.data[entry->name.len] = NULL;
}
ret = phb_store_entry( destStatus->book, entry, destStatus );
TRACE_EVENT_P2("bookCopy: phb_store_entry book %d result %d", destStatus->book, ret);
if (ret!=MFW_PHB_OK)
return ret;
/* Only try to delete the entry if we are moving an entry from one book
* to another. Don't try if it is an FDN entry */
TRACE_EVENT_P2("move %d, entry->book %d", move, entry->book);
if (move && entry->book!=PHB_FDN)
{
if (( srcStatus->book == PHB_UPN) || (srcStatus->book == PHB_FDN ))
srcBook = srcStatus->book;
else
srcBook = bookActiveBook(WRITE);
ret = phb_delete_entry(srcBook, srcIndex, srcStatus);
TRACE_EVENT_P3("bookCopy: phb_delete_entry book %d index %d result %d", srcStatus->book, srcIndex, ret);
}
TRACE_EVENT("bookCopy: leaving function");
return ret;
}
/*******************************************************************************
$Function: bookCopySingle
$Description: Copy or move a single phonebook entry
$Returns: None
$Arguments: None.
*******************************************************************************/
void bookCopySingle(T_MFW_HND win, UBYTE identifier, UBYTE reason)
{
T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data;
T_phbk *Phbk = (T_phbk *) win_data->user;
BOOL oldBook;
int txtId;
T_MFW_PHB_STATUS destStatus;
tMmiPhbData *current = &Phbk->phbk->current;
TRACE_FUNCTION("bookCopySingle");
oldBook = bookGetBookSelected();
bookSetBookSelected(!oldBook);
destStatus.book = bookActiveBook(WRITE);
bookGetCurrentStatus( &destStatus );
bookSetBookSelected(oldBook);
txtId = TxtStored;
if (destStatus.avail_entries)
{
switch (bookCopy(¤t->entry[current->selectedName], &destStatus, ¤t->status, identifier))
{
case MFW_PHB_OK:
txtId = TxtStored;
break;
case MFW_PHB_FULL:
txtId = TxtPhbkFull;
break;
default:
txtId = TxtFailed;
break;
}
}
else
{
txtId = TxtPhbkFull;
}
bookShowInformation( win, txtId, NULL, NULL );
if (identifier)
{
/* Destroy options menu and regenerate address list */
bookMenuDestroy(Phbk->menu_options_win);
if(Phbk->current.status.used_entries > 0)
SEND_EVENT(Phbk->search_win, SEARCH_SCROLL_UP, 0, 0 );
SEND_EVENT(Phbk->search_win, SEARCH_UPDATE, 0, (void*)Phbk->current.status.book );
}
return;
}
/*******************************************************************************
$Function: bookCopyMultiple
$Description: Copy or move multiple phonebook entries
$Returns: None
$Arguments: None.
*******************************************************************************/
void bookCopyMultiple(T_MFW_HND win, UBYTE move, UBYTE reason)
{
T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data;
T_phbk *Phbk = (T_phbk *) win_data->user;
UBYTE oldBook;
T_MFW_PHB_STATUS destStatus;
T_MFW_PHB_STATUS srcStatus;
T_MFW_PHB_LIST entries;
T_MFW_PHB_ENTRY entry;
UBYTE readIndex;
int txtId;
T_MFW_HND info_win;
static T_MFW_HND waitWin = NULL;
/* Set up some data */
TRACE_FUNCTION("bookCopyMultiple");
entries.entry = &entry;
srcStatus.book = bookActiveBook(WRITE);
bookGetCurrentStatus( &srcStatus );
oldBook = bookGetBookSelected();
bookSetBookSelected(!oldBook);
destStatus.book = bookActiveBook(WRITE);
bookGetCurrentStatus( &destStatus );
bookSetBookSelected(oldBook);
/* First time entering function, set up values.
* Store information so this function can be called again
* when the phonebook is ready */
if (ipbCopyIndex==0)
{
ipbCopyIndex = srcStatus.used_entries;
ipbWin = win;
ipbMove = move;
if (!bookGetBookSelected() && !move)
{
/* We need to drop out of this function briefly in order to get the dialog to display
* for this particular case! Show info screen very briefly, which calls this function as
* a callback. The info screen remains until we drop out of this function a second
* time */
waitWin = NULL;
bookShowInfoScreen( Phbk->win, TxtPleaseWait, NULL, (T_VOID_FUNC)bookCopyMultiple, NULL, 100);
return;
}
waitWin = bookShowInfoScreen( Phbk->win, TxtPleaseWait, NULL, NULL, NULL, FOREVER);
}
TRACE_EVENT_P1("Entries in list: %d", srcStatus.used_entries);
/* For special case where SIM will give no E_PHB_READY response, the
* do...while operates as a loop below. Otherwise, it will only go through
* once, and this function will be called repeatedly every E_PHB_READY */
do
{
txtId = TxtStored;
if (!destStatus.avail_entries)
{
txtId = TxtPhbkFull;
}
else if (ipbCopyIndex==0)
{
txtId = TxtEmpty;
}
else
{
/* For moving, always delete first entry alphabetically, list moves down.
* For copying, move through the list */
if (move)
readIndex = 1;
else
readIndex = ipbCopyIndex;
TRACE_EVENT_P1("Moving entry %d", readIndex);
/* Read in entry and copy/move it */
phb_read_entries(srcStatus.book, readIndex, MFW_PHB_ALPHA, 1, &entries);
switch (bookCopy(entries.entry, &destStatus, &srcStatus, move))
{
case MFW_PHB_OK:
txtId = TxtStored;
break;
case MFW_PHB_FULL:
txtId = TxtPhbkFull;
break;
default:
txtId = TxtFailed;
break;
}
ipbCopyIndex--;
}
}/* Is a loop in special case - see above */
while (!bookGetBookSelected() && !move && txtId==TxtStored && ipbCopyIndex>0);
/* If we've finished, or an error has occurred, show info dialog */
if (ipbCopyIndex==0 || txtId!=TxtStored)
{
ipbCopyIndex = 0;
/* Destroy the Please Wait window and show the result message */
bookShowInformation( win, txtId, NULL, NULL );
if (waitWin)
{
SEND_EVENT(waitWin, DIALOG_DESTROY,0,0);
}
if (move)
{
/* Destroy options menu and regenerate address list */
bookMenuDestroy(Phbk->menu_options_win);
bookGetCurrentStatus( &Phbk->current.status );
if(Phbk->current.status.used_entries > 0)
{
SEND_EVENT(Phbk->search_win, SEARCH_SCROLL_UP, 0, 0 );
SEND_EVENT(Phbk->search_win, SEARCH_UPDATE, 0, (void*)Phbk->current.status.book );
}
else
bookSearchDestroy(Phbk->search_win);
}
}
return;
}
#endif
/*******************************************************************************
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() );
}
/*******************************************************************************
$Function: bookDefaultCallBack
$Description:
This is a simple call back function which is invoked when
a not implemented dialog is displayed. We don't want anyone
outside of this module using it so define it as static,
this will still be callable from the info dialogs as it
will use the reference we set up.
$Returns: zero, always
$Arguments: win, parent window
identifier, of the window
reason, for the window
*******************************************************************************/
static tBookStatus bookDefaultCallBack( tBookMfwHnd win, UBYTE identifier, UBYTE reason )
{
if ( win )
winShow( win );
return 0;
}
/*******************************************************************************
$Function: bookWindowData
$Description:
This routine is designed to be invoked from within a menu
handler or call back function and will return a pointer to
the window data associated with the current MFW element.
$Returns: pointer to the data area
$Arguments: none.
*******************************************************************************/
void *bookWindowData( void )
{
tBookMfwHnd WinPtr;
if ( ( WinPtr = bookCurrentWindow() ) == NULL )
return (void *) NULL;
return (void *)((tBookMfwHdr *) WinPtr)->data;
}
/*******************************************************************************
$Function: bookMenuSelectedNumber
$Description:
This will return the currently selected entry in the phone
book, when the routine is being called from a menu handler
$Returns: pointer to the selected number buffer
$Arguments: none.
*******************************************************************************/
char *bookMenuSelectedNumber( void )
{
tBookMfwHnd WinData;
/* Have we got a valid window ?
*/
if ( ( WinData = (tBookMfwHnd) bookWindowData() ) == NULL )
return NULL;
return NULL;
}
/*******************************************************************************
$Function: bookPhoneBookLoading
$Description: access routine for the local static menu area
Utility functions to determine if the phone book is
still in the loading state
$Returns: BOOK_FAILURE if loading, otherwise BOOK_SUCCESS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -