1 /* |
|
2 * Copyright (c) 2002-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: Group item definitions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CGflmGroupItem.h" |
|
22 #include "MGflmItemGroup.h" |
|
23 #include <e32std.h> |
|
24 |
|
25 |
|
26 // CONSTANTS |
|
27 const TInt KIconIdUndefined = -1; |
|
28 const TInt KSortCollationLevel = 3; |
|
29 |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CGflmGroupItem::CGflmGroupItem |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CGflmGroupItem::CGflmGroupItem() |
|
40 : iIconId( KIconIdUndefined ) |
|
41 { |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CGflmGroupItem::~CGflmGroupItem() |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CGflmGroupItem::~CGflmGroupItem() |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CGflmGroupItem::GetIconId() |
|
54 // (other items were commented in a header). |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 EXPORT_C TInt CGflmGroupItem::GetIconId( TInt& aIconId ) |
|
58 { |
|
59 if ( iIconId == KIconIdUndefined ) |
|
60 { |
|
61 aIconId = 0; |
|
62 return KErrNotFound; |
|
63 } |
|
64 aIconId = iIconId; |
|
65 return KErrNone; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CGflmGroupItem::SetIconId() |
|
70 // (other items were commented in a header). |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 EXPORT_C void CGflmGroupItem::SetIconId( const TInt aIconId ) |
|
74 { |
|
75 iIconId = aIconId; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CGflmGroupItem::CanUseCompareF() |
|
80 // (other items were commented in a header). |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 TBool CGflmGroupItem::CanUseCompareF() const |
|
84 { |
|
85 if ( iStatus & ECanUseCompareF ) |
|
86 { |
|
87 return ETrue; |
|
88 } |
|
89 if ( iStatus & ECannotUseCompareF ) |
|
90 { |
|
91 return EFalse; |
|
92 } |
|
93 |
|
94 TPtrC name( Name() ); |
|
95 TInt len( name.Length() ); |
|
96 const TText* ptr = name.Ptr(); |
|
97 while ( len-- > 0 ) |
|
98 { |
|
99 TText ch = *ptr++; |
|
100 // Do not allow CompareF for non Ascii or special chars |
|
101 if ( !( ( ch >= 0x000A && ch <= 0x0039 ) || // Ascii basic symbols |
|
102 ( ch >= 0x0041 && ch <= 0x005A ) || // Ascii capital alpha |
|
103 ( ch >= 0x0061 && ch <= 0x007A ) ) ) // Ascii small alpha |
|
104 { |
|
105 iStatus |= ECannotUseCompareF; |
|
106 return EFalse; |
|
107 } |
|
108 } |
|
109 iStatus |= ECanUseCompareF; |
|
110 return ETrue; |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CGflmGroupItem::SetGroup() |
|
115 // (other items were commented in a header). |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CGflmGroupItem::SetGroup( MGflmItemGroup* aGroup ) |
|
119 { |
|
120 iGroup = aGroup; |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CGflmGroupItem::GetSortL() |
|
125 // (other items were commented in a header). |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 |
|
129 TLinearOrder< CGflmGroupItem > CGflmGroupItem::GetSortL( |
|
130 TGflmSortMethod aSortMethod ) |
|
131 { |
|
132 switch( aSortMethod ) |
|
133 { |
|
134 case EByName: |
|
135 { |
|
136 return CompareByName; |
|
137 } |
|
138 case EByType: |
|
139 { |
|
140 return CompareByType; |
|
141 } |
|
142 case EMostRecentFirst: |
|
143 { |
|
144 return CompareMostRecentFirst; |
|
145 } |
|
146 case ELargestFirst: |
|
147 { |
|
148 return CompareLargestFirst; |
|
149 } |
|
150 default: |
|
151 { |
|
152 User::Leave( KErrNotSupported ); |
|
153 } |
|
154 } |
|
155 return CompareByName; |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CGflmGroupItem::CompareByItemType |
|
160 // Compares two CGflmGroupItem objects by name (ascending) |
|
161 // (other items were commented in a header). |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 TInt CGflmGroupItem::CompareByItemType( |
|
165 const CGflmGroupItem& aFirst, const CGflmGroupItem& aSecond ) |
|
166 { |
|
167 TGflmItemType first( aFirst.Type() ); |
|
168 TGflmItemType second( aSecond.Type() ); |
|
169 if ( first < second ) |
|
170 { |
|
171 return -1; |
|
172 } |
|
173 else if ( first > second ) |
|
174 { |
|
175 return 1; |
|
176 } |
|
177 return 0; |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CGflmGroupItem::CompareByNameWithoutItemType |
|
182 // Compares two CGflmGroupItem objects by name (ascending) |
|
183 // (other items were commented in a header). |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 TInt CGflmGroupItem::CompareByNameWithoutItemType( |
|
187 const CGflmGroupItem& aFirst, const CGflmGroupItem& aSecond ) |
|
188 { |
|
189 // Do not use CompareC by default with collation |
|
190 // because it is very bad for performance when sorting |
|
191 // large folders i.e. several 1000s of files with long item names |
|
192 // e.g. names containing over 40 chars |
|
193 |
|
194 // However, some languages are not sorted correctly with CompareF, |
|
195 // so do cached name check to decide what comparison to use. |
|
196 |
|
197 if ( !aFirst.CanUseCompareF() || !aSecond.CanUseCompareF() ) |
|
198 { |
|
199 if ( aFirst.iGroup ) |
|
200 { |
|
201 const TCollationMethod* collate = |
|
202 aFirst.iGroup->CollationMethod(); |
|
203 if ( collate ) |
|
204 { |
|
205 return aFirst.Name().CompareC( |
|
206 aSecond.Name(), |
|
207 KSortCollationLevel, |
|
208 collate ); |
|
209 } |
|
210 } |
|
211 } |
|
212 |
|
213 return aFirst.Name().CompareF( aSecond.Name() ); |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // CGflmGroupItem::CompareByName |
|
218 // Compares two CGflmGroupItem objects by name (ascending) |
|
219 // (other items were commented in a header). |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 TInt CGflmGroupItem::CompareByName( |
|
223 const CGflmGroupItem& aFirst, const CGflmGroupItem& aSecond ) |
|
224 { |
|
225 TInt ret( CompareByItemType( aFirst, aSecond ) ); |
|
226 if ( !ret ) |
|
227 { |
|
228 return CompareByNameWithoutItemType( aFirst, aSecond ); |
|
229 } |
|
230 return ret; |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CGflmGroupItem::CompareByType |
|
235 // Compares two CGflmGroupItem objects by file extension (ascending) |
|
236 // (other items were commented in a header). |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 TInt CGflmGroupItem::CompareByType( |
|
240 const CGflmGroupItem& aFirst, const CGflmGroupItem& aSecond ) |
|
241 { |
|
242 TInt ret( CompareByItemType( aFirst, aSecond ) ); |
|
243 if ( ret ) |
|
244 { |
|
245 return ret; |
|
246 } |
|
247 |
|
248 // Do not use CompareC by default with collation |
|
249 // because it is very bad for performance when sorting |
|
250 // large folders i.e. several 1000s of files with long item names |
|
251 // e.g. names containing over 40 chars |
|
252 |
|
253 // However, some languages are not sorted correctly with CompareF, |
|
254 // so do cached name check to decide what comparison to use. |
|
255 |
|
256 if ( !aFirst.CanUseCompareF() || !aSecond.CanUseCompareF() ) |
|
257 { |
|
258 if ( aFirst.iGroup ) |
|
259 { |
|
260 const TCollationMethod* collate = |
|
261 aFirst.iGroup->CollationMethod(); |
|
262 if ( collate ) |
|
263 { |
|
264 ret = aFirst.Ext().CompareC( |
|
265 aSecond.Ext(), |
|
266 KSortCollationLevel, |
|
267 collate ); |
|
268 if ( !ret ) |
|
269 { |
|
270 ret = CompareByName( aFirst, aSecond ); |
|
271 } |
|
272 return ret; |
|
273 } |
|
274 } |
|
275 } |
|
276 |
|
277 ret = aFirst.Ext().CompareF( aSecond.Ext() ); |
|
278 if ( !ret ) |
|
279 { |
|
280 ret = CompareByNameWithoutItemType( aFirst, aSecond ); |
|
281 } |
|
282 return ret; |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CGflmGroupItem::CompareMostRecentFirst |
|
287 // Compares two CGflmGroupItem objects by date (ascending) |
|
288 // (other items were commented in a header). |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 TInt CGflmGroupItem::CompareMostRecentFirst( |
|
292 const CGflmGroupItem& aFirst, const CGflmGroupItem& aSecond ) |
|
293 { |
|
294 TInt ret( -CompareByItemType( aFirst, aSecond ) ); |
|
295 if ( ret ) |
|
296 { |
|
297 return ret; |
|
298 } |
|
299 |
|
300 TTime first( aFirst.Date() ); |
|
301 TTime second( aSecond.Date() ); |
|
302 |
|
303 if ( first > second ) |
|
304 { |
|
305 return -1; |
|
306 } |
|
307 else if ( first < second ) |
|
308 { |
|
309 return 1; |
|
310 } |
|
311 return CompareByNameWithoutItemType( aFirst, aSecond ); |
|
312 } |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // CGflmGroupItem::CompareLargestFirst |
|
316 // Compares two CGflmGroupItem objects by size (ascending) |
|
317 // (other items were commented in a header). |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 TInt CGflmGroupItem::CompareLargestFirst( |
|
321 const CGflmGroupItem& aFirst, const CGflmGroupItem& aSecond ) |
|
322 { |
|
323 TInt ret( -CompareByItemType( aFirst, aSecond ) ); |
|
324 if ( ret ) |
|
325 { |
|
326 return ret; |
|
327 } |
|
328 |
|
329 TInt64 first( aFirst.Size() ); |
|
330 TInt64 second( aSecond.Size() ); |
|
331 |
|
332 if ( first > second ) |
|
333 { |
|
334 return -1; |
|
335 } |
|
336 else if ( first < second ) |
|
337 { |
|
338 return 1; |
|
339 } |
|
340 return CompareByNameWithoutItemType( aFirst, aSecond ); |
|
341 } |
|
342 |
|
343 // End of File |
|