phonebookui/Phonebook2/Presentation/src/CPbk2ContactViewBuilder.cpp
changeset 0 e686773b3f54
child 3 04ab22b956c2
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-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: 
       
    15 *     Phonebook 2 contact view builder.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "CPbk2ContactViewBuilder.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "Pbk2PresentationUtils.h"
       
    24 #include "CPbk2StoreConfiguration.h"
       
    25 #include "CPbk2StoreProperty.h"
       
    26 #include "CPbk2StorePropertyArray.h"
       
    27 #include "CPbk2StoreViewDefinition.h"
       
    28 #include <RPbk2LocalizedResourceFile.h>
       
    29 #include <Pbk2Presentation.rsg>
       
    30 #include <Pbk2DataCaging.hrh>
       
    31 
       
    32  #include <CVPbkFieldTypeSelector.h>
       
    33  #include <VPbkContactViewFilterBuilder.h>
       
    34     
       
    35 // Virtual Phonebook
       
    36 #include <CVPbkContactStoreUriArray.h>
       
    37 #include <CVPbkContactViewDefinition.h>
       
    38 #include <CVPbkContactManager.h>
       
    39 #include <MVPbkContactViewBase.h>
       
    40 #include <MVPbkContactSelector.h>
       
    41 #include <VPbkContactView.hrh>
       
    42 
       
    43 // System includes
       
    44 #include <coemain.h>
       
    45 #include <barsread.h>
       
    46 
       
    47 
       
    48 // --------------------------------------------------------------------------
       
    49 // CPbk2ContactViewBuilder::CPbk2ContactViewBuilder
       
    50 // --------------------------------------------------------------------------
       
    51 //
       
    52 CPbk2ContactViewBuilder::CPbk2ContactViewBuilder(
       
    53             CVPbkContactManager& aContactManager,
       
    54             CPbk2StorePropertyArray& aStoreProperties ) :
       
    55         iContactManager( aContactManager ),
       
    56         iStoreProperties( aStoreProperties )
       
    57     {
       
    58     }
       
    59 
       
    60 // --------------------------------------------------------------------------
       
    61 // CPbk2ContactViewBuilder::~CPbk2ContactViewBuilder
       
    62 // --------------------------------------------------------------------------
       
    63 //
       
    64 CPbk2ContactViewBuilder::~CPbk2ContactViewBuilder()
       
    65     {
       
    66     }
       
    67 
       
    68 // --------------------------------------------------------------------------
       
    69 // CPbk2ContactViewBuilder::NewLC
       
    70 // --------------------------------------------------------------------------
       
    71 //
       
    72 EXPORT_C CPbk2ContactViewBuilder* CPbk2ContactViewBuilder::NewLC(
       
    73         CVPbkContactManager& aContactManager,
       
    74         CPbk2StorePropertyArray& aStoreProperties )
       
    75     {
       
    76     CPbk2ContactViewBuilder* self = new ( ELeave ) CPbk2ContactViewBuilder(
       
    77         aContactManager, aStoreProperties );
       
    78     CleanupStack::PushL( self );
       
    79     return self;
       
    80     }
       
    81 
       
    82 // --------------------------------------------------------------------------
       
    83 // CPbk2ContactViewBuilder::CreateContactViewForStoresLC
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C MVPbkContactViewBase*
       
    87     CPbk2ContactViewBuilder::CreateContactViewForStoresLC(
       
    88         const CVPbkContactStoreUriArray& aUriArray,
       
    89         MVPbkContactViewObserver& aObserver,
       
    90         const MVPbkFieldTypeList& aSortOrder,
       
    91         CVPbkFieldTypeSelector* aFilter,
       
    92         TUint32 aFlags ) const
       
    93     {
       
    94     return CreateViewForStoresLC
       
    95         ( EPbk2MainNamesList, aUriArray, aObserver, aSortOrder, aFilter, aFlags );
       
    96     }
       
    97 
       
    98 
       
    99 // --------------------------------------------------------------------------
       
   100 // CPbk2ContactViewBuilder::CreateTopNonTopContactViewForStoresLC
       
   101 //
       
   102 // Similar as CreateContactViewForStoresLC but TopContacts are filtered out
       
   103 // --------------------------------------------------------------------------
       
   104 //
       
   105 EXPORT_C MVPbkContactViewBase*
       
   106     CPbk2ContactViewBuilder::CreateTopNonTopContactViewForStoresLC(
       
   107         const CVPbkContactStoreUriArray& aUriArray,
       
   108         MVPbkContactViewObserver& aObserver,
       
   109         const MVPbkFieldTypeList& aSortOrder,
       
   110         CVPbkFieldTypeSelector* aFilter,
       
   111         TUint32 aFlags,
       
   112         MVPbkContactSelector& aContactSelector ) const
       
   113     {
       
   114     iContactSelector = &aContactSelector;
       
   115 
       
   116     return CreateViewForStoresLC(
       
   117         EPbk2MainTopContactsList, // This param has no effect if aTopContacts=ETrue
       
   118         aUriArray,
       
   119         aObserver,
       
   120         aSortOrder,
       
   121         aFilter,
       
   122         aFlags,
       
   123         ETrue ); // aTopContacts = ETrue
       
   124     }
       
   125     
       
   126 // --------------------------------------------------------------------------
       
   127 // CPbk2ContactViewBuilder::CreateGroupViewForStoresLC
       
   128 // --------------------------------------------------------------------------
       
   129 //
       
   130 EXPORT_C MVPbkContactViewBase*
       
   131     CPbk2ContactViewBuilder::CreateGroupViewForStoresLC(
       
   132         const CVPbkContactStoreUriArray& aUriArray,
       
   133         MVPbkContactViewObserver& aObserver,
       
   134         const MVPbkFieldTypeList& aSortOrder,
       
   135         CVPbkFieldTypeSelector* aFilter,
       
   136         TUint32 aFlags ) const
       
   137     {
       
   138     return CreateViewForStoresLC
       
   139         ( EPbk2MainGroupsList, aUriArray, aObserver, aSortOrder, aFilter, aFlags );
       
   140     }
       
   141 
       
   142 // --------------------------------------------------------------------------
       
   143 // CPbk2ContactViewBuilder::BuildMainViewStructureLC
       
   144 // --------------------------------------------------------------------------
       
   145 //
       
   146 CVPbkContactViewDefinition*
       
   147         CPbk2ContactViewBuilder::BuildMainViewStructureLC(
       
   148         		CVPbkFieldTypeSelector* aFilter,
       
   149         		TUint32 aFlags ) const
       
   150     {
       
   151     RPbk2LocalizedResourceFile resFile( *CCoeEnv::Static() );
       
   152     resFile.OpenLC( KPbk2RomFileDrive, 
       
   153         KDC_RESOURCE_FILES_DIR, 
       
   154         Pbk2PresentationUtils::PresentationResourceFile() );
       
   155     
       
   156     TResourceReader reader;
       
   157     CCoeEnv::Static()->CreateResourceReaderLC
       
   158         ( reader, R_PHONEBOOK2_MAIN_CONTACT_VIEW_STRUCTURE );
       
   159 
       
   160     CVPbkContactViewDefinition* viewDef =
       
   161         CVPbkContactViewDefinition::NewL( reader );
       
   162     CleanupStack::PopAndDestroy(2); // reader, resFile
       
   163     CleanupStack::PushL( viewDef );
       
   164     
       
   165     if( aFlags & EVPbkExcludeEmptyGroups )
       
   166     	{
       
   167     	viewDef->SetFlag ( EVPbkExcludeEmptyGroups, ETrue );
       
   168     	}
       
   169     
       
   170     viewDef->SetFieldTypeFilterL( aFilter );
       
   171     return viewDef;
       
   172     }
       
   173 
       
   174 // --------------------------------------------------------------------------
       
   175 // CPbk2ContactViewBuilder::CreateViewForStoresLC
       
   176 // Creates a sub-view for all matching view types, from the listed stores. 
       
   177 // --------------------------------------------------------------------------
       
   178 //
       
   179 /**
       
   180  * Creates a sub-view for all matching view types from the listed stores. 
       
   181  * @param aViewType The view type that should match.
       
   182  * @param aUriArray The Stores from which to look for views.
       
   183  * @param aObserver An observer
       
   184  * @param aSortOrder
       
   185  * @param aFilter An object that is able to discard contacts based on
       
   186  *                  field collection.
       
   187  * @param aTopContacts Whether or not to construct a top/non-top-contact style
       
   188  *                  of list, or a normal legacy list with no top contacts.
       
   189  * @return The actual new view. 
       
   190  */
       
   191 MVPbkContactViewBase* CPbk2ContactViewBuilder::CreateViewForStoresLC(
       
   192         TPbk2ContactViewType aViewType,
       
   193         const CVPbkContactStoreUriArray& aUriArray,
       
   194         MVPbkContactViewObserver& aObserver,
       
   195         const MVPbkFieldTypeList& aSortOrder,
       
   196         CVPbkFieldTypeSelector* aFilter,
       
   197         TUint32 aFlags,
       
   198         TBool aTopContacts ) const
       
   199     {
       
   200     // Main view is a composite view that contains several sub composite
       
   201     // views. The subviews are identified by TPbk2ContactViewLocation. 
       
   202     CVPbkContactViewDefinition* viewDef = BuildMainViewStructureLC( aFilter, aFlags );
       
   203     
       
   204     const TInt count = aUriArray.Count();
       
   205     for ( TInt i = 0; i < count; ++i )
       
   206         {
       
   207         // Get store property for each URI
       
   208         const CPbk2StoreProperty* storeProperty =
       
   209             iStoreProperties.FindProperty( aUriArray[i] );
       
   210         if ( storeProperty )
       
   211             {
       
   212             // Loop all view definitions of the store and
       
   213             // add the view definitions to the correct sub view of 
       
   214             // the main structure.
       
   215             TArray<const CPbk2StoreViewDefinition*> viewDefs = 
       
   216                 storeProperty->Views();
       
   217             const TInt viewDefCount = viewDefs.Count();
       
   218             for ( TInt j = 0; j < viewDefCount; ++j )
       
   219                 {
       
   220                 const CPbk2StoreViewDefinition* pb2ViewDef = viewDefs[j];
       
   221                 // Check that UI type of the view is the given type.
       
   222                 // Meaning that does the view belong to all-contacts-view
       
   223                 // or all-groups-view.
       
   224                 
       
   225                 TBool includeThisView = pb2ViewDef->ViewType() == aViewType;
       
   226                 if ( aTopContacts )
       
   227                     {
       
   228                     includeThisView = IncludeThisViewInTopContactMode( pb2ViewDef->ViewType() );
       
   229                     }
       
   230                 if ( includeThisView )
       
   231                     {
       
   232                     // Get the correct sub view of the main view structure.
       
   233                     CVPbkContactViewDefinition& subView = viewDef->SubViewAt( 
       
   234                         TInt( pb2ViewDef->ViewLocation() ) );
       
   235                     // Add store's view to composite.
       
   236                     CVPbkContactViewDefinition* newSubView =
       
   237                         CVPbkContactViewDefinition::NewL( 
       
   238                             pb2ViewDef->ViewDefinition() );
       
   239                     CleanupStack::PushL( newSubView );
       
   240                     if ( aTopContacts )
       
   241                         {
       
   242                         SetTopRelatedFilteringL(
       
   243                             *newSubView, pb2ViewDef->ViewType(), aFilter );
       
   244                         }
       
   245                     else
       
   246                         {
       
   247                         newSubView->SetFieldTypeFilterL( aFilter );
       
   248                         }
       
   249                     if( aFlags & EVPbkExcludeEmptyGroups )
       
   250                         {
       
   251                         newSubView->SetFlag ( EVPbkExcludeEmptyGroups, ETrue );
       
   252                         }
       
   253                     
       
   254                     if( aFlags & EVPbkExcludeEmptyGroups )
       
   255                     	{
       
   256                     	newSubView->SetFlag ( EVPbkExcludeEmptyGroups, ETrue );
       
   257                     	}
       
   258                     
       
   259                     subView.AddSubViewL( newSubView );
       
   260                     CleanupStack::Pop();
       
   261                     }
       
   262                 }
       
   263             }
       
   264         }
       
   265 
       
   266     MVPbkContactViewBase* result = iContactManager.CreateContactViewLC
       
   267         ( aObserver, *viewDef, aSortOrder );
       
   268     CleanupStack::Pop(); // result
       
   269 
       
   270     CleanupStack::PopAndDestroy(); // viewDef
       
   271     CleanupDeletePushL( result );
       
   272     return result;
       
   273     }
       
   274                     
       
   275                     
       
   276 TBool CPbk2ContactViewBuilder::IncludeThisViewInTopContactMode(
       
   277     TPbk2ContactViewType aViewType )
       
   278     {
       
   279     return aViewType == EPbk2MainTopContactsList || aViewType == EPbk2MainNamesList;
       
   280     }
       
   281     
       
   282 void CPbk2ContactViewBuilder::SetTopRelatedFilteringL(
       
   283     CVPbkContactViewDefinition& aNewSubViewDef,
       
   284     TPbk2ContactViewType aViewType,
       
   285     CVPbkFieldTypeSelector* aFilter ) const
       
   286     {
       
   287     if ( aViewType == EPbk2MainTopContactsList )
       
   288         {
       
   289         //Override original filter with top contact filter.
       
   290         CVPbkFieldTypeSelector* filter = CVPbkFieldTypeSelector::NewL(
       
   291             iContactManager.FieldTypes());
       
   292         CleanupStack::PushL(filter);         
       
   293 
       
   294         //Set the filter to retrieve Top contact items (VPbkContactView.hrh)
       
   295         VPbkContactViewFilterBuilder::BuildContactViewFilterL( *filter, 
       
   296             TVPbkContactViewFilter(EVPbkContactViewFilterTopContact), iContactManager );
       
   297         aNewSubViewDef.SetFieldTypeFilterL( filter ); 
       
   298         CleanupStack::PopAndDestroy(); //filter  
       
   299         }
       
   300     else if ( aViewType == EPbk2MainNamesList )
       
   301         {
       
   302         //Use original filter, if any
       
   303         aNewSubViewDef.SetFieldTypeFilterL( aFilter );  
       
   304         if ( iContactSelector )
       
   305             {
       
   306             // Add the contact selector
       
   307             // (usually the Non-Top Contacts selector)
       
   308             aNewSubViewDef.SetContactSelector( iContactSelector ); // ownership not transferred
       
   309             }
       
   310         }
       
   311     else
       
   312         {
       
   313         //Use original filter, if any
       
   314         aNewSubViewDef.SetFieldTypeFilterL( aFilter );          
       
   315         }
       
   316     }
       
   317 
       
   318 // End of File