phonebookui/Phonebook2/UIControls/src/Pbk2ImageCommands.cpp
branchRCL_3
changeset 6 e8e3147d53eb
parent 0 e686773b3f54
child 18 d4f567ce2e7c
equal deleted inserted replaced
5:81f8547efd4f 6:e8e3147d53eb
    61 #include <DocumentHandler.h>            // CDocumentHandler
    61 #include <DocumentHandler.h>            // CDocumentHandler
    62 #include <apmstd.h>                     // TDataType
    62 #include <apmstd.h>                     // TDataType
    63 #include <Pbk2CmdExtRes.rsg>
    63 #include <Pbk2CmdExtRes.rsg>
    64 #include <sysutil.h>
    64 #include <sysutil.h>
    65 #include <CPbk2ApplicationServices.h>
    65 #include <CPbk2ApplicationServices.h>
       
    66 #include <AknProgressDialog.h>
    66 
    67 
    67 /// Unnamed namespace for local definitions
    68 /// Unnamed namespace for local definitions
    68 namespace {
    69 namespace {
    69 
    70 
    70     const TInt KSelectedFilesDefaultGranularity = 1;
    71     const TInt KSelectedFilesDefaultGranularity = 1;
   114 //
   115 //
   115 NONSHARABLE_CLASS( CSetImageCmd ):
   116 NONSHARABLE_CLASS( CSetImageCmd ):
   116     public CBase,
   117     public CBase,
   117 	public MPbk2BaseCommand,
   118 	public MPbk2BaseCommand,
   118     private MPbk2ImageSetObserver,
   119     private MPbk2ImageSetObserver,
       
   120     public MProgressDialogCallback,
   119     private MMGFetchVerifier
   121     private MMGFetchVerifier
   120 	{
   122 	{
   121 	public:
   123 	public:
   122 		static CSetImageCmd* NewL(); 
   124 		static CSetImageCmd* NewL(); 
   123 		~CSetImageCmd();
   125 		~CSetImageCmd();
   129 	            MPbk2ImageOperation& aOperation);
   131 	            MPbk2ImageOperation& aOperation);
   130 	    void Pbk2ImageSetFailed(
   132 	    void Pbk2ImageSetFailed(
   131 	            MPbk2ImageOperation& aOperation,
   133 	            MPbk2ImageOperation& aOperation,
   132 	            TInt aError);
   134 	            TInt aError);
   133 	
   135 	
       
   136 	private: // from MProgressDialogCallback
       
   137 	        void DialogDismissedL( TInt aButtonId );
       
   138 	        
   134 	private: // from MMGFetchVerifier
   139 	private: // from MMGFetchVerifier
   135 	    TBool VerifySelectionL(
   140 	    TBool VerifySelectionL(
   136 	            const MDesCArray* aSelectedFiles);
   141 	            const MDesCArray* aSelectedFiles);
   137 	private:
   142 	private:
   138 		CSetImageCmd();
   143 		CSetImageCmd();
   139 		void ConstructL();
   144 		void ConstructL();
   140 		void Cancel();
   145 		void Cancel();
   141 		void DismissWaitNote();
   146 		void DismissWaitNote();
   142 		void SetImageRefL( MVPbkStoreContact* aContact,
   147 		void SetImageRefL( MVPbkStoreContact* aContact,
   143 				const TDesC& aFileName);
   148 				const TDesC& aFileName);
       
   149 		TBool DoVerifySelectionL(
       
   150 		        const MDesCArray* aSelectedFiles);
       
   151 		void ShowErrorNoteL();
   144 		
   152 		
   145 	private:
   153 	private:
   146         /// Own: image set operation
   154         /// Own: image set operation
   147         MPbk2ImageOperation* iImageOperation;
   155         MPbk2ImageOperation* iImageOperation;
   148         /// Own: wait note dialog
   156         /// Own: wait note dialog
   159         // Not own
   167         // Not own
   160         MVPbkStoreContact* iContact; 
   168         MVPbkStoreContact* iContact; 
   161         MPbk2ImageFieldObserver* iObserver;
   169         MPbk2ImageFieldObserver* iObserver;
   162         // Ref:
   170         // Ref:
   163         CPbk2ApplicationServices* iServices;	
   171         CPbk2ApplicationServices* iServices;	
       
   172         TBool iVerificationFailed;
       
   173         TBool iImageSetFailed;
       
   174         TBool iImageSetError;
   164 	};
   175 	};
   165 
   176 
   166 CSetImageCmd* CSetImageCmd::NewL()
   177 CSetImageCmd* CSetImageCmd::NewL()
   167 	{
   178 	{
   168 	CSetImageCmd* self = new(ELeave) CSetImageCmd();
   179 	CSetImageCmd* self = new(ELeave) CSetImageCmd();
   181 	Release( iServices );	
   192 	Release( iServices );	
   182 	}
   193 	}
   183 
   194 
   184 void CSetImageCmd::ExecuteL( MVPbkStoreContact* aContact,MPbk2ImageFieldObserver* aObserver )
   195 void CSetImageCmd::ExecuteL( MVPbkStoreContact* aContact,MPbk2ImageFieldObserver* aObserver )
   185 	{
   196 	{
       
   197     iImageSetFailed = EFalse;
   186     iObserver=aObserver;
   198     iObserver=aObserver;
   187     CDesCArray* selectedFile = new(ELeave) CDesCArrayFlat(
   199     CDesCArray* selectedFile = new(ELeave) CDesCArrayFlat(
   188             KSelectedFilesDefaultGranularity );
   200             KSelectedFilesDefaultGranularity );
   189     CleanupStack::PushL( selectedFile );
   201     CleanupStack::PushL( selectedFile );
   190 	TBool res( EFalse );
   202 	TBool res( EFalse );
   191 	
   203 		
   192 	// run image fetch dialog
   204 	// run image fetch dialog
   193 	res = MGFetch::RunL( *selectedFile, 
   205  	res = MGFetch::RunL( *selectedFile, 
   194 	        EImageFile, 
   206 	        EImageFile, 
   195 	        EFalse, /* multiselection */
   207 	        EFalse, /* multiselection */
   196 	        this /* provide MMGFetchVerifier interface to check DRM */);
   208 	        this /* provide MMGFetchVerifier interface to check DRM */);
   197 
   209  	        
   198 	if ( res && selectedFile->Count() > 0 )
   210     if ( !iVerificationFailed && res && selectedFile->Count() > 0 )
   199         {
   211         {
   200         if (iWaitNote==NULL)
   212         if (iWaitNote==NULL)
   201             {
   213             {
   202             iWaitNote =new(ELeave) CAknWaitDialog(reinterpret_cast<CEikDialog**>( &iWaitNote ),ETrue );
   214             iWaitNote =new(ELeave) CAknWaitDialog(reinterpret_cast<CEikDialog**>( &iWaitNote ),ETrue );
   203             }
   215             }
       
   216         iWaitNote->SetCallback( this );
       
   217         
   204         // doesn't delete waitNote
   218         // doesn't delete waitNote
   205         iWaitNote->ExecuteLD( R_QTN_GEN_NOTE_FETCHING );
   219         iWaitNote->ExecuteLD( R_QTN_GEN_NOTE_FETCHING );
   206 
   220 
   207         TPtrC fileName = (*selectedFile)[0];
   221         TPtrC fileName = (*selectedFile)[0];
   208 
   222 
   209         // delete old filename
   223         // delete old filename
   210         delete iImageFilename;
   224         delete iImageFilename;
   211         iImageFilename=NULL;
   225         iImageFilename=NULL;
   212         // store these for later use
   226         // store these for later use
   213         iImageFilename=fileName.AllocL();
   227         iImageFilename=fileName.AllocL();
   214         iContact=aContact;
   228         iContact=aContact;        
   215         
   229         
   216         
   230         // write data to thumbnail field        
   217         // write data to thumbnail field
       
   218         iImageOperation = 
   231         iImageOperation = 
   219             iImageManager->SetImageAsyncL(
   232             iImageManager->SetImageAsyncL(
   220                 *aContact, *iThumbnailFieldType, *this, fileName );
   233                 *aContact, *iThumbnailFieldType, *this, fileName );                                       
   221                 
   234         }        
   222         }
   235  	
   223 
   236     CleanupStack::PopAndDestroy( selectedFile );
   224     CleanupStack::PopAndDestroy( selectedFile );	
       
   225 	}
   237 	}
   226 
   238 
   227 CSetImageCmd::CSetImageCmd()
   239 CSetImageCmd::CSetImageCmd()
   228 	{
   240 	{
   229 	}
   241 	}
   261 	TRAPD( err, iWaitNote->ProcessFinishedL() );
   273 	TRAPD( err, iWaitNote->ProcessFinishedL() );
   262 	if ( err != KErrNone )
   274 	if ( err != KErrNone )
   263 		{
   275 		{
   264 		delete iWaitNote;
   276 		delete iWaitNote;
   265 		iWaitNote = NULL;
   277 		iWaitNote = NULL;
       
   278 		
       
   279 		if( iImageSetFailed )
       
   280             {
       
   281             ShowErrorNoteL();
       
   282             }
   266 		}
   283 		}
   267 	}
   284 	}
   268 
   285 
   269 void CSetImageCmd::Pbk2ImageSetComplete
   286 void CSetImageCmd::Pbk2ImageSetComplete
   270         ( MPbk2ImageOperation& /*aOperation*/ )
   287         ( MPbk2ImageOperation& /*aOperation*/ )
   277     iImageOperation = NULL;
   294     iImageOperation = NULL;
   278 	DismissWaitNote();
   295 	DismissWaitNote();
   279     if (iObserver)
   296     if (iObserver)
   280         {
   297         {
   281         iObserver->ImageLoadingComplete();
   298         iObserver->ImageLoadingComplete();
   282         }
   299         }	
   283 	
       
   284     }
   300     }
   285 
   301 
   286 // --------------------------------------------------------------------------
   302 // --------------------------------------------------------------------------
   287 // CPbk2SetImageCmd::Pbk2ImageSetFailed
   303 // CPbk2SetImageCmd::Pbk2ImageSetFailed
   288 // --------------------------------------------------------------------------
   304 // --------------------------------------------------------------------------
   289 //
   305 //
   290 void CSetImageCmd::Pbk2ImageSetFailed
   306 void CSetImageCmd::Pbk2ImageSetFailed
   291         ( MPbk2ImageOperation& /*aOperation*/, TInt aError )
   307         ( MPbk2ImageOperation& /*aOperation*/, TInt aError )
   292     {
   308     {        
   293     delete iImageOperation;
   309     delete iImageOperation;
   294     iImageOperation = NULL;
   310     iImageOperation = NULL;
   295 	DismissWaitNote();
   311     
   296     if (iObserver)
   312     iImageSetFailed = ETrue;
   297         {
   313     iImageSetError = aError;
   298         iObserver->ImageLoadingFailed();
   314     
   299         }
   315 	DismissWaitNote();    		   		
   300 	
       
   301 	if ( aError != KErrNone )
       
   302 		{
       
   303 		CCoeEnv::Static()->HandleError( aError );
       
   304 		}
       
   305     }
   316     }
   306 
   317 
   307 void CSetImageCmd::SetImageRefL( MVPbkStoreContact* aContact,
   318 void CSetImageCmd::SetImageRefL( MVPbkStoreContact* aContact,
   308 		const TDesC& aFileName)
   319 		const TDesC& aFileName)
   309     {
   320     {
   335     	CleanupStack::Pop(); // field                    
   346     	CleanupStack::Pop(); // field                    
   336         }
   347         }
   337     }
   348     }
   338 
   349 
   339 // --------------------------------------------------------------------------
   350 // --------------------------------------------------------------------------
   340 // DRM check for image fetch dialog
   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
   341 // --------------------------------------------------------------------------
   364 // --------------------------------------------------------------------------
   342 //	
   365 //	
   343 TBool CSetImageCmd::VerifySelectionL
   366 TBool CSetImageCmd::VerifySelectionL
   344         (const MDesCArray* aSelectedFiles)
   367     (const MDesCArray* aSelectedFiles)
   345     {
   368     {
   346     TBool result = EFalse;
   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     
   347     if ( aSelectedFiles && aSelectedFiles->MdcaCount() > 0 )
   395     if ( aSelectedFiles && aSelectedFiles->MdcaCount() > 0 )
   348         {
   396         {    
   349         // DRM for phonebook image fetch
   397         // DRM for phonebook image fetch
   350         TPtrC fileName = aSelectedFiles->MdcaPoint( 0 );
   398         TPtrC fileName = aSelectedFiles->MdcaPoint( 0 );
       
   399                 
   351         TBool isProtected( ETrue );
   400         TBool isProtected( ETrue );
   352         User::LeaveIfError( 
   401         User::LeaveIfError( 
   353             iDrmManager->IsProtectedFile( fileName, isProtected ) );
   402             iDrmManager->IsProtectedFile( fileName, isProtected ) );
       
   403                 
   354         if ( isProtected )
   404         if ( isProtected )
   355             {
   405             {        
       
   406             ret = EFalse;
       
   407             
   356 			RPbk2LocalizedResourceFile resFile( *CCoeEnv::Static() );
   408 			RPbk2LocalizedResourceFile resFile( *CCoeEnv::Static() );
   357 			resFile.OpenLC( 
   409 			resFile.OpenLC( 
   358 			    KPbk2RomFileDrive, 
   410 			    KPbk2RomFileDrive, 
   359 				KDC_RESOURCE_FILES_DIR, 
   411 				KDC_RESOURCE_FILES_DIR, 
   360 				Pbk2PresentationUtils::PresentationResourceFile() );
   412 				Pbk2PresentationUtils::PresentationResourceFile() );
   361             // show user copyright note
   413             // show user copyright note
       
   414 						
   362             HBufC* prompt = 
   415             HBufC* prompt = 
   363                 CCoeEnv::Static()->AllocReadResourceLC( R_PBK2_QTN_DRM_NOT_ALLOWED );
   416                 CCoeEnv::Static()->AllocReadResourceLC( R_PBK2_QTN_DRM_NOT_ALLOWED );
   364             CAknInformationNote* dlg = new(ELeave) CAknInformationNote( ETrue );
   417             CAknInformationNote* dlg = new(ELeave) CAknInformationNote( ETrue );
   365             dlg->ExecuteLD( *prompt );
   418             dlg->ExecuteLD( *prompt );
   366             CleanupStack::PopAndDestroy( 2 ); // resFile, prompt
   419             CleanupStack::PopAndDestroy( 2 ); // resFile, prompt
   367             }
   420             }        
   368         else
   421         }  
   369             {
   422     
   370             result = ETrue;
   423     return ret;
   371             }
       
   372         }
       
   373         
       
   374     return result;
       
   375     }	
   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     }
   376 
   453 
   377 // --------------------------------------------------------------------------
   454 // --------------------------------------------------------------------------
   378 // Starts external image viewer via doc.handler and waits for its exit
   455 // Starts external image viewer via doc.handler and waits for its exit
   379 // --------------------------------------------------------------------------
   456 // --------------------------------------------------------------------------
   380 //
   457 //