gssettingsuis/Gs/GSApplication/Src/GSUi.cpp
changeset 0 8c5d936e5675
child 14 9941bcf99348
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     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             GSDocument().WatchDog()->ReportCleanExitL();
       
   183             Exit();
       
   184             break;
       
   185         case EAknCmdExit:
       
   186             GSDocument().WatchDog()->ReportCleanExitL();
       
   187             Exit();
       
   188             break;
       
   189         case EAknSoftkeyExit:
       
   190             GSDocument().WatchDog()->ReportCleanExitL();
       
   191             Exit();
       
   192             break;
       
   193         default:
       
   194             break;
       
   195         }
       
   196     }
       
   197 
       
   198 
       
   199 // ----------------------------------------------------
       
   200 // CGSUi::HandleResourceChangeL()
       
   201 //
       
   202 //
       
   203 // ----------------------------------------------------
       
   204 //
       
   205 void CGSUi::HandleResourceChangeL( TInt aType )
       
   206     {
       
   207     CAknViewAppUi::HandleResourceChangeL( aType );
       
   208     }
       
   209 
       
   210 
       
   211 // ----------------------------------------------------
       
   212 // CGSUi::HandleKeyEventL()
       
   213 //
       
   214 //
       
   215 // ----------------------------------------------------
       
   216 TKeyResponse CGSUi::HandleKeyEventL( const TKeyEvent& aKeyEvent,
       
   217                                      TEventCode aType )
       
   218     {
       
   219     __GSLOGSTRING1( "[CGSUi] HandleKeyEventL(code:%d)", aKeyEvent.iCode );
       
   220 
       
   221     CAknNavigationControlContainer* naviContainer =
       
   222         static_cast<CAknNavigationControlContainer*>
       
   223         ( StatusPane()->ControlL( TUid::Uid(EEikStatusPaneUidNavi ) ) );
       
   224 
       
   225     TKeyResponse response = EKeyWasNotConsumed;
       
   226 
       
   227     if( naviContainer )
       
   228         {
       
   229         CAknNavigationDecorator* naviDec = naviContainer->Top();
       
   230         if( naviDec )
       
   231             {
       
   232             CCoeControl* decControl = naviDec->DecoratedControl();
       
   233             if( decControl)
       
   234                 {
       
   235                 response = decControl->OfferKeyEventL( aKeyEvent, aType );
       
   236                 }
       
   237             }
       
   238         }
       
   239 
       
   240     return response;
       
   241     }
       
   242 
       
   243 
       
   244 // ----------------------------------------------------
       
   245 // CGSUi::PhoneIdle()
       
   246 //
       
   247 //
       
   248 // ----------------------------------------------------
       
   249 //
       
   250 void CGSUi::PhoneIdle()
       
   251     {
       
   252     TRAP_IGNORE( CreateActivateViewEventL( TVwsViewId( TUid::Uid( KGSPhoneAppID ),
       
   253         TUid::Uid( KGSPhoneAppID ) ), KNullUid, KNullDesC8() ) );
       
   254     }
       
   255 
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 // CGSUi::EmbedAppL()
       
   259 //
       
   260 // Launches application as embedded.
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 void CGSUi::EmbedAppL( const TAppInfo& aApp )
       
   264     {
       
   265     if ( iEmbedded )
       
   266         {
       
   267         iEikonEnv->Process()->DestroyDocument( iEmbedded );
       
   268         iEmbedded = NULL;
       
   269         }
       
   270     CAknLocalScreenClearer* clearer = CAknLocalScreenClearer::NewLC();
       
   271     CEikProcess* process = iEikonEnv->Process();
       
   272     TApaApplicationFactory apaAppFactory( aApp.iUid );
       
   273     iEmbedded = process->AddNewDocumentL( apaAppFactory );
       
   274     TApaDocCleanupItem cleanup( process, iEmbedded );
       
   275     CleanupStack::PushL( cleanup );
       
   276     iEmbedded->NewDocumentL();
       
   277     CleanupStack::Pop();
       
   278     iEmbedded->EditL( NULL );
       
   279     CleanupStack::PopAndDestroy( clearer );
       
   280     }
       
   281 
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // CGSUi::Document()
       
   285 //
       
   286 //
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 CGSDocument& CGSUi::GSDocument() const
       
   290     {
       
   291     CGSDocument* doc = static_cast< CGSDocument* >( Document() );
       
   292     return *doc;
       
   293     }
       
   294 
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // CGSUi::ShowNoteGsNotOpenedDuringBackupRestoreL()
       
   298 //
       
   299 //
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 void CGSUi::ShowNoteGsNotOpenedDuringBackupRestoreL()
       
   303     {
       
   304     HBufC* prompt =
       
   305      StringLoader::LoadL( R_CONFIRM_NOTE_GS_EXIT_BACKUP_RESTORE_STRING );
       
   306     CleanupStack::PushL( prompt );
       
   307     CAknInformationNote* note =
       
   308                 new( ELeave ) CAknInformationNote( ETrue );
       
   309     note->ExecuteLD( *prompt );
       
   310     CleanupStack::PopAndDestroy( prompt );
       
   311     GSDocument().WatchDog()->ReportCleanExitL();
       
   312     Exit();
       
   313     }
       
   314 
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // CGSUi::HandleMessageL
       
   318 // Handles messages sent from gslauncher
       
   319 //
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 MCoeMessageObserver::TMessageResponse CGSUi::HandleMessageL(
       
   323     TUint32 /*aClientHandleOfTargetWindowGroup*/,
       
   324     TUid /*aMessageUid*/,
       
   325     const TDesC8 &aMessageParameters )
       
   326   {
       
   327   const TUint8* ptr = aMessageParameters.Ptr();
       
   328   __GSLOGSTRING1( "[CGSUi::HandleMessageL] aMessageParameters: %S", &aMessageParameters );
       
   329 
       
   330   FindAndKillEmbeddedAppL();
       
   331 
       
   332   TUid viewUid;
       
   333   TUid uid2;
       
   334 
       
   335   RDesReadStream str;
       
   336   str.Open(aMessageParameters);
       
   337   str >> viewUid;
       
   338   str >> uid2;
       
   339   HBufC8* msg8 = HBufC8::NewLC(str, 1024);
       
   340   str.Close();
       
   341 
       
   342   __GSLOGSTRING1( "[CGSUi::HandleMessageL] Launching  view 0x%x ", viewUid.iUid );
       
   343   TVwsViewId id( KUidGS , viewUid );
       
   344   if ( !View(viewUid) )
       
   345 	  {
       
   346 	  GSDocument().CreateShimmedViewL(viewUid);
       
   347 	  }
       
   348   ActivateViewL( id, uid2, *msg8 );
       
   349   CleanupStack::PopAndDestroy( msg8 );
       
   350   return MCoeMessageObserver::EMessageNotHandled;
       
   351   }
       
   352 
       
   353 
       
   354 // ---------------------------------------------------------------------------
       
   355 // CGSUi::FindAndKillEmbeddedAppL()
       
   356 // Find possiple child app of GS, and kill it.
       
   357 //
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 TInt CGSUi::FindAndKillEmbeddedAppL()
       
   361     {
       
   362     RWsSession ws  = CEikonEnv::Static()->WsSession();
       
   363     TApaTaskList taskList( ws );
       
   364     TApaTask gstask = taskList.FindApp( KUidGS  ); // Find GS
       
   365 
       
   366     if ( gstask.Exists() ) // Task should exist
       
   367         {
       
   368         TInt gswgid = gstask.WgId();
       
   369         RArray<RWsSession::TWindowGroupChainInfo> wgrp;
       
   370         ws.WindowGroupList( &wgrp );
       
   371         TInt i = 0;
       
   372 
       
   373         // Loop window groups, find GS's child app
       
   374         for ( i=0; i < wgrp.Count() ; ++i )
       
   375             {
       
   376             TBuf<100> name;
       
   377             ws.GetWindowGroupNameFromIdentifier( wgrp[i].iId , name );
       
   378             RWsSession::TWindowGroupChainInfo wginfo = wgrp[i];
       
   379             __GSLOGSTRING3( "[CGSUi] wginfo %d (%d) '%S'",  wginfo.iId, wginfo.iParentId, &( name.Left( 20 ) )  );
       
   380             if ( wginfo.iParentId == gswgid ) // Child of GS found
       
   381                 {
       
   382                 CApaWindowGroupName* windowName1 = CApaWindowGroupName::NewLC( ws, wginfo.iId );
       
   383                 TUid embeddeeuid;
       
   384                 embeddeeuid = windowName1->AppUid();
       
   385                 TApaTask embeddee = taskList.FindApp( embeddeeuid );
       
   386 
       
   387                 // Kill the child app
       
   388                 if ( embeddee.Exists() )
       
   389                     {
       
   390                     __GSLOGSTRING2( "[CGSUi] Embeddee: 0x%x  Embeddee thread=0x%x",
       
   391                                     embeddeeuid.iUid,
       
   392                                     embeddee.ThreadId() );
       
   393                     embeddee.KillTask();
       
   394                     }
       
   395                 CleanupStack::PopAndDestroy( windowName1 );  //windowName1
       
   396                 }
       
   397             }
       
   398         wgrp.Close();
       
   399         }
       
   400     return KErrNone;
       
   401     }
       
   402 
       
   403 
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 // ---------------------------------------------------------------------------
       
   408 //
       
   409 void CGSUi::HandleEComEvent( TEComEvent aEvent )
       
   410     {
       
   411     /**
       
   412      * Quietly close GS if GS-plugin is uninstalled. This is a precaution for
       
   413      * scenario where GS-plugin is uninstalled and GS tries to access the
       
   414      * plugin even though plugin's resources do not exist anymore.
       
   415      *
       
   416      * More sophisticated solution would have been to update whole GS plugin
       
   417      * structure but this would have been overkill for this very rare use
       
   418      * scenario and rather impossible due to BC requirements.
       
   419      */
       
   420     __GSLOGSTRING1( "[CGSUi::HandleEComEvent] aEvent:%d", aEvent );
       
   421 
       
   422     switch( aEvent )
       
   423         {
       
   424         case MGSEComObserver::EPluginRemoved:
       
   425             __GSLOGSTRING( "[CGSUi::HandleAppListEvent] Closing GS..." );
       
   426             TRAP_IGNORE( GSDocument().WatchDog()->ReportCleanExitL() );
       
   427             Exit();
       
   428             break;
       
   429         default:
       
   430             break;
       
   431         }
       
   432 
       
   433     }
       
   434 
       
   435 
       
   436 
       
   437 
       
   438 //End of File