uifw/AvKon/src/aknstatuspanedatasubscriber.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Implementation for the status pane data subscriber, which
       
    15 *                updates the data of system controlled sub-panes when
       
    16 *                their state changes.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // SYSTEM INCLUDE FILES
       
    22 #include <e32property.h>
       
    23 #include <AknCapServerClient.h>
       
    24 #include <eikapp.h>
       
    25 #include <eikappui.h>
       
    26 #include <coemain.h>
       
    27 
       
    28 // USER INCLUDE FILES
       
    29 #include "aknstatuspanedatasubscriber.h"
       
    30 #include "avkoninternalpskeys.h"
       
    31 #include "aknstatuspanedata.h"
       
    32 #include "aknstatuspanedataobserver.h"
       
    33 #include "AknSgcc.h"
       
    34 #include "AknDef.h"
       
    35 #include "AknIncallStatusBubble.h"
       
    36 
       
    37 class CAknStatusPaneSubscriberData : public CBase
       
    38     {
       
    39 public:
       
    40     CAknStatusPaneSubscriberData() {};
       
    41     ~CAknStatusPaneSubscriberData() {};
       
    42 public:
       
    43     TAknStatusPaneStateData iData;
       
    44     };
       
    45 
       
    46 /**
       
    47  * Class to monitor window server events.
       
    48  */
       
    49 NONSHARABLE_CLASS( CAknStatusPaneDataSubscriber::TWsEventObserver )
       
    50     : public MCoeMessageMonitorObserver
       
    51     {
       
    52     public:
       
    53 
       
    54         /**
       
    55          * Constructor.
       
    56          * @param  aSubs  Reference to subscriber.
       
    57          */
       
    58         TWsEventObserver( CAknStatusPaneDataSubscriber& aSubs );
       
    59 
       
    60     public:
       
    61 
       
    62         /**
       
    63          * From @c MCoeMessageMonitorObserver, this method is called
       
    64          * when a window server event is received.
       
    65          * @param  aEvent  received event.
       
    66          */
       
    67         virtual void MonitorWsMessage( const TWsEvent& aEvent );
       
    68 
       
    69     private:
       
    70 
       
    71         /** Now owned. Reference to subscriber.*/
       
    72         CAknStatusPaneDataSubscriber& iSubs;
       
    73     };
       
    74 
       
    75 // ============================ MEMBER FUNCTIONS ===============================
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CAknStatusPaneDataSubscriber::NewL
       
    79 // (other items were commented in a header).
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 EXPORT_C CAknStatusPaneDataSubscriber* CAknStatusPaneDataSubscriber::NewL()
       
    83     {
       
    84     CAknStatusPaneDataSubscriber* self =
       
    85         new (ELeave) CAknStatusPaneDataSubscriber();
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     CleanupStack::Pop( self );
       
    89     return self;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CAknStatusPaneDataSubscriber::ConstructL
       
    94 // (other items were commented in a header).
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CAknStatusPaneDataSubscriber::ConstructL()
       
    98     {
       
    99     // We create an unique id for this container, use app uid for that.
       
   100     CEikonEnv* eikEnv = CEikonEnv::Static();
       
   101     CEikAppUi* app = eikEnv->EikAppUi();
       
   102     if ( app )
       
   103         {
       
   104         CEikApplication* application = app->Application();
       
   105         if ( application )
       
   106             {
       
   107             iSubscriberId = application->AppDllUid().iUid;
       
   108             }
       
   109         }
       
   110 
       
   111     User::LeaveIfError( iProperty.Attach( KPSUidAvkonInternal,
       
   112                                           KAknStatusPaneSystemData) );
       
   113     DoSubscribe();
       
   114     iStatusPaneStateData = new (ELeave) CAknStatusPaneSubscriberData();
       
   115 
       
   116     iObserver = new (ELeave) TWsEventObserver( *this );
       
   117     eikEnv->AddMessageMonitorObserverL( *iObserver );
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CAknStatusPaneDataSubscriber::CAknStatusPaneDataSubscriber
       
   122 // C++ default constructor can NOT contain any code, that
       
   123 // might leave.
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 CAknStatusPaneDataSubscriber::CAknStatusPaneDataSubscriber()
       
   127     :CActive( EPriorityStandard )
       
   128     {
       
   129     CActiveScheduler::Add( this );
       
   130     iRefreshLevel = ERefreshLevelMedium;
       
   131     }
       
   132 
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // Destructor
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 CAknStatusPaneDataSubscriber::~CAknStatusPaneDataSubscriber()
       
   139     {
       
   140     CEikonEnv* eikEnv = CEikonEnv::Static();
       
   141     if ( eikEnv && iObserver )
       
   142         {
       
   143         eikEnv->RemoveMessageMonitorObserver( *iObserver );
       
   144         }
       
   145     delete iObserver;
       
   146 
       
   147     Cancel();
       
   148     iProperty.Close();
       
   149     iObservers.Close();
       
   150     delete iStatusPaneStateData;
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CAknStatusPaneDataSubscriber::RefreshDataL
       
   155 // (other items were commented in a header).
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 EXPORT_C void CAknStatusPaneDataSubscriber::RefreshDataL()
       
   159     {
       
   160     // If call bubble is visible refresh is needed.
       
   161     if ( iRefreshLevel == ERefreshLevelNone &&
       
   162          !( iStatusPaneStateData->iData.iIndicatorState.iIncallBubbleFlags
       
   163                 & CIncallStatusBubble::ESBVisible ) )
       
   164         {
       
   165         return;
       
   166         }
       
   167 
       
   168     TAknStatusPaneStateData::TAknStatusPaneStateDataPckg
       
   169         statusPaneStateDataPckg( iStatusPaneStateData->iData );
       
   170 
       
   171     TInt err = iProperty.Get( KPSUidAvkonInternal,
       
   172                               KAknStatusPaneSystemData,
       
   173                               statusPaneStateDataPckg );
       
   174 
       
   175     if ( err == KErrNone )
       
   176         {
       
   177         TInt count = iObservers.Count();
       
   178         for( TInt i = 0; i < count; i++ )
       
   179             {
       
   180             TRAP_IGNORE( iObservers[i]->HandleUpdateL(
       
   181                                             iStatusPaneStateData->iData ) );
       
   182             }
       
   183         }
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CAknStatusPaneDataSubscriber::SetAlwaysBackground
       
   188 // (other items were commented in a header).
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 EXPORT_C void CAknStatusPaneDataSubscriber::SetAlwaysBackground(
       
   192     TBool aAlwaysBackground )
       
   193     {
       
   194     iAlwaysBackground = aAlwaysBackground;
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CAknStatusPaneDataSubscriber::HandleGainingForeground
       
   199 // (other items were commented in a header).
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 EXPORT_C void CAknStatusPaneDataSubscriber::HandleGainingForeground()
       
   203     {
       
   204     iIsForeground = ETrue;
       
   205     
       
   206     // We let server side to know that now we are in the foreground.
       
   207     RAknUiServer* client = CAknSgcClient::AknSrv();
       
   208     if ( client && client->Handle() && !iAlwaysBackground )
       
   209         {
       
   210         client->SetFgSpDataSubscriberId( iSubscriberId );
       
   211         }
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CAknStatusPaneDataSubscriber::HandleLosingForeground
       
   216 // (other items were commented in a header).
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 EXPORT_C void CAknStatusPaneDataSubscriber::HandleLosingForeground()
       
   220     {
       
   221     iIsForeground = EFalse;
       
   222     
       
   223     // Data must be refreshed to hide the incall status bubble.
       
   224     TRAP_IGNORE( RefreshDataL() );
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CAknStatusPaneDataSubscriber::DoSubscribe
       
   229 // (other items were commented in a header).
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void CAknStatusPaneDataSubscriber::DoSubscribe()
       
   233     {
       
   234     if ( !IsActive() )
       
   235         {
       
   236         iProperty.Subscribe( iStatus );
       
   237         SetActive();
       
   238         }
       
   239     }
       
   240 
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CAknStatusPaneDataSubscriber::RunL
       
   244 // (other items were commented in a header).
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void CAknStatusPaneDataSubscriber::RunL()
       
   248     {
       
   249     TBool noError = (iStatus == KErrNone);
       
   250     
       
   251     // Re-subscribe immediately to prevent missing changes.
       
   252     DoSubscribe();
       
   253     
       
   254     if (noError)
       
   255         {
       
   256         TAknStatusPaneStateData::TAknStatusPaneStateDataPckg
       
   257             statusPaneStateDataPckg( iStatusPaneStateData->iData );
       
   258 
       
   259         TInt err = iProperty.Get( KPSUidAvkonInternal,
       
   260                                   KAknStatusPaneSystemData,
       
   261                                   statusPaneStateDataPckg );
       
   262 
       
   263         if ( err == KErrNone )
       
   264             {
       
   265             SetForegroundSubscriberId(
       
   266                 iStatusPaneStateData->iData.iForegroundSubscriberId );
       
   267 
       
   268             TInt count = iObservers.Count();
       
   269             for(TInt i = 0; i < count; i++)
       
   270                 {
       
   271                 TRAP_IGNORE( iObservers[i]->HandleUpdateL(
       
   272                                                 iStatusPaneStateData->iData ) );
       
   273                 }
       
   274             }
       
   275         }
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CAknStatusPaneDataSubscriber::DoCancel
       
   280 // (other items were commented in a header).
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CAknStatusPaneDataSubscriber::DoCancel()
       
   284     {
       
   285     iProperty.Cancel();
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CAknStatusPaneDataSubscriber::RunError
       
   290 // (other items were commented in a header).
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 TInt CAknStatusPaneDataSubscriber::RunError( TInt /*aError*/ )
       
   294     {
       
   295     DoSubscribe();
       
   296     return KErrNone;
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CAknStatusPaneDataSubscriber::ForegroundSubscriberId
       
   301 // (other items were commented in a header).
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 TInt CAknStatusPaneDataSubscriber::ForegroundSubscriberId() const
       
   305     {
       
   306     return iStatusPaneStateData->iData.iForegroundSubscriberId;
       
   307     }
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CAknStatusPaneDataSubscriber::SetForegroundSubscriberId
       
   311 // (other items were commented in a header).
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 void CAknStatusPaneDataSubscriber::SetForegroundSubscriberId( TInt aId )
       
   315     {
       
   316     iStatusPaneStateData->iData.iForegroundSubscriberId = aId;
       
   317     if ( aId == iSubscriberId )
       
   318         {
       
   319         SetRefreshLevel( ERefreshLevelHigh, EFalse );
       
   320         }
       
   321     else
       
   322         {
       
   323         SetRefreshLevel( ERefreshLevelMedium, EFalse );
       
   324         }
       
   325     }
       
   326 
       
   327 // -----------------------------------------------------------------------------
       
   328 // CAknStatusPaneDataSubscriber::SubscriberId
       
   329 // (other items were commented in a header).
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 TInt CAknStatusPaneDataSubscriber::SubscriberId() const
       
   333     {
       
   334     return iSubscriberId;
       
   335     }
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // CAknStatusPaneDataSubscriber::IsBackground
       
   339 // (other items were commented in a header).
       
   340 // -----------------------------------------------------------------------------
       
   341 //
       
   342 TBool CAknStatusPaneDataSubscriber::IsBackground() const
       
   343     {
       
   344     if ( !iIsForeground || iAlwaysBackground )
       
   345         {
       
   346         return ETrue;
       
   347         }
       
   348     else
       
   349         {
       
   350         return EFalse;
       
   351         }
       
   352     }
       
   353 
       
   354 // -----------------------------------------------------------------------------
       
   355 // CAknStatusPaneDataSubscriber::AddObserver
       
   356 // (other items were commented in a header).
       
   357 // -----------------------------------------------------------------------------
       
   358 void CAknStatusPaneDataSubscriber::AddObserver(
       
   359     MAknStatusPaneDataObserver* aObserver )
       
   360     {
       
   361     TRAP_IGNORE( iObservers.AppendL( aObserver ) );
       
   362     }
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // CAknStatusPaneDataSubscriber::RemoveObserver
       
   366 // (other items were commented in a header).
       
   367 // -----------------------------------------------------------------------------
       
   368 void CAknStatusPaneDataSubscriber::RemoveObserver(
       
   369     MAknStatusPaneDataObserver* aObserver )
       
   370     {
       
   371     TInt count = iObservers.Count();
       
   372     for( TInt i = 0; i < count; i++ )
       
   373         {
       
   374         if ( iObservers[i] == aObserver )
       
   375             {
       
   376             iObservers.Remove( i );
       
   377             iObservers.Compress();
       
   378             break;
       
   379             }
       
   380         }
       
   381     }
       
   382 
       
   383 // -----------------------------------------------------------------------------
       
   384 // CAknStatusPaneDataSubscriber::SetRefreshLevel
       
   385 // (other items were commented in a header).
       
   386 // -----------------------------------------------------------------------------
       
   387 EXPORT_C void CAknStatusPaneDataSubscriber::SetRefreshLevel(
       
   388     TInt aLevel,
       
   389     TBool aForced )
       
   390     {
       
   391     TInt oldLevel = iRefreshLevel;
       
   392     if ( iForcedRefreshLevel )
       
   393         {
       
   394         if ( aForced )
       
   395             {
       
   396             iRefreshLevel = aLevel;
       
   397             }
       
   398         }
       
   399     else
       
   400         {
       
   401         iRefreshLevel = aLevel;
       
   402         iForcedRefreshLevel = aForced;
       
   403         }
       
   404 
       
   405     if ( aLevel == ERefreshLevelNone )
       
   406         {
       
   407         // Refresh the data for the observers first, required in case the
       
   408         // incall status bubble is shown and status pane is made non-visible.
       
   409         TRAP_IGNORE( RefreshDataL() );
       
   410         Cancel();
       
   411         }
       
   412     else if ( oldLevel == ERefreshLevelNone &&
       
   413               iRefreshLevel != ERefreshLevelNone )
       
   414         {
       
   415         DoSubscribe();
       
   416         TRAP_IGNORE( RefreshDataL() );
       
   417         }
       
   418     }
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // CAknStatusPaneDataSubscriber::RefreshLevel
       
   422 // (other items were commented in a header).
       
   423 // -----------------------------------------------------------------------------
       
   424 EXPORT_C TInt CAknStatusPaneDataSubscriber::RefreshLevel()
       
   425     {
       
   426     return iRefreshLevel;
       
   427     }
       
   428 
       
   429 // Implementation of TWsEventObserver:
       
   430 
       
   431 // -----------------------------------------------------------------------------
       
   432 // CAknStatusPaneDataSubscriber::TWsEventObserver::TWsEventObserver
       
   433 // (other items were commented in a header).
       
   434 // -----------------------------------------------------------------------------
       
   435 //
       
   436 CAknStatusPaneDataSubscriber::TWsEventObserver::TWsEventObserver(
       
   437     CAknStatusPaneDataSubscriber& aSubs )
       
   438     : iSubs( aSubs )
       
   439     {
       
   440     }
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // CAknStatusPaneDataSubscriber::TWsEventObserver::MonitorWsMessage
       
   444 // (other items were commented in a header).
       
   445 // -----------------------------------------------------------------------------
       
   446 //
       
   447 void CAknStatusPaneDataSubscriber::TWsEventObserver::MonitorWsMessage(
       
   448     const TWsEvent& aEvent )
       
   449     {
       
   450     switch ( aEvent.Type() )
       
   451         {
       
   452         case KAknFullOrPartialForegroundGained:
       
   453             iSubs.HandleGainingForeground();
       
   454             break;
       
   455 
       
   456         case KAknFullOrPartialForegroundLost:
       
   457             iSubs.HandleLosingForeground();
       
   458             break;
       
   459 
       
   460         default:
       
   461             break;
       
   462         }
       
   463     }
       
   464 
       
   465 //  End of File