messagingappbase/mce/src/MceDeliveryReportAdapter.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  
       
    15 *     This class formats data from engine to listbox
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <avkon.rsg>
       
    23 #include <MceLogEng.rsg>
       
    24 #include <calslbs.h>  // TextUtils
       
    25 #include <StringLoader.h>
       
    26 
       
    27 #include <featmgr.h>
       
    28 #include <NumberGrouping.h>
       
    29 
       
    30 #include "MceDeliveryReportAdapter.h"
       
    31 #include "MceLogEngine.h"
       
    32 #include "MceUtils.h"
       
    33 
       
    34 // security data caging
       
    35 #include <data_caging_path_literals.hrh>
       
    36 #include <bldvariant.hrh>
       
    37 
       
    38 // CONSTANTS
       
    39 const TInt KTinyBufferLength = 5;
       
    40 const TInt KSmallBufferLength = 30;
       
    41 const TInt KMediumBufferLength = 128;
       
    42 const TInt KLargeBufferLength = 256;
       
    43 const TInt KInitConcItem = 0;
       
    44 const TInt KFirstConcItemPos = 0;
       
    45 const TInt KSecondConcItemPos = 2;
       
    46 const TInt KConcItemLength = 1;
       
    47 const TInt KPhoneNumberMaxLen = 48;
       
    48 const TInt KListBoxCellId = 1;
       
    49 
       
    50 // LOCAL CONSTANTS AND MACROS
       
    51 
       
    52 _LIT( KMceDirAndFile,"mcelogeng.rSC" );
       
    53 
       
    54 _LIT(KSmsEventType, "0\t");
       
    55 _LIT(KMmsEventType, "1\t");
       
    56 _LIT(KTab, "\t");
       
    57 
       
    58 #ifdef RD_MSG_NAVIPANE_IMPROVEMENT
       
    59 _LIT( KSeparator, "  " );
       
    60 #else
       
    61 _LIT( KSeparator, " - " );
       
    62 #endif // RD_MSG_NAVIPANE_IMPROVEMENT
       
    63 // ================= MEMBER FUNCTIONS =======================
       
    64 
       
    65 
       
    66 // Two-phased constructor.
       
    67 CMceDeliveryReportAdapter* CMceDeliveryReportAdapter::NewL
       
    68                             ( CMceLogEngine* aModel,
       
    69                               CEikFormattedCellListBox *aListBox )
       
    70     {
       
    71     CMceDeliveryReportAdapter* self = new( ELeave ) CMceDeliveryReportAdapter( aModel, aListBox );
       
    72     CleanupStack::PushL( self );
       
    73     self->ConstructL();
       
    74     CleanupStack::Pop(self);
       
    75     return self;
       
    76     }
       
    77 
       
    78 // C++ default constructor can NOT contain any code that
       
    79 // might leave.
       
    80 //
       
    81 CMceDeliveryReportAdapter::CMceDeliveryReportAdapter( CMceLogEngine* aModel, 
       
    82                                                       CEikFormattedCellListBox *aListBox  )
       
    83         : iModel( aModel ),        
       
    84         iResourceLoader( *CCoeEnv::Static() ),
       
    85         iListBox( aListBox )
       
    86     {
       
    87     TTime universal;
       
    88     TTime home;
       
    89 
       
    90     universal.UniversalTime();
       
    91     home.HomeTime();
       
    92     TInt err = home.MinutesFrom( universal, iInterval );
       
    93 
       
    94     if( err )
       
    95         {
       
    96         iInterval = 0;
       
    97         }
       
    98     }
       
    99 
       
   100 // Symbian OS default constructor can leave.
       
   101 void CMceDeliveryReportAdapter::ConstructL()
       
   102     {
       
   103     // security data caging
       
   104     TParse fp;
       
   105     fp.Set( KMceDirAndFile, &KDC_APP_RESOURCE_DIR , NULL );
       
   106     TFileName filename = fp.FullName();
       
   107 
       
   108     iResourceLoader.OpenL( filename );
       
   109     CEikonEnv* env = CEikonEnv::Static();
       
   110 
       
   111     iBuffer = HBufC::NewL( KLargeBufferLength );
       
   112     iTimeText = HBufC::NewL( KMediumBufferLength );
       
   113     iPendingText = env->AllocReadResourceL( R_MCE_LOG_ENG_PENDING_TEXT );
       
   114     iRead = env->AllocReadResourceL( R_MCE_LOG_ENG_READ_TEXT );  
       
   115     iFailedText = env->AllocReadResourceL( R_MCE_LOG_ENG_FAILED_TEXT );
       
   116     iDeliveredText = env->AllocReadResourceL( R_MCE_LOG_ENG_DELIVERED_TEXT );
       
   117     iTimeFormat = env->AllocReadResourceL( R_QTN_TIME_USUAL_WITH_ZERO );
       
   118     
       
   119 #ifdef RD_MSG_NAVIPANE_IMPROVEMENT    
       
   120     iTimeDateFormat = env->AllocReadResourceL( R_QTN_DATE_WITHOUT_YEAR_WITH_ZERO );
       
   121 #else
       
   122     iTimeDateFormat = env->AllocReadResourceL( R_QTN_DATE_SHORT_WITH_ZERO );
       
   123 #endif // RD_MSG_NAVIPANE_IMPROVEMENT
       
   124 
       
   125     iModel->GetStandardStrings( iFailed, iPending );
       
   126 
       
   127     iConcItems = new( ELeave ) CArrayFixFlat<TInt>( 1 );
       
   128     iConcItems->AppendL( KInitConcItem );
       
   129     iConcItems->AppendL( KInitConcItem );
       
   130 
       
   131     iConcText = StringLoader::LoadL( R_MCE_LOG_ENG_CONCATENATED_TEXT,
       
   132                                             *iConcItems );
       
   133 
       
   134     // CenRep key KCRUidNumberGrouping / KNumberGrouping is used to check if
       
   135     // number grouping is supported
       
   136     if( AknLayoutUtils::LayoutMirrored() || MceUtils::NumberGroupingEnabled() )
       
   137         {
       
   138         iNumberGrouping = CPNGNumberGrouping::NewL( KPhoneNumberMaxLen );
       
   139         }
       
   140     }
       
   141 
       
   142     
       
   143 // Destructor
       
   144 CMceDeliveryReportAdapter::~CMceDeliveryReportAdapter()
       
   145     {
       
   146     delete iBuffer;
       
   147     delete iPendingText;
       
   148     delete iFailedText;
       
   149     delete iDeliveredText;
       
   150     delete iTimeFormat;
       
   151     delete iTimeDateFormat;
       
   152     delete iTimeText;
       
   153     delete iConcItems;
       
   154     delete iConcText;   
       
   155     delete iRead;   
       
   156     iResourceLoader.Close();
       
   157 
       
   158     delete iNumberGrouping;
       
   159     }
       
   160 
       
   161 
       
   162 // from MDesCArray
       
   163 TInt  CMceDeliveryReportAdapter::MdcaCount () const 
       
   164     {
       
   165     return iModel->Count();
       
   166     }
       
   167     
       
   168 // from MDesCArray  
       
   169 TPtrC16  CMceDeliveryReportAdapter::MdcaPoint( TInt aIndex ) const
       
   170     {
       
   171     TPtr des = iBuffer->Des();
       
   172     /// Double Graphics Style " <SMS/MMS 0/1> \t<Remote Party>\t<time>" - "<Status>" 
       
   173         
       
   174     const CLogEvent* event = iModel->Event( aIndex );
       
   175     
       
   176     /// Event type ICON index
       
   177     if( event->EventType() == KLogShortMessageEventTypeUid )
       
   178         {
       
   179         des.Format( KSmsEventType );
       
   180         }
       
   181     else
       
   182         {
       
   183         des.Format( KMmsEventType );
       
   184         }
       
   185 
       
   186     // If there is a "name" then we show it.
       
   187     if( event->RemoteParty().Length() &&
       
   188        ( event->RemoteParty() != event->Number() ) ) 
       
   189         {
       
   190         des.Append( event->RemoteParty() );
       
   191         }
       
   192     else
       
   193         {
       
   194         if( iNumberGrouping )
       
   195             {
       
   196             if( event->Number().Length() <= iNumberGrouping->MaxDisplayLength() )
       
   197                 {
       
   198                 iNumberGrouping->Set( event->Number() );
       
   199                 TBuf<KMediumBufferLength> buf( iNumberGrouping->FormattedNumber() );
       
   200                 AknTextUtils::ClipToFit
       
   201                                 (   buf
       
   202                                 ,   AknTextUtils::EClipFromBeginning
       
   203                                 ,   iListBox
       
   204                                 ,   aIndex
       
   205                                 ,   KListBoxCellId
       
   206                                 );
       
   207                 // Arabic & Hebrew conversion if needed.
       
   208                 AknTextUtils::LanguageSpecificNumberConversion( buf ); 
       
   209                 des.Append( buf );
       
   210                 }
       
   211             else
       
   212                 {
       
   213                 TBuf<KMediumBufferLength> buf( event->Number() );
       
   214                 // Arabic & Hebrew conversion if needed.
       
   215                 AknTextUtils::LanguageSpecificNumberConversion( buf ); 
       
   216                 des.Append( buf );
       
   217                 }
       
   218             }
       
   219         else
       
   220             {
       
   221             TBuf<KMediumBufferLength> buf(event->Number());
       
   222             AknTextUtils::ClipToFit
       
   223                                 (   buf
       
   224                                 ,   AknTextUtils::EClipFromBeginning
       
   225                                 ,   iListBox
       
   226                                 ,   aIndex
       
   227                                 ,   KListBoxCellId
       
   228                                 );
       
   229             // Arabic & Hebrew conversion if needed.
       
   230             AknTextUtils::LanguageSpecificNumberConversion( buf ); 
       
   231             des.Append( buf );
       
   232             }
       
   233         }
       
   234 
       
   235     des.Append(KTab);
       
   236     TTime currentTime;
       
   237     currentTime.HomeTime();
       
   238 
       
   239     TTime time( event->Time() + iInterval );
       
   240     TPtr timePtr = iTimeText->Des();
       
   241 
       
   242     TTimeIntervalHours timeDiff;
       
   243     currentTime.HoursFrom( time, timeDiff );
       
   244 
       
   245     HBufC* tmpTimeFormat;
       
   246     if( currentTime.DayNoInYear() != time.DayNoInYear() )
       
   247         {
       
   248         tmpTimeFormat = iTimeDateFormat;
       
   249         }
       
   250     else 
       
   251         {
       
   252         tmpTimeFormat = iTimeFormat;
       
   253         }
       
   254     TRAPD( err, time.FormatL( timePtr, *tmpTimeFormat ) );
       
   255     if( err == KErrNone )
       
   256         {
       
   257         AknTextUtils::LanguageSpecificNumberConversion( timePtr ); 
       
   258         des.Append( timePtr );
       
   259         }
       
   260     des.Append( KSeparator );
       
   261 
       
   262     if( event->Status() == iPending )
       
   263         {
       
   264         if( iModel->PurgeData( event, iConcItems ) > 1 )
       
   265             {            
       
   266             TBuf<KSmallBufferLength> numBuf;
       
   267             TBuf<KTinyBufferLength> item;
       
   268 
       
   269             numBuf.Copy( *iConcText );
       
   270             item.Num( iConcItems->At( 1 ) );
       
   271             numBuf.Replace( KSecondConcItemPos, KConcItemLength, item );
       
   272             item.Num( iConcItems->At( 0 ) );
       
   273             numBuf.Replace( KFirstConcItemPos, KConcItemLength, item );
       
   274             des.Append( numBuf );
       
   275             }
       
   276         des.Append( *iPendingText );
       
   277         }
       
   278     else if( event->Status() == iFailed )
       
   279         {
       
   280         des.Append( *iFailedText );
       
   281         }       
       
   282     else if( event->Status() == KLogsMsgReadText )  
       
   283         {
       
   284         des.Append( *iRead );
       
   285         }       
       
   286     else
       
   287         {
       
   288         des.Append( *iDeliveredText );
       
   289         }
       
   290        
       
   291     return iBuffer->Des();
       
   292     }
       
   293 
       
   294 //  End of File