phonebookui/Phonebook2/ServerApplication/src/CPbk2SelectSinglePropertyPhase.cpp
changeset 0 e686773b3f54
child 18 d4f567ce2e7c
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 server app assign select single property phase.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2SelectSinglePropertyPhase.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "MPbk2ServicePhaseObserver.h"
       
    23 #include "CPbk2ServerAppAppUi.h"
       
    24 #include "CPbk2AssignSelectFieldDlg.h"
       
    25 #include "MPbk2SelectFieldProperty.h"
       
    26 #include "CPbk2AssignSingleProperty.h"
       
    27 #include <TPbk2DestructionIndicator.h>
       
    28 #include <MPbk2ApplicationServices.h>
       
    29 
       
    30 // Virtual Phonebook
       
    31 #include <MVPbkContactLink.h>
       
    32 #include <CVPbkContactLinkArray.h>
       
    33 #include <MVPbkContactOperationBase.h>
       
    34 #include <MVPbkStoreContact.h>
       
    35 #include <CVPbkContactManager.h>
       
    36 
       
    37 
       
    38 /// Unnamed namespace for local definitions
       
    39 namespace {
       
    40 
       
    41 const TInt KFirstElement = 0;
       
    42 
       
    43 /**
       
    44  * Copies a link array to another.
       
    45  *
       
    46  * @param aSourceLinkArray    Link array which is copied
       
    47  * @param aTargetLinkArray    Links are copied to this
       
    48  */
       
    49 void CopyContactLinksL( const MVPbkContactLinkArray& aSourceLinkArray,
       
    50         CVPbkContactLinkArray& aTargetLinkArray )
       
    51     {
       
    52     const TInt count = aSourceLinkArray.Count();
       
    53     for ( TInt i(0); i < count; ++i )
       
    54         {
       
    55         const MVPbkContactLink& contactLink = aSourceLinkArray.At(i);
       
    56         aTargetLinkArray.AppendL( contactLink.CloneLC() );
       
    57         CleanupStack::Pop(); // link
       
    58         }
       
    59     }
       
    60 
       
    61 } /// namespace
       
    62 
       
    63 // --------------------------------------------------------------------------
       
    64 // CPbk2SelectSinglePropertyPhase::CPbk2SelectSinglePropertyPhase
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 CPbk2SelectSinglePropertyPhase::CPbk2SelectSinglePropertyPhase
       
    68         ( MPbk2ServicePhaseObserver& aObserver,
       
    69           HBufC8* aFilterBuffer,
       
    70           MPbk2SelectFieldProperty*& aSelectFieldProperty, TInt& aResult ) :
       
    71             iObserver( aObserver ),
       
    72             iFilterBuffer( aFilterBuffer ),
       
    73             iSelectFieldProperty( aSelectFieldProperty ),
       
    74             iResult( aResult )
       
    75     {
       
    76     }
       
    77 
       
    78 // --------------------------------------------------------------------------
       
    79 // CPbk2SelectSinglePropertyPhase::~CPbk2SelectSinglePropertyPhase
       
    80 // --------------------------------------------------------------------------
       
    81 //
       
    82 CPbk2SelectSinglePropertyPhase::~CPbk2SelectSinglePropertyPhase()
       
    83     {
       
    84     if ( iSelectFieldDialogEliminator )
       
    85         {
       
    86         iSelectFieldDialogEliminator->ForceExit();
       
    87         }
       
    88 
       
    89     delete iRetrieveOperation;
       
    90     delete iContactLinks;
       
    91     delete iStoreContact;
       
    92 
       
    93     if ( iDestroyedPtr )
       
    94         {
       
    95         *iDestroyedPtr = ETrue;
       
    96         }
       
    97     }
       
    98 
       
    99 // --------------------------------------------------------------------------
       
   100 // CPbk2SelectSinglePropertyPhase::ConstructL
       
   101 // --------------------------------------------------------------------------
       
   102 //
       
   103 inline void CPbk2SelectSinglePropertyPhase::ConstructL
       
   104         ( MVPbkContactLinkArray* aContactLinks )
       
   105     {
       
   106     iContactLinks = CVPbkContactLinkArray::NewL();
       
   107     // Take a own copy of supplied contact links
       
   108     CopyContactLinksL( *aContactLinks, *iContactLinks );
       
   109     }
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CPbk2SelectSinglePropertyPhase::NewL
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 CPbk2SelectSinglePropertyPhase* CPbk2SelectSinglePropertyPhase::NewL
       
   116         ( MPbk2ServicePhaseObserver& aObserver,
       
   117           MVPbkContactLinkArray* aContactLinks,
       
   118           HBufC8* aFilterBuffer,
       
   119           MPbk2SelectFieldProperty*& aSelectFieldProperty, TInt& aResult )
       
   120     {
       
   121     CPbk2SelectSinglePropertyPhase* self =
       
   122         new ( ELeave ) CPbk2SelectSinglePropertyPhase
       
   123             ( aObserver, aFilterBuffer, aSelectFieldProperty, aResult );
       
   124     CleanupStack::PushL( self );
       
   125     self->ConstructL( aContactLinks );
       
   126     CleanupStack::Pop( self );
       
   127     return self;
       
   128     }
       
   129 
       
   130 // --------------------------------------------------------------------------
       
   131 // CPbk2SelectSinglePropertyPhase::LaunchServicePhaseL
       
   132 // --------------------------------------------------------------------------
       
   133 //
       
   134 void CPbk2SelectSinglePropertyPhase::LaunchServicePhaseL()
       
   135     {
       
   136     RetrieveContactL();
       
   137     }
       
   138 
       
   139 // --------------------------------------------------------------------------
       
   140 // CPbk2SelectSinglePropertyPhase::CancelServicePhase
       
   141 // --------------------------------------------------------------------------
       
   142 //
       
   143 void CPbk2SelectSinglePropertyPhase::CancelServicePhase()
       
   144     {
       
   145     if ( iSelectFieldDialogEliminator )
       
   146         {
       
   147         iSelectFieldDialogEliminator->ForceExit();
       
   148         }
       
   149 
       
   150     iObserver.PhaseCanceled( *this );
       
   151     }
       
   152 
       
   153 // --------------------------------------------------------------------------
       
   154 // CPbk2SelectSinglePropertyPhase::RequestCancelL
       
   155 // --------------------------------------------------------------------------
       
   156 //
       
   157 void CPbk2SelectSinglePropertyPhase::RequestCancelL( TInt aExitCommandId )
       
   158     {
       
   159     if ( iSelectFieldDialogEliminator )
       
   160         {
       
   161         iSelectFieldDialogEliminator->RequestExitL( aExitCommandId );
       
   162         }
       
   163 
       
   164    if ( aExitCommandId == EEikBidCancel )
       
   165         {
       
   166         iObserver.PhaseAborted( *this );
       
   167         }
       
   168     else
       
   169         {
       
   170         iObserver.PhaseCanceled( *this );
       
   171         }
       
   172     }
       
   173 
       
   174 // --------------------------------------------------------------------------
       
   175 // CPbk2SelectSinglePropertyPhase::AcceptDelayed
       
   176 // --------------------------------------------------------------------------
       
   177 //
       
   178 void CPbk2SelectSinglePropertyPhase::AcceptDelayedL
       
   179         ( const TDesC8& /*aContactLinkBuffer*/ )
       
   180     {
       
   181     // Nothing to do
       
   182     }
       
   183 
       
   184 // --------------------------------------------------------------------------
       
   185 // CPbk2SelectSinglePropertyPhase::Results
       
   186 // --------------------------------------------------------------------------
       
   187 //
       
   188 MVPbkContactLinkArray* CPbk2SelectSinglePropertyPhase::Results() const
       
   189     {
       
   190     return iContactLinks;
       
   191     }
       
   192 
       
   193 // --------------------------------------------------------------------------
       
   194 // CPbk2SelectSinglePropertyPhase::ExtraResultData
       
   195 // --------------------------------------------------------------------------
       
   196 //
       
   197 TInt CPbk2SelectSinglePropertyPhase::ExtraResultData() const
       
   198     {
       
   199     return KErrNotSupported;
       
   200     }
       
   201 
       
   202 // --------------------------------------------------------------------------
       
   203 // CPbk2SelectSinglePropertyPhase::TakeStoreContact
       
   204 // --------------------------------------------------------------------------
       
   205 //
       
   206 MVPbkStoreContact* CPbk2SelectSinglePropertyPhase::TakeStoreContact()
       
   207     {
       
   208     MVPbkStoreContact* contact = iStoreContact;
       
   209     iStoreContact = NULL;
       
   210     return contact;
       
   211     }
       
   212 
       
   213 // --------------------------------------------------------------------------
       
   214 // CPbk2SelectSinglePropertyPhase::FieldContent
       
   215 // --------------------------------------------------------------------------
       
   216 //
       
   217 HBufC* CPbk2SelectSinglePropertyPhase::FieldContent() const
       
   218     {
       
   219     return NULL;
       
   220     }
       
   221 
       
   222 // --------------------------------------------------------------------------
       
   223 // CPbk2SelectSinglePropertyPhase::VPbkSingleContactOperationComplete
       
   224 // --------------------------------------------------------------------------
       
   225 //
       
   226 void CPbk2SelectSinglePropertyPhase::VPbkSingleContactOperationComplete
       
   227         ( MVPbkContactOperationBase& /*aOperation*/,
       
   228           MVPbkStoreContact* aContact )
       
   229     {
       
   230     // Contact retrieval complete
       
   231     delete iStoreContact;
       
   232     iStoreContact = aContact;
       
   233 
       
   234     // Locking the contact and after the updating is finished, the contact 
       
   235     // will be committed in ContactOperationCompleted() or 
       
   236     // SelectFieldL()in case of the user's cancellation
       
   237     iStoreContact->LockL(*this);
       
   238     }
       
   239 
       
   240 // --------------------------------------------------------------------------
       
   241 // CPbk2SelectSinglePropertyPhase::VPbkSingleContactOperationFailed
       
   242 // --------------------------------------------------------------------------
       
   243 //
       
   244 void CPbk2SelectSinglePropertyPhase::VPbkSingleContactOperationFailed
       
   245         ( MVPbkContactOperationBase& /*aOperation*/, TInt aError )
       
   246     {
       
   247     iObserver.PhaseError( *this, aError );
       
   248     }
       
   249 
       
   250 // --------------------------------------------------------------------------
       
   251 // CPbk2SelectSinglePropertyPhase::OkToExitL
       
   252 // --------------------------------------------------------------------------
       
   253 //
       
   254 TBool CPbk2SelectSinglePropertyPhase::OkToExitL( TInt aCommandId )
       
   255     {
       
   256     return iObserver.PhaseOkToExit( *this, aCommandId );
       
   257     }
       
   258 
       
   259 // --------------------------------------------------------------------------
       
   260 // CPbk2SelectSinglePropertyPhase::RetrieveContactL
       
   261 // --------------------------------------------------------------------------
       
   262 //
       
   263 void CPbk2SelectSinglePropertyPhase::RetrieveContactL()
       
   264     {
       
   265     CPbk2ServerAppAppUi& appUi =
       
   266         static_cast<CPbk2ServerAppAppUi&>
       
   267             ( *CEikonEnv::Static()->EikAppUi() );
       
   268 
       
   269     delete iRetrieveOperation;
       
   270     iRetrieveOperation = NULL;
       
   271     iRetrieveOperation = appUi.ApplicationServices().ContactManager().
       
   272         RetrieveContactL( iContactLinks->At( KFirstElement ), *this );
       
   273     // Do not delete anything from iContactLinks since it is not necessary
       
   274     // and would result to errors when client queries results
       
   275     }
       
   276 
       
   277 // --------------------------------------------------------------------------
       
   278 // CPbk2SelectSinglePropertyPhase::SelectFieldL
       
   279 // --------------------------------------------------------------------------
       
   280 //
       
   281 void CPbk2SelectSinglePropertyPhase::SelectFieldL()
       
   282     {
       
   283     TInt result( KErrNone );
       
   284     
       
   285     CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&>
       
   286         ( *CEikonEnv::Static()->EikAppUi() );
       
   287 
       
   288     if( iFilterBuffer )
       
   289     	{
       
   290         CPbk2AssignSingleProperty* singleProperty =
       
   291             CPbk2AssignSingleProperty::NewL
       
   292                 ( *iFilterBuffer, *iStoreContact,
       
   293                   appUi.ApplicationServices().ContactManager() );
       
   294         iSelectFieldProperty = singleProperty;
       
   295 
       
   296         TBool thisDestroyed = EFalse;
       
   297         iDestroyedPtr = &thisDestroyed;
       
   298         TPbk2DestructionIndicator indicator( &thisDestroyed, iDestroyedPtr );
       
   299 
       
   300         CPbk2AssignSelectFieldDlg* dlg =
       
   301             CPbk2AssignSelectFieldDlg::NewL( *this );
       
   302         iSelectFieldDialogEliminator = dlg;
       
   303         iSelectFieldDialogEliminator->ResetWhenDestroyed
       
   304             ( &iSelectFieldDialogEliminator );
       
   305 
       
   306         result = dlg->ExecuteLD( *iSelectFieldProperty );
       
   307         
       
   308         if( thisDestroyed )
       
   309         	{
       
   310         	return;
       
   311         	}
       
   312     	}
       
   313 
       
   314     if ( result == KErrCancel )
       
   315         {
       
   316         iStoreContact->CommitL(*this);
       
   317         }
       
   318 
       
   319     iResult = result;
       
   320 
       
   321     iObserver.NextPhase( *this );
       
   322     }
       
   323 
       
   324 // --------------------------------------------------------------------------
       
   325 // CPbk2SelectSinglePropertyPhase::ContactOperationCompleted
       
   326 // --------------------------------------------------------------------------
       
   327 //
       
   328 void CPbk2SelectSinglePropertyPhase::ContactOperationCompleted
       
   329         ( TContactOpResult aResult )
       
   330     {
       
   331     if ( aResult.iOpCode == EContactLock )
       
   332         {
       
   333         TRAPD( err, SelectFieldL() );
       
   334         if ( err != KErrNone )
       
   335             {
       
   336             iStoreContact->CommitL(*this);
       
   337             iObserver.PhaseError( *this, err );
       
   338             }
       
   339         }
       
   340     }
       
   341 
       
   342 // --------------------------------------------------------------------------
       
   343 // CPbk2SelectSinglePropertyPhase::ContactOperationFailed
       
   344 // --------------------------------------------------------------------------
       
   345 //
       
   346 void CPbk2SelectSinglePropertyPhase::ContactOperationFailed
       
   347         ( TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/ )
       
   348     {
       
   349     iObserver.PhaseError( *this, aErrorCode );
       
   350     CancelServicePhase();  
       
   351     }
       
   352 // End of File