|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "nmframeworkadapterheaders.h" |
|
19 |
|
20 NmFwaStoreMessageOperation::NmFwaStoreMessageOperation( |
|
21 CFSMailMessage *message, |
|
22 CFSMailClient &mailClient) : |
|
23 mMessage(message), |
|
24 mMailClient(mailClient), |
|
25 mRequestId(NmNotFoundError), |
|
26 mStatus(EStoreHeader) |
|
27 { |
|
28 NM_FUNCTION; |
|
29 } |
|
30 |
|
31 NmFwaStoreMessageOperation::~NmFwaStoreMessageOperation() |
|
32 { |
|
33 NM_FUNCTION; |
|
34 |
|
35 doCancelOperation(); |
|
36 delete mMessage; |
|
37 } |
|
38 |
|
39 void NmFwaStoreMessageOperation::doRunAsyncOperation() |
|
40 { |
|
41 NM_FUNCTION; |
|
42 |
|
43 TInt err = KErrNone; |
|
44 |
|
45 if (mMessage) { |
|
46 switch (mStatus) { |
|
47 case EStoreHeader: { |
|
48 TRAP(err, mRequestId = mMessage->SaveMessageL(*this)); |
|
49 if (err != KErrNone) { |
|
50 completeOperation(NmGeneralError); |
|
51 } |
|
52 mStatus = EStoreSubParts; |
|
53 break; |
|
54 } |
|
55 case EStoreSubParts: { |
|
56 TRAP(err, mRequestId = mMessage->SaveMessagePartsL(*this)); |
|
57 if (err != KErrNone) { |
|
58 completeOperation(NmGeneralError); |
|
59 } |
|
60 mStatus = EComplete; |
|
61 break; |
|
62 } |
|
63 case EComplete: { |
|
64 completeOperation(NmNoError); |
|
65 break; |
|
66 } |
|
67 |
|
68 default: { |
|
69 completeOperation(NmNotFoundError); |
|
70 break; |
|
71 } |
|
72 } |
|
73 } else { |
|
74 completeOperation(NmGeneralError); |
|
75 } |
|
76 } |
|
77 |
|
78 /*! |
|
79 |
|
80 */ |
|
81 void NmFwaStoreMessageOperation::doCompleteOperation() |
|
82 { |
|
83 NM_FUNCTION; |
|
84 |
|
85 mRequestId = NmNotFoundError; |
|
86 } |
|
87 |
|
88 void NmFwaStoreMessageOperation::doCancelOperation() |
|
89 { |
|
90 NM_FUNCTION; |
|
91 |
|
92 if (mRequestId >= 0) { |
|
93 TRAP_IGNORE(mMailClient.CancelL(mRequestId)); |
|
94 mRequestId = NmNotFoundError; |
|
95 } |
|
96 } |
|
97 |
|
98 /** |
|
99 * asynchronous request response message |
|
100 * |
|
101 * @param aEvent plugin event description |
|
102 * @param aRequestId request id of asyncronous operation |
|
103 */ |
|
104 void NmFwaStoreMessageOperation::RequestResponseL(TFSProgress aEvent, |
|
105 TInt aRequestId) |
|
106 { |
|
107 NM_FUNCTION; |
|
108 |
|
109 if (aRequestId == mRequestId) { |
|
110 if (aEvent.iProgressStatus == |
|
111 TFSProgress::EFSStatus_RequestComplete) { |
|
112 if(mStatus != EComplete) { |
|
113 doRunAsyncOperation(); |
|
114 } else { |
|
115 completeOperation(NmNoError); |
|
116 } |
|
117 } |
|
118 else if (aEvent.iProgressStatus == |
|
119 TFSProgress::EFSStatus_RequestCancelled) { |
|
120 completeOperation(NmCancelError); |
|
121 } |
|
122 else { |
|
123 completeOperation(NmGeneralError); |
|
124 } |
|
125 } |
|
126 } |