35 */ |
35 */ |
36 NmFwaAddAttachmentsOperation::NmFwaAddAttachmentsOperation( |
36 NmFwaAddAttachmentsOperation::NmFwaAddAttachmentsOperation( |
37 const NmMessage &message, |
37 const NmMessage &message, |
38 const QList<QString> &fileList, |
38 const QList<QString> &fileList, |
39 CFSMailClient &mailClient) : |
39 CFSMailClient &mailClient) : |
40 mMessage(message), |
|
41 mMailClient(mailClient) |
40 mMailClient(mailClient) |
42 { |
41 { |
43 // Take own copy of the file list |
42 // Take own copy of the file list. |
44 mFileList.clear(); |
43 mFileList.clear(); |
45 for (int i=0; i<fileList.count(); ++i) { |
44 for (int i=0; i<fileList.count(); ++i) { |
46 mFileList.append(fileList.at(i)); |
45 mFileList.append(fileList.at(i)); |
47 } |
46 } |
|
47 mFSMessage = CFSMailMessage::NewL(message); |
|
48 mRequestId = NmNotFoundError; |
48 } |
49 } |
49 |
50 |
50 /*! |
51 /*! |
51 Destructor |
52 Destructor |
52 */ |
53 */ |
53 NmFwaAddAttachmentsOperation::~NmFwaAddAttachmentsOperation() |
54 NmFwaAddAttachmentsOperation::~NmFwaAddAttachmentsOperation() |
54 { |
55 { |
|
56 // Cancel all running operations. |
55 doCancelOperation(); |
57 doCancelOperation(); |
56 mFileList.clear(); |
58 mFileList.clear(); |
57 mRequestIds.clear(); |
59 delete mFSMessage; |
58 } |
60 } |
59 |
61 |
60 /*! |
62 /*! |
61 Called after base object construction via timer event, runs the |
63 Called after base object construction, runs the |
62 async operation. |
64 async operation. |
63 |
65 |
64 \sa NmOperation |
66 \sa NmOperation |
65 */ |
67 */ |
66 void NmFwaAddAttachmentsOperation::doRunAsyncOperation() |
68 void NmFwaAddAttachmentsOperation::doRunAsyncOperation() |
67 { |
69 { |
68 TRAPD(err, doRunAsyncOperationL()); |
70 TRAPD(err, doRunAsyncOperationL()); |
|
71 // Trap harness catches an error. |
69 if (err != KErrNone) { |
72 if (err != KErrNone) { |
70 completeOperation(NmGeneralError); |
73 // File not found, inform UI. |
|
74 if (err == KErrNotFound) { |
|
75 completeOperationPart(mFileList.takeFirst(), |
|
76 NULL, |
|
77 NmNotFoundError); |
|
78 // Let's continue, if files still left. |
|
79 if (mFileList.count() > 0) { |
|
80 doRunAsyncOperation(); |
|
81 } |
|
82 else { |
|
83 // We do not want to report whole operation error, |
|
84 // when the last file is, or files, are missing. |
|
85 completeOperation(NmNoError); |
|
86 } |
|
87 } |
|
88 else { |
|
89 // Complete operation part, because of unknown error. |
|
90 // File list is never empty in this situation. |
|
91 completeOperationPart(mFileList.takeFirst(), |
|
92 NULL, |
|
93 NmGeneralError); |
|
94 // Complete whole operation, because of unknown error. |
|
95 mFileList.clear(); |
|
96 mRequestId = NmNotFoundError ; |
|
97 completeOperation(NmGeneralError); |
|
98 } |
71 } |
99 } |
72 } |
100 } |
73 |
101 |
74 /*! |
102 /*! |
75 Leaving version of doRunAsyncOperationL |
103 Leaving version of doRunAsyncOperationL |
76 */ |
104 */ |
77 void NmFwaAddAttachmentsOperation::doRunAsyncOperationL() |
105 void NmFwaAddAttachmentsOperation::doRunAsyncOperationL() |
78 { |
106 { |
79 CFSMailMessage *msg = NULL; |
107 if (mFileList.count() > 0) { |
80 msg = CFSMailMessage::NewL(mMessage); |
108 // Add new attachment from first file in the list. |
81 |
109 HBufC *fileName = NmConverter::qstringToHBufCLC(mFileList.first()); |
82 // Go through the attachment list and add those into mail message one by one. |
110 mRequestId = mFSMessage->AddNewAttachmentL(*fileName, *this); |
83 for (int i=0; i<mFileList.count(); ++i) { |
111 CleanupStack::PopAndDestroy(fileName); |
84 HBufC *fileName = NmConverter::qstringToHBufCLC(mFileList.at(i)); |
112 } else { |
85 mRequestIds.append(msg->AddNewAttachmentL(*fileName, *this)); |
113 completeOperation(NmNoError); |
86 CleanupStack::PopAndDestroy(fileName); |
114 } |
87 } |
115 |
88 delete msg; |
|
89 msg = NULL; |
|
90 } |
116 } |
91 |
117 |
92 /*! |
118 /*! |
93 Asynchronous request response message. |
119 Asynchronous request response message. |
94 |
120 |
97 */ |
123 */ |
98 void NmFwaAddAttachmentsOperation::RequestResponseL(TFSProgress aEvent, |
124 void NmFwaAddAttachmentsOperation::RequestResponseL(TFSProgress aEvent, |
99 TInt aRequestId) |
125 TInt aRequestId) |
100 { |
126 { |
101 int err = NmNoError; |
127 int err = NmNoError; |
102 for (int i=0;i<mRequestIds.count();++i) { |
128 |
103 |
129 // Request id should always be valid. If not, |
104 if (aRequestId == mRequestIds[i]) { |
130 // then report general error and complete operation. |
|
131 if (aRequestId == mRequestId) { |
|
132 |
|
133 // Request completed so request id used. |
|
134 mRequestId = KErrNotFound; |
|
135 |
|
136 // If request completed we can process the results. |
|
137 // Otherwise, we report about cancellation or general error |
|
138 // and stop the operation. |
|
139 if (aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete) { |
105 |
140 |
106 TFSProgress::TFSProgressStatus status = aEvent.iProgressStatus; |
141 // Request completed. Let's check the result. If no error |
107 |
142 // and parameter not NULL, report UI about a file added. |
108 if (status == TFSProgress::EFSStatus_RequestComplete |
143 // Else complete operation part with general error, |
109 && aEvent.iParam) { |
144 // but continue if a file or files still left in the list. |
110 // Request completed. Let's check the result |
145 if (aEvent.iError == KErrNone && aEvent.iParam) { |
111 switch (aEvent.iError) { |
146 |
112 case KErrNone: { |
147 // Cast the parameter to FS message part object, since |
113 CFSMailMessagePart *fsMessagePart = |
148 // it can't be anything else. |
114 static_cast<CFSMailMessagePart *>(aEvent.iParam); |
149 CFSMailMessagePart *fsMessagePart = |
115 completeOperationPart( |
150 static_cast<CFSMailMessagePart *>(aEvent.iParam); |
116 mFileList.at(i), |
151 |
117 fsMessagePart->GetPartId().GetNmId(), |
152 completeOperationPart( |
118 NmNoError); |
153 mFileList.takeFirst(), |
119 delete fsMessagePart; |
154 fsMessagePart->GetPartId().GetNmId(), |
120 fsMessagePart = NULL; |
155 NmNoError); |
121 break; |
156 |
122 } |
157 delete fsMessagePart; |
123 case KErrNotFound: |
158 fsMessagePart = NULL; |
124 completeOperationPart(mFileList.at(i), |
|
125 NULL, |
|
126 NmNotFoundError); |
|
127 err = NmNotFoundError; |
|
128 break; |
|
129 default: |
|
130 completeOperationPart(mFileList.at(i), |
|
131 NULL, |
|
132 NmGeneralError); |
|
133 err = NmGeneralError; |
|
134 } // end switch case |
|
135 // remove request id and file name |
|
136 mRequestIds.removeAt(i); |
|
137 mFileList.removeAt(i); |
|
138 } |
|
139 else if (status == TFSProgress::EFSStatus_RequestCancelled) { |
|
140 completeOperationPart(mFileList.at(i), |
|
141 NULL, |
|
142 NmCancelError); |
|
143 mFileList.clear(); |
|
144 mRequestIds.clear(); |
|
145 operationCancelled(); |
|
146 err = NmCancelError; |
|
147 } |
159 } |
148 else { |
160 else { |
149 completeOperationPart(mFileList.at(i), |
161 completeOperationPart(mFileList.takeFirst(), |
150 NULL, |
162 NULL, |
151 NmGeneralError); |
163 NmGeneralError); |
152 mFileList.clear(); |
164 } |
153 mRequestIds.clear(); |
165 } |
154 err = NmGeneralError; |
166 else { |
155 } |
167 completeOperationPart(mFileList.takeFirst(), |
156 } // end if |
168 NULL, |
157 } // end for |
169 NmGeneralError); |
158 |
170 mFileList.clear(); |
159 // complete operation |
171 err = NmGeneralError; |
160 if (!mRequestIds.count()) { |
172 } |
|
173 } // if (aRequestId == mRequestId) |
|
174 else { |
|
175 // Just to be sure. |
|
176 if (mFileList.count() > 0) { |
|
177 completeOperationPart(mFileList.takeFirst(), |
|
178 NULL, |
|
179 NmGeneralError); |
|
180 } |
|
181 mFileList.clear(); |
|
182 err = NmGeneralError; |
|
183 } |
|
184 |
|
185 // Complete operation if there are no files left. |
|
186 // Otherwise, continue with next file. |
|
187 if (!mFileList.count()) { |
161 completeOperation(err); |
188 completeOperation(err); |
|
189 } else { |
|
190 doRunAsyncOperation(); |
162 } |
191 } |
163 } |
192 } |
164 |
193 |
165 /*! |
194 /*! |
166 Cancels the async operation. \sa NmOperation |
195 Cancels the async operation. \sa NmOperation |
167 */ |
196 */ |
168 void NmFwaAddAttachmentsOperation::doCancelOperation() |
197 void NmFwaAddAttachmentsOperation::doCancelOperation() |
169 { |
198 { |
170 for (int i=0;i<mRequestIds.count();++i) { |
199 if (mRequestId != KErrNotFound) { |
171 if (mRequestIds[i] >= 0) { |
200 TRAP_IGNORE(mMailClient.CancelL(mRequestId)); |
172 TInt reqId = static_cast<TInt>(mRequestIds[i]); |
201 } |
173 TRAP_IGNORE(mMailClient.CancelL(reqId)); |
202 mRequestId = NmCancelError; |
174 } |
203 } |
175 } |
|
176 } |
|