gssettingsuis/Gs/GSApplication/Src/GSUi.cpp
branchRCL_3
changeset 53 8ee96d21d9bf
parent 51 8bda91a87a00
child 54 7e0eff37aedb
equal deleted inserted replaced
51:8bda91a87a00 53:8ee96d21d9bf
     1 /*
       
     2 * Copyright (c) 2005-2008 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:  General Settings User Interface
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <bldvariant.hrh>
       
    21 #include    <eikapp.h>
       
    22 #include    <avkon.hrh>
       
    23 #include    <akncontext.h>
       
    24 #include    <aknnotewrappers.h>
       
    25 #include    <aknnavi.h>
       
    26 #include    <aknnavide.h>
       
    27 #include    <akntabgrp.h>
       
    28 #include    <akntitle.h>
       
    29 #include    <AknUtils.h>
       
    30 #include    <AknsConstants.h> // For determining skin change
       
    31 #include    <barsread.h>
       
    32 #include    <StringLoader.h>
       
    33 #include    <gsapp.rsg>
       
    34 #include    <eikenv.h>
       
    35 #include    <ConeResLoader.h>
       
    36 #include    <apgcli.h>
       
    37 #include    <f32file.h>
       
    38 #include    <hlplch.h> // For HlpLauncher
       
    39 #include    <w32std.h>
       
    40 #include    <eikproc.h> // Embedding CC in GS
       
    41 #include    <aknclearer.h> // Embedding CC in GS
       
    42 #include    <apacln.h> // Embedding CC in GS
       
    43 #include    <PSVariables.h>
       
    44 #include    <e32std.h> // The USER class
       
    45 #include    <featmgr.h>
       
    46 #include    <s32mem.h>
       
    47 
       
    48 #include    <gsplugininterface.h>
       
    49 #include    <gsbaseview.h>
       
    50 #include    <gsfwviewuids.h>
       
    51 
       
    52 #include  <apgwgnam.h>
       
    53 #include    "GsLogger.h"
       
    54 #include    "GSUi.h"
       
    55 #include    <gsmainview.h>
       
    56 #include    "GSDocument.h"
       
    57 #include    "gssettingid.h"
       
    58 #include    <mgswatchdog.h>
       
    59 
       
    60 // System Includes
       
    61 #include  <e32property.h>
       
    62 #include <sbdefs.h>
       
    63 using namespace conn;
       
    64 
       
    65 //CONSTANTS
       
    66 
       
    67 const TInt KGSPhoneAppID = 0x100058b3;
       
    68 
       
    69 
       
    70 // ================= MEMBER FUNCTIONS =======================
       
    71 
       
    72 
       
    73 // ----------------------------------------------------
       
    74 // CGSUi::CGSUi()
       
    75 //
       
    76 // Default constructor.
       
    77 // ----------------------------------------------------
       
    78 CGSUi::CGSUi()
       
    79     {
       
    80     }
       
    81 
       
    82 
       
    83 // ----------------------------------------------------
       
    84 // CGSUi::~CGSUi()
       
    85 // destructor
       
    86 //
       
    87 // ----------------------------------------------------
       
    88 CGSUi::~CGSUi()
       
    89     {
       
    90     GSDocument().PrepareForUIDestruction();
       
    91 
       
    92     FeatureManager::UnInitializeLib();
       
    93 
       
    94     //Embedding - removing created document
       
    95     if ( iEmbedded )
       
    96         {
       
    97         iEikonEnv->Process()->DestroyDocument( iEmbedded );
       
    98         }
       
    99     if( iEComNotifier )
       
   100         {
       
   101         delete iEComNotifier;
       
   102         }
       
   103     }
       
   104 
       
   105 
       
   106 // ----------------------------------------------------
       
   107 // CGSUi::ConstructL()
       
   108 //
       
   109 // Symbian OS two-phased constructor
       
   110 // ----------------------------------------------------
       
   111 void CGSUi::ConstructL()
       
   112     {
       
   113     __GSLOGSTRING( "[CGSUi] ConstructL()" );
       
   114     FeatureManager::InitializeLibL();
       
   115     BaseConstructL( EAknEnableSkin | EAknEnableMSK |EAknSingleClickCompatible );
       
   116     TInt backupInfo = 0;
       
   117   const TInt error = RProperty::Get( TUid::Uid( KUidSystemCategoryValue ),
       
   118                              KUidBackupRestoreKey,
       
   119                              backupInfo );
       
   120   // We check if the backup/restore process is underway
       
   121   if  ( error == KErrNone )
       
   122     {
       
   123         // Work out what kind of operation is underway:
       
   124     if ( ( backupInfo & KBURPartTypeMask ) == EBURNormal ||
       
   125          ( backupInfo & KBURPartTypeMask ) == EBURUnset )
       
   126       {
       
   127       ConstructViewsL();
       
   128       //Activate the main view to be the first view when
       
   129       // application is opened.
       
   130       SetDefaultViewL( *iMainView );
       
   131       }
       
   132     else
       
   133       {
       
   134       if ( ( backupInfo & KBURPartTypeMask) == EBURBackupFull ||
       
   135            ( backupInfo & KBURPartTypeMask) == EBURBackupPartial )
       
   136         {
       
   137             // Backup In Progress.. show a Note and Dont Launch GS
       
   138             ShowNoteGsNotOpenedDuringBackupRestoreL();
       
   139         }
       
   140       else if ( ( backupInfo & KBURPartTypeMask) == EBURRestoreFull ||
       
   141                 ( backupInfo & KBURPartTypeMask) == EBURRestorePartial )
       
   142         {
       
   143             // Restore In Progress.. show a Note and Dont Launch GS
       
   144                     ShowNoteGsNotOpenedDuringBackupRestoreL();
       
   145         }
       
   146       }
       
   147     }
       
   148 
       
   149     GSDocument().PreparePluginCacheL( *this );
       
   150 
       
   151     // This will observe plugin install events.
       
   152     iEComNotifier = CGSEComNotifier::NewL( this, GSDocument().GetImplInfo() );
       
   153     }
       
   154 
       
   155 
       
   156 // ----------------------------------------------------
       
   157 // CGSUi::ConstructViewsL()
       
   158 //
       
   159 // ----------------------------------------------------
       
   160 void CGSUi::ConstructViewsL()
       
   161     {
       
   162     __GSLOGSTRING( "[CGSUi] Constructing views..." );
       
   163 
       
   164     iMainView = CGSMainView::NewL();
       
   165     AddViewL( iMainView );         // transfer ownership to CAknViewAppUi
       
   166 
       
   167     __GSLOGSTRING( "[CGSUi] Constructing views done." );
       
   168     }
       
   169 
       
   170 
       
   171 // ----------------------------------------------------
       
   172 // CGSUi::HandleCommandL(TInt aCommand)
       
   173 //
       
   174 //
       
   175 // ----------------------------------------------------
       
   176 void CGSUi::HandleCommandL( TInt aCommand )
       
   177     {
       
   178     __GSLOGSTRING1( "[CGSUi] HandleCommandL(%d)", aCommand );
       
   179     switch ( aCommand )
       
   180         {
       
   181         case EEikCmdExit:
       
   182         case EAknCmdExit:
       
   183         case EAknSoftkeyExit:
       
   184         #ifdef GS_ENABLE_WATCH_DOG
       
   185             GSDocument().WatchDog()->ReportCleanExitL();
       
   186         #endif
       
   187             Exit();
       
   188             break;
       
   189         default:
       
   190             break;
       
   191         }
       
   192     }
       
   193 
       
   194 
       
   195 // ----------------------------------------------------
       
   196 // CGSUi::HandleResourceChangeL()
       
   197 //
       
   198 //
       
   199 // ----------------------------------------------------
       
   200 //
       
   201 void CGSUi::HandleResourceChangeL( TInt aType )
       
   202     {
       
   203     CAknViewAppUi::HandleResourceChangeL( aType );
       
   204     }
       
   205 
       
   206 
       
   207 // ----------------------------------------------------
       
   208 // CGSUi::HandleKeyEventL()
       
   209 //
       
   210 //
       
   211 // ----------------------------------------------------
       
   212 TKeyResponse CGSUi::HandleKeyEventL( const TKeyEvent& aKeyEvent,
       
   213                                      TEventCode aType )
       
   214     {
       
   215     __GSLOGSTRING1( "[CGSUi] HandleKeyEventL(code:%d)", aKeyEvent.iCode );
       
   216 
       
   217     CAknNavigationControlContainer* naviContainer =
       
   218         static_cast<CAknNavigationControlContainer*>
       
   219         ( StatusPane()->ControlL( TUid::Uid(EEikStatusPaneUidNavi ) ) );
       
   220 
       
   221     TKeyResponse response = EKeyWasNotConsumed;
       
   222 
       
   223     if( naviContainer )
       
   224         {
       
   225         CAknNavigationDecorator* naviDec = naviContainer->Top();
       
   226         if( naviDec )
       
   227             {
       
   228             CCoeControl* decControl = naviDec->DecoratedControl();
       
   229             if( decControl)
       
   230                 {
       
   231                 response = decControl->OfferKeyEventL( aKeyEvent, aType );
       
   232                 }
       
   233             }
       
   234         }
       
   235 
       
   236     return response;
       
   237     }
       
   238 
       
   239 
       
   240 // ----------------------------------------------------
       
   241 // CGSUi::PhoneIdle()
       
   242 //
       
   243 //
       
   244 // ----------------------------------------------------
       
   245 //
       
   246 void CGSUi::PhoneIdle()
       
   247     {
       
   248     TRAP_IGNORE( CreateActivateViewEventL( TVwsViewId( TUid::Uid( KGSPhoneAppID ),
       
   249         TUid::Uid( KGSPhoneAppID ) ), KNullUid, KNullDesC8() ) );
       
   250     }
       
   251 
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // CGSUi::EmbedAppL()
       
   255 //
       
   256 // Launches application as embedded.
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 void CGSUi::EmbedAppL( const TAppInfo& aApp )
       
   260     {
       
   261     if ( iEmbedded )
       
   262         {
       
   263         iEikonEnv->Process()->DestroyDocument( iEmbedded );
       
   264         iEmbedded = NULL;
       
   265         }
       
   266     CAknLocalScreenClearer* clearer = CAknLocalScreenClearer::NewLC();
       
   267     CEikProcess* process = iEikonEnv->Process();
       
   268     TApaApplicationFactory apaAppFactory( aApp.iUid );
       
   269     iEmbedded = process->AddNewDocumentL( apaAppFactory );
       
   270     TApaDocCleanupItem cleanup( process, iEmbedded );
       
   271     CleanupStack::PushL( cleanup );
       
   272     iEmbedded->NewDocumentL();
       
   273     CleanupStack::Pop();
       
   274     iEmbedded->EditL( NULL );
       
   275     CleanupStack::PopAndDestroy( clearer );
       
   276     }
       
   277 
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // CGSUi::Document()
       
   281 //
       
   282 //
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 CGSDocument& CGSUi::GSDocument() const
       
   286     {
       
   287     CGSDocument* doc = static_cast< CGSDocument* >( Document() );
       
   288     return *doc;
       
   289     }
       
   290 
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // CGSUi::ShowNoteGsNotOpenedDuringBackupRestoreL()
       
   294 //
       
   295 //
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 void CGSUi::ShowNoteGsNotOpenedDuringBackupRestoreL()
       
   299     {
       
   300     HBufC* prompt =
       
   301      StringLoader::LoadL( R_CONFIRM_NOTE_GS_EXIT_BACKUP_RESTORE_STRING );
       
   302     CleanupStack::PushL( prompt );
       
   303     CAknInformationNote* note =
       
   304                 new( ELeave ) CAknInformationNote( ETrue );
       
   305     note->ExecuteLD( *prompt );
       
   306     CleanupStack::PopAndDestroy( prompt );
       
   307 #ifdef GS_ENABLE_WATCH_DOG
       
   308     GSDocument().WatchDog()->ReportCleanExitL();
       
   309 #endif
       
   310     Exit();
       
   311     }
       
   312 
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // CGSUi::HandleMessageL
       
   316 // Handles messages sent from gslauncher
       
   317 //
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 MCoeMessageObserver::TMessageResponse CGSUi::HandleMessageL(
       
   321     TUint32 /*aClientHandleOfTargetWindowGroup*/,
       
   322     TUid /*aMessageUid*/,
       
   323     const TDesC8 &aMessageParameters )
       
   324   {
       
   325   const TUint8* ptr = aMessageParameters.Ptr();
       
   326   __GSLOGSTRING1( "[CGSUi::HandleMessageL] aMessageParameters: %S", &aMessageParameters );
       
   327 
       
   328   FindAndKillEmbeddedAppL();
       
   329 
       
   330   TUid viewUid;
       
   331   TUid uid2;
       
   332 
       
   333   RDesReadStream str;
       
   334   str.Open(aMessageParameters);
       
   335   str >> viewUid;
       
   336   str >> uid2;
       
   337   HBufC8* msg8 = HBufC8::NewLC(str, 1024);
       
   338   str.Close();
       
   339 
       
   340   __GSLOGSTRING1( "[CGSUi::HandleMessageL] Launching  view 0x%x ", viewUid.iUid );
       
   341   TVwsViewId id( KUidGS , viewUid );
       
   342   if ( !View(viewUid) )
       
   343 	  {
       
   344 	  GSDocument().CreateShimmedViewL(viewUid);
       
   345 	  }
       
   346   ActivateViewL( id, uid2, *msg8 );
       
   347   CleanupStack::PopAndDestroy( msg8 );
       
   348   return MCoeMessageObserver::EMessageNotHandled;
       
   349   }
       
   350 
       
   351 
       
   352 // ---------------------------------------------------------------------------
       
   353 // CGSUi::FindAndKillEmbeddedAppL()
       
   354 // Find possiple child app of GS, and kill it.
       
   355 //
       
   356 // ---------------------------------------------------------------------------
       
   357 //
       
   358 TInt CGSUi::FindAndKillEmbeddedAppL()
       
   359     {
       
   360     RWsSession ws  = CEikonEnv::Static()->WsSession();
       
   361     TApaTaskList taskList( ws );
       
   362     TApaTask gstask = taskList.FindApp( KUidGS  ); // Find GS
       
   363 
       
   364     if ( gstask.Exists() ) // Task should exist
       
   365         {
       
   366         TInt gswgid = gstask.WgId();
       
   367         RArray<RWsSession::TWindowGroupChainInfo> wgrp;
       
   368         ws.WindowGroupList( &wgrp );
       
   369         TInt i = 0;
       
   370 
       
   371         // Loop window groups, find GS's child app
       
   372         for ( i=0; i < wgrp.Count() ; ++i )
       
   373             {
       
   374             TBuf<100> name;
       
   375             ws.GetWindowGroupNameFromIdentifier( wgrp[i].iId , name );
       
   376             RWsSession::TWindowGroupChainInfo wginfo = wgrp[i];
       
   377             __GSLOGSTRING3( "[CGSUi] wginfo %d (%d) '%S'",  wginfo.iId, wginfo.iParentId, &( name.Left( 20 ) )  );
       
   378             if ( wginfo.iParentId == gswgid ) // Child of GS found
       
   379                 {
       
   380                 CApaWindowGroupName* windowName1 = CApaWindowGroupName::NewLC( ws, wginfo.iId );
       
   381                 TUid embeddeeuid;
       
   382                 embeddeeuid = windowName1->AppUid();
       
   383                 TApaTask embeddee = taskList.FindApp( embeddeeuid );
       
   384 
       
   385                 // Kill the child app
       
   386                 if ( embeddee.Exists() )
       
   387                     {
       
   388                     __GSLOGSTRING2( "[CGSUi] Embeddee: 0x%x  Embeddee thread=0x%x",
       
   389                                     embeddeeuid.iUid,
       
   390                                     embeddee.ThreadId() );
       
   391                     embeddee.KillTask();
       
   392                     }
       
   393                 CleanupStack::PopAndDestroy( windowName1 );  //windowName1
       
   394                 }
       
   395             }
       
   396         wgrp.Close();
       
   397         }
       
   398     return KErrNone;
       
   399     }
       
   400 
       
   401 
       
   402 
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 void CGSUi::HandleEComEvent( TEComEvent aEvent )
       
   408     {
       
   409     /**
       
   410      * Quietly close GS if GS-plugin is uninstalled. This is a precaution for
       
   411      * scenario where GS-plugin is uninstalled and GS tries to access the
       
   412      * plugin even though plugin's resources do not exist anymore.
       
   413      *
       
   414      * More sophisticated solution would have been to update whole GS plugin
       
   415      * structure but this would have been overkill for this very rare use
       
   416      * scenario and rather impossible due to BC requirements.
       
   417      */
       
   418     __GSLOGSTRING1( "[CGSUi::HandleEComEvent] aEvent:%d", aEvent );
       
   419 
       
   420     switch( aEvent )
       
   421         {
       
   422         case MGSEComObserver::EPluginRemoved:
       
   423             __GSLOGSTRING( "[CGSUi::HandleAppListEvent] Closing GS..." );
       
   424             #ifdef GS_ENABLE_WATCH_DOG
       
   425                 TRAP_IGNORE( GSDocument().WatchDog()->ReportCleanExitL() );
       
   426             #endif
       
   427             Exit();
       
   428             break;
       
   429         default:
       
   430             break;
       
   431         }
       
   432 
       
   433     }
       
   434 
       
   435 
       
   436 
       
   437 
       
   438 //End of File