|
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 mail editor view launching. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cmsgmaillaunchop.h" |
|
22 #include "mmsgmailappuiopdelegate.h" |
|
23 #include "MsgMailEditorDocument.h" |
|
24 #include "cmsgmailrestoresuperop.h" |
|
25 #include "MailLog.h" |
|
26 #include <MsgEditorAppUi.rsg> // resource identifiers |
|
27 #include <MsgMailEditor.rsg> |
|
28 #include <MsgBodyControl.h> |
|
29 #include <eikrted.h> |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CMsgMailLaunchOp::CMsgMailLaunchOp |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CMsgMailLaunchOp::CMsgMailLaunchOp( |
|
40 CMsgMailEditorDocument& aDocument, |
|
41 MMsgMailAppUiOpDelegate& aOpDelegate ) |
|
42 : CMsgMailBaseOp( aDocument ), |
|
43 iOpDelegate( aOpDelegate ) |
|
44 { |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CMsgMailLaunchOp::ConstructL |
|
49 // Symbian 2nd phase constructor can leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 void CMsgMailLaunchOp::ConstructL() |
|
53 { |
|
54 |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CMsgMailLaunchOp::NewL |
|
59 // Two-phased constructor. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CMsgMailLaunchOp* CMsgMailLaunchOp::NewL( |
|
63 CMsgMailEditorDocument& aDocument, |
|
64 MMsgMailAppUiOpDelegate& aOpDelegate ) |
|
65 { |
|
66 CMsgMailLaunchOp* self = new( ELeave ) CMsgMailLaunchOp( aDocument, |
|
67 aOpDelegate ); |
|
68 CleanupStack::PushL( self ); |
|
69 self->ConstructL(); |
|
70 |
|
71 CleanupStack::Pop(self); |
|
72 return self; |
|
73 } |
|
74 |
|
75 |
|
76 // Destructor |
|
77 CMsgMailLaunchOp::~CMsgMailLaunchOp() |
|
78 { |
|
79 LOG( "CMsgMailLaunchOp::~CMsgMailLaunchOp" ); |
|
80 Cancel(); |
|
81 delete iRestoreSuperOp; |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CMsgMailLaunchOp::HandleStateActionL |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 void CMsgMailLaunchOp::HandleStateActionL() |
|
89 { |
|
90 switch ( iState ) |
|
91 { |
|
92 case EInitLaunch: |
|
93 { |
|
94 InitLaunchL(); |
|
95 break; |
|
96 } |
|
97 case ERestoreBody: |
|
98 { |
|
99 RestoreBodyL(); |
|
100 break; |
|
101 } |
|
102 case EConvertLineBreaks: |
|
103 { |
|
104 ConvertLineBreaksL(); |
|
105 break; |
|
106 } |
|
107 case ERestoreAllAttas: |
|
108 { |
|
109 RestoreAllAttasL(); |
|
110 break; |
|
111 } |
|
112 case EExecuteView: |
|
113 { |
|
114 ExecuteViewL(); |
|
115 break; |
|
116 } |
|
117 case EFinalize: |
|
118 { |
|
119 FinalizeL(); |
|
120 break; |
|
121 } |
|
122 default: |
|
123 { |
|
124 // should never come here |
|
125 ASSERT( EFalse ); |
|
126 break; |
|
127 } |
|
128 } |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CMsgMailLaunchOp::SetNextState |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CMsgMailLaunchOp::SetNextState() |
|
136 { |
|
137 switch ( iState ) |
|
138 { |
|
139 case EIdleState: |
|
140 { |
|
141 iState = EInitLaunch; |
|
142 break; |
|
143 } |
|
144 case EInitLaunch: |
|
145 { |
|
146 iState = ERestoreBody; |
|
147 break; |
|
148 } |
|
149 case ERestoreBody: |
|
150 { |
|
151 iState = EConvertLineBreaks; |
|
152 break; |
|
153 } |
|
154 case EConvertLineBreaks: |
|
155 { |
|
156 iState = ERestoreAllAttas; |
|
157 break; |
|
158 } |
|
159 case ERestoreAllAttas: |
|
160 { |
|
161 iState = EExecuteView; |
|
162 break; |
|
163 } |
|
164 case EExecuteView: |
|
165 { |
|
166 iState = EFinalize; |
|
167 break; |
|
168 } |
|
169 case EFinalize: // fall through |
|
170 default: |
|
171 { |
|
172 iState = EIdleState; |
|
173 break; |
|
174 } |
|
175 } |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CMsgMailLaunchOp::HandleOperationCancel |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 void CMsgMailLaunchOp::HandleOperationCancel() |
|
183 { |
|
184 LOG( "CMsgMailLaunchOp::HandleOperationCancel, deleting iRestoreSuperOp" ); |
|
185 delete iRestoreSuperOp; |
|
186 iRestoreSuperOp = NULL; |
|
187 |
|
188 if ( iState == ERestoreBody ) |
|
189 { |
|
190 LOG( "HandleOperationCancel, ...MessageL().Cancel()..." ); |
|
191 TRAP_IGNORE( iDocument.MessageL().Cancel() ); |
|
192 } |
|
193 LOG( "HandleOperationCancel, ...finished" ); |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CMsgMailLaunchOp::InitLaunchL |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 void CMsgMailLaunchOp::InitLaunchL() |
|
201 { |
|
202 // start wait note showing at this point |
|
203 StartWaitNoteL( R_WAIT_OPENING, EFalse, R_MEB_WAIT_NOTE ); |
|
204 |
|
205 CMsgBodyControl& bodyControl( iOpDelegate.DelegateInitLaunchL() ); |
|
206 |
|
207 TInt editorFlags = bodyControl.Editor().AknEdwinFlags(); |
|
208 editorFlags &= ~EAknEditorFlagEnablePictographInput; |
|
209 bodyControl.Editor().SetAknEditorFlags( editorFlags ); |
|
210 iBodyText = &( bodyControl.TextContent() ); |
|
211 |
|
212 CompleteStateAction(); |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CMsgMailLaunchOp::RestoreBodyL |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 void CMsgMailLaunchOp::RestoreBodyL() |
|
220 { |
|
221 iDocument.MessageL().GetBodyTextL( |
|
222 iStatus, |
|
223 iDocument.Entry().Id(), |
|
224 CImEmailMessage::EThisMessageOnly, |
|
225 *iBodyText, |
|
226 const_cast<CParaFormatLayer&> (*(iBodyText->GlobalParaFormatLayer())), |
|
227 const_cast<CCharFormatLayer&> (*(iBodyText->GlobalCharFormatLayer()))); |
|
228 SetActive(); |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CMsgMailLaunchOp::ConvertLineBreaksL |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CMsgMailLaunchOp::ConvertLineBreaksL() |
|
236 { |
|
237 ASSERT( iBodyText ); // must be available in this state already |
|
238 ConvertLineBreaksL( *iBodyText ); |
|
239 CompleteStateAction(); |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CMsgMailLaunchOp::RestoreAllAttasL |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 void CMsgMailLaunchOp::RestoreAllAttasL() |
|
247 { |
|
248 delete iRestoreSuperOp; |
|
249 iRestoreSuperOp = NULL; |
|
250 iRestoreSuperOp = CMsgMailRestoreSuperOp::NewL( iDocument ); |
|
251 iRestoreSuperOp->StartOp( iStatus ); |
|
252 SetActive(); |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CMsgMailLaunchOp::ExecuteViewL |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 void CMsgMailLaunchOp::ExecuteViewL() |
|
260 { |
|
261 iOpDelegate.DelegateExecuteViewL(); |
|
262 StopWaitNote(); |
|
263 CompleteStateAction(); |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CMsgMailLaunchOp::FinalizeL |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 void CMsgMailLaunchOp::FinalizeL() |
|
271 { |
|
272 iOpDelegate.DelegateFinalizeLaunchL(); |
|
273 iRestoreSuperOp->ShowNoteIfInvalidAttaL(); |
|
274 iRestoreSuperOp->ShowNoteIfDRMAttaL(); |
|
275 CompleteStateAction(); |
|
276 } |
|
277 |
|
278 // ---------------------------------------------------------------------------- |
|
279 // CMsgMailLaunchOp::ConvertLineBreaksL() |
|
280 // ---------------------------------------------------------------------------- |
|
281 // |
|
282 void CMsgMailLaunchOp::ConvertLineBreaksL( CRichText& aRtf ) const |
|
283 { |
|
284 HBufC* buf = HBufC::NewLC(aRtf.DocumentLength()); |
|
285 TPtr bufPtr = buf->Des(); |
|
286 aRtf.Extract(bufPtr); |
|
287 TInt count(0); |
|
288 for (TInt i(0); i < bufPtr.Length(); i++) |
|
289 { |
|
290 if (bufPtr[i] == CEditableText::ELineBreak) |
|
291 { |
|
292 count++; |
|
293 // Replace every 10th linebreak with paragraph to |
|
294 // make body text scrolling smoother. |
|
295 if (count == 10) // CSI: 47 # See a comment above. |
|
296 { |
|
297 bufPtr[i] = CEditableText::EParagraphDelimiter; |
|
298 count = 0; |
|
299 } |
|
300 } |
|
301 // Replace 'CRLF' or 'LF' with LineBreak. |
|
302 else if (bufPtr[i] == 0x0A) // Linefeed character (LF) |
|
303 { |
|
304 bufPtr[i] = CEditableText::ELineBreak; |
|
305 |
|
306 // Check if previous char was CR |
|
307 if ( i>0 && bufPtr[i-1] == 0x0D) // ascii (CR) |
|
308 { |
|
309 bufPtr.Delete( i-1, 1 ); // Delete CR |
|
310 } |
|
311 } |
|
312 } |
|
313 aRtf.DeleteL(0, aRtf.DocumentLength()); |
|
314 aRtf.InsertL(0, *buf); |
|
315 CleanupStack::PopAndDestroy( buf ); // buf |
|
316 } |
|
317 |
|
318 // End Of File |