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: CUPnPPostFilter class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 // INCLUDE FILES |
|
25 #include <MCLFContentListingEngine.h> |
|
26 #include <ContentListingFactory.h> |
|
27 #include <MCLFItem.h> |
|
28 #include <CLFContentListing.hrh> |
|
29 |
|
30 #include "upnppostfilter.h" |
|
31 #include "upnpcontentserverdefs.h" |
|
32 |
|
33 _LIT( KComponentLogfile, "contentserver.txt"); |
|
34 #include "upnplog.h" |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS ============================= |
|
37 |
|
38 // -------------------------------------------------------------------------- |
|
39 // CUpnpPostFilter::CUpnpPostFilter |
|
40 // C++ default constructor can NOT contain any code, that |
|
41 // might leave. |
|
42 // -------------------------------------------------------------------------- |
|
43 // |
|
44 |
|
45 CUpnpPostFilter::CUpnpPostFilter( |
|
46 const TCLFExtendedFieldId aFilterCriteria, |
|
47 TBool aRemoveDuplicates ) |
|
48 : iFilterCriteria( aFilterCriteria ), |
|
49 iRemoveDuplicates( aRemoveDuplicates ) |
|
50 { |
|
51 } |
|
52 |
|
53 // -------------------------------------------------------------------------- |
|
54 // CCEPostFilter::ConstructL |
|
55 // Symbian 2nd phase constructor can leave. |
|
56 // -------------------------------------------------------------------------- |
|
57 // |
|
58 void CUpnpPostFilter::ConstructL( const TDesC& aFilterParameter ) |
|
59 { |
|
60 iFilterParameter = aFilterParameter.AllocL(); |
|
61 } |
|
62 |
|
63 // -------------------------------------------------------------------------- |
|
64 // CCEPostFilter::NewL |
|
65 // Two-phased constructor. |
|
66 // -------------------------------------------------------------------------- |
|
67 // |
|
68 |
|
69 CUpnpPostFilter* CUpnpPostFilter::NewL( |
|
70 const TCLFExtendedFieldId aFilterCriteria, |
|
71 const TDesC& aFilterParameter, |
|
72 TBool aRemoveDuplicates ) |
|
73 { |
|
74 CUpnpPostFilter* self = |
|
75 CUpnpPostFilter::NewLC( aFilterCriteria, aFilterParameter, |
|
76 aRemoveDuplicates ); |
|
77 CleanupStack::Pop( self ); |
|
78 return self; |
|
79 } |
|
80 |
|
81 // -------------------------------------------------------------------------- |
|
82 // CUpnpPostFilter::NewLC |
|
83 // Two-phased constructor, pointer is left to the CleanupStack. |
|
84 // -------------------------------------------------------------------------- |
|
85 // |
|
86 CUpnpPostFilter* CUpnpPostFilter::NewLC( |
|
87 const TCLFExtendedFieldId aFilterCriteria, |
|
88 const TDesC& aFilterParameter, |
|
89 TBool aRemoveDuplicates ) |
|
90 { |
|
91 CUpnpPostFilter* self = new (ELeave) CUpnpPostFilter( |
|
92 aFilterCriteria, aRemoveDuplicates ); |
|
93 CleanupStack::PushL( self ); |
|
94 self->ConstructL( aFilterParameter ); |
|
95 return self; |
|
96 } |
|
97 |
|
98 // Destructor |
|
99 CUpnpPostFilter::~CUpnpPostFilter() |
|
100 { |
|
101 delete iFilterParameter; |
|
102 } |
|
103 |
|
104 // -------------------------------------------------------------------------- |
|
105 // CCEPostFilter::FilterItemsL |
|
106 // Method for filtering the source list. |
|
107 // -------------------------------------------------------------------------- |
|
108 // |
|
109 void CUpnpPostFilter::FilterItemsL( const TArray<MCLFItem*>& aItemList, |
|
110 RPointerArray<MCLFItem>& aFilteredItemList ) |
|
111 { |
|
112 // Process all items in the item list |
|
113 TInt count( aItemList.Count() ); |
|
114 for( TInt i = 0; i < count; i++ ) |
|
115 { |
|
116 // Get value of the field defined in iFilterCriteria. |
|
117 // For example, if iFilterCriteria contains ECLFFieldIdAlbum, |
|
118 // name of the album is stored to fieldValue variable. |
|
119 TPtrC fieldValue; |
|
120 MCLFItem* currentItem = aItemList[i]; |
|
121 TInt error( currentItem->GetField( |
|
122 iFilterCriteria, fieldValue ) ); |
|
123 |
|
124 // Add the music file to the filtered list, |
|
125 // if value of of the field is same as iFilterParameter. |
|
126 // For example, if it is from the desired album. |
|
127 if( error == KErrNone ) |
|
128 { |
|
129 TBool add( EFalse ); |
|
130 if ( iRemoveDuplicates ) |
|
131 { |
|
132 if ( !IsAdded( aFilteredItemList, fieldValue ) ) |
|
133 { |
|
134 add = ETrue; |
|
135 } |
|
136 } |
|
137 else |
|
138 { |
|
139 if( fieldValue == iFilterParameter->Des() ) |
|
140 { |
|
141 add = ETrue; |
|
142 } |
|
143 } |
|
144 if( add ) |
|
145 { |
|
146 aFilteredItemList.AppendL( currentItem ); |
|
147 } |
|
148 } |
|
149 } |
|
150 } |
|
151 |
|
152 // -------------------------------------------------------------------------- |
|
153 // CUpnpPostFilter::IsAdded |
|
154 // ( other items are commented in header ) |
|
155 // -------------------------------------------------------------------------- |
|
156 // |
|
157 TBool CUpnpPostFilter::IsAdded( RPointerArray<MCLFItem>& aFilteredItemList, |
|
158 TPtrC& aFieldValue ) |
|
159 { |
|
160 TBool isAdded( EFalse ); |
|
161 for( TInt i(0); i<aFilteredItemList.Count(); i++ ) |
|
162 { |
|
163 MCLFItem* currentItem = aFilteredItemList[i]; |
|
164 |
|
165 TPtrC fieldValue; |
|
166 TInt error( currentItem->GetField( |
|
167 iFilterCriteria, fieldValue ) ); |
|
168 |
|
169 if( error == KErrNone ) |
|
170 { |
|
171 if ( fieldValue == aFieldValue ) |
|
172 { |
|
173 isAdded = ETrue; |
|
174 __LOG("found duplicate"); |
|
175 } |
|
176 } |
|
177 } |
|
178 return isAdded; |
|
179 } |
|
180 |
|
181 // End of File |
|