phonebookui/Phonebook2/UIServices/src/CPbk2AiwSelectionProvider.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     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     iEventParamList->AppendL(
       
   275         TAiwGenericParam( EGenericParamContactLinkArray,
       
   276             TAiwVariant( aContactLink ) ) );
       
   277     TBool acceptOutput = const_cast<MAiwNotifyCallback*>(iCallback)->
       
   278             HandleNotifyL( KAiwCmdSelect, KAiwEventOutParamCheck,
       
   279                 *iEventParamList, *iInParamList );
       
   280 
       
   281     return acceptOutput;
       
   282     }
       
   283 
       
   284 // --------------------------------------------------------------------------
       
   285 // CPbk2AiwSelectionProvider::PackParameterToBufferL
       
   286 // --------------------------------------------------------------------------
       
   287 //
       
   288 HBufC8* CPbk2AiwSelectionProvider::PackParameterToBufferL
       
   289         ( TGenericParamId aParamId,
       
   290           const CAiwGenericParamList& aInParamList) const
       
   291     {
       
   292     HBufC8* result = NULL;
       
   293 
       
   294     TInt paramIndex = 0;
       
   295     const TAiwGenericParam* paramData =
       
   296         aInParamList.FindFirst( paramIndex, aParamId );
       
   297 
       
   298     if ( paramData && paramData->Value().AsData().Ptr() )
       
   299         {
       
   300         result = paramData->Value().AsData().AllocL();
       
   301         }
       
   302     else if ( paramData && paramData->Value().AsDes().Ptr() )
       
   303         {
       
   304         // Data was given as 16-bit, transform it into 8-bit
       
   305         const TInt size( paramData->Value().AsDes().Size() );
       
   306         result = HBufC8::NewL( size );
       
   307         result->Des().Copy( paramData->Value().AsDes() );
       
   308         }
       
   309 
       
   310     return result;
       
   311     }
       
   312 
       
   313 
       
   314 // --------------------------------------------------------------------------
       
   315 // CPbk2AiwSelectionProvider::CreateConfigurationPackageL
       
   316 // --------------------------------------------------------------------------
       
   317 //
       
   318 void CPbk2AiwSelectionProvider::CreateConfigurationPackageL
       
   319         ( const CAiwGenericParamList& aInParamList )
       
   320     {
       
   321     // Store URIs
       
   322     HBufC8* storeUriBuffer = PackParameterToBufferL
       
   323         ( EGenericParamContactStoreUriArray, aInParamList );
       
   324     CleanupStack::PushL( storeUriBuffer );
       
   325 
       
   326     // Contact links
       
   327     HBufC8* linkBuffer = PackParameterToBufferL
       
   328         ( EGenericParamContactLinkArray, aInParamList );
       
   329     CleanupStack::PushL( linkBuffer );
       
   330 
       
   331     // StatusPane Id
       
   332     HBufC8* statusPaneId = PackParameterToBufferL
       
   333         ( EGenericParamUnspecified, aInParamList );
       
   334     CleanupStack::PushL( statusPaneId );
       
   335         
       
   336     // Title pane
       
   337     HBufC* titlePaneText = ClientTitlePaneL();
       
   338     CleanupStack::PushL( titlePaneText );
       
   339 
       
   340     // Default priorities and contact view filter buffers are
       
   341     // allready created elsewhere
       
   342 
       
   343     TInt length = Pbk2IPCPackage::CountPackageSize( storeUriBuffer );
       
   344     length += Pbk2IPCPackage::CountPackageSize( linkBuffer );
       
   345     length += Pbk2IPCPackage::CountPackageSize( iDefaultPrioritiesBuffer );
       
   346     length += Pbk2IPCPackage::CountPackageSize( iContactViewFilterBuffer );
       
   347     length += Pbk2IPCPackage::CountPackageSize( titlePaneText );
       
   348     length += Pbk2IPCPackage::CountPackageSize( statusPaneId );
       
   349 
       
   350     delete iConfigurationPackage;
       
   351     iConfigurationPackage = NULL;
       
   352     iConfigurationPackage = HBufC8::NewL( length );
       
   353     TPtr8 bufferPtr( iConfigurationPackage->Des() );
       
   354 
       
   355     RDesWriteStream writeStream( bufferPtr  );
       
   356     writeStream.PushL();
       
   357     Pbk2IPCPackage::ExternalizeL( storeUriBuffer, writeStream );
       
   358     Pbk2IPCPackage::ExternalizeL( linkBuffer, writeStream );
       
   359     Pbk2IPCPackage::ExternalizeL( iDefaultPrioritiesBuffer, writeStream );
       
   360     Pbk2IPCPackage::ExternalizeL( iContactViewFilterBuffer, writeStream );
       
   361     Pbk2IPCPackage::ExternalizeL( titlePaneText, writeStream );
       
   362     Pbk2IPCPackage::ExternalizeL( statusPaneId, writeStream );
       
   363     writeStream.CommitL();
       
   364 
       
   365     CleanupStack::PopAndDestroy( &writeStream );
       
   366     CleanupStack::PopAndDestroy( 4 ); // titlePaneText, statusPaneId, linkBuffer,
       
   367                                       // storeUriBuffer
       
   368     }
       
   369 
       
   370 // --------------------------------------------------------------------------
       
   371 // CPbk2AiwSelectionProvider::CreateInstructionPackageL
       
   372 // --------------------------------------------------------------------------
       
   373 //
       
   374 void CPbk2AiwSelectionProvider::CreateInstructionPackageL
       
   375         ( const CAiwGenericParamList& aInParamList )
       
   376     {
       
   377     delete iInstructionsPackage;
       
   378     iInstructionsPackage = NULL;
       
   379     iInstructionsPackage = PackParameterToBufferL
       
   380         ( EGenericParamContactSelectionData, aInParamList );
       
   381     }
       
   382 
       
   383 // --------------------------------------------------------------------------
       
   384 // CPbk2AiwSelectionProvider::ValidateInstructionPackageL
       
   385 // --------------------------------------------------------------------------
       
   386 //
       
   387 void CPbk2AiwSelectionProvider::ValidateInstructionPackageL()
       
   388     {
       
   389     TInt version = KErrNotFound;
       
   390     RVPbkContactFieldDefaultPriorities* priorities = NULL;
       
   391     CVPbkFieldTypeSelector* viewFilter = NULL;
       
   392 
       
   393     if ( iInstructionsPackage )
       
   394         {
       
   395         // Version check
       
   396         version = TAiwContactSelectionDataBase::
       
   397             SelectionDataTypeFromBuffer( *iInstructionsPackage );
       
   398         if ( version == EAiwContactSelectionDataTypeNotDefined )
       
   399             {
       
   400             User::Leave( KErrArgument );
       
   401             }
       
   402 
       
   403         switch ( version )
       
   404             {
       
   405             case EAiwSingleItemSelectionV1:
       
   406                 {
       
   407                 TAiwSingleItemSelectionDataV1Pckg data;
       
   408                 data.Copy( iInstructionsPackage->Ptr(),
       
   409                     sizeof( TAiwSingleItemSelectionDataV1 ) );
       
   410 
       
   411                 priorities = data().DefaultPriorities();
       
   412                 break;
       
   413                 }
       
   414 
       
   415             case EAiwSingleItemSelectionV2:
       
   416                 {
       
   417                 TAiwSingleItemSelectionDataV2Pckg data;
       
   418                 data.Copy( iInstructionsPackage->Ptr(),
       
   419                     sizeof( TAiwSingleItemSelectionDataV2 ) );
       
   420 
       
   421                 priorities = data().DefaultPriorities();
       
   422                 break;
       
   423                 }
       
   424             case EAiwSingleItemSelectionV3:
       
   425                 {
       
   426                 TAiwSingleItemSelectionDataV3Pckg data;
       
   427                 data.Copy( iInstructionsPackage->Ptr(),
       
   428                     sizeof( TAiwSingleItemSelectionDataV3 ) );
       
   429 
       
   430                 priorities = data().DefaultPriorities();
       
   431                 viewFilter = data().FetchFilter();
       
   432                 break;
       
   433                 }
       
   434             case EAiwSingleEntrySelectionV1:
       
   435                 {
       
   436                 TAiwSingleEntrySelectionDataV1Pckg data;
       
   437                 data.Copy( iInstructionsPackage->Ptr(),
       
   438                     sizeof( TAiwSingleEntrySelectionDataV1 ) );
       
   439                 break;
       
   440                 }
       
   441             case EAiwSingleEntrySelectionV2:
       
   442                 {
       
   443                 TAiwSingleEntrySelectionDataV2Pckg data;
       
   444                 data.Copy( iInstructionsPackage->Ptr(),
       
   445                     sizeof( TAiwSingleEntrySelectionDataV2 ) );
       
   446 
       
   447                 viewFilter = data().FetchFilter();
       
   448                 break;
       
   449                 }
       
   450             case EAiwMultipleEntrySelectionV1:
       
   451                 {
       
   452                 TAiwMultipleEntrySelectionDataV1Pckg data;
       
   453                 data.Copy( iInstructionsPackage->Ptr(),
       
   454                     sizeof( TAiwMultipleEntrySelectionDataV1 ) );
       
   455                 break;
       
   456                 }
       
   457             case EAiwMultipleEntrySelectionV2:
       
   458                 {
       
   459                 TAiwMultipleEntrySelectionDataV2Pckg data;
       
   460                 data.Copy( iInstructionsPackage->Ptr(),
       
   461                     sizeof( TAiwMultipleEntrySelectionDataV2 ) );
       
   462 
       
   463                 viewFilter = data().FetchFilter();
       
   464                 break;
       
   465                 }
       
   466             case EAiwMultipleItemSelectionV1:
       
   467                 {
       
   468                 TAiwMultipleItemSelectionDataV1Pckg data;
       
   469                 data.Copy( iInstructionsPackage->Ptr(),
       
   470                     sizeof( TAiwMultipleItemSelectionDataV1 ) );
       
   471 
       
   472                 priorities = data().DefaultPriorities();
       
   473                 viewFilter = data().FetchFilter();
       
   474                 break;
       
   475                 }
       
   476             default:
       
   477                 {
       
   478                 User::Leave( KErrArgument );
       
   479                 break;
       
   480                 }
       
   481             }
       
   482         }
       
   483     else
       
   484         {
       
   485         // Perform default fetch
       
   486         TAiwMultipleEntrySelectionDataV1 data;
       
   487         TAiwMultipleEntrySelectionDataV1Pckg dataPckg( data );
       
   488         iInstructionsPackage = dataPckg.AllocL();
       
   489         }
       
   490 
       
   491     delete iDefaultPrioritiesBuffer;
       
   492     iDefaultPrioritiesBuffer = NULL;
       
   493     if ( priorities )
       
   494         {
       
   495         iDefaultPrioritiesBuffer = priorities->ExternalizeLC();
       
   496         CleanupStack::Pop(); // iDefaultPrioritiesBuffer
       
   497         }
       
   498 
       
   499     delete iContactViewFilterBuffer;
       
   500     iContactViewFilterBuffer = NULL;
       
   501     if ( viewFilter )
       
   502         {
       
   503         iContactViewFilterBuffer = viewFilter->ExternalizeLC();
       
   504         CleanupStack::Pop(); // iContactViewFilterBuffer
       
   505         }
       
   506     }
       
   507 
       
   508 // --------------------------------------------------------------------------
       
   509 // CPbk2AiwSelectionProvider::ClientTitlePaneL
       
   510 // --------------------------------------------------------------------------
       
   511 //
       
   512 HBufC* CPbk2AiwSelectionProvider::ClientTitlePaneL()
       
   513     {
       
   514     HBufC* result = NULL;
       
   515 
       
   516     CEikStatusPane* statusPane =
       
   517         CEikonEnv::Static()->AppUiFactory()->StatusPane();
       
   518 
       
   519     if ( statusPane &&
       
   520          statusPane->PaneCapabilities(
       
   521             TUid::Uid( EEikStatusPaneUidTitle ) ).IsPresent() )
       
   522         {
       
   523         CAknTitlePane* titlePane = static_cast<CAknTitlePane*>( statusPane->
       
   524             ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   525 
       
   526         if ( titlePane->Text() )
       
   527             {
       
   528             result = titlePane->Text()->AllocL();
       
   529             }
       
   530         }
       
   531 
       
   532     return result;
       
   533     }
       
   534 
       
   535 // End of File