pushmtm/MtmUiSrc/PushMessageInfoDialog.cpp
changeset 32 92a061761a7b
parent 0 84ad3b177aa3
child 48 5c11946e75b3
equal deleted inserted replaced
31:868cceedabd3 32:92a061761a7b
    22 #include "PushMessageInfoDialog.h"
    22 #include "PushMessageInfoDialog.h"
    23 #include "PushMtmUiDef.h"
    23 #include "PushMtmUiDef.h"
    24 #include "PushMtmUiPanic.h"
    24 #include "PushMtmUiPanic.h"
    25 #include "PushMtmUtil.h"
    25 #include "PushMtmUtil.h"
    26 #include "PushMtmLog.h"
    26 #include "PushMtmLog.h"
    27 #include <CSIPushMsgEntry.h>
    27 #include <push/CSIPushMsgEntry.h>
    28 #include <CSLPushMsgEntry.h>
    28 #include <push/CSLPushMsgEntry.h>
    29 #include <CUnknownPushMsgEntry.h>
    29 #include <push/CUnknownPushMsgEntry.h>
    30 #include <PushMtmUi.rsg>
    30 #include <PushMtmUi.rsg>
    31 #include <AknLists.h>
    31 #include <AknLists.h>
    32 #include <msvapi.h>
    32 #include <msvapi.h>
    33 #include <e32math.h>
    33 #include <e32math.h>
    34 #include <StringLoader.h>
    34 #include <StringLoader.h>
    54 // ---------------------------------------------------------
    54 // ---------------------------------------------------------
    55 // CPushMessageInfoDialog::CPushMessageInfoDialog
    55 // CPushMessageInfoDialog::CPushMessageInfoDialog
    56 // ---------------------------------------------------------
    56 // ---------------------------------------------------------
    57 //
    57 //
    58 CPushMessageInfoDialog::CPushMessageInfoDialog()
    58 CPushMessageInfoDialog::CPushMessageInfoDialog()
    59 :   CAknPopupList(), 
    59 :   CAknPopupList(),
    60     iResourceLoader( *iCoeEnv )
    60     iResourceLoader( *iCoeEnv )
    61     {
    61     {
    62     }
    62     }
    63 
    63 
    64 // ---------------------------------------------------------
    64 // ---------------------------------------------------------
    90 //
    90 //
    91 void CPushMessageInfoDialog::ConstructL( CMsvSession& aMsvSession, TMsvId aId )
    91 void CPushMessageInfoDialog::ConstructL( CMsvSession& aMsvSession, TMsvId aId )
    92     {
    92     {
    93     PUSHLOG_ENTERFN("CPushMessageInfoDialog::ConstructL");
    93     PUSHLOG_ENTERFN("CPushMessageInfoDialog::ConstructL");
    94 
    94 
    95     __ASSERT_DEBUG( !iListBox && 
    95     __ASSERT_DEBUG( !iListBox &&
    96                     !iListBoxModel, 
    96                     !iListBoxModel,
    97                     UiPanic( EPushMtmUiPanAlreadyInitialized ) );
    97                     UiPanic( EPushMtmUiPanAlreadyInitialized ) );
    98 
    98 
    99     FeatureManager::InitializeLibL();
    99     FeatureManager::InitializeLibL();
   100 
   100 
   101     // Add resource file.
   101     // Add resource file.
   102     TParse* fileParser = new (ELeave) TParse;
   102     TParse* fileParser = new (ELeave) TParse;
   103     // Unnecessary to call CleanupStack::PushL( fileParser );
   103     // Unnecessary to call CleanupStack::PushL( fileParser );
   104     fileParser->Set( KPushMtmUiResourceFileAndDrive, &KDC_MTM_RESOURCE_DIR, NULL ); 
   104     fileParser->Set( KPushMtmUiResourceFileAndDrive, &KDC_MTM_RESOURCE_DIR, NULL );
   105     iResourceFile = fileParser->FullName();
   105     iResourceFile = fileParser->FullName();
   106     PUSHLOG_WRITE_FORMAT(" iResourceFile: <%S>",&iResourceFile);
   106     PUSHLOG_WRITE_FORMAT(" iResourceFile: <%S>",&iResourceFile);
   107     delete fileParser;
   107     delete fileParser;
   108     fileParser = NULL;
   108     fileParser = NULL;
   109     iResourceLoader.OpenL( iResourceFile );
   109     iResourceLoader.OpenL( iResourceFile );
   110     PUSHLOG_WRITE(" iResourceFile opened");
   110     PUSHLOG_WRITE(" iResourceFile opened");
   111 
   111 
   112     // Construct list box's model first
   112     // Construct list box's model first
   113     // This list box will be used by an CAknPopupList object.
   113     // This list box will be used by an CAknPopupList object.
   114     __ASSERT_DEBUG( !iListBoxModel && !iListBox, 
   114     __ASSERT_DEBUG( !iListBoxModel && !iListBox,
   115                     UiPanic( EPushMtmUiPanAlreadyInitialized ) );
   115                     UiPanic( EPushMtmUiPanAlreadyInitialized ) );
   116    	iListBoxModel = new (ELeave) CDesCArrayFlat( KArrayGranularity );
   116    	iListBoxModel = new (ELeave) CDesCArrayFlat( KArrayGranularity );
   117     // Construct list box.
   117     // Construct list box.
   118     iListBox = new (ELeave) CAknSingleHeadingPopupMenuStyleListBox;
   118     iListBox = new (ELeave) CAknSingleHeadingPopupMenuStyleListBox;
   119 
   119 
   120     // ========================================================
   120     // ========================================================
   121     // Layout info of CAknSingleHeadingPopupMenuStyleListBox
   121     // Layout info of CAknSingleHeadingPopupMenuStyleListBox
   122     TAknTextLineLayout textLayout = 
   122     TAknTextLineLayout textLayout =
   123         AknLayout::List_pane_texts__menu_single_heading__Line_2(0);
   123         AknLayout::List_pane_texts__menu_single_heading__Line_2(0);
   124 
   124 
   125     // Font of the second column of the given list box
   125     // Font of the second column of the given list box
   126     iSecondColumnFont = AknLayoutUtils::FontFromId( textLayout.FontId() );
   126     iSecondColumnFont = AknLayoutUtils::FontFromId( textLayout.FontId() );
   127 
   127 
   128     // Line width of the second column of the given list box
   128     // Line width of the second column of the given list box
   129     TInt itemCount = 0; // No need to set
   129     TInt itemCount = 0; // No need to set
   130     TInt titleVisible = 1; // known value (we always have title)
   130     TInt titleVisible = 1; // known value (we always have title)
   131     TRect main_pane = iAvkonAppUi->ClientRect();
   131     TRect main_pane = iAvkonAppUi->ClientRect();
   132  
   132 
   133     TAknLayoutRect popup_menu_graphic_window;
   133     TAknLayoutRect popup_menu_graphic_window;
   134     popup_menu_graphic_window.LayoutRect( main_pane,
   134     popup_menu_graphic_window.LayoutRect( main_pane,
   135         AknLayout::popup_menu_graphic_window(itemCount) );
   135         AknLayout::popup_menu_graphic_window(itemCount) );
   136  
   136 
   137     TAknLayoutRect menu_heading_pane;
   137     TAknLayoutRect menu_heading_pane;
   138     menu_heading_pane.LayoutRect( popup_menu_graphic_window.Rect(),
   138     menu_heading_pane.LayoutRect( popup_menu_graphic_window.Rect(),
   139         AknLayout::list_menu_heading_pane(titleVisible, itemCount) );
   139         AknLayout::list_menu_heading_pane(titleVisible, itemCount) );
   140  
   140 
   141     TAknLayoutRect list_item;
   141     TAknLayoutRect list_item;
   142     list_item.LayoutRect( menu_heading_pane.Rect(),
   142     list_item.LayoutRect( menu_heading_pane.Rect(),
   143         AknLayout::list_single_heading_popup_menu_pane(itemCount) );
   143         AknLayout::list_single_heading_popup_menu_pane(itemCount) );
   144  
   144 
   145     TAknLayoutText text;
   145     TAknLayoutText text;
   146     text.LayoutText( list_item.Rect(), textLayout );
   146     text.LayoutText( list_item.Rect(), textLayout );
   147 
   147 
   148     iSecondColumnWidth = text.TextRect().Width();
   148     iSecondColumnWidth = text.TextRect().Width();
   149     // ========================================================
   149     // ========================================================
   150 
   150 
   151     // Add items to the list.
   151     // Add items to the list.
   152     AddMessageInfoItemsL( aMsvSession, aId );
   152     AddMessageInfoItemsL( aMsvSession, aId );
   153 
   153 
   154     CAknPopupList::ConstructL( iListBox, 
   154     CAknPopupList::ConstructL( iListBox,
   155                                R_AVKON_SOFTKEYS_OK_EMPTY__OK, 
   155                                R_AVKON_SOFTKEYS_OK_EMPTY__OK,
   156                                AknPopupLayouts::EMenuGraphicHeadingWindow );
   156                                AknPopupLayouts::EMenuGraphicHeadingWindow );
   157 
   157 
   158 	iListBox->ConstructL( this, EAknListBoxViewerFlags );
   158 	iListBox->ConstructL( this, EAknListBoxViewerFlags );
   159 	iListBox->CreateScrollBarFrameL( ETrue );
   159 	iListBox->CreateScrollBarFrameL( ETrue );
   160 	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL
   160 	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL
   175 
   175 
   176 // ---------------------------------------------------------
   176 // ---------------------------------------------------------
   177 // CPushMessageInfoDialog::AddMessageInfoItemL
   177 // CPushMessageInfoDialog::AddMessageInfoItemL
   178 // ---------------------------------------------------------
   178 // ---------------------------------------------------------
   179 //
   179 //
   180 void CPushMessageInfoDialog::AddMessageInfoItemL( TInt aHeaderResourceId, 
   180 void CPushMessageInfoDialog::AddMessageInfoItemL( TInt aHeaderResourceId,
   181                                                   const TDesC& aText ) const
   181                                                   const TDesC& aText ) const
   182     {
   182     {
   183     __ASSERT_DEBUG( iListBoxModel, UiPanic( EPushMtmUiPanNotInitialized ) );
   183     __ASSERT_DEBUG( iListBoxModel, UiPanic( EPushMtmUiPanNotInitialized ) );
   184 
   184 
   185     // Make some necessary conversion.
   185     // Make some necessary conversion.
   191     if ( paramTextCopyPtr.Length() > 0 )
   191     if ( paramTextCopyPtr.Length() > 0 )
   192         {
   192         {
   193         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( paramTextCopyPtr );
   193         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( paramTextCopyPtr );
   194         }
   194         }
   195 
   195 
   196     HBufC* header = ( aHeaderResourceId == KNoResource ? 
   196     HBufC* header = ( aHeaderResourceId == KNoResource ?
   197         KNullDesC().AllocLC() : 
   197         KNullDesC().AllocLC() :
   198         iCoeEnv->AllocReadResourceLC( aHeaderResourceId ) );
   198         iCoeEnv->AllocReadResourceLC( aHeaderResourceId ) );
   199 
   199 
   200     CArrayFix<TPtrC>* wrappedArray = 
   200     CArrayFix<TPtrC>* wrappedArray =
   201         new ( ELeave ) CArrayFixFlat<TPtrC>( KArrayGranularity );
   201         new ( ELeave ) CArrayFixFlat<TPtrC>( KArrayGranularity );
   202     CleanupStack::PushL( wrappedArray );
   202     CleanupStack::PushL( wrappedArray );
   203 
   203 
   204     AknTextUtils::WrapToArrayL
   204     AknTextUtils::WrapToArrayL
   205                                 ( paramTextCopyPtr, iSecondColumnWidth, 
   205                                 ( paramTextCopyPtr, iSecondColumnWidth,
   206                                   *iSecondColumnFont, *wrappedArray );
   206                                   *iSecondColumnFont, *wrappedArray );
   207     // visual is directly not used, but wrappedArray points to it
   207     // visual is directly not used, but wrappedArray points to it
   208 
   208 
   209     // Add the lines in wrappedArray to the list
   209     // Add the lines in wrappedArray to the list
   210     const TInt lines = wrappedArray->Count();
   210     const TInt lines = wrappedArray->Count();
   211     for ( TInt loop = 0; loop < lines; ++loop )
   211     for ( TInt loop = 0; loop < lines; ++loop )
   212         {
   212         {
   213         TPtrC current = ( *wrappedArray )[loop];
   213         TPtrC current = ( *wrappedArray )[loop];
   214         // Allocate a buffer for the new list box item text 
   214         // Allocate a buffer for the new list box item text
   215         // (including header, separator and wrapped text)
   215         // (including header, separator and wrapped text)
   216         HBufC* currentFormattedLine = HBufC::NewLC
   216         HBufC* currentFormattedLine = HBufC::NewLC
   217             ( ((loop==0) ? header->Length() : /*KSpace().Length()*/1) + 
   217             ( ((loop==0) ? header->Length() : /*KSpace().Length()*/1) +
   218               /*KTab().Length()*/1 + current.Length() );
   218               /*KTab().Length()*/1 + current.Length() );
   219         TPtr currentFormattedLinePtr = currentFormattedLine->Des(); // writeable
   219         TPtr currentFormattedLinePtr = currentFormattedLine->Des(); // writeable
   220 
   220 
   221         if ( loop == 0 )
   221         if ( loop == 0 )
   222             { currentFormattedLinePtr.Copy( *header ); }
   222             { currentFormattedLinePtr.Copy( *header ); }
   254           TTimeIntervalHours daylightSaving(1);
   254           TTimeIntervalHours daylightSaving(1);
   255           time += daylightSaving;   // Now it is Home Time.
   255           time += daylightSaving;   // Now it is Home Time.
   256           }
   256           }
   257 
   257 
   258 #ifdef __TEST_LOG__
   258 #ifdef __TEST_LOG__
   259         // The following section will call LEAVEable functions, but 
   259         // The following section will call LEAVEable functions, but
   260         // they are only for logging purposes.
   260         // they are only for logging purposes.
   261         _LIT( KDateFormat, "%E%D%X%N%Y %1 %2 %3" );
   261         _LIT( KDateFormat, "%E%D%X%N%Y %1 %2 %3" );
   262         _LIT( KTimeFormat, "%-B%:0%J%:1%T%:2%S%:3%+B" );
   262         _LIT( KTimeFormat, "%-B%:0%J%:1%T%:2%S%:3%+B" );
   263         TBuf<32> dateHolder;
   263         TBuf<32> dateHolder;
   264         TBuf<32> timeHolder;
   264         TBuf<32> timeHolder;
   277 
   277 
   278 // ---------------------------------------------------------
   278 // ---------------------------------------------------------
   279 // CPushMessageInfoDialog::AddMessageInfoItemsL
   279 // CPushMessageInfoDialog::AddMessageInfoItemsL
   280 // ---------------------------------------------------------
   280 // ---------------------------------------------------------
   281 //
   281 //
   282 void CPushMessageInfoDialog::AddMessageInfoItemsL( CMsvSession& aMsvSession, 
   282 void CPushMessageInfoDialog::AddMessageInfoItemsL( CMsvSession& aMsvSession,
   283                                                    TMsvId aId ) const
   283                                                    TMsvId aId ) const
   284     {
   284     {
   285     PUSHLOG_ENTERFN("CPushMessageInfoDialog::AddMessageInfoItemsL");
   285     PUSHLOG_ENTERFN("CPushMessageInfoDialog::AddMessageInfoItemsL");
   286 
   286 
   287     TMsvEntry tEntry;
   287     TMsvEntry tEntry;
   328     // This can be MSISDN number, URL, etc.
   328     // This can be MSISDN number, URL, etc.
   329     // ************************************************************************
   329     // ************************************************************************
   330     TPtrC8 from8( msg->From() );
   330     TPtrC8 from8( msg->From() );
   331     if ( from8.Length() )
   331     if ( from8.Length() )
   332         {
   332         {
   333         // Copy the 8-bit text into a 16-bit one and convert the string to 
   333         // Copy the 8-bit text into a 16-bit one and convert the string to
   334         // decoded form.
   334         // decoded form.
   335         HBufC* from16 = HBufC::NewMaxLC( from8.Length() );
   335         HBufC* from16 = HBufC::NewMaxLC( from8.Length() );
   336         from16->Des().Copy( from8 );
   336         from16->Des().Copy( from8 );
   337 
   337 
   338         HBufC* convertedFrom = 
   338         HBufC* convertedFrom =
   339             CPushMtmUtil::ConvertUriToDisplayFormL( *from16 );
   339             CPushMtmUtil::ConvertUriToDisplayFormL( *from16 );
   340         CleanupStack::PushL( convertedFrom );
   340         CleanupStack::PushL( convertedFrom );
   341         //
   341         //
   342         AddMessageInfoItemL( R_PUSHMID_FROM, *convertedFrom );
   342         AddMessageInfoItemL( R_PUSHMID_FROM, *convertedFrom );
   343         PUSHLOG_WRITE(" From added");
   343         PUSHLOG_WRITE(" From added");
   353         CSIPushMsgEntry* si = STATIC_CAST( CSIPushMsgEntry*, msg );
   353         CSIPushMsgEntry* si = STATIC_CAST( CSIPushMsgEntry*, msg );
   354         const TPtrC url = si->Url();
   354         const TPtrC url = si->Url();
   355         if ( url.Length() )
   355         if ( url.Length() )
   356             {
   356             {
   357             //
   357             //
   358             HBufC* convertedUrl = 
   358             HBufC* convertedUrl =
   359                 CPushMtmUtil::ConvertUriToDisplayFormL( url );
   359                 CPushMtmUtil::ConvertUriToDisplayFormL( url );
   360             CleanupStack::PushL( convertedUrl );
   360             CleanupStack::PushL( convertedUrl );
   361             //
   361             //
   362             AddMessageInfoItemL( R_PUSHMID_URL, *convertedUrl );
   362             AddMessageInfoItemL( R_PUSHMID_URL, *convertedUrl );
   363             PUSHLOG_WRITE(" URL added");
   363             PUSHLOG_WRITE(" URL added");
   371         CSLPushMsgEntry* sl = STATIC_CAST( CSLPushMsgEntry*, msg );
   371         CSLPushMsgEntry* sl = STATIC_CAST( CSLPushMsgEntry*, msg );
   372         const TPtrC url = sl->Url();
   372         const TPtrC url = sl->Url();
   373         if ( url.Length() )
   373         if ( url.Length() )
   374             {
   374             {
   375             //
   375             //
   376             HBufC* convertedUrl = 
   376             HBufC* convertedUrl =
   377                 CPushMtmUtil::ConvertUriToDisplayFormL( url );
   377                 CPushMtmUtil::ConvertUriToDisplayFormL( url );
   378             CleanupStack::PushL( convertedUrl );
   378             CleanupStack::PushL( convertedUrl );
   379             //
   379             //
   380             AddMessageInfoItemL( R_PUSHMID_URL, sl->Url() );
   380             AddMessageInfoItemL( R_PUSHMID_URL, sl->Url() );
   381             PUSHLOG_WRITE(" URL added");
   381             PUSHLOG_WRITE(" URL added");
   424         }
   424         }
   425 #endif // __SERIES60_PUSH_SP
   425 #endif // __SERIES60_PUSH_SP
   426 
   426 
   427     TBuf<32> time;
   427     TBuf<32> time;
   428     TBuf<32> date;
   428     TBuf<32> date;
   429     HBufC* dateFormatString = 
   429     HBufC* dateFormatString =
   430                 iCoeEnv->AllocReadResourceLC( R_QTN_DATE_USUAL_WITH_ZERO );
   430                 iCoeEnv->AllocReadResourceLC( R_QTN_DATE_USUAL_WITH_ZERO );
   431     HBufC* timeFormatString = 
   431     HBufC* timeFormatString =
   432                 iCoeEnv->AllocReadResourceLC( R_QTN_TIME_USUAL_WITH_ZERO );
   432                 iCoeEnv->AllocReadResourceLC( R_QTN_TIME_USUAL_WITH_ZERO );
   433 
   433 
   434     // ************************************************************************
   434     // ************************************************************************
   435     // SI specific information item: creation time and date.
   435     // SI specific information item: creation time and date.
   436     // ************************************************************************
   436     // ************************************************************************
   480             AddMessageInfoItemL( KNoResource, date );
   480             AddMessageInfoItemL( KNoResource, date );
   481             PUSHLOG_WRITE(" Expires added");
   481             PUSHLOG_WRITE(" Expires added");
   482             }
   482             }
   483         }
   483         }
   484 
   484 
   485     CleanupStack::PopAndDestroy( 2, dateFormatString ); 
   485     CleanupStack::PopAndDestroy( 2, dateFormatString );
   486     // timeFormatString, dateFormatString
   486     // timeFormatString, dateFormatString
   487 
   487 
   488     // ************************************************************************
   488     // ************************************************************************
   489     // Information item: Size.
   489     // Information item: Size.
   490     // Convert the message size given in bytes into kilobytes. Round the 
   490     // Convert the message size given in bytes into kilobytes. Round the
   491     // value up, if necessary.
   491     // value up, if necessary.
   492     // ************************************************************************
   492     // ************************************************************************
   493     TReal messageSize( 0 );
   493     TReal messageSize( 0 );
   494     if ( msg->PushMsgType() == KUidWapPushMsgSI.iUid )
   494     if ( msg->PushMsgType() == KUidWapPushMsgSI.iUid )
   495         {
   495         {
   516     User::LeaveIfError( Math::Frac( fraction, messageSize ) );
   516     User::LeaveIfError( Math::Frac( fraction, messageSize ) );
   517     if ( fraction )
   517     if ( fraction )
   518         {
   518         {
   519         ++messageSizeInt;
   519         ++messageSizeInt;
   520         }
   520         }
   521     HBufC* size = 
   521     HBufC* size =
   522         StringLoader::LoadLC( R_QTN_SIZE_KB, messageSizeInt, iCoeEnv );
   522         StringLoader::LoadLC( R_QTN_SIZE_KB, messageSizeInt, iCoeEnv );
   523     // From avkon.loc:
   523     // From avkon.loc:
   524     // #define qtn_size_kb " %N kB"
   524     // #define qtn_size_kb " %N kB"
   525     // We don't need white spaces at the beginning of the size string, so 
   525     // We don't need white spaces at the beginning of the size string, so
   526     // remove them:
   526     // remove them:
   527     size->Des().Trim();
   527     size->Des().Trim();
   528     AddMessageInfoItemL( R_PUSHMID_SIZE, *size );
   528     AddMessageInfoItemL( R_PUSHMID_SIZE, *size );
   529     PUSHLOG_WRITE(" Size added");
   529     PUSHLOG_WRITE(" Size added");
   530     CleanupStack::PopAndDestroy( size ); // size
   530     CleanupStack::PopAndDestroy( size ); // size