|
1 /* |
|
2 * Copyright (c) 2002-2007 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: State machine -based operation for sending mail message. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cmsgmailsendop.h" |
|
22 #include "mmsgmailappuiopdelegate.h" |
|
23 #include "MailLog.h" |
|
24 #include "MailUtils.h" |
|
25 #include "MsgMailPreferences.h" |
|
26 #include "MsgMailEditorDocument.h" |
|
27 #include <StringLoader.h> |
|
28 #include <mtmuibas.h> |
|
29 #include <cemailaccounts.h> |
|
30 #include <Muiumsginfo.hrh> |
|
31 #include <aknnotewrappers.h> |
|
32 #include <MtmExtendedCapabilities.hrh> |
|
33 #include <MsgEditorAppUi.rsg> // resource identifiers |
|
34 #include <MsgMailEditor.rsg> |
|
35 #include <MuiuMsvUiServiceUtilities.h> // MUIU MTM utils |
|
36 #include <ImumInHealthServices.h> |
|
37 #include <ImumInMailboxServices.h> |
|
38 #include "EmailFeatureUtils.h" |
|
39 |
|
40 |
|
41 const TInt KMaximumAddressLength(100); |
|
42 |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CMsgMailSendOp::CMsgMailSendOp |
|
47 // C++ default constructor can NOT contain any code, that |
|
48 // might leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CMsgMailSendOp::CMsgMailSendOp( |
|
52 CMsgMailEditorDocument& aDocument, |
|
53 MMsgMailAppUiOpDelegate& aOpDelegate ) |
|
54 : CMsgMailBaseOp( aDocument ), |
|
55 iOpDelegate( aOpDelegate ) |
|
56 { |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CMsgMailSendOp::ConstructL |
|
61 // Symbian 2nd phase constructor can leave. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void CMsgMailSendOp::ConstructL() |
|
65 { |
|
66 iFlags = MsvEmailMtmUiFeatureUtils::EmailFeaturesL( ETrue, ETrue ); |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CMsgMailSendOp::NewL |
|
71 // Two-phased constructor. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CMsgMailSendOp* CMsgMailSendOp::NewL( |
|
75 CMsgMailEditorDocument& aDocument, |
|
76 MMsgMailAppUiOpDelegate& aOpDelegate ) |
|
77 { |
|
78 CMsgMailSendOp* self = new( ELeave ) CMsgMailSendOp( aDocument, |
|
79 aOpDelegate ); |
|
80 CleanupStack::PushL( self ); |
|
81 self->ConstructL(); |
|
82 |
|
83 CleanupStack::Pop( self ); |
|
84 return self; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CMsgMailSendOp::~CMsgMailSendOp |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CMsgMailSendOp::~CMsgMailSendOp() |
|
92 { |
|
93 Cancel(); |
|
94 delete iFlags; |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CMsgMailSendOp::HandleStateActionL |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 void CMsgMailSendOp::HandleStateActionL() |
|
102 { |
|
103 switch ( iState ) |
|
104 { |
|
105 case EPrepare: |
|
106 { |
|
107 PrepareL(); |
|
108 break; |
|
109 } |
|
110 case ESaveMessage: |
|
111 { |
|
112 SaveMessageL(); |
|
113 break; |
|
114 } |
|
115 case ESendMessage: |
|
116 { |
|
117 SendMessageL(); |
|
118 break; |
|
119 } |
|
120 case EFinalize: |
|
121 { |
|
122 Finalize(); |
|
123 break; |
|
124 } |
|
125 default: |
|
126 { |
|
127 // should never come here |
|
128 ASSERT( EFalse ); |
|
129 break; |
|
130 } |
|
131 } |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CMsgMailSendOp::SetNextState |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CMsgMailSendOp::SetNextState() |
|
139 { |
|
140 switch ( iState ) |
|
141 { |
|
142 case EIdleState: |
|
143 { |
|
144 iState = EPrepare; |
|
145 break; |
|
146 } |
|
147 case EPrepare: |
|
148 { |
|
149 iState = ESaveMessage; |
|
150 break; |
|
151 } |
|
152 case ESaveMessage: |
|
153 { |
|
154 iState = ESendMessage; |
|
155 break; |
|
156 } |
|
157 case ESendMessage: |
|
158 { |
|
159 iState = EFinalize; |
|
160 break; |
|
161 } |
|
162 case EFinalize: // fall through |
|
163 default: |
|
164 { |
|
165 iState = EIdleState; |
|
166 break; |
|
167 } |
|
168 } |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CMsgMailSendOp::HandleOperationCancel |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 void CMsgMailSendOp::HandleOperationCancel() |
|
176 { |
|
177 // nothing to cancel |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CMsgMailSendOp::PrepareL |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CMsgMailSendOp::PrepareL() |
|
185 { |
|
186 CMsgMailPreferences& prefs = iDocument.SendOptions(); |
|
187 TMsvId sendingBox = SendingBoxL( prefs ); |
|
188 SetSchedulingOptionsL( prefs, sendingBox ); |
|
189 CompleteStateAction(); |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CMsgMailSendOp::SaveMessageL |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 void CMsgMailSendOp::SaveMessageL() |
|
197 { |
|
198 // we can't handle saving by ourself so call the delegator |
|
199 iOpDelegate.DelegateSaveMsgL(); |
|
200 CompleteStateAction(); |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CMsgMailSendOp::SendMessageL |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CMsgMailSendOp::SendMessageL() |
|
208 { |
|
209 // We need to do offline check before sendind so that correct note can |
|
210 // be displayed |
|
211 if ( MailUtils::OfflineProfileActiveL() && !iFlags->GF( EMailFeatureProtocolWlan )) |
|
212 { |
|
213 iDocument.SendOptions().SetMessageScheduling( |
|
214 CMsgMailPreferences::EMsgMailSchedulingNextConn ); |
|
215 } |
|
216 |
|
217 // start wait note showing at this point |
|
218 StartWaitNoteL( WaitNoteTextResourceId(), ETrue, R_WAIT_SEND_NOTE ); |
|
219 SendNativeMailL(); |
|
220 CompleteStateAction(); |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CMsgMailSendOp::Finalize |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 void CMsgMailSendOp::Finalize() |
|
228 { |
|
229 StopWaitNote(); |
|
230 CompleteStateAction(); |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CMsgMailSendOp::SendingBoxL |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 TMsvId CMsgMailSendOp::SendingBoxL( CMsgMailPreferences& aPrefs ) const |
|
238 { |
|
239 // Check that box exists |
|
240 TMsvId sendingBox = aPrefs.ServiceId(); |
|
241 CMsvEntrySelection* sendingAccounts = |
|
242 MsvUiServiceUtilities::GetListOfAccountsWithMTML( |
|
243 iDocument.Session(), |
|
244 iDocument.CurrentEntry().Entry().iMtm, |
|
245 ETrue ); |
|
246 TInt retValue = sendingAccounts->Find( sendingBox ); |
|
247 delete sendingAccounts; |
|
248 |
|
249 if ( retValue == KErrNotFound ) |
|
250 { // no mailboxes defined |
|
251 HBufC* string = StringLoader::LoadLC( R_MAIL_MAILBOX_MISSING, |
|
252 CEikonEnv::Static() ); // CSI: 27 # Must be used because of iEikEnv |
|
253 // is not accessible. |
|
254 CAknInformationNote* note = |
|
255 new( ELeave ) CAknInformationNote( ETrue ); |
|
256 note->ExecuteLD( *string ); |
|
257 CleanupStack::PopAndDestroy( string ); // string |
|
258 // unacceptable situation -> leave |
|
259 User::Leave( KErrNotFound ); |
|
260 } |
|
261 |
|
262 // check own address |
|
263 else if ( !CheckOwnAddressL() ) |
|
264 { |
|
265 // consider this case as cancelled send operation |
|
266 User::Leave( KErrCancel ); |
|
267 } |
|
268 return sendingBox; |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CMsgMailSendOp::SetSchedulingOptionsL |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 void CMsgMailSendOp::SetSchedulingOptionsL( |
|
276 CMsgMailPreferences& aPrefs, |
|
277 TMsvId aSendingBox ) const |
|
278 { |
|
279 // Overwrite send options if not wlan and offline mode |
|
280 CImumInternalApi* api = CreateEmailApiLC( &iDocument.Session() ); |
|
281 if ( !api->MailboxUtilitiesL().HasWlanConnectionL( aSendingBox ) && |
|
282 MailUtils::OfflineProfileActiveL()) |
|
283 { |
|
284 aPrefs.SetMessageScheduling( |
|
285 CMsgMailPreferences::EMsgMailSchedulingNextConn); |
|
286 } |
|
287 else if(iDocument.IsOnlineL()) |
|
288 { |
|
289 aPrefs.SetMessageScheduling( |
|
290 CMsgMailPreferences::EMsgMailSchedulingNow); |
|
291 } |
|
292 |
|
293 CleanupStack::PopAndDestroy( api ); |
|
294 api = NULL; |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CMsgMailSendOp::WaitNoteTextResourceId |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 TInt CMsgMailSendOp::WaitNoteTextResourceId() const |
|
302 { |
|
303 //Select correct text for the wait note. |
|
304 TInt textResID = R_TEXT_SENDING_MAIL; |
|
305 if ( iDocument.SendOptions().MessageScheduling() |
|
306 == CMsgMailPreferences::EMsgMailSchedulingNextConn ) |
|
307 { |
|
308 textResID = R_TEXT_SENDING_MAIL_NEXTCON; |
|
309 } |
|
310 |
|
311 return textResID; |
|
312 } |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // CMsgMailSendOp::CheckOwnAddressL |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 TBool CMsgMailSendOp::CheckOwnAddressL() const |
|
319 { |
|
320 TBool result( ETrue ); |
|
321 |
|
322 CEmailAccounts* smtpAccount = CEmailAccounts::NewLC(); |
|
323 CImSmtpSettings* smtpSet=new( ELeave ) CImSmtpSettings(); |
|
324 CleanupStack::PushL( smtpSet ); |
|
325 const TMsvId smtpSetId = iDocument.CurrentEntry().Entry().iServiceId; |
|
326 |
|
327 TSmtpAccount accountParams; |
|
328 smtpAccount->GetSmtpAccountL( smtpSetId, accountParams ); |
|
329 smtpAccount->LoadSmtpSettingsL( accountParams, *smtpSet ); |
|
330 |
|
331 if ( !smtpSet->EmailAddress().Length() ) |
|
332 { |
|
333 TBuf<KMaximumAddressLength> text; |
|
334 CAknTextQueryDialog* dlg = new( ELeave ) CAknTextQueryDialog( text ); |
|
335 if ( dlg->ExecuteLD( R_MAIL_ADDRESS_QUERY ) ) |
|
336 { |
|
337 smtpSet->SetEmailAddressL( text ); |
|
338 smtpAccount->SaveSmtpSettingsL( accountParams, *smtpSet ); |
|
339 } |
|
340 else |
|
341 { |
|
342 result = EFalse; |
|
343 } |
|
344 } |
|
345 |
|
346 CleanupStack::PopAndDestroy( 2, smtpAccount ); // CSI: 47,12 # smtpSet, smtpAccount |
|
347 return result; |
|
348 } |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CMsgMailSendOp::SendNativeMailL |
|
352 // ----------------------------------------------------------------------------- |
|
353 // |
|
354 void CMsgMailSendOp::SendNativeMailL() |
|
355 { |
|
356 // get entry |
|
357 const TMsvEmailEntry& msvEntry = iDocument.Entry(); |
|
358 TMsvId messageId( msvEntry.Id() ); |
|
359 if ( msvEntry.Parent() != KMsvGlobalOutBoxIndexEntryId ) |
|
360 { |
|
361 // MsgEditor can handle moving to outbox so ask delegator's help |
|
362 messageId = iOpDelegate.DelegateMoveMsgToOutboxL(); |
|
363 } |
|
364 |
|
365 // check, if message sending type is EMsgMailSchedulingNow |
|
366 if ( iDocument.SendOptions().MessageScheduling() == |
|
367 CMsgMailPreferences::EMsgMailSchedulingNow ) |
|
368 { |
|
369 // send immediately |
|
370 iDocument.SetEntryL( messageId ); |
|
371 // SendImmediatelyL() is also asynchronous by nature |
|
372 iDocument.SendImmediatelyL( messageId ); |
|
373 } |
|
374 |
|
375 } |
|
376 |
|
377 // End Of File |