uifw/AknGlobalUI/AknCapServer/src/akncapserverdiscreetpopuphandler.cpp
changeset 0 2f259fa3e83a
child 4 8ca85d2f0db7
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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:  Avkon cap server discreet popup handler.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <apgtask.h>
       
    19 #include <coeaui.h>
       
    20 #include <e32property.h>
       
    21 #include <avkondomainpskeys.h>
       
    22 
       
    23 #include "akncapserverdiscreetpopuphandler.h"
       
    24 #include "akndiscreetpopupcontrol.h"
       
    25 #include "akndiscreetpopupdata.h"
       
    26 
       
    27 const TUid KAknCapServerDiscreetPopupHandler = { 0x2001FDF8 };
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // CAknCapServerDiscreetPopupHandler::~CAknCapServerDiscreetPopupHandler
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CAknCapServerDiscreetPopupHandler::~CAknCapServerDiscreetPopupHandler()
       
    36     {
       
    37     for ( TInt i = 0; i < iPopupDataArray.Count(); i++ )
       
    38         {
       
    39         if ( iPopupDataArray[ i ].iPopupControl )
       
    40             {
       
    41             delete iPopupDataArray[ i ].iPopupControl;
       
    42             iPopupDataArray[ i ].iPopupControl = NULL;
       
    43             }
       
    44         }
       
    45     iPopupDataArray.Close();    
       
    46     }
       
    47 
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CAknCapServerDiscreetPopupHandler::HandleDiscreetPopupMessageL
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 void CAknCapServerDiscreetPopupHandler::HandleDiscreetPopupMessageL( 
       
    54         const RMessage2& aMessage )
       
    55     {
       
    56     CAknCapServerDiscreetPopupHandler* instance 
       
    57         = CAknCapServerDiscreetPopupHandler::InstanceL();
       
    58     if ( instance )
       
    59         {
       
    60         instance->DoHandleDiscreetPopupMessageL( aMessage );
       
    61         }
       
    62     }
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CAknCapServerDiscreetPopupHandler::CreateDiscreetPopupHandlerL
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CAknCapServerDiscreetPopupHandler::CreateDiscreetPopupHandlerL()
       
    70     {
       
    71     CAknCapServerDiscreetPopupHandler* instance 
       
    72         = CAknCapServerDiscreetPopupHandler::InstanceL();
       
    73     }
       
    74 
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CAknCapServerDiscreetPopupHandler::CAknCapServerDiscreetPopupHandler
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CAknCapServerDiscreetPopupHandler::CAknCapServerDiscreetPopupHandler() 
       
    81     : 
       
    82     CCoeStatic( KAknCapServerDiscreetPopupHandler, CCoeStatic::EThread ),
       
    83     iAppUi( CCoeEnv::Static()->AppUi() )
       
    84     {
       
    85     }
       
    86 
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CAknCapServerDiscreetPopupHandler::ConstructL
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CAknCapServerDiscreetPopupHandler::ConstructL()
       
    93     {
       
    94     }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CAknCapServerDiscreetPopupHandler::InstanceL
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 CAknCapServerDiscreetPopupHandler* CAknCapServerDiscreetPopupHandler::InstanceL()
       
   102     {
       
   103     CAknCapServerDiscreetPopupHandler* instance = 
       
   104         static_cast<CAknCapServerDiscreetPopupHandler*>( 
       
   105             CCoeEnv::Static( KAknCapServerDiscreetPopupHandler ) );
       
   106     if ( !instance )
       
   107         {
       
   108         instance = new ( ELeave ) CAknCapServerDiscreetPopupHandler;
       
   109         CleanupStack::PushL( instance );
       
   110         instance->ConstructL();
       
   111         CleanupStack::Pop( instance );
       
   112         }
       
   113     return instance;
       
   114     }
       
   115 
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CAknCapServerDiscreetPopupHandler::DoLaunchDiscreetPopupL
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CAknCapServerDiscreetPopupHandler::DoHandleDiscreetPopupMessageL(
       
   122     const RMessage2& aMessage )
       
   123     {
       
   124     TAknDiscreetPopupData dataType;
       
   125     TPckg<TAknDiscreetPopupData> pkgType( dataType );
       
   126     aMessage.ReadL( 0, pkgType );
       
   127     switch ( dataType.Type() )
       
   128         {
       
   129         case ( TAknDiscreetPopupData::EAknPopupTypeResource ):
       
   130             {
       
   131             LaunchFromResourceL( aMessage );
       
   132             break;
       
   133             }
       
   134         case ( TAknDiscreetPopupData::EAknPopupTypeParam ):
       
   135             {
       
   136             LaunchWithParamsL( aMessage );
       
   137             break;
       
   138             }
       
   139         case ( TAknDiscreetPopupData::EAknPopupTypeCancelRequest ):
       
   140             {
       
   141             HandleRequestCancellationL( aMessage );
       
   142             break;
       
   143             }
       
   144         case ( TAknDiscreetPopupData::EAknPopupTypeQueryInUseRect ):
       
   145             {
       
   146             HandleQueryInUseRect( aMessage );
       
   147             break;
       
   148             }        
       
   149         default:
       
   150             {
       
   151             break;
       
   152             }
       
   153         }
       
   154     }
       
   155 
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CAknCapServerDiscreetPopupHandler::LaunchFromResourceL
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CAknCapServerDiscreetPopupHandler::LaunchFromResourceL(  
       
   162         const RMessage2& aMessage )
       
   163     {
       
   164     TAknDiscreetPopupResourceData data;
       
   165     TPckg<TAknDiscreetPopupResourceData> pkg( data );
       
   166     aMessage.ReadL( 0, pkg );
       
   167 
       
   168     MEikCommandObserver* observer( NULL );
       
   169     TInt commandId( 0 );
       
   170     if ( data.Action() )
       
   171         {
       
   172         commandId = NextAvailableCommandId();
       
   173         observer = this;
       
   174         }
       
   175 
       
   176     CAknDiscreetPopupControl* popup = 
       
   177         CAknDiscreetPopupControl::NewL( 
       
   178                 ETrue,
       
   179                 data.ResourceId(),
       
   180                 data.ResourceFile(),
       
   181                 commandId,
       
   182                 data.PopupId(),
       
   183                 observer );
       
   184     CleanupStack::PushL( popup );
       
   185     ShowPopupL( commandId,
       
   186         popup,
       
   187         data.AppUid(),
       
   188         data.ViewUid(),
       
   189         aMessage );
       
   190     CleanupStack::Pop( popup );
       
   191     }
       
   192 
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CAknCapServerDiscreetPopupHandler::LaunchWithParamsL
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CAknCapServerDiscreetPopupHandler::LaunchWithParamsL(  
       
   199         const RMessage2& aMessage )
       
   200     {
       
   201     TAknDiscreetPopupParamData data;
       
   202     TPckg<TAknDiscreetPopupParamData> pkg( data );
       
   203     aMessage.ReadL( 0, pkg );
       
   204 
       
   205     MEikCommandObserver* observer( NULL );
       
   206     TInt commandId( 0 );
       
   207     if ( data.Action() )
       
   208         {
       
   209         commandId = NextAvailableCommandId();
       
   210         observer = this;
       
   211         }
       
   212 
       
   213     CAknDiscreetPopupControl* popup = 
       
   214         CAknDiscreetPopupControl::NewL( 
       
   215                 ETrue,
       
   216                 data.TitleText(),
       
   217                 data.BodyText(),
       
   218                 NULL,
       
   219                 data.SkinId(),
       
   220                 data.BitmapFile(),
       
   221                 data.BitmapId(),
       
   222                 data.MaskId(),
       
   223                 data.Flags(),
       
   224                 commandId,
       
   225                 data.PopupId(),
       
   226                 observer );
       
   227     CleanupStack::PushL( popup );
       
   228     ShowPopupL( commandId,
       
   229         popup,
       
   230         data.AppUid(),
       
   231         data.ViewUid(),
       
   232         aMessage );
       
   233     CleanupStack::Pop( popup );
       
   234     }
       
   235 
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CAknCapServerDiscreetPopupHandler::HandleRequestCancellationL
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CAknCapServerDiscreetPopupHandler::HandleRequestCancellationL(  
       
   242         const RMessage2& aMessage )
       
   243     {
       
   244     TAknDiscreetPopupCancelRequestData data;
       
   245     TPckg<TAknDiscreetPopupCancelRequestData> pkg( data );
       
   246     aMessage.ReadL( 0, pkg );
       
   247     
       
   248     for ( TInt i = 0; i < iPopupDataArray.Count(); i++ )
       
   249         {
       
   250         if ( !iPopupDataArray[ i ].iMessage.IsNull()
       
   251                 && ( TUint ) iPopupDataArray[ i ].iMessage.ClientStatus() 
       
   252                 == data.StatusHandle() )
       
   253             {
       
   254             iPopupDataArray[ i ].iMessage.Complete( KErrNone );
       
   255             if ( !iPopupDataArray[ i ].iPopupControl->IsVisible() )
       
   256                 {
       
   257                 delete iPopupDataArray[ i ].iPopupControl;
       
   258                 iPopupDataArray[ i ].iPopupControl = NULL;
       
   259                 iPopupDataArray.Remove( i );
       
   260                 NotifyRunningGlobalDiscreetPopupChanged();
       
   261                 break;
       
   262                 }
       
   263             }
       
   264         }
       
   265     aMessage.Complete( KErrNone );
       
   266     }
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // CAknCapServerDiscreetPopupHandler::HandleQueryInUseRect
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 void CAknCapServerDiscreetPopupHandler::HandleQueryInUseRect( 
       
   273         const RMessage2& aMessage )
       
   274     {
       
   275     TRect rect(TRect::EUninitialized);
       
   276     if( iPopupDataArray.Count() != 0 ) 
       
   277         {
       
   278         rect = iPopupDataArray[0].iPopupControl->Rect();
       
   279         }
       
   280     
       
   281     TAknDiscreetPopupRectData data(rect);
       
   282     TPckg<TAknDiscreetPopupRectData> pkg( data );
       
   283     aMessage.WriteL( 0, pkg );
       
   284     aMessage.Complete( KErrNone );
       
   285     }
       
   286 
       
   287 // ---------------------------------------------------------------------------
       
   288 // CAknCapServerDiscreetPopupHandler::ShowPopupL
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 void CAknCapServerDiscreetPopupHandler::ShowPopupL(
       
   292         const TInt& aCommandId,
       
   293         CAknDiscreetPopupControl* aPopup,
       
   294         const TUid& aAppUid,
       
   295         const TUid& aViewUid,
       
   296         const RMessage2& aMessage )
       
   297     {
       
   298     aPopup->SetObserver( this );
       
   299 
       
   300     // Inform other popups that new popup is launched
       
   301     for ( TInt i = 0; i < iPopupDataArray.Count(); i++ )
       
   302         {
       
   303         iPopupDataArray[ i ].iPopupControl->HandleDiscreetPopupActionL( 
       
   304             CAknDiscreetPopupControl::EAknDiscreetPopupAnotherLaunched );
       
   305         }
       
   306 
       
   307     aPopup->HandleDiscreetPopupActionL( 
       
   308         CAknDiscreetPopupControl::EAknDiscreetPopupShow );
       
   309 
       
   310     // Show popup and add it to popup list
       
   311     TAknCapServerDiscreetPopupData popupData;
       
   312     popupData.iCommandId = aCommandId;
       
   313     popupData.iPopupControl = aPopup;
       
   314     popupData.iAppUid = aAppUid;
       
   315     popupData.iViewUid = aViewUid;
       
   316     popupData.iMessage = aMessage;
       
   317     iPopupDataArray.AppendL( popupData );
       
   318     NotifyRunningGlobalDiscreetPopupChanged();
       
   319     }
       
   320 
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // CAknCapServerDiscreetPopupHandler::NextAvailableCommandId
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 TInt CAknCapServerDiscreetPopupHandler::NextAvailableCommandId()
       
   327     {
       
   328     TBool idFoundInArray( ETrue );
       
   329     TInt commandId( 0 );
       
   330     
       
   331     while ( idFoundInArray )
       
   332         {
       
   333         commandId++;
       
   334         idFoundInArray = EFalse;
       
   335         for ( TInt i = 0; i < iPopupDataArray.Count(); i++ )
       
   336             {
       
   337             if ( iPopupDataArray[ i ].iCommandId == commandId )
       
   338                 {
       
   339                 idFoundInArray = ETrue;
       
   340                 break;
       
   341                 }
       
   342             }
       
   343         }
       
   344     return commandId;
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // CAknCapServerDiscreetPopupHandler::NotifyRunningGlobalDiscreetPopupChanged
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 void CAknCapServerDiscreetPopupHandler::NotifyRunningGlobalDiscreetPopupChanged()
       
   352     {
       
   353     _LIT_SECURITY_POLICY_S0( writePolicy, RProcess().SecureId() );
       
   354 	_LIT_SECURITY_POLICY_PASS( readPolicy );
       
   355     
       
   356     TInt err = RProperty::Define( KPSUidAvkonDomain, 
       
   357                                   KAknGlobalDiscreetPopupNumChanged, 
       
   358                                   RProperty::EInt, 
       
   359                                   readPolicy, 
       
   360                                   writePolicy );
       
   361 
       
   362     if( err == KErrAlreadyExists || err == KErrNone )
       
   363         {
       
   364         RProperty::Set( KPSUidAvkonDomain, KAknGlobalDiscreetPopupNumChanged, 0 );
       
   365         }            
       
   366     }
       
   367 
       
   368 // ---------------------------------------------------------------------------
       
   369 // CAknCapServerDiscreetPopupHandler::ProcessCommandL
       
   370 // ---------------------------------------------------------------------------
       
   371 //
       
   372 void CAknCapServerDiscreetPopupHandler::ProcessCommandL( TInt aCommandId )
       
   373     {
       
   374     TAknCapServerDiscreetPopupData* popupData( NULL );
       
   375     for ( TInt i = 0; i < iPopupDataArray.Count(); i++ )
       
   376         {
       
   377         if ( iPopupDataArray[ i ].iCommandId == aCommandId )
       
   378             {
       
   379             popupData = &iPopupDataArray[ i ];
       
   380             break;
       
   381             }
       
   382         }
       
   383 
       
   384     // If client has defined application uid, it should be launched when the
       
   385     // command is handled
       
   386     if ( popupData && popupData->iAppUid != TUid::Null() && iAppUi )
       
   387         {
       
   388         TApaTaskList taskList( CCoeEnv::Static()->WsSession() );
       
   389         TApaTask task = taskList.FindApp( popupData->iAppUid );
       
   390         
       
   391         if ( task.Exists() && popupData->iViewUid == TUid::Null() )
       
   392             {
       
   393             task.BringToForeground();
       
   394             }
       
   395         else
       
   396             {
       
   397             iAppUi->CreateActivateViewEventL(
       
   398             TVwsViewId( popupData->iAppUid, popupData->iViewUid ),
       
   399             TUid::Null(),
       
   400             KNullDesC8() );   
       
   401             }        
       
   402 
       
   403         }
       
   404     if ( popupData && !popupData->iMessage.IsNull() )
       
   405         {
       
   406         popupData->iMessage.Complete( KErrCompletion );
       
   407         }
       
   408     }
       
   409 
       
   410 
       
   411 // ---------------------------------------------------------------------------
       
   412 // CAknCapServerDiscreetPopupHandler::HandleControlEventL
       
   413 // ---------------------------------------------------------------------------
       
   414 //
       
   415 void CAknCapServerDiscreetPopupHandler::HandleControlEventL( 
       
   416     CCoeControl* aControl, TCoeEvent aEventType )
       
   417     {
       
   418     // Popup has been closed or cancelled - remove from array
       
   419     if ( aEventType == EEventRequestExit || aEventType == EEventRequestCancel )
       
   420         {
       
   421         for ( TInt i = 0; i < iPopupDataArray.Count(); i++ )
       
   422             {
       
   423             if ( iPopupDataArray[ i ].iPopupControl == aControl )
       
   424                 {
       
   425                 if ( !iPopupDataArray[ i ].iMessage.IsNull() )
       
   426                     {
       
   427                     iPopupDataArray[ i ].iMessage.Complete( KErrNone );
       
   428                     }
       
   429                 delete iPopupDataArray[ i ].iPopupControl;
       
   430                 iPopupDataArray[ i ].iPopupControl = NULL;
       
   431                 iPopupDataArray.Remove( i );
       
   432                 NotifyRunningGlobalDiscreetPopupChanged();
       
   433                 break;
       
   434                 }
       
   435             }
       
   436         }
       
   437     }