iaupdate/IAD/ui/src/iaupdatedetailsdialog.cpp
branchRCL_3
changeset 26 8b7f4e561641
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
       
     1 /*
       
     2 * Copyright (c) 2008-2010 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 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "iaupdatedetailsdialog.h"
       
    23 #include "iaupdatedialogutil.h"
       
    24 #include "iaupdatebasenode.h"
       
    25 #include "iaupdatenode.h"  
       
    26 #include "iaupdatedebug.h"
       
    27 #include <iaupdate.rsg>
       
    28 
       
    29 #include <aknmessagequerydialog.h>      // CAknMessageQueryDialog
       
    30 
       
    31 #include <StringLoader.h>
       
    32 
       
    33 // CONSTANTS
       
    34 const TInt KKiloByte = 1024;
       
    35 const TInt KMegaByte = 1024 * 1024;
       
    36 const TInt KMaxShownInKiloBytes = 10 * KMegaByte;
       
    37 
       
    38 
       
    39 /*******************************************************************************
       
    40  * class CIAUpdateDetailsDialog
       
    41  *******************************************************************************/
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CIAUpdateDetailsDialog::ShowDialogL
       
    46 // 
       
    47 // -----------------------------------------------------------------------------
       
    48 TBool CIAUpdateDetailsDialog::ShowDialogL( TIAUpdateDialogParam* aParam )
       
    49 	{
       
    50 	CIAUpdateDetailsDialog* dialog = CIAUpdateDetailsDialog::NewL( aParam );
       
    51 	CleanupStack::PushL( dialog );
       
    52 
       
    53 	dialog->ShowDialogL();
       
    54 
       
    55 	CleanupStack::PopAndDestroy( dialog );
       
    56     
       
    57     return ETrue;
       
    58 	}
       
    59 
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CIAUpdateDetailsDialog::NewL
       
    63 //
       
    64 // -----------------------------------------------------------------------------
       
    65 CIAUpdateDetailsDialog* CIAUpdateDetailsDialog::NewL( TIAUpdateDialogParam* aParam )
       
    66     {
       
    67     CIAUpdateDetailsDialog* self = new ( ELeave ) CIAUpdateDetailsDialog( aParam );
       
    68     CleanupStack::PushL( self );
       
    69     self->ConstructL();
       
    70     CleanupStack::Pop( self );
       
    71 
       
    72     return self;
       
    73     }
       
    74 
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CIAUpdateDetailsDialog::CIAUpdateDetailsDialog
       
    78 // 
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CIAUpdateDetailsDialog::CIAUpdateDetailsDialog( TIAUpdateDialogParam* aParam )
       
    82 	{
       
    83 	iParam = aParam;
       
    84     }
       
    85 
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CIAUpdateDetailsDialog::ConstructL
       
    89 //
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CIAUpdateDetailsDialog::ConstructL()
       
    93     {
       
    94     if ( !iParam->iNode )
       
    95         {
       
    96     	User::Leave( KErrNotFound );
       
    97         }
       
    98         
       
    99     TInt size = BufferSize();
       
   100 
       
   101  	iBuf = HBufC::NewL( size );
       
   102     } 
       
   103 
       
   104 
       
   105 
       
   106 // ----------------------------------------------------------------------------
       
   107 // Destructor
       
   108 //
       
   109 // ----------------------------------------------------------------------------
       
   110 //
       
   111 CIAUpdateDetailsDialog::~CIAUpdateDetailsDialog()
       
   112     {
       
   113     delete iBuf;
       
   114     }
       
   115 
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CIAUpdateDetailsDialog::BufferSize
       
   119 //
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 TInt CIAUpdateDetailsDialog::BufferSize()
       
   123     {
       
   124     const TInt KExtraSize = 512;
       
   125     
       
   126     TPtrC ptr1 = iParam->iNode->Base().Name();
       
   127     TPtrC ptr2 = iParam->iNode->Base().Description();
       
   128     
       
   129     TInt len = ptr1.Length() + ptr2.Length() + KExtraSize;
       
   130     
       
   131     return len;
       
   132     } 
       
   133 
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CIAUpdateDetailsDialog::ConstructTextL
       
   137 //
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CIAUpdateDetailsDialog::ConstructTextL()
       
   141     {
       
   142     _LIT(KNewLine, "\n");
       
   143 
       
   144     TPtr ptr = iBuf->Des();
       
   145     
       
   146     TPtrC name =         iParam->iNode->Base().Name();
       
   147     TPtrC description =  iParam->iNode->Base().Description();
       
   148     TIAUpdateVersion version = iParam->iNode->Base().Version();
       
   149     TInt contentSize =   iParam->iNode->Base().ContentSizeL();
       
   150     
       
   151     
       
   152     HBufC* hBuf = StringLoader::LoadLC( R_IAUPDATE_DETAILS_DIALOG_APP_NAME );
       
   153     ptr.Append( KOpeningBoldTag );
       
   154     ptr.Append( *hBuf );
       
   155     ptr.Append( KClosingBoldTag );
       
   156     CleanupStack::PopAndDestroy( hBuf );
       
   157     
       
   158     ptr.Append( KNewLine );
       
   159     ptr.Append( name );
       
   160     ptr.Append( KNewLine );
       
   161     ptr.Append( KNewLine );
       
   162        
       
   163     hBuf = StringLoader::LoadLC( R_IAUPDATE_DETAILS_DIALOG_DESCRIPTION );
       
   164     ptr.Append( KOpeningBoldTag );
       
   165     ptr.Append( *hBuf );
       
   166     ptr.Append( KClosingBoldTag );
       
   167     CleanupStack::PopAndDestroy( hBuf );
       
   168     
       
   169     ptr.Append( KNewLine );
       
   170     ptr.Append( description );
       
   171     ptr.Append( KNewLine );
       
   172     ptr.Append( KNewLine );
       
   173     
       
   174     
       
   175     if( iParam->iNode->Type() != MIAUpdateNode::EPackageTypeServicePack )
       
   176         {
       
   177         hBuf = StringLoader::LoadLC( R_IAUPDATE_DETAILS_DIALOG_VERSION );
       
   178         ptr.Append( KOpeningBoldTag );
       
   179         ptr.Append( *hBuf );
       
   180         ptr.Append( KClosingBoldTag );
       
   181         CleanupStack::PopAndDestroy( hBuf );
       
   182         
       
   183         ptr.Append( KNewLine );
       
   184         hBuf = VersionTextLC( version );
       
   185         ptr.Append( *hBuf );
       
   186         ptr.Append( KNewLine );
       
   187         ptr.Append( KNewLine );
       
   188         CleanupStack::PopAndDestroy( hBuf );
       
   189         }
       
   190    
       
   191     
       
   192     hBuf = StringLoader::LoadLC( R_IAUPDATE_DETAILS_DIALOG_FILE_SIZE );
       
   193     ptr.Append( KOpeningBoldTag );
       
   194     ptr.Append( *hBuf );
       
   195     ptr.Append( KClosingBoldTag );
       
   196     CleanupStack::PopAndDestroy( hBuf );
       
   197     
       
   198     ptr.Append( KNewLine );
       
   199     
       
   200     hBuf = FileSizeTextLC( contentSize );
       
   201     ptr.Append( *hBuf );
       
   202     CleanupStack::PopAndDestroy( hBuf );
       
   203     } 
       
   204 
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CIAUpdateDetailsDialog::ShowDialogL
       
   208 // 
       
   209 // -----------------------------------------------------------------------------
       
   210 TBool CIAUpdateDetailsDialog::ShowDialogL()
       
   211 	{
       
   212 	ConstructTextL();
       
   213 
       
   214 	HBufC* hBuf = StringLoader::LoadLC( R_IAUPDATE_DETAILS_DIALOG_TITLE );
       
   215 	IAUpdateDialogUtil::ShowMessageQueryL( *hBuf, *iBuf );
       
   216 	CleanupStack::PopAndDestroy( hBuf );
       
   217     
       
   218     return ETrue;
       
   219 	}
       
   220 
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CIAUpdateDetailsDialog::FileSizeTextLC
       
   224 // 
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 HBufC* CIAUpdateDetailsDialog::FileSizeTextLC( TInt aFileSize )
       
   228 	{
       
   229     TInt resourceId = 0;
       
   230 	TInt size = 0;
       
   231 	
       
   232 	if ( aFileSize >= KMaxShownInKiloBytes )
       
   233 	    {
       
   234 	    resourceId = R_IAUPDATE_DETAILS_DIALOG_SIZE_MEGABYTE;
       
   235 	    size = aFileSize / KMegaByte;
       
   236    	    if ( aFileSize % KMegaByte != 0 )
       
   237 	        {
       
   238 	        size++;
       
   239 	        }
       
   240 	    }
       
   241 	else
       
   242 	    {
       
   243 	    resourceId = R_IAUPDATE_DETAILS_DIALOG_SIZE_KILOBYTE;
       
   244 	    size = aFileSize / KKiloByte;
       
   245    	    if ( aFileSize % KKiloByte != 0 )
       
   246 	        {
       
   247 	        size++;
       
   248 	        }	
       
   249 	    }
       
   250 	    
       
   251 	HBufC* sizeAsString = StringLoader::LoadLC( resourceId, size );
       
   252 	TPtr ptr = sizeAsString->Des();
       
   253     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr ); 
       
   254     return sizeAsString;
       
   255 	}
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CIAUpdateDetailsDialog::VersionTextLC
       
   259 // 
       
   260 // Version format is '%1N.%2N(%3N)' where
       
   261 //
       
   262 // %0N is major version number
       
   263 // %1N is minor version number
       
   264 // %2N is build number
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 HBufC* CIAUpdateDetailsDialog::VersionTextLC( TIAUpdateVersion aVersion )
       
   268     {
       
   269     const TInt KVersionSize = 64;
       
   270     
       
   271     TInt major = aVersion.iMajor;
       
   272     TInt minor = aVersion.iMinor;
       
   273     TInt build = aVersion.iBuild;
       
   274     
       
   275     TBuf<KVersionSize> buf1;
       
   276     TBuf<KVersionSize> buf2;
       
   277     
       
   278     HBufC* hBuf   = HBufC::NewLC( KVersionSize );
       
   279     TPtr ptr = hBuf->Des();
       
   280     
       
   281     HBufC* versionFormat = 
       
   282     StringLoader::LoadLC( R_IAUPDATE_DETAILS_DIALOG_VERSION_FORMAT );
       
   283    
       
   284     // replace  %0N with major number
       
   285     StringLoader::Format( buf1, versionFormat->Des(), 0, major );
       
   286     
       
   287     // replace  %1N with minor number
       
   288     StringLoader::Format( buf2, buf1, 1, minor );
       
   289 
       
   290     // replace  %2N with build number
       
   291     StringLoader::Format( ptr, buf2, 2, build );
       
   292 
       
   293     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );
       
   294     
       
   295     CleanupStack::PopAndDestroy( versionFormat );
       
   296     
       
   297     return hBuf;
       
   298     }
       
   299 
       
   300    
       
   301 //  End of File