uifw/AknGlobalUI/AknCapServer/src/AknCapServerEntry.cpp
changeset 0 2f259fa3e83a
child 4 8ca85d2f0db7
child 26 62ef28f7b435
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    19 #include <uikon/eikdefconst.h>
       
    20 #include <uikon/eikenvinterface.h>
       
    21 #endif
       
    22 #include <eikstart.h>
       
    23 #include <AknDef.h>
       
    24 #include <barsread.h>
       
    25 #include <bautils.h>
       
    26 #include <e32std.h>
       
    27 #include <e32property.h>
       
    28 #include <UikonInternalPSKeys.h>     // KUikLayoutState, KPSUidUikon, KUikAppHiddenList
       
    29 #include <AknFepInternalCRKeys.h>    // KAknFepHashKeySelection, KAknFepEditTextSubmenu
       
    30 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
    31 #include <AknFepInternalPSKeys.h>    // KAknFepFnKeyState
       
    32 #endif
       
    33 #include "avkoninternalpskeys.h"     // KAknIdleAppWindowGroupId
       
    34 #include <AknCapServerDefs.h>
       
    35 #include <activeidle2domainpskeys.h>
       
    36 #include <eikpriv.rsg>
       
    37 #include <coedef.h>
       
    38 #include <eiksvdef.h>
       
    39 #include <aknconsts.h>
       
    40 #include <AknsConstants.h>
       
    41 #include <apgwgnam.h>
       
    42 
       
    43 #include "AknCapServerDefs.h"
       
    44 #include "AknCapServerEntry.h"
       
    45 #include "AknCapServer.h"
       
    46 #include "AknFastswapWindowControl.h"
       
    47 #include "AknMemoryCardDialogImpl.h"
       
    48 #include "oommonitor.h"
       
    49 #include "AknKeyFilter.h"
       
    50 #include <AknWsEventObserver.h>
       
    51 
       
    52 #include <PtiEngine.h>
       
    53 #include <PtiKeyMappings.h>
       
    54 #include <PtiDefs.h>
       
    55 
       
    56 // For Gs to initiate OFN status
       
    57 #include <settingsinternalcrkeys.h>
       
    58 
       
    59 #include <aknenv.h>
       
    60 #include <AknSettingCache.h>
       
    61 #include <eikspane.h>
       
    62 #include "aknstatuspanedatapublisher.h"
       
    63 
       
    64 #include <syslangutil.h> // SysLangUtil::GetInstalledLanguages
       
    65 #include <featmgr.h>
       
    66 #include <centralrepository.h>
       
    67 #include "aknmessagereaderlongpressdetector.h" // MAknMessageReaderLongPressDetector
       
    68 
       
    69 #include <akncapserveralternatefsplugin.h>
       
    70 #include <akncapserveralternatefspluginconst.hrh>
       
    71 
       
    72 #ifdef RD_UI_TRANSITION_EFFECTS_LAYOUT_SWITCH
       
    73     #include <gfxtranseffect/gfxtranseffect.h>
       
    74     #include <akntranseffect.h> // for Transition effect enumerations
       
    75 #endif
       
    76 
       
    77 #ifdef SYMBIAN_BUILD_GCE
       
    78     #include <alf/alfclientbase.h>
       
    79 #endif    
       
    80 
       
    81 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
    82 #include <AvkonInternalCRKeys.h>
       
    83 
       
    84 #include "akncapserverdiscreetpopuphandler.h"
       
    85 
       
    86 const TUid KPtiEnginePSUid = {0x101F8610}; // Same as PtiEngine dll
       
    87 
       
    88 enum TPtiEnginePSKeys
       
    89     {
       
    90     EKeyMapPropertyCount,
       
    91     EKeyMapPropertyData,
       
    92     EKeyMapPropertyCount2,
       
    93     EKeyMapPropertyData2,    
       
    94     EKeyMapPropertyCount3,
       
    95     EKeyMapPropertyData3        
       
    96     };
       
    97 
       
    98  // Read capability: AlwaysPass.
       
    99 _LIT_SECURITY_POLICY_PASS( KCapServerPtiEngineAlwaysPass );    
       
   100 _LIT_SECURITY_POLICY_S1( KCapServerPtiEngineWritePolicy, 0x10207218, ECapabilityWriteDeviceData);  
       
   101 #endif
       
   102 
       
   103 // External keyboard modifier
       
   104 const TUint KModifierExternalKeyboard = 0x00200000;
       
   105 
       
   106 const TInt KWgPriorityCoverEverything = 10000;
       
   107 const TInt KKeyEventICodeThreshold = 0x001f;
       
   108 const TInt KMaxLanguageCodeLength = 6; // 5 digits + separator
       
   109 
       
   110                 
       
   111 
       
   112 _LIT(KEikSrvUIResFileName, "z:\\resource\\eiksrvui.rsc");
       
   113 _LIT_SECURITY_POLICY_PASS(KPassReadPolicy);
       
   114 _LIT_SECURITY_POLICY_C1(KWriteDDPolicy, ECapabilityWriteDeviceData);
       
   115 _LIT_SECURITY_POLICY_C1(KReadPolicy,    ECapability_None);
       
   116 _LIT( KSeparator, " " );
       
   117 
       
   118 CAknCapServerApplication::CAknCapServerApplication()
       
   119     {
       
   120     }
       
   121 
       
   122 void CAknCapServerApplication::NewAppServerL(CApaAppServer*& aAppServer)
       
   123     {
       
   124     CAknCapServer* server = new (ELeave) CAknCapServer();
       
   125     
       
   126     CleanupStack::PushL(server);
       
   127     server->CreateDynamicSoftNoteEventManagerL();
       
   128     CleanupStack::Pop(server);    
       
   129     
       
   130     server->SetPriority(EActivePriorityIpcEventsHigh);
       
   131     aAppServer=&*server;
       
   132     iCapServer = server;
       
   133     }
       
   134     
       
   135 CApaDocument* CAknCapServerApplication::CreateDocumentL()
       
   136     {
       
   137     return new (ELeave) CAknCapAppServerDocument(*this);
       
   138     }
       
   139 
       
   140 CEikAppUi* CAknCapAppServerDocument::CreateAppUiL()
       
   141     {
       
   142     CAknCapServerApplication* app = static_cast<CAknCapServerApplication*>(iApp);
       
   143     CAknCapServer* server = app->CapServer();
       
   144     CAknCapAppServerAppUi* ret = new (ELeave) CAknCapAppServerAppUi( server );
       
   145     return ret;
       
   146     }
       
   147 
       
   148 CAknCapAppServerAppUi::CAknCapAppServerAppUi( CAknCapServer* aCapServer ) : iCapServer( aCapServer )
       
   149     {
       
   150     iIdleActive = ETrue;
       
   151     }
       
   152     
       
   153 CAknCapAppServerAppUi::~CAknCapAppServerAppUi()
       
   154     {
       
   155     delete iAlternateFS;
       
   156     delete iTelephonyIdleUidSubscriber;
       
   157     delete iGlobalNotesAllowedSubscriber;
       
   158     
       
   159     if (iKeyCaptureControl)
       
   160         {
       
   161         RemoveFromStack(iKeyCaptureControl);   // ownership in stack 
       
   162         }
       
   163         
       
   164     delete iFSControl;
       
   165     
       
   166     if (iResourceFileOffset)
       
   167         {
       
   168         iCoeEnv->DeleteResourceFile(iResourceFileOffset);   
       
   169         }
       
   170     
       
   171     delete iHiddenList;
       
   172     delete iMMCUnlock;
       
   173     delete iIdler;
       
   174     iEikSrv.Close(); // this shouldn't be connected here anyway
       
   175     delete iPtiEngine;          
       
   176     }
       
   177 
       
   178 _LIT(KProductSpecificHalFile, "z:\\system\\data\\ProductSpecificHalParams.txt");
       
   179 
       
   180 void DoProductSpecificHalFunction()
       
   181     {
       
   182     RFs& fs = CCoeEnv::Static()->FsSession();
       
   183     RFile file;
       
   184     if (fs.Handle() && file.Open(fs,KProductSpecificHalFile, EFileRead)==KErrNone)
       
   185         {
       
   186         TBuf8<30> desc;
       
   187         file.Read(desc);
       
   188         TLex8 lex(desc);
       
   189         TInt i[4];
       
   190         TInt ii = 0;
       
   191         for (;ii < 4; ii++)
       
   192             {
       
   193             if (lex.Val(i[ii]))
       
   194                 {
       
   195                 ii = KErrArgument;
       
   196                 break;
       
   197                 }
       
   198             lex.SkipSpace();
       
   199             }
       
   200         if (ii != KErrArgument)
       
   201             {
       
   202             UserSvr::HalFunction(i[0], i[1], &i[2], &i[3]);         
       
   203             }
       
   204         file.Close();
       
   205         }
       
   206     }
       
   207 
       
   208 TInt StartOOM(TAny* aThis)
       
   209     {
       
   210     // By running idle priority active object twice, we allow idle priority objects
       
   211     // scheduled after AppUi::ConstructL() run at least once.
       
   212     CAknCapAppServerAppUi* me = (CAknCapAppServerAppUi*)aThis;
       
   213     if (!me->iHasRunOnce)
       
   214         {
       
   215         DoProductSpecificHalFunction();
       
   216         
       
   217         me->iHasRunOnce = ETrue;        
       
   218         me->iIdler->Start(TCallBack(StartOOM, aThis));
       
   219         return KErrNone;
       
   220         }
       
   221     
       
   222     // free resources of idler
       
   223     delete me->iIdler;
       
   224     me->iIdler = 0;
       
   225     
       
   226     // do the actual startup
       
   227     TRAPD( err, CreateOOMWatcherThreadL());
       
   228     // we panic here if something goes wrong as startup will fail anyway.
       
   229     __ASSERT_ALWAYS(err==KErrNone, User::Invariant());
       
   230 
       
   231     me->iEikSrv.AllowNotifierAppServersToLoad();
       
   232     me->iEikSrv.Close(); // currently there is no use to keep this session alive.
       
   233     
       
   234 #ifdef SYMBIAN_BUILD_GCE
       
   235     TRAP(err, CAlfAsynchStartup::StartL());
       
   236 #endif     
       
   237     
       
   238     return err;
       
   239     }
       
   240 
       
   241 void CAknCapAppServerAppUi::LoadAlternateFsPlugin()
       
   242     {
       
   243     // List all plugins
       
   244     RImplInfoPtrArray implInfoArray;
       
   245     TRAPD( error, REComSession::ListImplementationsL(
       
   246         TUid::Uid( KAknCapServerAlternateFsPluginInterfaceUid ), implInfoArray ) );
       
   247     
       
   248     if ( error == KErrNone && implInfoArray.Count() )
       
   249         {
       
   250         TUid uid = implInfoArray[0]->ImplementationUid();
       
   251         TRAP_IGNORE( iAlternateFS = CAknCapAppServerAlternateFs::NewL( uid ) );
       
   252         }
       
   253     
       
   254     implInfoArray.ResetAndDestroy();
       
   255     }
       
   256 
       
   257 void CAknCapAppServerAppUi::ShowOrDismissAlternateFs()
       
   258     {
       
   259     if ( !iAlternateFS )
       
   260         {
       
   261         return;
       
   262         }
       
   263     
       
   264     if ( iAlternateFS->IsVisible() )
       
   265         {
       
   266         iAlternateFS->HandleLongAppKeyPress();
       
   267         }
       
   268     else
       
   269         {
       
   270         iAlternateFS->Show();
       
   271         }
       
   272     }
       
   273 
       
   274 void CAknCapAppServerAppUi::ConstructL()
       
   275     {
       
   276     User::SetCritical(User::ESystemCritical);
       
   277 
       
   278     InitiateOFNStatus();
       
   279 
       
   280     // install default FEP if none set before
       
   281     if (iEikonEnv->FepUid() == KNullUid)
       
   282         {
       
   283         iEikonEnv->InstallFepL(TUid::Uid(0x101FD65A));
       
   284         }
       
   285     
       
   286     // define and set the PS key listing installed languages
       
   287     PublishInstalledLanguagesL();
       
   288 
       
   289     TInt value = 1;
       
   290     if ( FeatureManager::FeatureSupported( KFeatureIdEditKey ) )
       
   291         {
       
   292         // The edit key exists in the device. Hash-key selection disabled and
       
   293         // edit text sub-menu removed from the options menu
       
   294         value = 0;
       
   295         }
       
   296     CRepository* repository = CRepository::NewL(KCRUidAknFep);
       
   297     // Return value of repository->Set() ignored.
       
   298     repository->Set(KAknFepHashKeySelection, value);
       
   299     repository->Set(KAknFepEditTextSubmenu, value);
       
   300     delete repository;
       
   301     repository = NULL;
       
   302     
       
   303     // kick eikon server in (in case it is not running yet)
       
   304     TInt error = iEikSrv.Connect();
       
   305     __ASSERT_ALWAYS(error == KErrNone, User::Invariant());
       
   306     
       
   307     // base call
       
   308     CAknNotifierAppServerAppUi::ConstructL();
       
   309 
       
   310     RWsSession& wsSession=iEikonEnv->WsSession();
       
   311     iBackdropWindowGroup=RWindowGroup(wsSession);
       
   312     User::LeaveIfError(iBackdropWindowGroup.Construct((TUint32)&iBackdropWindowGroup, EFalse));
       
   313     iBackdropWindowGroup.AutoForeground(EFalse);
       
   314     
       
   315     CApaWindowGroupName* apaName = 
       
   316         CApaWindowGroupName::NewLC(wsSession, (TUint32)&iBackdropWindowGroup);
       
   317         
       
   318     apaName->SetHidden(ETrue);
       
   319     apaName->SetSystem(ETrue); 
       
   320 
       
   321     apaName->SetCaptionL(EIKON_SERVER_BACKDROP_WINDOW_GROUP_NAME);
       
   322     User::LeaveIfError(apaName->SetWindowGroupName(iBackdropWindowGroup));
       
   323     CleanupStack::PopAndDestroy(); //apaName
       
   324     iBackdropWindowGroup.SetOrdinalPosition(1, ECoeWinPriorityNormal);
       
   325 
       
   326     // to make sure that wserv does not change our priority even we lose foreground
       
   327     wsSession.ComputeMode(RWsSession::EPriorityControlDisabled);
       
   328 
       
   329     wsSession.SetDoubleClick(KTimeBetweenClicks,KDoubleClickDistance);
       
   330     
       
   331     // AKNLAF
       
   332     wsSession.SetKeyboardRepeatRate(KAknKeyboardRepeatInitialDelay, KAknStandardKeyboardRepeatRate); 
       
   333  
       
   334     // Disable some of wserv hotkeys if not in RnD mode.
       
   335     if (!BaflUtils::FileExists( iEikonEnv->FsSession(), KRDSupport ))
       
   336         {
       
   337         User::LeaveIfError(wsSession.ClearHotKeys(EHotKeyOfDeath));
       
   338         // Symbian already protects this in urel mode, but just to play it safe  
       
   339         User::LeaveIfError(wsSession.ClearHotKeys(EHotKeyShutDown)); 
       
   340         User::LeaveIfError(wsSession.ClearHotKeys(EHotKeyOff));       
       
   341         }
       
   342 
       
   343     // Create statuspane & SGcs
       
   344     if (iEikonEnv->StatusPaneCoreResId())
       
   345         {
       
   346         iStatusPane = CEikServStatusPane::NewL(
       
   347             *iEikonEnv, 
       
   348             &iBackdropWindowGroup, 
       
   349             iEikonEnv->StatusPaneCoreResId());
       
   350         }
       
   351 
       
   352     iSgcs = CEikSgcServer::NewL();
       
   353     iSgcs->SetStatusPane(iStatusPane);
       
   354     iSgcs->SetAknCapAppServerAppUi(this);
       
   355     
       
   356     RWindowGroup& rootWin = iCoeEnv->RootWin();
       
   357     rootWin.EnableGroupListChangeEvents();
       
   358     rootWin.EnableScreenChangeEvents();
       
   359     rootWin.EnableFocusChangeEvents (); // For cover UI/status pane refresh problems
       
   360 
       
   361     iSgcs->HandleWindowGroupParamChangeL(rootWin.Identifier(), EFalse, 0, 0, KAknScreenModeUnset);
       
   362 
       
   363     // create a high priority key filter
       
   364     // i.e. capture Apps-Key
       
   365     iKeyCaptureControl=new(ELeave) CAknServKeyFilter();
       
   366     iKeyCaptureControl->ConstructL(*this);
       
   367 
       
   368     TFileName fileName(KEikSrvUIResFileName);
       
   369     BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(),fileName);
       
   370     iResourceFileOffset=iCoeEnv->AddResourceFileL(fileName);
       
   371 
       
   372     // Create FSW
       
   373     iFSControl= new (ELeave) CAknFastSwapWindowControl(*this);
       
   374     iFSControl->ConstructL();
       
   375     
       
   376     // MMC unlocker
       
   377     iMMCUnlock = CAknMMCPasswordRequester::NewL();
       
   378     
       
   379     // Boost our priority similar to eikon server.
       
   380     RThread thread; 
       
   381 #if defined(__EPOC32__)
       
   382     thread.SetProcessPriority(EPriorityHigh);
       
   383 #else
       
   384     thread.SetPriority(EPriorityAbsoluteForeground);
       
   385 #endif
       
   386 
       
   387     // Start OOM watcher thread when scheduler is running
       
   388     // effectively this frees eikon server thread also.
       
   389     iIdler = CIdle::NewL(CActive::EPriorityIdle);
       
   390     iIdler->Start(TCallBack(StartOOM, this));
       
   391     SetAliasKeyCodeResolverL(this);       
       
   392     
       
   393     // Define the property for Idle application window group id. This cannot be done in AknIcon,
       
   394     // because the property is internal in classicui domain.
       
   395     TInt err = RProperty::Define(
       
   396         KPSUidAvkonInternal, 
       
   397         KAknIdleAppWindowGroupId, 
       
   398         RProperty::EInt, 
       
   399         KPassReadPolicy,  // None
       
   400         KWriteDDPolicy);  // WriteDeviceData
       
   401         
       
   402     if (err != KErrAlreadyExists)
       
   403         {
       
   404         User::LeaveIfError(err);
       
   405         }
       
   406         
       
   407     // Define a PubSub key indicate menu option has the task swapper item or not
       
   408     err =  RProperty::Define(
       
   409     KPSUidAvkonInternal, 
       
   410     KAknMenuOptionNoTaskSwapper, 
       
   411     RProperty::EInt); 
       
   412                
       
   413     if ( err != KErrNone && err != KErrAlreadyExists )
       
   414          {
       
   415          User::LeaveIfError( err );
       
   416          } 
       
   417 #ifdef RD_INTELLIGENT_TEXT_INPUT        
       
   418     // Define the property for Idle application window group id. This cannot be done in AknIcon,
       
   419     // because the property is internal in classicui domain.
       
   420     err = RProperty::Define(
       
   421         KPSUidAknFep, 
       
   422         KAknFepFnKeyState, 
       
   423         RProperty::EInt, 
       
   424         KPassReadPolicy,  // None
       
   425         KWriteDDPolicy);  // WriteDeviceData
       
   426         
       
   427     if (err != KErrAlreadyExists)
       
   428         {
       
   429         User::LeaveIfError(err);
       
   430         }
       
   431 #endif
       
   432     
       
   433     // Start listening "global notes allowed" property. When global notes are allowed,
       
   434     // we know that the boot is finished and the Idle app window group id can be fetched.       
       
   435     User::LeaveIfError(iGlobalNotesAllowedProperty.Attach(
       
   436         KPSUidUikon, 
       
   437         KUikGlobalNotesAllowed));        
       
   438 
       
   439     iGlobalNotesAllowedSubscriber = new (ELeave) CPropertySubscriber(
       
   440         TCallBack(GlobalNotesAllowedCallBack, this), 
       
   441         iGlobalNotesAllowedProperty);
       
   442 
       
   443     iGlobalNotesAllowedSubscriber->Subscribe();
       
   444     
       
   445     // Start listening "telephony idle uid" property.
       
   446     User::LeaveIfError(iTelephonyIdleUidProperty.Attach(
       
   447         KPSUidAiInformation, 
       
   448         KActiveIdleUid));
       
   449 
       
   450     iTelephonyIdleUidSubscriber = new (ELeave) CPropertySubscriber(
       
   451         TCallBack(TelephonyIdleUidCallBack, this), 
       
   452         iTelephonyIdleUidProperty);
       
   453 
       
   454     iTelephonyIdleUidSubscriber->Subscribe();    
       
   455 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   456          
       
   457     TInt err1 = 0;         
       
   458                                          
       
   459     err1 = RProperty::Define(KPtiEnginePSUid, EKeyMapPropertyCount, RProperty::EInt,
       
   460                             KCapServerPtiEngineAlwaysPass, KCapServerPtiEngineWritePolicy);
       
   461     err1 |= RProperty::Set(KPtiEnginePSUid, EKeyMapPropertyCount, 0);    
       
   462     err1 |= RProperty::Define(KPtiEnginePSUid, EKeyMapPropertyData, RProperty::EByteArray,    
       
   463                             KCapServerPtiEngineAlwaysPass, KCapServerPtiEngineWritePolicy);
       
   464                             
       
   465     err1 |= RProperty::Define(KPtiEnginePSUid, EKeyMapPropertyData2, RProperty::EByteArray,
       
   466                              KCapServerPtiEngineAlwaysPass, KCapServerPtiEngineWritePolicy);                                           
       
   467     err1 |= RProperty::Define(KPtiEnginePSUid, EKeyMapPropertyCount2, RProperty::EInt,
       
   468                             KCapServerPtiEngineAlwaysPass, KCapServerPtiEngineWritePolicy);
       
   469     err1 |= RProperty::Set(KPtiEnginePSUid, EKeyMapPropertyCount2, 0);      
       
   470     
       
   471     err1 |= RProperty::Define(KPtiEnginePSUid, EKeyMapPropertyData3, RProperty::EByteArray,
       
   472                              KCapServerPtiEngineAlwaysPass, KCapServerPtiEngineWritePolicy);                                           
       
   473     err1 |= RProperty::Define(KPtiEnginePSUid, EKeyMapPropertyCount3, RProperty::EInt,
       
   474                             KCapServerPtiEngineAlwaysPass, KCapServerPtiEngineWritePolicy);
       
   475     err1 |= RProperty::Set(KPtiEnginePSUid, EKeyMapPropertyCount3, 0);   
       
   476     
       
   477    // Create ptiengine instance for key code resolver.
       
   478 	if (err1 == KErrNone && !iPtiEngine)
       
   479    		{   		
       
   480    		// create PtiEngine already here because only cap server process has write rights to
       
   481    		// above properties and several PtiEngine cores want to cache language
       
   482    		// bindings to those properties.
       
   483 		TRAP_IGNORE(iPtiEngine = CPtiEngine::NewL(ETrue));
       
   484 	 	}           
       
   485 #endif
       
   486 
       
   487     // Create capserver discreetpopuphandler     
       
   488     CAknCapServerDiscreetPopupHandler::CreateDiscreetPopupHandlerL();     
       
   489 	LoadAlternateFsPlugin();
       
   490 
       
   491 	ProcessInitFlipStatus();
       
   492     }
       
   493     
       
   494 TKeyResponse CAknCapAppServerAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   495     {
       
   496     return CAknNotifierAppServerAppUi::HandleKeyEventL(aKeyEvent, aType);
       
   497     }
       
   498 
       
   499 // This must not leave if aAddCount == 0.
       
   500 void CAknCapAppServerAppUi::SuppressAppSwitchingL(TInt aAddCount, TInt aClientId)
       
   501     {
       
   502     TInt index = KErrNotFound;
       
   503     for (TInt ii=0;ii<iAppsKeyArray.Count();ii++)
       
   504         {
       
   505         if (iAppsKeyArray[ii].iUid == aClientId)
       
   506             {
       
   507             index = ii;
       
   508             }
       
   509         }
       
   510     
       
   511     if (aAddCount == EAknAppsKeyBlockRemoveClient && aClientId) // client is exiting
       
   512         {
       
   513         if (index != KErrNotFound)
       
   514             {
       
   515             iAppsKeyArray.Remove(index);
       
   516             }
       
   517         return;
       
   518         }
       
   519         
       
   520     // create client entry (did not previosly exist)
       
   521     if (index == KErrNotFound)
       
   522         {
       
   523         __ASSERT_DEBUG(aAddCount == EAknAppsKeyBlockAddCount, User::Invariant());
       
   524         SSuppressInfo info = SSuppressInfo(aClientId);
       
   525         User::LeaveIfError(iAppsKeyArray.Insert(info,0));
       
   526         index = 0;
       
   527         }
       
   528     // Add aAddcount to client data
       
   529     iAppsKeyArray[index].iReferenceCount += aAddCount;
       
   530     if ( IsAppsKeySuppressed() )
       
   531         {
       
   532         TInt err = RProperty::Set(
       
   533         KPSUidAvkonInternal, 
       
   534         KAknMenuOptionNoTaskSwapper, ENoTaskSwapper );
       
   535         if ( err!=KErrNone )
       
   536             {
       
   537             User::LeaveIfError( err );
       
   538             }    
       
   539         }
       
   540     else
       
   541         {
       
   542         TInt err = RProperty::Set(
       
   543         KPSUidAvkonInternal, 
       
   544         KAknMenuOptionNoTaskSwapper, ETaskSwapper );
       
   545         if ( err!=KErrNone )
       
   546             {
       
   547             User::LeaveIfError( err );
       
   548             }
       
   549         }    
       
   550     }
       
   551     
       
   552 void CAknCapAppServerAppUi::KillAppL(const RMessage2& aMessage)
       
   553     {
       
   554     aMessage.Complete(KErrNotSupported);
       
   555     }
       
   556     
       
   557 void CAknCapAppServerAppUi::DoTaskListCommandL(const RMessage2& aMessage)        
       
   558     {
       
   559     switch (aMessage.Function())
       
   560         {
       
   561         case EAknSEnableTaskList:
       
   562             {
       
   563             TInt err = EnableTaskList(aMessage.Int0());
       
   564             aMessage.Complete(err);
       
   565             break;
       
   566             }
       
   567         case EAknsLaunchTaskList:
       
   568             {
       
   569             if (iTaskListEnabled)
       
   570                 {
       
   571                 if ( iAlternateFS && iAlternateFS->IsReady() )
       
   572                     {
       
   573                     if ( aMessage.Int0() )
       
   574                         {
       
   575                         iAlternateFS->Show();
       
   576                         }
       
   577                     else
       
   578                         {
       
   579                         iAlternateFS->Dismiss();
       
   580                         }                         
       
   581                     }
       
   582                 else
       
   583                     {
       
   584                     if ( aMessage.Int0() )
       
   585                         {
       
   586                         TInt err = KErrNone;
       
   587                         TRAP( err, iFSControl->InitializeWindowGroupListL( EFalse ));
       
   588                         if ( !err )
       
   589                             {   
       
   590                             iFSControl->RunFastSwapL();             
       
   591                             }
       
   592                         }
       
   593                     else
       
   594                         {
       
   595                         iFSControl->CloseFastSwap();
       
   596                         }                        
       
   597                     }
       
   598                 }
       
   599             aMessage.Complete(KErrNone);
       
   600             break;
       
   601             }
       
   602         case EAknSRefreshTaskList:
       
   603             {
       
   604             TInt err = UpdateTaskListL( ETrue );
       
   605             if ( err != KErrNone )
       
   606                 {
       
   607                 iFSControl->CloseFastSwap();
       
   608                 }
       
   609             aMessage.Complete(err);
       
   610             break;
       
   611             }
       
   612         default:
       
   613             {
       
   614             aMessage.Complete(KErrNotSupported);
       
   615             break;          
       
   616             }
       
   617         }
       
   618     }
       
   619 
       
   620 TBool CAknCapAppServerAppUi::IsAppsKeySuppressed()
       
   621     {
       
   622     if (!iTaskListEnabled)
       
   623         {
       
   624         return ETrue;
       
   625         }
       
   626     
       
   627     for(TInt ii = 0; ii < iAppsKeyArray.Count(); ii++)
       
   628         {
       
   629         if (iAppsKeyArray[ii].iReferenceCount)
       
   630             {
       
   631             return ETrue;
       
   632             }
       
   633         }
       
   634     return EFalse;
       
   635     }
       
   636     
       
   637 void CAknCapAppServerAppUi::HideApplicationFromFswL(TInt aUid,TBool aDisable)
       
   638     {
       
   639     if (!iHiddenList)
       
   640         {
       
   641         iHiddenList = new (ELeave) CArrayFixFlat<TInt>(1); // This won't grow very big I hope
       
   642         // the appui server reserves a property where it stores the hidden list.
       
   643         RProperty::Define(KPSUidUikon, KUikAppHiddenList, RProperty::ELargeByteArray);
       
   644         }
       
   645     TBool foundUid( EFalse );
       
   646     
       
   647     for (TInt i = 0; i < iHiddenList->Count(); i++)
       
   648         {
       
   649         if (aUid == iHiddenList->At(i))
       
   650             {
       
   651             iHiddenList->Delete(i);
       
   652             foundUid = ETrue;
       
   653             break;
       
   654             }
       
   655         }
       
   656 
       
   657     if (aDisable)
       
   658         {
       
   659         iHiddenList->AppendL(aUid);
       
   660         // visible uid hidden -> refresh tasklist
       
   661         if ( !foundUid )
       
   662             {
       
   663             UpdateTaskListL( ETrue );
       
   664             }
       
   665         }
       
   666     else 
       
   667         {
       
   668         // hidden uid set to visible -> refresh tasklist
       
   669         if ( foundUid )
       
   670             {
       
   671             UpdateTaskListL( ETrue );
       
   672             }
       
   673         }
       
   674         
       
   675     // when the hidden list is ready it get's published to P&S service 
       
   676     PublishHiddenList();    
       
   677     }
       
   678 
       
   679 void CAknCapAppServerAppUi::ProcessInitFlipStatus()
       
   680     {
       
   681     // we remove the definition from hal_switch.h
       
   682     enum
       
   683         {
       
   684         ECoverSwitch,
       
   685         EHalGroupSwitch = 29
       
   686         };
       
   687 
       
   688 		const TInt KFeatureIdFfSliderLandscapeStartsApp_LocalDefinition = 5126; //we have to define it here because of some header exporting problem
       
   689     if (FeatureManager::FeatureSupported(KFeatureIdFfSliderLandscapeStartsApp_LocalDefinition))
       
   690         {
       
   691         // check the state of phone slide, if it is open during startup, 
       
   692         // we enable the landscape orientation
       
   693         TBool flipStatus(EFalse); // flipStatus true : flip open / false : flip close
       
   694         TInt err = UserSvr::HalFunction(EHalGroupSwitch, ECoverSwitch, &flipStatus, reinterpret_cast<TAny*>(EFalse));
       
   695         if (KErrNone == err && flipStatus)
       
   696             {
       
   697             TRAP_IGNORE(RotateScreenL());
       
   698             }
       
   699         }
       
   700     }
       
   701 
       
   702 // For Gs to initiate OFN status
       
   703 void CAknCapAppServerAppUi::InitiateOFNStatus()
       
   704     {
       
   705     // For Gs to initiate OFN status
       
   706     enum TFidOFNFunctionForGs
       
   707         {
       
   708         EOFNSetPowerON,     // OFN Powering (ON/OFF)
       
   709         EHalGroupOFN = 28
       
   710         };
       
   711 
       
   712     const TInt KFeatureId_Ff_Ofn_Feature = 193;
       
   713     const TInt KSettingsOptical_Joystick_Status = 0x00000019;
       
   714     
       
   715     // For Gs to initiate OFN status
       
   716     if( FeatureManager::FeatureSupported( KFeatureId_Ff_Ofn_Feature ) )
       
   717         {
       
   718         CRepository* personalizationRepository = NULL;
       
   719         TRAPD( errCode, personalizationRepository = CRepository::NewL( KCRUidPersonalizationSettings ) );
       
   720         if (errCode == KErrNone)
       
   721             {
       
   722             TInt ofnStatus = 0;
       
   723             personalizationRepository->Get( KSettingsOptical_Joystick_Status, ofnStatus );
       
   724             delete personalizationRepository;
       
   725             
       
   726             UserSvr::HalFunction( EHalGroupOFN, EOFNSetPowerON, reinterpret_cast<TAny*>( ofnStatus ), 
       
   727                                 reinterpret_cast<TAny*>( ofnStatus ) );
       
   728             }
       
   729 	    }
       
   730     }
       
   731 
       
   732 void CAknCapAppServerAppUi::PublishHiddenList()
       
   733     {
       
   734     // 1. the creation of hidden list array
       
   735     TBuf16 <2*KMaxHiddenApps> hiddenList;
       
   736     TInt i;
       
   737     TUint16 upperBits;
       
   738     // the limit of hidden application uids
       
   739     TInt hiddenCount = ( iHiddenList->Count() > KMaxHiddenApps ) ? 
       
   740         KMaxHiddenApps : iHiddenList->Count();
       
   741     
       
   742     for ( i = 0; i < hiddenCount; i++)                
       
   743         {
       
   744         // 32-bit integer is appended in two parst to 16-bit buffer 
       
   745         upperBits = iHiddenList->At(i) >> 16;
       
   746         hiddenList.Append( upperBits );
       
   747         // upper values are automatically truncated
       
   748         hiddenList.Append( iHiddenList->At(i) );
       
   749         }
       
   750         
       
   751     // the end of hidden list is marked null (0x00000000)
       
   752     if ( i < KMaxHiddenApps )
       
   753         {
       
   754         hiddenList.Append( 0x0000 );
       
   755         hiddenList.Append( 0x0000 );
       
   756         }
       
   757         
       
   758     // 2. setting the property value 
       
   759     RProperty::Set(KPSUidUikon, KUikAppHiddenList, hiddenList);
       
   760     }
       
   761 
       
   762 TBool CAknCapAppServerAppUi::HiddenFromFSW( TInt aUid )
       
   763     {
       
   764     if ( iHiddenList )
       
   765         {
       
   766         for ( TInt i = 0; i < iHiddenList->Count(); i++)
       
   767             {
       
   768             if (aUid == iHiddenList->At(i))
       
   769                 {
       
   770                 return ETrue;
       
   771                 }
       
   772             }
       
   773         }
       
   774 
       
   775     return EFalse;
       
   776     }
       
   777 
       
   778 TInt CAknCapAppServerAppUi::EnableTaskList(TBool aEnable)
       
   779     {
       
   780     TInt err = KErrNone;
       
   781     
       
   782     iTaskListEnabled = aEnable;
       
   783        
       
   784     if ( IsAppsKeySuppressed() )
       
   785         {
       
   786         err = RProperty::Set(KPSUidAvkonInternal, KAknMenuOptionNoTaskSwapper, ENoTaskSwapper);    
       
   787         }
       
   788     else
       
   789         {
       
   790         err = RProperty::Set(KPSUidAvkonInternal, KAknMenuOptionNoTaskSwapper, ETaskSwapper);
       
   791         }
       
   792     return err;
       
   793     }
       
   794 
       
   795 TBool CAknCapAppServerAppUi::HandleShortAppsKeyPressL()
       
   796     {
       
   797     if(iAlternateFS && iAlternateFS->IsReady() && iAlternateFS->IsVisible())
       
   798         {
       
   799         iAlternateFS->HandleShortAppKeyPress();
       
   800         return ETrue;
       
   801         }
       
   802     if (iFSControl->IsVisible())
       
   803         {
       
   804         iFSControl->HandleShortAppsKeyPressL();
       
   805         return ETrue;
       
   806         }
       
   807         
       
   808     return EFalse;
       
   809     }
       
   810 
       
   811 TBool CAknCapAppServerAppUi::HandleLongAppsKeyPressL()
       
   812     {
       
   813     if (iTaskListEnabled)
       
   814         {
       
   815         if ( iAlternateFS && iAlternateFS->IsReady() )
       
   816             {        
       
   817             ShowOrDismissAlternateFs();
       
   818             }
       
   819         else
       
   820             {
       
   821             if (iFSControl->IsVisible())
       
   822                 {
       
   823                 iFSControl->HandleLongAppsKeyPressL();
       
   824                 }
       
   825             else
       
   826                 {
       
   827                 if (iFSControl->VisibleWindowGroupsCountL()<1)
       
   828                     {
       
   829                     return EFalse;
       
   830                     }
       
   831                 else
       
   832                     {
       
   833                     iFSControl->RunFastSwapL();
       
   834                     }
       
   835                 }            
       
   836             }
       
   837         }
       
   838     return ETrue;
       
   839     }
       
   840 
       
   841 void CAknCapAppServerAppUi::SetStatusPaneFlags(TInt aFlags)
       
   842     {
       
   843     if (iStatusPane)
       
   844         {
       
   845         iStatusPane->SetFlags(aFlags);
       
   846         }
       
   847     }
       
   848 
       
   849 void CAknCapAppServerAppUi::SetStatusPaneLayoutL(TInt aLayoutResId)
       
   850     {
       
   851     if (iStatusPane)
       
   852         {
       
   853         iStatusPane->SwitchLayoutL(aLayoutResId);
       
   854         }
       
   855     }
       
   856 
       
   857 void CAknCapAppServerAppUi::BlankScreenL(TBool aBlank, TBool aToForeground)
       
   858     {
       
   859     if (aBlank)
       
   860         {
       
   861         if (++iBlankWinRefCount == 1)
       
   862             {
       
   863             ASSERT(!iBlankWin);
       
   864             if (aToForeground)
       
   865                 {
       
   866                 iBackdropWindowGroup.SetOrdinalPosition(0, KWgPriorityCoverEverything);
       
   867                 }
       
   868             else
       
   869                 {
       
   870                 iBackdropWindowGroup.SetOrdinalPosition(1, ECoeWinPriorityNormal); 
       
   871                 }
       
   872             iBlankWin = CAknServBlankWin::NewL(iBackdropWindowGroup, iStatusPane);
       
   873             iForegroundBlankScreen = aToForeground;
       
   874             }
       
   875         }
       
   876     else if (--iBlankWinRefCount <= 0)
       
   877         {
       
   878         iBlankWinRefCount = 0;
       
   879         if (iForegroundBlankScreen)
       
   880             {
       
   881 #ifdef RD_UI_TRANSITION_EFFECTS_LAYOUT_SWITCH
       
   882             CWsScreenDevice* screen = iEikonEnv->ScreenDevice();
       
   883             /*
       
   884             RWsSession& ws = iEikonEnv->WsSession();
       
   885             TInt wgId = ws.GetFocusWindowGroup();
       
   886             CApaWindowGroupName* wgName = CApaWindowGroupName::NewL(ws, wgId);
       
   887             CleanupStack::PushL( wgName );
       
   888             TUid appUid = wgName->AppUid();
       
   889             CleanupStack::PopAndDestroy( wgName );
       
   890             */
       
   891             //GfxTransEffect::BeginFullScreen( AknTransEffect::ELayoutSwitch,
       
   892             //        TRect( screen->SizeInPixels() ),
       
   893             //        AknTransEffect::EParameterType,
       
   894             //        AknTransEffect::GfxTransParam( KTfxServerUid )
       
   895             //        );
       
   896 
       
   897             GfxTransEffect::EndFullScreen();
       
   898 #endif
       
   899             iBackdropWindowGroup.SetOrdinalPosition(1, ECoeWinPriorityNormal);
       
   900             }
       
   901         delete iBlankWin;
       
   902         iBlankWin = 0;
       
   903         iForegroundBlankScreen = EFalse;
       
   904         } 
       
   905     }
       
   906 
       
   907 void CAknCapAppServerAppUi::SwapLayoutSwitchBlankScreenL()
       
   908     {
       
   909     if (iBlankWin)
       
   910         {
       
   911         if (!iForegroundBlankScreen)
       
   912             {
       
   913             iBackdropWindowGroup.SetOrdinalPosition(0, KWgPriorityCoverEverything);
       
   914             }
       
   915         iForegroundBlankScreen = ETrue;
       
   916         CAknServBlankWin* newBlankWin = CAknServBlankWin::NewL(iBackdropWindowGroup, iStatusPane);
       
   917         newBlankWin->SetLayoutBlank(ETrue);
       
   918         delete iBlankWin;
       
   919         iBlankWin = newBlankWin;
       
   920         }
       
   921     }
       
   922 
       
   923 TBool CAknCapAppServerAppUi::IsDisplayingForegroundBlankScreen() const
       
   924     {
       
   925     return iForegroundBlankScreen;
       
   926     }
       
   927 
       
   928 void CAknCapAppServerAppUi::HandleResourceChangeL(TInt aType)
       
   929     {
       
   930     if (aType == KAknInternalFSWClose) // for notifiers running inside this thread
       
   931         {
       
   932         if (iFSControl)
       
   933             {
       
   934             iFSControl->CloseFastSwap();
       
   935             
       
   936             // This cancels power menu when keys are locked / soft note accepted.
       
   937             Manager()->CancelNotifier(KAknGlobalListQueryUid); 
       
   938             }
       
   939         return; // don't pass this outside this class
       
   940         }
       
   941     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   942         {
       
   943         iCapServer->RefreshLongTapAnimation();
       
   944         }
       
   945     
       
   946     CAknNotifierAppServerAppUi::HandleResourceChangeL(aType);
       
   947     if (iFSControl)
       
   948         {
       
   949         if ( aType == KAknsMessageSkinChange )
       
   950             {
       
   951             UpdateTaskListL( ETrue );
       
   952             }
       
   953         iFSControl->HandleResourceChange(aType);
       
   954         }
       
   955     if (iStatusPane)
       
   956         {
       
   957         iStatusPane->HandleResourceChange(aType);
       
   958         }
       
   959 	if (aType == KAknsMessageSkinChange )
       
   960 		{
       
   961 		iSgcs->FadeBitmapGenerationL();
       
   962 		iSgcs->FadeColorGenerationL();
       
   963 		}
       
   964     }
       
   965     
       
   966 void CAknCapAppServerAppUi::HandleWsEventL(const TWsEvent& aEvent,CCoeControl* aDestination)
       
   967     {
       
   968     if ( iMessageReaderLongPressDetector && !IsAppsKeySuppressed() && !iFSControl->IsDisplayed() )
       
   969         {
       
   970         // Message Reader can be launched by long pressing left soft key 
       
   971         // events need to be intercepted/consumed before they are forwarded to cba
       
   972         if ( iMessageReaderLongPressDetector->HandleWsEventL( aEvent, aDestination ) )
       
   973             {
       
   974             return;
       
   975             }
       
   976         }
       
   977     switch( aEvent.Type() )
       
   978         {
       
   979         case EEventFocusGroupChanged: // For cover UI/status pane refresh problems
       
   980         case EEventWindowGroupListChanged:
       
   981             {
       
   982             // only updated if application has informed about it's intentions to exit
       
   983             UpdateTaskListL( EFalse );
       
   984             iSgcs->HandleWindowGroupListChangeL();
       
   985             break;
       
   986             }
       
   987         case KUidValueAknsSkinChangeEvent:
       
   988             {
       
   989             HandleResourceChangeL(KAknsMessageSkinChange);
       
   990             HandleStackedControlsResourceChange(KAknsMessageSkinChange);
       
   991             break;
       
   992             }
       
   993         default:
       
   994             { 
       
   995             CAknNotifierAppServerAppUi::HandleWsEventL(aEvent, aDestination);
       
   996             if (EventMonitor())
       
   997                 {
       
   998                 EventMonitor()->HandleWsEventL(aEvent, aDestination); // for ecs
       
   999                 }
       
  1000             }
       
  1001         }
       
  1002     }
       
  1003 
       
  1004 void CAknCapAppServerAppUi::SetCurrentAppStatuspaneResourceIdL(TInt aResourceId)
       
  1005     {
       
  1006     iStatusPane->SetCurrentAppStatuspaneResourceId(aResourceId);
       
  1007     }
       
  1008 
       
  1009 TInt CAknCapAppServerAppUi::CurrentAppStatuspaneResourceIdL()
       
  1010     {
       
  1011     return iStatusPane->CurrentAppStatuspaneResourceId();
       
  1012     }
       
  1013 
       
  1014 void CAknCapAppServerAppUi::RotateScreenL()
       
  1015     {
       
  1016     iSgcs->RotateScreenL();
       
  1017     }
       
  1018 
       
  1019 // ---------------------------------------------------------
       
  1020 // CAknCapAppServerAppUi::UpdateTaskListL
       
  1021 // Tasklist will be updated when its visible and when 
       
  1022 // when the old tasklist is no longer valid
       
  1023 // ---------------------------------------------------------
       
  1024 //  
       
  1025 TInt CAknCapAppServerAppUi::UpdateTaskListL( TBool aTaskListRefreshNeeded )
       
  1026     {
       
  1027     TInt err = KErrNone;
       
  1028     if ( iFSControl->IsDisplayed() )
       
  1029         {
       
  1030         // update window group list (task list)
       
  1031         TInt windowGroupListChanged = ETrue;
       
  1032         
       
  1033         TRAP( err, windowGroupListChanged = iFSControl->InitializeWindowGroupListL( 
       
  1034             !aTaskListRefreshNeeded ) );
       
  1035             
       
  1036         if ( windowGroupListChanged || aTaskListRefreshNeeded ) 
       
  1037             {
       
  1038             TRAP( err, iFSControl->HandleChangeInWindowGroupListL() ); 
       
  1039             }
       
  1040         }
       
  1041     return err;
       
  1042     }
       
  1043 
       
  1044 LOCAL_C TBool IsQwertyKey(TPtiKey aKey) 
       
  1045     {
       
  1046     if ((aKey >= EPtiKeyQwertyA && aKey <= EPtiKeyQwertyZ) ||
       
  1047         (aKey >= EPtiKeyQwerty0 && aKey <= EPtiKeyQwerty9) ||
       
  1048         aKey == EPtiKeyQwertyPlus || 
       
  1049         aKey == EPtiKeyQwertyMinus ||
       
  1050         aKey == EPtiKeyQwertyComma ||
       
  1051         aKey == EPtiKeyQwertySemicolon ||       
       
  1052         aKey == EPtiKeyQwertyFullstop ||
       
  1053         aKey == EPtiKeyQwertyHash ||       
       
  1054         aKey == EPtiKeyQwertySlash ||
       
  1055         aKey == EPtiKeyQwertyApostrophe
       
  1056 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
  1057         || aKey == EPtiKeyQwertySpace       
       
  1058         || aKey == EPtiKeyQwertyAtCharacter   
       
  1059 #endif
       
  1060        )
       
  1061             {    
       
  1062             return ETrue;
       
  1063             }   
       
  1064 
       
  1065     return EFalse;  
       
  1066     } 
       
  1067 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
  1068 TBool CAknCapAppServerAppUi::IsCharacterCategoryNumber(TUint aChar) const
       
  1069 {
       
  1070     TChar::TBdCategory numCategory;
       
  1071     TBool isNumber = EFalse;
       
  1072     numCategory = (TChar(aChar)).GetBdCategory();
       
  1073     isNumber = ((numCategory == TChar::EEuropeanNumber) || (numCategory == TChar::EArabicNumber) ||
       
  1074                (numCategory == TChar::EEuropeanNumberTerminator) || (aChar == 0x2E) || 
       
  1075                (aChar == 0x2A) || (aChar == 0x3D) || (aChar == 0x2F));
       
  1076     return isNumber;
       
  1077 }
       
  1078 #endif
       
  1079 
       
  1080 TInt CAknCapAppServerAppUi::GetAliasKeyCode(TUint& aCode, const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
       
  1081     {   
       
  1082     aCode = aKeyEvent.iCode;
       
  1083 #ifdef RD_INTELLIGENT_TEXT_INPUT                               
       
  1084     TKeyEvent keyEventLocal = aKeyEvent;
       
  1085     
       
  1086     #if defined(__WINS__)
       
  1087         if ( keyEventLocal.iScanCode == EStdKeyNkpPlus )
       
  1088             {
       
  1089             // Workaround solution for the qwerty '+' key in emulator environment.
       
  1090             // I did not find a way how to to configure epoc_352x416_Qwerty.ini to send '+' keyevent.
       
  1091             keyEventLocal.iScanCode = 0x2b;  // '+' key.
       
  1092             }
       
  1093 	#endif 
       
  1094         
       
  1095 #endif 
       
  1096     if (!iQwertyStatus || (aKeyEvent.iModifiers & EModifierSpecial) != 0)
       
  1097         {
       
  1098         // Only qwerty events are converted. Coversion is also rejected if EModifierSpecial
       
  1099         // bit is set. That can be used for disabling conversion for simulated
       
  1100         // key events.
       
  1101         return KErrNone;
       
  1102         }
       
  1103             
       
  1104 #ifdef RD_INTELLIGENT_TEXT_INPUT                               
       
  1105     if (IsQwertyKey((TPtiKey)keyEventLocal.iScanCode))       
       
  1106 #else
       
  1107     if (IsQwertyKey((TPtiKey)aKeyEvent.iScanCode))       
       
  1108 #endif 
       
  1109         {           
       
  1110         // We know in advance that iCode values below this threshold are not
       
  1111         // going to be converted, so just return.    
       
  1112         if (aCode <= KKeyEventICodeThreshold)
       
  1113             {
       
  1114             return KErrNone;
       
  1115             }
       
  1116             
       
  1117         if (aKeyEvent.iModifiers & KModifierExternalKeyboard)            
       
  1118             {
       
  1119             // The event is coming from external keyboard, do not convert.
       
  1120             return KErrNone;
       
  1121             }
       
  1122                 
       
  1123         TInt err = KErrNone;                
       
  1124         
       
  1125         if (!iPtiEngine)
       
  1126             {
       
  1127             TRAP(err, iPtiEngine = CPtiEngine::NewL(ETrue));
       
  1128             if (err != KErrNone)
       
  1129                 {
       
  1130                 return err;
       
  1131                 }
       
  1132             }
       
  1133                                            
       
  1134         CAknSettingCache& settingsCache =   CAknEnv::Static()->SettingCache();
       
  1135                                 
       
  1136         const TInt KMaxNumCharsPerCase = 50;
       
  1137         TBuf<KMaxNumCharsPerCase> keys; 
       
  1138    
       
  1139         const TBool shifted = (aKeyEvent.iModifiers & EModifierLeftShift) ||
       
  1140             (aKeyEvent.iModifiers & EModifierRightShift); 
       
  1141 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
  1142 
       
  1143 		TInt fnState;
       
  1144     	RProperty::Get(KPSUidAknFep,KAknFepFnKeyState, fnState);
       
  1145 		const TBool functionized = (keyEventLocal.iModifiers & EModifierRightFunc) ;
       
  1146 									//||	(fnState == 6); 
       
  1147 
       
  1148         const TBool isCtrl = (aKeyEvent.iModifiers & EModifierLeftCtrl) ||
       
  1149             (aKeyEvent.iModifiers & EModifierRightCtrl);
       
  1150         if(isCtrl)
       
  1151             return KErrNone;
       
  1152 #endif
       
  1153         CPtiCoreLanguage* lang = static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage(
       
  1154             settingsCache.InputLanguage()));                 
       
  1155 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
  1156             // Qwerty Keyboard layout
       
  1157         TInt keyboardLayout = 0;       
       
  1158         RProperty::Get(KCRUidAvkon, KAknKeyBoardLayout, keyboardLayout);
       
  1159 
       
  1160         TPtiKeyboardType keyboardType = (TPtiKeyboardType) keyboardLayout ;
       
  1161 #endif
       
  1162             
       
  1163         if (lang)
       
  1164             {                   
       
  1165 #ifdef RD_INTELLIGENT_TEXT_INPUT                               
       
  1166             CPtiQwertyKeyMappings* maps;
       
  1167             if(keyboardType != EPtiKeyboardHalfQwerty)
       
  1168                 maps = static_cast<CPtiQwertyKeyMappings*>(lang->GetQwertyKeymappings());
       
  1169             else
       
  1170                 maps = static_cast<CPtiQwertyKeyMappings*>(lang->GetHalfQwertyKeymappings());
       
  1171             
       
  1172 #else
       
  1173             CPtiQwertyKeyMappings* maps = 
       
  1174                 static_cast<CPtiQwertyKeyMappings*>(lang->GetQwertyKeymappings());
       
  1175 #endif                    
       
  1176                 
       
  1177             if (maps)
       
  1178                 {
       
  1179 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
  1180                 maps->SetKeyboardType(keyboardType);
       
  1181                 if(functionized)
       
  1182                     {
       
  1183                     maps->GetDataForKey((TPtiKey)keyEventLocal.iScanCode, keys, EPtiCaseFnLower);
       
  1184 					if( !(keys.Length() && IsCharacterCategoryNumber(keys[0])))
       
  1185                         maps->GetDataForKey((TPtiKey)keyEventLocal.iScanCode, keys, EPtiCaseFnUpper);					
       
  1186 					if(!keys.Length())
       
  1187                         {
       
  1188                         maps->GetDataForKey((TPtiKey)keyEventLocal.iScanCode, keys, EPtiCaseFnLower);
       
  1189                         }
       
  1190                     }
       
  1191 				else if(shifted)
       
  1192 					{
       
  1193 					maps->GetDataForKey((TPtiKey)keyEventLocal.iScanCode, keys, EPtiCaseUpper);
       
  1194 					}
       
  1195 				else
       
  1196 					{               
       
  1197                 maps->GetDataForKey((TPtiKey)keyEventLocal.iScanCode, keys, EPtiCaseFnLower);
       
  1198                 if( !(keys.Length() && IsCharacterCategoryNumber(keys[0])))
       
  1199                     maps->GetDataForKey((TPtiKey)keyEventLocal.iScanCode, keys, EPtiCaseFnUpper);
       
  1200                 if( !(keys.Length() && IsCharacterCategoryNumber(keys[0])))
       
  1201                     maps->GetDataForKey((TPtiKey)keyEventLocal.iScanCode, keys, EPtiCaseLower);
       
  1202                 if( !(keys.Length() && IsCharacterCategoryNumber(keys[0])))
       
  1203                     maps->GetDataForKey((TPtiKey)keyEventLocal.iScanCode, keys, EPtiCaseUpper);                
       
  1204                     if( !(keys.Length() && IsCharacterCategoryNumber(keys[0])))
       
  1205                         keys.SetLength(0);
       
  1206 					}
       
  1207                 
       
  1208 #else
       
  1209                 if (shifted)
       
  1210                     {
       
  1211                     maps->GetDataForKey((TPtiKey)aKeyEvent.iScanCode, keys, EPtiCaseUpper);             
       
  1212                     }
       
  1213                 else
       
  1214                     {
       
  1215                     maps->GetDataForKey((TPtiKey)aKeyEvent.iScanCode, keys, EPtiCaseLower);             
       
  1216                     }                       
       
  1217 #endif
       
  1218                 }
       
  1219             }
       
  1220         
       
  1221         if ( keys.Length() > 0 )
       
  1222             {
       
  1223             switch (keys[0])        
       
  1224                 {
       
  1225                 case KPtiPinyinMarker:
       
  1226                 case KPtiStrokeMarker:
       
  1227                 case KPtiZhuyinMarker:
       
  1228                 case KPtiCangjieMarker:
       
  1229                 case KPtiGetAllMarker:                  
       
  1230                     if (keys.Length() > 1)
       
  1231                         {
       
  1232                         aCode = keys[1];
       
  1233                         }
       
  1234                     break;
       
  1235                 default:                 
       
  1236                     aCode = keys[0];                 
       
  1237                 }
       
  1238             } 
       
  1239         } 
       
  1240         
       
  1241     return KErrNone;
       
  1242     }
       
  1243 
       
  1244 void CAknCapAppServerAppUi::ForwardKeyToPhoneAppL(const TKeyEvent& aKeyEvent)
       
  1245     {
       
  1246     if (iScanCodeCaptureHandle)
       
  1247         {
       
  1248         return;
       
  1249         }
       
  1250     iPhoneKey = aKeyEvent; // reset
       
  1251     
       
  1252     iScanCodeCaptureHandle = CCoeEnv::Static()->RootWin().CaptureKeyUpAndDowns(
       
  1253         aKeyEvent.iScanCode,0,0 );
       
  1254         
       
  1255     if (!iIdler)
       
  1256         {
       
  1257         iIdler = CIdle::NewL(CActive::EPriorityStandard);        
       
  1258         }
       
  1259     iIdler->Start(TCallBack(AknPhoneKeyForwarder::ForwardKeyToPhoneApp, &iPhoneKey));
       
  1260     iUpReceived = EFalse;
       
  1261     }
       
  1262 
       
  1263 
       
  1264 
       
  1265 void CAknCapAppServerAppUi::PhoneKeyUpReceived()
       
  1266     {              
       
  1267     if (iScanCodeCaptureHandle)
       
  1268         {
       
  1269         CCoeEnv::Static()->RootWin().CancelCaptureKeyUpAndDowns(iScanCodeCaptureHandle);
       
  1270         }
       
  1271     iScanCodeCaptureHandle = 0;
       
  1272     iUpReceived = ETrue;
       
  1273     if (!iIdler->IsActive()) // callback already triggered
       
  1274         { // direct call
       
  1275         AknPhoneKeyForwarder::ForwardUpEventToPhoneApp(&iPhoneKey);
       
  1276         }
       
  1277     }
       
  1278 
       
  1279 void CAknCapAppServerAppUi::SetFgSpDataSubscriberIdL(TInt aId)
       
  1280     {   
       
  1281     CEikStatusPaneBase* statusPane = CEikStatusPaneBase::Current();
       
  1282     if (statusPane)
       
  1283         {
       
  1284         CEikServStatusPane* ssp = static_cast<CEikServStatusPane*>(statusPane);
       
  1285         CAknStatusPaneDataPublisher* publisher = ssp->iDataPublisher;
       
  1286         if (publisher)
       
  1287             {
       
  1288             publisher->SetForegroundSubscriberId(aId);
       
  1289             publisher->PublishDataL();
       
  1290             }            
       
  1291         }
       
  1292     }
       
  1293 
       
  1294 void CAknCapAppServerAppUi::CloseFSW()
       
  1295     {
       
  1296     if (iFSControl)
       
  1297         {
       
  1298         iFSControl->CloseFastSwap();
       
  1299         }
       
  1300     }
       
  1301 	
       
  1302 void CAknCapAppServerAppUi::SetIdleActive( TBool bActive )
       
  1303     {
       
  1304     iIdleActive = bActive;
       
  1305     }
       
  1306 
       
  1307 TBool CAknCapAppServerAppUi::IsIdelActive( )
       
  1308     {
       
  1309     return iIdleActive;
       
  1310     }
       
  1311 
       
  1312 void CAknCapAppServerAppUi::PublishInstalledLanguagesL()
       
  1313     {
       
  1314     User::LeaveIfError( RProperty::Define( 
       
  1315         KPSUidUikon,
       
  1316         KUikInstalledLanguages,
       
  1317         RProperty::EText,
       
  1318         KReadPolicy,        // None
       
  1319         KWriteDDPolicy ) ); // WriteDeviceData
       
  1320     
       
  1321     CArrayFixFlat<TInt>* installedLanguages = 0;
       
  1322     
       
  1323     User::LeaveIfError( SysLangUtil::GetInstalledLanguages( installedLanguages ) );
       
  1324     
       
  1325     CleanupStack::PushL( installedLanguages );
       
  1326     
       
  1327     TInt nbrOfLanguages = installedLanguages->Count();
       
  1328     
       
  1329     // This is a bit more than enough buffer in most cases
       
  1330     // Add one just for the space at the beginning of the data.
       
  1331     TInt bufferLength = nbrOfLanguages * KMaxLanguageCodeLength + 1;
       
  1332             
       
  1333     HBufC8* languages = HBufC8::NewLC( bufferLength );
       
  1334     TPtr8 ptr( languages->Des() );
       
  1335     
       
  1336     if ( nbrOfLanguages > 0 )
       
  1337         {
       
  1338         ptr.Append( KSeparator ); // Add space at the beginning of the data
       
  1339         }
       
  1340     
       
  1341     for ( TInt i = 0; i < nbrOfLanguages; i++ )
       
  1342         {
       
  1343         ptr.AppendNum( installedLanguages->At(i) ); // Add language ID to data
       
  1344         ptr.Append( KSeparator );// Space is also added as the last character
       
  1345         }    
       
  1346           
       
  1347     RProperty::Set( KPSUidUikon, KUikInstalledLanguages, ptr );
       
  1348     
       
  1349     CleanupStack::PopAndDestroy( 2, installedLanguages );
       
  1350     }
       
  1351 
       
  1352 TInt CAknCapAppServerAppUi::GlobalNotesAllowedCallBack(TAny* aPtr)
       
  1353     {
       
  1354     CAknCapAppServerAppUi* self = static_cast<CAknCapAppServerAppUi*>(aPtr);
       
  1355     if (self)
       
  1356         {
       
  1357         self->HandlePropertyChange(KUikGlobalNotesAllowed);
       
  1358         }
       
  1359     return KErrNone;
       
  1360     }
       
  1361 
       
  1362 TInt CAknCapAppServerAppUi::TelephonyIdleUidCallBack(TAny* aPtr)
       
  1363     {
       
  1364     CAknCapAppServerAppUi* self = static_cast<CAknCapAppServerAppUi*>(aPtr);
       
  1365     if (self)
       
  1366         {
       
  1367         self->HandlePropertyChange(KActiveIdleUid);
       
  1368         }
       
  1369     return KErrNone;
       
  1370     }
       
  1371     
       
  1372 void CAknCapAppServerAppUi::HandlePropertyChange(const TInt aProperty)
       
  1373     {
       
  1374     switch(aProperty)
       
  1375         {
       
  1376         case KUikGlobalNotesAllowed:
       
  1377             {
       
  1378             TInt globalNotesAllowed = 0;
       
  1379             TInt err = iTelephonyIdleUidProperty.Get(globalNotesAllowed);
       
  1380             if(!err && globalNotesAllowed)
       
  1381                 {
       
  1382                 // Global notes allowed, so the boot is finished. Now the idle app uid and its
       
  1383                 // window group id can be fetched.
       
  1384                 HandlePropertyChange(KActiveIdleUid);
       
  1385                 }
       
  1386             }
       
  1387             break;
       
  1388         case KActiveIdleUid:
       
  1389             {
       
  1390             TInt idleAppUid = 0;
       
  1391             TInt err = iTelephonyIdleUidProperty.Get(idleAppUid);
       
  1392             if(!err)
       
  1393                 {
       
  1394                 // Fetch the Idle application window group id.
       
  1395                 TApaTaskList taskList(CEikonEnv::Static()->WsSession());
       
  1396                 TApaTask task = taskList.FindApp(TUid::Uid(idleAppUid));
       
  1397                 TInt wgId = task.WgId();
       
  1398                 
       
  1399                 // Save the window group id to PubSub. 
       
  1400                 RProperty::Set(KPSUidAvkonInternal, KAknIdleAppWindowGroupId, wgId);     
       
  1401                 }
       
  1402             }
       
  1403             break;
       
  1404         default:
       
  1405             break;
       
  1406         };
       
  1407     }
       
  1408     
       
  1409 // -----------------------------------------------------------------------------
       
  1410 // C++ constructor can NOT contain any code, that might leave.
       
  1411 // -----------------------------------------------------------------------------
       
  1412 //
       
  1413 CPropertySubscriber::CPropertySubscriber(TCallBack aCallBack, RProperty& aProperty)
       
  1414     : CActive(EPriorityNormal), iCallBack(aCallBack), iProperty(aProperty)
       
  1415     {
       
  1416     CActiveScheduler::Add(this);
       
  1417     }
       
  1418 
       
  1419 // -----------------------------------------------------------------------------
       
  1420 // Destructor.
       
  1421 // -----------------------------------------------------------------------------
       
  1422 //
       
  1423 CPropertySubscriber::~CPropertySubscriber()
       
  1424     {
       
  1425     Cancel();
       
  1426     }
       
  1427 
       
  1428 // -----------------------------------------------------------------------------
       
  1429 // Starts to listen for changes.
       
  1430 // -----------------------------------------------------------------------------
       
  1431 //
       
  1432 void CPropertySubscriber::Subscribe()
       
  1433     {
       
  1434     if (!IsActive())
       
  1435         {
       
  1436         iProperty.Subscribe(iStatus);
       
  1437         SetActive();
       
  1438         }
       
  1439     }
       
  1440 
       
  1441 // -----------------------------------------------------------------------------
       
  1442 // Stops listening for changes.
       
  1443 // -----------------------------------------------------------------------------
       
  1444 //
       
  1445 void CPropertySubscriber::StopSubscribe()
       
  1446     {
       
  1447     Cancel();
       
  1448     }
       
  1449 
       
  1450 // -----------------------------------------------------------------------------
       
  1451 // When active object fires, call callback and continue listening.
       
  1452 // -----------------------------------------------------------------------------
       
  1453 //
       
  1454 void CPropertySubscriber::RunL()
       
  1455     {
       
  1456     if (iStatus.Int() == KErrNone)
       
  1457         {
       
  1458         iCallBack.CallBack();
       
  1459         Subscribe();
       
  1460         }
       
  1461     }
       
  1462 
       
  1463 // -----------------------------------------------------------------------------
       
  1464 // Cancel.
       
  1465 // -----------------------------------------------------------------------------
       
  1466 //
       
  1467 void CPropertySubscriber::DoCancel()
       
  1468     {
       
  1469     iProperty.Cancel();
       
  1470     }
       
  1471     
       
  1472 // Actual entry point.  
       
  1473 LOCAL_C CApaApplication* NewApplication()
       
  1474     {
       
  1475     return new CAknCapServerApplication();
       
  1476     }   
       
  1477     
       
  1478 GLDEF_C TInt E32Main()
       
  1479     {
       
  1480     return EikStart::RunApplication(NewApplication);
       
  1481     }
       
  1482 
       
  1483 // End of file