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

📄 finditemtestappappui.cpp

📁 这个代码实现了从一段字符提取手机号码、email、url等信息的功能。这个是symbian下实现的。
💻 CPP
字号:
/*
* ============================================================================
*  Name        : CFindItemTestAppAppUi from FindItemTestAppAppUi.cpp
*  Part of     : FindItemTestApp
*  Interface   : 
*  Description : Find Item Test application UI implementation
*  Version     : 
*
*  Copyright (c) 2002-2006 Nokia Corporation.
*  This material, including documentation and any related 
*  computer programs, is protected by copyright controlled by 
*  Nokia Corporation.
* ============================================================================
*/

// INCLUDE FILES
#include <aknNoteWrappers.h>
#include <eikmenup.h>
#include <avkon.hrh>
#include <aknselectionlist.h>
#include <barsread.h>  // for TResourceReader
#include "FindItemTestAppAppUi.h"
#include "FindItemTestAppContainer.h" 
#include "FindItemTestApp.hrh"

// CONSTANTS
_LIT(KInstructionsText, "Press options, look at the menu opened and select 'Example text' to see text used in the application or select test case to find items from the example text.");

			
// ================= MEMBER FUNCTIONS =======================
//

// ----------------------------------------------------------
// CFindItemTestAppAppUi::ConstructL
// Symbian 2nd phase constructor can leave.
// ----------------------------------------------------------
//
void CFindItemTestAppAppUi::ConstructL()
    {
    BaseConstructL(CAknAppUi::EAknEnableSkin);
    iAppContainer = new (ELeave) CFindItemTestAppContainer;
    iAppContainer->SetMopParent(this);
    iAppContainer->ConstructL( ClientRect() );
    iUsageStarted = EFalse;
    AddToStackL( iAppContainer );
	//_LIT(KExampleText, "Mail to me@someplace.com or call 040 1234567 or 123 123. You can also tune in to audio feed at rtsp://someplace.com/somefeed.ra.");
	_LIT(KExampleText, "010101001010101010100123123123123123sadasdasdasffdf3434343432000100101001001010010001");
	iStrSomeText = KExampleText;
	iAppContainer->AddMessageL( KInstructionsText );
    }

// ----------------------------------------------------
// CFindItemTestAppAppUi::~CFindItemTestAppAppUi
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
CFindItemTestAppAppUi::~CFindItemTestAppAppUi()
    {
    if (iAppContainer)
        {
        RemoveFromStack( iAppContainer );
        delete iAppContainer;
        } 
    }

// ------------------------------------------------------------------------------
//  CFindItemTestAppAppUi::::DynInitMenuPaneL
//  This function is called by the EIKON framework just before it displays
//  a menu pane. Its default implementation is empty, and by overriding it,
//  the application can set the state of menu items dynamically according
//  to the state of application data.
// ------------------------------------------------------------------------------
//
void CFindItemTestAppAppUi::DynInitMenuPaneL(
    TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/)
    {

	}

// ----------------------------------------------------
// CFindItemTestAppAppUi::HandleKeyEventL
// Pass key event to app container
// ----------------------------------------------------
//
TKeyResponse CFindItemTestAppAppUi::HandleKeyEventL(
    const TKeyEvent& aKeyEvent,TEventCode aType)
    {
    return iAppContainer->OfferKeyEventL( aKeyEvent, aType );
    }

// ----------------------------------------------------
// CFindItemTestAppAppUi::HandleCommandL
// Handle command entered by user
// ----------------------------------------------------
//
void CFindItemTestAppAppUi::HandleCommandL(TInt aCommand)
    {
    TInt err(KErrNone);
    switch ( aCommand )
        {
        case EAknSoftkeyBack:
            {
            if ( iUsageStarted )
                {
                iUsageStarted = EFalse;
                iAppContainer->ResetMessage();
                iAppContainer->AddMessageL( KInstructionsText );
                }
            else
                {
                Exit();
                }
            break;
            }
        	
        case EEikCmdExit:
            {
            Exit();
            break;
            }
        case EFindItemTestAppCmdExampleText:
            { 
            iUsageStarted = ETrue;
            iAppContainer->ResetMessage();
            iAppContainer->AddMessageL( iStrSomeText );
            break;
            }
        case EFindItemTestAppCmdPhoneNumber:
            {
            iUsageStarted = ETrue; 
            TRAP( err, SearchItemL(CFindItemEngine::EFindItemSearchPhoneNumberBin) );
            break;
            }
        case EFindItemTestAppCmdMailAddress:
            {
            iUsageStarted = ETrue;
            TRAP( err, SearchItemL(CFindItemEngine::EFindItemSearchMailAddressBin) );
            break;
            }            
        case EFindItemTestAppCmdURL:
            {
            iUsageStarted = ETrue;
            TRAP( err, SearchItemL(CFindItemEngine::EFindItemSearchURLBin) );
            break;
            }            
        case EFindItemTestAppCmdURI:
            {
            iUsageStarted = ETrue;
            TRAP( err, SearchItemL(CFindItemEngine::EFindItemSearchScheme) );
            break;
            }
        case EFindItemTestAppCmdSearchAll:
            {
            iUsageStarted = ETrue;
            TRAP( err, SearchAllItemsL() );
            break;
            }
        default:
            break;      
        }
    if( err != KErrNone )
        {
        TBuf<100> buf;
        _LIT(KErrTrapped, "Error Trapped = %d!!!");
        buf.Format( KErrTrapped );
        buf.Append( err );
        iAppContainer->AddMessageL( buf );
        }
    }
