phonebookui/Phonebook2/ServerApplication/src/CPbk2ContactEditorOperator.cpp
changeset 0 e686773b3f54
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 contact editor operator.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "CPbk2ContactEditorOperator.h"
       
    19 
       
    20 // Phonebook 2
       
    21 #include "CPbk2ServerAppAppUi.h"
       
    22 #include <CPbk2ContactEditorDlg.h>
       
    23 #include <MPbk2ApplicationServices.h>
       
    24 
       
    25 // Virtual Phonebook
       
    26 #include <MVPbkStoreContact.h>
       
    27 #include <MVPbkContactStore.h>
       
    28 #include <MVPbkContactStoreProperties.h>
       
    29 #include <CVPbkContactManager.h>
       
    30 #include <VPbkUtils.h>
       
    31 
       
    32 // System includes
       
    33 #include <AiwContactAssignDataTypes.h>
       
    34 
       
    35 
       
    36 using namespace AiwContactAssign;
       
    37 
       
    38 // --------------------------------------------------------------------------
       
    39 // CPbk2ContactEditorOperator::CPbk2ContactEditorOperator
       
    40 // --------------------------------------------------------------------------
       
    41 //
       
    42 inline CPbk2ContactEditorOperator::CPbk2ContactEditorOperator
       
    43         ( MPbk2ExitCallback& aExitCallback,
       
    44           MPbk2EditedContactObserver& aContactObserver ) :
       
    45             iExitCallback( aExitCallback ),
       
    46             iContactObserver( aContactObserver )
       
    47     {
       
    48     }
       
    49 
       
    50 // --------------------------------------------------------------------------
       
    51 // CPbk2ContactEditorOperator::~CPbk2ContactEditorOperator
       
    52 // --------------------------------------------------------------------------
       
    53 //
       
    54 CPbk2ContactEditorOperator::~CPbk2ContactEditorOperator()
       
    55     {
       
    56     if ( iSelfPtr )
       
    57         {
       
    58         *iSelfPtr = NULL;
       
    59         }
       
    60     }
       
    61 
       
    62 // --------------------------------------------------------------------------
       
    63 // CPbk2ContactEditorOperator::NewLC
       
    64 // --------------------------------------------------------------------------
       
    65 //
       
    66 CPbk2ContactEditorOperator* CPbk2ContactEditorOperator::NewLC
       
    67         ( MPbk2ExitCallback& aExitCallback,
       
    68           MPbk2EditedContactObserver& aContactObserver )
       
    69     {
       
    70     CPbk2ContactEditorOperator* self =
       
    71         new ( ELeave ) CPbk2ContactEditorOperator
       
    72             ( aExitCallback, aContactObserver );
       
    73     CleanupStack::PushL( self );
       
    74     return self;
       
    75     }
       
    76 
       
    77 // --------------------------------------------------------------------------
       
    78 // CPbk2ContactEditorOperator::OpenEditorL
       
    79 // --------------------------------------------------------------------------
       
    80 //
       
    81 void CPbk2ContactEditorOperator::OpenEditorL
       
    82         ( MVPbkStoreContact*& aStoreContact, TInt& aIndex,
       
    83           TUint& aFlags, TCoeHelpContext& aHelpContext )
       
    84     {
       
    85     // Set editor flags
       
    86     TUint32 editorFlags = 0;
       
    87     if ( aFlags & EHideEditorExit )
       
    88         {
       
    89         editorFlags |= TPbk2ContactEditorParams::EHideExit;
       
    90         }
       
    91     if ( aFlags & ECreateNewContact )
       
    92         {
       
    93         editorFlags |= TPbk2ContactEditorParams::ENewContact;
       
    94         }
       
    95     else
       
    96         {
       
    97         editorFlags |= TPbk2ContactEditorParams::EModified;
       
    98         }
       
    99 
       
   100     TCoeHelpContext* helpContext = NULL;
       
   101     if ( !aHelpContext.IsNull() )
       
   102         {
       
   103         helpContext = &aHelpContext;
       
   104         }
       
   105 
       
   106     // Verify syncronization field existance and content
       
   107     CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&>
       
   108         ( *CEikonEnv::Static()->EikAppUi() );
       
   109 
       
   110     VPbkUtils::VerifySyncronizationFieldL(
       
   111             appUi.ApplicationServices().ContactManager().FsSession(),
       
   112             aStoreContact->ParentStore().StoreProperties().SupportedFields(),
       
   113             *aStoreContact );
       
   114 
       
   115     MVPbkBaseContactField* field = NULL;
       
   116     if ( aIndex >= KErrNone )
       
   117         {
       
   118         field = aStoreContact->Fields().FieldAtLC( aIndex );
       
   119         }
       
   120     else
       
   121         {
       
   122         // We must keep cleanup stack level the same
       
   123         CleanupStack::PushL( field );
       
   124         }
       
   125 
       
   126     TPbk2ContactEditorParams params
       
   127         ( editorFlags, field, helpContext, this );
       
   128     
       
   129     CPbk2ContactEditorDlg* editor = CPbk2ContactEditorDlg::NewL
       
   130         ( params, aStoreContact, iContactObserver );
       
   131     aStoreContact = NULL; // ownership was taken away
       
   132     iContactEditorEliminator = editor;
       
   133     editor->ResetWhenDestroyed( &iContactEditorEliminator );
       
   134     editor->ExecuteLD();
       
   135 
       
   136     aIndex = params.iFocusedIndex;
       
   137 
       
   138     CleanupStack::PopAndDestroy( field );
       
   139     }
       
   140 
       
   141 // --------------------------------------------------------------------------
       
   142 // CPbk2ContactEditorOperator::RequestExitL
       
   143 // --------------------------------------------------------------------------
       
   144 //
       
   145 void CPbk2ContactEditorOperator::RequestExitL( TInt aCommandId )
       
   146     {
       
   147     if ( iContactEditorEliminator )
       
   148         {
       
   149         iContactEditorEliminator->RequestExitL( aCommandId );
       
   150         }
       
   151     }
       
   152 
       
   153 // --------------------------------------------------------------------------
       
   154 // CPbk2ContactEditorOperator::ForceExitL
       
   155 // --------------------------------------------------------------------------
       
   156 //
       
   157 void CPbk2ContactEditorOperator::ForceExit()
       
   158     {
       
   159     if ( iContactEditorEliminator )
       
   160         {
       
   161         iContactEditorEliminator->ForceExit();
       
   162         }
       
   163     }
       
   164 
       
   165 // --------------------------------------------------------------------------
       
   166 // CPbk2ContactEditorOperator::ResetWhenDestroyed
       
   167 // --------------------------------------------------------------------------
       
   168 //
       
   169 void CPbk2ContactEditorOperator::ResetWhenDestroyed(
       
   170                 MPbk2DialogEliminator** aSelfPtr )
       
   171     {
       
   172     iSelfPtr = aSelfPtr;
       
   173     }
       
   174 
       
   175 // --------------------------------------------------------------------------
       
   176 // CPbk2ContactEditorOperator::OkToExitL
       
   177 // --------------------------------------------------------------------------
       
   178 //
       
   179 TBool CPbk2ContactEditorOperator::OkToExitL( TInt aCommandId )
       
   180     {
       
   181     // Deny editor exit and pass an asynchronous query to the consumer,
       
   182     // which may later approve exit
       
   183     iExitCallback.OkToExitL( aCommandId );
       
   184     return EFalse;
       
   185     }
       
   186 
       
   187 // End of File