commsconfig/cscapplicationui/src/cscappui.cpp
branchRCL_3
changeset 22 d38647835c2e
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2007-2010 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 #include <gsfwviewuids.h>
       
    33 #include <apgwgnam.h>
       
    34 
       
    35 #include "cscappui.h"
       
    36 #include "csclogger.h"
       
    37 #include "cscdocument.h"
       
    38 #include "cscconstants.h"
       
    39 #include "cscserviceview.h"
       
    40 #include "cscengcchhandler.h"
       
    41 #include "cscengstartuphandler.h"
       
    42 #include "cscengservicehandler.h"
       
    43 #include "cscengbrandinghandler.h"
       
    44 #include "cscengconnectionhandler.h"
       
    45 #include "cscengservicepluginhandler.h"
       
    46 #include "cscengdestinationshandler.h"
       
    47 #include "cscenguiextensionpluginhandler.h"
       
    48 
       
    49 const TInt KMaxParamLength = 255;
       
    50 const TInt KGSChildAppWindowGroupNameLength = 100;
       
    51 
       
    52 // ======== MEMBER FUNCTIONS ========
       
    53 
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CCSCAppUi::CCSCAppUi()                         
       
    59     {
       
    60     }
       
    61     
       
    62     
       
    63 // ---------------------------------------------------------------------------
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 void CCSCAppUi::ConstructL()
       
    67     {
       
    68     CSCDEBUG( "CCSCAppUi::ConstructL - begin" );
       
    69     
       
    70     BaseConstructL( 
       
    71         EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible );
       
    72     
       
    73     iStartupHandler = CCSCEngStartupHandler::NewL();
       
    74     iServiceHandler = CCSCEngServiceHandler::NewL( this );
       
    75     iBrandingHandler = CCSCEngBrandingHandler::NewL();
       
    76     iCCHHandler = CCSCEngCCHHandler::NewL( *this );
       
    77     iConnectionHandler = CCSCEngConnectionHandler::NewL( *this );
       
    78     
       
    79     CCSCEngServicePluginHandler* servicePluginHandler = 
       
    80         CCSCEngServicePluginHandler::NewL( 
       
    81             *iEikonEnv, *this, *iServiceHandler );
       
    82     
       
    83     CleanupStack::PushL( servicePluginHandler );
       
    84     
       
    85     CCSCEngUiExtensionPluginHandler* uiExtensionPluginHandler = 
       
    86         CCSCEngUiExtensionPluginHandler::NewL( 
       
    87             *iEikonEnv, *this, *iStartupHandler );
       
    88 
       
    89     CleanupStack::Pop( servicePluginHandler );
       
    90     
       
    91     // Responsibility or Plugin Handlers are transferred to document,
       
    92     // because UI framework might make calls to ECom plugin after the
       
    93     // application UI is deleted. Case exists when Exit() is 
       
    94     // called from plugin.
       
    95     CCSCDocument* doc = static_cast< CCSCDocument* >( Document() );
       
    96     doc->SetOwnershipOfPluginHandlers( 
       
    97         servicePluginHandler, uiExtensionPluginHandler );
       
    98     
       
    99     TRAP_IGNORE(   
       
   100         servicePluginHandler->InitializePluginsL();
       
   101         uiExtensionPluginHandler->InitializePluginsL();
       
   102         );
       
   103         
       
   104     iServiceView = CCSCServiceView::NewL( 
       
   105         *servicePluginHandler, 
       
   106         *uiExtensionPluginHandler,
       
   107         *iStartupHandler,
       
   108         *iServiceHandler,
       
   109         *iBrandingHandler,
       
   110         *iCCHHandler );
       
   111     
       
   112     AddViewL( iServiceView );
       
   113      
       
   114     CSCDEBUG( "CCSCAppUi::ConstructL - end" );
       
   115     }
       
   116 
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 CCSCAppUi::~CCSCAppUi()
       
   122     {
       
   123     CSCDEBUG( "CCSCAppUi::~CCSCAppUi - begin" );
       
   124         
       
   125     delete iStartupHandler;
       
   126     delete iServiceHandler;
       
   127     delete iBrandingHandler;
       
   128     delete iCCHHandler;
       
   129     delete iConnectionHandler;
       
   130                   
       
   131     CSCDEBUG( "CCSCAppUi::~CCSCAppUi - end" );
       
   132     }
       
   133 
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // From class CEikAppUi
       
   137 // For giving startup parameters to CSC application
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 TBool CCSCAppUi::ProcessCommandParametersL(
       
   141     TApaCommand /*aCommand*/,
       
   142     TFileName& aDocumentName,
       
   143     const TDesC8& /*aTail*/)
       
   144     {
       
   145     CSCDEBUG( "CCSCAppUi::ProcessCommandParametersL - begin" );
       
   146     
       
   147     if ( aDocumentName.Length() )
       
   148         {
       
   149         iStartupHandler->SetStartupParametersL( aDocumentName );
       
   150         if ( CCSCEngStartupHandler::EOpenSettingsUi == 
       
   151             iStartupHandler->GetParamAction() )
       
   152             {
       
   153             iServiceView->InitializeWithStartupParametersL();
       
   154             }
       
   155         }
       
   156         
       
   157     CSCDEBUG( "CCSCAppUi::ProcessCommandParametersL - end" );
       
   158     
       
   159     return EFalse;
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // From class CEikAppUi
       
   164 // For giving startup parameters to CSC application
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CCSCAppUi::ProcessMessageL( TUid /* aUid */, const TDesC8 &aParams )
       
   168 	{
       
   169 	CSCDEBUG( "CCSCAppUi::ProcessMessageL - begin" );
       
   170 	    
       
   171 	if ( aParams.Length() && ( aParams.Length() <= KMaxParamLength ) )
       
   172 	    {
       
   173         TBuf<KMaxParamLength> params;
       
   174 	    params.Copy( aParams );  
       
   175 	    iStartupHandler->SetStartupParametersL( params );
       
   176 	        
       
   177 	    iServiceView->InitializeWithStartupParametersL();
       
   178 	    iServiceView->ExecuteStartupActionsL( EFalse, EFalse );
       
   179 	    }
       
   180 	        
       
   181 	CSCDEBUG( "CCSCAppUi::ProcessMessageL - end" );
       
   182 	}
       
   183 
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // From class CAknViewAppUi
       
   187 // For command handling.
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CCSCAppUi::HandleCommandL( TInt aCommand ) 
       
   191     {
       
   192     CSCDEBUG( "CCSCAppUi::HandleCommandL - begin" );
       
   193     
       
   194     switch ( aCommand )
       
   195         {
       
   196         case EAknSoftkeyBack:
       
   197             {
       
   198             Exit();
       
   199             break;
       
   200             }
       
   201         case EEikCmdExit:
       
   202         case EAknSoftkeyExit:
       
   203         case EAknCmdExit:
       
   204             {
       
   205             ExitGSIfParentL();
       
   206             Exit();
       
   207             break;
       
   208             }
       
   209         default:
       
   210             break;
       
   211         }
       
   212     
       
   213     CSCDEBUG( "CCSCAppUi::HandleCommandL - end" );
       
   214     }
       
   215 
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // From class CAknViewAppUi
       
   219 // Handling changing of the skin and layout.
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 void CCSCAppUi::HandleResourceChangeL( TInt aType )
       
   223     {
       
   224     CSCDEBUG( "CCSCAppUi::HandleResourceChangeL" );
       
   225 
       
   226     CAknViewAppUi::HandleResourceChangeL( aType );
       
   227     }
       
   228 
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // From class MCSCProvisioningObserver
       
   232 // Notifies service plug-in event
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 void CCSCAppUi::NotifyServicePluginResponse( 
       
   236     const CCSCEngServicePluginHandler::TServicePluginResponse& aResponse, 
       
   237     const TInt aIndex, 
       
   238     const TUid& aPluginUid )
       
   239     {
       
   240     CSCDEBUG( "CCSCAppUi::NotifyServicePluginResponse - begin" );
       
   241     
       
   242     CCSCEngStartupHandler::TAction action = iStartupHandler->GetParamAction();
       
   243     TUid pluginUid = iStartupHandler->GetParamPluginUid();
       
   244   
       
   245     switch ( aResponse )
       
   246         {
       
   247         case CCSCEngServicePluginHandler::EPluginInitialized:
       
   248             {           
       
   249             // Run service configuration procedure, if new plugin is added
       
   250             // after service setup plugins has been initialized and plugin 
       
   251             // is set to be configured in startup parameters.
       
   252             if ( CCSCEngStartupHandler::EAddSetupPluginService == action &&
       
   253                 aPluginUid == pluginUid )
       
   254                 {       
       
   255                 TRAP_IGNORE( 
       
   256                     TBool canceled ( EFalse );
       
   257                     canceled = iServiceView->HandleServiceConfigurationL( 
       
   258                                 aPluginUid );
       
   259                                 
       
   260                     if ( canceled )
       
   261                         {
       
   262                         iServiceView->ExecuteStartupActionsL();
       
   263                         }
       
   264                     );
       
   265                 } 
       
   266             else if ( iStartupHandler->StartedFromHomescreen() )
       
   267                 {
       
   268                 TRAP_IGNORE( iServiceView->HandleServiceConfigurationL( KNullUid ) );
       
   269                 }
       
   270             break;
       
   271             }
       
   272         case CCSCEngServicePluginHandler::EPluginProvisioned:
       
   273             {
       
   274             CSCDEBUG( "CCSCAppUi::NotifyServicePluginResponse - plugin provisioned" );
       
   275                   
       
   276             // shutdown csc (provisioned service plugin should open phonebook tab).
       
   277             RunAppShutter();
       
   278             break;
       
   279             }
       
   280         case CCSCEngServicePluginHandler::EPluginRemoved:
       
   281             {
       
   282             // Service removed. If application is started with statup
       
   283             // parameters, close application and retuns to application
       
   284             // installer. Otherwise dismiss wait note from the screen.
       
   285             if ( CCSCEngStartupHandler::ERemoveSetupPluginService == action &&
       
   286                 KNullUid != pluginUid )
       
   287                 {
       
   288                 iServiceView->HideDialogWaitNote();
       
   289                 RunAppShutter();
       
   290                 }
       
   291             else
       
   292                 {
       
   293                 CCSCDocument* doc = 
       
   294                     static_cast< CCSCDocument* >( Document() );
       
   295                     
       
   296                 CCSCEngServicePluginHandler& handler = 
       
   297                     doc->ServicePluginHandler();
       
   298 
       
   299                 TServicePluginInfo pluginInfo = 
       
   300                     handler.ItemFromPluginInfoArray( aIndex );
       
   301                           
       
   302                 CAknView* view = View( pluginInfo.iViewId );
       
   303                 if( !view )
       
   304                     {
       
   305                     RemoveView( pluginInfo.iViewId );
       
   306                     }
       
   307                 else
       
   308                     {
       
   309                     // nothing to do
       
   310                     }
       
   311                        
       
   312                 iServiceView->HideDialogWaitNote();
       
   313                 }
       
   314             break;
       
   315             }
       
   316         case CCSCEngServicePluginHandler::EPluginError:
       
   317             {
       
   318             TRAP_IGNORE( iServiceView->ServiceConfiguringFailedL( aIndex ) );
       
   319             break;
       
   320             }
       
   321         case CCSCEngServicePluginHandler::EPluginModified:
       
   322         default:
       
   323              break;
       
   324         }
       
   325     
       
   326     CSCDEBUG( "CCSCAppUi::NotifyServicePluginResponse - end" );
       
   327     }
       
   328 
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // From class MCSCUiExtensionObserver
       
   332 // Notifies when configuring of service plug-in is done.
       
   333 // ---------------------------------------------------------------------------
       
   334 //
       
   335 void CCSCAppUi::NotifyUiExtensionPluginResponse( 
       
   336     const CCSCEngUiExtensionPluginHandler::TUiExtensionPluginResponse& 
       
   337     aResponse, 
       
   338     const TInt /*aIndex*/, 
       
   339     const TUid& /*aPluginUid*/ )
       
   340     {
       
   341     CSCDEBUG( "CCSCAppUi::NotifyUiExtensionPluginResponse - begin" );
       
   342     
       
   343     switch ( aResponse )
       
   344         {
       
   345         case CCSCEngUiExtensionPluginHandler::EPluginExited:
       
   346             {
       
   347             TRAP_IGNORE( iServiceView->HandleUiExtensionExitL() );
       
   348             break;
       
   349             }
       
   350         case CCSCEngUiExtensionPluginHandler::EPluginError:
       
   351             {
       
   352             TRAP_IGNORE( ActivateLocalViewL( KCSCServiceViewId ) );
       
   353             break;
       
   354             }
       
   355         case CCSCEngUiExtensionPluginHandler::EPluginInitialized:
       
   356             // nothing to do
       
   357         default:
       
   358             break;
       
   359         }
       
   360    
       
   361     CSCDEBUG( "CCSCAppUi::NotifyUiExtensionPluginResponse - end" );
       
   362     }
       
   363 
       
   364 
       
   365 // ---------------------------------------------------------------------------
       
   366 // From class MCSCEngServiceObserver
       
   367 // Notifies when service(s) have changed.
       
   368 // ---------------------------------------------------------------------------
       
   369 //
       
   370 void CCSCAppUi::NotifyServiceChange()
       
   371     {
       
   372     CSCDEBUG( "CCSCAppUi::NotifyServiceChange - begin" );
       
   373     
       
   374     TVwsViewId activeViewId;
       
   375     GetActiveViewId( activeViewId );
       
   376     
       
   377     if( iServiceView && KCSCServiceViewId == activeViewId.iViewUid )
       
   378         {
       
   379         TRAP_IGNORE( iServiceView->UpdateServiceViewL() );
       
   380         }
       
   381     
       
   382     CSCDEBUG( "CCSCAppUi::NotifyServiceChange - end" );  
       
   383     }
       
   384 
       
   385 
       
   386 // ---------------------------------------------------------------------------
       
   387 // From class MCSCEngCCHObserver
       
   388 // ---------------------------------------------------------------------------
       
   389 //
       
   390 void CCSCAppUi::ServiceStatusChanged(
       
   391     TUint aServiceId, 
       
   392     TCCHSubserviceType /*aType*/, 
       
   393     const TCchServiceStatus& aServiceStatus )
       
   394     {
       
   395     CSCDEBUG2( 
       
   396        "CCSCAppUi::ServiceStatusChanged - STATE=%d", aServiceStatus.State() );
       
   397     
       
   398     if ( ECCHDisabled == aServiceStatus.State() )
       
   399         {        
       
   400         TVwsViewId activeViewId;
       
   401         GetActiveViewId( activeViewId );
       
   402         
       
   403         if( iServiceView && KCSCServiceViewId == activeViewId.iViewUid )
       
   404             {            
       
   405             TRAPD( err, SnapCheckL( aServiceId ) );  
       
   406             
       
   407             if ( KErrInUse == err )
       
   408                 {
       
   409                 iMonitoredService = aServiceId;
       
   410                 }
       
   411             else
       
   412                 {
       
   413                 TRAP_IGNORE( iServiceView->DeleteServiceL( aServiceId ) );
       
   414                 }
       
   415             }
       
   416         }
       
   417         
       
   418     CSCDEBUG( "CCSCAppUi::ServiceStatusChanged - end" );
       
   419     }
       
   420 
       
   421 
       
   422 // ---------------------------------------------------------------------------
       
   423 // From class MCSCEngConnectionObserver
       
   424 // ---------------------------------------------------------------------------
       
   425 //
       
   426 void CCSCAppUi::NotifyConnectionEvent( 
       
   427     CCSCEngConnectionHandler::TConnectionEvent aConnectionEvent )
       
   428     {
       
   429     CSCDEBUG( "CCSCAppUi::NotifyConnectionEvent - begin" );
       
   430         
       
   431     TVwsViewId activeViewId;
       
   432     GetActiveViewId( activeViewId );
       
   433     
       
   434     if( ( iServiceView && KCSCServiceViewId == activeViewId.iViewUid ) &&
       
   435         ( CCSCEngConnectionHandler::EEventConnectionDown == aConnectionEvent || 
       
   436           CCSCEngConnectionHandler::EEventTimedOut == aConnectionEvent ) )
       
   437         {        
       
   438         iConnectionHandler->StopListeningConnectionEvents();
       
   439         TRAP_IGNORE( iServiceView->DeleteServiceL( iMonitoredService ) );
       
   440         }
       
   441     
       
   442     CSCDEBUG( "CCSCAppUi::NotifyConnectionEvent - end" );
       
   443     }
       
   444 
       
   445 // ---------------------------------------------------------------------------
       
   446 // For checking if SNAP is still in use.
       
   447 // ---------------------------------------------------------------------------
       
   448 //
       
   449 void CCSCAppUi::SnapCheckL( TUint aServiceId ) const
       
   450     {
       
   451     CSCDEBUG( "CCSCAppUi::SnapCheckL - begin" );  
       
   452     
       
   453     CCSCEngDestinationsHandler* destHandler =
       
   454         CCSCEngDestinationsHandler::NewL();
       
   455     CleanupStack::PushL( destHandler );
       
   456     
       
   457     TInt snapId( 0 );
       
   458     snapId = iServiceHandler->SnapIdL( aServiceId );
       
   459     
       
   460     if ( destHandler->IsSnapInUseL( snapId ) )
       
   461         {
       
   462         iConnectionHandler->StartListeningConnectionEvents();
       
   463         User::Leave( KErrInUse );
       
   464         }
       
   465     
       
   466     CleanupStack::PopAndDestroy( destHandler );
       
   467     
       
   468     CSCDEBUG( "CCSCAppUi::SnapCheckL - end" );  
       
   469     }
       
   470 
       
   471 // ---------------------------------------------------------------------------
       
   472 // Check if GS has to be closed
       
   473 // ---------------------------------------------------------------------------
       
   474 //
       
   475 TBool CCSCAppUi::ExitGSIfParentL()
       
   476     {
       
   477     TBool ret = EFalse;
       
   478     
       
   479     RWsSession ws  = CEikonEnv::Static()->WsSession();
       
   480     TApaTaskList taskList( ws );
       
   481     TApaTask gstask = taskList.FindApp( KUidGS  );
       
   482 
       
   483     if ( gstask.Exists() )
       
   484         {
       
   485         TInt gswgid = gstask.WgId();
       
   486         RArray<RWsSession::TWindowGroupChainInfo> wgrp;
       
   487         ws.WindowGroupList( &wgrp );
       
   488         TInt i = 0;
       
   489 
       
   490         // Loop window groups, find GS's child app
       
   491         for ( i=0; i < wgrp.Count() ; ++i )
       
   492             {
       
   493             TBuf< KGSChildAppWindowGroupNameLength > name;
       
   494             ws.GetWindowGroupNameFromIdentifier( wgrp[i].iId , name );
       
   495             RWsSession::TWindowGroupChainInfo wginfo = wgrp[i];
       
   496             if ( wginfo.iParentId == gswgid ) // Child of GS found
       
   497                 {
       
   498                 CApaWindowGroupName* windowName1 =
       
   499                     CApaWindowGroupName::NewLC( ws, wginfo.iId ); // CS:1
       
   500                 TUid embeddeeuid;
       
   501                 embeddeeuid = windowName1->AppUid();
       
   502 
       
   503                 // Check if CSC is the child of GS
       
   504                 if ( KUidCSCApp == embeddeeuid )
       
   505                     {
       
   506                     ret = ETrue;
       
   507                     gstask.EndTask();
       
   508                     }
       
   509                 CleanupStack::PopAndDestroy( windowName1 );  // CS:0
       
   510                 }
       
   511             }
       
   512         wgrp.Close();
       
   513         }
       
   514     
       
   515     return ret;
       
   516     }
       
   517 
       
   518 // ---------------------------------------------------------------------------
       
   519 // Handle view change messages (e.g. from MeCo)
       
   520 // ---------------------------------------------------------------------------
       
   521 //
       
   522 MCoeMessageObserver::TMessageResponse CCSCAppUi::HandleMessageL(
       
   523     TUint32 /*aClientHandleOfTargetWindowGroup*/, TUid aMessageUid,
       
   524     const TDesC8& aMessageParameters )
       
   525     {
       
   526     CSCDEBUG( "CCSCAppUi::HandleMessageL - begin" ); 
       
   527 
       
   528     MCoeMessageObserver::TMessageResponse ret = EMessageNotHandled;
       
   529 
       
   530     if ( TUid::Uid( KUidApaMessageSwitchOpenFileValue ) == aMessageUid &&
       
   531         aMessageParameters.Length() &&
       
   532         aMessageParameters.Length() <= KMaxParamLength )
       
   533         {
       
   534         TBuf<KMaxParamLength> params;
       
   535         params.Copy( aMessageParameters );  
       
   536         iStartupHandler->SetStartupParametersL( params );
       
   537             
       
   538         iServiceView->InitializeWithStartupParametersL();
       
   539         iServiceView->ExecuteStartupActionsL( EFalse, EFalse );
       
   540         
       
   541         ret = EMessageHandled;
       
   542         }
       
   543 
       
   544     CSCDEBUG( "CCSCAppUi::HandleMessageL - end" ); 
       
   545     return ret;
       
   546     }