uifw/AknGlobalUI/OldStyleNotif/Src/AknSoftNotificationPlugin.cpp
changeset 0 2f259fa3e83a
child 29 a8834a2e9a96
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-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: 
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    21 #include <vwsdefpartner.h>
       
    22 #endif
       
    23 #include <avkon.rsg>
       
    24 #include <eikbtgpc.h>
       
    25 #include <eikenv.h>
       
    26 #include <avkon.hrh>
       
    27 #include <aknnotpi.rsg>
       
    28 #include <aknnotedialog.h>
       
    29 #include <AknPanic.h>
       
    30 #include <aknappui.h>
       
    31 #include <StringLoader.h>
       
    32 #include "AknSoftNotificationPlugin.h"
       
    33 #include <AknNotifyStd.h>
       
    34 #include <msvstd.hrh>   // for Messaging centre constants
       
    35 #include "AknNotifyPlugin.hrh"
       
    36 #include <centralrepository.h>
       
    37 #include <AvkonInternalCRKeys.h>
       
    38 #include <viewcli.h>
       
    39 #include <s32file.h>
       
    40 #include <s32mem.h>
       
    41 #include <e32cmn.h>
       
    42 #include "AknNotifierController.h"
       
    43 #include <eikfrlb.h>
       
    44 #include <eiklbi.h>
       
    45 #include <bautils.h>
       
    46 #include <AknNotifySignature.h>
       
    47 #include <apgcli.h>
       
    48 #include <aknsoundsystem.h>
       
    49 #include "AknCapServerEntry.h"
       
    50 #include "AknDynamicNotificationData.h"
       
    51 #include "aknsoftnoteconsts.h"
       
    52 #include "akndynamicsoftnoteeventmanager.h"
       
    53 
       
    54 // Messaging UIDs
       
    55 // Traditional messaging UIDs.
       
    56 #define KMessagingCentreMainViewUid TVwsViewId(TUid::Uid(0x100058C5),TUid::Uid(0x01))
       
    57 #define KMessagingCentreInboxView TVwsViewId(TUid::Uid(0x100058C5),TUid::Uid(0x02))
       
    58 
       
    59 // Conversational messaging UIDs.
       
    60 #define KConversationApplicationViewUid TVwsViewId(TUid::Uid(0x2002A540),TUid::Uid(0x01))
       
    61 const TInt KConversationListViewUid  = 0x01 ;
       
    62 
       
    63 // Messaging central repository. Used to read default view settings.
       
    64 const TUid KCRUidMessageSettings = {0x101F87EB};
       
    65 const TUint32 KMessagingAppDefaultViewCRKey = 0x0000001C;  
       
    66 
       
    67 // Cbs topic list view Uid. This view is shown when there are several cbs messages
       
    68 #define KCbsApplicationUidTopicListView TVwsViewId(TUid::Uid(0x101F4CD3),TUid::Uid(0x02))
       
    69 // Cbs message view Uid. This view is shown when there is only one new cbs message
       
    70 #define KCbsApplicationUidMessageView TVwsViewId(TUid::Uid(0x101F4CD3),TUid::Uid(0x04))
       
    71 
       
    72 // Voice messages are handleb by speed dial application.
       
    73 #define KSpeeddialVmbxDialUidView TVwsViewId( TUid::Uid( 0x1000590A ),TUid::Uid( 0x02 ) )
       
    74 
       
    75 // Logs application UID
       
    76 #define KUidLogs TUid(TUid::Uid(0x101F4CD5))
       
    77 _LIT8(KLogsActivationMsg ,"missed");
       
    78 
       
    79 _LIT8( KExternalLaunch, "outside" );
       
    80 
       
    81 #define KUidGS TUid(TUid::Uid(0x100058EC))
       
    82 #define KSettListNetViewId TUid(TUid::Uid(0x102824A8)) // Implementation UID for GSNetworkPlugin in GS.
       
    83 #define KSelectNetworkAppUidView TVwsViewId(KUidGS, KSettListNetViewId)
       
    84 
       
    85 #define KChatSpecificView TVwsViewId(TUid::Uid(0x101F4673),TUid::Uid(7))
       
    86 const TInt KGSCustomActivateNetView = 9000;
       
    87 
       
    88 const TInt KSoftNoteGranularity = 4;
       
    89 
       
    90 const TInt KNetworkInfoPriority     = 2500;
       
    91 const TInt KSelectNetworkPriority   = 2400;
       
    92 const TInt KUSSDPriority            = 2300;
       
    93 const TInt KVoiceMailPriority       = 2200;
       
    94 const TInt KVoiceMailOnLinePriority = 2100;
       
    95 const TInt KCBSPriority             = 2000;
       
    96 const TInt KGroupedNotification     = 1500;
       
    97 const TInt KMissedCallsPriority     = 1300;
       
    98 const TInt KNewMessagesPriority     = 1200;
       
    99 const TInt KChatMessagePriority     = 1150;
       
   100 const TInt KNewEmailPriority        = 1100;
       
   101 
       
   102 /// Lowest value for unique id. Id range: KMinimumUniqueId...KMaxTInt.
       
   103 const TInt KMinimumUniqueId         = 0x00ff;
       
   104 
       
   105 #define KDeliveryTextMaxLength 64
       
   106 
       
   107 _LIT( KAknSNFilename, "c:\\private\\10207218\\softnote.dat" );
       
   108 /// File where to store unique identification counter.
       
   109 _LIT( KAknDynamicIdFilename, "c:\\private\\10207218\\dynamic.dat" );
       
   110 
       
   111 NONSHARABLE_CLASS(CCustomNotifParams) : public CBase
       
   112     {
       
   113 public:
       
   114     ~CCustomNotifParams()
       
   115         {
       
   116         delete iParamData;
       
   117         delete iDynamicData;
       
   118         if ( iCoeResourceHandle )
       
   119             {
       
   120             CCoeEnv::Static()->DeleteResourceFile(iCoeResourceHandle);
       
   121             }
       
   122         };
       
   123         
       
   124     /**
       
   125      * Internalize content of CCustomNotifParams from stream.
       
   126      * @param aStream Source stream.
       
   127      */
       
   128     void InternalizeL( RReadStream& aStream );
       
   129     /**
       
   130      * Externalize content of CCustomNotifParams to stream.
       
   131      * @param aStream Destination stream.
       
   132      */
       
   133     void ExternalizeL( RWriteStream& aStream ) const;
       
   134     /**
       
   135      * Return text for custom notification.
       
   136      * 
       
   137      * @param aCount Count of items to be displayed in notification.
       
   138      * @param aGroupText ETrue  : Text is shown in grouped list.
       
   139      *                   EFalse : Text is shown in single dialog.
       
   140      * @return Custom text.
       
   141      */
       
   142     const TDesC& CustomText( TInt aCount, TBool aGroupText ) const;
       
   143     /**
       
   144      * @return View activation message or KNullDesC8 if not defined.
       
   145      */
       
   146     const TDesC8& ViewActivationMessage() const;
       
   147     /**
       
   148      * @return Flag whether user events are wanted by the event manager.
       
   149      */
       
   150     TBool EnableObserver() const;
       
   151     
       
   152     TInt iId;
       
   153     TInt iNoteId;
       
   154     TBool iSupportsGroupedform;
       
   155     TBool iHasViewInfo;
       
   156     TInt iCount;
       
   157     /// Data for custom soft notification.
       
   158     CAknPrivateSoftNoteParameters* iParamData;
       
   159     /// Data for dynamic soft notification.
       
   160     CAknDynamicNotificationData* iDynamicData;
       
   161     /// Parameter type to distinguish dynamic note from custom note. 
       
   162     /// Use KAknSoftNotificationCustom or KAknSoftNotificationDynamic. 
       
   163     TInt iParamType;
       
   164     CCustomNotifParams* iNext;
       
   165     TInt iCoeResourceHandle;
       
   166     };
       
   167 
       
   168 TBool CCustomNotifParams::EnableObserver() const
       
   169     {
       
   170     if (iDynamicData)
       
   171         {
       
   172         return iDynamicData->EnableObserver();
       
   173         }
       
   174     else
       
   175         {
       
   176         return EFalse;
       
   177         }        
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------
       
   181 // CCustomNotifParams::InternalizeL
       
   182 // ---------------------------------------------------------
       
   183 //
       
   184 void CCustomNotifParams::InternalizeL( RReadStream& aStream )
       
   185     {
       
   186     iParamType = aStream.ReadInt16L();
       
   187     switch( iParamType )
       
   188         {
       
   189         case KAknSoftNotificationCustom:
       
   190             {
       
   191             CAknPrivateSoftNoteParameters* param = 
       
   192                 CAknPrivateSoftNoteParameters::NewL(); 
       
   193             aStream >> *param;
       
   194             delete iParamData;
       
   195             iParamData = param;
       
   196             break;
       
   197             }
       
   198         case KAknSoftNotificationDynamic:
       
   199             {
       
   200             CAknDynamicNotificationData* data = 
       
   201                 CAknDynamicNotificationData::NewLC( aStream );
       
   202             
       
   203             // Duplicate values to ease the changes required
       
   204             //
       
   205             CAknPrivateSoftNoteParameters* param = 
       
   206                 CAknPrivateSoftNoteParameters::NewL();
       
   207             CleanupStack::PushL( param );
       
   208             
       
   209             // copy some values
       
   210             param->iCustomMessageId = data->CustomMsgUid();
       
   211             param->iPluralViewId = data->PluralViewId();
       
   212             param->iViewId = data->ViewId();
       
   213             param->iPriority = data->Priority();
       
   214             param->iTone = data->Tone();
       
   215             param->iNoteResourceId = data->Id();
       
   216             param->iAcceptSoftKey = EAknSoftkeyShow;
       
   217             
       
   218             // secondary display data
       
   219             if( aStream.ReadInt8L() ) 
       
   220                 {
       
   221                 // item has secondary display data
       
   222                 CAknSDData* sddata = new (ELeave) CAknSDData();
       
   223                 CleanupStack::PushL( sddata );
       
   224                 aStream >> *sddata;
       
   225                 delete param->iSecondaryDisplayData;
       
   226                 param->iSecondaryDisplayData = sddata;
       
   227                 CleanupStack::Pop( sddata );
       
   228                 }
       
   229 
       
   230             // Assign values when we can't leave anymore. 
       
   231             CleanupStack::Pop( 2, data ); // param
       
   232             delete iParamData;
       
   233             iParamData = param;
       
   234             delete iDynamicData;
       
   235             iDynamicData = data;
       
   236 
       
   237             break;
       
   238             }
       
   239         default:
       
   240             {
       
   241             User::Leave( KErrCorrupt );
       
   242             break;
       
   243             }
       
   244         }
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------
       
   248 // CCustomNotifParams::ExternalizeL
       
   249 // ---------------------------------------------------------
       
   250 //
       
   251 void CCustomNotifParams::ExternalizeL( RWriteStream& aStream ) const
       
   252     {
       
   253     if( iParamType <= KAknSoftNotificationCustom && iParamData ) // default
       
   254         {
       
   255         aStream.WriteInt16L( KAknSoftNotificationCustom );
       
   256         aStream << *iParamData;
       
   257         }
       
   258     else if( iParamType == KAknSoftNotificationDynamic && iDynamicData )
       
   259         {
       
   260         aStream.WriteInt16L( KAknSoftNotificationDynamic );
       
   261         aStream << *iDynamicData;
       
   262         
       
   263         // secondary display data
       
   264         if( iParamData && iParamData->iSecondaryDisplayData )
       
   265             {
       
   266             aStream.WriteInt8L( ETrue );
       
   267             aStream << iParamData->iSecondaryDisplayData;
       
   268             }
       
   269         else
       
   270             {
       
   271             aStream.WriteInt8L( EFalse );
       
   272             }
       
   273         }
       
   274     else
       
   275         {
       
   276         User::Leave( KErrCorrupt );
       
   277         }
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------
       
   281 // CCustomNotifParams::CustomText
       
   282 // ---------------------------------------------------------
       
   283 //
       
   284 const TDesC& CCustomNotifParams::CustomText( 
       
   285     TInt count, TBool aGroupText ) const
       
   286     {
       
   287     if( iParamType == KAknSoftNotificationDynamic && iDynamicData )
       
   288         {
       
   289         if( count > 1 )
       
   290             {
       
   291             // use plural text
       
   292             return aGroupText ? iDynamicData->PluralLabelGroup() :
       
   293                 iDynamicData->PluralLabel();
       
   294             }
       
   295         else
       
   296             {
       
   297             // use singular text
       
   298             return aGroupText ? iDynamicData->SingularLabelGroup() : 
       
   299                 iDynamicData->SingularLabel();
       
   300             }
       
   301         }
       
   302     return KNullDesC();
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------
       
   306 // CCustomNotifParams::ViewActivationMessage
       
   307 // ---------------------------------------------------------
       
   308 //
       
   309 const TDesC8& CCustomNotifParams::ViewActivationMessage() const
       
   310     {
       
   311     if( iParamType == KAknSoftNotificationDynamic && iDynamicData )
       
   312         {
       
   313         return iDynamicData->CustomMsg();
       
   314         }
       
   315     else if( iParamData && iParamData->iViewActivationMsg )
       
   316         {
       
   317         return *iParamData->iViewActivationMsg;
       
   318         }
       
   319     return KNullDesC8();
       
   320     }
       
   321 
       
   322 void AknSoftNoteSDObserver::SetSoftNotificationSubject( CAknSoftNotificationSubject* aSubject )
       
   323     {
       
   324     iSubject = aSubject;
       
   325     }
       
   326     
       
   327 TAknDialogMediatorObserverCommand AknSoftNoteSDObserver::MediatorCommandL( TUid, TUid, TInt, 
       
   328     const TDesC8& aData)
       
   329     {
       
   330     RDesReadStream* readStreamSDData = new(ELeave) RDesReadStream();
       
   331     CleanupStack::PushL( readStreamSDData );
       
   332     readStreamSDData->Open( aData ); // aData = data received from Mediator    
       
   333     TPckgBuf<SAknSoftNotificationFeedbackData> paramsBuf;
       
   334     *readStreamSDData >> paramsBuf;
       
   335     
       
   336     if ( paramsBuf().iType == EShowGroupedNotification ) 
       
   337         {
       
   338         CAknGroupedNotifierNote* groupedNote = iSubject->iGroupedNote;
       
   339         iSubject->GroupedNoteCompletedL(EAknSoftkeyExit, EMaxItem); // saves as well
       
   340         // iSubject->iGroupedNote equals to NULL now
       
   341         delete groupedNote;
       
   342         }
       
   343         
       
   344     else if (paramsBuf().iType != ECustomSoftNotification )
       
   345         {
       
   346         TAknSoftNotificationType type = paramsBuf().iType;
       
   347         iSubject->iSoftNotificationAmounts[ type ] = 0;
       
   348         iSubject->RemoveByType( type );
       
   349 
       
   350         if ( type == EMissedCallsNotification ||
       
   351              type == ENewMessagesNotification ||
       
   352              type == ENewMailNotification ||
       
   353              type == EChatMessageNotification)
       
   354             {
       
   355             iSubject->RemoveByType(EShowGroupedNotification);
       
   356             iSubject->ScheduleGroupedNotifierL();
       
   357             }
       
   358         else
       
   359             {
       
   360             iSubject->iGlobalNoteController->TryDisplayNextNoteL();
       
   361             }
       
   362         
       
   363         iSubject->iNotificationsSaved = EFalse;
       
   364         iSubject->SaveSoftNotificationsL();
       
   365         }
       
   366         
       
   367     else
       
   368         {
       
   369         CCustomNotifParams* params = iSubject->iCustomNoteParamsStack;
       
   370         for (;params;params = params->iNext)
       
   371             {
       
   372             if (params->iParamData->iSecondaryDisplayData)
       
   373                 {
       
   374                 if ( params->iParamData->iSecondaryDisplayData->iCategory.iUid == paramsBuf().iCategory 
       
   375                      && params->iParamData->iSecondaryDisplayData->iDialogIdx == paramsBuf().iDialogID )
       
   376                     {
       
   377                     TInt noteId = params->iNoteId;
       
   378                     if ( noteId == 0 )
       
   379                         {
       
   380                         iSubject->RemoveCustomNoteForId( params->iId );
       
   381                         iSubject->ScheduleGroupedNotifierL();
       
   382                         }
       
   383                     else
       
   384                         {
       
   385                         iSubject->RemoveCustomNoteForId( noteId, ETrue );
       
   386                         if ( noteId != KErrNotFound ) // was added to global notes queue
       
   387                             {
       
   388                             iSubject->iGlobalNoteController->TryDisplayNextNoteL();
       
   389                             }
       
   390                         }
       
   391 
       
   392                     iSubject->iNotificationsSaved = EFalse;
       
   393                     iSubject->SaveSoftNotificationsL();
       
   394                     break;
       
   395                     }
       
   396                 }
       
   397             }
       
   398         }
       
   399         
       
   400     readStreamSDData->Close(); 
       
   401     CleanupStack::PopAndDestroy(); // read stream
       
   402     return EDoNothingWithThisCommand;
       
   403     }
       
   404     
       
   405     
       
   406 // ================= MEMBER FUNCTIONS =======================
       
   407 
       
   408 // C++ default constructor can NOT contain any code, that
       
   409 // might leave.
       
   410 //
       
   411 CAknSoftNotificationSubject::CAknSoftNotificationSubject(
       
   412     MAknKeyLockController* aKeyLockController,
       
   413     CAknGlobalNoteSubject* aGlobalNoteController)
       
   414 :iKeyLockController(aKeyLockController), 
       
   415     iGlobalNoteController(aGlobalNoteController), 
       
   416     iNotificationsSaved(ETrue), // We'll have to assume there are saved notifications on startup
       
   417     iUniqueIdCounter(KMinimumUniqueId)
       
   418     {
       
   419     iMessagingRepository = NULL;
       
   420     iDynamicSoftNoteManager = CAknDynamicSoftNoteEventManager::UniqueInstance();
       
   421     __ASSERT_ALWAYS(iDynamicSoftNoteManager != NULL, User::Invariant());
       
   422     }
       
   423 
       
   424 // EPOC default constructor can leave.
       
   425 void CAknSoftNotificationSubject::ConstructL()
       
   426     {
       
   427     iKeyLockController->AddObserverL(this);
       
   428 
       
   429     iSoftNoteEntryList = new(ELeave)CArrayFixFlat<TSoftNoteEntry>(KSoftNoteGranularity);
       
   430     iGlobalNoteController->SetSoftNoteObserver(this);
       
   431     // Set initial state to 'non-idle'
       
   432     iGlobalNoteController->SetMaxDisplayPriorityL(KMinimumSoftNotePriority);
       
   433 
       
   434     iGlobalNoteController->SetMessageNotifierObserver(this);
       
   435 
       
   436     // Messaging settings repository
       
   437     TRAP_IGNORE( iMessagingRepository = CRepository::NewL(KCRUidMessageSettings) );
       
   438     
       
   439 #ifdef __COVER_DISPLAY  
       
   440     // Just to give something, not used.
       
   441     iCoverClient = CAknMediatorFacade::NewL((CEikDialog*)CEikonEnv::Static()->Alert()->AsEikDialog()); 
       
   442     
       
   443     iCoverClient->SetObserver(&iObsStub);
       
   444     iObsStub.SetSoftNotificationSubject( this );
       
   445     iCoverClient->CatUid() = KAknSecondaryDisplayCategory;
       
   446     iCoverClient->DialogIndex() = EAknSoftNotificationSDInfo;
       
   447 #endif
       
   448     
       
   449     // If the loading fails, then we'll start using unique id's 
       
   450     // from KMinimumUniqueId.
       
   451     TRAPD( err, LoadUniqueIdL() );
       
   452     if( err )
       
   453         {
       
   454 #ifdef _DEBUG
       
   455         _LIT( KDmsg, "AknSoftNotificationPlugin, Unique Id restore err: %d" );
       
   456         RDebug::Print( KDmsg, err );
       
   457 #endif //_DEBUG
       
   458         }
       
   459     }
       
   460 
       
   461 CAknSoftNotificationSubject::~CAknSoftNotificationSubject()
       
   462     {
       
   463     delete iSoftNoteEntryList;
       
   464 
       
   465     while(iCustomNoteParamsStack)
       
   466         {
       
   467         CCustomNotifParams* params = iCustomNoteParamsStack->iNext;
       
   468         delete iCustomNoteParamsStack;
       
   469         iCustomNoteParamsStack = params;
       
   470         }
       
   471 
       
   472     delete iIdle;
       
   473     delete iCoverClient;
       
   474     
       
   475     if(iKeyLockController)
       
   476         {
       
   477         iKeyLockController->RemoveObserver(this);
       
   478         }    
       
   479 
       
   480     if ( iMessagingRepository )
       
   481         {
       
   482         delete iMessagingRepository;
       
   483         iMessagingRepository = NULL;
       
   484         }
       
   485     }
       
   486 
       
   487 // Two-phased constructor.
       
   488 CAknSoftNotificationSubject* CAknSoftNotificationSubject::NewL(
       
   489     MAknKeyLockController* aKeyLockController,
       
   490     CAknGlobalNoteSubject* aGlobalNoteController )
       
   491     {
       
   492     CAknSoftNotificationSubject* self = new (ELeave) CAknSoftNotificationSubject(
       
   493         aKeyLockController, 
       
   494         aGlobalNoteController);
       
   495         
       
   496     CleanupStack::PushL( self );
       
   497     self->ConstructL();
       
   498     CleanupStack::Pop( self);
       
   499     return self;
       
   500     }
       
   501 
       
   502 // ---------------------------------------------------------
       
   503 // CAknSoftNotificationSubject::KeyLockStatusChange
       
   504 // ---------------------------------------------------------
       
   505 //
       
   506 void CAknSoftNotificationSubject::KeyLockStatusChange(TKeyLockStatus aStatus)
       
   507     {
       
   508     if ( aStatus == EKeyLockEnabled )
       
   509         {
       
   510         iKeysLocked = ETrue;
       
   511         }
       
   512     else if ( aStatus == EKeyLockDisabled )
       
   513         {
       
   514         iKeysLocked = EFalse;
       
   515         }
       
   516         
       
   517     if ( iGroupedNote && iGroupedNote->ListBox())
       
   518         {
       
   519         if ( aStatus == EKeyLockEnabled )
       
   520             {
       
   521             iGroupedNote->ListBox()->View()->ItemDrawer()->SetFlags(
       
   522                 CListItemDrawer::EDisableHighlight);
       
   523                 
       
   524             iGroupedNote->DrawDeferred();
       
   525             }
       
   526         else if ( aStatus == EKeyLockDisabled )
       
   527             {
       
   528             iGroupedNote->ListBox()->View()->ItemDrawer()->ClearFlags(
       
   529                 CListItemDrawer::EDisableHighlight);
       
   530                 
       
   531             iGroupedNote->DrawDeferred();
       
   532             }
       
   533         }
       
   534     }    
       
   535 
       
   536 // ---------------------------------------------------------
       
   537 // CAknSoftNotificationSubject::Release()
       
   538 //
       
   539 // (other items were commented in a header).
       
   540 // ---------------------------------------------------------
       
   541 //
       
   542 void CAknSoftNotificationSubject::Release()
       
   543     {
       
   544     delete this;
       
   545     }
       
   546 
       
   547 // ---------------------------------------------------------
       
   548 // CAknSoftNotificationSubject::RegisterL()
       
   549 // (other items were commented in a header).
       
   550 // ---------------------------------------------------------
       
   551 //
       
   552 CAknSoftNotificationSubject::TNotifierInfo CAknSoftNotificationSubject::RegisterL()
       
   553     {
       
   554     iInfo.iUid=KAknSoftNotificationUid;
       
   555     iInfo.iChannel=EAknNotifierChannelNote;
       
   556     iInfo.iPriority=ENotifierPriorityHigh;
       
   557     return iInfo;
       
   558     }
       
   559 
       
   560 // ---------------------------------------------------------
       
   561 // CAknSoftNotificationSubject::Info()
       
   562 // (other items were commented in a header).
       
   563 // ---------------------------------------------------------
       
   564 //
       
   565 CAknSoftNotificationSubject::TNotifierInfo CAknSoftNotificationSubject::Info() const
       
   566     {
       
   567     return iInfo;
       
   568     }
       
   569 
       
   570 // ---------------------------------------------------------
       
   571 // CAknSoftNotificationSubject::StartL(const TDesC8& aBuffer)
       
   572 //
       
   573 // (other items were commented in a header).
       
   574 // ---------------------------------------------------------
       
   575 //
       
   576 TPtrC8 CAknSoftNotificationSubject::StartL(const TDesC8& aBuffer)
       
   577     {
       
   578     TInt id = KErrNotFound;
       
   579     HandleNotifierMessageL( aBuffer, id );
       
   580 
       
   581     if( id > 0 )
       
   582         {
       
   583         // Custom note id generated, report it back to client
       
   584         WriteResponse( iResponseMsg, id );
       
   585         return iResponseMsg;
       
   586         }
       
   587     return KNullDesC8();
       
   588     }
       
   589 
       
   590 // ---------------------------------------------------------
       
   591 // CAknSoftNotificationSubject::StartL()
       
   592 // This is the asynchronous version that should not be used
       
   593 // (other items were commented in a header).
       
   594 // ---------------------------------------------------------
       
   595 //
       
   596 void CAknSoftNotificationSubject::StartL(const TDesC8& aBuffer, TInt aReplySlot, 
       
   597     const RMessagePtr2& aMessage)
       
   598     {
       
   599     TInt id = KErrNotFound;
       
   600     HandleNotifierMessageL( aBuffer, id );    
       
   601     if( id > 0 )
       
   602         {
       
   603         // Custom note id generated, report it back to client
       
   604         WriteResponse( iResponseMsg, id );
       
   605         aMessage.WriteL( aReplySlot, iResponseMsg );
       
   606         }
       
   607     aMessage.Complete( KErrNone );
       
   608     }
       
   609 
       
   610 // ---------------------------------------------------------
       
   611 // CAknSoftNotificationSubject::Cancel()
       
   612 // Not much happening here. If a certain type of of soft
       
   613 // notification should be canceled, please use the wrapper's
       
   614 // method
       
   615 // (other items were commented in a header).
       
   616 // ---------------------------------------------------------
       
   617 //
       
   618 void CAknSoftNotificationSubject::Cancel()
       
   619     {
       
   620     }
       
   621 
       
   622 // ---------------------------------------------------------
       
   623 // CAknSoftNotificationSubject::UpdateL(const TDesC8& aBuffer)
       
   624 //
       
   625 // (other items were commented in a header).
       
   626 // ---------------------------------------------------------
       
   627 //
       
   628 TPtrC8 CAknSoftNotificationSubject::UpdateL(const TDesC8& aBuffer)
       
   629     {
       
   630     return StartL( aBuffer );
       
   631     }
       
   632 
       
   633 // ---------------------------------------------------------
       
   634 // HandleMessageL(const TDesC8& aBuffer)
       
   635 // Required because of framework
       
   636 // (other items were commented in a header).
       
   637 // ---------------------------------------------------------
       
   638 //
       
   639 void HandleMessageL( const TDesC8& /*aBuffer*/ )
       
   640     {
       
   641     }
       
   642 
       
   643 void CAknSoftNotificationSubject::HandleNotifierMessageL( 
       
   644     const TDesC8& aBuffer, TInt& aNoteId )
       
   645     {
       
   646     RDesReadStream readStream( aBuffer );
       
   647 
       
   648     if ( aBuffer.Length() < 4 // TInt takes four char
       
   649         || readStream.ReadInt32L() != KAKNNOTIFIERSIGNATURE )
       
   650         {
       
   651         User::Leave( KErrArgument );
       
   652         }
       
   653 
       
   654     TAknSoftNotificationType type = STATIC_CAST(TAknSoftNotificationType,readStream.ReadUint8L());
       
   655     TInt16 count = readStream.ReadInt16L();
       
   656     
       
   657     //set current idle status to appui
       
   658     if ( type == ESetIdleState )
       
   659         {
       
   660         ((CAknCapAppServerAppUi*)(CEikonEnv::Static())->EikAppUi())
       
   661             ->SetIdleActive( count ? ETrue : EFalse );
       
   662         }
       
   663         
       
   664     switch ( type )
       
   665         {
       
   666         case ENetworkInformationNotification:
       
   667         case ESelectNetworkNotification:
       
   668         case EUnstructuredSSDataNotification:
       
   669         case EVoiceMailNotification:
       
   670         case ESeparateVoiceMailOnLine1Notification:
       
   671         case ESeparateVoiceMailOnLine2Notification:
       
   672         case ECellBroadcastNotification:
       
   673         case EDeliveryReportNotification:
       
   674         case EClass0SmsNotification:
       
   675         case EMissedCallsNotification:
       
   676         case ENewMessagesNotification:
       
   677         case ENewMailNotification:
       
   678         case EShowActiveNotifications:
       
   679         case EShowGroupedNotification:
       
   680         case ECustomSoftNotification:
       
   681         case EChatMessageNotification:
       
   682         case ESetIdleState:
       
   683             break;
       
   684         case ENoSoftNotification:
       
   685         case EMaxSoftNotification:
       
   686         default:
       
   687             // Simply return with no error code.
       
   688             return;
       
   689         }
       
   690 
       
   691     // Stores value for future use.
       
   692     TBool notificationsSavedTmp = iNotificationsSaved;
       
   693 
       
   694     TInt err = KErrNone;
       
   695     if ( !iIdleStateActive )
       
   696         {
       
   697         TRAP( err, LoadAndQueueSoftNotesL() ); // leaves if file does not exist.
       
   698         }
       
   699     else if ( type != ESetIdleState && type != EShowActiveNotifications ) 
       
   700         {
       
   701         // To make sure that changes will be saved even we didn't load them.
       
   702         iNotificationsSaved = EFalse; 
       
   703         }
       
   704 
       
   705     if ( err && err != KErrNotFound && err != KErrNoMemory ) 
       
   706         {
       
   707         // There was an error, check allowed error codes, others mean corruption of data.
       
   708         CEikonEnv::Static()->FsSession().Delete( KAknSNFilename );
       
   709         iNotificationsSaved = EFalse;
       
   710         }
       
   711 
       
   712 #ifdef _DEBUG
       
   713     _LIT(KDmsg, "AknSoftNotificationPlugin, HandleNotifierMessageL:type %d,count %d, Load returned %d");
       
   714     RDebug::Print(KDmsg,type,count,err);
       
   715 #endif
       
   716 
       
   717     if ( type == EShowActiveNotifications )
       
   718         {
       
   719         return;
       
   720         }
       
   721 
       
   722     if ( type == ESetIdleState )
       
   723         {
       
   724         if ( count )
       
   725             {
       
   726             iGlobalNoteController->SetMaxDisplayPriorityL( KMaxTInt );
       
   727             iIdleStateActive = ETrue;
       
   728             }
       
   729         else
       
   730             {
       
   731             iGlobalNoteController->SetMaxDisplayPriorityL( KMinimumSoftNotePriority );
       
   732             iIdleStateActive = EFalse;
       
   733             }
       
   734         return;
       
   735         }
       
   736 
       
   737     TChar isCancel = readStream.ReadUint8L();
       
   738     TChar addCount = readStream.ReadUint8L();
       
   739 
       
   740     // using hbuf allows us to use dynamic sized buffers, client should send the info...
       
   741     HBufC* noteTextH = HBufC::NewLC( KGlobalNoteTextLength );
       
   742     TPtr noteText = noteTextH->Des();
       
   743     
       
   744     readStream >> noteText;
       
   745 
       
   746     if ( count == 0 && !addCount )
       
   747         {
       
   748         isCancel = 1; // true
       
   749         }
       
   750     else if ( count < 0 )
       
   751         {
       
   752         count = 1;
       
   753         }
       
   754 
       
   755     if ( type == ECustomSoftNotification )
       
   756         {
       
   757         TInt customNoteID = readStream.ReadInt32L();
       
   758 
       
   759         CCustomNotifParams* params = SeekCustomNoteForId( customNoteID );
       
   760         TInt noteId = ( params==0 ) ? KErrNotFound : params->iNoteId;
       
   761 
       
   762         if ( isCancel )
       
   763             {
       
   764             if ( !params ) 
       
   765                 {
       
   766                 // No note for id, no need to do anything but restore the iNotificationsSaved value.
       
   767                 CleanupStack::PopAndDestroy( noteTextH );
       
   768                 iNotificationsSaved = notificationsSavedTmp;
       
   769                 return;
       
   770                 }
       
   771 
       
   772             if ( noteId == 0 ) // was displayed in grouped form
       
   773                 {
       
   774                 RemoveCustomNoteForId( customNoteID );
       
   775                 
       
   776                 if (!IsGroupedFormed())
       
   777                     {
       
   778                     // ScheduleGroupedNotifierL does not remove EShowGroupedNotification item
       
   779                     // so let's do it here.
       
   780                     RemoveByType(EShowGroupedNotification);
       
   781                     }                
       
   782                 
       
   783                 ScheduleGroupedNotifierL();
       
   784                 SaveSoftNotificationsL();
       
   785                 
       
   786                 // If grouped note was visible and only one groupable soft note was left,
       
   787                 // then iSoftNoteEntryList and iCustomNoteParamsStack states are not exactly 
       
   788                 // correct. Load restores this state.
       
   789                 TRAP_IGNORE(LoadAndQueueSoftNotesL());
       
   790                 }
       
   791             else
       
   792                 {
       
   793                 RemoveCustomNoteForId( noteId, ETrue );
       
   794                 if ( noteId != KErrNotFound ) // was added to global notes queue
       
   795                     {
       
   796                     iGlobalNoteController->TryDisplayNextNoteL();
       
   797                     }
       
   798                     
       
   799                 SaveSoftNotificationsL();           
       
   800                 }
       
   801             
       
   802             CleanupStack::PopAndDestroy( noteTextH );
       
   803             return;
       
   804             }
       
   805 
       
   806         if ( params ) // Remove old
       
   807             {
       
   808             count += ( addCount ? params->iCount : 0 );
       
   809             TBool isNotGrouped = noteId != 0;
       
   810             RemoveCustomNoteForId( isNotGrouped ? noteId : customNoteID, isNotGrouped );
       
   811             }
       
   812 
       
   813         TBool newNote = ( params == NULL );
       
   814         AddNewCustomNoteL( readStream, count, newNote );
       
   815 
       
   816         if( iCustomNoteParamsStack && 
       
   817             iCustomNoteParamsStack->iParamType == KAknSoftNotificationDynamic )
       
   818             {
       
   819             aNoteId = iCustomNoteParamsStack->iId; // generated id
       
   820             TPtrC customTxt( iCustomNoteParamsStack->CustomText( count, EFalse ) );
       
   821             if( customTxt.Length() > 0 )
       
   822                 {
       
   823                 noteText.Copy( customTxt.Left( KGlobalNoteTextLength ) );
       
   824                 }
       
   825             }
       
   826         }
       
   827 
       
   828     if ( !isCancel )
       
   829         {
       
   830 #ifdef __COVER_DISPLAY
       
   831         // Play tone for select network notification immediately if device has cover display.
       
   832         if ((type == ESelectNetworkNotification) && count && !iSoftNotificationAmounts[type])
       
   833             {
       
   834             ((CAknCapAppServerAppUi*)(CEikonEnv::Static())->EikAppUi())->KeySounds()->
       
   835                 PlaySound(CAknNoteDialog::EErrorTone);
       
   836             }
       
   837 #endif // __COVER_DISPLAY            
       
   838 
       
   839         TBool countChanged = ETrue;
       
   840         
       
   841         if ( addCount )
       
   842             {
       
   843             iSoftNotificationAmounts[type] += count;
       
   844             }
       
   845         else
       
   846             {
       
   847             if ( iSoftNotificationAmounts[type] == count )
       
   848                 {
       
   849                 // If the amount is not changed, set up a flag for
       
   850                 // not updating the note.
       
   851                 countChanged = EFalse;
       
   852                 }
       
   853             iSoftNotificationAmounts[type] = count;
       
   854             }
       
   855             
       
   856         UpdateNoteL(type, noteText, iSoftNotificationAmounts[type], countChanged);
       
   857         CleanupStack::PopAndDestroy( noteTextH );
       
   858 
       
   859         User::ResetInactivityTime();
       
   860         }
       
   861     else // Cancel note by type
       
   862         {
       
   863         CleanupStack::PopAndDestroy( noteTextH );
       
   864 
       
   865         if (iSoftNotificationAmounts[type] == 0)
       
   866             {
       
   867             // There is not this type of soft notifications on queue
       
   868             // Just restore the iNotificationsSaved value and return.
       
   869             iNotificationsSaved = notificationsSavedTmp;
       
   870             return;
       
   871             }
       
   872             
       
   873         iSoftNotificationAmounts[type] = 0;
       
   874         RemoveByType(type);
       
   875         
       
   876         if (type == EMissedCallsNotification ||
       
   877             type == ENewMessagesNotification ||
       
   878             type == ENewMailNotification ||
       
   879             type == EChatMessageNotification)
       
   880             {
       
   881             RemoveByType(EShowGroupedNotification);
       
   882             ScheduleGroupedNotifierL();
       
   883             }
       
   884         else
       
   885             {
       
   886             iGlobalNoteController->TryDisplayNextNoteL();
       
   887             }
       
   888         }
       
   889 
       
   890     SaveSoftNotificationsL();
       
   891     }
       
   892 
       
   893 // ---------------------------------------------------------
       
   894 // CAknSoftNotificationSubject::GroupedNoteCompletedL(TInt aCommandId,TAknGroupedNotifierItem aSelectedItem)
       
   895 // (other items were commented in a header).
       
   896 // ---------------------------------------------------------
       
   897 //
       
   898 void CAknSoftNotificationSubject::GroupedNoteCompletedL(TInt aCommandId,TAknGroupedNotifierItem aSelectedItem)
       
   899     {
       
   900     if ( iGroupedNote )
       
   901         {
       
   902         //No delete is necessary as the dialog will take care of deleting itself
       
   903         iGroupedNote->RemoveEditorIndicator();
       
   904         iGroupedNote = NULL;
       
   905         }
       
   906 
       
   907     if ( aCommandId == EEikBidTab ) // Apps or end-key pressed
       
   908         {
       
   909         SaveSoftNotificationsL();
       
   910         ClearAllNotes();
       
   911         return;
       
   912         }
       
   913 
       
   914     if ( aCommandId == EAknSoftkeyExit )
       
   915         {
       
   916         SetNcnFlag(EFalse);
       
   917         }
       
   918 
       
   919     // Make sure goruped notification is removed from queue
       
   920     RemoveByType(EShowGroupedNotification);
       
   921 
       
   922     if (aSelectedItem > EMaxItem || aSelectedItem < 0 ) // out of "static" range
       
   923         {
       
   924         CCustomNotifParams* params = SeekCustomNoteForId(aSelectedItem);
       
   925         if (params)
       
   926             {
       
   927             HandleCustomNoteCompletedL(params, aCommandId);
       
   928             }
       
   929         RemoveCustomNoteForId(aSelectedItem);
       
   930         
       
   931         // To allow this to fall through next clause (saving, rescheduling etc.).
       
   932         aCommandId = EAknSoftkeyOk; 
       
   933         }
       
   934 
       
   935     if (aCommandId == EAknSoftkeyShow  || aCommandId == EAknSoftkeyOk)
       
   936         {
       
   937         if (aSelectedItem == EMissedCalls)
       
   938             {
       
   939             iSoftNotificationAmounts[EMissedCallsNotification] = 0;
       
   940             LaunchMissedCallsAppL();
       
   941             }
       
   942         else if (aSelectedItem == ENewMessages)
       
   943             {
       
   944             iSoftNotificationAmounts[ENewMessagesNotification] = 0;
       
   945             LaunchNewMessagesAppL();
       
   946             }
       
   947         else if (aSelectedItem == ENewChatMsgs)
       
   948             {
       
   949             iSoftNotificationAmounts[EChatMessageNotification] = 0;
       
   950             LaunchNewIMAppL();
       
   951             }
       
   952         else if (aSelectedItem == ENewMails)
       
   953             {
       
   954             iSoftNotificationAmounts[ENewMailNotification] = 0;
       
   955             LaunchNewMailAppL();
       
   956             }
       
   957 
       
   958         ScheduleGroupedNotifierL();
       
   959         iNotificationsSaved = EFalse;
       
   960 
       
   961     }
       
   962     else if (aCommandId == EAknSoftkeyExit || aCommandId == KErrCancel)
       
   963         {
       
   964         if ( aCommandId == EAknSoftkeyExit )
       
   965             {
       
   966             iSoftNotificationAmounts[EMissedCallsNotification] = 0;
       
   967             iSoftNotificationAmounts[ENewMessagesNotification] = 0;
       
   968             iSoftNotificationAmounts[EChatMessageNotification] = 0;
       
   969             iSoftNotificationAmounts[ENewMailNotification] = 0;
       
   970 
       
   971             // Null Customs
       
   972             CCustomNotifParams* params = iCustomNoteParamsStack;
       
   973             while(params)
       
   974                 {
       
   975                 CCustomNotifParams* tmp = params->iNext;
       
   976                 if (params->iSupportsGroupedform)
       
   977                     {
       
   978                     if( params->iParamType == KAknSoftNotificationDynamic )
       
   979                         {
       
   980                         if (params->EnableObserver())
       
   981                             {
       
   982                             // notify user event
       
   983                             iDynamicSoftNoteManager->IssueEvent(
       
   984                                 params->iId, EAknDynamicSNoteEventCanceled, ETrue);    
       
   985                             }
       
   986                         }
       
   987                     RemoveCustomNoteForId(params->iId);
       
   988                     }
       
   989                 params = tmp;
       
   990                 }
       
   991 
       
   992             RemoveByType(EShowGroupedNotification); // Remove also from global notes queue
       
   993             iNotificationsSaved = EFalse;
       
   994             }
       
   995         iGlobalNoteController->TryDisplayNextNoteL();
       
   996         }
       
   997     SaveSoftNotificationsL();
       
   998     }
       
   999 
       
  1000 
       
  1001 // ---------------------------------------------------------
       
  1002 // CAknSoftNotificationSubject::UpdateNoteL(TSoftNotifierType aType)
       
  1003 // (other items were commented in a header).
       
  1004 // ---------------------------------------------------------
       
  1005 //
       
  1006 void CAknSoftNotificationSubject::UpdateNoteL(
       
  1007     TAknSoftNotificationType aType,const TDesC& aText, TInt aCount, TBool aCountChanged)
       
  1008     {
       
  1009     iLatestType = aType;
       
  1010 
       
  1011     if ((aType > ENoSoftNotification && aType < EMissedCallsNotification)
       
  1012         || aType == ECustomSoftNotification)
       
  1013         {
       
  1014         // Received an ungrouped soft notification
       
  1015         DisplayUngroupedNotifierL(aType, aText, aCount);
       
  1016         }
       
  1017     else if ((aType >= EMissedCallsNotification && aType <= ENewMailNotification)
       
  1018         || aType == EChatMessageNotification)
       
  1019         {
       
  1020         // Set shared data flag if this is missed calls notification.
       
  1021         // This is needed for synchronizing notes with screensaver
       
  1022         // indicator view.
       
  1023         if (aType == EMissedCallsNotification && aCount > 0)
       
  1024             {
       
  1025             SetNcnFlag( ETrue );
       
  1026             }
       
  1027             
       
  1028         // Update grouped notifier only if the count has actually changed.
       
  1029         // This removes flicker in some cases.
       
  1030         if ( aCountChanged )
       
  1031             {
       
  1032             ScheduleGroupedNotifierL();
       
  1033             }
       
  1034         }
       
  1035     }
       
  1036 
       
  1037 
       
  1038 void CAknSoftNotificationSubject::ScheduleGroupedNotifierL()
       
  1039     {
       
  1040     // Possible grouped notification
       
  1041     TBool grouped = IsGroupedFormed();
       
  1042     if (grouped)
       
  1043         {
       
  1044         if (iGroupedNote)
       
  1045             {
       
  1046             // grouped note already exists, so just update it
       
  1047             ShowGroupedNotificationL();
       
  1048             }
       
  1049         else
       
  1050             {
       
  1051             // Schedule grouped note
       
  1052             RemoveByType(EShowGroupedNotification);
       
  1053             RemoveByType(EMissedCallsNotification);
       
  1054             RemoveByType(ENewMessagesNotification);
       
  1055             RemoveByType(EChatMessageNotification);
       
  1056             RemoveByType(ENewMailNotification);
       
  1057 
       
  1058             CCustomNotifParams* params = iCustomNoteParamsStack;
       
  1059             for (;params;params = params->iNext)
       
  1060                 {
       
  1061                 if( params->iSupportsGroupedform )
       
  1062                     {
       
  1063                     if ( params->iNoteId != KErrNotFound && params->iNoteId != 0)
       
  1064                         {
       
  1065                         iGlobalNoteController->CancelNote(params->iNoteId, EFalse);
       
  1066                         for (TInt ii = 0; ii < iSoftNoteEntryList->Count(); ii++)
       
  1067                             {
       
  1068                             if (params->iNoteId == iSoftNoteEntryList->At(ii).iId )
       
  1069                                 {
       
  1070                                 iSoftNoteEntryList->At(ii).iId = 0;
       
  1071                                 iSoftNoteEntryList->At(ii).iCustomId = params->iId;
       
  1072                                 break;
       
  1073                                 }
       
  1074                             }
       
  1075                         }
       
  1076 
       
  1077                     params->iNoteId = 0;
       
  1078                     }
       
  1079                 }
       
  1080 
       
  1081             // Create grouped notification
       
  1082             TSoftNoteEntry softNote;
       
  1083             softNote.iType = EShowGroupedNotification;
       
  1084             softNote.iId = iGlobalNoteController->AddSoftNotificationL(KNullDesC, 0, 0,
       
  1085                 KGroupedNotification, 0);
       
  1086             iGlobalNoteController->TryDisplayNextNoteL();
       
  1087             iSoftNoteEntryList->AppendL(softNote);
       
  1088             }
       
  1089         }
       
  1090     else
       
  1091         {
       
  1092         if (iGroupedNote)
       
  1093             {
       
  1094             delete iGroupedNote;
       
  1095             iGroupedNote = NULL;
       
  1096             }
       
  1097         // Display using ungrouped layout
       
  1098         if (iSoftNotificationAmounts[EMissedCallsNotification])
       
  1099             {
       
  1100             DisplayUngroupedNotifierL(EMissedCallsNotification, KNullDesC, 
       
  1101                 iSoftNotificationAmounts[EMissedCallsNotification]);
       
  1102             }
       
  1103         if (iSoftNotificationAmounts[ENewMessagesNotification])
       
  1104             {
       
  1105             DisplayUngroupedNotifierL(ENewMessagesNotification, KNullDesC, 
       
  1106                 iSoftNotificationAmounts[ENewMessagesNotification]);
       
  1107             }
       
  1108         if (iSoftNotificationAmounts[EChatMessageNotification])
       
  1109             {
       
  1110             DisplayUngroupedNotifierL(EChatMessageNotification, KNullDesC, 
       
  1111                 iSoftNotificationAmounts[EChatMessageNotification]);
       
  1112             }
       
  1113         if (iSoftNotificationAmounts[ENewMailNotification])
       
  1114             {
       
  1115             DisplayUngroupedNotifierL(ENewMailNotification, KNullDesC, 
       
  1116                 iSoftNotificationAmounts[ENewMailNotification]);
       
  1117             }
       
  1118         }
       
  1119     }
       
  1120 
       
  1121 
       
  1122 
       
  1123 void CAknSoftNotificationSubject::DisplayUngroupedNotifierL(TAknSoftNotificationType aType, 
       
  1124     const TDesC& aText, TInt aCount)
       
  1125     {
       
  1126     TInt resource = 0;
       
  1127     TInt priority = 0;
       
  1128     TBool cancel = EFalse;
       
  1129     TInt count = 0;
       
  1130     TInt softkeys = 0;
       
  1131     TInt tone = 0; // ENoTone;
       
  1132     switch (aType)
       
  1133         {
       
  1134         case ENetworkInformationNotification:
       
  1135             resource = R_NETWORK_INFORMATION_NOTE;
       
  1136             softkeys = R_AVKON_SOFTKEYS_OK_EMPTY__OK;
       
  1137             priority = KNetworkInfoPriority;
       
  1138             break;
       
  1139         case ESelectNetworkNotification:
       
  1140             resource = R_SELECT_NETWORK_NOTE;
       
  1141             softkeys = R_AVKON_SOFTKEYS_OK_CANCEL__OK;
       
  1142             priority = KSelectNetworkPriority;
       
  1143 #ifndef __COVER_DISPLAY            
       
  1144             tone = CAknNoteDialog::EErrorTone;
       
  1145 #endif // __COVER_DISPLAY            
       
  1146             if ( CheckIfAlreadyExists(ESelectNetworkNotification) )
       
  1147                 {
       
  1148                 return;
       
  1149                 }
       
  1150             break;
       
  1151         case EUnstructuredSSDataNotification:
       
  1152             resource = R_UNSTRUCTURED_SS_DATA_NOTE;
       
  1153             softkeys = R_AVKON_SOFTKEYS_READ_EXIT__READ;
       
  1154             priority = KUSSDPriority;
       
  1155             break;
       
  1156         case EVoiceMailNotification:
       
  1157             resource = R_VOICE_MAIL_NOTE;
       
  1158             softkeys = R_AVKON_SOFTKEYS_LISTEN_EXIT__LISTEN;
       
  1159             priority = KVoiceMailPriority;
       
  1160             cancel = ETrue;
       
  1161             break;
       
  1162         case ESeparateVoiceMailOnLine2Notification:
       
  1163             resource = R_VOICE_MAIL_ON_LINE2_NOTE;
       
  1164             softkeys = R_AVKON_SOFTKEYS_LISTEN_EXIT__LISTEN;
       
  1165             priority = KVoiceMailOnLinePriority;
       
  1166             cancel = ETrue;
       
  1167             break;
       
  1168         case ESeparateVoiceMailOnLine1Notification:
       
  1169             resource = R_VOICE_MAIL_ON_LINE1_NOTE;
       
  1170             softkeys = R_AVKON_SOFTKEYS_LISTEN_EXIT__LISTEN;
       
  1171             priority = KVoiceMailOnLinePriority;
       
  1172             cancel = ETrue;
       
  1173             break;
       
  1174         case ECellBroadcastNotification:
       
  1175             resource = R_CELL_BROADCAST_NOTE;
       
  1176             softkeys = R_AVKON_SOFTKEYS_READ_EXIT__READ;
       
  1177             priority = KCBSPriority;
       
  1178             cancel = ETrue;
       
  1179             break;
       
  1180         case EMissedCallsNotification:
       
  1181             resource = R_MISSED_CALLS_NOTE;
       
  1182             softkeys = R_AVKON_SOFTKEYS_SHOW_EXIT__SHOW;
       
  1183             priority = KMissedCallsPriority;
       
  1184             cancel = ETrue;
       
  1185             SetNcnFlag(ETrue);
       
  1186             break;
       
  1187         case ENewMessagesNotification:
       
  1188             resource = R_NEW_MESSAGES_NOTE;
       
  1189             softkeys = R_AVKON_SOFTKEYS_SHOW_EXIT__SHOW;
       
  1190             priority = KNewMessagesPriority;
       
  1191             cancel = ETrue;
       
  1192             break;
       
  1193         case ENewMailNotification:
       
  1194             resource = R_NEW_MAIL_NOTE;
       
  1195             softkeys = R_AVKON_SOFTKEYS_SHOW_EXIT__SHOW;
       
  1196             priority = KNewEmailPriority;
       
  1197             cancel = ETrue;
       
  1198             break;
       
  1199         case EChatMessageNotification:
       
  1200             resource = R_NEW_CHAT_MESSAGES_NOTE;
       
  1201             softkeys = R_AVKON_SOFTKEYS_SHOW_EXIT__SHOW;
       
  1202             priority = KChatMessagePriority;
       
  1203             cancel = ETrue;
       
  1204             break;
       
  1205         case ECustomSoftNotification:
       
  1206             {
       
  1207             resource = iCustomNoteParamsStack->iId;
       
  1208             softkeys = iCustomNoteParamsStack->iParamData->iSoftkeys;
       
  1209             priority = iCustomNoteParamsStack->iParamData->iPriority;
       
  1210             tone = iCustomNoteParamsStack->iParamData->iTone;
       
  1211             cancel = EFalse;
       
  1212             count = iCustomNoteParamsStack->iCount;
       
  1213             break;
       
  1214             }
       
  1215         default:
       
  1216             break;
       
  1217         };
       
  1218 
       
  1219     if (cancel)
       
  1220         {
       
  1221         // Remove duplicate notes
       
  1222         RemoveByType(aType);
       
  1223         count = aCount;
       
  1224         }
       
  1225 
       
  1226     TSoftNoteEntry softNote;
       
  1227     softNote.iType = aType;
       
  1228     softNote.iCount = count;
       
  1229 
       
  1230 #ifdef _DEBUG
       
  1231     _LIT(KDmsg, "AknSoftNotificationPlugin, Adding ungrouped:type %d,count %d ");
       
  1232     RDebug::Print(KDmsg,aType, count);
       
  1233 #endif
       
  1234 
       
  1235     if ( aType == ECustomSoftNotification )
       
  1236         {
       
  1237         if( iCustomNoteParamsStack->iParamType == KAknSoftNotificationCustom )
       
  1238             {
       
  1239             TFileName resourceFile;
       
  1240             CEikonEnv* environment = CEikonEnv::Static();
       
  1241             resourceFile.Append(iCustomNoteParamsStack->iParamData->iResourceFile->Des());
       
  1242             BaflUtils::NearestLanguageFile(environment->FsSession(),resourceFile);
       
  1243     
       
  1244             TRAPD( err, iCustomNoteParamsStack->iCoeResourceHandle =
       
  1245                 environment->AddResourceFileL(resourceFile));
       
  1246     
       
  1247             if ( err )
       
  1248                 { // couldn't load note resource, remove note from queue
       
  1249 #ifdef _DEBUG
       
  1250                 _LIT(KDmsg2,"AknSoftNotificationPlugin,Resource loading failed: %s");
       
  1251                 RDebug::Print(KDmsg2,&resourceFile);
       
  1252 #endif
       
  1253                 RemoveCustomNoteForId(resource);
       
  1254                 return;
       
  1255                 }
       
  1256             }
       
  1257 
       
  1258         if (iCustomNoteParamsStack->iSupportsGroupedform && IsGroupedFormed())
       
  1259             { // don't add to global notes queue
       
  1260             softNote.iId = 0; // grouped, not in global notes queue
       
  1261             softNote.iCustomId = iCustomNoteParamsStack->iId;
       
  1262             iSoftNoteEntryList->AppendL(softNote);
       
  1263             ScheduleGroupedNotifierL();
       
  1264             return;
       
  1265             }
       
  1266         }
       
  1267 
       
  1268     if( aType == ECustomSoftNotification &&
       
  1269         iCustomNoteParamsStack->iParamType == KAknSoftNotificationDynamic )
       
  1270         {
       
  1271         if( iCustomNoteParamsStack->iDynamicData )
       
  1272             {
       
  1273             CAknDynamicNotificationData* data = 
       
  1274                 iCustomNoteParamsStack->iDynamicData;
       
  1275             softNote.iId = iGlobalNoteController->AddSoftNotificationL(
       
  1276                 aText,
       
  1277                 count,
       
  1278                 data->Priority(),
       
  1279                 data->Tone(),
       
  1280                 data->LeftSoftkey(),
       
  1281                 data->RightSoftkey(),
       
  1282                 data->ImageData() );
       
  1283             }
       
  1284         }
       
  1285     else
       
  1286         {
       
  1287         softNote.iId = iGlobalNoteController->AddSoftNotificationL(aText, resource, count, priority, 
       
  1288             softkeys, tone );
       
  1289         }
       
  1290         
       
  1291     if ( aType == ECustomSoftNotification )
       
  1292         {
       
  1293         CAknSDData* sdData = iCustomNoteParamsStack->iParamData->iSecondaryDisplayData;
       
  1294         
       
  1295         if ( sdData )
       
  1296             {
       
  1297             CAknSDData* cloneSDData = NULL;
       
  1298             cloneSDData = CAknSDData::NewL( sdData->iCategory, sdData->iDialogIdx, *(sdData->iAdditionalData) );
       
  1299             CleanupStack::PushL( cloneSDData );
       
  1300             
       
  1301             TBool sdDataSet = iGlobalNoteController->SetSDData( softNote.iId, cloneSDData );
       
  1302             
       
  1303             if ( sdDataSet )
       
  1304                 {
       
  1305                 CleanupStack::Pop( cloneSDData );
       
  1306                 }          
       
  1307             else // cloneSDData ownership not transferred
       
  1308             	{
       
  1309             	CleanupStack::PopAndDestroy( cloneSDData );
       
  1310             	}
       
  1311             }
       
  1312             
       
  1313         iCustomNoteParamsStack->iNoteId = softNote.iId;
       
  1314         }
       
  1315 
       
  1316     iGlobalNoteController->TryDisplayNextNoteL();
       
  1317     iSoftNoteEntryList->AppendL(softNote);
       
  1318 
       
  1319 #ifdef _DEBUG
       
  1320     _LIT(KDmsg3,"AknSoftNotificationPlugin, Added SoftNote:type %d,NoteId %d ");
       
  1321     RDebug::Print(KDmsg3,aType, softNote.iId);
       
  1322 #endif
       
  1323     }
       
  1324 
       
  1325 
       
  1326 void CAknSoftNotificationSubject::RemoveByType(TAknSoftNotificationType aType, TInt aId)
       
  1327     {
       
  1328     TInt count = iSoftNoteEntryList->Count();
       
  1329     for (TInt ii=count-1; ii>=0; ii--)
       
  1330         {
       
  1331         TSoftNoteEntry& entry = (*iSoftNoteEntryList)[ii];
       
  1332 
       
  1333         if ( ( aType != ECustomSoftNotification && entry.iType == aType)
       
  1334             || ( aId != 0 && entry.iType == ECustomSoftNotification && entry.iId == aId) )
       
  1335             {
       
  1336             iGlobalNoteController->CancelNote(entry.iId, EFalse);
       
  1337             iSoftNoteEntryList->Delete(ii);
       
  1338             }
       
  1339         }
       
  1340     }
       
  1341 
       
  1342 void CAknSoftNotificationSubject::ClearAllNotes()
       
  1343     {
       
  1344 #ifdef _DEBUG
       
  1345     _LIT(KDmsg, "AknSoftNotificationPlugin,ClearAllNotes");
       
  1346     RDebug::Print(KDmsg);
       
  1347 #endif
       
  1348 
       
  1349     while ( iSoftNoteEntryList->Count())
       
  1350         {
       
  1351         TSoftNoteEntry& entry = (*iSoftNoteEntryList)[0];
       
  1352         if (entry.iId != 0)
       
  1353             {
       
  1354             iGlobalNoteController->CancelNote(entry.iId, EFalse);
       
  1355             }
       
  1356         iSoftNotificationAmounts[entry.iType] = 0;
       
  1357         iSoftNoteEntryList->Delete(0);
       
  1358         }
       
  1359 
       
  1360     CCustomNotifParams* params = iCustomNoteParamsStack;
       
  1361     while ( params )
       
  1362         {
       
  1363         CCustomNotifParams* tmp = params;
       
  1364         params = params->iNext;
       
  1365         delete tmp;
       
  1366         }
       
  1367     iCustomNoteParamsStack = 0;
       
  1368     }
       
  1369 
       
  1370 // Used only with ungrouped notes
       
  1371 TAknSoftNotificationType CAknSoftNotificationSubject::TypeFromId(TInt aId)
       
  1372     {
       
  1373     TInt count = iSoftNoteEntryList->Count();
       
  1374     for (TInt ii = count - 1; ii >= 0; ii--)
       
  1375         {
       
  1376         TSoftNoteEntry& entry = (*iSoftNoteEntryList)[ii];
       
  1377         if (entry.iId == aId)
       
  1378             {
       
  1379             return entry.iType;
       
  1380             }
       
  1381         }
       
  1382     return ENoSoftNotification;
       
  1383     }
       
  1384 
       
  1385 // Used only with ungrouped notes
       
  1386 void CAknSoftNotificationSubject::CompleteId(TInt aId)
       
  1387     {
       
  1388     TInt count = iSoftNoteEntryList->Count();
       
  1389     for (TInt ii=count-1; ii>=0; ii--)
       
  1390         {
       
  1391         TSoftNoteEntry& entry = (*iSoftNoteEntryList)[ii];
       
  1392         if (entry.iId == aId)
       
  1393             {
       
  1394             // Set notification count to zero
       
  1395             iSoftNotificationAmounts[entry.iType] = 0;
       
  1396             iSoftNoteEntryList->Delete(ii);
       
  1397             RemoveCustomNoteForId(aId,ETrue);
       
  1398             iNotificationsSaved = EFalse;
       
  1399             return;
       
  1400             }
       
  1401         }
       
  1402     return;
       
  1403     }
       
  1404 
       
  1405 void CAknSoftNotificationSubject::SoftNoteCompleted(TInt aId, TInt aCommand)
       
  1406     {
       
  1407     TRAPD(err, DoSoftNoteCompletedL(aId, aCommand));
       
  1408     if (err)
       
  1409         {
       
  1410         CEikonEnv::Static()->HandleError(err);
       
  1411         }
       
  1412     }
       
  1413 
       
  1414 void CAknSoftNotificationSubject::DoSoftNoteCompletedL(TInt aId, TInt aCommand)
       
  1415     {
       
  1416     TAknSoftNotificationType type = TypeFromId( aId );
       
  1417 
       
  1418 #ifdef _DEBUG
       
  1419     _LIT(KDmsg, "AknSoftNotificationPlugin,DoSoftNoteCompletedL:type %d,NoteId %d, command %d ");
       
  1420     RDebug::Print(KDmsg,type, aId, aCommand);
       
  1421 #endif
       
  1422 
       
  1423     if ( aCommand == EAknSoftkeyExit )
       
  1424         {
       
  1425         if ( type == EMissedCallsNotification )
       
  1426             {
       
  1427             SetNcnFlag(EFalse);
       
  1428             }
       
  1429         if( type == ECustomSoftNotification )
       
  1430             {
       
  1431             CCustomNotifParams* params = SeekCustomNoteForId( aId, ETrue );
       
  1432             if( params )
       
  1433                 {
       
  1434                 HandleCustomNoteCanceledL( params, aCommand );
       
  1435                 }            
       
  1436             }
       
  1437         CompleteId(aId);
       
  1438         SaveSoftNotificationsL();
       
  1439         return;
       
  1440         }
       
  1441 
       
  1442     switch (type)
       
  1443         {
       
  1444         case ESelectNetworkNotification:
       
  1445             if (aCommand == EAknSoftkeyOk)
       
  1446                 {
       
  1447                 LaunchSelectNetworkAppL();
       
  1448                 CompleteId(aId);
       
  1449                 }
       
  1450             break;
       
  1451         case EUnstructuredSSDataNotification:
       
  1452             if (aCommand == EAknSoftkeyRead || aCommand == EAknSoftkeyOk)
       
  1453                 {
       
  1454                 LaunchUSSDAppL();
       
  1455                 CompleteId(aId);
       
  1456                 }
       
  1457             break;
       
  1458         case EVoiceMailNotification:
       
  1459         case ESeparateVoiceMailOnLine1Notification:
       
  1460         case ESeparateVoiceMailOnLine2Notification:
       
  1461             if (aCommand == EAknSoftkeyListen || aCommand == EAknSoftkeyOk)
       
  1462                 {
       
  1463                 LaunchNewVoiceMailAppL(type);
       
  1464                 CompleteId(aId);
       
  1465                 }
       
  1466             break;
       
  1467         case ECellBroadcastNotification:
       
  1468             if (aCommand == EAknSoftkeyRead || aCommand == EAknSoftkeyOk)
       
  1469                 {
       
  1470                 LaunchNewCbsAppL();
       
  1471                 CompleteId(aId);
       
  1472                 }
       
  1473             break;
       
  1474         case EMissedCallsNotification:
       
  1475             if (aCommand == EAknSoftkeyShow || aCommand == EAknSoftkeyOk)
       
  1476                 {
       
  1477                 LaunchMissedCallsAppL();
       
  1478                 CompleteId(aId);
       
  1479                 }
       
  1480             break;
       
  1481         case ENewMessagesNotification:
       
  1482             if (aCommand == EAknSoftkeyShow || aCommand == EAknSoftkeyOk)
       
  1483                 {
       
  1484                 LaunchNewMessagesAppL();
       
  1485                 CompleteId(aId);
       
  1486                 }
       
  1487             break;
       
  1488         case ENewMailNotification:
       
  1489             if (aCommand == EAknSoftkeyShow || aCommand == EAknSoftkeyOk)
       
  1490                 {
       
  1491                 LaunchNewMailAppL();
       
  1492                 CompleteId(aId);
       
  1493                 }
       
  1494             break;
       
  1495         case EChatMessageNotification:
       
  1496             if (aCommand == EAknSoftkeyShow || aCommand == EAknSoftkeyOk)
       
  1497                 {
       
  1498                 LaunchNewIMAppL();
       
  1499                 CompleteId(aId);
       
  1500                 }
       
  1501             break;
       
  1502         case ECustomSoftNotification:
       
  1503             {
       
  1504             CCustomNotifParams* params = SeekCustomNoteForId(aId, ETrue);
       
  1505             if (params)
       
  1506                 {
       
  1507                 HandleCustomNoteCompletedL(params, aCommand);
       
  1508                 CompleteId(aId);
       
  1509                 }
       
  1510             }
       
  1511             break;
       
  1512         default:
       
  1513             // Note type something else, this should not be the case.
       
  1514             // Remove note from queue anyway.
       
  1515             CompleteId( aId );
       
  1516             break;
       
  1517         }
       
  1518     SaveSoftNotificationsL();
       
  1519     }
       
  1520 
       
  1521 
       
  1522 void CAknSoftNotificationSubject::HandleCustomNoteCompletedL(CCustomNotifParams* aParams, 
       
  1523     TInt aCommand)
       
  1524     {
       
  1525     if (aParams->iHasViewInfo)
       
  1526         {
       
  1527         if ( aCommand == EAknSoftkeyOk ||
       
  1528              aParams->iParamData->iAcceptSoftKey == aCommand )
       
  1529             {
       
  1530             LaunchViewL( 
       
  1531                 ((aParams->iParamData->iPluralViewId != KNullViewId && aParams->iCount > 1)?
       
  1532                     aParams->iParamData->iPluralViewId:
       
  1533                     aParams->iParamData->iViewId),
       
  1534 
       
  1535                 aParams->iParamData->iCustomMessageId,
       
  1536                 aParams->ViewActivationMessage() );
       
  1537             }
       
  1538         }
       
  1539     
       
  1540     // notify user event
       
  1541     if( aParams->iParamType == KAknSoftNotificationDynamic )
       
  1542         {
       
  1543         if( aParams->EnableObserver() )
       
  1544             {
       
  1545             iDynamicSoftNoteManager->IssueEvent( 
       
  1546                 aParams->iId, EAknDynamicSNoteEventAccepted, ETrue );
       
  1547             }        
       
  1548         }
       
  1549     }
       
  1550 
       
  1551 void CAknSoftNotificationSubject::HandleCustomNoteCanceledL( 
       
  1552     CCustomNotifParams* aParams, TInt /*aCommand*/ )
       
  1553     {
       
  1554     // notify user event
       
  1555     if( aParams->iParamType == KAknSoftNotificationDynamic )
       
  1556         {
       
  1557         if( aParams->EnableObserver() )
       
  1558             {
       
  1559             iDynamicSoftNoteManager->IssueEvent( 
       
  1560                 aParams->iId, EAknDynamicSNoteEventCanceled, ETrue );
       
  1561             }         
       
  1562         }
       
  1563     }
       
  1564 
       
  1565 //
       
  1566 // Sets shared data flag to indicate that NCN is active.
       
  1567 // This implementation sets this only for missed calls note.
       
  1568 //
       
  1569 void CAknSoftNotificationSubject::SetNcnFlag(TBool aValue)
       
  1570     {
       
  1571     CRepository* repository = NULL;
       
  1572     TRAPD(ret, repository = CRepository::NewL(KCRUidAvkon));
       
  1573     if (ret == KErrNone)
       
  1574         {
       
  1575         ret = repository->Set(KAknNewContactsNoteActive, aValue);
       
  1576         }
       
  1577     delete repository;
       
  1578     }
       
  1579 
       
  1580 
       
  1581 // Handler function for ncn flag shared data state change.
       
  1582 TInt CAknSoftNotificationSubject::HandleNcnFlagStateChange(TAny* /* aPtr */)
       
  1583     {
       
  1584     return KErrNone;
       
  1585     }
       
  1586 
       
  1587 TBool CAknSoftNotificationSubject::ShowSoftNoteL(TInt aPriority, const TDesC& /*aText*/)
       
  1588     {
       
  1589     if (aPriority == KGroupedNotification)
       
  1590         {
       
  1591         ShowGroupedNotificationL();
       
  1592         return ETrue;
       
  1593         }
       
  1594     return EFalse;
       
  1595     }
       
  1596 
       
  1597 TBool CAknSoftNotificationSubject::CancelSoftNote(TInt aPriority)
       
  1598     {
       
  1599     if (aPriority == KGroupedNotification)
       
  1600         {
       
  1601         if (iGroupedNote)
       
  1602             {
       
  1603             iGroupedNote->RemoveEditorIndicator();
       
  1604             delete iGroupedNote;
       
  1605             iGroupedNote = NULL;
       
  1606             }
       
  1607         return ETrue;
       
  1608         }
       
  1609     return EFalse;
       
  1610     }
       
  1611 
       
  1612 // ---------------------------------------------------------
       
  1613 // CAknSoftNotificationSubject::ShowGroupedNotificationL()
       
  1614 // (other items were commented in a header).
       
  1615 // ---------------------------------------------------------
       
  1616 //
       
  1617 void CAknSoftNotificationSubject::ShowGroupedNotificationL()
       
  1618     {
       
  1619     if ( iGroupedNote )
       
  1620         {
       
  1621         iGroupedNote->RemoveEditorIndicator();
       
  1622         }
       
  1623 
       
  1624     CAknGroupedNotifierNote* note = new (ELeave) CAknGroupedNotifierNote();
       
  1625     CleanupStack::PushL( note );
       
  1626     note->ConstructL( this );
       
  1627 
       
  1628     note->SetItemAmountL(
       
  1629         EMissedCalls, 
       
  1630         iSoftNotificationAmounts[EMissedCallsNotification], 
       
  1631         iLatestType == EMissedCallsNotification);
       
  1632         
       
  1633     note->SetItemAmountL(
       
  1634         ENewMessages, 
       
  1635         iSoftNotificationAmounts[ENewMessagesNotification], 
       
  1636         iLatestType == ENewMessagesNotification);
       
  1637         
       
  1638     note->SetItemAmountL(
       
  1639         ENewChatMsgs, 
       
  1640         iSoftNotificationAmounts[EChatMessageNotification], 
       
  1641         iLatestType == EChatMessageNotification);
       
  1642         
       
  1643     note->SetItemAmountL(
       
  1644         ENewMails, 
       
  1645         iSoftNotificationAmounts[ENewMailNotification], 
       
  1646         iLatestType == ENewMailNotification);
       
  1647         
       
  1648     CleanupStack::Pop( note );
       
  1649 
       
  1650     note->ExecuteLD( R_GROUPED_SOFT_NOTIFICATION );
       
  1651 
       
  1652     delete iGroupedNote;
       
  1653     iGroupedNote = note;
       
  1654     if ( iKeysLocked && note )
       
  1655         {
       
  1656         iGroupedNote->ListBox()->View()->ItemDrawer()->SetFlags(
       
  1657             CListItemDrawer::EDisableHighlight );
       
  1658         }
       
  1659     }
       
  1660 
       
  1661 // ---------------------------------------------------------
       
  1662 // CAknSoftNotificationSubject::MessageNotifierShown()
       
  1663 // ---------------------------------------------------------
       
  1664 //
       
  1665 TBool CAknSoftNotificationSubject::MessageNotifierShown()
       
  1666     {
       
  1667     TBool messageNotifierActive( EFalse );
       
  1668 
       
  1669     for ( TInt ii = 0; ii <= ECustomSoftNotification; ii++)
       
  1670         {
       
  1671         // Check that one of the message notifiers is first in the 
       
  1672         // priority order (visible). 
       
  1673         if (iSoftNotificationAmounts[ii] > 0)
       
  1674             {
       
  1675             if (ii == EMissedCallsNotification && IsGroupedFormed())
       
  1676                 {
       
  1677                 continue;
       
  1678                 }
       
  1679             if ( ii == ENewMessagesNotification ||
       
  1680                  ii == ENewMailNotification ||
       
  1681                  ii == ECustomSoftNotification ) // Email uses custom soft note.
       
  1682                 {
       
  1683                 messageNotifierActive = ETrue;
       
  1684                 }
       
  1685             break;                
       
  1686             }
       
  1687         }
       
  1688 
       
  1689     return messageNotifierActive;
       
  1690     }
       
  1691 
       
  1692 // ---------------------------------------------------------
       
  1693 // CAknSoftNotificationSubject::ButtonGroupContainer()
       
  1694 // ---------------------------------------------------------
       
  1695 //
       
  1696 CEikButtonGroupContainer* CAknSoftNotificationSubject::ButtonGroupContainer()
       
  1697     {
       
  1698     CEikButtonGroupContainer* container = NULL;
       
  1699     if ( iGroupedNote ) 
       
  1700         {
       
  1701         container = &iGroupedNote->ButtonGroupContainer();
       
  1702         }
       
  1703     return container;
       
  1704     }
       
  1705         
       
  1706 // ---------------------------------------------------------
       
  1707 // CAknSoftNotificationSubject::IsGroupedFormed()
       
  1708 // (other items were commented in a header).
       
  1709 // ---------------------------------------------------------
       
  1710 //
       
  1711 TBool CAknSoftNotificationSubject::IsGroupedFormed()
       
  1712     {
       
  1713     TInt foundTypes = 0;
       
  1714     if (iSoftNotificationAmounts[EMissedCallsNotification])
       
  1715         {
       
  1716         foundTypes++;
       
  1717         }
       
  1718     if (iSoftNotificationAmounts[ENewMessagesNotification])
       
  1719         {
       
  1720         foundTypes++;
       
  1721         }
       
  1722     if (iSoftNotificationAmounts[EChatMessageNotification])
       
  1723         {
       
  1724         foundTypes++;
       
  1725         }
       
  1726     if (iSoftNotificationAmounts[ENewMailNotification])
       
  1727         {
       
  1728         foundTypes++;
       
  1729         }
       
  1730         
       
  1731     // check custom notes which support grouped form
       
  1732     CCustomNotifParams* params = iCustomNoteParamsStack;
       
  1733     for (;params;params = params->iNext)
       
  1734         {
       
  1735         if(params->iSupportsGroupedform)
       
  1736             {
       
  1737             foundTypes++;
       
  1738             }
       
  1739         }
       
  1740 
       
  1741     if (foundTypes > 1)
       
  1742         {
       
  1743         return ETrue;
       
  1744         }
       
  1745     else
       
  1746         {
       
  1747         return EFalse;
       
  1748         }
       
  1749     }
       
  1750 
       
  1751 // ------------------------------------
       
  1752 // From MAknGroupedNotifierNoteObserver
       
  1753 // Add items to grouped form
       
  1754 // ------------------------------------
       
  1755 void CAknSoftNotificationSubject::AddItemsL( CDesCArray& aTexts, CArrayFix<TInt>& aOrder )
       
  1756     {
       
  1757     // check custom notes which support grouped form
       
  1758     CCustomNotifParams* params = iCustomNoteParamsStack;
       
  1759     for (;params;params = params->iNext)
       
  1760         {
       
  1761         if(params->iSupportsGroupedform)
       
  1762             {
       
  1763             if( params->iParamType == KAknSoftNotificationDynamic )
       
  1764                 {
       
  1765                 if( params->iCount > 1 )
       
  1766                     {
       
  1767                     // plural text needs to be formatted
       
  1768                     TPtrC text( params->CustomText( params->iCount, ETrue ) );
       
  1769                     const TInt formatSpace = 11; // space needed for 'count'
       
  1770                     HBufC* buf = HBufC::NewLC( text.Length() + formatSpace );
       
  1771                     buf->Des().Format( text, params->iCount );
       
  1772                     
       
  1773                     aTexts.AppendL( *buf );
       
  1774                     aOrder.AppendL( params->iId );
       
  1775                     
       
  1776                     CleanupStack::PopAndDestroy( buf );
       
  1777                     }
       
  1778                 else
       
  1779                     {
       
  1780                     // append singular text
       
  1781                     aTexts.AppendL( params->CustomText( params->iCount, ETrue ) );
       
  1782                     aOrder.AppendL( params->iId );
       
  1783                     }
       
  1784                 }
       
  1785             else
       
  1786                 {
       
  1787                 // Load text
       
  1788                 CCoeEnv* coe = CCoeEnv::Static();
       
  1789                 TResourceReader reader;
       
  1790                 HBufC* buf = 0;
       
  1791     
       
  1792                 // Resources are loaded in DisplayUngroupedNotifierL()
       
  1793                 coe->CreateResourceReaderLC(reader, params->iParamData->iGroupedTextResourceId);
       
  1794                 TInt stringResource = reader.ReadInt32();
       
  1795     
       
  1796                 // Handle Singular / plural + possible plural string w/o number tag
       
  1797                 if (params->iCount == 1)
       
  1798                     {
       
  1799                     buf = coe->AllocReadResourceLC(stringResource);
       
  1800                     }
       
  1801                 else 
       
  1802                     {
       
  1803                     stringResource = reader.ReadInt32();
       
  1804                     buf = coe->AllocReadResourceLC(stringResource);
       
  1805                     _LIT(KNumberId, "%N");
       
  1806                     if (buf->Find(KNumberId) != KErrNotFound)
       
  1807                         {
       
  1808                         CleanupStack::PopAndDestroy();
       
  1809                         buf = 0;
       
  1810                         buf = StringLoader::LoadLC(stringResource,params->iCount);
       
  1811                         }
       
  1812                     }
       
  1813  
       
  1814                 // Add Text
       
  1815                 aTexts.AppendL(buf->Des());
       
  1816                 // add order
       
  1817                 aOrder.AppendL(params->iId);
       
  1818                 
       
  1819                 CleanupStack::PopAndDestroy( 2 ); // buf and reader
       
  1820                 }
       
  1821             
       
  1822 
       
  1823             }
       
  1824         }
       
  1825     }
       
  1826     
       
  1827 // --------------------------------------------------
       
  1828 // CAknSoftNotificationSubject::SoftkeysForCustomItem
       
  1829 // (other items were commented in a header).
       
  1830 // --------------------------------------------------
       
  1831 void CAknSoftNotificationSubject::SoftkeysForCustomItem(TAknGroupedNotifierItem aCustomItem,
       
  1832     TInt& aSoftkeyResourceId, TInt& aAcceptKeyId,
       
  1833     TDes& aLeftSoftkey,
       
  1834     TDes& aRightSoftkey )
       
  1835     {
       
  1836     CCustomNotifParams* params = SeekCustomNoteForId(aCustomItem, EFalse);
       
  1837     if( params )
       
  1838         {
       
  1839         if( params->iParamType == KAknSoftNotificationCustom && 
       
  1840             params->iParamData )
       
  1841             {
       
  1842             aSoftkeyResourceId = params->iParamData->iSoftkeys;
       
  1843             aAcceptKeyId       = params->iParamData->iAcceptSoftKey;
       
  1844             }
       
  1845         
       
  1846         if( params->iParamType == KAknSoftNotificationDynamic && 
       
  1847             params->iDynamicData )
       
  1848             {
       
  1849             TPtrC sk( params->iDynamicData->LeftSoftkey() );
       
  1850             if( sk.Length() > 0 )
       
  1851                 {
       
  1852                 aLeftSoftkey.Copy( sk.Left( aLeftSoftkey.MaxLength() ) );
       
  1853                 }
       
  1854             
       
  1855             sk.Set( params->iDynamicData->RightSoftkey() );
       
  1856             if( sk.Length() > 0 )
       
  1857                 {
       
  1858                 aRightSoftkey.Copy( sk.Left( aRightSoftkey.MaxLength() ) );
       
  1859                 }
       
  1860             
       
  1861             }
       
  1862         }
       
  1863     }
       
  1864 
       
  1865 // ---------------------------------------------------------
       
  1866 // CAknSoftNotificationSubject::LaunchMissedCallsAppL()
       
  1867 // (other items were commented in a header).
       
  1868 // ---------------------------------------------------------
       
  1869 //
       
  1870 void CAknSoftNotificationSubject::LaunchMissedCallsAppL()
       
  1871     {
       
  1872     TPtrC8 msg(KLogsActivationMsg);                
       
  1873     
       
  1874     TApaTaskList taskList( CCoeEnv::Static()->WsSession() );
       
  1875     TApaTask task = taskList.FindApp( KUidLogs );
       
  1876 
       
  1877     // close fsw in case it is active.
       
  1878     // this is needed because LaunchMissedCallsAppL doesn't call 
       
  1879     // method LaunchViewL, which does the same
       
  1880     ((CAknCapAppServerAppUi*)(CEikonEnv::Static())->EikAppUi())->
       
  1881         HandleResourceChangeL(KAknInternalFSWClose); // won't leave
       
  1882     
       
  1883     TInt err = KErrNone;
       
  1884     
       
  1885     if( task.Exists() ) //Logs already open. Request it to
       
  1886         {               //activate the correct view
       
  1887         task.SendMessage( KUidLogs, msg ); // the uid has no meaning so just re-use existing 
       
  1888 
       
  1889      // preventing from the flicker of log view, the view will activte ieself when receiving a message.   
       
  1890      // task.BringToForeground();
       
  1891         }
       
  1892     else                //Start Logs and request it to activate
       
  1893         {               //the correct view
       
  1894         TApaAppInfo appInfo;
       
  1895         RApaLsSession lsSession;
       
  1896         err = lsSession.Connect();
       
  1897         
       
  1898         if ( err == KErrNone )
       
  1899             {
       
  1900             CleanupClosePushL( lsSession );
       
  1901             
       
  1902             if( lsSession.GetAppInfo( appInfo, KUidLogs ) == KErrNone )
       
  1903                 {
       
  1904                 CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
  1905                 cmdLine->SetExecutableNameL( appInfo.iFullName );
       
  1906                 cmdLine->SetCommandL( EApaCommandRun );
       
  1907                 cmdLine->SetTailEndL( msg );
       
  1908 
       
  1909                 lsSession.StartApp( *cmdLine );
       
  1910                 CleanupStack::PopAndDestroy( cmdLine );
       
  1911                 }
       
  1912 
       
  1913             CleanupStack::PopAndDestroy();  // lsSession
       
  1914             }
       
  1915         else
       
  1916             {
       
  1917             User::LeaveIfError( err );
       
  1918             }
       
  1919         }
       
  1920     
       
  1921     if ( err == KErrNone )
       
  1922         {
       
  1923         // We'll assume that application was launched/activated succesfully
       
  1924         SetNcnFlag(EFalse);
       
  1925         }
       
  1926     }
       
  1927 
       
  1928 // ---------------------------------------------------------
       
  1929 // CAknSoftNotificationSubject::LaunchNewMessagesAppL()
       
  1930 // (other items were commented in a header).
       
  1931 // ---------------------------------------------------------
       
  1932 //
       
  1933 void CAknSoftNotificationSubject::LaunchNewMessagesAppL()
       
  1934     {        
       
  1935     TInt viewtype = 0; // Default is traditional Inbox
       
  1936 
       
  1937     if ( iMessagingRepository )
       
  1938         {
       
  1939 	// Read the messaging settings
       
  1940         iMessagingRepository->Get(KMessagingAppDefaultViewCRKey,viewtype);
       
  1941         }
       
  1942 
       
  1943     if ( viewtype == 1 ) // Launch conversations 
       
  1944         {
       
  1945         LaunchViewL( 
       
  1946                 KConversationApplicationViewUid,           
       
  1947                 TUid::Uid(KConversationListViewUid),         
       
  1948                 KNullDesC8() );
       
  1949         }    
       
  1950     else  // Launch traditional Inbox
       
  1951         {
       
  1952         LaunchViewL( 
       
  1953             KMessagingCentreInboxView, 
       
  1954             TUid::Uid(KMsvGlobalInBoxIndexEntryIdValue), 
       
  1955             KNullDesC8() );
       
  1956         }    
       
  1957     }
       
  1958 
       
  1959 // ---------------------------------------------------------
       
  1960 // CAknSoftNotificationSubject::LaunchNewMailAppL()
       
  1961 // (other items were commented in a header).
       
  1962 // ---------------------------------------------------------
       
  1963 //
       
  1964 void CAknSoftNotificationSubject::LaunchNewMailAppL()
       
  1965     {
       
  1966     // reactivate MCE main view with arbitrary UID
       
  1967     LaunchViewL( KMessagingCentreMainViewUid, TUid::Uid(1),KNullDesC8() );
       
  1968     }
       
  1969 
       
  1970 void CAknSoftNotificationSubject::LaunchNewCbsAppL()
       
  1971     {
       
  1972     if ( iSoftNotificationAmounts[ECellBroadcastNotification] == 1)
       
  1973         {
       
  1974         LaunchViewL( KCbsApplicationUidMessageView, TUid::Uid(1), KNullDesC8() );
       
  1975         }
       
  1976     else
       
  1977         {
       
  1978         LaunchViewL( KCbsApplicationUidTopicListView, TUid::Uid(1), KNullDesC8() );
       
  1979         }
       
  1980     }
       
  1981 
       
  1982 void CAknSoftNotificationSubject::LaunchNewVoiceMailAppL(TInt aType)
       
  1983     {
       
  1984     TUid uid = {1}; // als line 1 or no als (TVmbxNumberEntry::EAlsLine1Entry)
       
  1985     if ( aType == ESeparateVoiceMailOnLine2Notification )
       
  1986         {
       
  1987         uid.iUid = 2; // (TVmbxNumberEntry::EAlsLine2Entry)
       
  1988         }
       
  1989 
       
  1990     LaunchViewL( KSpeeddialVmbxDialUidView, uid, KExternalLaunch );
       
  1991     }
       
  1992 
       
  1993 void CAknSoftNotificationSubject::LaunchSelectNetworkAppL()
       
  1994     {
       
  1995     LaunchViewL( KSelectNetworkAppUidView, TUid::Uid( KGSCustomActivateNetView ), KNullDesC8() );
       
  1996     }
       
  1997 
       
  1998 void CAknSoftNotificationSubject::LaunchUSSDAppL()
       
  1999     {
       
  2000     }
       
  2001 
       
  2002 void CAknSoftNotificationSubject::LaunchViewL(const TVwsViewId& aViewId, TUid aCustomMessageId, 
       
  2003     const TDesC8& aCustomMessage)
       
  2004     {
       
  2005     CCoeEnv::Static()->AppUi()->CreateActivateViewEventL(aViewId, aCustomMessageId, aCustomMessage);
       
  2006 
       
  2007     SaveSoftNotificationsL();
       
  2008     
       
  2009     // close fsw in case it is active.
       
  2010     ((CAknCapAppServerAppUi*)(CEikonEnv::Static())->EikAppUi())->HandleResourceChangeL(
       
  2011         KAknInternalFSWClose); // won't leave
       
  2012    
       
  2013     // We assume that view switching was successful, change idle state to false:
       
  2014     delete iIdle;
       
  2015     iIdle = 0;
       
  2016     iIdle = CIdle::NewL(EPriorityLow);
       
  2017     iIdle->Start(TCallBack(SetIdleStateFalse, this));
       
  2018     }
       
  2019 
       
  2020 TInt CAknSoftNotificationSubject::SetIdleStateFalse(TAny* aThis)
       
  2021     {
       
  2022     TRAPD( err, ((CAknSoftNotificationSubject*)aThis)->iGlobalNoteController->
       
  2023         SetMaxDisplayPriorityL(KMinimumSoftNotePriority))
       
  2024     if (!err)
       
  2025         {
       
  2026         ((CAknSoftNotificationSubject*)aThis)->iIdleStateActive = EFalse;
       
  2027         ((CAknCapAppServerAppUi*)(CEikonEnv::Static())->EikAppUi())->SetIdleActive( EFalse );
       
  2028         }
       
  2029     return err;
       
  2030     }
       
  2031 
       
  2032 void CAknSoftNotificationSubject::SaveSoftNotificationsL()
       
  2033     {
       
  2034     // Save all soft notifications in case of power failure
       
  2035     if ( iNotificationsSaved ) // notifications haven't been loaded since saved i.e. no changes
       
  2036         {
       
  2037         return;
       
  2038         }
       
  2039 
       
  2040     TInt count = iSoftNoteEntryList->Count();
       
  2041     RFs& fs = CEikonEnv::Static()->FsSession();
       
  2042 #ifdef __COVER_DISPLAY  
       
  2043     iCoverClient->CancelCommand();
       
  2044     iCoverClient->ResetBuffer();
       
  2045 #endif
       
  2046     if (count == 0)
       
  2047         {
       
  2048         // Nothing to save, delete any existing file
       
  2049         TInt err = fs.Delete(KAknSNFilename);
       
  2050         iNotificationsSaved = EFalse;
       
  2051 #ifdef __COVER_DISPLAY  
       
  2052         // if deleted for the first time, inform the cover ui,
       
  2053         // otherwise the deletion returns KErrNotFound
       
  2054         if ( err == KErrNone ) 
       
  2055             {
       
  2056             // inform the cover ui that there are no soft notifications
       
  2057             iCoverClient->BufStream().WriteInt32L(count);
       
  2058             iCoverClient->BufStream().CommitL();
       
  2059             iCoverClient->IssueCommand();
       
  2060             }
       
  2061 #endif        
       
  2062         }
       
  2063     else
       
  2064         {
       
  2065         // Create new file and save soft notifications
       
  2066         RFileWriteStream file;
       
  2067         TInt err = file.Replace(fs, KAknSNFilename, EFileWrite);
       
  2068         // path may not yet exist in 3.0 (private directory).
       
  2069         if (err == KErrPathNotFound)
       
  2070             {
       
  2071             User::LeaveIfError(fs.MkDirAll(KAknSNFilename));
       
  2072             User::LeaveIfError(file.Create(fs, KAknSNFilename, EFileWrite));
       
  2073             }
       
  2074 
       
  2075         CleanupClosePushL(file);
       
  2076         file.WriteInt32L(count);
       
  2077 
       
  2078 #ifdef __COVER_DISPLAY  
       
  2079         TBool groupedExists = EFalse;
       
  2080         iCoverClient->BufStream().WriteInt32L(count);
       
  2081 #endif
       
  2082 
       
  2083         // Save in reverse order so order of notifications with identical priority remains
       
  2084         for (TInt ii = count - 1; ii >= 0; ii--)
       
  2085             {
       
  2086             TSoftNoteEntry& entry = (*iSoftNoteEntryList)[ii];
       
  2087             SaveNoteL(file, entry);
       
  2088 
       
  2089 #ifdef __COVER_DISPLAY
       
  2090             if (entry.iType == EShowGroupedNotification)
       
  2091                 {
       
  2092                 groupedExists = ETrue;
       
  2093                 }
       
  2094             
       
  2095             iCoverClient->BufStream().WriteInt32L(entry.iType);
       
  2096             iCoverClient->BufStream().WriteInt32L(entry.iCount);
       
  2097 #endif
       
  2098             };
       
  2099 
       
  2100 #ifdef __COVER_DISPLAY
       
  2101 
       
  2102         TUint8 customsWCoverDataCount( 0 );
       
  2103         // we don't have actual count of custom params (nor ones with secondary display data..)
       
  2104         for (CCustomNotifParams* params = iCustomNoteParamsStack; params; params = params->iNext)
       
  2105             {
       
  2106             if (params->iParamData->iSecondaryDisplayData)
       
  2107                 {
       
  2108                 customsWCoverDataCount++;
       
  2109                 }
       
  2110             }                
       
  2111             
       
  2112         iCoverClient->BufStream().WriteInt8L(customsWCoverDataCount);
       
  2113         if (customsWCoverDataCount)
       
  2114             {
       
  2115             for (CCustomNotifParams* params = iCustomNoteParamsStack; params; params = params->iNext)
       
  2116                 {
       
  2117                 if (params->iParamData->iSecondaryDisplayData)
       
  2118                     {
       
  2119                     iCoverClient->BufStream() << *params->iParamData->iSecondaryDisplayData;
       
  2120                     }
       
  2121                 }
       
  2122             }
       
  2123 
       
  2124         if (groupedExists)
       
  2125             {
       
  2126             iCoverClient->BufStream().WriteInt32L(EMissedCallsNotification);
       
  2127             iCoverClient->BufStream().WriteInt32L(iSoftNotificationAmounts[EMissedCallsNotification]);
       
  2128             iCoverClient->BufStream().WriteInt32L(ENewMessagesNotification);
       
  2129             iCoverClient->BufStream().WriteInt32L(iSoftNotificationAmounts[ENewMessagesNotification]);
       
  2130             iCoverClient->BufStream().WriteInt32L(EChatMessageNotification);
       
  2131             iCoverClient->BufStream().WriteInt32L(iSoftNotificationAmounts[EChatMessageNotification]);
       
  2132             iCoverClient->BufStream().WriteInt32L(ENewMailNotification);
       
  2133             iCoverClient->BufStream().WriteInt32L(iSoftNotificationAmounts[ENewMailNotification]);
       
  2134             }
       
  2135 
       
  2136         iCoverClient->BufStream().CommitL();
       
  2137         iCoverClient->IssueCommand();
       
  2138 #endif
       
  2139         CleanupStack::PopAndDestroy();  // close file
       
  2140         iNotificationsSaved = ETrue;
       
  2141         }
       
  2142     }
       
  2143 
       
  2144 
       
  2145 void CAknSoftNotificationSubject::SaveNoteL(RWriteStream& aFile, TSoftNoteEntry& aEntry)
       
  2146     {
       
  2147     TInt plural = aEntry.iCount;
       
  2148     const TDesC& text = iGlobalNoteController->NoteText(aEntry.iId);
       
  2149 
       
  2150 #ifdef _DEBUG
       
  2151     _LIT(KDmsg, "AknSoftNotificationPlugin,SaveNoteL:type %d,NoteId %d, count %d ");
       
  2152     RDebug::Print(KDmsg, aEntry.iType, aEntry.iId, plural);
       
  2153 #endif
       
  2154 
       
  2155     switch (aEntry.iType)
       
  2156         {
       
  2157         case ENetworkInformationNotification:
       
  2158         case EUnstructuredSSDataNotification:
       
  2159             aFile.WriteUint8L(aEntry.iType);
       
  2160             aFile << text;
       
  2161             break;
       
  2162         case ESelectNetworkNotification:
       
  2163             aFile.WriteUint8L(aEntry.iType);
       
  2164             break;
       
  2165         case ESeparateVoiceMailOnLine1Notification:
       
  2166         case ESeparateVoiceMailOnLine2Notification:
       
  2167         case ECellBroadcastNotification:
       
  2168         case EVoiceMailNotification:
       
  2169         case EMissedCallsNotification:
       
  2170         case ENewMessagesNotification:
       
  2171         case ENewMailNotification:
       
  2172         case EChatMessageNotification:
       
  2173             aFile.WriteUint8L(aEntry.iType);
       
  2174             aFile.WriteInt32L(plural);
       
  2175             break;
       
  2176         case EShowGroupedNotification:
       
  2177             aFile.WriteUint8L(aEntry.iType);
       
  2178             aFile.WriteInt32L(iSoftNotificationAmounts[EMissedCallsNotification]);
       
  2179             aFile.WriteInt32L(iSoftNotificationAmounts[ENewMessagesNotification]);
       
  2180             aFile.WriteInt32L(iSoftNotificationAmounts[EChatMessageNotification]);
       
  2181             aFile.WriteInt32L(iSoftNotificationAmounts[ENewMailNotification]);
       
  2182             break;
       
  2183         case ECustomSoftNotification:
       
  2184             {
       
  2185             CCustomNotifParams* params = 0;
       
  2186             if (aEntry.iId != 0 )
       
  2187                 {
       
  2188                 params = SeekCustomNoteForId(aEntry.iId,ETrue);
       
  2189                 }
       
  2190             else
       
  2191                 {
       
  2192                 params = SeekCustomNoteForId(aEntry.iCustomId);
       
  2193                 }
       
  2194 
       
  2195             if ( params )
       
  2196                 {
       
  2197                 aFile.WriteUint8L(aEntry.iType);
       
  2198                 aFile.WriteInt16L(params->iCount);
       
  2199                 aFile << *params;
       
  2200                 }
       
  2201             }
       
  2202             break;
       
  2203         default:
       
  2204             break;
       
  2205         }
       
  2206     }
       
  2207 
       
  2208 void CAknSoftNotificationSubject::LoadAndQueueSoftNotesL()
       
  2209     {
       
  2210     if ( !iNotificationsSaved )
       
  2211         {
       
  2212         return;
       
  2213         }
       
  2214 
       
  2215     RFs& fs = CEikonEnv::Static()->FsSession();
       
  2216     RFileReadStream file;
       
  2217 
       
  2218     TInt err = file.Open(fs, KAknSNFilename, EFileRead);
       
  2219     if ( err != KErrNone )
       
  2220         {
       
  2221         iNotificationsSaved =EFalse;
       
  2222         User::Leave(err);
       
  2223         }
       
  2224 
       
  2225     CleanupClosePushL(file);
       
  2226 
       
  2227     TInt count = file.ReadInt32L();
       
  2228 
       
  2229     if ( count > 0 )
       
  2230         {
       
  2231         ClearAllNotes();
       
  2232         }
       
  2233 
       
  2234     for (TInt ii=0; ii<count; ii++)
       
  2235         {
       
  2236         LoadAndQueueNoteL(file);
       
  2237         }
       
  2238 
       
  2239     iNotificationsSaved = EFalse;
       
  2240 
       
  2241     if ( iSoftNotificationAmounts[EMissedCallsNotification] )
       
  2242         {
       
  2243         SetNcnFlag(ETrue);
       
  2244         }
       
  2245 
       
  2246     CleanupStack::PopAndDestroy();  // close file
       
  2247     }
       
  2248 
       
  2249 void CAknSoftNotificationSubject::LoadAndQueueNoteL(RReadStream& aStream)
       
  2250     {
       
  2251     TAknSoftNotificationType type = STATIC_CAST(TAknSoftNotificationType, aStream.ReadUint8L());
       
  2252     TInt count = 1;
       
  2253     TBuf<200> text;
       
  2254     switch (type)
       
  2255         {
       
  2256         case ENetworkInformationNotification:
       
  2257         case EUnstructuredSSDataNotification:
       
  2258             aStream >> text;
       
  2259             break;
       
  2260         case ESeparateVoiceMailOnLine1Notification:
       
  2261         case ESeparateVoiceMailOnLine2Notification:
       
  2262         case ECellBroadcastNotification:
       
  2263         case EVoiceMailNotification:
       
  2264         case EMissedCallsNotification:
       
  2265         case ENewMessagesNotification:
       
  2266         case ENewMailNotification:
       
  2267         case EChatMessageNotification:
       
  2268             count = aStream.ReadInt32L();
       
  2269             break;
       
  2270         case EShowGroupedNotification:
       
  2271             iSoftNotificationAmounts[EMissedCallsNotification] = aStream.ReadInt32L();
       
  2272             iSoftNotificationAmounts[ENewMessagesNotification] = aStream.ReadInt32L();
       
  2273             iSoftNotificationAmounts[EChatMessageNotification] = aStream.ReadInt32L();
       
  2274             iSoftNotificationAmounts[ENewMailNotification]     = aStream.ReadInt32L();
       
  2275             break;
       
  2276         case ECustomSoftNotification:
       
  2277             {
       
  2278             count = aStream.ReadInt16L();
       
  2279             AddNewCustomNoteL(aStream, count);
       
  2280             if( iCustomNoteParamsStack )
       
  2281                 {
       
  2282                 TPtrC customTxt( iCustomNoteParamsStack->CustomText( count, EFalse ) );
       
  2283                 if( customTxt.Length() > 0 )
       
  2284                     {
       
  2285                     text.Copy( customTxt.Left( text.MaxLength() ) );
       
  2286                     }
       
  2287                 }            
       
  2288             }
       
  2289         default:
       
  2290             break;
       
  2291         }
       
  2292 
       
  2293 #ifdef _DEBUG
       
  2294     _LIT(KDmsg, "AknSoftNotificationPlugin,LoadNoteL:type %d, count %d ");
       
  2295     RDebug::Print(KDmsg,type, count);
       
  2296 #endif
       
  2297 
       
  2298     if (type != EShowGroupedNotification)
       
  2299         {
       
  2300         TBool countChanged = ( iSoftNotificationAmounts[type] != count );
       
  2301         iSoftNotificationAmounts[type] = count;
       
  2302         UpdateNoteL(type, text, count, countChanged);
       
  2303         }
       
  2304     else
       
  2305         {
       
  2306         ScheduleGroupedNotifierL();
       
  2307         }
       
  2308     }
       
  2309 
       
  2310 
       
  2311 TBool CAknSoftNotificationSubject::CheckIfAlreadyExists(TAknSoftNotificationType aType)
       
  2312     {
       
  2313     TInt count = iSoftNoteEntryList->Count();
       
  2314     for (TInt ii=count-1; ii>=0; ii--)
       
  2315         {
       
  2316         TSoftNoteEntry& entry = (*iSoftNoteEntryList)[ii];
       
  2317         if (entry.iType == aType)
       
  2318             {
       
  2319             return ETrue;
       
  2320             }
       
  2321         }
       
  2322     return EFalse;
       
  2323     }
       
  2324 
       
  2325 
       
  2326 TBool CAknSoftNotificationSubject::AutoLockEnabled()
       
  2327     {
       
  2328     return EFalse;
       
  2329     }
       
  2330 
       
  2331 void CAknSoftNotificationSubject::AddNewCustomNoteL(
       
  2332     RReadStream& readStream, TInt aCount, TBool aNewNote )
       
  2333     {
       
  2334     AddNewCustomNoteL((RDesReadStream&)readStream, aCount, aNewNote );
       
  2335     }
       
  2336 
       
  2337 
       
  2338 void CAknSoftNotificationSubject::AddNewCustomNoteL(
       
  2339     RDesReadStream& readStream, TInt aCount, TBool aNewNote )
       
  2340     {
       
  2341     // Before adding, check if there is a note of this type
       
  2342     CCustomNotifParams* next = new (ELeave) CCustomNotifParams;
       
  2343     CleanupStack::PushL( next );
       
  2344     readStream >> *next;
       
  2345     CCustomNotifParams* existing = SeekCustomNoteForId(next->iParamData->iNoteResourceId,EFalse);
       
  2346     if ( existing )
       
  2347         {
       
  2348         existing->iCount = aCount;
       
  2349         CleanupStack::PopAndDestroy( next );
       
  2350         return;
       
  2351         }
       
  2352 
       
  2353     // do the switch (append new entry to stack)    
       
  2354     next->iNext = iCustomNoteParamsStack;
       
  2355     iCustomNoteParamsStack = next;
       
  2356     CleanupStack::Pop();
       
  2357 
       
  2358     if( next->iParamType == KAknSoftNotificationDynamic )
       
  2359         {
       
  2360         if( aNewNote )
       
  2361             {
       
  2362             // if new note, then generate new id
       
  2363             next->iDynamicData->SetId( GenerateUniqueId() );
       
  2364             }
       
  2365         next->iId = next->iDynamicData->Id();
       
  2366         next->iHasViewInfo = ( KNullViewId != next->iDynamicData->ViewId() );
       
  2367         next->iCount = aCount;
       
  2368         next->iNoteId = KErrNotFound;
       
  2369         next->iSupportsGroupedform = ( 
       
  2370             next->iDynamicData->SingularLabelGroup().Length() > 0 ||
       
  2371             next->iDynamicData->PluralLabelGroup().Length() > 0 );
       
  2372         }
       
  2373     else // default
       
  2374         {
       
  2375         iCustomNoteParamsStack->iId = iCustomNoteParamsStack->iParamData->iNoteResourceId;
       
  2376         
       
  2377         iCustomNoteParamsStack->iHasViewInfo = ( 
       
  2378             KNullViewId != iCustomNoteParamsStack->iParamData->iViewId);
       
  2379             
       
  2380         iCustomNoteParamsStack->iCount = aCount;
       
  2381         iCustomNoteParamsStack->iNoteId = KErrNotFound;
       
  2382         
       
  2383         iCustomNoteParamsStack->iSupportsGroupedform = 
       
  2384             (iCustomNoteParamsStack->iParamData->iGroupedTextResourceId != 0);
       
  2385         }
       
  2386     }
       
  2387 
       
  2388 CCustomNotifParams* CAknSoftNotificationSubject::SeekCustomNoteForId(TInt aID, TBool aSeekByGNoteId)
       
  2389     {
       
  2390     CCustomNotifParams* params = iCustomNoteParamsStack;
       
  2391 
       
  2392     for (;params && (aID != (aSeekByGNoteId?params->iNoteId:params->iId));)
       
  2393         {
       
  2394         params = params->iNext;
       
  2395         }
       
  2396 
       
  2397     return params;
       
  2398     }
       
  2399 
       
  2400 
       
  2401 void CAknSoftNotificationSubject::RemoveCustomNoteForId(TInt aID, TBool aSeekByGNoteId)
       
  2402     {
       
  2403     CCustomNotifParams* params = iCustomNoteParamsStack;
       
  2404 
       
  2405     if ( !params )
       
  2406         {
       
  2407         return;
       
  2408         }
       
  2409 
       
  2410     if ( aSeekByGNoteId )
       
  2411         {
       
  2412         RemoveByType(ECustomSoftNotification, aID);
       
  2413         }
       
  2414     else
       
  2415         { // just remove entry from list
       
  2416         TInt count = iSoftNoteEntryList->Count();
       
  2417         for (TInt ii=0; ii<count; ii++)
       
  2418             {
       
  2419             if ( iSoftNoteEntryList->At(ii).iCustomId == aID )
       
  2420                 {
       
  2421                 iSoftNoteEntryList->Delete(ii);
       
  2422                 break;
       
  2423                 }
       
  2424             }
       
  2425         }
       
  2426 
       
  2427     if ( aID == (aSeekByGNoteId?params->iNoteId:params->iId)) // Remove first note on stack
       
  2428         {
       
  2429         iCustomNoteParamsStack = params->iNext;
       
  2430         delete params;
       
  2431 
       
  2432         if (!iCustomNoteParamsStack)
       
  2433             {
       
  2434             iSoftNotificationAmounts[ECustomSoftNotification] = 0;
       
  2435             }
       
  2436 
       
  2437         return;
       
  2438         }
       
  2439 
       
  2440 
       
  2441     for (;params->iNext && (aID != (aSeekByGNoteId?params->iNext->iNoteId:params->iNext->iId));)
       
  2442         {
       
  2443         params = params->iNext;
       
  2444         }
       
  2445 
       
  2446     if ( params->iNext ) // Found previous item
       
  2447         {
       
  2448         CCustomNotifParams* tmp = params->iNext;
       
  2449         params->iNext = tmp->iNext;
       
  2450         delete tmp;
       
  2451         }
       
  2452 
       
  2453     if (!iCustomNoteParamsStack)
       
  2454         {
       
  2455         iSoftNotificationAmounts[ECustomSoftNotification] = 0;
       
  2456         }
       
  2457     }
       
  2458 
       
  2459 void CAknPrivateSoftNoteParameters::InternalizeL( RReadStream& aStream )
       
  2460     {
       
  2461     delete iResourceFile;
       
  2462     iResourceFile = 0;
       
  2463     TInt length = aStream.ReadInt32L();
       
  2464     if ( length )
       
  2465         {
       
  2466         iResourceFile = HBufC::NewL(length);
       
  2467         TPtr resptr( iResourceFile->Des() );
       
  2468         aStream >> resptr;
       
  2469         }
       
  2470 
       
  2471     iNoteResourceId = aStream.ReadInt32L();
       
  2472     iPriority = aStream.ReadInt32L();
       
  2473     iSoftkeys = aStream.ReadInt32L();
       
  2474     iTone = (CAknNoteDialog::TTone)aStream.ReadInt32L();
       
  2475 
       
  2476     iViewId.iAppUid = TUid::Uid(aStream.ReadUint32L());
       
  2477     iViewId.iViewUid = TUid::Uid(aStream.ReadUint32L());
       
  2478     iCustomMessageId = TUid::Uid(aStream.ReadUint32L());
       
  2479     iAcceptSoftKey = aStream.ReadInt32L();
       
  2480 
       
  2481     iPluralViewId.iAppUid = TUid::Uid(aStream.ReadUint32L());
       
  2482     iPluralViewId.iViewUid = TUid::Uid(aStream.ReadUint32L());
       
  2483     iGroupedTextResourceId = aStream.ReadInt32L();
       
  2484 
       
  2485     delete iViewActivationMsg;
       
  2486     iViewActivationMsg = 0;
       
  2487     length = aStream.ReadInt32L();
       
  2488     if ( length != KErrNotFound )
       
  2489         {
       
  2490         iViewActivationMsg = HBufC8::NewL(length);
       
  2491         TPtr8 ptr( iViewActivationMsg->Des() );
       
  2492         aStream >> ptr;
       
  2493         }
       
  2494     
       
  2495     delete iSecondaryDisplayData;
       
  2496     iSecondaryDisplayData = 0;
       
  2497         
       
  2498     if (aStream.ReadInt8L()) // item has secondary display data
       
  2499         {
       
  2500         iSecondaryDisplayData = new (ELeave) CAknSDData();
       
  2501         aStream >> *iSecondaryDisplayData;
       
  2502         }
       
  2503     }
       
  2504 
       
  2505 void CAknPrivateSoftNoteParameters::ExternalizeL( RWriteStream& aStream ) const
       
  2506     {
       
  2507     aStream.WriteInt32L(iResourceFile->Length());
       
  2508     aStream << (*iResourceFile);
       
  2509     aStream.WriteInt32L(iNoteResourceId);
       
  2510     aStream.WriteInt32L(iPriority);
       
  2511     aStream.WriteInt32L(iSoftkeys);
       
  2512     aStream.WriteInt32L(iTone);
       
  2513     aStream.WriteUint32L(iViewId.iAppUid.iUid);
       
  2514     aStream.WriteUint32L(iViewId.iViewUid.iUid);
       
  2515     aStream.WriteUint32L(iCustomMessageId.iUid);
       
  2516     aStream.WriteInt32L(iAcceptSoftKey);
       
  2517 
       
  2518     aStream.WriteUint32L(iPluralViewId.iAppUid.iUid);
       
  2519     aStream.WriteUint32L(iPluralViewId.iViewUid.iUid);
       
  2520     aStream.WriteUint32L(iGroupedTextResourceId);
       
  2521 
       
  2522     if ( iViewActivationMsg ) // optional
       
  2523         {
       
  2524         aStream.WriteInt32L(iViewActivationMsg->Length());
       
  2525         aStream << (*iViewActivationMsg);
       
  2526         }
       
  2527     else
       
  2528         {
       
  2529         aStream.WriteInt32L(KErrNotFound);
       
  2530         }
       
  2531     
       
  2532     if (iSecondaryDisplayData)
       
  2533         {
       
  2534         aStream.WriteInt8L(ETrue);
       
  2535         aStream << *iSecondaryDisplayData;
       
  2536         }
       
  2537     else
       
  2538         {
       
  2539         aStream.WriteInt8L(EFalse);            
       
  2540         }
       
  2541     }
       
  2542 
       
  2543 void CAknSoftNotificationSubject::LaunchNewIMAppL()
       
  2544     {
       
  2545     LaunchViewL( KChatSpecificView, TUid::Uid(42), KNullDesC8() );
       
  2546     }
       
  2547 
       
  2548 // ---------------------------------------------------------
       
  2549 // CAknSoftNotificationSubject::LoadUniqueIdL
       
  2550 // ---------------------------------------------------------
       
  2551 //
       
  2552 void CAknSoftNotificationSubject::LoadUniqueIdL()
       
  2553     {
       
  2554     RFs& fs( CEikonEnv::Static()->FsSession() );
       
  2555 
       
  2556     RFileReadStream file;
       
  2557     User::LeaveIfError( file.Open( fs, KAknDynamicIdFilename, EFileRead ) );
       
  2558 
       
  2559     file.PushL();
       
  2560     iUniqueIdCounter = file.ReadInt32L();
       
  2561     CleanupStack::PopAndDestroy( &file );
       
  2562     }
       
  2563 
       
  2564 // ---------------------------------------------------------
       
  2565 // CAknSoftNotificationSubject::StoreUniqueIdL
       
  2566 // ---------------------------------------------------------
       
  2567 //
       
  2568 void CAknSoftNotificationSubject::StoreUniqueIdL()
       
  2569     {
       
  2570     RFs& fs( CEikonEnv::Static()->FsSession() );
       
  2571 
       
  2572     RFileWriteStream file;
       
  2573     TInt err = file.Replace( fs, KAknDynamicIdFilename, EFileWrite );
       
  2574 
       
  2575     if( err == KErrPathNotFound )
       
  2576         {
       
  2577         // folder not found -> create it
       
  2578         User::LeaveIfError( fs.MkDirAll( KAknDynamicIdFilename ) );
       
  2579         User::LeaveIfError( file.Create( fs, KAknDynamicIdFilename, EFileWrite ) );
       
  2580         }
       
  2581     else
       
  2582         {
       
  2583 #ifdef _DEBUG
       
  2584         if( err )
       
  2585             {
       
  2586             _LIT(KDmsg, "AknSoftNotificationPlugin,StoreUniqueIdL: error %d");
       
  2587             RDebug::Print( KDmsg, err);
       
  2588             }
       
  2589 #endif        
       
  2590         User::LeaveIfError( err );
       
  2591         }
       
  2592 
       
  2593     file.PushL();
       
  2594     file.WriteInt32L( iUniqueIdCounter );
       
  2595     file.CommitL();
       
  2596     CleanupStack::PopAndDestroy( &file );
       
  2597     }
       
  2598 
       
  2599 
       
  2600 // ---------------------------------------------------------
       
  2601 // CAknSoftNotificationSubject::GenerateUniqueId
       
  2602 // ---------------------------------------------------------
       
  2603 //
       
  2604 TInt CAknSoftNotificationSubject::GenerateUniqueId()
       
  2605     {
       
  2606     TInt failsafe = KMaxTInt; // prevent infinite loop
       
  2607     while( failsafe ) // loop until found or failsafe expires
       
  2608         {
       
  2609         // try next id. Disallow values below KMinimumUniqueId.
       
  2610         iUniqueIdCounter = Max( KMinimumUniqueId, iUniqueIdCounter + 1 );
       
  2611         
       
  2612         // go through existing notes and verify that the id is not used
       
  2613         CCustomNotifParams* params = iCustomNoteParamsStack;
       
  2614         while( params && params->iId != iUniqueIdCounter )
       
  2615             {
       
  2616             params = params->iNext;
       
  2617             }
       
  2618         
       
  2619         if( !params )
       
  2620             {
       
  2621             // Unique id found
       
  2622             break;
       
  2623             }
       
  2624         
       
  2625         --failsafe;
       
  2626         }
       
  2627     
       
  2628     // Store new id always when it has changed. We can't do anything if the
       
  2629     // saving fails, so we just ignore the error. 
       
  2630     TRAPD( err, StoreUniqueIdL() );
       
  2631     if( err )
       
  2632         {
       
  2633 #ifdef _DEBUG
       
  2634         _LIT(KDmsg, "AknSoftNotificationPlugin,GenerateUniqueId: save error %d");
       
  2635         RDebug::Print( KDmsg, err );
       
  2636 #endif //_DEBUG    
       
  2637         }
       
  2638     
       
  2639     return iUniqueIdCounter;
       
  2640     }
       
  2641 
       
  2642 // ---------------------------------------------------------
       
  2643 // CAknSoftNotificationSubject::WriteResponse
       
  2644 // ---------------------------------------------------------
       
  2645 //
       
  2646 void CAknSoftNotificationSubject::WriteResponse( 
       
  2647     TDes8& aResponse, TInt aNoteId ) const
       
  2648     {
       
  2649     TPckg<TInt> response( aNoteId );
       
  2650     aResponse.Copy( response.Left( aResponse.MaxLength() ) );
       
  2651     }
       
  2652 
       
  2653 //  End of File