|
1 /* |
|
2 * Copyright (c) 2008 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: Class for providing list filtering. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mpxmedia.h> |
|
20 #include <mpxmediaarray.h> |
|
21 #include <mpxmediageneraldefs.h> |
|
22 #include "mpxcommoncontainerfilteredlist.h" |
|
23 |
|
24 // CONSTANTS |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 CMPXCommonContainerFilteredList* CMPXCommonContainerFilteredList::NewL() |
|
31 { |
|
32 CMPXCommonContainerFilteredList* self = |
|
33 CMPXCommonContainerFilteredList::NewLC(); |
|
34 CleanupStack::Pop( self ); |
|
35 return self; |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CMPXCommonContainerFilteredList* CMPXCommonContainerFilteredList::NewLC() |
|
43 { |
|
44 CMPXCommonContainerFilteredList* self = |
|
45 new (ELeave) CMPXCommonContainerFilteredList(); |
|
46 CleanupStack::PushL( self ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CMPXCommonContainerFilteredList::CMPXCommonContainerFilteredList() |
|
55 : iFiltering( EFalse ) |
|
56 { |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CMPXCommonContainerFilteredList::~CMPXCommonContainerFilteredList() |
|
64 { |
|
65 iFilteredMediaList.Reset(); |
|
66 delete iFilteringWord; |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 void CMPXCommonContainerFilteredList::ReplaceMediaListL( const CMPXMediaArray& aMediaList ) |
|
74 { |
|
75 iMediaList = const_cast<CMPXMediaArray*>(&aMediaList); |
|
76 |
|
77 if ( iFiltering ) |
|
78 { |
|
79 HBufC* tempWord = iFilteringWord; |
|
80 CleanupStack::PushL( tempWord ); |
|
81 iFilteringWord = NULL; |
|
82 |
|
83 ReAdjustFilteringL( *tempWord ); |
|
84 |
|
85 CleanupStack::PopAndDestroy( tempWord ); |
|
86 } |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 void CMPXCommonContainerFilteredList::SetFilteringWordL( const TDesC& aWord ) |
|
94 { |
|
95 if ( aWord.Length() > 0 ) |
|
96 { |
|
97 if ( HasMediaList() ) |
|
98 { |
|
99 ReAdjustFilteringL( aWord ); |
|
100 iFiltering = ETrue; |
|
101 } |
|
102 } |
|
103 else |
|
104 { |
|
105 iFilteredMediaList.Reset(); |
|
106 delete iFilteringWord; |
|
107 iFilteringWord = NULL; |
|
108 iFiltering = EFalse; |
|
109 } |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 TBool CMPXCommonContainerFilteredList::IsFiltering() |
|
117 { |
|
118 return iFiltering; |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 TBool CMPXCommonContainerFilteredList::HasMediaList() |
|
126 { |
|
127 return iMediaList != NULL; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 TInt CMPXCommonContainerFilteredList::FilteredCount() |
|
135 { |
|
136 if ( HasMediaList() ) |
|
137 { |
|
138 if ( iFiltering ) |
|
139 { |
|
140 return iFilteredMediaList.Count(); |
|
141 } |
|
142 else |
|
143 { |
|
144 return iMediaList->Count(); |
|
145 } |
|
146 } |
|
147 |
|
148 return 0; |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 TBool CMPXCommonContainerFilteredList::IsFilteredIndexValid( TInt aFilteredIndex ) |
|
156 { |
|
157 if ( HasMediaList() && aFilteredIndex >= 0 ) |
|
158 { |
|
159 if ( iFiltering ) |
|
160 { |
|
161 if ( aFilteredIndex < iFilteredMediaList.Count() ) |
|
162 { |
|
163 return ETrue; |
|
164 } |
|
165 } |
|
166 else |
|
167 { |
|
168 if ( aFilteredIndex < iMediaList->Count() ) |
|
169 { |
|
170 return ETrue; |
|
171 } |
|
172 } |
|
173 } |
|
174 |
|
175 return EFalse; |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 TInt CMPXCommonContainerFilteredList::FilteredIndexToRealIndex( TInt aFilteredIndex ) |
|
183 { |
|
184 TInt realIndex( KErrNotFound ); |
|
185 |
|
186 if ( HasMediaList() ) |
|
187 { |
|
188 if ( iFiltering ) |
|
189 { |
|
190 if ( aFilteredIndex < iFilteredMediaList.Count() ) |
|
191 { |
|
192 realIndex = iFilteredMediaList[aFilteredIndex]; |
|
193 } |
|
194 } |
|
195 else |
|
196 { |
|
197 if ( aFilteredIndex < iMediaList->Count() ) |
|
198 { |
|
199 realIndex = aFilteredIndex; |
|
200 } |
|
201 } |
|
202 } |
|
203 |
|
204 return realIndex; |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CMPXCommonContainerFilteredList::ReAdjustFilteringL( const TDesC& aWord ) |
|
212 { |
|
213 CMPXMedia* media = NULL; |
|
214 |
|
215 // If user added more letters to filtering, update from existing set. |
|
216 if ( iFilteringWord && |
|
217 iFilteringWord->Length() < aWord.Length() ) |
|
218 { |
|
219 TInt ri( KErrNotFound ); |
|
220 |
|
221 for ( TInt fi = 0; fi < iFilteredMediaList.Count(); fi++ ) |
|
222 { |
|
223 ri = iFilteredMediaList[fi]; |
|
224 if ( ri < iMediaList->Count() ) |
|
225 { |
|
226 media = (*iMediaList)[ri]; |
|
227 |
|
228 if ( media->IsSupported( KMPXMediaGeneralTitle ) ) |
|
229 { |
|
230 if ( media->ValueText( KMPXMediaGeneralTitle ).FindF( aWord ) == KErrNotFound ) |
|
231 { |
|
232 iFilteredMediaList.Remove( fi ); |
|
233 fi--; |
|
234 } |
|
235 } |
|
236 } |
|
237 } |
|
238 } |
|
239 // If there is no filtering, or user removed letters, create a new filtering set. |
|
240 else |
|
241 { |
|
242 iFilteredMediaList.Reset(); |
|
243 |
|
244 for ( TInt ri = 0; ri < iMediaList->Count(); ri++ ) |
|
245 { |
|
246 media = (*iMediaList)[ri]; |
|
247 |
|
248 if ( media->IsSupported( KMPXMediaGeneralTitle ) ) |
|
249 { |
|
250 if ( media->ValueText( KMPXMediaGeneralTitle ).FindF( aWord ) != KErrNotFound ) |
|
251 { |
|
252 iFilteredMediaList.AppendL( ri ); |
|
253 } |
|
254 } |
|
255 } |
|
256 } |
|
257 |
|
258 delete iFilteringWord; |
|
259 iFilteringWord = NULL; |
|
260 iFilteringWord = aWord.AllocL(); |
|
261 } |