commsconfig/cscapplicationui/src/cscappui.cpp
changeset 0 a4daefaec16c
child 6 fc8c25e5a2e8
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2007-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:  CSC Applicationīs AppUi
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <apgcli.h>
       
    20 #include <AknDoc.h>
       
    21 #include <eikclb.h>
       
    22 #include <aknview.h>
       
    23 #include <eikappui.h>
       
    24 #include <cchclient.h>
       
    25 #include <cmmanagerext.h>
       
    26 #include <AknIconUtils.h>
       
    27 #include <AknsConstants.h>
       
    28 #include <cscsettingsui.h>
       
    29 #include <xSPViewServices.h>
       
    30 #include <AiwServiceHandler.h>
       
    31 #include <mspnotifychangeobserver.h>
       
    32 
       
    33 #include "cscappui.h"
       
    34 #include "csclogger.h"
       
    35 #include "cscdocument.h"
       
    36 #include "cscconstants.h"
       
    37 #include "cscserviceview.h"
       
    38 #include "cscengcchhandler.h"
       
    39 #include "cscengstartuphandler.h"
       
    40 #include "cscengservicehandler.h"
       
    41 #include "cscengbrandinghandler.h"
       
    42 #include "cscengconnectionhandler.h"
       
    43 #include "cscengservicepluginhandler.h"
       
    44 #include "cscengdestinationshandler.h"
       
    45 #include "cscenguiextensionpluginhandler.h"
       
    46 
       
    47 const TInt KMaxParamLength = 255;
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CCSCAppUi::CCSCAppUi()                         
       
    56     {
       
    57     }
       
    58     
       
    59     
       
    60 // ---------------------------------------------------------------------------
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void CCSCAppUi::ConstructL()
       
    64     {
       
    65     CSCDEBUG( "CCSCAppUi::ConstructL - begin" );
       
    66     
       
    67     BaseConstructL( 
       
    68         EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible );
       
    69     
       
    70     iStartupHandler = CCSCEngStartupHandler::NewL();
       
    71     iServiceHandler = CCSCEngServiceHandler::NewL( this );
       
    72     iBrandingHandler = CCSCEngBrandingHandler::NewL();
       
    73     iCCHHandler = CCSCEngCCHHandler::NewL( *this );
       
    74     iConnectionHandler = CCSCEngConnectionHandler::NewL( *this );
       
    75     
       
    76     CCSCEngServicePluginHandler* servicePluginHandler = 
       
    77         CCSCEngServicePluginHandler::NewL( 
       
    78             *iEikonEnv, *this, *iServiceHandler );
       
    79     
       
    80     CleanupStack::PushL( servicePluginHandler );
       
    81     
       
    82     CCSCEngUiExtensionPluginHandler* uiExtensionPluginHandler = 
       
    83         CCSCEngUiExtensionPluginHandler::NewL( 
       
    84             *iEikonEnv, *this, *iStartupHandler );
       
    85 
       
    86     CleanupStack::Pop( servicePluginHandler );
       
    87     
       
    88     // Responsibility or Plugin Handlers are transferred to document,
       
    89     // because UI framework might make calls to ECom plugin after the
       
    90     // application UI is deleted. Case exists when Exit() is 
       
    91     // called from plugin.
       
    92     CCSCDocument* doc = static_cast< CCSCDocument* >( Document() );
       
    93     doc->SetOwnershipOfPluginHandlers( 
       
    94         servicePluginHandler, uiExtensionPluginHandler );
       
    95     
       
    96     TRAP_IGNORE(   
       
    97         servicePluginHandler->InitializePluginsL();
       
    98         uiExtensionPluginHandler->InitializePluginsL();
       
    99         );
       
   100         
       
   101     iServiceView = CCSCServiceView::NewL( 
       
   102         *servicePluginHandler, 
       
   103         *uiExtensionPluginHandler,
       
   104         *iStartupHandler,
       
   105         *iServiceHandler,
       
   106         *iBrandingHandler,
       
   107         *iCCHHandler );
       
   108     
       
   109     AddViewL( iServiceView );
       
   110      
       
   111     CSCDEBUG( "CCSCAppUi::ConstructL - end" );
       
   112     }
       
   113 
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 CCSCAppUi::~CCSCAppUi()
       
   119     {
       
   120     CSCDEBUG( "CCSCAppUi::~CCSCAppUi - begin" );
       
   121         
       
   122     delete iStartupHandler;
       
   123     delete iServiceHandler;
       
   124     delete iBrandingHandler;
       
   125     delete iCCHHandler;
       
   126     delete iConnectionHandler;
       
   127                   
       
   128     CSCDEBUG( "CCSCAppUi::~CCSCAppUi - end" );
       
   129     }
       
   130 
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // From class CEikAppUi
       
   134 // For giving startup parameters to CSC application
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 TBool CCSCAppUi::ProcessCommandParametersL(
       
   138     TApaCommand /*aCommand*/,
       
   139     TFileName& aDocumentName,
       
   140     const TDesC8& /*aTail*/)
       
   141     {
       
   142     CSCDEBUG( "CCSCAppUi::ProcessCommandParametersL - begin" );
       
   143     
       
   144     if ( aDocumentName.Length() )
       
   145         {
       
   146         iStartupHandler->SetStartupParametersL( aDocumentName );
       
   147         if ( CCSCEngStartupHandler::EOpenSettingsUi == 
       
   148             iStartupHandler->GetParamAction() )
       
   149             {
       
   150             iServiceView->InitializeWithStartupParametersL();
       
   151             }
       
   152         }
       
   153         
       
   154     CSCDEBUG( "CCSCAppUi::ProcessCommandParametersL - end" );
       
   155     
       
   156     return EFalse;
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // From class CEikAppUi
       
   161 // For giving startup parameters to CSC application
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CCSCAppUi::ProcessMessageL( TUid /* aUid */, const TDesC8 &aParams )
       
   165 	{
       
   166 	CSCDEBUG( "CCSCAppUi::ProcessMessageL - begin" );
       
   167 	    
       
   168 	if ( aParams.Length() && ( aParams.Length() <= KMaxParamLength ) )
       
   169 	    {
       
   170         TBuf<KMaxParamLength> params;
       
   171 	    params.Copy( aParams );  
       
   172 	    iStartupHandler->SetStartupParametersL( params );
       
   173 	        
       
   174 	    iServiceView->InitializeWithStartupParametersL();
       
   175 	    iServiceView->ExecuteStartupActionsL( EFalse, EFalse );
       
   176 	    }
       
   177 	        
       
   178 	CSCDEBUG( "CCSCAppUi::ProcessMessageL - end" );
       
   179 	}
       
   180 
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // From class CAknViewAppUi
       
   184 // For command handling.
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 void CCSCAppUi::HandleCommandL( TInt aCommand ) 
       
   188     {
       
   189     CSCDEBUG( "CCSCAppUi::HandleCommandL - begin" );
       
   190     
       
   191     switch ( aCommand )
       
   192         {
       
   193         case EEikCmdExit:
       
   194         case EAknSoftkeyExit:
       
   195         case EAknSoftkeyBack:
       
   196         case EAknCmdExit:
       
   197             Exit();
       
   198             break;
       
   199         default:
       
   200             break;
       
   201         }
       
   202     
       
   203     CSCDEBUG( "CCSCAppUi::HandleCommandL - end" );
       
   204     }
       
   205 
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // From class CAknViewAppUi
       
   209 // Handling changing of the skin and layout.
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CCSCAppUi::HandleResourceChangeL( TInt aType )
       
   213     {
       
   214     CSCDEBUG( "CCSCAppUi::HandleResourceChangeL - begin" );
       
   215     
       
   216     if ( aType == KAknsMessageSkinChange || 
       
   217          aType == KEikDynamicLayoutVariantSwitch )
       
   218         {
       
   219         iServiceView->UpdateLayout( aType );
       
   220         }
       
   221 
       
   222     CAknViewAppUi::HandleResourceChangeL( aType );
       
   223     
       
   224     CSCDEBUG( "CCSCAppUi::HandleResourceChangeL - end" );
       
   225     }
       
   226 
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // From class MCSCProvisioningObserver
       
   230 // Notifies service plug-in event
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 void CCSCAppUi::NotifyServicePluginResponse( 
       
   234     const CCSCEngServicePluginHandler::TServicePluginResponse& aResponse, 
       
   235     const TInt aIndex, 
       
   236     const TUid& aPluginUid )
       
   237     {
       
   238     CSCDEBUG( "CCSCAppUi::NotifyServicePluginResponse - begin" );
       
   239     
       
   240     CCSCEngStartupHandler::TAction action = iStartupHandler->GetParamAction();
       
   241     TUid pluginUid = iStartupHandler->GetParamPluginUid();
       
   242   
       
   243     switch ( aResponse )
       
   244         {
       
   245         case CCSCEngServicePluginHandler::EPluginInitialized:
       
   246             {           
       
   247             // Run service configuration procedure, if new plugin is added
       
   248             // after service setup plugins has been initialized and plugin 
       
   249             // is set to be configured in startup parameters.
       
   250             if ( CCSCEngStartupHandler::EAddSetupPluginService == action &&
       
   251                 aPluginUid == pluginUid )
       
   252                 {       
       
   253                 TRAP_IGNORE( 
       
   254                     TBool canceled ( EFalse );
       
   255                     canceled = iServiceView->HandleServiceConfigurationL( 
       
   256                                 aPluginUid );
       
   257                                 
       
   258                     if ( canceled )
       
   259                         {
       
   260                         iServiceView->ExecuteStartupActionsL();
       
   261                         }
       
   262                     );
       
   263                 } 
       
   264             else if ( iStartupHandler->StartedFromHomescreen() )
       
   265                 {
       
   266                 TRAP_IGNORE( iServiceView->HandleServiceConfigurationL( KNullUid ) );
       
   267                 }
       
   268             break;
       
   269             }
       
   270         case CCSCEngServicePluginHandler::EPluginProvisioned:
       
   271             {
       
   272             CSCDEBUG( "CCSCAppUi::NotifyServicePluginResponse - plugin provisioned" );
       
   273                   
       
   274             // shutdown csc (provisioned service plugin should open phonebook tab).
       
   275             RunAppShutter();
       
   276             break;
       
   277             }
       
   278         case CCSCEngServicePluginHandler::EPluginRemoved:
       
   279             {
       
   280             // Service removed. If application is started with statup
       
   281             // parameters, close application and retuns to application
       
   282             // installer. Otherwise dismiss wait note from the screen.
       
   283             if ( CCSCEngStartupHandler::ERemoveSetupPluginService == action &&
       
   284                 KNullUid != pluginUid )
       
   285                 {
       
   286                 iServiceView->HideDialogWaitNote();
       
   287                 RunAppShutter();
       
   288                 }
       
   289             else
       
   290                 {
       
   291                 CCSCDocument* doc = 
       
   292                     static_cast< CCSCDocument* >( Document() );
       
   293                     
       
   294                 CCSCEngServicePluginHandler& handler = 
       
   295                     doc->ServicePluginHandler();
       
   296 
       
   297                 TServicePluginInfo pluginInfo = 
       
   298                     handler.ItemFromPluginInfoArray( aIndex );
       
   299                           
       
   300                 CAknView* view = View( pluginInfo.iViewId );
       
   301                 if( !view )
       
   302                     {
       
   303                     RemoveView( pluginInfo.iViewId );
       
   304                     }
       
   305                 else
       
   306                     {
       
   307                     // nothing to do
       
   308                     }
       
   309                        
       
   310                 iServiceView->HideDialogWaitNote();
       
   311                 }
       
   312             break;
       
   313             }
       
   314         case CCSCEngServicePluginHandler::EPluginError:
       
   315             {
       
   316             TRAP_IGNORE( iServiceView->ServiceConfiguringFailedL( aIndex ) );
       
   317             break;
       
   318             }
       
   319         case CCSCEngServicePluginHandler::EPluginModified:
       
   320         default:
       
   321              break;
       
   322         }
       
   323     
       
   324     CSCDEBUG( "CCSCAppUi::NotifyServicePluginResponse - end" );
       
   325     }
       
   326 
       
   327 
       
   328 // ---------------------------------------------------------------------------
       
   329 // From class MCSCUiExtensionObserver
       
   330 // Notifies when configuring of service plug-in is done.
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 void CCSCAppUi::NotifyUiExtensionPluginResponse( 
       
   334     const CCSCEngUiExtensionPluginHandler::TUiExtensionPluginResponse& 
       
   335     aResponse, 
       
   336     const TInt /*aIndex*/, 
       
   337     const TUid& /*aPluginUid*/ )
       
   338     {
       
   339     CSCDEBUG( "CCSCAppUi::NotifyUiExtensionPluginResponse - begin" );
       
   340     
       
   341     switch ( aResponse )
       
   342         {
       
   343         case CCSCEngUiExtensionPluginHandler::EPluginExited:
       
   344             {
       
   345             TRAP_IGNORE( iServiceView->HandleUiExtensionExitL() );
       
   346             break;
       
   347             }
       
   348         case CCSCEngUiExtensionPluginHandler::EPluginError:
       
   349             {
       
   350             TRAP_IGNORE( ActivateLocalViewL( KCSCServiceViewId ) );
       
   351             break;
       
   352             }
       
   353         case CCSCEngUiExtensionPluginHandler::EPluginInitialized:
       
   354             // nothing to do
       
   355         default:
       
   356             break;
       
   357         }
       
   358    
       
   359     CSCDEBUG( "CCSCAppUi::NotifyUiExtensionPluginResponse - end" );
       
   360     }
       
   361 
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // From class MCSCEngServiceObserver
       
   365 // Notifies when service(s) have changed.
       
   366 // ---------------------------------------------------------------------------
       
   367 //
       
   368 void CCSCAppUi::NotifyServiceChange()
       
   369     {
       
   370     CSCDEBUG( "CCSCAppUi::NotifyServiceChange - begin" );
       
   371     
       
   372     TVwsViewId activeViewId;
       
   373     GetActiveViewId( activeViewId );
       
   374     
       
   375     if( iServiceView && KCSCServiceViewId == activeViewId.iViewUid )
       
   376         {
       
   377         TRAP_IGNORE( iServiceView->UpdateServiceViewL() );
       
   378         }
       
   379     
       
   380     CSCDEBUG( "CCSCAppUi::NotifyServiceChange - end" );  
       
   381     }
       
   382 
       
   383 
       
   384 // ---------------------------------------------------------------------------
       
   385 // From class MCSCEngCCHObserver
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 void CCSCAppUi::ServiceStatusChanged(
       
   389     TUint aServiceId, 
       
   390     TCCHSubserviceType /*aType*/, 
       
   391     const TCchServiceStatus& aServiceStatus )
       
   392     {
       
   393     CSCDEBUG2( 
       
   394        "CCSCAppUi::ServiceStatusChanged - STATE=%d", aServiceStatus.State() );
       
   395     
       
   396     if ( ECCHDisabled == aServiceStatus.State() )
       
   397         {        
       
   398         TVwsViewId activeViewId;
       
   399         GetActiveViewId( activeViewId );
       
   400         
       
   401         if( iServiceView && KCSCServiceViewId == activeViewId.iViewUid )
       
   402             {            
       
   403             TRAPD( err, SnapCheckL( aServiceId ) );  
       
   404             
       
   405             if ( KErrInUse == err )
       
   406                 {
       
   407                 iMonitoredService = aServiceId;
       
   408                 }
       
   409             else
       
   410                 {
       
   411                 TRAP_IGNORE( iServiceView->DeleteServiceL( aServiceId ) );
       
   412                 }
       
   413             }
       
   414         }
       
   415         
       
   416     CSCDEBUG( "CCSCAppUi::ServiceStatusChanged - end" );
       
   417     }
       
   418 
       
   419 
       
   420 // ---------------------------------------------------------------------------
       
   421 // From class MCSCEngConnectionObserver
       
   422 // ---------------------------------------------------------------------------
       
   423 //
       
   424 void CCSCAppUi::NotifyConnectionEvent( 
       
   425     CCSCEngConnectionHandler::TConnectionEvent aConnectionEvent )
       
   426     {
       
   427     CSCDEBUG( "CCSCAppUi::NotifyConnectionEvent - begin" );
       
   428         
       
   429     TVwsViewId activeViewId;
       
   430     GetActiveViewId( activeViewId );
       
   431     
       
   432     if( ( iServiceView && KCSCServiceViewId == activeViewId.iViewUid ) &&
       
   433         ( CCSCEngConnectionHandler::EEventConnectionDown == aConnectionEvent || 
       
   434           CCSCEngConnectionHandler::EEventTimedOut == aConnectionEvent ) )
       
   435         {        
       
   436         iConnectionHandler->StopListeningConnectionEvents();
       
   437         TRAP_IGNORE( iServiceView->DeleteServiceL( iMonitoredService ) );
       
   438         }
       
   439     
       
   440     CSCDEBUG( "CCSCAppUi::NotifyConnectionEvent - end" );
       
   441     }
       
   442 
       
   443 // ---------------------------------------------------------------------------
       
   444 // For checking if SNAP is still in use.
       
   445 // ---------------------------------------------------------------------------
       
   446 //
       
   447 void CCSCAppUi::SnapCheckL( TUint aServiceId ) const
       
   448     {
       
   449     CSCDEBUG( "CCSCAppUi::SnapCheckL - begin" );  
       
   450     
       
   451     CCSCEngDestinationsHandler* destHandler =
       
   452         CCSCEngDestinationsHandler::NewL();
       
   453     CleanupStack::PushL( destHandler );
       
   454     
       
   455     TInt snapId( 0 );
       
   456     snapId = iServiceHandler->SnapIdL( aServiceId );
       
   457     
       
   458     if ( destHandler->IsSnapInUseL( snapId ) )
       
   459         {
       
   460         iConnectionHandler->StartListeningConnectionEvents();
       
   461         User::Leave( KErrInUse );
       
   462         }
       
   463     
       
   464     CleanupStack::PopAndDestroy( destHandler );
       
   465     
       
   466     CSCDEBUG( "CCSCAppUi::SnapCheckL - end" );  
       
   467     }