|
1 /* |
|
2 * Copyright (c) 2002 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 * A helper class for filling the viewer component with data from a |
|
16 * calendar item. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include "VCalBcDataFiller.h" // CVCalBcDataFiller |
|
25 #include "VCalBcPanics.h" // panic codes |
|
26 |
|
27 #include <calentry.h> |
|
28 #include <calalarm.h> |
|
29 #include <StringLoader.h> // StringLoader |
|
30 #include <vcalbc.rsg> // resouce identifiers |
|
31 #include <avkon.rsg> // resouce identifiers |
|
32 #include <CRichBio.h> // CRichBio |
|
33 |
|
34 // CONSTANTS |
|
35 |
|
36 const TInt KMaxDateTimeTextLength = 100; |
|
37 const TInt KRepeatIntervalBiWeekly = 2; |
|
38 |
|
39 // MEMBER FUNCTIONS |
|
40 |
|
41 CVCalBcDataFiller::~CVCalBcDataFiller() |
|
42 { |
|
43 delete iDateFormat; |
|
44 delete iTimeFormat; |
|
45 delete iSummaryDescr; |
|
46 } |
|
47 |
|
48 void CVCalBcDataFiller::FillViewerWithDataL( |
|
49 CRichBio& aViewer, |
|
50 CCalEntry& aEntry, |
|
51 CCoeEnv& aCoeEnv) |
|
52 { |
|
53 // An instance is used because otherwise we would have to pass around many |
|
54 // arguments. |
|
55 CVCalBcDataFiller* filler = CVCalBcDataFiller::NewLC(aEntry, aCoeEnv); |
|
56 filler->FillViewerWithDataL(aViewer); |
|
57 CleanupStack::PopAndDestroy(filler); |
|
58 } |
|
59 |
|
60 void CVCalBcDataFiller::FillViewerWithDataL(CRichBio& aViewer) |
|
61 { |
|
62 __ASSERT_DEBUG(&aViewer != NULL, Panic(ENullViewer)); |
|
63 |
|
64 TTime startTime(Time::NullTTime()); |
|
65 //we want to trap KErrArgument if time is not set |
|
66 TRAP_IGNORE((startTime = iEntry.StartTimeL().TimeLocalL())); |
|
67 |
|
68 TTime endTime(Time::NullTTime()); |
|
69 TRAP_IGNORE((endTime = iEntry.EndTimeL().TimeLocalL())); |
|
70 |
|
71 CCalEntry::TType type( iEntry.EntryTypeL() ); |
|
72 if (type == CCalEntry::EAnniv) |
|
73 { |
|
74 AddAnniversarySpecificInfoL(aViewer, startTime); |
|
75 } |
|
76 else if (type == CCalEntry::EAppt) |
|
77 { |
|
78 AddMeetingSpecificInfoL(aViewer, startTime, endTime); |
|
79 } |
|
80 else if (type == CCalEntry::EEvent) |
|
81 { |
|
82 AddDaynoteSpecificInfoL(aViewer, startTime, endTime); |
|
83 } |
|
84 else if (type ==CCalEntry::ETodo) |
|
85 { |
|
86 AddVTodoSpecificInfoL(aViewer); |
|
87 } |
|
88 else |
|
89 { |
|
90 // The class CCalenImporter is responsible for checking the Series 60 |
|
91 // compatibility of the entry. It is used before coming here. |
|
92 __ASSERT_ALWAYS(EFalse, Panic(EUnsupportedEntryType)); |
|
93 return; |
|
94 } |
|
95 |
|
96 if (type != CCalEntry::ETodo) |
|
97 { |
|
98 AddConfidentialityInfoL(aViewer); |
|
99 } |
|
100 |
|
101 //the description field is supported by all entry types |
|
102 AddDescriptionInfoL( aViewer ); |
|
103 } |
|
104 |
|
105 void CVCalBcDataFiller::AddAnniversarySpecificInfoL( |
|
106 CRichBio& aViewer, |
|
107 const TTime& aStartTime) |
|
108 { |
|
109 AddItemL(aViewer, R_QTN_SM_CAL_TYPELABEL, R_QTN_SM_CAL_TYPE_ANNIV); |
|
110 AddItemL(aViewer, R_QTN_SM_CAL_ANNIVERS_SUBJECT, *iSummaryDescr); |
|
111 AddItemAsDateL(aViewer, R_QTN_SM_CAL_ANNIVERS_DATE, aStartTime); |
|
112 AddAlarmInfoL(aViewer); |
|
113 } |
|
114 |
|
115 void CVCalBcDataFiller::AddMeetingSpecificInfoL( |
|
116 CRichBio& aViewer, |
|
117 const TTime& aStartTime, |
|
118 const TTime& aEndTime) |
|
119 { |
|
120 AddItemL(aViewer, R_QTN_SM_CAL_TYPELABEL, R_QTN_SM_CAL_TYPE_MEETING); |
|
121 AddItemL(aViewer, R_QTN_SM_CAL_MEETING_SUBJECT, *iSummaryDescr); |
|
122 if (iEntry.LocationL().Length() > 0) |
|
123 { |
|
124 AddItemL(aViewer, R_QTN_SM_CAL_MEETING_LOCATION, iEntry.LocationL()); |
|
125 } |
|
126 AddItemAsDateL(aViewer, R_QTN_SM_CAL_STARTDATE, aStartTime); |
|
127 AddItemAsTimeL(aViewer, R_QTN_SM_CAL_MEETING_START_TIME, aStartTime); |
|
128 AddItemAsDateL(aViewer, R_QTN_SM_CAL_ENDDATE, aEndTime); |
|
129 AddItemAsTimeL(aViewer, R_QTN_SM_CAL_MEETING_END_TIME, aEndTime); |
|
130 AddAlarmInfoL(aViewer); |
|
131 AddRepeatInfoL(aViewer); |
|
132 } |
|
133 |
|
134 void CVCalBcDataFiller::AddDaynoteSpecificInfoL( |
|
135 CRichBio& aViewer, |
|
136 const TTime& aStartTime, |
|
137 const TTime& aEndTime) |
|
138 { |
|
139 AddItemL(aViewer, R_QTN_SM_CAL_TYPELABEL, R_QTN_SM_CAL_TYPE_DAYNOTE); |
|
140 AddItemL(aViewer, R_QTN_SM_CAL_DAY_NOTE_SUBJECT, *iSummaryDescr); |
|
141 |
|
142 TInt duration = aEndTime.DaysFrom(aStartTime).Int(); |
|
143 |
|
144 if(duration > 0) |
|
145 duration--; |
|
146 TTimeIntervalDays offset(duration); |
|
147 |
|
148 TTime endTime(aStartTime); |
|
149 endTime += offset; |
|
150 AddItemAsDateL(aViewer, R_QTN_SM_CAL_STARTDATE, aStartTime); |
|
151 AddItemAsDateL(aViewer, R_QTN_SM_CAL_ENDDATE, endTime); |
|
152 AddRepeatInfoL(aViewer); |
|
153 } |
|
154 |
|
155 void CVCalBcDataFiller::AddVTodoSpecificInfoL(CRichBio& aViewer) |
|
156 { |
|
157 AddVTodoTypeInfoL(aViewer); |
|
158 AddVTodoSubjectInfoL(aViewer); |
|
159 AddVTodoDueDateInfoL(aViewer); |
|
160 AddVTodoAlarmInfoL(aViewer); |
|
161 AddVTodoPriorityInfoL(aViewer); |
|
162 } |
|
163 |
|
164 void CVCalBcDataFiller::AddAlarmInfoL( |
|
165 CRichBio& aViewer) |
|
166 { |
|
167 CCalAlarm* alarm = iEntry.AlarmL(); |
|
168 if ( alarm ) |
|
169 { |
|
170 CleanupStack::PushL( alarm ); |
|
171 TTime alarmTime(iEntry.StartTimeL().TimeLocalL()); |
|
172 |
|
173 alarmTime -= alarm->TimeOffset(); |
|
174 AddItemAsTimeL(aViewer, R_QTN_SM_CAL_EVENT_ALARM_TIME, alarmTime ); |
|
175 AddItemAsDateL(aViewer, R_QTN_SM_CAL_EVENT_ALARM_DATE, alarmTime ); |
|
176 CleanupStack::PopAndDestroy( alarm ); |
|
177 } |
|
178 } |
|
179 |
|
180 |
|
181 void CVCalBcDataFiller::AddRepeatInfoL(CRichBio& aViewer) |
|
182 { |
|
183 TCalRRule repeatRule;//( TCalRRule::EInvalid ); |
|
184 if( !iEntry.GetRRuleL (repeatRule) ) |
|
185 { |
|
186 return; |
|
187 } |
|
188 TInt valueRes = RepeatIndexValueTextRes( repeatRule ); |
|
189 if( valueRes ) |
|
190 { |
|
191 AddItemL(aViewer, R_QTN_SM_CAL_MEETING_REPEAT, valueRes); |
|
192 TTime endtime = repeatRule.Until().TimeLocalL(); |
|
193 AddItemAsDateL( aViewer, R_QTN_SM_CAL_MEETING_REPEAT_UNTIL, endtime ); |
|
194 } |
|
195 } |
|
196 |
|
197 |
|
198 TInt CVCalBcDataFiller::RepeatIndexValueTextRes(TCalRRule aRepeatRule ) const |
|
199 { |
|
200 TInt res = 0; |
|
201 |
|
202 switch( aRepeatRule.Type() ) |
|
203 { |
|
204 case TCalRRule::EInvalid: |
|
205 { |
|
206 // No repeat value |
|
207 break; |
|
208 } |
|
209 case TCalRRule::EDaily: |
|
210 { |
|
211 res = R_QTN_SM_CAL_MEETING_RPT_DAILY; |
|
212 break; |
|
213 } |
|
214 case TCalRRule::EWeekly: |
|
215 { |
|
216 if( aRepeatRule.Interval() == KRepeatIntervalBiWeekly ) |
|
217 { |
|
218 res = R_QTN_SM_CAL_MEETING_RPT_BIWEEKLY; |
|
219 } |
|
220 else |
|
221 { |
|
222 res = R_QTN_SM_CAL_MEETING_RPT_WEEKLY; |
|
223 } |
|
224 break; |
|
225 } |
|
226 case TCalRRule::EMonthly: |
|
227 { |
|
228 res = R_QTN_SM_CAL_MEETING_RPT_MONTHLY; |
|
229 break; |
|
230 } |
|
231 case TCalRRule::EYearly: |
|
232 { |
|
233 res = R_QTN_SM_CAL_MEETING_RPT_YEARLY; |
|
234 break; |
|
235 } |
|
236 default: |
|
237 { |
|
238 // Unexpected repeat index value |
|
239 __ASSERT_DEBUG(res, Panic(EVCalBCPanicUndefinedRepeatIndex)); |
|
240 res = R_QTN_SM_CAL_RPT_OTHER; |
|
241 break; |
|
242 } |
|
243 } |
|
244 return res; |
|
245 } |
|
246 |
|
247 |
|
248 void CVCalBcDataFiller::AddConfidentialityInfoL(CRichBio& aViewer) |
|
249 { |
|
250 CCalEntry::TReplicationStatus status = iEntry.ReplicationStatusL(); |
|
251 // TAgnReplicationData::TStatus status = replicationData.Status(); |
|
252 TInt valueRes = 0; |
|
253 if (status == CCalEntry::EOpen) |
|
254 { |
|
255 valueRes = R_QTN_SM_CAL_SYNC_PUBLIC; |
|
256 } |
|
257 else if (status == CCalEntry::EPrivate) |
|
258 { |
|
259 valueRes = R_QTN_SM_CAL_SYNC_PRIVATE; |
|
260 } |
|
261 else if (status == CCalEntry::ERestricted) |
|
262 { |
|
263 valueRes = R_QTN_SM_CAL_SYNC_NO_SYNC; |
|
264 } |
|
265 __ASSERT_DEBUG(valueRes, Panic(EInvalidConfid)); |
|
266 AddItemL(aViewer, R_QTN_SM_CAL_SYNCHRONISATION, valueRes); |
|
267 } |
|
268 |
|
269 |
|
270 void CVCalBcDataFiller::AddDescriptionInfoL(CRichBio& aViewer) |
|
271 { |
|
272 const TDesC& descData = iEntry.DescriptionL(); |
|
273 if ( descData.Length() != 0 ) |
|
274 { |
|
275 AddItemL(aViewer, R_QTN_SM_CAL_MEETING_DESCRIPTION, descData); |
|
276 } |
|
277 } |
|
278 |
|
279 |
|
280 HBufC* CVCalBcDataFiller::TextContentsFromEntryL(CCalEntry& aEntry) |
|
281 { |
|
282 HBufC* text = aEntry.SummaryL().AllocL(); |
|
283 /*TPtr textPtr(text->Des()); |
|
284 // Copy the text from richtext to descriptor: |
|
285 aEntry.RichTextL()->Extract(textPtr, 0, |
|
286 aEntry.RichTextL()->DocumentLength()); |
|
287 CleanupStack::Pop(text);*/ |
|
288 return text; |
|
289 } |
|
290 |
|
291 void CVCalBcDataFiller::AddItemL(CRichBio& aViewer, TInt aLabelRes, |
|
292 const TDesC& aValue) |
|
293 { |
|
294 // Empty fields are not shown. |
|
295 if (aValue.Length()) |
|
296 { |
|
297 aViewer.AddItemL(*StringLoader::LoadLC(aLabelRes, &iCoeEnv), aValue); |
|
298 CleanupStack::PopAndDestroy(); // (label text) |
|
299 } |
|
300 } |
|
301 |
|
302 void CVCalBcDataFiller::AddItemL(CRichBio& aViewer, TInt aLabelRes, |
|
303 TInt aValueRes) |
|
304 { |
|
305 aViewer.AddItemL( |
|
306 *StringLoader::LoadLC(aLabelRes, &iCoeEnv), |
|
307 *StringLoader::LoadLC(aValueRes, &iCoeEnv)); |
|
308 CleanupStack::PopAndDestroy(2); // (label and value text) |
|
309 } |
|
310 |
|
311 void CVCalBcDataFiller::AddItemAsDateL(CRichBio& aViewer, |
|
312 TInt aLabelRes, |
|
313 const TTime& aTime) |
|
314 { |
|
315 if(aTime != Time::NullTTime()) |
|
316 { |
|
317 TBuf<KMaxDateTimeTextLength> tmpString; |
|
318 aTime.FormatL(tmpString, *iDateFormat); |
|
319 AddItemL(aViewer, aLabelRes, tmpString); |
|
320 } |
|
321 } |
|
322 |
|
323 void CVCalBcDataFiller::AddItemAsTimeL(CRichBio& aViewer, |
|
324 TInt aLabelRes, |
|
325 const TTime& aTime) |
|
326 { |
|
327 if(aTime != Time::NullTTime()) |
|
328 { |
|
329 TBuf<KMaxDateTimeTextLength> tmpString; |
|
330 aTime.FormatL(tmpString, *iTimeFormat); |
|
331 AddItemL(aViewer, aLabelRes, tmpString); |
|
332 } |
|
333 } |
|
334 |
|
335 CVCalBcDataFiller* CVCalBcDataFiller::NewLC(CCalEntry& aEntry, CCoeEnv& aCoeEnv) |
|
336 { |
|
337 __ASSERT_DEBUG(&aEntry != NULL, Panic(ENullEntryGivenToFiller)); |
|
338 CVCalBcDataFiller* self = new (ELeave)CVCalBcDataFiller(aEntry, aCoeEnv); |
|
339 CleanupStack::PushL(self); |
|
340 self->ConstructL(); |
|
341 return self; |
|
342 } |
|
343 |
|
344 CVCalBcDataFiller::CVCalBcDataFiller(CCalEntry& aEntry, CCoeEnv& aCoeEnv) |
|
345 : iCoeEnv(aCoeEnv), iEntry(aEntry) |
|
346 { |
|
347 } |
|
348 |
|
349 void CVCalBcDataFiller::ConstructL() |
|
350 { |
|
351 iDateFormat = StringLoader::LoadL(R_QTN_DATE_USUAL_WITH_ZERO, &iCoeEnv); |
|
352 iTimeFormat = StringLoader::LoadL(R_QTN_TIME_USUAL, &iCoeEnv); |
|
353 //Get the text field contents. It is needed for all four types of entry. |
|
354 iSummaryDescr = TextContentsFromEntryL(iEntry); |
|
355 } |
|
356 |
|
357 void CVCalBcDataFiller::AddVTodoTypeInfoL(CRichBio& aViewer) |
|
358 { |
|
359 AddItemL(aViewer, R_QTN_SM_CAL_TYPELABEL, R_QTN_SM_CAL_TYPE_TODO); |
|
360 } |
|
361 |
|
362 void CVCalBcDataFiller::AddVTodoSubjectInfoL(CRichBio& aViewer) |
|
363 { |
|
364 AddItemL(aViewer, R_QTN_SM_TODO_SUBJECT, *iSummaryDescr); |
|
365 } |
|
366 |
|
367 void CVCalBcDataFiller::AddVTodoDueDateInfoL(CRichBio& aViewer) |
|
368 { |
|
369 TTime dueDate(Time::NullTTime()); |
|
370 TRAP_IGNORE((dueDate = iEntry.EndTimeL().TimeLocalL())); |
|
371 AddItemAsDateL(aViewer, R_QTN_SM_TODO_DUE_DATE, dueDate); |
|
372 } |
|
373 |
|
374 void CVCalBcDataFiller::AddVTodoAlarmInfoL(CRichBio& aViewer) |
|
375 { |
|
376 CCalAlarm* alarm = iEntry.AlarmL(); |
|
377 |
|
378 if( alarm ) |
|
379 { |
|
380 CleanupStack::PushL(alarm); |
|
381 TTime alarmTime(iEntry.EndTimeL().TimeLocalL()); |
|
382 |
|
383 alarmTime -= alarm->TimeOffset(); |
|
384 AddItemAsTimeL(aViewer, R_QTN_SM_CAL_EVENT_ALARM_TIME, alarmTime ); |
|
385 AddItemAsDateL(aViewer, R_QTN_SM_CAL_EVENT_ALARM_DATE, alarmTime ); |
|
386 CleanupStack::PopAndDestroy(alarm); |
|
387 } |
|
388 |
|
389 |
|
390 } |
|
391 |
|
392 void CVCalBcDataFiller::AddVTodoPriorityInfoL(CRichBio& aViewer) |
|
393 { |
|
394 TUint todoPriority = iEntry.PriorityL(); |
|
395 |
|
396 TInt priorityString( 0 ); |
|
397 |
|
398 if (todoPriority == 1 ) |
|
399 { |
|
400 priorityString = R_QTN_SM_TODO_PRIORITY_HIGH; |
|
401 } |
|
402 else if (todoPriority == 2) |
|
403 { |
|
404 priorityString = R_QTN_SM_TODO_PRIORITY_NORMAL; |
|
405 } |
|
406 else if (todoPriority == 3) |
|
407 { |
|
408 priorityString = R_QTN_SM_TODO_PRIORITY_LOW; |
|
409 } |
|
410 |
|
411 if( todoPriority >= 1 && todoPriority <= 3 ) |
|
412 AddItemL(aViewer, R_QTN_SM_TODO_PRIORITY, priorityString); |
|
413 |
|
414 } |
|
415 |
|
416 // end of file |
|
417 |