|
1 /* |
|
2 * Copyright (c) 2009 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 : Aiw provider class provide menuservice which launched calendar |
|
15 * list dialog with multiple calendars. |
|
16 * |
|
17 */ |
|
18 |
|
19 // System includes. |
|
20 #include <AiwMenu.h> |
|
21 #include <calenaiwprovidermenu.rsg> |
|
22 #include <AiwGenericParam.hrh> |
|
23 #include <AiwCommon.hrh> |
|
24 #include <CalenImporter.h> |
|
25 #include <s32file.h> |
|
26 #include <CalenInterimUtils2.h> |
|
27 #include <calentryview.h> |
|
28 #include <sysutil.h> |
|
29 #include <aknnotewrappers.h> |
|
30 #include <calcalendariterator.h> |
|
31 #include <StringLoader.h> |
|
32 #include <CalenInterimUtils2.h> |
|
33 #include <calentry.h> |
|
34 #include <bautils.h> |
|
35 #include <data_caging_path_literals.hrh> |
|
36 |
|
37 // User inlcudes. |
|
38 #include "calenaiwprovider.h" |
|
39 #include "multicaluidialog.h" |
|
40 #include "calendarui_debug.h" |
|
41 #include "calsession.h" |
|
42 #include "calendar.hrh" |
|
43 // Literals. |
|
44 _LIT( KResourceFileName, "calenaiwprovidermenu.rsc" ); |
|
45 // Recognition string for ical |
|
46 _LIT8(KVersionICal, "VERSION:2.0"); |
|
47 // Recognition string for vcal |
|
48 _LIT8(KVersionVCal, "VERSION:1.0"); |
|
49 |
|
50 // Constants. |
|
51 const TInt KReadDataAmount = 256; |
|
52 const TInt KVCalBcLeaveCodeCorrupt = -90; |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // CCalenAiwProvider::NewL |
|
56 // (rest of the details are commented in the header) |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CCalenAiwProvider* CCalenAiwProvider::NewL() |
|
60 { |
|
61 TRACE_ENTRY_POINT |
|
62 |
|
63 CCalenAiwProvider* self = CCalenAiwProvider::NewLC(); |
|
64 CleanupStack::Pop(self); |
|
65 |
|
66 TRACE_EXIT_POINT |
|
67 return self; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CCalenAiwProvider::NewLC |
|
72 // (rest of the details are commented in the header) |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CCalenAiwProvider* CCalenAiwProvider::NewLC() |
|
76 { |
|
77 TRACE_ENTRY_POINT |
|
78 |
|
79 CCalenAiwProvider* self = new (ELeave) CCalenAiwProvider; |
|
80 CleanupStack::PushL(self); |
|
81 self->ConstructL(); |
|
82 |
|
83 TRACE_EXIT_POINT |
|
84 return self; |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // CCalenAiwProvider::~CCalenAiwProvider |
|
89 // (rest of the details are commented in the header) |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 CCalenAiwProvider::~CCalenAiwProvider() |
|
93 { |
|
94 TRACE_ENTRY_POINT |
|
95 |
|
96 if(iCalEntryArray.Count()) |
|
97 { |
|
98 iCalEntryArray.ResetAndDestroy(); |
|
99 } |
|
100 if( iCalEntryView ) |
|
101 { |
|
102 delete iCalEntryView; |
|
103 iCalEntryView = NULL; |
|
104 } |
|
105 if( iCalSession ) |
|
106 { |
|
107 delete iCalSession; |
|
108 iCalSession = NULL; |
|
109 } |
|
110 if( iResourceFileOffset ) |
|
111 { |
|
112 CCoeEnv::Static()->DeleteResourceFile( iResourceFileOffset ); |
|
113 } |
|
114 if(iInterimUtils) |
|
115 { |
|
116 delete iInterimUtils; |
|
117 iInterimUtils = NULL; |
|
118 } |
|
119 |
|
120 TRACE_EXIT_POINT |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // CCalenAiwProvider::InitialiseL |
|
125 // (rest of the details are commented in the header) |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 void CCalenAiwProvider::InitialiseL( MAiwNotifyCallback& /*aFrameworkCallback*/, |
|
129 const RCriteriaArray& /*aInterest*/ ) |
|
130 { |
|
131 TRACE_ENTRY_POINT |
|
132 |
|
133 // No implementation yet. |
|
134 |
|
135 TRACE_EXIT_POINT |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // CCalenAiwProvider::HandleServiceCmdL |
|
140 // Handles the menu item command. |
|
141 // (rest of the details are commented in the header) |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CCalenAiwProvider::HandleServiceCmdL( const TInt& aCmdId, |
|
145 const CAiwGenericParamList& aInParamList, |
|
146 CAiwGenericParamList& /*aOutParamList*/, |
|
147 TUint /*aCmdOptions*/, |
|
148 const MAiwNotifyCallback* /*aCallback*/ ) |
|
149 { |
|
150 TRACE_ENTRY_POINT |
|
151 |
|
152 switch( aCmdId ) |
|
153 { |
|
154 case KAiwCmdSaveToCalendar: |
|
155 { |
|
156 // Parsing the parameters sent by consumer. |
|
157 TInt count = aInParamList.Count(); |
|
158 TInt index = 0; |
|
159 TInt errTrapVal( KErrNone ); |
|
160 TInt errVal( KErrNone ); |
|
161 const TAiwGenericParam* uidParam = aInParamList.FindFirst( index, |
|
162 EGenericParamFile, |
|
163 EVariantTypeFileHandle); |
|
164 |
|
165 if( index >= 0 ) |
|
166 { |
|
167 // Get the data. |
|
168 const TAiwVariant& val = uidParam->Value(); |
|
169 RFile fileHandle ( val.AsFileHandle() ); |
|
170 |
|
171 // Get the entries from filehandle. |
|
172 ImportVCalendarL( fileHandle ); |
|
173 |
|
174 if( HasMorethanOneCalendarL() ) |
|
175 { |
|
176 TRAP( errTrapVal, errVal = SaveWithDialogL() ); |
|
177 if( !errTrapVal && ( -2 == errVal || errVal == ECalenSelectCmdOk ) ) |
|
178 { |
|
179 CAknInformationNote* calSavenote = new( ELeave )CAknInformationNote; |
|
180 HBufC* calSaveNote = StringLoader::LoadLC( R_SAVECALENDARNOTE_TEXT, |
|
181 CCoeEnv::Static() ); |
|
182 |
|
183 calSavenote->ExecuteLD( *calSaveNote ); |
|
184 CleanupStack::PopAndDestroy( calSaveNote ); |
|
185 } |
|
186 } |
|
187 else |
|
188 { |
|
189 TRAP( errTrapVal, errVal = SaveWithoutDialogL() ); |
|
190 if( !errTrapVal && ( 0 == errVal ) ) |
|
191 { |
|
192 CAknInformationNote* calSavenote = new( ELeave )CAknInformationNote; |
|
193 HBufC* calSaveNote = StringLoader::LoadLC( R_SAVECALENDARNOTE_TEXT, |
|
194 CCoeEnv::Static() ); |
|
195 |
|
196 calSavenote->ExecuteLD( *calSaveNote ); |
|
197 CleanupStack::PopAndDestroy( calSaveNote ); |
|
198 } |
|
199 } |
|
200 |
|
201 } |
|
202 else |
|
203 { |
|
204 // RFile param not found param not found. Error handling could be added here. |
|
205 } |
|
206 } |
|
207 break; |
|
208 |
|
209 default: |
|
210 { |
|
211 // no implementation yet. |
|
212 } |
|
213 break; |
|
214 } |
|
215 |
|
216 TRACE_EXIT_POINT |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // CCalenAiwProvider::InitializeMenuPaneL |
|
221 // (rest of the details are commented in the header) |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 void CCalenAiwProvider::InitializeMenuPaneL( CAiwMenuPane& aMenuPane, |
|
225 TInt aIndex, |
|
226 TInt /*aCascadeId*/, |
|
227 const CAiwGenericParamList& /*aInParamList*/ ) |
|
228 { |
|
229 TRACE_ENTRY_POINT |
|
230 |
|
231 // Append the item to the menu pane. |
|
232 aMenuPane.AddMenuItemsL( iResourceFileName, |
|
233 R_CALEN_AIW_PROVIDER_MENU_PANE, |
|
234 KAiwCmdSaveToCalendar, |
|
235 aIndex ); |
|
236 TRACE_EXIT_POINT |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // CCalenAiwProvider::HandleMenuCmdL |
|
241 // (rest of the details are commented in the header) |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CCalenAiwProvider::HandleMenuCmdL( TInt aMenuCmdId, |
|
245 const CAiwGenericParamList& aInParamList, |
|
246 CAiwGenericParamList& aOutParamList, |
|
247 TUint aCmdOptions, |
|
248 const MAiwNotifyCallback* aCallback ) |
|
249 { |
|
250 TRACE_ENTRY_POINT |
|
251 |
|
252 // Handle it in HandleServiceCmdL. |
|
253 HandleServiceCmdL( aMenuCmdId, |
|
254 aInParamList, |
|
255 aOutParamList, |
|
256 aCmdOptions, |
|
257 aCallback ); |
|
258 |
|
259 TRACE_EXIT_POINT |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // CCalenAiwProvider::Progress |
|
264 // (rest of the details are commented in the header) |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 void CCalenAiwProvider::Progress( TInt /* aPercentageCompleted */ ) |
|
268 { |
|
269 // No implementation yet. |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // CCalenAiwProvider::Completed |
|
274 // (rest of the details are commented in the header) |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 void CCalenAiwProvider::Completed( TInt aError ) |
|
278 { |
|
279 iCalEntryViewInitErrno = aError; |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // CCalenAiwProvider::NotifyProgress |
|
284 // (rest of the details are commented in the header) |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 TBool CCalenAiwProvider::NotifyProgress() |
|
288 { |
|
289 // Return ETrue if you want progress information. |
|
290 return EFalse; |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // CCalenAiwProvider::ImportVCalendarL |
|
295 // (rest of the details are commented in the header) |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 #if defined (__I_CAL_SUPPORT) && defined (RD_MESSAGING_ICAL_IMPORT) |
|
299 void CCalenAiwProvider::ImportVCalendarL( RFile& aFileHandle ) |
|
300 { |
|
301 TRACE_ENTRY_POINT |
|
302 |
|
303 CCalenImporter* calImporter = CCalenImporter::NewL( *iCalSession ); |
|
304 CleanupStack::PushL( calImporter ); |
|
305 calImporter->SetImportMode( ECalenImportModeExtended ); |
|
306 |
|
307 RFileReadStream stream( aFileHandle,0 ); |
|
308 CleanupClosePushL( stream ); |
|
309 |
|
310 TBuf8<KReadDataAmount> vcalData; |
|
311 |
|
312 TInt errRead( KErrNone ); |
|
313 TRAP( errRead,stream.ReadL( vcalData, KReadDataAmount ) ); |
|
314 |
|
315 if( errRead != KErrEof && errRead != KErrNone ) |
|
316 { |
|
317 User::Leave( KVCalBcLeaveCodeCorrupt ); |
|
318 } |
|
319 |
|
320 // Return the read stream back to the beginning for import |
|
321 stream.Source()->SeekL( MStreamBuf::ERead, EStreamBeginning, 0 ); |
|
322 |
|
323 TInt errImport( KErrNone ); |
|
324 //Reset the array if its already imported. |
|
325 if(iCalEntryArray.Count()) |
|
326 { |
|
327 iCalEntryArray.ResetAndDestroy(); |
|
328 } |
|
329 |
|
330 |
|
331 if ( vcalData.FindF( KVersionVCal ) == KErrNotFound ) |
|
332 { |
|
333 //using the ICAl import API |
|
334 TRAP( errImport, calImporter->ImportICalendarL( stream, iCalEntryArray ) ); |
|
335 } |
|
336 else if ( vcalData.FindF( KVersionICal ) == KErrNotFound ) |
|
337 { |
|
338 //using the VCAL import API |
|
339 TRAP( errImport, calImporter->ImportVCalendarL( stream, iCalEntryArray ) ); |
|
340 } |
|
341 // Cleaning up calImproter and stream. |
|
342 CleanupStack::PopAndDestroy( 2, calImporter ); |
|
343 |
|
344 if( errImport != KErrNone || iCalEntryArray.Count() == 0 ) |
|
345 { |
|
346 // the data was corrupt |
|
347 User::Leave( KVCalBcLeaveCodeCorrupt ); |
|
348 } |
|
349 |
|
350 // BIO viewer always sets the local UID to 0 in imported entry |
|
351 iCalEntryArray[0]->SetLocalUidL( TCalLocalUid( 0 ) ); |
|
352 |
|
353 TRACE_EXIT_POINT |
|
354 } |
|
355 #else |
|
356 void CCalenAiwProvider::ImportVCalendarL( RFile& aFileHandle ) |
|
357 { |
|
358 TRACE_ENTRY_POINT |
|
359 |
|
360 CCalenImporter* calImporter = CCalenImporter::NewL( *iCalSession ); |
|
361 CleanupStack::PushL( calImporter ); |
|
362 calImporter->SetImportMode( ECalenImportModeExtended ); |
|
363 |
|
364 RFileReadStream stream( aFileHandle,0 ); |
|
365 CleanupClosePushL( stream ); |
|
366 |
|
367 iCalEntryArray.ResetAndDestroy(); |
|
368 TRAPD( err, calImporter->ImportVCalendarL( stream, iCalEntryArray ) ); |
|
369 |
|
370 // Cleaning up calImproter and stream. |
|
371 CleanupStack::PopAndDestroy( 2,calImporter );//stream, calImporter |
|
372 if( err != KErrNone || iCalEntryArray.Count() == 0 ) |
|
373 { |
|
374 // The data was corrupt |
|
375 User::Leave( KVCalBcLeaveCodeCorrupt ); |
|
376 } |
|
377 |
|
378 // BIO viewer always sets the local UID to 0 in imported entry |
|
379 iCalEntryArray[0]->SetLocalUidL( TCalLocalUid( 0 ) ); |
|
380 |
|
381 TRACE_EXIT_POINT |
|
382 } |
|
383 #endif |
|
384 |
|
385 // ---------------------------------------------------------------------------- |
|
386 // CCalenListDialogModel::HasMorethanOneCalendar |
|
387 // Rest of the details are commented in header. |
|
388 // ---------------------------------------------------------------------------- |
|
389 // |
|
390 TBool CCalenAiwProvider::HasMorethanOneCalendarL() |
|
391 { |
|
392 TRACE_ENTRY_POINT |
|
393 |
|
394 TInt retVal( EFalse ); |
|
395 if(iCalSession) |
|
396 { |
|
397 CCalCalendarIterator* calIter = CCalCalendarIterator::NewL( *iCalSession ); |
|
398 CleanupStack::PushL( calIter ); |
|
399 if ( calIter->Count()> 1 ) |
|
400 { |
|
401 retVal = ETrue; |
|
402 } |
|
403 CleanupStack::PopAndDestroy(calIter); |
|
404 } |
|
405 |
|
406 |
|
407 TRACE_EXIT_POINT |
|
408 return retVal; |
|
409 } |
|
410 |
|
411 // ---------------------------------------------------------------------------- |
|
412 // CCalenListDialogModel::SaveWithDialogL |
|
413 // Rest of the details are commented in header. |
|
414 // ---------------------------------------------------------------------------- |
|
415 // |
|
416 TInt CCalenAiwProvider::SaveWithDialogL() |
|
417 { |
|
418 TRACE_ENTRY_POINT |
|
419 |
|
420 TInt errVal( KErrNone ); |
|
421 |
|
422 if( SysUtil::FFSSpaceBelowCriticalLevelL( NULL ) ) |
|
423 { |
|
424 errVal = KErrDiskFull ; |
|
425 User::LeaveIfError( errVal ); |
|
426 } |
|
427 // Handle the command here. |
|
428 |
|
429 CMultiCalUiDialog* multiCalUiDialog = CMultiCalUiDialog::NewLC( iCalEntryArray ); |
|
430 errVal = multiCalUiDialog->LaunchL(); |
|
431 CleanupStack::PopAndDestroy( multiCalUiDialog ); |
|
432 |
|
433 return errVal; |
|
434 |
|
435 TRACE_EXIT_POINT |
|
436 } |
|
437 |
|
438 // ---------------------------------------------------------------------------- |
|
439 // CCalenListDialogModel::SaveWithoutDialogL |
|
440 // Rest of the details are commented in header. |
|
441 // ---------------------------------------------------------------------------- |
|
442 // |
|
443 TInt CCalenAiwProvider::SaveWithoutDialogL() |
|
444 { |
|
445 TRACE_ENTRY_POINT |
|
446 |
|
447 TInt errVal( KErrNone ); |
|
448 if( ! iCalEntryView ) |
|
449 { |
|
450 iCalEntryView = CCalEntryView::NewL( *iCalSession ); |
|
451 User::LeaveIfError( iCalEntryViewInitErrno ); |
|
452 } |
|
453 |
|
454 if( SysUtil::FFSSpaceBelowCriticalLevelL( NULL ) ) |
|
455 { |
|
456 errVal = KErrDiskFull ; |
|
457 return errVal; |
|
458 } |
|
459 |
|
460 TInt numSuccessfulEntry(0); |
|
461 if( iCalEntryView ) |
|
462 { |
|
463 // Get the guid changed for every entires. |
|
464 CreateCopyWithNewGuidL( iCalEntryArray ); |
|
465 TRAP( errVal, iCalEntryView->StoreL( iCalEntryArray, numSuccessfulEntry ) ); |
|
466 |
|
467 if( numSuccessfulEntry != iCalEntryArray.Count() ) |
|
468 { |
|
469 errVal = KErrCompletion ; |
|
470 } |
|
471 } |
|
472 |
|
473 |
|
474 TRACE_EXIT_POINT |
|
475 |
|
476 return errVal; |
|
477 } |
|
478 |
|
479 // ---------------------------------------------------------------------------- |
|
480 // CCalenListDialogModel::CreateCopyWithNewGuidL |
|
481 // Rest of the details are commented in header. |
|
482 // ---------------------------------------------------------------------------- |
|
483 // |
|
484 void CCalenAiwProvider::CreateCopyWithNewGuidL( RPointerArray<CCalEntry>& aSrcDesEntryArray ) |
|
485 { |
|
486 TRACE_ENTRY_POINT; |
|
487 |
|
488 for( TInt count = 0; count< aSrcDesEntryArray.Count(); count++ ) |
|
489 { |
|
490 CCalEntry* sourceEnrty = aSrcDesEntryArray[count]; |
|
491 HBufC8* guid = iInterimUtils->GlobalUidL(); |
|
492 CleanupStack::PushL(guid); |
|
493 CCalEntry* entry = CCalEntry::NewL( sourceEnrty->EntryTypeL(), guid, CCalEntry::EMethodNone, 0 ); |
|
494 |
|
495 // ownership was passed |
|
496 CleanupStack::Pop( guid ); |
|
497 CleanupStack::PushL( entry ); |
|
498 // make sure entry is fully loaded. |
|
499 sourceEnrty->DescriptionL(); |
|
500 entry->CopyFromL( *sourceEnrty, CCalEntry::EDontCopyId ); |
|
501 // make sure entry is fully copied |
|
502 entry->DescriptionL(); |
|
503 |
|
504 // Remove the entry at current "count" and insert the new entry in same place. |
|
505 aSrcDesEntryArray.Remove(count); |
|
506 delete sourceEnrty; |
|
507 aSrcDesEntryArray.Insert( entry, count ); |
|
508 CleanupStack::Pop( entry ); |
|
509 } |
|
510 |
|
511 |
|
512 TRACE_EXIT_POINT; |
|
513 } |
|
514 |
|
515 // --------------------------------------------------------------------------- |
|
516 // CCalenAiwProvider::ConstructL |
|
517 // (rest of the details are commented in the header) |
|
518 // --------------------------------------------------------------------------- |
|
519 // |
|
520 void CCalenAiwProvider::ConstructL() |
|
521 { |
|
522 TRACE_ENTRY_POINT |
|
523 |
|
524 if( !iCalSession ) |
|
525 { |
|
526 iCalSession = CCalSession::NewL(); |
|
527 } |
|
528 |
|
529 // Which calendar file should be used. |
|
530 TRAPD( err, iCalSession->OpenL( iCalSession->DefaultFileNameL() ) ); |
|
531 if ( err == KErrNotFound ) |
|
532 { |
|
533 // TODO : what to do with this code ?????? |
|
534 // If calendar file was not found, should we create it or not? |
|
535 // I think is not BIO control's responsibility to create it. |
|
536 // |
|
537 iCalSession->CreateCalFileL( iCalSession->DefaultFileNameL() ); |
|
538 iCalSession->OpenL( iCalSession->DefaultFileNameL() ); |
|
539 } |
|
540 else |
|
541 { |
|
542 User::LeaveIfError( err ); |
|
543 } |
|
544 |
|
545 // Load the required the resource file. |
|
546 TFileName resFile; |
|
547 |
|
548 // We take the drive in which the dll is being used from append the same |
|
549 // drive name to the beginning of the resource file path. |
|
550 TFileName dllName; |
|
551 Dll::FileName( dllName ); |
|
552 // Two characters for the drive name. For e.g: (C:) |
|
553 TBuf< 2 > driveLetter = dllName.Left( 2 ); |
|
554 resFile.Insert( 0, driveLetter ); |
|
555 resFile.Append( KDC_APP_RESOURCE_DIR ); |
|
556 resFile.Append( KResourceFileName ); |
|
557 |
|
558 iResourceFileName = resFile; |
|
559 |
|
560 BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), iResourceFileName ); |
|
561 |
|
562 iResourceFileOffset = CCoeEnv::Static()->AddResourceFileL( iResourceFileName ); |
|
563 |
|
564 iInterimUtils = CCalenInterimUtils2::NewL(); |
|
565 |
|
566 TRACE_EXIT_POINT |
|
567 } |
|
568 |
|
569 // --------------------------------------------------------------------------- |
|
570 // CCalenAiwProvider::CCalenAiwProvider |
|
571 // (rest of the details are commented in the header) |
|
572 // --------------------------------------------------------------------------- |
|
573 // |
|
574 CCalenAiwProvider::CCalenAiwProvider() |
|
575 { |
|
576 TRACE_ENTRY_POINT |
|
577 |
|
578 // No implementation yet. |
|
579 |
|
580 TRACE_EXIT_POINT |
|
581 } |
|
582 |
|
583 // End of file --Don't delete this. |