phonebookui/Phonebook2/CommonUI/src/CPbk2MemoryEntryContactLoader.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:  Memory entry contact loader.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <CPbk2MemoryEntryContactLoader.h>
       
    21 
       
    22 // Phonebook 2
       
    23 #include <MPbk2MemoryEntryView.h>
       
    24 #include <MPbk2AppUi.h>
       
    25 #include <MPbk2ApplicationServices.h>
       
    26 
       
    27 // Virtual Phonebook
       
    28 #include <MVPbkContactViewBase.h>
       
    29 #include <CVPbkContactManager.h>
       
    30 #include <MVPbkStoreContact.h>
       
    31 #include <MVPbkContactOperationBase.h>
       
    32 #include <MVPbkContactLink.h>
       
    33 #include <MVPbkContactStore.h>
       
    34 
       
    35 // System includes
       
    36 #include <coemain.h>
       
    37 
       
    38 // --------------------------------------------------------------------------
       
    39 // CPbk2MemoryEntryContactLoader::CPbk2MemoryEntryContactLoader
       
    40 // --------------------------------------------------------------------------
       
    41 //
       
    42 CPbk2MemoryEntryContactLoader::CPbk2MemoryEntryContactLoader
       
    43         ( MPbk2MemoryEntryView& aMemoryEntryView ) :
       
    44             iMemoryEntryView( aMemoryEntryView )
       
    45     {
       
    46     }
       
    47 
       
    48 // --------------------------------------------------------------------------
       
    49 // CPbk2MemoryEntryContactLoader::~CPbk2MemoryEntryContactLoader
       
    50 // --------------------------------------------------------------------------
       
    51 //
       
    52 CPbk2MemoryEntryContactLoader::~CPbk2MemoryEntryContactLoader()
       
    53     {
       
    54     delete iRetrieveOperation;
       
    55     delete iContactLink;
       
    56 
       
    57     if ( iContactStore )
       
    58         {
       
    59         iContactStore->Close( *this );
       
    60         }
       
    61     }
       
    62 
       
    63 // --------------------------------------------------------------------------
       
    64 // CPbk2MemoryEntryContactLoader::NewL
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C CPbk2MemoryEntryContactLoader* CPbk2MemoryEntryContactLoader::NewL
       
    68         ( MPbk2MemoryEntryView& aMemoryEntryView )
       
    69     {
       
    70     CPbk2MemoryEntryContactLoader* self =
       
    71         new( ELeave ) CPbk2MemoryEntryContactLoader( aMemoryEntryView );
       
    72     return self;
       
    73     }
       
    74 
       
    75 // --------------------------------------------------------------------------
       
    76 // CPbk2MemoryEntryContactLoader::ChangeContactL
       
    77 // --------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C void CPbk2MemoryEntryContactLoader::ChangeContactL
       
    80         (  const MVPbkContactLink& aContactLink )
       
    81     {
       
    82     MVPbkContactLink* temp = aContactLink.CloneLC();
       
    83     iMemoryEntryView.PrepareForContactChangeL();
       
    84     CleanupStack::Pop(); // temp
       
    85     delete iContactLink;
       
    86     iContactLink = temp;        
       
    87 
       
    88     if ( !iContactStore )
       
    89         {
       
    90         iContactStore = &iContactLink->ContactStore();
       
    91         iContactStore->OpenL( *this );
       
    92         }
       
    93     else if ( &iContactLink->ContactStore() != iContactStore )
       
    94         {
       
    95         iContactStore->Close( *this );
       
    96         iContactStore = &iContactLink->ContactStore();
       
    97         iContactStore->OpenL( *this );
       
    98         }
       
    99     else
       
   100         {
       
   101         RetrieveContactL();
       
   102         }
       
   103     }
       
   104 
       
   105 // --------------------------------------------------------------------------
       
   106 // CPbk2MemoryEntryContactLoader::ContactLinkLC
       
   107 // --------------------------------------------------------------------------
       
   108 //
       
   109 EXPORT_C MVPbkContactLink*
       
   110         CPbk2MemoryEntryContactLoader::ContactLinkLC() const
       
   111     {
       
   112     MVPbkContactLink* link = NULL;
       
   113     const MVPbkStoreContact* contact = iMemoryEntryView.Contact();
       
   114     if (contact)
       
   115         {
       
   116         link = contact->CreateLinkLC();
       
   117         }
       
   118     else
       
   119         {
       
   120         // LC function semantics
       
   121         CleanupDeletePushL(link);
       
   122         }
       
   123 
       
   124     return link;
       
   125     }
       
   126 
       
   127 // --------------------------------------------------------------------------
       
   128 // CPbk2MemoryEntryContactLoader::VPbkSingleContactOperationComplete
       
   129 // --------------------------------------------------------------------------
       
   130 //
       
   131 void CPbk2MemoryEntryContactLoader::VPbkSingleContactOperationComplete
       
   132         ( MVPbkContactOperationBase& aOperation,
       
   133           MVPbkStoreContact* aContact )
       
   134     {
       
   135     if (&aOperation == iRetrieveOperation)
       
   136         {
       
   137         delete iRetrieveOperation;
       
   138         iRetrieveOperation = NULL;
       
   139 
       
   140         // The aContact ownership is taken care of in ContactChangedL
       
   141         TRAPD( err, iMemoryEntryView.ContactChangedL( aContact ) );
       
   142         // Do not anything, if KErrNone or KErrDied        
       
   143         if (err != KErrNone && err != KErrDied )
       
   144             {
       
   145             CCoeEnv::Static()->HandleError( err );
       
   146             iMemoryEntryView.ContactChangeFailed();
       
   147             }
       
   148         }
       
   149     }
       
   150 
       
   151 // --------------------------------------------------------------------------
       
   152 // CPbk2MemoryEntryContactLoader::VPbkSingleContactOperationFailed
       
   153 // --------------------------------------------------------------------------
       
   154 //
       
   155 void CPbk2MemoryEntryContactLoader::VPbkSingleContactOperationFailed
       
   156         ( MVPbkContactOperationBase& aOperation, TInt aError )
       
   157     {
       
   158     if (&aOperation == iRetrieveOperation)
       
   159         {
       
   160         delete iRetrieveOperation;
       
   161         iRetrieveOperation = NULL;
       
   162 
       
   163         // Display standard error message
       
   164         CCoeEnv::Static()->HandleError(aError);
       
   165 
       
   166         iMemoryEntryView.ContactChangeFailed();
       
   167         }
       
   168     }
       
   169 
       
   170 // --------------------------------------------------------------------------
       
   171 // CPbk2MemoryEntryContactLoader::StoreReady
       
   172 // --------------------------------------------------------------------------
       
   173 //
       
   174 void CPbk2MemoryEntryContactLoader::StoreReady
       
   175         ( MVPbkContactStore& /*aContactStore*/ )
       
   176     {
       
   177     TRAPD( err, RetrieveContactL() );
       
   178     if ( err != KErrNone )
       
   179         {
       
   180         CCoeEnv::Static()->HandleError( err );
       
   181 
       
   182         iMemoryEntryView.ContactChangeFailed();
       
   183         }
       
   184     }
       
   185 
       
   186 // --------------------------------------------------------------------------
       
   187 // CPbk2NavigationBase::StoreUnavailable
       
   188 // --------------------------------------------------------------------------
       
   189 //
       
   190 void CPbk2MemoryEntryContactLoader::StoreUnavailable
       
   191         ( MVPbkContactStore& /*aContactStore*/, TInt aReason )
       
   192     {
       
   193     //special fix for BT SAP case. When BT SAP is activate, this will show "Feature Not Supported", which is not
       
   194     //wanted.
       
   195     if( aReason != KErrNotSupported )
       
   196 		{
       
   197 	    CCoeEnv::Static()->HandleError( aReason );
       
   198 		}
       
   199 
       
   200     iMemoryEntryView.ContactChangeFailed();
       
   201     }
       
   202 
       
   203 // --------------------------------------------------------------------------
       
   204 // CPbk2MemoryEntryContactLoader::HandleStoreEventL
       
   205 // --------------------------------------------------------------------------
       
   206 //
       
   207 void CPbk2MemoryEntryContactLoader::HandleStoreEventL
       
   208         ( MVPbkContactStore& /*aContactStore*/,
       
   209           TVPbkContactStoreEvent /*aStoreEvent*/ )
       
   210     {
       
   211     // Do nothing
       
   212     }
       
   213 
       
   214 // --------------------------------------------------------------------------
       
   215 // CPbk2MemoryEntryContactLoader::RetrieveContactL
       
   216 // --------------------------------------------------------------------------
       
   217 //
       
   218 void CPbk2MemoryEntryContactLoader::RetrieveContactL()
       
   219     {
       
   220     delete iRetrieveOperation;
       
   221     iRetrieveOperation = NULL;
       
   222     // Retrieve the actual store contact from the given link
       
   223     iRetrieveOperation = Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   224         ContactManager().RetrieveContactL( *iContactLink, *this );
       
   225     }
       
   226 
       
   227 // End of File