emailcontacts/remotecontactlookup/engine/src/cpbkxrclactionservicewrapper.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 11 0396474f30f5
child 13 8592a65ad3fb
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
       
     2 * Copyright (c) 2008 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:  Definition of the class CPbkxRclSearchEngine.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <coemain.h>
       
    21 //<cmail>
       
    22 #include "cfsccontactactionservice.h"
       
    23 #include "mfsccontactaction.h"
       
    24 #include "fscactionpluginactionuids.h"
       
    25 
       
    26 #include "tfsccontactactionqueryresult.h"
       
    27 //</cmail>
       
    28 #include <CPbkContactEngine.h>
       
    29 #include <CPbkContactItem.h>
       
    30 
       
    31 #include <CVPbkContactStoreUriArray.h>
       
    32 #include <TVPbkContactStoreUriPtr.h>
       
    33 #include <CVPbkContactManager.h>
       
    34 #include <MVPbkContactStore.h>
       
    35 #include <MVPbkContactStoreList.h>
       
    36 #include <MVPbkContactStoreProperties.h>
       
    37 #include <MVPbkStoreContact.h>  // for RFscStoreContactList items
       
    38 
       
    39 #include "cpbkxrclactionservicewrapper.h"
       
    40 #include "pbkxrclengineconstants.h"
       
    41 #include "cpbkxrclcontactconverter.h"
       
    42 
       
    43 
       
    44 // Contact databases
       
    45 _LIT(KRclDefaultCntDbURI, "cntdb://c:contacts.cdb");
       
    46 
       
    47 // ======== MEMBER FUNCTIONS ========
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CPbkxRclActionServiceWrapper::NewL
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CPbkxRclActionServiceWrapper* CPbkxRclActionServiceWrapper::NewL( 
       
    54     CPbkContactEngine& aContactEngine )
       
    55     {
       
    56     FUNC_LOG;
       
    57     CPbkxRclActionServiceWrapper* wrapper = new ( ELeave ) 
       
    58         CPbkxRclActionServiceWrapper( aContactEngine );
       
    59     CleanupStack::PushL( wrapper );
       
    60     wrapper->ConstructL();
       
    61     CleanupStack::Pop( wrapper );
       
    62     return wrapper;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CPbkxRclActionServiceWrapper::CPbkxRclActionServiceWrapper
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CPbkxRclActionServiceWrapper::CPbkxRclActionServiceWrapper( CPbkContactEngine& 
       
    70     aContactEngine ) : CBase(), iContactEngine( aContactEngine ) 
       
    71     {
       
    72     FUNC_LOG;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CPbkxRclActionServiceWrapper::~CPbkxRclActionServiceWrapper
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CPbkxRclActionServiceWrapper::~CPbkxRclActionServiceWrapper()
       
    80     {
       
    81     FUNC_LOG;
       
    82     
       
    83     iConvertedContact.ResetAndDestroy(); 
       
    84     
       
    85     if( iContactManager )
       
    86         {
       
    87         if ( iContactStore )
       
    88             {
       
    89             iContactStore->Close(*this);
       
    90             }
       
    91         } 
       
    92     delete iContactManager;
       
    93     delete iContactActionService;
       
    94     delete iContactConverter;    
       
    95     delete iWait;  
       
    96     
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // CPbkxRclActionServiceWrapper::ConstructL
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CPbkxRclActionServiceWrapper::ConstructL()
       
   104     {
       
   105     FUNC_LOG;
       
   106     // Create Contact Manager
       
   107     CVPbkContactStoreUriArray* uriList = CVPbkContactStoreUriArray::NewLC();    
       
   108     uriList->AppendL( TVPbkContactStoreUriPtr( KRclDefaultCntDbURI ) );  
       
   109     iContactManager = CVPbkContactManager::NewL( *uriList, &(CCoeEnv::Static()->FsSession()) );
       
   110     CleanupStack::PopAndDestroy( uriList );
       
   111     
       
   112     // Get store list
       
   113     MVPbkContactStoreList& defaultstore = iContactManager->ContactStoresL();
       
   114     
       
   115     // Open contact store
       
   116     iContactStore = &defaultstore.At( 0 );
       
   117     iContactStore->OpenL( *this );   
       
   118     
       
   119     iContactActionService = CFscContactActionService::NewL( *iContactManager );
       
   120     
       
   121     iContactConverter = CPbkxRclContactConverter::NewL( 
       
   122             iContactEngine, *iContactManager, *iContactStore );
       
   123     
       
   124     iWait = new ( ELeave ) CActiveSchedulerWait();
       
   125 
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // CPbkxRclActionServiceWrapper::SetContactSelectorMode
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 void CPbkxRclActionServiceWrapper::SetContactSelectorMode( 
       
   133     TBool aContactSelectorMode )
       
   134     {
       
   135     FUNC_LOG;
       
   136     iContactSelectorMode = aContactSelectorMode;
       
   137     if ( aContactSelectorMode )
       
   138         {
       
   139         // in contact selector mode the flags are static
       
   140 
       
   141         // all actions except save as is queried 
       
   142         iFlags = KFscAtMan & ( ~KFscAtManSaveAs );
       
   143         }
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CPbkxRclActionServiceWrapper::SetActionMenuMode
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CPbkxRclActionServiceWrapper::SetActionMenuMode(
       
   151     TBool aActionMenuMode )
       
   152     {
       
   153     FUNC_LOG;
       
   154     // if not in contact selector mode, flags depend on whether
       
   155     // we are showing the action menu or not
       
   156     if ( !iContactSelectorMode )
       
   157         {
       
   158         if ( aActionMenuMode )
       
   159             {
       
   160             // in action menu mode poc and save as are disabled
       
   161             iFlags = KFscAtAll & ( ~KFscAtComCallPoc ) & ( ~KFscAtManSaveAs );
       
   162             }
       
   163         else
       
   164             {
       
   165             // when not in action menu mode, all actions but save as contact 
       
   166             // are enabled
       
   167             iFlags = KFscAtAll & ( ~KFscAtManSaveAs );
       
   168             }
       
   169         }
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CPbkxRclActionServiceWrapper::SetCurrentContactL
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CPbkxRclActionServiceWrapper::SetCurrentContactL( CPbkContactItem* aContactItem )
       
   177     {
       
   178     FUNC_LOG;
       
   179 
       
   180     iConvertedContact.ResetAndDestroy(); // clean before new use
       
   181     
       
   182     // Convert contact to MVPbkStoreContact object, only one item in 
       
   183     if ( aContactItem )
       
   184         {
       
   185         iContactConverter->ConvertContactL( *aContactItem, iConvertedContact );
       
   186         }
       
   187 
       
   188     iContactActionService->SetContactSetL( iConvertedContact );
       
   189 
       
   190     iSaveAsContactActionExists = EFalse;
       
   191 
       
   192     iQueryComplete = EFalse;
       
   193     // first query for save as contact
       
   194     iContactActionService->QueryActionsL( this, EFalse, KFscAtManSaveAs );
       
   195 
       
   196     // Wait async operation callback. If operation is completed before returning method call
       
   197     // don't start waiting
       
   198     if (!iQueryComplete)
       
   199         {
       
   200         iWait->Start();
       
   201         }
       
   202     
       
   203     const CFscContactActionList& actions = iContactActionService->QueryResults();
       
   204 
       
   205     // look for save as contact
       
   206     for ( TInt i = 0; i < actions.Count(); i++ )
       
   207         {
       
   208         const TFscContactActionQueryResult& result = actions[i];
       
   209         if ( result.iAction->Uid() == KFscActionUidSaveAsContact )
       
   210             {
       
   211             iSaveAsContactResult = TFscContactActionQueryResult(
       
   212                 result.iAction, 
       
   213                 result.iPriority,
       
   214                 result.iActionMenuVisibility,
       
   215                 result.iOptionsMenuVisibility );
       
   216             
       
   217             iSaveAsContactActionExists = ETrue;
       
   218             break;
       
   219             }
       
   220         }
       
   221     
       
   222     // Wait async operation callback. If operation is completed before returning method call
       
   223     // don't start waiting
       
   224     iQueryComplete = EFalse;
       
   225     iContactActionService->QueryActionsL( this, EFalse, iFlags );
       
   226     if (!iQueryComplete)
       
   227         {
       
   228         iWait->Start();
       
   229         } 
       
   230         
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CPbkxRclActionServiceWrapper::IsActionEnabled
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 TBool CPbkxRclActionServiceWrapper::IsActionEnabled( 
       
   238     const TUint64 aActionType ) const
       
   239     {
       
   240     FUNC_LOG;
       
   241     TBool enabled = EFalse;
       
   242     
       
   243     const TFscContactActionQueryResult* result = GetResult( aActionType );
       
   244     
       
   245     if ( result != NULL )
       
   246         {
       
   247         enabled = ( result->iOptionsMenuVisibility.iVisibility == 
       
   248         TFscContactActionVisibility::EFscActionVisible && 
       
   249                     result->iPriority >= 0 );
       
   250         }
       
   251 
       
   252     return enabled;
       
   253     }
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // CPbkxRclActionServiceWrapper::ExecuteActionL
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 void CPbkxRclActionServiceWrapper::ExecuteActionL( const TUint64 aActionType )
       
   260     {
       
   261     FUNC_LOG;
       
   262     const TFscContactActionQueryResult* result = GetResult( aActionType );
       
   263    
       
   264     if ( result == NULL )
       
   265         {
       
   266         User::Leave( KErrNotFound );
       
   267         }
       
   268     iExecuteComplete = EFalse;
       
   269     iContactActionService->ExecuteL( result->iAction->Uid(), this );
       
   270     // Wait async operation callback. If operation is completed before returning method call
       
   271     // don't start waiting
       
   272     if (!iExecuteComplete)
       
   273         {
       
   274         iWait->Start();
       
   275         }     
       
   276    
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // CPbkxRclActionServiceWrapper::ActionService
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 CFscContactActionService* CPbkxRclActionServiceWrapper::ActionService()
       
   284     {
       
   285     FUNC_LOG;
       
   286     return iContactActionService;
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CPbkxRclActionServiceWrapper::GetResult
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 const TFscContactActionQueryResult* CPbkxRclActionServiceWrapper::GetResult( 
       
   294     const TUint64 aType ) const
       
   295     {
       
   296     FUNC_LOG;
       
   297     if ( iSaveAsContactActionExists && aType == iSaveAsContactResult.iAction->Type() )
       
   298         {
       
   299         return &iSaveAsContactResult;
       
   300         }
       
   301     else
       
   302         {
       
   303         const CFscContactActionList& actions = iContactActionService->QueryResults();
       
   304         
       
   305         for ( TInt i = 0; i < actions.Count(); i++ )
       
   306             {
       
   307             const TFscContactActionQueryResult& queryResult = actions[i];
       
   308             if ( queryResult.iAction->Type() == aType )
       
   309                 {
       
   310                 return &queryResult;
       
   311                 }
       
   312             }
       
   313         }
       
   314     return NULL;
       
   315     }
       
   316 // ---------------------------------------------------------------------------
       
   317 // CPbkxRclActionServiceWrapper::ContactConverter
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 CPbkxRclContactConverter* CPbkxRclActionServiceWrapper::ContactConverter()
       
   321     {
       
   322     FUNC_LOG;
       
   323     return iContactConverter;
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // CPbkxRclActionServiceWrapper::StoreReady
       
   328 // ---------------------------------------------------------------------------
       
   329 //
       
   330 void CPbkxRclActionServiceWrapper::StoreReady( 
       
   331         MVPbkContactStore& /* aContactStore */ )
       
   332     {
       
   333     FUNC_LOG;
       
   334     iLastError = KErrNone;
       
   335     }
       
   336 // ---------------------------------------------------------------------------
       
   337 // CPbkxRclActionServiceWrapper::StoreUnavailable()
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 void CPbkxRclActionServiceWrapper::StoreUnavailable( 
       
   341         MVPbkContactStore& /* aContactStore */, 
       
   342         TInt aReason )
       
   343     {
       
   344     FUNC_LOG;
       
   345     iLastError = aReason;
       
   346     }
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 // CPbkxRclActionServiceWrapper::HandleStoreEventL()
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 void CPbkxRclActionServiceWrapper::HandleStoreEventL( 
       
   353         MVPbkContactStore& /* aContactStore */, 
       
   354         TVPbkContactStoreEvent /* aStoreEvent */ )
       
   355     {
       
   356     FUNC_LOG;
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------------------------
       
   360 // CPbkxRclActionServiceWrapper::QueryActionsComplete()
       
   361 // ---------------------------------------------------------------------------
       
   362 //
       
   363 void CPbkxRclActionServiceWrapper::QueryActionsComplete()
       
   364     {
       
   365     FUNC_LOG;
       
   366     iLastError = KErrNone;
       
   367     iQueryComplete = ETrue;
       
   368     if (iWait->IsStarted())
       
   369         {
       
   370         iWait->AsyncStop();
       
   371         }
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // CPbkxRclActionServiceWrapper::QueryActionsFailed()
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 void CPbkxRclActionServiceWrapper::QueryActionsFailed( TInt aError )
       
   379     {
       
   380     FUNC_LOG;
       
   381     iLastError = aError;
       
   382     iQueryComplete = ETrue;
       
   383     if (iWait->IsStarted())
       
   384         {    
       
   385         iWait->AsyncStop();
       
   386         }
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // CPbkxRclActionServiceWrapper::ExecuteComplete()
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 void CPbkxRclActionServiceWrapper::ExecuteComplete()
       
   394     {
       
   395     FUNC_LOG;
       
   396     iLastError = KErrNone;
       
   397     iExecuteComplete = ETrue;
       
   398     if (iWait->IsStarted())
       
   399         {    
       
   400         iWait->AsyncStop();
       
   401         }
       
   402     }
       
   403 
       
   404 // ---------------------------------------------------------------------------
       
   405 // CPbkxRclActionServiceWrapper::ExecuteFailed()
       
   406 // ---------------------------------------------------------------------------
       
   407 //
       
   408 void CPbkxRclActionServiceWrapper::ExecuteFailed( TInt aError )
       
   409     {
       
   410     FUNC_LOG;
       
   411     iLastError = aError;
       
   412     iExecuteComplete = ETrue;
       
   413     if (iWait->IsStarted())
       
   414         {
       
   415         iWait->AsyncStop();
       
   416         }
       
   417     }
       
   418 
       
   419 // ---------------------------------------------------------------------------
       
   420 // CPbkxRclActionServiceWrapper::ExecuteFailed()
       
   421 // ---------------------------------------------------------------------------
       
   422 //
       
   423 void CPbkxRclActionServiceWrapper::CancelQuery()
       
   424 	{
       
   425     FUNC_LOG;
       
   426 	iContactActionService->CancelQueryActions();
       
   427 	if (iWait->IsStarted())
       
   428 		{
       
   429 		iWait->AsyncStop();
       
   430 		}
       
   431 	}