|
1 /* |
|
2 * Copyright (c) 2006 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: Mail editor header content handler. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <MsgEditorView.h> |
|
19 #include <MsgEditor.hrh> |
|
20 #include "msgmaileditor.hrh" |
|
21 #include <MsgAddressControl.h> |
|
22 #include <MsgAttachmentControl.h> |
|
23 #include <MsgAttachmentModel.h> |
|
24 #include "cmsgmaileditorheader.h" |
|
25 #include "MsgMailEditorDocument.h" |
|
26 #include <MsgMailEditor.rsg> |
|
27 #include "CMailCRHandler.h" |
|
28 #include "MailInternalCRKeys.h" |
|
29 #include "MailLog.h" |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CMsgMailEditorHeader |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CMsgMailEditorHeader::CMsgMailEditorHeader( CMsgMailEditorDocument& aDocument, |
|
36 CMsgEditorView& aView): iDocument( aDocument ), |
|
37 iView( aView ) |
|
38 { |
|
39 iDocument.AttachmentModel().SetObserver( this ); |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // ConstructL |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 void CMsgMailEditorHeader::ConstructL() |
|
47 { |
|
48 CreateHeadersL(); |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // NewL |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CMsgMailEditorHeader* CMsgMailEditorHeader::NewL( |
|
56 CMsgMailEditorDocument& aDocument, |
|
57 CMsgEditorView& aView ) |
|
58 { |
|
59 CMsgMailEditorHeader* self = new( ELeave ) CMsgMailEditorHeader( |
|
60 aDocument, |
|
61 aView ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop( self ); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // ~CMsgMailEditorHeader |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CMsgMailEditorHeader::~CMsgMailEditorHeader() |
|
73 { |
|
74 |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // UpdateHeaderVisibilityL |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 void CMsgMailEditorHeader::UpdateHeaderVisibilityL( |
|
82 RPointerArray<TAdditionalHeaderStatus>& aHeaders ) |
|
83 { |
|
84 TInt focusedControl(KErrNotFound); |
|
85 TInt controlCount = 0; // to field is always present |
|
86 |
|
87 for ( TInt index=0; index< aHeaders.Count(); ++index ) |
|
88 { |
|
89 TAdditionalHeaderStatus* header = aHeaders[index]; |
|
90 TMsgControlId controlID = header->iHeaderValue; |
|
91 CMsgBaseControl* headerControl = |
|
92 iView.ControlById( controlID ); |
|
93 |
|
94 if ( headerControl ) |
|
95 { |
|
96 if ( header->iStatus == EHeaderHidden ) |
|
97 { |
|
98 iView.DeleteControlL(controlID ); |
|
99 } |
|
100 else |
|
101 { |
|
102 ++controlCount; |
|
103 } |
|
104 |
|
105 } |
|
106 else |
|
107 { |
|
108 if ( header->iStatus == EHeaderVisible || |
|
109 header->iStatus == EHeaderOnlySave ) |
|
110 { |
|
111 AddControlL( controlID ); |
|
112 focusedControl = controlID; |
|
113 } |
|
114 } |
|
115 |
|
116 } |
|
117 |
|
118 if ( focusedControl >=0 ) |
|
119 { |
|
120 iView.SetFocus( focusedControl ); |
|
121 } |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------------------------- |
|
125 // show / hide reply to control |
|
126 // ---------------------------------------------------------------------------- |
|
127 // |
|
128 void CMsgMailEditorHeader::UpdateReplyToControlL() |
|
129 { |
|
130 const CImHeader& header = iDocument.HeaderL(); |
|
131 TPtrC replyto = header.ReplyTo(); |
|
132 if ( replyto.Length() ) |
|
133 { |
|
134 AddControlL( EMailEditorControlReplyTo ); |
|
135 CMsgAddressControl* addressCtrl = static_cast<CMsgAddressControl*> ( |
|
136 iView.ControlById( EMailEditorControlReplyTo )); |
|
137 ASSERT( addressCtrl ); |
|
138 addressCtrl->Reset(); |
|
139 addressCtrl->SetReadOnly( ETrue ); |
|
140 |
|
141 MVPbkContactLink* link( NULL ); |
|
142 addressCtrl->AddRecipientL( |
|
143 KNullDesC(), replyto, ETrue, link ); |
|
144 } |
|
145 else |
|
146 { |
|
147 CMsgBaseControl* field = iView.RemoveControlL( |
|
148 EMailEditorControlReplyTo ); |
|
149 if ( field ) |
|
150 { |
|
151 field->Reset(); |
|
152 delete field; |
|
153 field = NULL; |
|
154 } |
|
155 } |
|
156 } |
|
157 |
|
158 // ---------------------------------------------------------------------------- |
|
159 // AddControlL |
|
160 // ---------------------------------------------------------------------------- |
|
161 // |
|
162 void CMsgMailEditorHeader::AddControlL( TInt aControlType ) |
|
163 { |
|
164 TInt resourceId(0); |
|
165 TInt controlType(0); |
|
166 |
|
167 switch (aControlType) |
|
168 { |
|
169 case EMsgComponentIdTo: |
|
170 { |
|
171 resourceId = R_MAIL_EDITOR_TO; |
|
172 controlType = EMsgAddressControl; |
|
173 break; |
|
174 } |
|
175 case EMsgComponentIdCc: |
|
176 { |
|
177 resourceId = R_MAIL_EDITOR_CC; |
|
178 controlType = EMsgAddressControl; |
|
179 break; |
|
180 } |
|
181 case EMsgComponentIdBcc: |
|
182 { |
|
183 resourceId = R_MAIL_EDITOR_BCC; |
|
184 controlType = EMsgAddressControl; |
|
185 break; |
|
186 } |
|
187 case EMailEditorControlReplyTo: |
|
188 { |
|
189 resourceId = R_MAIL_EDITOR_REPLYTO; |
|
190 controlType = EMsgAddressControl; |
|
191 break; |
|
192 } |
|
193 case EMsgComponentIdSubject: |
|
194 { |
|
195 resourceId = R_MAIL_EDITOR_SUBJECT; |
|
196 controlType = EMsgExpandableControl; |
|
197 break; |
|
198 } |
|
199 default: |
|
200 break; |
|
201 } |
|
202 |
|
203 if ( !iView.ControlById( aControlType ) ) |
|
204 { |
|
205 // Mail editor control order |
|
206 const TInt TControls[] = |
|
207 { |
|
208 EMsgComponentIdTo, |
|
209 EMsgComponentIdCc, |
|
210 EMsgComponentIdBcc, |
|
211 EMailEditorControlReplyTo, |
|
212 EMsgComponentIdSubject |
|
213 }; |
|
214 |
|
215 const TInt count( sizeof(TControls) / sizeof(TInt) ); |
|
216 TInt location( EMsgFirstControl ); // find correct location for control |
|
217 for( TInt index(0); index<count; ++index ) |
|
218 { |
|
219 __ASSERT_DEBUG( index >= 0 && index < count, User::Invariant() ); |
|
220 |
|
221 if ( iView.ControlById( TControls[ index ] ) && // CSI: 2 # This is checked above in the assert macro. |
|
222 TControls[ index ] != aControlType ) // CSI: 2 # This is checked above in the assert macro. |
|
223 { |
|
224 ++location; |
|
225 } |
|
226 else if ( TControls[ index ] == aControlType ) // CSI: 2 # This is checked above in the assert macro. |
|
227 { |
|
228 // we are here, so no need to check rest of controls |
|
229 break; |
|
230 } |
|
231 } |
|
232 |
|
233 iView.AddControlFromResourceL( |
|
234 resourceId, controlType, |
|
235 location, EMsgHeader); |
|
236 } |
|
237 } |
|
238 |
|
239 // ---------------------------------------------------------------------------- |
|
240 // AttachmentControl |
|
241 // ---------------------------------------------------------------------------- |
|
242 // |
|
243 CMsgAttachmentControl* CMsgMailEditorHeader::AttachmentControl() const |
|
244 { |
|
245 CMsgBaseControl* ctrl = iView.ControlById( EMsgComponentIdAttachment ); |
|
246 ASSERT( ctrl ); |
|
247 |
|
248 return static_cast<CMsgAttachmentControl*>( ctrl ); |
|
249 } |
|
250 |
|
251 // ---------------------------------------------------------------------------- |
|
252 // CreateHeadersL |
|
253 // ---------------------------------------------------------------------------- |
|
254 // |
|
255 void CMsgMailEditorHeader::CreateHeadersL() |
|
256 { |
|
257 AddControlL( EMsgComponentIdTo ); |
|
258 |
|
259 TInt headersvalue(0); |
|
260 CMsgMailPreferences& prefs = iDocument.SendOptions(); |
|
261 iDocument.MailCRHandler()->GetCRInt( |
|
262 KCRUidMail,KMailAdditionalHeaderSettings,headersvalue); |
|
263 prefs.SetAdditionalHeaders( headersvalue ); |
|
264 |
|
265 TAdditionalHeaderStatus header_status_cc; |
|
266 TAdditionalHeaderStatus header_status_bcc; |
|
267 TAdditionalHeaderStatus header_status_subject; |
|
268 |
|
269 header_status_cc.iStatus = |
|
270 prefs.GetAdditionalHeaderVisibility(EMsgComponentIdCc); |
|
271 header_status_bcc.iStatus = |
|
272 prefs.GetAdditionalHeaderVisibility(EMsgComponentIdBcc); |
|
273 header_status_subject.iStatus = |
|
274 prefs.GetAdditionalHeaderVisibility(EMsgComponentIdSubject); |
|
275 |
|
276 const CImHeader& header = iDocument.HeaderL(); |
|
277 const CDesCArray& ccArr = header.CcRecipients(); |
|
278 if(header_status_cc.iStatus == EHeaderVisible || ccArr.Count() > 0) |
|
279 { |
|
280 AddControlL(EMsgComponentIdCc); |
|
281 } |
|
282 // Check if bcc field is allowed |
|
283 if ( iDocument.MailCRHandler()->MailAdditionalHeaders() ) |
|
284 { |
|
285 const CDesCArray& bccArr = header.BccRecipients(); |
|
286 if(header_status_bcc.iStatus == EHeaderVisible || bccArr.Count() > 0) |
|
287 { |
|
288 AddControlL(EMsgComponentIdBcc); |
|
289 } |
|
290 } |
|
291 // Reply-to |
|
292 UpdateReplyToControlL(); |
|
293 |
|
294 // Subject |
|
295 const TPtrC& subjectStr = header.Subject(); |
|
296 if(header_status_subject.iStatus == |
|
297 EHeaderVisible || |
|
298 subjectStr.Length() > 0) |
|
299 { |
|
300 AddControlL(EMsgComponentIdSubject); |
|
301 } |
|
302 } |
|
303 |
|
304 // ---------------------------------------------------------------------------- |
|
305 // DoCreateAttachmentControlL |
|
306 // ---------------------------------------------------------------------------- |
|
307 // |
|
308 void CMsgMailEditorHeader::DoCreateAttachmentControlL() |
|
309 { |
|
310 if ( !iView.ControlById( EMsgComponentIdAttachment ) ) |
|
311 { |
|
312 LOG( "CMsgMailEditorAppUi::DoCreateAttachmentControlL() - create" ); |
|
313 CMsgAttachmentControl* control = |
|
314 CMsgAttachmentControl::NewL( iView, iView ); |
|
315 CleanupStack::PushL( control ); |
|
316 iView.AddControlL( control, |
|
317 EMsgComponentIdAttachment, |
|
318 EMsgAppendControl, |
|
319 EMsgHeader ); |
|
320 CleanupStack::Pop( control ); |
|
321 } |
|
322 } |
|
323 |
|
324 // ---------------------------------------------------------------------------- |
|
325 // DoRemoveAttachmentControlL |
|
326 // ---------------------------------------------------------------------------- |
|
327 // |
|
328 void CMsgMailEditorHeader::DoRemoveAttachmentControlL() |
|
329 { |
|
330 CMsgBaseControl* control = |
|
331 iView.RemoveControlL( EMsgComponentIdAttachment ); |
|
332 if ( control ) |
|
333 { |
|
334 delete control; |
|
335 control = NULL; |
|
336 } |
|
337 } |
|
338 |
|
339 // ---------------------------------------------------------------------------- |
|
340 // UpdateAttachmentControlL |
|
341 // ---------------------------------------------------------------------------- |
|
342 // |
|
343 void CMsgMailEditorHeader::UpdateAttachmentControlL( |
|
344 TMsgAttachmentCommand aCommand, |
|
345 CMsgAttachmentInfo* aAttachmentInfo ) |
|
346 { |
|
347 CMsgAttachmentModel& model = iDocument.AttachmentModel(); |
|
348 if ( aCommand == EMsgAttachmentAdded ) |
|
349 { |
|
350 DoCreateAttachmentControlL(); |
|
351 AttachmentControl()->AddAttachmentsL( model ); |
|
352 } |
|
353 else // to be removed |
|
354 { |
|
355 if ( model.NumberOfItems() == 1 ) // 1 = we are removing last atta |
|
356 { |
|
357 DoRemoveAttachmentControlL(); |
|
358 } |
|
359 else |
|
360 { |
|
361 ASSERT( aAttachmentInfo ); |
|
362 TParsePtrC fileParser( aAttachmentInfo->FileName() ); |
|
363 AttachmentControl()->RemoveAttachmentL( |
|
364 fileParser.NameAndExt() ); |
|
365 } |
|
366 } |
|
367 } |
|
368 |
|
369 // --------------------------------------------------------------------------- |
|
370 // From class MMsgAttachmentModelObserver. |
|
371 // NotifyChanges |
|
372 // --------------------------------------------------------------------------- |
|
373 // |
|
374 void CMsgMailEditorHeader::NotifyChanges( |
|
375 TMsgAttachmentCommand aCommand, |
|
376 CMsgAttachmentInfo* aAttachmentInfo ) |
|
377 { |
|
378 LOG1( "CMsgMailEditorHeader::NotifyChanges: %d", aCommand ); |
|
379 iDocument.NotifyChanges( aCommand, aAttachmentInfo ); |
|
380 TRAP_IGNORE( UpdateAttachmentControlL( aCommand, aAttachmentInfo ) ); |
|
381 } |
|
382 |
|
383 // --------------------------------------------------------------------------- |
|
384 // From class MMsgAttachmentModelObserver. |
|
385 // GetAttachmentFileL |
|
386 // --------------------------------------------------------------------------- |
|
387 // |
|
388 RFile CMsgMailEditorHeader::GetAttachmentFileL( TMsvAttachmentId aId ) |
|
389 { |
|
390 return iDocument.GetAttachmentFileL( aId ); |
|
391 } |
|
392 |
|
393 // End of File |
|
394 |