|
1 /* |
|
2 * Copyright (c) 2006-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: CUPnPCustomGrouper class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 // INCLUDE FILES |
|
25 #include <MCLFContentListingEngine.h> |
|
26 #include <ContentListingFactory.h> |
|
27 #include <MCLFModifiableItem.h> |
|
28 #include <CLFContentListing.hrh> |
|
29 #include "upnpcustomgrouper.h" |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS ============================= |
|
32 |
|
33 // -------------------------------------------------------------------------- |
|
34 // CUpnpCustomGrouper::CUpnpCustomGrouper |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // -------------------------------------------------------------------------- |
|
38 // |
|
39 CUpnpCustomGrouper::CUpnpCustomGrouper( |
|
40 const TCLFExtendedFieldId aGroupingCriteria ) |
|
41 : iGroupingCriteria( aGroupingCriteria ) |
|
42 { |
|
43 } |
|
44 |
|
45 // -------------------------------------------------------------------------- |
|
46 // CUpnpCustomGrouper::NewL |
|
47 // Two-phased constructor. |
|
48 // -------------------------------------------------------------------------- |
|
49 // |
|
50 CUpnpCustomGrouper* CUpnpCustomGrouper::NewL( |
|
51 TCLFExtendedFieldId aGroupingCriteria ) |
|
52 { |
|
53 CUpnpCustomGrouper* self = |
|
54 new (ELeave) CUpnpCustomGrouper( aGroupingCriteria ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // Destructor |
|
59 CUpnpCustomGrouper::~CUpnpCustomGrouper() |
|
60 { |
|
61 iModItems.ResetAndDestroy(); |
|
62 } |
|
63 |
|
64 // -------------------------------------------------------------------------- |
|
65 // CUpnpCustomGrouper::GroupItemsL |
|
66 // Method for grouping Content Listing Framework items. |
|
67 // -------------------------------------------------------------------------- |
|
68 // |
|
69 void CUpnpCustomGrouper::GroupItemsL(const TArray<MCLFItem*>& aSourceList, |
|
70 RPointerArray<MCLFItem>& aGroupedList) |
|
71 { |
|
72 // Delete old modifiable items (groups) is any |
|
73 iModItems.ResetAndDestroy(); |
|
74 |
|
75 // Process all items of the source list |
|
76 TInt count( aSourceList.Count() ); |
|
77 for( TInt i = 0; i < count; i++ ) |
|
78 { |
|
79 // Get value of the field in iGroupingCriteria. |
|
80 // For example, if iFilterCriteria contains ECLFFieldIdArtist, |
|
81 // name of the artist is stored to fieldValue variable. |
|
82 TPtrC fieldValue; |
|
83 MCLFItem* currentItem = aSourceList[i]; |
|
84 TInt error( currentItem->GetField( |
|
85 iGroupingCriteria, fieldValue ) ); |
|
86 |
|
87 if( error == KErrNone ) |
|
88 { |
|
89 // Check if the group is already added to the list |
|
90 if( !GroupAlreadyExists( fieldValue ) ) |
|
91 { |
|
92 // Create a new modifiable item and add a field |
|
93 // name and value of the field. |
|
94 // For example, if grouping criteria is ECLFFieldIdArtist, |
|
95 // the field is added to the item with name of the artist. |
|
96 MCLFModifiableItem* modItem = |
|
97 ContentListingFactory::NewModifiableItemLC(); |
|
98 modItem->AddFieldL( iGroupingCriteria, fieldValue ); |
|
99 |
|
100 // Add the item to the iModItems array to keep track, |
|
101 // which groups are already in the list (for example, which |
|
102 // groups are already in the list). The iModItems array |
|
103 // also deletes these items, when they are no longer needed. |
|
104 iModItems.AppendL( modItem ); // ownership transferred |
|
105 |
|
106 CleanupStack::Pop(); // modItem |
|
107 |
|
108 // Add the item to the model |
|
109 aGroupedList.AppendL( modItem ); |
|
110 } |
|
111 } |
|
112 } |
|
113 } |
|
114 |
|
115 // -------------------------------------------------------------------------- |
|
116 // CUpnpCustomGrouper::GroupAlreadyExists |
|
117 // Checks if group has been added to the model already. |
|
118 // -------------------------------------------------------------------------- |
|
119 // |
|
120 TBool CUpnpCustomGrouper::GroupAlreadyExists( const TDesC& aGroupName ) |
|
121 { |
|
122 TBool status = EFalse; |
|
123 TInt count( iModItems.Count() ); |
|
124 for( TInt i = 0; i < count; i++ ) |
|
125 { |
|
126 // Get value of the field in iGroupingCriteria. |
|
127 // For example, if iGroupingCriteria contains ECLFFieldIdArtist, |
|
128 // name of the artist is stored to fieldValue variable. |
|
129 TPtrC fieldValue; |
|
130 MCLFItem* currentItem = iModItems[i]; |
|
131 TInt error( currentItem->GetField( |
|
132 iGroupingCriteria, fieldValue ) ); |
|
133 |
|
134 if( error == KErrNone ) |
|
135 { |
|
136 if( fieldValue == aGroupName ) |
|
137 { |
|
138 // Group is in the list |
|
139 status = ETrue; |
|
140 } |
|
141 } |
|
142 } |
|
143 |
|
144 // Group is not in the list |
|
145 return status; |
|
146 } |
|
147 |
|
148 |
|
149 // End of File |