author | Pat Downey <patd@symbian.org> |
Wed, 01 Sep 2010 12:28:47 +0100 | |
branch | RCL_3 |
changeset 66 | a9c0808a1095 |
parent 65 | 0b68a1b0c15e |
permissions | -rw-r--r-- |
19 | 1 |
/* |
2 |
* Copyright (c) 2007-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 the License "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: It filter the media items as per the filter value sets |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
||
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
20 |
#include <MCLFItem.h> |
19 | 21 |
#include "mgpostfilter.h" |
66 | 22 |
#include <mmfcontrollerpluginresolver.h> |
19 | 23 |
|
24 |
const TInt32 KLargestSigned32 = 0x7fffffff; |
|
25 |
const TInt64 KLargestSigned64 = 0x7fffffffffffffff; |
|
26 |
||
27 |
// ----------------------------------------------------------------------------- |
|
28 |
// CPostFilter::NewL |
|
29 |
// Returns the instance of CPostFilter. |
|
30 |
// ----------------------------------------------------------------------------- |
|
31 |
CPostFilter* CPostFilter::NewL() |
|
32 |
{ |
|
33 |
||
34 |
CPostFilter* self = new (ELeave) CPostFilter(); |
|
35 |
return self; |
|
36 |
} |
|
37 |
||
38 |
||
39 |
||
40 |
// ----------------------------------------------------------------------------- |
|
41 |
// CPostFilter::~CPostFilter |
|
42 |
// Destructor |
|
43 |
// ----------------------------------------------------------------------------- |
|
44 |
||
45 |
CPostFilter::~CPostFilter() |
|
46 |
{ |
|
47 |
delete iFilterVal; |
|
48 |
} |
|
49 |
||
50 |
// ----------------------------------------------------------------------------- |
|
51 |
// CPostFilter::FilterItemsL |
|
52 |
// Method to filter source list. This method is called when |
|
53 |
// the filtering process is executed by list model refresh method. |
|
54 |
// ----------------------------------------------------------------------------- |
|
55 |
void CPostFilter::FilterItemsL( const TArray<MCLFItem*>& aItemList, |
|
56 |
RPointerArray<MCLFItem>& aFilteredItemList ) |
|
57 |
{ |
|
58 |
// It will filter the Items |
|
66 | 59 |
CleanupResetAndDestroyPushL(aFilteredItemList); |
19 | 60 |
MCLFItem* item = NULL; |
61 |
||
62 |
for( TInt i = 0 ; i < aItemList.Count() ; ++i ) |
|
63 |
{ |
|
64 |
item = aItemList[i]; |
|
65 |
||
66 |
if( 0 == CompareItem( item )) |
|
67 |
{ |
|
68 |
// item should be include in result |
|
69 |
aFilteredItemList.AppendL( item ); |
|
70 |
} |
|
71 |
} |
|
66 | 72 |
CleanupStack::Pop(&aFilteredItemList); |
19 | 73 |
} |
74 |
||
75 |
// ----------------------------------------------------------------------------- |
|
76 |
// CPostFilter::SetFilterMetaData |
|
77 |
// method to set the filter metadata |
|
78 |
// ----------------------------------------------------------------------------- |
|
79 |
void CPostFilter::SetFilterMetaData(const TCLFDefaultFieldId& aMetaDataId, |
|
80 |
const TCLFItemDataType& aMetaDataType) |
|
81 |
{ |
|
82 |
iFilterMetaData = aMetaDataId; |
|
83 |
iFilterDataType = aMetaDataType; |
|
84 |
} |
|
85 |
||
86 |
// ----------------------------------------------------------------------------- |
|
87 |
// CPostFilter::SetFilterValue |
|
88 |
// Method to set the filter value |
|
89 |
// return KErrCancel if the FilterMetaData is not Set |
|
90 |
// return KErrArgument if the Start or End Value is not Supported |
|
91 |
// return KErrNone if sucessful |
|
92 |
// ----------------------------------------------------------------------------- |
|
93 |
void CPostFilter::SetFilterValueL(const TDesC& aStartVal, |
|
94 |
const TDesC& aEndVal) |
|
95 |
{ |
|
96 |
// check the filter values as per the meta data ... |
|
97 |
// If any abnormal values come it will return proper error code.. |
|
98 |
switch ( iFilterDataType ) |
|
99 |
{ |
|
100 |
case ECLFItemDataTypeDesC: |
|
101 |
{ |
|
102 |
//Filter Id and Value Not NULL |
|
103 |
if( 0 != aStartVal.CompareF( KNullDesC ) ) |
|
104 |
{ |
|
105 |
iFilterVal = aStartVal.AllocL(); |
|
106 |
} |
|
107 |
else |
|
108 |
{ |
|
109 |
User::Leave( KErrNotFound ); |
|
110 |
} |
|
111 |
break; |
|
112 |
} |
|
113 |
||
114 |
case ECLFItemDataTypeTTime: |
|
115 |
{ |
|
116 |
if( ( 0 == aStartVal.CompareF( KNullDesC ) ) && |
|
117 |
( 0 == aEndVal.CompareF( KNullDesC ) ) ) |
|
118 |
{ |
|
119 |
User::Leave( KErrArgument ); |
|
120 |
} |
|
121 |
if( 0 != aStartVal.CompareF( KNullDesC ) ) |
|
122 |
{ |
|
123 |
// check whether start time is in correct format |
|
124 |
if( KErrNone != iStartTime.Set( aStartVal ) ) |
|
125 |
{ |
|
126 |
User::Leave( KErrArgument ); |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
if( 0 != aEndVal.CompareF( KNullDesC ) ) |
|
131 |
{ |
|
132 |
// check whether end time is in correct format |
|
133 |
if( KErrNone != iEndTime.Set( aEndVal ) ) |
|
134 |
{ |
|
135 |
User::Leave( KErrArgument ); |
|
136 |
} |
|
137 |
} |
|
138 |
||
139 |
if( iStartTime > iEndTime ) |
|
140 |
{ |
|
141 |
User::Leave( KErrArgument ); |
|
142 |
} |
|
143 |
||
144 |
break; |
|
145 |
} |
|
146 |
||
147 |
case ECLFItemDataTypeTInt32: |
|
148 |
{ |
|
149 |
TLex lex; |
|
150 |
if( ( 0 == aStartVal.CompareF( KNullDesC ) ) && |
|
151 |
( 0 == aEndVal.CompareF( KNullDesC ) ) ) |
|
152 |
{ |
|
153 |
User::Leave( KErrArgument ); |
|
154 |
} |
|
155 |
if( 0 != aStartVal.CompareF( KNullDesC ) ) |
|
156 |
{ |
|
157 |
lex = aStartVal; |
|
158 |
//check if start value was valid |
|
159 |
if( KErrNone != lex.Val( iStartIntVal ) ) |
|
160 |
{ |
|
161 |
User::Leave( KErrArgument ); |
|
162 |
} |
|
163 |
} |
|
164 |
||
165 |
if( 0 != aEndVal.CompareF( KNullDesC ) ) |
|
166 |
{ |
|
167 |
lex = aEndVal; |
|
168 |
//check if end value given was valid |
|
169 |
if( KErrNone != lex.Val( iEndIntVal ) ) |
|
170 |
{ |
|
171 |
User::Leave( KErrArgument ); |
|
172 |
} |
|
173 |
} |
|
174 |
||
175 |
if( iStartIntVal > iEndIntVal |
|
176 |
|| iStartIntVal<0 |
|
177 |
|| iEndIntVal<0) |
|
178 |
{ |
|
179 |
User::Leave( KErrArgument ); |
|
180 |
} |
|
181 |
||
182 |
break; |
|
183 |
} |
|
184 |
||
185 |
default: |
|
186 |
{ |
|
187 |
User::Leave( KErrArgument ); |
|
188 |
} |
|
189 |
}//End Switch Case |
|
190 |
||
191 |
||
192 |
}// End Function |
|
193 |
||
194 |
||
195 |
// ----------------------------------------------------------------------------- |
|
196 |
// CPostFilter::CPostFilter |
|
197 |
// Constructor |
|
198 |
// ----------------------------------------------------------------------------- |
|
199 |
CPostFilter::CPostFilter(): |
|
200 |
iFilterMetaData( ECLFFieldIdNull ), |
|
201 |
iFilterVal(NULL), |
|
202 |
iStartTime( 0 ), |
|
203 |
iEndTime( KLargestSigned64 ), |
|
204 |
iStartIntVal( 0 ), |
|
205 |
iEndIntVal( KLargestSigned32 ) |
|
206 |
{ |
|
207 |
||
208 |
} |
|
209 |
||
210 |
||
211 |
||
212 |
||
213 |
||
214 |
// ----------------------------------------------------------------------------- |
|
215 |
// CPostFilter::Clear |
|
216 |
// It will clear the filter metadata field |
|
217 |
// ----------------------------------------------------------------------------- |
|
218 |
void CPostFilter::Clear() |
|
219 |
{ |
|
220 |
iFilterMetaData = ECLFFieldIdNull; |
|
221 |
iFilterDataType = ECLFItemDataTypeNull; |
|
222 |
iStartIntVal=0; |
|
223 |
iEndIntVal =KLargestSigned32; |
|
224 |
iStartTime = 0; |
|
225 |
iEndTime =KLargestSigned64; |
|
226 |
||
227 |
||
228 |
delete iFilterVal; |
|
229 |
iFilterVal = NULL; |
|
230 |
||
231 |
} |
|
232 |
||
233 |
||
234 |
// ----------------------------------------------------------------------------- |
|
235 |
// CPostFilter::CompareItem |
|
236 |
// This function will check if the given aItem matches with the set |
|
237 |
// filtered values or not. |
|
238 |
// @return -1 If aItem does not match with the set filter values ,0 If it match. |
|
239 |
// ----------------------------------------------------------------------------- |
|
240 |
TInt CPostFilter::CompareItem( MCLFItem* aItem ) |
|
241 |
{ |
|
242 |
//this function matches the aItem with the filter values. |
|
243 |
TInt retValue = 0; |
|
244 |
// If no filter MetaData skip the function |
|
245 |
if( ECLFFieldIdNull != iFilterMetaData ) |
|
246 |
{ |
|
247 |
switch ( iFilterDataType ) |
|
248 |
{ |
|
249 |
case ECLFItemDataTypeDesC: |
|
250 |
{ |
|
251 |
if( 0 != ( *iFilterVal ).CompareF( KNullDesC ) ) |
|
252 |
{ |
|
253 |
TPtrC itemVal; |
|
254 |
if( KErrNone == aItem->GetField( iFilterMetaData, itemVal ) ) |
|
255 |
{ |
|
256 |
if( 0 != itemVal.CompareF( *iFilterVal ) ) |
|
257 |
{ |
|
258 |
retValue = -1; |
|
259 |
} |
|
260 |
} |
|
261 |
else |
|
262 |
{ |
|
263 |
retValue = -1; |
|
264 |
} |
|
265 |
} |
|
266 |
break; |
|
267 |
}// case ECLFItemDataTypeDesC |
|
268 |
||
269 |
||
270 |
case ECLFItemDataTypeTTime: |
|
271 |
{ |
|
272 |
TTime itemVal; |
|
273 |
if( KErrNone == aItem->GetField( iFilterMetaData, itemVal ) ) |
|
274 |
{ |
|
275 |
if( !(( itemVal >= iStartTime ) && ( itemVal <= iEndTime )) ) |
|
276 |
{ |
|
277 |
retValue = -1; |
|
278 |
} |
|
279 |
||
280 |
} |
|
281 |
else |
|
282 |
{ |
|
283 |
retValue = -1; |
|
284 |
} |
|
285 |
break; |
|
286 |
}// case ECLFItemDataTypeTTime |
|
287 |
||
288 |
||
289 |
case ECLFItemDataTypeTInt32: |
|
290 |
{ |
|
291 |
TInt32 itemVal; |
|
292 |
if( KErrNone == aItem->GetField( iFilterMetaData, itemVal ) ) |
|
293 |
{ |
|
294 |
if( !(( itemVal >= iStartIntVal ) && ( itemVal <= iEndIntVal ))) |
|
295 |
{ |
|
296 |
retValue = -1; |
|
297 |
} |
|
298 |
} |
|
299 |
else |
|
300 |
{ |
|
301 |
retValue = -1; |
|
302 |
} |
|
303 |
break; |
|
304 |
}// case ECLFItemDataTypeTInt32 |
|
305 |
||
306 |
default: |
|
307 |
{ |
|
308 |
retValue = -1; |
|
309 |
break; |
|
310 |
} |
|
311 |
||
312 |
}//End Switch Case |
|
313 |
} |
|
314 |
return retValue; |
|
315 |
} |
|
316 |
||
317 |