predictivesearch/PcsAlgorithm/Algorithm1/src/CPcsAdaptiveGridItem.cpp
branchRCL_3
changeset 39 a6539d1e8e43
equal deleted inserted replaced
35:4ae315f230bc 39:a6539d1e8e43
       
     1 /*
       
     2 * Copyright (c) 2010 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:  Utility class to hold a single item for Adaptive Grid.
       
    15 *               Used to provide quickly to client applications (Phonebook)
       
    16 *               The Adaptive Grid for the full list of contacts, which is
       
    17 *               the one that is displayed when the Find Box is empty.
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CPcsDebug.h"
       
    23 #include "CPcsAlgorithm1Utils.h"
       
    24 #include "CPcsAdaptiveGridItem.h"
       
    25 
       
    26 
       
    27 // ============================== MEMBER FUNCTIONS ============================
       
    28 
       
    29 // ----------------------------------------------------------------------------
       
    30 // CPcsAdaptiveGridItem::NewL
       
    31 // Two Phase Construction
       
    32 // ----------------------------------------------------------------------------
       
    33 CPcsAdaptiveGridItem* CPcsAdaptiveGridItem::NewL( const TChar& aChar )
       
    34 {
       
    35 	return new ( ELeave ) CPcsAdaptiveGridItem( aChar );
       
    36 } 
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // CPcsAdaptiveGridItem::CPcsAdaptiveGridItem
       
    40 // Constructor
       
    41 // ----------------------------------------------------------------------------
       
    42 CPcsAdaptiveGridItem::CPcsAdaptiveGridItem( const TChar& aChar ):
       
    43         iCharacter(User::UpperCase( aChar ))
       
    44 {
       
    45     // Set zeroes in the reference counters array
       
    46     for ( TInt i=0; i < CPcsAdaptiveGridItem::ENumberCounters; i++ )
       
    47         {
       
    48         iCountersArr[i] = 0;
       
    49         }
       
    50 }
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CPcsAdaptiveGridItem::~CPcsAdaptiveGridItem
       
    54 // Destructor
       
    55 // ----------------------------------------------------------------------------
       
    56 CPcsAdaptiveGridItem::~CPcsAdaptiveGridItem( )
       
    57 {
       
    58     iCountersArr.Reset();
       
    59 }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CPcsAlgorithm1Utils::CompareByCharacter()
       
    63 // TLinearOrder rule for comparison of data objects
       
    64 // ----------------------------------------------------------------------------
       
    65 TInt CPcsAdaptiveGridItem::CompareByCharacter( const CPcsAdaptiveGridItem& aObject1, 
       
    66                                                const CPcsAdaptiveGridItem& aObject2 )
       
    67 {
       
    68     return CPcsAlgorithm1Utils::CompareByCharacter(
       
    69             aObject1.Character(), aObject2.Character() );
       
    70 }
       
    71 
       
    72 // ----------------------------------------------------------------------------
       
    73 // CPcsAdaptiveGridItem::Character
       
    74 // Return character of the Adaptive Grid Item 
       
    75 // ----------------------------------------------------------------------------
       
    76 TChar CPcsAdaptiveGridItem::Character( ) const
       
    77 {
       
    78     return iCharacter;
       
    79 }
       
    80 
       
    81 // ----------------------------------------------------------------------------
       
    82 // CPcsAdaptiveGridItem::GetRefCounter
       
    83 // Return the reference counter for one selector 
       
    84 // ----------------------------------------------------------------------------
       
    85 TUint CPcsAdaptiveGridItem::GetRefCounter( const TUint aSelector )
       
    86 {
       
    87     if ( aSelector < CPcsAdaptiveGridItem::ENumberCounters )
       
    88         {
       
    89         return iCountersArr[aSelector];
       
    90         }
       
    91     else
       
    92         {
       
    93         return 0;
       
    94         }
       
    95 }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // CPcsAdaptiveGridItem::IncrementRefCounter
       
    99 // Increment the reference counter for one selector 
       
   100 // ----------------------------------------------------------------------------
       
   101 void CPcsAdaptiveGridItem::IncrementRefCounter( const TUint aSelector )
       
   102 {
       
   103     if ( aSelector < CPcsAdaptiveGridItem::ENumberCounters )
       
   104         {
       
   105         iCountersArr[aSelector]++;
       
   106         }
       
   107 }
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CPcsAdaptiveGridItem::DecrementRefCounter
       
   111 // Decrement the reference counter for one selector 
       
   112 // ----------------------------------------------------------------------------
       
   113 void CPcsAdaptiveGridItem::DecrementRefCounter( const TUint aSelector )
       
   114 {
       
   115     if ( aSelector < CPcsAdaptiveGridItem::ENumberCounters )
       
   116         {
       
   117         if ( iCountersArr[aSelector] > 0 )
       
   118             {
       
   119             iCountersArr[aSelector]--;
       
   120             }
       
   121         else
       
   122             {
       
   123              PRINT2 ( _L("CPcsAdaptiveGridItem::DecrementRefCounter: ERROR Decrement ref counter 0, Character=%c, Selector=%d"),
       
   124                       (TUint) Character(), aSelector );
       
   125             }
       
   126         }
       
   127 }
       
   128 
       
   129 // ----------------------------------------------------------------------------
       
   130 // CPcsAdaptiveGridItem::AreRefCountersZero
       
   131 // Check if reference counters for all selectors are 0 
       
   132 // ----------------------------------------------------------------------------
       
   133 TBool CPcsAdaptiveGridItem::AreRefCountersZero( )
       
   134 {
       
   135     TBool retValue = ETrue;
       
   136 
       
   137     for ( TInt i=0; i < CPcsAdaptiveGridItem::ENumberCounters; i++ )
       
   138         {
       
   139         if ( iCountersArr[i] > 0 )
       
   140             {
       
   141             retValue = EFalse;
       
   142             break;
       
   143             }
       
   144         }
       
   145 
       
   146     return retValue;
       
   147 }
       
   148 
       
   149 // ----------------------------------------------------------------------------
       
   150 // CPcsAdaptiveGridItem::IsRefCounterNonZero
       
   151 // Check if reference counters for all selectors are 0 
       
   152 // ----------------------------------------------------------------------------
       
   153 TBool CPcsAdaptiveGridItem::IsRefCounterNonZero( const TBool aCompanyName )
       
   154 {
       
   155     TBool retValue = EFalse;
       
   156 
       
   157     if ( iCountersArr[CPcsAdaptiveGridItem::EFirstNameLastName] > 0 || 
       
   158          iCountersArr[CPcsAdaptiveGridItem::EUnnamedCompanyName] > 0 ||
       
   159          ( aCompanyName && iCountersArr[CPcsAdaptiveGridItem::ECompanyName] > 0 ) )
       
   160         {
       
   161         retValue = ETrue;
       
   162         }
       
   163 
       
   164     return retValue;
       
   165 }
       
   166 
       
   167 // End of file