coreapplicationuis/SysAp/Src/CenRepObservers/sysapcenrepmsgwaitingobserver.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 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:  Message waiting CenRep-key observer implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "sysapcenrepmsgwaitingobserver.h"
       
    20 #include "SysApAppUi.h"
       
    21 #include "SysApEtelConnector.h"
       
    22 
       
    23 static const TInt KCenRepKeyUninitialized = -1;
       
    24 
       
    25 // ========================== LOCAL FUNCTIONS ================================
       
    26 static TBool BitFieldChanged( TInt aNewValue, TInt aOldValue, TInt aBitField )
       
    27     {
       
    28     return ( (aNewValue & aBitField) != (aOldValue & aBitField) );
       
    29     }
       
    30 
       
    31 // ========================== MEMBER FUNCTIONS ================================
       
    32 
       
    33 // ----------------------------------------------------------------------------
       
    34 // CSysApCenRepMsgWaitingObserver* CSysApCenRepMsgWaitingObserver::NewL()
       
    35 // ----------------------------------------------------------------------------
       
    36 //
       
    37 CSysApCenRepMsgWaitingObserver* CSysApCenRepMsgWaitingObserver::NewL( CSysApAppUi& aSysApAppUi )
       
    38     {       
       
    39     TRACES( RDebug::Print( _L("CSysApCenRepMsgWaitingObserver::NewL" ) ) );
       
    40     CSysApCenRepMsgWaitingObserver* self = new ( ELeave ) CSysApCenRepMsgWaitingObserver( aSysApAppUi );
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL();
       
    43     CleanupStack::Pop(); //self
       
    44     return self;
       
    45     }
       
    46 
       
    47 // ----------------------------------------------------------------------------
       
    48 // CSysApCenRepMsgWaitingObserver::CSysApCenRepMsgWaitingObserver( CSysApAppUi& aSysApAppUi )
       
    49 // ----------------------------------------------------------------------------
       
    50 //
       
    51 CSysApCenRepMsgWaitingObserver::CSysApCenRepMsgWaitingObserver( CSysApAppUi& aSysApAppUi  )
       
    52     : iSysApAppUi( aSysApAppUi ),
       
    53       iSession( NULL ),
       
    54       iMessageWaitingHandler( NULL ),
       
    55       iMessageWaitingDisplayStatus( 0 ),
       
    56       iOldDisplayStatus( 0 ),
       
    57       iUiReady( EFalse )
       
    58     {
       
    59     TRACES( RDebug::Print( _L("CSysApCenRepMsgWaitingObserver::CSysApCenRepMsgWaitingObserver" ) ) );
       
    60     }
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // CSysApCenRepMsgWaitingObserver::~CSysApCenRepMsgWaitingObserver()
       
    64 // ----------------------------------------------------------------------------
       
    65 //
       
    66 CSysApCenRepMsgWaitingObserver::~CSysApCenRepMsgWaitingObserver()
       
    67     {
       
    68     TRACES( RDebug::Print( _L("~CSysApCenRepMsgWaitingObserver") ) );
       
    69     if ( iMessageWaitingHandler )
       
    70         {
       
    71         iMessageWaitingHandler->StopListening();
       
    72         }
       
    73     delete iMessageWaitingHandler;
       
    74     delete iSession;
       
    75     }
       
    76 
       
    77 // ----------------------------------------------------------------------------
       
    78 // CSysApCenRepMsgWaitingObserver::ConstructL()
       
    79 // ----------------------------------------------------------------------------
       
    80 //
       
    81 void CSysApCenRepMsgWaitingObserver::ConstructL()
       
    82     {
       
    83     TRACES( RDebug::Print( _L("CSysApCenRepMsgWaitingObserver::ConstructL") ) );
       
    84     
       
    85     iSession = CRepository::NewL( KCRUidCtsyMessageWaitingIndicator );
       
    86     
       
    87     iMessageWaitingHandler = CCenRepNotifyHandler::NewL( *this, 
       
    88                                                          *iSession, 
       
    89                                                          CCenRepNotifyHandler::EIntKey, 
       
    90                                                          KCtsyMessageWaitingDisplayStatus );
       
    91 
       
    92     iMessageWaitingHandler->StartListeningL();
       
    93                                     
       
    94     TInt err = iSession->Get( KCtsyMessageWaitingDisplayStatus, iMessageWaitingDisplayStatus );
       
    95     
       
    96     if ( err == KErrNone )
       
    97         {
       
    98         TRACES( RDebug::Print( _L("CSysApCenRepMsgWaitingObserver::ConstructL(): iMessageWaitingDisplayStatus=0x%x" ),
       
    99                                iMessageWaitingDisplayStatus ) );
       
   100         
       
   101         if ( iMessageWaitingDisplayStatus == KCenRepKeyUninitialized )
       
   102             {
       
   103             iMessageWaitingDisplayStatus = 0;
       
   104             }
       
   105         }
       
   106     else
       
   107         {
       
   108         TRACES( RDebug::Print( _L("CSysApCenRepMsgWaitingObserver::ConstructL(): err=%d" ), err ) );    
       
   109         }
       
   110     }
       
   111 
       
   112 // ----------------------------------------------------------------------------
       
   113 // CSysApCenRepMsgWaitingObserver::HandleNotifyInt()
       
   114 // ----------------------------------------------------------------------------
       
   115 //
       
   116 void CSysApCenRepMsgWaitingObserver::HandleNotifyInt( TUint32 aId, TInt aNewValue )
       
   117     {
       
   118     TRACES( RDebug::Print( _L("CSysApCenRepMsgWaitingObserver::HandleNotifyInt(): aId=0x%x, aNewValue=0x%x, iUiReady=%d" ), 
       
   119                             aId, aNewValue, iUiReady ) );
       
   120     
       
   121     if ( aId == KCtsyMessageWaitingDisplayStatus )
       
   122         {
       
   123         iOldDisplayStatus = iMessageWaitingDisplayStatus;
       
   124         
       
   125         iMessageWaitingDisplayStatus = ( aNewValue == KCenRepKeyUninitialized ? 0 : aNewValue );
       
   126  
       
   127         if ( iUiReady )
       
   128             {
       
   129             TRAPD( err, UpdateMessageWaitingIndicatorsIfNeededL() );
       
   130             
       
   131             if ( err != KErrNone )
       
   132                 {
       
   133                 TRACES( RDebug::Print( _L("CSysApCenRepMsgWaitingObserver::HandleNotifyInt(): err=%d"), err ) );
       
   134                 iMessageWaitingDisplayStatus = 0; // forced update on next notification
       
   135                 }
       
   136             }
       
   137         }
       
   138     }
       
   139 
       
   140 
       
   141 // ----------------------------------------------------------------------------
       
   142 // CSysApCenRepMsgWaitingObserver::HandleNotifyError()
       
   143 // ----------------------------------------------------------------------------
       
   144 //
       
   145 void CSysApCenRepMsgWaitingObserver::HandleNotifyError( TUint32 /* aId */, TInt /* error */, CCenRepNotifyHandler* /* aHandler */ )
       
   146     {
       
   147     TRACES( RDebug::Print( _L("CSysApCenRepMsgWaitingObserver::HandleNotifyError()" ) ) );
       
   148     }
       
   149 
       
   150 // ----------------------------------------------------------------------------
       
   151 // CSysApCenRepMsgWaitingObserver::UpdateMessageWaitingIndicatorsL()
       
   152 // ----------------------------------------------------------------------------
       
   153 //
       
   154 void CSysApCenRepMsgWaitingObserver::UpdateMessageWaitingIndicatorsL()
       
   155     {
       
   156     TRACES( RDebug::Print( _L("CSysApCenRepMsgWaitingObserver::UpdateMessageWaitingIndicatorsL(): iMessageWaitingDisplayStatus=0x%x, iUiReady=%d" ), 
       
   157                             iMessageWaitingDisplayStatus, iUiReady ) );
       
   158     
       
   159     if ( !iUiReady )
       
   160         {
       
   161         iUiReady = ETrue; // start updating indicators according to notifications    
       
   162         }
       
   163     
       
   164     // Update requested from outside of this class, forcibly update all indicators
       
   165     UpdateVoiceMailWaitingIndicatorsL();
       
   166     UpdateFaxMessageWaitingIndicatorL();
       
   167     UpdateEmailMessageWaitingIndicatorL();
       
   168     UpdateOtherMessageWaitingIndicatorL();
       
   169     
       
   170     TRACES( RDebug::Print( _L("CSysApCenRepMsgWaitingObserver::UpdateMessageWaitingIndicatorsL(): end" ) ) );
       
   171     }
       
   172 
       
   173 // ----------------------------------------------------------------------------
       
   174 // CSysApCenRepMsgWaitingObserver::UpdateMessageWaitingIndicatorsIfNeededL()
       
   175 // ----------------------------------------------------------------------------
       
   176 //
       
   177 void CSysApCenRepMsgWaitingObserver::UpdateMessageWaitingIndicatorsIfNeededL() const
       
   178     {
       
   179     if ( BitFieldChanged( iMessageWaitingDisplayStatus, iOldDisplayStatus, RMobilePhone::KDisplayVoicemailActive|RMobilePhone::KDisplayAuxVoicemailActive ) )
       
   180         {
       
   181         UpdateVoiceMailWaitingIndicatorsL();
       
   182         }
       
   183     
       
   184     if ( BitFieldChanged( iMessageWaitingDisplayStatus, iOldDisplayStatus, RMobilePhone::KDisplayFaxActive ) )
       
   185         {
       
   186         UpdateFaxMessageWaitingIndicatorL();
       
   187         }
       
   188     
       
   189     if ( BitFieldChanged( iMessageWaitingDisplayStatus, iOldDisplayStatus, RMobilePhone::KDisplayEmailActive ) )
       
   190         {
       
   191         UpdateEmailMessageWaitingIndicatorL();
       
   192         }
       
   193         
       
   194     if ( BitFieldChanged( iMessageWaitingDisplayStatus, iOldDisplayStatus, RMobilePhone::KDisplayOtherActive ) )
       
   195         {
       
   196         UpdateOtherMessageWaitingIndicatorL();
       
   197         }
       
   198     }
       
   199 
       
   200 // ----------------------------------------------------------------------------
       
   201 // CSysApCenRepMsgWaitingObserver::UpdateFaxMessageWaitingIndicatorL()
       
   202 // ----------------------------------------------------------------------------
       
   203 //
       
   204 void CSysApCenRepMsgWaitingObserver::UpdateFaxMessageWaitingIndicatorL() const
       
   205     {
       
   206     if ( iMessageWaitingDisplayStatus & RMobilePhone::KDisplayFaxActive )
       
   207         {
       
   208         iSysApAppUi.SetIndicatorStateL( EAknIndicatorFaxMessage, EAknIndicatorStateOn );    
       
   209         }
       
   210     else
       
   211         {
       
   212         iSysApAppUi.SetIndicatorStateL( EAknIndicatorFaxMessage, EAknIndicatorStateOff );
       
   213         }        
       
   214     }
       
   215 
       
   216 // ----------------------------------------------------------------------------
       
   217 // CSysApCenRepMsgWaitingObserver::UpdateEmailMessageWaitingIndicatorL()
       
   218 // ----------------------------------------------------------------------------
       
   219 //
       
   220 void CSysApCenRepMsgWaitingObserver::UpdateEmailMessageWaitingIndicatorL() const
       
   221     {
       
   222     
       
   223     if ( iMessageWaitingDisplayStatus & RMobilePhone::KDisplayEmailActive )
       
   224         {
       
   225         iSysApAppUi.SetIndicatorStateL( EAknIndicatorRemoteMailboxEmailMessage, EAknIndicatorStateOn );
       
   226         }
       
   227     else
       
   228         {
       
   229         iSysApAppUi.SetIndicatorStateL( EAknIndicatorRemoteMailboxEmailMessage, EAknIndicatorStateOff );    
       
   230         }        
       
   231     }
       
   232 
       
   233 // ----------------------------------------------------------------------------
       
   234 // CSysApCenRepMsgWaitingObserver::UpdateOtherMessageWaitingIndicatorL()
       
   235 // ----------------------------------------------------------------------------
       
   236 //    
       
   237 void CSysApCenRepMsgWaitingObserver::UpdateOtherMessageWaitingIndicatorL() const   
       
   238     {
       
   239     if ( iMessageWaitingDisplayStatus & RMobilePhone::KDisplayOtherActive )
       
   240         {
       
   241         iSysApAppUi.SetIndicatorStateL( EAknIndicatorOtherMessage, EAknIndicatorStateOn );
       
   242         }
       
   243     else
       
   244         {
       
   245         iSysApAppUi.SetIndicatorStateL( EAknIndicatorOtherMessage, EAknIndicatorStateOff );
       
   246         }        
       
   247     }
       
   248 
       
   249 // ----------------------------------------------------------------------------
       
   250 // CSysApCenRepMsgWaitingObserver::UpdateVoiceMailWaitingIndicatorsL()
       
   251 // ----------------------------------------------------------------------------
       
   252 //
       
   253 void CSysApCenRepMsgWaitingObserver::UpdateVoiceMailWaitingIndicatorsL() const
       
   254     {
       
   255     
       
   256     switch( ResolveVoiceMailState() )
       
   257         {
       
   258         case EWaiting:
       
   259             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnLine1, EAknIndicatorStateOff );
       
   260             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnLine2, EAknIndicatorStateOff );
       
   261             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnBothLines, EAknIndicatorStateOff );
       
   262             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaiting, EAknIndicatorStateOn );
       
   263             break;
       
   264         case EWaitingOnLine1:
       
   265             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnLine2, EAknIndicatorStateOff );
       
   266             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnBothLines, EAknIndicatorStateOff );
       
   267             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaiting, EAknIndicatorStateOff );
       
   268             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnLine1, EAknIndicatorStateOn );
       
   269             break;
       
   270         case EWaitingOnLine2:
       
   271             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnLine1, EAknIndicatorStateOff );
       
   272             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnBothLines, EAknIndicatorStateOff );
       
   273             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaiting, EAknIndicatorStateOff );
       
   274             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnLine2, EAknIndicatorStateOn );
       
   275             break;
       
   276         case EWaitingOnBothLines:
       
   277             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnLine1, EAknIndicatorStateOff );
       
   278             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnLine2, EAknIndicatorStateOff );
       
   279             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaiting, EAknIndicatorStateOff );
       
   280             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnBothLines, EAknIndicatorStateOn );
       
   281             break;
       
   282         case ENoVoiceMails:
       
   283             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnLine1, EAknIndicatorStateOff );
       
   284             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnLine2, EAknIndicatorStateOff );
       
   285             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaitingOnBothLines, EAknIndicatorStateOff );
       
   286             iSysApAppUi.SetIndicatorStateL( EAknIndicatorVoiceMailWaiting, EAknIndicatorStateOff );
       
   287             break;
       
   288         default:
       
   289             break;
       
   290         }
       
   291     
       
   292     }
       
   293     
       
   294 // ---------------------------------------------------------------------------
       
   295 // CSysApCenRepMsgWaitingObserver::ResolveVoiceMailState()
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 CSysApCenRepMsgWaitingObserver::TVoiceMailWaitingState CSysApCenRepMsgWaitingObserver::ResolveVoiceMailState() const     
       
   299     {
       
   300     TVoiceMailWaitingState voiceMailState(ENoVoiceMails);
       
   301     
       
   302     TBool alsSupported(EFalse);
       
   303     
       
   304     CSysApEtelConnector* etelConnector = iSysApAppUi.EtelConnector();
       
   305     
       
   306     if ( etelConnector )
       
   307         {
       
   308         alsSupported = etelConnector->AlsSupported();
       
   309         }
       
   310     
       
   311     if ( alsSupported ) // line specific indicator is shown if ALS is supported
       
   312         {
       
   313         if ( ( iMessageWaitingDisplayStatus & RMobilePhone::KDisplayAuxVoicemailActive )
       
   314              && ( iMessageWaitingDisplayStatus & RMobilePhone::KDisplayVoicemailActive ) )
       
   315             {
       
   316             voiceMailState = EWaitingOnBothLines;
       
   317             }
       
   318         else if ( iMessageWaitingDisplayStatus & RMobilePhone::KDisplayVoicemailActive )
       
   319             {
       
   320             voiceMailState = EWaitingOnLine1;
       
   321             }
       
   322         else if ( iMessageWaitingDisplayStatus & RMobilePhone::KDisplayAuxVoicemailActive )
       
   323             {
       
   324             voiceMailState = EWaitingOnLine2;
       
   325             }
       
   326         }
       
   327     else
       
   328         {
       
   329         if ( iMessageWaitingDisplayStatus & RMobilePhone::KDisplayVoicemailActive )
       
   330             {
       
   331             voiceMailState = EWaiting;
       
   332             }
       
   333         }
       
   334 
       
   335     return voiceMailState;
       
   336     }
       
   337     
       
   338 // End of File
       
   339