messagingappbase/obexmtms/TObexMTM/SRC/AddObexAttachmentState.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // $Workfile: AddObexAttachmentState.cpp $
       
    15 // $Author: Simonk $
       
    16 // $Revision: 4 $
       
    17 // $Date: 29/01/02 11:23 $
       
    18 // 
       
    19 //
       
    20 
       
    21 #include "AddObexAttachmentState.h"
       
    22 
       
    23 //TODO:- check that all these headers are required
       
    24 
       
    25 // System includes
       
    26 #include <btmsgtypeuid.h>   // KUidMsgTypeBt
       
    27 #include <btmtmcmds.h>      // TBtMtmAsyncCmds
       
    28 #include <irmsgtypeuid.h>   // KUidMsgTypeIr
       
    29 #include <irmtmcmds.h>      // TIrMtmAsyncCmds
       
    30 #include <obexMtmUtil.h>    // CObexMtmFileNameExternaliser
       
    31 #include <msvuids.h>        // KUidMsvMessageEntry
       
    32 #include <obexclientmtm.h>
       
    33 
       
    34 #include <mmsvattachmentmanager.h>
       
    35 #include <cmsvattachment.h>
       
    36 
       
    37 #include "casyncwaiter.h"
       
    38 
       
    39 // User includes
       
    40 #include "obexharness.h"
       
    41 #include "obextestutils.h"  // CObexTestUtils
       
    42 
       
    43 
       
    44 
       
    45 //
       
    46 // CAddObexAttachmentAsEntryState
       
    47 //
       
    48 
       
    49 CAddObexAttachmentAsEntryState::CAddObexAttachmentAsEntryState(const TDesC& aFileName, CObexClientTest& aClientTest) :
       
    50  iClientTest(aClientTest),
       
    51  iFileName(aFileName)
       
    52 	{
       
    53     }
       
    54 
       
    55 void CAddObexAttachmentAsEntryState::StartL(TRequestStatus& aStatus)
       
    56     {
       
    57     // Add an attachment as a child entry
       
    58 
       
    59     CBaseMtm& clientMtm = iClientTest.ObexTestUtils().GetCurrentObexClientMtm();
       
    60 
       
    61 	CMsvEntry& entry = clientMtm.Entry();
       
    62 	CMsvStore* store = entry.EditStoreL();
       
    63 	CleanupStack::PushL(store);
       
    64 	
       
    65 	CAsyncWaiter* waiter = CAsyncWaiter::NewL();
       
    66 	CleanupStack::PushL(waiter);
       
    67 	CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
       
    68 	CleanupStack::PushL(attachment);
       
    69 	TParse fileNameParser;
       
    70 	User::LeaveIfError(fileNameParser.Set(iFileName, NULL, NULL));
       
    71 	attachment->SetAttachmentNameL(fileNameParser.NameAndExt());
       
    72 	store->AttachmentManagerL().AddAttachmentL(iFileName, attachment, waiter->iStatus);
       
    73 	CleanupStack::Pop(attachment);
       
    74 	waiter->StartAndWait();
       
    75 	User::LeaveIfError(waiter->Result());
       
    76 	CleanupStack::PopAndDestroy(waiter);
       
    77 	
       
    78 	store->CommitL();
       
    79 	CleanupStack::PopAndDestroy(store);
       
    80 
       
    81     TRequestStatus* status = &aStatus;
       
    82 	User::RequestComplete(status, KErrNone);
       
    83     }
       
    84 
       
    85 
       
    86 //
       
    87 // CAddObexAttachmentByNameState
       
    88 //
       
    89 
       
    90 CAddObexAttachmentByNameState::CAddObexAttachmentByNameState(const TDesC& aFileName, CObexClientTest& aClientTest) :
       
    91  iClientTest(aClientTest),
       
    92  iFileName(aFileName)
       
    93     {
       
    94     }
       
    95 
       
    96 void CAddObexAttachmentByNameState::StartL(TRequestStatus& aStatus)
       
    97     {
       
    98 	// Get the attachment list and append the file path to it
       
    99 	RPointerArray<CObexTestFilenameAndHeaders>& attachments = iClientTest.Attachments();
       
   100 	
       
   101 	CObexTestFilenameAndHeaders* obexPackage = CObexTestFilenameAndHeaders::NewL();
       
   102 	CleanupStack::PushL(obexPackage);
       
   103 	// set the filename but no headers
       
   104 	obexPackage->iFileName = iFileName;
       
   105 	
       
   106 	User::LeaveIfError(attachments.Append(obexPackage));
       
   107 	CleanupStack::Pop(obexPackage); // ownership passed to array
       
   108 
       
   109 	// Complete the state.
       
   110     TRequestStatus* status = &aStatus;
       
   111 	User::RequestComplete(status, KErrNone);
       
   112     }
       
   113 
       
   114 
       
   115 //
       
   116 // CAddObexAttachmentByNameWithHeadersState
       
   117 //
       
   118 
       
   119 CAddObexAttachmentByNameWithHeadersState::CAddObexAttachmentByNameWithHeadersState(const TDesC& aFileName, CObexClientTest& aClientTest) :
       
   120  iClientTest(aClientTest),
       
   121  iFileName(aFileName)
       
   122     {
       
   123     }
       
   124 
       
   125 void CAddObexAttachmentByNameWithHeadersState::StartL(TRequestStatus& aStatus)
       
   126     {
       
   127 	// Get the attachment list and append the file path to it
       
   128 	RPointerArray<CObexTestFilenameAndHeaders>& attachments = iClientTest.Attachments();
       
   129 
       
   130 	CObexTestFilenameAndHeaders* obexPackage = CObexTestFilenameAndHeaders::NewL();
       
   131 	CleanupStack::PushL(obexPackage);
       
   132 	// set the filename and the headers
       
   133 	obexPackage->iFileName = iFileName;
       
   134 	CObexHeaderList* currentHeaders = iClientTest.CurrentHeaders();
       
   135 	obexPackage->iHeaderList = currentHeaders;
       
   136 	iClientTest.ReleaseCurrentHeaders();	// Release ownership of current headers.
       
   137 	
       
   138 	User::LeaveIfError(attachments.Append(obexPackage));
       
   139 	CleanupStack::Pop(obexPackage); // ownership passed to array
       
   140 
       
   141 	// Complete the state.
       
   142     TRequestStatus* status = &aStatus;
       
   143 	User::RequestComplete(status, KErrNone);
       
   144     }
       
   145 
       
   146