uiservicetab/vimpstdetailsviewplugin/src/cvimpstdetailsviewlistboxmodel.cpp
branchRCL_3
changeset 23 9a48e301e94b
parent 0 5e5d6b214f4f
equal deleted inserted replaced
22:3104fc151679 23:9a48e301e94b
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Implementation of detailsview plugin control data model
       
    15  *
       
    16 */
       
    17 
       
    18  
       
    19 #include "cvimpstdetailsviewlistboxmodel.h"
       
    20 
       
    21 #include "cvimpstfieldproperty.h"
       
    22 #include "cvimpstfieldpropertyarray.h"
       
    23 #include "vimpstdetailsview.hrh"
       
    24 #include "tvimpstenums.h"
       
    25 #include <vimpstdetailsviewpluginrsc.rsg>
       
    26 // virtual phonebook 
       
    27 #include <MVPbkFieldType.h>
       
    28 #include <MVPbkStoreContact.h>
       
    29 #include <MVPbkContactStore.h>
       
    30 #include <MVPbkContactStoreProperties.h>
       
    31 // system includes
       
    32 #include <aknlists.h>
       
    33 #include <avkon.rsg>
       
    34 #include <VPbkEng.rsg>
       
    35 #include <AknIconArray.h>
       
    36 #include <barsc.h>
       
    37 #include <barsread.h>
       
    38 #include <StringLoader.h>
       
    39 
       
    40 // ======== LOCAL FUNCTIONS ========
       
    41 
       
    42 // ======== MEMBER FUNCTIONS ========
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CVIMPSTDetailsViewListBoxModel::NewL
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CVIMPSTDetailsViewListBoxModel* CVIMPSTDetailsViewListBoxModel::NewL(
       
    49     CEikListBox& aListBox,
       
    50     MVIMPSTDetailsPresenceHandler& aPresenceHandler,
       
    51     HBufC8* aFieldBuffer)
       
    52 	{
       
    53 	CVIMPSTDetailsViewListBoxModel* self =
       
    54 	    new(ELeave) CVIMPSTDetailsViewListBoxModel(aListBox, aPresenceHandler,
       
    55 	    aFieldBuffer );
       
    56 	CleanupStack::PushL(self);
       
    57 	self->ConstructL();
       
    58 	CleanupStack::Pop(self);
       
    59 
       
    60 	return self;
       
    61 	}
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CVIMPSTDetailsViewListBoxModel::~CVIMPSTDetailsViewListBoxModel
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CVIMPSTDetailsViewListBoxModel::~CVIMPSTDetailsViewListBoxModel()
       
    68 	{
       
    69 	delete iFieldArray;
       
    70 	delete iTextCache;
       
    71 	delete iFieldBuffer;
       
    72 	}
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CVIMPSTDetailsViewListBoxModel::CVIMPSTDetailsViewListBoxModel
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CVIMPSTDetailsViewListBoxModel::CVIMPSTDetailsViewListBoxModel(
       
    79 	    CEikListBox& aListBox,
       
    80 	    MVIMPSTDetailsPresenceHandler& aPresenceHandler,
       
    81 	    HBufC8* aFieldBuffer )
       
    82 	: iListBox(aListBox),
       
    83     iPresenceHandler( aPresenceHandler )
       
    84 	{
       
    85 	// owns
       
    86     iFieldBuffer = aFieldBuffer ;
       
    87 	}
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CVIMPSTDetailsViewListBoxModel::ConstructL
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CVIMPSTDetailsViewListBoxModel::ConstructL()
       
    94 	{
       
    95 	iTextCache = new(ELeave) CDesCArrayFlat(KCacheGranularity);
       
    96 	}
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CVIMPSTDetailsViewListBoxModel::
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 TInt CVIMPSTDetailsViewListBoxModel::FocusedFieldIndex()
       
   103 	{
       
   104 	return iListBox.CurrentItemIndex();
       
   105 	}
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CVIMPSTDetailsViewListBoxModel::
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 void CVIMPSTDetailsViewListBoxModel::SetFocusedListIndex(TInt aIndex)
       
   112 	{
       
   113 	if( !iFieldArray )
       
   114 		{
       
   115 		return;
       
   116 		}
       
   117 	TInt count = iFieldArray->Count();
       
   118 	if (  aIndex < 0 || aIndex >= count  )
       
   119 		{
       
   120 		aIndex = 0;
       
   121 		}
       
   122 	if( count )
       
   123 		{
       
   124 		iListBox.SetCurrentItemIndexAndDraw(aIndex); 
       
   125 		}
       
   126 	}
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // CVIMPSTDetailsViewListBoxModel::
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132  CVIMPSTFieldProperty& CVIMPSTDetailsViewListBoxModel::FocusField()
       
   133 	{
       
   134 	return ( iFieldArray->At( FocusedFieldIndex() ) );
       
   135 	}
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // CVIMPSTDetailsViewListBoxModel::FieldsArray
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141  CVIMPSTFieldPropertyArray& CVIMPSTDetailsViewListBoxModel::FieldsArray()
       
   142 	{
       
   143 	return *iFieldArray;
       
   144 	}
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CVIMPSTDetailsViewListBoxModel::FieldsCount
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 TInt CVIMPSTDetailsViewListBoxModel::FieldsCount()
       
   151 	{
       
   152 	if( !iFieldArray )
       
   153 		{
       
   154 		return 0;	
       
   155 		}
       
   156 	return iFieldArray->Count();
       
   157 	}
       
   158 // ---------------------------------------------------------------------------
       
   159 // CVIMPSTDetailsViewListBoxModel::CreateListPresentationL
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void CVIMPSTDetailsViewListBoxModel::CreateListPresentationL( MVPbkStoreContact& aContact,
       
   163 													   TInt aFocusFieldIndex,TDesC& aServiceName,  TStoreType aStoreType )
       
   164 	{
       
   165 	const MVPbkContactStoreProperties& storeProperties =  aContact.ParentStore().StoreProperties();
       
   166 	const MVPbkFieldTypeList& supportedFieldTypes = storeProperties.SupportedFields();
       
   167 	
       
   168 	if( iFieldBuffer )
       
   169 	    {
       
   170 	    TResourceReader reader;
       
   171         HBufC8* buf = iFieldBuffer->AllocL();
       
   172         CleanupStack::PushL( buf );
       
   173         reader.SetBuffer( buf );        
       
   174         iFieldArray = CVIMPSTFieldPropertyArray::NewL( supportedFieldTypes, 
       
   175                                                     aContact,
       
   176                                                     reader , 
       
   177                                                     iPresenceHandler.IsSupported(),
       
   178                                                     aServiceName,
       
   179                                                     aStoreType);
       
   180         CleanupStack::PopAndDestroy( buf );
       
   181         } 	
       
   182 
       
   183 	AddFieldsDataL();
       
   184 	if( iTextCache->Count() ) 
       
   185 		{
       
   186 	    CVIMPSTFieldProperty* field = iFieldArray->GetFieldById( EVIMPSTFieldIdImpp  );
       
   187 		if( field )
       
   188 			{
       
   189 	 		iPresenceHandler.SubscribePresenceL( field->FieldDataL() );	
       
   190 			}
       
   191 		SetFocusedListIndex( aFocusFieldIndex );	
       
   192 		}
       
   193 	}
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CVIMPSTDetailsViewListBoxModel::SetEmptyTextsToListboxL()
       
   197 // See header for details. 
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void CVIMPSTDetailsViewListBoxModel::SetEmptyTextsToListboxL()
       
   201     { 
       
   202     // update the empty string now to avoid flickering
       
   203     HBufC* string = StringLoader::LoadLC( R_SERVDETAIL_BACKGROUNDTEXT_HEADER );
       
   204     if( string )
       
   205 		{
       
   206 		iListBox.View()->SetListEmptyTextL( *string );
       
   207 		CleanupStack::PopAndDestroy( string );
       
   208 		iListBox.DrawNow(); 	
       
   209 		}
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CVIMPSTDetailsViewListBoxModel::MdcaCount
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 TInt CVIMPSTDetailsViewListBoxModel::MdcaCount() const
       
   217 	{
       
   218 	return iTextCache->Count();
       
   219 	}
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CVIMPSTDetailsViewListBoxModel::MdcaPoint
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 TPtrC CVIMPSTDetailsViewListBoxModel::MdcaPoint(TInt aIndex) const
       
   226 	{
       
   227 	return iTextCache->MdcaPoint(aIndex);
       
   228 	}
       
   229 
       
   230 // --------------------------------------------------------------------------
       
   231 // CVIMPSTDetailsViewListBoxModel::AddFieldsDataL
       
   232 // --------------------------------------------------------------------------
       
   233 //
       
   234 void CVIMPSTDetailsViewListBoxModel::AddFieldsDataL( )
       
   235 	{
       
   236 	iTextCache->Reset();
       
   237 	
       
   238 	TInt fieldCount = iFieldArray->Count();
       
   239 
       
   240 	for (TInt i = 0; i < fieldCount; i++)
       
   241 		{
       
   242 		TBuf<KBufferSize> buffer;
       
   243 		buffer.Zero();
       
   244 		
       
   245 		CVIMPSTFieldProperty& field = iFieldArray->At(i);
       
   246 		TInt iconId = field.IconId();
       
   247 		if( field.FieldId() == EVIMPSTFieldIdStatusMsg )
       
   248 			{
       
   249 			TVIMPSTEnums::TOnlineStatus status = iPresenceHandler.GetPresenceStatus();
       
   250 			switch( status )
       
   251 				{
       
   252 				case TVIMPSTEnums::EOnline:
       
   253 					{
       
   254 					iconId = static_cast<TInt>(EVIMPSTServiceIconOn);
       
   255 					break;	
       
   256 					}
       
   257 				case TVIMPSTEnums::EInvisible:
       
   258 					{
       
   259 					iconId = static_cast<TInt>(EVIMPSTServiceIconInvi);
       
   260 					break;	
       
   261 					}
       
   262 				case TVIMPSTEnums::EAway:
       
   263 					{
       
   264 					iconId = static_cast<TInt>(EVIMPSTServiceIconAway);
       
   265 					break;	
       
   266 					}
       
   267 				case TVIMPSTEnums::EBusy:
       
   268 				case TVIMPSTEnums::EDoNotDisturb:    
       
   269 					{
       
   270 					iconId = static_cast<TInt>(EVIMPSTServiceIconBusy);
       
   271 					break;	
       
   272 					}
       
   273 				case TVIMPSTEnums::EOnPhone:
       
   274 					{
       
   275 					iconId = static_cast<TInt>(EVIMPSTServiceIconOnMobile);
       
   276 					break;	
       
   277 					}
       
   278 				case TVIMPSTEnums::EOffline:
       
   279 					{
       
   280 					iconId = static_cast<TInt>(EVIMPSTServiceIconOff);
       
   281 					break;	
       
   282 					}
       
   283 				case TVIMPSTEnums::ECallForward:
       
   284 				    {
       
   285 				    iconId = static_cast<TInt>(EVIMPSTServiceIconCallForward);
       
   286 				    break;  
       
   287 				    }				                    
       
   288 				case TVIMPSTEnums::EPending:
       
   289                 case TVIMPSTEnums::EBlocked:
       
   290                 case TVIMPSTEnums::EUnknown:
       
   291                 case TVIMPSTEnums::EServiceOut:
       
   292                 default:
       
   293                     {
       
   294                     iconId = static_cast<TInt>(EVIMPSTServiceIconEmpty);
       
   295                     break;  
       
   296                     }   
       
   297                         }
       
   298                     field.SetFieldTextL( iPresenceHandler.GetStatusMessageL() )	;
       
   299                     }
       
   300 					
       
   301 	    if( iconId == static_cast<TInt>(EVIMPSTServiceIconEmpty ) )
       
   302 			{
       
   303 			buffer.Append(KTabLit);	//0
       
   304 			}
       
   305 		else
       
   306 			{
       
   307 			buffer.AppendNum(iconId); //0
       
   308 			buffer.Append(KTabLit);	
       
   309 			}
       
   310 			
       
   311 		TPtrC labelPtr = field.DefaultLabelL();
       
   312 		buffer.Append( labelPtr );
       
   313 		buffer.Append(KTabLit);
       
   314 		TPtrC fieldText = field.FieldDataL();
       
   315 		buffer.Append( fieldText );
       
   316 		iTextCache->AppendL(buffer);
       
   317 		buffer.Zero();
       
   318 		}
       
   319 	iListBox.HandleItemAdditionL();
       
   320 	}
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CVIMPSTDetailsViewListBoxModel::DisplayId
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 TPtrC CVIMPSTDetailsViewListBoxModel::DisplayId( const TDesC& aId, TBool aListHiding )
       
   327     {
       
   328     TPtrC ret( aId );
       
   329     // locate ":" for userid, groupid.
       
   330     // locate "/" for list id.
       
   331     TInt pos = aId.FindC( aListHiding ? KSlash : KColon );
       
   332 
       
   333     if ( ( pos != KErrNotFound) && ( pos != aId.Length()-1) )
       
   334         {
       
   335         // contains the special character, and it is not the last char
       
   336         // remove everything before the special char (including the char)
       
   337         ret.Set( aId.Mid( pos + 1 ) );
       
   338         }
       
   339    // remove also the domain part
       
   340     TInt domainPos = ret.FindC( KAt );
       
   341     if ( ( domainPos != KErrNotFound ) && ( domainPos != 0 ) )
       
   342         {
       
   343         ret.Set( ret.Mid( 0, domainPos ) );
       
   344         }
       
   345     return ret;
       
   346     }    
       
   347    
       
   348 // End of File