srsf/vcommandhandler/src/vcommandui.cpp
branchRCL_3
changeset 23 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
22:cad71a31b7fc 23:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2006 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 of the CVCommandUi class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <vcommandapi.h>
       
    20 #include <AknsSkinInstance.h>
       
    21 #include <AknsUtils.h>
       
    22 #include <gulicon.h>
       
    23 #include "rubydebug.h"
       
    24 
       
    25 /**
       
    26 * The version of the streamed data protocol
       
    27 * It is rather likely, that the format of the data streamed changes in the future.
       
    28 * Using the protocol version, the code can check if it knows how to parse the 
       
    29 * input stream
       
    30 */
       
    31 const TInt32 KVCCommandUiProtocolVersion = 5;
       
    32 
       
    33 
       
    34 /**
       
    35 * This object does not take an ownership of the passed descriptors, 
       
    36 * but makes own copies. 
       
    37 * 
       
    38 * @param aWrittenText Text to display
       
    39 * @param aTooltip Second line of the text if ant
       
    40 * @param aFolderInfo Folder-related details
       
    41 * @param aModifiable If user can modify the command
       
    42 * @leave KErrOverflow if descriptors are too big
       
    43 */
       
    44 EXPORT_C CVCCommandUi* CVCCommandUi::NewL( const TDesC& aWrittenText, 
       
    45                                   const CVCFolderInfo& aFolderInfo, 
       
    46                                   TBool aModifiable, const TDesC& aTooltip,
       
    47                                   const TUid& aIconUid, const TDesC& aUserText, 
       
    48                                   TBool aConfirmationNeeded ) 
       
    49     {
       
    50     RUBY_DEBUG_BLOCKL( "CVCCommandUi::NewL" );
       
    51     CVCCommandUi* self = new (ELeave) CVCCommandUi;
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL( aWrittenText, aFolderInfo, aModifiable, aTooltip, aIconUid, 
       
    54                       aUserText, aConfirmationNeeded );
       
    55     CleanupStack::Pop( self );
       
    56     return self;
       
    57     }
       
    58     
       
    59 /**
       
    60 * Copy the existing CVCCommandUi
       
    61 */
       
    62 EXPORT_C CVCCommandUi* CVCCommandUi::NewL( const CVCCommandUi& aOriginal )
       
    63     {
       
    64     CVCCommandUi* self = new (ELeave) CVCCommandUi;
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL( aOriginal.WrittenText(), aOriginal.FolderInfo(), 
       
    67                       aOriginal.Modifiable(), aOriginal.Tooltip(), 
       
    68                       aOriginal.IconUid(), aOriginal.UserText(),
       
    69                       aOriginal.ConfirmationNeeded() );
       
    70     CleanupStack::Pop( self );
       
    71     return self;
       
    72     }
       
    73     
       
    74 /** 
       
    75 * Internalizes the command from stream 
       
    76 * values are read in the same order as ExternalizeL wrote them
       
    77 */
       
    78 EXPORT_C CVCCommandUi* CVCCommandUi::NewL( RReadStream &aStream )
       
    79     {
       
    80     CVCCommandUi* self = new (ELeave) CVCCommandUi;
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL( aStream );
       
    83     CleanupStack::Pop( self );
       
    84     return self;
       
    85     }
       
    86     
       
    87     
       
    88 void CVCCommandUi::ConstructL( RReadStream &aStream )
       
    89 	{
       
    90 	/**
       
    91 	* @todo extract the repeated descriptor internalization code into
       
    92 	*       a separate method
       
    93 	*/
       
    94 	TInt32 ver;
       
    95     aStream >> ver;
       
    96     __ASSERT_ALWAYS( ver == KVCCommandUiProtocolVersion, User::Leave( KErrNotSupported  ) );
       
    97     iWrittenText = HBufC::NewL( aStream.ReadInt32L() );
       
    98     TPtr pWrittenText = iWrittenText->Des();
       
    99     aStream >> pWrittenText;
       
   100     iFolderInfo = CVCFolderInfo::NewL( aStream );
       
   101     TInt32 intModifiable;
       
   102     aStream >> intModifiable;
       
   103     iUserCanModify = static_cast<TBool>( intModifiable );
       
   104     iTooltip = HBufC::NewL( aStream.ReadInt32L() );
       
   105     TPtr pTooltip = iTooltip->Des();
       
   106     aStream >> pTooltip;
       
   107     iIconUid = TUid::Uid( aStream.ReadInt32L() );
       
   108     iUserText = HBufC::NewL( aStream.ReadInt32L() );
       
   109     TPtr pUserText = iUserText->Des();
       
   110     aStream >> pUserText;
       
   111     TInt32 intConfirmationNeeded;
       
   112     aStream >> intConfirmationNeeded;
       
   113     iConfirmationNeeded = static_cast<TBool>( intConfirmationNeeded );
       
   114 	}
       
   115     
       
   116     
       
   117 /** 
       
   118 * Second-phase constructor 
       
   119 * @see NewL for guarding conditions
       
   120 */    
       
   121 void CVCCommandUi::ConstructL( const TDesC& aWrittenText, const CVCFolderInfo& aFolderInfo,
       
   122                                TBool aModifiable, const TDesC& aTooltip, const TUid& aIconUid,
       
   123                                const TDesC& aUserText, TBool aConfirmationNeeded ) 
       
   124     {
       
   125     RUBY_DEBUG_BLOCKL( "CVCCommandUi::ConstructL" );
       
   126     iWrittenText = HBufC::NewL( aWrittenText.Length() );
       
   127     *iWrittenText = aWrittenText;
       
   128     iFolderInfo = CVCFolderInfo::NewL( aFolderInfo );
       
   129     iTooltip = HBufC::NewL( aTooltip.Length() );
       
   130     *iTooltip = aTooltip;
       
   131     iUserCanModify = aModifiable;
       
   132     iIconUid = TUid::Uid( aIconUid.iUid );
       
   133     iUserText = HBufC::NewL( aUserText.Length() );
       
   134     *iUserText = aUserText;
       
   135     iConfirmationNeeded = aConfirmationNeeded;
       
   136     }
       
   137     
       
   138 EXPORT_C CVCCommandUi::~CVCCommandUi() 
       
   139     {
       
   140     delete iUserText;
       
   141     delete iWrittenText;
       
   142     delete iFolderInfo;
       
   143     delete iTooltip;
       
   144     }
       
   145     
       
   146 /** 
       
   147  * Saves the command to stream.
       
   148  * Descriptor components are saved as <length><descriptor> pairs, where 
       
   149  * <length> is TInt32 and <descriptor> is the default descriptor represetation
       
   150  * TBools are saved as TInt32 either
       
   151  */
       
   152 EXPORT_C void CVCCommandUi::ExternalizeL( RWriteStream &aStream ) const
       
   153     {
       
   154     aStream << KVCCommandUiProtocolVersion;
       
   155     aStream << static_cast<TInt32>( iWrittenText->Length() );
       
   156     aStream << *iWrittenText;
       
   157     aStream << *iFolderInfo;
       
   158     aStream << static_cast<TInt32> ( iUserCanModify );
       
   159     aStream << static_cast<TInt32>( iTooltip->Length() );
       
   160     aStream << *iTooltip;
       
   161     aStream << iIconUid.iUid;
       
   162     aStream << static_cast<TInt32>( iUserText->Length() );
       
   163     aStream << *iUserText;
       
   164     aStream << static_cast<TInt32> ( iConfirmationNeeded );
       
   165     }
       
   166     
       
   167 
       
   168 EXPORT_C const TDesC& CVCCommandUi::WrittenText() const 
       
   169     {
       
   170     return *iWrittenText;
       
   171     }
       
   172 
       
   173 EXPORT_C const TDesC& CVCCommandUi::UserText() const 
       
   174     {
       
   175     return *iUserText;
       
   176     }
       
   177 
       
   178 EXPORT_C const CVCFolderInfo& CVCCommandUi::FolderInfo() const 
       
   179     {
       
   180     return *iFolderInfo;
       
   181     }
       
   182 
       
   183 EXPORT_C const TDesC& CVCCommandUi::Tooltip() const 
       
   184     {
       
   185     return *iTooltip;
       
   186     }
       
   187     
       
   188 EXPORT_C TBool CVCCommandUi::Modifiable() const
       
   189     {
       
   190     return iUserCanModify;
       
   191     }
       
   192 
       
   193 EXPORT_C TBool CVCCommandUi::ConfirmationNeeded() const
       
   194     {
       
   195     return iConfirmationNeeded;
       
   196     }
       
   197     
       
   198 EXPORT_C const TUid& CVCCommandUi::IconUid() const 
       
   199     {
       
   200     return iIconUid;
       
   201     }
       
   202     
       
   203 EXPORT_C TBool CVCCommandUi::operator==( const CVCCommandUi& aCommandUi ) const
       
   204     {
       
   205     return (
       
   206             ( *iWrittenText == aCommandUi.WrittenText() ) &&
       
   207             ( *iFolderInfo == aCommandUi.FolderInfo() ) &&
       
   208             ( *iTooltip == aCommandUi.Tooltip() ) &&
       
   209             ( iUserCanModify == aCommandUi.Modifiable() ) &&
       
   210             ( iIconUid == aCommandUi.IconUid() ) &&
       
   211             ( *iUserText == aCommandUi.UserText() ) &&
       
   212             ( iConfirmationNeeded == aCommandUi.ConfirmationNeeded() )
       
   213            );
       
   214     }
       
   215     
       
   216 EXPORT_C CGulIcon* CVCCommandUi::IconLC() const
       
   217 	{
       
   218 	MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   219 
       
   220     CFbsBitmap* bitmap = NULL;
       
   221     CFbsBitmap* mask = NULL;
       
   222 
       
   223 	AknsUtils::CreateAppIconLC( skin, IconUid(), EAknsAppIconTypeList, bitmap, mask );
       
   224 
       
   225     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   226     icon->SetBitmapsOwnedExternally( EFalse );
       
   227 
       
   228     // icon now owns the bitmaps, no need to keep on cleanup stack.
       
   229     CleanupStack::Pop( 2 ); // mask, bitmap
       
   230 
       
   231     CleanupStack::PushL( icon );
       
   232     return icon;
       
   233 	}
       
   234 
       
   235 /**
       
   236  * Tells if all non user-changeable parts of aCommandUi are equal to this object's
       
   237  * @return ETrue if equal, EFalse otherwise
       
   238  */
       
   239 EXPORT_C TBool CVCCommandUi::EqualNonUserChangeableData( const CVCCommandUi& aCommandUi ) const
       
   240     {
       
   241     if( WrittenText() != aCommandUi.WrittenText() ) return EFalse;
       
   242     if( !(FolderInfo() == aCommandUi.FolderInfo()) ) return EFalse;    
       
   243     if( Modifiable() != aCommandUi.Modifiable() ) return EFalse;    
       
   244     if( ConfirmationNeeded() != aCommandUi.ConfirmationNeeded() ) return EFalse;    
       
   245     if( Tooltip() != aCommandUi.Tooltip() ) return EFalse;    
       
   246     if( IconUid() != aCommandUi.IconUid() ) return EFalse;    
       
   247     return ETrue;    
       
   248     }
       
   249     
       
   250 //End of file