uifw/AvKon/notifsrc/AknGlobalNote.cpp
changeset 0 2f259fa3e83a
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:  Implementation for the client used to show global notes.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "AknGlobalNote.h"
       
    20 
       
    21 #include <s32mem.h>
       
    22 #include <AknNotifySignature.h>
       
    23 #include <aknSDData.h>
       
    24 
       
    25 #include <gfxtranseffect/gfxtranseffect.h>
       
    26 #include <akntransitionutils.h>
       
    27 
       
    28 const TInt KBufferGranularity    = 128;
       
    29 const TInt KGlobalNoteTextLength = 256;
       
    30 
       
    31 void CheckOpcodeForDisplayingGlobalNoteL( TInt aType )
       
    32     {
       
    33     if ( ( aType < EAknGlobalInformationNote ||
       
    34            aType > EAknGlobalTextNote ||
       
    35            aType == EAknCancelGlobalNote ) &&
       
    36          aType != EAknGlobalBatteryFullUnplugNote &&
       
    37          aType != EAknGlobalUnplugChargerNote )
       
    38         {
       
    39         User::Leave( KErrNotSupported );
       
    40         }
       
    41     }
       
    42 
       
    43 EXPORT_C CAknGlobalNote* CAknGlobalNote::NewL()
       
    44     {
       
    45     CAknGlobalNote* self = NewLC();
       
    46     CleanupStack::Pop( self );
       
    47     return self;
       
    48     }
       
    49 
       
    50 EXPORT_C CAknGlobalNote* CAknGlobalNote::NewLC()
       
    51     {
       
    52     CAknGlobalNote* self = new (ELeave) CAknGlobalNote;
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     return self;
       
    56     }
       
    57 
       
    58 EXPORT_C CAknGlobalNote::~CAknGlobalNote()
       
    59     {
       
    60     delete iBuffer;
       
    61     delete iCancelBuffer;
       
    62     }
       
    63 
       
    64 EXPORT_C void CAknGlobalNote::SetTextProcessing( TBool aEnabled )
       
    65     {
       
    66     iTextProcessing = aEnabled;
       
    67     }
       
    68 
       
    69 EXPORT_C TInt CAknGlobalNote::ShowNoteL( TRequestStatus& aStatus, 
       
    70                                          TAknGlobalNoteType aType,
       
    71                                          const TDesC& aNoteText )
       
    72     {
       
    73     CheckOpcodeForDisplayingGlobalNoteL( aType );
       
    74     
       
    75     // We need to pre-allocate a note id for the global note first. It is fetched synchronously.
       
    76     TPckgBuf<TInt32> msg( KAKNNOTIFIERSIGNATURE_GETNOTEID );
       
    77     TPckgBuf<SAknGlobalNoteReturnParams> noteIdRetPckg;
       
    78     StartOrUpdateL( msg, noteIdRetPckg );
       
    79 
       
    80     // Then the global note is shown asynchronously with pre-allocated note id as a parameter. 
       
    81     PrepareBufferL( aType, aNoteText, noteIdRetPckg().iNoteId );
       
    82     StartOrUpdateAndGetResponseL( aStatus, iBufferPtr, iRetPckg );
       
    83 
       
    84     return noteIdRetPckg().iNoteId;
       
    85     }
       
    86 
       
    87 EXPORT_C TInt CAknGlobalNote::ShowNoteL( TAknGlobalNoteType aType,
       
    88                                          const TDesC& aNoteText )
       
    89     {
       
    90     CheckOpcodeForDisplayingGlobalNoteL( aType );
       
    91     PrepareBufferL( aType, aNoteText );
       
    92     TPckgBuf<SAknGlobalNoteReturnParams> retPckg;
       
    93     StartOrUpdateL( iBufferPtr, retPckg );
       
    94 
       
    95     return retPckg().iNoteId;
       
    96     }
       
    97 
       
    98 void CAknGlobalNote::PrepareBufferL( 
       
    99     TAknGlobalNoteType aType,
       
   100     const TDesC& aNoteText,
       
   101     TInt aPreallocatedGlobalNoteId)
       
   102     {
       
   103     CBufFlat* buffer = CBufFlat::NewL( KBufferGranularity );
       
   104     CleanupStack::PushL( buffer );
       
   105     
       
   106     TBool isAdapterEnabled( EFalse );
       
   107 
       
   108     if ( iPriority > 0xFFFF ) // It would overflow, we use this as an
       
   109                               // indication that global note has been
       
   110         {                     // activated from adapter.  
       
   111         isAdapterEnabled = ETrue;
       
   112         iPriority = 0;        // Restore default priority
       
   113         }
       
   114 
       
   115     DoGlobalNoteBufferL(
       
   116         aType,
       
   117         iPriority,
       
   118         iSoftkeys,
       
   119         iGraphic,
       
   120         iGraphicMask,
       
   121         iAnimation,
       
   122         iTone,
       
   123         isAdapterEnabled,
       
   124         iTextProcessing,
       
   125         aNoteText,
       
   126         buffer,
       
   127         aPreallocatedGlobalNoteId
       
   128         );
       
   129     
       
   130     if ( SecondaryDisplayData() )
       
   131         {
       
   132         RBufWriteStream bufStream;
       
   133         // To overwrite sd info previously set
       
   134         bufStream.Open( *buffer, buffer->Size() - 1 );
       
   135 
       
   136         CleanupClosePushL( bufStream );
       
   137 
       
   138         bufStream.WriteInt8L( ETrue );
       
   139         bufStream << *( SecondaryDisplayData() );        
       
   140         
       
   141         CleanupStack::PopAndDestroy( &bufStream );
       
   142         }
       
   143         
       
   144     if (aType == EAknCancelGlobalNote)
       
   145         {
       
   146         delete iCancelBuffer;
       
   147         iCancelBuffer = buffer;
       
   148         iCancelBufferPtr.Set( buffer->Ptr( 0 ) );
       
   149         }
       
   150     else
       
   151         {
       
   152         delete iBuffer;
       
   153         iBuffer = buffer;
       
   154         iBufferPtr.Set( buffer->Ptr( 0 ) );
       
   155         }        
       
   156         
       
   157     CleanupStack::Pop( buffer );
       
   158     }
       
   159 
       
   160 EXPORT_C void CAknGlobalNote::CancelNoteL( TInt aNoteId )
       
   161     {
       
   162     TInt oldPriority = iPriority;
       
   163     iPriority        = aNoteId;
       
   164     
       
   165     PrepareBufferL( EAknCancelGlobalNote, KNullDesC );
       
   166     TPckgBuf<SAknGlobalNoteReturnParams> retPckg;
       
   167     StartOrUpdateL( iCancelBufferPtr, retPckg );
       
   168     iPriority = oldPriority;
       
   169     }
       
   170 
       
   171 EXPORT_C void CAknGlobalNote::SetPriority( TInt aPriority )
       
   172     {
       
   173     iPriority = aPriority;
       
   174     }
       
   175 
       
   176 EXPORT_C void CAknGlobalNote::SetSoftkeys( TInt aId )
       
   177     {
       
   178     iSoftkeys = aId;
       
   179     }
       
   180 
       
   181 EXPORT_C void CAknGlobalNote::SetGraphic( TInt aId, TInt aMaskId )
       
   182     {
       
   183     iGraphic     = aId;
       
   184     iGraphicMask = aMaskId;
       
   185     }
       
   186 
       
   187 EXPORT_C void CAknGlobalNote::SetAnimation( TInt aResourceId )
       
   188     {
       
   189     iAnimation = aResourceId;
       
   190     }
       
   191 
       
   192 EXPORT_C void CAknGlobalNote::SetTone( TInt aTone )
       
   193     {
       
   194     iTone = aTone;
       
   195     }
       
   196 
       
   197 CAknGlobalNote::CAknGlobalNote() : CAknNotifyBase( KAknGlobalNoteUid )
       
   198     {
       
   199     iGraphic        = -1;
       
   200     iGraphicMask    = -1;
       
   201     iTone           = -1;
       
   202     iTextProcessing = ETrue;
       
   203     }
       
   204 
       
   205 void CAknGlobalNote::ConstructL()
       
   206     {
       
   207     CAknNotifyBase::ConstructL();
       
   208     }
       
   209 
       
   210 EXPORT_C void CAknGlobalNote::CAknNotifyBase_Reserved()
       
   211     {
       
   212     }
       
   213 
       
   214 EXPORT_C void CAknGlobalNote::DoGlobaNoteBufferL(
       
   215     TInt16 aType,
       
   216     TInt16 aPriority,
       
   217     TInt aSoftkeys,
       
   218     TInt16 aGraphic,
       
   219     TInt16 aGraphicMask,
       
   220     TInt aAnimation,
       
   221     TInt16 aTone,
       
   222     TBool aAdapterUsed,
       
   223     TBool aTextProcessingEnabled,
       
   224     const TDesC& aNoteText,
       
   225     CBufFlat* aBuffer )
       
   226     {
       
   227     DoGlobalNoteBufferL(
       
   228         aType,
       
   229         aPriority,
       
   230         aSoftkeys,
       
   231         aGraphic,
       
   232         aGraphicMask,
       
   233         aAnimation,
       
   234         aTone,
       
   235         aAdapterUsed,
       
   236         aTextProcessingEnabled,
       
   237         aNoteText,
       
   238         aBuffer,
       
   239         0);
       
   240     }
       
   241     
       
   242 void CAknGlobalNote::DoGlobalNoteBufferL(
       
   243     TInt16 aType,
       
   244     TInt16 aPriority,
       
   245     TInt aSoftkeys,
       
   246     TInt16 aGraphic,
       
   247     TInt16 aGraphicMask,
       
   248     TInt aAnimation,
       
   249     TInt16 aTone,
       
   250     TBool aAdapterUsed,
       
   251     TBool aTextProcessingEnabled,
       
   252     const TDesC& aNoteText,
       
   253     CBufFlat* aBuffer,
       
   254     TInt32 aPreallocatedGlobalNoteId)
       
   255     {
       
   256     if ( aNoteText.Length() > KGlobalNoteTextLength )
       
   257         {
       
   258         User::Leave( KErrTooBig );
       
   259         }
       
   260 
       
   261     RBufWriteStream bufStream;
       
   262     bufStream.Open( *aBuffer );
       
   263 
       
   264     CleanupClosePushL( bufStream );
       
   265 
       
   266     bufStream.WriteInt32L( KAKNNOTIFIERSIGNATURE );
       
   267 
       
   268     bufStream.WriteInt16L( aType );
       
   269     bufStream << aNoteText;
       
   270     bufStream.WriteInt16L( aPriority );
       
   271     bufStream.WriteInt32L( aSoftkeys );
       
   272     bufStream.WriteInt16L( aGraphic );
       
   273     bufStream.WriteInt16L( aGraphicMask );
       
   274     bufStream.WriteInt32L( aAnimation );
       
   275     bufStream.WriteInt16L( aTone );
       
   276     bufStream.WriteInt8L( aAdapterUsed );
       
   277     bufStream.WriteInt8L( aTextProcessingEnabled );
       
   278     bufStream.WriteInt32L( aPreallocatedGlobalNoteId );
       
   279     bufStream.WriteInt8L( EFalse ); // suppress sd data by default
       
   280 
       
   281     CleanupStack::PopAndDestroy( &bufStream );
       
   282     }
       
   283 
       
   284 // End of File