uifw/AvKon/notifsrc/AknSoftNotifier.cpp
changeset 0 2f259fa3e83a
child 4 8ca85d2f0db7
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    19 #include <vwsdefpartner.h>
       
    20 #endif
       
    21 #include "AknSoftNotifier.h"
       
    22 #include <s32mem.h>
       
    23 #include <AknSoftNotificationParameters.h>
       
    24 #include <AknNotifySignature.h>
       
    25 #include <aknSDData.h>
       
    26 #include "AknSoftNoteConsts.h"
       
    27 
       
    28 const TInt KBufferGranularity = 128;
       
    29 const TInt KGlobalNoteTextLength = 256;
       
    30 
       
    31 
       
    32 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
    33 #include <akntranseffect.h>
       
    34 #include <akntransitionutils.h>
       
    35 #include <gfxtranseffect/gfxtranseffect.h>
       
    36 
       
    37 
       
    38 class CWait;
       
    39 const TInt KNoteDelayToIdleState = 450000; // 0,45s.
       
    40 
       
    41 /*
       
    42 * AknSoftNotifier's extension class
       
    43 */
       
    44 NONSHARABLE_CLASS(CAknSoftNotifierExt): public CBase
       
    45     {
       
    46     public:
       
    47         static CAknSoftNotifierExt* NewL();
       
    48         ~CAknSoftNotifierExt();
       
    49         void ShowNotifsDelayed( TBool aShow );
       
    50         void SetNotifier( CAknSoftNotifier* aNotifier );
       
    51         void CancelNotifDelay();
       
    52             
       
    53     private: // Methods
       
    54         CAknSoftNotifierExt();
       
    55         void ConstructL();
       
    56         TInt DoShowNotifs();
       
    57         
       
    58     private: // Data
       
    59         CAknSoftNotifier* iNotifier;
       
    60         CWait* iWait;
       
    61         TBool iNotifsShowState;
       
    62         
       
    63     public:
       
    64     friend class CWait;
       
    65     
       
    66     
       
    67     };
       
    68 
       
    69 /*
       
    70 * Class used from CAknSoftNotifierExt to create 
       
    71 * small delay when entering idle state
       
    72 * Delay is needed for soft notification transition to be shown
       
    73 */
       
    74 NONSHARABLE_CLASS(CWait) : public CTimer
       
    75 	{
       
    76 	public:
       
    77 	    static CWait* NewL();
       
    78 		void Wait( CAknSoftNotifierExt* aExt, TInt aTimeToWait );
       
    79 	private:
       
    80 		CWait();
       
    81 		void ConstructL();
       
    82 		void RunL();
       
    83 	private:
       
    84 		CAknSoftNotifierExt* iExt;
       
    85 	};	
       
    86 
       
    87 
       
    88 CWait* CWait::NewL()
       
    89     {
       
    90     CWait * self = new(ELeave) CWait;
       
    91     CleanupStack::PushL(self);
       
    92     self->ConstructL();
       
    93     CleanupStack::Pop();
       
    94     return self;
       
    95     }
       
    96     
       
    97 void CWait::Wait( CAknSoftNotifierExt* aExt, TInt aTimeToWait )
       
    98 	{
       
    99 	iExt = aExt;
       
   100 	After(aTimeToWait);
       
   101 	}
       
   102 
       
   103 CWait::CWait() : CTimer(CActive::EPriorityIdle) 
       
   104 	{
       
   105 	CActiveScheduler::Add(this);
       
   106 	}
       
   107 
       
   108 void CWait::ConstructL()
       
   109     {
       
   110     CTimer::ConstructL();
       
   111     }
       
   112     
       
   113 void CWait::RunL()
       
   114 	{
       
   115 	TInt error = iExt->DoShowNotifs();
       
   116 	User::LeaveIfError( error );
       
   117 	}
       
   118 
       
   119     
       
   120 CAknSoftNotifierExt* CAknSoftNotifierExt::NewL()
       
   121     {
       
   122     CAknSoftNotifierExt * self = new(ELeave) CAknSoftNotifierExt;
       
   123     CleanupStack::PushL(self);
       
   124     self->ConstructL();
       
   125     CleanupStack::Pop();
       
   126     return self;
       
   127     } 
       
   128     
       
   129 CAknSoftNotifierExt::~CAknSoftNotifierExt()
       
   130     {
       
   131     delete iWait;
       
   132     iWait = NULL;
       
   133     }
       
   134     
       
   135 void CAknSoftNotifierExt::ShowNotifsDelayed( TBool aShow )
       
   136     {
       
   137     iNotifsShowState = aShow;
       
   138     iWait->Cancel();
       
   139     
       
   140     if( aShow && iWait )
       
   141         {
       
   142         iWait->Wait( this, KNoteDelayToIdleState );
       
   143         }
       
   144     else
       
   145         {
       
   146         // no delay when exiting idle state
       
   147         iWait->Wait( this, 0 );
       
   148         }
       
   149     }
       
   150     
       
   151 void CAknSoftNotifierExt::SetNotifier( CAknSoftNotifier* aNotifier )
       
   152     {
       
   153     iNotifier = aNotifier;
       
   154     }
       
   155     
       
   156 void CAknSoftNotifierExt::CancelNotifDelay()
       
   157     {
       
   158     iWait->Cancel();
       
   159     }
       
   160     
       
   161 CAknSoftNotifierExt::CAknSoftNotifierExt()
       
   162     {
       
   163     }
       
   164 
       
   165 void CAknSoftNotifierExt::ConstructL()
       
   166     {
       
   167     iWait = CWait::NewL();
       
   168     }
       
   169     
       
   170     
       
   171 TInt CAknSoftNotifierExt::DoShowNotifs()
       
   172     {
       
   173     TRAPD( error,iNotifier->PrepareBufferL(ESetIdleState, iNotifsShowState, NULL, EFalse, ETrue));
       
   174     return error;
       
   175     }
       
   176          
       
   177     
       
   178 #endif // RD_UI_TRANSITION_EFFECTS_POPUPS
       
   179     
       
   180    
       
   181     
       
   182     
       
   183 
       
   184 EXPORT_C CAknSoftNotifier* CAknSoftNotifier::NewL()
       
   185     {
       
   186     CAknSoftNotifier* self = NewLC();
       
   187     CleanupStack::Pop();
       
   188     return self;
       
   189     }
       
   190 
       
   191 EXPORT_C CAknSoftNotifier* CAknSoftNotifier::NewLC()
       
   192     {
       
   193     CAknSoftNotifier * self = new(ELeave) CAknSoftNotifier;
       
   194     CleanupStack::PushL(self);
       
   195     self->ConstructL();
       
   196     return self;
       
   197     }
       
   198 
       
   199 EXPORT_C CAknSoftNotifier::~CAknSoftNotifier()
       
   200     {
       
   201     delete iBuffer;
       
   202     
       
   203 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
   204     delete iExt;
       
   205 #endif
       
   206     }
       
   207 
       
   208 void CAknSoftNotifier::ConstructL()
       
   209     {
       
   210     CAknNotifyBase::ConstructL();
       
   211 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
   212     iExt = CAknSoftNotifierExt::NewL();
       
   213     iExt->SetNotifier( this );
       
   214 #endif
       
   215     }
       
   216 
       
   217 EXPORT_C void CAknSoftNotifier::AddNotificationL(TAknSoftNotificationType aType, TPtrC* aText)
       
   218     {
       
   219     PrepareBufferL(aType, 1, aText, EFalse, ETrue);
       
   220     }
       
   221 
       
   222 EXPORT_C void CAknSoftNotifier::AddNotificationL(TAknSoftNotificationType aType,TInt aCount)
       
   223     {
       
   224     PrepareBufferL(aType, aCount, NULL, EFalse, ETrue);
       
   225     }
       
   226 
       
   227 EXPORT_C void CAknSoftNotifier::SetNotificationCountL(TAknSoftNotificationType aType, TInt aCount, 
       
   228     TPtrC* aText)
       
   229     {
       
   230     PrepareBufferL(aType, aCount, aText, EFalse, EFalse);
       
   231     }
       
   232 
       
   233 EXPORT_C void CAknSoftNotifier::CancelSoftNotificationL(TAknSoftNotificationType aType)
       
   234     {
       
   235     PrepareBufferL(aType, 0, NULL, ETrue, EFalse);
       
   236     }
       
   237 
       
   238 CAknSoftNotifier::CAknSoftNotifier() : CAknNotifyBase(KAknSoftNotificationUid)
       
   239     {
       
   240     }
       
   241 
       
   242 EXPORT_C void CAknSoftNotifier::SetIdleStateL(TBool aIdleState)
       
   243     {
       
   244 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
   245     iExt->CancelNotifDelay();
       
   246 
       
   247     if( CAknTransitionUtils::TransitionsEnabled( AknTransEffect::EComponentTransitionsOff ) &&
       
   248         aIdleState )
       
   249         {
       
   250         // Shows notes in idle with small delay when going to idle, if popup transitions
       
   251         // are enabled. This is to secure that note appear transition can be seen.
       
   252         iExt->ShowNotifsDelayed( aIdleState );    
       
   253         }
       
   254     else
       
   255         {
       
   256         PrepareBufferL(ESetIdleState, aIdleState, NULL, EFalse, ETrue);    
       
   257         }
       
   258 #else
       
   259     PrepareBufferL(ESetIdleState, aIdleState, NULL, EFalse, ETrue);
       
   260 #endif
       
   261     }
       
   262 
       
   263 void CAknSoftNotifier::PrepareBufferL(TAknSoftNotificationType aType, TInt aCount, TPtrC* aText, 
       
   264     TBool aCancel, TBool aAddCount, CAknSoftNotificationParameters* aParams)
       
   265     {
       
   266     delete iBuffer;
       
   267     iBuffer = NULL;
       
   268 
       
   269     if ( aText && aText->Length() > KGlobalNoteTextLength )
       
   270         {
       
   271         User::Leave( KErrTooBig );
       
   272         }
       
   273 
       
   274     iBuffer = CBufFlat::NewL(KBufferGranularity);
       
   275 
       
   276     RBufWriteStream bufStream;
       
   277     bufStream.Open(*iBuffer);
       
   278 
       
   279     CleanupClosePushL(bufStream);
       
   280 
       
   281     bufStream.WriteInt32L(KAKNNOTIFIERSIGNATURE);
       
   282 
       
   283     bufStream.WriteUint8L(aType);
       
   284     bufStream.WriteInt16L(aCount);  // count
       
   285     bufStream.WriteUint8L(aCancel); // iscancel
       
   286     bufStream.WriteUint8L(aAddCount);   // add
       
   287 
       
   288     if (aText)
       
   289         {
       
   290         bufStream << (*aText);
       
   291         }
       
   292     else
       
   293         {
       
   294         bufStream << KNullDesC();
       
   295         }
       
   296 
       
   297     if (aParams)
       
   298         {
       
   299         bufStream.WriteInt32L( aParams->iNoteResourceId); // Works as unique ID
       
   300         bufStream.WriteInt16L( KAknSoftNotificationCustom ); // parameter type
       
   301         
       
   302         // If this sequence is changed, remeber also change the reading in notify plugin's side  
       
   303         bufStream.WriteInt32L(aParams->iResourceFile->Length());
       
   304         bufStream << (*aParams->iResourceFile);
       
   305         bufStream.WriteInt32L(aParams->iNoteResourceId);
       
   306         bufStream.WriteInt32L(aParams->iPriority);
       
   307         bufStream.WriteInt32L(aParams->iSoftkeys);
       
   308         bufStream.WriteInt32L(aParams->iTone);
       
   309         bufStream.WriteUint32L(aParams->iViewId.iAppUid.iUid);
       
   310         bufStream.WriteUint32L(aParams->iViewId.iViewUid.iUid);
       
   311         bufStream.WriteUint32L(aParams->iCustomMessageId.iUid);
       
   312         bufStream.WriteInt32L(aParams->iAcceptSoftKey);
       
   313 
       
   314         bufStream.WriteUint32L(aParams->iPluralViewId.iAppUid.iUid);
       
   315         bufStream.WriteUint32L(aParams->iPluralViewId.iViewUid.iUid);
       
   316         bufStream.WriteUint32L(aParams->iGroupedTextResourceId);
       
   317 
       
   318         if ( aParams->iViewId != KNullViewId )
       
   319             {
       
   320             bufStream.WriteInt32L(aParams->iViewActivationMsg->Length());
       
   321             bufStream << (*aParams->iViewActivationMsg);
       
   322             }
       
   323         else
       
   324             {
       
   325             bufStream.WriteInt32L(KErrNotFound);
       
   326             }
       
   327 
       
   328         // only custrom notes may need to send data to cover ui
       
   329         if (SecondaryDisplayData())
       
   330             {
       
   331             bufStream.WriteInt8L(ETrue);
       
   332             bufStream << *(SecondaryDisplayData());
       
   333             }
       
   334         else
       
   335             {
       
   336             bufStream.WriteInt8L(EFalse);            
       
   337             }
       
   338         }
       
   339 
       
   340     CleanupStack::PopAndDestroy();  // bufStream
       
   341 
       
   342     iBufferPtr.Set(iBuffer->Ptr(0));
       
   343 
       
   344     TBuf8<1> resp;
       
   345     StartOrUpdateL(iBufferPtr,resp);
       
   346     }
       
   347 
       
   348 EXPORT_C void CAknSoftNotifier::CAknNotifyBase_Reserved()
       
   349     {
       
   350     }
       
   351 
       
   352 EXPORT_C void CAknSoftNotifier::AddCustomNotificationL( 
       
   353     CAknSoftNotificationParameters& aParams, 
       
   354     TInt aCount )
       
   355     {
       
   356     PrepareBufferL(ECustomSoftNotification, aCount, NULL, EFalse, ETrue, &aParams );
       
   357     }
       
   358 
       
   359 EXPORT_C void CAknSoftNotifier::SetCustomNotificationCountL( 
       
   360     CAknSoftNotificationParameters& aParams, 
       
   361     TInt aCount )
       
   362     {
       
   363     PrepareBufferL(ECustomSoftNotification, aCount, NULL, EFalse, EFalse, &aParams );
       
   364     }
       
   365 
       
   366 EXPORT_C void CAknSoftNotifier::CancelCustomSoftNotificationL( 
       
   367     CAknSoftNotificationParameters& aParams )
       
   368     {
       
   369     PrepareBufferL(ECustomSoftNotification, 0, NULL, ETrue, EFalse, &aParams );
       
   370     }
       
   371 
       
   372 // End of File