|
1 /* |
|
2 * Copyright (c) 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: Calendar context, info on what's currently focused |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //debug |
|
21 #include "calendarui_debug.h" |
|
22 |
|
23 #include "calencontextimpl.h" |
|
24 |
|
25 #include "calencontextchangeobserver.h" |
|
26 #include <calendateutils.h> |
|
27 #include <lbsposition.h> |
|
28 |
|
29 const TInt KCalenDefaultTimeForViews = 480; // 480 minutes == 8 hours == 8 am. |
|
30 |
|
31 // ---------------------------------------------------------------------------- |
|
32 // CCalenContextImpl::CCalenContextImpl |
|
33 // Constructor. |
|
34 // (other items were commented in a header). |
|
35 // ---------------------------------------------------------------------------- |
|
36 // |
|
37 CCalenContextImpl::CCalenContextImpl( MCalenContextChangeObserver* aObserver ) |
|
38 : iObserver( aObserver ), |
|
39 iFocusTime( -1 ), |
|
40 iInstanceId( TCalenInstanceId::NullInstanceId() ) |
|
41 { |
|
42 TRACE_ENTRY_POINT; |
|
43 TRACE_EXIT_POINT; |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // CCalenContextImpl::CCalenContextImpl |
|
48 // Default Constructor. |
|
49 // (other items were commented in a header). |
|
50 // ---------------------------------------------------------------------------- |
|
51 // |
|
52 CCalenContextImpl::CCalenContextImpl() |
|
53 : iInstanceId( TCalenInstanceId::NullInstanceId() ) |
|
54 { |
|
55 TRACE_ENTRY_POINT; |
|
56 TRACE_EXIT_POINT; |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // CCalenContextImpl::CCalenContextImpl |
|
61 // Copy Constructor. |
|
62 // (other items were commented in a header). |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 CCalenContextImpl::CCalenContextImpl( const CCalenContextImpl& aContext ) |
|
66 { |
|
67 TRACE_ENTRY_POINT; |
|
68 |
|
69 // When copying, set the observer to NULL because the only context that |
|
70 // should be set is accessed from the global data. |
|
71 iObserver = NULL; |
|
72 iFocusTime = aContext.iFocusTime; |
|
73 iInstanceId = aContext.iInstanceId; |
|
74 iViewId = aContext.iViewId; |
|
75 |
|
76 TRACE_EXIT_POINT; |
|
77 } |
|
78 |
|
79 // ---------------------------------------------------------------------------- |
|
80 // CCalenContextImpl::~CCalenContextImpl |
|
81 // Destructor. |
|
82 // (other items were commented in a header). |
|
83 // ---------------------------------------------------------------------------- |
|
84 // |
|
85 CCalenContextImpl::~CCalenContextImpl() |
|
86 { |
|
87 TRACE_ENTRY_POINT; |
|
88 TRACE_EXIT_POINT; |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // CCalenContextImpl::DefaultTimeForViews |
|
93 // If a view knows what day they should be looking at, but doesn't know what |
|
94 // time (for example the month view only deals in days), they should set the |
|
95 // time to this value. |
|
96 // (other items were commented in a header). |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 TTimeIntervalMinutes CCalenContextImpl::DefaultTimeForViews() const |
|
100 { |
|
101 TRACE_ENTRY_POINT; |
|
102 TRACE_EXIT_POINT; |
|
103 return TTimeIntervalMinutes( KCalenDefaultTimeForViews ); |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------------------------- |
|
107 // CCalenContextImpl::DefaultCalTimeForViewsL |
|
108 // If a view has no preference as to what time/day to be focused on (e.g. when |
|
109 // a view is the first view loaded), they should set focus to this TCalTime. |
|
110 // (other items were commented in a header). |
|
111 // ---------------------------------------------------------------------------- |
|
112 // |
|
113 TCalTime CCalenContextImpl::DefaultCalTimeForViewsL() const |
|
114 { |
|
115 TRACE_ENTRY_POINT; |
|
116 |
|
117 TTime today; |
|
118 today.HomeTime(); |
|
119 today = CalenDateUtils::BeginningOfDay( today ); |
|
120 TCalTime ret; |
|
121 ret.SetTimeLocalL( today + CCalenContextImpl::DefaultTimeForViews() ); |
|
122 |
|
123 TRACE_EXIT_POINT; |
|
124 return ret; |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------------------------------- |
|
128 // CCalenContextImpl::SetFocusDateAndTimeL |
|
129 // Sets the focus time |
|
130 // (other items were commented in a header). |
|
131 // ---------------------------------------------------------------------------- |
|
132 // |
|
133 void CCalenContextImpl::SetFocusDateAndTimeL( const TCalTime& aFocusDateTime, |
|
134 const TVwsViewId& aViewId ) |
|
135 { |
|
136 TRACE_ENTRY_POINT; |
|
137 |
|
138 // If this fails you're using a context that was constructed yourself. |
|
139 // Use the accessor from the global data instead, or don't try to set |
|
140 // anything on this context. |
|
141 ASSERT( iObserver ); |
|
142 |
|
143 #ifdef _DEBUG |
|
144 TDateTime dt = aFocusDateTime.TimeLocalL().DateTime(); |
|
145 #endif |
|
146 |
|
147 iFocusDate.SetTimeLocalL( CalenDateUtils::BeginningOfDay( aFocusDateTime.TimeLocalL() ) ); |
|
148 User::LeaveIfError( aFocusDateTime.TimeLocalL().MinutesFrom( iFocusDate.TimeLocalL(), |
|
149 iFocusTime ) ); |
|
150 ASSERT( iFocusTime.Int() >= 0 ); |
|
151 iInstanceId = TCalenInstanceId::NullInstanceId(); |
|
152 iViewId = aViewId; |
|
153 |
|
154 iObserver->ContextChanged(); |
|
155 |
|
156 TRACE_EXIT_POINT; |
|
157 } |
|
158 |
|
159 // ---------------------------------------------------------------------------- |
|
160 // CCalenContextImpl::SetFocusDateL |
|
161 // Sets the focus date |
|
162 // (other items were commented in a header). |
|
163 // ---------------------------------------------------------------------------- |
|
164 // |
|
165 void CCalenContextImpl::SetFocusDateL( const TCalTime& aFocusDate, |
|
166 const TVwsViewId& aViewId ) |
|
167 { |
|
168 TRACE_ENTRY_POINT; |
|
169 |
|
170 // If this fails you're using a context that was constructed yourself. |
|
171 // Use the accessor from the global data instead, or don't try to set |
|
172 // anything on this context. |
|
173 ASSERT( iObserver ); |
|
174 |
|
175 #ifdef _DEBUG |
|
176 TDateTime dt = aFocusDate.TimeLocalL().DateTime(); |
|
177 #endif |
|
178 |
|
179 iFocusDate.SetTimeLocalL( CalenDateUtils::BeginningOfDay( aFocusDate.TimeLocalL() ) ); |
|
180 iFocusTime = TTimeIntervalMinutes( -1 ); |
|
181 iInstanceId = TCalenInstanceId::NullInstanceId(); |
|
182 iViewId = aViewId; |
|
183 |
|
184 iObserver->ContextChanged(); |
|
185 |
|
186 TRACE_EXIT_POINT; |
|
187 } |
|
188 |
|
189 // ---------------------------------------------------------------------------- |
|
190 // CCalenContextImpl::SetInstanceIdL |
|
191 // Sets the instance id |
|
192 // (other items were commented in a header). |
|
193 // ---------------------------------------------------------------------------- |
|
194 // |
|
195 void CCalenContextImpl::SetInstanceIdL( const TCalenInstanceId& aInstanceId, |
|
196 const TVwsViewId& aViewId ) |
|
197 { |
|
198 TRACE_ENTRY_POINT; |
|
199 |
|
200 // If this fails you're using a context that was constructed yourself. |
|
201 // Use the accessor from the global data instead, or don't try to set |
|
202 // anything on this context. |
|
203 ASSERT( iObserver ); |
|
204 |
|
205 iFocusDate.SetTimeUtcL( Time::NullTTime() ); |
|
206 iFocusTime = TTimeIntervalMinutes( -1 ); |
|
207 iInstanceId = aInstanceId; |
|
208 iViewId = aViewId; |
|
209 |
|
210 iObserver->ContextChanged(); |
|
211 |
|
212 TRACE_EXIT_POINT; |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CCalenContextImpl::SetFocusDateAndTimeAndInstanceL |
|
217 // Sets the currently focused time and instance |
|
218 // (other items were commented in a header). |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 void CCalenContextImpl::SetFocusDateAndTimeAndInstanceL( const TCalTime& aFocusDateTime, |
|
222 const TCalenInstanceId& aInstanceId, |
|
223 const TVwsViewId& aViewId ) |
|
224 { |
|
225 TRACE_ENTRY_POINT; |
|
226 |
|
227 // If this fails you're using a context that was constructed yourself. |
|
228 // Use the accessor from the global data instead, or don't try to set |
|
229 // anything on this context. |
|
230 ASSERT( iObserver ); |
|
231 |
|
232 #ifdef _DEBUG |
|
233 TDateTime dt = aFocusDateTime.TimeLocalL().DateTime(); |
|
234 #endif |
|
235 |
|
236 iFocusDate.SetTimeLocalL( CalenDateUtils::BeginningOfDay( aFocusDateTime.TimeLocalL() ) ); |
|
237 User::LeaveIfError( aFocusDateTime.TimeLocalL().MinutesFrom( iFocusDate.TimeLocalL(), |
|
238 iFocusTime ) ); |
|
239 ASSERT( iFocusTime.Int() >= 0 ); |
|
240 iInstanceId = aInstanceId; |
|
241 iViewId = aViewId; |
|
242 |
|
243 iObserver->ContextChanged(); |
|
244 |
|
245 TRACE_EXIT_POINT; |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CCalenContextImpl::FocusDateAndTimeL |
|
250 // Returns the focus time |
|
251 // (other items were commented in a header). |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 TCalTime CCalenContextImpl::FocusDateAndTimeL() const |
|
255 { |
|
256 TRACE_ENTRY_POINT; |
|
257 |
|
258 TCalTime ret; |
|
259 |
|
260 if( iFocusDate.TimeUtcL() != Time::NullTTime() ) |
|
261 { |
|
262 if ( iFocusTime.Int() >= 0 ) |
|
263 { |
|
264 ret.SetTimeLocalL( iFocusDate.TimeLocalL() + iFocusTime ); |
|
265 } |
|
266 else |
|
267 { |
|
268 ret.SetTimeLocalL( iFocusDate.TimeLocalL() + DefaultTimeForViews() ); |
|
269 } |
|
270 } |
|
271 else |
|
272 { |
|
273 ret.SetTimeLocalL( iInstanceId.iInstanceTime ); |
|
274 } |
|
275 |
|
276 TRACE_EXIT_POINT; |
|
277 return ret; |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CCalenContextImpl::FocusTime |
|
282 // Returns the focus time |
|
283 // (other items were commented in a header). |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 TTimeIntervalMinutes CCalenContextImpl::FocusTime() const |
|
287 { |
|
288 TRACE_ENTRY_POINT; |
|
289 TRACE_EXIT_POINT; |
|
290 return iFocusTime; |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CCalenContextImpl::InstanceId |
|
295 // Returns the instance id |
|
296 // (other items were commented in a header). |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 TCalenInstanceId CCalenContextImpl::InstanceId() const |
|
300 { |
|
301 TRACE_ENTRY_POINT; |
|
302 TRACE_EXIT_POINT; |
|
303 return iInstanceId; |
|
304 } |
|
305 |
|
306 // ----------------------------------------------------------------------------- |
|
307 // CCalenContextImpl::ViewId |
|
308 // Returns the view id |
|
309 // (other items were commented in a header). |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 TVwsViewId CCalenContextImpl::ViewId() const |
|
313 { |
|
314 TRACE_ENTRY_POINT; |
|
315 TRACE_EXIT_POINT; |
|
316 return iViewId; |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CCalenContextImpl::SetMutlipleContextIds |
|
321 // Set multiple context ids |
|
322 // (other items were commented in a header). |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 void CCalenContextImpl::SetMutlipleContextIds( |
|
326 RArray<TCalenInstanceId>& aMutlipleContextIds) |
|
327 { |
|
328 TRACE_ENTRY_POINT; |
|
329 |
|
330 iMutlipleContextIds.Reset(); |
|
331 iMutlipleContextIds = aMutlipleContextIds; |
|
332 |
|
333 TRACE_EXIT_POINT; |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CCalenContextImpl::RemoveMultipleContextId |
|
338 // Remove multiple context id |
|
339 // (other items were commented in a header). |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 void CCalenContextImpl::RemoveMultipleContextId(TCalenInstanceId aInstanceId) |
|
343 { |
|
344 TRACE_ENTRY_POINT; |
|
345 |
|
346 for(TInt index = 0;index < iMutlipleContextIds.Count();index++) |
|
347 { |
|
348 if(aInstanceId == iMutlipleContextIds[index]) |
|
349 { |
|
350 iMutlipleContextIds.Remove(index); |
|
351 } |
|
352 } |
|
353 |
|
354 TRACE_EXIT_POINT; |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // CCalenContextImpl::ResetMultipleContextIds |
|
359 // Resets all the multiple context ids |
|
360 // (other items were commented in a header). |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 void CCalenContextImpl::ResetMultipleContextIds(TInt /*aDbId*/) |
|
364 { |
|
365 TRACE_ENTRY_POINT; |
|
366 |
|
367 //if(iMutlipleContextIds.Count()) |
|
368 { |
|
369 iMutlipleContextIds.Reset(); |
|
370 iMutlipleContextIds.Close(); |
|
371 } |
|
372 |
|
373 TRACE_EXIT_POINT; |
|
374 } |
|
375 |
|
376 // ----------------------------------------------------------------------------- |
|
377 // CCalenContextImpl::GetMutlipleContextIds |
|
378 // Getter for multiple context ids |
|
379 // (other items were commented in a header). |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 RArray<TCalenInstanceId>& CCalenContextImpl::GetMutlipleContextIds(TInt /*aDbId*/) |
|
383 { |
|
384 TRACE_ENTRY_POINT; |
|
385 TRACE_EXIT_POINT; |
|
386 |
|
387 return iMutlipleContextIds; |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CCalenContextImpl::MutlipleContextIdsCount |
|
392 // Returns mutliple context's count |
|
393 // (other items were commented in a header). |
|
394 // ----------------------------------------------------------------------------- |
|
395 // |
|
396 TInt CCalenContextImpl::MutlipleContextIdsCount() |
|
397 { |
|
398 TRACE_ENTRY_POINT; |
|
399 TRACE_EXIT_POINT; |
|
400 |
|
401 return iMutlipleContextIds.Count(); |
|
402 } |
|
403 |
|
404 // ----------------------------------------------------------------------------- |
|
405 // CCalenContextImpl::SetLandMark |
|
406 // Sets the user selected landmark |
|
407 // (other items were commented in a header). |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 void CCalenContextImpl::SetLandMark(CPosLandmark* aLandMark) |
|
411 { |
|
412 TRACE_ENTRY_POINT; |
|
413 if(iLandMark) |
|
414 { |
|
415 delete iLandMark; |
|
416 } |
|
417 iLandMark = aLandMark; |
|
418 TRACE_EXIT_POINT; |
|
419 } |
|
420 |
|
421 // ----------------------------------------------------------------------------- |
|
422 // CCalenContextImpl::GetLandMark |
|
423 // Returns the user selected landmark |
|
424 // (other items were commented in a header). |
|
425 // ----------------------------------------------------------------------------- |
|
426 // |
|
427 CPosLandmark* CCalenContextImpl::GetLandMark() |
|
428 { |
|
429 TRACE_ENTRY_POINT; |
|
430 TRACE_EXIT_POINT; |
|
431 |
|
432 return(iLandMark); |
|
433 } |
|
434 |
|
435 // ----------------------------------------------------------------------------- |
|
436 // CCalenContextImpl::ResetLandMark |
|
437 // Resets the landmark |
|
438 // (other items were commented in a header). |
|
439 // ----------------------------------------------------------------------------- |
|
440 // |
|
441 void CCalenContextImpl::ResetLandMark() |
|
442 { |
|
443 TRACE_ENTRY_POINT; |
|
444 if(iLandMark) |
|
445 { |
|
446 delete iLandMark; |
|
447 iLandMark = NULL; |
|
448 } |
|
449 TRACE_EXIT_POINT; |
|
450 } |
|
451 |
|
452 // ---------------------------------------------------------------------------- |
|
453 // CCalenContextImpl::CalenCommandHandlerExtensionL |
|
454 // Dummy implementation. |
|
455 // (other items were commented in a header). |
|
456 // ---------------------------------------------------------------------------- |
|
457 // |
|
458 TAny* CCalenContextImpl::CalenContextExtensionL( TUid /*aExtensionUid*/ ) |
|
459 { |
|
460 TRACE_ENTRY_POINT; |
|
461 TRACE_EXIT_POINT; |
|
462 return NULL; |
|
463 } |
|
464 |
|
465 // ----------------------------------------------------------------------------- |
|
466 // CCalenContextImpl::GetCalendarFileNameL |
|
467 // Get calendar file name |
|
468 // ----------------------------------------------------------------------------- |
|
469 TDesC& CCalenContextImpl::GetCalendarFileNameL() const |
|
470 { |
|
471 TRACE_ENTRY_POINT |
|
472 TRACE_EXIT_POINT |
|
473 return *iCalenFileName; |
|
474 } |
|
475 |
|
476 // ----------------------------------------------------------------------------- |
|
477 // CCalenContextImpl::SetCalendarFileNameL |
|
478 // Set calendar file name to context |
|
479 // ----------------------------------------------------------------------------- |
|
480 void CCalenContextImpl::SetCalendarFileNameL(const TDesC& aCalFileName) |
|
481 { |
|
482 TRACE_ENTRY_POINT |
|
483 |
|
484 if(iCalenFileName) |
|
485 { |
|
486 delete iCalenFileName; |
|
487 iCalenFileName = NULL; |
|
488 } |
|
489 iCalenFileName = aCalFileName.AllocL(); |
|
490 TRACE_EXIT_POINT |
|
491 } |
|
492 |
|
493 // ----------------------------------------------------------------------------- |
|
494 // CCalenContextImpl::ResetCalendarFileName |
|
495 // Resets calendar file name in context |
|
496 // ----------------------------------------------------------------------------- |
|
497 void CCalenContextImpl::ResetCalendarFileName() |
|
498 { |
|
499 TRACE_ENTRY_POINT; |
|
500 if(iCalenFileName) |
|
501 { |
|
502 delete iCalenFileName; |
|
503 iCalenFileName = NULL; |
|
504 } |
|
505 |
|
506 TRACE_EXIT_POINT; |
|
507 } |
|
508 |
|
509 // End of file |