phonebookui/Phonebook2/ServerApplication/src/CPbk2AssignMultiProperty.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
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 contact field property selector
       
    15 *              : for multi contact assign.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "CPbk2AssignMultiProperty.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "CPbk2ServerAppAppUi.h"
       
    24 #include <Pbk2ServerApp.rsg>
       
    25 #include <MPbk2FieldProperty.h>
       
    26 #include <TPbk2AddItemWrapper.h>
       
    27 #include <CPbk2FieldPropertyArray.h>
       
    28 #include <MPbk2ApplicationServices.h>
       
    29 
       
    30 // Virtual Phonebook
       
    31 #include <CVPbkContactManager.h>
       
    32 #include <MVPbkContactLink.h>
       
    33 #include <MVPbkContactStore.h>
       
    34 #include <MVPbkContactStoreList.h>
       
    35 #include <MVPbkContactStoreProperties.h>
       
    36 #include <VPbkContactStoreUris.h>
       
    37 #include <CVPbkFieldTypeSelector.h>
       
    38 
       
    39 // System includes
       
    40 #include <barsread.h>
       
    41 
       
    42 /// Unnamed namespace for local definitions
       
    43 namespace {
       
    44 
       
    45 enum TPanicCode
       
    46     {
       
    47     ENullPointer,
       
    48     EInvalidParameter
       
    49     };
       
    50 
       
    51 void Panic(TPanicCode aReason)
       
    52     {
       
    53     _LIT(KPanicText, "CPbk2AssignMultiProperty");
       
    54     User::Panic(KPanicText,aReason);
       
    55     }
       
    56 
       
    57 } /// namespace
       
    58 
       
    59 // --------------------------------------------------------------------------
       
    60 // CPbk2AssignMultiProperty::CPbk2AssignMultiProperty
       
    61 // --------------------------------------------------------------------------
       
    62 //
       
    63 CPbk2AssignMultiProperty::CPbk2AssignMultiProperty
       
    64         ( HBufC8& aSelector, TInt aResourceId,
       
    65           MVPbkContactLinkArray& aMarkedEntries ) :
       
    66             CPbk2SelectFieldPropertyBase( aSelector,  aResourceId ),
       
    67             iMarkedEntries( aMarkedEntries )
       
    68     {
       
    69     }
       
    70 
       
    71 // --------------------------------------------------------------------------
       
    72 // CPbk2AssignMultiProperty::~CPbk2AssignMultiProperty
       
    73 // --------------------------------------------------------------------------
       
    74 //
       
    75 CPbk2AssignMultiProperty::~CPbk2AssignMultiProperty()
       
    76     {
       
    77     }
       
    78 
       
    79 // --------------------------------------------------------------------------
       
    80 // CPbk2AssignMultiProperty::NewL
       
    81 // --------------------------------------------------------------------------
       
    82 //
       
    83 CPbk2AssignMultiProperty* CPbk2AssignMultiProperty::NewL
       
    84         ( HBufC8& aSelector, MVPbkContactLinkArray& aMarkedEntries )
       
    85     {
       
    86     CPbk2AssignMultiProperty* self = new ( ELeave ) CPbk2AssignMultiProperty
       
    87         ( aSelector, R_QTN_PHOB_QTL_ENTRY_ADD_TO, aMarkedEntries );
       
    88     CleanupStack::PushL( self );
       
    89     self->ConstructL();
       
    90     CleanupStack::Pop( self );
       
    91     return self;
       
    92     }
       
    93 
       
    94 // --------------------------------------------------------------------------
       
    95 // CPbk2AssignMultiProperty::ConstructL
       
    96 // --------------------------------------------------------------------------
       
    97 //
       
    98 void CPbk2AssignMultiProperty::ConstructL()
       
    99     {
       
   100     BaseConstructL();
       
   101     }
       
   102 
       
   103 // --------------------------------------------------------------------------
       
   104 // CPbk2AssignMultiProperty::PrepareL
       
   105 // --------------------------------------------------------------------------
       
   106 //
       
   107 void CPbk2AssignMultiProperty::PrepareL()
       
   108     {
       
   109     __ASSERT_ALWAYS( iMarkedEntries.Count() > 0,
       
   110         Panic( EInvalidParameter ) );
       
   111 
       
   112     if ( AreAllContactsFromSameStore( iMarkedEntries ) )
       
   113         {
       
   114         TVPbkContactStoreUriPtr uriPtr =
       
   115             iMarkedEntries.At( 0 ).ContactStore().StoreProperties().Uri();
       
   116         CPbk2SelectFieldPropertyBase::CreateWrappersL( uriPtr );
       
   117         if ( iWrappers.Count() <= 0 )
       
   118             {
       
   119             CreateWrappersFromCntDbL();
       
   120             }
       
   121         }
       
   122     else
       
   123         {
       
   124         CreateWrappersFromCntDbL();
       
   125         }
       
   126     }
       
   127 
       
   128 // --------------------------------------------------------------------------
       
   129 // CPbk2AssignMultiProperty::ExecuteL
       
   130 // --------------------------------------------------------------------------
       
   131 //
       
   132 TInt CPbk2AssignMultiProperty::ExecuteL()
       
   133     {
       
   134     __ASSERT_ALWAYS( iFieldProperties, Panic( ENullPointer ) );
       
   135 
       
   136     TInt result = ShowSelectFieldQueryL();
       
   137 
       
   138     if ( result > KErrNotFound &&
       
   139          iWrappers.Count() > 0 &&
       
   140          iWrappers.Count() > result )
       
   141         {
       
   142         iSelectedFieldType = &iWrappers[result].PropertyAt( 0 ).FieldType();
       
   143         }
       
   144 
       
   145     return result;
       
   146     }
       
   147 
       
   148 // --------------------------------------------------------------------------
       
   149 // CPbk2AssignMultiProperty::SelectedFieldIndex
       
   150 // --------------------------------------------------------------------------
       
   151 //
       
   152 TInt CPbk2AssignMultiProperty::SelectedFieldIndex() const
       
   153     {
       
   154     return KErrNotSupported;
       
   155     }
       
   156 
       
   157 // --------------------------------------------------------------------------
       
   158 // CPbk2AssignMultiProperty::AreAllContactsFromSameStore
       
   159 // --------------------------------------------------------------------------
       
   160 //
       
   161 TBool CPbk2AssignMultiProperty::AreAllContactsFromSameStore
       
   162         ( MVPbkContactLinkArray& aMarkedEntries )
       
   163     {
       
   164     TBool ret = ETrue;
       
   165 
       
   166     const TInt count( aMarkedEntries.Count() );
       
   167     if ( count > 1 )
       
   168         {
       
   169         // Take the first URI from array
       
   170         TVPbkContactStoreUriPtr uriPtr =
       
   171             aMarkedEntries.At( 0 ).ContactStore().StoreProperties().Uri();
       
   172         for ( TInt i(1); i < count; ++i )
       
   173             {
       
   174             TVPbkContactStoreUriPtr nextUriPtr =
       
   175                 aMarkedEntries.At( i ).ContactStore().
       
   176                     StoreProperties().Uri();
       
   177             if ( uriPtr.Compare( nextUriPtr,
       
   178                    TVPbkContactStoreUriPtr::EContactStoreUriAllComponents )
       
   179                     != 0 )
       
   180                 {
       
   181                 ret = EFalse;
       
   182                 break;
       
   183                 }
       
   184             }
       
   185         }
       
   186 
       
   187     return ret;
       
   188     }
       
   189 
       
   190 // --------------------------------------------------------------------------
       
   191 // CPbk2AssignMultiProperty::CreateWrappersFromCntDbL
       
   192 // --------------------------------------------------------------------------
       
   193 //
       
   194 void CPbk2AssignMultiProperty::CreateWrappersFromCntDbL()
       
   195     {
       
   196     TResourceReader reader;
       
   197     reader.SetBuffer( &iSelector );
       
   198 
       
   199     // Default saving store
       
   200     CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&>
       
   201         ( *CEikonEnv::Static()->EikAppUi() );
       
   202     MVPbkContactStore* store =
       
   203         appUi.ApplicationServices().ContactManager().ContactStoresL().Find
       
   204             ( VPbkContactStoreUris::DefaultCntDbUri() );
       
   205 
       
   206     CVPbkFieldTypeSelector* selector =
       
   207         CVPbkFieldTypeSelector::NewL( reader,
       
   208             appUi.ApplicationServices().ContactManager().FieldTypes() );
       
   209 
       
   210     CleanupStack::PushL( selector );
       
   211 
       
   212     CreateFieldPropertiesArrayL( *store );
       
   213 
       
   214     const TInt count( iFieldProperties->Count() );
       
   215     for ( TInt i = 0; i < count; ++i )
       
   216         {
       
   217         const MPbk2FieldProperty& property =
       
   218             iFieldProperties->At( i );
       
   219         if ( selector->IsFieldTypeIncluded( property.FieldType() ) )
       
   220             {
       
   221             TPbk2AddItemWrapper wrapper( property );
       
   222             iWrappers.Append( wrapper );
       
   223             }
       
   224         }
       
   225     CleanupStack::PopAndDestroy( selector );
       
   226     }
       
   227 
       
   228 // End of File
       
   229