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