Nokia N97 SDK
Example Applications Guide

CCECustomGrouper Class Reference

#include <CCECustomGrouper.h>

Inheritance diagram for CCECustomGrouper:

List of all members.

Detailed Description

CLF Custom Grouper. Example of Custom Grouper that can be used to group files in the list model. With Custom Groupers you can create grouping functionality that is not supported in Content Listing Framework by default. This Custom Grouper can group items of a list model by any field. In this example application, this Custom Grouper is used to group music items by artist name.

Definition at line 41 of file CCECustomGrouper.h.


Public Member Functions

virtual  ~CCECustomGrouper ()

Static Public Member Functions

static CCECustomGrouper *  NewL (TCLFDefaultFieldId aGroupingCriteria)

Protected Member Functions

void  GroupItemsL (const TArray< MCLFItem * > &aSourceList, RPointerArray< MCLFItem > &aGroupedList)

Private Member Functions

  CCECustomGrouper (TCLFDefaultFieldId aGroupingCriteria)
TBool  GroupAlreadyExists (const TDesC &aGroupName)

Private Attributes

RPointerArray< MCLFModifiableItem >  iModItems
TCLFDefaultFieldId  iGroupingCriteria


Constructor & Destructor Documentation

CCECustomGrouper::~CCECustomGrouper (   )  [virtual]
 

Destructor.

Definition at line 55 of file CCECustomGrouper.cpp.

References iModItems.

00056     {
00057     iModItems.ResetAndDestroy();
00058     }

CCECustomGrouper::CCECustomGrouper (  TCLFDefaultFieldId  aGroupingCriteria  )  [private]
 

C++ default constructor.

Parameters:
aGroupingCriteria  Group list items by this criteria

Definition at line 37 of file CCECustomGrouper.cpp.

Referenced by NewL().

00038     : iGroupingCriteria( aGroupingCriteria )
00039     {
00040     }


Member Function Documentation

CCECustomGrouper * CCECustomGrouper::NewL (  TCLFDefaultFieldId  aGroupingCriteria  )  [static]
 

Creates and returns a new instance of this class.

Parameters:
aGroupingCriteria  Group items by this criteria
Returns:
Pointer to the CCECustomGrouper object

Definition at line 47 of file CCECustomGrouper.cpp.

References CCECustomGrouper().

00048     {
00049     CCECustomGrouper* self =
00050         new (ELeave) CCECustomGrouper( aGroupingCriteria );
00051     return self;
00052     }

void CCECustomGrouper::GroupItemsL (  const TArray< MCLFItem * > &  aSourceList,
RPointerArray< MCLFItem > &  aGroupedList
)  [protected]
 

From MCLFCustomGrouper. Method for grouping Content Listing Framework items. Will get called when grouping operation is executed by calling refresh for the list model.

Since:
Series 60 3.0
Parameters:
aSourceList  Source list
aGroupedList  Grouped/destination list

Definition at line 65 of file CCECustomGrouper.cpp.

References GroupAlreadyExists(), iGroupingCriteria, and iModItems.

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     }

TBool CCECustomGrouper::GroupAlreadyExists (  const TDesC &  aGroupName  )  [private]
 

Checks if group has been added to the destination array already.

Parameters:
aGroupName  Name of the group to be checked
Returns:
ETrue If group has been added to the model, EFalse if not

Definition at line 116 of file CCECustomGrouper.cpp.

References iGroupingCriteria, and iModItems.

Referenced by GroupItemsL().

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     }


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top