phonebookui/Phonebook2/ServerApplication/src/CPbk2MultiContactDataAssigner.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
child 68 9da50d567e3c
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 multiple contact data assigner.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2MultiContactDataAssigner.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "CPbk2ServerAppAppUi.h"
       
    23 #include "MPbk2UiServiceObserver.h"
       
    24 #include "CPbk2SelectMultiplePropertyPhase.h"
       
    25 #include "CPbk2ContactFetchPhase.h"
       
    26 #include "CPbk2MultiAssignDataPhase.h"
       
    27 #include "CPbk2PrepareMultipleAssignPhase.h"
       
    28 #include "TPbk2TitlePaneOperator.h"
       
    29 #include "TPbk2ServerMessageDataRetriever.h"
       
    30 #include "CPbk2ServerAppStoreManager.h"
       
    31 #include "MPbk2SelectFieldProperty.h"
       
    32 #include <CPbk2FetchDlg.h>
       
    33 #include <MPbk2ApplicationServices.h>
       
    34 #include <Pbk2UIControls.rsg>
       
    35 #include <Pbk2ServerApp.rsg>
       
    36 
       
    37 // Virtual Phonebook
       
    38 #include <CVPbkContactManager.h>
       
    39 #include <CVPbkContactStoreUriArray.h>
       
    40 #include <MVPbkContactLink.h>
       
    41 #include <CVPbkFieldTypeSelector.h>
       
    42 
       
    43 // System includes
       
    44 #include <AiwContactAssignDataTypes.h>
       
    45 
       
    46 using namespace AiwContactAssign;
       
    47 
       
    48 /// Unnamed namespace for local definitions
       
    49 namespace {
       
    50 
       
    51 #ifdef _DEBUG
       
    52 
       
    53 enum TPanicCode
       
    54     {
       
    55     EPanicLogicPhaseCompletion
       
    56     };
       
    57 
       
    58 void Panic(TPanicCode aReason)
       
    59     {
       
    60     _LIT(KPanicText, "CPbk2MultiContactDataAssigner");
       
    61     User::Panic(KPanicText,aReason);
       
    62     }
       
    63 
       
    64 #endif // _DEBUG
       
    65 
       
    66 /**
       
    67  * Sets title pane.
       
    68  *
       
    69  * @param aDataRetriever    Server message data retriever.
       
    70  * @param aFlags            Assign flags.
       
    71  * @param aMessage          Server message.
       
    72  */
       
    73 void SetTitlePaneL
       
    74         ( TPbk2ServerMessageDataRetriever& aDataRetriever, TUint aFlags,
       
    75           const RMessage2& aMessage )
       
    76     {
       
    77     HBufC* titlePaneText = NULL;
       
    78     if ( !( aFlags & AiwContactAssign::EUseProviderTitle ) )
       
    79         {
       
    80         titlePaneText = aDataRetriever.GetTitlePaneTextL( aMessage );
       
    81         }
       
    82     TPbk2TitlePaneOperator titlePaneOperator;
       
    83     titlePaneOperator.SetTitlePaneL( titlePaneText ); // takes ownership
       
    84     }
       
    85 
       
    86 } /// namespace
       
    87 
       
    88 
       
    89 // --------------------------------------------------------------------------
       
    90 // CPbk2MultiContactDataAssigner::CPbk2MultiContactDataAssigner
       
    91 // --------------------------------------------------------------------------
       
    92 //
       
    93 CPbk2MultiContactDataAssigner::CPbk2MultiContactDataAssigner
       
    94         ( MPbk2UiServiceObserver& aObserver ) :
       
    95             iObserver( aObserver )
       
    96     {
       
    97     }
       
    98 
       
    99 // --------------------------------------------------------------------------
       
   100 // CPbk2MultiContactDataAssigner::~CPbk2MultiContactDataAssigner
       
   101 // --------------------------------------------------------------------------
       
   102 //
       
   103 CPbk2MultiContactDataAssigner::~CPbk2MultiContactDataAssigner()
       
   104     {
       
   105     delete iSelectPropertyPhase;
       
   106     delete iFetchPhase;
       
   107     delete iPrepareAssignPhase;
       
   108     delete iAssignDataPhase;
       
   109     delete iStoreUris;
       
   110     delete iDataBuffer;
       
   111     delete iAddressSelectFilterBuffer;
       
   112     delete iPreselectedContacts;
       
   113     delete iSelectFieldProperty;
       
   114     delete iContactViewFilter;
       
   115     delete iStoreManager;
       
   116     }
       
   117 
       
   118 // --------------------------------------------------------------------------
       
   119 // CPbk2MultiContactDataAssigner::NewL
       
   120 // --------------------------------------------------------------------------
       
   121 //
       
   122 CPbk2MultiContactDataAssigner* CPbk2MultiContactDataAssigner::NewL(
       
   123         const RMessage2& aFetchCompleteMessage,
       
   124         MPbk2UiServiceObserver& aObserver )
       
   125     {
       
   126     CPbk2MultiContactDataAssigner* self =
       
   127         new ( ELeave ) CPbk2MultiContactDataAssigner( aObserver );
       
   128     CleanupStack::PushL( self );
       
   129     self->ConstructL( aFetchCompleteMessage );
       
   130     CleanupStack::Pop( self );
       
   131     return self;
       
   132     }
       
   133 
       
   134 // --------------------------------------------------------------------------
       
   135 // CPbk2MultiContactDataAssigner::ConstructL
       
   136 // --------------------------------------------------------------------------
       
   137 //
       
   138 void CPbk2MultiContactDataAssigner::ConstructL( const RMessage2& aMessage )
       
   139     {
       
   140     // Retrieve data from the client-server message
       
   141     TPbk2ServerMessageDataRetriever dataRetriever;
       
   142     TUint flags = dataRetriever.MultipleContactAssignFlagsL( aMessage );
       
   143 
       
   144     // Set title pane
       
   145     SetTitlePaneL( dataRetriever, flags, aMessage );
       
   146 
       
   147     CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&>
       
   148         ( *CEikonEnv::Static()->EikAppUi() );
       
   149 
       
   150     iPreselectedContacts = dataRetriever.GetPreselectedContactLinksL
       
   151         ( aMessage, appUi.ApplicationServices().ContactManager() );
       
   152     iStoreUris = dataRetriever.GetContactStoreUriArrayL
       
   153         ( aMessage, appUi.ApplicationServices().StoreConfiguration(),
       
   154           iPreselectedContacts, iUseDeviceConfig );
       
   155     iAddressSelectFilterBuffer =
       
   156         dataRetriever.GetAddressSelectFilterBufferL( aMessage );
       
   157     iDataBuffer = dataRetriever.GetDataBufferL( aMessage );
       
   158     iMimeType = dataRetriever.GetMimeTypeL( aMessage );
       
   159     
       
   160     // check if the client has special orientation setting to make sure keeping 
       
   161     // the same orientation with the client.
       
   162     TInt clientOrientationType = dataRetriever.GetOrietationTypeL( aMessage );
       
   163     if( clientOrientationType == CAknAppUi::EAppUiOrientationLandscape )
       
   164         {
       
   165         appUi.SetOrientationL( CAknAppUi::EAppUiOrientationLandscape );
       
   166         }
       
   167     else if( clientOrientationType == CAknAppUi::EAppUiOrientationPortrait )
       
   168         {
       
   169         appUi.SetOrientationL( CAknAppUi::EAppUiOrientationPortrait );
       
   170         }
       
   171 
       
   172     // Drop all non-writable stores
       
   173     iStoreManager = CPbk2ServerAppStoreManager::NewL
       
   174         ( appUi.StoreManager(),
       
   175           appUi.ApplicationServices().ContactManager() );
       
   176     iStoreManager->RemoveReadOnlyStoreUris
       
   177         ( *iStoreUris, appUi.ApplicationServices().StoreProperties() );
       
   178 
       
   179     // Retrieve view filter
       
   180     iContactViewFilter =
       
   181         dataRetriever.GetContactViewFilterForAttributeAssignL
       
   182             ( aMessage,
       
   183               appUi.ApplicationServices().ContactManager().FieldTypes() );
       
   184     }
       
   185 
       
   186 // --------------------------------------------------------------------------
       
   187 // CPbk2MultiContactDataAssigner::LaunchServiceL
       
   188 // --------------------------------------------------------------------------
       
   189 //
       
   190 void CPbk2MultiContactDataAssigner::LaunchServiceL()
       
   191     {
       
   192     // Open stores
       
   193     iStoreManager->LoadAndOpenContactStoresL( *iStoreUris, *this, ETrue );
       
   194     }
       
   195 
       
   196 // --------------------------------------------------------------------------
       
   197 // CPbk2MultiContactDataAssigner::CancelService
       
   198 // --------------------------------------------------------------------------
       
   199 //
       
   200 void CPbk2MultiContactDataAssigner::CancelService()
       
   201     {
       
   202     if ( iAssignDataPhase )
       
   203         {
       
   204         iAssignDataPhase->CancelServicePhase();
       
   205         }
       
   206 
       
   207     if ( iPrepareAssignPhase )
       
   208         {
       
   209         iPrepareAssignPhase->CancelServicePhase();
       
   210         }
       
   211 
       
   212     if ( iSelectPropertyPhase )
       
   213         {
       
   214         iSelectPropertyPhase->CancelServicePhase();
       
   215         }
       
   216 
       
   217     if ( iFetchPhase )
       
   218         {
       
   219         iFetchPhase->CancelServicePhase();
       
   220         }
       
   221     }
       
   222 
       
   223 // --------------------------------------------------------------------------
       
   224 // CPbk2MultiContactDataAssigner::AcceptDelayedContactsL
       
   225 // --------------------------------------------------------------------------
       
   226 //
       
   227 void CPbk2MultiContactDataAssigner::AcceptDelayedContactsL
       
   228         ( const TDesC8& /*aContactLinkBuffer*/ )
       
   229     {
       
   230     // Do nothing
       
   231     }
       
   232 
       
   233 // --------------------------------------------------------------------------
       
   234 // CPbk2MultiContactDataAssigner::AcceptDelayedContactsL
       
   235 // --------------------------------------------------------------------------
       
   236 //
       
   237 void CPbk2MultiContactDataAssigner::DenyDelayedContactsL
       
   238         ( const TDesC8& /*aContactLinkBuffer*/ )
       
   239     {
       
   240     // Do nothing
       
   241     }
       
   242 
       
   243 // --------------------------------------------------------------------------
       
   244 // CPbk2MultiContactDataAssigner::ExitServiceL
       
   245 // --------------------------------------------------------------------------
       
   246 //
       
   247 void CPbk2MultiContactDataAssigner::ExitServiceL( TInt aExitCommandId )
       
   248     {
       
   249     if ( iAssignDataPhase )
       
   250         {
       
   251         iAssignDataPhase->RequestCancelL( aExitCommandId );
       
   252         }
       
   253 
       
   254     if ( iPrepareAssignPhase )
       
   255         {
       
   256         iPrepareAssignPhase->RequestCancelL( aExitCommandId );
       
   257         }
       
   258 
       
   259     if ( iSelectPropertyPhase )
       
   260         {
       
   261         iSelectPropertyPhase->RequestCancelL( aExitCommandId );
       
   262         }
       
   263 
       
   264     if ( iFetchPhase )
       
   265         {
       
   266         iFetchPhase->RequestCancelL( aExitCommandId );
       
   267         }
       
   268     }
       
   269 
       
   270 // --------------------------------------------------------------------------
       
   271 // CPbk2MultiContactDataAssigner::ServiceResults
       
   272 // --------------------------------------------------------------------------
       
   273 //
       
   274 void CPbk2MultiContactDataAssigner::ServiceResults(TServiceResults* aResults) const
       
   275     {
       
   276     if ( iAssignDataPhase )
       
   277         {
       
   278         aResults->iLinkArray = iAssignDataPhase->Results();
       
   279         aResults->iExtraData = iAssignDataPhase->ExtraResultData();
       
   280         aResults->iFieldContent = iAssignDataPhase->FieldContent();
       
   281         }
       
   282     }
       
   283 
       
   284 // --------------------------------------------------------------------------
       
   285 // CPbk2MultiContactDataAssigner::NextPhase
       
   286 // --------------------------------------------------------------------------
       
   287 //
       
   288 void CPbk2MultiContactDataAssigner::NextPhase
       
   289         ( MPbk2ServicePhase& aPhase )
       
   290     {
       
   291     TInt err = KErrNone;
       
   292 
       
   293     if ( &aPhase == iFetchPhase )
       
   294         {
       
   295         MVPbkContactLinkArray* fetchResults = iFetchPhase->Results();
       
   296         __ASSERT_DEBUG( fetchResults && fetchResults->Count() > 0,
       
   297             Panic( EPanicLogicPhaseCompletion ) );
       
   298 
       
   299         TRAP( err, LaunchSelectMultiPropertyPhaseL( fetchResults ) );
       
   300         }
       
   301     else if ( &aPhase == iSelectPropertyPhase )
       
   302         {
       
   303         MVPbkContactLinkArray* selectPropertyResults
       
   304             = iSelectPropertyPhase->Results();
       
   305         __ASSERT_DEBUG( selectPropertyResults &&
       
   306             selectPropertyResults->Count() > 0,
       
   307                 Panic( EPanicLogicPhaseCompletion ) );
       
   308 
       
   309         TRAP( err, LaunchPrepareMultiAssignPhaseL( selectPropertyResults ) );
       
   310         }
       
   311     else if ( &aPhase == iPrepareAssignPhase )
       
   312         {
       
   313         MVPbkContactLinkArray* prepareResults
       
   314             = iPrepareAssignPhase->Results();
       
   315         __ASSERT_DEBUG( prepareResults &&
       
   316             prepareResults->Count() > 0,
       
   317                 Panic( EPanicLogicPhaseCompletion ) );
       
   318 
       
   319         TRAP( err, LaunchAssignPhaseL( prepareResults ) );
       
   320         }
       
   321     else if ( &aPhase == iAssignDataPhase )
       
   322         {
       
   323         iObserver.ServiceComplete();
       
   324         }
       
   325     else
       
   326         {
       
   327         __ASSERT_DEBUG( EFalse, Panic( EPanicLogicPhaseCompletion ) );
       
   328         }
       
   329 
       
   330     if ( err != KErrNone )
       
   331         {
       
   332         iObserver.ServiceError( err );
       
   333         }
       
   334     }
       
   335 
       
   336 // --------------------------------------------------------------------------
       
   337 // CPbk2MultiContactDataAssigner::PreviousPhase
       
   338 // --------------------------------------------------------------------------
       
   339 //
       
   340 void CPbk2MultiContactDataAssigner::PreviousPhase
       
   341         ( MPbk2ServicePhase& /*aPhase*/ )
       
   342     {
       
   343     // Not supported in multiple assign
       
   344     }
       
   345 
       
   346 // --------------------------------------------------------------------------
       
   347 // CPbk2MultiContactDataAssigner::PhaseCanceled
       
   348 // --------------------------------------------------------------------------
       
   349 //
       
   350 void CPbk2MultiContactDataAssigner::PhaseCanceled
       
   351         ( MPbk2ServicePhase& /*aPhase*/ )
       
   352     {
       
   353     iObserver.ServiceCanceled();
       
   354     }
       
   355 
       
   356 // --------------------------------------------------------------------------
       
   357 // CPbk2MultiContactDataAssigner::PhaseAborted
       
   358 // --------------------------------------------------------------------------
       
   359 //
       
   360 void CPbk2MultiContactDataAssigner::PhaseAborted
       
   361         ( MPbk2ServicePhase& /*aPhase*/ )
       
   362     {
       
   363     iObserver.ServiceAborted();
       
   364     }
       
   365 
       
   366 // --------------------------------------------------------------------------
       
   367 // CPbk2MultiContactDataAssigner::PhaseError
       
   368 // --------------------------------------------------------------------------
       
   369 //
       
   370 void CPbk2MultiContactDataAssigner::PhaseError
       
   371         ( MPbk2ServicePhase& /*aPhase*/, TInt aErrorCode )
       
   372     {
       
   373     iObserver.ServiceError( aErrorCode );
       
   374     }
       
   375 
       
   376 // --------------------------------------------------------------------------
       
   377 // CPbk2MultiContactDataAssigner::PhaseOkToExit
       
   378 // --------------------------------------------------------------------------
       
   379 //
       
   380 TBool CPbk2MultiContactDataAssigner::PhaseOkToExit
       
   381         ( MPbk2ServicePhase& /*aPhase*/, TInt aCommandId )
       
   382     {
       
   383     // Deny exit and pass an asynchronous query to the consumer,
       
   384     // which may later approve exit
       
   385     iObserver.CompleteExitMessage( aCommandId );
       
   386     return EFalse;
       
   387     }
       
   388 
       
   389 // --------------------------------------------------------------------------
       
   390 // CPbk2MultiContactDataAssigner::PhaseAccept
       
   391 // --------------------------------------------------------------------------
       
   392 //
       
   393 void CPbk2MultiContactDataAssigner::PhaseAccept
       
   394         ( MPbk2ServicePhase& /*aPhase*/, const TDesC8& /*aMarkedEntries*/,
       
   395           const TDesC8& /*aLinkData*/ )
       
   396     {
       
   397     // Not supported in assign
       
   398     }
       
   399 
       
   400 // --------------------------------------------------------------------------
       
   401 // CPbk2MultiContactDataAssigner::ContactUiReadyL
       
   402 // --------------------------------------------------------------------------
       
   403 //
       
   404 void CPbk2MultiContactDataAssigner::ContactUiReadyL
       
   405         ( MPbk2StartupMonitor& aStartupMonitor )
       
   406     {
       
   407     aStartupMonitor.DeregisterEvents( *this );
       
   408     if ( iPreselectedContacts && iPreselectedContacts->Count() > 0 )
       
   409         {
       
   410         if ( iStoreManager->ContactsAvailableL( *iPreselectedContacts ) )
       
   411             {
       
   412             LaunchSelectMultiPropertyPhaseL( iPreselectedContacts );
       
   413             }
       
   414         else
       
   415             {
       
   416             iObserver.ServiceError( KErrNotSupported );
       
   417             }
       
   418         }
       
   419     else
       
   420         {
       
   421         LaunchFetchPhaseL();
       
   422         }
       
   423     }
       
   424 
       
   425 // --------------------------------------------------------------------------
       
   426 // CPbk2MultiContactDataAssigner::StartupCanceled
       
   427 // --------------------------------------------------------------------------
       
   428 //
       
   429 void  CPbk2MultiContactDataAssigner::StartupCanceled( TInt aErrorCode )
       
   430     {
       
   431     if ( aErrorCode == KErrCancel )
       
   432         {
       
   433         iObserver.ServiceCanceled();
       
   434         }
       
   435     else
       
   436         {
       
   437         iObserver.ServiceError( aErrorCode );
       
   438         }
       
   439     }
       
   440 
       
   441 // --------------------------------------------------------------------------
       
   442 // CPbk2MultiContactDataAssigner::LaunchFetchPhaseL
       
   443 // --------------------------------------------------------------------------
       
   444 //
       
   445 void CPbk2MultiContactDataAssigner::LaunchFetchPhaseL()
       
   446     {
       
   447     CPbk2FetchDlg::TParams params;
       
   448     params.iResId = R_PBK2_MULTIPLE_ENTRY_FETCH_DLG;
       
   449     params.iFlags = CPbk2FetchDlg::EFetchMultiple;
       
   450 
       
   451     delete iFetchPhase;
       
   452     iFetchPhase = NULL;
       
   453     iFetchPhase = CPbk2ContactFetchPhase::NewL
       
   454         ( *this, *iStoreManager, params, ETrue,
       
   455           MPbk2FetchDlgObserver::EFetchYes, iContactViewFilter,
       
   456           iUseDeviceConfig, iStoreUris );
       
   457 
       
   458     CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&>
       
   459         ( *CEikonEnv::Static()->EikAppUi() );
       
   460 
       
   461     // Change layout to fetch's layout
       
   462     appUi.ChangeStatuspaneLayoutL(
       
   463         CPbk2ServerAppAppUi::EStatusPaneLayoutUsual );
       
   464 
       
   465     iFetchPhase->LaunchServicePhaseL();
       
   466     }
       
   467 
       
   468 // --------------------------------------------------------------------------
       
   469 // CPbk2MultiContactDataAssigner::LaunchSelectMultiPropertyPhaseL
       
   470 // --------------------------------------------------------------------------
       
   471 //
       
   472 void CPbk2MultiContactDataAssigner::LaunchSelectMultiPropertyPhaseL
       
   473         ( MVPbkContactLinkArray* aContactLinks )
       
   474     {
       
   475     delete iSelectPropertyPhase;
       
   476     iSelectPropertyPhase = NULL;
       
   477 
       
   478     // Prepare parameters by reseting them
       
   479     delete iSelectFieldProperty;
       
   480     iSelectFieldProperty = NULL;
       
   481 
       
   482     iSelectPropertyPhase = CPbk2SelectMultiplePropertyPhase::NewL
       
   483         ( *this, aContactLinks, *iAddressSelectFilterBuffer,
       
   484           iSelectFieldProperty );
       
   485 
       
   486     CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&>
       
   487         ( *CEikonEnv::Static()->EikAppUi() );
       
   488 
       
   489     // Change layout back to regular layout after fetch
       
   490     appUi.ChangeStatuspaneLayoutL(
       
   491         CPbk2ServerAppAppUi::EStatusPaneLayoutEmpty );
       
   492 
       
   493     iSelectPropertyPhase->LaunchServicePhaseL();
       
   494     }
       
   495 
       
   496 // --------------------------------------------------------------------------
       
   497 // CPbk2MultiContactDataAssigner::LaunchPrepareMultiAssignPhaseL
       
   498 // --------------------------------------------------------------------------
       
   499 //
       
   500 void CPbk2MultiContactDataAssigner::LaunchPrepareMultiAssignPhaseL
       
   501         ( MVPbkContactLinkArray* aContactLinks )
       
   502     {
       
   503     delete iPrepareAssignPhase;
       
   504     iPrepareAssignPhase = NULL;
       
   505 
       
   506     iPrepareAssignPhase = CPbk2PrepareMultipleAssignPhase::NewL
       
   507         ( *this, aContactLinks, iSelectFieldProperty,
       
   508           iInformationNoteFlags );
       
   509 
       
   510     iPrepareAssignPhase->LaunchServicePhaseL();
       
   511     }
       
   512 
       
   513 // --------------------------------------------------------------------------
       
   514 // CPbk2MultiContactDataAssigner::LaunchAssignPhaseL
       
   515 // --------------------------------------------------------------------------
       
   516 //
       
   517 void CPbk2MultiContactDataAssigner::LaunchAssignPhaseL
       
   518         ( MVPbkContactLinkArray* aContactLinks )
       
   519     {
       
   520     delete iAssignDataPhase;
       
   521     iAssignDataPhase = NULL;
       
   522 
       
   523     iAssignDataPhase = CPbk2MultiAssignDataPhase::NewL
       
   524         ( *this, aContactLinks, iSelectFieldProperty,
       
   525           iDataBuffer, iMimeType, iInformationNoteFlags );
       
   526 
       
   527     // In case of the assign phase it is important to delete the
       
   528     // previous phases so that exit and cancel methods work correctly
       
   529     delete iPrepareAssignPhase;
       
   530     iPrepareAssignPhase = NULL;
       
   531     delete iSelectPropertyPhase;
       
   532     iSelectPropertyPhase = NULL;
       
   533     delete iFetchPhase;
       
   534     iFetchPhase = NULL;
       
   535 
       
   536     iAssignDataPhase->LaunchServicePhaseL();
       
   537     }
       
   538 
       
   539 // End of File