meetingrequest/mrgui/mrfieldbuildercommon/src/cmrattachmentprogressinfo.cpp
branchRCL_3
changeset 12 4ce476e64c59
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
       
     1 /*
       
     2 * Copyright (c) 2009 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: Attachment progress info
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cmrattachmentprogressinfo.h"
       
    19 
       
    20 #include <esmrgui.rsg>
       
    21 #include <eikprogi.h>
       
    22 #include <aknwaitdialog.h> 
       
    23 #include <stringloader.h>
       
    24 
       
    25 // Unnamed namespace for local definitions
       
    26 namespace { // codescanner::namespace
       
    27 
       
    28 const TInt KOneKiloByte( 1024 );
       
    29 const TInt KOneMegaByte( 1048576 ); // (1024^2 or 2^20):
       
    30 
       
    31 }//namespace
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CMRAttachmentProgressInfo::NewL
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CMRAttachmentProgressInfo* CMRAttachmentProgressInfo::NewL(
       
    38 		CMRFileManager& aFileMan, MProgressDialogCallback& aObserver )
       
    39 	{
       
    40 	CMRAttachmentProgressInfo* self =
       
    41 			new (ELeave) CMRAttachmentProgressInfo( aFileMan, aObserver );
       
    42 	return self;
       
    43 	}
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CMRAttachmentProgressInfo::CMRAttachmentProgressInfo
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CMRAttachmentProgressInfo::CMRAttachmentProgressInfo(
       
    50 		CMRFileManager& aFileMan, MProgressDialogCallback& aObserver  )
       
    51 : iFileMan( aFileMan ), iObserver( aObserver )
       
    52 	{
       
    53 	}
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CMRAttachmentProgressInfo::~CMRAttachmentProgressInfo
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CMRAttachmentProgressInfo::~CMRAttachmentProgressInfo()
       
    60 	{
       
    61 	if( iProgressDialog )
       
    62 		{
       
    63 		// We cannot do anything for an error at this point
       
    64 		TRAP_IGNORE( iProgressDialog->ProcessFinishedL() ); 
       
    65 		}
       
    66 	delete iAsynCallBack;
       
    67 	}
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CMRAttachmentProgressInfo::StopL
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 void CMRAttachmentProgressInfo::StopL()
       
    74 	{
       
    75 	iProgressDialog->ProcessFinishedL();
       
    76 	}
       
    77  
       
    78 // ---------------------------------------------------------------------------
       
    79 // CMRAttachmentProgressInfo::StartProgressNoteL
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 void CMRAttachmentProgressInfo::StartProgressNoteL(TInt aFinalValue)	
       
    83 	{
       
    84 	iAttachmentSize = aFinalValue;
       
    85 	
       
    86 	iProgressDialog = new (ELeave) CAknProgressDialog(
       
    87 			(REINTERPRET_CAST(CEikDialog**, &iProgressDialog)),
       
    88 			ETrue);
       
    89 	iProgressDialog->PrepareLC(R_ATTACHMENT_PROGRESS_NOTE);
       
    90 	iProgressInfo = iProgressDialog->GetProgressInfoL();
       
    91 	iProgressDialog->SetCallback(this);
       
    92 	iProgressDialog->RunLD();
       
    93 	iProgressInfo->SetFinalValue(aFinalValue);
       
    94 	}
       
    95  
       
    96 // ---------------------------------------------------------------------------
       
    97 // CMRAttachmentProgressInfo::DialogDismissedL
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CMRAttachmentProgressInfo::DialogDismissedL( TInt aButtonId )
       
   101 	{	
       
   102 	iProgressDialog = NULL;
       
   103 	iProgressInfo = NULL;
       
   104 	if (aButtonId == EAknSoftkeyCancel)
       
   105 		{
       
   106 		  // cancel any process in here
       
   107 		iFileMan.CancelOp();
       
   108 		}
       
   109 
       
   110 	// Notify client asynchronously
       
   111 	if( iAsynCallBack )
       
   112 		{
       
   113 		delete iAsynCallBack;
       
   114 		iAsynCallBack = NULL;
       
   115 		}
       
   116 	TCallBack callback( NotifyObserverCallback, this );
       
   117 	iAsynCallBack = new (ELeave) CAsyncCallBack(
       
   118 	        callback,
       
   119 	        CActive::EPriorityStandard );
       
   120 
       
   121 	// The observer will not be notified if this is not called
       
   122 	iAsynCallBack->CallBack();
       
   123 	}
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CMRAttachmentProgressInfo::NotifyStart
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void CMRAttachmentProgressInfo::NotifyStartL( const TDesC& aFilename )
       
   130 	{
       
   131 	TParse parser;
       
   132 	parser.Set( aFilename , NULL, NULL );
       
   133 	const TDesC& filename = parser.NameAndExt();
       
   134 	
       
   135     HBufC* stringholder;
       
   136 
       
   137     CDesCArrayFlat* attachmentStrings = 
       
   138         new(ELeave)CDesCArrayFlat( 1 );
       
   139     CleanupStack::PushL( attachmentStrings );
       
   140         
       
   141     CArrayFixFlat<TInt>* integers =
       
   142         new (ELeave) CArrayFixFlat<TInt>(1);
       
   143     CleanupStack::PushL( integers );
       
   144     
       
   145 	if ( iAttachmentSize >= KOneMegaByte )
       
   146         {
       
   147         attachmentStrings->AppendL( filename ); 
       
   148 
       
   149         integers->AppendL( iAttachmentSize / KOneMegaByte );
       
   150         
       
   151         stringholder = StringLoader::LoadLC(
       
   152                 R_MEET_REQ_NOTE_ATTACHMENT_PROGRESS_MEGABYTE,
       
   153                 *attachmentStrings,
       
   154                 *integers );
       
   155         }
       
   156     else
       
   157         {
       
   158         attachmentStrings->AppendL( filename ); 
       
   159 
       
   160         integers->AppendL( iAttachmentSize / KOneKiloByte );
       
   161 
       
   162         stringholder = StringLoader::LoadLC(
       
   163                 R_MEET_REQ_NOTE_ATTACHMENT_PROGRESS_KILOBYTE,
       
   164                 *attachmentStrings,
       
   165                 *integers );
       
   166         }
       
   167 
       
   168     iProgressDialog->SetTextProcessing( ETrue );
       
   169     iProgressDialog->SetTextL( *stringholder );
       
   170 
       
   171     CleanupStack::PopAndDestroy( stringholder );
       
   172     CleanupStack::PopAndDestroy( integers );
       
   173     CleanupStack::PopAndDestroy( attachmentStrings );
       
   174 
       
   175 	}
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CMRAttachmentProgressInfo::NotifyProgress
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 void CMRAttachmentProgressInfo::NotifyProgress( TInt aBytesCopied )
       
   182 	{
       
   183 	iBytesTransferred += aBytesCopied;
       
   184 	if(iProgressInfo)
       
   185 		{
       
   186 		iProgressInfo->SetAndDraw(iBytesTransferred);
       
   187 		}
       
   188 	}
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CMRAttachmentProgressInfo::NotifyEnd
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 void CMRAttachmentProgressInfo::NotifyEnd()
       
   195 	{
       
   196 	if( iProgressDialog )
       
   197 		{
       
   198 		// We can't do anything if this leaves
       
   199 		TRAP_IGNORE( iProgressDialog->ProcessFinishedL() );
       
   200 		}
       
   201 	}
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CMRAttachmentProgressInfo::NotifyObserverCallback
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 TInt CMRAttachmentProgressInfo::NotifyObserverCallback( TAny* aThis )
       
   208 	{
       
   209 	(static_cast<CMRAttachmentProgressInfo*>( aThis ))->NotifyObserver();
       
   210 	return 0;
       
   211 	}
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CMRAttachmentProgressInfo::NotifyObserver
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CMRAttachmentProgressInfo::NotifyObserver()
       
   218 	{
       
   219 	// We don't do anything with observer's leaves
       
   220 	TRAP_IGNORE( iObserver.DialogDismissedL( 0 ) );
       
   221 	}
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // CMRAttachmentProgressInfo::NotifyError
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CMRAttachmentProgressInfo::NotifyError( TInt /*aError*/ )
       
   228 	{
       
   229 	NotifyEnd();
       
   230 	}
       
   231 // End of file