phonebookui/Phonebook2/CommandsExtension/src/TPbk2CopyContactsUtil.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 copy contacts result diplay utility.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "TPbk2CopyContactsUtil.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include <CPbk2StoreConfiguration.h>
       
    24 #include <MPbk2ContactUiControl.h>
       
    25 #include <CPbk2ApplicationServices.h>
       
    26 #include <MPbk2AppUi.h>
       
    27 
       
    28 // Virtual Phonebook
       
    29 #include <CVPbkContactManager.h>
       
    30 #include <CVPbkContactStoreUriArray.h>
       
    31 #include <MVPbkContactStoreList.h>
       
    32 #include <MVPbkContactStore.h>
       
    33 #include <TVPbkContactStoreUriPtr.h>
       
    34 #include <MVPbkContactStoreProperties.h>
       
    35 #include <VPbkContactStoreUris.h>
       
    36 #include <MVPbkContactLink.h>
       
    37 #include <MVPbkBaseContact.h>
       
    38 
       
    39 
       
    40 /// Unnamed namespace for local definitions
       
    41 namespace {
       
    42 
       
    43 const TInt KOneStore = 1;
       
    44 const TInt KNoContacts = 0;
       
    45 
       
    46 } /// namespace
       
    47 
       
    48 // --------------------------------------------------------------------------
       
    49 // TPbk2CopyContactsUtil::CopyContactTargetStoresLC
       
    50 // --------------------------------------------------------------------------
       
    51 //
       
    52 CVPbkContactStoreUriArray* TPbk2CopyContactsUtil::
       
    53         CopyContactTargetStoresLC(
       
    54             MPbk2ContactUiControl& aControl,
       
    55             CVPbkContactStoreUriArray* aDiscardedUris)
       
    56     {
       
    57     CVPbkContactStoreUriArray* targets = CVPbkContactStoreUriArray::NewLC();
       
    58 
       
    59     CPbk2ApplicationServices* appServices = CPbk2ApplicationServices::InstanceLC();
       
    60 
       
    61     // Add the number of writable stores
       
    62     CPbk2StoreConfiguration& config = appServices->StoreConfiguration();
       
    63     CVPbkContactStoreUriArray* stores =
       
    64         config.SupportedStoreConfigurationL();
       
    65     CleanupStack::PushL(stores);
       
    66     TInt count = stores->Count();
       
    67     for (TInt i = 0; i < count; ++i)
       
    68         {
       
    69         MVPbkContactStore* store =
       
    70             appServices->ContactManager().
       
    71                 ContactStoresL().Find((*stores)[i]);
       
    72         if ( store && !store->StoreProperties().ReadOnly() )
       
    73             {
       
    74             TVPbkContactStoreUriPtr uri = store->StoreProperties().Uri();
       
    75             if ( aDiscardedUris && aDiscardedUris->IsIncluded( uri ) )
       
    76                 {
       
    77                 // Do not append, the URI needs to be discarded
       
    78                 }
       
    79             else
       
    80                 {
       
    81                 targets->AppendL( uri );
       
    82                 }
       
    83             }
       
    84         }
       
    85     CleanupStack::PopAndDestroy(); // stores
       
    86 
       
    87     CleanupStack::PopAndDestroy(); // appServices
       
    88 
       
    89     // Get the number of selected contacts
       
    90     MVPbkContactLinkArray* selected = 
       
    91         aControl.SelectedContactsOrFocusedContactL();
       
    92     CleanupDeletePushL( selected );
       
    93     if ( selected ) // selected is NULL if the names list is empty
       
    94         {
       
    95         count = selected->Count();
       
    96         }
       
    97     else
       
    98         {
       
    99         count = KNoContacts;
       
   100         }
       
   101 
       
   102     // Construct a second URI array for all the writable stores
       
   103     // of selected contacs
       
   104     CVPbkContactStoreUriArray* writablesInSelected =
       
   105         CVPbkContactStoreUriArray::NewLC();
       
   106     for ( TInt i = 0; i < count; ++i )
       
   107         {
       
   108         const MVPbkContactStoreProperties& props =
       
   109             selected->At(i).ContactStore().StoreProperties();
       
   110         // If the store is not readonly and it is not allready in the array,
       
   111         // add it there
       
   112         if ( !props.ReadOnly() && !writablesInSelected->IsIncluded
       
   113                 ( props.Uri() ) )
       
   114             {
       
   115             writablesInSelected->AppendL( props.Uri() );
       
   116             }
       
   117         }
       
   118 
       
   119     if ( writablesInSelected->Count() == KOneStore )
       
   120         {
       
   121         // The contact selection contains contacts only from one writable
       
   122         // store. Remove that store from the target count.
       
   123         targets->Remove( ( *writablesInSelected )[0] );
       
   124         }
       
   125 
       
   126     CleanupStack::PopAndDestroy( 2 ); // selected, writablesInSelected
       
   127     return targets;
       
   128     }
       
   129 
       
   130 //  End of File