emailuis/emailui/src/FreestyleEmailUiCLSItem.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 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:  CLS list item class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "emailtrace.h"
       
    21 #include <MVPbkContactLink.h>
       
    22 
       
    23 #include "FreestyleEmailUiCLSItem.h"		// CFSEmailUiClsItem
       
    24 #include "ncsconstants.h"
       
    25 
       
    26 // ================= MEMBER FUNCTIONS ==========================================
       
    27 // -----------------------------------------------------------------------------
       
    28 // CFSEmailUiClsItem::NewL
       
    29 // -----------------------------------------------------------------------------
       
    30 CFSEmailUiClsItem* CFSEmailUiClsItem::NewL()
       
    31 	{
       
    32     FUNC_LOG;
       
    33 	CFSEmailUiClsItem* object =  CFSEmailUiClsItem::NewLC();
       
    34 	CleanupStack::Pop( object );
       
    35 	return object;
       
    36 	}
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CFSEmailUiClsItem::NewLC
       
    40 // -----------------------------------------------------------------------------
       
    41 CFSEmailUiClsItem* CFSEmailUiClsItem::NewLC()
       
    42 	{
       
    43     FUNC_LOG;
       
    44 	CFSEmailUiClsItem* object = new (ELeave) CFSEmailUiClsItem();
       
    45 	CleanupStack::PushL( object );
       
    46 	object->ConstructL();
       
    47 	return object;
       
    48 	} 
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CFSEmailUiClsItem::~CFSEmailUiClsItem
       
    52 // -----------------------------------------------------------------------------
       
    53 CFSEmailUiClsItem::~CFSEmailUiClsItem()
       
    54 	{
       
    55     FUNC_LOG;
       
    56 	delete iDisplayName;
       
    57 	delete iEMailAddress;
       
    58 	delete iFullText;
       
    59 	delete iLink;
       
    60 
       
    61 	iHighlights.Close();
       
    62 	}
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // Creates a copy of the CLS item.
       
    66 // -----------------------------------------------------------------------------
       
    67 CFSEmailUiClsItem* CFSEmailUiClsItem::CloneLC() const
       
    68     {
       
    69     FUNC_LOG;
       
    70     CFSEmailUiClsItem* clone = CFSEmailUiClsItem::NewLC();
       
    71     clone->SetDisplayNameL( DisplayName() );
       
    72     clone->SetEmailAddressL( EmailAddress() );
       
    73     if ( ContactLink() )
       
    74         {
       
    75     	clone->SetContactLinkL( *ContactLink() );
       
    76         }
       
    77     clone->SetHighlights( Highlights() );
       
    78     clone->SetIsMruItem( IsMruItem() );
       
    79     clone->SetMultipleEmails( MultipleEmails() );
       
    80     return clone;
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CFSEmailUiClsItem::SetDisplayNameL
       
    85 // -----------------------------------------------------------------------------
       
    86 void CFSEmailUiClsItem::SetDisplayNameL( const TDesC& aDisplayName )
       
    87 	{
       
    88     FUNC_LOG;
       
    89 	delete iDisplayName;
       
    90 	iDisplayName = NULL;
       
    91 	iDisplayName = aDisplayName.AllocL();
       
    92 	}
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CFSEmailUiClsItem::SetEmailAddressL
       
    96 // -----------------------------------------------------------------------------
       
    97 void CFSEmailUiClsItem::SetEmailAddressL( const TDesC& aEmailAddress )
       
    98 	{
       
    99     FUNC_LOG;
       
   100 	delete iEMailAddress;
       
   101 	iEMailAddress = NULL;
       
   102 	iEMailAddress = aEmailAddress.AllocL();
       
   103 	}
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CFSEmailUiClsItem::SetContactId
       
   107 // -----------------------------------------------------------------------------
       
   108 void CFSEmailUiClsItem::SetContactLinkL( const MVPbkContactLink& aLink )
       
   109     {
       
   110     FUNC_LOG;
       
   111     MVPbkContactLink* copyLink = aLink.CloneLC();
       
   112     CleanupStack::Pop();
       
   113     iLink = copyLink;
       
   114     }
       
   115 
       
   116 void CFSEmailUiClsItem::SetIsMruItem( TBool aIsMruItem )
       
   117     {
       
   118     FUNC_LOG;
       
   119     iIsMruItem = aIsMruItem;
       
   120     }
       
   121 
       
   122 void CFSEmailUiClsItem::SetMultipleEmails( TBool ETrue )
       
   123 	{
       
   124     FUNC_LOG;
       
   125 	iMultipleEmails = ETrue;
       
   126 	}
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CFSEmailUiClsItem::Highlights
       
   130 // -----------------------------------------------------------------------------
       
   131 const RArray<TPsMatchLocation>& CFSEmailUiClsItem::Highlights() const
       
   132 	{
       
   133 	return iHighlights;
       
   134 	}
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CFSEmailUiClsItem::DisplayName
       
   138 // -----------------------------------------------------------------------------
       
   139 const TDesC& CFSEmailUiClsItem::DisplayName() const
       
   140 	{
       
   141     FUNC_LOG;
       
   142 	return *iDisplayName;
       
   143 	}
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CFSEmailUiClsItem::EmailAddress
       
   147 // -----------------------------------------------------------------------------
       
   148 const TDesC& CFSEmailUiClsItem::EmailAddress() const
       
   149 	{
       
   150     FUNC_LOG;
       
   151 	return *iEMailAddress;
       
   152 	}
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CFSEmailUiClsItem::FullText
       
   156 // -----------------------------------------------------------------------------
       
   157 const TDesC& CFSEmailUiClsItem::FullTextL()
       
   158 	{
       
   159     FUNC_LOG;
       
   160 	delete iFullText;
       
   161 	iFullText = NULL;
       
   162 	iFullText = HBufC::NewL( iDisplayName->Length() + 
       
   163 							 KSpace().Length() +
       
   164 							 iEMailAddress->Length() );
       
   165    
       
   166 	// don't add space if there is no display name
       
   167 	if( iDisplayName->CompareC( KNullDesC ) != 0 )
       
   168 		{
       
   169         iFullText->Des().Append( *iDisplayName );
       
   170 		iFullText->Des().Append( KSpace );
       
   171 		}
       
   172 	iFullText->Des().Append( *iEMailAddress );
       
   173 	return *iFullText;
       
   174 	}
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CFSEmailUiClsItem::ContactItemId
       
   178 // -----------------------------------------------------------------------------
       
   179 MVPbkContactLink* CFSEmailUiClsItem::ContactLink() const
       
   180     {
       
   181     FUNC_LOG;
       
   182     return iLink;
       
   183     }
       
   184 
       
   185 TBool CFSEmailUiClsItem::IsMruItem() const
       
   186     {
       
   187     FUNC_LOG;
       
   188     return iIsMruItem;
       
   189     }
       
   190 
       
   191 TBool CFSEmailUiClsItem::MultipleEmails() const
       
   192 	{
       
   193     FUNC_LOG;
       
   194 	return iMultipleEmails;
       
   195 	}
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CFSEmailUiClsItem::CFSEmailUiClsItem
       
   199 // -----------------------------------------------------------------------------
       
   200 CFSEmailUiClsItem::CFSEmailUiClsItem()
       
   201     : iMultipleEmails( EFalse ), iLink( NULL )
       
   202 	{
       
   203     FUNC_LOG;
       
   204 	}
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CFSEmailUiClsItem::ConstructL
       
   208 // -----------------------------------------------------------------------------
       
   209 void CFSEmailUiClsItem::ConstructL()
       
   210 	{
       
   211     FUNC_LOG;
       
   212 	iDisplayName = KNullDesC().AllocL();
       
   213 	iEMailAddress = KNullDesC().AllocL();
       
   214 	}
       
   215 
       
   216 TInt CompareHighlightElements( TPsMatchLocation const& aElement, TPsMatchLocation const& aElement2)
       
   217 {
       
   218 	return aElement.index - aElement2.index;
       
   219 }
       
   220 
       
   221 void CFSEmailUiClsItem::SetHighlights( const RArray<TPsMatchLocation>& aHighlights )
       
   222 	{
       
   223     FUNC_LOG;
       
   224 	iHighlights.Reset();
       
   225 	
       
   226 	// Convert right->left to left->right, this eases the visualisation
       
   227 	for ( TInt i=0; i<aHighlights.Count(); i++ )
       
   228 		{
       
   229 		iHighlights.Append(aHighlights[i]);
       
   230 		if(iHighlights[i].direction == TBidiText::ERightToLeft)
       
   231 			{
       
   232 			iHighlights[i].index -= aHighlights[i].length - 1;
       
   233 			iHighlights[i].direction = TBidiText::ELeftToRight;
       
   234 			}
       
   235 		}
       
   236 	
       
   237 	// Sort match locations according to index, this eases the visualisation
       
   238 	TLinearOrder<TPsMatchLocation> highlightSortOrder( &CompareHighlightElements );
       
   239 	iHighlights.Sort(highlightSortOrder);
       
   240 	}	
       
   241