uifw/AknGlobalUI/NotifierWrapper/src/AknNotiferAppServerApplication.cpp
changeset 0 2f259fa3e83a
child 10 9f56a4e1b8ab
child 45 667edd0b8678
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2004-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:  Notifier server app wrapper implementation. 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <coemain.h>
       
    19 #include <aknenv.h>
       
    20 #include <apgwgnam.h> 
       
    21 #include <apgtask.h>
       
    22 #include <eiknotapi.h>
       
    23 #include <AknCapServerClient.h>
       
    24 #include <aknnotewrappers.h>
       
    25 #include <AknCapServerDefs.h>
       
    26 
       
    27 #include <avkondomainpskeys.h>
       
    28 #include <e32property.h>
       
    29 
       
    30 #include "AknNotiferAppServerApplication.h" 
       
    31 #include "AknNotifierAppServer.h"
       
    32 #include "AknNotifierControllerUtilities.h"
       
    33 #include "AknNotiferAppServerApplicationInterface.h"
       
    34 
       
    35 #include <AknMediatorFacade.h>
       
    36 #include <SecondaryDisplay/AknSecondaryDisplayDefs.h>
       
    37 #include <aknglobalpopupprioritycontroller.h>
       
    38 
       
    39 //---- Awkward, but declaring base classes otherwise in Akncapserver entry would break app fw.
       
    40 class CAknCapAppServerAppUiInterface : 
       
    41     public CAknNotifierAppServerAppUi, 
       
    42     public MAknCapServerInterface
       
    43     {
       
    44     };
       
    45 //----
       
    46 
       
    47 //----------------------------------
       
    48 // Application
       
    49 //----------------------------------
       
    50 class CAknAsyncAppFader: public CBase
       
    51     {
       
    52 public:
       
    53     CAknAsyncAppFader(CAknNotifierAppServerAppUi* aAppUi):iAppUi(aAppUi)
       
    54         {}
       
    55     ~CAknAsyncAppFader()
       
    56         {
       
    57         delete iIdle;
       
    58         }   
       
    59     TBool IsActive() 
       
    60         {
       
    61         return iIdle != 0;
       
    62         }
       
    63     void StartL(TBool aFade);
       
    64     void Cancel()
       
    65         {
       
    66         delete iIdle;
       
    67         iIdle = 0;
       
    68         }
       
    69     static TInt BaseCall(TAny* aThis);
       
    70     
       
    71     TBool iFade;
       
    72     CAknNotifierAppServerAppUi* iAppUi; // not owned
       
    73     CIdle* iIdle;   
       
    74     };
       
    75 
       
    76 void CAknAsyncAppFader::StartL(TBool aFade)
       
    77     {
       
    78     if(!iIdle)
       
    79         {
       
    80         iFade = aFade;
       
    81         iIdle = CIdle::NewL(CActive::EPriorityStandard);
       
    82         iIdle->Start(TCallBack(BaseCall,this));
       
    83         }
       
    84     }
       
    85 
       
    86 TInt CAknAsyncAppFader::BaseCall(TAny* aThis)
       
    87     {
       
    88     CAknAsyncAppFader* me = (CAknAsyncAppFader*) aThis;
       
    89     TRAPD(err, me->iAppUi->BaseCallFadeL(me->iFade));
       
    90     return err;
       
    91     }
       
    92 
       
    93     
       
    94 class CAknNotifierManagerExtension: public CBase
       
    95     {
       
    96 public:
       
    97     CAknNotifierManagerExtension()
       
    98         {
       
    99         iKeyLock = EKeyguardNotActive;    
       
   100         }
       
   101         
       
   102     ~CAknNotifierManagerExtension()
       
   103         {
       
   104         iAppsKeyClient.Close();
       
   105         delete iController;
       
   106         delete iAsynchFader;
       
   107         }
       
   108     TInt ConnectAndSendAppsKeySuppress(TBool aSuppress);
       
   109     MEikSrvNotifierManager* iManager; // Not owned
       
   110     CAknNotifierControllerUtility* iController;
       
   111     CAknAsyncAppFader* iAsynchFader;
       
   112     TBool iEikServBlocked;
       
   113     TInt iKeyLock;
       
   114     
       
   115 private:
       
   116     RAknUiServer iAppsKeyClient;
       
   117     };
       
   118 
       
   119 TInt CAknNotifierManagerExtension::ConnectAndSendAppsKeySuppress(TBool aSuppress)
       
   120     {
       
   121     return iAppsKeyClient.ConnectAndSendAppsKeySuppress(aSuppress);
       
   122     }
       
   123 
       
   124 EXPORT_C CAknNotifierAppServerApplication::CAknNotifierAppServerApplication()
       
   125     {
       
   126     }
       
   127    
       
   128 EXPORT_C CAknNotifierAppServerApplication::~CAknNotifierAppServerApplication()
       
   129     {
       
   130     }
       
   131 
       
   132 EXPORT_C void CAknNotifierAppServerApplication::NewAppServerL(CApaAppServer*& aAppServer)
       
   133     { 
       
   134     // Default implementation just creates instance of server, it is ok to use this if 
       
   135     // old style notifier libraries are loaded on demand later.
       
   136     CAknNotifierAppServer* server = new (ELeave) CAknNotifierAppServer();
       
   137     aAppServer=&*server;
       
   138     }
       
   139     
       
   140 EXPORT_C CApaDocument* CAknNotifierAppServerApplication::CreateDocumentL() 
       
   141     {
       
   142     return new (ELeave) CAknNotifierAppServerDocument(*this);
       
   143     }
       
   144 
       
   145 CEikAppUi* CAknNotifierAppServerDocument::CreateAppUiL()
       
   146     {
       
   147     return new (ELeave) CAknNotifierAppServerAppUi();
       
   148     }
       
   149 
       
   150  
       
   151 //----------------------------------
       
   152 // AppUi
       
   153 //----------------------------------
       
   154 EXPORT_C CAknNotifierAppServerAppUi::CAknNotifierAppServerAppUi()
       
   155     {
       
   156     SetFullScreenApp(EFalse);
       
   157     }
       
   158  
       
   159 EXPORT_C CAknNotifierAppServerAppUi::~CAknNotifierAppServerAppUi()
       
   160     {
       
   161     delete iExtension;
       
   162     }
       
   163  
       
   164 EXPORT_C void CAknNotifierAppServerAppUi::ConstructL()
       
   165     {
       
   166     iExtension = new (ELeave) CAknNotifierManagerExtension();
       
   167     iExtension->iAsynchFader = new (ELeave) CAknAsyncAppFader(this);
       
   168 
       
   169     TInt flags = EStandardApp | ENoScreenFurniture | ENonStandardResourceFile | EAknEnableSkin | 
       
   170         EAknEnableMSK | EAknSingleClickCompatible;
       
   171 
       
   172     CAknAppUi::BaseConstructL(flags);
       
   173  
       
   174     // fetch name and hide 
       
   175     CCoeEnv* coe = CCoeEnv::Static();
       
   176     
       
   177     AknGlobalPopupPriorityController::EnablePriorityControlL();
       
   178     AknGlobalPopupPriorityController::AllowGlobalPopups(ETrue);
       
   179 
       
   180     CApaWindowGroupName* name = CApaWindowGroupName::NewLC(
       
   181         coe->WsSession(),coe->RootWin().Identifier());
       
   182         
       
   183     name->SetHidden(ETrue);
       
   184     RThread me;
       
   185     name->SetCaptionL(me.Name());
       
   186     name->SetAppUid(Document()->Application()->AppDllUid());
       
   187     name->SetWindowGroupName(coe->RootWin());
       
   188 
       
   189     CleanupStack::PopAndDestroy();
       
   190     
       
   191     // and send to background
       
   192     TApaTask task = TApaTask(coe->WsSession());
       
   193     task.SetWgId(coe->RootWin().Identifier());
       
   194     task.SendToBackground();
       
   195     
       
   196     // Creates window controller for system wide notifier hiding & cancellation       
       
   197     // value given is used to determine this app position if several wgs with same    
       
   198     // priority exist.                                                               
       
   199     SetOrdinalPositionL(0); 
       
   200     }
       
   201  
       
   202 EXPORT_C void CAknNotifierAppServerAppUi::HandleCommandL(TInt aCommand)
       
   203     {
       
   204     if (aCommand == EEikCmdExit)
       
   205         {
       
   206         CAknEnv::Static()->RunAppShutter();
       
   207         }
       
   208     }
       
   209     
       
   210 EXPORT_C TKeyResponse CAknNotifierAppServerAppUi::HandleKeyEventL(const TKeyEvent& /*aKeyEvent*/,
       
   211     TEventCode /*aType*/)
       
   212     {
       
   213     return EKeyWasConsumed;    
       
   214     }
       
   215  
       
   216 EXPORT_C TInt CAknNotifierAppServerAppUi::SuppressAppSwitching(TBool aSuppress)
       
   217     {
       
   218     
       
   219     // Get key lock's status
       
   220     if (KErrNone !=  RProperty::Get( KPSUidAvkonDomain, KAknKeyguardStatus ,
       
   221                         iExtension->iKeyLock ) )
       
   222         {
       
   223     	iExtension->iKeyLock = EKeyguardNotActive;
       
   224         }
       
   225     
       
   226     RThread me;
       
   227     if (me.Name() == KAknCapServerThreadName) 
       
   228          {
       
   229          TRAPD(err, ((CAknCapAppServerAppUiInterface*)iAvkonAppUi)->SuppressAppSwitchingL(
       
   230              aSuppress ? EAknAppsKeyBlockAddCount : EAknAppsKeyBlockDecreaseCount, 0))
       
   231          return err;
       
   232          }
       
   233     else if (iExtension) 
       
   234          {
       
   235          return iExtension->ConnectAndSendAppsKeySuppress(aSuppress);    
       
   236          }
       
   237     
       
   238     return KErrNotReady; 
       
   239     }
       
   240 
       
   241     
       
   242 EXPORT_C void CAknNotifierAppServerAppUi::SetManager(MEikSrvNotifierManager* aManager)
       
   243     {
       
   244     if (iExtension)
       
   245         {
       
   246         iExtension->iManager = aManager;
       
   247         }
       
   248     }
       
   249     
       
   250 EXPORT_C MEikSrvNotifierManager* CAknNotifierAppServerAppUi::Manager()
       
   251     {
       
   252     // If non standard manager is set, return it, othewise return default ie. server.
       
   253     if (iExtension && iExtension->iManager )
       
   254         {
       
   255         return iExtension->iManager;
       
   256         }
       
   257     else 
       
   258         {
       
   259         return (CAknNotifierAppServer*) CEikonEnv::Static()->AppServer();
       
   260         }    
       
   261     }
       
   262 
       
   263 EXPORT_C void CAknNotifierAppServerAppUi::SetOrdinalPositionL(TInt aPosition)
       
   264     {
       
   265     if (iExtension)
       
   266         {
       
   267         delete iExtension->iController;
       
   268         iExtension->iController = 0;
       
   269         iExtension->iController = new (ELeave) CAknNotifierControllerUtility(aPosition);
       
   270         }
       
   271     }
       
   272 
       
   273 EXPORT_C void CAknNotifierAppServerAppUi::SetFadedL(TBool aFade)
       
   274     {
       
   275 
       
   276     // Don't unfade the screen when no global popup control in stack.
       
   277     // let the following window is unfaded during focus change in windows group.
       
   278     // If key guard locked, always fade/unfade.
       
   279     if (aFade || (iExtension->iKeyLock != EKeyguardNotActive))
       
   280       {
       
   281       CAknAppUi::SetFadedL(aFade);
       
   282       }
       
   283     return; 
       
   284     }
       
   285 
       
   286 void CAknNotifierAppServerAppUi::BaseCallFadeL(TBool aFade)
       
   287     {
       
   288     CAknAppUi::SetFadedL(aFade);
       
   289     }
       
   290 
       
   291 EXPORT_C TBool& CAknNotifierAppServerAppUi::EikSrvBlocked()
       
   292     {
       
   293     return iExtension->iEikServBlocked;
       
   294     }
       
   295 
       
   296 EXPORT_C TErrorHandlerResponse CAknNotifierAppServerAppUi::HandleError(
       
   297     TInt aError, 
       
   298     const SExtendedError& /*aExtErr*/,  
       
   299     TDes& /*aErrorText*/, 
       
   300     TDes& /*aContextText*/ )
       
   301     {
       
   302     HBufC* buf = 0;
       
   303     TRAPD(err, HandleErrorL(aError, &buf, EFalse));
       
   304 
       
   305     if (!err && buf->Length() > 0)
       
   306         {
       
   307         CAknWarningNote* note = new CAknWarningNote;
       
   308         if (!note)
       
   309             {
       
   310             err = KErrNoMemory;
       
   311             }
       
   312         else 
       
   313             {
       
   314             // secondary display needs to be informed about the error note
       
   315             TRAP( err, note->PublishDialogL( EAknErrorNote, KAknSecondaryDisplayCategory ));
       
   316             if (!err)
       
   317                 {
       
   318                 CAknMediatorFacade* coverData = AknMediatorFacade(note);
       
   319                 if(coverData)
       
   320                     {
       
   321                     SAknIntegerUpdate s = 
       
   322                         {
       
   323                         EAknTrappedError,
       
   324                         aError 
       
   325                         };
       
   326                     TPckg<SAknIntegerUpdate> pck(s);
       
   327                     coverData->BufStream() << pck;
       
   328                     TRAP_IGNORE( coverData->BufStream().CommitL() );
       
   329                     }            
       
   330                 }
       
   331             TRAP(err, note->ExecuteLD(buf->Des()));
       
   332             }
       
   333         }
       
   334 
       
   335     delete buf;
       
   336 
       
   337     if ( !err )
       
   338         {
       
   339         return(ENoDisplay); // Error handled proper way.
       
   340         }
       
   341     
       
   342     return(EErrorNotHandled); // Error not handled, let EIKENV handle the error.
       
   343     }
       
   344 
       
   345 EXPORT_C void CAknNotifierAppServerAppUi::HandleSystemEventL(const TWsEvent& aEvent)
       
   346     {
       
   347     switch (*(TApaSystemEvent*)(aEvent.EventData()))
       
   348         {
       
   349     case EApaSystemEventBroughtToForeground:
       
   350         { // ignore this event as it causes undesired effects on applications underneath
       
   351         break;
       
   352         }
       
   353     default:
       
   354         CAknAppUi::HandleSystemEventL(aEvent);
       
   355         }
       
   356 
       
   357     return;
       
   358     }
       
   359 
       
   360 CAknNotifierControllerUtility* CAknNotifierAppServerAppUi::NotifierControllerUtility()
       
   361     {
       
   362     if (iExtension)
       
   363         {
       
   364         return iExtension->iController;
       
   365         }
       
   366     
       
   367     return 0;
       
   368     }
       
   369 
       
   370 // End of file