phonebookui/Phonebook2/UIServices/src/CPbk2AiwSelectionProvider.cpp
changeset 0 e686773b3f54
child 3 04ab22b956c2
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Phonebook 2 selection service AIW provider.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2AiwSelectionProvider.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "CPbk2ServerAppConnection.h"
       
    23 #include <Pbk2IPCPackage.h>
       
    24 
       
    25 // Virtual Phonebook
       
    26 #include <RVPbkContactFieldDefaultPriorities.h>
       
    27 #include <CVPbkFieldTypeSelector.h>
       
    28 
       
    29 // System includes
       
    30 #include <AiwContactSelectionDataTypes.h>
       
    31 #include <s32mem.h>
       
    32 #include <eikspane.h>
       
    33 #include <akntitle.h>
       
    34 #include <avkon.hrh>
       
    35 
       
    36 // Debugging headers
       
    37 #include <Pbk2Debug.h>
       
    38 
       
    39 /// Unnamed namespace for local definitions
       
    40 namespace {
       
    41 
       
    42 /**
       
    43  * Verifies whether the given command id is handled here.
       
    44  * This should be done by AIW.
       
    45  *
       
    46  * @param aCmdId    The command id to check.
       
    47  * @return  ETrue if command is handled by this provider.
       
    48  */
       
    49 inline TBool IsCorrectAiwCmd( const TInt aCmdId )
       
    50     {
       
    51     TBool ret = EFalse;
       
    52     switch ( aCmdId )
       
    53         {
       
    54         case KAiwCmdSelect:
       
    55             {
       
    56             ret = ETrue;
       
    57             break;
       
    58             }
       
    59 
       
    60         default:
       
    61             {
       
    62             // Do nothing
       
    63             break;
       
    64             }
       
    65         }
       
    66     return ret;
       
    67     }
       
    68 
       
    69 } /// namespace
       
    70 
       
    71 // --------------------------------------------------------------------------
       
    72 // CPbk2AiwSelectionProvider::CPbk2AiwSelectionProvider
       
    73 // --------------------------------------------------------------------------
       
    74 //
       
    75 CPbk2AiwSelectionProvider::CPbk2AiwSelectionProvider()
       
    76     {
       
    77     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
    78         "CPbk2AiwSelectionProvider::CPbk2AiwSelectionProvider(0x%x)"), this );
       
    79     }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // CPbk2AiwSelectionProvider::~CPbk2AiwSelectionProvider
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 CPbk2AiwSelectionProvider::~CPbk2AiwSelectionProvider()
       
    86     {
       
    87     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
    88         "CPbk2AiwSelectionProvider::~CPbk2AiwSelectionProvider(0x%x)"), this );
       
    89     delete iConnection;
       
    90     delete iEventParamList;
       
    91     delete iConfigurationPackage;
       
    92     delete iInstructionsPackage;
       
    93     delete iContactViewFilterBuffer;
       
    94     delete iDefaultPrioritiesBuffer;
       
    95     }
       
    96 
       
    97 // --------------------------------------------------------------------------
       
    98 // CPbk2AiwSelectionProvider::NewL
       
    99 // --------------------------------------------------------------------------
       
   100 //
       
   101 CPbk2AiwSelectionProvider* CPbk2AiwSelectionProvider::NewL()
       
   102     {
       
   103     CPbk2AiwSelectionProvider* self =
       
   104         new ( ELeave ) CPbk2AiwSelectionProvider;
       
   105     return self;
       
   106     }
       
   107 
       
   108 // --------------------------------------------------------------------------
       
   109 // CPbk2AiwSelectionProvider::InitialiseL
       
   110 // --------------------------------------------------------------------------
       
   111 //
       
   112 void CPbk2AiwSelectionProvider::InitialiseL
       
   113         ( MAiwNotifyCallback& /*aFrameworkCallback*/,
       
   114           const RCriteriaArray& /*aInterest*/ )
       
   115     {
       
   116     // Nothing needs to be done
       
   117     }
       
   118 
       
   119 // --------------------------------------------------------------------------
       
   120 // CPbk2AiwSelectionProvider::HandleServiceCmdL
       
   121 // --------------------------------------------------------------------------
       
   122 //
       
   123 void CPbk2AiwSelectionProvider::HandleServiceCmdL
       
   124         ( const TInt& aCmdId, const CAiwGenericParamList& aInParamList,
       
   125           CAiwGenericParamList& /*aOutParamList*/, TUint aCmdOptions /*= 0*/,
       
   126           const MAiwNotifyCallback* aCallback /* = NULL*/ )
       
   127     {
       
   128     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   129         "CPbk2AiwSelectionProvider::HandleServiceCmdL(0x%x)"), this );
       
   130    if ( IsCorrectAiwCmd( aCmdId ) )
       
   131         {
       
   132         if ( !aCallback )
       
   133             {
       
   134             // The callback is mandatory
       
   135             User::Leave( KErrArgument );
       
   136             }
       
   137 
       
   138         if ( !iConnection )
       
   139             {
       
   140             iConnection = CPbk2ServerAppConnection::NewL( *this );
       
   141             }
       
   142         else if( iConnection->IsActive() )
       
   143             {
       
   144             
       
   145             if ( aCmdOptions & KAiwOptCancel )
       
   146 		            {
       
   147 		            // Client wants to cancel existing service
       
   148 		            iConnection->CancelFetch();
       
   149 		            }
       
   150             
       
   151             // Request is already active for the same client, do nothing
       
   152             // as Phonebook supports only one request per client at a time.
       
   153             return;
       
   154             }    
       
   155             
       
   156         iCallback = aCallback;
       
   157         iInParamList = &aInParamList;
       
   158             
       
   159         if ( !iEventParamList )
       
   160             {
       
   161             iEventParamList = CAiwGenericParamList::NewL();
       
   162             }
       
   163 
       
   164         CreateInstructionPackageL( aInParamList );
       
   165         ValidateInstructionPackageL();
       
   166         CreateConfigurationPackageL( aInParamList );
       
   167 
       
   168         // Launch
       
   169         iConnection->LaunchFetchL
       
   170             ( iConfigurationPackage, iInstructionsPackage );
       
   171         }
       
   172     }
       
   173 
       
   174 // --------------------------------------------------------------------------
       
   175 // CPbk2AiwSelectionProvider::OperationCompleteL
       
   176 // --------------------------------------------------------------------------
       
   177 //
       
   178 void CPbk2AiwSelectionProvider::OperationCompleteL
       
   179     ( const TDesC8& aContactLinks, TInt /*aExtraResultData*/,
       
   180       const TDesC& aField )
       
   181     {
       
   182     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   183         "CPbk2AiwSelectionProvider::OperationCompleteL(0x%x)"), this );
       
   184     iEventParamList->Reset();
       
   185     iEventParamList->AppendL(
       
   186         TAiwGenericParam( EGenericParamContactLinkArray,
       
   187             TAiwVariant( aContactLinks ) ) );
       
   188 
       
   189     iEventParamList->AppendL(
       
   190         TAiwGenericParam( EGenericParamContactFieldData,
       
   191             TAiwVariant( aField ) ) );
       
   192 
       
   193      if ( iCallback )
       
   194         {
       
   195         // Must cast this because of AIW bug
       
   196         const_cast<MAiwNotifyCallback*>( iCallback )->HandleNotifyL
       
   197             ( KAiwCmdSelect, KAiwEventCompleted, *iEventParamList,
       
   198               *iInParamList );
       
   199         }
       
   200     }
       
   201 
       
   202 // --------------------------------------------------------------------------
       
   203 // CPbk2AiwSelectionProvider::OperationCanceledL
       
   204 // --------------------------------------------------------------------------
       
   205 //
       
   206 void CPbk2AiwSelectionProvider::OperationCanceledL()
       
   207     {
       
   208     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   209         "CPbk2AiwSelectionProvider::OperationCanceledL(0x%x)"), this );
       
   210     iEventParamList->Reset();
       
   211 
       
   212     // Must cast this because of AIW bug
       
   213     const_cast<MAiwNotifyCallback*>( iCallback )->HandleNotifyL
       
   214         ( KAiwCmdSelect, KAiwEventCanceled, *iEventParamList,
       
   215           *iInParamList );
       
   216     }
       
   217 
       
   218 // --------------------------------------------------------------------------
       
   219 // CPbk2AiwSelectionProvider::OperationErrorL
       
   220 // --------------------------------------------------------------------------
       
   221 //
       
   222 void CPbk2AiwSelectionProvider::OperationErrorL( TInt aError )
       
   223     {
       
   224     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   225         "CPbk2AiwSelectionProvider::OperationErrorL(0x%x, %d)"), this, aError );
       
   226     iEventParamList->Reset();
       
   227     iEventParamList->AppendL(
       
   228             TAiwGenericParam( EGenericParamError,
       
   229                 TAiwVariant( aError ) ) );
       
   230 
       
   231     // Must cast this because of AIW bug
       
   232     const_cast<MAiwNotifyCallback*>( iCallback )->HandleNotifyL
       
   233         ( KAiwCmdSelect, KAiwEventError, *iEventParamList,
       
   234           *iInParamList );
       
   235     }
       
   236 
       
   237 // --------------------------------------------------------------------------
       
   238 // CPbk2AiwSelectionProvider::OkToExitL
       
   239 // --------------------------------------------------------------------------
       
   240 //
       
   241 TBool CPbk2AiwSelectionProvider::OkToExitL
       
   242         ( TInt /*aCommandId*/, TPbk2ExitCommandParams aExitParameter )
       
   243     {
       
   244     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   245         "CPbk2AiwSelectionProvider::OkToExitL(0x%x)"), this );
       
   246     TBool okToExit = ETrue;
       
   247 
       
   248     iEventParamList->Reset();
       
   249     iEventParamList->AppendL(
       
   250         TAiwGenericParam( EGenericParamApplication,
       
   251             TAiwVariant( aExitParameter ) ) );
       
   252 
       
   253     // Must cast this because of AIW design error
       
   254     okToExit = const_cast<MAiwNotifyCallback*>( iCallback )
       
   255         ->HandleNotifyL( KAiwCmdSelect, KAiwEventQueryExit,
       
   256             *iEventParamList, *iInParamList );
       
   257 
       
   258     return okToExit;
       
   259     }
       
   260 
       
   261 // --------------------------------------------------------------------------
       
   262 // CPbk2AiwSelectionProvider::AcceptSelectionL
       
   263 // --------------------------------------------------------------------------
       
   264 //
       
   265 TBool CPbk2AiwSelectionProvider::AcceptSelectionL
       
   266         ( TInt aNumberOfSelectedContacts, HBufC8& /*aContactLink*/ )
       
   267     {
       
   268     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   269         "CPbk2AiwSelectionProvider::AcceptSelectionL(0x%x)"), this );
       
   270     iEventParamList->Reset();
       
   271     iEventParamList->AppendL(
       
   272         TAiwGenericParam( EGenericParamSelectedCount,
       
   273             TAiwVariant(aNumberOfSelectedContacts ) ) );
       
   274     TBool acceptOutput = const_cast<MAiwNotifyCallback*>(iCallback)->
       
   275             HandleNotifyL( KAiwCmdSelect, KAiwEventOutParamCheck,
       
   276                 *iEventParamList, *iInParamList );
       
   277 
       
   278     return acceptOutput;
       
   279     }
       
   280 
       
   281 // --------------------------------------------------------------------------
       
   282 // CPbk2AiwSelectionProvider::PackParameterToBufferL
       
   283 // --------------------------------------------------------------------------
       
   284 //
       
   285 HBufC8* CPbk2AiwSelectionProvider::PackParameterToBufferL
       
   286         ( TGenericParamId aParamId,
       
   287           const CAiwGenericParamList& aInParamList) const
       
   288     {
       
   289     HBufC8* result = NULL;
       
   290 
       
   291     TInt paramIndex = 0;
       
   292     const TAiwGenericParam* paramData =
       
   293         aInParamList.FindFirst( paramIndex, aParamId );
       
   294 
       
   295     if ( paramData && paramData->Value().AsData().Ptr() )
       
   296         {
       
   297         result = paramData->Value().AsData().AllocL();
       
   298         }
       
   299     else if ( paramData && paramData->Value().AsDes().Ptr() )
       
   300         {
       
   301         // Data was given as 16-bit, transform it into 8-bit
       
   302         const TInt size( paramData->Value().AsDes().Size() );
       
   303         result = HBufC8::NewL( size );
       
   304         result->Des().Copy( paramData->Value().AsDes() );
       
   305         }
       
   306 
       
   307     return result;
       
   308     }
       
   309 
       
   310 
       
   311 // --------------------------------------------------------------------------
       
   312 // CPbk2AiwSelectionProvider::CreateConfigurationPackageL
       
   313 // --------------------------------------------------------------------------
       
   314 //
       
   315 void CPbk2AiwSelectionProvider::CreateConfigurationPackageL
       
   316         ( const CAiwGenericParamList& aInParamList )
       
   317     {
       
   318     // Store URIs
       
   319     HBufC8* storeUriBuffer = PackParameterToBufferL
       
   320         ( EGenericParamContactStoreUriArray, aInParamList );
       
   321     CleanupStack::PushL( storeUriBuffer );
       
   322 
       
   323     // Contact links
       
   324     HBufC8* linkBuffer = PackParameterToBufferL
       
   325         ( EGenericParamContactLinkArray, aInParamList );
       
   326     CleanupStack::PushL( linkBuffer );
       
   327 
       
   328     // Title pane
       
   329     HBufC* titlePaneText = ClientTitlePaneL();
       
   330     CleanupStack::PushL( titlePaneText );
       
   331 
       
   332     // Default priorities and contact view filter buffers are
       
   333     // allready created elsewhere
       
   334 
       
   335     TInt length = Pbk2IPCPackage::CountPackageSize( storeUriBuffer );
       
   336     length += Pbk2IPCPackage::CountPackageSize( linkBuffer );
       
   337     length += Pbk2IPCPackage::CountPackageSize( iDefaultPrioritiesBuffer );
       
   338     length += Pbk2IPCPackage::CountPackageSize( iContactViewFilterBuffer );
       
   339     length += Pbk2IPCPackage::CountPackageSize( titlePaneText );
       
   340 
       
   341     delete iConfigurationPackage;
       
   342     iConfigurationPackage = NULL;
       
   343     iConfigurationPackage = HBufC8::NewL( length );
       
   344     TPtr8 bufferPtr( iConfigurationPackage->Des() );
       
   345 
       
   346     RDesWriteStream writeStream( bufferPtr  );
       
   347     writeStream.PushL();
       
   348     Pbk2IPCPackage::ExternalizeL( storeUriBuffer, writeStream );
       
   349     Pbk2IPCPackage::ExternalizeL( linkBuffer, writeStream );
       
   350     Pbk2IPCPackage::ExternalizeL( iDefaultPrioritiesBuffer, writeStream );
       
   351     Pbk2IPCPackage::ExternalizeL( iContactViewFilterBuffer, writeStream );
       
   352     Pbk2IPCPackage::ExternalizeL( titlePaneText, writeStream );
       
   353     writeStream.CommitL();
       
   354 
       
   355     CleanupStack::PopAndDestroy( &writeStream );
       
   356     CleanupStack::PopAndDestroy( 3 ); // titlePaneText, linkBuffer,
       
   357                                       // storeUriBuffer
       
   358     }
       
   359 
       
   360 // --------------------------------------------------------------------------
       
   361 // CPbk2AiwSelectionProvider::CreateInstructionPackageL
       
   362 // --------------------------------------------------------------------------
       
   363 //
       
   364 void CPbk2AiwSelectionProvider::CreateInstructionPackageL
       
   365         ( const CAiwGenericParamList& aInParamList )
       
   366     {
       
   367     delete iInstructionsPackage;
       
   368     iInstructionsPackage = NULL;
       
   369     iInstructionsPackage = PackParameterToBufferL
       
   370         ( EGenericParamContactSelectionData, aInParamList );
       
   371     }
       
   372 
       
   373 // --------------------------------------------------------------------------
       
   374 // CPbk2AiwSelectionProvider::ValidateInstructionPackageL
       
   375 // --------------------------------------------------------------------------
       
   376 //
       
   377 void CPbk2AiwSelectionProvider::ValidateInstructionPackageL()
       
   378     {
       
   379     TInt version = KErrNotFound;
       
   380     RVPbkContactFieldDefaultPriorities* priorities = NULL;
       
   381     CVPbkFieldTypeSelector* viewFilter = NULL;
       
   382 
       
   383     if ( iInstructionsPackage )
       
   384         {
       
   385         // Version check
       
   386         version = TAiwContactSelectionDataBase::
       
   387             SelectionDataTypeFromBuffer( *iInstructionsPackage );
       
   388         if ( version == EAiwContactSelectionDataTypeNotDefined )
       
   389             {
       
   390             User::Leave( KErrArgument );
       
   391             }
       
   392 
       
   393         switch ( version )
       
   394             {
       
   395             case EAiwSingleItemSelectionV1:
       
   396                 {
       
   397                 TAiwSingleItemSelectionDataV1Pckg data;
       
   398                 data.Copy( iInstructionsPackage->Ptr(),
       
   399                     sizeof( TAiwSingleItemSelectionDataV1 ) );
       
   400 
       
   401                 priorities = data().DefaultPriorities();
       
   402                 break;
       
   403                 }
       
   404 
       
   405             case EAiwSingleItemSelectionV2:
       
   406                 {
       
   407                 TAiwSingleItemSelectionDataV2Pckg data;
       
   408                 data.Copy( iInstructionsPackage->Ptr(),
       
   409                     sizeof( TAiwSingleItemSelectionDataV2 ) );
       
   410 
       
   411                 priorities = data().DefaultPriorities();
       
   412                 break;
       
   413                 }
       
   414             case EAiwSingleItemSelectionV3:
       
   415                 {
       
   416                 TAiwSingleItemSelectionDataV3Pckg data;
       
   417                 data.Copy( iInstructionsPackage->Ptr(),
       
   418                     sizeof( TAiwSingleItemSelectionDataV3 ) );
       
   419 
       
   420                 priorities = data().DefaultPriorities();
       
   421                 viewFilter = data().FetchFilter();
       
   422                 break;
       
   423                 }
       
   424             case EAiwSingleEntrySelectionV1:
       
   425                 {
       
   426                 TAiwSingleEntrySelectionDataV1Pckg data;
       
   427                 data.Copy( iInstructionsPackage->Ptr(),
       
   428                     sizeof( TAiwSingleEntrySelectionDataV1 ) );
       
   429                 break;
       
   430                 }
       
   431             case EAiwSingleEntrySelectionV2:
       
   432                 {
       
   433                 TAiwSingleEntrySelectionDataV2Pckg data;
       
   434                 data.Copy( iInstructionsPackage->Ptr(),
       
   435                     sizeof( TAiwSingleEntrySelectionDataV2 ) );
       
   436 
       
   437                 viewFilter = data().FetchFilter();
       
   438                 break;
       
   439                 }
       
   440             case EAiwMultipleEntrySelectionV1:
       
   441                 {
       
   442                 TAiwMultipleEntrySelectionDataV1Pckg data;
       
   443                 data.Copy( iInstructionsPackage->Ptr(),
       
   444                     sizeof( TAiwMultipleEntrySelectionDataV1 ) );
       
   445                 break;
       
   446                 }
       
   447             case EAiwMultipleEntrySelectionV2:
       
   448                 {
       
   449                 TAiwMultipleEntrySelectionDataV2Pckg data;
       
   450                 data.Copy( iInstructionsPackage->Ptr(),
       
   451                     sizeof( TAiwMultipleEntrySelectionDataV2 ) );
       
   452 
       
   453                 viewFilter = data().FetchFilter();
       
   454                 break;
       
   455                 }
       
   456             case EAiwMultipleItemSelectionV1:
       
   457                 {
       
   458                 TAiwMultipleItemSelectionDataV1Pckg data;
       
   459                 data.Copy( iInstructionsPackage->Ptr(),
       
   460                     sizeof( TAiwMultipleItemSelectionDataV1 ) );
       
   461 
       
   462                 priorities = data().DefaultPriorities();
       
   463                 viewFilter = data().FetchFilter();
       
   464                 break;
       
   465                 }
       
   466             default:
       
   467                 {
       
   468                 User::Leave( KErrArgument );
       
   469                 break;
       
   470                 }
       
   471             }
       
   472         }
       
   473     else
       
   474         {
       
   475         // Perform default fetch
       
   476         TAiwMultipleEntrySelectionDataV1 data;
       
   477         TAiwMultipleEntrySelectionDataV1Pckg dataPckg( data );
       
   478         iInstructionsPackage = dataPckg.AllocL();
       
   479         }
       
   480 
       
   481     delete iDefaultPrioritiesBuffer;
       
   482     iDefaultPrioritiesBuffer = NULL;
       
   483     if ( priorities )
       
   484         {
       
   485         iDefaultPrioritiesBuffer = priorities->ExternalizeLC();
       
   486         CleanupStack::Pop(); // iDefaultPrioritiesBuffer
       
   487         }
       
   488 
       
   489     delete iContactViewFilterBuffer;
       
   490     iContactViewFilterBuffer = NULL;
       
   491     if ( viewFilter )
       
   492         {
       
   493         iContactViewFilterBuffer = viewFilter->ExternalizeLC();
       
   494         CleanupStack::Pop(); // iContactViewFilterBuffer
       
   495         }
       
   496     }
       
   497 
       
   498 // --------------------------------------------------------------------------
       
   499 // CPbk2AiwSelectionProvider::ClientTitlePaneL
       
   500 // --------------------------------------------------------------------------
       
   501 //
       
   502 HBufC* CPbk2AiwSelectionProvider::ClientTitlePaneL()
       
   503     {
       
   504     HBufC* result = NULL;
       
   505 
       
   506     CEikStatusPane* statusPane =
       
   507         CEikonEnv::Static()->AppUiFactory()->StatusPane();
       
   508 
       
   509     if ( statusPane &&
       
   510          statusPane->PaneCapabilities(
       
   511             TUid::Uid( EEikStatusPaneUidTitle ) ).IsPresent() )
       
   512         {
       
   513         CAknTitlePane* titlePane = static_cast<CAknTitlePane*>( statusPane->
       
   514             ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   515 
       
   516         if ( titlePane->Text() )
       
   517             {
       
   518             result = titlePane->Text()->AllocL();
       
   519             }
       
   520         }
       
   521 
       
   522     return result;
       
   523     }
       
   524 
       
   525 // End of File