uifw/EikStd/srvuisrc/EIKSRVUI.CPP
changeset 0 2f259fa3e83a
child 4 8ca85d2f0db7
child 14 3320e4e6e8bb
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-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 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    19 #include <uikon/eiknotifyalert.h>
       
    20 #include <viewclipartner.h>
       
    21 #include <uiklaf/private/pluginuid.hrh>
       
    22 #endif
       
    23 #include <hal.h>
       
    24 #include <hal_data.h>
       
    25 #include <s32file.h>
       
    26 #include <basched.h>
       
    27 #include <bautils.h>
       
    28 #include <eikdll.h>
       
    29 #include <eikenv.h>
       
    30 #include <eikkeys.h>
       
    31 #include "eikkwin.h"
       
    32 #include <eikmover.h>
       
    33 #include <eikon.rsg>
       
    34 
       
    35 #include <uikon/eiksrvui.h>
       
    36 #include <eiksvdef.h>
       
    37 #include <Eikalmct.h>
       
    38 
       
    39 #define __ASSHDBITFLAGS_H__
       
    40 
       
    41 #include <uikon/eikalsup.h>
       
    42 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    43 #include <uikon/eikenvinterface.h>
       
    44 #endif
       
    45 #include <eikunder.h>
       
    46 #include <uikon/eikalsrv.h>
       
    47 #include <uikon/eiknfysv.h>
       
    48 #include "EIKNFYUI.H"
       
    49 #include <eiksrvui.rsg>
       
    50 #include <viewcli.h>
       
    51 
       
    52 /*
       
    53 * Following resources used from Symbian's eikpriv.rss file:
       
    54 * 
       
    55 * r_eik_system_default_view_id
       
    56 * r_eik_system_view_server_event_time_out
       
    57 * r_eik_system_view_server_client_request_time_out
       
    58 */
       
    59 #include <eikpriv.rsg>
       
    60 #include "EIKSRV.HRH"
       
    61 
       
    62 #include <aknPopup.h>
       
    63 #include <avkon.rsg>
       
    64 #include <eiktxlbx.h>
       
    65 #include <eiktxlbm.h>
       
    66 #include "eikkeysoundserver.h"
       
    67 #include <aknsoundsystem.h>
       
    68 #include <eikapp.h>
       
    69 #include <aknenv.h>
       
    70 
       
    71 #include <AknLayout.lag>
       
    72 #include <AknUtils.h>
       
    73 #include <AknsUtils.h>
       
    74 #include <featmgr.h>
       
    75 
       
    76 #include <e32property.h>
       
    77 #include <UikonInternalPSKeys.h>    // KUikLayoutState
       
    78 
       
    79 #include <aknpriv.rsg>
       
    80 #include <AknDef.h>
       
    81 
       
    82 #include <AknIconUtils.h>
       
    83 #include <avkon.mbg>
       
    84 #include <aknlayout.cdl.h>
       
    85 
       
    86 #include <asclisession.h>
       
    87 #include <asclidefinitions.h>
       
    88 #include <ascliclientutils.h>
       
    89 #include <c32comm.h>
       
    90 
       
    91 #include <apasvst.h>
       
    92 #include <apgcli.h>
       
    93 #include <apgwgnam.h>
       
    94 #include <viewcli.h>
       
    95 #include <vwsappst.h> 
       
    96 
       
    97 #include "e32uid.h"
       
    98 
       
    99 #include <eiksrvsp.h>
       
   100 #include <eiksrvs.h>
       
   101 #include <akneiksrvs.h>
       
   102 
       
   103 #include <uiklaf/private/lafenv.h>
       
   104 #include <uiklaf/private/lafsrv.h>
       
   105 
       
   106 #include <eikrutil.h>
       
   107 #include <AknSgcc.h>
       
   108 #include <aknconsts.h>
       
   109 
       
   110 #include "EikLafShutStarter.h"
       
   111 #include "EikLafShutScheduler.h"
       
   112 
       
   113 #include <AknWsEventObserver.h>
       
   114 #include <aknappui.h>
       
   115 #include <aknlayoutscalable_avkon.cdl.h>
       
   116 #include <AknFontSpecification.h>
       
   117 #include <AknTextDecorationMetrics.h>
       
   118 #include <e32capability.h>
       
   119 
       
   120 #include <AknCapServerDefs.h>
       
   121 #include <akndialogcontroller.h>
       
   122 
       
   123 #include "AknNotifierControllerPlugin.h"
       
   124 #include <AknCustomCursorSupport.h>
       
   125 #include "AknEikSrv.pan"
       
   126 
       
   127 #if defined(__WINS__)
       
   128 const TInt KEikServSideBarWidth = 35;
       
   129 const TInt KEikServAppbarHeight = 50;
       
   130 #endif
       
   131 
       
   132 #if defined (__WINS__)
       
   133 _LIT(COMMS_PDD_NAME, "ECDRV");
       
   134 _LIT(COMMS_LDD_NAME, "ECOMM");
       
   135 #else
       
   136 _LIT(COMMS_PDD_NAME, "EUART1");
       
   137 _LIT(COMMS_LDD_NAME, "ECOMM");
       
   138 #endif
       
   139 
       
   140 const TInt KEikServServerRestartDelay = 500000; // .5 sec
       
   141 const TInt KEikServServerRestartInterval = 3000000; // 3 sec
       
   142 
       
   143 _LIT(KResFileName, "z:\\resource\\eiksrvui.rsc");
       
   144 _LIT(KAnimDllFileName, "AknAnimDll.Dll");
       
   145 _LIT(KWatcherThreadName, "UikonWatchers");
       
   146 
       
   147 const TInt KEikServPanicTextBufferSize = 512;
       
   148 
       
   149 GLDEF_C void Panic(TEikServPanic aPanic)
       
   150     {
       
   151     _LIT(KPanicCat,"EIKON-SERVER");
       
   152     User::Panic(KPanicCat,aPanic);
       
   153     }
       
   154 
       
   155 #define iAknCapServerClient (*(CAknSgcClient::AknSrv()))
       
   156 
       
   157 class CFbsBitmap;
       
   158 
       
   159 // =====================
       
   160 // RKeySoundServerCloser
       
   161 // =====================
       
   162 
       
   163 class RKeySoundServerCloser : public RSessionBase
       
   164     {
       
   165 public:
       
   166     void CloseServer();
       
   167     };
       
   168 
       
   169 void RKeySoundServerCloser::CloseServer()
       
   170     {
       
   171     if (CreateSession(__KEYSOUND_SERVER_NAME, TVersion(KKeySoundServMajorVN, KKeySoundServMinorVN, 
       
   172         KKeySoundServBuildVN), 0) == KErrNone)
       
   173         {
       
   174         SendReceive(EKeySoundServerCloseServer, TIpcArgs());
       
   175         Close();
       
   176         }
       
   177     }
       
   178 
       
   179 // ==================
       
   180 // CEikServAppStarter
       
   181 // ==================
       
   182 
       
   183 class CEikServAppStarter : public CBase, public MVwsAppStarter
       
   184     {
       
   185 public:
       
   186     static CEikServAppStarter* NewL();
       
   187     ~CEikServAppStarter();
       
   188 public: // From MVwsAppStarter.
       
   189     void StartAppL(TUid aAppUid, TThreadId& aThreadId);
       
   190 private:
       
   191     CEikServAppStarter();
       
   192     void ConstructL();
       
   193 private:
       
   194     };
       
   195 
       
   196 CEikServAppStarter* CEikServAppStarter::NewL()
       
   197     {
       
   198     CEikServAppStarter* self=new(ELeave) CEikServAppStarter;
       
   199     CleanupStack::PushL(self);
       
   200     self->ConstructL();
       
   201     CleanupStack::Pop();
       
   202     return self;
       
   203     }
       
   204 
       
   205 CEikServAppStarter::~CEikServAppStarter()
       
   206     {
       
   207     }
       
   208 
       
   209 CEikServAppStarter::CEikServAppStarter()
       
   210     {
       
   211     }
       
   212 
       
   213 void CEikServAppStarter::ConstructL()
       
   214     {
       
   215     }
       
   216 
       
   217 void CEikServAppStarter::StartAppL(TUid aAppUid, TThreadId& aThreadId)
       
   218     {
       
   219     RApaLsSession ls;
       
   220     CleanupClosePushL(ls);
       
   221     User::LeaveIfError(ls.Connect());
       
   222     TApaAppInfo info;
       
   223     TInt err = ls.GetAppInfo(info,aAppUid);
       
   224 
       
   225     User::LeaveIfError(err);
       
   226     
       
   227     // LeaveIfError does not trigger to positive values, but GetAppInfo does not return valid 
       
   228     // data unless server returns KErrNone.
       
   229     if ( err > 0 ) 
       
   230         {         
       
   231         User::Leave(KErrNotReady);
       
   232         }
       
   233 
       
   234     CApaCommandLine* cmdLine = CApaCommandLine::NewLC();  
       
   235     cmdLine->SetExecutableNameL(info.iFullName);
       
   236     cmdLine->SetCommandL(EApaCommandViewActivate);
       
   237     
       
   238     // Using apparc client-server to do this "internal" launch.
       
   239     ls.StartApp(*cmdLine, aThreadId); 
       
   240     CleanupStack::PopAndDestroy(); // cmdLine
       
   241     CleanupStack::PopAndDestroy(); // ls
       
   242     }
       
   243 
       
   244 // Thread function for OOD watcher.
       
   245 GLDEF_C TInt WatcherThreadFunction(TAny* /*aParameters*/)
       
   246     {
       
   247     TInt err(KErrNone);
       
   248 
       
   249     CTrapCleanup* cleanup = CTrapCleanup::New();
       
   250     CActiveScheduler* scheduler = new CEikLafShutScheduler();
       
   251     CEikLafShutStarter* lafShut = NULL;
       
   252 
       
   253     if (!cleanup || !scheduler)
       
   254         {
       
   255         err = KErrNoMemory;
       
   256         }
       
   257 
       
   258     else
       
   259         {
       
   260         CActiveScheduler::Install(scheduler);
       
   261         TRAP(err, 
       
   262             {
       
   263             RThread me;
       
   264             me.SetPriority(EPriorityLess);
       
   265             lafShut = CEikLafShutStarter::NewL();
       
   266             })
       
   267 
       
   268         if (err == KErrNone)
       
   269             {
       
   270             // start the watchers
       
   271             CActiveScheduler::Start();
       
   272             }
       
   273         }
       
   274 
       
   275     delete cleanup;
       
   276     delete scheduler;
       
   277     delete lafShut;
       
   278     
       
   279     return err;
       
   280     }
       
   281 
       
   282 // Creates thread for OOM & OOD watchers.
       
   283 GLDEF_C void CreateWatcherThreadL()
       
   284     {
       
   285     RThread thread;
       
   286 
       
   287     TInt ret = thread.Create( 
       
   288         KWatcherThreadName, 
       
   289         WatcherThreadFunction,
       
   290         0x2000,                 // stack size
       
   291         NULL,                   // uses caller thread's heap
       
   292         (TAny*)NULL );
       
   293 
       
   294     if (ret == KErrNone)
       
   295         {
       
   296         thread.Resume();
       
   297         thread.Close();
       
   298         }
       
   299 
       
   300     User::LeaveIfError(ret);
       
   301     }
       
   302 
       
   303 // ==================
       
   304 // CEikSrvAppShutdown
       
   305 // ==================
       
   306 
       
   307 NONSHARABLE_CLASS(CEikSrvAppShutdown) : public CActive
       
   308     {
       
   309 public:
       
   310     static void StartL(
       
   311         const TUid aRequesterUID, 
       
   312         const RMessage2& aShutdownMessage, 
       
   313         const TInt aTimeoutInMicroseconds);
       
   314 private:
       
   315     CEikSrvAppShutdown(const RMessage2& aShutdownMessage);
       
   316     ~CEikSrvAppShutdown();
       
   317     void DoCancel();
       
   318     void RunL();
       
   319 private:
       
   320     RMessagePtr2 iMessage;
       
   321     };
       
   322 
       
   323 void CEikSrvAppShutdown::StartL(const TUid aRequesterUID, const RMessage2& aShutdownMessage,
       
   324     const TInt aTimeoutInMicroseconds)
       
   325     {
       
   326     if (iAknCapServerClient.Handle())
       
   327         {
       
   328         CEikSrvAppShutdown* self = new(ELeave) CEikSrvAppShutdown(aShutdownMessage);
       
   329         iAknCapServerClient.ShutdownApps(aRequesterUID, aTimeoutInMicroseconds, self->iStatus);
       
   330         self->SetActive();
       
   331         }
       
   332     else
       
   333         aShutdownMessage.Complete(KErrNone);
       
   334     }
       
   335 
       
   336 CEikSrvAppShutdown::CEikSrvAppShutdown(const RMessage2& aShutdownMessage)
       
   337 : CActive(CActive::EPriorityStandard), iMessage(aShutdownMessage)
       
   338     {
       
   339     CActiveScheduler::Add(this);
       
   340     }
       
   341 
       
   342 CEikSrvAppShutdown::~CEikSrvAppShutdown()
       
   343     {
       
   344     Cancel();
       
   345     }
       
   346 
       
   347 void CEikSrvAppShutdown::DoCancel()
       
   348     {
       
   349     }
       
   350 
       
   351 void CEikSrvAppShutdown::RunL()
       
   352     {
       
   353     iMessage.Complete(KErrNone);
       
   354     delete this;
       
   355     }
       
   356 
       
   357 // =============
       
   358 // CEikServExtra
       
   359 // =============
       
   360 
       
   361 class CEikServExtra : public CBase
       
   362     {
       
   363 public:
       
   364     CPeriodic* iServerRestarter;
       
   365     CArrayPtr<RWsPointerCursor>* iPointerCursors;
       
   366     CIdle* iNotifierServerStarter;
       
   367     };
       
   368 
       
   369 const TInt KEiksrvUiDllValue = 0x100053D0;
       
   370 
       
   371 
       
   372 EXPORT_C CEikServAppUiBase* CEikServAppUiBase::NewLC()
       
   373     {
       
   374     if (CEikonEnv::Static()->WsSession().FindWindowGroupIdentifier(
       
   375         0, __EIKON_SERVER_NAME, 0) > KErrNotFound)
       
   376         {
       
   377         return NULL; // Already an Eikon server running.
       
   378         }
       
   379 
       
   380     // This code duplicates what is in EikSrv.cpp in CEikServAppUiServer::CreateAppUiL().
       
   381     _LIT(KRomPath, "\\System\\Libs\\");
       
   382     _LIT(KEiksrvUiDllName, "EiksrvUi.dll");
       
   383     TFileName path;
       
   384     Dll::FileName(path);
       
   385     const TUint16& drv = path[0];
       
   386     if (drv == 'z' || drv == 'Z')
       
   387         {
       
   388         path.Append(KRomPath);
       
   389         }
       
   390     else
       
   391         {
       
   392         TParse parse;
       
   393         User::LeaveIfError(parse.Set(path, NULL, NULL));
       
   394         path = parse.DriveAndPath();
       
   395         }
       
   396     TUidType uidType(KDynamicLibraryUid, KSharedLibraryUid, TUid::Uid(KEiksrvUiDllValue));
       
   397     RLibrary lib;
       
   398     User::LeaveIfError(lib.Load(KEiksrvUiDllName, path, uidType));
       
   399     CleanupClosePushL(lib);
       
   400     TLibraryFunction appui = lib.Lookup(1);
       
   401     CEikServAppUiBase* self = REINTERPRET_CAST(CEikServAppUiBase*, (*appui)());
       
   402     User::LeaveIfNull(self);
       
   403     STATIC_CAST(CEikServEnv*, CEikonEnv::Static())->SetUiDll(lib);
       
   404     CleanupStack::Pop(); // lib
       
   405     CleanupStack::PushL(self);
       
   406     STATIC_CAST(CEikAppUi*, self)->ConstructL();
       
   407 
       
   408     return self;
       
   409     }
       
   410 
       
   411 EXPORT_C void CEikServAppUiBase::NotifyAlarmServerOfTaskChangeL()
       
   412     {
       
   413     if (iAlarmAlertServer)
       
   414         {
       
   415         iAlarmAlertServer->TaskKeyPressedL();
       
   416         }
       
   417     }
       
   418 
       
   419 EXPORT_C void CEikServAppUiBase::EnableTaskListL()
       
   420     {
       
   421     User::Leave(KErrNotSupported);
       
   422     }
       
   423 
       
   424 EXPORT_C void CEikServAppUiBase::LaunchTaskListL()
       
   425     {
       
   426     User::Leave(KErrNotSupported);
       
   427     }
       
   428 
       
   429 EXPORT_C void CEikServAppUiBase::CycleTasksL(enum TTaskCycleDirection aDirection) 
       
   430     {
       
   431     TApaTaskList taskList(iCoeEnv->WsSession());
       
   432     if (aDirection == EBackwards)
       
   433         {
       
   434         TApaTask task = taskList.FindByPos(-1);
       
   435         task.BringToForeground();
       
   436         }
       
   437     else
       
   438         {
       
   439         TApaTask task = taskList.FindByPos(0);
       
   440         task.SendToBackground();
       
   441         }
       
   442     
       
   443     // Will also task away from alarm when only 1 task!! Correct?        
       
   444     NotifyAlarmServerOfTaskChangeL(); 
       
   445     }
       
   446 
       
   447 EXPORT_C CEikServAppUiBase::CEikServAppUiBase()
       
   448     {
       
   449     SetFullScreenApp(EFalse);
       
   450     }
       
   451 
       
   452 LOCAL_C void ReleaseFactories(TAny* aPtr)
       
   453     {
       
   454     TEikServCtrlFactories& factory = *(TEikServCtrlFactories*)aPtr;
       
   455     if (factory.iAlert)
       
   456         {
       
   457         factory.iAlert->Release();
       
   458         }
       
   459     }
       
   460 
       
   461 LOCAL_C void PointerCleanup(TAny* aPtr)
       
   462     {
       
   463     RWsPointerCursor* ptr = REINTERPRET_CAST(RWsPointerCursor*, aPtr);
       
   464     ptr->Close();
       
   465     delete ptr;
       
   466     }
       
   467 
       
   468 EXPORT_C void CEikServAppUiBase::ConstructL() 
       
   469     {
       
   470     RWindowGroup& groupWin = iCoeEnv->RootWin();
       
   471     RWsSession& wsSession = iCoeEnv->WsSession();
       
   472     iEikonEnv->SetAutoForwarding(ETrue);
       
   473     iEikonEnv->SetSystem(ETrue);
       
   474     iEikonEnv->FsSession().SetNotifyUser(EFalse);
       
   475 
       
   476     // Must call BaseConstructL to get Avkon classes called.
       
   477 #ifdef _DEBUG
       
   478     RDebug::Print(_L("CAknAppUiBase::BaseConstructL() in "));
       
   479 #endif
       
   480     CAknAppUiBase::BaseConstructL(ENonStandardResourceFile|ENoScreenFurniture|
       
   481         EAknEnableMSK|EAknSingleClickCompatible);
       
   482 #ifdef _DEBUG
       
   483     RDebug::Print(_L("CAknAppUiBase::BaseConstructL() out"));
       
   484 #endif
       
   485 
       
   486     groupWin.SetName(__EIKON_SERVER_NAME);
       
   487     groupWin.EnableErrorMessages(EEventControlAlways);
       
   488     groupWin.EnableOnEvents(EEventControlAlways);
       
   489     wsSession.ComputeMode(RWsSession::EPriorityControlDisabled);
       
   490     iCoeEnv->RootWin().EnableScreenChangeEvents();
       
   491     RThread thread;
       
   492     
       
   493 #if defined(__EPOC32__)
       
   494     thread.SetProcessPriority(EPriorityHigh);
       
   495 #else
       
   496     thread.SetPriority(EPriorityAbsoluteForeground);
       
   497 #endif
       
   498 
       
   499     // Create a window group for the password and alarm screens.
       
   500     iAlertGroupWin = RWindowGroup(wsSession);
       
   501     
       
   502     // EFalse disables key events - they will be enabled again as soon as the ordinal position is 
       
   503     // set such that iAlertGroupWin is not the foreground window-group.
       
   504     User::LeaveIfError(iAlertGroupWin.Construct((TUint32)this, EFalse)); 
       
   505     
       
   506     iAlertGroupWin.SetOrdinalPosition(0, ECoeWinPriorityNeverAtFront);
       
   507     
       
   508     // Enable key events, now that iAlertGroupWin is not in the foreground.
       
   509     iAlertGroupWin.EnableReceiptOfFocus(ETrue); 
       
   510 
       
   511     iEikServExtra = new(ELeave) CEikServExtra();
       
   512     
       
   513     TInt numCursors = LafServAppUiBase::NumberOfCursorsInSystemCursorList();
       
   514     if(numCursors != 0 && LafServAppUiBase::ClaimPointerCursorListIfNeeded(*iEikonEnv) == KErrNone)
       
   515         {
       
   516         iEikServExtra->iPointerCursors = new(ELeave) CArrayPtrFlat<RWsPointerCursor>(4);
       
   517         TSpriteMember member;
       
   518         for(TInt ii = 0; ii < numCursors; ii++)
       
   519             {
       
   520             RWsPointerCursor* cursor = LafServAppUiBase::ConstructPointerCursorL(ii, member, 
       
   521                 *iEikonEnv);
       
   522                 
       
   523             CleanupStack::PushL(TCleanupItem(PointerCleanup, cursor));
       
   524             iEikServExtra->iPointerCursors->AppendL(cursor);
       
   525             CleanupStack::Pop(); // cursor - handle & ptr
       
   526             }
       
   527         }
       
   528     }
       
   529 
       
   530 EXPORT_C void CEikServAppUiBase::InitializeL(TEikServCtrlFactories& aCtrlFactories)
       
   531     {
       
   532     RWindowGroup& rootWin = iCoeEnv->RootWin();
       
   533 
       
   534     CleanupStack::PushL(TCleanupItem(&ReleaseFactories,&aCtrlFactories));
       
   535     RFs& fsSession = iCoeEnv->FsSession();
       
   536     _LIT(KAppDirName, "C:\\System\\Apps\\");
       
   537     fsSession.MkDirAll(KAppDirName); // !! prevent app arch crash
       
   538 
       
   539     // Initialize some system settings.
       
   540     SetSystemTime();
       
   541     rootWin.EnableOnEvents(EEventControlAlways);
       
   542 
       
   543     TPasswordMode mode = EPasswordNone;
       
   544 
       
   545     TRAP_IGNORE(
       
   546         CEikPasswordModeCategory* pcategory = CEikPasswordModeCategory::NewLC(fsSession);
       
   547         if( pcategory )
       
   548             {
       
   549             pcategory->GetPasswordModeL(mode);
       
   550             if (mode == EPasswordNone) // prevent overwriting once per day
       
   551                 {
       
   552                 mode = EPasswordAlways;    
       
   553                 }
       
   554             // Initialise (write to system.ini) here so that it won't fail in the future due to OOM.
       
   555             pcategory->SetPasswordModeL(mode);
       
   556             CleanupStack::PopAndDestroy(); // pcategory
       
   557             }
       
   558         );
       
   559 
       
   560     // Create separate thread for OOD watchers.
       
   561     CreateWatcherThreadL();
       
   562 
       
   563     // Start View Server.
       
   564     iAppStarter = CEikServAppStarter::NewL();
       
   565     User::LeaveIfError(CVwsSessionWrapper::StartViewServer(*iAppStarter));
       
   566     iVwsSession = CVwsSessionWrapper::NewL();
       
   567     
       
   568     TResourceReader reader;
       
   569     iEikonEnv->CreateResourceReaderLC(reader, R_EIK_SYSTEM_DEFAULT_VIEW_ID);
       
   570     TVwsViewId viewId;
       
   571     viewId.iAppUid.iUid = reader.ReadInt32();
       
   572     viewId.iViewUid.iUid = reader.ReadInt32();
       
   573     CleanupStack::PopAndDestroy(); // reader
       
   574     iVwsSession->SetSystemDefaultView(viewId);
       
   575 
       
   576     TInt serverEventTimeOutDuration = EikResourceUtils::ReadTInt32L(    
       
   577         R_EIK_SYSTEM_VIEW_SERVER_EVENT_TIME_OUT, iEikonEnv);
       
   578         
       
   579     iVwsSession->SetServerEventTimeOut( TTimeIntervalMicroSeconds32(serverEventTimeOutDuration) );
       
   580     
       
   581     TInt clientRequestTimeOutDuration = EikResourceUtils::ReadTInt32L(
       
   582         R_EIK_SYSTEM_VIEW_SERVER_CLIENT_REQUEST_TIME_OUT, iEikonEnv);
       
   583         
       
   584     iVwsSession->SetClientRequestTimeOut( TTimeIntervalMicroSeconds32(clientRequestTimeOutDuration) );
       
   585 
       
   586     iVwsSession->EnableServerBlankScreen(EFalse);
       
   587     
       
   588     // Start Comms
       
   589     TInt err = StartC32();
       
   590     if (err != KErrNone && err != KErrAlreadyExists)
       
   591         {
       
   592         User::Leave(err);
       
   593         }
       
   594     
       
   595     err = User::LoadPhysicalDevice(COMMS_PDD_NAME);
       
   596     if (err != KErrNone && err != KErrAlreadyExists && err != KErrNotFound)
       
   597         {
       
   598         User::Leave(err);
       
   599         }
       
   600         
       
   601     err = User::LoadLogicalDevice(COMMS_LDD_NAME);
       
   602     if (err != KErrNone && err != KErrAlreadyExists && err != KErrNotFound)
       
   603         {
       
   604         User::Leave(err);
       
   605         }
       
   606 
       
   607     // Start notifier server last as these may have plug-ins that rely on the other servers 
       
   608     // started here being up and running.
       
   609     iNotifyServer = CEikServNotifyServer::NewL(aCtrlFactories.iAlert);
       
   610 
       
   611     CleanupStack::Pop(); // aCtrlFactories
       
   612 
       
   613     iEikServExtra->iNotifierServerStarter = CIdle::NewL(CActive::EPriorityLow);
       
   614     iEikServExtra->iNotifierServerStarter->Start(TCallBack(StartNotifierServerCallBackL, this));
       
   615 
       
   616     rootWin.EnableGroupListChangeEvents();
       
   617 
       
   618     // Create undertaker active object.
       
   619     iUndertaker = CEikUndertaker::NewL(*this);
       
   620 
       
   621     // Create an active object to restart servers. 
       
   622     iEikServExtra->iServerRestarter = CPeriodic::NewL(CActive::EPriorityStandard);
       
   623     }
       
   624 
       
   625 EXPORT_C void CEikServAppUiBase::HandleThreadExitL(RThread& aThread)
       
   626     {
       
   627     if (aThread.Name() == ASCliDefinitions::ServerAndThreadName()) // alarm server died
       
   628         {
       
   629         aThread.Close(); // need to Close() before restarting with same name
       
   630         iServerToRestart |= EAlwlSvr; // restarted under active object
       
   631         }
       
   632     else if (aThread.Name()==NameApaServServerThread()) // AppArc server died
       
   633         {
       
   634         aThread.Close();
       
   635         iServerToRestart|=EApaSvr;
       
   636         }
       
   637         
       
   638     if (iServerToRestart && !iEikServExtra->iServerRestarter->IsActive())
       
   639         {
       
   640         iEikServExtra->iServerRestarter->Start(
       
   641             KEikServServerRestartDelay, 
       
   642             KEikServServerRestartInterval, 
       
   643             TCallBack(RestartServerCallback, this));
       
   644         }
       
   645     }
       
   646 
       
   647 EXPORT_C void CEikServAppUiBase::HandleForegroundEventL(TBool aForeground)
       
   648     {
       
   649     CAknAppUiBase::HandleForegroundEventL(aForeground);
       
   650     }
       
   651 
       
   652 TInt CEikServAppUiBase::RestartServerCallback(TAny* aObj)
       
   653     {
       
   654     STATIC_CAST(CEikServAppUiBase*, aObj)->RestartServer();
       
   655     return KErrNone;
       
   656     }
       
   657 
       
   658 TInt CEikServAppUiBase::StartNotifierServerCallBackL(TAny* aPtr)
       
   659     { // static
       
   660     CEikServAppUiBase* self = static_cast<CEikServAppUiBase*>(aPtr);
       
   661     self->iNotifyServer->StartL();
       
   662     delete self->iEikServExtra->iNotifierServerStarter;
       
   663     self->iEikServExtra->iNotifierServerStarter=NULL;
       
   664     return KErrNone;
       
   665     }
       
   666 
       
   667 // Kick dead servers back to life, if we can connect then stop kicking.
       
   668 void CEikServAppUiBase::RestartServer()
       
   669     {
       
   670     if (iServerToRestart & EAlwlSvr)
       
   671         {
       
   672         // Start AlarmServer
       
   673         TInt err = AlarmClientUtils::StartAlarmServer();
       
   674         if (err == KErrNone)
       
   675             {
       
   676             iServerToRestart&=(~EAlwlSvr);
       
   677             }
       
   678         }
       
   679         
       
   680     if (iServerToRestart&EApaSvr)
       
   681         {
       
   682         AknStartupApaServerProcess();
       
   683 
       
   684         // try to connect to the server
       
   685         RApaLsSession ls;
       
   686         TInt err = ls.Connect();
       
   687         if (err == KErrNone)
       
   688             {
       
   689             ls.Close();
       
   690             iServerToRestart&=(~EApaSvr);
       
   691             }
       
   692         }
       
   693         
       
   694     if (!iServerToRestart)
       
   695         {
       
   696         iEikServExtra->iServerRestarter->Cancel();
       
   697         }
       
   698     }
       
   699 
       
   700 EXPORT_C TKeyResponse CEikServAppUiBase::HandleKeyEventL(const TKeyEvent& aKeyEvent, 
       
   701     TEventCode /*aType*/)
       
   702     {
       
   703     if (aKeyEvent.iCode == CTRL('e'))
       
   704         {
       
   705         CBaActiveScheduler::Exit();
       
   706         }
       
   707     return EKeyWasConsumed;
       
   708     }
       
   709 
       
   710 // Check the battery states and update any alarm snooze time.
       
   711 EXPORT_C void CEikServAppUiBase::HandleSwitchOnEventL(CCoeControl* /*aDestination*/)
       
   712     {
       
   713     // Could just expose alarm alert server to UI dll!!
       
   714     if (iAlarmAlertServer)
       
   715         {
       
   716         iAlarmAlertServer->HandleSwitchOnEvent();
       
   717         }
       
   718     }
       
   719 
       
   720 EXPORT_C void CEikServAppUiBase::HandleSystemEventL(const TWsEvent& aEvent)
       
   721     {
       
   722     TInt event = *((TInt*)aEvent.EventData());
       
   723     switch (event)
       
   724         {
       
   725 #ifdef _DEBUG
       
   726         case EEikServExit:
       
   727             CBaActiveScheduler::Exit();
       
   728             break;
       
   729 #endif
       
   730         default:
       
   731             break;
       
   732         }
       
   733     }
       
   734 
       
   735 EXPORT_C void CEikServAppUiBase::HandleApplicationSpecificEventL(TInt aType, const TWsEvent& aEvent)
       
   736     {
       
   737     // Check command/number or whatever first!!
       
   738     CAknAppUiBase::HandleApplicationSpecificEventL(aType, aEvent);
       
   739     }
       
   740 
       
   741 
       
   742 EXPORT_C CEikServAppUiBase::~CEikServAppUiBase()
       
   743     {
       
   744     delete iUndertaker;
       
   745     
       
   746     if (iEikServExtra)
       
   747         {
       
   748         delete iEikServExtra->iServerRestarter;
       
   749         
       
   750         if (iEikServExtra->iPointerCursors)
       
   751             {
       
   752             const TInt count = iEikServExtra->iPointerCursors->Count();
       
   753             
       
   754             for (TInt ii = 0; ii < count; ii++)
       
   755                 {
       
   756                 (*(iEikServExtra->iPointerCursors))[ii]->Close();
       
   757                 }
       
   758                 
       
   759             iEikServExtra->iPointerCursors->ResetAndDestroy();
       
   760             delete iEikServExtra->iPointerCursors;
       
   761             }
       
   762             
       
   763         delete iEikServExtra->iNotifierServerStarter;
       
   764         delete iEikServExtra;
       
   765         }
       
   766         
       
   767     LafServAppUiBase::FreePointerCursorListIfNeeded(*iEikonEnv);
       
   768     RWindowGroup& groupWin = iEikonEnv->RootWin();
       
   769     groupWin.DisableErrorMessages();
       
   770     groupWin.DisableOnEvents();
       
   771     iAlertGroupWin.Close();
       
   772     delete iNotifyServer;
       
   773     delete iAlarmAlertServer;
       
   774     delete iAppStarter;
       
   775     
       
   776     if (iVwsSession)
       
   777         {
       
   778         iVwsSession->ShutdownViewServer();
       
   779         delete iVwsSession;
       
   780         }
       
   781     }
       
   782 
       
   783 void CEikServAppUiBase::SetSystemTime() const
       
   784     {
       
   785     // Deprecated, we don't have capability to set system time.
       
   786     }
       
   787 
       
   788 // Bring to foreground or send to background appropriately.
       
   789 EXPORT_C void CEikServAppUiBase::BringAlertGroupWinForwards(TBool aForwards)
       
   790     {
       
   791     if (aForwards)
       
   792         {
       
   793         if (!iAlertGroupForwardsCount++)
       
   794             {
       
   795             iAlertGroupWin.SetOrdinalPosition(0, KMaxTInt); 
       
   796             }
       
   797         }
       
   798     else if (--iAlertGroupForwardsCount == 0)
       
   799         {
       
   800         iAlertGroupWin.SetOrdinalPosition(0, ECoeWinPriorityNeverAtFront); 
       
   801         }
       
   802     }
       
   803 
       
   804 EXPORT_C void CEikServAppUiBase::SetStatusPaneFlags(TInt /*aFlags*/)
       
   805     {
       
   806     User::Leave(KErrNotSupported);
       
   807     }
       
   808 
       
   809 EXPORT_C void CEikServAppUiBase::SetStatusPaneLayoutL(TInt /*aLayoutResId*/)
       
   810     {
       
   811     User::Leave(KErrNotSupported);
       
   812     }
       
   813 
       
   814 EXPORT_C void CEikServAppUiBase::BlankScreenL()
       
   815     {
       
   816     User::Leave(KErrNotSupported);
       
   817     }
       
   818 
       
   819 EXPORT_C void CEikServAppUiBase::UnblankScreen()
       
   820     {
       
   821     User::Leave(KErrNotSupported);
       
   822     }
       
   823 
       
   824 EXPORT_C void CEikServAppUiBase::ShutdownAppsL(const TUid aRequesterUID, 
       
   825     const RMessage2& aShutdownMessage, const TInt aTimeoutInMicroseconds)
       
   826     {
       
   827     CEikSrvAppShutdown::StartL(aRequesterUID, aShutdownMessage, aTimeoutInMicroseconds);
       
   828     }
       
   829 
       
   830 EXPORT_C void CEikServAppUiBase::HandleResourceChangeL(TInt aType)
       
   831     {
       
   832     CAknAppUiBase::HandleResourceChangeL(aType);
       
   833     }
       
   834 
       
   835 void CEikServAppUiBase::Extension(TUid /*aExtensionUid*/, const TDesC8& /*aBuffer*/, 
       
   836     RMessagePtr2 /*aMessage*/)
       
   837     {
       
   838     // Not implemented
       
   839     }
       
   840 
       
   841 EXPORT_C void CEikServAppUiBase::HandleWsEventL(const TWsEvent& aEvent,CCoeControl* aDestination)
       
   842     {
       
   843     CAknAppUiBase::HandleWsEventL(aEvent, aDestination);
       
   844     }
       
   845 
       
   846 void CEikServAppUiBase::SetSgcParamsL(TInt /*aWgId*/, TBitFlags /*aAppFlags*/, TInt /*aSpLayout*/, 
       
   847     TInt /*aSpFlags*/)
       
   848     {
       
   849     }
       
   850 
       
   851 void CEikServAppUiBase::PrepareForAppExitL(TInt /*aWgId*/)
       
   852     {
       
   853     }
       
   854 
       
   855 
       
   856 // =============
       
   857 // CEikServAppUi
       
   858 // =============
       
   859 
       
   860 void CEikServAppUi::SetStatusPaneFlags(TInt aFlags)
       
   861     {
       
   862     if (iAknCapServerClient.Handle())
       
   863         {
       
   864         iAknCapServerClient.SetStatusPaneFlags(aFlags);
       
   865         }
       
   866     }
       
   867 
       
   868 void CEikServAppUi::SetStatusPaneLayoutL(TInt aLayoutResId)
       
   869     {
       
   870     if (iAknCapServerClient.Handle())
       
   871         {
       
   872         iAknCapServerClient.SetStatusPaneLayout(aLayoutResId);
       
   873         }
       
   874     }
       
   875 
       
   876 void CEikServAppUi::BlankScreenL()
       
   877     {
       
   878     if (iAknCapServerClient.Handle())
       
   879         {
       
   880         iAknCapServerClient.BlankScreen();
       
   881         }
       
   882     }
       
   883 
       
   884 void CEikServAppUi::UnblankScreen()
       
   885     {
       
   886     if (iAknCapServerClient.Handle())
       
   887         {
       
   888         iAknCapServerClient.UnblankScreen();
       
   889         }
       
   890     }
       
   891 
       
   892 void CEikServAppUi::EnableTaskListL()
       
   893     {
       
   894     User::LeaveIfError(iAknCapServerClient.EnableTaskList(ETrue));
       
   895     }
       
   896 
       
   897 void CEikServAppUi::LaunchTaskListL() //const
       
   898     {
       
   899     User::LeaveIfError(iAknCapServerClient.MakeTaskListVisible(ETrue));
       
   900     }
       
   901 
       
   902 void CEikServAppUi::CloseTaskList() //const
       
   903     {
       
   904     // Ignore possible error.
       
   905     iAknCapServerClient.MakeTaskListVisible(EFalse);
       
   906     }
       
   907 
       
   908 CEikServAppUi::CEikServAppUi()
       
   909     {
       
   910     }
       
   911 
       
   912 void CEikServAppUi::ConstructL()
       
   913     {
       
   914     // Create stub to allow device boot up with old notifier controller dependencies.
       
   915     iNotifierDialogController = CNotifierDialogController::NewL(0);
       
   916 
       
   917 #ifdef _DEBUG
       
   918     RDebug::Print(_L("CEikServAppUi::ConstructL() in"));
       
   919 #endif
       
   920 
       
   921     AknsUtils::InitSkinSupportL();
       
   922 #ifdef _DEBUG
       
   923     RDebug::Print(_L("CEikServAppUi::ConstructL() init skins ok"));
       
   924 #endif
       
   925 
       
   926     CEikServAppUiBase::ConstructL();
       
   927 #ifdef _DEBUG
       
   928     RDebug::Print(_L("CEikServAppUi::ConstructL() CEikServAppUiBase constructed"));
       
   929 #endif
       
   930 
       
   931     AknsUtils::SetAvkonSkinEnabledL( ETrue );
       
   932 #ifdef _DEBUG
       
   933     RDebug::Print(_L("CEikServAppUi::ConstructL(), CEikServAppUiBase::ConstructL() succeed"));
       
   934 #endif
       
   935 
       
   936     AknsUtils::SetAvkonSkinEnabledL( ETrue );
       
   937 #ifdef _DEBUG
       
   938     RDebug::Print(_L("CEikServAppUiBase::ConstructL(), Skins enabled"));
       
   939 #endif
       
   940 
       
   941     TFileName fileName(KResFileName);
       
   942     BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(), fileName);
       
   943     iResourceFileOffset = iCoeEnv->AddResourceFileL(fileName);
       
   944 
       
   945     // Create notifier controller before Notfier server is started.
       
   946     iNotifierController = CAknNotifierController::NewL();
       
   947 
       
   948 #ifdef _DEBUG
       
   949     RDebug::Print(_L("CEikServAppUi::ConstructL(), initializing Alert"));
       
   950 #endif
       
   951 
       
   952     CEikServNotifyAlert* alert=new(ELeave) CEikServNotifyAlert;
       
   953     CleanupStack::PushL(alert);
       
   954     alert->ConstructL();
       
   955     TEikServCtrlFactories fctry;
       
   956     fctry.iAlert = alert;
       
   957     fctry.iAlarmAlert = this;
       
   958     CleanupStack::Pop();
       
   959 
       
   960 #ifdef _DEBUG
       
   961     RDebug::Print(_L("CEikServAppUi::ConstructL(), Alert created"));
       
   962 #endif
       
   963 
       
   964     CEikServAppUiBase::InitializeL(fctry);
       
   965 
       
   966 #ifdef _DEBUG
       
   967     RDebug::Print(_L("CEikServAppUiBase::InitializeL(fctry) succeed"));
       
   968 #endif
       
   969 
       
   970     RWsSession& wsSession = iCoeEnv->WsSession();
       
   971 
       
   972     // Initialize some system settings.
       
   973     TRAP_IGNORE(EnsureExternalKeyHandlerAppStreamExistsL());
       
   974 
       
   975 #ifdef _DEBUG
       
   976     RDebug::Print(_L("CEikServAppUi::ConstructL(), Creating WG for status pane"));
       
   977 #endif
       
   978 
       
   979     // Create high priority windows for app bar and side bar.
       
   980     iOffScreenGroupWin = RWindowGroup(wsSession);
       
   981     User::LeaveIfError(iOffScreenGroupWin.Construct((TUint32)&iOffScreenGroupWin, 
       
   982         EFalse)); // EFalse disables key events
       
   983     iOffScreenGroupWin.SetOrdinalPosition(0,ECoeWinPriorityHigh);
       
   984 
       
   985 #ifdef _DEBUG
       
   986     RDebug::Print(_L("CEikServAppUi::ConstructL(), Starting sound server"));
       
   987 #endif
       
   988 
       
   989     // Launch the Avkon KeySound Server
       
   990     User::LeaveIfError(CEikKeySoundServer::LaunchServer(iKeySoundThreadId));
       
   991     
       
   992     // Start the Avkon Anim Dll - required for keysounds
       
   993     iAknAnimDll = new(ELeave)RAnimDll(wsSession);
       
   994     iAknAnimDll->Load(KAnimDllFileName);
       
   995     iAknAnimKeySound = new(ELeave)RAknAnimKeySound(*iAknAnimDll);
       
   996     iAknAnimKeySound->ConstructL(&iOffScreenGroupWin);
       
   997 
       
   998 #ifdef _DEBUG
       
   999     RDebug::Print(_L("CEikServAppUi::ConstructL(), Keysounds and plugin initialized"));
       
  1000 #endif
       
  1001 
       
  1002     // Create default keysounds - pass in UID.
       
  1003     ReplaceKeySoundsL(0x100053D0);
       
  1004 
       
  1005 #ifdef _DEBUG
       
  1006     RDebug::Print(_L("CEikServAppUi::ConstructL(), Default client and context for keysound created "));
       
  1007 #endif
       
  1008 
       
  1009     // Window server buffer size.
       
  1010     RWsSession &ws = iEikonEnv->WsSession();
       
  1011     TInt bufSize = 6400;
       
  1012     ws.SetMaxBufferSizeL(bufSize);
       
  1013 
       
  1014     // Load bitmap cursors.
       
  1015     LoadBitmapCursorsL();
       
  1016 
       
  1017     STATIC_CAST(CEikServEnv*,CEikonEnv::Static())->SetEikServAppUiSessionFactory( this );
       
  1018 
       
  1019 #ifdef _DEBUG
       
  1020     RDebug::Print(_L("CEikServAppUi::ConstructL(), over and out"));
       
  1021 #endif
       
  1022     }
       
  1023 
       
  1024 
       
  1025 void CEikServAppUi::RestartKeySoundThreadL()
       
  1026     {
       
  1027     // Restart keysound server.
       
  1028     TInt err = CEikKeySoundServer::LaunchServer(iKeySoundThreadId);
       
  1029     if (err != KErrNone)
       
  1030         {
       
  1031         // Server cannot be restarted, so leave existing animation dll.
       
  1032         // No sounds will be played, but machine will still operate.
       
  1033         return;
       
  1034         }
       
  1035         
       
  1036     // Restart the animation dll
       
  1037     if (iAknAnimKeySound)
       
  1038         {
       
  1039         iAknAnimKeySound->Close();
       
  1040         delete iAknAnimKeySound;
       
  1041         iAknAnimKeySound = NULL;
       
  1042         }
       
  1043         
       
  1044     if (iAknAnimDll)
       
  1045         {
       
  1046         iAknAnimDll->Close();
       
  1047         delete iAknAnimDll;
       
  1048         iAknAnimDll = NULL;
       
  1049         }
       
  1050 
       
  1051     // Restart the animation dll.
       
  1052     iAknAnimDll = new(ELeave)RAnimDll(iCoeEnv->WsSession());
       
  1053     iAknAnimDll->Load(KAnimDllFileName);
       
  1054     iAknAnimKeySound = new(ELeave)RAknAnimKeySound(*iAknAnimDll);
       
  1055     iAknAnimKeySound->ConstructL(&iOffScreenGroupWin);
       
  1056 
       
  1057     // Invented new API.
       
  1058     ReplaceKeySoundsL(0x100053D0);
       
  1059     KeySounds()->BringToForeground();
       
  1060     }
       
  1061 
       
  1062 
       
  1063 void CEikServAppUi::HandleThreadExitL(RThread& aThread)
       
  1064     {
       
  1065     if(aThread.Name().CompareF(_L("aknnfysrv")) == 0)
       
  1066         {
       
  1067         StartNewServerApplicationL(KCommonNotifierAppSrvUid);
       
  1068         return;
       
  1069         }
       
  1070 
       
  1071     TThreadId id = aThread.Id();
       
  1072     TExitType exitType = aThread.ExitType();
       
  1073     if (id == iExternalKeyHandlerThreadId)
       
  1074         {
       
  1075         iExternalKeyHandlerRunning = EFalse;
       
  1076         }
       
  1077     else if (id == iHelpAppThreadId)
       
  1078         {
       
  1079         iHelpAppRunning = EFalse;
       
  1080         }
       
  1081     else if (id == iKeySoundThreadId)
       
  1082         {
       
  1083         RestartKeySoundThreadL();
       
  1084         // Don't tell the user about it.
       
  1085         return;
       
  1086         }
       
  1087 
       
  1088     TBool rdSupport = BaflUtils::FileExists( iEikonEnv->FsSession(), KRDSupport );
       
  1089 
       
  1090     // Show panic notes only if that feature is enabled.
       
  1091     if ( exitType == EExitPanic && ( rdSupport || FeatureManager::FeatureSupported( 
       
  1092         KFeatureIdShowPanics )) )
       
  1093         {
       
  1094         // Construct text for a panic note.
       
  1095         HBufC* panicText = ConstructPanicTextLC( aThread, rdSupport );
       
  1096         
       
  1097         iAknCapServerClient.ShowGlobalNoteL(panicText->Des(), EAknGlobalErrorNote);
       
  1098         CleanupStack::PopAndDestroy(); // panicText
       
  1099         }
       
  1100         
       
  1101     CEikServAppUiBase::HandleThreadExitL(aThread);
       
  1102     }
       
  1103 
       
  1104 void CEikServAppUi::UpdateTaskListL()
       
  1105     {
       
  1106     iAknCapServerClient.UpdateTaskList();
       
  1107     }
       
  1108 
       
  1109 TKeyResponse CEikServAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode /*aType*/)
       
  1110     {
       
  1111     if (aKeyEvent.iCode == CTRL('e')) // Exit
       
  1112         {
       
  1113         CBaActiveScheduler::Exit();
       
  1114         }
       
  1115     return EKeyWasConsumed;
       
  1116     }
       
  1117 
       
  1118 void CEikServAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination)
       
  1119     {
       
  1120     switch (aEvent.Type())
       
  1121         {
       
  1122         case EEventPassword:
       
  1123             {
       
  1124             // No action in Avkon.
       
  1125             break;
       
  1126             }
       
  1127         case EEventErrorMessage:
       
  1128             HandleErrorMessageEvent(*(aEvent.ErrorMessage()));
       
  1129             break;
       
  1130         case KUidValueAknsSkinChangeEvent:
       
  1131             {
       
  1132             HandleResourceChangeL(KAknsMessageSkinChange);
       
  1133             HandleStackedControlsResourceChange(KAknsMessageSkinChange);
       
  1134             break;
       
  1135             }
       
  1136         default:
       
  1137             CEikServAppUiBase::HandleWsEventL(aEvent, aDestination);
       
  1138             break;
       
  1139         }
       
  1140     }
       
  1141 
       
  1142 // Handle an error message from the window server.
       
  1143 void CEikServAppUi::HandleErrorMessageEvent(const TWsErrorMessage& aErrorMessage)
       
  1144     {
       
  1145     TUint err = aErrorMessage.iError;
       
  1146     
       
  1147     switch (aErrorMessage.iErrorCategory)
       
  1148         {
       
  1149         case TWsErrorMessage::EDrawingRegion:
       
  1150             HandleOomEvent();
       
  1151             break;
       
  1152         case TWsErrorMessage::EBackLight:
       
  1153             HandleBacklightError(err);
       
  1154             break;
       
  1155         case TWsErrorMessage::ELogging:
       
  1156             HandleWservLoggingError(err);
       
  1157             break;
       
  1158         default:
       
  1159             break; // intentionally ignored
       
  1160         }
       
  1161     }
       
  1162 
       
  1163 void CEikServAppUi::HandleResourceChangeL(TInt aType)
       
  1164     {
       
  1165     CEikServAppUiBase::HandleResourceChangeL(aType);
       
  1166     if ( aType == KEikDynamicLayoutVariantSwitch )
       
  1167         {
       
  1168         UpdateCursorsL();
       
  1169         }
       
  1170     }
       
  1171 
       
  1172 // Check the battery states and update any alarm snooze time.
       
  1173 void CEikServAppUi::HandleSwitchOnEventL(CCoeControl* /*aDestination*/)
       
  1174     {
       
  1175     if (iAlarmAlertServer)
       
  1176         {
       
  1177         iAlarmAlertServer->HandleSwitchOnEvent();
       
  1178         }
       
  1179     }
       
  1180 
       
  1181 void CEikServAppUi::HandleSystemEventL(const TWsEvent& aEvent)
       
  1182     {
       
  1183     TInt event = *((TInt*)aEvent.EventData());
       
  1184     switch (event)
       
  1185         {
       
  1186 #ifdef _DEBUG
       
  1187         case EEikServExit:
       
  1188             CBaActiveScheduler::Exit();
       
  1189             break;
       
  1190 #endif
       
  1191         case EEikServChangePasswordMode:
       
  1192             // No action in Avkon
       
  1193             break;
       
  1194         case EEikServShowTaskList:
       
  1195             LaunchTaskListL();
       
  1196             break;
       
  1197         case EEikServHideTaskList:
       
  1198             CloseTaskList();
       
  1199             break;
       
  1200         default:
       
  1201             break;
       
  1202         }
       
  1203     }
       
  1204 
       
  1205 CEikServAppUi::~CEikServAppUi()
       
  1206     {
       
  1207     if (iAknAnimKeySound)
       
  1208         {
       
  1209         iAknAnimKeySound->Close();
       
  1210         }
       
  1211     delete iAknAnimKeySound;
       
  1212     
       
  1213     if (iAknAnimDll)
       
  1214         {
       
  1215         iAknAnimDll->Close();
       
  1216         }
       
  1217     delete iAknAnimDll;
       
  1218 
       
  1219     // Shut down the key sound server.
       
  1220     RKeySoundServerCloser ksCloserSession;
       
  1221     ksCloserSession.CloseServer();
       
  1222 
       
  1223     iOffScreenGroupWin.Close();
       
  1224     delete iAppbarWindow;
       
  1225     delete iSidebarWindow;
       
  1226     
       
  1227     if (iCoeEnv)
       
  1228         {
       
  1229         iCoeEnv->DeleteResourceFile(iResourceFileOffset);
       
  1230         }
       
  1231 
       
  1232     delete iIdler;
       
  1233     iNotifServerAppQueue.Close();
       
  1234 
       
  1235     delete iNotifierController;
       
  1236     delete iNotifierDialogController;
       
  1237     }
       
  1238 
       
  1239 MEikServAlarm* CEikServAppUi::NewAlarmL(CEikAlmControlSupervisor& aSupervisor)
       
  1240     {
       
  1241     CEikAlarmControl* alarm = new(ELeave) CEikAlarmControl(&aSupervisor,this);
       
  1242     CleanupStack::PushL(alarm);
       
  1243     alarm->ConstructL();
       
  1244     CleanupStack::Pop(); // alarm
       
  1245     return alarm;
       
  1246     }
       
  1247 
       
  1248 void CEikServAppUi::EnsureExternalKeyHandlerAppStreamExistsL()
       
  1249     {
       
  1250     }
       
  1251 
       
  1252 // Respond to an out of memory event from the window server.
       
  1253 void CEikServAppUi::HandleOomEvent()
       
  1254     {
       
  1255     TBuf<80> msg1;
       
  1256     TBuf<80> msg2;
       
  1257     iEikonEnv->ReadResource(msg1, R_EIKSRV_OOM_EVENT_TOP);
       
  1258     iEikonEnv->ReadResource(msg2, R_EIKSRV_OOM_EVENT_BOT);
       
  1259     MEikAlertWin* mAlert = CONST_CAST(MEikAlertWin*, iEikonEnv->Alert());
       
  1260     CEikDialog* alert = mAlert->AsEikDialog();
       
  1261     
       
  1262     CEikMover* title = NULL;
       
  1263     if ( alert )
       
  1264         {
       
  1265         title = &( alert->Title() );
       
  1266         alert->SetGloballyCapturing(ETrue);
       
  1267         title->SetActive(EFalse);
       
  1268         }
       
  1269     iEikonEnv->AlertWin(msg1, msg2);
       
  1270     if ( alert )
       
  1271         {
       
  1272         title->SetActive(ETrue);
       
  1273         alert->SetGloballyCapturing(EFalse);
       
  1274         }
       
  1275     }
       
  1276 
       
  1277 // Respond to an error from the backlight (battery too low).
       
  1278 void CEikServAppUi::HandleBacklightError(TInt /*aError*/)
       
  1279     {
       
  1280     }
       
  1281 
       
  1282 // Respond to a logging error from wserv (for use by developers)
       
  1283 void CEikServAppUi::HandleWservLoggingError(TInt aError)
       
  1284     {
       
  1285     TBuf<80> temp;
       
  1286     iEikonEnv->ReadResource(temp, R_EIKSRV_WSERV_LOGGING_ERROR);
       
  1287     TBuf<80> msg;
       
  1288     msg.Format(temp, aError);
       
  1289     iEikonEnv->AlertWin(msg);
       
  1290     }
       
  1291 
       
  1292 EXPORT_C void CEikServAppUi::SuppressAppSwitching(TBool aSuppress)
       
  1293     {
       
  1294     // Ignore error as there is nothing to do if failing.
       
  1295     iAknCapServerClient.ConnectAndSendAppsKeySuppress(aSuppress);
       
  1296     }
       
  1297 
       
  1298 HBufC* CEikServAppUi::ConstructPanicTextLC( RThread& aThread, TBool aRDSupport ) const
       
  1299     {
       
  1300     HBufC* panicText = HBufC::NewLC( KEikServPanicTextBufferSize );
       
  1301     TPtr ptr = panicText->Des();
       
  1302 
       
  1303     iEikonEnv->ReadResource( ptr, R_PROGRAM_CLOSED );
       
  1304 
       
  1305     ptr.Append( '\n' );
       
  1306 
       
  1307     HBufC* buffer = aThread.Name().AllocL();
       
  1308     TPtr name = buffer->Des();
       
  1309 
       
  1310     // Here we truncate the thread name to fit in the second and third lines of the note.
       
  1311 
       
  1312     TRect mainPane;
       
  1313     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EPopupParent, mainPane );
       
  1314     TAknLayoutRect popupNoteWindow;
       
  1315     
       
  1316     AknLayoutUtils::TAknCbaLocation cbaLocation( AknLayoutUtils::CbaLocation() );
       
  1317     TInt variety( 0 );
       
  1318     if ( cbaLocation == AknLayoutUtils::EAknCbaLocationRight )
       
  1319         {
       
  1320         variety = 3;
       
  1321         }
       
  1322     else if ( cbaLocation == AknLayoutUtils::EAknCbaLocationLeft )
       
  1323         {
       
  1324         variety = 6;
       
  1325         }
       
  1326     else
       
  1327         {
       
  1328         variety = 0;
       
  1329         }
       
  1330         
       
  1331     popupNoteWindow.LayoutRect(mainPane, AknLayoutScalable_Avkon::popup_note_window( variety ) );
       
  1332         
       
  1333     TAknLayoutText textRectTwoLines;
       
  1334     
       
  1335     textRectTwoLines.LayoutText(
       
  1336         popupNoteWindow.Rect(), 
       
  1337         AKN_LAYOUT_TEXT_Note_pop_up_window_texts_Line_1(1));
       
  1338 
       
  1339     // First determine how much fits in the 2. line of the note this can't return NULL.
       
  1340     const CFont* font = textRectTwoLines.Font();
       
  1341 
       
  1342     TInt characters( font->TextCount( name, textRectTwoLines.TextRect().Width() ) );
       
  1343 
       
  1344     // 'characters' is now the amount of characters that fit in the second line.
       
  1345 
       
  1346     ptr.Append( name.Left( characters ) );
       
  1347     ptr.Append( '\n' );
       
  1348 
       
  1349     // If the name was cut, clip the rest in the third line.
       
  1350     TInt charactersLeft( name.Length() - characters );
       
  1351 
       
  1352     if ( charactersLeft > 0 )
       
  1353         {
       
  1354         TPtr line3( 
       
  1355             (TText*)&name[characters],
       
  1356             charactersLeft,
       
  1357             charactersLeft );
       
  1358 
       
  1359         popupNoteWindow.LayoutRect(
       
  1360             mainPane, 
       
  1361             AknLayoutScalable_Avkon::popup_note_window( variety + 1) );
       
  1362             
       
  1363         TAknLayoutText textRectThreeLines;
       
  1364         
       
  1365         textRectThreeLines.LayoutText(
       
  1366             popupNoteWindow.Rect(), 
       
  1367             AKN_LAYOUT_TEXT_Note_pop_up_window_texts_Line_1(2));
       
  1368             
       
  1369         // No bidirectional text support for rendering the thread name. This is intentional.
       
  1370 
       
  1371         AknTextUtils::ClipToFit(
       
  1372             line3,
       
  1373             *font,
       
  1374             textRectThreeLines.TextRect().Width() );
       
  1375 
       
  1376         ptr.Append( line3 );
       
  1377         ptr.Append( '\n' );
       
  1378         }
       
  1379 
       
  1380     delete buffer;
       
  1381 
       
  1382     // Append panic category and reason only if RD-support file exists.
       
  1383 
       
  1384     if ( aRDSupport )
       
  1385         {
       
  1386         ptr.Append( aThread.ExitCategory() );
       
  1387         ptr.Append( ' ' );
       
  1388         ptr.AppendNum( aThread.ExitReason() );
       
  1389         }
       
  1390 
       
  1391     return panicText;
       
  1392     }
       
  1393 
       
  1394 void CEikServAppUi::LoadBitmapCursorsL()
       
  1395     {
       
  1396     RWsSession& ws = iEikonEnv->WsSession();
       
  1397 
       
  1398     // Create the array containing one sprite member.
       
  1399     TFixedArray<TSpriteMember, 1> spriteMemberArray;
       
  1400     TSpriteMember& spriteMember = spriteMemberArray[0];
       
  1401     spriteMember.iInterval = TTimeIntervalMicroSeconds32(0);
       
  1402 
       
  1403     // This resource is of type AVKON_CUSTOM_TEXT_CURSORS defined in eiksrvui.rss.
       
  1404     TResourceReader reader;
       
  1405     iEikonEnv->CreateResourceReaderLC(reader, R_AKN_CUSTOM_TEXT_CURSORS);
       
  1406 
       
  1407     HBufC* bmpFile = reader.ReadHBufCL();
       
  1408     CleanupStack::PushL(bmpFile);
       
  1409 
       
  1410 
       
  1411     TInt count = reader.ReadInt16();
       
  1412     for (TInt ii = 0; ii < count; ii++)
       
  1413         {
       
  1414         // id
       
  1415         TInt id = reader.ReadInt32();
       
  1416 
       
  1417         // bmpId and maskId
       
  1418         TInt bmpId = reader.ReadInt32();
       
  1419         TInt maskId = reader.ReadInt32();
       
  1420         spriteMember.iBitmap = NULL;
       
  1421         spriteMember.iMaskBitmap = NULL;
       
  1422 
       
  1423         if (maskId != -1)
       
  1424             {
       
  1425             AknIconUtils::CreateIconLC( 
       
  1426                 spriteMember.iBitmap,
       
  1427                 spriteMember.iMaskBitmap,
       
  1428                 *bmpFile,
       
  1429                 bmpId,
       
  1430                 maskId );
       
  1431             }
       
  1432         else
       
  1433             {
       
  1434             spriteMember.iBitmap = AknIconUtils::CreateIconL( *bmpFile, bmpId );
       
  1435             CleanupStack::PushL( spriteMember.iBitmap );
       
  1436             }
       
  1437          
       
  1438         TAknWindowLineLayout l;
       
  1439 
       
  1440         switch( id )
       
  1441             {
       
  1442             case KAknCustomTextCursorIdLeftToRight:
       
  1443             case KAknCustomTextCursorIdRightToLeft:
       
  1444                 l = AknLayoutScalable_Avkon::cursor_primary_pane().LayoutLine();
       
  1445                 break;
       
  1446             case KAknCustomTextCursorIdLeftToRightThin:
       
  1447             case KAknCustomTextCursorIdRightToLeftThin:
       
  1448             default:
       
  1449                 l = AknLayoutScalable_Avkon::cursor_primary_small_pane().LayoutLine();                   
       
  1450                 break;
       
  1451             }
       
  1452 
       
  1453         TRect rectParent = ApplicationRect();
       
  1454         TAknLayoutRect layoutRect;
       
  1455         layoutRect.LayoutRect( rectParent, l );
       
  1456         TRect rectCursorBitmap( layoutRect.Rect() );
       
  1457         TSize scaledSize(rectCursorBitmap.Width(),  rectCursorBitmap.Height() );
       
  1458         
       
  1459         // Perform the scaling
       
  1460         AknIconUtils::SetSize( 
       
  1461             spriteMember.iBitmap, 
       
  1462             scaledSize, 
       
  1463             EAspectRatioPreservedAndUnusedSpaceRemoved);
       
  1464             
       
  1465         if ( spriteMember.iMaskBitmap )
       
  1466             {
       
  1467             AknIconUtils::SetSize( 
       
  1468                 spriteMember.iMaskBitmap, 
       
  1469                 scaledSize, 
       
  1470                 EAspectRatioPreservedAndUnusedSpaceRemoved);
       
  1471             }
       
  1472         
       
  1473         // Flags.
       
  1474         TUint flags = reader.ReadUint16();
       
  1475         spriteMember.iInvertMask = flags|EAknCustomTextCursorFlagInvertMask;
       
  1476 
       
  1477         // Draw mode.
       
  1478         spriteMember.iDrawMode = (CGraphicsContext::TDrawMode)reader.ReadInt16();
       
  1479 
       
  1480         // Offset. Use actual scalings used. Do not read inside TPoint constructor for compiler 
       
  1481         // independence.
       
  1482         TInt offsetX = reader.ReadInt16(); 
       
  1483         TInt offsetY = reader.ReadInt16(); 
       
  1484         spriteMember.iOffset = TPoint(offsetX, offsetY);
       
  1485 
       
  1486         // Alignment.
       
  1487         TInt align = reader.ReadInt16();
       
  1488 
       
  1489         // Decode the "vehicle ids" into features:
       
  1490         TAknFontCategory category(EAknFontCategoryPrimary);
       
  1491         TBool isRightToLeft(EFalse);
       
  1492 
       
  1493         switch( id )
       
  1494             {
       
  1495             case KAknCustomTextCursorIdLeftToRight:
       
  1496                 break;
       
  1497             case KAknCustomTextCursorIdRightToLeft:
       
  1498                 isRightToLeft = ETrue;
       
  1499                 break;
       
  1500             case KAknCustomTextCursorIdLeftToRightThin:
       
  1501                 category = EAknFontCategoryPrimarySmall;
       
  1502                 break;
       
  1503             case KAknCustomTextCursorIdRightToLeftThin:
       
  1504                 category = EAknFontCategoryPrimarySmall;
       
  1505                 isRightToLeft = ETrue;
       
  1506                 break;
       
  1507             default:
       
  1508                 // Should not get here if the resource is correct. Already initialized defaults 
       
  1509                 // get used.
       
  1510                 break;
       
  1511             }
       
  1512 
       
  1513         id = AknCustomCursorSupport::CustomBidiTextCursorId( 
       
  1514             category, 
       
  1515             rectCursorBitmap, 
       
  1516             isRightToLeft );
       
  1517 
       
  1518         // Return code is ignored since we will regularly be setting a bitmap twice
       
  1519         (void)ws.SetCustomTextCursor(
       
  1520             id, 
       
  1521             spriteMemberArray.Array(), 
       
  1522             ESpriteFlash, 
       
  1523             (RWsSession::TCustomTextCursorAlignment)align);
       
  1524 
       
  1525         if (maskId != -1)
       
  1526             {
       
  1527             CleanupStack::PopAndDestroy(spriteMember.iMaskBitmap);
       
  1528             }
       
  1529         CleanupStack::PopAndDestroy(spriteMember.iBitmap);
       
  1530         }
       
  1531 
       
  1532     CleanupStack::PopAndDestroy(bmpFile);
       
  1533     CleanupStack::PopAndDestroy();        // reader
       
  1534     }
       
  1535 
       
  1536 //
       
  1537 // First export
       
  1538 //
       
  1539 
       
  1540 EXPORT_C CEikServAppUi* CreateAppUi()
       
  1541     {
       
  1542     return new CEikServAppUi;
       
  1543     }
       
  1544 
       
  1545 EXPORT_C void CEikServAppUi::ActivateDisplayIfNeeded()
       
  1546     {
       
  1547 #ifndef __WINS__
       
  1548 
       
  1549     // Check if screen saver active.
       
  1550     TApaTaskList list(iCoeEnv->WsSession());
       
  1551     TApaTask task = list.FindByPos(0); // topmost application
       
  1552     CApaWindowGroupName* name = 0;
       
  1553     TRAPD( err, name = CApaWindowGroupName::NewL(iCoeEnv->WsSession(), task.WgId()));
       
  1554     if ( !err && name->AppUid() == TUid::Uid(0x100056CF) ) // Screen saver Uid
       
  1555         {
       
  1556         User::ResetInactivityTime();
       
  1557         }
       
  1558     delete name;
       
  1559 #endif
       
  1560     }
       
  1561 
       
  1562 EXPORT_C CEikServAppUiSession* CEikServAppUi::CreateSessionL( /*RThread aClient*/ )
       
  1563     {
       
  1564     return CAknEikServAppUiSession::NewL( /*aClient,*/ this, *this);
       
  1565     }
       
  1566 
       
  1567 void CEikServAppUi::Extension(TUid aExtensionUid, const TDesC8& aBuffer, RMessagePtr2 aMessage)
       
  1568     {
       
  1569     TBool hasCap = aMessage.HasCapability(ECapabilityWriteDeviceData); // Write Dev D required here
       
  1570 
       
  1571     if (!hasCap)
       
  1572         {
       
  1573         aMessage.Complete(KErrPermissionDenied);
       
  1574         return;
       
  1575         }
       
  1576 
       
  1577     switch(aExtensionUid.iUid)
       
  1578         {
       
  1579         case EAknCommonNotifierServerRunning:
       
  1580             {
       
  1581             aMessage.Complete(KErrNone);
       
  1582             TRAP_IGNORE(
       
  1583                 // Do not clear the list, it can be used when common notifier server is being
       
  1584                 // restarted due crash.
       
  1585                 for (TInt i = iNotifierController->iPreloadList.Count() - 1; i >= 0; i--)
       
  1586                     {
       
  1587                     iNotifierController->iPreloadList[i]->PreLoadLibraryL();
       
  1588                     }
       
  1589                 );
       
  1590             break;   
       
  1591             }
       
  1592         case EAknNotifierControllerCmd: 
       
  1593             {
       
  1594             TInt cmd = static_cast<TInt>(*(aBuffer.Ptr()));
       
  1595 #ifdef _DEBUG
       
  1596             RThread thread;
       
  1597             aMessage.ClientL(thread); // ok to leave in debug mode
       
  1598             TName threadName( thread.Name() );
       
  1599 #endif        
       
  1600             if(cmd == CAknNotifierControllerUtility::EDoAllow)
       
  1601                 {
       
  1602 #ifdef _DEBUG
       
  1603                 
       
  1604                 RDebug::Print(_L("Allow all notifications: thread %S"), &threadName);      
       
  1605 #endif
       
  1606                 NotifierController()->DoAllowNotifications();
       
  1607                 }
       
  1608             else if(cmd == CAknNotifierControllerUtility::EDoStop)
       
  1609                 {
       
  1610 #ifdef _DEBUG
       
  1611                 RDebug::Print(_L("Stop all notifications: thread %S"), &threadName);
       
  1612 #endif
       
  1613                 NotifierController()->DoStopNotifications();
       
  1614                 }
       
  1615             else if(cmd == CAknNotifierControllerUtility::DoCancelAll)
       
  1616                 {
       
  1617 #ifdef _DEBUG
       
  1618                 RDebug::Print(_L("Cancel all notifications: thread %S"), &threadName);      
       
  1619 #endif
       
  1620                 CloseTaskList();
       
  1621                 NotifierController()->DoCancelAllNotificatons();
       
  1622                 }
       
  1623             else    
       
  1624                 {
       
  1625                 if (!aMessage.IsNull())
       
  1626                     {
       
  1627                     aMessage.Complete(KErrNotSupported);
       
  1628                     }
       
  1629                 return; 
       
  1630                 } 
       
  1631     
       
  1632             if (!aMessage.IsNull())
       
  1633                 { 
       
  1634                 // Release caller before forwarding to app servers.                    
       
  1635                 aMessage.Complete(KErrNone); 
       
  1636                 }
       
  1637             
       
  1638             NotifierController()->NotifyAppServers(cmd);
       
  1639             break;
       
  1640             }
       
  1641         case EAknCapServerStartupComplete:
       
  1642             {
       
  1643             aMessage.Complete(KErrNone); // No one is listening this return value.
       
  1644             TRAP_IGNORE(DoAknCapServerStartupCompleteL());
       
  1645             break;  
       
  1646             }
       
  1647         case EAknSignalAknCapServerReady:
       
  1648             {
       
  1649             DoSignalWhenAknServerReady(aMessage); // Completes message when akncapserver is ready.
       
  1650             break;
       
  1651             }
       
  1652         default:
       
  1653             aMessage.Complete(KErrNotSupported);
       
  1654         }
       
  1655     }
       
  1656 
       
  1657 /// Session within avkon code:
       
  1658 
       
  1659 CAknEikServAppUiSession::CAknEikServAppUiSession(
       
  1660     /* RThread aClient, */
       
  1661     MEikServAppUiSessionHandler* aHandler, 
       
  1662     CEikServAppUi& aAppUi )
       
  1663 : CEikServAppUiSession( aHandler), iAppUi(aAppUi)
       
  1664     {
       
  1665     }
       
  1666 
       
  1667 CAknEikServAppUiSession* CAknEikServAppUiSession::NewL(
       
  1668     /*RThread aClient, */
       
  1669     MEikServAppUiSessionHandler* aHandler, 
       
  1670     CEikServAppUi& aAppUi )
       
  1671     {
       
  1672     CAknEikServAppUiSession* session = new(ELeave) CAknEikServAppUiSession( 
       
  1673         /*aClient,*/ 
       
  1674         aHandler, 
       
  1675         aAppUi);
       
  1676         
       
  1677     CleanupStack::PushL(session);
       
  1678     session->ConstructL();
       
  1679     CleanupStack::Pop();
       
  1680     return session;
       
  1681     }
       
  1682 
       
  1683 CAknEikServAppUiSession::~CAknEikServAppUiSession()
       
  1684     {
       
  1685     }
       
  1686 
       
  1687 void CAknEikServAppUiSession::ConstructL()
       
  1688     {
       
  1689     }
       
  1690 
       
  1691 void CAknEikServAppUiSession::ServiceL(const RMessage2 &aMessage)
       
  1692     {
       
  1693     switch (aMessage.Function())
       
  1694         {
       
  1695         case EEikAppUiNotifyAlarmServerOfTaskChange:
       
  1696             SessionHandler()->NotifyAlarmServerOfTaskChangeL();
       
  1697             aMessage.Complete(KErrNone); 
       
  1698             break;
       
  1699         case EEikAppUiEnableTaskList:
       
  1700             SessionHandler()->EnableTaskListL();
       
  1701             aMessage.Complete(KErrNone);
       
  1702             break;
       
  1703         case EEikAppUiLaunchTaskList:
       
  1704             SessionHandler()->LaunchTaskListL();
       
  1705             aMessage.Complete(KErrNone);
       
  1706             break;
       
  1707         case EEikAppUiCycleTasks:
       
  1708             {
       
  1709             aMessage.Complete(KErrNone); 
       
  1710             }
       
  1711             break;
       
  1712         case EAknEikAppUiAddToStack:
       
  1713             {
       
  1714             CCoeControl*temp = REINTERPRET_CAST(CCoeControl*, CONST_CAST(TAny*, aMessage.Ptr0()) );
       
  1715             iAppUi.AddToStackL(temp, aMessage.Int1(), aMessage.Int2());
       
  1716             aMessage.Complete(KErrNone);
       
  1717             }
       
  1718             break;
       
  1719         case EAknEikAppUiRemoveFromStack:
       
  1720             {
       
  1721             CCoeControl*temp = REINTERPRET_CAST(CCoeControl*, CONST_CAST(TAny*, aMessage.Ptr0()) );
       
  1722             iAppUi.RemoveFromStack(temp);
       
  1723             aMessage.Complete(KErrNone);
       
  1724             }
       
  1725             break;
       
  1726         case EAknEikAppUiShutdownApps:
       
  1727             {
       
  1728             aMessage.HasCapabilityL(ECapabilityPowerMgmt); // PowerMgmt required here
       
  1729             TUid uid;
       
  1730             uid.iUid = (REINTERPRET_CAST(TInt, CONST_CAST(TAny*, aMessage.Ptr0()) ));
       
  1731             TInt timeout = REINTERPRET_CAST(TInt, CONST_CAST(TAny*, aMessage.Ptr1()) );
       
  1732             
       
  1733             //ShutdownAppsL must complete message.
       
  1734             TRAPD(err, iAppUi.ShutdownAppsL(uid, aMessage, timeout)); 
       
  1735             if (err != KErrNone)
       
  1736                 { 
       
  1737                 // Message wasn't completed.
       
  1738                 aMessage.Complete(err);
       
  1739                 }
       
  1740             }
       
  1741             break;
       
  1742          
       
  1743         default:
       
  1744             {
       
  1745             // It is the base class' responsibility to complete.
       
  1746             // This will pick up any new opcodes added by Symbian that are
       
  1747             // not yet handled here.
       
  1748             CEikServAppUiSession::ServiceL(aMessage);
       
  1749             break;    
       
  1750             }
       
  1751         }
       
  1752     }
       
  1753 void CAknEikServAppUiSession::Write(const RMessage2& aMessage, const TAny* aPtr, const TDesC8& aDes,
       
  1754     TInt anOffset)
       
  1755     {
       
  1756     TRAPD(ret, aMessage.WriteL( (TInt)aPtr, aDes, anOffset);)
       
  1757     if (ret != KErrNone)
       
  1758         {
       
  1759         RThread clientThread;
       
  1760         (void)aMessage.Client( clientThread); 
       
  1761         clientThread.Panic(_L("CEikServAppUi server"), KErrGeneral);
       
  1762         }
       
  1763     }
       
  1764 
       
  1765 //
       
  1766 // Main
       
  1767 //
       
  1768 
       
  1769 GLDEF_C TInt PanicNoteThreadFunction( TAny* /*aParameters*/ )
       
  1770     {
       
  1771     return KErrNone;
       
  1772     }
       
  1773     
       
  1774 // Probably obsolete, but just in case, Fix Me !!
       
  1775 EXPORT_C void CEikServAppUi::HideApplicationFromFswL(TInt aUid,TBool aDisable)
       
  1776     {
       
  1777     iAknCapServerClient.HideApplicationFromFsw(aDisable, aUid);
       
  1778     }
       
  1779 
       
  1780 // Start new notifier server plugin using fixed server differentiator.
       
  1781 void StartNotifierAppServerL(TUid aAppServerUid)
       
  1782     {
       
  1783     RApaLsSession apa;
       
  1784     User::LeaveIfError(apa.Connect());
       
  1785     CleanupClosePushL(apa);
       
  1786 
       
  1787     TApaAppInfo info;
       
  1788     
       
  1789     TInt err(0);
       
  1790     for(TInt i = 20;
       
  1791         ((err = apa.GetAppInfo(info, aAppServerUid)) == RApaLsSession::EAppListInvalid) && i > 0;
       
  1792         i--)
       
  1793         {
       
  1794         User::After(500000);    
       
  1795         }
       
  1796 
       
  1797     User::LeaveIfError(err);
       
  1798 
       
  1799     CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
  1800     cmdLine->SetExecutableNameL(info.iFullName);
       
  1801     cmdLine->SetServerRequiredL(KUikonUidPluginInterfaceNotifiers);
       
  1802     cmdLine->SetCommandL(EApaCommandBackground);
       
  1803     TThreadId dummy;
       
  1804     User::LeaveIfError(apa.StartApp(*cmdLine, dummy));
       
  1805 
       
  1806     CleanupStack::PopAndDestroy(2, &apa);   // cmdLine and apa
       
  1807     }
       
  1808 
       
  1809 TBool StartNotifierAppServer(TAny* aAny)
       
  1810     {
       
  1811     // Resolve uid.
       
  1812     CEikServAppUi* appUI = (CEikServAppUi*)aAny;
       
  1813     TUid serverUid = appUI->NextNotifierServerUid();  
       
  1814 
       
  1815     // Check if the aknnfysrv.exe is running, perventing for dropping into
       
  1816     // an infinite loop of launching aknnfysrv.exe
       
  1817     if (serverUid == KCommonNotifierAppSrvUid)
       
  1818         {
       
  1819         TFullName serverName;
       
  1820         serverName.Format(_L("%08x_%08x_AppServer"), KUikonUidPluginInterfaceNotifiers, KCommonNotifierAppSrvUid);
       
  1821         TFindServer find(serverName);
       
  1822         TFullName fullName;
       
  1823         if (find.Next(fullName) == KErrNone)
       
  1824             {
       
  1825             // Aknnfysrv.exe is already running, so just return.
       
  1826             return EFalse;
       
  1827             }    
       
  1828         }
       
  1829 
       
  1830     if (serverUid != KNullUid)
       
  1831         {
       
  1832         TRAP_IGNORE(StartNotifierAppServerL(serverUid))
       
  1833         }
       
  1834 
       
  1835     return EFalse; // do not call back again 
       
  1836     }
       
  1837 
       
  1838 EXPORT_C void CEikServAppUi::StartNewServerApplicationL(TUid aAppServerUid)
       
  1839     {
       
  1840     // Add to queue.   
       
  1841     if (iNotifServerAppQueue.Find(aAppServerUid.iUid) == KErrNotFound)
       
  1842         {
       
  1843         iNotifServerAppQueue.AppendL(aAppServerUid.iUid);    
       
  1844         }
       
  1845 
       
  1846     // Start idler if does not exist (if only akncapserver is already running).
       
  1847     if (!iIdler && iAknCapServerClient.Handle() != 0)
       
  1848         {
       
  1849         iIdler = CIdle::NewL(CActive::EPriorityHigh);
       
  1850         iIdler->Start(TCallBack(StartNotifierAppServer, this));
       
  1851         }
       
  1852     }
       
  1853     
       
  1854 TUid CEikServAppUi::NextNotifierServerUid()
       
  1855     {
       
  1856     TInt uid = 0;
       
  1857 
       
  1858     delete iIdler;
       
  1859     iIdler = 0;
       
  1860 
       
  1861     if (iNotifServerAppQueue.Count()) 
       
  1862         {
       
  1863         uid = iNotifServerAppQueue[0];
       
  1864         iNotifServerAppQueue.Remove(0);
       
  1865         }    
       
  1866 
       
  1867     // Activate idler for next uid.
       
  1868     if (iNotifServerAppQueue.Count()) 
       
  1869         {
       
  1870         // We must trap this call, if creating a new CIdle fails, no applications will be started 
       
  1871         // from queue until new request comes.
       
  1872         TRAPD(err, iIdler = CIdle::NewL(CActive::EPriorityHigh))
       
  1873         if (!err)
       
  1874             {
       
  1875             iIdler->Start(TCallBack(StartNotifierAppServer, this));
       
  1876             }
       
  1877         }
       
  1878      else
       
  1879         { 
       
  1880         // Last notifier app server is being launched, free starter.
       
  1881         if (!iAknCapServerMessage.IsNull())
       
  1882             {
       
  1883             iAknCapServerMessage.Complete(KErrNone);
       
  1884             }
       
  1885         }
       
  1886         
       
  1887     // Return uid of topmost.
       
  1888     return TUid::Uid(uid);  
       
  1889     }
       
  1890     
       
  1891 void CEikServAppUi::UpdateCursorsL() 
       
  1892     {
       
  1893     LoadBitmapCursorsL();
       
  1894     }
       
  1895 
       
  1896 TInt DoPollCapServer(TAny* appui)
       
  1897     {
       
  1898     _LIT(KServerNameFormat, "%08x_%08x_AppServer");
       
  1899     TFullName serverName;
       
  1900     serverName.Format(KServerNameFormat, KUikonUidPluginInterfaceNotifiers, KAknCapServerUid.iUid);
       
  1901     TFindServer find(serverName);
       
  1902     TFullName fullName;
       
  1903     ((CEikServAppUi*)appui)->AknCapServerStartupComplete(find.Next(fullName) == KErrNone);
       
  1904     return KErrNone;
       
  1905     }
       
  1906 
       
  1907 // We are doing this on startup when there is always enough memory, so methods with L really 
       
  1908 // can't leave.
       
  1909 void CEikServAppUi::AknCapServerStartupComplete(TBool aComplete)
       
  1910     {
       
  1911     delete iIdler;
       
  1912     iIdler = 0;
       
  1913 
       
  1914     if (aComplete)
       
  1915         {
       
  1916         // In this phase of boot, create real connection to akncapserver.
       
  1917         iAknCapServerClient.DoEikonServerConnect();           
       
  1918         
       
  1919         // Create alarm server as we have capserver running.
       
  1920         TRAPD(err, DoAlarmServerStartupL());
       
  1921         
       
  1922         // No use to startup phone if this fails.
       
  1923         __ASSERT_ALWAYS(!err, User::Invariant()); 
       
  1924         
       
  1925         iIdler = CIdle::NewL(CActive::EPriorityHigh);
       
  1926         iIdler->Start(TCallBack(StartNotifierAppServer, this));
       
  1927         }
       
  1928     else
       
  1929         {
       
  1930         const TInt waitDelay = 200000;  // 0.2 seconds
       
  1931         User::After(waitDelay);
       
  1932         DoAknCapServerStartupCompleteL();
       
  1933         }
       
  1934     }
       
  1935 
       
  1936 void CEikServAppUi::DoAknCapServerStartupCompleteL()
       
  1937     {
       
  1938     __ASSERT_DEBUG(iIdler == 0, User::Invariant());
       
  1939 
       
  1940     iIdler = CIdle::NewL(CActive::EPriorityIdle);
       
  1941     iIdler->Start(TCallBack(DoPollCapServer, this));
       
  1942     }
       
  1943     
       
  1944 void CEikServAppUi::DoSignalWhenAknServerReady(const RMessagePtr2& aMessage)
       
  1945     {
       
  1946     if (iAknCapServerClient.Handle() != 0)
       
  1947         {
       
  1948         aMessage.Complete(KErrNone);
       
  1949         }
       
  1950         
       
  1951     // This should be used as single shot.
       
  1952     __ASSERT_DEBUG(iAknCapServerMessage.IsNull(), User::Invariant());   
       
  1953     iAknCapServerMessage = aMessage;
       
  1954     }
       
  1955 
       
  1956 void CEikServAppUi::DoAlarmServerStartupL()
       
  1957     {
       
  1958     // Stupid naming, perhaps.
       
  1959     iAlarmAlertServer = CEikServAlarmAlertServer::NewL(this);
       
  1960 
       
  1961     // Start AlarmServer.
       
  1962     TInt err = AlarmClientUtils::StartAlarmServer();
       
  1963     if (err != KErrNone && err != KErrAlreadyExists)
       
  1964         {
       
  1965         User::Leave(err);
       
  1966         }
       
  1967 
       
  1968     HandleSwitchOnEventL( NULL );    
       
  1969     }
       
  1970 
       
  1971 // End of file