ImagePrint/ImagePrintUI/imgpprintdll/src/cimgpprintutils.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 <imageprintapp.rsg>
       
    20 #include <imageprintengine.rsg>
       
    21 #include <AknQueryDialog.h>
       
    22 #include <aknnotewrappers.h>
       
    23 #include <aknstaticnotedialog.h>
       
    24 #include <MGFetch.h>
       
    25 #include <eikspane.h>
       
    26 #include <aknnavi.h>
       
    27 #include <aknnavide.h>
       
    28 #include <imageconversion.h>
       
    29 #include <StringLoader.h>
       
    30 #include <avkon.hrh>
       
    31 #include <bautils.h>
       
    32 #include <hlplch.h>
       
    33 #include <e32std.h>
       
    34 #include <coehelp.h>
       
    35 #include <s32file.h>
       
    36 #include <AiwGenericParam.h>
       
    37 #include <e32property.h>
       
    38 #include <bluetooth/hci/hcierrors.h>
       
    39 #include <pathinfo.h>
       
    40 #include <driveinfo.h>
       
    41 
       
    42 #include "cimgpprintutils.h"
       
    43 #include "imageprint.h"
       
    44 #include "cimageprintsettingsview.h"
       
    45 #include "mdiscoveryobserver.h"
       
    46 #include "cimageprintdoc.h"
       
    47 #include "imgpprintapputil.h"
       
    48 #include "imageprintapp.hrh"
       
    49 #include "mprintsettings.h"
       
    50 #include "cimgpprintdlgmanager.h"
       
    51 #include "clog.h"
       
    52 #include "cimageprintengine.h"
       
    53 #include "ciffactory.h"
       
    54 #include "cuiprotocolcontroller.h"
       
    55 #include "imageprintconsts.h"
       
    56 #include "printmessagecodes.h"
       
    57 #include "mprinteventregisterif.h"
       
    58 
       
    59 #ifndef __WINS__
       
    60 _LIT( KEngineRsc, "imageprintengine.rsc" );
       
    61 _LIT( KImagePrintAppRsc, "imageprintapp.rsc" );
       
    62 #else
       
    63 _LIT( KEngineRsc, "imageprintengine.rsc" );
       
    64 _LIT( KImagePrintAppRsc, "imageprintapp.rsc" );
       
    65 #endif
       
    66 
       
    67 EXPORT_C CIMGPPrintUtils* CIMGPPrintUtils::NewL( MAiwObserver* aAiwObserver )
       
    68     {
       
    69     CIMGPPrintUtils* self = NewLC( aAiwObserver );
       
    70     CleanupStack::Pop(self);
       
    71     return self;
       
    72     }
       
    73 
       
    74 CIMGPPrintUtils* CIMGPPrintUtils::NewLC( MAiwObserver* aAiwObserver )
       
    75     {
       
    76     CIMGPPrintUtils* self =
       
    77                 new (ELeave) CIMGPPrintUtils;
       
    78     CleanupStack::PushL(self);
       
    79     self->ConstructL( aAiwObserver );
       
    80     return self;
       
    81     }
       
    82 // Second class constructor
       
    83 void CIMGPPrintUtils::ConstructL( MAiwObserver* aAiwObserver )
       
    84     {
       
    85 	iAiwObserver = aAiwObserver;
       
    86 
       
    87 #ifndef __WINS__
       
    88     TFileName file;
       
    89     TParse parse;
       
    90     parse.Set( file, NULL, NULL );
       
    91     file.Append( KDC_APP_RESOURCE_DIR );
       
    92     file.Append( KImagePrintAppRsc );
       
    93     TFileName file2;
       
    94     parse.Set( file2, NULL, NULL );
       
    95     file2.Append( KDC_RESOURCE_FILES_DIR );
       
    96     file2.Append( KEngineRsc );
       
    97 #else
       
    98     TFileName file;
       
    99     file.Append( KDC_APP_RESOURCE_DIR );
       
   100     file.Append( KImagePrintAppRsc);
       
   101     TFileName file2;
       
   102     file2.Append( KDC_RESOURCE_FILES_DIR );
       
   103     file2.Append( KEngineRsc );
       
   104 #endif
       
   105 	// get the best matching resource for the current locale
       
   106 	BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), file );
       
   107     iResourceOffset = CCoeEnv::Static()->AddResourceFileL( file );
       
   108 
       
   109 	// get the best matching resource for the current locale
       
   110 	BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), file2 );
       
   111     iResourceOffset2 = CCoeEnv::Static()->AddResourceFileL( file2 );
       
   112 
       
   113 	TRAPD( err, iEngine = CImagePrintEngine::NewL( 0 ));
       
   114 	if ( err == KErrInUse )
       
   115 		{
       
   116         HBufC* buf = StringLoader::LoadLC( R_QTN_PRINT_CONCURRENT_NOTE );
       
   117         CAknErrorNote* errornote = new (ELeave) CAknErrorNote( ETrue );
       
   118         errornote->ExecuteLD( *buf );
       
   119 		CleanupStack::PopAndDestroy( buf );
       
   120 		User::Leave( KErrInUse );
       
   121 		}
       
   122 	else
       
   123 		{
       
   124 		User::LeaveIfError( err );
       
   125 		}
       
   126 
       
   127 	iSettings = iEngine->InterfaceFactory().SettingsIF();
       
   128 
       
   129     if ( iEngine->InterfaceFactory().IsApplicationAlreadyInUse() )
       
   130 		{
       
   131         HBufC* buf = StringLoader::LoadLC( R_QTN_PRINT_CONCURRENT_NOTE );
       
   132         CAknErrorNote* errornote = new (ELeave) CAknErrorNote( ETrue );
       
   133         errornote->ExecuteLD( *buf );
       
   134 		CleanupStack::PopAndDestroy( buf );
       
   135 		User::Leave( KErrInUse );
       
   136 		}
       
   137 
       
   138     // Default value for printer UID before printer is selected.
       
   139     iPrinterUID = -1;
       
   140 
       
   141     iIdle = CIdle::NewL( CActive::EPriorityIdle );
       
   142     }
       
   143 
       
   144 // Destructor
       
   145 CIMGPPrintUtils::~CIMGPPrintUtils()
       
   146     {
       
   147     CCoeEnv::Static()->DeleteResourceFile( iResourceOffset );
       
   148     CCoeEnv::Static()->DeleteResourceFile( iResourceOffset2 );
       
   149 
       
   150 	if ( iEngine )
       
   151 		{
       
   152 		iEngine->InterfaceFactory().PrintEventRegisterIF()->UnRegisterObserver( this );
       
   153 		}
       
   154 
       
   155     if (iPrintDlgManager)
       
   156         {
       
   157         delete iPrintDlgManager;
       
   158         }
       
   159 	delete iProtocolController;
       
   160     delete iEngine;
       
   161     delete iIdle;
       
   162     }
       
   163 
       
   164 // Set the printer uid in the UI side
       
   165 void CIMGPPrintUtils::SetPrinterUID( TInt aPrinterUID )
       
   166     {
       
   167     iPrinterUID = aPrinterUID;
       
   168     }
       
   169 
       
   170 // Get the printer uid in the UI side
       
   171 TInt CIMGPPrintUtils::GetPrinterUID()
       
   172     {
       
   173     return iPrinterUID;
       
   174     }
       
   175 
       
   176 CImagePrintEngine& CIMGPPrintUtils::Engine() const
       
   177 	{
       
   178 	return *iEngine;
       
   179 	}
       
   180 
       
   181 EXPORT_C TBool CIMGPPrintUtils::CheckMIMEType( const TDesC8& aMimeType,
       
   182 											   const TFileName& aFileName )
       
   183     {
       
   184     TBool retVal(ETrue);
       
   185     TBuf8<128> mimeType;
       
   186     mimeType.Zero();
       
   187 
       
   188     RFs fServer;
       
   189     TInt res = fServer.Connect();
       
   190     if ( res != KErrNone )
       
   191     	{
       
   192     	return EFalse;
       
   193     	}
       
   194 
       
   195     TRAPD( err, CImageDecoder::GetMimeTypeFileL(fServer, aFileName, mimeType) );
       
   196     fServer.Close();
       
   197     if ( err != KErrNone )
       
   198         {
       
   199         retVal = EFalse;
       
   200         }
       
   201     else if ( aMimeType.Length() > 0 )
       
   202         {
       
   203         // Check that MIME-type matches, otherwise don't use the image
       
   204         if ( mimeType.CompareF( aMimeType ) != 0 )
       
   205             {
       
   206             retVal = EFalse;
       
   207             }
       
   208         }
       
   209     return retVal;
       
   210     }
       
   211 
       
   212 
       
   213 // Print
       
   214 EXPORT_C void CIMGPPrintUtils::StartPrintingL( CDesCArrayFlat* aImages )
       
   215     {
       
   216     iEngine->InterfaceFactory().PrintEventRegisterIF()->RegisterObserver( this );
       
   217     iEngine->SetImageArrayL(aImages);
       
   218     iProtocolController = CUIProtocolController::NewL( this, iEngine->InterfaceFactory() );
       
   219     TBool printerFound = iProtocolController->SearchDefaultPrinterL();
       
   220     iSettings->UpdateNumberOfCopiesToServer();
       
   221     if( printerFound )
       
   222         {
       
   223         LOG( "CIMGPPrintUtils::StartPrintingL default printer found, printing" );
       
   224         PrintL();
       
   225         }
       
   226     else
       
   227         {
       
   228         LOG( "CIMGPPrintUtils::StartPrintingL default printer NOT found, leaving" );
       
   229         User::Leave( KErrCancel );
       
   230         }
       
   231     }
       
   232 
       
   233 void CIMGPPrintUtils::PrintL()
       
   234     {
       
   235 	LOG( "CIMGPPrintUtils::PrintL Start" );
       
   236     TInt prot = iSettings->GetCurrentPrinterProtocol();
       
   237     TUint vendor = iSettings->GetCurrentPrinterVendor();
       
   238     TBool mmc = EFalse;
       
   239     if( prot == MDiscoveryObserver::EMMC )
       
   240         {
       
   241         mmc = ETrue;
       
   242         }
       
   243     else
       
   244         {
       
   245         mmc = EFalse;
       
   246         }
       
   247 
       
   248     delete iPrintDlgManager;
       
   249     iPrintDlgManager = 0;
       
   250     iPrintDlgManager = CIMGPPrintDlgManager::NewL( 1,
       
   251     		iEngine->InterfaceFactory().PrintJobIF(), 1, mmc, vendor, this );
       
   252     iPrintDlgManager->StartPrintingL();
       
   253     LOG( "CIMGPPrintUtils::PrintL End" );
       
   254     }
       
   255 
       
   256 void CIMGPPrintUtils::JobFinished()
       
   257     {
       
   258     iAiwObserver->JobFinished();
       
   259     }
       
   260 
       
   261 void CIMGPPrintUtils::UsbCableDisconnected()
       
   262     {
       
   263     iAiwObserver->JobFinished();
       
   264     }
       
   265 
       
   266 void CIMGPPrintUtils::RestartPrintingL()
       
   267 	{
       
   268 	TBool printerFound = iProtocolController->FullSearchL();
       
   269     if( printerFound )
       
   270         {
       
   271         LOG( "CIMGPPrintUtils::RestartPrinting: printer selected, printing" );
       
   272 	    iSettings->UpdateNumberOfCopiesToServer();
       
   273         PrintL();
       
   274         }
       
   275     else
       
   276         {
       
   277         LOG( "CIMGPPrintUtils::RestartPrinting: printer not selected, leaving" );
       
   278         iAiwObserver->JobFinished();
       
   279         }
       
   280 	}
       
   281 
       
   282 void CIMGPPrintUtils::PrintJobProgress( TInt /*aStatus*/,
       
   283         					   TInt /*aPercentCompletion*/,
       
   284             				   TInt /*aJobStateCode*/ )
       
   285 	{
       
   286 	// No implementation
       
   287 	}
       
   288 
       
   289 void CIMGPPrintUtils::PrintJobError( TInt aError, TInt aErrorStringCode )
       
   290 	{
       
   291 	if ( aError == KHCIErrorBase-EPageTimedOut &&
       
   292 		 aErrorStringCode == EObexConnectError )
       
   293 		{
       
   294 		//If full discovery is not wanted, uncomment next two lines for error msg & quit
       
   295 		//TRAP_IGNORE( IMGPPrintAppUtil::ShowErrorMsgL( aError, aErrorStringCode ));
       
   296 		iIdle->Cancel();
       
   297 		iIdle->Start( TCallBack( IdleCallbackL, this ));
       
   298 		}
       
   299 	}
       
   300 
       
   301 TInt CIMGPPrintUtils::IdleCallbackL( TAny* aObj )
       
   302 	{
       
   303 	CIMGPPrintUtils* obj = static_cast<CIMGPPrintUtils*>( aObj );
       
   304 	obj->RestartPrintingL();
       
   305 	return EFalse;
       
   306 	}
       
   307 
       
   308 void CIMGPPrintUtils::PrinterStatus( TInt /*aError*/, TInt /*aErrorStringCode*/ )
       
   309 	{
       
   310 	// No implementation
       
   311 	}
       
   312 
       
   313 EXPORT_C void CIMGPPrintUtils::GetDataFilePathL( TFileName& aFileName )
       
   314 	{
       
   315 	TInt phoneMemoryNumber( 0 );    
       
   316 	User::LeaveIfError( DriveInfo::GetDefaultDrive(
       
   317 			DriveInfo::EDefaultPhoneMemory, phoneMemoryNumber ) );
       
   318 
       
   319 	TDriveUnit unit( phoneMemoryNumber );
       
   320 
       
   321 	aFileName.Append( unit.Name() );
       
   322 	aFileName.Append( KParamFile );
       
   323 	}
       
   324 
       
   325 
       
   326 //  End of File