|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : CCECustomGrouper.cpp 00004 * Part of : Content Listing Framework Sample Application 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 00017 // INCLUDE FILES 00018 #include "CCECustomGrouper.h" 00019 00020 #include "CLFExample.hrh" 00021 #include "CLFExampleConsts.h" 00022 00023 #include <MCLFContentListingEngine.h> 00024 #include <ContentListingFactory.h> 00025 #include <MCLFModifiableItem.h> 00026 #include <CLFContentListing.hrh> 00027 #include <CLFExample.rsg> 00028 00029 // ============================ MEMBER FUNCTIONS =============================== 00030 00031 // ----------------------------------------------------------------------------- 00032 // CCECustomGrouper::CCECustomGrouper 00033 // C++ default constructor can NOT contain any code, that 00034 // might leave. 00035 // ----------------------------------------------------------------------------- 00036 // 00037 CCECustomGrouper::CCECustomGrouper( const TCLFDefaultFieldId aGroupingCriteria ) 00038 : iGroupingCriteria( aGroupingCriteria ) 00039 { 00040 } 00041 00042 // ----------------------------------------------------------------------------- 00043 // CCECustomGrouper::NewL 00044 // Two-phased constructor. 00045 // ----------------------------------------------------------------------------- 00046 // 00047 CCECustomGrouper* CCECustomGrouper::NewL( TCLFDefaultFieldId aGroupingCriteria ) 00048 { 00049 CCECustomGrouper* self = 00050 new (ELeave) CCECustomGrouper( aGroupingCriteria ); 00051 return self; 00052 } 00053 00054 // Destructor 00055 CCECustomGrouper::~CCECustomGrouper() 00056 { 00057 iModItems.ResetAndDestroy(); 00058 } 00059 00060 // ----------------------------------------------------------------------------- 00061 // CCECustomGrouper::GroupItemsL 00062 // Method for grouping Content Listing Framework items. 00063 // ----------------------------------------------------------------------------- 00064 // 00065 void CCECustomGrouper::GroupItemsL( const TArray<MCLFItem*>& aSourceList, 00066 RPointerArray<MCLFItem>& aGroupedList ) 00067 { 00068 // Delete old modifiable items (groups) is any 00069 iModItems.ResetAndDestroy(); 00070 00071 // Process all items of the source list 00072 TInt count( aSourceList.Count() ); 00073 for( TInt i = 0; i < count; ++i ) 00074 { 00075 // Get value of the field in iGroupingCriteria. 00076 // For example, if iFilterCriteria contains ECLFFieldIdArtist, 00077 // name of the artist is stored to fieldValue variable. 00078 TPtrC fieldValue; 00079 MCLFItem* currentItem = aSourceList[i]; 00080 TInt error( currentItem->GetField( 00081 iGroupingCriteria, fieldValue ) ); 00082 00083 if( error == KErrNone ) 00084 { 00085 // Check if the group is already added to the list 00086 if( !GroupAlreadyExists( fieldValue ) ) 00087 { 00088 // Create a new modifiable item and add a field 00089 // name and value of the field. 00090 // For example, if grouping criteria is ECLFFieldIdArtist, 00091 // the field is added to the item with name of the artist. 00092 MCLFModifiableItem* modItem = 00093 ContentListingFactory::NewModifiableItemLC(); 00094 modItem->AddFieldL( iGroupingCriteria, fieldValue ); 00095 00096 // Add the item to the iModItems array to keep track, 00097 // which groups are already in the list (for example, which 00098 // groups are already in the list). The iModItems array 00099 // also deletes these items, when they are no longer needed. 00100 iModItems.AppendL( modItem ); // ownership transferred 00101 00102 CleanupStack::Pop(); // modItem 00103 00104 // Add the item to the model 00105 aGroupedList.AppendL( modItem ); 00106 } 00107 } 00108 } 00109 } 00110 00111 // ----------------------------------------------------------------------------- 00112 // CCECustomGrouper::GroupAlreadyExists 00113 // Checks if group has been added to the model already. 00114 // ----------------------------------------------------------------------------- 00115 // 00116 TBool CCECustomGrouper::GroupAlreadyExists( const TDesC& aGroupName ) 00117 { 00118 TInt count( iModItems.Count() ); 00119 for( TInt i = 0; i < count; ++i ) 00120 { 00121 // Get value of the field in iGroupingCriteria. 00122 // For example, if iGroupingCriteria contains ECLFFieldIdArtist, 00123 // name of the artist is stored to fieldValue variable. 00124 TPtrC fieldValue; 00125 MCLFItem* currentItem = iModItems[i]; 00126 TInt error( currentItem->GetField( 00127 iGroupingCriteria, fieldValue ) ); 00128 00129 if( error == KErrNone ) 00130 { 00131 if( fieldValue == aGroupName ) 00132 { 00133 // Group is in the list 00134 return ETrue; 00135 } 00136 } 00137 } 00138 00139 // Group is not in the list 00140 return EFalse; 00141 } 00142 00143 00144 // End of File
|
© Nokia 2009 |