|
1 /* |
|
2 * Copyright (c) 2009 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: MR viewer attahcment field implementation |
|
15 * |
|
16 */ |
|
17 #include "cmrviewerattachmentfield.h" |
|
18 |
|
19 #include "mesmrlistobserver.h" |
|
20 #include "mesmrmeetingrequestentry.h" |
|
21 #include "nmrlayoutmanager.h" |
|
22 #include "nmrbitmapmanager.h" |
|
23 #include "cmrimage.h" |
|
24 #include "cesmrrichtextviewer.h" |
|
25 #include "cesmreditor.h" |
|
26 #include "cesmrrichtextlink.h" |
|
27 #include "cmrattachmentcommandhandler.h" |
|
28 #include "ccalremoteattachmentapi.h" |
|
29 #include "ccalremoteattachmentinfo.h" |
|
30 #include "mcalremoteattachmentoperation.h" |
|
31 #include "cesmrglobalnote.h" |
|
32 |
|
33 #include <aknsbasicbackgroundcontrolcontext.h> |
|
34 #include <calentry.h> |
|
35 #include <calattachment.h> |
|
36 #include <stringloader.h> |
|
37 #include <esmrgui.rsg> |
|
38 #include <gulicon.h> |
|
39 #include <ct/rcpointerarray.h> |
|
40 #include <aknbiditextutils.h> |
|
41 #include <badesca.h> |
|
42 |
|
43 // DEBUG |
|
44 #include "emailtrace.h" |
|
45 |
|
46 |
|
47 // unnamed namespace for local definitions |
|
48 namespace { // codescanner::namespace |
|
49 //CONSTANTS |
|
50 |
|
51 _LIT( KNewLine, "\f" ); |
|
52 |
|
53 const TInt KOneKiloByte( 1024 ); |
|
54 const TInt KOneMegaByte( 1048576 ); // (1024^2 or 2^20): |
|
55 const TInt KMargin = 5; |
|
56 |
|
57 /** |
|
58 * Checks that command is valid attachment viewer command. |
|
59 * @param aCommmand Command ID |
|
60 */ |
|
61 TBool IsValidAttachmentViewerCommand( TInt aCommand ) |
|
62 { |
|
63 TBool ret( EFalse ); |
|
64 |
|
65 switch( aCommand ) |
|
66 { |
|
67 case EESMRViewerOpenAttachment: |
|
68 case EESMRViewerSaveAttachment: |
|
69 case EESMRViewerSaveAllAttachments: |
|
70 case EESMRViewerCancelAttachmentDownload: |
|
71 ret = ETrue; |
|
72 break; |
|
73 |
|
74 default: |
|
75 ret = EFalse; |
|
76 break; |
|
77 } |
|
78 |
|
79 return ret; |
|
80 } |
|
81 |
|
82 }//namespace |
|
83 |
|
84 // ======== MEMBER FUNCTIONS ======== |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // CMRViewerAttachmentsField::CMRViewerAttachmentsField |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 CMRViewerAttachmentsField::CMRViewerAttachmentsField() |
|
91 { |
|
92 FUNC_LOG; |
|
93 SetFocusType( EESMRHighlightFocus ); |
|
94 SetFieldId( EESMRFieldViewerAttachments ); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CMRViewerAttachmentsField::~CMRViewerAttachmentsField |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 CMRViewerAttachmentsField::~CMRViewerAttachmentsField( ) |
|
102 { |
|
103 FUNC_LOG; |
|
104 delete iBgCtrlContext; |
|
105 delete iFieldIcon; |
|
106 delete iLockIcon; |
|
107 delete iAttachmentCommandHandler; |
|
108 delete iRemoteAttUris; |
|
109 delete iAttachmentInfo; |
|
110 delete iRemoteAttApi; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CMRViewerAttachmentsField::NewL |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 CMRViewerAttachmentsField* CMRViewerAttachmentsField::NewL() |
|
118 { |
|
119 FUNC_LOG; |
|
120 CMRViewerAttachmentsField* self = new( ELeave )CMRViewerAttachmentsField(); |
|
121 CleanupStack::PushL ( self ); |
|
122 self->ConstructL ( ); |
|
123 CleanupStack::Pop ( self ); |
|
124 return self; |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CMRViewerAttachmentsField::ConstructL |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void CMRViewerAttachmentsField::ConstructL( ) |
|
132 { |
|
133 FUNC_LOG; |
|
134 SetComponentsToInheritVisibility( ETrue ); |
|
135 |
|
136 iFieldIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapAttachment ); |
|
137 iFieldIcon->SetParent( this ); |
|
138 |
|
139 iRichTextViewer = CESMRRichTextViewer::NewL( this ); |
|
140 CESMRField::ConstructL( iRichTextViewer ); // ownership transferred |
|
141 iRichTextViewer->SetEdwinSizeObserver ( this ); |
|
142 iRichTextViewer->SetLinkObserver (this ); |
|
143 iRichTextViewer->SetParent( this ); |
|
144 |
|
145 // Draw bg instead of using skin bg |
|
146 TRect tempRect( 0, 0, 0, 0 ); |
|
147 NMRBitmapManager::TMRBitmapStruct bitmapStruct; |
|
148 bitmapStruct = NMRBitmapManager::GetBitmapStruct( |
|
149 NMRBitmapManager::EMRBitmapInputCenter ); |
|
150 |
|
151 iBgCtrlContext = CAknsBasicBackgroundControlContext::NewL( |
|
152 bitmapStruct.iItemId, |
|
153 tempRect, |
|
154 EFalse ); |
|
155 |
|
156 iRichTextViewer->SetSkinBackgroundControlContextL( iBgCtrlContext ); |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // CMRViewerAttachmentsField::MinimumSize |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 TSize CMRViewerAttachmentsField::MinimumSize() |
|
164 { |
|
165 TRect parentRect( Parent()->Rect() ); |
|
166 |
|
167 TRect fieldRect = |
|
168 NMRLayoutManager::GetFieldLayoutRect( parentRect, 1 ).Rect(); |
|
169 |
|
170 TRect viewerRect( NMRLayoutManager::GetLayoutText( |
|
171 fieldRect, |
|
172 NMRLayoutManager::EMRTextLayoutTextEditor ).TextRect() ); |
|
173 |
|
174 // Adjust field size so that there's room for expandable editor. |
|
175 fieldRect.Resize( 0, iRichTextSize.iHeight - viewerRect.Height() ); |
|
176 |
|
177 return fieldRect.Size(); |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CMRViewerAttachmentsField::InitializeL |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 void CMRViewerAttachmentsField::InitializeL() |
|
185 { |
|
186 FUNC_LOG; |
|
187 TAknLayoutText layoutText = |
|
188 NMRLayoutManager::GetLayoutText( Rect(), |
|
189 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
190 iRichTextViewer->SetFontL( layoutText.Font() ); |
|
191 if( iAttachmentCount > 1 ) |
|
192 { |
|
193 iRichTextViewer->SetLineSpacingL( LineSpacing() ); |
|
194 } |
|
195 |
|
196 iRichTextViewer->ApplyLayoutChangesL(); |
|
197 |
|
198 //wake up current contact menu selection by calling this |
|
199 iRichTextViewer->FocusChanged( ENoDrawNow ); |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // CMRViewerAttachmentsField::InternalizeL |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 void CMRViewerAttachmentsField::InternalizeL( MESMRCalEntry& aEntry ) |
|
207 { |
|
208 FUNC_LOG; |
|
209 |
|
210 delete iAttachmentCommandHandler; |
|
211 iAttachmentCommandHandler = NULL; |
|
212 |
|
213 iEntry = &aEntry; |
|
214 |
|
215 CreateRemoteAttApiL(); |
|
216 UpdateAttachmentsListL(); |
|
217 |
|
218 if ( iAttachmentCount ) |
|
219 { |
|
220 //wake up current contact menu selection by calling this |
|
221 iRichTextViewer->FocusChanged( ENoDrawNow ); |
|
222 iDisableRedraw = ETrue; |
|
223 iAttachmentCommandHandler = |
|
224 CMRAttachmentCommandHandler::NewL( iEntry->Entry(), *iEventQueue ); |
|
225 |
|
226 if ( iRemoteAttApi ) |
|
227 { |
|
228 iAttachmentCommandHandler->SetRemoteAttachmentInformationL( |
|
229 *iRemoteAttApi, |
|
230 *iAttachmentInfo ); |
|
231 } |
|
232 } |
|
233 else |
|
234 { |
|
235 iObserver->HideControl( EESMRFieldViewerAttachments ); |
|
236 } |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // CMRViewerAttachmentsField::ExternalizeL |
|
241 // --------------------------------------------------------------------------- |
|
242 // |
|
243 void CMRViewerAttachmentsField::ExternalizeL( MESMRCalEntry& /*aEntry*/ ) |
|
244 { |
|
245 FUNC_LOG; |
|
246 // No implementation |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // CMRViewerAttachmentsField::CountComponentControls |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 TInt CMRViewerAttachmentsField::CountComponentControls( ) const |
|
254 { |
|
255 FUNC_LOG; |
|
256 TInt count( 0 ); |
|
257 if ( iFieldIcon ) |
|
258 { |
|
259 ++count; |
|
260 } |
|
261 |
|
262 if ( iRichTextViewer ) |
|
263 { |
|
264 ++count; |
|
265 } |
|
266 |
|
267 if ( iLockIcon ) |
|
268 { |
|
269 ++count; |
|
270 } |
|
271 |
|
272 return count; |
|
273 |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 // CMRViewerAttachmentsField::ComponentControl |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 CCoeControl* CMRViewerAttachmentsField::ComponentControl( TInt aInd ) const |
|
281 { |
|
282 FUNC_LOG; |
|
283 switch ( aInd ) |
|
284 { |
|
285 case 0: |
|
286 return iRichTextViewer; |
|
287 case 1: |
|
288 return iFieldIcon; |
|
289 case 2: |
|
290 return iLockIcon; |
|
291 default: |
|
292 return NULL; |
|
293 } |
|
294 } |
|
295 |
|
296 // --------------------------------------------------------------------------- |
|
297 // CMRViewerAttachmentsField::SizeChanged |
|
298 // --------------------------------------------------------------------------- |
|
299 // |
|
300 void CMRViewerAttachmentsField::SizeChanged( ) |
|
301 { |
|
302 FUNC_LOG; |
|
303 TRect rect( Rect() ); |
|
304 |
|
305 TAknLayoutRect rowLayoutRect( |
|
306 NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ) ); |
|
307 TRect rowRect( rowLayoutRect.Rect() ); |
|
308 |
|
309 // Layouting field icon |
|
310 if( iFieldIcon ) |
|
311 { |
|
312 TAknWindowComponentLayout iconLayout( |
|
313 NMRLayoutManager::GetWindowComponentLayout( |
|
314 NMRLayoutManager::EMRLayoutSingleRowAColumnGraphic ) ); |
|
315 AknLayoutUtils::LayoutControl( iFieldIcon, rowRect, iconLayout ); |
|
316 } |
|
317 |
|
318 // Layouting lock icon |
|
319 if( iLockIcon ) |
|
320 { |
|
321 TAknWindowComponentLayout iconLayout( |
|
322 NMRLayoutManager::GetWindowComponentLayout( |
|
323 NMRLayoutManager::EMRLayoutSingleRowDColumnGraphic ) ); |
|
324 AknLayoutUtils::LayoutImage( iLockIcon, rowRect, iconLayout ); |
|
325 } |
|
326 |
|
327 // Layouting viewer rect |
|
328 TAknLayoutText viewerLayoutText; |
|
329 if( iLockIcon ) |
|
330 { |
|
331 viewerLayoutText = NMRLayoutManager::GetLayoutText( rowRect, |
|
332 NMRLayoutManager::EMRTextLayoutSingleRowEditorText ); |
|
333 } |
|
334 else |
|
335 { |
|
336 viewerLayoutText = NMRLayoutManager::GetLayoutText( rowRect, |
|
337 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
338 } |
|
339 |
|
340 TRect viewerRect( viewerLayoutText.TextRect() ); |
|
341 |
|
342 // Resize height according to actual height required by edwin. |
|
343 viewerRect.Resize( 0, iSize.iHeight - viewerRect.Height() ); |
|
344 iRichTextViewer->SetRect( viewerRect ); |
|
345 |
|
346 // Layouting focus |
|
347 TRect bgRect( 0, 0, 0, 0 ); |
|
348 if( iAttachmentCount > 1 ) |
|
349 { |
|
350 bgRect.SetRect( |
|
351 TPoint( viewerRect.iTl.iX, |
|
352 viewerRect.iTl.iY - FocusMargin() ), |
|
353 TPoint( viewerRect.iBr.iX, |
|
354 viewerRect.iBr.iY + FocusMargin() ) ); |
|
355 } |
|
356 else |
|
357 { |
|
358 TAknLayoutRect bgLayoutRect = |
|
359 NMRLayoutManager::GetLayoutRect( |
|
360 rowRect, NMRLayoutManager::EMRLayoutTextEditorBg ); |
|
361 bgRect = bgLayoutRect.Rect(); |
|
362 } |
|
363 |
|
364 // Move focus rect so that it's relative to field's position. |
|
365 bgRect.Move( -Position() ); |
|
366 SetFocusRect( bgRect ); |
|
367 |
|
368 // Failures are ignored. |
|
369 TRAP_IGNORE( |
|
370 // Set font |
|
371 iRichTextViewer->SetFontL( viewerLayoutText.Font() ); |
|
372 if( iAttachmentCount > 1 ) |
|
373 { |
|
374 // Set line spacing |
|
375 iRichTextViewer->SetLineSpacingL( LineSpacing() ); |
|
376 } |
|
377 |
|
378 // Apply changes. |
|
379 iRichTextViewer->ApplyLayoutChangesL(); |
|
380 ) |
|
381 } |
|
382 |
|
383 // --------------------------------------------------------------------------- |
|
384 // CMRViewerAttachmentsField::OfferKeyEventL |
|
385 // --------------------------------------------------------------------------- |
|
386 // |
|
387 TKeyResponse CMRViewerAttachmentsField::OfferKeyEventL( |
|
388 const TKeyEvent& aEvent, |
|
389 TEventCode aType ) |
|
390 { |
|
391 FUNC_LOG; |
|
392 TKeyResponse response( EKeyWasNotConsumed ); |
|
393 |
|
394 if( iAttachmentCount > 0 ) |
|
395 { |
|
396 response = iRichTextViewer->OfferKeyEventL( aEvent, aType ); |
|
397 } |
|
398 |
|
399 return response; |
|
400 } |
|
401 |
|
402 // --------------------------------------------------------------------------- |
|
403 // CMRViewerAttachmentsField::SetContainerWindowL() |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 void CMRViewerAttachmentsField::SetContainerWindowL( const CCoeControl& aControl ) |
|
407 { |
|
408 FUNC_LOG; |
|
409 CESMRField::SetContainerWindowL( aControl ); |
|
410 iRichTextViewer->SetContainerWindowL( aControl ); |
|
411 iRichTextViewer->SetParent( this ); |
|
412 |
|
413 iFieldIcon->SetContainerWindowL( aControl ); |
|
414 iFieldIcon->SetParent( this ); |
|
415 |
|
416 iButtonGroupContainer = CEikButtonGroupContainer::Current(); |
|
417 } |
|
418 |
|
419 // --------------------------------------------------------------------------- |
|
420 // CMRViewerAttachmentsField::HandleEdwinSizeEventL |
|
421 // --------------------------------------------------------------------------- |
|
422 // |
|
423 TBool CMRViewerAttachmentsField::HandleEdwinSizeEventL( CEikEdwin* aEdwin, |
|
424 TEdwinSizeEvent /*aType*/, TSize aSize ) |
|
425 { |
|
426 FUNC_LOG; |
|
427 TBool reDraw( EFalse ); |
|
428 |
|
429 if( iRichTextSize.iHeight != aSize.iHeight && iAttachmentCount > 0 ) |
|
430 { |
|
431 // Let's save the required size of the rich text viewer |
|
432 iRichTextSize = aSize; |
|
433 |
|
434 if ( iObserver && aEdwin == iRichTextViewer ) |
|
435 { |
|
436 iObserver->ControlSizeChanged( this ); |
|
437 reDraw = ETrue; |
|
438 } |
|
439 } |
|
440 |
|
441 return reDraw; |
|
442 } |
|
443 |
|
444 // --------------------------------------------------------------------------- |
|
445 // CMRViewerAttachmentsField::ListObserverSet |
|
446 // --------------------------------------------------------------------------- |
|
447 // |
|
448 void CMRViewerAttachmentsField::ListObserverSet() |
|
449 { |
|
450 FUNC_LOG; |
|
451 iRichTextViewer->SetListObserver( iObserver ); |
|
452 } |
|
453 |
|
454 // --------------------------------------------------------------------------- |
|
455 // CMRViewerAttachmentsField::ExecuteGenericCommandL |
|
456 // --------------------------------------------------------------------------- |
|
457 // |
|
458 TBool CMRViewerAttachmentsField::ExecuteGenericCommandL( TInt aCommand ) |
|
459 { |
|
460 FUNC_LOG; |
|
461 // TODO: Changes from other fields have to be implemented here |
|
462 TBool handled( EFalse ); |
|
463 |
|
464 //handle locked field first |
|
465 if( IsLocked() ) |
|
466 { |
|
467 if( aCommand == EESMRViewerOpenAttachment || |
|
468 aCommand == EAknCmdOpen ) |
|
469 { |
|
470 HandleTactileFeedbackL(); |
|
471 |
|
472 CESMRGlobalNote::ExecuteL( |
|
473 CESMRGlobalNote::EESMRUnableToEdit ); |
|
474 return ETrue; |
|
475 } |
|
476 } |
|
477 |
|
478 if ( IsValidAttachmentViewerCommand(aCommand) && iAttachmentCommandHandler ) |
|
479 { |
|
480 const CESMRRichTextLink* currentLink = iRichTextViewer->GetSelectedLink(); |
|
481 |
|
482 ASSERT( currentLink ); |
|
483 |
|
484 TBool remoteCommand( |
|
485 iAttachmentCommandHandler->IsRemoteAttachmentL( *currentLink) ); |
|
486 |
|
487 if ( !remoteCommand ) |
|
488 { |
|
489 iAttachmentCommandHandler->HandleAttachmentCommandL( |
|
490 aCommand, |
|
491 *currentLink ); |
|
492 |
|
493 HandleTactileFeedbackL(); |
|
494 } |
|
495 else |
|
496 { |
|
497 iAttachmentCommandHandler->HandleRemoteAttachmentCommandL( |
|
498 aCommand, |
|
499 *currentLink ); |
|
500 |
|
501 HandleTactileFeedbackL(); |
|
502 } |
|
503 |
|
504 handled = ETrue; |
|
505 } |
|
506 return handled; |
|
507 } |
|
508 |
|
509 // --------------------------------------------------------------------------- |
|
510 // CMRViewerAttachmentsField::SetOutlineFocusL |
|
511 // --------------------------------------------------------------------------- |
|
512 // |
|
513 void CMRViewerAttachmentsField::SetOutlineFocusL( TBool aFocus ) |
|
514 { |
|
515 FUNC_LOG; |
|
516 CESMRField::SetOutlineFocusL( aFocus ); |
|
517 |
|
518 if ( aFocus && iAttachmentCount) |
|
519 { |
|
520 ChangeMiddleSoftKeyL( |
|
521 EAknSoftkeyContextOptions, |
|
522 R_QTN_MSK_OPEN ); |
|
523 } |
|
524 } |
|
525 |
|
526 // ----------------------------------------------------------------------------- |
|
527 // CMRViewerAttachmentsField::HandleRichTextLinkSelection |
|
528 // ----------------------------------------------------------------------------- |
|
529 // |
|
530 TBool CMRViewerAttachmentsField::HandleRichTextLinkSelection( |
|
531 const CESMRRichTextLink* aLink ) |
|
532 { |
|
533 FUNC_LOG; |
|
534 TBool ret( EFalse ); |
|
535 |
|
536 // Open context menu in editor and viewer modes with link selection |
|
537 if ( aLink->Type() == CESMRRichTextLink::ETypeAttachment ) |
|
538 { |
|
539 TRAP_IGNORE( NotifyEventL( EMRLaunchAttachmentContextMenu )); |
|
540 ret = ETrue; |
|
541 |
|
542 TRAP_IGNORE( HandleTactileFeedbackL() ); |
|
543 } |
|
544 |
|
545 return ret; |
|
546 } |
|
547 |
|
548 // ----------------------------------------------------------------------------- |
|
549 // CMRViewerAttachmentsField::UpdateAttachmentsListL |
|
550 // ----------------------------------------------------------------------------- |
|
551 // |
|
552 void CMRViewerAttachmentsField::UpdateAttachmentsListL() |
|
553 { |
|
554 FUNC_LOG; |
|
555 |
|
556 |
|
557 if ( iRemoteAttApi ) |
|
558 { |
|
559 // Let's fetch remote attachment information |
|
560 iRemoteAttApi->AttachmentInfo( |
|
561 *iAttachmentInfo, |
|
562 *iRemoteAttUris ); |
|
563 } |
|
564 |
|
565 RBuf buffer; // codescanner::resourcenotoncleanupstack |
|
566 buffer.CleanupClosePushL(); |
|
567 |
|
568 RCPointerArray<CESMRRichTextLink> attachmentLinks; |
|
569 CleanupClosePushL( attachmentLinks ); |
|
570 |
|
571 TAknLayoutText layoutText = NMRLayoutManager::GetLayoutText( |
|
572 Rect(), |
|
573 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
574 |
|
575 iAttachmentCount = iEntry->Entry().AttachmentCountL(); |
|
576 attachmentLinks.ReserveL( iAttachmentCount ); |
|
577 for ( TInt i = 0; i < iAttachmentCount; ++i ) |
|
578 { |
|
579 CCalAttachment* att = iEntry->Entry().AttachmentL( i ); // Ownership not gained |
|
580 |
|
581 // Reducing space required by file size information from |
|
582 // max line width, so that file name can be trimmed to correct |
|
583 // length |
|
584 TInt maxLineWidth = layoutText.TextRect().Width(); |
|
585 const CFont* font = layoutText.Font(); |
|
586 |
|
587 HBufC* attachmentSize = AttachmentNameAndSizeL( KNullDesC(), *att ); |
|
588 TInt attachmentSizeLength = attachmentSize->Length(); |
|
589 maxLineWidth -= font->TextWidthInPixels( *attachmentSize ); |
|
590 delete attachmentSize; |
|
591 attachmentSize = NULL; |
|
592 |
|
593 // TODO: correct icon zise to correct one. Ask from UI specifier. |
|
594 TSize iconSize( 20, 20); |
|
595 maxLineWidth -= iconSize.iWidth; |
|
596 |
|
597 // Trimming file name to fit to one line |
|
598 TPtrC text = att->Label(); |
|
599 HBufC* clippedTextHBufC = ClipTextLC( text, *font, maxLineWidth ); |
|
600 TPtr clippedText = clippedTextHBufC->Des(); |
|
601 clippedText.Trim(); |
|
602 |
|
603 if ( clippedText.Length() > 0 ) |
|
604 { |
|
605 // Creating rich text link |
|
606 CESMRRichTextLink* link = CESMRRichTextLink::NewL( |
|
607 buffer.Length(), |
|
608 clippedText.Length() + attachmentSizeLength, |
|
609 text, |
|
610 CESMRRichTextLink::ETypeAttachment, |
|
611 CESMRRichTextLink::ETriggerKeyRight ); |
|
612 CleanupStack::PushL( link ); |
|
613 attachmentLinks.AppendL( link ); |
|
614 CleanupStack::Pop( link ); |
|
615 |
|
616 HBufC* buf = AttachmentNameAndSizeL( clippedText, *att ); |
|
617 CleanupStack::PushL( buf ); |
|
618 |
|
619 // Append attachment name and size with line feed to buffer |
|
620 buffer.ReAllocL( buffer.Length() + |
|
621 clippedText.Length() + |
|
622 buf->Length() + |
|
623 KNewLine().Length() ); |
|
624 |
|
625 buffer.Append( buf->Des() ); |
|
626 buffer.Append( KNewLine ); |
|
627 |
|
628 CleanupStack::PopAndDestroy( buf ); |
|
629 } |
|
630 |
|
631 CleanupStack::PopAndDestroy( clippedTextHBufC ); |
|
632 } |
|
633 |
|
634 // Remove unnecessary new line from the end of buffer. |
|
635 if ( buffer.Length() >= KNewLine().Length() ) |
|
636 { |
|
637 buffer.SetLength( buffer.Length() - KNewLine().Length() ); |
|
638 } |
|
639 |
|
640 // Adding all rich text links to the rich text viewer |
|
641 if ( buffer.Length() > 0 ) |
|
642 { |
|
643 iRichTextViewer->SetTextL( &buffer ); |
|
644 iRichTextViewer->SetFontL( layoutText.Font() ); |
|
645 if( iAttachmentCount > 1 ) |
|
646 { |
|
647 iRichTextViewer->SetLineSpacingL( LineSpacing() ); |
|
648 } |
|
649 |
|
650 iRichTextViewer->ApplyLayoutChangesL(); |
|
651 |
|
652 iRichTextViewer->SetMargins( KMargin ); // What's this? |
|
653 iRichTextViewer->HandleTextChangedL(); |
|
654 |
|
655 while ( attachmentLinks.Count() > 0 ) |
|
656 { |
|
657 CESMRRichTextLink* link = attachmentLinks[0]; |
|
658 CleanupStack::PushL( link ); |
|
659 attachmentLinks.Remove( 0 ); |
|
660 iRichTextViewer->AddLinkL( link ); |
|
661 CleanupStack::Pop( link ); |
|
662 } |
|
663 } |
|
664 |
|
665 CleanupStack::PopAndDestroy( &attachmentLinks ); |
|
666 CleanupStack::PopAndDestroy( &buffer ); |
|
667 |
|
668 if ( iAttachmentCount ) |
|
669 { |
|
670 ChangeMiddleSoftKeyL( |
|
671 EAknSoftkeyContextOptions, |
|
672 R_QTN_MSK_OPEN ); |
|
673 } |
|
674 } |
|
675 |
|
676 // ----------------------------------------------------------------------------- |
|
677 // CMRViewerAttachmentsField::ClipTextLC |
|
678 // ----------------------------------------------------------------------------- |
|
679 // |
|
680 HBufC* CMRViewerAttachmentsField::ClipTextLC( |
|
681 const TDesC& aText, const CFont& aFont, TInt aWidth ) |
|
682 { |
|
683 FUNC_LOG; |
|
684 HBufC* text = HBufC::NewLC( aText.Length() + KAknBidiExtraSpacePerLine ); |
|
685 TPtr textPtr = text->Des(); |
|
686 AknBidiTextUtils::ConvertToVisualAndClip( |
|
687 aText, textPtr, aFont, aWidth, aWidth ); |
|
688 return text; |
|
689 } |
|
690 |
|
691 // --------------------------------------------------------------------------- |
|
692 // CMRViewerAttachmentsField::AttachmentNameAndSizeL |
|
693 // --------------------------------------------------------------------------- |
|
694 // |
|
695 HBufC* CMRViewerAttachmentsField::AttachmentNameAndSizeL( |
|
696 const TDesC& aDes, |
|
697 const CCalAttachment& aAttachment ) |
|
698 { |
|
699 HBufC* stringholder = NULL; |
|
700 |
|
701 CDesCArrayFlat* attachmentStrings = |
|
702 new(ELeave)CDesCArrayFlat( 1 ); |
|
703 CleanupStack::PushL( attachmentStrings ); |
|
704 |
|
705 CArrayFixFlat<TInt>* integers = |
|
706 new (ELeave) CArrayFixFlat<TInt>(1); |
|
707 CleanupStack::PushL( integers ); |
|
708 |
|
709 CCalAttachment::TType attType( aAttachment.Type() ); |
|
710 |
|
711 TInt attachmentSize(0); |
|
712 if ( CCalAttachment::EFile == attType ) |
|
713 { |
|
714 attachmentSize = aAttachment.FileAttachment()->Size(); |
|
715 } |
|
716 else if ( iAttachmentInfo && iAttachmentInfo->AttachmentCount() ) |
|
717 { |
|
718 TInt remoteAttCount( iAttachmentInfo->AttachmentCount() ); |
|
719 for ( TInt i(0); i < remoteAttCount; ++i ) |
|
720 { |
|
721 TPtrC label( aAttachment.Label() ); |
|
722 TPtrC remoteLabel( |
|
723 iAttachmentInfo->AttachmentL(i).AttachmentLabel() ); |
|
724 if ( !label.Compare( remoteLabel ) ) |
|
725 { |
|
726 attachmentSize = iAttachmentInfo->AttachmentL(i).AttachmentSizeInBytes(); |
|
727 } |
|
728 } |
|
729 } |
|
730 |
|
731 if ( attachmentSize >= KOneMegaByte ) |
|
732 { |
|
733 attachmentStrings->AppendL( aDes ); |
|
734 |
|
735 integers->AppendL( attachmentSize / KOneMegaByte ); |
|
736 |
|
737 stringholder = StringLoader::LoadLC( |
|
738 R_MEET_REQ_ATTACHMENT_FILE_MEGABYTE, |
|
739 *attachmentStrings, |
|
740 *integers ); |
|
741 } |
|
742 else if (( attachmentSize < KOneKiloByte ) && (attachmentSize != 0)) |
|
743 { |
|
744 attachmentStrings->AppendL( aDes ); |
|
745 |
|
746 stringholder = StringLoader::LoadLC( |
|
747 R_MEET_REQ_ATTACHMENT_FILE_LESS_THAN_KILOBYTE , |
|
748 *attachmentStrings ); |
|
749 } |
|
750 else |
|
751 { |
|
752 attachmentStrings->AppendL( aDes ); |
|
753 |
|
754 integers->AppendL( attachmentSize / KOneKiloByte ); |
|
755 |
|
756 stringholder = StringLoader::LoadLC( |
|
757 R_MEET_REQ_ATTACHMENT_FILE_KILOBYTE, |
|
758 *attachmentStrings, |
|
759 *integers ); |
|
760 } |
|
761 |
|
762 CleanupStack::Pop( stringholder ); |
|
763 CleanupStack::PopAndDestroy( integers ); |
|
764 CleanupStack::PopAndDestroy( attachmentStrings ); |
|
765 |
|
766 return stringholder; |
|
767 } |
|
768 |
|
769 // --------------------------------------------------------------------------- |
|
770 // CMRViewerAttachmentsField::HandleLongtapEventL |
|
771 // --------------------------------------------------------------------------- |
|
772 // |
|
773 void CMRViewerAttachmentsField::HandleLongtapEventL( const TPoint& aPosition ) |
|
774 { |
|
775 FUNC_LOG; |
|
776 |
|
777 if ( iRichTextViewer->Rect().Contains( aPosition ) ) |
|
778 { |
|
779 if( iRichTextViewer->LinkSelectedL() ) |
|
780 { |
|
781 HandleTactileFeedbackL(); |
|
782 } |
|
783 } |
|
784 } |
|
785 |
|
786 // --------------------------------------------------------------------------- |
|
787 // CMRViewerAttachmentsField::HandleRawPointerEventL |
|
788 // --------------------------------------------------------------------------- |
|
789 // |
|
790 TBool CMRViewerAttachmentsField::HandleRawPointerEventL( |
|
791 const TPointerEvent& aPointerEvent ) |
|
792 { |
|
793 FUNC_LOG; |
|
794 // Handles short on attachment fields actual attachments |
|
795 TBool ret( EFalse ); |
|
796 |
|
797 if( iAttachmentCount > 0 && |
|
798 aPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
799 { |
|
800 if( iRichTextViewer->Rect().Contains( aPointerEvent.iPosition ) ) |
|
801 { |
|
802 iRichTextViewer->HandlePointerEventL( aPointerEvent ); |
|
803 ret = ETrue; |
|
804 } |
|
805 } |
|
806 |
|
807 return ret; |
|
808 } |
|
809 |
|
810 // --------------------------------------------------------------------------- |
|
811 // CMRViewerAttachmentsField::DynInitMenuPaneL |
|
812 // --------------------------------------------------------------------------- |
|
813 // |
|
814 void CMRViewerAttachmentsField::DynInitMenuPaneL( |
|
815 TInt aResourceId, |
|
816 CEikMenuPane* aMenuPane ) |
|
817 { |
|
818 FUNC_LOG; |
|
819 |
|
820 if ( R_MR_VIEWER_ATTACHMENT_MENU == aResourceId ) |
|
821 { |
|
822 DynInitMenuPaneForCurrentAttachmentL( aMenuPane ); |
|
823 } |
|
824 } |
|
825 |
|
826 // --------------------------------------------------------------------------- |
|
827 // CMRViewerAttachmentsField::LockL |
|
828 // --------------------------------------------------------------------------- |
|
829 // |
|
830 void CMRViewerAttachmentsField::LockL() |
|
831 { |
|
832 FUNC_LOG; |
|
833 if( IsLocked() ) |
|
834 { |
|
835 return; |
|
836 } |
|
837 |
|
838 CESMRField::LockL(); |
|
839 |
|
840 delete iLockIcon; |
|
841 iLockIcon = NULL; |
|
842 iLockIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapLockField, ETrue ); |
|
843 iLockIcon->SetParent( this ); |
|
844 } |
|
845 |
|
846 // --------------------------------------------------------------------------- |
|
847 // CMRViewerAttachmentsField::LineSpacing |
|
848 // --------------------------------------------------------------------------- |
|
849 // |
|
850 TInt CMRViewerAttachmentsField::LineSpacing() |
|
851 { |
|
852 FUNC_LOG; |
|
853 // Calculates the line spacing based on default one line layout data |
|
854 TInt lineSpacing( 0 ); |
|
855 |
|
856 TRect rect( Rect() ); |
|
857 |
|
858 TAknLayoutRect rowLayoutRect = |
|
859 NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ); |
|
860 TRect rowRect = rowLayoutRect.Rect(); |
|
861 |
|
862 TAknLayoutText labelLayout = |
|
863 NMRLayoutManager::GetLayoutText( |
|
864 rect, NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
865 |
|
866 TRect defaultTextRect = labelLayout.TextRect(); |
|
867 |
|
868 TInt difference = rowRect.Height() - defaultTextRect.Height(); |
|
869 |
|
870 lineSpacing = difference * 2; |
|
871 |
|
872 return lineSpacing; |
|
873 } |
|
874 |
|
875 // --------------------------------------------------------------------------- |
|
876 // CMRViewerAttachmentsField::FocusMargin |
|
877 // --------------------------------------------------------------------------- |
|
878 // |
|
879 TInt CMRViewerAttachmentsField::FocusMargin() |
|
880 { |
|
881 FUNC_LOG; |
|
882 // Calculates focus margin based on default one line layout data |
|
883 TInt focusMagin( 0 ); |
|
884 |
|
885 TRect rect( Rect() ); |
|
886 |
|
887 TAknLayoutRect rowLayoutRect = |
|
888 NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ); |
|
889 TRect rowRect = rowLayoutRect.Rect(); |
|
890 |
|
891 TAknLayoutText labelLayout = |
|
892 NMRLayoutManager::GetLayoutText( |
|
893 rect, NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
894 |
|
895 TRect defaultTextRect = labelLayout.TextRect(); |
|
896 |
|
897 TAknLayoutRect bgLayoutRect = |
|
898 NMRLayoutManager::GetLayoutRect( |
|
899 rect, NMRLayoutManager::EMRLayoutTextEditorBg ); |
|
900 TRect defaultBgRect( bgLayoutRect.Rect() ); |
|
901 |
|
902 TInt difference = defaultBgRect.Height() - defaultTextRect.Height(); |
|
903 |
|
904 focusMagin = TReal( difference / 2 ); |
|
905 |
|
906 return focusMagin; |
|
907 } |
|
908 |
|
909 // --------------------------------------------------------------------------- |
|
910 // CMRViewerAttachmentsField::CreateRemoteAttApiL |
|
911 // --------------------------------------------------------------------------- |
|
912 // |
|
913 void CMRViewerAttachmentsField::CreateRemoteAttApiL() |
|
914 { |
|
915 FUNC_LOG; |
|
916 |
|
917 delete iAttachmentCommandHandler; |
|
918 iAttachmentCommandHandler = NULL; |
|
919 |
|
920 delete iRemoteAttUris; |
|
921 iRemoteAttUris = NULL; |
|
922 |
|
923 delete iAttachmentInfo; |
|
924 iAttachmentInfo = NULL; |
|
925 |
|
926 TInt attachmentCount( iEntry->Entry().AttachmentCountL() ); |
|
927 if ( attachmentCount ) |
|
928 { |
|
929 iRemoteAttUris = new (ELeave) CDesCArrayFlat( 4 ); |
|
930 iAttachmentInfo = CCalRemoteAttachmentInfo::NewL(); |
|
931 } |
|
932 |
|
933 for (TInt i(0); i < attachmentCount; ++i ) |
|
934 { |
|
935 // Ownership not gained |
|
936 CCalAttachment* att = iEntry->Entry().AttachmentL( i ); |
|
937 CCalAttachment::TType attachhmentType( att->Type() ); |
|
938 |
|
939 if ( CCalAttachment::EUri == attachhmentType ) |
|
940 { |
|
941 if ( !iRemoteAttApi ) |
|
942 { |
|
943 TPtrC8 uri( att->Value() ); |
|
944 iRemoteAttApi = CCalRemoteAttachmentApi::NewL( uri ); |
|
945 } |
|
946 |
|
947 HBufC* uri16 = HBufC16::NewLC(att->Value().Length() ); |
|
948 uri16->Des().Copy( att->Value() ); |
|
949 iRemoteAttUris->AppendL( *uri16 ); |
|
950 CleanupStack::PopAndDestroy( uri16 ); |
|
951 } |
|
952 } |
|
953 } |
|
954 |
|
955 // --------------------------------------------------------------------------- |
|
956 // CMRViewerAttachmentsField::DynInitMenuPaneForCurrentAttachmentL |
|
957 // --------------------------------------------------------------------------- |
|
958 // |
|
959 void CMRViewerAttachmentsField::DynInitMenuPaneForCurrentAttachmentL( |
|
960 CEikMenuPane* aMenuPane ) |
|
961 { |
|
962 FUNC_LOG; |
|
963 TInt commandInProgress( |
|
964 iAttachmentCommandHandler->CurrentCommandInProgress() ); |
|
965 |
|
966 // Get selected attachment |
|
967 CCalAttachment* selectedAttachment = NULL; |
|
968 |
|
969 const CESMRRichTextLink* currentLink = iRichTextViewer->GetSelectedLink(); |
|
970 ASSERT( currentLink ); |
|
971 |
|
972 TPtrC currentAttachmentName( currentLink->Value() ); |
|
973 for ( TInt i(0); i < iAttachmentCount && !selectedAttachment; ++i ) |
|
974 { |
|
975 CCalAttachment* attachment = iEntry->Entry().AttachmentL( i ); |
|
976 TPtrC attachmentLabel ( attachment->Label() ); |
|
977 |
|
978 if ( !attachmentLabel.Compare( currentAttachmentName ) ) |
|
979 { |
|
980 selectedAttachment = attachment; |
|
981 } |
|
982 } |
|
983 |
|
984 ASSERT( selectedAttachment ); |
|
985 |
|
986 |
|
987 /* |
|
988 * Case 1: Download in progress |
|
989 */ |
|
990 if( commandInProgress ) |
|
991 { |
|
992 // A) If selected attachment is remote attachment and download is in progress |
|
993 // or attachment is queued for downloading |
|
994 if( selectedAttachment->Type() == CCalAttachment::EUri && |
|
995 EESMRViewerSaveAllAttachments == commandInProgress ) |
|
996 { |
|
997 aMenuPane->SetItemDimmed( |
|
998 EESMRViewerOpenAttachment, |
|
999 ETrue ); |
|
1000 |
|
1001 aMenuPane->SetItemDimmed( |
|
1002 EESMRViewerSaveAttachment, |
|
1003 ETrue ); |
|
1004 |
|
1005 aMenuPane->SetItemDimmed( |
|
1006 EESMRViewerSaveAllAttachments, |
|
1007 ETrue ); |
|
1008 } |
|
1009 |
|
1010 // B) If selected attachment is local attachment |
|
1011 else if( selectedAttachment->Type() == CCalAttachment::EFile ) |
|
1012 { |
|
1013 // Always hide cancel attachment download item |
|
1014 aMenuPane->SetItemDimmed( |
|
1015 EESMRViewerCancelAttachmentDownload, |
|
1016 ETrue ); |
|
1017 |
|
1018 // If attachment count is one, hide 'Save All' also |
|
1019 if ( iAttachmentCount == 1 ) |
|
1020 { |
|
1021 aMenuPane->SetItemDimmed( |
|
1022 EESMRViewerSaveAllAttachments, |
|
1023 ETrue ); |
|
1024 } |
|
1025 } |
|
1026 |
|
1027 // C) If selected attachment is Uri, and some other command is in progress |
|
1028 // than save all |
|
1029 else if( selectedAttachment->Type() == CCalAttachment::EUri && |
|
1030 commandInProgress != EESMRViewerSaveAllAttachments ) |
|
1031 { |
|
1032 // If this attachment is the one being downloaded |
|
1033 if( IsAttachmentDownloadInProgress( *selectedAttachment ) ) |
|
1034 { |
|
1035 aMenuPane->SetItemDimmed( |
|
1036 EESMRViewerOpenAttachment, |
|
1037 ETrue ); |
|
1038 |
|
1039 aMenuPane->SetItemDimmed( |
|
1040 EESMRViewerSaveAttachment, |
|
1041 ETrue ); |
|
1042 |
|
1043 aMenuPane->SetItemDimmed( |
|
1044 EESMRViewerSaveAllAttachments, |
|
1045 ETrue ); |
|
1046 } |
|
1047 |
|
1048 |
|
1049 // if this attacment is not the one being downloaded |
|
1050 else |
|
1051 { |
|
1052 // Always hide cancel attachment download item |
|
1053 aMenuPane->SetItemDimmed( |
|
1054 EESMRViewerCancelAttachmentDownload, |
|
1055 ETrue ); |
|
1056 |
|
1057 // If attachment count is one, hide 'Save All' also |
|
1058 if ( iAttachmentCount == 1 ) |
|
1059 { |
|
1060 aMenuPane->SetItemDimmed( |
|
1061 EESMRViewerSaveAllAttachments, |
|
1062 ETrue ); |
|
1063 } |
|
1064 } |
|
1065 } |
|
1066 } |
|
1067 |
|
1068 /* |
|
1069 * Case 2: No download in progress |
|
1070 */ |
|
1071 else |
|
1072 { |
|
1073 // Always hide cancel attachment download item |
|
1074 aMenuPane->SetItemDimmed( |
|
1075 EESMRViewerCancelAttachmentDownload, |
|
1076 ETrue ); |
|
1077 |
|
1078 // If attachment count is one, hide 'Save All' also |
|
1079 if ( iAttachmentCount == 1 ) |
|
1080 { |
|
1081 aMenuPane->SetItemDimmed( |
|
1082 EESMRViewerSaveAllAttachments, |
|
1083 ETrue ); |
|
1084 } |
|
1085 } |
|
1086 } |
|
1087 |
|
1088 // --------------------------------------------------------------------------- |
|
1089 // CMRViewerAttachmentsField::IsAttachmentDownloadInProgress |
|
1090 // --------------------------------------------------------------------------- |
|
1091 // |
|
1092 TBool CMRViewerAttachmentsField::IsAttachmentDownloadInProgress( |
|
1093 const CCalAttachment& aAttachment ) |
|
1094 { |
|
1095 TBool ret( EFalse ); |
|
1096 |
|
1097 RPointerArray<MCalRemoteAttachmentOperation>& remoteOperations( |
|
1098 iAttachmentCommandHandler->RemoteOperations() ); |
|
1099 |
|
1100 TPtrC currentAttachmentName( aAttachment.Label() ); |
|
1101 |
|
1102 TInt downloadOperationCount( remoteOperations.Count() ); |
|
1103 if ( downloadOperationCount ) |
|
1104 { |
|
1105 for ( TInt i(0); i < downloadOperationCount; ++i ) |
|
1106 { |
|
1107 // There are download operations in progress |
|
1108 const MCalRemoteAttachment& attachInfo = |
|
1109 remoteOperations[i]->AttachmentInformation(); |
|
1110 |
|
1111 TPtrC label( attachInfo.AttachmentLabel() ); |
|
1112 |
|
1113 if ( label.Compare( currentAttachmentName ) == 0 ) |
|
1114 { |
|
1115 ret = ETrue; |
|
1116 } |
|
1117 } |
|
1118 } |
|
1119 |
|
1120 return ret; |
|
1121 } |
|
1122 |
|
1123 //EOF |