messagingappbase/mce/src/MceAttachmentAddition.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2005 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:   Active object for adding an attachment to the entry
       
    15 *                in the message store (3.x platform).
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "MceAttachmentAddition.h"
       
    24 #include <msvapi.h>
       
    25 #include <mmsvattachmentmanager.h>
       
    26 #include <msvstore.h>
       
    27 #include <e32std.h>
       
    28 
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CMceAttachmentAddition::CMceAttachmentAddition
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CMceAttachmentAddition::CMceAttachmentAddition()
       
    39     : CActive(EPriorityStandard)
       
    40     {
       
    41     CActiveScheduler::Add(this); 
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CMceAttachmentAddition::NewLC
       
    46 // Two phase constructor
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CMceAttachmentAddition* CMceAttachmentAddition::NewLC()
       
    50 	{
       
    51     CMceAttachmentAddition* self = new(ELeave) CMceAttachmentAddition();
       
    52     CleanupStack::PushL(self);
       
    53 
       
    54     return self;
       
    55     }
       
    56 	
       
    57 // -----------------------------------------------------------------------------
       
    58 // CMceAttachmentAddition::~CMceAttachmentAddition
       
    59 // Destructor
       
    60 // -----------------------------------------------------------------------------
       
    61 CMceAttachmentAddition::~CMceAttachmentAddition()
       
    62     {
       
    63     delete iStore;
       
    64     iStore = NULL;
       
    65     Cancel();
       
    66     }	
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CMceAttachmentAddition::AttachFileL
       
    70 // Assign the asyncronous request for adding the attachment into the entry.
       
    71 // (other items were commented in a header).
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CMceAttachmentAddition::AttachFileL( CMsvEntry* aEntry, TFileName aFileName, RFile& /*aFileHandle*/, TInt aSize )
       
    75 	{
       
    76 	if( IsActive() )
       
    77         {
       
    78         User::Leave(KErrInUse);	    
       
    79         }
       
    80 	
       
    81 	// Get the attachment manager for the entry
       
    82 	iStore = aEntry->EditStoreL();
       
    83 	iAttachmentManager = &( iStore->AttachmentManagerL() );
       
    84 
       
    85 	// Create a new attachment attributes object
       
    86 	CMsvAttachment* attachmentInfo = CMsvAttachment::NewL( CMsvAttachment::EMsvLinkedFile );
       
    87 	CleanupStack::PushL( attachmentInfo );
       
    88 	
       
    89 	// set the attachment name and size attributes	
       
    90 	TParse fparse;
       
    91 	User::LeaveIfError( fparse.Set(aFileName,NULL,NULL) );
       
    92 	attachmentInfo->SetAttachmentNameL( fparse.NameAndExt() );
       
    93 	attachmentInfo->SetSize( aSize );
       
    94 
       
    95 	// Add the attachment, the ownership of the open file aFileHandle and the
       
    96 	// attachmentInfo are transferred to the message server
       
    97 	iAttachmentManager->AddLinkedAttachmentL(aFileName, attachmentInfo, iStatus);
       
    98 	CleanupStack::Pop( attachmentInfo );
       
    99 
       
   100 	SetActive();
       
   101 
       
   102     // Start the nested scheduler loop
       
   103     iWait.Start();
       
   104 	}
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CMceAttachmentAddition::Result()
       
   108 // Returns the error code
       
   109 // (other items were commented in a header).
       
   110 // -----------------------------------------------------------------------------
       
   111 //  
       
   112 TInt CMceAttachmentAddition::Result() const
       
   113 	{
       
   114 	return iError;
       
   115 	}
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CMceAttachmentAddition::RunL
       
   119 // Completes the asyncronous service request
       
   120 // (other items were commented in a header).
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CMceAttachmentAddition::RunL()
       
   124     {
       
   125     iError = iStatus.Int();
       
   126     
       
   127     if ( iError == KErrNone )
       
   128         {
       
   129         iStore->CommitL();
       
   130         }
       
   131 
       
   132     Reset();
       
   133     
       
   134     if (iWait.IsStarted())
       
   135         {
       
   136         // Stops the scheduler loop, when all nested scheduler loops have stopped.
       
   137         iWait.AsyncStop();
       
   138         }
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CMceAttachmentAddition::DoCancel
       
   143 // Cancels the asyncronous request, adding the attachment
       
   144 // (other items were commented in a header).
       
   145 // -----------------------------------------------------------------------------
       
   146 //	
       
   147 void CMceAttachmentAddition::DoCancel()
       
   148     {
       
   149     iError = KErrCancel;
       
   150     iAttachmentManager->CancelRequest();
       
   151     Reset();
       
   152     
       
   153     if (iWait.IsStarted())
       
   154         {
       
   155         // Stops the scheduler loop, when all nested scheduler loops have stopped.
       
   156         iWait.AsyncStop();
       
   157         }
       
   158     }
       
   159   
       
   160  // -----------------------------------------------------------------------------
       
   161 // CMceAttachmentAddition::RunError
       
   162 // Called by the framework if RunL leaves
       
   163 // (other items were commented in a header).
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 TInt CMceAttachmentAddition::RunError( TInt )
       
   167  	{
       
   168  	return KErrNone;
       
   169  	}
       
   170   
       
   171 // -----------------------------------------------------------------------------
       
   172 // CMceAttachmentAddition::Reset
       
   173 // Resets the state of the active object
       
   174 // (other items were commented in a header).
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CMceAttachmentAddition::Reset()
       
   178     {
       
   179     __ASSERT_ALWAYS(IsActive() == EFalse, User::Invariant());
       
   180 
       
   181     iAttachmentManager = NULL;
       
   182     delete iStore;
       
   183     iStore = NULL;
       
   184     }
       
   185 
       
   186 
       
   187 //  End of File