messagingappbase/msgavkon/msgindicatorplugin/src/MsgWaitingObserver.cpp
changeset 79 2981cb3aa489
equal deleted inserted replaced
25:84d9eb65b26f 79:2981cb3aa489
       
     1 /*
       
     2 * Copyright (c) 2006-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:   MsgIndicatorPlugin plugin implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <etelmm.h>
       
    21 #include <MessagingDomainCRKeys.h>
       
    22 #include "MsgWaitingObserver.h"
       
    23 #include "msgindicatorpluginlog.h"
       
    24 #include "msgindicatorpluginimplementation.h"
       
    25 	
       
    26 // ---------------------------------------------------------------------------
       
    27 // CMsgIndicatorPluginImplementation::CMsgIndicatorPluginImplementation
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CWaitingObserver::CWaitingObserver( RMobilePhone &aMobilePhone,
       
    31     CMsgIndicatorPluginImplementation& iIndicatorPlugin ) :
       
    32     CActive( EPriorityNormal ),
       
    33 	iChangeNotifySubscribed( EFalse ),
       
    34     iMobilePhone( aMobilePhone ),
       
    35     iMsgWaiting(),
       
    36   	iMsgWaitingPckg( iMsgWaiting ),
       
    37   	iIndicatorPlugin(iIndicatorPlugin)
       
    38     {
       
    39     CActiveScheduler::Add( this );
       
    40     }
       
    41 // -----------------------------------------------------------------------------
       
    42 // CWaitingObserver::NewL
       
    43 // Two-phased constructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CWaitingObserver* CWaitingObserver::NewL( RMobilePhone &aMobilePhone,
       
    47                             CMsgIndicatorPluginImplementation& iIndicatorPlugin )
       
    48     {
       
    49     CWaitingObserver* self = new (ELeave) CWaitingObserver( aMobilePhone, iIndicatorPlugin);
       
    50 
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop( self );
       
    54 
       
    55     return self;
       
    56     }
       
    57 // ---------------------------------------------------------------------------
       
    58 // CMsgIndicatorPluginImplementation::ConstructL
       
    59 // Symbian 2nd phase constructor can leave.
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void CWaitingObserver::ConstructL()
       
    63     {
       
    64     MSGPLUGINLOGGER_WRITE_FORMAT( "::ConstructL: this 0x%x", 
       
    65     	this );
       
    66 
       
    67     User::LeaveIfError( iTelServer.Connect() );
       
    68 
       
    69     User::LeaveIfError( iTelServer.GetPhoneInfo( 0, iPhoneInfo ) );
       
    70         
       
    71     User::LeaveIfError( iMobilePhone.Open( iTelServer, iPhoneInfo.iName ) );   
       
    72 
       
    73     iMobilePhone.GetIccMessageWaitingIndicators( iStatus, iMsgWaitingPckg );
       
    74     SetActive();
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CWaitingObserver::~CWaitingObserver()
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 CWaitingObserver::~CWaitingObserver()
       
    82     {
       
    83     MSGPLUGINLOGGER_WRITE_FORMAT( "Destructor: this 0x%x", 
       
    84     	this );
       
    85     Cancel();
       
    86     iTelServer.Close();
       
    87     }
       
    88     
       
    89 // ---------------------------------------------------------------------------
       
    90 // CWaitingObserver::RunL()
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CWaitingObserver::RunL()
       
    94     {
       
    95     TInt err = iStatus.Int();
       
    96     MSGPLUGINLOGGER_WRITE_FORMAT("RunL(): err: %d", err);    
       
    97     // subscribe for notifications
       
    98 
       
    99     if ( err == KErrNone )
       
   100         {
       
   101         UpdateIndicatorStatusL();
       
   102         }
       
   103         
       
   104     iMobilePhone.NotifyIccMessageWaitingIndicatorsChange( iStatus, iMsgWaitingPckg );
       
   105     SetActive();
       
   106 
       
   107     // get-request completed, DoCancel() must now cancel notify request
       
   108     iChangeNotifySubscribed = ETrue; 
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CWaitingObserver::DoCancel()
       
   113 // ---------------------------------------------------------------------------
       
   114 //    
       
   115 void CWaitingObserver::DoCancel()
       
   116     {
       
   117     if ( iChangeNotifySubscribed )
       
   118         {
       
   119         iMobilePhone.CancelAsyncRequest( EMobilePhoneNotifyIccMessageWaitingIndicatorsChange );  
       
   120         }
       
   121     else
       
   122         {
       
   123         iMobilePhone.CancelAsyncRequest( EMobilePhoneGetIccMessageWaitingIndicators );    
       
   124         }
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CWaitingObserver::GetMsgCount(const TIndicatorMessageType aMsgType)
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 TInt CWaitingObserver::GetMsgCount( const TIndicatorMessageType aMsgType )
       
   132     {
       
   133     TInt msgCount = 0;
       
   134     MSGPLUGINLOGGER_WRITE( "GetMsgCount()");
       
   135     switch( aMsgType )
       
   136         {
       
   137     	case EIndicatorMessageTypeFax:
       
   138     		msgCount = iMsgWaiting.iFaxMsgs;			
       
   139         	MSGPLUGINLOGGER_WRITE_FORMAT( "GetMsgCount->FAX %d", msgCount );
       
   140         	MSGPLUGINLOGGER_WRITE_FORMAT( "GetMsgCount->FAX %d", iMsgWaiting.iFaxMsgs );
       
   141     		break;
       
   142     		
       
   143     	case EIndicatorMessageTypeVMLine1:
       
   144     		msgCount = iMsgWaiting.iVoiceMsgs;
       
   145         	MSGPLUGINLOGGER_WRITE_FORMAT( "GetMsgCount->LINE1 %d", msgCount );
       
   146         	MSGPLUGINLOGGER_WRITE_FORMAT( "GetMsgCount->LINE1 %d", iMsgWaiting.iVoiceMsgs );
       
   147     		break;
       
   148     		
       
   149     	case EIndicatorMessageTypeVMLine2:
       
   150     		msgCount = iMsgWaiting.iAuxVoiceMsgs;
       
   151         	MSGPLUGINLOGGER_WRITE_FORMAT( "GetMsgCount->LINE2 %d", msgCount );
       
   152         	MSGPLUGINLOGGER_WRITE_FORMAT( "GetMsgCount->LINE2 %d", iMsgWaiting.iAuxVoiceMsgs );
       
   153     		break;  
       
   154         
       
   155     	default:
       
   156     		break;	    	
       
   157         }
       
   158     MSGPLUGINLOGGER_WRITE_FORMAT( "GetMsgCount->RETURN %d", msgCount );	    
       
   159     return msgCount;
       
   160     }
       
   161     
       
   162 // ---------------------------------------------------------------------------
       
   163 // CWaitingObserver::UpdateIndicatorStatusL()
       
   164 // ---------------------------------------------------------------------------
       
   165 //	    	    
       
   166 void CWaitingObserver::UpdateIndicatorStatusL()
       
   167 	{
       
   168     MSGPLUGINLOGGER_WRITE( "UpdateIndicatorStatus()");
       
   169 
       
   170     MSGPLUGINLOGGER_WRITE_FORMAT( "::UpdateIndicatorStatus: Voice mail line 1 count %d", iMsgWaiting.iVoiceMsgs );
       
   171     MSGPLUGINLOGGER_WRITE_FORMAT( "::UpdateIndicatorStatus: Fax count %d", iMsgWaiting.iFaxMsgs );
       
   172 
       
   173     iMsgWaiting = iMsgWaitingPckg();
       
   174     if(!CheckSupressNotificationSettingL())
       
   175         {
       
   176     	if(iMsgWaiting.iDisplayStatus & RMobilePhone::KDisplayVoicemailActive)
       
   177         	{
       
   178         	if ( !iIndicatorPlugin.IsALSSupported() )
       
   179             	{
       
   180             	MSGPLUGINLOGGER_WRITE( "iIndicatorPlugin.UpdateTextL( EAknIndicatorVoiceMailWaiting )");
       
   181             	iIndicatorPlugin.UpdateL( EAknIndicatorVoiceMailWaiting );
       
   182             	}
       
   183         	else
       
   184             	{
       
   185             	MSGPLUGINLOGGER_WRITE( "iIndicatorPlugin.UpdateTextL( EAknIndicatorVoiceMailWaitingOnLine1 )");
       
   186             	iIndicatorPlugin.UpdateL( EAknIndicatorVoiceMailWaitingOnLine1 );
       
   187             	}
       
   188         	}
       
   189         }
       
   190     if ( iMsgWaiting.iDisplayStatus & RMobilePhone::KDisplayAuxVoicemailActive )
       
   191         {
       
   192         MSGPLUGINLOGGER_WRITE( "iIndicatorPlugin.UpdateTextL( EAknIndicatorVoiceMailWaitingOnLine2 )");
       
   193     	iIndicatorPlugin.UpdateL( EAknIndicatorVoiceMailWaitingOnLine2 );
       
   194         }
       
   195     if ( iMsgWaiting.iDisplayStatus & RMobilePhone::KDisplayFaxActive) 
       
   196         {
       
   197         MSGPLUGINLOGGER_WRITE( "iIndicatorPlugin.UpdateTextL( EAknIndicatorFaxMessage )");
       
   198         iIndicatorPlugin.UpdateL( EAknIndicatorFaxMessage );
       
   199         }
       
   200 	}	    
       
   201 // -------------------------------------------------------------------
       
   202 // Check the KMuiuSupressAllNotificationConfiguration value
       
   203 // -------------------------------------------------------------------
       
   204 //
       
   205 TBool CWaitingObserver::CheckSupressNotificationSettingL()
       
   206 {
       
   207     TBool result = EFalse; 
       
   208     TInt value = 0;
       
   209     CRepository* repository = NULL;
       
   210    
       
   211    TRAPD( err, repository = CRepository::NewL( KCRUidMuiuMessagingConfiguration ) );
       
   212    if( err == KErrNone && repository != NULL )
       
   213        {
       
   214        CleanupStack::PushL( repository ); 
       
   215        err = repository->Get( KMuiuSupressAllNotificationConfiguration, value );
       
   216        
       
   217        if(err == KErrNone && (value & KMuiuNotificationSupressedForVoiceMail ))
       
   218            {
       
   219            result = ETrue;
       
   220            }
       
   221         } 
       
   222        MSGPLUGINLOGGER_WRITE_FORMAT( "CWaitingObserver:  SupressNotification %d", result );
       
   223        CleanupStack::PopAndDestroy( repository );
       
   224        return result;
       
   225 }	    
       
   226 //  End of File