usbuis/imageprintuiprovider/src/caiwprintingprovider.cpp
changeset 93 2dc695882abd
parent 89 3592750162a5
equal deleted inserted replaced
89:3592750162a5 93:2dc695882abd
     1 /*
       
     2 * Copyright (c) 2006 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:  Launch Image Print App when file is marked or open MG
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "caiwprintingprovider.h"
       
    21 
       
    22 #include <AiwMenu.h>
       
    23 #include <AiwCommon.h>
       
    24 #include <AiwCommon.hrh>
       
    25 #include <coemain.h>
       
    26 #include <barsread.h>
       
    27 #include <imageprintuiprovider.rsg>
       
    28 
       
    29 #include <e32property.h>
       
    30 #include <s32strm.h>
       
    31 #include <s32file.h>
       
    32 #include <f32file.h>
       
    33 
       
    34 #include <apacmdln.h>
       
    35 #include <apgtask.h>
       
    36 #include <apaid.h>
       
    37 #include <apgcli.h>
       
    38 #include <w32std.h>
       
    39 #include <imageconversion.h>
       
    40 
       
    41 #include <aknViewAppUi.h>
       
    42 #include <aknnotedialog.h>
       
    43 #include <aknstaticnotedialog.h>
       
    44 #include <eikprogi.h>
       
    45 #include <aknnotewrappers.h>
       
    46 #include <StringLoader.h>
       
    47 #include <pathinfo.h> 
       
    48 
       
    49 #include "caiwimageprintif.h"
       
    50 #include "imageprintuidebug.h"
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // 
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CAiwPrintingProvider* CAiwPrintingProvider::NewL()
       
    58     {
       
    59 
       
    60     CAiwPrintingProvider* self = new( ELeave ) CAiwPrintingProvider;
       
    61     CleanupStack::PushL( self );
       
    62     self->ConstructL();
       
    63     CleanupStack::Pop( self );
       
    64     return self;
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // 
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CAiwPrintingProvider::~CAiwPrintingProvider()
       
    72     {
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // 
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 void CAiwPrintingProvider::InitialiseL( MAiwNotifyCallback& aFrameworkCallback,
       
    80                                        const RCriteriaArray& /*aInterest*/ )
       
    81     {
       
    82     iNotifyCallback = &aFrameworkCallback;
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // 
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CAiwPrintingProvider::HandleServiceCmdL( const TInt& aCmdId,
       
    90                                const CAiwGenericParamList& aInParamList,
       
    91                                CAiwGenericParamList& aOutParamList,
       
    92                                TUint aCmdOptions,
       
    93                                const MAiwNotifyCallback* aCallback )
       
    94 
       
    95     {
       
    96     FLOG(_L("[CAiwPrintingProvider]<<<  HandleServiceCmdL BEGIN"));
       
    97     DoHandleCmdL( aCmdId, aInParamList, aOutParamList, aCmdOptions, aCallback );
       
    98     FLOG(_L("[CAiwPrintingProvider]<<<  HandleServiceCmdL END"));
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // 
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CAiwPrintingProvider::InitializeMenuPaneL
       
   106         ( CAiwMenuPane& aMenuPane, TInt aIndex,
       
   107          TInt /*aCascadeId*/, const CAiwGenericParamList& aInParamList )
       
   108     {
       
   109     FLOG(_L("[CAiwPrintingProvider]<<<  InitializeMenuPaneL BEGIN"));
       
   110     if ( IsPrintingSupported( aInParamList ) )
       
   111         {
       
   112         TResourceReader reader;
       
   113         iEikEnv.CreateResourceReaderLC
       
   114                 ( reader, R_AIW_PRINTING_PROVIDER_MENU );
       
   115         aMenuPane.AddMenuItemsL( reader, KAiwCmdPrint, aIndex );
       
   116         CleanupStack::PopAndDestroy(); // aResourceId 
       
   117         }
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // 
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void CAiwPrintingProvider::HandleMenuCmdL
       
   125         ( TInt aMenuCmdId, const CAiwGenericParamList& aInParamList,
       
   126          CAiwGenericParamList& aOutParamList, TUint aCmdOptions,
       
   127          const MAiwNotifyCallback* aCallback)
       
   128     {
       
   129     FLOG(_L("[CAiwPrintingProvider]<<<  HandleMenuCmdL BEGIN"));
       
   130     DoHandleCmdL( aMenuCmdId, aInParamList, aOutParamList, aCmdOptions, aCallback );
       
   131     FLOG(_L("[CAiwPrintingProvider]<<<  HandleMenuCmdL END"));
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // 
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CAiwPrintingProvider::DoHandleCmdL(TInt aMenuCmdId,
       
   139                             const CAiwGenericParamList& aInParamList,
       
   140                             CAiwGenericParamList& aOutParamList,
       
   141                             TUint /*aCmdOptions*/,
       
   142                             const MAiwNotifyCallback* aCallback)
       
   143     {
       
   144     if ( aMenuCmdId == KAiwCmdPrint || aMenuCmdId == KAiwCmdPrintPreview  )
       
   145         {
       
   146         FLOG(_L("[CAiwPrintingProvider]<<<  DoHandleCmdL"));
       
   147         
       
   148         CAiwGenericParamList* checkedParams = CAiwGenericParamList::NewL();
       
   149         
       
   150         iConsumerInParamList = &aInParamList;
       
   151         iConsumerOutParamList = &aOutParamList;
       
   152         iConsumerCallback = aCallback;
       
   153         
       
   154         TInt index( 0 );
       
   155 	    const TAiwGenericParam* param = aInParamList.FindFirst(index,
       
   156 	            EGenericParamFile,
       
   157 	            EVariantTypeDesC);
       
   158 	    while ( index != KErrNotFound )
       
   159 			{
       
   160 	        TFileName filename( param->Value().AsDes() );
       
   161  	        TInt err = KErrNone;
       
   162 	        TBool result = EFalse;
       
   163 	        TRAP( err, result = IsPrintingSupportedL( filename ) );
       
   164 	        if ( err == KErrNone && result )
       
   165 	        	{
       
   166 	            FLOG(_L("[CAiwPrintingProvider] DoHandleCmdL; supported file"));
       
   167 	        	checkedParams->AppendL(*param);
       
   168 	        	}
       
   169 	        else
       
   170 	        	{
       
   171 	        	FLOG(_L("[CAiwPrintingProvider] DoHandleCmdL; not supported"));
       
   172 	        	++iNumberOfUnSuppFiles;
       
   173 	        	iUnsupportedFiles = ETrue;
       
   174 	        	}	
       
   175 	        param = aInParamList.FindNext(index,
       
   176 	            EGenericParamFile,
       
   177 	            EVariantTypeDesC);
       
   178 	        }
       
   179    
       
   180                 
       
   181 		FTRACE(FPrint(_L("[CAiwPrintingProvider] UnSuppFiles is %d"), iNumberOfUnSuppFiles )); 
       
   182 
       
   183 		RFileWriteStream stream;
       
   184 	  	CleanupClosePushL(stream);
       
   185 		if((stream.Replace(iEikEnv.FsSession(), *iUnsuppFileName ,EFileWrite)) == KErrNone)
       
   186 			{
       
   187 			stream.WriteInt16L(iNumberOfUnSuppFiles);
       
   188 			stream.CommitL();
       
   189 			}
       
   190 		CleanupStack::PopAndDestroy(&stream); 
       
   191 		
       
   192         FLOG(_L("[IMAGEPRINTUI]<<< CAiwPrintingProvider;Save iUnsupportedFiles  is done"));
       
   193 	
       
   194         
       
   195         RFileWriteStream writeStream;
       
   196         User::LeaveIfError( writeStream.Replace(iEikEnv.FsSession(),
       
   197         										*iPrintFileName , EFileWrite) );
       
   198         writeStream.PushL();
       
   199         checkedParams->ExternalizeL(writeStream);
       
   200         writeStream.CommitL();
       
   201         CleanupStack::PopAndDestroy( &writeStream );
       
   202         
       
   203         iNumberOfUnSuppFiles = 0;
       
   204         delete checkedParams;
       
   205         checkedParams = NULL;
       
   206         
       
   207         LaunchImagePrintApplicationL();
       
   208         FLOG(_L("[CAiwPrintingProvider]>>> DoHandleCmdL "));
       
   209         }
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // 
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CAiwPrintingProvider::StartApplicationL()
       
   217 	{
       
   218 	FLOG(_L("[CAiwPrintingProvider] StartApplicationL"));
       
   219 	LaunchImagePrintApplicationL();
       
   220 	}
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // 
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 
       
   227 TBool CAiwPrintingProvider::IsImagePrintUiRunning()
       
   228     {
       
   229     TFindThread findt(KImagePrintUiSearchPatternBySID);
       
   230     TFullName result;
       
   231     TBool running(EFalse);
       
   232     if (!findt.Next(result))
       
   233         {
       
   234         FTRACE(FPrint(_L("[CAiwPrintingProvider] Thread '%S'is found"), &result));
       
   235         running = ETrue;
       
   236         }
       
   237      return running;
       
   238     }
       
   239 // ---------------------------------------------------------------------------
       
   240 // 
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CAiwPrintingProvider::ShowNoteL()
       
   244     {
       
   245     FLOG(_L("[CAiwPrintingProvider]>>> App launch error "));
       
   246     HBufC* str = StringLoader::LoadLC( R_USB_INFO_APP_IN_USE  );
       
   247     CAknErrorNote* note = new ( ELeave ) CAknErrorNote;
       
   248     note->ExecuteLD( *str );
       
   249     CleanupStack::PopAndDestroy( str );  // str	
       
   250     }
       
   251 
       
   252 // ---------------------------------------------------------------------------
       
   253 // 
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 void CAiwPrintingProvider::LaunchImagePrintApplicationL()
       
   257     {
       
   258     FLOG(_L("[CAiwPrintingProvider]<<< LaunchImagePrintApplicationL"));
       
   259     TUid appuid;
       
   260     appuid.iUid = KImagePrintUID;
       
   261     if (!IsImagePrintUiRunning())
       
   262         { 
       
   263         TRAPD( err, iService = CAknLaunchAppService::NewL(
       
   264         appuid,
       
   265         this,
       
   266         NULL ));
       
   267 	   
       
   268 	    if ( err != KErrNone )
       
   269 		   { 
       
   270 		   FTRACE(FPrint(_L("[CAiwPrintingProvider] error when launch is  %d"), err ));
       
   271 	       FLOG(_L("[CAiwPrintingProvider] LaunchImagePrintApplicationL  error"));
       
   272 		   }   
       
   273         }
       
   274     else
       
   275         {
       
   276      	ShowNoteL(); 
       
   277 		}
       
   278     
       
   279     FLOG(_L("[CAiwPrintingProvider]>>> LaunchImagePrintApplicationL"));
       
   280     }
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // 
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 void CAiwPrintingProvider::HandleServerAppExit( TInt aReason )
       
   287     {
       
   288     delete iService;
       
   289     iService = NULL;
       
   290     FLOG(_L("[CAiwPrintingProvider]<<<  HandleServerAppExit"));
       
   291 
       
   292     // In the case that we want to exit also the parent application,
       
   293     // ImagePrint is exited with User::Exit() which is seen here as
       
   294     // KErrServerTerminated (-15).
       
   295     if( iConsumerInParamList && iConsumerOutParamList && iConsumerCallback && iConsumerCallback )
       
   296         {
       
   297         // Const cast is used to fix weirdness in AIW header files. MWaiNotifyCallback
       
   298         // does not define any const function but CAiwServiceIfMenu interface provides
       
   299         // const callback object.
       
   300         TRAP_IGNORE( const_cast<MAiwNotifyCallback*>(iConsumerCallback)->HandleNotifyL(
       
   301             KAiwCmdPrintPreview, KAiwEventCompleted,
       
   302             *iConsumerOutParamList, *iConsumerInParamList ));
       
   303         iConsumerInParamList = NULL;
       
   304         iConsumerOutParamList = NULL;
       
   305         iConsumerCallback = NULL;
       
   306         }
       
   307     if ( aReason == KErrServerTerminated )
       
   308         {
       
   309         FLOG(_L("[CAiwPrintingProvider]  HandleServerAppExit KErrServerTerminated"));
       
   310         }
       
   311     }
       
   312 
       
   313 // End of file
       
   314