usbuis/imageprintuiprovider/src/caiwimageprintIf.cpp
changeset 93 2dc695882abd
parent 89 3592750162a5
equal deleted inserted replaced
89:3592750162a5 93:2dc695882abd
     1 /*
       
     2 * Copyright (c) 2006, 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:  Check if file is OK for printing
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //External includes
       
    21 #include <badesca.h>
       
    22 #include <bautils.h>
       
    23 #include <e32std.h>
       
    24 #include <f32file.h>
       
    25 #include <DRMCommon.h>
       
    26 #include <imageconversion.h>
       
    27 #include <pathinfo.h> 
       
    28 
       
    29 //Internal includes
       
    30 #include "caiwimageprintif.h"
       
    31 #include "imageprintuidebug.h"
       
    32 
       
    33 
       
    34 _LIT8( KJpegFileType, "image/jpeg" );
       
    35 _LIT( KJpegFileType16, "image/jpeg" );
       
    36 
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // 
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CAiwImagePrintIf::~CAiwImagePrintIf()
       
    43     {
       
    44     iEikEnv.FsSession().Delete(*iPrintFileName);
       
    45     iEikEnv.FsSession().Delete(*iUnsuppFileName);
       
    46     iEikEnv.DeleteResourceFile( iResourceOffset );
       
    47     delete iDRM;
       
    48     delete iPrintFileName;
       
    49     delete iUnsuppFileName;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // 
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CAiwImagePrintIf::CAiwImagePrintIf():iEikEnv( *CEikonEnv::Static() )
       
    57     {
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // 
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void CAiwImagePrintIf::ConstructL()
       
    65     {
       
    66     
       
    67     TFileName file( KResource );
       
    68     file = PathInfo::RomRootPath();
       
    69     TBuf<KResource> length2(KResourceFile);    
       
    70     file.SetLength(KDriver + length2.Length());
       
    71     file.Replace(KDriver, length2.Length(), KResourceFile);
       
    72     
       
    73     BaflUtils::NearestLanguageFile( iEikEnv.FsSession(), file );
       
    74     iResourceOffset = iEikEnv.AddResourceFileL( file );
       
    75     iDRM = DRMCommon::NewL();
       
    76     User::LeaveIfError( iDRM->Connect() );
       
    77     iNumberOfUnSuppFiles = 0;
       
    78     
       
    79     
       
    80     TFileName printNameFile( KResource ); 
       
    81     printNameFile = PathInfo::PhoneMemoryRootPath(); 
       
    82     TBuf<KResource> length3(KParamFile);
       
    83     printNameFile.SetLength(KDriver + length3.Length());
       
    84     printNameFile.Replace(KDriver, length3.Length(), KParamFile); 
       
    85     
       
    86     iPrintFileName = HBufC::NewL(printNameFile.Length() );
       
    87     iPrintFileName->Des().Copy(printNameFile);
       
    88     
       
    89     TFileName unSuppFile( KResource ); 
       
    90     unSuppFile = PathInfo::PhoneMemoryRootPath(); 
       
    91     TBuf<KResource> lengthUn(KUnSuppFile);
       
    92     unSuppFile.SetLength(KDriver + lengthUn.Length());
       
    93     unSuppFile.Replace(KDriver, lengthUn.Length(), KUnSuppFile);
       
    94     
       
    95     iUnsuppFileName = HBufC::NewL(unSuppFile.Length() );
       
    96     iUnsuppFileName->Des().Copy(unSuppFile);
       
    97     
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // 
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 TBool CAiwImagePrintIf::IsPrintingSupported( const CAiwGenericParamList& aInParamList )
       
   105     {  
       
   106     TInt index(0);
       
   107     FLOG(_L("[CAiwImagePrintIf]  IsPrintingSupported "));
       
   108     const TAiwGenericParam* param = aInParamList.FindFirst( index, EGenericParamMIMEType );
       
   109 	TBool printable( EFalse );
       
   110 	
       
   111     if ( index == KErrNotFound )	
       
   112         {    
       
   113         index = 0;
       
   114    	    const TAiwGenericParam* param = aInParamList.FindFirst(index, EGenericParamFile, EVariantTypeDesC);
       
   115 
       
   116         //Check if there is any printable images available. At least image must be
       
   117         //JPEG and it also must be unprotected to be printable.
       
   118         while ( index != KErrNotFound && !printable)
       
   119             {
       
   120             FLOG(_L("[CAiwImagePrintIf]  IsPrintingSupported 3"));
       
   121             TRAP_IGNORE( printable = IsPrintingSupportedL( param->Value().AsDes() ));
       
   122    	        param = aInParamList.FindNext(index, EGenericParamFile, EVariantTypeDesC);        
       
   123             }
       
   124         FTRACE(FPrint(_L("[CAiwImagePrintIf] IsPrintingSupported  printable is  %d"), printable ));     
       
   125         return printable;    
       
   126         }
       
   127 	
       
   128 	while ( index != KErrNotFound && !printable )
       
   129 		{
       
   130 	   	if ( param->Value().TypeId() == EVariantTypeDesC &&
       
   131 			 param->Value().AsDes() == KJpegFileType16 )
       
   132 	    	{
       
   133 	    	// MIME-type parameter follows filename parameter in parameter list.
       
   134 	    	// Because of that previous item in list is used.
       
   135 	    	if (index > 0)
       
   136 	    	    {   
       
   137 	    	    FLOG(_L("[CAiwImagePrintIf]  IsPrintingSupported 5")); 	    
       
   138     	      	printable = !IsProtected( aInParamList[index-1].Value().AsDes() );
       
   139 	    	    }
       
   140 	    	}
       
   141 
       
   142 	    if ( !printable )
       
   143 	        {        
       
   144     	   	param = aInParamList.FindNext(index, EGenericParamMIMEType);
       
   145 	        }
       
   146        	}    
       
   147 	FTRACE(FPrint(_L("[CAiwImagePrintIf] IsPrintingSupported 2 printable is  %d"), printable ));     
       
   148     return printable;	 
       
   149     }
       
   150     
       
   151 // ---------------------------------------------------------------------------
       
   152 // 
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 TBool CAiwImagePrintIf::IsPrintingSupportedL( const TDesC& aFileName )
       
   156     {       
       
   157     //1. check: Mimetype should be correct (JPEG)
       
   158     FLOG(_L("[CAiwImagePrintIf]  IsPrintingSupported TBool 1"));
       
   159     TBool printable = CheckMIMETypeL( KJpegFileType, aFileName ); 
       
   160        
       
   161     if (printable)
       
   162         {
       
   163         //2. check: file should not be protected
       
   164         printable = !IsProtected( aFileName ); 
       
   165         }     
       
   166     FTRACE(FPrint(_L("[CAiwImagePrintIf] IsPrintingSupportedL  TBool printable is  %d"), printable ));    
       
   167     return printable;                                      
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // 
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 TBool CAiwImagePrintIf::IsProtected( const TDesC& aFileName )
       
   175     {
       
   176     TBool fileProtect;
       
   177     TInt err = iDRM->IsProtectedFile( aFileName, fileProtect );
       
   178     FTRACE(FPrint(_L("[CAiwImagePrintIf] IsProtected   retVal is  %d"), err ? ETrue : fileProtect )); 
       
   179     return err ? ETrue : fileProtect;  
       
   180     }
       
   181     
       
   182 // ---------------------------------------------------------------------------
       
   183 // 
       
   184 // ---------------------------------------------------------------------------
       
   185 //    
       
   186 TBool CAiwImagePrintIf::CheckMIMETypeL( const TDesC8& aMimeType,
       
   187 											   const TDesC& aFileName )
       
   188     {
       
   189     TBuf8<128> mimeType(0);
       
   190     CImageDecoder::GetMimeTypeFileL(iEikEnv.FsSession(), aFileName, mimeType);
       
   191 
       
   192     // Check that MIME-type matches (compare returns 0), otherwise return EFalse
       
   193     FTRACE(FPrint(_L("[CAiwImagePrintIf] CheckMIMETypeL   retVal is  %d"), mimeType.CompareF( aMimeType ) ? EFalse : ETrue )); 
       
   194     return mimeType.CompareF( aMimeType ) ? EFalse : ETrue;
       
   195     }
       
   196 
       
   197 // End of file