|
1 /* |
|
2 * Copyright (c) 2006-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: This class provides the text for an alarm notification. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "pim_trace.h" |
|
22 #include "AlmAlarmInfo.h" |
|
23 |
|
24 #include <asshdalarm.h> |
|
25 #include <calentry.h> |
|
26 #include <StringLoader.h> |
|
27 #include <AknUtils.h> |
|
28 #include <akndialogcontroller.h> |
|
29 |
|
30 #include <AlmAlert.rsg> |
|
31 |
|
32 const TInt KAlarmNoteTextLength( 256 ); // KGlobalNoteTextLength |
|
33 const TInt KDateTimeDescLen( 20 ); // enough space for // "16:54" or "1:56 am" or "10.10.2010" |
|
34 const TInt KClockAlarmType( -1 ); |
|
35 _LIT( KWesternSubjectSeparator, ", " ); |
|
36 _LIT( KArabicSubjectSeparator, " \x060c" ); |
|
37 _LIT( KNewLine, "\n" ); |
|
38 _LIT( KSpace, " " ); |
|
39 |
|
40 |
|
41 // ============================ MEMBER FUNCTIONS =============================== |
|
42 |
|
43 // constructor |
|
44 CAlmAlarmInfo::CAlmAlarmInfo(CAlarmUtils* aAlarmUtils) |
|
45 : iAlarmUtils( aAlarmUtils ) |
|
46 { |
|
47 TRACE_ENTRY_POINT; |
|
48 TRACE_EXIT_POINT; |
|
49 } |
|
50 |
|
51 // destructor |
|
52 CAlmAlarmInfo::~CAlmAlarmInfo(void) |
|
53 { |
|
54 TRACE_ENTRY_POINT; |
|
55 delete iSubject; |
|
56 delete iLocation; |
|
57 delete iDate; |
|
58 delete iTime; |
|
59 TRACE_EXIT_POINT; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // Get the text for the alarm query. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 void CAlmAlarmInfo::GetAlarmLabelL( const TASShdAlarm& aAlarm, |
|
67 HBufC*& aText, |
|
68 const CAlarmUtils::TAlarmType& aAlarmType ) |
|
69 { |
|
70 /** |
|
71 * Clock alarm: Other/unknown alarms: |
|
72 * --------------------------- --------------------------- |
|
73 * | Clock alarm: :::::: | | 01.01.2010 :::::: | |
|
74 * | 12:00 :icon: | | 12:00 :icon: | |
|
75 * | DescriptionDesc :::::: | | DescriptionDesc :::::: | |
|
76 * | riptionDescriptionDescr | | riptionDescriptionDescr | |
|
77 * | iptionDescriptionDes... | | iptionDescriptionDes... | |
|
78 * --------------------------- --------------------------- |
|
79 * |
|
80 * Meeting or reminder alarm: Event or anniversary alarm: To-Do alarm: |
|
81 * --------------------------- --------------------------- --------------------------- |
|
82 * | 01.01.2010 :::::: | | 01.01.2010 :::::: | | To-Do Task: :::::: | |
|
83 * | 12:00 :icon: | | SubjectSubjectS :icon: | | Due: 01.01.2010 :icon: | |
|
84 * | SubjectSubjectS :::::: | | ubjectSubjectSu :::::: | | SubjectSubjectS :::::: | |
|
85 * | ubject, LocationLocatio | | ubject, LocationLocatio | | ubject, LocationLocatio | |
|
86 * | nLocationLocationLoc... | | nLocationLocationLoc... | | nLocationLocationLoc... | |
|
87 * --------------------------- --------------------------- --------------------------- |
|
88 * |
|
89 * Cover UI parameters: |
|
90 * ==================== |
|
91 * Clock: time: "12:00", date: "", subject: "Description", location: "" |
|
92 * Unknown: time: "12:00", date: "01.01.2010", subject: "Description", location: "" |
|
93 * |
|
94 * Meeting: time: "12:00", date: "01.01.2010", subject: "Subject", location: "Location" |
|
95 * Reminder: time: "12:00", date: "01.01.2010", subject: "Subject", location: "Location" |
|
96 * |
|
97 * Anniversary: time: "", date: "01.01.2010", subject: "Subject", location: "Location" |
|
98 * Event: time: "", date: "01.01.2010", subject: "Subject", location: "Location" |
|
99 * To-Do: time: "", date: "01.01.2010", subject: "Subject", location: "Location" |
|
100 */ |
|
101 TRACE_ENTRY_POINT; |
|
102 |
|
103 // cover UI params... |
|
104 TInt coverUIAlarmType( KClockAlarmType ); |
|
105 |
|
106 switch( aAlarmType ) |
|
107 { |
|
108 case CAlarmUtils::EAlarmTypeClock: |
|
109 { |
|
110 GetCoverUIParamsForClockAndOtherL( aAlarm, CAlarmUtils::EAlarmTypeClock ); |
|
111 SetupClockAlarmL( aText ); |
|
112 } |
|
113 break; |
|
114 |
|
115 case CAlarmUtils::EAlarmTypeOther: |
|
116 { |
|
117 // For Cover UI - unknown alarms are handled as calendar meetings |
|
118 coverUIAlarmType = CCalEntry::EAppt; |
|
119 |
|
120 GetCoverUIParamsForClockAndOtherL( aAlarm, CAlarmUtils::EAlarmTypeOther ); |
|
121 SetupUnknownAlarmL( aText ); |
|
122 } |
|
123 break; |
|
124 |
|
125 case CAlarmUtils::EAlarmTypeCalendar: |
|
126 { |
|
127 // check phone restore mode before creating agenda session |
|
128 if( iAlarmUtils->IsPhoneInRestoreMode() ) |
|
129 { |
|
130 User::Leave( KErrCancel ); // trapped in CAlmAlarmControl |
|
131 } |
|
132 |
|
133 // fetch the calendar entry and instance time |
|
134 // |
|
135 CCalEntry* entry = NULL; |
|
136 iAlarmUtils->FetchEntryL( entry ); |
|
137 CleanupStack::PushL( entry ); |
|
138 CleanupStack::PushL( aText ); |
|
139 |
|
140 // entry type |
|
141 CCalEntry::TType type = entry->EntryTypeL(); |
|
142 coverUIAlarmType = type; |
|
143 |
|
144 GetCoverUIParamsForCalendarL( entry ); |
|
145 |
|
146 switch( type ) |
|
147 { |
|
148 case CCalEntry::EAppt: // Appointment |
|
149 case CCalEntry::EReminder: // Reminder |
|
150 { |
|
151 SetupAppointmentAlarmL( aText ); |
|
152 } |
|
153 break; |
|
154 |
|
155 case CCalEntry::ETodo: // To-Do |
|
156 { |
|
157 SetupToDoAlarmL( aText ); |
|
158 } |
|
159 break; |
|
160 |
|
161 //case CCalEntry::EAnniv: // Anniversary |
|
162 //case CCalEntry::EEvent: // Day note / All day event |
|
163 default: |
|
164 { |
|
165 SetupAnniversaryAlarmL( aText ); |
|
166 } |
|
167 break; |
|
168 } |
|
169 |
|
170 CleanupStack::Pop(); // aText |
|
171 CleanupStack::PopAndDestroy( entry ); |
|
172 } |
|
173 break; |
|
174 |
|
175 default: |
|
176 __ASSERT_DEBUG( EFalse, User::Invariant() ); |
|
177 } |
|
178 |
|
179 // Set information for cover UI... |
|
180 // |
|
181 iAlarmUtils->NotifierDialogController()->AddAlarmAdditionalInfo( coverUIAlarmType, |
|
182 *iCoverTime, |
|
183 *iCoverDate, |
|
184 *iSubject, |
|
185 *iLocation ); |
|
186 // ... and cleanup |
|
187 delete iSubject; iSubject = NULL; |
|
188 delete iLocation; iLocation = NULL; |
|
189 delete iDate; iDate = NULL; |
|
190 delete iTime; iTime = NULL; |
|
191 delete iCoverDate; iCoverDate = NULL; |
|
192 delete iCoverTime; iCoverTime = NULL; |
|
193 |
|
194 TRACE_EXIT_POINT; |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // Get the text for the wake-up query. |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CAlmAlarmInfo::GetWakeupLabelL(HBufC*& aLabel) |
|
202 { |
|
203 TRACE_ENTRY_POINT; |
|
204 aLabel = StringLoader::LoadL( R_EIKALARM_CONFIRMATION ); |
|
205 TRACE_EXIT_POINT; |
|
206 } |
|
207 |
|
208 // ============================================================================= |
|
209 // ALARM SETUP METHODS |
|
210 // ============================================================================= |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // Create alarm notification string for Clock alarm. |
|
214 // "[Clock alarm:][\n][time][\n][Description]" |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void CAlmAlarmInfo::SetupClockAlarmL(HBufC*& aText) |
|
218 { |
|
219 TRACE_ENTRY_POINT; |
|
220 // default text for clock alarm |
|
221 HBufC* clockText = StringLoader::LoadLC( R_EIKALARM_CLOCK_ALARM_TYPE ); |
|
222 |
|
223 aText = HBufC::NewLC( clockText->Length() |
|
224 + KNewLine().Length() |
|
225 + iTime->Length() |
|
226 + KNewLine().Length() |
|
227 + iSubject->Length() ); |
|
228 |
|
229 // add default clock alarm text |
|
230 *aText = *clockText; |
|
231 TPtr ptr = aText->Des(); |
|
232 ptr.Append( KNewLine ); |
|
233 |
|
234 // add time |
|
235 ptr.Append( *iTime ); |
|
236 |
|
237 // add description |
|
238 if( iSubject->Length() ) |
|
239 { |
|
240 ptr.Append( KNewLine ); |
|
241 ptr.Append( *iSubject ); |
|
242 } |
|
243 |
|
244 CleanupStack::Pop( aText ); |
|
245 CleanupStack::Pop( clockText ); |
|
246 TRACE_EXIT_POINT; |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // Create alarm notification string for an unknown alarm type. |
|
251 // "[date][\n][time][\n][Description]" |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void CAlmAlarmInfo::SetupUnknownAlarmL(HBufC*& aText) |
|
255 { |
|
256 TRACE_ENTRY_POINT; |
|
257 aText = HBufC::NewLC( iDate->Length() |
|
258 + KNewLine().Length() |
|
259 + iTime->Length() |
|
260 + KNewLine().Length() |
|
261 + iSubject->Length() ); |
|
262 // add date |
|
263 *aText = *iDate; |
|
264 TPtr ptr = aText->Des(); |
|
265 ptr.Append( KNewLine ); |
|
266 |
|
267 // add time |
|
268 ptr.Append( *iTime ); |
|
269 |
|
270 // add description |
|
271 if( iSubject->Length() ) |
|
272 { |
|
273 ptr.Append( KNewLine ); |
|
274 ptr.Append( *iSubject ); |
|
275 } |
|
276 |
|
277 CleanupStack::Pop( aText ); |
|
278 TRACE_EXIT_POINT; |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // Create alarm notification string for a calendar appointment alarm. |
|
283 // "[date][\n][time][\n][Subject][, ][Location]" |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 void CAlmAlarmInfo::SetupAppointmentAlarmL(HBufC*& aText) |
|
287 { |
|
288 TRACE_ENTRY_POINT; |
|
289 const TDesC& separator( User::Language() == ELangArabic ? |
|
290 KArabicSubjectSeparator : |
|
291 KWesternSubjectSeparator ); |
|
292 |
|
293 aText = HBufC::NewLC( iDate->Length() |
|
294 + KNewLine().Length() |
|
295 + iTime->Length() |
|
296 + KNewLine().Length() |
|
297 + iSubject->Length() |
|
298 + separator.Length() |
|
299 + iLocation->Length() ); |
|
300 |
|
301 // add date |
|
302 *aText = *iDate; |
|
303 TPtr ptr = aText->Des(); |
|
304 ptr.Append( KNewLine ); |
|
305 |
|
306 // add time |
|
307 ptr.Append( *iTime ); |
|
308 ptr.Append( KNewLine ); |
|
309 |
|
310 // subject and location |
|
311 AppendSubjectLocationText( ptr, separator ); |
|
312 |
|
313 CleanupStack::Pop( aText ); |
|
314 TRACE_EXIT_POINT; |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // Create alarm notification string for a calendar to-do alarm. |
|
319 // "[To-Do Task:][\n][Due:][ ][date][\n][Subject][, ][Location]" |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 void CAlmAlarmInfo::SetupToDoAlarmL(HBufC*& aText) |
|
323 { |
|
324 TRACE_ENTRY_POINT; |
|
325 HBufC* todoStr1 = StringLoader::LoadLC( R_EIKALARM_TODO_TITLE ); // "To-Do Task:" |
|
326 HBufC* todoStr2 = StringLoader::LoadLC( R_EIKALARM_TODO_DUE ); // "Due:" |
|
327 const TDesC& separator( User::Language() == ELangArabic ? |
|
328 KArabicSubjectSeparator : |
|
329 KWesternSubjectSeparator ); |
|
330 |
|
331 aText = HBufC::NewLC( todoStr1->Length() |
|
332 + KNewLine().Length() |
|
333 + todoStr2->Length() |
|
334 + KSpace().Length() |
|
335 + iDate->Length() |
|
336 + KNewLine().Length() |
|
337 + iSubject->Length() |
|
338 + separator.Length() |
|
339 + iLocation->Length() ); |
|
340 |
|
341 // add default to-do alarm text |
|
342 *aText = *todoStr1; |
|
343 TPtr ptr = aText->Des(); |
|
344 ptr.Append( KNewLine ); |
|
345 ptr.Append( *todoStr2 ); |
|
346 ptr.Append( KSpace ); |
|
347 |
|
348 // add date |
|
349 ptr.Append( *iDate ); |
|
350 ptr.Append( KNewLine ); |
|
351 |
|
352 // subject and location |
|
353 AppendSubjectLocationText( ptr, separator ); |
|
354 |
|
355 CleanupStack::Pop( aText ); |
|
356 CleanupStack::PopAndDestroy( todoStr2 ); |
|
357 CleanupStack::PopAndDestroy( todoStr1 ); |
|
358 TRACE_EXIT_POINT; |
|
359 } |
|
360 |
|
361 // ----------------------------------------------------------------------------- |
|
362 // Create alarm notification string for a calendar anniversary alarm. |
|
363 // "[date][\n][Subject][, ][Location]" |
|
364 // ----------------------------------------------------------------------------- |
|
365 // |
|
366 void CAlmAlarmInfo::SetupAnniversaryAlarmL(HBufC*& aText) |
|
367 { |
|
368 TRACE_ENTRY_POINT; |
|
369 const TDesC& separator( User::Language() == ELangArabic ? |
|
370 KArabicSubjectSeparator : |
|
371 KWesternSubjectSeparator ); |
|
372 |
|
373 aText = HBufC::NewLC( iDate->Length() |
|
374 + KNewLine().Length() |
|
375 + iSubject->Length() |
|
376 + separator.Length() |
|
377 + iLocation->Length() ); |
|
378 // add date |
|
379 *aText = *iDate; |
|
380 TPtr ptr = aText->Des(); |
|
381 ptr.Append( KNewLine ); |
|
382 |
|
383 // subject and location |
|
384 AppendSubjectLocationText( ptr, separator ); |
|
385 |
|
386 CleanupStack::Pop( aText ); |
|
387 TRACE_EXIT_POINT; |
|
388 } |
|
389 |
|
390 |
|
391 |
|
392 // ============================================================================= |
|
393 // STRING UTILITY FUNCTIONS |
|
394 // ============================================================================= |
|
395 |
|
396 // ----------------------------------------------------------------------------- |
|
397 // Append subject and location strings into aText. |
|
398 // ----------------------------------------------------------------------------- |
|
399 // |
|
400 void CAlmAlarmInfo::AppendSubjectLocationText(TPtr& aDest, const TDesC& aSeparator) |
|
401 { |
|
402 TRACE_ENTRY_POINT; |
|
403 aDest.Append( *iSubject ); |
|
404 |
|
405 if( iLocation->Length() ) |
|
406 { |
|
407 if( iSubject->Length() ) |
|
408 { |
|
409 // add ", " if we have both subject and location |
|
410 aDest.Append( aSeparator ); |
|
411 } |
|
412 // add locaton |
|
413 aDest.Append( *iLocation ); |
|
414 } |
|
415 TRACE_EXIT_POINT; |
|
416 } |
|
417 |
|
418 // ----------------------------------------------------------------------------- |
|
419 // Create strings needed for calendar alarms. |
|
420 // AVKON global note can't (currently) show more than 256 characters. So no |
|
421 // need to use more than KAlarmNoteTextLength -KDateTimeDescLen for subject |
|
422 // and location strings. |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 void CAlmAlarmInfo::GetCoverUIParamsForCalendarL(const CCalEntry* aEntry) |
|
426 { |
|
427 TRACE_ENTRY_POINT; |
|
428 HBufC* dateFormat = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO ); |
|
429 HBufC* timeFormat = StringLoader::LoadLC( R_QTN_TIME_USUAL_WITH_ZERO ); |
|
430 const TTime instanceTime( iAlarmUtils->AlarmData().iInstanceTime.TimeLocalL() ); |
|
431 |
|
432 // subject |
|
433 iSubject = HBufC::NewL( KAlarmNoteTextLength -KDateTimeDescLen ); |
|
434 iSubject->Des().Append( aEntry->SummaryL().Left( iSubject->Des().MaxLength() ) ); |
|
435 iSubject->Des().TrimAll(); |
|
436 |
|
437 // location |
|
438 iLocation = HBufC::NewL( Max( 0, KAlarmNoteTextLength -KDateTimeDescLen -iSubject->Length() ) ); |
|
439 iLocation->Des().Append( aEntry->LocationL().Left( iLocation->Des().MaxLength() ) ); |
|
440 iLocation->Des().TrimAll(); |
|
441 |
|
442 // date |
|
443 iDate = HBufC::NewL( KDateTimeDescLen ); |
|
444 TPtr datePtr = iDate->Des(); |
|
445 instanceTime.FormatL( datePtr, *dateFormat ); |
|
446 iCoverDate = iDate->AllocL(); |
|
447 AknTextUtils::LanguageSpecificNumberConversion( datePtr ); // digit conversion |
|
448 |
|
449 // time |
|
450 if( aEntry->EntryTypeL() == CCalEntry::EAppt || |
|
451 aEntry->EntryTypeL() == CCalEntry::EReminder ) |
|
452 { |
|
453 iTime = HBufC::NewL( KDateTimeDescLen ); |
|
454 TPtr timePtr = iTime->Des(); |
|
455 instanceTime.FormatL( timePtr, *timeFormat ); |
|
456 iCoverTime = iTime->AllocL(); |
|
457 AknTextUtils::LanguageSpecificNumberConversion( timePtr ); // digit conversion |
|
458 } |
|
459 else // no time for other calendar types |
|
460 { |
|
461 iTime = HBufC::NewL( 0 ); |
|
462 iCoverTime = HBufC::NewL( 0 ); |
|
463 } |
|
464 |
|
465 CleanupStack::PopAndDestroy( timeFormat ); |
|
466 CleanupStack::PopAndDestroy( dateFormat ); |
|
467 TRACE_EXIT_POINT; |
|
468 } |
|
469 |
|
470 // ----------------------------------------------------------------------------- |
|
471 // Create strings needed for clock alarm and unknown alarms. |
|
472 // ----------------------------------------------------------------------------- |
|
473 // |
|
474 void CAlmAlarmInfo::GetCoverUIParamsForClockAndOtherL( const TASShdAlarm& aAlarm, |
|
475 const CAlarmUtils::TAlarmType aType ) |
|
476 { |
|
477 TRACE_ENTRY_POINT; |
|
478 HBufC* dateFormat = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO ); |
|
479 HBufC* timeFormat = StringLoader::LoadLC( R_QTN_TIME_USUAL_WITH_ZERO ); |
|
480 |
|
481 // alarm description |
|
482 iSubject = aAlarm.Message().AllocL(); |
|
483 iSubject->Des().TrimAll(); |
|
484 |
|
485 // no location for clock alarms |
|
486 iLocation = HBufC::NewL( 0 ); |
|
487 |
|
488 TTime alarmTime( aType == CAlarmUtils::EAlarmTypeClock ? |
|
489 aAlarm.NextDueTime() : |
|
490 aAlarm.OriginalExpiryTime() ); |
|
491 |
|
492 // alarm time |
|
493 iTime = HBufC::NewL( KDateTimeDescLen ); |
|
494 TPtr timePtr = iTime->Des(); |
|
495 alarmTime.FormatL( timePtr, *timeFormat ); |
|
496 iCoverTime = iTime->AllocL(); |
|
497 AknTextUtils::LanguageSpecificNumberConversion( timePtr ); // digit conversion |
|
498 |
|
499 if( aType == CAlarmUtils::EAlarmTypeClock ) |
|
500 { |
|
501 // no date for clock alarms |
|
502 iDate = HBufC::NewL( 0 ); |
|
503 iCoverDate = HBufC::NewL( 0 ); |
|
504 } |
|
505 else // other alarm types |
|
506 { |
|
507 // date |
|
508 iDate = HBufC::NewL( KDateTimeDescLen ); |
|
509 TPtr datePtr = iDate->Des(); |
|
510 alarmTime.FormatL( datePtr, *dateFormat ); |
|
511 iCoverDate = iDate->AllocL(); |
|
512 AknTextUtils::LanguageSpecificNumberConversion( datePtr ); // digit conversion |
|
513 } |
|
514 |
|
515 CleanupStack::PopAndDestroy( timeFormat ); |
|
516 CleanupStack::PopAndDestroy( dateFormat ); |
|
517 TRACE_EXIT_POINT; |
|
518 } |
|
519 |
|
520 |
|
521 // End of File |