wvuing/wvuiprocess/Src/CCARecordedChatsArrayPC.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Array Interface for recorded chats array to interact with
       
    15 *				 the engine
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "MCALoggerHeadersInterface.h"
       
    21 #include "CCARecordedChatsArrayPC.h"
       
    22 #include "MCARecordedChatsPC.h"
       
    23 #include "chatdefinitions.h"
       
    24 #include "AknUtils.h"
       
    25 #include "StringLoader.h"
       
    26 #include <chatNG.rsg>
       
    27 
       
    28 
       
    29 // Format for listbox item.
       
    30 // 1\tTextLabel\tTimeAndDate
       
    31 // 2\tTextLabel\tTimeAndDate
       
    32 // First icon is mandatory and is chosen between group and I-messages (1\t 2\t ).
       
    33 _LIT( KRecordedIMessageIcon, "1\t" );
       
    34 _LIT( KRecordedGroupChatIcon, "2\t" );
       
    35 
       
    36 const TInt KGranularity = 2;
       
    37 
       
    38 // ---------------------------------------------------------
       
    39 // CCARecordedChatsArrayPC::CCARecordedChatsArrayPC
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 CCARecordedChatsArrayPC::CCARecordedChatsArrayPC( MCALoggerHeadersInterface&
       
    43                                                   aLoggerHeadersInterface )
       
    44         : iLoggerHeadersInterface( aLoggerHeadersInterface )
       
    45     {
       
    46 
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------
       
    50 // CCARecordedChatsArrayPC::NewL
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 CCARecordedChatsArrayPC* CCARecordedChatsArrayPC::NewL(
       
    54     MCALoggerHeadersInterface& aLoggerHeadersInterface )
       
    55     {
       
    56     CCARecordedChatsArrayPC* self = new ( ELeave ) CCARecordedChatsArrayPC( aLoggerHeadersInterface );
       
    57     return self;
       
    58     }
       
    59 
       
    60 
       
    61 // ------------------------------------------------------------------
       
    62 // CCARecordedChatsArrayPC::FinalizeRecChatsArrayPCConstructionL
       
    63 // To be called from the app ui once all the construction is over
       
    64 // since this PC class uses the string resources
       
    65 // ------------------------------------------------------------------
       
    66 //
       
    67 void CCARecordedChatsArrayPC::FinalizeRecChatsArrayPCConstructionL()
       
    68     {
       
    69     // maximum length of icons appended to identification
       
    70     // KRecordedIMessageIcon and KRecordedGroupChatIcon have same length
       
    71     TInt maxLengthOfIcons = KRecordedIMessageIcon().Length();
       
    72 
       
    73     // Reserve enough memory to handle maximum size item
       
    74     iData = HBufC::NewL( KFriendsListMaxIdentificationLength + maxLengthOfIcons );
       
    75 
       
    76     // get and format the time/date string
       
    77     HBufC* tFormat = CCoeEnv::Static()->AllocReadResourceLC(
       
    78                          R_QTN_TIME_USUAL_WITH_ZERO );
       
    79     HBufC* dFormat = CCoeEnv::Static()->AllocReadResourceLC(
       
    80                          R_QTN_DATE_SHORT_WITH_ZERO );
       
    81 
       
    82     CDesCArray* array = new( ELeave )CDesCArrayFlat( KGranularity ); // two items
       
    83     CleanupStack::PushL( array );
       
    84     array->AppendL( *tFormat );
       
    85     array->AppendL( *dFormat );
       
    86     iDateFormat = StringLoader::LoadL( R_QTN_CHAT_RECORD_END, *array );
       
    87     iStartDateFormat = StringLoader::LoadL(
       
    88                            R_CHATCLIENT_HISTORY_START_DATE, *array );
       
    89     iEndDateFormat = StringLoader::LoadL( R_CHATCLIENT_HISTORY_END_TIME, *array );
       
    90 
       
    91     // Same iTime is used for every format.
       
    92     // Take max length of them for buffer size.
       
    93     iTime = HBufC::NewL( Max( iEndDateFormat->Length(), Max( iDateFormat->Length(),
       
    94                                                              iStartDateFormat->Length() ) ) );
       
    95 
       
    96     //Codescanner warning ignored
       
    97     CleanupStack::PopAndDestroy( 3, tFormat ); //array, dFormat, tFormat
       
    98 
       
    99     }
       
   100 
       
   101 // ------------------------------------------------------------------
       
   102 // CCARecordedChatsArrayPC::~CCARecordedChatsArrayPC
       
   103 // ------------------------------------------------------------------
       
   104 //
       
   105 CCARecordedChatsArrayPC::~CCARecordedChatsArrayPC()
       
   106     {
       
   107     delete iDateFormat;
       
   108     delete iStartDateFormat;
       
   109     delete iEndDateFormat;
       
   110     delete iTime;
       
   111     delete iData;
       
   112     }
       
   113 
       
   114 // ------------------------------------------------------------------
       
   115 // CCARecordedChatsArrayPC::GetDateFormat
       
   116 // ------------------------------------------------------------------
       
   117 //
       
   118 TPtr CCARecordedChatsArrayPC::GetDateFormat()
       
   119     {
       
   120     return iDateFormat->Des();
       
   121     }
       
   122 
       
   123 // ------------------------------------------------------------------
       
   124 // CCARecordedChatsArrayPC::GetStartFormat
       
   125 // ------------------------------------------------------------------
       
   126 //
       
   127 TPtr CCARecordedChatsArrayPC::GetStartDateFormat()
       
   128     {
       
   129     return iStartDateFormat->Des();
       
   130     }
       
   131 
       
   132 // ------------------------------------------------------------------
       
   133 // CCARecordedChatsArrayPC::GetEndFormat
       
   134 // ------------------------------------------------------------------
       
   135 //
       
   136 TPtr CCARecordedChatsArrayPC::GetEndDateFormat()
       
   137     {
       
   138     return iEndDateFormat->Des();
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------
       
   142 // CCARecordedChatsArrayPC::MdcaCount
       
   143 // Returns the number of descriptor elements in a descriptor array.
       
   144 // (other items were commented in a header).
       
   145 // ---------------------------------------------------------
       
   146 //
       
   147 TInt CCARecordedChatsArrayPC::MdcaCount() const
       
   148     {
       
   149     return iLoggerHeadersInterface.HeaderCount();
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------
       
   153 // CCARecordedChatsArrayPC::MdcaPoint
       
   154 // Return pointer to descriptor data in given index of an array
       
   155 // (other items were commented in a header).
       
   156 // ---------------------------------------------------------
       
   157 //
       
   158 TPtrC16 CCARecordedChatsArrayPC::MdcaPoint( TInt aIndex ) const
       
   159     {
       
   160 
       
   161     if ( aIndex < 0 || aIndex >= iLoggerHeadersInterface.HeaderCount() )
       
   162         {
       
   163         return KNullDesC();
       
   164         }
       
   165 
       
   166     // Copy available identification (nickname/screenname/wvid) to buffer
       
   167     // Altough this is const method, next line does affect it's member data,
       
   168     // because of performance -> no need to create new buffer every time...
       
   169     // Copy max KFriendsListMaxIdentificationLength from identification
       
   170 
       
   171 
       
   172     TPtr dataPtr( iData->Des() );
       
   173     dataPtr.Copy( Name( aIndex ).Left( KFriendsListMaxIdentificationLength ) );
       
   174 
       
   175     //Show chat type icon in front of chat name.
       
   176     if ( ChatType( aIndex ) == EPTOPChat )
       
   177         {
       
   178         dataPtr.Insert( 0, KRecordedIMessageIcon );
       
   179         }
       
   180     else
       
   181         {
       
   182         dataPtr.Insert( 0, KRecordedGroupChatIcon );
       
   183         }
       
   184 
       
   185     //After chat name and before time
       
   186     dataPtr.Append( KTabulator );
       
   187 
       
   188     TPtr ptrDate( Time() );
       
   189 
       
   190     // This hardly fails. And if it for some reason fails, it is not critical,
       
   191     // because only thing what user notifies is missing end time of chat
       
   192     TRAPD( err, EndTime( aIndex ).FormatL( ptrDate, *iDateFormat ) );
       
   193     if ( err )
       
   194         {
       
   195         CActiveScheduler::Current()->Error( err );
       
   196         }
       
   197 
       
   198     AknTextUtils::LanguageSpecificNumberConversion( ptrDate );
       
   199 
       
   200     //Append time
       
   201     dataPtr.Append( Time() );
       
   202 
       
   203     return iData->Des();
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------
       
   207 // CCARecordedChatsArrayPC::Time
       
   208 // Return reference to time
       
   209 // ---------------------------------------------------------
       
   210 //
       
   211 TPtr CCARecordedChatsArrayPC::Time() const
       
   212     {
       
   213     return iTime->Des();
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------
       
   217 // CCARecordedChatsArrayPC::Name
       
   218 // Return reference to descriptor data in given index of an array
       
   219 // ---------------------------------------------------------
       
   220 //
       
   221 const TDesC& CCARecordedChatsArrayPC::Name( TInt aIndex ) const
       
   222     {
       
   223     return iLoggerHeadersInterface.Name( aIndex );
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CCARecordedChatsPC::ChatType
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 TEnumsPC::TChatType CCARecordedChatsArrayPC::ChatType( TInt aIndex ) const
       
   231     {
       
   232     TEnumsPC::TChatType chatType = TEnumsPC::EUnknownChatType;
       
   233 
       
   234     switch ( iLoggerHeadersInterface.ChatType( aIndex ) )
       
   235         {
       
   236         case EPTOPChat:
       
   237             {
       
   238             chatType = TEnumsPC::EPTOPChat;
       
   239             break;
       
   240             }
       
   241         case EGroupChat:
       
   242             {
       
   243             chatType = TEnumsPC::EGroupChat;
       
   244             break;
       
   245             }
       
   246         default:
       
   247             {
       
   248             chatType = TEnumsPC::EUnknownChatType;
       
   249             }
       
   250         }
       
   251     return chatType;
       
   252     }
       
   253 // -----------------------------------------------------------------------------
       
   254 // CCARecordedChatsArrayPC::StartTime
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 TTime CCARecordedChatsArrayPC::StartTime( TInt aIndex ) const
       
   258     {
       
   259     return iLoggerHeadersInterface.StartTime( aIndex );
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CCARecordedChatsArrayPC::EndTime
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 TTime CCARecordedChatsArrayPC::EndTime( TInt aIndex ) const
       
   267     {
       
   268     return iLoggerHeadersInterface.EndTime( aIndex );
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CCARecordedChatsArrayPC::Identification
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 const TDesC& CCARecordedChatsArrayPC::Identification( TInt aIndex ) const
       
   276     {
       
   277     return iLoggerHeadersInterface.Identification( aIndex );
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // CCARecordedChatsArrayPC::Index
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 TInt CCARecordedChatsArrayPC::Index( const TDesC& aName ) const
       
   285     {
       
   286     return iLoggerHeadersInterface.Index( aName );
       
   287     }
       
   288 //End of File
       
   289