|
1 /* |
|
2 * Copyright (c) 2005-2006 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "aicalendarplugin2data.h" |
|
19 #include "aicalendarplugin2contentmodel.h" |
|
20 #include "aicalendarplugin2constants.hrh" |
|
21 #include <aicontentmodel.h> |
|
22 #include <aipropertyextension.h> |
|
23 #include <e32cmn.h> |
|
24 |
|
25 // Helper for sort method |
|
26 TInt TimeDetermination( const CAiCalendarPlugin2EventItem& aOne, |
|
27 const CAiCalendarPlugin2EventItem& aTwo ) |
|
28 { |
|
29 if( aOne.Time() == aTwo.Time() ) |
|
30 { |
|
31 TTime time_1 = aOne.LastModifiedTime(); |
|
32 TTime time_2 = aTwo.LastModifiedTime(); |
|
33 if( time_1 == time_2 ) |
|
34 { |
|
35 return 0; |
|
36 } |
|
37 else if( time_1 > time_2 ) |
|
38 { |
|
39 return 1; // oldest first |
|
40 } |
|
41 else |
|
42 { |
|
43 return -1; |
|
44 } |
|
45 } |
|
46 else if( aOne.Time() < aTwo.Time() ) |
|
47 { |
|
48 return -1; |
|
49 } |
|
50 return 1; |
|
51 } |
|
52 |
|
53 TInt TypeDetermination( const CAiCalendarPlugin2EventItem& aOne, |
|
54 const CAiCalendarPlugin2EventItem& aTwo ) |
|
55 { |
|
56 TBool oneIsMeeting = EFalse; |
|
57 TBool twoIsMeeting = EFalse; |
|
58 if( ( ( aOne.Type() == EPluginItemMeeting ) || |
|
59 ( aOne.Type() == EPluginItemUpcomingMeeting ) || |
|
60 ( aOne.Type() == EPluginItemOnGoingEvent ) || |
|
61 ( aOne.Type() == EPluginItemOlderOnGoingEvent ) ) ) |
|
62 { |
|
63 oneIsMeeting = ETrue; |
|
64 } |
|
65 if( ( aTwo.Type() == EPluginItemMeeting ) || |
|
66 ( aTwo.Type() == EPluginItemUpcomingMeeting ) || |
|
67 ( aTwo.Type() == EPluginItemOnGoingEvent ) || |
|
68 ( aTwo.Type() == EPluginItemOlderOnGoingEvent ) ) |
|
69 { |
|
70 twoIsMeeting = ETrue; |
|
71 } |
|
72 |
|
73 if( oneIsMeeting || twoIsMeeting ) |
|
74 { |
|
75 // Meetings always overrule non timed |
|
76 return( ( oneIsMeeting == twoIsMeeting ) ? ( 0 ) : ( oneIsMeeting * -1 + twoIsMeeting ) ); |
|
77 } |
|
78 else |
|
79 { |
|
80 // Both are non timed |
|
81 if( aOne.Type() == aTwo.Type() ) |
|
82 { |
|
83 return 0; |
|
84 } |
|
85 else if( aOne.Type() == EPluginItemToDo ) |
|
86 { |
|
87 return -1; |
|
88 } |
|
89 else if( aTwo.Type() == EPluginItemToDo ) |
|
90 { |
|
91 return 1; |
|
92 } |
|
93 else if( aOne.Type() == EPluginItemDayNote ) |
|
94 { |
|
95 return -1; |
|
96 } |
|
97 else if( aTwo.Type() == EPluginItemDayNote ) |
|
98 { |
|
99 return 1; |
|
100 } |
|
101 } |
|
102 // Should never happed... |
|
103 return 0; |
|
104 } |
|
105 |
|
106 // Sort method |
|
107 TInt CompareEventItems( const CAiCalendarPlugin2EventItem& aOne, |
|
108 const CAiCalendarPlugin2EventItem& aTwo ) |
|
109 { |
|
110 if( aOne.Type() != aTwo.Type() ) |
|
111 { |
|
112 if( aOne.OnSameDay( aOne.Time(), aTwo.Time() ) ) |
|
113 { |
|
114 // Different types, same day |
|
115 TInt typeDetermination = TypeDetermination( aOne, aTwo ); |
|
116 if( typeDetermination != 0 ) |
|
117 { |
|
118 return typeDetermination; |
|
119 } |
|
120 } |
|
121 } |
|
122 // Same types or different types different day or both meetings(not same category) |
|
123 return TimeDetermination( aOne, aTwo ); |
|
124 } |
|
125 |
|
126 // ============================ MEMBER FUNCTIONS =============================== |
|
127 |
|
128 CAICalendarPlugin2Data* CAICalendarPlugin2Data::NewL() |
|
129 { |
|
130 CAICalendarPlugin2Data* self = new( ELeave )CAICalendarPlugin2Data; |
|
131 CleanupStack::PushL( self ); |
|
132 self->ConstructL(); |
|
133 CleanupStack::Pop( self ); |
|
134 return self; |
|
135 } |
|
136 |
|
137 CAICalendarPlugin2Data::CAICalendarPlugin2Data() |
|
138 : iSpaceTakenByTimedEvent( 1 ), |
|
139 iSpaceTakenByNonTimedEvent( 1 ), |
|
140 iHadExpiredEvents( EFalse ) |
|
141 { |
|
142 } |
|
143 |
|
144 void CAICalendarPlugin2Data::ConstructL() |
|
145 { |
|
146 } |
|
147 |
|
148 CAICalendarPlugin2Data::~CAICalendarPlugin2Data() |
|
149 { |
|
150 ClearDataArrays(); |
|
151 |
|
152 iUpcoming2HrsItemData.Close(); |
|
153 iUpcomingItemData.Close(); |
|
154 iOngoing30MinItemData.Close(); |
|
155 iOngoingItemData.Close(); |
|
156 iNonTimedItemData.Close(); |
|
157 iTomorrowItemData.Close(); |
|
158 iNotTodayItemData.Close(); |
|
159 iFutureItemData.Close(); |
|
160 iLongOngoingItemData.Close(); |
|
161 |
|
162 iEventFocusData.Reset(); |
|
163 iEventFocusData.Close(); |
|
164 |
|
165 iObservers.Reset(); |
|
166 iObservers.Close(); |
|
167 } |
|
168 |
|
169 void CAICalendarPlugin2Data::ClearDataArrays() |
|
170 { |
|
171 // cleanup |
|
172 iUpcoming2HrsItemData.ResetAndDestroy(); |
|
173 iUpcomingItemData.ResetAndDestroy(); |
|
174 iOngoing30MinItemData.ResetAndDestroy(); |
|
175 iOngoingItemData.ResetAndDestroy(); |
|
176 iNonTimedItemData.ResetAndDestroy(); |
|
177 iTomorrowItemData.ResetAndDestroy(); |
|
178 iNotTodayItemData.ResetAndDestroy(); |
|
179 iFutureItemData.ResetAndDestroy(); |
|
180 iLongOngoingItemData.ResetAndDestroy(); |
|
181 } |
|
182 |
|
183 RPointerArray<CAiCalendarPlugin2EventItem>& CAICalendarPlugin2Data::Upcoming2HrsArray() |
|
184 { |
|
185 return iUpcoming2HrsItemData; |
|
186 } |
|
187 |
|
188 RPointerArray<CAiCalendarPlugin2EventItem>& CAICalendarPlugin2Data::UpcomingArray() |
|
189 { |
|
190 return iUpcomingItemData; |
|
191 } |
|
192 |
|
193 RPointerArray<CAiCalendarPlugin2EventItem>& CAICalendarPlugin2Data::Ongoing30MinArray() |
|
194 { |
|
195 return iOngoing30MinItemData; |
|
196 } |
|
197 |
|
198 RPointerArray<CAiCalendarPlugin2EventItem>& CAICalendarPlugin2Data::OngoingArray() |
|
199 { |
|
200 return iOngoingItemData; |
|
201 } |
|
202 |
|
203 RPointerArray<CAiCalendarPlugin2EventItem>& CAICalendarPlugin2Data::NonTimedEventArray() |
|
204 { |
|
205 return iNonTimedItemData; |
|
206 } |
|
207 |
|
208 RPointerArray<CAiCalendarPlugin2EventItem>& CAICalendarPlugin2Data::TomorrowEventArray() |
|
209 { |
|
210 return iTomorrowItemData; |
|
211 } |
|
212 |
|
213 RPointerArray<CAiCalendarPlugin2EventItem>& CAICalendarPlugin2Data::NotTodayItemArray() |
|
214 { |
|
215 return iNotTodayItemData; |
|
216 } |
|
217 |
|
218 RPointerArray<CAiCalendarPlugin2EventItem>& CAICalendarPlugin2Data::FutureItemArray() |
|
219 { |
|
220 return iFutureItemData; |
|
221 } |
|
222 |
|
223 RPointerArray<CAiCalendarPlugin2EventItem>& CAICalendarPlugin2Data::LongOngoingArray() |
|
224 { |
|
225 return iLongOngoingItemData; |
|
226 } |
|
227 |
|
228 TInt CAICalendarPlugin2Data::AppendItemToCorrectArray( CAiCalendarPlugin2EventItem& aItem, |
|
229 TInt& aDayNoteIndex ) |
|
230 { |
|
231 TInt err; |
|
232 if( aItem.IsTomorrow() && aItem.IsFutureEvent() ) |
|
233 { |
|
234 err = iTomorrowItemData.Append( &aItem ); |
|
235 return err; |
|
236 } |
|
237 else if( !aItem.IsToday() && !aItem.IsFutureEvent() && |
|
238 aItem.Type() == EPluginItemOlderOnGoingEvent ) |
|
239 { |
|
240 err = iLongOngoingItemData.Append( &aItem ); |
|
241 return err; |
|
242 } |
|
243 else if( !aItem.IsToday() && aItem.IsNotTodayEvent() && |
|
244 !aItem.IsFutureEvent() && |
|
245 ( aItem.Type() == EPluginItemDayNote || |
|
246 aItem.Type() == EPluginItemToDo || |
|
247 aItem.Type() == EPluginItemAnniv ) ) |
|
248 { |
|
249 if( aItem.Type() == EPluginItemDayNote || |
|
250 aItem.Type() == EPluginItemToDo ) |
|
251 { |
|
252 // insert...just to make sure day notes are always first |
|
253 err = iNonTimedItemData.Insert( &aItem, aDayNoteIndex++ ); |
|
254 } |
|
255 else |
|
256 { |
|
257 // append...just to make sure day notes are always first |
|
258 err = iNonTimedItemData.Append( &aItem ); |
|
259 } |
|
260 return err; |
|
261 } |
|
262 else if( !aItem.IsToday() && aItem.IsNotTodayEvent() ) |
|
263 { |
|
264 err = iNotTodayItemData.Append( &aItem ); |
|
265 return err; |
|
266 } |
|
267 else if( !aItem.IsToday() && aItem.IsFutureEvent() ) |
|
268 { |
|
269 err = iFutureItemData.Append( &aItem ); |
|
270 return err; |
|
271 } |
|
272 switch( aItem.Type() ) |
|
273 { |
|
274 case EPluginItemMeeting: |
|
275 { |
|
276 // Meetings starting within 2 hrs |
|
277 err = iUpcoming2HrsItemData.Append( &aItem ); |
|
278 break; |
|
279 } |
|
280 case EPluginItemUpcomingMeeting: |
|
281 { |
|
282 // Meetings starting more than 2 hrs current time |
|
283 err = iUpcomingItemData.Append( &aItem ); |
|
284 break; |
|
285 } |
|
286 case EPluginItemOnGoingEvent: |
|
287 { |
|
288 // Meetings that have started with 30 mon before current time |
|
289 // and are still on going. |
|
290 err = iOngoing30MinItemData.Append( &aItem ); |
|
291 break; |
|
292 } |
|
293 case EPluginItemOlderOnGoingEvent: |
|
294 { |
|
295 // Meetings that have started more that 30 minutes ago and |
|
296 // are still ongoing |
|
297 err = iOngoingItemData.Append( &aItem ); |
|
298 break; |
|
299 } |
|
300 case EPluginItemDayNote: // fallthrough |
|
301 case EPluginItemToDo: |
|
302 { |
|
303 // insert...just to make sure day notes are always first |
|
304 err = iNonTimedItemData.Insert( &aItem, aDayNoteIndex++ ); |
|
305 break; |
|
306 } |
|
307 case EPluginItemAnniv: |
|
308 { |
|
309 // append...just to make sure day notes are always first |
|
310 err = iNonTimedItemData.Append( &aItem ); |
|
311 break; |
|
312 } |
|
313 default: |
|
314 { |
|
315 err = KErrNotSupported; |
|
316 break; |
|
317 } |
|
318 } |
|
319 return err; |
|
320 } |
|
321 |
|
322 void CAICalendarPlugin2Data::SortArrayByTime( RPointerArray<CAiCalendarPlugin2EventItem>& aArray ) |
|
323 { |
|
324 // Sort |
|
325 aArray.Sort( TLinearOrder<CAiCalendarPlugin2EventItem>( CompareEventItems ) ); |
|
326 } |
|
327 |
|
328 TInt CAICalendarPlugin2Data::TotalTimedTodaySpaceReservation() |
|
329 { |
|
330 return |
|
331 ( iUpcoming2HrsItemData.Count() * iSpaceTakenByTimedEvent ) + |
|
332 ( iUpcomingItemData.Count() * iSpaceTakenByTimedEvent ) + |
|
333 ( iOngoing30MinItemData.Count() * iSpaceTakenByTimedEvent ) + |
|
334 ( iOngoingItemData.Count() * iSpaceTakenByTimedEvent ); |
|
335 } |
|
336 |
|
337 TInt CAICalendarPlugin2Data::TotalTodayItemCount() |
|
338 { |
|
339 return |
|
340 ( iUpcoming2HrsItemData.Count() ) + |
|
341 ( iUpcomingItemData.Count() ) + |
|
342 ( iOngoing30MinItemData.Count() ) + |
|
343 ( iOngoingItemData.Count() ) + |
|
344 iNonTimedItemData.Count(); |
|
345 } |
|
346 |
|
347 TInt CAICalendarPlugin2Data::TotalTimedTodayItemCount() |
|
348 { |
|
349 return |
|
350 ( iUpcoming2HrsItemData.Count() ) + |
|
351 ( iUpcomingItemData.Count() ) + |
|
352 ( iOngoing30MinItemData.Count() ) + |
|
353 ( iOngoingItemData.Count() ); |
|
354 } |
|
355 |
|
356 RPointerArray<MAiContentObserver>& CAICalendarPlugin2Data::ObserverArray() |
|
357 { |
|
358 return iObservers; |
|
359 } |
|
360 |
|
361 void CAICalendarPlugin2Data::AppendObserverL( MAiContentObserver& aObserver ) |
|
362 { |
|
363 // make sure that 1 obs only subscribed once |
|
364 for( TInt i( 0 ); i < iObservers.Count(); ++i ) |
|
365 { |
|
366 if( iObservers[i] == &aObserver ) |
|
367 { |
|
368 User::Leave( KErrAlreadyExists ); |
|
369 } |
|
370 } |
|
371 iObservers.AppendL( &aObserver ); |
|
372 } |
|
373 |
|
374 RArray<TAiCalendarFocusData>& CAICalendarPlugin2Data::FocusDataArray() |
|
375 { |
|
376 return iEventFocusData; |
|
377 } |
|
378 |
|
379 void CAICalendarPlugin2Data::LaunchCalendarApplication( TInt aIndex, TBool aLaunchFirstValid ) |
|
380 { |
|
381 if( aIndex < 0 || |
|
382 aIndex >= iEventFocusData.Count() ) |
|
383 { |
|
384 // invalid index |
|
385 return; |
|
386 } |
|
387 |
|
388 TInt indexToLaunch = aIndex; |
|
389 if( aLaunchFirstValid ) |
|
390 { |
|
391 for( TInt i = 0; i < iEventFocusData.Count(); ++i ) |
|
392 { |
|
393 if( iEventFocusData[i].iType != EAI2CalOpenToday ) |
|
394 { |
|
395 indexToLaunch = i; |
|
396 break; |
|
397 } |
|
398 } |
|
399 } |
|
400 |
|
401 TRAP_IGNORE( |
|
402 iEventFocusData[indexToLaunch].LaunchCalendarApplicationL(); |
|
403 ); |
|
404 } |
|
405 |
|
406 TBool CAICalendarPlugin2Data::HadExpiredEvents() |
|
407 { |
|
408 return iHadExpiredEvents; |
|
409 } |
|
410 |
|
411 void CAICalendarPlugin2Data::SetHadExpiredEvents( TBool aHadExpired ) |
|
412 { |
|
413 iHadExpiredEvents = aHadExpired; |
|
414 } |