ImagePrint/ImagePrintUI/imageprintapp/src/cimageprintsettingsview.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 <aknViewAppUi.h>
       
    20 #include <aknnavi.h>
       
    21 #include <akntitle.h>
       
    22 #include <avkon.hrh>
       
    23 #include <imageprintapp.rsg>
       
    24 #include <eikmenup.h>
       
    25 #include <aknnotewrappers.h>
       
    26 #include <StringLoader.h>
       
    27 #include <wlaninternalpskeys.h>
       
    28 #include <e32property.h>
       
    29 
       
    30 #include "cimageprintsettingsview.h"
       
    31 #include "cimageprintsettingscontainer.h"
       
    32 #include "cimageprintsettingsview.h"
       
    33 #include "cimageprintappui.h"
       
    34 #include "cimageprintdoc.h"
       
    35 #include "cimgpprintdlgmanager.h"
       
    36 #include "mprintsettings.h"
       
    37 #include "mprintjob.h"
       
    38 #include "imageprintapp.hrh"
       
    39 #include "cimageprintengine.h"
       
    40 #include "muimode.h"
       
    41 #include "ciffactory.h"
       
    42 #include "mdiscoveryobserver.h"
       
    43 
       
    44 _LIT( KImagePrintAppHelpSettings, "IMGPRNAPP_HLP_SETTINGS" );
       
    45 
       
    46 // CONSTRUCTION
       
    47 CImagePrintSettingsView* CImagePrintSettingsView::NewL(
       
    48     MPrintSettings* aSettings,
       
    49     MPrintJob* aPrintJob,
       
    50     CImagePrintAppUi* aAppUi,
       
    51     MUIMode* aUIMode )
       
    52     {
       
    53     CImagePrintSettingsView* self = CImagePrintSettingsView::NewLC(
       
    54         aSettings, aPrintJob, aAppUi, aUIMode );
       
    55     CleanupStack::Pop();	// self
       
    56 
       
    57     return self;
       
    58     }
       
    59 
       
    60 CImagePrintSettingsView* CImagePrintSettingsView::NewLC( 
       
    61     MPrintSettings* aSettings,
       
    62     MPrintJob* aPrintJob,
       
    63     CImagePrintAppUi* aAppUi,
       
    64     MUIMode* aUIMode )
       
    65     {
       
    66     CImagePrintSettingsView* self = 
       
    67         new ( ELeave ) CImagePrintSettingsView( aPrintJob, aAppUi, aUIMode  );    
       
    68     CleanupStack::PushL( self );
       
    69     self->ConstructL( aSettings);
       
    70 
       
    71     return self;
       
    72     }
       
    73 
       
    74 // 2nd phase constructor
       
    75 void CImagePrintSettingsView::ConstructL(
       
    76     MPrintSettings* aSettings )
       
    77     {    
       
    78        
       
    79     iSettings = aSettings;    
       
    80     TUint vendor = iSettings->GetCurrentPrinterVendor();
       
    81     iPrintDlgManager = CIMGPPrintDlgManager::NewL( 1,
       
    82         iPrintJob, aSettings->NumOfPagesL(), 
       
    83         aSettings->IsMMC(), vendor );
       
    84     BaseConstructL( R_SETTINGS_VIEW );    
       
    85     }
       
    86 
       
    87 // Default constructor
       
    88 CImagePrintSettingsView::CImagePrintSettingsView( 
       
    89     MPrintJob* aPrintJob, CImagePrintAppUi* aAppUi, MUIMode* aUIMode ) 
       
    90       : CAknView(),
       
    91         iPrintJob( aPrintJob ),
       
    92         iAppUi( aAppUi ),
       
    93         iUIMode(aUIMode)
       
    94     {
       
    95     }
       
    96 
       
    97 // Default destructor
       
    98 CImagePrintSettingsView::~CImagePrintSettingsView()
       
    99     {
       
   100     delete iPrintDlgManager;
       
   101     DestroyContainer();
       
   102     }
       
   103 
       
   104 // Returns IDs
       
   105 TUid CImagePrintSettingsView::Id() const
       
   106     {
       
   107     return KImageSettingsViewId;
       
   108     }
       
   109 
       
   110 // Handles commands coming to this viwe
       
   111 void CImagePrintSettingsView::HandleCommandL(
       
   112     TInt aCommand )
       
   113     {
       
   114     switch ( aCommand )
       
   115         {
       
   116         case ESettingsChangeItem:
       
   117             {
       
   118             iContainer->EditItemL();
       
   119             break;
       
   120             }
       
   121 
       
   122         case ESettingsPrint:
       
   123             {
       
   124             StartPrintingL();
       
   125             break;
       
   126             }
       
   127 
       
   128         case ESettingsExit:  
       
   129             {
       
   130             // Exit caller also
       
   131             AppUi()->HandleCommandL( EEikCmdExit );          
       
   132             break;
       
   133             }
       
   134 
       
   135         case EAknSoftkeyBack:
       
   136             {
       
   137             // Exit to gallery
       
   138             AppUi()->HandleCommandL( EAknCmdExit );
       
   139             break;
       
   140             }
       
   141 
       
   142         case ECmdPrintHelp:
       
   143             {
       
   144             iAppUi->LaunchHelpApplicationL( KImagePrintAppHelpSettings );
       
   145             break;
       
   146             }
       
   147 
       
   148         default:            
       
   149             AppUi()->HandleCommandL( aCommand );
       
   150             break;
       
   151         }
       
   152     }
       
   153 
       
   154 // Activates the view, creates the control container
       
   155 void CImagePrintSettingsView::DoActivateL(
       
   156     const TVwsViewId& /*aPrevViewId*/,
       
   157     TUid /*aCustomMessageId*/,
       
   158     const TDesC8& /*aCustomMessage*/)
       
   159     {
       
   160     // Change the status pane text
       
   161     CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane();
       
   162     sp->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL );
       
   163     CAknTitlePane* tp = static_cast<CAknTitlePane*>( 
       
   164         sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); 
       
   165     tp->SetTextL( iEikonEnv->AllocReadResourceLC( 
       
   166         R_TXT_IMAGEPRINT_TITLE_PRINTSETTINGS )->Des() );
       
   167     CleanupStack::PopAndDestroy();  // tp
       
   168     sp->DrawNow();
       
   169     
       
   170     if ( !iContainer )
       
   171         {
       
   172         iContainer = CImagePrintSettingsContainer::NewL( 
       
   173             iSettings, this, AppUi()->ClientRect(), iAppUi, iUIMode );        
       
   174         AppUi()->AddToStackL( *this, iContainer );
       
   175 		}      
       
   176 	}
       
   177 
       
   178 // Deactivates view, deletes the control
       
   179 void CImagePrintSettingsView::DoDeactivate()
       
   180     {
       
   181     DestroyContainer();
       
   182     }
       
   183 
       
   184 // Destroys control container
       
   185 void CImagePrintSettingsView::DestroyContainer()
       
   186     {
       
   187     if ( iContainer )
       
   188         {
       
   189         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   190         }
       
   191 
       
   192     delete iContainer;
       
   193     iContainer = 0;
       
   194     }
       
   195 
       
   196 // Starts the printing sequence
       
   197 void CImagePrintSettingsView::StartPrintingL()
       
   198     {
       
   199     
       
   200     // First of all check that WLAN is on, in case WLAN is current printing protocol.
       
   201     if ( iSettings->GetCurrentPrinterProtocol() == MDiscoveryObserver::EWLAN )
       
   202     	{
       
   203 		HandlePossibleLinkDisconnectionL();   
       
   204     	}
       
   205     
       
   206     TUint vendor = iSettings->GetCurrentPrinterVendor();
       
   207     
       
   208     // Default number of copies value = 1, so keep it, if iSettings doesn't return deviant value.
       
   209     TInt copiesBuffer = 1;
       
   210     iSettings->NumberOfCopies( copiesBuffer, 0 );
       
   211 
       
   212     delete iPrintDlgManager;
       
   213     iPrintDlgManager = 0;
       
   214     iPrintDlgManager = CIMGPPrintDlgManager::NewL( copiesBuffer,
       
   215     iPrintJob, iSettings->NumOfPagesL(), 
       
   216     iSettings->IsMMC(), vendor );
       
   217     
       
   218     CIFFactory& factory = iAppUi->GetDocument()->Engine()->InterfaceFactory();
       
   219     factory.SettingsIF()->UpdateNumberOfCopiesToServer();
       
   220      
       
   221     iPrintDlgManager->StartPrintingL();
       
   222     }
       
   223 
       
   224 void CImagePrintSettingsView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
       
   225     {
       
   226     // Hide command <exit> if application is started from active idle 
       
   227     // and it is in landscape orientation
       
   228     if( aResourceId == R_PROFILE_LIST_VIEW_MENU ) 
       
   229         {
       
   230 		// If there is no default printer selected, remove print option from menu to avoid incorrect print sequency. 
       
   231         TInt currentProtocol = iSettings->GetCurrentPrinterProtocol();
       
   232         if ( currentProtocol == MDiscoveryObserver::ENOPRINTER )
       
   233         	{
       
   234         	aMenuPane->DeleteMenuItem( ESettingsPrint );
       
   235         	}          
       
   236         }
       
   237     }
       
   238 
       
   239 void CImagePrintSettingsView::HandleForegroundEventL( TBool aForeground )
       
   240     {
       
   241     if ( aForeground )
       
   242         {
       
   243         ViewScreenDeviceChangedL();
       
   244         }
       
   245     }
       
   246 
       
   247 void CImagePrintSettingsView::HandlePossibleLinkDisconnectionL()	
       
   248 	{
       
   249 	TInt wlanState;
       
   250 	RProperty::Get( KPSUidWlan, KPSWlanIndicator, wlanState );
       
   251 
       
   252 	if ( wlanState == EPSWlanIndicatorNone )
       
   253       	{         
       
   254       	// Show connection to printer lost -note and exit application.
       
   255 		HBufC* buf = StringLoader::LoadLC( R_NOTE_DISCONNECT_PRINT_ERROR );
       
   256 		CAknErrorNote* errornote = new CAknErrorNote( ETrue );       
       
   257 		errornote->ExecuteLD( *buf );	        	
       
   258 		CleanupStack::PopAndDestroy( buf );
       
   259 	    	
       
   260 		AppUi()->HandleCommandL( EEikCmdExit );  
       
   261 		}
       
   262 	}
       
   263 
       
   264 
       
   265 //  End of File