email/mail/PluginSrc/MailPlainView/CLoadAttachments.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Loads message attachments 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CLoadAttachments.h"
       
    22 #include "MailLog.h"
       
    23 #include "MailUtils.h"
       
    24 #include "MailLoadStateMachine.h"
       
    25 #include <MailPlainView.rsg>
       
    26 #include <MMailAppUiInterface.h>
       
    27 #include <CMailMessage.h>
       
    28 #include <mmsvattachmentmanager.h>
       
    29 #include <StringLoader.h>
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 /// messages
       
    34 // -----------------------------------------------------------------------------
       
    35 // CLoadAttachments::MessageLoadingL
       
    36 // -----------------------------------------------------------------------------
       
    37 //	
       
    38 void CLoadAttachments::MessageLoadingL(TInt aStatus, CMailMessage& aMessage)
       
    39 	{
       
    40 	if( aStatus == CMailMessage::EAttachmentsReady ) 
       
    41 		{
       
    42 		//Tell that loading of attachments has started
       
    43 		iAppUI->StartWaitNoteL();
       
    44 
       
    45 	    MMsvAttachmentManager& manager = aMessage.AttachmentManager();		
       
    46         TRAPD( err, AddAttachmentsToAppUiL( manager ) );
       
    47         LOG1("CLoadAttachments::MessageLoadingL AddAttachmentsToAppUiL: err=%d", err );
       
    48         
       
    49 		//Tell that loading of attachments has ended
       
    50 		iAppUI->StopWaitNote();
       
    51 		
       
    52 		// Complete observer regardless of result
       
    53 		TRequestStatus* observer = iLoadStatus;
       
    54 		User::RequestComplete( observer, err );
       
    55 		
       
    56 		// Then leave this method if error occurred
       
    57 		User::LeaveIfError( err );
       
    58 		}
       
    59 	}
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CLoadAttachments::CLoadAttachments
       
    63 // -----------------------------------------------------------------------------
       
    64 //	
       
    65 CLoadAttachments::CLoadAttachments( MMailAppUiInterface* aAppUI )
       
    66 	{
       
    67 	iAppUI = aAppUI;
       
    68 	}
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CLoadAttachments::~CLoadAttachments
       
    72 // -----------------------------------------------------------------------------
       
    73 //	
       
    74 CLoadAttachments::~CLoadAttachments()
       
    75 	{
       
    76 	
       
    77 	}
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CLoadAttachments::NextStateL
       
    81 // -----------------------------------------------------------------------------
       
    82 //	
       
    83 MLoadState* CLoadAttachments::NextStateL()
       
    84 	{
       
    85 	return NULL;
       
    86 	}
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CLoadAttachments::MakeRequestL
       
    90 // -----------------------------------------------------------------------------
       
    91 //		
       
    92 void CLoadAttachments::MakeRequestL( 
       
    93 	TRequestStatus& aStatus,
       
    94 	CMailMessage& aMessage )
       
    95 	{
       
    96 	iLoadStatus = &aStatus;
       
    97 	aMessage.LoadAttachmentsL( *this );
       
    98 	aStatus = KRequestPending;
       
    99 	}
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CLoadAttachments::AddAttachmentsToAppUiL
       
   103 // -----------------------------------------------------------------------------
       
   104 //		
       
   105 void CLoadAttachments::AddAttachmentsToAppUiL( MMsvAttachmentManager& aManager )
       
   106     {
       
   107 	LOG1("CLoadAttachments::AddAttachmentsToAppUiL attachmentCount:%d", 
       
   108 	     aManager.AttachmentCount());
       
   109 
       
   110 	//It is possible that aManager.AttachmentCount() changes while we are in 
       
   111 	//this loop. That is why latest count is checked every round.
       
   112 	for ( TInt index(0); index < aManager.AttachmentCount(); ++index ) 
       
   113 		{ 
       
   114 		LOG1("CLoadAttachments::AddAttachmentsToAppUiL iteration: %d", index);
       
   115 		CMsvAttachment* info = aManager.GetAttachmentInfoL( index );
       
   116 		CleanupStack::PushL( info );
       
   117 #ifdef MAIL_ENABLE_LOGGING
       
   118         LOG("CLoadAttachments::AddAttachmentsToAppUiL Attachment info:");
       
   119 		LOG1("CLoadAttachments::AddAttachmentsToAppUiL ID  : 0x%x", info->Id() );
       
   120         TPtrC name( info->AttachmentName() );
       
   121 		LOG1("CLoadAttachments::AddAttachmentsToAppUiL Name: '%S'", &name );
       
   122         TPtrC path( info->FilePath() );
       
   123         LOG1("CLoadAttachments::AddAttachmentsToAppUiL Path: '%S'", &path );
       
   124         HBufC* mime = HBufC::NewLC( info->MimeType().Length() );
       
   125         mime->Des().Copy( info->MimeType() );
       
   126         LOG1("CLoadAttachments::AddAttachmentsToAppUiL Mime: '%S'", mime );
       
   127         CleanupStack::PopAndDestroy( mime );
       
   128 #endif
       
   129 		LOG("CLoadAttachments::AddAttachmentsToAppUiL adding atta");
       
   130 		iAppUI->AddAttachmentL( *info, ETrue );
       
   131 		LOG("CLoadAttachments::AddAttachmentsToAppUiL atta added");
       
   132 		
       
   133 		CleanupStack::PopAndDestroy( info );
       
   134 		}    
       
   135     }
       
   136 
       
   137 //  End of File