ImagePrint/ImagePrintUI/imageprintprovider/src/caiwimageprintif.cpp
branchGCC_SURGE
changeset 25 59ea2209bb67
parent 23 08cc4cc059d4
parent 15 a92d00fca574
equal deleted inserted replaced
23:08cc4cc059d4 25:59ea2209bb67
     1 /*
       
     2 * Copyright (c) 2004-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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <badesca.h>
       
    20 #include <bautils.h>
       
    21 #include <e32std.h>
       
    22 #include <f32file.h>
       
    23 #include <caf/content.h>
       
    24 #include <imageconversion.h>
       
    25 
       
    26 #include "caiwimageprintif.h"
       
    27 #include "cimgpprintutils.h"
       
    28 
       
    29 using namespace ContentAccess;
       
    30 
       
    31 #ifndef __WINS__
       
    32 _LIT( KResourceFile, "aiwprintingprovider.rsc" );
       
    33 _LIT(KResourceFilePath, "z:\\resource\\");
       
    34 #else
       
    35 _LIT(KResourceFile, "z:\\resource\\aiwprintingprovider.rsc");
       
    36 #endif
       
    37 
       
    38 _LIT8( KJpegFileType, "image/jpeg" );
       
    39 _LIT( KJpegFileType16, "image/jpeg" );
       
    40 
       
    41 CAiwImagePrintIf::~CAiwImagePrintIf()
       
    42     {
       
    43     iEikEnv.DeleteResourceFile( iResourceOffset );
       
    44     }
       
    45 
       
    46 CAiwImagePrintIf::CAiwImagePrintIf():iEikEnv( *CEikonEnv::Static() )
       
    47     {
       
    48     }
       
    49 
       
    50 void CAiwImagePrintIf::ConstructL()
       
    51     {
       
    52 #ifndef __WINS__
       
    53     TFileName file;
       
    54     TParse parse;
       
    55     parse.Set( file, NULL, NULL );
       
    56     file.Append(KResourceFilePath);
       
    57     file.Append( KResourceFile );
       
    58 #else
       
    59     TFileName file( KResourceFile );
       
    60 #endif
       
    61     BaflUtils::NearestLanguageFile( iEikEnv.FsSession(), file );
       
    62     iResourceOffset = iEikEnv.AddResourceFileL( file );
       
    63     }
       
    64 
       
    65 // Get image array
       
    66 CDesCArrayFlat* CAiwImagePrintIf::GetImageArrayL( const CAiwGenericParamList& aInParamList )
       
    67     {
       
    68     CDesCArrayFlat* imageFiles = new (ELeave) CDesCArrayFlat(5); //image list for the application
       
    69     CleanupStack::PushL( imageFiles );
       
    70     TInt index = 0;
       
    71 	const TAiwGenericParam* param = aInParamList.FindFirst(index, 
       
    72 			EGenericParamFile, 
       
    73             EVariantTypeDesC);
       
    74     TFileName filename;
       
    75 
       
    76 	while ( index != KErrNotFound )
       
    77 		{
       
    78 		filename.Copy( param->Value().AsDes() );
       
    79 
       
    80 		if ( IsPrintingSupportedL( filename ) )
       
    81 			{
       
    82 			imageFiles->AppendL( filename );
       
    83 			}
       
    84 		param = aInParamList.FindNext(index, 
       
    85 			EGenericParamFile, 
       
    86             EVariantTypeDesC);
       
    87 		}	
       
    88 
       
    89     CleanupStack::Pop( imageFiles );
       
    90 	return imageFiles;
       
    91     }
       
    92 
       
    93 TBool CAiwImagePrintIf::IsPrintingSupportedL( const CAiwGenericParamList& aInParamList )
       
    94     {  
       
    95     TInt index(0);
       
    96     const TAiwGenericParam* param = aInParamList.FindFirst( index, EGenericParamMIMEType );
       
    97 	TBool printable( EFalse );
       
    98 	
       
    99 	// Currently Media Gallery does not offer MIME-parameter in aInParamList (Fix exists).
       
   100 	// Because of that there is checked directly from files if printing is supported
       
   101 	// This is slow and because of this should be deleted when MG offers MIMEs as parameter.
       
   102     if ( index == KErrNotFound )	
       
   103         {        
       
   104         index = 0;
       
   105    	    const TAiwGenericParam* param = aInParamList.FindFirst(index, EGenericParamFile, EVariantTypeDesC);
       
   106 
       
   107         //Check if there is any printable images available. At least image must be
       
   108         //JPEG and it also must be unprotected to be printable.
       
   109         while ( index != KErrNotFound && !printable)
       
   110             {
       
   111             TRAP_IGNORE( printable = IsPrintingSupportedL( param->Value().AsDes() ));
       
   112    	        param = aInParamList.FindNext(index, EGenericParamFile, EVariantTypeDesC);        
       
   113             }
       
   114         return printable;    
       
   115         }
       
   116 	//End of "To be removed" section
       
   117 	
       
   118 	while ( index != KErrNotFound && !printable )
       
   119 		{
       
   120 	   	if ( param->Value().TypeId() == EVariantTypeDesC &&
       
   121 			 param->Value().AsDes() == KJpegFileType16 )
       
   122 	    	{
       
   123 	    	// MIME-type parameter follows filename parameter in parameter list.
       
   124 	    	// Because of that previous item in list is used.
       
   125 	    	if (index > 0)
       
   126 	    	    {    	    
       
   127     	      	printable = !IsProtectedL( aInParamList[index-1].Value().AsDes() );
       
   128 	    	    }
       
   129 	    	}
       
   130 
       
   131 	    if ( !printable )
       
   132 	        {        
       
   133     	   	param = aInParamList.FindNext(index, EGenericParamMIMEType);
       
   134 	        }
       
   135        	}    
       
   136 	     
       
   137     return printable;	 
       
   138     }
       
   139 
       
   140 TBool CAiwImagePrintIf::IsPrintingSupportedL( const TDesC& aFileName )
       
   141     {       
       
   142     //1. check: Mimetype should be correct (JPEG)
       
   143     TBool printable = CheckMIMETypeL( KJpegFileType, aFileName ); 
       
   144        
       
   145     if (printable)
       
   146         {
       
   147         //2. check: file should not be protected
       
   148         printable = !IsProtectedL( aFileName ); 
       
   149         }
       
   150         
       
   151     return printable;                                      
       
   152     }
       
   153 
       
   154 TBool CAiwImagePrintIf::IsProtectedL( const TDesC& aFileName )
       
   155     {
       
   156     CContent* content = NULL;
       
   157 		content = CContent::NewLC( aFileName );
       
   158 		TInt isDrmProtected( 0 );
       
   159 		TInt err = content->GetAttribute( EIsProtected, isDrmProtected );
       
   160 		CleanupStack::PopAndDestroy(); // content
       
   161     return err ? ETrue : isDrmProtected;  
       
   162     }
       
   163     
       
   164     
       
   165 TBool CAiwImagePrintIf::CheckMIMETypeL( const TDesC8& aMimeType,
       
   166 											   const TDesC& aFileName )
       
   167     {
       
   168     TBuf8<128> mimeType(0);
       
   169     CImageDecoder::GetMimeTypeFileL(iEikEnv.FsSession(), aFileName, mimeType);
       
   170 
       
   171     // Check that MIME-type matches (compare returns 0), otherwise return EFalse
       
   172     return mimeType.CompareF( aMimeType ) ? EFalse : ETrue;
       
   173     }
       
   174 
       
   175 //  End of File