// =============================================================================
//                          FIND ITEM RELATED METHODS
// =============================================================================

// -----------------------------------------------------------------------------
// CFindItemTestAppAppUi::SearchItemL
// Search for selected items
// -----------------------------------------------------------------------------
//
void CFindItemTestAppAppUi::SearchItemL(CFindItemEngine::TFindItemSearchCase aTestCase)
    {
    // SFoundItem instance
	CFindItemEngine::SFoundItem item;
	
	// Create an instance of FindItemEngine and search for selected items.
	CFindItemEngine* singleSearch = CFindItemEngine::NewL(iStrSomeText, aTestCase);

	// Reset messages
	iAppContainer->ResetMessage();
	
	// Print message
	if( aTestCase == CFindItemEngine::EFindItemSearchPhoneNumberBin )
		{
		_LIT(KFoundPhoneNumbers, "Found phone numbers:");
		iAppContainer->AddMessageL( KFoundPhoneNumbers );
		}
	else if( aTestCase == CFindItemEngine::EFindItemSearchMailAddressBin )
		{
		_LIT(KFoundMailAddresses, "Found mail addresses:");
		iAppContainer->AddMessageL( KFoundMailAddresses );
		}
	else if( aTestCase == CFindItemEngine::EFindItemSearchURLBin )
		{
		_LIT(KFoundURLs, "Found URLs:");
		iAppContainer->AddMessageL( KFoundURLs );
		}
    else if( aTestCase == CFindItemEngine::EFindItemSearchScheme )
		{
		_LIT(KFoundURIs, "Found URIs:");
		iAppContainer->AddMessageL( KFoundURIs );
		}
	else
		{
		_LIT(KInvalidSearchCase, "Invalid search case");
		iAppContainer->AddMessageL( KInvalidSearchCase );
		}
    
    // Get count of found items
	TInt count(singleSearch->ItemCount());
	
    // Get currently selected item to the result variable
    // and print found items.
	singleSearch->Item(item);

	for( TInt i=0; i<count; i++)
		{
    	TPtrC16 result(iStrSomeText.Mid(item.iStartPos, item.iLength));
    	iAppContainer->AddMessageL(result);
    	singleSearch->NextItem(item);
		}
    
    // Deallocate memory
	delete singleSearch;
    
    } 

// ----------------------------------------------------
// CFindItemTestAppAppUi::SearchAllItemsL
// Search for all possible items
// ----------------------------------------------------
//
void CFindItemTestAppAppUi::SearchAllItemsL()
    {
	// SFoundItem instance
	CFindItemEngine::SFoundItem item;

	// Look for all possible things (cases work as binary mask)
	CFindItemEngine* multiSearch = CFindItemEngine::NewL(iStrSomeText, (CFindItemEngine::TFindItemSearchCase)
           (CFindItemEngine::EFindItemSearchPhoneNumberBin |           
            CFindItemEngine::EFindItemSearchURLBin | 
            CFindItemEngine::EFindItemSearchMailAddressBin | 
            CFindItemEngine::EFindItemSearchScheme));
	
	// Get count of found items
	TInt count(multiSearch->ItemCount());
	
	// Get currently selected item to the result variable
	multiSearch->Item(item);
	
	// Reset messages
	iAppContainer->ResetMessage();

	for( TInt i=0; i<count; i++)
		{
    	TPtrC16 result(iStrSomeText.Mid(item.iStartPos, item.iLength));
    	
    	// Print all found items and their type
        if ( item.iItemType == CFindItemEngine::EFindItemSearchPhoneNumberBin)
    	    {
    	    _LIT(KFoundPhoneNumber, "Found phone number:");
		    iAppContainer->AddMessageL( KFoundPhoneNumber );
    	    iAppContainer->AddMessageL(result);
    	    }
    	else if ( item.iItemType == CFindItemEngine::EFindItemSearchMailAddressBin )
    	    {
    	    _LIT(KFoundMailAddress, "Found mail address:");
		    iAppContainer->AddMessageL( KFoundMailAddress );
    	    iAppContainer->AddMessageL(result);
    	    }
    	else if ( item.iItemType == CFindItemEngine::EFindItemSearchURLBin )
    	    {
    	    _LIT(KFoundURL, "Found URL:");
		    iAppContainer->AddMessageL( KFoundURL );
    	    iAppContainer->AddMessageL(result);
    	    }
    	else if ( item.iItemType == CFindItemEngine::EFindItemSearchScheme )
    	    {
    	    _LIT(KFoundURI, "Found URI:");
		    iAppContainer->AddMessageL( KFoundURI );
    	    iAppContainer->AddMessageL(result);
    	    }
    	else
    	    {
    	    _LIT(KInvalidSearchCase, "Invalid search case");
		    iAppContainer->AddMessageL( KInvalidSearchCase );
    	    }
    	
    	// Move the selection to point to the next item
    	multiSearch->NextItem(item);
		}

	// Deallocate memory
	delete multiSearch;
	
    }

// End of File  

⌨️ 快捷键说明

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