messagingappbase/ncnlist/src/NcnSNNotifier.cpp
changeset 0 72b543305e3a
child 5 4697dfb2d7ad
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 CNcnSNNotifier class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "NcnDebug.h"
       
    22 #include    "NcnSNNotifier.h"
       
    23 #include    <AknSoftNotifier.h>
       
    24 #include    <AknNotifyStd.h>
       
    25 #include    <AknSoftNotificationParameters.h>
       
    26 #include    <avkon.rsg>
       
    27 #include    <Ncnlist.rsg>
       
    28 #include    <aknSDData.h>
       
    29 #include    "NcnModel.h"
       
    30 #include    "CVoiceMailManager.h"
       
    31 
       
    32 // ================= DEFINITIONS ============================
       
    33 #define KSpeedDialViewId TVwsViewId( TUid::Uid( 0x1000590A ), TUid::Uid( 0x02 ) )
       
    34 #define KMceMailViewId TVwsViewId( TUid::Uid( 0x100058C5 ), TUid::Uid( 0x01 ) )
       
    35 #define KMceAudioMessageViewId TVwsViewId(TUid::Uid(0x100058C5),TUid::Uid(0x01) )
       
    36 
       
    37 // ================= LOCAL CONSTANTS ========================
       
    38 namespace
       
    39     {
       
    40     _LIT( KNcnResourceFile, "z:\\resource\\Ncnlist.rSC" );
       
    41     const TInt KNcnNotificationPriority = 2200;
       
    42     const TUid KNcnDefaultMessageUid = { 1 };
       
    43     const TUid KNcnLine2MessageUid = { 2 };
       
    44     const TUid KNcnAudioMessageUid = { 3 };
       
    45     _LIT8( KNcnExternalLaunch, "outside" );
       
    46     const TUint KNcnExternalizedNumberMaxLength = 8;
       
    47     }
       
    48     
       
    49 // ================= MEMBER FUNCTIONS =======================
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // CNcnSNNotifier default constructor
       
    53 // ---------------------------------------------------------
       
    54 //
       
    55 CNcnSNNotifier::CNcnSNNotifier()
       
    56     {
       
    57     }
       
    58 
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // CNcnSNNotifier::~CNcnSNNotifier
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 CNcnSNNotifier::~CNcnSNNotifier()
       
    65     {
       
    66     // Delete notifier
       
    67     delete iNotifier;
       
    68     iNotifier = NULL;
       
    69     }
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // CNcnSNNotifier::NewL
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 CNcnSNNotifier* CNcnSNNotifier::NewL()
       
    77     {
       
    78     // Create the notifier instance
       
    79     CNcnSNNotifier* self = new (ELeave) CNcnSNNotifier();
       
    80 
       
    81     // Call the construct safely
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL();
       
    84     CleanupStack::Pop();
       
    85         
       
    86     return self;
       
    87     }
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // CNcnSNNotifier::ConstructL
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 void CNcnSNNotifier::ConstructL()
       
    95     {
       
    96     // Create notifier instance
       
    97     iNotifier = CAknSoftNotifier::NewL();
       
    98     }
       
    99 
       
   100 
       
   101 // ---------------------------------------------------------
       
   102 // CNcnSNNotifier::IdleState
       
   103 // ---------------------------------------------------------
       
   104 //
       
   105 void CNcnSNNotifier::IdleState( TBool aCurrentState )
       
   106     {
       
   107     TRAP_IGNORE( DoInformIdleStateL( aCurrentState ) );
       
   108     }
       
   109 
       
   110 
       
   111 // ---------------------------------------------------------
       
   112 // CNcnSNNotifier::NewItems
       
   113 // ---------------------------------------------------------
       
   114 //
       
   115 void CNcnSNNotifier::NewItems( const MNcnNotifier::TNcnNotificationType aNotificationType, const TInt aAmount )
       
   116     {
       
   117     //Convert to avkon type
       
   118     TAknSoftNotificationType aknType = ConvertNCNTypeToAvkonType(aNotificationType);
       
   119 
       
   120 	//Get the secondary display id for this note
       
   121 	SecondaryDisplay::TSecondaryDisplayNcnListDialogs dialogID = 
       
   122 		ConvertNCNTypeToSecondaryDisplayType(aNotificationType);
       
   123 	
       
   124     // Amount needs to be stored to "additional parameter"
       
   125     TBuf8<KNcnExternalizedNumberMaxLength> additionalData;
       
   126     additionalData.Num(aAmount);
       
   127     
       
   128     // Encapsulate the sent data
       
   129     CAknSDData* sdData = NULL;
       
   130     TRAPD( status, sdData = CAknSDData::NewL(
       
   131 		    SecondaryDisplay::KCatNcnList, 
       
   132 		    dialogID, 
       
   133 		    additionalData) );
       
   134     
       
   135     // Send data to cover ui    
       
   136     if ( status == KErrNone && sdData != NULL)
       
   137 	    {
       
   138 	    iNotifier->SetSecondaryDisplayData( sdData ); //Takes ownership	
       
   139 	    }
       
   140     
       
   141     // If there are problems with notifier, just catch the error and 
       
   142     // try to finish the other processes.
       
   143     TRAP( status, ShowNewItemsL( aknType, aAmount ) );
       
   144     
       
   145     NCN_RDEBUG_INT( _L("CNcnSNNotifier::NewItems: ShowNewItemsL returned %d"), status );    
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------
       
   149 // CNcnSNNotifier::DoInformIdleStateL
       
   150 // ---------------------------------------------------------
       
   151 //
       
   152 void CNcnSNNotifier::DoInformIdleStateL( TBool aCurrentState )
       
   153     {
       
   154     NCN_RDEBUG_INT(_L("CNcnSNNotifier::DoInformIdleStateL aCurrentState = %d" ), aCurrentState );
       
   155 
       
   156     // Inform the notifier component about new idle state status.
       
   157     iNotifier->SetIdleStateL( aCurrentState );
       
   158     }
       
   159 
       
   160 
       
   161 // ---------------------------------------------------------
       
   162 // CNcnSNNotifier::ShowNewItemsL
       
   163 // ---------------------------------------------------------
       
   164 //
       
   165 void CNcnSNNotifier::ShowNewItemsL( const TAknSoftNotificationType aNotificationType, const TInt aAmount )
       
   166     {
       
   167     NCN_RDEBUG_INT2(_L("CNcnSNNotifier::ShowNewItemsL: aNotificationType %d, aAmount: %d" ), aNotificationType, aAmount );
       
   168 
       
   169     // Separate handling for voice mail notifications for now
       
   170     switch( aNotificationType )
       
   171         {
       
   172         case ECustomSoftNotification:
       
   173         	// Fallthrough
       
   174         case ENewMailNotification:
       
   175             // Fallthrough
       
   176         case EVoiceMailNotification:
       
   177             // Fallthrough
       
   178         case ESeparateVoiceMailOnLine1Notification:
       
   179             // Fallthrough
       
   180         case ESeparateVoiceMailOnLine2Notification:
       
   181             {
       
   182             ShowCustomNotificationL( aNotificationType, aAmount );
       
   183             break;
       
   184             }            
       
   185         default:
       
   186             {
       
   187             ShowDefaultNotificationL( aNotificationType, aAmount );
       
   188             break;
       
   189             }
       
   190         }
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------
       
   194 // CNcnSNNotifier::ShowVoiceMailNotificationL
       
   195 // ---------------------------------------------------------
       
   196 //
       
   197 void CNcnSNNotifier::ShowCustomNotificationL( const TAknSoftNotificationType aNotificationType, const TInt aAmount )
       
   198     {
       
   199     TBool amountKnown = ( aAmount <= CVoiceMailManager::EVMMaximumNumber );
       
   200 
       
   201     NCN_RDEBUG_INT2(_L("CNcnSNNotifier::ShowCustomNotificationL: aNotificationType %d, amount known: %d" ), aNotificationType, amountKnown );
       
   202 
       
   203     // fuzzy voicemail note and normal voice mail note should never exist at the same time. 
       
   204     // Always cancel the other before adding new note.
       
   205     if ( aNotificationType == EVoiceMailNotification
       
   206         || aNotificationType == ESeparateVoiceMailOnLine1Notification
       
   207         || aNotificationType == ESeparateVoiceMailOnLine2Notification )
       
   208         {
       
   209         CAknSoftNotificationParameters* params =
       
   210             CreateNotificationParametersLC( aNotificationType, !amountKnown );
       
   211         iNotifier->CancelCustomSoftNotificationL( *params );
       
   212         CleanupStack::PopAndDestroy( params );
       
   213         }
       
   214 
       
   215     // create notification parameters
       
   216     CAknSoftNotificationParameters* params =
       
   217         CreateNotificationParametersLC( aNotificationType, amountKnown );
       
   218         
       
   219     if( aAmount <= 0 )
       
   220         {
       
   221         iNotifier->CancelCustomSoftNotificationL( *params );
       
   222         }
       
   223     else
       
   224         {
       
   225         iNotifier->SetCustomNotificationCountL( *params, aAmount );
       
   226         }
       
   227 
       
   228     // destroy parameters
       
   229     CleanupStack::PopAndDestroy( params );
       
   230     }
       
   231      
       
   232 // ---------------------------------------------------------
       
   233 // CNcnSNNotifier::ShowDefaultNotificationL
       
   234 // ---------------------------------------------------------
       
   235 //
       
   236 void CNcnSNNotifier::ShowDefaultNotificationL( const TAknSoftNotificationType aNotificationType, const TInt aAmount )
       
   237     {
       
   238     NCN_RDEBUG_INT2(_L("CNcnSNNotifier::ShowDefaultNotificationL aNotificationType %d, aAmount: %d" ), aNotificationType, aAmount );
       
   239     
       
   240     if( aAmount <= 0 )
       
   241         {
       
   242         iNotifier->CancelSoftNotificationL( aNotificationType );
       
   243         }
       
   244     else
       
   245         {
       
   246         TRAPD( err, iNotifier->SetNotificationCountL( aNotificationType, aAmount ) );
       
   247     	NCN_RDEBUG_INT(_L("CNcnSNNotifier::ShowDefaultNotificationL: SetNotificationCountL returned %d"  ), err );
       
   248     	User::LeaveIfError( err );
       
   249 //      iNotifier->SetNotificationCountL( aNotificationType, aAmount );
       
   250         }
       
   251     }
       
   252 // ---------------------------------------------------------
       
   253 // CNcnSNNotifier::VoicemailNoteId
       
   254 // ---------------------------------------------------------
       
   255 //        
       
   256 CAknSoftNotificationParameters* CNcnSNNotifier::VoicemailNoteParametersL( 
       
   257     const TAknSoftNotificationType aNotificationType, 
       
   258     const TBool aAmountKnown )
       
   259     {
       
   260     NCN_RDEBUG_INT2(_L("CNcnSNNotifier::VoicemailNoteParametersL: aNotificationType %d, aAmountKnown: %d" ), aNotificationType, aAmountKnown );
       
   261     
       
   262     // note is different only for voice mails, if amount is known or not known.
       
   263     TUid customMessageId = KNcnDefaultMessageUid; // default
       
   264     TInt groupId(0);
       
   265     TInt noteId(0);
       
   266     switch( aNotificationType )
       
   267         {
       
   268         case EVoiceMailNotification:
       
   269             {
       
   270             noteId = aAmountKnown ? R_NCN_VOICE_MAIL_NOTE : R_NCN_VOICE_MAILS_UNK_AMOUNT;
       
   271             groupId = aAmountKnown ? R_NCN_VOICE_MAIL_GROUPED : R_NCN_VOICE_MAILS_UNK_AMOUNT_GROUPED;
       
   272             break;
       
   273             }
       
   274         case ESeparateVoiceMailOnLine1Notification:
       
   275             {
       
   276             noteId = aAmountKnown ? R_NCN_VOICE_MAIL_ON_LINE1_NOTE : R_NCN_VOICE_MAILS_UNK_AMOUNT_ON_LINE1;
       
   277             groupId = aAmountKnown ? R_NCN_VOICE_MAIL_ON_LINE1_GROUPED : R_NCN_VOICE_MAILS_UNK_AMOUNT_ON_LINE1_GROUPED;
       
   278             break;
       
   279             }
       
   280         case ESeparateVoiceMailOnLine2Notification:
       
   281             {
       
   282             noteId = aAmountKnown ? R_NCN_VOICE_MAIL_ON_LINE2_NOTE : R_NCN_VOICE_MAILS_UNK_AMOUNT_ON_LINE2;
       
   283             groupId = aAmountKnown ? R_NCN_VOICE_MAIL_ON_LINE2_GROUPED : R_NCN_VOICE_MAILS_UNK_AMOUNT_ON_LINE2_GROUPED;
       
   284             customMessageId = KNcnLine2MessageUid;
       
   285             break;
       
   286             }
       
   287         default:
       
   288             {
       
   289             ASSERT( EFalse );
       
   290             break;
       
   291             }
       
   292         }
       
   293         
       
   294         CAknSoftNotificationParameters* ret = CAknSoftNotificationParameters::NewL(
       
   295                 KNcnResourceFile,
       
   296                 noteId,
       
   297                 KNcnNotificationPriority,
       
   298                 R_AVKON_SOFTKEYS_LISTEN_EXIT,
       
   299                 CAknNoteDialog::ENoTone,
       
   300                 KSpeedDialViewId,
       
   301                 customMessageId,
       
   302                 EAknSoftkeyListen,
       
   303                 KNcnExternalLaunch );
       
   304         ret->SetGroupedTexts( groupId );
       
   305         return ret;
       
   306     }
       
   307     
       
   308 // ---------------------------------------------------------
       
   309 // CNcnSNNotifier::CreateNotificationParametersLC
       
   310 // ---------------------------------------------------------
       
   311 //    
       
   312 CAknSoftNotificationParameters* CNcnSNNotifier::CreateNotificationParametersLC(
       
   313     const TAknSoftNotificationType aNotificationType,
       
   314     TBool aAmountKnown )
       
   315     {
       
   316     NCN_RDEBUG_INT(_L("CNcnSNNotifier::CreateNotificationParametersLC: aNotificationType %d" ), aNotificationType );
       
   317     // instantiate parameters    
       
   318     CAknSoftNotificationParameters* ret = 0;
       
   319         
       
   320     // determine resource ids based on notification type
       
   321     switch( aNotificationType )
       
   322         {
       
   323         // Notification for audio message
       
   324         case ECustomSoftNotification:
       
   325         	{
       
   326         	ret = CAknSoftNotificationParameters::NewL(
       
   327                 KNcnResourceFile,
       
   328                 R_NCN_AUDIO_MESSAGE_NOTE,
       
   329                 KNcnNotificationPriority,
       
   330                 R_AVKON_SOFTKEYS_SHOW_EXIT,
       
   331                 CAknNoteDialog::ENoTone,
       
   332                 KMceAudioMessageViewId,
       
   333                 KNcnAudioMessageUid,
       
   334                 EAknSoftkeyShow,
       
   335                 KNullDesC8() );
       
   336             ret->SetGroupedTexts( R_NCN_AUDIO_MESSAGE_GROUPED );
       
   337             break;
       
   338         	}
       
   339         case ENewMailNotification:
       
   340             {
       
   341             ret = CAknSoftNotificationParameters::NewL(
       
   342                 KNcnResourceFile,
       
   343                 R_NCN_EMAIL_NOTE,
       
   344                 KNcnNotificationPriority,
       
   345                 R_AVKON_SOFTKEYS_SHOW_EXIT,
       
   346                 CAknNoteDialog::ENoTone,
       
   347                 KMceMailViewId,
       
   348                 KNcnDefaultMessageUid,
       
   349                 EAknSoftkeyShow,
       
   350                 KNullDesC8() );
       
   351             ret->SetGroupedTexts( R_NCN_EMAIL_GROUPED );
       
   352             break;
       
   353             }
       
   354         case EVoiceMailNotification:
       
   355         case ESeparateVoiceMailOnLine1Notification:
       
   356         case ESeparateVoiceMailOnLine2Notification:
       
   357             {
       
   358             ret = VoicemailNoteParametersL( aNotificationType, aAmountKnown );
       
   359             break;
       
   360             }
       
   361         default:
       
   362             {
       
   363             // Not found.
       
   364             User::Leave( KErrNotFound );
       
   365             break;
       
   366             }
       
   367         }
       
   368         
       
   369     CleanupStack::PushL( ret );
       
   370     return ret;
       
   371     }
       
   372     
       
   373 
       
   374 // ---------------------------------------------------------
       
   375 // CNcnSNNotifier::ConvertNCNTypeToAvkonType
       
   376 // ---------------------------------------------------------
       
   377 //   
       
   378 TAknSoftNotificationType CNcnSNNotifier::ConvertNCNTypeToAvkonType( 
       
   379         	const MNcnNotifier::TNcnNotificationType aNotification ) const
       
   380 	{
       
   381     // default to no notification
       
   382     TAknSoftNotificationType aknNotificationType = ENoSoftNotification;
       
   383             
       
   384     // Map ncn specific notification to Akn notification type and update
       
   385     // notification.
       
   386     // Note that only the messages with valid Akn notification need to be
       
   387     // mapped (ie. class0 needs no mapping)
       
   388     switch( aNotification )
       
   389         {
       
   390         case MNcnNotifier::ENcnMessagesNotification:
       
   391             {
       
   392             aknNotificationType = ENewMessagesNotification;
       
   393             break;
       
   394             }
       
   395 	    case MNcnNotifier::ENcnAudioMessagesNotification:
       
   396 	        {
       
   397 	        aknNotificationType = ECustomSoftNotification;
       
   398 	        break;
       
   399 	        }
       
   400         case MNcnNotifier::ENcnEmailNotification:
       
   401             {
       
   402             aknNotificationType = ENewMailNotification;
       
   403             break;
       
   404             }
       
   405         case MNcnNotifier::ENcnVoiceMailNotification:
       
   406             {
       
   407             aknNotificationType = EVoiceMailNotification;
       
   408             break;
       
   409             }
       
   410         case MNcnNotifier::ENcnVoiceMailOnLine1Notification:
       
   411             {
       
   412             aknNotificationType = ESeparateVoiceMailOnLine1Notification;
       
   413             break;
       
   414             }
       
   415         case MNcnNotifier::ENcnVoiceMailOnLine2Notification:
       
   416             {
       
   417             aknNotificationType = ESeparateVoiceMailOnLine2Notification;
       
   418             break;
       
   419             }
       
   420         case MNcnNotifier::ENcnMissedCallsNotification:
       
   421             {
       
   422             aknNotificationType = EMissedCallsNotification;
       
   423             break;
       
   424             }
       
   425         default:
       
   426             {
       
   427             break;
       
   428             }
       
   429         }
       
   430         
       
   431     return aknNotificationType;
       
   432 	}    
       
   433 	
       
   434 // ---------------------------------------------------------
       
   435 // CNcnSNNotifier::ConvertNCNTypeToSecondaryDisplayType
       
   436 // ---------------------------------------------------------
       
   437 //   
       
   438 SecondaryDisplay::TSecondaryDisplayNcnListDialogs CNcnSNNotifier::ConvertNCNTypeToSecondaryDisplayType( 
       
   439 	const MNcnNotifier::TNcnNotificationType aNotification ) const
       
   440 	{
       
   441     // default to no notification
       
   442     SecondaryDisplay::TSecondaryDisplayNcnListDialogs secDisplayDialog = 
       
   443     	SecondaryDisplay::ECmdNoNotification;
       
   444             
       
   445     //Get the corresbonding secondary display dialog id
       
   446     switch( aNotification )
       
   447         {
       
   448         case MNcnNotifier::ENcnMessagesNotification:
       
   449             {
       
   450             secDisplayDialog = SecondaryDisplay::ECmdMessagesNotification;
       
   451             break;
       
   452             }
       
   453         case MNcnNotifier::ENcnClass0MessageNotification:
       
   454             {
       
   455             secDisplayDialog = SecondaryDisplay::ECmdClass0MessageNotification;
       
   456             break;
       
   457             }
       
   458 	    case MNcnNotifier::ENcnAudioMessagesNotification:
       
   459 	        {
       
   460 	        secDisplayDialog = SecondaryDisplay::ECmdAudioMessagesNotification;
       
   461 	        break;
       
   462 	        }
       
   463         case MNcnNotifier::ENcnEmailNotification:
       
   464             {
       
   465             secDisplayDialog = SecondaryDisplay::ECmdEmailNotification;
       
   466             break;
       
   467             }
       
   468         case MNcnNotifier::ENcnVoiceMailNotification:
       
   469             {
       
   470             secDisplayDialog = SecondaryDisplay::ECmdVoiceMailNotification;
       
   471             break;
       
   472             }
       
   473         case MNcnNotifier::ENcnVoiceMailOnLine1Notification:
       
   474             {
       
   475             secDisplayDialog = SecondaryDisplay::ECmdVoiceMailOnLine1Notification;
       
   476             break;
       
   477             }
       
   478         case MNcnNotifier::ENcnVoiceMailOnLine2Notification:
       
   479             {
       
   480             secDisplayDialog = SecondaryDisplay::ECmdVoiceMailOnLine2Notification;
       
   481             break;
       
   482             }
       
   483         case MNcnNotifier::ENcnMissedCallsNotification:
       
   484             {
       
   485             secDisplayDialog = SecondaryDisplay::ECmdMissedCallsNotification;
       
   486             break;
       
   487             }
       
   488         default:
       
   489             {
       
   490             break;
       
   491             }
       
   492         }
       
   493         
       
   494     return secDisplayDialog;		
       
   495 	}
       
   496 //  End of File