|
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: Helper tool to get alarm and repeat data of Calendar note. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //debug |
|
21 #include "calendarui_debug.h" |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include "calennotedatautil.h" |
|
25 #include "calendar.hrh" |
|
26 |
|
27 #include <calencommonui.rsg> |
|
28 |
|
29 #include <StringLoader.h> |
|
30 #include <aknPopup.h> |
|
31 #include <pathinfo.h> |
|
32 #include <aknlists.h> |
|
33 #include <bautils.h> |
|
34 #include <calrrule.h> |
|
35 #include <calalarm.h> |
|
36 #include <calentry.h> |
|
37 #include <data_caging_path_literals.hrh> |
|
38 |
|
39 // Constants |
|
40 #define KNoOfDaysInWeek 7 |
|
41 |
|
42 // ================= MEMBER FUNCTIONS ======================= |
|
43 // --------------------------------------------------------- |
|
44 // CalenNoteDataUtil::RepeatIndexL |
|
45 // Return index of repeat type |
|
46 // (other items were commented in a header). |
|
47 // --------------------------------------------------------- |
|
48 // |
|
49 EXPORT_C TCalenRepeatIndex CalenNoteDataUtil::RepeatIndexL(const CCalEntry& aEntry) |
|
50 { |
|
51 TRACE_ENTRY_POINT; |
|
52 |
|
53 TCalenRepeatIndex repeatIndex( ERepeatNotRepeated ); |
|
54 |
|
55 TCalRRule rrule; |
|
56 |
|
57 if( aEntry.GetRRuleL( rrule) ) |
|
58 { |
|
59 TCalRRule::TType type( rrule.Type() ); |
|
60 TInt repeatInterval( rrule.Interval() ); |
|
61 |
|
62 // If repeat type of current note is not supported in Calendar, |
|
63 // default repeat value is "Other". |
|
64 repeatIndex = ERepeatOther; |
|
65 |
|
66 switch( type ) |
|
67 { |
|
68 case TCalRRule::EDaily: |
|
69 { |
|
70 switch (repeatInterval) |
|
71 { |
|
72 case 1: repeatIndex = ERepeatDaily; break; |
|
73 case 7: repeatIndex = ERepeatWeekly; break; |
|
74 case 14: repeatIndex = ERepeatBiWeekly; break; |
|
75 default: break; |
|
76 } |
|
77 break; |
|
78 } |
|
79 |
|
80 case TCalRRule::EWeekly: |
|
81 { |
|
82 |
|
83 TBool status = IsWorkdaysRepeatingL(rrule); |
|
84 |
|
85 if(status) |
|
86 { |
|
87 repeatIndex = ERepeatWorkdays ; |
|
88 } |
|
89 else |
|
90 { |
|
91 switch( repeatInterval ) |
|
92 { |
|
93 case 1: repeatIndex = ERepeatWeekly; break; |
|
94 case 2: repeatIndex = ERepeatBiWeekly; break; |
|
95 default: break; |
|
96 } |
|
97 } |
|
98 |
|
99 break; |
|
100 } |
|
101 |
|
102 case TCalRRule::EMonthly: |
|
103 { |
|
104 RArray<TInt> monthDays(31); |
|
105 rrule.GetByMonthDayL ( monthDays ); |
|
106 |
|
107 if( monthDays.Count() == 1) // FIXME: AL - is this necessary? |
|
108 { |
|
109 switch( repeatInterval ) |
|
110 { |
|
111 case 1: repeatIndex = ERepeatMonthly; break; |
|
112 // If interval of repeat is 12 months, |
|
113 // every year is shown in Note Editor, |
|
114 // because it means yearly repeat. |
|
115 case 12: repeatIndex = ERepeatYearly; break; |
|
116 default: break; |
|
117 } |
|
118 } |
|
119 |
|
120 monthDays.Close(); |
|
121 |
|
122 break; |
|
123 } |
|
124 case TCalRRule::EYearly: |
|
125 { |
|
126 if( repeatInterval == 1 ) |
|
127 { |
|
128 repeatIndex = ERepeatYearly; |
|
129 } |
|
130 break; |
|
131 } |
|
132 |
|
133 default: |
|
134 { |
|
135 // If repeat type of current note is not supported in Calendar, |
|
136 // default repeat value is "Other". |
|
137 repeatIndex = ERepeatOther; |
|
138 break; |
|
139 } |
|
140 } |
|
141 } |
|
142 |
|
143 TRACE_EXIT_POINT; |
|
144 return repeatIndex; |
|
145 } |
|
146 // --------------------------------------------------------- |
|
147 // CalenNoteDataUtil::GetAlarmDateTimeL |
|
148 // If note has alarm, alarm time is set to aAlarmDateTime |
|
149 // and return ETrue. aAlarmDateTime has dd/mm/yy, hh:mm part, |
|
150 // E.g. 15/Sep/2002, 13:00. |
|
151 // If note has no alarm, aAlarmDateTime is not changed |
|
152 // and return EFalse. |
|
153 // (other items were commented in a header). |
|
154 // --------------------------------------------------------- |
|
155 // |
|
156 EXPORT_C TBool CalenNoteDataUtil::GetAlarmDateTimeL(const CCalEntry& aEntry, TTime& aAlarmDateTime) |
|
157 { |
|
158 TRACE_ENTRY_POINT; |
|
159 |
|
160 TBool ret( EFalse ); |
|
161 // FIXME: leaving! |
|
162 CCalAlarm* alarm = aEntry.AlarmL(); |
|
163 |
|
164 if( alarm ) |
|
165 { |
|
166 CleanupStack::PushL( alarm ); |
|
167 ret = ETrue; |
|
168 |
|
169 switch( aEntry.EntryTypeL() ) |
|
170 { |
|
171 case CCalEntry::ETodo: |
|
172 aAlarmDateTime = aEntry.EndTimeL().TimeLocalL(); |
|
173 break; |
|
174 |
|
175 case CCalEntry::EAppt: |
|
176 case CCalEntry::EEvent: |
|
177 case CCalEntry::EAnniv: |
|
178 default: |
|
179 aAlarmDateTime = aEntry.StartTimeL().TimeLocalL(); |
|
180 break; |
|
181 } |
|
182 aAlarmDateTime -= alarm->TimeOffset(); |
|
183 |
|
184 CleanupStack::PopAndDestroy( alarm ); |
|
185 } |
|
186 |
|
187 TRACE_EXIT_POINT; |
|
188 return ret; |
|
189 } |
|
190 |
|
191 // ---------------------------------------------------------------------------- |
|
192 // CalenNoteDataUtil::ShowRepeatTypeQueryL |
|
193 // Shows a query asking the user to choose the repeat type. |
|
194 // (other items were commented in a header). |
|
195 // ---------------------------------------------------------------------------- |
|
196 // |
|
197 EXPORT_C TBool CalenNoteDataUtil::ShowRepeatTypeQueryL( CalCommon::TRecurrenceRange& aAnswer, |
|
198 const TRepeatQueryType aType ) |
|
199 { |
|
200 TRACE_ENTRY_POINT; |
|
201 |
|
202 CAknSinglePopupMenuStyleListBox* list = new( ELeave )CAknSinglePopupMenuStyleListBox; |
|
203 CleanupStack::PushL( list ); |
|
204 CAknPopupList* popupList = CAknPopupList::NewL( list, R_AVKON_SOFTKEYS_OK_CANCEL ); |
|
205 CleanupStack::PushL( popupList ); |
|
206 |
|
207 list->ConstructL( popupList, CEikListBox::ELeftDownInViewRect ); |
|
208 list->CreateScrollBarFrameL(ETrue); |
|
209 list->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
210 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
211 |
|
212 CEikonEnv* eikEnv = CEikonEnv::Static(); |
|
213 CDesCArrayFlat* items = eikEnv->ReadDesCArrayResourceL( aType == EEdit ? |
|
214 R_CALEN_COMMONUI_REPEATNOTE_EDIT_CHOICELIST : |
|
215 R_CALEN_COMMONUI_REPEATNOTE_CHOICELIST ); |
|
216 CTextListBoxModel* model = list->Model(); |
|
217 model->SetItemTextArray( items ); |
|
218 |
|
219 TInt resID(0); |
|
220 |
|
221 switch( aType ) |
|
222 { |
|
223 case ESave: |
|
224 resID = R_CALEN_COMMONUI_QTN_CALE_LQ_SAVE_CHANG_REPEATED; |
|
225 break; |
|
226 case EEdit: |
|
227 resID = R_CALEN_COMMONUI_QTN_CALE_LQ_EDIT_RECURRING; |
|
228 break; |
|
229 default: |
|
230 User::Leave( KErrArgument ); |
|
231 break; |
|
232 } |
|
233 |
|
234 HBufC* title = StringLoader::LoadLC( resID, eikEnv ); |
|
235 popupList->SetTitleL( *title ); |
|
236 CleanupStack::PopAndDestroy( title ); |
|
237 |
|
238 TBool ret( ETrue ); |
|
239 |
|
240 if( popupList->ExecuteLD() ) |
|
241 { |
|
242 const TInt selected( list->CurrentItemIndex() ); |
|
243 |
|
244 switch( selected ) |
|
245 { |
|
246 case ECalenRepeatThis: |
|
247 aAnswer = CalCommon::EThisOnly; |
|
248 break; |
|
249 case ECalenRepeatThisFuture: |
|
250 aAnswer = CalCommon::EThisAndFuture; |
|
251 break; |
|
252 case ECalenRepeatThisPast: |
|
253 aAnswer = CalCommon::EThisAndPrior; |
|
254 break; |
|
255 case ECalenRepeatAll: |
|
256 aAnswer = CalCommon::EThisAndAll; |
|
257 break; |
|
258 default: |
|
259 ASSERT( EFalse ); |
|
260 break; |
|
261 } |
|
262 } |
|
263 else |
|
264 { |
|
265 ret = EFalse; |
|
266 } |
|
267 |
|
268 CleanupStack::Pop( popupList ); |
|
269 CleanupStack::PopAndDestroy( list ); |
|
270 |
|
271 TRACE_EXIT_POINT; |
|
272 return ret; |
|
273 } |
|
274 // --------------------------------------------------------- |
|
275 // CalenNoteDataUtil::IsWorkdaysRepeatingL |
|
276 // (other items were commented in a header). |
|
277 // --------------------------------------------------------- |
|
278 // |
|
279 EXPORT_C TBool CalenNoteDataUtil::IsWorkdaysRepeatingL(const TCalRRule aRrule) |
|
280 { |
|
281 TRACE_ENTRY_POINT; |
|
282 TBool status = ETrue; |
|
283 TInt fixedNum = 1; |
|
284 TInt ruleday = 0; |
|
285 TLocale locale; |
|
286 TUint workDays = locale.WorkDays(); |
|
287 |
|
288 RArray<TDay> weekDays(KNoOfDaysInWeek); |
|
289 aRrule.GetByDayL( weekDays ); |
|
290 |
|
291 RArray<TDay> dayArray; |
|
292 CleanupClosePushL(dayArray); |
|
293 |
|
294 // "workDays" is a bit mask of seven bits indicating (by being set) which days are workdays. |
|
295 // The least significant bit corresponds to Monday, the next bit to Tuesday and so on. |
|
296 // "workDays" is converted into RArray for comparing with "weekDays". |
|
297 for (TInt i =0 ; i < KNoOfDaysInWeek ; i++) |
|
298 { |
|
299 ruleday = fixedNum << i; |
|
300 if(workDays & ruleday) |
|
301 { |
|
302 dayArray.Append((TDay)i); |
|
303 } |
|
304 } |
|
305 |
|
306 // Checks whether the device "workdays" are same as the event's repeat days. |
|
307 if( weekDays.Count() == dayArray.Count()) |
|
308 { |
|
309 for(TInt i=0 ; i< dayArray.Count() ; i++) |
|
310 { |
|
311 if((TInt)dayArray[i] != (TInt)weekDays[i]) |
|
312 { |
|
313 status = EFalse; |
|
314 break; |
|
315 } |
|
316 } |
|
317 } |
|
318 else |
|
319 { |
|
320 status = EFalse; |
|
321 } |
|
322 CleanupStack::PopAndDestroy(&dayArray); |
|
323 weekDays.Close(); |
|
324 |
|
325 TRACE_EXIT_POINT; |
|
326 return status; |
|
327 } |
|
328 |
|
329 // End of file |