uiservicetab/vimpstui/src/cvimpstuidoublelistboxarray.cpp
branchRCL_3
changeset 23 9a48e301e94b
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:  CVIMPSTUiDoubleListboxArray-array decorator
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include	"cvimpstuidoublelistboxarray.h"
       
    21 #include    "tvimpstconsts.h"
       
    22 #include    "vimpstutils.h"
       
    23 #include    "mvimpstprocessarray.h"
       
    24 #include    "cvimpstuidoublelistboxtabviewcontrol.h" // tab control
       
    25 #include 	<vimpstuires.rsg>
       
    26 #include    "tvimpstenums.h"
       
    27 #include "uiservicetabtracer.h"
       
    28 // platform includes
       
    29 
       
    30 #include    <AknUtils.h>
       
    31 #include    <StringLoader.h>
       
    32 #include    <AknIconUtils.h>
       
    33 #include    <AknIconArray.h>
       
    34 #include    <eikclbd.h>
       
    35 #include    <AknsConstants.h>
       
    36 
       
    37 #include    <vimpstui.mbg>
       
    38 
       
    39 const TInt KAvtarLength = 3;
       
    40  _LIT( KAvatarString ,   "%d\t" );
       
    41 // ================= MEMBER FUNCTIONS =======================
       
    42 
       
    43 // Two-phased constructor.
       
    44 CVIMPSTUiDoubleListboxArray* CVIMPSTUiDoubleListboxArray::NewL(MVIMPSTProcessArray& aItemModel,
       
    45 							            CFormattedCellListBoxData* aListboxData,
       
    46 							            CVIMPSTUiDoubleStyleListBox& aListBox,
       
    47 							            CVIMPSTUiDoubleListBoxTabViewControl& aTabbedviewControl
       
    48 							            )
       
    49     {
       
    50 	TRACER_AUTO;
       
    51     CVIMPSTUiDoubleListboxArray* self = new (ELeave) CVIMPSTUiDoubleListboxArray( aItemModel, 
       
    52     								aListboxData, aListBox,aTabbedviewControl);
       
    53     								
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL();
       
    56     CleanupStack::Pop( self );
       
    57     return self;
       
    58     }
       
    59 
       
    60 // Destructor
       
    61 CVIMPSTUiDoubleListboxArray::~CVIMPSTUiDoubleListboxArray()
       
    62     {
       
    63     delete iData;
       
    64     }
       
    65 
       
    66 // C++ default constructor can NOT contain any code, that
       
    67 // might leave.
       
    68 //
       
    69 CVIMPSTUiDoubleListboxArray::CVIMPSTUiDoubleListboxArray( MVIMPSTProcessArray& aItemModel,
       
    70         CFormattedCellListBoxData* aListboxData, CVIMPSTUiDoubleStyleListBox& aListBox /*= NULL*/,
       
    71         CVIMPSTUiDoubleListBoxTabViewControl& aTabbedviewControl)
       
    72     :
       
    73      iItemArray(aItemModel), 
       
    74      iListboxData( aListboxData ),
       
    75      iListBox(aListBox),
       
    76      iTabbedviewControl(aTabbedviewControl)
       
    77     {
       
    78     }
       
    79 
       
    80 // Symbian OS default constructor can leave.
       
    81 void CVIMPSTUiDoubleListboxArray::ConstructL()
       
    82 	{
       
    83 	TRACER_AUTO;
       
    84 	 // maximum length of icons appended to identification
       
    85     // There can be four icons (A+B and two on D-column)
       
    86     iMaxLengthOfIcons =
       
    87         KDefaultAvatar().Length()+  // longest A-Column icon
       
    88         (KTab().Length() * 2)+ // length of tabs between items 
       
    89         KContactOnlineIconA().Length(); // longest D-Column icon
       
    90         
       
    91     // Reserve enough memory to handle maximum size item
       
    92 	iData = HBufC::NewL( KFriendsListMaxIdentificationLength +
       
    93 	                     KStatusMsgMaxLength +
       
    94 					     iMaxLengthOfIcons );
       
    95 	
       
    96 	iPresenceSupported = iItemArray.IsSubServiceSupportedL(TVIMPSTEnums::EPresence);
       
    97 	iIMSupported = iItemArray.IsSubServiceSupportedL(TVIMPSTEnums::EIM );
       
    98     }
       
    99 
       
   100 
       
   101 // ---------------------------------------------------------
       
   102 // CVIMPSTUiDoubleListboxArray::MdcaCount
       
   103 // Returns the number of descriptor elements in a descriptor array.
       
   104 // (other items were commented in a header).
       
   105 // ---------------------------------------------------------
       
   106 //
       
   107 TInt CVIMPSTUiDoubleListboxArray::MdcaCount() const
       
   108 	{
       
   109 	return iItemArray.Count();
       
   110 	}
       
   111 
       
   112 // ---------------------------------------------------------
       
   113 // CVIMPSTUiDoubleListboxArray::MdcaCount
       
   114 // Return pointer to descriptor data in given index of an array
       
   115 // (other items were commented in a header).
       
   116 // ---------------------------------------------------------
       
   117 //
       
   118 TPtrC16 CVIMPSTUiDoubleListboxArray::MdcaPoint( TInt aIndex ) const
       
   119 	{
       
   120 	TRACER_AUTO;
       
   121 	TRACE(" aIndex: %d", aIndex );	    
       
   122 	// Although this is a const method, we do change the member data.
       
   123 	// This is done because of performance
       
   124 	// -> no need to create new buffer every time.
       
   125     TPtr dataPtr( iData->Des() );
       
   126     dataPtr.Zero();
       
   127 
       
   128   
       
   129     // fetch the item and process correct type    
       
   130     TVIMPSTEnums::TItem type = iItemArray.GetType(aIndex);
       
   131     TRACE(" item type: %d", type );	    
       
   132  
       
   133     switch( type )
       
   134         {
       
   135         case TVIMPSTEnums::EOwnStatusItem:
       
   136 	        {
       
   137 	        TRACE("  own data" );	    
       
   138 	        TRAP_IGNORE( AppendOwnDataL(dataPtr,aIndex ) );
       
   139 	        break;	
       
   140 	        }	
       
   141         case TVIMPSTEnums::EContactItem: 		
       
   142         case TVIMPSTEnums::EUnknonContactItem:
       
   143         case TVIMPSTEnums::EFriendRequestItem:
       
   144             {
       
   145             return iItemArray.GetFormattedString(aIndex);
       
   146             }
       
   147         default:
       
   148             {
       
   149             // shouldn't be here
       
   150             TRACE(" -> default" );	    
       
   151             break;
       
   152             }
       
   153         } //end outer switch
       
   154     
       
   155        
       
   156     return dataPtr;
       
   157 	}
       
   158 	
       
   159 
       
   160 
       
   161 // ---------------------------------------------------------
       
   162 // CVIMPSTUiDoubleListboxArray::AppendContact
       
   163 // Append formatted contact identification to buffer
       
   164 // (other items were commented in a header).
       
   165 // ---------------------------------------------------------
       
   166 //
       
   167 void CVIMPSTUiDoubleListboxArray::AppendOwnDataL( TPtr& aBuffer,
       
   168                                       TInt aIndex
       
   169                                       ) const
       
   170     {    
       
   171 	TRACER_AUTO;		
       
   172     TVIMPSTEnums::TVIMPSTRegistrationState loginstate = iItemArray.GetLoginState();
       
   173     TRACE("login state: %d" , loginstate );		
       
   174     TInt avtarIndex = iItemArray.OwnAvatarIndexL();
       
   175 
       
   176     if( avtarIndex )
       
   177         {
       
   178         TBuf<KAvtarLength> buf;
       
   179         buf.Format( KAvatarString, avtarIndex);
       
   180         aBuffer.Append( buf);
       
   181         }
       
   182     else
       
   183         {
       
   184         // append default avatar  for column A 
       
   185         aBuffer.Append( KDefaultAvatar );
       
   186         }
       
   187     // B-column  append dispplay id 
       
   188      
       
   189   
       
   190     // append only max length of the user id allowed : extra check
       
   191     
       
   192     TPtrC identification(VIMPSTUtils::DisplayId(iItemArray.GetItemUserId(aIndex)));
       
   193     aBuffer.Append( identification.Left( KFriendsListMaxIdentificationLength ) );
       
   194 
       
   195    
       
   196 
       
   197     // append  \t before second line text
       
   198     aBuffer.Append( KTab );
       
   199 
       
   200     // append status text for second line and Icon for column D  based on conditions 
       
   201     if (  TVIMPSTEnums::ESVCERegistered == loginstate ) 
       
   202         {
       
   203         TVIMPSTEnums::TOnlineStatus status = iItemArray.GetOnlineStatusL(aIndex);
       
   204         TRACE(" status: %d" , status );		
       
   205         TPtrC statusText = iItemArray.StatusTextL( aIndex );
       
   206         if( statusText.Length()  > 0) // if status text show it
       
   207             {
       
   208             // append only KStatusMsgMaxLenght of status masg
       
   209             aBuffer.Append( statusText.Left( KStatusMsgMaxLength ) );
       
   210             }
       
   211         else
       
   212             { // show default if no status text based on status
       
   213             switch(status) // no need to handle the serviceout case as its not applicable here in case of own data
       
   214                 {
       
   215                 case TVIMPSTEnums::EOnline:
       
   216                     {
       
   217                     HBufC* onlineText = StringLoader::LoadLC( R_QTN_SERVTAB_DEFAULT_STATUSTEXT_ONLINE );
       
   218                     aBuffer.Append( onlineText->Des());
       
   219                     CleanupStack::PopAndDestroy(); //onlineText
       
   220                     break;
       
   221                     }
       
   222                 case TVIMPSTEnums::EBusy:
       
   223                     {
       
   224                     HBufC* busyText = StringLoader::LoadLC( R_SERVDETAIL_STATUSTEXT_BUSY ) ;
       
   225                     aBuffer.Append( busyText->Des());
       
   226                     CleanupStack::PopAndDestroy(); //busyText
       
   227                     break;
       
   228                     }
       
   229                 case TVIMPSTEnums::EAway:   
       
   230                     {
       
   231                     HBufC* awayText = StringLoader::LoadLC( R_QTN_SERVTAB_DEFAULT_STATUSTEXT_AWAY );
       
   232                     aBuffer.Append( awayText->Des());
       
   233                     CleanupStack::PopAndDestroy(); //awayText
       
   234                     break;
       
   235                     }
       
   236                 case TVIMPSTEnums::EOnPhone:   
       
   237                     {
       
   238                     HBufC* onphoneText = StringLoader::LoadLC( R_SERVDETAIL_STATUSTEXT_ONTHEPHONE );
       
   239                     aBuffer.Append( onphoneText->Des());
       
   240                     CleanupStack::PopAndDestroy(); //onphone text
       
   241                     break;
       
   242                     }
       
   243                 case TVIMPSTEnums::EDoNotDisturb:   
       
   244                     {
       
   245                     HBufC* dndText = StringLoader::LoadLC( R_SERVDETAIL_STATUSTEXT_DND );
       
   246                     aBuffer.Append( dndText->Des());
       
   247                     CleanupStack::PopAndDestroy(); //dnd Text
       
   248                     break;
       
   249                     }
       
   250                case TVIMPSTEnums::EInvisible:
       
   251                    {
       
   252                    HBufC* invisibleText = StringLoader::LoadLC( R_QTN_SERVTAB_DEFAULT_STATUSTEXT_INVISIBLE );
       
   253                    aBuffer.Append( invisibleText->Des());
       
   254                    CleanupStack::PopAndDestroy(); //invisible text
       
   255                    break;
       
   256                    }  
       
   257                case TVIMPSTEnums::EOffline:  
       
   258                default:
       
   259                     {
       
   260                     HBufC* offlineText = StringLoader::LoadLC( R_QTN_SERVTAB_DEFAULT_STATUSTEXT_OFFLINE );
       
   261                     aBuffer.Append( offlineText->Des());
       
   262                     CleanupStack::PopAndDestroy(); //offlineText
       
   263                     break;
       
   264                     }
       
   265                 }// end case for status text
       
   266             }
       
   267         // append tab before appending icon
       
   268         aBuffer.Append( KTab );
       
   269 
       
   270         TRACE(" handle status enum: %d" , status );		
       
   271         switch(status)
       
   272             {
       
   273             case TVIMPSTEnums::EOnline:
       
   274                 {
       
   275                 aBuffer.Append( KContactOnlineIconA );
       
   276                 break;
       
   277                 }
       
   278             case TVIMPSTEnums::EInvisible:
       
   279                 {
       
   280                 aBuffer.Append( KListInvisibleIcon );
       
   281                 break;
       
   282                 }
       
   283             case TVIMPSTEnums::EBusy:
       
   284             case TVIMPSTEnums::EDoNotDisturb:
       
   285                 {
       
   286                 aBuffer.Append( KListBusyIcon );
       
   287                 break;
       
   288                 }
       
   289             case TVIMPSTEnums::EAway:   
       
   290                 {
       
   291                 aBuffer.Append( KListAwayIcon );
       
   292                 break;
       
   293                 }
       
   294 			case TVIMPSTEnums::EOnPhone:   
       
   295 			    {
       
   296 			    aBuffer.Append( KFrndOnMobileIcon );
       
   297 			    break;
       
   298 			    }
       
   299             case TVIMPSTEnums::EOffline: //Flowthrough 
       
   300                 {
       
   301                 aBuffer.Append( KContactOfflineIconA );
       
   302                 break;
       
   303                 }
       
   304             case TVIMPSTEnums::EBlocked:  
       
   305             case TVIMPSTEnums::EPending:
       
   306             default:
       
   307                 {
       
   308                 aBuffer.Append( KEmptyIconA );
       
   309                 break;
       
   310                 }
       
   311             }//end switch 
       
   312 
       
   313         }         
       
   314     else 
       
   315         {
       
   316         // except in  disconnecting state show username
       
   317         if(TVIMPSTEnums::ESVCENetworkDisConnecting != loginstate )                               
       
   318             {
       
   319 			TRACE(" offline state" );		
       
   320             TPtrC userId = iItemArray.LoginUserIdFromStoreL(); 
       
   321             aBuffer.Append( VIMPSTUtils::DisplayId( userId ));
       
   322             }
       
   323         aBuffer.Append( KTab ); // append tab 
       
   324         aBuffer.Append( KEmptyIconC );  // no icon
       
   325         }
       
   326 
       
   327 }
       
   328 
       
   329 
       
   330 
       
   331 
       
   332 
       
   333 //  End of File