|
1 /* |
|
2 * Copyright (c) 2002 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: MsgViewAttachmentsDialog implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // ========== INCLUDE FILES ================================ |
|
21 #include <msvapi.h> |
|
22 #include <eikspane.h> |
|
23 #include <eikmenup.h> |
|
24 #include <AknDef.h> |
|
25 #include <aknappui.h> |
|
26 #include <akntitle.h> |
|
27 #include <aknnavi.h> |
|
28 #include <aknlists.h> |
|
29 #include <gulicon.h> |
|
30 #include <coeutils.h> // for ConeUtils::FileExists |
|
31 #include <bautils.h> |
|
32 #include <aknnotewrappers.h> |
|
33 #include <AknWaitDialog.h> // CAknWaitDialog |
|
34 #include <DocumentHandler.h> |
|
35 #include <StringLoader.h> // StringLoader |
|
36 #include <AiwCommon.h> |
|
37 #include <NpdApi.h> |
|
38 |
|
39 #include <mmsvattachmentmanager.h> |
|
40 |
|
41 #include <avkon.hrh> |
|
42 |
|
43 #include <aknlayout.cdl.h> |
|
44 #include <aknlayoutscalable_avkon.cdl.h> |
|
45 |
|
46 #include <AknUtils.h> |
|
47 #include <AknsUtils.h> // skinned icons |
|
48 #include <AknsConstants.h> // skinned icon ids |
|
49 |
|
50 #include "MsgEditorCommon.h" // for KMsgEditorMbm |
|
51 #include "MsgEditorDocument.h" |
|
52 #include "MsgAttachmentInfo.h" |
|
53 #include "MsgAttachmentModel.h" |
|
54 #include "MsgViewAttachmentsDialog.h" |
|
55 #include "MsgAttachmentUtils.h" |
|
56 |
|
57 #include <msgeditor.mbg> |
|
58 #include "MsgEditorAppUi.hrh" |
|
59 #include <MsgEditorAppUi.rsg> // resouce identifiers |
|
60 |
|
61 #include <aknlistloadertfx.h> |
|
62 #include <aknlistboxtfxinternal.h> |
|
63 |
|
64 // ========== EXTERNAL DATA STRUCTURES ===================== |
|
65 |
|
66 // ========== EXTERNAL FUNCTION PROTOTYPES ================= |
|
67 |
|
68 // ========== CONSTANTS ==================================== |
|
69 |
|
70 _LIT8( KTextDataType, "text/plain" ); |
|
71 const TUid KNotepadUID3 = { 0x1000599d }; |
|
72 |
|
73 // ========== MACROS ======================================= |
|
74 |
|
75 // ========== LOCAL CONSTANTS AND MACROS =================== |
|
76 |
|
77 // ========== MODULE DATA STRUCTURES ======================= |
|
78 |
|
79 // ========== LOCAL FUNCTION PROTOTYPES ==================== |
|
80 |
|
81 // ========== LOCAL FUNCTIONS ============================== |
|
82 |
|
83 // ========== MEMBER FUNCTIONS ============================= |
|
84 |
|
85 // --------------------------------------------------------- |
|
86 // CMsgViewAttachmentsDialog::CMsgViewAttachmentsDialog |
|
87 // |
|
88 // Constructor. |
|
89 // --------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C CMsgViewAttachmentsDialog::CMsgViewAttachmentsDialog( |
|
92 TDesC& aTitle, TInt aMenuId, CMsgAttachmentModel& aAttachmentModel ) |
|
93 : iAttachmentModel( aAttachmentModel ), |
|
94 iNewTitle( aTitle ), |
|
95 iMenuId( aMenuId ) |
|
96 { |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CMsgViewAttachmentsDialog::~CMsgViewAttachmentsDialog |
|
101 // |
|
102 // Destructor. |
|
103 // --------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C CMsgViewAttachmentsDialog::~CMsgViewAttachmentsDialog() |
|
106 { |
|
107 delete iOldTitle; |
|
108 |
|
109 // because it's not possible to set externally owned icon array |
|
110 // for listbox, we delete our icon array here and set listbox |
|
111 // icon array to NULL. |
|
112 delete iIconArray; |
|
113 if ( iListBox ) |
|
114 { |
|
115 TRAP_IGNORE( iListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL( NULL ) ); |
|
116 } |
|
117 |
|
118 delete iListItems; |
|
119 delete iDocHandler; |
|
120 |
|
121 // remove empty navi pane. |
|
122 if ( iNaviPane ) |
|
123 { |
|
124 iNaviPane->Pop(); |
|
125 } |
|
126 delete iOpenParamList; |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------- |
|
130 // CMsgViewAttachmentsDialog::ConstructL |
|
131 // |
|
132 // 2nd phase constructor. |
|
133 // --------------------------------------------------------- |
|
134 // |
|
135 EXPORT_C void CMsgViewAttachmentsDialog::ConstructL() |
|
136 { |
|
137 DoConstructL(); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------- |
|
141 // CMsgViewAttachmentsDialog::ConstructL |
|
142 // |
|
143 // 2nd phase constructor. |
|
144 // --------------------------------------------------------- |
|
145 // |
|
146 EXPORT_C void CMsgViewAttachmentsDialog::ConstructL( CMsvEntry& aMessageEntry ) |
|
147 { |
|
148 iMessageEntry = &aMessageEntry; |
|
149 DoConstructL(); |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------- |
|
153 // CMsgViewAttachmentsDialog::DoConstructL |
|
154 // --------------------------------------------------------- |
|
155 // |
|
156 void CMsgViewAttachmentsDialog::DoConstructL() |
|
157 { |
|
158 CAknDialog::ConstructL( R_MEB_ATTACHMENTS_MENUBAR ); |
|
159 |
|
160 iDocHandler = CDocumentHandler::NewL( iEikonEnv->Process() ); |
|
161 |
|
162 // replace navi pane with empty one. |
|
163 iNaviPane = static_cast<CAknNavigationControlContainer*> |
|
164 ( iEikonEnv->AppUiFactory()->StatusPane()->ControlL( |
|
165 TUid::Uid( EEikStatusPaneUidNavi ) ) ); |
|
166 // CAknNavigationControlContainer internal array of decorators seem to |
|
167 // have big enough granularity that it does not need realloc |
|
168 // and therefore PushDefaultL does not leave. |
|
169 iNaviPane->PushDefaultL(); |
|
170 |
|
171 iDocHandler->SetExitObserver( this ); |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------- |
|
175 // CMsgViewAttachmentsDialog::CurrentListItemIndex |
|
176 // |
|
177 // |
|
178 // --------------------------------------------------------- |
|
179 // |
|
180 EXPORT_C TInt CMsgViewAttachmentsDialog::CurrentListItemIndex() |
|
181 { |
|
182 return iListBox->CurrentItemIndex(); |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------- |
|
186 // CMsgViewAttachmentsDialog::UpdateIcon |
|
187 // |
|
188 // |
|
189 // --------------------------------------------------------- |
|
190 // |
|
191 EXPORT_C void CMsgViewAttachmentsDialog::UpdateIcon( TInt aListIndex ) |
|
192 { |
|
193 iListBox->DrawItem( aListIndex ); |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------- |
|
197 // CMsgViewAttachmentsDialog::ProcessCommandL |
|
198 // |
|
199 // |
|
200 // --------------------------------------------------------- |
|
201 // |
|
202 EXPORT_C void CMsgViewAttachmentsDialog::ProcessCommandL( TInt aCommandId ) |
|
203 { |
|
204 HideMenu(); |
|
205 |
|
206 TFileName filename; |
|
207 TInt index = iListBox->CurrentItemIndex(); |
|
208 |
|
209 switch ( aCommandId ) |
|
210 { |
|
211 case EMsgViewAttachmentCmdOpen: |
|
212 { |
|
213 if ( iBusy ) |
|
214 { |
|
215 return; |
|
216 } |
|
217 |
|
218 if ( index != KErrNotFound ) |
|
219 { |
|
220 iBusy = ETrue; |
|
221 CleanupStack::PushL( TCleanupItem( CleanupPointer, &iBusy ) ); |
|
222 CMsgAttachmentInfo& attInfo = |
|
223 iAttachmentModel.AttachmentInfoAt( index ); |
|
224 |
|
225 TDataType datatype( attInfo.DataType() ); |
|
226 RFile file = iAttachmentModel.GetAttachmentFileL( index ); |
|
227 |
|
228 TInt ret( KErrNone ); |
|
229 |
|
230 if ( datatype == KTextDataType() ) |
|
231 { |
|
232 |
|
233 TInt charset( attInfo.CharacterSet() ); |
|
234 |
|
235 CleanupClosePushL( file ); |
|
236 |
|
237 // file handle ownership transferred. |
|
238 ret = CNotepadApi::ExecFileViewerL( file, |
|
239 NULL, |
|
240 ETrue, |
|
241 charset != KErrNotFound ? EFalse : ETrue, |
|
242 charset ); |
|
243 |
|
244 CleanupStack::Pop( &file ); |
|
245 } |
|
246 else |
|
247 { |
|
248 CleanupClosePushL( file ); |
|
249 |
|
250 if ( iOpenParamList ) |
|
251 { |
|
252 TRAP( ret,iDocHandler->OpenFileEmbeddedL( file, datatype, *iOpenParamList ) ); |
|
253 } |
|
254 else |
|
255 { |
|
256 TRAP( ret,iDocHandler->OpenFileEmbeddedL( file, datatype ) ); |
|
257 } |
|
258 |
|
259 CleanupStack::PopAndDestroy( &file ); |
|
260 } |
|
261 // sets iBusy to EFalse. |
|
262 CleanupStack::PopAndDestroy(); // CleanupPointer |
|
263 |
|
264 switch ( ret ) |
|
265 { |
|
266 case KErrNone: |
|
267 { |
|
268 if (datatype != KTextDataType()) |
|
269 { |
|
270 iBusy = ETrue; |
|
271 } |
|
272 |
|
273 } |
|
274 case KUserCancel: |
|
275 { |
|
276 break; |
|
277 } |
|
278 case KErrNoMemory: |
|
279 case KErrDiskFull: |
|
280 { |
|
281 User::Leave( ret ); |
|
282 } |
|
283 default: |
|
284 { |
|
285 CAknInformationNote* note = new ( ELeave ) CAknInformationNote; |
|
286 HBufC* text = StringLoader::LoadLC( R_QTN_MMS_INFO_CANNOT_OPEN, iCoeEnv ); |
|
287 note->ExecuteLD( *text ); |
|
288 CleanupStack::PopAndDestroy(); // text |
|
289 } |
|
290 } |
|
291 } |
|
292 break; |
|
293 } |
|
294 case EMsgViewAttachmentCmdSave: |
|
295 { |
|
296 if ( index != KErrNotFound ) |
|
297 { |
|
298 // Save to the default location of this type |
|
299 TInt ret = KErrNone; |
|
300 CMsgAttachmentInfo& attInfo = iAttachmentModel.AttachmentInfoAt( index ); |
|
301 TDataType datatype( attInfo.DataType() ); |
|
302 |
|
303 RFile file = iAttachmentModel.GetAttachmentFileL( index ); |
|
304 CleanupClosePushL( file ); |
|
305 |
|
306 if ( datatype == KTextDataType() ) |
|
307 { |
|
308 ret = DoSaveTextFileL( file, attInfo.CharacterSet() ); |
|
309 } |
|
310 else |
|
311 { |
|
312 TFileName dst; |
|
313 User::LeaveIfError( file.Name( dst ) ); |
|
314 ret = iDocHandler->CopyL( file, dst, datatype, KEntryAttNormal ); |
|
315 } |
|
316 |
|
317 CleanupStack::PopAndDestroy( &file ); |
|
318 |
|
319 if ( ret != KErrNone && ret != KUserCancel ) |
|
320 { |
|
321 User::LeaveIfError( ret ); |
|
322 } |
|
323 else if ( ret == KErrNone ) |
|
324 { |
|
325 attInfo.SetSaved( ETrue ); |
|
326 } |
|
327 } |
|
328 break; |
|
329 } |
|
330 case EMsgViewAttachmentCmdRemove: |
|
331 { |
|
332 if ( index != KErrNotFound ) |
|
333 { |
|
334 RemoveAttachmentL( index ); |
|
335 ItemRemovedL( index ); |
|
336 } |
|
337 break; |
|
338 } |
|
339 case EMsgViewAttachmentCmdInsertImage: |
|
340 { |
|
341 if ( MsgAttachmentUtils::FetchFileL( |
|
342 MsgAttachmentUtils::EImage, filename ) ) |
|
343 { |
|
344 InsertAttachmentL( filename, aCommandId ); |
|
345 } |
|
346 break; |
|
347 } |
|
348 case EMsgViewAttachmentCmdInsertAudio: |
|
349 { |
|
350 if ( MsgAttachmentUtils::FetchFileL( |
|
351 MsgAttachmentUtils::EAudio, filename ) ) |
|
352 { |
|
353 InsertAttachmentL( filename, aCommandId ); |
|
354 } |
|
355 break; |
|
356 } |
|
357 case EMsgViewAttachmentCmdInsertVideo: |
|
358 { |
|
359 if ( MsgAttachmentUtils::FetchFileL( |
|
360 MsgAttachmentUtils::EVideo, filename ) ) |
|
361 { |
|
362 InsertAttachmentL( filename, aCommandId ); |
|
363 } |
|
364 break; |
|
365 } |
|
366 case EMsgViewAttachmentCmdInsertNote: |
|
367 { |
|
368 if ( MsgAttachmentUtils::FetchFileL( |
|
369 MsgAttachmentUtils::ENote, filename ) ) |
|
370 { |
|
371 InsertAttachmentL( filename, aCommandId ); |
|
372 } |
|
373 break; |
|
374 } |
|
375 case EAknCmdExit: |
|
376 case EEikCmdExit: |
|
377 { |
|
378 static_cast<MEikCommandObserver*>( iEikonEnv->EikAppUi() ) |
|
379 ->ProcessCommandL( EAknCmdExit ); |
|
380 break; |
|
381 } |
|
382 default: |
|
383 { |
|
384 break; |
|
385 } |
|
386 } |
|
387 } |
|
388 |
|
389 // --------------------------------------------------------- |
|
390 // CMsgViewAttachmentsDialog::DynInitMenuPaneL |
|
391 // |
|
392 // |
|
393 // --------------------------------------------------------- |
|
394 // |
|
395 EXPORT_C void CMsgViewAttachmentsDialog::DynInitMenuPaneL( |
|
396 TInt aMenuId, CEikMenuPane* aMenuPane ) |
|
397 { |
|
398 if ( aMenuId == R_MEB_ATTACHMENTS_MENUPANE ) |
|
399 { |
|
400 // Add menu items from given menu. |
|
401 aMenuPane->AddMenuItemsL( iMenuId, 0, ETrue ); |
|
402 // Delete our dummy first menu item. |
|
403 aMenuPane->DeleteMenuItem( 0 ); |
|
404 } |
|
405 } |
|
406 |
|
407 // --------------------------------------------------------- |
|
408 // CMsgViewAttachmentsDialog::HandleResourceChangeL |
|
409 // |
|
410 // |
|
411 // --------------------------------------------------------- |
|
412 // |
|
413 EXPORT_C void CMsgViewAttachmentsDialog::HandleResourceChange(TInt aType) |
|
414 { |
|
415 if ( aType == KEikDynamicLayoutVariantSwitch || |
|
416 aType == KAknsMessageSkinChange ) |
|
417 { |
|
418 TRAP_IGNORE( iAttachmentModel.LoadResourcesL() ); |
|
419 } |
|
420 CEikDialog::HandleResourceChange( aType ); |
|
421 } |
|
422 |
|
423 // --------------------------------------------------------- |
|
424 // CMsgViewAttachmentsDialog::HandleServerAppExit |
|
425 // --------------------------------------------------------- |
|
426 // |
|
427 EXPORT_C void CMsgViewAttachmentsDialog::HandleServerAppExit( TInt /*aReason*/) |
|
428 { |
|
429 // replace navi pane with empty one. |
|
430 iNaviPane->PushDefaultL(); |
|
431 iBusy = EFalse; |
|
432 } |
|
433 |
|
434 // --------------------------------------------------------- |
|
435 // CMsgViewAttachmentsDialog::HandleControlStateChangeL |
|
436 // |
|
437 // |
|
438 // --------------------------------------------------------- |
|
439 // |
|
440 EXPORT_C void CMsgViewAttachmentsDialog::HandleControlStateChangeL( TInt aControlId ) |
|
441 { |
|
442 if ( aControlId == EMsgAttachmentListBoxId ) |
|
443 { |
|
444 DoUpdateUiL(); |
|
445 } |
|
446 |
|
447 CAknDialog::HandleControlStateChangeL( aControlId ); |
|
448 } |
|
449 |
|
450 // --------------------------------------------------------- |
|
451 // CMsgViewAttachmentsDialog::OkToExitL |
|
452 // |
|
453 // |
|
454 // --------------------------------------------------------- |
|
455 // |
|
456 EXPORT_C TBool CMsgViewAttachmentsDialog::OkToExitL( TInt aButtonId ) |
|
457 { |
|
458 if ( iBusy ) |
|
459 { |
|
460 return EFalse; |
|
461 } |
|
462 |
|
463 if ( aButtonId == EAknSoftkeyBack ) |
|
464 { |
|
465 iTitlePane->SetTextL( *iOldTitle ); |
|
466 } |
|
467 else if ( aButtonId == EAknSoftkeyOpen ) |
|
468 { |
|
469 if ( iAttachmentModel.NumberOfItems() != 0 && |
|
470 !iAttachmentModel.AttachmentInfoAt( CurrentListItemIndex() ).IsEmptyAttachment() ) |
|
471 { |
|
472 ProcessCommandL( EMsgViewAttachmentCmdOpen ); |
|
473 } |
|
474 |
|
475 return EFalse; |
|
476 } |
|
477 |
|
478 return CAknDialog::OkToExitL( aButtonId ); |
|
479 } |
|
480 |
|
481 // --------------------------------------------------------- |
|
482 // CMsgViewAttachmentsDialog::CreateCustomControlL |
|
483 // |
|
484 // |
|
485 // --------------------------------------------------------- |
|
486 // |
|
487 EXPORT_C SEikControlInfo CMsgViewAttachmentsDialog::CreateCustomControlL( TInt aControlType ) |
|
488 { |
|
489 SEikControlInfo controlInfo; |
|
490 controlInfo.iControl = NULL; |
|
491 controlInfo.iTrailerTextId = 0; |
|
492 controlInfo.iFlags = 0; |
|
493 |
|
494 if ( aControlType == EMsgAttachmentListBox ) |
|
495 { |
|
496 controlInfo.iControl = new ( ELeave ) CMsgAttachmentsListBox( iAttachmentModel ); |
|
497 } |
|
498 |
|
499 return controlInfo; |
|
500 } |
|
501 |
|
502 // --------------------------------------------------------- |
|
503 // CMsgViewAttachmentsDialog::HandleListBoxEventL |
|
504 // |
|
505 // |
|
506 // --------------------------------------------------------- |
|
507 // |
|
508 #ifdef RD_SCALABLE_UI_V2 |
|
509 EXPORT_C void CMsgViewAttachmentsDialog::HandleListBoxEventL( CEikListBox* /*aListBox*/, |
|
510 TListBoxEvent aEventType ) |
|
511 { |
|
512 if ( aEventType == MEikListBoxObserver::EEventItemSingleClicked && |
|
513 !iAttachmentModel.AttachmentInfoAt( CurrentListItemIndex() ).IsEmptyAttachment() ) |
|
514 { |
|
515 ProcessCommandL( EMsgViewAttachmentCmdOpen ); |
|
516 } |
|
517 } |
|
518 #else |
|
519 EXPORT_C void CMsgViewAttachmentsDialog::HandleListBoxEventL( CEikListBox* /*aListBox*/, |
|
520 TListBoxEvent /*aEventType*/ ) |
|
521 { |
|
522 } |
|
523 #endif // RD_SCALABLE_UI_V2 |
|
524 // --------------------------------------------------------- |
|
525 // CMsgViewAttachmentsDialog::PreLayoutDynInitL |
|
526 // |
|
527 // |
|
528 // --------------------------------------------------------- |
|
529 // |
|
530 EXPORT_C void CMsgViewAttachmentsDialog::PreLayoutDynInitL() |
|
531 { |
|
532 CEikStatusPane *sp = static_cast<CAknAppUi*> |
|
533 ( iEikonEnv->EikAppUi() )->StatusPane(); |
|
534 iTitlePane = static_cast<CAknTitlePane*> |
|
535 ( sp->ControlL( TUid::Uid(EEikStatusPaneUidTitle ) ) ); |
|
536 |
|
537 const TDesC* title = iTitlePane->Text(); |
|
538 iOldTitle = title->AllocL(); |
|
539 |
|
540 iTitlePane->SetTextL( iNewTitle ); |
|
541 |
|
542 iListBox = static_cast<CMsgAttachmentsListBox*> |
|
543 ( Control( EMsgAttachmentListBoxId ) ); |
|
544 |
|
545 iListBox->CreateScrollBarFrameL( ETrue ); |
|
546 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
547 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
548 |
|
549 iListBox->SetListBoxObserver( this ); |
|
550 |
|
551 LoadFormDataL(); |
|
552 |
|
553 |
|
554 } |
|
555 |
|
556 // --------------------------------------------------------- |
|
557 // CMsgViewAttachmentsDialog::LoadFormDataL |
|
558 // |
|
559 // |
|
560 // --------------------------------------------------------- |
|
561 // |
|
562 EXPORT_C void CMsgViewAttachmentsDialog::LoadFormDataL() |
|
563 { |
|
564 // iconarray for two icons. |
|
565 // index 0: application icon. |
|
566 // index 1: indicator. |
|
567 iIconArray = new ( ELeave ) CArrayPtrFlat<CGulIcon>( 2 ); |
|
568 |
|
569 iListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL( iIconArray ); |
|
570 |
|
571 // list items is not actually an array but object that returns |
|
572 // list item text for listbox in MdcaPoint method. |
|
573 iListItems = CMsgAttaListItemArray::NewL( iAttachmentModel, iIconArray ); |
|
574 iListBox->Model()->SetItemTextArray( iListItems ); |
|
575 iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
576 } |
|
577 |
|
578 // --------------------------------------------------------- |
|
579 // CMsgViewAttachmentsDialog::ItemAddedL |
|
580 // |
|
581 // |
|
582 // --------------------------------------------------------- |
|
583 EXPORT_C void CMsgViewAttachmentsDialog::ItemAddedL( TInt aIndex ) |
|
584 { |
|
585 iListBox->View()->CalcBottomItemIndex(); |
|
586 |
|
587 TInt itemIndex = aIndex; |
|
588 |
|
589 if ( aIndex == -1 ) |
|
590 { |
|
591 itemIndex = Max( iListBox->Model()->NumberOfItems() - 1, 0 ); |
|
592 } |
|
593 |
|
594 iListBox->SetCurrentItemIndex( itemIndex ); |
|
595 |
|
596 if ( !iAttachmentModel.AttachmentInfoAt( itemIndex ).IsEmptyAttachment() ) |
|
597 { |
|
598 if ( !ButtonGroupContainer().IsCommandVisible( EAknSoftkeyOpen ) ) |
|
599 { |
|
600 // Set middle button visible if invisible and inserted attachment |
|
601 // has content (i.e. it is not empty) |
|
602 UpdateButtonVisiblity( EAknSoftkeyOpen, ETrue ); |
|
603 } |
|
604 } |
|
605 else |
|
606 { |
|
607 if ( ButtonGroupContainer().IsCommandVisible( EAknSoftkeyOpen ) ) |
|
608 { |
|
609 // Set middle button invisible if visible and inserted attachment |
|
610 // does not hava content (i.e. it is empty) |
|
611 UpdateButtonVisiblity( EAknSoftkeyOpen, EFalse ); |
|
612 } |
|
613 } |
|
614 |
|
615 iListBox->HandleItemAdditionL(); |
|
616 } |
|
617 |
|
618 // --------------------------------------------------------- |
|
619 // CMsgViewAttachmentsDialog::ItemRemovedL |
|
620 // |
|
621 // |
|
622 // --------------------------------------------------------- |
|
623 EXPORT_C void CMsgViewAttachmentsDialog::ItemRemovedL( TInt aIndex ) |
|
624 { |
|
625 iListBox->HandleItemRemovalL(); |
|
626 TInt lastItem = Max( iListBox->Model()->NumberOfItems() - 1, 0 ); |
|
627 |
|
628 if ( aIndex - 1 == lastItem ) |
|
629 { |
|
630 TInt numItems = iListBox->View()->NumberOfItemsThatFitInRect( |
|
631 iListBox->View()->ViewRect() ); |
|
632 TInt topItem = Max( lastItem - numItems, 0 ); |
|
633 iListBox->SetTopItemIndex( topItem ); |
|
634 } |
|
635 |
|
636 iListBox->SetCurrentItemIndex( Min( aIndex, lastItem ) ); |
|
637 iListBox->DrawNow(); |
|
638 |
|
639 if ( iAttachmentModel.NumberOfItems() == 0 || |
|
640 iAttachmentModel.AttachmentInfoAt( CurrentListItemIndex() ).IsEmptyAttachment() ) |
|
641 { |
|
642 UpdateButtonVisiblity( EAknSoftkeyOpen, EFalse ); |
|
643 } |
|
644 } |
|
645 |
|
646 // --------------------------------------------------------- |
|
647 // CMsgViewAttachmentsDialog::InsertAttachmentL |
|
648 // |
|
649 // |
|
650 // --------------------------------------------------------- |
|
651 // |
|
652 EXPORT_C void CMsgViewAttachmentsDialog::InsertAttachmentL( |
|
653 const TFileName& aFileName, |
|
654 TInt /*aCommandId*/, |
|
655 TInt aIndex /*= -1*/ ) |
|
656 { |
|
657 iBusy = ETrue; |
|
658 // sets iBusy to EFalse on leave. |
|
659 CleanupStack::PushL( TCleanupItem( CleanupPointer, &iBusy ) ); |
|
660 |
|
661 iWaitDialog = new ( ELeave ) CAknWaitDialog( |
|
662 reinterpret_cast<CEikDialog**>( &iWaitDialog ), |
|
663 ETrue ); |
|
664 CleanupStack::PushL( TCleanupItem( CleanupWaitDialog, (TAny**)&iWaitDialog ) ); |
|
665 |
|
666 iWaitDialog->PrepareLC( R_MEB_WAIT_NOTE ); |
|
667 |
|
668 HBufC* text = StringLoader::LoadLC( R_QTN_MAIL_WAIT_INSERT_ATTACHMENT ); |
|
669 iWaitDialog->SetTextL( *text ); |
|
670 CleanupStack::PopAndDestroy(); // text |
|
671 |
|
672 iWaitDialog->RunLD(); |
|
673 |
|
674 // find file size |
|
675 TInt filesize = 0; |
|
676 RFile file; |
|
677 RFs& fs = iEikonEnv->FsSession(); |
|
678 |
|
679 TInt err = file.Open( fs, aFileName, EFileShareAny ); |
|
680 if ( err == KErrAccessDenied || err == KErrInUse ) |
|
681 { |
|
682 err = file.Open( fs, aFileName, EFileShareReadersOnly ); |
|
683 } |
|
684 if ( err == KErrNone ) |
|
685 { |
|
686 file.Size( filesize ); |
|
687 } |
|
688 file.Close(); |
|
689 |
|
690 iAttachmentModel.AddAttachmentL( aFileName, filesize, 0, ETrue, aIndex ); |
|
691 |
|
692 ItemAddedL( aIndex ); |
|
693 |
|
694 // will delete iWaitDialog. |
|
695 CleanupStack::PopAndDestroy(); // CleanupWaitDialog |
|
696 |
|
697 // sets iBusy to EFalse. |
|
698 CleanupStack::PopAndDestroy(); // CleanupPointer |
|
699 } |
|
700 |
|
701 // --------------------------------------------------------- |
|
702 // CMsgViewAttachmentsDialog::RemoveAttachmentL |
|
703 // |
|
704 // |
|
705 // --------------------------------------------------------- |
|
706 // |
|
707 EXPORT_C void CMsgViewAttachmentsDialog::RemoveAttachmentL( TInt aIndex ) |
|
708 { |
|
709 // delete item from attachment model (notifies its observer about deletion). |
|
710 iAttachmentModel.DeleteAttachment( aIndex ); |
|
711 } |
|
712 |
|
713 // --------------------------------------------------------- |
|
714 // CMsgViewAttachmentsDialog::CleanupPointer |
|
715 // |
|
716 // |
|
717 // --------------------------------------------------------- |
|
718 // |
|
719 EXPORT_C void CMsgViewAttachmentsDialog::CleanupPointer( TAny* aItem ) |
|
720 { |
|
721 TInt* item = static_cast<TInt*>( aItem ); |
|
722 *item = EFalse; |
|
723 } |
|
724 |
|
725 // --------------------------------------------------------- |
|
726 // CMsgViewAttachmentsDialog::CleanupWaitDialog |
|
727 // |
|
728 // |
|
729 // --------------------------------------------------------- |
|
730 // |
|
731 void CMsgViewAttachmentsDialog::CleanupWaitDialog( TAny* aAny ) |
|
732 { |
|
733 CAknWaitDialog** dialog = (CAknWaitDialog**) aAny; |
|
734 if ( dialog && *dialog ) |
|
735 { |
|
736 delete *dialog; |
|
737 } |
|
738 } |
|
739 |
|
740 // --------------------------------------------------------- |
|
741 // CMsgViewAttachmentsDialog::SetOpenParamList |
|
742 // |
|
743 // |
|
744 // --------------------------------------------------------- |
|
745 // |
|
746 EXPORT_C void CMsgViewAttachmentsDialog::SetOpenParamList(CAiwGenericParamList* aOpenParamList) |
|
747 { |
|
748 delete iOpenParamList; |
|
749 iOpenParamList = aOpenParamList; |
|
750 } |
|
751 |
|
752 // --------------------------------------------------------- |
|
753 // CMsgViewAttachmentsDialog::OpenParamList |
|
754 // |
|
755 // |
|
756 // --------------------------------------------------------- |
|
757 // |
|
758 EXPORT_C CAiwGenericParamList* CMsgViewAttachmentsDialog::OpenParamList( ) |
|
759 { |
|
760 return iOpenParamList; |
|
761 } |
|
762 |
|
763 // --------------------------------------------------------- |
|
764 // CMsgViewAttachmentsDialog::DoSaveTextFileL |
|
765 // --------------------------------------------------------- |
|
766 // |
|
767 TInt CMsgViewAttachmentsDialog::DoSaveTextFileL( RFile& aFile, TInt aCharSet ) |
|
768 { |
|
769 TInt result( KErrNone ); |
|
770 |
|
771 if ( aCharSet == KErrNotFound ) |
|
772 { |
|
773 TRAP( result, CNotepadApi::SaveFileAsMemoL( aFile ) ); |
|
774 } |
|
775 else |
|
776 { |
|
777 TRAP( result, CNotepadApi::SaveFileAsMemoL( aFile, |
|
778 aCharSet ) ); |
|
779 } |
|
780 |
|
781 // Show confirmation note |
|
782 RApaLsSession appList; |
|
783 if ( result == KErrNone && |
|
784 appList.Connect() == KErrNone ) |
|
785 { |
|
786 CleanupClosePushL( appList ); |
|
787 |
|
788 TApaAppInfo appInfo; |
|
789 if ( appList.GetAppInfo( appInfo, KNotepadUID3 ) == KErrNone ) |
|
790 { |
|
791 HBufC* text = StringLoader::LoadLC( R_MSG_FILE_SAVED_TO, appInfo.iCaption ); |
|
792 |
|
793 CAknConfirmationNote* note = new( ELeave ) CAknConfirmationNote( ETrue ); |
|
794 note->ExecuteLD( *text ); |
|
795 |
|
796 CleanupStack::PopAndDestroy( text ); |
|
797 } |
|
798 |
|
799 CleanupStack::PopAndDestroy( &appList ); |
|
800 } |
|
801 |
|
802 return result; |
|
803 } |
|
804 |
|
805 // --------------------------------------------------------- |
|
806 // CMsgViewAttachmentsDialog::DoUpdateUiL |
|
807 // --------------------------------------------------------- |
|
808 // |
|
809 void CMsgViewAttachmentsDialog::DoUpdateUiL() |
|
810 { |
|
811 if ( iAttachmentModel.NumberOfItems() == 0 || |
|
812 iAttachmentModel.AttachmentInfoAt( CurrentListItemIndex() ).IsEmptyAttachment() ) |
|
813 { |
|
814 UpdateButtonVisiblity( EAknSoftkeyOpen, EFalse ); |
|
815 } |
|
816 else |
|
817 { |
|
818 UpdateButtonVisiblity( EAknSoftkeyOpen, ETrue ); |
|
819 } |
|
820 } |
|
821 |
|
822 // --------------------------------------------------------- |
|
823 // CMsgViewAttachmentsDialog::UpdateButtonVisiblity |
|
824 // --------------------------------------------------------- |
|
825 // |
|
826 void CMsgViewAttachmentsDialog::UpdateButtonVisiblity( TInt aCommandId, TBool aValue ) |
|
827 { |
|
828 if ( ButtonGroupContainer().ControlOrNull( aCommandId ) ) |
|
829 { |
|
830 ButtonGroupContainer().MakeCommandVisible( aCommandId, aValue ); |
|
831 } |
|
832 } |
|
833 |
|
834 // End of File |