31 |
31 |
32 \param message pointer to the message under sent, ownership is transferred to operation |
32 \param message pointer to the message under sent, ownership is transferred to operation |
33 \param mailClient Reference to mail client object. |
33 \param mailClient Reference to mail client object. |
34 */ |
34 */ |
35 NmFwaMessageSendingOperation::NmFwaMessageSendingOperation( |
35 NmFwaMessageSendingOperation::NmFwaMessageSendingOperation( |
|
36 NmDataPluginInterface &pluginInterface, |
36 NmMessage *message, |
37 NmMessage *message, |
37 CFSMailClient &mailClient) : |
38 CFSMailClient &mailClient) : |
|
39 mPluginInterface(pluginInterface), |
|
40 mSaveOperation(NULL), |
38 mMessage(message), |
41 mMessage(message), |
39 mMailClient(mailClient), |
42 mMailClient(mailClient), |
40 mRequestId(NmNotFoundError) |
43 mRequestId(NmNotFoundError), |
41 { |
44 mSaved(false) |
|
45 { |
|
46 mMailClient.IncReferenceCount(); |
42 } |
47 } |
43 |
48 |
44 /*! |
49 /*! |
45 Destructor |
50 Destructor |
46 */ |
51 */ |
47 NmFwaMessageSendingOperation::~NmFwaMessageSendingOperation() |
52 NmFwaMessageSendingOperation::~NmFwaMessageSendingOperation() |
48 { |
53 { |
|
54 delete mSaveOperation; |
|
55 |
49 doCancelOperation(); |
56 doCancelOperation(); |
|
57 mMailClient.Close(); // decrease ref count |
50 delete mMessage; |
58 delete mMessage; |
51 } |
59 } |
52 |
60 |
53 /*! |
61 /*! |
54 returns pointer to message, ownership is not transferred |
62 returns pointer to message, ownership is not transferred |
55 */ |
63 */ |
56 const NmMessage *NmFwaMessageSendingOperation::getMessage() |
64 const NmMessage *NmFwaMessageSendingOperation::getMessage() const |
57 { |
65 { |
58 return mMessage; |
66 return mMessage; |
59 } |
67 } |
60 |
68 |
61 /*! |
69 /*! |
62 Slot, called after base object construction via timer event, runs the |
70 Called after base object construction via timer event, runs the |
63 async operation. |
71 async operation. |
64 |
72 |
65 \sa NmOperation |
73 \sa NmOperation |
66 */ |
74 */ |
67 void NmFwaMessageSendingOperation::runAsyncOperation() |
75 void NmFwaMessageSendingOperation::doRunAsyncOperation() |
68 { |
76 { |
69 TInt err (KErrNone); |
77 int err = NmNoError; |
70 TRAP(err, runAsyncOperationL()); |
78 |
71 |
79 if (mSaved) { |
72 if (err == KErrNotFound) { |
80 TRAPD(trapped, err = sendMessageL()); |
73 completeOperation(NmNotFoundError); |
81 |
74 } |
82 if (trapped == KErrNotFound) { |
75 else if (err != KErrNone){ |
83 err = NmNotFoundError; |
76 completeOperation(NmGeneralError); |
84 } |
77 } |
85 else if (trapped != KErrNone) { |
78 // err == KErrNone means everything went well and the operation is |
86 err = NmGeneralError; |
79 // proceeding |
87 } |
80 } |
88 } |
81 |
89 else { |
82 /*! |
90 err = saveMessageWithSubparts(); |
83 Leaving version of runAsyncOperation |
91 } |
84 */ |
92 |
85 void NmFwaMessageSendingOperation::runAsyncOperationL() |
93 if (err != NmNoError) { |
86 { |
94 completeOperation(err); |
87 CFSMailBox *currentMailbox( NULL ); |
95 } |
88 |
96 // err == NmNoError means everything went well and the operation is proceeding |
89 if (!mMessage) { |
|
90 User::Leave( KErrNotFound ); |
|
91 } |
|
92 TFSMailMsgId mailboxId = NmConverter::nmIdToMailMsgId(mMessage->mailboxId()); |
|
93 currentMailbox = mMailClient.GetMailBoxByUidL(mailboxId); |
|
94 CleanupStack::PushL(currentMailbox); |
|
95 if (!currentMailbox) { |
|
96 User::Leave( KErrNotFound ); |
|
97 } |
|
98 |
|
99 CFSMailMessage *msg = CFSMailMessage::NewL(*mMessage); // no leave -> msg != NULL |
|
100 CleanupStack::PushL(msg); |
|
101 |
|
102 mRequestId = currentMailbox->SendMessageL(*msg, *this); |
|
103 CleanupStack::PopAndDestroy(2); // msg, currentMailbox |
|
104 } |
97 } |
105 |
98 |
106 /*! |
99 /*! |
107 |
100 |
108 */ |
101 */ |
143 else { |
136 else { |
144 completeOperation(NmGeneralError); |
137 completeOperation(NmGeneralError); |
145 } |
138 } |
146 } |
139 } |
147 } |
140 } |
|
141 |
|
142 /*! |
|
143 Handle completed store message operation |
|
144 */ |
|
145 void NmFwaMessageSendingOperation::handleCompletedSaveOperation(int error) |
|
146 { |
|
147 if (error == NmNoError) { |
|
148 mTimer->stop(); |
|
149 mTimer->start(1); |
|
150 mSaved = true; |
|
151 } |
|
152 else { |
|
153 completeOperation(NmGeneralError); |
|
154 } |
|
155 } |
|
156 |
|
157 /*! |
|
158 Saves a message with its subparts (into message store). |
|
159 */ |
|
160 int NmFwaMessageSendingOperation::saveMessageWithSubparts() |
|
161 { |
|
162 int ret = NmNotFoundError; |
|
163 |
|
164 if (mMessage) { |
|
165 delete mSaveOperation; |
|
166 mSaveOperation = NULL; |
|
167 |
|
168 mSaveOperation = mPluginInterface.saveMessageWithSubparts(*mMessage); |
|
169 |
|
170 if (mSaveOperation) { |
|
171 connect(mSaveOperation, SIGNAL(operationCompleted(int)), this, |
|
172 SLOT(handleCompletedSaveOperation(int))); |
|
173 ret = NmNoError; |
|
174 } |
|
175 else { |
|
176 ret = NmGeneralError; |
|
177 } |
|
178 |
|
179 } |
|
180 |
|
181 return ret; |
|
182 } |
|
183 |
|
184 /*! |
|
185 Sends the message. |
|
186 */ |
|
187 int NmFwaMessageSendingOperation::sendMessageL() |
|
188 { |
|
189 int ret = NmNotFoundError; |
|
190 |
|
191 if (mMessage) { |
|
192 TFSMailMsgId mailboxId = NmConverter::nmIdToMailMsgId(mMessage->mailboxId()); |
|
193 CFSMailBox *currentMailbox( NULL ); |
|
194 currentMailbox = mMailClient.GetMailBoxByUidL(mailboxId); |
|
195 CleanupStack::PushL(currentMailbox); |
|
196 if (!currentMailbox) { |
|
197 User::Leave( KErrNotFound ); |
|
198 } |
|
199 |
|
200 CFSMailMessage *msg = CFSMailMessage::NewL(*mMessage); // no leave -> msg != NULL |
|
201 CleanupStack::PushL(msg); |
|
202 |
|
203 mRequestId = currentMailbox->SendMessageL(*msg, *this); |
|
204 CleanupStack::PopAndDestroy(2); // msg, currentMailbox |
|
205 |
|
206 ret = NmNoError; |
|
207 } |
|
208 |
|
209 return ret; |
|
210 } |