|
1 /* |
|
2 * Copyright (c) 2005-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: Phonebook 2 ringing tone commands. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 |
|
21 // Phonebook 2 |
|
22 #include <e32base.h> |
|
23 #include "Pbk2ImageCommands.h" |
|
24 #include "MPbk2ImageFieldObserver.h" |
|
25 #include "MPbk2BaseCommand.h" |
|
26 |
|
27 #include <MVPbkContactFieldTextData.h> |
|
28 #include <CPbk2AppUiBase.h> |
|
29 #include <MPbk2ApplicationServices.h> |
|
30 #include <TPbk2StoreContactAnalyzer.h> |
|
31 #include "CPbk2ImageManager.h" |
|
32 #include "CPbk2DrmManager.h" |
|
33 #include <MPbk2ImageOperationObservers.h> // MPbk2ImageSetObserver |
|
34 #include <MMGFetchVerifier.h> // MMGFetchVerifier |
|
35 |
|
36 #include <RPbk2LocalizedResourceFile.h> |
|
37 #include "Pbk2DataCaging.hrh" |
|
38 #include "Pbk2PresentationUtils.h" |
|
39 #include <Pbk2CommonUi.rsg> |
|
40 #include <Pbk2UIControls.rsg> |
|
41 #include <Pbk2Commands.rsg> |
|
42 |
|
43 #include <MPbk2ImageOperationObservers.h> // MPbk2ImageSetObserver |
|
44 #include <AknServerApp.h> // MAknServerAppExitObserver |
|
45 |
|
46 // VPbk includes |
|
47 #include <MVPbkStoreContact.h> |
|
48 #include <MVPbkStoreContactField.h> |
|
49 #include <CVPbkContactManager.h> |
|
50 #include <TVPbkFieldTypeMapping.h> |
|
51 #include <MVPbkFieldType.h> |
|
52 #include <VPbkEng.rsg> |
|
53 |
|
54 // System includes |
|
55 #include <barsread.h> |
|
56 #include <coemain.h> |
|
57 #include <AknWaitDialog.h> |
|
58 #include <aknnotewrappers.h> |
|
59 #include <StringLoader.h> |
|
60 #include <MGFetch.h> |
|
61 #include <DocumentHandler.h> // CDocumentHandler |
|
62 #include <apmstd.h> // TDataType |
|
63 #include <Pbk2CmdExtRes.rsg> |
|
64 #include <sysutil.h> |
|
65 #include <CPbk2ApplicationServices.h> |
|
66 #include <AknProgressDialog.h> |
|
67 |
|
68 /// Unnamed namespace for local definitions |
|
69 namespace { |
|
70 |
|
71 const TInt KSelectedFilesDefaultGranularity = 1; |
|
72 |
|
73 #ifdef _DEBUG |
|
74 |
|
75 enum TPanicCode |
|
76 { |
|
77 EPanicPreCond_NULL_Contact = 1 |
|
78 }; |
|
79 |
|
80 void Panic( TPanicCode aPanic ) |
|
81 { |
|
82 _LIT( KPanicCat, "MPbk2ImageCommands" ); |
|
83 User::Panic( KPanicCat, aPanic ); |
|
84 } |
|
85 |
|
86 #endif // _DEBUG |
|
87 |
|
88 // -------------------------------------------------------------------------- |
|
89 // ImageFieldTypeL |
|
90 // -------------------------------------------------------------------------- |
|
91 // |
|
92 inline const MVPbkFieldType* ImageFieldTypeL( |
|
93 MPbk2ApplicationServices& aApplicationServices ) |
|
94 { |
|
95 return aApplicationServices.ContactManager(). |
|
96 FieldTypes().Find( R_VPBK_FIELD_TYPE_CALLEROBJIMG ); |
|
97 } |
|
98 |
|
99 // -------------------------------------------------------------------------- |
|
100 // ThumbnailFieldTypeL |
|
101 // -------------------------------------------------------------------------- |
|
102 // |
|
103 inline const MVPbkFieldType* ThumbnailFieldTypeL( |
|
104 MPbk2ApplicationServices& aApplicationServices ) |
|
105 { |
|
106 return aApplicationServices.ContactManager(). |
|
107 FieldTypes().Find( R_VPBK_FIELD_TYPE_THUMBNAILPIC ); |
|
108 } |
|
109 |
|
110 // -------------------------------------------------------------------------- |
|
111 // Set image operation. |
|
112 // Uses asynchronous operation of CPbk2ImageManager to set image. |
|
113 // MMGFetchVerifier implemented to perform DRM check for select image dialog. |
|
114 // -------------------------------------------------------------------------- |
|
115 // |
|
116 NONSHARABLE_CLASS( CSetImageCmd ): |
|
117 public CBase, |
|
118 public MPbk2BaseCommand, |
|
119 private MPbk2ImageSetObserver, |
|
120 public MProgressDialogCallback, |
|
121 private MMGFetchVerifier |
|
122 { |
|
123 public: |
|
124 static CSetImageCmd* NewL(); |
|
125 ~CSetImageCmd(); |
|
126 |
|
127 void ExecuteL( MVPbkStoreContact* aContact,MPbk2ImageFieldObserver* aObserver ); |
|
128 |
|
129 private: // from MPbkImageSetObserver |
|
130 void Pbk2ImageSetComplete( |
|
131 MPbk2ImageOperation& aOperation); |
|
132 void Pbk2ImageSetFailed( |
|
133 MPbk2ImageOperation& aOperation, |
|
134 TInt aError); |
|
135 |
|
136 private: // from MProgressDialogCallback |
|
137 void DialogDismissedL( TInt aButtonId ); |
|
138 |
|
139 private: // from MMGFetchVerifier |
|
140 TBool VerifySelectionL( |
|
141 const MDesCArray* aSelectedFiles); |
|
142 private: |
|
143 CSetImageCmd(); |
|
144 void ConstructL(); |
|
145 void Cancel(); |
|
146 void DismissWaitNote(); |
|
147 void SetImageRefL( MVPbkStoreContact* aContact, |
|
148 const TDesC& aFileName); |
|
149 TBool DoVerifySelectionL( |
|
150 const MDesCArray* aSelectedFiles); |
|
151 void ShowErrorNoteL(); |
|
152 |
|
153 private: |
|
154 /// Own: image set operation |
|
155 MPbk2ImageOperation* iImageOperation; |
|
156 /// Own: wait note dialog |
|
157 CAknWaitDialog* iWaitNote; |
|
158 /// Own: DRM support |
|
159 CPbk2DrmManager* iDrmManager; |
|
160 const MVPbkFieldType* iThumbnailFieldType; |
|
161 /// Own: Image manager |
|
162 CPbk2ImageManager* iImageManager; |
|
163 |
|
164 // Own |
|
165 HBufC* iImageFilename; |
|
166 |
|
167 // Not own |
|
168 MVPbkStoreContact* iContact; |
|
169 MPbk2ImageFieldObserver* iObserver; |
|
170 // Ref: |
|
171 CPbk2ApplicationServices* iServices; |
|
172 TBool iVerificationFailed; |
|
173 TBool iImageSetFailed; |
|
174 TBool iImageSetError; |
|
175 }; |
|
176 |
|
177 CSetImageCmd* CSetImageCmd::NewL() |
|
178 { |
|
179 CSetImageCmd* self = new(ELeave) CSetImageCmd(); |
|
180 CleanupStack::PushL( self ); |
|
181 self->ConstructL(); |
|
182 CleanupStack::Pop(); |
|
183 return self; |
|
184 } |
|
185 |
|
186 CSetImageCmd::~CSetImageCmd() |
|
187 { |
|
188 Cancel(); |
|
189 delete iImageFilename; |
|
190 delete iDrmManager; |
|
191 delete iImageManager; |
|
192 Release( iServices ); |
|
193 } |
|
194 |
|
195 void CSetImageCmd::ExecuteL( MVPbkStoreContact* aContact,MPbk2ImageFieldObserver* aObserver ) |
|
196 { |
|
197 iImageSetFailed = EFalse; |
|
198 iObserver=aObserver; |
|
199 CDesCArray* selectedFile = new(ELeave) CDesCArrayFlat( |
|
200 KSelectedFilesDefaultGranularity ); |
|
201 CleanupStack::PushL( selectedFile ); |
|
202 TBool res( EFalse ); |
|
203 |
|
204 // run image fetch dialog |
|
205 res = MGFetch::RunL( *selectedFile, |
|
206 EImageFile, |
|
207 EFalse, /* multiselection */ |
|
208 this /* provide MMGFetchVerifier interface to check DRM */); |
|
209 |
|
210 if ( !iVerificationFailed && res && selectedFile->Count() > 0 ) |
|
211 { |
|
212 if (iWaitNote==NULL) |
|
213 { |
|
214 iWaitNote =new(ELeave) CAknWaitDialog(reinterpret_cast<CEikDialog**>( &iWaitNote ),ETrue ); |
|
215 } |
|
216 iWaitNote->SetCallback( this ); |
|
217 |
|
218 // doesn't delete waitNote |
|
219 iWaitNote->ExecuteLD( R_QTN_GEN_NOTE_FETCHING ); |
|
220 |
|
221 TPtrC fileName = (*selectedFile)[0]; |
|
222 |
|
223 // delete old filename |
|
224 delete iImageFilename; |
|
225 iImageFilename=NULL; |
|
226 // store these for later use |
|
227 iImageFilename=fileName.AllocL(); |
|
228 iContact=aContact; |
|
229 |
|
230 // write data to thumbnail field |
|
231 iImageOperation = |
|
232 iImageManager->SetImageAsyncL( |
|
233 *aContact, *iThumbnailFieldType, *this, fileName ); |
|
234 } |
|
235 |
|
236 CleanupStack::PopAndDestroy( selectedFile ); |
|
237 } |
|
238 |
|
239 CSetImageCmd::CSetImageCmd() |
|
240 { |
|
241 } |
|
242 |
|
243 void CSetImageCmd::ConstructL() |
|
244 { |
|
245 /* |
|
246 * In Social phonebook case, the contact editor (that uses this class) is launched outside of pbk2 context. |
|
247 * Then the Pbk2AppUi is not valid. |
|
248 */ |
|
249 iServices = CPbk2ApplicationServices::InstanceL(); |
|
250 iImageManager = CPbk2ImageManager::NewL( iServices->ContactManager() ); |
|
251 |
|
252 iThumbnailFieldType = ThumbnailFieldTypeL(*iServices); |
|
253 iDrmManager = CPbk2DrmManager::NewL(); |
|
254 |
|
255 } |
|
256 |
|
257 void CSetImageCmd::Cancel() |
|
258 { |
|
259 delete iWaitNote; |
|
260 iWaitNote = NULL; |
|
261 delete iImageOperation; |
|
262 iImageOperation = NULL; |
|
263 if (iObserver) |
|
264 { |
|
265 iObserver->ImageLoadingCancelled(); |
|
266 } |
|
267 } |
|
268 |
|
269 void CSetImageCmd::DismissWaitNote() |
|
270 { |
|
271 // ProcessFinishedL initiate iWaitNote destruction |
|
272 // and iWaitNote is set to NULL during CAknWaitDialog destruction |
|
273 TRAPD( err, iWaitNote->ProcessFinishedL() ); |
|
274 if ( err != KErrNone ) |
|
275 { |
|
276 delete iWaitNote; |
|
277 iWaitNote = NULL; |
|
278 |
|
279 if( iImageSetFailed ) |
|
280 { |
|
281 ShowErrorNoteL(); |
|
282 } |
|
283 } |
|
284 } |
|
285 |
|
286 void CSetImageCmd::Pbk2ImageSetComplete |
|
287 ( MPbk2ImageOperation& /*aOperation*/ ) |
|
288 { |
|
289 |
|
290 // set the image reference after image has been loaded. |
|
291 SetImageRefL( iContact, iImageFilename->Des() ); |
|
292 |
|
293 delete iImageOperation; |
|
294 iImageOperation = NULL; |
|
295 DismissWaitNote(); |
|
296 if (iObserver) |
|
297 { |
|
298 iObserver->ImageLoadingComplete(); |
|
299 } |
|
300 } |
|
301 |
|
302 // -------------------------------------------------------------------------- |
|
303 // CPbk2SetImageCmd::Pbk2ImageSetFailed |
|
304 // -------------------------------------------------------------------------- |
|
305 // |
|
306 void CSetImageCmd::Pbk2ImageSetFailed |
|
307 ( MPbk2ImageOperation& /*aOperation*/, TInt aError ) |
|
308 { |
|
309 delete iImageOperation; |
|
310 iImageOperation = NULL; |
|
311 |
|
312 iImageSetFailed = ETrue; |
|
313 iImageSetError = aError; |
|
314 |
|
315 DismissWaitNote(); |
|
316 } |
|
317 |
|
318 void CSetImageCmd::SetImageRefL( MVPbkStoreContact* aContact, |
|
319 const TDesC& aFileName) |
|
320 { |
|
321 CVPbkContactManager& manager = iServices->ContactManager(); |
|
322 |
|
323 TPbk2StoreContactAnalyzer analyzer( |
|
324 manager, |
|
325 aContact ); |
|
326 TInt fieldIndex = analyzer.HasFieldL( R_PHONEBOOK2_IMAGE_SELECTOR ); |
|
327 |
|
328 MVPbkStoreContactField* field; |
|
329 if ( fieldIndex != KErrNotFound ) |
|
330 { |
|
331 // If filename has been set and the contact has the field |
|
332 // field should be updated. |
|
333 field = &aContact->Fields().FieldAt( fieldIndex ); |
|
334 MVPbkContactFieldTextData::Cast( field->FieldData() ). |
|
335 SetTextL( aFileName ); |
|
336 } |
|
337 else if ( aFileName.Length() > 0 ) |
|
338 { |
|
339 const MVPbkFieldType* imageFieldType = ImageFieldTypeL(*iServices); |
|
340 |
|
341 // Contact does not have the field, so create new one. |
|
342 field = aContact->CreateFieldLC( *imageFieldType ); |
|
343 MVPbkContactFieldTextData::Cast( field->FieldData() ). |
|
344 SetTextL( aFileName ); |
|
345 aContact->AddFieldL( field ); |
|
346 CleanupStack::Pop(); // field |
|
347 } |
|
348 } |
|
349 |
|
350 // -------------------------------------------------------------------------- |
|
351 // CSetImageCmd::DialogDismissedL |
|
352 // -------------------------------------------------------------------------- |
|
353 // |
|
354 void CSetImageCmd::DialogDismissedL( TInt /*aButtonId*/ ) |
|
355 { |
|
356 if( iImageSetFailed ) |
|
357 { |
|
358 ShowErrorNoteL(); |
|
359 } |
|
360 } |
|
361 |
|
362 // -------------------------------------------------------------------------- |
|
363 // CSetImageCmd::VerifySelectionL |
|
364 // -------------------------------------------------------------------------- |
|
365 // |
|
366 TBool CSetImageCmd::VerifySelectionL |
|
367 (const MDesCArray* aSelectedFiles) |
|
368 { |
|
369 iVerificationFailed = EFalse; |
|
370 TBool ret = ETrue; |
|
371 |
|
372 TRAPD( err, ret = DoVerifySelectionL( aSelectedFiles ) ); |
|
373 |
|
374 if( err != KErrNone ) |
|
375 { |
|
376 iVerificationFailed = ETrue; |
|
377 ShowErrorNoteL(); |
|
378 } |
|
379 |
|
380 // Selection is always accepted if the image is not drm protected. |
|
381 // Image fetch dialog functionality is always same in spite of error |
|
382 // type (DRM check, ImageDecoder, etc. errors) Dialog is always closed. |
|
383 return ret; |
|
384 } |
|
385 |
|
386 // -------------------------------------------------------------------------- |
|
387 // CSetImageCmd::DoVerifySelectionL |
|
388 // -------------------------------------------------------------------------- |
|
389 // |
|
390 TBool CSetImageCmd::DoVerifySelectionL |
|
391 (const MDesCArray* aSelectedFiles) |
|
392 { |
|
393 TBool ret = ETrue; |
|
394 |
|
395 if ( aSelectedFiles && aSelectedFiles->MdcaCount() > 0 ) |
|
396 { |
|
397 // DRM for phonebook image fetch |
|
398 TPtrC fileName = aSelectedFiles->MdcaPoint( 0 ); |
|
399 |
|
400 TBool isProtected( ETrue ); |
|
401 User::LeaveIfError( |
|
402 iDrmManager->IsProtectedFile( fileName, isProtected ) ); |
|
403 |
|
404 if ( isProtected ) |
|
405 { |
|
406 ret = EFalse; |
|
407 |
|
408 RPbk2LocalizedResourceFile resFile( *CCoeEnv::Static() ); |
|
409 resFile.OpenLC( |
|
410 KPbk2RomFileDrive, |
|
411 KDC_RESOURCE_FILES_DIR, |
|
412 Pbk2PresentationUtils::PresentationResourceFile() ); |
|
413 // show user copyright note |
|
414 |
|
415 HBufC* prompt = |
|
416 CCoeEnv::Static()->AllocReadResourceLC( R_PBK2_QTN_DRM_NOT_ALLOWED ); |
|
417 CAknInformationNote* dlg = new(ELeave) CAknInformationNote( ETrue ); |
|
418 dlg->ExecuteLD( *prompt ); |
|
419 CleanupStack::PopAndDestroy( 2 ); // resFile, prompt |
|
420 } |
|
421 } |
|
422 |
|
423 return ret; |
|
424 } |
|
425 |
|
426 // -------------------------------------------------------------------------- |
|
427 // CSetImageCmd::ShowErrorNoteL |
|
428 // -------------------------------------------------------------------------- |
|
429 // |
|
430 void CSetImageCmd::ShowErrorNoteL() |
|
431 { |
|
432 HBufC* prompt = StringLoader::LoadLC( R_QTN_ALBUM_ERR_FORMAT_UNKNOWN ); |
|
433 CAknInformationNote* dlg = new ( ELeave ) CAknInformationNote( ETrue ); |
|
434 dlg->ExecuteLD( *prompt ); |
|
435 CleanupStack::PopAndDestroy( prompt ); |
|
436 |
|
437 if( iImageSetFailed ) |
|
438 { |
|
439 iImageSetFailed = EFalse; |
|
440 |
|
441 if (iObserver) |
|
442 { |
|
443 iObserver->ImageLoadingFailed(); |
|
444 } |
|
445 |
|
446 if ( iImageSetError != KErrNone ) |
|
447 { |
|
448 CCoeEnv::Static()->HandleError( iImageSetError ); |
|
449 iImageSetError = KErrNone; |
|
450 } |
|
451 } |
|
452 } |
|
453 |
|
454 // -------------------------------------------------------------------------- |
|
455 // Starts external image viewer via doc.handler and waits for its exit |
|
456 // -------------------------------------------------------------------------- |
|
457 // |
|
458 NONSHARABLE_CLASS( CViewImageCmd ): |
|
459 public CBase, |
|
460 public MPbk2BaseCommand, |
|
461 private MAknServerAppExitObserver |
|
462 { |
|
463 public: |
|
464 static CViewImageCmd* NewL(); |
|
465 ~CViewImageCmd(); |
|
466 |
|
467 void ExecuteL( MVPbkStoreContact* aContact ); |
|
468 |
|
469 private: // from MAknServerAppExitObserver |
|
470 void HandleServerAppExit( |
|
471 TInt aReason ); |
|
472 private: |
|
473 CViewImageCmd(); |
|
474 void ConstructL(); |
|
475 void ShowImageNotOpenedNoteL(); |
|
476 |
|
477 private: |
|
478 /// Own: Document handler for image opening |
|
479 CDocumentHandler* iDocHandler; /// Own: wait note dialog |
|
480 TFileName iFileName; |
|
481 CPbk2ApplicationServices* iServices; |
|
482 }; |
|
483 |
|
484 CViewImageCmd* CViewImageCmd::NewL() |
|
485 { |
|
486 CViewImageCmd* self = new(ELeave) CViewImageCmd(); |
|
487 CleanupStack::PushL( self ); |
|
488 self->ConstructL(); |
|
489 CleanupStack::Pop(); |
|
490 return self; |
|
491 } |
|
492 |
|
493 CViewImageCmd::CViewImageCmd() |
|
494 { |
|
495 } |
|
496 |
|
497 void CViewImageCmd::ConstructL() |
|
498 { |
|
499 iDocHandler = CDocumentHandler::NewL(); |
|
500 iDocHandler->SetExitObserver( this ); |
|
501 |
|
502 /* |
|
503 * In Social phonebook case, the contact editor (that uses this class) is launched outside of pbk2 context. |
|
504 * Then the Pbk2AppUi is not valid. |
|
505 */ |
|
506 iServices = CPbk2ApplicationServices::InstanceL(); |
|
507 } |
|
508 |
|
509 CViewImageCmd::~CViewImageCmd() |
|
510 { |
|
511 delete iDocHandler; |
|
512 Release( iServices ); |
|
513 } |
|
514 |
|
515 void CViewImageCmd::HandleServerAppExit( TInt aReason ) |
|
516 { |
|
517 // make base call first |
|
518 MAknServerAppExitObserver::HandleServerAppExit( aReason ); |
|
519 } |
|
520 |
|
521 void CViewImageCmd::ShowImageNotOpenedNoteL() |
|
522 { |
|
523 HBufC* prompt = StringLoader::LoadLC( R_QTN_ALBUM_ERR_FORMAT_UNKNOWN ); |
|
524 CAknInformationNote* dlg = new ( ELeave ) CAknInformationNote( ETrue ); |
|
525 dlg->ExecuteLD( *prompt ); |
|
526 CleanupStack::PopAndDestroy( prompt ); |
|
527 } |
|
528 |
|
529 void CViewImageCmd::ExecuteL( MVPbkStoreContact* aContact ) |
|
530 { |
|
531 CVPbkContactManager& manager = iServices->ContactManager(); |
|
532 |
|
533 TPbk2StoreContactAnalyzer analyzer( |
|
534 manager, |
|
535 aContact ); |
|
536 TInt fieldIndex = analyzer.HasFieldL( R_PHONEBOOK2_IMAGE_SELECTOR ); |
|
537 |
|
538 if( fieldIndex != KErrNotFound ) |
|
539 { |
|
540 // retrieve field pointer and its current text for call |
|
541 MVPbkStoreContactField& field = |
|
542 aContact->Fields().FieldAt( fieldIndex ); |
|
543 iFileName.Copy( |
|
544 MVPbkContactFieldTextData::Cast( field.FieldData() ).Text() ); |
|
545 |
|
546 // empty datatype for automatic recognization |
|
547 TDataType dataType; |
|
548 |
|
549 TRAPD( error, iDocHandler->OpenFileEmbeddedL( iFileName, dataType ) ); |
|
550 |
|
551 // KErrNotReady, when no mmc inserted |
|
552 // KErrNotFound, when image is deleted |
|
553 if ( error == KErrNotFound || error == KErrUnderflow |
|
554 || error == KErrCorrupt |
|
555 || error == KErrNotReady ) |
|
556 { |
|
557 // if the image has been deleted from Image Gallery |
|
558 // or it is corrupted, show a note instead of leave |
|
559 ShowImageNotOpenedNoteL(); |
|
560 } |
|
561 } |
|
562 } |
|
563 } /// namespace |
|
564 |
|
565 // -------------------------------------------------------------------------- |
|
566 // MPbk2ImageCommands::SetImageL |
|
567 // -------------------------------------------------------------------------- |
|
568 // |
|
569 MPbk2BaseCommand* Pbk2ImageCommands::SetImageL( |
|
570 MVPbkStoreContact* aContact, MPbk2ImageFieldObserver* aObserver ) |
|
571 { |
|
572 __ASSERT_DEBUG( aContact, Panic( EPanicPreCond_NULL_Contact ) ); |
|
573 |
|
574 RFs fs = CCoeEnv::Static()->FsSession(); |
|
575 if ( SysUtil::FFSSpaceBelowCriticalLevelL( &fs ) ) |
|
576 { |
|
577 User::Leave( KErrDiskFull ); |
|
578 } |
|
579 |
|
580 CSetImageCmd* cmd = CSetImageCmd::NewL(); |
|
581 CleanupStack::PushL( cmd ); |
|
582 cmd->ExecuteL( aContact , aObserver); |
|
583 CleanupStack::Pop(); |
|
584 |
|
585 return cmd; |
|
586 } |
|
587 |
|
588 // -------------------------------------------------------------------------- |
|
589 // MPbk2ImageCommands::ViewImageL |
|
590 // -------------------------------------------------------------------------- |
|
591 // |
|
592 MPbk2BaseCommand* Pbk2ImageCommands::ViewImageL( |
|
593 MVPbkStoreContact* aContact ) |
|
594 { |
|
595 __ASSERT_DEBUG( aContact, Panic( EPanicPreCond_NULL_Contact ) ); |
|
596 |
|
597 CViewImageCmd* cmd = CViewImageCmd::NewL(); |
|
598 CleanupStack::PushL( cmd ); |
|
599 cmd->ExecuteL( aContact ); |
|
600 CleanupStack::Pop(); |
|
601 |
|
602 return cmd; |
|
603 } |
|
604 |
|
605 // -------------------------------------------------------------------------- |
|
606 // MPbk2ImageCommands::RemoveImageL |
|
607 // -------------------------------------------------------------------------- |
|
608 // |
|
609 MPbk2BaseCommand* Pbk2ImageCommands::RemoveImageL( |
|
610 MVPbkStoreContact* aContact ) |
|
611 { |
|
612 __ASSERT_DEBUG( aContact, Panic( EPanicPreCond_NULL_Contact ) ); |
|
613 |
|
614 // If Social phonebook is enabled, the contact editor (that uses this class) |
|
615 // is launched outside of pbk2 context. Then the Pbk2AppUi is not valid. |
|
616 MPbk2ApplicationServices& services = *CPbk2ApplicationServices::InstanceLC(); |
|
617 |
|
618 CPbk2ImageManager* imageManager = CPbk2ImageManager::NewL( |
|
619 services.ContactManager() ); |
|
620 CleanupStack::PushL( imageManager ); |
|
621 |
|
622 const MVPbkFieldType* thumbType = services.ContactManager().FieldTypes().Find( |
|
623 R_VPBK_FIELD_TYPE_THUMBNAILPIC ); |
|
624 |
|
625 // show a confirmation query if contact has an image |
|
626 if (thumbType && imageManager->HasImage( *aContact, *thumbType ) ) |
|
627 { |
|
628 if ( CAknQueryDialog::NewL()->ExecuteLD( |
|
629 R_PHONEBOOK2_REMOVE_IMAGE_CONFIRMATION_DIALOG ) ) |
|
630 { |
|
631 TPbk2StoreContactAnalyzer analyzer( |
|
632 services.ContactManager(), aContact ); |
|
633 TInt imageIndex = analyzer.HasFieldL( R_PHONEBOOK2_IMAGE_SELECTOR ); |
|
634 |
|
635 if ( imageIndex != KErrNotFound ) |
|
636 { |
|
637 //aContact->RemoveField( imageIndex ); |
|
638 //Instead of above we don't remove the field, just zero it's data |
|
639 MVPbkContactFieldData& data(aContact->Fields(). |
|
640 FieldAt( imageIndex ).FieldData()); |
|
641 MVPbkContactFieldTextData::Cast( data ).SetTextL(KNullDesC); |
|
642 } |
|
643 |
|
644 const MVPbkFieldType* thumbFieldType = ThumbnailFieldTypeL(services); |
|
645 imageManager->RemoveImage( *aContact, *thumbFieldType ); |
|
646 } |
|
647 } |
|
648 |
|
649 CleanupStack::PopAndDestroy( imageManager ); |
|
650 CleanupStack::PopAndDestroy(); // services |
|
651 |
|
652 return NULL; // synchronous operation |
|
653 } |
|
654 |
|
655 // -------------------------------------------------------------------------- |
|
656 // MPbk2ImageCommands::IsImageFieldL |
|
657 // -------------------------------------------------------------------------- |
|
658 // |
|
659 TBool Pbk2ImageCommands::IsImageFieldL( |
|
660 const MVPbkStoreContactField& aField ) |
|
661 { |
|
662 /* |
|
663 * In Social phonebook case, the contact editor (that uses this class) is launched outside of pbk2 context. |
|
664 * Then the Pbk2AppUi is not valid. |
|
665 */ |
|
666 CPbk2ApplicationServices* services = CPbk2ApplicationServices::InstanceL(); |
|
667 TPbk2StoreContactAnalyzer analyzer( |
|
668 services->ContactManager(), |
|
669 NULL ); |
|
670 Release( services ); |
|
671 |
|
672 return analyzer.IsFieldTypeIncludedL( |
|
673 aField, R_PHONEBOOK2_IMAGE_SELECTOR ); |
|
674 } |
|
675 |
|
676 // -------------------------------------------------------------------------- |
|
677 // MPbk2ImageCommands::IsImageFieldL |
|
678 // -------------------------------------------------------------------------- |
|
679 // |
|
680 TBool Pbk2ImageCommands::IsThumbnailFieldL( |
|
681 const MVPbkStoreContactField& aField ) |
|
682 { |
|
683 /* |
|
684 * In Social phonebook case, the contact editor (that uses this class) is launched outside of pbk2 context. |
|
685 * Then the Pbk2AppUi is not valid. |
|
686 */ |
|
687 CPbk2ApplicationServices* services = CPbk2ApplicationServices::InstanceL(); |
|
688 TPbk2StoreContactAnalyzer analyzer( |
|
689 services->ContactManager(), |
|
690 NULL ); |
|
691 Release( services ); |
|
692 |
|
693 return analyzer.IsFieldTypeIncludedL( |
|
694 aField, R_PHONEBOOK2_THUMBNAIL_SELECTOR ); |
|
695 } |
|
696 |
|
697 // -------------------------------------------------------------------------- |
|
698 // MPbk2ImageCommands::IsImageFieldValidL |
|
699 // -------------------------------------------------------------------------- |
|
700 // |
|
701 TBool Pbk2ImageCommands::IsImageFieldValidL( |
|
702 const MVPbkStoreContactField& aField ) |
|
703 { |
|
704 const MVPbkContactFieldTextData& textData = |
|
705 MVPbkContactFieldTextData::Cast( aField.FieldData() ); |
|
706 TEntry ignore; |
|
707 return CCoeEnv::Static()->FsSession().Entry( textData.Text(), ignore ) == KErrNone; |
|
708 } |
|
709 |
|
710 // End of File |