phonebookui/Phonebook2/ServerApplication/src/CPbk2SelectSinglePropertyPhase.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
child 85 38bb213f60ba
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 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::DenyDelayed
       
   186 // --------------------------------------------------------------------------
       
   187 //
       
   188 void CPbk2SelectSinglePropertyPhase::DenyDelayedL
       
   189         ( const TDesC8& /*aContactLinkBuffer*/ )
       
   190     {
       
   191     // Nothing to do
       
   192     }
       
   193 
       
   194 // --------------------------------------------------------------------------
       
   195 // CPbk2SelectSinglePropertyPhase::Results
       
   196 // --------------------------------------------------------------------------
       
   197 //
       
   198 MVPbkContactLinkArray* CPbk2SelectSinglePropertyPhase::Results() const
       
   199     {
       
   200     return iContactLinks;
       
   201     }
       
   202 
       
   203 // --------------------------------------------------------------------------
       
   204 // CPbk2SelectSinglePropertyPhase::ExtraResultData
       
   205 // --------------------------------------------------------------------------
       
   206 //
       
   207 TInt CPbk2SelectSinglePropertyPhase::ExtraResultData() const
       
   208     {
       
   209     return KErrNotSupported;
       
   210     }
       
   211 
       
   212 // --------------------------------------------------------------------------
       
   213 // CPbk2SelectSinglePropertyPhase::TakeStoreContact
       
   214 // --------------------------------------------------------------------------
       
   215 //
       
   216 MVPbkStoreContact* CPbk2SelectSinglePropertyPhase::TakeStoreContact()
       
   217     {
       
   218     MVPbkStoreContact* contact = iStoreContact;
       
   219     iStoreContact = NULL;
       
   220     return contact;
       
   221     }
       
   222 
       
   223 // --------------------------------------------------------------------------
       
   224 // CPbk2SelectSinglePropertyPhase::FieldContent
       
   225 // --------------------------------------------------------------------------
       
   226 //
       
   227 HBufC* CPbk2SelectSinglePropertyPhase::FieldContent() const
       
   228     {
       
   229     return NULL;
       
   230     }
       
   231 
       
   232 // --------------------------------------------------------------------------
       
   233 // CPbk2SelectSinglePropertyPhase::VPbkSingleContactOperationComplete
       
   234 // --------------------------------------------------------------------------
       
   235 //
       
   236 void CPbk2SelectSinglePropertyPhase::VPbkSingleContactOperationComplete
       
   237         ( MVPbkContactOperationBase& /*aOperation*/,
       
   238           MVPbkStoreContact* aContact )
       
   239     {
       
   240     // Contact retrieval complete
       
   241     delete iStoreContact;
       
   242     iStoreContact = aContact;
       
   243 
       
   244     // Locking the contact and after the updating is finished, the contact 
       
   245     // will be committed in ContactOperationCompleted() or 
       
   246     // SelectFieldL()in case of the user's cancellation
       
   247     iStoreContact->LockL(*this);
       
   248     }
       
   249 
       
   250 // --------------------------------------------------------------------------
       
   251 // CPbk2SelectSinglePropertyPhase::VPbkSingleContactOperationFailed
       
   252 // --------------------------------------------------------------------------
       
   253 //
       
   254 void CPbk2SelectSinglePropertyPhase::VPbkSingleContactOperationFailed
       
   255         ( MVPbkContactOperationBase& /*aOperation*/, TInt aError )
       
   256     {
       
   257     iObserver.PhaseError( *this, aError );
       
   258     }
       
   259 
       
   260 // --------------------------------------------------------------------------
       
   261 // CPbk2SelectSinglePropertyPhase::OkToExitL
       
   262 // --------------------------------------------------------------------------
       
   263 //
       
   264 TBool CPbk2SelectSinglePropertyPhase::OkToExitL( TInt aCommandId )
       
   265     {
       
   266     return iObserver.PhaseOkToExit( *this, aCommandId );
       
   267     }
       
   268 
       
   269 // --------------------------------------------------------------------------
       
   270 // CPbk2SelectSinglePropertyPhase::RetrieveContactL
       
   271 // --------------------------------------------------------------------------
       
   272 //
       
   273 void CPbk2SelectSinglePropertyPhase::RetrieveContactL()
       
   274     {
       
   275     CPbk2ServerAppAppUi& appUi =
       
   276         static_cast<CPbk2ServerAppAppUi&>
       
   277             ( *CEikonEnv::Static()->EikAppUi() );
       
   278 
       
   279     delete iRetrieveOperation;
       
   280     iRetrieveOperation = NULL;
       
   281     iRetrieveOperation = appUi.ApplicationServices().ContactManager().
       
   282         RetrieveContactL( iContactLinks->At( KFirstElement ), *this );
       
   283     // Do not delete anything from iContactLinks since it is not necessary
       
   284     // and would result to errors when client queries results
       
   285     }
       
   286 
       
   287 // --------------------------------------------------------------------------
       
   288 // CPbk2SelectSinglePropertyPhase::SelectFieldL
       
   289 // --------------------------------------------------------------------------
       
   290 //
       
   291 void CPbk2SelectSinglePropertyPhase::SelectFieldL()
       
   292     {
       
   293     TInt result( KErrNone );
       
   294     
       
   295     CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&>
       
   296         ( *CEikonEnv::Static()->EikAppUi() );
       
   297 
       
   298     if( iFilterBuffer )
       
   299     	{
       
   300         CPbk2AssignSingleProperty* singleProperty =
       
   301             CPbk2AssignSingleProperty::NewL
       
   302                 ( *iFilterBuffer, *iStoreContact,
       
   303                   appUi.ApplicationServices().ContactManager() );
       
   304         iSelectFieldProperty = singleProperty;
       
   305 
       
   306         TBool thisDestroyed = EFalse;
       
   307         iDestroyedPtr = &thisDestroyed;
       
   308         TPbk2DestructionIndicator indicator( &thisDestroyed, iDestroyedPtr );
       
   309 
       
   310         CPbk2AssignSelectFieldDlg* dlg =
       
   311             CPbk2AssignSelectFieldDlg::NewL( *this );
       
   312         iSelectFieldDialogEliminator = dlg;
       
   313         iSelectFieldDialogEliminator->ResetWhenDestroyed
       
   314             ( &iSelectFieldDialogEliminator );
       
   315 
       
   316         result = dlg->ExecuteLD( *iSelectFieldProperty );
       
   317         
       
   318         if( thisDestroyed )
       
   319         	{
       
   320         	return;
       
   321         	}
       
   322     	}
       
   323 
       
   324     if ( result == KErrCancel )
       
   325         {
       
   326         iStoreContact->CommitL(*this);
       
   327         }
       
   328 
       
   329     iResult = result;
       
   330 
       
   331     iObserver.NextPhase( *this );
       
   332     }
       
   333 
       
   334 // --------------------------------------------------------------------------
       
   335 // CPbk2SelectSinglePropertyPhase::ContactOperationCompleted
       
   336 // --------------------------------------------------------------------------
       
   337 //
       
   338 void CPbk2SelectSinglePropertyPhase::ContactOperationCompleted
       
   339         ( TContactOpResult aResult )
       
   340     {
       
   341     if ( aResult.iOpCode == EContactLock )
       
   342         {
       
   343         TRAPD( err, SelectFieldL() );
       
   344         if ( err != KErrNone )
       
   345             {
       
   346             iStoreContact->CommitL(*this);
       
   347             iObserver.PhaseError( *this, err );
       
   348             }
       
   349         }
       
   350     }
       
   351 
       
   352 // --------------------------------------------------------------------------
       
   353 // CPbk2SelectSinglePropertyPhase::ContactOperationFailed
       
   354 // --------------------------------------------------------------------------
       
   355 //
       
   356 void CPbk2SelectSinglePropertyPhase::ContactOperationFailed
       
   357         ( TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/ )
       
   358     {
       
   359     iObserver.PhaseError( *this, aErrorCode );
       
   360     CancelServicePhase();  
       
   361     }
       
   362 // End of File