|
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: Model class for Events management UI start-up view. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Includes |
|
20 #include <e32keys.h> |
|
21 #include <barsread.h> // For TResourceReader |
|
22 #include <bautils.h> |
|
23 #include <StringLoader.h> |
|
24 #include <evtmgmtui.rsg> |
|
25 #include <eikenv.h> |
|
26 #include <AknUtils.h> |
|
27 |
|
28 // User Include |
|
29 #include "evtmgmtuimodel.h" |
|
30 #include "evtbasiceventinfo.h" |
|
31 #include "evtdebug.h" |
|
32 |
|
33 // Constants |
|
34 const TInt KPreDefinedItems = 1; |
|
35 const TInt KMaxConversionBufferLength = 0x200; |
|
36 |
|
37 // ========================= MEMBER FUNCTIONS ================================ |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CEvtMgmtUiStartupLBModel::CEvtMgmtUiStartupLBModel |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CEvtMgmtUiModel::CEvtMgmtUiModel() |
|
44 { |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CEvtMgmtUiModel::~CEvtMgmtUiModel |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CEvtMgmtUiModel::~CEvtMgmtUiModel() |
|
52 { |
|
53 // Delete the Buffers |
|
54 delete iBuffer; |
|
55 iBuffer = NULL; |
|
56 |
|
57 delete iCreateNew; |
|
58 iCreateNew = NULL; |
|
59 |
|
60 delete iUnnamed; |
|
61 iUnnamed = NULL; |
|
62 |
|
63 iEventsArray.ResetAndDestroy(); |
|
64 iEventsArray.Close(); |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CEvtMgmtUiModel* CEvtMgmtUiModel::NewL |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CEvtMgmtUiModel* CEvtMgmtUiModel::NewL() |
|
72 { |
|
73 CEvtMgmtUiModel* self = CEvtMgmtUiModel::NewLC(); |
|
74 CleanupStack::Pop( self ); |
|
75 return self; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CEvtMgmtUiModel* CEvtMgmtUiModel::NewLC |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 CEvtMgmtUiModel* CEvtMgmtUiModel::NewLC() |
|
83 { |
|
84 CEvtMgmtUiModel* self = new( ELeave )CEvtMgmtUiModel(); |
|
85 CleanupStack::PushL( self ); |
|
86 self->ConstructL(); |
|
87 return self; |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // void CEvtMgmtUiModel::ConstructL |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void CEvtMgmtUiModel::ConstructL() |
|
95 { |
|
96 EVTUIDEBUG( "+ CEvtMgmtUiModel::ConstructL()" ); |
|
97 |
|
98 // Allocate the Conversion Buffer |
|
99 iBuffer = HBufC16::NewL( KMaxConversionBufferLength ); |
|
100 |
|
101 // Open the Resource File |
|
102 // OpenLocalizedResourceFileL( KEvtEngineResFileName, iResourceLoader ); |
|
103 |
|
104 // Allocate and set the access point title |
|
105 iCreateNew = StringLoader::LoadL( R_EVTUI_CREATENEW_LIST ); |
|
106 iUnnamed = StringLoader::LoadL( R_EVTUI_UNNAMED ); |
|
107 |
|
108 iStatusFilter = CEvtMgmtUiEngine::EEvtFilterAll; |
|
109 |
|
110 EVTUIDEBUG( "- CEvtMgmtUiModel::ConstructL()" ); |
|
111 |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // TInt CEvtMgmtUiModel::MdcaCount() const |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 TInt CEvtMgmtUiModel::MdcaCount() const |
|
119 { |
|
120 // Return the Model count based on the Status Filter |
|
121 switch( iStatusFilter ) |
|
122 { |
|
123 case CEvtMgmtUiEngine::EEvtFilterAll: |
|
124 return KPreDefinedItems + iActiveTriggers + iDraftTriggers + iCompletedTriggers; |
|
125 case CEvtMgmtUiEngine::EEvtFilterActive: |
|
126 return KPreDefinedItems + iActiveTriggers; |
|
127 case CEvtMgmtUiEngine::EEvtFilterDraft: |
|
128 return KPreDefinedItems + iDraftTriggers; |
|
129 case CEvtMgmtUiEngine::EEvtFilterCompleted: |
|
130 return KPreDefinedItems + iCompletedTriggers; |
|
131 default: |
|
132 return KPreDefinedItems + iActiveTriggers + iDraftTriggers + iCompletedTriggers; |
|
133 } |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // TPtrC16 CEvtMgmtUiModel::MdcaPoint() const |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 TPtrC16 CEvtMgmtUiModel::MdcaPoint( TInt aIndex ) const |
|
141 { |
|
142 // Zero the internal buffer |
|
143 TPtr16 ptr( iBuffer->Des()); |
|
144 TPtrC subject(KNullDesC); |
|
145 TPtrC place(KNullDesC); |
|
146 ptr.Zero(); |
|
147 |
|
148 // Format "%d\t%S\t%S\t%d" |
|
149 |
|
150 // Append the Icon ID |
|
151 if( aIndex==0 ) |
|
152 ptr.AppendNum( 1 ); |
|
153 else |
|
154 { |
|
155 // Get the Index based on the Status Filter |
|
156 aIndex = IndexBasedOnFilter( aIndex ); |
|
157 switch(iEventsArray[aIndex-1]->EventStatus()) |
|
158 { |
|
159 case EActive: |
|
160 { |
|
161 ptr.AppendNum( 2 ); |
|
162 break; |
|
163 } |
|
164 case EDraft: |
|
165 { |
|
166 ptr.AppendNum( 3 ); |
|
167 break; |
|
168 } |
|
169 case ECompleted: |
|
170 { |
|
171 ptr.AppendNum( 4 ); |
|
172 break; |
|
173 } |
|
174 } |
|
175 } |
|
176 |
|
177 // Append the first tab |
|
178 ptr.Append( EKeyTab ); |
|
179 |
|
180 // Subject |
|
181 if(aIndex==0) |
|
182 { |
|
183 ptr.Append( *iCreateNew ); |
|
184 ptr.Append( EKeyTab ); |
|
185 ptr.Append( EKeyTab ); |
|
186 } |
|
187 else |
|
188 { |
|
189 subject.Set(iEventsArray[aIndex-1]->Subject()); |
|
190 place.Set(iEventsArray[aIndex-1]->Place()); |
|
191 if(subject.Compare(KNullDesC)==0 && place.Compare(KNullDesC)==0) |
|
192 { |
|
193 ptr.Append(*iUnnamed); |
|
194 } |
|
195 else |
|
196 ptr.Append(subject); |
|
197 |
|
198 //Place |
|
199 ptr.Append( EKeyTab ); |
|
200 |
|
201 { |
|
202 HBufC* localPlace = place.Alloc(); |
|
203 if( localPlace ) |
|
204 { |
|
205 TPtr placePtr = localPlace->Des(); |
|
206 ptr.Append(placePtr); |
|
207 delete localPlace; |
|
208 } |
|
209 } |
|
210 ptr.Append( EKeyTab ); |
|
211 if( iEventsArray[aIndex-1]->Repeat() ) |
|
212 ptr.AppendNum(5); |
|
213 } |
|
214 |
|
215 return *iBuffer; |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------------------------- |
|
219 // TInt CEvtMgmtUiModel::IndexBasedOnFilter() const |
|
220 // --------------------------------------------------------------------------- |
|
221 // |
|
222 TInt CEvtMgmtUiModel::IndexBasedOnFilter( TInt aIndex ) const |
|
223 { |
|
224 // We calculate the Index based on the Status Filter |
|
225 // This is calculated based on the assumption of the Order of the Events |
|
226 // which is in the order of Active->Draft->Completed |
|
227 switch( iStatusFilter ) |
|
228 { |
|
229 case CEvtMgmtUiEngine::EEvtFilterAll: |
|
230 case CEvtMgmtUiEngine::EEvtFilterActive: |
|
231 return aIndex; |
|
232 case CEvtMgmtUiEngine::EEvtFilterDraft: |
|
233 return iActiveTriggers + aIndex; |
|
234 case CEvtMgmtUiEngine::EEvtFilterCompleted: |
|
235 return iActiveTriggers + iDraftTriggers + aIndex; |
|
236 default: |
|
237 return aIndex; |
|
238 } |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // CEvtMgmtUiModel::IndexWithoutFilter() |
|
243 // It will Index without filter provided the index based on filter. |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 TInt CEvtMgmtUiModel::IndexWithoutFilter( TInt aIndex ) const |
|
247 { |
|
248 // The Actual Index in the model is calculated based on the Status Filter |
|
249 switch( iStatusFilter ) |
|
250 { |
|
251 case CEvtMgmtUiEngine::EEvtFilterAll: |
|
252 case CEvtMgmtUiEngine::EEvtFilterActive: |
|
253 return KPreDefinedItems + aIndex; |
|
254 case CEvtMgmtUiEngine::EEvtFilterDraft: |
|
255 return KPreDefinedItems + aIndex - iActiveTriggers; |
|
256 case CEvtMgmtUiEngine::EEvtFilterCompleted: |
|
257 return KPreDefinedItems + aIndex - ( iActiveTriggers + iDraftTriggers ); |
|
258 default: |
|
259 return KPreDefinedItems + aIndex; |
|
260 } |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // CEvtMgmtUiModel::EventsArray() |
|
265 // It will return Events array object reference. |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 RPointerArray<CEvtBasicEventInfo>& CEvtMgmtUiModel::EventsArray() |
|
269 { |
|
270 return iEventsArray; |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // CEvtMgmtUiModel::TotalEvents() |
|
275 // It will return total events |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 TInt CEvtMgmtUiModel::TotalEvents() |
|
279 { |
|
280 return iEventsArray.Count(); |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // CEvtMgmtUiModel::StatusFilter() |
|
285 // It will Show Events based on Filter |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 CEvtMgmtUiEngine::TEvtEventStatusFilter CEvtMgmtUiModel::StatusFilter( ) |
|
289 { |
|
290 return iStatusFilter; |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // CEvtMgmtUiModel::SetStatusFilter() |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 void CEvtMgmtUiModel::SetStatusFilter( CEvtMgmtUiEngine::TEvtEventStatusFilter |
|
298 aFilter ) |
|
299 { |
|
300 iStatusFilter = aFilter; |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // CEvtMgmtUiModel::EventFromModel() |
|
305 // It will return eventinfo object. |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 CEvtBasicEventInfo& CEvtMgmtUiModel::EventFromModel( TInt aIndex ) |
|
309 { |
|
310 return *(iEventsArray[IndexBasedOnFilter( aIndex )-1]); |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // CEvtMgmtUiModel::MandatoryFieldsFilled() |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 TBool CEvtMgmtUiModel::MandatoryFieldsFilled( TInt aIndex ) |
|
318 { |
|
319 // Check the Array boundary conditions |
|
320 if( aIndex == 0 || aIndex > iEventsArray.Count()) |
|
321 return EFalse; |
|
322 |
|
323 // Check the Status of the event considering the current Status Filter |
|
324 if( iEventsArray[IndexBasedOnFilter( aIndex )-1]->Subject().Compare(KNullDesC)==0 || |
|
325 iEventsArray[IndexBasedOnFilter( aIndex )-1]->Place().Compare(KNullDesC)==0 ) |
|
326 return EFalse; |
|
327 else |
|
328 return ETrue; |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------------------------- |
|
332 // CEvtMgmtUiModel::EventId() |
|
333 // It will return event id. |
|
334 // --------------------------------------------------------------------------- |
|
335 // |
|
336 TEvtEventId CEvtMgmtUiModel::EventId( TInt aIndex ) |
|
337 { |
|
338 // Check the Array boundary conditions |
|
339 if(aIndex<1 || aIndex > iEventsArray.Count() ) |
|
340 return 0; |
|
341 return iEventsArray[IndexBasedOnFilter( aIndex )-1]->EventId(); |
|
342 } |
|
343 |
|
344 // --------------------------------------------------------------------------- |
|
345 // CEvtMgmtUiModel::EventStatus() |
|
346 // It will return event status. |
|
347 // --------------------------------------------------------------------------- |
|
348 // |
|
349 TEvtEventStatus CEvtMgmtUiModel::EventStatus( TInt aIndex ) |
|
350 { |
|
351 // Check the Array boundary conditions |
|
352 if(aIndex<1 || aIndex > iEventsArray.Count() ) |
|
353 return EActive; |
|
354 return iEventsArray[IndexBasedOnFilter( aIndex )-1]->EventStatus(); |
|
355 } |
|
356 |
|
357 // --------------------------------------------------------------------------- |
|
358 // CEvtMgmtUiModel::UpdatedCurrentItemIndex() |
|
359 // It will return updated current item index |
|
360 // --------------------------------------------------------------------------- |
|
361 // |
|
362 TInt CEvtMgmtUiModel::UpdatedCurrentItemIndex( ) |
|
363 { |
|
364 switch( iStatusFilter ) |
|
365 { |
|
366 case CEvtMgmtUiEngine::EEvtFilterAll: |
|
367 if(iCurrentEventIndex<0 || iCurrentEventIndex > (iActiveTriggers+iDraftTriggers+iCompletedTriggers) ) |
|
368 iCurrentEventIndex = KPreDefinedItems + iActiveTriggers + iDraftTriggers + iCompletedTriggers; |
|
369 break; |
|
370 case CEvtMgmtUiEngine::EEvtFilterActive: |
|
371 if(iCurrentEventIndex<0 || iCurrentEventIndex > iActiveTriggers ) |
|
372 iCurrentEventIndex = KPreDefinedItems + iActiveTriggers; |
|
373 break; |
|
374 case CEvtMgmtUiEngine::EEvtFilterDraft: |
|
375 if(iCurrentEventIndex<0 || iCurrentEventIndex > iDraftTriggers ) |
|
376 iCurrentEventIndex = KPreDefinedItems + iDraftTriggers; |
|
377 break; |
|
378 case CEvtMgmtUiEngine::EEvtFilterCompleted: |
|
379 if(iCurrentEventIndex<0 || iCurrentEventIndex > iCompletedTriggers ) |
|
380 iCurrentEventIndex = KPreDefinedItems + iCompletedTriggers; |
|
381 break; |
|
382 default: |
|
383 iCurrentEventIndex = 0; |
|
384 break; |
|
385 } |
|
386 return iCurrentEventIndex; |
|
387 } |
|
388 |
|
389 // --------------------------------------------------------------------------- |
|
390 // CEvtMgmtUiModel::SetCurrentItemId() |
|
391 // --------------------------------------------------------------------------- |
|
392 // |
|
393 void CEvtMgmtUiModel::SetCurrentItemId( TInt aItemIndex ) |
|
394 { |
|
395 if(aItemIndex > 0 && aItemIndex <= iEventsArray.Count() ) |
|
396 { |
|
397 iCurrentEventId = iEventsArray[IndexBasedOnFilter( aItemIndex )-1]->EventId(); |
|
398 iCurrentEventIndex = aItemIndex - 1; |
|
399 } |
|
400 else |
|
401 { |
|
402 iCurrentEventId = 0; //if focus is on 'create new event' |
|
403 iCurrentEventIndex = 0; |
|
404 } |
|
405 } |
|
406 |
|
407 // --------------------------------------------------------------------------- |
|
408 // CEvtMgmtUiModel::UpdateEventsStatus() |
|
409 // --------------------------------------------------------------------------- |
|
410 // |
|
411 void CEvtMgmtUiModel::UpdateEventsStatus() |
|
412 { |
|
413 // Maintain the previous count to compare with the updated model |
|
414 TInt prevCount = iActiveTriggers + iDraftTriggers + iCompletedTriggers; |
|
415 iActiveTriggers = 0; |
|
416 iDraftTriggers = 0; |
|
417 iCompletedTriggers = 0; |
|
418 TInt cnt = iEventsArray.Count(); |
|
419 TEvtModelUpdateState updateState; |
|
420 |
|
421 // Get the update type based on the previous and current model count. |
|
422 if( prevCount < cnt ) |
|
423 { |
|
424 updateState = EEvtCreate; |
|
425 } |
|
426 else if( prevCount > cnt ) |
|
427 { |
|
428 updateState = EEvtDelete; |
|
429 iCurrentEventId = 0; |
|
430 } |
|
431 else |
|
432 { |
|
433 updateState = EEvtModify; |
|
434 } |
|
435 |
|
436 // Loop through the model to update the Event Status mask. |
|
437 TInt index; |
|
438 iEventsStatusMask = 0; |
|
439 for( index = 0; index<cnt; index++ ) |
|
440 { |
|
441 |
|
442 if( updateState == EEvtCreate && iCurrentEventId < iEventsArray[index]->EventId() ) |
|
443 { |
|
444 iCurrentEventId = iEventsArray[index]->EventId(); |
|
445 iCurrentEventIndex = index; |
|
446 } |
|
447 |
|
448 if( updateState == EEvtModify && iCurrentEventId == iEventsArray[index]->EventId() ) |
|
449 { |
|
450 iCurrentEventId = iEventsArray[index]->EventId(); |
|
451 iCurrentEventIndex = index; |
|
452 } |
|
453 |
|
454 // Append the Event status to Event status mask. |
|
455 switch(iEventsArray[index]->EventStatus()) |
|
456 { |
|
457 case EActive: |
|
458 { |
|
459 iActiveTriggers++; |
|
460 iEventsStatusMask|= EEvtShowAttributeActive; |
|
461 break; |
|
462 } |
|
463 case EDraft: |
|
464 { |
|
465 iDraftTriggers++; |
|
466 iEventsStatusMask|= EEvtShowAttributeDraft; |
|
467 break; |
|
468 } |
|
469 case ECompleted: |
|
470 { |
|
471 iCompletedTriggers++; |
|
472 iEventsStatusMask|= EEvtShowAttributeCompleted; |
|
473 break; |
|
474 } |
|
475 } |
|
476 } |
|
477 |
|
478 // If the current view(show) is empty, then switch to Filter All View |
|
479 switch(iStatusFilter) |
|
480 { |
|
481 case CEvtMgmtUiEngine::EEvtFilterActive: |
|
482 { |
|
483 if( !iActiveTriggers ) |
|
484 iStatusFilter = CEvtMgmtUiEngine::EEvtFilterAll; |
|
485 break; |
|
486 } |
|
487 case CEvtMgmtUiEngine::EEvtFilterDraft: |
|
488 { |
|
489 if( !iDraftTriggers ) |
|
490 iStatusFilter = CEvtMgmtUiEngine::EEvtFilterAll; |
|
491 break; |
|
492 } |
|
493 case CEvtMgmtUiEngine::EEvtFilterCompleted: |
|
494 { |
|
495 if( !iCompletedTriggers ) |
|
496 iStatusFilter = CEvtMgmtUiEngine::EEvtFilterAll; |
|
497 break; |
|
498 } |
|
499 } |
|
500 |
|
501 // Update the index for create and modify |
|
502 if( updateState == EEvtCreate || updateState == EEvtModify ) |
|
503 iCurrentEventIndex = IndexWithoutFilter( iCurrentEventIndex ); |
|
504 } |
|
505 |
|
506 // --------------------------------------------------------------------------- |
|
507 // CEvtMgmtUiModel::EventsStatus() |
|
508 // It will return type of events |
|
509 // --------------------------------------------------------------------------- |
|
510 // |
|
511 TEvtEventsStatusMask CEvtMgmtUiModel::EventsStatus() |
|
512 { |
|
513 return iEventsStatusMask; |
|
514 } |