phonebookui/Phonebook2/UIControls/src/CPbk2ContactIconsUtils.cpp
changeset 0 e686773b3f54
child 32 2828b4d142c0
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 view list box model.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <CPbk2ContactIconsUtils.h>
       
    22 
       
    23 // Phonebook 2
       
    24 #include <CPbk2IconArray.h>
       
    25 #include <CPbk2StoreProperty.h>
       
    26 #include <CPbk2StoreViewDefinition.h>
       
    27 #include <CPbk2StorePropertyArray.h>
       
    28 #include <MPbk2ContactUiControlExtension.h>
       
    29 #include <CPbk2UIExtensionManager.h>
       
    30 #include <MPbk2UIExtensionIconSupport.h>
       
    31 
       
    32 #include <Pbk2UIControls.rsg>
       
    33 #include <Pbk2PresentationUtils.h>
       
    34 #include "Pbk2NamesListExUID.h"
       
    35 
       
    36 // Virtual Phonebook
       
    37 #include <MVPbkContactViewBase.h>
       
    38 #include <MVPbkContactStore.h>
       
    39 #include <MVPbkContactStoreProperties.h>
       
    40 #include <MVPbkViewContact.h>
       
    41 #include <CVPbkContactViewDefinition.h>
       
    42 #include <CVPbkContactManager.h>
       
    43 #include <MVPbkFieldType.h>
       
    44 #include <MVPbkBaseContactField.h>
       
    45 #include <CVPbkFieldTypeSelector.h>
       
    46 #include <MVPbkBaseContactFieldCollection.h>
       
    47 #include <MVPbkContactFieldData.h>
       
    48 
       
    49 // System includes
       
    50 #include <eikenv.h>
       
    51 #include <barsread.h>
       
    52 
       
    53 
       
    54 EXPORT_C CPbk2ContactIconsUtils* CPbk2ContactIconsUtils::NewL(
       
    55         CPbk2StorePropertyArray& aStoreProperties,
       
    56         MPbk2ContactUiControlExtension* aUiExtension )
       
    57     {
       
    58     CPbk2ContactIconsUtils* self = new(ELeave) CPbk2ContactIconsUtils(
       
    59             aStoreProperties,
       
    60             aUiExtension);
       
    61     return self;
       
    62     }
       
    63 
       
    64 CPbk2ContactIconsUtils::~CPbk2ContactIconsUtils()
       
    65     {
       
    66     }
       
    67 
       
    68 CPbk2ContactIconsUtils::CPbk2ContactIconsUtils(
       
    69         CPbk2StorePropertyArray& aStoreProperties,
       
    70         MPbk2ContactUiControlExtension* aUiExtension ):
       
    71         iStoreProperties(aStoreProperties),
       
    72         iUiExtension(aUiExtension)
       
    73     {
       
    74     }
       
    75 
       
    76 EXPORT_C CPbk2IconArray* CPbk2ContactIconsUtils::CreateListboxIconArrayL(
       
    77         TInt aResourceId)
       
    78     {
       
    79     TResourceReader reader;
       
    80     CCoeEnv::Static()->CreateResourceReaderLC( reader, aResourceId );
       
    81     CPbk2IconArray* iconArray = CPbk2IconArray::NewL( reader );
       
    82     CleanupStack::PushL( iconArray );
       
    83 
       
    84     // Add icons from UI extensions
       
    85     CPbk2UIExtensionManager* extManager = CPbk2UIExtensionManager::InstanceL();
       
    86     extManager->PushL();
       
    87     extManager->IconSupportL().AppendExtensionIconsL( *iconArray );
       
    88     CleanupStack::PopAndDestroy(); // extManager
       
    89     CleanupStack::Pop( iconArray );
       
    90     CleanupStack::PopAndDestroy(); // reader
       
    91 
       
    92     return iconArray;    
       
    93     }
       
    94 
       
    95 EXPORT_C void CPbk2ContactIconsUtils::GetIconIdsForContactL(
       
    96         const MVPbkViewContact& aViewContact,
       
    97         RArray<TPbk2IconId>& aIconArray ) const
       
    98     {
       
    99     aIconArray.Reset();
       
   100     
       
   101     // get dynamic icons from ui extension
       
   102     if ( iUiExtension )
       
   103         {
       
   104         const TArray<TPbk2IconId>& ids =
       
   105             iUiExtension->GetDynamicIconsL( &aViewContact );
       
   106         for (TInt i = 0; i < ids.Count(); ++i)
       
   107             {
       
   108             aIconArray.AppendL( ids[i] );
       
   109             }
       
   110         }
       
   111     
       
   112     // find icon from view definition
       
   113     TVPbkContactViewType viewType = aViewContact.ParentView().Type();
       
   114     const TInt propCount = iStoreProperties.Count();
       
   115     TBool propertyFound = EFalse;
       
   116     TBool viewIconFound = EFalse;
       
   117     for (TInt i = 0; i < propCount && !propertyFound; ++i)
       
   118         {
       
   119         // Find store property for the view contact
       
   120         const CPbk2StoreProperty& prop = iStoreProperties.At(i);
       
   121         if (aViewContact.MatchContactStore(prop.StoreUri().UriDes()))
       
   122             {
       
   123             propertyFound = ETrue;
       
   124             TArray<const CPbk2StoreViewDefinition*> pbk2Defs = prop.Views();
       
   125             const TInt defCount = pbk2Defs.Count();
       
   126             for (TInt j = 0; j < defCount && !viewIconFound; ++j)
       
   127                 {
       
   128                 // if types are same use item icon
       
   129                 if (viewType == pbk2Defs[j]->ViewDefinition().Type())
       
   130                     {
       
   131                     aIconArray.AppendL( pbk2Defs[j]->ViewItemIconId() );
       
   132                     viewIconFound = ETrue;
       
   133                     }
       
   134                 }
       
   135             }
       
   136         }
       
   137     }
       
   138 
       
   139 //  End of File