phonebookui/Phonebook2/spbcontentprovider/src/spbcontactdatamodelrow.cpp
branchRCL_3
changeset 6 e8e3147d53eb
equal deleted inserted replaced
5:81f8547efd4f 6:e8e3147d53eb
       
     1 /*
       
     2  * Copyright (c) 2009 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:  Listbox model row contact model
       
    15  *
       
    16  */
       
    17 
       
    18 #include "spbcontactdatamodelrow.h"
       
    19 #include <s32strm.h>
       
    20 
       
    21 // ======== MEMBER FUNCTIONS ========
       
    22 
       
    23 // --------------------------------------------------------------------------
       
    24 // CSpbContactDataModelRow::CSpbContactDataModelRow
       
    25 // --------------------------------------------------------------------------
       
    26 //
       
    27 inline CSpbContactDataModelRow::CSpbContactDataModelRow()
       
    28     {
       
    29     }
       
    30 
       
    31 // --------------------------------------------------------------------------
       
    32 // CSpbContactDataModelRow::~CSpbContactDataModelRow
       
    33 // --------------------------------------------------------------------------
       
    34 //
       
    35 CSpbContactDataModelRow::~CSpbContactDataModelRow()
       
    36     {
       
    37     iColumns.ResetAndDestroy();
       
    38     }
       
    39 
       
    40 // --------------------------------------------------------------------------
       
    41 // CSpbContactDataModelRow::NewL
       
    42 // --------------------------------------------------------------------------
       
    43 //
       
    44 CSpbContactDataModelRow* CSpbContactDataModelRow::NewL()
       
    45     {
       
    46     return new (ELeave) CSpbContactDataModelRow;
       
    47     }
       
    48 
       
    49 // --------------------------------------------------------------------------
       
    50 // CSpbContactDataModelRow::ColumnCount
       
    51 // --------------------------------------------------------------------------
       
    52 //
       
    53 TInt CSpbContactDataModelRow::ColumnCount() const
       
    54     {
       
    55     return iColumns.Count();
       
    56     }
       
    57 
       
    58 // --------------------------------------------------------------------------
       
    59 // CSpbContactDataModelRow::At
       
    60 // --------------------------------------------------------------------------
       
    61 //
       
    62 TPtrC CSpbContactDataModelRow::At(TInt aColumnIndex) const
       
    63     {
       
    64     return *iColumns[aColumnIndex];
       
    65     }
       
    66 
       
    67 // --------------------------------------------------------------------------
       
    68 // CSpbContactDataModelRow::AppendColumnL
       
    69 // --------------------------------------------------------------------------
       
    70 //
       
    71 void CSpbContactDataModelRow::AppendColumnL(const TDesC& aColumnText)
       
    72     {
       
    73     HBufC* buf = aColumnText.AllocLC();
       
    74     iColumns.AppendL( buf );
       
    75     CleanupStack::Pop( buf );
       
    76     }
       
    77 
       
    78 // --------------------------------------------------------------------------
       
    79 // CSpbContactDataModelRow::ReplaceColumnL
       
    80 // --------------------------------------------------------------------------
       
    81 //
       
    82 void CSpbContactDataModelRow::ReplaceColumnL( 
       
    83     TInt aIndex, const TDesC& aColumnText )
       
    84     {
       
    85     HBufC* buf = aColumnText.AllocL();
       
    86     HBufC*& old = iColumns[aIndex];
       
    87     delete old;
       
    88     old = buf;
       
    89     }
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // CSpbContactDataModelRow::IsClipRequired
       
    93 // --------------------------------------------------------------------------
       
    94 //
       
    95 TBool CSpbContactDataModelRow::IsClipRequired() const
       
    96     {
       
    97     return iClipBeginning;
       
    98     }
       
    99 
       
   100 // --------------------------------------------------------------------------
       
   101 // CSpbContactDataModelRow::SetClipRequired
       
   102 // --------------------------------------------------------------------------
       
   103 //
       
   104 void CSpbContactDataModelRow::SetClipRequired(TBool aFlag)
       
   105     {
       
   106     iClipBeginning = aFlag;
       
   107     }
       
   108 
       
   109 // --------------------------------------------------------------------------
       
   110 // CSpbContactDataModelRow::Icon
       
   111 // --------------------------------------------------------------------------
       
   112 //
       
   113 const TPbk2IconId& CSpbContactDataModelRow::Icon()
       
   114     {
       
   115     return iIcon;
       
   116     }
       
   117 
       
   118 // --------------------------------------------------------------------------
       
   119 // CSpbContactDataModelRow::SetIcon
       
   120 // --------------------------------------------------------------------------
       
   121 //
       
   122 void CSpbContactDataModelRow::SetIcon( const TPbk2IconId& aIcon )
       
   123     {
       
   124     iIcon = aIcon;
       
   125     }
       
   126 
       
   127 // --------------------------------------------------------------------------
       
   128 // CSpbContactDataModelRow::TotalLength
       
   129 // --------------------------------------------------------------------------
       
   130 //
       
   131 TInt CSpbContactDataModelRow::TotalLength() const
       
   132     {
       
   133     TInt result = 0;
       
   134     const TInt count = iColumns.Count();
       
   135     for (TInt i = 0; i < count; ++i)
       
   136         {
       
   137         result += At(i).Length();
       
   138         }
       
   139     return result;
       
   140     }
       
   141 
       
   142 // --------------------------------------------------------------------------
       
   143 // CSpbContactDataModelRow::MaxColumnLength
       
   144 // --------------------------------------------------------------------------
       
   145 //
       
   146 TInt CSpbContactDataModelRow::MaxColumnLength() const
       
   147     {
       
   148     TInt result = 0;
       
   149     const TInt count = iColumns.Count();
       
   150     for (TInt i = 0; i < count; ++i)
       
   151         {
       
   152         result = Max(result, At(i).Length());
       
   153         }
       
   154     return result;
       
   155     }
       
   156 
       
   157 // --------------------------------------------------------------------------
       
   158 // CSpbContactDataModelRow::ExternalizeL
       
   159 // --------------------------------------------------------------------------
       
   160 //
       
   161 void CSpbContactDataModelRow::ExternalizeL( RWriteStream& aStream ) const
       
   162     {
       
   163     const TInt count = iColumns.Count();
       
   164     aStream.WriteInt8L( iClipBeginning );
       
   165     aStream.WriteL( (TUint8*)(&iIcon), sizeof( TPbk2IconId ) );
       
   166 
       
   167     aStream.WriteInt32L( count );
       
   168     for (TInt i = 0; i < count; ++i)
       
   169         {
       
   170         HBufC* text = iColumns[i]; 
       
   171         aStream.WriteInt32L( text->Length() );
       
   172         aStream.WriteL( *text );
       
   173         }
       
   174     }
       
   175 
       
   176 // --------------------------------------------------------------------------
       
   177 // CSpbContactDataModelRow::InternalizeL
       
   178 // --------------------------------------------------------------------------
       
   179 //
       
   180 void CSpbContactDataModelRow::InternalizeL( RReadStream& aStream )
       
   181     {
       
   182     iColumns.ResetAndDestroy();
       
   183 
       
   184     iClipBeginning = aStream.ReadInt8L();
       
   185     aStream.ReadL( (TUint8*)(&iIcon), sizeof( TPbk2IconId ) );
       
   186     
       
   187     const TInt count = aStream.ReadInt32L();
       
   188     for (TInt i = 0; i < count; ++i)
       
   189         {
       
   190         const TInt length = aStream.ReadInt32L();
       
   191         HBufC* buffer = HBufC::NewLC( length );
       
   192         TPtr column( buffer->Des() );
       
   193         aStream.ReadL( column, length );
       
   194         iColumns.AppendL( buffer );
       
   195         CleanupStack::Pop( buffer );
       
   196         }
       
   197     }
       
   198 
       
   199 // End of File