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