S60 3rd Edition SDK for Symbian OS
Example Applications Guide

FindItemTestAppAppUi.cpp

00001 /*
00002 * ============================================================================
00003 *  Name        : CFindItemTestAppAppUi from FindItemTestAppAppUi.cpp
00004 *  Part of     : FindItemTestApp
00005 *  Interface   : 
00006 *  Description : Find Item Test application UI implementation
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2002-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ============================================================================
00014 */
00015 
00016 // INCLUDE FILES
00017 #include <aknNoteWrappers.h>
00018 #include <eikmenup.h>
00019 #include <avkon.hrh>
00020 #include <aknselectionlist.h>
00021 #include <barsread.h>  // for TResourceReader
00022 #include "FindItemTestAppAppUi.h"
00023 #include "FindItemTestAppContainer.h" 
00024 #include "FindItemTestApp.hrh"
00025 
00026 // CONSTANTS
00027 _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.");
00028 
00029                         
00030 // ================= MEMBER FUNCTIONS =======================
00031 //
00032 
00033 // ----------------------------------------------------------
00034 // CFindItemTestAppAppUi::ConstructL
00035 // Symbian 2nd phase constructor can leave.
00036 // ----------------------------------------------------------
00037 //
00038 void CFindItemTestAppAppUi::ConstructL()
00039     {
00040     BaseConstructL(CAknAppUi::EAknEnableSkin);
00041     iAppContainer = new (ELeave) CFindItemTestAppContainer;
00042     iAppContainer->SetMopParent(this);
00043     iAppContainer->ConstructL( ClientRect() );
00044     iUsageStarted = EFalse;
00045     AddToStackL( iAppContainer );
00046     _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.");
00047         iStrSomeText = KExampleText;
00048         iAppContainer->AddMessageL( KInstructionsText );
00049     }
00050 
00051 // ----------------------------------------------------
00052 // CFindItemTestAppAppUi::~CFindItemTestAppAppUi
00053 // Destructor
00054 // Frees reserved resources
00055 // ----------------------------------------------------
00056 //
00057 CFindItemTestAppAppUi::~CFindItemTestAppAppUi()
00058     {
00059     if (iAppContainer)
00060         {
00061         RemoveFromStack( iAppContainer );
00062         delete iAppContainer;
00063         } 
00064     }
00065 
00066 // ------------------------------------------------------------------------------
00067 //  CFindItemTestAppAppUi::::DynInitMenuPaneL
00068 //  This function is called by the EIKON framework just before it displays
00069 //  a menu pane. Its default implementation is empty, and by overriding it,
00070 //  the application can set the state of menu items dynamically according
00071 //  to the state of application data.
00072 // ------------------------------------------------------------------------------
00073 //
00074 void CFindItemTestAppAppUi::DynInitMenuPaneL(
00075     TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/)
00076     {
00077 
00078         }
00079 
00080 // ----------------------------------------------------
00081 // CFindItemTestAppAppUi::HandleKeyEventL
00082 // Pass key event to app container
00083 // ----------------------------------------------------
00084 //
00085 TKeyResponse CFindItemTestAppAppUi::HandleKeyEventL(
00086     const TKeyEvent& aKeyEvent,TEventCode aType)
00087     {
00088     return iAppContainer->OfferKeyEventL( aKeyEvent, aType );
00089     }
00090 
00091 // ----------------------------------------------------
00092 // CFindItemTestAppAppUi::HandleCommandL
00093 // Handle command entered by user
00094 // ----------------------------------------------------
00095 //
00096 void CFindItemTestAppAppUi::HandleCommandL(TInt aCommand)
00097     {
00098     TInt err(KErrNone);
00099     switch ( aCommand )
00100         {
00101         case EAknSoftkeyBack:
00102             {
00103             if ( iUsageStarted )
00104                 {
00105                 iUsageStarted = EFalse;
00106                 iAppContainer->ResetMessage();
00107                 iAppContainer->AddMessageL( KInstructionsText );
00108                 }
00109             else
00110                 {
00111                 Exit();
00112                 }
00113             break;
00114             }
00115                 
00116         case EEikCmdExit:
00117             {
00118             Exit();
00119             break;
00120             }
00121         case EFindItemTestAppCmdExampleText:
00122             { 
00123             iUsageStarted = ETrue;
00124             iAppContainer->ResetMessage();
00125             iAppContainer->AddMessageL( iStrSomeText );
00126             break;
00127             }
00128         case EFindItemTestAppCmdPhoneNumber:
00129             {
00130             iUsageStarted = ETrue; 
00131             TRAP( err, SearchItemL(CFindItemEngine::EFindItemSearchPhoneNumberBin) );
00132             break;
00133             }
00134         case EFindItemTestAppCmdMailAddress:
00135             {
00136             iUsageStarted = ETrue;
00137             TRAP( err, SearchItemL(CFindItemEngine::EFindItemSearchMailAddressBin) );
00138             break;
00139             }            
00140         case EFindItemTestAppCmdURL:
00141             {
00142             iUsageStarted = ETrue;
00143             TRAP( err, SearchItemL(CFindItemEngine::EFindItemSearchURLBin) );
00144             break;
00145             }            
00146         case EFindItemTestAppCmdURI:
00147             {
00148             iUsageStarted = ETrue;
00149             TRAP( err, SearchItemL(CFindItemEngine::EFindItemSearchScheme) );
00150             break;
00151             }
00152         case EFindItemTestAppCmdSearchAll:
00153             {
00154             iUsageStarted = ETrue;
00155             TRAP( err, SearchAllItemsL() );
00156             break;
00157             }
00158         default:
00159             break;      
00160         }
00161     if( err != KErrNone )
00162         {
00163         TBuf<100> buf;
00164         _LIT(KErrTrapped, "Error Trapped = %d!!!");
00165         buf.Format( KErrTrapped );
00166         buf.Append( err );
00167         iAppContainer->AddMessageL( buf );
00168         }
00169     }
00170 // =============================================================================
00171 //                          FIND ITEM RELATED METHODS
00172 // =============================================================================
00173 
00174 // -----------------------------------------------------------------------------
00175 // CFindItemTestAppAppUi::SearchItemL
00176 // Search for selected items
00177 // -----------------------------------------------------------------------------
00178 //
00179 void CFindItemTestAppAppUi::SearchItemL(CFindItemEngine::TFindItemSearchCase aTestCase)
00180     {
00181     // SFoundItem instance
00182         CFindItemEngine::SFoundItem item;
00183         
00184         // Create an instance of FindItemEngine and search for selected items.
00185         CFindItemEngine* singleSearch = CFindItemEngine::NewL(iStrSomeText, aTestCase);
00186 
00187         // Reset messages
00188         iAppContainer->ResetMessage();
00189         
00190         // Print message
00191         if( aTestCase == CFindItemEngine::EFindItemSearchPhoneNumberBin )
00192                 {
00193                 _LIT(KFoundPhoneNumbers, "Found phone numbers:");
00194                 iAppContainer->AddMessageL( KFoundPhoneNumbers );
00195                 }
00196         else if( aTestCase == CFindItemEngine::EFindItemSearchMailAddressBin )
00197                 {
00198                 _LIT(KFoundMailAddresses, "Found mail addresses:");
00199                 iAppContainer->AddMessageL( KFoundMailAddresses );
00200                 }
00201         else if( aTestCase == CFindItemEngine::EFindItemSearchURLBin )
00202                 {
00203                 _LIT(KFoundURLs, "Found URLs:");
00204                 iAppContainer->AddMessageL( KFoundURLs );
00205                 }
00206     else if( aTestCase == CFindItemEngine::EFindItemSearchScheme )
00207                 {
00208                 _LIT(KFoundURIs, "Found URIs:");
00209                 iAppContainer->AddMessageL( KFoundURIs );
00210                 }
00211         else
00212                 {
00213                 _LIT(KInvalidSearchCase, "Invalid search case");
00214                 iAppContainer->AddMessageL( KInvalidSearchCase );
00215                 }
00216     
00217     // Get count of found items
00218         TInt count(singleSearch->ItemCount());
00219         
00220     // Get currently selected item to the result variable
00221     // and print found items.
00222         singleSearch->Item(item);
00223 
00224         for( TInt i=0; i<count; i++)
00225                 {
00226         TPtrC16 result(iStrSomeText.Mid(item.iStartPos, item.iLength));
00227         iAppContainer->AddMessageL(result);
00228         singleSearch->NextItem(item);
00229                 }
00230     
00231     // Deallocate memory
00232         delete singleSearch;
00233     
00234     } 
00235 
00236 // ----------------------------------------------------
00237 // CFindItemTestAppAppUi::SearchAllItemsL
00238 // Search for all possible items
00239 // ----------------------------------------------------
00240 //
00241 void CFindItemTestAppAppUi::SearchAllItemsL()
00242     {
00243         // SFoundItem instance
00244         CFindItemEngine::SFoundItem item;
00245 
00246         // Look for all possible things (cases work as binary mask)
00247         CFindItemEngine* multiSearch = CFindItemEngine::NewL(iStrSomeText, (CFindItemEngine::TFindItemSearchCase)
00248            (CFindItemEngine::EFindItemSearchPhoneNumberBin |           
00249             CFindItemEngine::EFindItemSearchURLBin | 
00250             CFindItemEngine::EFindItemSearchMailAddressBin | 
00251             CFindItemEngine::EFindItemSearchScheme));
00252         
00253         // Get count of found items
00254         TInt count(multiSearch->ItemCount());
00255         
00256         // Get currently selected item to the result variable
00257         multiSearch->Item(item);
00258         
00259         // Reset messages
00260         iAppContainer->ResetMessage();
00261 
00262         for( TInt i=0; i<count; i++)
00263                 {
00264         TPtrC16 result(iStrSomeText.Mid(item.iStartPos, item.iLength));
00265         
00266         // Print all found items and their type
00267         if ( item.iItemType == CFindItemEngine::EFindItemSearchPhoneNumberBin)
00268             {
00269             _LIT(KFoundPhoneNumber, "Found phone number:");
00270                     iAppContainer->AddMessageL( KFoundPhoneNumber );
00271             iAppContainer->AddMessageL(result);
00272             }
00273         else if ( item.iItemType == CFindItemEngine::EFindItemSearchMailAddressBin )
00274             {
00275             _LIT(KFoundMailAddress, "Found mail address:");
00276                     iAppContainer->AddMessageL( KFoundMailAddress );
00277             iAppContainer->AddMessageL(result);
00278             }
00279         else if ( item.iItemType == CFindItemEngine::EFindItemSearchURLBin )
00280             {
00281             _LIT(KFoundURL, "Found URL:");
00282                     iAppContainer->AddMessageL( KFoundURL );
00283             iAppContainer->AddMessageL(result);
00284             }
00285         else if ( item.iItemType == CFindItemEngine::EFindItemSearchScheme )
00286             {
00287             _LIT(KFoundURI, "Found URI:");
00288                     iAppContainer->AddMessageL( KFoundURI );
00289             iAppContainer->AddMessageL(result);
00290             }
00291         else
00292             {
00293             _LIT(KInvalidSearchCase, "Invalid search case");
00294                     iAppContainer->AddMessageL( KInvalidSearchCase );
00295             }
00296         
00297         // Move the selection to point to the next item
00298         multiSearch->NextItem(item);
00299                 }
00300 
00301         // Deallocate memory
00302         delete multiSearch;
00303         
00304     }
00305 
00306 // End of File  

© Nokia 2006

Back to top