phonebookui/Phonebook2/xSPExtensionManager/src/CxSPViewData.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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 
       
    19 // INCLUDE FILES
       
    20 #include <CxSPViewData.h>
       
    21 
       
    22 // System includes
       
    23 #include <s32mem.h>
       
    24 
       
    25 
       
    26 /// Unnamed namespace for local definitions
       
    27 namespace {
       
    28 
       
    29 /**
       
    30  * Stream buffer which counts number of bytes written to it.
       
    31  */
       
    32 class TCalcLengthStreamBuf : public MStreamBuf
       
    33     {
       
    34     public: // Construction
       
    35 
       
    36         /**
       
    37          * Constructor.
       
    38          */
       
    39         inline TCalcLengthStreamBuf() :
       
    40                 iBytesWritten( 0 )
       
    41             {
       
    42             }
       
    43 
       
    44         /**
       
    45          * Returns the number of bytes written.
       
    46          *
       
    47          * @return  Number of bytes written.
       
    48          */
       
    49         inline TInt BytesWritten() const
       
    50             {
       
    51             return iBytesWritten;
       
    52             }
       
    53 
       
    54     private: // From MStreamBuf
       
    55 
       
    56         void DoWriteL( const TAny* /*aPtr*/, TInt aLength )
       
    57             {
       
    58             // Just count the bytes
       
    59             iBytesWritten += aLength;
       
    60             }
       
    61 
       
    62     private: // Data
       
    63         /// Ref: Count of bytes written to this streambuf
       
    64         TInt iBytesWritten;
       
    65     };
       
    66 
       
    67 
       
    68 } /// namespace
       
    69 
       
    70 
       
    71 
       
    72 
       
    73 CxSPViewData::CxSPViewData() :
       
    74         iEComId( 0 ),
       
    75         iOriginalViewId( KErrNotFound ),
       
    76         iIconId( KErrNotFound ),
       
    77         iMaskId( KErrNotFound )
       
    78     {
       
    79     }
       
    80 
       
    81 CxSPViewData::~CxSPViewData()
       
    82     {
       
    83     delete iIconFile;
       
    84     delete iViewName;
       
    85     }
       
    86 
       
    87 EXPORT_C CxSPViewData* CxSPViewData::NewL()
       
    88     {
       
    89     CxSPViewData* self = new ( ELeave ) CxSPViewData;
       
    90     return self;
       
    91     }
       
    92 
       
    93 EXPORT_C CxSPViewData* CxSPViewData::NewL( const TDesC8& aBuf )
       
    94     {
       
    95     CxSPViewData* self = new ( ELeave ) CxSPViewData;
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL( aBuf );
       
    98     CleanupStack::Pop( self );
       
    99     return self;    
       
   100     }
       
   101 
       
   102 void CxSPViewData::ConstructL( const TDesC8& aBuf )
       
   103     {
       
   104     UnpackL( aBuf );
       
   105     }
       
   106 
       
   107 
       
   108 EXPORT_C TUint32 CxSPViewData::EComId() const
       
   109 	{
       
   110 	return iEComId;
       
   111 	}
       
   112 
       
   113 EXPORT_C TInt32 CxSPViewData::OriginalViewId() const
       
   114 	{
       
   115 	return iOriginalViewId;
       
   116 	}
       
   117 
       
   118 EXPORT_C TInt32 CxSPViewData::IconId() const
       
   119 	{
       
   120 	return iIconId;
       
   121 	}
       
   122 
       
   123 EXPORT_C TInt32 CxSPViewData::MaskId() const
       
   124 	{
       
   125 	return iMaskId;
       
   126 	}
       
   127 
       
   128 EXPORT_C const TDesC& CxSPViewData::IconFile() const
       
   129 	{
       
   130 	if( iIconFile )
       
   131 		{
       
   132 		return *iIconFile;
       
   133 		}
       
   134 	else
       
   135 		{
       
   136 		return KNullDesC();
       
   137 		}
       
   138 	}
       
   139 
       
   140 EXPORT_C const TDesC& CxSPViewData::ViewName() const
       
   141 	{
       
   142 	if( iViewName )
       
   143 		{
       
   144 		return *iViewName;
       
   145 		}
       
   146 	else
       
   147 		{
       
   148 		return KNullDesC();
       
   149 		}
       
   150 	}
       
   151 	
       
   152 EXPORT_C void CxSPViewData::SetEComId( TUint32 aEComId )
       
   153 	{
       
   154 	iEComId = aEComId;
       
   155 	}
       
   156 
       
   157 EXPORT_C void CxSPViewData::SetOriginalViewId( TInt32 aOriginalViewId )
       
   158 	{
       
   159 	iOriginalViewId = aOriginalViewId;
       
   160 	}
       
   161 
       
   162 EXPORT_C void CxSPViewData::SetIconId( TInt32 aIconId )
       
   163 	{
       
   164 	iIconId = aIconId;
       
   165 	}
       
   166 
       
   167 EXPORT_C void CxSPViewData::SetMaskId( TInt32 aMaskId )
       
   168 	{
       
   169 	iMaskId = aMaskId;
       
   170 	}
       
   171 
       
   172 EXPORT_C void CxSPViewData::SetIconFileL( const TDesC& aIconFile )
       
   173 	{
       
   174 	delete iIconFile;
       
   175 	iIconFile = NULL;
       
   176 	iIconFile = aIconFile.AllocL();
       
   177 	}
       
   178 
       
   179 EXPORT_C void CxSPViewData::SetViewNameL( const TDesC& aViewName )
       
   180 	{
       
   181 	{
       
   182 	delete iViewName;
       
   183 	iViewName = NULL;
       
   184 	iViewName = aViewName.AllocL();
       
   185 	}
       
   186 	}
       
   187 
       
   188 EXPORT_C void CxSPViewData::Reset()
       
   189     {
       
   190     iEComId = 0;
       
   191     iOriginalViewId = KErrNotFound;
       
   192     iIconId = KErrNotFound;
       
   193     iMaskId = KErrNotFound;
       
   194     delete iIconFile;
       
   195     iIconFile = NULL;
       
   196     delete iViewName;
       
   197     iViewName = NULL;
       
   198     }
       
   199 
       
   200 EXPORT_C HBufC8* CxSPViewData::PackL() const
       
   201     {
       
   202     // Calculate needed buffer size using TCalcLengthStreamBuf
       
   203     TCalcLengthStreamBuf countBuf;     
       
   204     RWriteStream countStream( &countBuf );
       
   205     // This can't leave because we are using TCalcLengthStreamBuf
       
   206     ExternalizeL( countStream );
       
   207 
       
   208     // Allocate a buffer and a stream
       
   209     HBufC8* buf = HBufC8::NewLC( countBuf.BytesWritten() );
       
   210     TPtr8 bufPtr = buf->Des();
       
   211     RDesWriteStream stream( bufPtr );
       
   212     stream.PushL();
       
   213 
       
   214     // Write this object to buf through stream
       
   215     ExternalizeL( stream );
       
   216 
       
   217     stream.CommitL();
       
   218     CleanupStack::PopAndDestroy(); // stream
       
   219     CleanupStack::Pop(); // buf
       
   220     return buf;
       
   221     }
       
   222 
       
   223 EXPORT_C void CxSPViewData::UnpackL( const TDesC8& aPack )
       
   224     {
       
   225     RDesReadStream stream( aPack );
       
   226     stream.PushL();
       
   227     InternalizeL( stream );
       
   228     CleanupStack::PopAndDestroy(); // stream
       
   229     }
       
   230 
       
   231 void CxSPViewData::ExternalizeL( RWriteStream& aStream ) const
       
   232     {
       
   233     aStream.WriteUint32L( iEComId );
       
   234     aStream.WriteInt32L( iOriginalViewId );
       
   235     aStream.WriteInt32L( iIconId );
       
   236     aStream.WriteInt32L( iMaskId );
       
   237     
       
   238     if( iIconFile )
       
   239     	{
       
   240     	aStream.WriteUint16L( iIconFile->Length() );
       
   241     	aStream.WriteL( *iIconFile );
       
   242     	}
       
   243    	else
       
   244    		{
       
   245    		aStream.WriteUint16L( KNullDesC().Length() );
       
   246    		aStream.WriteL( KNullDesC() );
       
   247    		}
       
   248 
       
   249 	if( iViewName )
       
   250     	{
       
   251     	aStream.WriteUint16L( iViewName->Length() );
       
   252     	aStream.WriteL( *iViewName );
       
   253     	}
       
   254    	else
       
   255    		{
       
   256    		aStream.WriteUint16L( KNullDesC().Length() );
       
   257    		aStream.WriteL( KNullDesC() );
       
   258    		}    
       
   259     }
       
   260 
       
   261 void CxSPViewData::InternalizeL( RReadStream& aStream )
       
   262     {
       
   263     Reset();
       
   264 
       
   265 	iEComId = aStream.ReadUint32L();
       
   266 	iOriginalViewId = aStream.ReadInt32L();
       
   267 	iIconId = aStream.ReadInt32L();
       
   268 	iMaskId = aStream.ReadInt32L();
       
   269 
       
   270 	TInt length = aStream.ReadUint16L();
       
   271 	iIconFile = HBufC::NewL( length );
       
   272 	TPtr iconFilePtr = iIconFile->Des();
       
   273     aStream.ReadL( iconFilePtr, length );
       
   274 
       
   275 	length = aStream.ReadUint16L();
       
   276 	iViewName = HBufC::NewL( length );
       
   277 	TPtr viewNamePtr = iViewName->Des();
       
   278     aStream.ReadL( viewNamePtr, length );    
       
   279     }
       
   280 
       
   281 //  End of File