phonebookui/Phonebook/View/src/CPbkContactGroupListModel.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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 *       Provides methods for phonebook contact view listbox model.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkContactGroupListModel.h"  // This class
       
    22 #include <cntviewbase.h>    // CContactViewBase
       
    23 #include <PbkEngUtils.h>
       
    24 
       
    25 /// Unnamed namespace for local definitions
       
    26 namespace {
       
    27 
       
    28 // LOCAL CONSTANTS AND MACROS
       
    29 _LIT(KCharsToReplace, "\t");
       
    30 _LIT(KReplacementChars, " ");
       
    31 
       
    32 #ifdef _DEBUG
       
    33 enum TPanicCode
       
    34     {
       
    35     EPanicPreCond_ConstructL = 1,
       
    36     EPanicLogic_FormatBufferForContactL
       
    37     };
       
    38 
       
    39 static void Panic(TPanicCode aReason)
       
    40     {
       
    41     _LIT(KPanicText, "CPbkContactGroupListModel");
       
    42     User::Panic(KPanicText, aReason);
       
    43     }
       
    44 #endif // _DEBUG
       
    45 
       
    46 } // namespace
       
    47 
       
    48 
       
    49 // ================= MEMBER FUNCTIONS =======================
       
    50 
       
    51 inline CPbkContactGroupListModel::CPbkContactGroupListModel
       
    52         (CContactViewBase& aView) : 
       
    53     CPbkContactViewListModelBase(aView,iFormattingBuffer), 
       
    54     iGroupLabelFieldIndex(-1)
       
    55     {
       
    56     }
       
    57 
       
    58 inline void CPbkContactGroupListModel::ConstructL()
       
    59     {
       
    60     __ASSERT_DEBUG(iView.ContactViewPreferences() & EGroupsOnly, 
       
    61         Panic(EPanicPreCond_ConstructL));
       
    62     iGroupLabelFieldIndex = GroupLabelFieldIndexL();
       
    63     }
       
    64 
       
    65 CPbkContactGroupListModel* CPbkContactGroupListModel::NewL
       
    66         (CContactViewBase& aGroupView)
       
    67     {
       
    68     CPbkContactGroupListModel* self =
       
    69         new(ELeave) CPbkContactGroupListModel(aGroupView);
       
    70     CleanupStack::PushL(self);
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop(self);
       
    73     return self;
       
    74     }
       
    75 
       
    76 CPbkContactGroupListModel::~CPbkContactGroupListModel()
       
    77     {
       
    78     }
       
    79 
       
    80 void CPbkContactGroupListModel::FormatBufferForContactL
       
    81         (const CViewContact& /*aViewContact*/) const
       
    82     {
       
    83     __ASSERT_DEBUG(EFalse, Panic(EPanicLogic_FormatBufferForContactL));
       
    84     }
       
    85 
       
    86 void CPbkContactGroupListModel::FormatBufferForGroupL
       
    87         (const CViewContact& aViewContact) const
       
    88     {
       
    89     iBuffer.Zero();
       
    90     AppendName(aViewContact.Field(iGroupLabelFieldIndex));
       
    91     }
       
    92 
       
    93 void CPbkContactGroupListModel::AppendName(const TDesC& aName) const
       
    94     {
       
    95     const TInt spaceLeft = iBuffer.MaxLength()-iBuffer.Length();
       
    96     PbkEngUtils::AppendAndReplaceChars
       
    97         (iBuffer, aName.Left(spaceLeft), KCharsToReplace, KReplacementChars);
       
    98     }
       
    99 
       
   100 void CPbkContactGroupListModel::FormatEmptyBuffer() const
       
   101     {
       
   102     iBuffer.Zero();
       
   103     }
       
   104 
       
   105 
       
   106 //  End of File