browserutilities/browserdialogsprovider/Src/BrowserUploadProgressNote.cpp
changeset 0 dd21522fd290
child 25 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     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 the License "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 creates a progress dialog, which shows the progress of an upload
       
    16 *     
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 #include "BrowserUploadProgressNote.h"
       
    23 #include "BrowserDialogsProviderObserver.h"
       
    24 
       
    25 #include <BrowserDialogsProvider.rsg>
       
    26 #include <StringLoader.h>
       
    27 
       
    28 // ----------------------------------------------------------------------------
       
    29 // CBrowserUploadProgressNote::CBrowserUploadProgressNote
       
    30 // ----------------------------------------------------------------------------
       
    31 //
       
    32 CBrowserUploadProgressNote::CBrowserUploadProgressNote( 
       
    33                             TInt aMaxValue,
       
    34                             MBrowserDialogsProviderObserver* aObserver,
       
    35                             CEikDialog** aSelfPtr ) :
       
    36     CAknProgressDialog( aSelfPtr, ETrue ), // should use EFalse, but doesn't work!
       
    37     iMaxValue( aMaxValue ),
       
    38     iObserver( aObserver )
       
    39     {
       
    40     }
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // CBrowserUploadProgressNote::~CBrowserUploadProgressNote
       
    44 // ----------------------------------------------------------------------------
       
    45 //
       
    46 CBrowserUploadProgressNote::~CBrowserUploadProgressNote( )
       
    47     {
       
    48 	delete iStrUploaded;
       
    49 	delete iStrUnit;
       
    50     }
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CBrowserUploadProgressNote::NewL
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 CBrowserUploadProgressNote* CBrowserUploadProgressNote::NewL( 
       
    57                             TInt aMaxValue,
       
    58                             MBrowserDialogsProviderObserver* aObserver,
       
    59                             CEikDialog** aSelfPtr )
       
    60     {
       
    61     CBrowserUploadProgressNote* self = NewLC( aMaxValue, aObserver, aSelfPtr );
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // CBrowserUploadProgressNote::NewLC
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 CBrowserUploadProgressNote* CBrowserUploadProgressNote::NewLC( 
       
    71                             TInt aMaxValue,
       
    72                             MBrowserDialogsProviderObserver* aObserver,
       
    73                             CEikDialog** aSelfPtr )
       
    74     {	
       
    75     CBrowserUploadProgressNote* self = 
       
    76                             new ( ELeave ) CBrowserUploadProgressNote( 
       
    77                             aMaxValue, aObserver, aSelfPtr );
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL( );
       
    80     return self;	
       
    81     }
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CBrowserUploadProgressNote::UpdateL
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 void CBrowserUploadProgressNote::UpdateL( TInt aChunkSize )
       
    88 	{ 
       
    89     iUploaded+=aChunkSize; // Set the uploaded size.
       
    90 
       
    91     // ...Length() + 20 because if we substitute the uploaded, 
       
    92     // and the max upload strings into the
       
    93     // "Uploaded:\ %U / %U" string, there should be enough space in the buffer.
       
    94     // The max length of the substituted strings is not more than 8 characters, 
       
    95     // so 20 characters should be enough, and won`t cause errors, if the size 
       
    96     // of the substituted strings slightly changes.
       
    97 	TInt length = iStrUploaded->Des( ).Length() + iStrUnit->Des().Length() + 20;
       
    98 
       
    99     // The final string that will be displayed on the progress note.
       
   100 	HBufC* progressNoteText = HBufC::NewLC( length );
       
   101 
       
   102     // Temporary buffer for formatting.
       
   103     HBufC* tempProgressNoteText = HBufC::NewLC( length );
       
   104 
       
   105     // Temporary pointer needed, for using StringLoader::Format.
       
   106     TPtr progressNoteTextPtr = progressNoteText->Des();
       
   107 
       
   108 	// If we are showing data in kB Units.
       
   109 	if ( iMaxValue < 1000 )
       
   110 		{
       
   111         // Convert the uploaded, and max upload size to string.
       
   112         TBuf<3> strMax,strUploaded;
       
   113         strMax.AppendNum( iMaxValue );
       
   114         strUploaded.AppendNum( iUploaded );
       
   115         
       
   116         // Substitute the first index in the string from .loc file.
       
   117         StringLoader::Format( progressNoteTextPtr,iStrUploaded->Des(),
       
   118                                                                 0,strUploaded );
       
   119 
       
   120         // Substitute the second index in the string from .loc file.
       
   121         tempProgressNoteText->Des( ).Copy( progressNoteTextPtr ); // Copy to a temporary buffer.
       
   122         // Format and put the fully formatted string into progressNoteText
       
   123         StringLoader::Format( progressNoteTextPtr,tempProgressNoteText->Des(),
       
   124                                                                     1,strMax );
       
   125         }
       
   126 	// If we are showing data in MB Units.
       
   127 	else 
       
   128 		{
       
   129         // Convert the uploaded, and max upload size to MB units.
       
   130 		HBufC* strMax = DivisionL( iMaxValue,1000 );
       
   131         CleanupStack::PushL( strMax );
       
   132 		HBufC* strUploaded = DivisionL( iUploaded,1000 );
       
   133         CleanupStack::PushL( strUploaded );
       
   134 
       
   135         // Substitute the first index in the string from .loc file.
       
   136         StringLoader::Format( progressNoteTextPtr,iStrUploaded->Des(),
       
   137                                                         0,strUploaded->Des() );
       
   138 
       
   139         // Substitute the second index in the string from .loc file.
       
   140         tempProgressNoteText->Des().Copy( progressNoteTextPtr ); // Copy to a temporary buffer.
       
   141         // Format and put the fully formatted string into progressNoteText
       
   142         StringLoader::Format( progressNoteTextPtr,tempProgressNoteText->Des(),
       
   143                                                             1,strMax->Des() );
       
   144 
       
   145 		CleanupStack::PopAndDestroy( 2 ); // strMax, struploaded
       
   146 		}
       
   147 
       
   148     progressNoteText->Des().Append( iStrUnit->Des() ); // Append the unit.        
       
   149 	/*iProgressDlg->*/SetTextL( progressNoteText->Des() ); // Set the text of the note.
       
   150 	iProgressInfo->SetAndDraw( iUploaded ); 
       
   151     CleanupStack::PopAndDestroy( 2 ); //progressNoteText, tempProgressNoteText
       
   152 	}
       
   153 
       
   154 
       
   155 // ----------------------------------------------------------------------------
       
   156 // CBrowserUploadProgressNote::ConstructL
       
   157 // ----------------------------------------------------------------------------
       
   158 //
       
   159 void CBrowserUploadProgressNote::ConstructL( )
       
   160     {
       
   161     // TO DO: Param should be EFalse, but it fails....
       
   162 	/*iProgressDlg = new( ELeave ) CAknProgressDialog( 
       
   163                         ( REINTERPRET_CAST ( CEikDialog**, &iProgressDlg) ), ETrue );*/
       
   164 	
       
   165     iStrUploaded = StringLoader::LoadL( 
       
   166                                 R_QTN_BROWSER_UPLOAD_PROGRESSNOTE_UPLOADED );
       
   167 
       
   168     // If "kB" unit is needed...
       
   169 	if ( iMaxValue<1000 )
       
   170 		{
       
   171 		iStrUnit = CCoeEnv::Static()->AllocReadResourceL( 
       
   172                                 R_QTN_BROWSER_UPLOAD_PROGRESSNOTE_UNIT_KBYTE );
       
   173 		}
       
   174 	else
       
   175 		{
       
   176 		iStrUnit = CCoeEnv::Static()->AllocReadResourceL( 
       
   177                                 R_QTN_BROWSER_UPLOAD_PROGRESSNOTE_UNIT_MB );
       
   178 		}
       
   179 
       
   180 	PrepareLC( R_UPLOAD_PROGRESSNOTE );
       
   181     
       
   182     iProgressInfo = GetProgressInfoL( );
       
   183 	iProgressInfo->SetFinalValue( iMaxValue );
       
   184 	
       
   185 	// Set callback for when dialog is dismissed, handled in DialogDismissedL()
       
   186 	SetCallback( this );
       
   187 	
       
   188 	// Show the dialog
       
   189 	RunLD();
       
   190     }
       
   191 
       
   192 // ----------------------------------------------------------------------------
       
   193 // CBrowserUploadProgressNote::DivisionL
       
   194 // ----------------------------------------------------------------------------
       
   195 //
       
   196 HBufC* CBrowserUploadProgressNote::DivisionL( TInt aNumerator,TInt aDenominator )
       
   197 	{
       
   198     TLocale locale;
       
   199 	TInt reminder = aNumerator%aDenominator;
       
   200     // Temporary buffer for the result of the division.
       
   201 	HBufC* tempString = HBufC::NewLC( 50 );
       
   202 
       
   203     // Copy the integer part of the division.
       
   204 	tempString->Des().AppendNum( aNumerator / aDenominator );
       
   205     //Copy the decimal separator.
       
   206     tempString->Des().Append( locale.DecimalSeparator() );
       
   207  
       
   208     // Copy the fraction part, we need 3 decimal fractions.
       
   209     // Example: 2.00 or 3.50...
       
   210     for ( TInt i=0;i<3;i++ )
       
   211         {
       
   212         TInt newReminder = ( reminder * 10 ) % aDenominator;
       
   213         reminder = ( reminder * 10 ) / aDenominator;
       
   214         tempString->Des().AppendNum( reminder );
       
   215         reminder = newReminder;
       
   216         }
       
   217 
       
   218     HBufC* returnString = HBufC::NewLC( 4 );
       
   219 
       
   220     // Only 3 numbers needed in the string. So, if the integer part is bigger
       
   221     // than 99.9, we chop the reminder part...
       
   222     // Example 100.342 will be 100 , 158.654 will be 158, 
       
   223     // because of the specification.
       
   224 
       
   225     //If the integer value is bigger than 99, then chop...
       
   226     if ( ( TChar )tempString->Des()[3] == locale.DecimalSeparator() )
       
   227         {
       
   228         returnString->Des().Copy( tempString->Des().Left( 3 ) );
       
   229         }
       
   230     // Or simply copy to the result...
       
   231     else
       
   232         {
       
   233         returnString->Des().Copy( tempString->Des().Left( 4 ) );
       
   234         }
       
   235 
       
   236     CleanupStack::Pop(); // returnString
       
   237     CleanupStack::PopAndDestroy(); // tempString
       
   238     return returnString;
       
   239 	}
       
   240 
       
   241 // ----------------------------------------------------------------------------
       
   242 // CBrowserUploadProgressNote::DialogDismissedL
       
   243 // ----------------------------------------------------------------------------
       
   244 //
       
   245 void CBrowserUploadProgressNote::DialogDismissedL( TInt aButtonId )
       
   246     {
       
   247     if ( aButtonId == EAknSoftkeyCancel )
       
   248         {
       
   249         if ( iObserver )
       
   250             {
       
   251             // Indicate to observer that the dialog is now dismissed
       
   252             iObserver->ReportDialogEventL( 
       
   253                 MBrowserDialogsProviderObserver::EUploadProgress, KErrCancel );
       
   254             }
       
   255         }
       
   256     }
       
   257 
       
   258 //  END OF FILE