messagingappbase/ncnlist/src/CNcnNotifier.cpp
changeset 0 72b543305e3a
child 12 caea42e26caa
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2004 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:   Methods for CNcnNotifier class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <centralrepository.h>
       
    22 #include    <coreapplicationuisdomainpskeys.h>
       
    23 #include    <sacls.h>
       
    24 #include    <MessagingDomainCRKeys.h>
       
    25 
       
    26 #include    "CNcnNotifier.h"
       
    27 #include    "NcnModelBase.h"
       
    28 #include    "MNcnUI.h"
       
    29 #include 	"MNcnMsgWaitingManager.h"
       
    30 
       
    31 
       
    32 // ================= LOCAL CONSTANTS =======================
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 
       
    36 // ----------------------------------------------------
       
    37 //  CNcnNotifier::CNcnNotifier
       
    38 // ----------------------------------------------------
       
    39 //
       
    40 CNcnNotifier::CNcnNotifier( MNcnUI& aNcnUI, CNcnModelBase& aModel ) :
       
    41     iNcnUI( aNcnUI ),
       
    42     iModel( aModel )
       
    43     {
       
    44     // clear notification amount array
       
    45     for( int i = 0; i < ENcnNoNotification; i++ )
       
    46         {
       
    47         iNotificationAmounts[ i ] = 0;
       
    48         }
       
    49     }
       
    50 
       
    51 // ----------------------------------------------------
       
    52 //  CNcnNotifier::ConstructL
       
    53 // ----------------------------------------------------
       
    54 //
       
    55 void CNcnNotifier::ConstructL()
       
    56     {
       
    57     
       
    58        TInt state; 
       
    59        CRepository* repository = NULL;
       
    60        iDisplayLightstate = 63;
       
    61        TRAPD( err, repository = CRepository::NewL( KCRUidMuiuMessagingConfiguration ) );
       
    62        if( err == KErrNone && repository != NULL )
       
    63            {
       
    64            CleanupStack::PushL( repository ); 
       
    65            
       
    66            err = repository->Get( KMuiuDisplayLightsConfiguration, state );
       
    67            NCN_RDEBUG_INT( _L("CNcnNotifier::ConstructL() -  iDisplayLightstate: %d"), state );
       
    68            if(err == KErrNone)
       
    69                iDisplayLightstate = state;
       
    70            }
       
    71        CleanupStack::PopAndDestroy( repository );
       
    72     
       
    73     }
       
    74     
       
    75 // ----------------------------------------------------
       
    76 //  CNcnNotifier::NewL
       
    77 // ----------------------------------------------------
       
    78 //
       
    79 CNcnNotifier* CNcnNotifier::NewL( MNcnUI& aNcnUI, CNcnModelBase& aModel )
       
    80     {
       
    81     CNcnNotifier* self = new (ELeave) CNcnNotifier( aNcnUI, aModel );
       
    82     
       
    83     CleanupStack::PushL( self );
       
    84     self->ConstructL();
       
    85     CleanupStack::Pop( self );
       
    86     
       
    87     return self;
       
    88     }
       
    89 
       
    90 // ----------------------------------------------------
       
    91 //  CNcnNotifier::~CNcnNotifier
       
    92 // ----------------------------------------------------
       
    93 //
       
    94 CNcnNotifier::~CNcnNotifier()
       
    95     {
       
    96     }
       
    97 
       
    98 // ----------------------------------------------------
       
    99 //  CNcnNotifier::SetNotification
       
   100 // ----------------------------------------------------
       
   101 //
       
   102 void CNcnNotifier::SetNotification(
       
   103                 TNcnNotificationType aNotificationType,
       
   104                 TUint aAmount,
       
   105 				TBool aIcon,
       
   106 				TBool aTone,
       
   107 				TBool aNote )
       
   108     {
       
   109     NCN_RDEBUG_INT( _L("CNcnNotifier::SetNotification() -  aNotificationType: %d"), aNotificationType );
       
   110     
       
   111     // if notification is one of the specified notifications
       
   112     // (ENcnNoNotification is a special case with no amount)
       
   113     if( aNotificationType != ENcnNoNotification )
       
   114         {        
       
   115         NCN_RDEBUG_INT( _L("CNcnNotifier::SetNotification() -  prev: %d"), iNotificationAmounts[ aNotificationType ] );
       
   116         NCN_RDEBUG_INT( _L("CNcnNotifier::SetNotification() -  curr: %d"), aAmount );
       
   117 
       
   118         // update notification only if amount changes
       
   119         if( iNotificationAmounts[ aNotificationType ] != aAmount || aAmount == 0 ||
       
   120             aNotificationType == MNcnNotifier::ENcnVoiceMailNotification || 
       
   121             aNotificationType == MNcnNotifier::ENcnVoiceMailOnLine1Notification || 
       
   122             aNotificationType == MNcnNotifier::ENcnVoiceMailOnLine2Notification )
       
   123             {
       
   124             // store previous amount
       
   125             TUint previousAmount = iNotificationAmounts[ aNotificationType ];
       
   126             
       
   127             // change notification amount
       
   128             iNotificationAmounts[ aNotificationType ] = aAmount;
       
   129             
       
   130             // update notification
       
   131             HandleNotificationChange(
       
   132                 aNotificationType,
       
   133                 previousAmount,
       
   134                 aAmount,
       
   135                 aIcon,
       
   136                 aTone,
       
   137                 aNote );
       
   138             }        
       
   139         }
       
   140     }
       
   141 
       
   142 // ----------------------------------------------------
       
   143 //  CNcnNotifier::NotificationAmount
       
   144 // ----------------------------------------------------
       
   145 //
       
   146 TUint CNcnNotifier::NotificationAmount(
       
   147     TNcnNotificationType aNotificationType )
       
   148     {
       
   149     TUint amount = 0;
       
   150     
       
   151     // if notification is one of the specified notifications
       
   152     // (ENcnNoNotification is a special case with no amount)
       
   153     if( aNotificationType != ENcnNoNotification )
       
   154         {
       
   155         amount = iNotificationAmounts[ aNotificationType ];        
       
   156         }
       
   157         
       
   158     return amount;
       
   159     }
       
   160 
       
   161       									
       
   162 // ----------------------------------------------------
       
   163 //  CNcnNotifier::HandleNotificationChange
       
   164 // ----------------------------------------------------
       
   165 //    
       
   166 void CNcnNotifier::HandleNotificationChange(
       
   167     TNcnNotificationType aNotificationType,
       
   168     TUint aPreviousAmount,
       
   169     TUint aCurrentAmount,
       
   170 	TBool aIcon,
       
   171 	TBool aTone,
       
   172 	TBool aNote )
       
   173     {
       
   174     TBool displaySN;
       
   175     NCN_RDEBUG_INT( _L("CNcnNotifier::HandleNotificationChange() -  notifType: %d"), aNotificationType );
       
   176     
       
   177     
       
   178     
       
   179     // handles voice mail note as the correct amount of new
       
   180     // voice mail messages isn't known
       
   181     TBool amountUnknown( EFalse );
       
   182         
       
   183     // determine notification type
       
   184     switch( aNotificationType )
       
   185         {
       
   186         case MNcnNotifier::ENcnClass0MessageNotification:
       
   187             {
       
   188             HandleClass0MessageNotificationChange(
       
   189                 aPreviousAmount,
       
   190                 aCurrentAmount );            
       
   191             break;
       
   192             }
       
   193         case MNcnNotifier::ENcnMessagesNotification:
       
   194             {
       
   195             HandleMessageNotificationChange(
       
   196                 aPreviousAmount,
       
   197                 aCurrentAmount );
       
   198             break;
       
   199             }
       
   200         case MNcnNotifier::ENcnAudioMessagesNotification:
       
   201         	{
       
   202         	HandleAudioMessageNotificationChange(
       
   203                 aPreviousAmount,
       
   204                 aCurrentAmount );                
       
   205             break;
       
   206             }
       
   207         case MNcnNotifier::ENcnVoiceMailNotification:
       
   208         case MNcnNotifier::ENcnVoiceMailOnLine1Notification:
       
   209         case MNcnNotifier::ENcnVoiceMailOnLine2Notification:
       
   210             {
       
   211         	amountUnknown = ETrue;
       
   212         	
       
   213             HandleVoiceMailNotificationChange(
       
   214                 aPreviousAmount,
       
   215                 aCurrentAmount );
       
   216             break;
       
   217             }
       
   218 
       
   219         case MNcnNotifier::ENcnEmailNotification:
       
   220         	{
       
   221         	//Email define which notes they want
       
   222         	//others don't define it ATM.
       
   223             HandleEMailNotificationChange(
       
   224                 aPreviousAmount,
       
   225                 aCurrentAmount,
       
   226 				aIcon,
       
   227 				aTone );
       
   228             break;
       
   229             }    
       
   230         default:
       
   231             {
       
   232             break;
       
   233             }
       
   234         }
       
   235     TRAP_IGNORE( displaySN = CheckSNStatusL( aNotificationType ));
       
   236     TBool DisplayLight = CheckDLStatus( aNotificationType );
       
   237     NCN_RDEBUG_INT( _L("CNcnNotifier::HandleNotificationChange() -  displaySN: %d"), displaySN );		
       
   238 
       
   239     // note is updated only if the count increases
       
   240     // or if count remains the same as is the case with voice mail messages,
       
   241     // where we don't know the actual message amount
       
   242     if( ( aCurrentAmount > aPreviousAmount ) 
       
   243             && displaySN 
       
   244             && aNote )
       
   245         {
       
   246             if(DisplayLight)
       
   247             {
       
   248             NCN_RDEBUG( _L( "CNcnNotifier::HandleNotificationChange - calling Flash Display" ) );
       
   249             iNcnUI.FlashDisplay();
       
   250             }
       
   251             iNcnUI.UpdateSoftNotification( aNotificationType, aCurrentAmount );	
       
   252         }
       
   253     else 
       
   254         if( amountUnknown // This is ETrue only with voicemails
       
   255             && displaySN
       
   256             && aCurrentAmount > 0 
       
   257         )
       
   258         {
       
   259             if(DisplayLight)
       
   260             {
       
   261             NCN_RDEBUG( _L( "CNcnNotifier::HandleNotificationChange - calling Flash Display" ) );
       
   262             iNcnUI.FlashDisplay();
       
   263             }
       
   264             iNcnUI.UpdateSoftNotification( aNotificationType, aCurrentAmount );	
       
   265         }
       
   266 	//If the count decreases we must wipe it out
       
   267 	else
       
   268 		{
       
   269 		iNcnUI.UpdateSoftNotification( aNotificationType, 0 );				
       
   270 		}
       
   271     }
       
   272 
       
   273 // ----------------------------------------------------
       
   274 //  CNcnNotifier::HandleClass0MessageNotificationChange
       
   275 // ----------------------------------------------------
       
   276 //    
       
   277 void CNcnNotifier::HandleClass0MessageNotificationChange(
       
   278             TUint /*aPreviousAmount*/,
       
   279             TUint /*aCurrentAmount*/ )
       
   280     {
       
   281     // alert tone is always played for class0
       
   282     iNcnUI.PlayMessageAlertTone();
       
   283     
       
   284     // Special: since we don't need to keep track of the amount of
       
   285     // class0 messages reset in now.
       
   286     iNotificationAmounts[ MNcnNotifier::ENcnClass0MessageNotification ] = 0;
       
   287     }
       
   288     
       
   289 // ----------------------------------------------------
       
   290 //  CNcnNotifier::HandleMessageNotificationChange
       
   291 // ----------------------------------------------------
       
   292 //        
       
   293 void CNcnNotifier::HandleMessageNotificationChange(
       
   294             TUint aPreviousAmount,
       
   295             TUint aCurrentAmount )
       
   296     {
       
   297     // update message icon
       
   298     UpdateMessageIcon( aCurrentAmount );
       
   299     
       
   300     // play message alert tone if there are new messages
       
   301     if( aCurrentAmount > aPreviousAmount )
       
   302         {
       
   303         iNcnUI.PlayMessageAlertTone();
       
   304         }
       
   305     }
       
   306 
       
   307 // ----------------------------------------------------
       
   308 //  CNcnNotifier::HandleAudioMessageNotificationChange
       
   309 // ----------------------------------------------------
       
   310 //        
       
   311 void CNcnNotifier::HandleAudioMessageNotificationChange(
       
   312             TUint aPreviousAmount,
       
   313             TUint aCurrentAmount )
       
   314     {    
       
   315     // update message icon
       
   316     UpdateMessageIcon( aCurrentAmount );
       
   317     
       
   318     // play message alert tone if there are new audio messages
       
   319     if( aCurrentAmount > aPreviousAmount )
       
   320         {
       
   321         iNcnUI.PlayMessageAlertTone();
       
   322         }
       
   323     }
       
   324 
       
   325 // ----------------------------------------------------
       
   326 //  CNcnNotifier::HandleVoiceMailNotificationChange
       
   327 // ----------------------------------------------------
       
   328 //            
       
   329 void CNcnNotifier::HandleVoiceMailNotificationChange(
       
   330             TUint aPreviousAmount,
       
   331             TUint aCurrentAmount )
       
   332     {
       
   333     // play message alert tone always when messages are
       
   334     // received and the count of them is more than 0
       
   335     if( aCurrentAmount > 0 && aCurrentAmount > aPreviousAmount )
       
   336         {
       
   337         iNcnUI.PlayMessageAlertTone();
       
   338         }
       
   339     }
       
   340 
       
   341 // ----------------------------------------------------
       
   342 //  CNcnNotifier::HandleEMailNotificationChange
       
   343 // ----------------------------------------------------
       
   344 //            
       
   345 void CNcnNotifier::HandleEMailNotificationChange(
       
   346             TUint aPreviousAmount,
       
   347             TUint aCurrentAmount,
       
   348 			TBool aIcon,
       
   349 			TBool aTone  )
       
   350     {        
       
   351     // update icon
       
   352     if ( aIcon == TRUE )
       
   353 	    {
       
   354 	    UpdateEmailIcon( aCurrentAmount );   	
       
   355 	    }
       
   356         
       
   357     // play email alert tone if there are new messages
       
   358     if( aCurrentAmount > aPreviousAmount && aTone == TRUE )
       
   359         {
       
   360         iNcnUI.PlayEMailAlertTone();
       
   361         }
       
   362     }
       
   363 
       
   364 // ----------------------------------------------------
       
   365 //  CNcnNotifier::UpdateEmailIcon
       
   366 //  Updates email message indicator. It does not update
       
   367 //  remote mailbox email message indicator. 
       
   368 // ----------------------------------------------------
       
   369 //    
       
   370 void CNcnNotifier::UpdateEmailIcon( TInt aAmount )
       
   371     {
       
   372     // default to messages waiting    
       
   373     TUint value = ECoreAppUIsNewEmail;
       
   374                 
       
   375     // change the default if there are now messages waiting
       
   376     if( !aAmount )
       
   377         {
       
   378         value = ECoreAppUIsNoNewEmail;
       
   379         }
       
   380 
       
   381     // update key value. SysApp will show @ icon based on this value
       
   382 	iModel.NotifyPublishAndSubscribe(
       
   383             KPSUidCoreApplicationUIs, KCoreAppUIsNewEmailStatus, value );   
       
   384 			
       
   385     }
       
   386 
       
   387 // ----------------------------------------------------
       
   388 //  CNcnNotifier::UpdateMessageIcon
       
   389 // ----------------------------------------------------
       
   390 //
       
   391 void CNcnNotifier::UpdateMessageIcon( TInt aAmount )
       
   392     {
       
   393     // default to inbox empty
       
   394     TInt state = ESAInboxEmpty;
       
   395     
       
   396     // if there are any messages to be notified of
       
   397 	if( ( iModel.IsSupported( KNcnAudioMessaging ) &&
       
   398 		( iNotificationAmounts[ ENcnMessagesNotification ] > 0 ||
       
   399     	  iNotificationAmounts[ ENcnAudioMessagesNotification ] > 0 ))
       
   400     	  || aAmount )
       
   401 		{
       
   402 		NCN_RDEBUG( _L( "CNcnNotifier::UpdateMessageIcon - setting message icon on " ) );
       
   403 		state = ESADocumentsInInbox;
       
   404 	    }
       
   405     else
       
   406         {
       
   407         NCN_RDEBUG( _L( "CNcnNotifier::UpdateMessageIcon - setting UpdateMessageIcon icon off " ) );
       
   408         }
       
   409         
       
   410     // set icon state through P&S variable
       
   411     iModel.NotifyPublishAndSubscribe(
       
   412         KUidSystemCategory,
       
   413         KUidInboxStatusValue,
       
   414         state );        
       
   415     }
       
   416     
       
   417 TBool CNcnNotifier::CheckSNStatusL( const TNcnNotificationType& aNotificationType ) const
       
   418     {
       
   419     NCN_RDEBUG_INT( _L("CNcnNotifier::CheckSNStatusL() -  aNotificationType: %d"), aNotificationType );
       
   420     TUint32 flag;
       
   421     
       
   422     switch ( aNotificationType )
       
   423         {
       
   424         case ENcnMessagesNotification:
       
   425             {
       
   426             flag = KMuiuNewMessageSNFlag;
       
   427             break;
       
   428             }
       
   429         case ENcnEmailNotification:
       
   430             {
       
   431             flag = KMuiuNewEmailSNFlag;
       
   432             break;
       
   433             }
       
   434         case ENcnVoiceMailNotification:
       
   435         	// Fallthrough
       
   436         case ENcnVoiceMailOnLine1Notification:
       
   437         	// Fallthrough
       
   438         case ENcnVoiceMailOnLine2Notification:
       
   439             {
       
   440             flag = KMuiuNewVoiceMailSNFlag;
       
   441             break;
       
   442             }
       
   443         case ENcnMissedCallsNotification:
       
   444             {
       
   445             flag = KMuiuMissedCallSNFlag;
       
   446             break;
       
   447             }
       
   448         case ENcnInstantMessagesNotification:
       
   449             {
       
   450             flag = KMuiuInstantMessageSNFlag;
       
   451             break;
       
   452             }
       
   453         case ENcnAudioMessagesNotification:
       
   454             {
       
   455             flag = KMuiuAudioMessageSNFlag;
       
   456             break;
       
   457             }        
       
   458         case ENcnClass0MessageNotification:
       
   459         	// Fallthrough
       
   460         case ENcnNoNotification:
       
   461         	// Fallthrough
       
   462         default:
       
   463             return ETrue; // This is already default value for displaying SN  
       
   464         }
       
   465         
       
   466     TInt state; 
       
   467     CRepository* repository = NULL;
       
   468     
       
   469     TRAPD( err, repository = CRepository::NewL( KCRUidMuiuMessagingConfiguration ) );
       
   470     if( err == KErrNone && repository != NULL )
       
   471 	    {
       
   472 	    CleanupStack::PushL( repository ); // CSI: 42 # Should not leave
       
   473 	    
       
   474 		err = repository->Get( KMuiuSoftNotificationConfiguration, state );
       
   475 		NCN_RDEBUG_INT( _L("CNcnNotifier::CheckSNStatusL() -  state: %d"), state );
       
   476 		
       
   477 		TBool result( EFalse );
       
   478 		if( err == KErrNone && ( state & flag ) == flag )		
       
   479 			{
       
   480 			result = ETrue;				
       
   481 			}
       
   482 		else if( err != KErrNone )				
       
   483 			{
       
   484 			// soft note is displayed if we fail to get SN config state
       
   485 			result = ETrue;				
       
   486 			}
       
   487 							
       
   488 		CleanupStack::PopAndDestroy( repository );
       
   489 		return result;
       
   490 	    }
       
   491 	else
       
   492 		{
       
   493 		return ETrue;			
       
   494 		}	    
       
   495     }
       
   496     
       
   497 
       
   498 
       
   499 TBool CNcnNotifier::CheckDLStatus( const TNcnNotificationType& aNotificationType ) const
       
   500     {
       
   501     NCN_RDEBUG_INT( _L("CNcnNotifier::CheckDLStatus() -  aNotificationType: %d"), aNotificationType );
       
   502     TUint32 flag;
       
   503     
       
   504     switch ( aNotificationType )
       
   505         {
       
   506         case ENcnMessagesNotification:
       
   507             {
       
   508             flag = KMuiuDLNewMessageFlag;
       
   509             break;
       
   510             }
       
   511         case ENcnEmailNotification:
       
   512             {
       
   513             flag = KMuiuDLNewEmailFlag;
       
   514             break;
       
   515             }
       
   516         case ENcnVoiceMailNotification:
       
   517             // Fallthrough
       
   518         case ENcnVoiceMailOnLine1Notification:
       
   519             // Fallthrough
       
   520         case ENcnVoiceMailOnLine2Notification:
       
   521             {
       
   522             flag = KMuiuDLNewVoiceMailFlag;
       
   523             break;
       
   524             }
       
   525         case ENcnMissedCallsNotification:
       
   526             {
       
   527             flag = KMuiuDLMissedCallFlag;
       
   528             break;
       
   529             }
       
   530         case ENcnInstantMessagesNotification:
       
   531             {
       
   532             flag = KMuiuDLInstantMessageFlag;
       
   533             break;
       
   534             }
       
   535         case ENcnAudioMessagesNotification:
       
   536             {
       
   537             flag = KMuiuDLAudioMessageFlag;
       
   538             break;
       
   539             }        
       
   540         case ENcnClass0MessageNotification:
       
   541             // Fallthrough
       
   542         case ENcnNoNotification:
       
   543             // Fallthrough
       
   544         default:
       
   545             return ETrue; // This is already default value for displaying SN  
       
   546         }
       
   547   
       
   548     if((iDisplayLightstate & flag ) == flag)
       
   549         return ETrue;
       
   550     else
       
   551         return EFalse;
       
   552             
       
   553           
       
   554     }
       
   555     
       
   556 //  End of File
       
   557