|
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: Implementation of UI utils |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <calencommonui.rsg> |
|
20 #include <Calendar.rsg> |
|
21 #include <calenagendautils.h> |
|
22 #include <aknlists.h> |
|
23 #include <aknnotewrappers.h> |
|
24 #include <AknQueryDialog.h> |
|
25 #include <AknUtils.h> |
|
26 #include <calalarm.h> |
|
27 #include <calentry.h> |
|
28 #include <calentryview.h> |
|
29 #include <ErrorUI.h> |
|
30 #include <StringLoader.h> |
|
31 #include <sysutil.h> |
|
32 #include <calentry.h> |
|
33 #include <calinstance.h> |
|
34 #include <calinstanceview.h> |
|
35 #include <calencommands.hrh> // Calendar commands |
|
36 #include <calendateutils.h> |
|
37 #include <caleninstanceid.h> // TCalenInstanceId |
|
38 #include <calenactionuiutils.h> |
|
39 |
|
40 #include "calendarui_debug.h" // Debug |
|
41 #include "calendar.hrh" |
|
42 #include "calenicons.h" |
|
43 #include "calenglobaldata.h" |
|
44 #include "CalenInterimUtils2.h" |
|
45 #include "CleanupResetAndDestroy.h" |
|
46 |
|
47 // Constants |
|
48 const TInt KArrayGranularity = 5; |
|
49 |
|
50 // ---------------------------------------------------------------------------- |
|
51 // CalenActionUiUtils::ShowDeleteConfirmationQueryL |
|
52 // Shows a delete confirmation query. |
|
53 // (other items were commented in a header). |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 EXPORT_C TInt CalenActionUiUtils::ShowDeleteConfirmationQueryL( |
|
57 const TDeleteConfirmationType aType, |
|
58 const TInt aCount ) |
|
59 { |
|
60 TRACE_ENTRY_POINT; |
|
61 |
|
62 CAknQueryDialog* dialog = CAknQueryDialog::NewL(); |
|
63 CleanupStack::PushL( dialog ); |
|
64 |
|
65 TInt resID( 0 ); |
|
66 |
|
67 switch( aType ) |
|
68 { |
|
69 case EDeleteEntry: |
|
70 resID = R_CALEN_COMMONUI_QTN_CALE_QUEST_DELETE_EVENT; |
|
71 break; |
|
72 case EDeleteToDo: |
|
73 resID = R_CALEN_COMMONUI_QTN_TODO_QUEST_DELETE_NOTE; |
|
74 break; |
|
75 case EDeleteToDos: |
|
76 resID = R_CALEN_COMMONUI_QTN_TODO_QUEST_DELETE_NOTES; |
|
77 break; |
|
78 case EDeleteAll: |
|
79 resID = R_CALEN_COMMONUI_QTN_CALE_QUEST_DELETE_ALL_NOTES; |
|
80 break; |
|
81 default: |
|
82 User::Leave( KErrArgument ); |
|
83 break; |
|
84 } |
|
85 |
|
86 HBufC* prompt; |
|
87 |
|
88 // if >1 event to be deleted, load multi-deletion confirmation string |
|
89 if( aCount > 1 ) |
|
90 { |
|
91 prompt = StringLoader::LoadLC( resID, aCount ); |
|
92 } |
|
93 // otherwise load common deletion confirmation string |
|
94 else |
|
95 { |
|
96 prompt = StringLoader::LoadLC( resID ); |
|
97 } |
|
98 |
|
99 dialog->SetPromptL( *prompt ); |
|
100 CleanupStack::PopAndDestroy( prompt ); |
|
101 |
|
102 CleanupStack::Pop( dialog ); |
|
103 |
|
104 TRACE_EXIT_POINT; |
|
105 return dialog->ExecuteLD( R_CALEN_COMMONUI_ERASEQUERY_NOTE ); |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------------------------------- |
|
109 // CalenActionUiUtils::ShowRepeatTypeQueryL |
|
110 // Shows a query asking the user to choose the repeat type. |
|
111 // (other items were commented in a header). |
|
112 // ---------------------------------------------------------------------------- |
|
113 // |
|
114 EXPORT_C TBool CalenActionUiUtils::ShowRepeatTypeQueryL( |
|
115 CalCommon::TRecurrenceRange& aAnswer, |
|
116 const TRepeatQueryType aType ) |
|
117 { |
|
118 TRACE_ENTRY_POINT; |
|
119 |
|
120 CAknSinglePopupMenuStyleListBox* list; |
|
121 list = new( ELeave ) CAknSinglePopupMenuStyleListBox; |
|
122 CleanupStack::PushL( list ); |
|
123 |
|
124 CAknPopupList* popupList; |
|
125 popupList = CAknPopupList::NewL( list, R_AVKON_SOFTKEYS_OK_CANCEL ); |
|
126 CleanupStack::PushL( popupList ); |
|
127 |
|
128 list->ConstructL( popupList, CEikListBox::ELeftDownInViewRect ); |
|
129 list->CreateScrollBarFrameL(ETrue); |
|
130 list->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, |
|
131 CEikScrollBarFrame::EAuto ); |
|
132 CEikonEnv* eikEnv = CEikonEnv::Static(); |
|
133 |
|
134 CDesCArrayFlat* items = eikEnv->ReadDesCArrayResourceL( aType == EEdit ? |
|
135 R_CALEN_COMMONUI_REPEATNOTE_EDIT_CHOICELIST : |
|
136 R_CALEN_COMMONUI_REPEATNOTE_CHOICELIST ); |
|
137 CTextListBoxModel* model = list->Model(); |
|
138 model->SetItemTextArray( items ); |
|
139 |
|
140 TInt resID( 0 ); |
|
141 |
|
142 switch( aType ) |
|
143 { |
|
144 case ESave: |
|
145 resID = R_CALEN_COMMONUI_QTN_CALE_LQ_SAVE_CHANG_REPEATED; |
|
146 break; |
|
147 case EDelete: |
|
148 resID = R_CALEN_COMMONUI_QTN_CALE_LQ_DEL_REPEATED_NOTE; |
|
149 break; |
|
150 case EEdit: |
|
151 resID = R_CALEN_COMMONUI_QTN_CALE_LQ_EDIT_RECURRING; |
|
152 break; |
|
153 default: |
|
154 User::Leave( KErrArgument ); |
|
155 break; |
|
156 } |
|
157 |
|
158 HBufC* title = StringLoader::LoadLC( resID, eikEnv ); |
|
159 popupList->SetTitleL( *title ); |
|
160 CleanupStack::PopAndDestroy( title ); |
|
161 |
|
162 TBool ret( ETrue ); |
|
163 |
|
164 if( popupList->ExecuteLD() ) |
|
165 { |
|
166 const TInt selected( list->CurrentItemIndex() ); |
|
167 |
|
168 switch( selected ) |
|
169 { |
|
170 case ECalenRepeatThis: |
|
171 aAnswer = CalCommon::EThisOnly; |
|
172 break; |
|
173 case ECalenRepeatThisFuture: |
|
174 aAnswer = CalCommon::EThisAndFuture; |
|
175 break; |
|
176 case ECalenRepeatThisPast: |
|
177 aAnswer = CalCommon::EThisAndPrior; |
|
178 break; |
|
179 case ECalenRepeatAll: |
|
180 aAnswer = CalCommon::EThisAndAll; |
|
181 break; |
|
182 default: |
|
183 ASSERT( EFalse ); |
|
184 break; |
|
185 } |
|
186 } |
|
187 else |
|
188 { |
|
189 ret = EFalse; |
|
190 } |
|
191 |
|
192 CleanupStack::Pop( popupList ); |
|
193 CleanupStack::PopAndDestroy( list ); |
|
194 |
|
195 TRACE_EXIT_POINT; |
|
196 return ret; |
|
197 } |
|
198 |
|
199 // ---------------------------------------------------------------------------- |
|
200 // CalenActionUiUtils::DateQueryL |
|
201 // Prompts the user for a time. Requires a title resource id, or pass 0 |
|
202 // for default title "Date:". |
|
203 // (other items were commented in a header). |
|
204 // ---------------------------------------------------------------------------- |
|
205 // |
|
206 EXPORT_C TInt CalenActionUiUtils::DateQueryL( TTime& aDate, TInt aPromptId ) |
|
207 { |
|
208 TRACE_ENTRY_POINT; |
|
209 |
|
210 if ( aPromptId == 0 ) |
|
211 { |
|
212 aPromptId = R_CALEN_DATE_PROMPT; |
|
213 } |
|
214 |
|
215 CAknTimeQueryDialog* dlg = CAknTimeQueryDialog::NewL( aDate, |
|
216 CAknQueryDialog::ENoTone ); |
|
217 CleanupStack::PushL( dlg ); |
|
218 |
|
219 HBufC* prompt = StringLoader::LoadLC( aPromptId, CEikonEnv::Static() ); |
|
220 dlg->SetPromptL( *prompt ); |
|
221 CleanupStack::PopAndDestroy( prompt ); |
|
222 |
|
223 CleanupStack::Pop(); // dlg |
|
224 |
|
225 TRACE_EXIT_POINT; |
|
226 return dlg->ExecuteLD( R_CALEN_DAYQUERY_NOTE ); |
|
227 } |
|
228 |
|
229 // ---------------------------------------------------------------------------- |
|
230 // CalenActionUiUtils::SetToDoCompleteStatusL |
|
231 // Mark to-do entry as completed or restore a completed to-do and save. |
|
232 // This is not in the engine layer because it shows an error mesage on failure. |
|
233 // (other items were commented in a header). |
|
234 // ---------------------------------------------------------------------------- |
|
235 // |
|
236 EXPORT_C void CalenActionUiUtils::SetToDoCompleteStatusL( |
|
237 CCalEntryView& aEntryView, |
|
238 CCalEntry* aEntry, |
|
239 const TBool aStatus ) |
|
240 { |
|
241 TRACE_ENTRY_POINT; |
|
242 |
|
243 ASSERT( aEntry ); |
|
244 TTime now; |
|
245 now.HomeTime(); |
|
246 TCalTime caltime; |
|
247 caltime.SetTimeLocalL( now ); |
|
248 |
|
249 // set as completed or restore |
|
250 aEntry->SetCompletedL( aStatus, caltime ); |
|
251 |
|
252 // Save the to-do |
|
253 TInt error( 0 ); |
|
254 CEikonEnv* eikenv = CEikonEnv::Static(); |
|
255 |
|
256 // Check disk space of C drive. |
|
257 const TInt writesize( 512 ); // Write size |
|
258 |
|
259 if( SysUtil::FFSSpaceBelowCriticalLevelL( &( eikenv->FsSession() ), writesize ) ) |
|
260 { |
|
261 CErrorUI* errorui = CErrorUI::NewLC(); |
|
262 errorui->ShowGlobalErrorNoteL( KErrDiskFull ); |
|
263 CleanupStack::PopAndDestroy(); |
|
264 TRACE_EXIT_POINT; |
|
265 return; |
|
266 } |
|
267 |
|
268 RPointerArray<CCalEntry> list; |
|
269 CleanupClosePushL( list ); |
|
270 |
|
271 TInt entrynum; |
|
272 |
|
273 // update entry |
|
274 list.Append( aEntry ); |
|
275 TRAP( error, aEntryView.UpdateL( list, entrynum ) ); |
|
276 |
|
277 if( error == KErrNotFound ) |
|
278 { |
|
279 // entry was deleted...? |
|
280 list.Reset(); |
|
281 list.Append( aEntry ); |
|
282 TRAP( error, aEntryView.StoreL( list, entrynum ) ); |
|
283 } |
|
284 CleanupStack::PopAndDestroy( &list ); |
|
285 User::LeaveIfError( error ); |
|
286 |
|
287 TRACE_EXIT_POINT; |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // CCalenCommonUI::PrepareLbDataForNewNotesQueryL |
|
292 // Prepares ListBox items for NewEntry query |
|
293 // (other items were commented in a header). |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 void CalenActionUiUtils::PrepareLbDataForNewNotesQueryL( |
|
297 CDesCArrayFlat*& aListItems, |
|
298 CArrayFixFlat<TInt>*& aListItemCommands ) |
|
299 { |
|
300 TRACE_ENTRY_POINT; |
|
301 |
|
302 if( ( aListItems == NULL ) && ( aListItemCommands == NULL) ) |
|
303 { |
|
304 // List items for list query. |
|
305 aListItems = new( ELeave ) CDesCArrayFlat( KArrayGranularity ); |
|
306 |
|
307 // This array is used to map user selection to correct service. |
|
308 aListItemCommands = new( ELeave ) CArrayFixFlat<TInt>( KArrayGranularity ); |
|
309 |
|
310 // Add the item strings to listItems |
|
311 // Add the item commands to listItemCommands |
|
312 // Consider also meeting request item |
|
313 HBufC* temp = NULL; |
|
314 |
|
315 temp = CCoeEnv::Static()->AllocReadResourceLC( R_CALEN_NEW_MEETING_NOTE ); |
|
316 aListItems->AppendL( *temp ); |
|
317 CleanupStack::PopAndDestroy( temp ); |
|
318 temp = NULL; |
|
319 aListItemCommands->AppendL( ECalenNewMeeting ); |
|
320 |
|
321 // Check with interim utils if the Meeting request viewers are enabled. |
|
322 CCalenInterimUtils2* interimUtils = CCalenInterimUtils2::NewL(); |
|
323 CleanupStack::PushL( interimUtils ); |
|
324 if( interimUtils->MRViewersEnabledL() ) |
|
325 { |
|
326 temp = CCoeEnv::Static()->AllocReadResourceLC( R_CALEN_NEW_MEETING_REQUEST_NOTE ); |
|
327 aListItems->AppendL( *temp ); |
|
328 CleanupStack::PopAndDestroy( temp ); |
|
329 temp = NULL; |
|
330 aListItemCommands->AppendL( ECalenNewMeetingRequest ); |
|
331 } |
|
332 CleanupStack::PopAndDestroy( interimUtils ); |
|
333 |
|
334 temp = CCoeEnv::Static()->AllocReadResourceLC( R_CALEN_DAY_NOTE ); |
|
335 aListItems->AppendL(*temp ); |
|
336 CleanupStack::PopAndDestroy( temp ); |
|
337 temp = NULL; |
|
338 aListItemCommands->AppendL( ECalenNewDayNote ); |
|
339 |
|
340 temp = CCoeEnv::Static()->AllocReadResourceLC( R_CALEN_NOTE_ANNIVERSARY ); |
|
341 aListItems->AppendL(*temp); |
|
342 CleanupStack::PopAndDestroy( temp ); |
|
343 temp = NULL; |
|
344 aListItemCommands->AppendL( ECalenNewAnniv ); |
|
345 |
|
346 temp = CCoeEnv::Static()->AllocReadResourceLC( R_CALEN_NOTE_TODO ); |
|
347 aListItems->AppendL(*temp ); |
|
348 CleanupStack::PopAndDestroy( temp ); |
|
349 temp = NULL; |
|
350 aListItemCommands->AppendL( ECalenNewTodo ); |
|
351 } |
|
352 |
|
353 TRACE_EXIT_POINT; |
|
354 } |
|
355 |
|
356 // ----------------------------------------------------------------------------- |
|
357 // CCalenCommonUI::ShowNewNoteQueryL |
|
358 // Shows the list query for NewEntry |
|
359 // (other items were commented in a header). |
|
360 // ----------------------------------------------------------------------------- |
|
361 // |
|
362 EXPORT_C TInt CalenActionUiUtils::ShowNewNoteQueryL( |
|
363 CDesCArrayFlat*& aListItems, |
|
364 CArrayFixFlat<TInt>*& aListItemCommands ) |
|
365 { |
|
366 TRACE_ENTRY_POINT; |
|
367 |
|
368 PrepareLbDataForNewNotesQueryL( aListItems, aListItemCommands ); |
|
369 |
|
370 // Show list query. |
|
371 TInt choice = KErrCancel; //KErrNotFound; |
|
372 CAknListQueryDialog* dlg = new( ELeave ) CAknListQueryDialog( &choice ); |
|
373 dlg->PrepareLC( R_CALENDAR_NEW_NOTE_QUERY ); // pushes dlg to CS |
|
374 dlg->SetItemTextArray( aListItems ); |
|
375 dlg->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
376 |
|
377 // Set title |
|
378 CAknPopupHeadingPane* heading = dlg->Heading(); |
|
379 HBufC* title = NULL; |
|
380 title = CCoeEnv::Static()->AllocReadResourceLC( |
|
381 R_CALENDAR_NEW_NOTE_QUERY_TITLE ); |
|
382 heading->SetTextL( *title ); |
|
383 CleanupStack::PopAndDestroy( title ); |
|
384 |
|
385 if( dlg->RunLD() ) |
|
386 { |
|
387 // user made a choice |
|
388 choice = aListItemCommands->At( choice ); |
|
389 } |
|
390 |
|
391 TRACE_EXIT_POINT; |
|
392 return choice; |
|
393 } |
|
394 |
|
395 // ----------------------------------------------------------------------------- |
|
396 // CCalenCommonUI::FindPossibleInstanceL |
|
397 // Finds an instance with the given instance id and instance view. |
|
398 // (other items were commented in a header). |
|
399 // ----------------------------------------------------------------------------- |
|
400 // |
|
401 EXPORT_C CCalInstance* CalenActionUiUtils::FindPossibleInstanceL( |
|
402 const TCalenInstanceId& aId, |
|
403 CCalInstanceView& aInstanceView ) |
|
404 { |
|
405 TRACE_ENTRY_POINT; |
|
406 |
|
407 RPointerArray<CCalInstance> instances; |
|
408 CleanupResetAndDestroyPushL( instances ); |
|
409 |
|
410 TCalTime moment; |
|
411 moment.SetTimeLocalL( aId.iInstanceTime ); |
|
412 CalCommon::TCalTimeRange range( moment, moment ); |
|
413 aInstanceView.FindInstanceL( instances, CalCommon::EIncludeAll, range ); |
|
414 |
|
415 CCalInstance* result = NULL; |
|
416 |
|
417 // For instances finishing the next day (now possible with unified DateTime editor), |
|
418 // we have to do our best to match the instance time exactly - otherwise we could |
|
419 // match the LocalUid to the incorrect instance in a series. |
|
420 for ( TInt i=0; i < instances.Count() && !result; ++i ) |
|
421 { |
|
422 if( (instances[i]->InstanceIdL().iCollectionId == aId.iColId) && (instances[i]->Entry().LocalUidL() == aId.iEntryLocalUid )) // comparing the collection id and Local Uid |
|
423 { |
|
424 // Check the instance time matches. |
|
425 if( instances[i]->StartTimeL().TimeLocalL() == aId.iInstanceTime ) |
|
426 { |
|
427 result = instances[i]; |
|
428 instances.Remove(i); |
|
429 } |
|
430 } |
|
431 } |
|
432 |
|
433 if( !result ) |
|
434 { |
|
435 // Couldn't match the instance time exactly - just use the instance |
|
436 // with the same LocalUid as the one we're looking for. |
|
437 for ( TInt i=0; i < instances.Count() && !result; ++i ) |
|
438 { |
|
439 if( instances[i]->Entry().LocalUidL() == aId.iEntryLocalUid ) |
|
440 { |
|
441 result = instances[i]; |
|
442 instances.Remove(i); |
|
443 } |
|
444 } |
|
445 } |
|
446 |
|
447 CleanupStack::PopAndDestroy( &instances ); |
|
448 |
|
449 TRACE_EXIT_POINT; |
|
450 return result; |
|
451 } |
|
452 |
|
453 // End of file |