ImagePrint/ImagePrintUI/imageprintapp/src/cimageprintappui.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 <AknQueryDialog.h>
       
    21 #include <aknnotewrappers.h>
       
    22 #include <aknstaticnotedialog.h>
       
    23 #include <MGFetch.h>
       
    24 #include <eikspane.h>
       
    25 #include <aknnavi.h>
       
    26 #include <aknnavide.h>
       
    27 #include <imageconversion.h>
       
    28 #include <StringLoader.h>
       
    29 #include <avkon.hrh>
       
    30 #include <bautils.h>
       
    31 #include <hlplch.h>
       
    32 #include <e32std.h>
       
    33 #include <coehelp.h>
       
    34 #include <hal.h>
       
    35 #include <apgcli.h>
       
    36 #include <s32file.h>
       
    37 #include <AiwGenericParam.h>
       
    38 #include <e32property.h>
       
    39 #include <featmgr.h>
       
    40 #include <caf/content.h>
       
    41 
       
    42 #include "cimageprintappui.h"
       
    43 #include "imageprint.h"
       
    44 #include "cimageprintsettingsview.h"
       
    45 #include "cimgpviewemptyview.h"
       
    46 #include "cdiscoverydlgmanager.h"
       
    47 #include "cimageprintdoc.h"
       
    48 #include "printapputil.h"
       
    49 #include "imageprintapp.hrh"
       
    50 #include "mprintsettings.h"
       
    51 #include "cimgpprintdlgmanager.h"
       
    52 #include "clog.h"
       
    53 #include "cimageprintengine.h"
       
    54 #include "ciffactory.h"
       
    55 #include "mdiscovery.h"
       
    56 #include "cimgpprintutils.h"
       
    57 #include "uimodefactory.h"
       
    58 #include "muimode.h"
       
    59 #include "muimodeobserver.h"
       
    60 #include "caiwprintpreviewprovider.h"
       
    61 
       
    62 using namespace ContentAccess;
       
    63 
       
    64 _LIT( KEngineRsc, "imageprintengine.rsc" );
       
    65 _LIT8( KJpegFileType, "image/jpeg" );
       
    66 
       
    67 // For navipane changes
       
    68 _LIT( KLine, " - " );
       
    69 const TInt KLineLength(3);
       
    70 const TInt32 KUid (0x101FFA84);
       
    71 
       
    72 // Second class constructor
       
    73 void CImagePrintAppUi::ConstructL()
       
    74     {
       
    75 	LOG("CImagePrintAppUi::ConstructL BEGIN");
       
    76 	// Add EAknSingleClickCompatible to BaseConstructL function parameter for single click event 
       
    77     BaseConstructL( EAknEnableSkin | EAppOrientationAutomatic | EAknEnableMSK | EAknSingleClickCompatible );	
       
    78   	
       
    79     FeatureManager::InitializeLibL();
       
    80 
       
    81 	// get the best matching resource for the current locale
       
    82 	TFileName file(NULL);	
       
    83 
       
    84 	file.Append( KDC_RESOURCE_FILES_DIR );
       
    85 	file.Append( KEngineRsc );
       
    86 	BaflUtils::NearestLanguageFile( iEikonEnv->FsSession(), file );
       
    87     iResourceOffset = iEikonEnv->AddResourceFileL( file );
       
    88 
       
    89     iDoc = static_cast<CImagePrintDoc*>( CAknAppUi::Document() );
       
    90 
       
    91 	TRAPD( err, iDoc->InitializeEngineL() );
       
    92 	if ( err == KErrInUse )
       
    93 		{
       
    94 		LOG("Too many connections. Exiting...");
       
    95 		CAknErrorNote* errornote = new (ELeave) CAknErrorNote( ETrue );
       
    96 		HBufC* buf = StringLoader::LoadLC( R_QTN_PRINT_CONCURRENT_NOTE );
       
    97 		errornote->ExecuteLD( *buf );
       
    98 		CleanupStack::PopAndDestroy( buf );
       
    99 		Exit();
       
   100 		}
       
   101 	else
       
   102 		{
       
   103 		User::LeaveIfError( err );
       
   104 		}
       
   105 
       
   106     if ( iDoc->Engine()->InterfaceFactory().IsApplicationAlreadyInUse() )
       
   107     	{
       
   108     	LOG("Too many connections. Exiting...");
       
   109 		CAknErrorNote* errornote = new (ELeave) CAknErrorNote( ETrue );
       
   110 		HBufC* buf = StringLoader::LoadLC( R_QTN_PRINT_CONCURRENT_NOTE );
       
   111 		errornote->ExecuteLD( *buf );
       
   112 		CleanupStack::PopAndDestroy( buf );
       
   113 		Exit();
       
   114     	}
       
   115 
       
   116     iAiwState = ENotAiwCall;
       
   117     TInt r = iAiwCall.Attach(KPrintPropertyCat,EPrintProperty,EOwnerProcess);
       
   118     if (r == KErrNone)
       
   119         {
       
   120         iAiwCall.Get(KPrintPropertyCat,EPrintProperty,iAiwState);
       
   121         }
       
   122 
       
   123 	TBool aiw = EFalse;
       
   124 	if ( iAiwState == EAiwPrintCall )
       
   125         {
       
   126 		// Set the aiw call RProperty key back to default value so that
       
   127 		// if application for some reason crashes the value is not left for AIW mode.
       
   128 		iAiwCall.Set( KPrintPropertyCat,EPrintProperty, ENotAiwCall );
       
   129         SetImageArrayL(GetImagesFromAiwProviderL());
       
   130         aiw = ETrue;
       
   131         }
       
   132 
       
   133 
       
   134     iUIMode = UIModeFactory::CreateL( aiw, this, iDoc->Engine()->InterfaceFactory() );
       
   135     
       
   136 	LOG("CImagePrintAppUi::ConstructL CImagePrintSettingsView");
       
   137     CImagePrintSettingsView* settingsView = CImagePrintSettingsView::NewL(
       
   138         iDoc->PrintSettings(), iDoc->PrintJob(), this, iUIMode );
       
   139     CleanupStack::PushL( settingsView );
       
   140 	AddViewL( settingsView );
       
   141     CleanupStack::Pop( settingsView );
       
   142 
       
   143 	LOG("CImagePrintAppUi::ConstructL CIMGPViewEmptyView");
       
   144     CIMGPViewEmptyView* emptyView = CIMGPViewEmptyView::NewL();
       
   145     CleanupStack::PushL( emptyView );
       
   146 	AddViewL( emptyView );
       
   147     CleanupStack::Pop( emptyView);
       
   148 
       
   149     SetDefaultViewL( *emptyView );
       
   150     // default printer search in aiw mode must be done via
       
   151     // CIdle callback for UI to construct itself properly
       
   152     iIdleSearch = CIdle::NewL( CActive::EPriorityStandard );
       
   153 	iIdleSearch->Start( TCallBack( SearchDefaultPrinterCbL, this ));
       
   154 
       
   155     // Default value for printer UID before printer is selected.
       
   156     iPrinterUID = -1;
       
   157 
       
   158     iCoeEnv->RootWin().EnableScreenChangeEvents();
       
   159 
       
   160     iApplicationStarting = ETrue;
       
   161     iAlbumCall = KErrNotFound;
       
   162 	LOG("CImagePrintAppUi::ConstructL END");
       
   163     }
       
   164 
       
   165 // aiw search callback
       
   166 TInt CImagePrintAppUi::SearchDefaultPrinterCbL( TAny* aObj )
       
   167 	{
       
   168 	LOG("CImagePrintAppUi::SearchDefaultPrinterCbL begin");
       
   169 	CImagePrintAppUi* obj = static_cast<CImagePrintAppUi*>( aObj );
       
   170 	TRAPD( err, obj->iUIMode->SearchDefaultPrinterL() );
       
   171 	if ( err != KErrNone )
       
   172 		{
       
   173 		LOG1( "CImagePrintAppUi::SearchDefaultPrinterCbL search failed, err: %d", err );
       
   174 		
       
   175 		if ( err == KErrDisconnected )
       
   176 		    {
       
   177 			HBufC* buf = StringLoader::LoadLC( R_NOTE_DISCONNECT_PRINT_ERROR );
       
   178     		CAknErrorNote* errornote = new CAknErrorNote( ETrue );       
       
   179     		errornote->ExecuteLD( *buf );	        	
       
   180     		CleanupStack::PopAndDestroy( buf );
       
   181 		    }
       
   182 
       
   183         // Closes program
       
   184 		obj->Exit();
       
   185 		}
       
   186 	LOG("CImagePrintAppUi::SearchDefaultPrinterCbL end");
       
   187 	return EFalse;
       
   188 	}
       
   189 
       
   190 // Destructor
       
   191 CImagePrintAppUi::~CImagePrintAppUi()
       
   192     {
       
   193 	FeatureManager::UnInitializeLib();
       
   194     delete iNaviDecorator;
       
   195 
       
   196     iEikonEnv->DeleteResourceFile( iResourceOffset );
       
   197     delete iPrintDlgManager;
       
   198     delete iUSBConnectionWaitNote;
       
   199 
       
   200 	if( iIdleSearch )
       
   201 		{
       
   202 		iIdleSearch->Cancel();
       
   203 		}
       
   204 	
       
   205 	delete iUIMode;
       
   206 	delete iIdleSearch;
       
   207 
       
   208     iAiwCall.Close();
       
   209     }
       
   210 
       
   211 // Handles global user events
       
   212 void CImagePrintAppUi::HandleCommandL(
       
   213     TInt aCommand )
       
   214     {
       
   215     LOG1( "CImagePrintAppUi::HandleCommandL BEGIN: %d", aCommand );
       
   216     switch ( aCommand )
       
   217         {
       
   218         case EAknCmdExit:
       
   219         case EAknSoftkeyExit:
       
   220             {
       
   221             Exit();
       
   222             break;
       
   223             }
       
   224         case EEikCmdExit:
       
   225         	{
       
   226         	// Cancel current printjob because this command may have come from MMC removal
       
   227         	// cancelling may fail in engine if mmc writing was in critical point, so TRAP
       
   228         	TRAP_IGNORE( iDoc->PrintJob()->CancelL() );
       
   229         	if ( iAiwState == EAiwPrintCall )
       
   230         		{
       
   231 	            User::Exit( EAiwPrintCall );
       
   232         		}
       
   233         	else
       
   234         		{
       
   235         		Exit();
       
   236         		}
       
   237             break;
       
   238         	}
       
   239 
       
   240         case EAknSoftkeyBack:
       
   241             {       
       
   242             break;
       
   243             }
       
   244 
       
   245         case ESelectMarked:
       
   246             {
       
   247 			if( iValidImages )
       
   248             	{
       
   249 				iUIMode->SearchDefaultPrinterL();
       
   250 				}
       
   251 			else
       
   252 				{
       
   253            		CAknErrorNote* errornote = new (ELeave) CAknErrorNote( ETrue );
       
   254 				HBufC* buf = StringLoader::LoadLC( R_QTN_PRINT_SELECTNEW_NOTE );
       
   255 				errornote->ExecuteLD( *buf );
       
   256 				CleanupStack::PopAndDestroy( buf );
       
   257 				}
       
   258 			break;
       
   259             }
       
   260 		default:
       
   261             break;
       
   262         }
       
   263 	LOG( "CImagePrintAppUi::HandleCommandL END" );        
       
   264     }
       
   265 
       
   266 void CImagePrintAppUi::LaunchHelpApplicationL( const TDesC& aHelpText )
       
   267     {
       
   268     CArrayFix< TCoeHelpContext >* cntx = new( ELeave ) CArrayFixFlat< TCoeHelpContext >( 1 );
       
   269     CleanupStack::PushL( cntx );
       
   270 
       
   271     //make uid
       
   272     TUid uid;
       
   273     uid.iUid = ( KUid );
       
   274 
       
   275     cntx->AppendL( TCoeHelpContext( uid, aHelpText ) );
       
   276     CleanupStack::Pop( cntx );
       
   277 
       
   278     //and launch help - takes ownership of context array
       
   279     HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), cntx );
       
   280     }
       
   281 
       
   282 // Set the image array
       
   283 void CImagePrintAppUi::SetImageArrayL( CDesCArrayFlat* aFileArray )
       
   284     {
       
   285     iFiles = aFileArray;
       
   286 
       
   287     // Sets default navipane text with no copies.     
       
   288     SetNavipaneTextL( 1 );            
       
   289         
       
   290     iDoc->SetImageArrayL( aFileArray );
       
   291     }
       
   292 
       
   293 // Get the image array
       
   294 CDesCArrayFlat* CImagePrintAppUi::GetImageArray()
       
   295     {
       
   296     return iFiles;
       
   297     }
       
   298 
       
   299 // Get the document class
       
   300 CImagePrintDoc* CImagePrintAppUi::GetDocument()
       
   301     {
       
   302     return iDoc;
       
   303     }
       
   304 
       
   305 TInt CImagePrintAppUi::GetAlbumCall()
       
   306     {
       
   307     return iAlbumCall;
       
   308     }
       
   309 
       
   310 void CImagePrintAppUi::SetAlbumCall(TInt aAlbumCall)
       
   311     {
       
   312     iAlbumCall = aAlbumCall;
       
   313     }
       
   314 
       
   315 void CImagePrintAppUi::SetValidImagesStatus( TBool aStatus )
       
   316     {
       
   317     iValidImages = aStatus;
       
   318     }
       
   319 
       
   320 void CImagePrintAppUi::ChangeViewL( TInt aView )
       
   321     {
       
   322     switch( aView )
       
   323         {	
       
   324         case MUIModeObserver::SettingsView:
       
   325             {
       
   326             ActivateLocalViewL( KImageSettingsViewId );
       
   327             break;
       
   328             }
       
   329         }
       
   330     }
       
   331 
       
   332 void CImagePrintAppUi::ExitApplication()
       
   333     {
       
   334     Exit();
       
   335     }
       
   336 
       
   337 
       
   338 TInt CImagePrintAppUi::GetAiwState()
       
   339     {
       
   340     return iAiwState;
       
   341     }
       
   342 
       
   343 TBool CImagePrintAppUi::AiwState()
       
   344     {
       
   345     TBool retValue = EFalse;
       
   346     if( iAiwState == EAiwPrintCall )
       
   347         {
       
   348         retValue = ETrue;
       
   349         }
       
   350     return retValue;
       
   351     }
       
   352 
       
   353 
       
   354 // Files from AIW customer
       
   355 CDesCArrayFlat* CImagePrintAppUi::GetImagesFromAiwProviderL()
       
   356     {
       
   357 	LOG("TBool CImagePrintAppUi::GetImagesFromAiwProvider() BEGIN");
       
   358 
       
   359     RFs fileServer;
       
   360     User::LeaveIfError(fileServer.Connect());
       
   361     CleanupClosePushL( fileServer );
       
   362     RFileReadStream readStream;
       
   363     
       
   364     TFileName paramFile;
       
   365     CIMGPPrintUtils::GetDataFilePathL( paramFile );
       
   366     
       
   367     User::LeaveIfError( readStream.Open(fileServer, paramFile, EFileRead) );
       
   368     readStream.PushL();
       
   369     CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC(readStream);
       
   370 
       
   371     CDesCArrayFlat* imageFiles = new (ELeave) CDesCArrayFlat(5);
       
   372 
       
   373 	TBool noOtherFileTypes( EFalse );
       
   374     TBool showFilesremovedNote ( EFalse );
       
   375 
       
   376     TInt index( 0 );
       
   377 	const TAiwGenericParam* param = paramList->FindFirst(index,
       
   378 			EGenericParamFile,
       
   379             EVariantTypeDesC);
       
   380 	while ( index != KErrNotFound )
       
   381 		{
       
   382 		TFileName filename( param->Value().AsDes() );
       
   383 		// CheckMIMEType needs to be changed so that we can distinguish between
       
   384 		// a) file not found b) file was incorrect MIME-type
       
   385 		noOtherFileTypes = CIMGPPrintUtils::CheckMIMEType( KJpegFileType, filename );
       
   386 		if ( noOtherFileTypes )
       
   387 			{
       
   388 			// check drm protection
       
   389 			CContent* content = NULL;
       
   390 			content = CContent::NewLC( filename );
       
   391 
       
   392 			TInt isDrmProtected( 0 );
       
   393 			TInt err = content->GetAttribute( EIsProtected, isDrmProtected );
       
   394 			CleanupStack::PopAndDestroy(); // content
       
   395    		if ( err || isDrmProtected )
       
   396     			{
       
   397     			LOG("CImagePrintAppUi::GetImagesFromAiwProvider(): found drm file!");
       
   398     			noOtherFileTypes = EFalse;
       
   399     			}
       
   400 			}
       
   401 
       
   402 		if ( noOtherFileTypes )
       
   403 			{
       
   404 			imageFiles->AppendL( filename );
       
   405 			}
       
   406         else
       
   407             {
       
   408             showFilesremovedNote = ETrue;
       
   409 		    }
       
   410 
       
   411 		param = paramList->FindNext(index,
       
   412 			EGenericParamFile,
       
   413             EVariantTypeDesC);
       
   414 		}
       
   415 
       
   416     if ( showFilesremovedNote )
       
   417         {
       
   418         CAknErrorNote* errornote = new (ELeave) CAknErrorNote( ETrue );
       
   419 		    HBufC* buf = StringLoader::LoadLC( R_QTN_PRINT_WRONGTYPE_NOTE );
       
   420 		    errornote->ExecuteLD( *buf );
       
   421 		    CleanupStack::PopAndDestroy( buf );
       
   422         }
       
   423     
       
   424     // If only one image is selected to print and it's corrupted, exit from application.
       
   425     if ( showFilesremovedNote && ( imageFiles->Count() == KErrNone ))
       
   426     	{
       
   427   		CAknErrorNote* errornote = new (ELeave) CAknErrorNote( ETrue );
       
   428 		HBufC* buf = StringLoader::LoadLC( R_QTN_PRINT_SELECTNEW_NOTE );
       
   429 		errornote->ExecuteLD( *buf );
       
   430 		CleanupStack::PopAndDestroy( buf );
       
   431 		Exit();
       
   432     	}
       
   433 
       
   434     CleanupStack::PopAndDestroy(paramList); //paramList
       
   435 
       
   436     LOG("TBool CImagePrintAppUi::GetImagesFromAiwProvider() END");
       
   437 
       
   438     readStream.Close();
       
   439     readStream.Pop();
       
   440     CleanupStack::PopAndDestroy( &fileServer );
       
   441     return imageFiles;
       
   442     }
       
   443 
       
   444 TBool CImagePrintAppUi::OrientationPortrait()
       
   445     {
       
   446     TBool retValue = ETrue;
       
   447     TSize screenSize = CCoeEnv::Static()->ScreenDevice()->SizeInPixels();
       
   448     if( screenSize.iWidth == 416 ||
       
   449     	screenSize.iWidth == 320 )
       
   450         {
       
   451         retValue = EFalse;
       
   452         }
       
   453     return retValue;
       
   454     }
       
   455 
       
   456 TBool CImagePrintAppUi::QVGAMode()
       
   457     {
       
   458     TBool retValue = EFalse;
       
   459     TSize screenSize = CCoeEnv::Static()->ScreenDevice()->SizeInPixels();
       
   460     if( screenSize.iWidth == 240 ||
       
   461     	screenSize.iWidth == 320 )
       
   462         {
       
   463         retValue = ETrue;
       
   464         }
       
   465     return retValue;
       
   466     }
       
   467 
       
   468 // Sets NaviPane text
       
   469 void CImagePrintAppUi::SetNavipaneTextL( const TInt aCopiesOfImage, HBufC* aPaperSize )
       
   470 	{	
       
   471 	// Navipane image count will be sum of all images on current print job.
       
   472 	// E.g. If 2 images selected and copies value is 2, navi value will be: 2 x 2 = 4.
       
   473 	TInt printCount = aCopiesOfImage * ( iFiles->MdcaCount() );
       
   474     
       
   475     // Buffer to store image or images -string.
       
   476 	HBufC* naviText;
       
   477     
       
   478     // If only one image to print navipane text will be: Image
       
   479     if ( printCount == 1 )
       
   480     	{    	
       
   481     	naviText = StringLoader::LoadLC( R_PRINTJOB_IMAGE );
       
   482 		}
       
   483     // If more than one image to print navipane text will be: Images
       
   484 	else 
       
   485 		{
       
   486 		naviText = StringLoader::LoadLC( R_PRINTJOB_IMAGES, printCount );
       
   487 		}  
       
   488 	
       
   489     TInt strLength = naviText->Length();
       
   490     
       
   491     CEikStatusPane* sp =
       
   492         iEikonEnv->AppUiFactory()->StatusPane();
       
   493     CAknNavigationControlContainer* np =
       
   494         static_cast<CAknNavigationControlContainer*>(
       
   495             sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   496     delete iNaviDecorator;
       
   497     iNaviDecorator = NULL;
       
   498 
       
   499     // If paper size needs to be added to the NaviPane, more space is needed
       
   500     if( aPaperSize )
       
   501         {
       
   502         strLength += aPaperSize->Length() + KLineLength;
       
   503         }
       
   504     // Clear the printer name string from all formatting tabs & numbers
       
   505 	HBufC* stringholder = HBufC::NewLC( strLength );
       
   506 	*stringholder = *naviText;
       
   507 	TPtr ptr = stringholder->Des();
       
   508 	TInt pos = stringholder->Find( KTabChar );
       
   509 	if ( pos == 1 ) // 1st possible icon formatting tab is at pos 1
       
   510 		{
       
   511 		ptr.Delete( 0, 2 ); // delete the first icon tab and the number previous to it
       
   512 		pos = stringholder->Find( KTabChar );
       
   513 		}
       
   514 	// 2nd possible iconformatting tab is 2nd last char (len - 2), don't delete it here  		
       
   515 	while ( pos != KErrNotFound &&
       
   516 		    pos != stringholder->Length() - 2 )
       
   517 		{
       
   518 		ptr.Delete( pos, 1); // delete all middle tabs
       
   519 		pos = stringholder->Find( KTabChar );
       
   520 		}
       
   521 	// 2nd possible iconformatting tab is 2nd last char
       
   522 	if ( pos != KErrNotFound &&
       
   523 		 pos == stringholder->Length() - 2 )
       
   524 		{
       
   525 		// delete the 2nd icon formatting tab and the number next to it
       
   526 		ptr.Delete( stringholder->Length() - 2, 2 );
       
   527 		}
       
   528 
       
   529     // Add paper size and '-', in the beginning of the text
       
   530     if( aPaperSize )
       
   531 	    {
       
   532         TPtr ptr2 = aPaperSize->Des();
       
   533         ptr.Insert(0, KLine);
       
   534         ptr.Insert(0, ptr2);
       
   535 	    }
       
   536 
       
   537     iNaviDecorator = np->CreateNavigationLabelL( *stringholder );
       
   538     CleanupStack::PopAndDestroy( stringholder );
       
   539     np->PushL( *iNaviDecorator );
       
   540     sp->DrawNow();
       
   541     
       
   542     CleanupStack::PopAndDestroy( naviText );
       
   543     }
       
   544 
       
   545 TUid CImagePrintAppUi::GetSettingsViewUid()
       
   546     {
       
   547     return KImageSettingsViewId;
       
   548     }
       
   549 
       
   550 // End of File