phoneuis/easydialing/tsrc/edta/src/edta_appview.cpp
branchRCL_3
changeset 3 8871b09be73b
equal deleted inserted replaced
2:c84cf270c54f 3:8871b09be73b
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Easy dialing test application.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <coemain.h>
       
    20 #include <aknutils.h>
       
    21 #include "edta_appview.h"
       
    22 #include "edta_debugprint.h"
       
    23 #include "edta_dummylistener.h"
       
    24 #include <aknnotewrappers.h>        
       
    25 
       
    26 // AVKON components
       
    27 #include <aknlists.h>
       
    28 #include <aknpopup.h>
       
    29 
       
    30 // Predictive search header files.
       
    31 #include <CPsSettings.h>
       
    32 #include <CPsQuery.h>
       
    33 #include <CPsQueryItem.h>
       
    34 #include <CPsClientData.h>
       
    35 #include <CPsPattern.h>
       
    36 #include <CPsRequestHandler.h>
       
    37 
       
    38 // Virtual phonebook header files.
       
    39 #include <VPbkContactStoreUris.h>
       
    40 #include <CVPbkContactStoreUriArray.h>
       
    41 #include <TVPbkContactStoreUriPtr.h>
       
    42 // contains virtual phonebook data fields
       
    43 #include <vpbkeng.rsg>
       
    44 
       
    45 // Phonebook engine API 
       
    46 #include <CPbkContactEngine.h>
       
    47 
       
    48 // CCA Launcher header files.
       
    49 #include <ccafactory.h>
       
    50 #include <mccaparameter.h>
       
    51 #include <mccaconnection.h>
       
    52 
       
    53 
       
    54 const TInt KEdtaMaximumMatchingCount = 100;
       
    55 const TInt KEdtaContactCompanyIndex = 2;
       
    56 const TInt KEdtaContactEmailHomeIndex = 3;
       
    57 const TInt KEdtaContactEmailWorkIndex = 4;
       
    58 const TInt KEdtaContactEmailGenIndex = 5;
       
    59 const TInt KEdtaListBoxGranularity = 5;
       
    60 
       
    61 
       
    62 // ============================ MEMBER FUNCTIONS ===============================
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // NewL
       
    66 // First phase constructor without cleanup stack.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CEdtaAppView* CEdtaAppView::NewL( const TRect& aRect )
       
    70     {
       
    71     CEdtaAppView* self = CEdtaAppView::NewLC( aRect );
       
    72     CleanupStack::Pop( self );
       
    73     return self;
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // NewLC
       
    78 // First phase constructor with cleanup stack.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CEdtaAppView* CEdtaAppView::NewLC( const TRect& aRect )
       
    82     {
       
    83     CEdtaAppView* self = new ( ELeave ) CEdtaAppView;
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL( aRect );
       
    86     return self;
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // ConstructL
       
    91 // Second phase constructor.
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CEdtaAppView::ConstructL( const TRect& aRect )
       
    95     {
       
    96     DebugPrintF(_L("CEdtaAppView::ConstructL enter, rect: %d, %d - %d, %d"), aRect.iTl.iX, aRect.iTl.iY, aRect.iBr.iX, aRect.iBr.iY  );
       
    97 
       
    98     // Create a window for this application view
       
    99     CreateWindowL();
       
   100 
       
   101     const TDesC& thname = RThread().Name();
       
   102     iScreenBuffer = CEdtaScreenTextBuffer::NewL( aRect );
       
   103     iScreenBuffer->SetFocus( ETrue );
       
   104     iScreenBuffer->WriteLineL(thname);
       
   105 
       
   106     LoadPluginL(); 
       
   107   
       
   108     DebugPrintF(_L("CEdtaAppView::ConstructL: iScreenBuffer: 0x%X, iEasyDialer: 0x%X"), iScreenBuffer, iEasyDialer );
       
   109 
       
   110     if (iEasyDialer) 
       
   111         {
       
   112         DebugPrintF(_L("CEdtaAppView::ConstructL: Easydialer plugin found, adding observer..") );
       
   113 
       
   114         iEasyDialer->AddObserverL( this );
       
   115         iEasyDialer->SetFocus( EFalse );
       
   116 
       
   117         DebugPrintF(_L("CEdtaAppView::ConstructL: Add observer done"));
       
   118         }
       
   119 
       
   120     // Init PCS Server..
       
   121     TRAPD( error, InitPredictiveContactSearchL());
       
   122     if( error )
       
   123         {
       
   124         DebugPrintF(_L("CEdtaAppView::ConstructL: Failed to load predictive search engine: %d"), error );
       
   125         iScreenBuffer->WriteLineL(_L("* PCS Server load fail: %d"), error );
       
   126         }
       
   127 
       
   128     // Init Communication Launcher..
       
   129     TRAP( error, iContactLauncher = TCCAFactory::NewConnectionL());
       
   130     if( error )
       
   131         {
       
   132         DebugPrintF(_L("CEdtaAppView::ConstructL: Failed connect communication launcher: %d"), error );
       
   133         iScreenBuffer->WriteLineL(_L("* CCA open fail: %d"), error );
       
   134         }
       
   135         
       
   136     iDummyListener = new ( ELeave ) CDummyListener();
       
   137 
       
   138     // Set the windows size
       
   139     SetRect( aRect );
       
   140     ActivateL();
       
   141 
       
   142     DebugPrintF(_L("CEdtaAppView::ConstructL exit"));
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CEdtaAppView
       
   147 // The C++ default constructor can NOT contain any code, that might leave.
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 CEdtaAppView::CEdtaAppView()
       
   151     {
       
   152     // No implementation here
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // ~CEdtaAppView
       
   157 // The destructor.
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 CEdtaAppView::~CEdtaAppView()
       
   161     {
       
   162     DebugPrintF(_L("CEdtaAppView::~CEdtaAppView enter, iEasyDialer: 0x%x"), iEasyDialer );
       
   163     
       
   164     delete iDummyListener;
       
   165 
       
   166     if (iEasyDialer)
       
   167         {
       
   168         iEasyDialer->RemoveObserver( this );
       
   169         }
       
   170 
       
   171     if (iPredictiveContactSearchHandler)
       
   172         {
       
   173         iPredictiveContactSearchHandler->RemoveObserver(this);
       
   174         }
       
   175 
       
   176     delete iEasyDialer;
       
   177     iContactNames.ResetAndDestroy();
       
   178     iMatchingContactLinks.ResetAndDestroy();
       
   179 
       
   180     if (iContactLauncher)
       
   181         {
       
   182         iContactLauncher->Close();
       
   183         }
       
   184 
       
   185     delete iPredictiveSearchQuery;
       
   186     delete iContactManager;
       
   187     delete iPredictiveContactSearchHandler;
       
   188     delete iContactStoreUriArray;
       
   189     iContactDataStores.ResetAndDestroy();
       
   190 
       
   191     delete iScreenBuffer;
       
   192     DebugPrintF(_L("CEdtaAppView::~CEdtaAppView exit"));
       
   193     }
       
   194 
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // Draw
       
   198 // Draw itself. Clear the canvas.
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 
       
   202 void CEdtaAppView::Draw( const TRect& aRect ) const
       
   203     {
       
   204     DebugPrintF(_L("CEdtaAppView::Draw, rect: %d, %d - %d, %d"), aRect.iTl.iX, aRect.iTl.iY, aRect.iBr.iX, aRect.iBr.iY );
       
   205 
       
   206     CWindowGc& gc = SystemGc();
       
   207     gc.SetClippingRect( aRect );
       
   208     
       
   209     gc.SetBrushColor( KRgbWhite );
       
   210     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   211     gc.Clear( aRect );
       
   212     }
       
   213 
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // SizeChanged
       
   217 // Called by framework when the view size is changed.
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void CEdtaAppView::SizeChanged()
       
   221     {
       
   222     DebugPrintF(_L("CEdtaAppView::SizeChanged: iScreenBuffer: 0x%X, iEasyDialer: 0x%X"), iScreenBuffer, iEasyDialer );
       
   223 
       
   224     // Controls must set rects, otherwise not drawn
       
   225     // If easy dialer plugin is loaded, the controls are reorganized to screen.
       
   226     if( iEasyDialer )
       
   227         {
       
   228         // Screen buffer occupies upper half of the view.
       
   229         TRect screen_buffer_rect = iAvkonAppUi->ClientRect();
       
   230         screen_buffer_rect.iBr.iY -= (screen_buffer_rect.Height() / 2 );
       
   231         TRect easy_dialer_rect(0, screen_buffer_rect.Height(), screen_buffer_rect.Width(), iAvkonAppUi->ClientRect().Height());
       
   232         iEasyDialer->SetRect( easy_dialer_rect );
       
   233         iScreenBuffer->SetRect(screen_buffer_rect);
       
   234         }
       
   235     else if ( iScreenBuffer )
       
   236         {
       
   237         iScreenBuffer->SetRect(iAvkonAppUi->ClientRect());
       
   238         }
       
   239     }
       
   240 
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CountComponentControls
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 TInt CEdtaAppView::CountComponentControls() const
       
   247     {
       
   248     return iEasyDialer ? 2 : 1;
       
   249     }
       
   250 
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // ComponentControl
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 CCoeControl* CEdtaAppView::ComponentControl(TInt aIndex) const
       
   257     {
       
   258     switch (aIndex)
       
   259         {
       
   260         case 0: return iScreenBuffer;
       
   261         case 1: return iEasyDialer; // Can be null
       
   262         default: return NULL;
       
   263         }
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // OfferKeyEventL
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 TKeyResponse CEdtaAppView::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   271     {
       
   272     TKeyResponse handled = EKeyWasNotConsumed;
       
   273     
       
   274     if ( iEasyDialer )
       
   275         {
       
   276         handled = iEasyDialer->OfferKeyEventL(aKeyEvent, aType);
       
   277         }
       
   278     
       
   279     if ( handled == EKeyWasNotConsumed )
       
   280         {
       
   281         handled = iScreenBuffer->OfferKeyEventL(aKeyEvent, aType);
       
   282         }
       
   283     else 
       
   284         {
       
   285         handled = EKeyWasConsumed;
       
   286         }
       
   287 
       
   288     return handled;
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // GetScreenBuffer
       
   293 // Returns the pointer to the screen buffer of the view.
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 CEdtaScreenTextBuffer* CEdtaAppView::GetScreenBuffer()
       
   297     {
       
   298     return iScreenBuffer;
       
   299     }
       
   300 
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // GetEasyDialer
       
   304 // Returns the pointer to the easy dialer.
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 CDialingExtensionInterface* CEdtaAppView::GetEasyDialer()
       
   308     {
       
   309     return iEasyDialer;
       
   310     }
       
   311 
       
   312 
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // InitContactDataStoreUrisL
       
   316 // Initialises user contact data store URIs into field iContactDataStores.
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 void CEdtaAppView::InitContactDataStoreUrisL()
       
   320     {
       
   321     HBufC* default_cdb = VPbkContactStoreUris::DefaultCntDbUri().AllocLC();
       
   322     User::LeaveIfError(iContactDataStores.Append( default_cdb ));
       
   323     CleanupStack::Pop( default_cdb );
       
   324 
       
   325     iContactStoreUriArray = CVPbkContactStoreUriArray::NewL();
       
   326     iContactStoreUriArray->AppendL(TVPbkContactStoreUriPtr( VPbkContactStoreUris::DefaultCntDbUri() ));
       
   327     }
       
   328 
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // InitPredictiveContactSearchL
       
   332 // Initialises predictive contact search.
       
   333 // -----------------------------------------------------------------------------
       
   334 //
       
   335 void CEdtaAppView::InitPredictiveContactSearchL()
       
   336     {
       
   337     DebugPrintF(_L("CEdtaAppView::InitPredictiveContactSearchL enter"));
       
   338 
       
   339     iPredictiveContactSearchHandler = CPSRequestHandler::NewL();
       
   340     iPredictiveContactSearchHandler->AddObserverL(this);
       
   341 
       
   342     DebugPrintF(_L("CEdtaAppView::InitPredictiveContactSearchL => CPSRequestHandler::NewL done"));
       
   343 
       
   344     InitContactDataStoreUrisL();
       
   345 
       
   346     DebugPrintF(_L("CEdtaAppView::InitPredictiveContactSearchL => InitContactDataStoreUrisL done"));
       
   347 
       
   348     iContactManager = CVPbkContactManager::NewL(*iContactStoreUriArray);
       
   349 
       
   350     // Put the searched contact fields into array.
       
   351     RArray<TInt> contact_fields;
       
   352     CleanupClosePushL(contact_fields);
       
   353 
       
   354     // All supported fields are searched. The supported fiels are specified in cenrep private\10202BE9\2000B5C6.
       
   355     contact_fields.Append(R_VPBK_FIELD_TYPE_FIRSTNAME);
       
   356     contact_fields.Append(R_VPBK_FIELD_TYPE_LASTNAME);
       
   357     contact_fields.Append(R_VPBK_FIELD_TYPE_COMPANYNAME);
       
   358     contact_fields.Append(R_VPBK_FIELD_TYPE_EMAILHOME);
       
   359     contact_fields.Append(R_VPBK_FIELD_TYPE_EMAILWORK);
       
   360     contact_fields.Append(R_VPBK_FIELD_TYPE_EMAILGEN);
       
   361 
       
   362     // Create and fill ps settings object.
       
   363     CPsSettings* ps_settings = CPsSettings::NewL();
       
   364     CleanupStack::PushL(ps_settings);
       
   365 
       
   366     ps_settings->SetSearchUrisL(iContactDataStores);
       
   367     ps_settings->SetMaxResults(KEdtaMaximumMatchingCount);
       
   368     ps_settings->SetSortType(EAlphabetical);
       
   369     ps_settings->SetDisplayFieldsL(contact_fields);
       
   370 
       
   371     // Set the ps settings.
       
   372     iPredictiveContactSearchHandler->SetSearchSettingsL(*ps_settings);
       
   373 
       
   374     DebugPrintF(_L("CEdtaAppView::InitPredictiveContactSearchL => CPSRequestHandler::SetSearchSettingsL done"));
       
   375 
       
   376     CleanupStack::PopAndDestroy(ps_settings);
       
   377     CleanupStack::PopAndDestroy(&contact_fields);
       
   378 
       
   379     iPredictiveSearchQuery = CPsQuery::NewL();
       
   380 
       
   381     DebugPrintF(_L("CEdtaAppView::InitPredictiveContactSearchL => CPsQuery::NewL done"));
       
   382 
       
   383     DebugPrintF(_L("CEdtaAppView::InitPredictiveContactSearchL exit"));
       
   384     }
       
   385 
       
   386 
       
   387 // -----------------------------------------------------------------------------
       
   388 // void ShowMatchingContacts(const TDesC& aSearchString)
       
   389 // Starts an asynchronous search for contacts matching to aSearchString.
       
   390 // The actual displaying of contact is done in callback HandlePsResultsUpdate
       
   391 // - Hardcode to use ITU keyboard parameters
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 void CEdtaAppView::ShowMatchingContactsL(const TDesC& aSearchString)
       
   395     {
       
   396     DebugPrintF(_L("CEdtaAppView::ShowMatchingContactsL: enter '%S'"), &aSearchString );
       
   397 
       
   398     iPredictiveSearchQuery->Reset();
       
   399 
       
   400     for(TInt i = 0; i < aSearchString.Length() ;i++)
       
   401         {
       
   402          // Add a query item
       
   403         CPsQueryItem* item = CPsQueryItem::NewL();
       
   404         CleanupStack::PushL(item);
       
   405 
       
   406         item->SetCharacter( aSearchString[i] );
       
   407         item->SetMode( EItut );
       
   408         iPredictiveSearchQuery->AppendL(*item);
       
   409 
       
   410         // Previous CPsQuery::AppendL takes the ownership of item.
       
   411         // Do not delete item.
       
   412         CleanupStack::Pop(item);
       
   413         }
       
   414 
       
   415     // Issue the search. SearchL is asynchronous function => returns immediately.
       
   416     iPredictiveContactSearchHandler->SearchL(*iPredictiveSearchQuery);
       
   417 
       
   418     DebugPrintF(_L("CEdtaAppView::ShowMatchingContactsL: exit"));
       
   419     }
       
   420 
       
   421 
       
   422 // -----------------------------------------------------------------------------
       
   423 // ShowNameOrderL
       
   424 // Check the name ordering from phonebook engine by using phonebook engine API.
       
   425 // -----------------------------------------------------------------------------
       
   426 // 
       
   427 void CEdtaAppView::ShowNameOrderL()
       
   428     {
       
   429     DebugPrintF(_L("CEdtaAppView::ShowNameOrderL: enter"));
       
   430 
       
   431     CPbkContactEngine* pbkEngine = CPbkContactEngine::NewL();
       
   432     CPbkContactEngine::TPbkNameOrder nameOrder = pbkEngine->NameDisplayOrderL();
       
   433 
       
   434     iScreenBuffer->WriteLineL(_L("Phonebook name order is"));
       
   435     switch ( nameOrder )
       
   436         {
       
   437         case CPbkContactEngine::EPbkNameOrderLastNameFirstName:
       
   438             DebugPrintF(_L("CEdtaAppView::ShowNameOrderL: The name order is: %d == LastName -> FirstName"), nameOrder );
       
   439             iScreenBuffer->WriteLineL(_L("* Last name, first name"));
       
   440             break;
       
   441         case CPbkContactEngine::EPbkNameOrderFirstNameLastName:
       
   442             DebugPrintF(_L("CEdtaAppView::ShowNameOrderL: The name order is: %d == FirstName -> LastName"), nameOrder );
       
   443             iScreenBuffer->WriteLineL(_L("* First name, last name"));
       
   444             break;
       
   445         case CPbkContactEngine::EPbkNameOrderNotDefined:
       
   446             DebugPrintF(_L("CEdtaAppView::ShowNameOrderL: The name order is: %d == Not defined"), nameOrder );
       
   447             iScreenBuffer->WriteLineL(_L("* Not defined"));
       
   448             break;
       
   449         default:
       
   450             DebugPrintF(_L("CEdtaAppView::ShowNameOrderL: The name order is: %d == Unknown"), nameOrder );
       
   451             iScreenBuffer->WriteLineL(_L("* Unknown value: %d"), nameOrder );
       
   452         }
       
   453 
       
   454     delete pbkEngine;
       
   455     
       
   456     DebugPrintF(_L("CEdtaAppView::ShowNameOrderL: exit"));
       
   457     }
       
   458 
       
   459 // -----------------------------------------------------------------------------
       
   460 // IsPCSServerLoaded
       
   461 // Checks if the PCSServer is loaded properly at constructor
       
   462 // -----------------------------------------------------------------------------
       
   463 //
       
   464 TBool CEdtaAppView::IsPCSServerLoaded()
       
   465     {
       
   466     if( !iPredictiveSearchQuery )
       
   467         {
       
   468         DebugPrintF(_L("CEdtaAppView::CheckPCSServerL: PCS server not loaded properly!"));
       
   469 
       
   470         TBuf<KEdtaMaxLineWidth> tempStr;
       
   471         tempStr.Copy(_L("PCS server not loaded!"));;
       
   472         
       
   473         TRAP_IGNORE(
       
   474                 {
       
   475                 CAknErrorNote* myNote = new (ELeave) CAknErrorNote();
       
   476                 myNote->SetTimeout( CAknNoteDialog::ELongTimeout );
       
   477                 TRAP_IGNORE( myNote->ExecuteLD( tempStr ) );
       
   478                 }
       
   479         );
       
   480         return EFalse;
       
   481         }
       
   482     return ETrue;
       
   483     }
       
   484 
       
   485 // -----------------------------------------------------------------------------
       
   486 // CheckPCSServerL
       
   487 // Checks the configuration of the PCSServer and prints the sortorder of fields.
       
   488 // -----------------------------------------------------------------------------
       
   489 //
       
   490 void CEdtaAppView::CheckPCSServerL()
       
   491     {
       
   492     RArray<TInt> field_order;
       
   493     CleanupClosePushL(field_order);
       
   494 
       
   495     HBufC* default_cdb = VPbkContactStoreUris::DefaultCntDbUri().AllocLC();
       
   496 
       
   497     _LIT(KEdtaField, "*");
       
   498     TBuf<KEdtaMaxLineWidth> line(KEdtaField);
       
   499 
       
   500     iPredictiveContactSearchHandler->GetDataOrderL(*default_cdb, field_order);
       
   501 
       
   502     DebugPrintF(_L("CEdtaAppView::ShowContactFieldOrderL: Number of fields: %d"), field_order.Count() );
       
   503 
       
   504     TInt requiredFieldsCount = 3;
       
   505     
       
   506     for ( TInt i = 0; i < field_order.Count(); i++)
       
   507         {
       
   508         line.Append((TChar) ' ');
       
   509         line.AppendNum(field_order[i]);
       
   510         
       
   511         if(( field_order[i] ==  R_VPBK_FIELD_TYPE_FIRSTNAME) ||
       
   512            ( field_order[i] ==  R_VPBK_FIELD_TYPE_LASTNAME) ||
       
   513            ( field_order[i] ==  R_VPBK_FIELD_TYPE_COMPANYNAME ))
       
   514             {
       
   515             requiredFieldsCount--;
       
   516             }
       
   517         }
       
   518 
       
   519     CleanupStack::PopAndDestroy( default_cdb );
       
   520     CleanupStack::PopAndDestroy( &field_order );
       
   521 
       
   522     iScreenBuffer->WriteLineL(_L("PCS server fields:"));
       
   523     iScreenBuffer->WriteLineL(line);
       
   524 
       
   525     DebugPrintF(_L("CEdtaAppView::ShowContactFieldOrderL: '%S'"), &line );
       
   526 
       
   527     if( requiredFieldsCount == 0 )
       
   528         {
       
   529         DebugPrintF(_L("CEdtaAppView::ShowContactFieldOrderL: All required fields found from PCSServer, configuration is OK"));
       
   530         iScreenBuffer->WriteLineL(_L("* All required fields found"));
       
   531         }
       
   532     else
       
   533         {
       
   534         DebugPrintF(_L("CEdtaAppView::ShowContactFieldOrderL: Not all required fields found from PCSServer, configuration is wrong"));
       
   535         iScreenBuffer->WriteLineL(_L("* PCS server misconfigured!"));
       
   536         iScreenBuffer->WriteLineL(_L("* Easydialing may not"));
       
   537         iScreenBuffer->WriteLineL(_L("* match your queries!"));
       
   538         }
       
   539     }
       
   540 
       
   541 
       
   542 // -----------------------------------------------------------------------------
       
   543 // void LaunchNthContactL(TInt aIx)
       
   544 // Launches communication launcher for the first contact in the previous
       
   545 // search. If not contacts found or no search yet done, function does nothing.
       
   546 // -----------------------------------------------------------------------------
       
   547 //
       
   548 void CEdtaAppView::LaunchNthContactL(TInt aIx)
       
   549     {
       
   550     if (aIx < 0 || iMatchingContactLinks.Count() <= aIx)
       
   551         {
       
   552         DebugPrintF(_L("CEdtaAppView::LaunchNthContactL: No contacts retrieved yet") );
       
   553         return;
       
   554         }
       
   555 
       
   556     DebugPrintF(_L("CEdtaAppView::LaunchNthContactL: enter, index: %d, setting parameters.."), aIx );
       
   557 
       
   558     MCCAParameter* launch_parameters = TCCAFactory::NewParameterL();
       
   559     CleanupClosePushL( *launch_parameters );
       
   560 
       
   561     launch_parameters->SetConnectionFlag(MCCAParameter::ENormal);
       
   562     launch_parameters->SetContactDataFlag(MCCAParameter::EContactLink);
       
   563 
       
   564     // Pack the contact link and expand it to 16-bit descriptor.
       
   565     HBufC8* contact8 = iMatchingContactLinks[aIx]->PackLC();
       
   566     HBufC16* contact16 = HBufC16::NewLC( contact8->Length() );
       
   567     contact16->Des().Copy( contact8->Des() );
       
   568 
       
   569     launch_parameters->SetContactDataL( contact16->Des() );
       
   570 
       
   571     CleanupStack::PopAndDestroy( contact16 );
       
   572     CleanupStack::PopAndDestroy( contact8 );
       
   573 
       
   574     DebugPrintF(_L("CEdtaAppView::LaunchNthContactL: launching CCA.."));
       
   575 
       
   576     iContactLauncher->LaunchAppL( *launch_parameters, this );
       
   577 
       
   578     // Ownership of parameter transferred to CCA launcher => pop but do not destroy.
       
   579     CleanupStack::Pop(launch_parameters);  // Close parameter
       
   580 
       
   581     DebugPrintF(_L("CEdtaAppView::LaunchNthContactL: exit"));
       
   582     }
       
   583 
       
   584 
       
   585 
       
   586 // -----------------------------------------------------------------------------
       
   587 // void DoMiscellaneousTestsL()
       
   588 // Does various tests on easy dialing that are difficult to do through normal
       
   589 // testing. Mainly for coverage testing purposes.
       
   590 // -----------------------------------------------------------------------------
       
   591 //
       
   592 void CEdtaAppView::DoMiscellaneousTestsL()
       
   593     {
       
   594     // Coverage tests for observer handling.
       
   595     iEasyDialer->AddObserverL( iDummyListener );
       
   596     iEasyDialer->AddObserverL( NULL );
       
   597     iEasyDialer->RemoveObserver( iDummyListener );
       
   598     }
       
   599 
       
   600 // -----------------------------------------------------------------------------
       
   601 // void HandlePsResultsUpdate(RPointerArray<CPsClientData>& aResult, RPointerArray<CPsPattern>& aSeqs)
       
   602 // Searched matching contacts using PCS and shows them on the screen.
       
   603 // -----------------------------------------------------------------------------
       
   604 //
       
   605 void CEdtaAppView::HandlePsResultsUpdate(RPointerArray<CPsClientData>& aResults, RPointerArray<CPsPattern>& aSeqs)
       
   606     {
       
   607     TRAP_IGNORE( HandlePredictiveSearchResultL(aResults, aSeqs) );
       
   608     }
       
   609 
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // void HandlePsError(TInt aErrorCode)
       
   613 // Called when search error happens.
       
   614 // -----------------------------------------------------------------------------
       
   615 //
       
   616 void CEdtaAppView::HandlePsError(TInt aErrorCode)
       
   617     {
       
   618     DebugPrintF(_L("CEdtaAppView::HandlePsError: %d"), aErrorCode );
       
   619 
       
   620     _LIT(KEdtaCachingError, "*** Caching error %d ***");
       
   621     TRAP_IGNORE( iScreenBuffer->WriteLineL(KEdtaCachingError, aErrorCode) );
       
   622 
       
   623     }
       
   624 
       
   625 
       
   626 // -----------------------------------------------------------------------------
       
   627 // void CachingStatus(TCachingStatus& aStatus, TInt& aError)
       
   628 // Called to update caching status.
       
   629 // -----------------------------------------------------------------------------
       
   630 //
       
   631 void CEdtaAppView::CachingStatus(TCachingStatus& aStatus, TInt& aError )
       
   632     {
       
   633     DebugPrintF(_L("CEdtaAppView::CachingStatus: %d"), aError);
       
   634 
       
   635     switch (aStatus)
       
   636         {
       
   637         case ECachingNotStarted:
       
   638             {
       
   639             _LIT(KEdtaCachingStatusStarted, "*** Caching started ***");
       
   640             TRAP_IGNORE( iScreenBuffer->WriteLineL(KEdtaCachingStatusStarted) );
       
   641             }
       
   642             break;
       
   643         case ECachingInProgress:
       
   644             {
       
   645             _LIT(KEdtaCachingStatusInProgress, "*** Caching in progress ***");
       
   646             TRAP_IGNORE( iScreenBuffer->WriteLineL(KEdtaCachingStatusInProgress) );
       
   647             }
       
   648             break;
       
   649         case ECachingComplete:
       
   650             {
       
   651             _LIT(KEdtaCachingStatusComplete, "*** Caching complete ***");
       
   652             TRAP_IGNORE( iScreenBuffer->WriteLineL(KEdtaCachingStatusComplete) );
       
   653             }
       
   654             break;
       
   655         case ECachingCompleteWithErrors:
       
   656             {
       
   657             _LIT(KEdtaCachingStatusCompleteWithErrors, "*** Caching complete with error %d ***");
       
   658             TRAP_IGNORE( iScreenBuffer->WriteLineL(KEdtaCachingStatusCompleteWithErrors, aError) );
       
   659             }
       
   660             break;
       
   661         default:
       
   662             {
       
   663             _LIT(KEdtaCachingStatusUnknown, "*** Unknown caching status %d ***");
       
   664             TRAP_IGNORE( iScreenBuffer->WriteLineL(KEdtaCachingStatusUnknown, (TInt) aStatus) );
       
   665             }
       
   666             break;
       
   667         }
       
   668     }
       
   669 
       
   670 
       
   671 
       
   672 // -----------------------------------------------------------------------------
       
   673 // void HandlePredictiveSearchResultL(RPointerArray<CPsClientData>& aResult, RPointerArray<CPsPattern>& aSeqs)
       
   674 // Handles predictive search results. A leaving version to be trapped in HandlePsResultsUpdate.
       
   675 // -----------------------------------------------------------------------------
       
   676 //
       
   677 void CEdtaAppView::HandlePredictiveSearchResultL(RPointerArray<CPsClientData>& aResults, RPointerArray<CPsPattern>& /* aSeqs */)
       
   678     {
       
   679     TInt results = aResults.Count();
       
   680     DebugPrintF(_L("CEdtaAppView::HandlePredictiveSearchResultL enter, matching contacts found: %d"), results );
       
   681 
       
   682     iContactNames.ResetAndDestroy();
       
   683     iMatchingContactLinks.ResetAndDestroy();
       
   684 
       
   685     // map results to old contact match data
       
   686     for (TInt i = 0; i < aResults.Count(); i ++)
       
   687         {
       
   688         TBuf<KEdtaMaxLineWidth> temp;
       
   689         _LIT(KEdtaContactFormatString, "%S %S");
       
   690 
       
   691         // Store each contact name into iContactNames.
       
   692         temp.Format(KEdtaContactFormatString, aResults[i]->Data(0), aResults[i]->Data(1));
       
   693 
       
   694         DebugPrintF(_L("CEdtaAppView::HandlePredictiveSearchResultL: Contact #%d: '%S'"), i+1, &temp );
       
   695 
       
   696         HBufC* contact_name = HBufC::NewL(temp.Length());
       
   697         *contact_name = temp;
       
   698         iContactNames.Append( contact_name );
       
   699 
       
   700 
       
   701         // Each contact link stored to iMatchingContactLinks, to be possible used later by
       
   702         // CCA launcher functions.
       
   703         MVPbkContactLink* link = iPredictiveContactSearchHandler->ConvertToVpbkLinkLC(*(aResults[i]), *iContactManager);
       
   704         iMatchingContactLinks.Append( link );
       
   705         CleanupStack::Pop( link );
       
   706 
       
   707         // Write the contact name to screen buffer
       
   708         iScreenBuffer->WriteLineL( *contact_name );
       
   709 
       
   710         TUint8 match_mask = aResults[i]->FieldMatch();
       
   711 
       
   712         // Show other search fields only if search matches them.
       
   713         if (match_mask & (1 << KEdtaContactCompanyIndex))
       
   714             {
       
   715             _LIT(KEdtaContactCompany, "* Company: %S");
       
   716             iScreenBuffer->WriteLineL(KEdtaContactCompany, aResults[i]->Data(KEdtaContactCompanyIndex));
       
   717             }
       
   718         if (match_mask & (1 << KEdtaContactEmailHomeIndex))
       
   719             {
       
   720             _LIT(KEdtaContactEmailHome, "* Home e-mail: %S");
       
   721             iScreenBuffer->WriteLineL(KEdtaContactEmailHome, aResults[i]->Data(KEdtaContactEmailHomeIndex));
       
   722             }
       
   723         if (match_mask & (1 << KEdtaContactEmailWorkIndex))
       
   724             {
       
   725             _LIT(KEdtaContactEmailWork, "* Work e-mail: %S");
       
   726             iScreenBuffer->WriteLineL(KEdtaContactEmailWork, aResults[i]->Data(KEdtaContactEmailWorkIndex));
       
   727             }
       
   728         if (match_mask & (1 << KEdtaContactEmailGenIndex))
       
   729             {
       
   730             _LIT(KEdtaContactEmailGen, "* E-mail: %S");
       
   731             iScreenBuffer->WriteLineL(KEdtaContactEmailGen, aResults[i]->Data(KEdtaContactEmailGenIndex));
       
   732             }
       
   733         }
       
   734     _LIT(KEdtaNumberOfMatchingContacts, "*** %d contacts found! ***");
       
   735     iScreenBuffer->WriteLineL(KEdtaNumberOfMatchingContacts, aResults.Count());
       
   736 
       
   737     DebugPrintF(_L("CEdtaAppView::HandlePredictiveSearchResultL exit"));
       
   738     }
       
   739 
       
   740 
       
   741 // -----------------------------------------------------------------------------
       
   742 // HandleDialingExtensionEvent
       
   743 // 
       
   744 // -----------------------------------------------------------------------------
       
   745 //
       
   746 void CEdtaAppView::HandleDialingExtensionEvent( MDialingExtensionObserver::TEvent aEvent )
       
   747     {
       
   748     DebugPrintF(_L("CEdtaAppView::HandleDialingExtensionEvent"));
       
   749 
       
   750     if ( aEvent == MDialingExtensionObserver::EFocusChanged )
       
   751         {
       
   752         if ( iEasyDialer->IsFocused() )
       
   753             {
       
   754             iScreenBuffer->SetFocus( EFalse, EDrawNow );
       
   755             }
       
   756         else 
       
   757             {
       
   758             iScreenBuffer->SetFocus( ETrue, EDrawNow );
       
   759             }
       
   760         }
       
   761     }
       
   762 
       
   763 
       
   764 // -----------------------------------------------------------------------------
       
   765 // SelectAndLaunchContactL
       
   766 // Shows a list box, the launches CCA launcher for user selected contact.
       
   767 // -----------------------------------------------------------------------------
       
   768 //
       
   769 void CEdtaAppView::SelectAndLaunchContactL()
       
   770     {
       
   771     DebugPrintF(_L("CEdtaAppView::SelectAndLaunchContactL enter"));
       
   772 
       
   773     // Create list of matched contacts and show them on the screen
       
   774 
       
   775     CAknSingleHeadingPopupMenuStyleListBox* listBox = new(ELeave) CAknSingleHeadingPopupMenuStyleListBox;
       
   776     CleanupStack::PushL( listBox );
       
   777 
       
   778     CAknPopupList* popupList = CAknPopupList::NewL( listBox,
       
   779                                                     R_AVKON_SOFTKEYS_SELECT_CANCEL,
       
   780                                                     AknPopupLayouts::EMenuGraphicHeadingWindow );
       
   781     CleanupStack::PushL( popupList );
       
   782 
       
   783     listBox->ConstructL( popupList, EAknListBoxSelectionList );
       
   784     listBox->CreateScrollBarFrameL( ETrue );
       
   785     listBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
   786                                                         CEikScrollBarFrame::EAuto );
       
   787 
       
   788     _LIT( KMatchedContacts, "Matched contacts:" );
       
   789     popupList->SetTitleL( KMatchedContacts );
       
   790 
       
   791     // Add items into list
       
   792 
       
   793     CDesCArrayFlat* itemArray = new(ELeave)CDesCArrayFlat(KEdtaListBoxGranularity);
       
   794     CleanupStack::PushL(itemArray);
       
   795 
       
   796     _LIT( KListItemSeparator1, ". \t" );
       
   797 
       
   798     for (TInt listIndex = 0; listIndex < iContactNames.Count(); listIndex++ )
       
   799         {
       
   800         TBuf<KEdtaMaxLineWidth> itemString;
       
   801         itemString.Zero();
       
   802         itemString.AppendNum( listIndex+1 );
       
   803         itemString.Append( KListItemSeparator1 );
       
   804         itemString.Append( *iContactNames[listIndex] );
       
   805 
       
   806         itemArray->AppendL(itemString);
       
   807         }
       
   808 
       
   809     CTextListBoxModel* model = listBox->Model();
       
   810     model->SetItemTextArray( itemArray );
       
   811     model->SetOwnershipType( ELbmOwnsItemArray );
       
   812     CleanupStack::Pop( itemArray );     // Pop itemArray - the listBox model owns this now
       
   813 
       
   814     if( popupList->ExecuteLD() )        // Show the list finally
       
   815         {
       
   816         if( listBox->CurrentItemIndex() >= 0 )
       
   817             {
       
   818             // Launch communication launcher for selected contact
       
   819             LaunchNthContactL( listBox->CurrentItemIndex() );
       
   820             }
       
   821         }
       
   822 
       
   823     CleanupStack::Pop( popupList );
       
   824     CleanupStack::PopAndDestroy( listBox );
       
   825 
       
   826     DebugPrintF(_L("CEdtaAppView::SelectAndLaunchContactL exit"));
       
   827     }
       
   828 
       
   829 
       
   830 // -----------------------------------------------------------------------------
       
   831 // CCASimpleNotifyL
       
   832 // Implements MCCAObserver notification interface.
       
   833 // Nothing better to do but show the parameters.
       
   834 // -----------------------------------------------------------------------------
       
   835 //
       
   836 void CEdtaAppView::CCASimpleNotifyL( TNotifyType aType, TInt aReason )
       
   837     {
       
   838     DebugPrintF(_L("CEdtaAppView::CCASimpleNotifyL: aType: %d, aReason: %d"), (TInt)aType, aReason );
       
   839 
       
   840     _LIT(KEdtaCCAExitReason, "Launcher exit reason %d, %d");
       
   841     iScreenBuffer->WriteLineL(KEdtaCCAExitReason, aType, aReason);
       
   842     }
       
   843 
       
   844 
       
   845 // -----------------------------------------------------------------------------
       
   846 // LoadPluginL
       
   847 // Load the easydialing ECOM plugin
       
   848 // -----------------------------------------------------------------------------
       
   849 //
       
   850 void CEdtaAppView::LoadPluginL()
       
   851     {
       
   852     TRAPD( error, 
       
   853         {
       
   854         iEasyDialer = CDialingExtensionInterface::NewL();
       
   855         iEasyDialer->InitializeL( *this );        
       
   856         } );
       
   857 
       
   858     if( error )
       
   859         {
       
   860         DebugPrintF(_L("CEdtaAppView::LoadPluginL FAIL, error: %d"), error );
       
   861         iScreenBuffer->WriteLineL(_L("* EasyDialing Plugin load fail: %d"), error );
       
   862         iEasyDialer = NULL;
       
   863         }
       
   864     else
       
   865         {
       
   866         iScreenBuffer->WriteLineL(_L("EasyDialing Plugin loaded"));
       
   867         DebugPrintF(_L("CEdtaAppView::LoadPluginL OK" ));
       
   868         }
       
   869     }
       
   870 
       
   871 // End of File
       
   872