mobilemessaging/unieditor/utils/src/UniObjectsViewDialog.cpp
changeset 0 72b543305e3a
child 9 1d7827e39b52
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2005-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:  
       
    15 *       Defines implementation of CUniObjectsViewDialog class methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // ========== INCLUDE FILES ================================
       
    22 #include "UniObjectsViewDialog.h"
       
    23 
       
    24 #include <gulicon.h>
       
    25 #include <eikenv.h>                         // Eikon Enviroment
       
    26 #include <eikdll.h>                         // Application start
       
    27 #include <eikmenup.h>                       // for CEikMenuPane
       
    28 #include <eikmenub.h>                       // for CEikMenuBar
       
    29 #include <bautils.h>                        // NearestLanguageFile
       
    30 #include <aknlists.h>
       
    31 #include <apgcli.h>                         // RApaLsSession
       
    32 #include <AknQueryDialog.h>
       
    33 #include <aknnotewrappers.h>
       
    34 #include <DocumentHandler.h>                // doc handler
       
    35 #include <StringLoader.h>                   // StringLoader
       
    36 #include <data_caging_path_literals.hrh> 
       
    37 #include <txtrich.h>                        // CRichText
       
    38 #include <avkon.hrh>
       
    39 
       
    40 #include <mmsvattachmentmanager.h>
       
    41 #include <msvstore.h>
       
    42 #include <msvstd.h>                         // TMsvId
       
    43 #include <biodb.h>                          // CBioDatabase
       
    44 #include <mtclbase.h>
       
    45 
       
    46 #include <NpdApi.h>
       
    47 
       
    48 #include <sendui.h>
       
    49 #include <SenduiMtmUids.h>
       
    50 #include <Sendnorm.rsg>
       
    51 #include <CMessageData.h>
       
    52 
       
    53 #include <msgtextutils.h>
       
    54 #include <MsgMediaInfo.h>
       
    55 
       
    56 #include <MsgEditorAppUi.rsg>               // atta dlg base resouce identifiers
       
    57 #include <UniUtils.rsg>                    // obj view resouce identifiers
       
    58 #include <AiwGenericParam.h>
       
    59 
       
    60 // Features
       
    61 #include <featmgr.h>    
       
    62 
       
    63 #include <fileprotectionresolver.h>
       
    64 
       
    65 // Help
       
    66 #include <csxhelp/unif.hlp.hrh>
       
    67 #include <csxhelp/mms.hlp.hrh>
       
    68 #include <hlplch.h>   // For HlpLauncher
       
    69 
       
    70 #include "UniUtils.h"
       
    71 
       
    72 #include <unimodelconst.h>
       
    73 #include <unidatamodel.h>
       
    74 #include <unidatautils.h>
       
    75 #include <uniobject.h>
       
    76 #include <unidrminfo.h>
       
    77 #include <unismilmodel.h>
       
    78 #include <uniobjectlist.h>
       
    79 #include <unimimeinfo.h>
       
    80 #include <uniobjectsinfo.h>
       
    81 #include <uniobjectsmodel.h>
       
    82 
       
    83 #include <MsgEditorCommon.h>
       
    84 #include <MsgMimeTypes.h>
       
    85 
       
    86 #include <MsgEditorAppUi.hrh>               // atta dlg base commands
       
    87 #include "UniObjectsViewDialog.hrh"         // obj view commands
       
    88 
       
    89 #include <UniUtils.rsg>
       
    90 
       
    91 #include "UniEditorLogging.h"
       
    92 
       
    93 #include "UniObjectsListArray.h"
       
    94 
       
    95 // ========== EXTERNAL DATA STRUCTURES =====================
       
    96 
       
    97 // ========== EXTERNAL FUNCTION PROTOTYPES =================
       
    98 
       
    99 // ========== CONSTANTS ====================================
       
   100 
       
   101 _LIT( KMmsFormatTwoDigits, "%x_%x\\" );
       
   102 
       
   103 const TUid KNotepadUID3 = { 0x1000599d };
       
   104 const TUid KUidMmsViewer = { 0x100058DF };
       
   105 const TUid KUniEditorAppId = { 0x102072D8 };
       
   106 
       
   107 // ========== MACROS =======================================
       
   108 
       
   109 // ========== LOCAL CONSTANTS AND MACROS ===================
       
   110 
       
   111 // ========== MODULE DATA STRUCTURES =======================
       
   112 
       
   113 // ========== LOCAL FUNCTION PROTOTYPES ====================
       
   114 
       
   115 // ========== LOCAL FUNCTIONS ==============================
       
   116 
       
   117 // ========== MEMBER FUNCTIONS =============================
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CUniObjectsViewDialog::ObjectsViewL
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 EXPORT_C TInt CUniObjectsViewDialog::ObjectsViewL( TUniObjectsDialogType aDialogType,
       
   124                                                    CUniObjectsModel& aAttachmentModel,
       
   125                                                    CEikonEnv* aEikonEnv,
       
   126                                                    TUniObjectsDialogExitCmd& aExitCmd,
       
   127                                                    CUniDataModel& aDataModel,
       
   128                                                    TInt aFocusedItemIndex )
       
   129     {
       
   130     TFileName* fileName = new ( ELeave ) TFileName;
       
   131     CleanupStack::PushL( fileName );
       
   132     
       
   133     TParse parse;
       
   134     User::LeaveIfError( parse.Set( KUniUtilsResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL ) );
       
   135     *fileName = parse.FullName();
       
   136     
       
   137     BaflUtils::NearestLanguageFile( aEikonEnv->FsSession(), *fileName );
       
   138     TInt offset = aEikonEnv->AddResourceFileL( *fileName );
       
   139     
       
   140     CleanupStack::PopAndDestroy( fileName );
       
   141     
       
   142     TInt menuId = R_UNUT_EDITOR_OBJECTS_MENU;
       
   143 
       
   144     switch ( aDialogType )
       
   145         {
       
   146         case EViewer:
       
   147             {
       
   148             menuId = R_UNUT_VIEWER_OBJECTS_MENU;
       
   149             break;
       
   150             }
       
   151         case EForward:
       
   152             {
       
   153             menuId = R_UNUT_FORWARD_OBJECTS_MENU;
       
   154             break;
       
   155             }
       
   156         case EEditor:
       
   157             {
       
   158             menuId = R_UNUT_EDITOR_OBJECTS_MENU;
       
   159             break;
       
   160             }
       
   161         default:
       
   162             {
       
   163             break;
       
   164             }
       
   165         }
       
   166 
       
   167     HBufC* title = aEikonEnv->AllocReadResourceLC( R_UNUT_OBJECTS_TITLE );
       
   168     TInt ret = 0;
       
   169     
       
   170     PopulateAttachmentModelL( aAttachmentModel, aDataModel );
       
   171     
       
   172     CUniObjectsViewDialog* dlg = new ( ELeave ) CUniObjectsViewDialog (
       
   173         *title, 
       
   174         aDialogType, 
       
   175         menuId, 
       
   176         aAttachmentModel,  
       
   177         offset, 
       
   178         aExitCmd,
       
   179         aDataModel,
       
   180         aFocusedItemIndex );
       
   181     
       
   182     CleanupStack::PushL( dlg );
       
   183     dlg->ConstructL( aDataModel.Mtm().Entry() );
       
   184     CleanupStack::Pop( dlg );
       
   185         
       
   186     ret = dlg->ExecuteLD( R_MEB_VIEW_ATTACHMENT_DIALOG ); // wait dialog.
       
   187     CleanupStack::PopAndDestroy( title ); // store, title
       
   188 
       
   189     return ret;
       
   190     }
       
   191 
       
   192 
       
   193 // ---------------------------------------------------------
       
   194 // CUniObjectsViewDialog::CUniObjectsViewDialog
       
   195 // ---------------------------------------------------------
       
   196 //
       
   197 CUniObjectsViewDialog::CUniObjectsViewDialog( TDesC& aTitle,
       
   198                                               TUniObjectsDialogType aDialogType,
       
   199                                               TInt aMenuId,
       
   200                                               CUniObjectsModel& aAttachmentModel,
       
   201                                               TInt aResourceOffset,
       
   202                                               TUniObjectsDialogExitCmd& aExitCmd,
       
   203                                               CUniDataModel& aDataModel,
       
   204                                               TInt aFocusedItemIndex ) :
       
   205     CMsgViewAttachmentsDialog( aTitle, aMenuId, aAttachmentModel ),
       
   206     iDialogType( aDialogType ),
       
   207     iResourceOffset( aResourceOffset ),
       
   208     iDataModel( aDataModel ),
       
   209     iSupportedFeatures( 0 ),
       
   210     iExitCmd( aExitCmd ),
       
   211     iFocusedItemIndex( aFocusedItemIndex )
       
   212     {
       
   213     iExitCmd = EUniObjectsViewBack;
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------
       
   217 // CUniObjectsViewDialog::~CUniObjectsViewDialog
       
   218 // ---------------------------------------------------------
       
   219 //
       
   220 CUniObjectsViewDialog::~CUniObjectsViewDialog()
       
   221     {
       
   222     if ( iResourceOffset != -1 )
       
   223         {
       
   224         iEikonEnv->DeleteResourceFile( iResourceOffset );
       
   225         }
       
   226 
       
   227     // Remove drm info observer
       
   228     CUniObjectsModel& model( static_cast<CUniObjectsModel&>( iAttachmentModel ) );
       
   229     TInt countObjects = model.NumberOfItems( );
       
   230     for ( TInt i = 0; i < countObjects; i++ )
       
   231         {
       
   232         CUniObject* obj = 
       
   233             static_cast<CUniObjectsInfo&>
       
   234                 ( model.AttachmentInfoAt( i ) ).Object();
       
   235         if ( obj )
       
   236             {
       
   237             obj->RemoveObserver( this );
       
   238             }
       
   239         }
       
   240 
       
   241     delete iSendUi;
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------
       
   245 // CUniObjectsViewDialog::ConstructL
       
   246 // ---------------------------------------------------------
       
   247 //
       
   248 void CUniObjectsViewDialog::ConstructL( CMsvEntry& aEntry )
       
   249     {
       
   250     FeatureManager::InitializeLibL();
       
   251     
       
   252     if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   253         {
       
   254         iSupportedFeatures |= EUniFeatureHelp;
       
   255         }
       
   256     if ( FeatureManager::FeatureSupported( KFeatureIdDrmFull ) )
       
   257         {
       
   258         iSupportedFeatures |= EUniFeatureDrmFull;
       
   259         }
       
   260     if ( FeatureManager::FeatureSupported( KFeatureIdJapanese ) )
       
   261         {
       
   262         iSupportedFeatures |= EUniFeatureJapanese;
       
   263         }
       
   264 
       
   265     FeatureManager::UnInitializeLib();
       
   266 
       
   267     CMsgViewAttachmentsDialog::ConstructL( aEntry );
       
   268     
       
   269     if ( iDialogType == EViewer )
       
   270         {
       
   271         iSendUi = CSendUi::NewL();
       
   272         }
       
   273         
       
   274     // Add drm info observer
       
   275     CUniObjectsModel& model( static_cast<CUniObjectsModel&>( iAttachmentModel ) );
       
   276     TInt countObjects = model.NumberOfItems( );
       
   277     for ( TInt i = 0; i < countObjects; i++ )
       
   278         {
       
   279         CUniObject* obj = 
       
   280             static_cast<CUniObjectsInfo&>
       
   281                 ( model.AttachmentInfoAt( i ) ).Object();
       
   282         if ( obj )
       
   283             {
       
   284             // concept of 'DRM rights when loaded' is different
       
   285             // current status applies; consumed status does not matter
       
   286             obj->SetDrmRightsWhenLoadedObjects( IsRightsNow( *obj ) );
       
   287             obj->SetObserverL( this );
       
   288             }
       
   289 
       
   290         }
       
   291     // Enable task swapper to options menu after launch has been completed.
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------
       
   295 // CMsgViewAttachmentsDialog::LoadFormDataL
       
   296 // ---------------------------------------------------------
       
   297 //
       
   298 void CUniObjectsViewDialog::LoadFormDataL()
       
   299     {
       
   300     // iconarray for two icons.
       
   301     // index 0: application icon.
       
   302     // index 1: indicator.
       
   303     iIconArray = new ( ELeave ) CArrayPtrFlat<CGulIcon>( 2 );
       
   304 
       
   305     iListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL( iIconArray );
       
   306 
       
   307     // list items is not actually an array but object that returns
       
   308     // list item text for listbox in MdcaPoint method.
       
   309     iListItems = CUniObjectListItemArray::NewL( iAttachmentModel, iIconArray, iDataModel.DataUtils() );
       
   310     iListBox->Model()->SetItemTextArray( iListItems );
       
   311     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );    
       
   312     }
       
   313 
       
   314 // ---------------------------------------------------------
       
   315 // CUniObjectsViewDialog::PreLayoutDynInitL
       
   316 //
       
   317 // Sets the intial focus if given. Also enables open middle softkey.
       
   318 // Assumes that empty slides are not set initially focused.
       
   319 // ---------------------------------------------------------
       
   320 //
       
   321 void CUniObjectsViewDialog::PreLayoutDynInitL()
       
   322     {    
       
   323     CMsgViewAttachmentsDialog::PreLayoutDynInitL();    
       
   324     
       
   325     if ( iFocusedItemIndex != -1)
       
   326         {
       
   327         iListBox->SetCurrentItemIndex( iFocusedItemIndex );
       
   328         if ( ButtonGroupContainer().ControlOrNull( EAknSoftkeyOpen ) )
       
   329             {
       
   330             ButtonGroupContainer().MakeCommandVisible( EAknSoftkeyOpen, ETrue );
       
   331             }
       
   332         }
       
   333     }
       
   334 
       
   335 // ---------------------------------------------------------
       
   336 // CUniObjectsViewDialog::ProcessCommandL
       
   337 // ---------------------------------------------------------
       
   338 //
       
   339 void CUniObjectsViewDialog::ProcessCommandL( TInt aCommandId )
       
   340     {
       
   341     HideMenu();
       
   342 
       
   343     TInt index = CurrentListItemIndex();
       
   344 
       
   345     switch ( aCommandId )
       
   346         {
       
   347         case EMmsObjectsTextFirst:
       
   348         case EMmsObjectsTextSecond:
       
   349             ChangeOrderL( aCommandId, 0 );
       
   350             break;
       
   351         case EMsgViewAttachmentCmdOpen:
       
   352             ProcessCommandOpenL( index );
       
   353             break;
       
   354         case EMsgViewAttachmentCmdSave:
       
   355             ProcessCommandSaveL( index );
       
   356             break;
       
   357         case EMsgViewAttachmentCmdRemove:
       
   358             {
       
   359             CUniObjectsInfo& selectedObject = static_cast<CUniObjectsInfo&>
       
   360                         ( iAttachmentModel.AttachmentInfoAt( CurrentListItemIndex() ) );   
       
   361             TBool emptySlide = ( selectedObject.Flags() & CUniObjectsInfo::EMmsSlide );
       
   362             if(emptySlide)
       
   363                 break;
       
   364             ProcessCommandRemoveL( index );
       
   365             }
       
   366             break;
       
   367 
       
   368         case EAknCmdHelp:
       
   369             {
       
   370             LaunchHelpL();
       
   371             }
       
   372             break;
       
   373         
       
   374         case EMmsObjectsSendVia:
       
   375             {
       
   376             CArrayFix<TUid>* uids = new ( ELeave ) CArrayFixFlat<TUid>( 1 );
       
   377             CleanupStack::PushL( uids );
       
   378             
       
   379             CUniObjectsInfo& selectedObject = static_cast<CUniObjectsInfo&>
       
   380                 ( iAttachmentModel.AttachmentInfoAt( index ) );
       
   381             CUniObject* obj = selectedObject.Object();
       
   382             
       
   383             // TODO bio support
       
   384             TSendingCapabilities requiredCapabilities = KCapabilitiesForAllServices;
       
   385             requiredCapabilities.iFlags =       TSendingCapabilities::ESupportsAttachments;
       
   386             
       
   387             if ( obj->MediaType() == EMsgMediaText )
       
   388                 {
       
   389                 requiredCapabilities.iFlags |= TSendingCapabilities::ESupportsBodyText;
       
   390                 }
       
   391             
       
   392             if ( iDialogType != EViewer )
       
   393                 {
       
   394                 uids->AppendL( KSenduiMtmMmsUid );   // MMS menu item, if already in editor
       
   395                 }
       
   396 
       
   397             CMessageData* msgData = CMessageData::NewLC();
       
   398             RFile fileHandle; 
       
   399             if ( obj->AttachmentId() == KMsvNullIndexEntryId )
       
   400                 {
       
   401                 fileHandle = CUniDataUtils::GetAttachmentFileL( iDataModel.Mtm(), obj->AttachmentId() );
       
   402                 }
       
   403             else
       
   404                 {
       
   405                 // Always pass full file path to SendUi. Even
       
   406                 // in case of attachments.
       
   407                 CMsvStore* store = iMessageEntry->ReadStoreL();
       
   408                 CleanupStack::PushL( store );
       
   409                 MMsvAttachmentManager& manager = store->AttachmentManagerL();
       
   410                 fileHandle = manager.GetAttachmentFileL( obj->AttachmentId() );
       
   411                 CleanupStack::PopAndDestroy( store ); 
       
   412                 }
       
   413             CleanupClosePushL( fileHandle );
       
   414 
       
   415             TUid bioUid;
       
   416             bioUid.iUid = 0;
       
   417             if ( fileHandle.SubSessionHandle() )
       
   418                 {
       
   419                 msgData->AppendAttachmentHandleL( fileHandle );
       
   420                 if ( obj->MediaInfo() )
       
   421                     {
       
   422                     if ( BioMessageTypeL( obj->MediaInfo()->MimeType(), bioUid ) )
       
   423                         {
       
   424                         requiredCapabilities.iFlags |= TSendingCapabilities::ESupportsBioSending;
       
   425                         }
       
   426                     }
       
   427                 }
       
   428 
       
   429             TUid serviceId = iSendUi->ShowSendQueryL( msgData, 
       
   430                                                       requiredCapabilities, 
       
   431                                                       uids );
       
   432             ProcessCommandSendL( *msgData, index, serviceId, bioUid );
       
   433 
       
   434             CleanupStack::PopAndDestroy( 3, uids ); // + fileHandle, msgData
       
   435             }
       
   436             break;
       
   437         
       
   438         case EEikCmdExit:
       
   439         case EAknCmdExit:
       
   440             iExitCmd = EUniObjectsViewExit;
       
   441             // Fallthrough
       
   442         default:
       
   443                 // call parent class to process other commands.
       
   444             CMsgViewAttachmentsDialog::ProcessCommandL( aCommandId ); 
       
   445             break;
       
   446         }
       
   447 
       
   448     }
       
   449 
       
   450 // ---------------------------------------------------------
       
   451 // CUniObjectsViewDialog::ProcessCommandOpenL
       
   452 // ---------------------------------------------------------
       
   453 //
       
   454 void CUniObjectsViewDialog::ProcessCommandOpenL( TInt aIndex )
       
   455     {
       
   456     CUniObjectsInfo& selectedObject = 
       
   457         static_cast<CUniObjectsInfo&>( iAttachmentModel.AttachmentInfoAt( aIndex ) );
       
   458     CUniObject* obj = selectedObject.Object();    
       
   459     
       
   460     if ( obj->MediaType() == EMsgMediaText )
       
   461         {
       
   462         if ( !iBusy )
       
   463             {
       
   464             iBusy = ETrue;
       
   465             CleanupStack::PushL( TCleanupItem( CleanupPointer, &iBusy ) );
       
   466             
       
   467             TUint mibCharset = obj->MimeInfo()->Charset();
       
   468             if ( !mibCharset )
       
   469                 {
       
   470                 //assume US-ASCII - mandated by RFC 2046
       
   471                 mibCharset = KCharacterSetMIBEnumUsAscii;
       
   472                 }
       
   473             TUint charconvCharsetID = iDataModel.DataUtils().MibIdToCharconvIdL( mibCharset );
       
   474 
       
   475             RFile file = CUniDataUtils::GetAttachmentFileL( iDataModel.Mtm(), obj->AttachmentId() );
       
   476             CleanupClosePushL( file );
       
   477             // Takes ownership of "file":
       
   478             CNotepadApi::ExecFileViewerL( file, 
       
   479                                       NULL,
       
   480                                       ETrue,
       
   481                                       EFalse,
       
   482                                       charconvCharsetID );
       
   483             CleanupStack::Pop( &file ); 
       
   484             
       
   485             // sets iBusy to EFalse.
       
   486             CleanupStack::PopAndDestroy(); // CleanupPointer
       
   487             }       
       
   488         }
       
   489     else
       
   490         {
       
   491         if ( iDialogType == EViewer )
       
   492             {
       
   493             if ( selectedObject.IsSaved() )
       
   494                 {
       
   495                 SetOpenParamList( NULL );
       
   496                 }
       
   497             else if ( !OpenParamList() )
       
   498                 {
       
   499                 CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC();
       
   500 				//Applications that require Media Player to show the save 
       
   501                 //option must set the EGenericParamAllowSave to ETrue. 
       
   502                 //If they don't need the save option there is no need to set 
       
   503                 //the parameter to EFalse.
       
   504                 TAiwVariant allowSaveVariant( ETrue );
       
   505                 TAiwGenericParam genericParamAllowSave( EGenericParamAllowSave,
       
   506                                                                allowSaveVariant );
       
   507                 paramList->AppendL( genericParamAllowSave );      
       
   508                 //paramList->AppendL( EGenericParamAllowSave );
       
   509                 SetOpenParamList( paramList );
       
   510                 CleanupStack::Pop( paramList );
       
   511                 }
       
   512             }
       
   513                         
       
   514         CMsgViewAttachmentsDialog::ProcessCommandL( EMsgViewAttachmentCmdOpen ); 
       
   515         }
       
   516     }
       
   517 
       
   518 // ---------------------------------------------------------
       
   519 // CUniObjectsViewDialog::ProcessCommandSaveL
       
   520 // ---------------------------------------------------------
       
   521 //
       
   522 void CUniObjectsViewDialog::ProcessCommandSaveL( TInt aIndex )
       
   523     {
       
   524     CUniObjectsInfo& selectedObject = static_cast<CUniObjectsInfo&>
       
   525         ( iAttachmentModel.AttachmentInfoAt( aIndex ) );
       
   526     CUniObject* obj = selectedObject.Object();
       
   527     if ( obj->MediaType() == EMsgMediaText )
       
   528         {
       
   529         // Save text files directly to Notepad.
       
   530         // This is needed because automatic character set recognation
       
   531         // is not too reliable.
       
   532         TUint mibCharset = obj->MimeInfo()->Charset();
       
   533         if ( !mibCharset )
       
   534             {
       
   535             //assume US-ASCII - mandated by RFC 2046
       
   536             mibCharset = KCharacterSetMIBEnumUsAscii;
       
   537             }
       
   538         TUint charconvCharsetID = iDataModel.DataUtils().MibIdToCharconvIdL( mibCharset );
       
   539 
       
   540         RFile file = CUniDataUtils::GetAttachmentFileL( iDataModel.Mtm(), obj->AttachmentId() );
       
   541         CleanupClosePushL( file );
       
   542         CNotepadApi::SaveFileAsMemoL(
       
   543             file, 
       
   544             charconvCharsetID );
       
   545         CleanupStack::PopAndDestroy(); // file
       
   546 
       
   547         // Show confirmation note
       
   548         RApaLsSession appList;
       
   549         if ( appList.Connect() == KErrNone )
       
   550             {
       
   551             TApaAppInfo appInfo;
       
   552             if ( appList.GetAppInfo( appInfo, KNotepadUID3 ) == KErrNone )
       
   553                 {
       
   554                 HBufC* text = StringLoader::LoadLC( R_UNUT_FILE_SAVED_TO, appInfo.iCaption );
       
   555                 CAknConfirmationNote* note = new ( ELeave ) CAknConfirmationNote( ETrue );
       
   556                 note->ExecuteLD( *text );
       
   557                 CleanupStack::PopAndDestroy( text );
       
   558                 }
       
   559             appList.Close();
       
   560             }
       
   561 
       
   562         // Set saved information
       
   563         selectedObject.SetSaved( ETrue );
       
   564         if ( obj ) 
       
   565             {
       
   566             obj->SetSaved( ETrue );
       
   567             }
       
   568         }
       
   569     else
       
   570         {
       
   571         CMsgViewAttachmentsDialog::ProcessCommandL( EMsgViewAttachmentCmdSave ); 
       
   572 
       
   573         // Set saved information
       
   574         if (    selectedObject.IsSaved( )
       
   575             &&  obj )
       
   576             {
       
   577             obj->SetSaved( ETrue );
       
   578             }
       
   579         }
       
   580     }
       
   581 
       
   582 // ---------------------------------------------------------
       
   583 // CUniObjectsViewDialog::ProcessCommandRemoveL
       
   584 // ---------------------------------------------------------
       
   585 //
       
   586 void CUniObjectsViewDialog::ProcessCommandRemoveL( TInt aIndex )
       
   587     {
       
   588     if ( ( aIndex != -1 ) && iAttachmentModel.NumberOfItems() )
       
   589         {
       
   590         CMsgAttachmentInfo& attInfo = iAttachmentModel.AttachmentInfoAt( aIndex );
       
   591 
       
   592         // Get the file name from atta info full path name.
       
   593         TParsePtrC parser( attInfo.FileName() );
       
   594         TFileName fileName2( parser.NameAndExt() );
       
   595 
       
   596         if ( fileName2.Length() == 0 )
       
   597             {
       
   598             fileName2 = iDataModel.DataUtils().DefaultFileName();
       
   599             }
       
   600 
       
   601         HBufC* prompt = StringLoader::LoadLC( 
       
   602             R_UNUT_QUERY_COMMON_CONF_REMOVE, 
       
   603             fileName2, 
       
   604             iCoeEnv );
       
   605 
       
   606         CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   607         TInt ret = dlg->ExecuteLD( R_UNUT_REMOVE_OBJECT_QUERY, *prompt );
       
   608 
       
   609         CleanupStack::PopAndDestroy( prompt );
       
   610 
       
   611         if ( ret )
       
   612             {
       
   613             TBool removingLastOfSlide = EFalse;
       
   614             TBool setSeparatorToNext = EFalse;
       
   615             if ( iDataModel.SmilModel().SlideObjectCount( SlideNumber( aIndex ) ) == 1 )
       
   616                 {
       
   617                 removingLastOfSlide = ETrue;
       
   618                 }
       
   619             else if ( ( ( aIndex + 1 ) < iAttachmentModel.NumberOfItems() ) &&
       
   620                       ( SlideNumber( aIndex ) == SlideNumber( aIndex + 1 ) ) )
       
   621                 {
       
   622                 CUniObjectsInfo& object = static_cast<CUniObjectsInfo&>
       
   623                     ( iAttachmentModel.AttachmentInfoAt( aIndex ) );
       
   624                 if ( object.IsSeparator() )
       
   625                     {
       
   626                     setSeparatorToNext = ETrue;
       
   627                     }
       
   628                 }
       
   629 
       
   630             // updates listbox after calling RemoveAttachmentL.
       
   631             CMsgViewAttachmentsDialog::ProcessCommandL( EMsgViewAttachmentCmdRemove );
       
   632 
       
   633             if ( removingLastOfSlide )
       
   634                 {
       
   635                 //removing the last object of the slide
       
   636                 CUniObjectsModel& objModel = 
       
   637                     static_cast<CUniObjectsModel&>( iAttachmentModel );
       
   638 
       
   639                 CUniObjectsInfo* info = objModel.AddEmptySlideL(
       
   640                     iDataModel.DataUtils().EmptyPageString(),
       
   641                     aIndex );
       
   642                 if ( aIndex )
       
   643                     {
       
   644                     info->SetSeparator( ETrue );
       
   645                     }
       
   646                 ItemAddedL( aIndex );
       
   647                 }
       
   648             else if ( setSeparatorToNext )
       
   649                 {
       
   650                 CUniObjectsInfo& object2 = static_cast<CUniObjectsInfo&>
       
   651                     ( iAttachmentModel.AttachmentInfoAt( aIndex ) );
       
   652                 object2.SetSeparator( ETrue );
       
   653                 }
       
   654             }
       
   655         }
       
   656     }
       
   657 
       
   658 // ---------------------------------------------------------
       
   659 // CUniObjectsViewDialog::ProcessCommandSendL
       
   660 // ---------------------------------------------------------
       
   661 //
       
   662 void CUniObjectsViewDialog::ProcessCommandSendL( CMessageData&   aMsgData, 
       
   663                                                  TInt aIndex, 
       
   664                                                  TUid aServiceId,
       
   665                                                  TUid aBioUid )
       
   666     {
       
   667     CUniObjectsInfo& selectedObject = static_cast<CUniObjectsInfo&>
       
   668         ( iAttachmentModel.AttachmentInfoAt( aIndex ) );
       
   669     CUniObject* obj = selectedObject.Object();
       
   670 
       
   671     TFileName fileName;
       
   672     CRichText* text = NULL;
       
   673     CFileMan* fileManager = NULL;
       
   674     TSendingCapabilities serviceCapabilities;
       
   675     iSendUi->ServiceCapabilitiesL(  aServiceId,
       
   676                                     serviceCapabilities);
       
   677     TInt supportsBodyText( serviceCapabilities.iFlags & TSendingCapabilities::ESupportsBodyText );
       
   678 
       
   679     if (    // send as body text
       
   680             (   obj->MediaType() == EMsgMediaText 
       
   681             &&  supportsBodyText )
       
   682             // send as atta
       
   683         ||  (   obj->MediaType() == EMsgMediaText &&
       
   684                 obj->MimeInfo()->Charset() != KCharacterSetMIBEnumUTF16BE &&
       
   685                 obj->MimeInfo()->Charset() != KCharacterSetMIBEnumUTF16LE &&
       
   686                 obj->MimeInfo()->Charset() != KCharacterSetMIBEnumUTF16 ) )
       
   687         {
       
   688         aMsgData.ClearAttachmentArray();
       
   689         
       
   690         fileManager = CFileMan::NewL( iEikonEnv->FsSession() );
       
   691         // CSa2
       
   692         CleanupStack::PushL( fileManager );
       
   693         CreateTempTextFileL( obj, fileName );
       
   694         if ( supportsBodyText )
       
   695             {
       
   696             // send as body
       
   697             text = CRichText::NewL( iEikonEnv->SystemParaFormatLayerL(), 
       
   698                                     iEikonEnv->SystemCharFormatLayerL(), 
       
   699                                     CEditableText::EFlatStorage );
       
   700             // CSa3
       
   701             CleanupStack::PushL(text);
       
   702             text->ImportTextFileL(0,fileName,CPlainText::EOrganiseByParagraph);
       
   703 
       
   704             // does not take ownership
       
   705             aMsgData.SetBodyTextL( text );
       
   706             }
       
   707         else
       
   708             {
       
   709             aMsgData.AppendAttachmentL( fileName );
       
   710             }
       
   711         }
       
   712     // else - aMsgData has already the needed handle
       
   713     
       
   714     TRAPD( err, iSendUi->CreateAndSendMessageL( aServiceId, &aMsgData, aBioUid ) );
       
   715     if ( text )
       
   716         {
       
   717         CleanupStack::PopAndDestroy( text );
       
   718         }
       
   719     if ( fileManager )
       
   720         {
       
   721         // Remove temp file & dir
       
   722         fileManager->Delete( fileName );
       
   723         fileManager->RmDir( fileName ); // remove directory
       
   724         CleanupStack::PopAndDestroy( fileManager ); 
       
   725         }
       
   726     User::LeaveIfError( err );
       
   727     }
       
   728 
       
   729 // ---------------------------------------------------------
       
   730 // CUniObjectsViewDialog::CreateTempTextFileL
       
   731 // ---------------------------------------------------------
       
   732 //
       
   733 void CUniObjectsViewDialog::CreateTempTextFileL( CUniObject* aObject, TFileName& aTempFileName )
       
   734     {
       
   735     CreateTempPathL( aObject->MediaInfo()->FullFilePath(), aTempFileName );
       
   736 
       
   737     TUint mibCharset = aObject->MimeInfo()->Charset();
       
   738     if ( !mibCharset )
       
   739         {
       
   740         //assume US-ASCII - mandated by RFC 2046
       
   741         mibCharset = KCharacterSetMIBEnumUsAscii;
       
   742         }
       
   743     TUint charconvCharsetID = iDataModel.DataUtils().MibIdToCharconvIdL( mibCharset );
       
   744 
       
   745     // Import text
       
   746     CPlainText* text = CPlainText::NewL();
       
   747     CleanupStack::PushL( text );
       
   748 
       
   749     RFile file = CUniDataUtils::GetAttachmentFileL( iDataModel.Mtm(), aObject->AttachmentId() );
       
   750     CleanupClosePushL( file );
       
   751 
       
   752     RFileReadStream input_stream( file );
       
   753     CleanupClosePushL( input_stream );
       
   754     
       
   755     CPlainText::TImportExportParam param;
       
   756     param.iForeignEncoding = charconvCharsetID;
       
   757     CPlainText::TImportExportResult result;
       
   758     text->ImportTextL( 0, input_stream, param, result );
       
   759 
       
   760     CleanupStack::PopAndDestroy( 2 ); // input_stream, file
       
   761     
       
   762     // Export text as UCS-2
       
   763     text->ExportAsTextL( aTempFileName, CPlainText::EOrganiseByParagraph, 0 );
       
   764     CleanupStack::PopAndDestroy(); //text
       
   765     }
       
   766 
       
   767 // ---------------------------------------------------------
       
   768 // CUniObjectsViewDialog::CreateTempPathL
       
   769 // ---------------------------------------------------------
       
   770 //
       
   771 void CUniObjectsViewDialog::CreateTempPathL( const TDesC& aFileName, TFileName& aTempFileName )
       
   772     {
       
   773     // Create temp path
       
   774     TParsePtrC parser( aFileName );
       
   775     MsgAttachmentUtils::GetMsgEditorTempPath( aTempFileName );
       
   776     aTempFileName.Append( KMmsFormatTwoDigits );
       
   777     TTime time;
       
   778     time.UniversalTime();
       
   779     TBuf<KMaxFileName> tempDir;
       
   780     tempDir.Format( aTempFileName, I64HIGH( time.Int64() ), I64LOW( time.Int64() ) );
       
   781     iEikonEnv->FsSession().MkDir( tempDir );
       
   782     aTempFileName = tempDir;
       
   783     aTempFileName.Append( parser.NameAndExt() );
       
   784     }
       
   785 
       
   786 // ---------------------------------------------------------
       
   787 // CUniObjectsViewDialog::OfferKeyEventL
       
   788 //
       
   789 // Handles key events. 
       
   790 // ---------------------------------------------------------
       
   791 //
       
   792 TKeyResponse CUniObjectsViewDialog::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
   793                                                     TEventCode aType )
       
   794     {
       
   795     if ( aType == EEventKey && !MenuShowing() )
       
   796         {
       
   797         CUniObjectsInfo& selectedObject = static_cast<CUniObjectsInfo&>
       
   798             ( iAttachmentModel.AttachmentInfoAt( CurrentListItemIndex() ) );
       
   799 
       
   800         TBool emptySlide = ( selectedObject.Flags() & CUniObjectsInfo::EMmsSlide );
       
   801         switch ( aKeyEvent.iCode )
       
   802             {
       
   803             case EKeyEnter:
       
   804             case EKeyOK:
       
   805                 if ( !emptySlide )
       
   806                     {
       
   807                     ProcessCommandL(EMsgViewAttachmentCmdOpen);
       
   808                     }
       
   809                 return EKeyWasConsumed;
       
   810 
       
   811             default:
       
   812                 break;
       
   813             }
       
   814 
       
   815         switch ( aKeyEvent.iScanCode )
       
   816             {
       
   817             case EStdKeyBackspace:
       
   818             case EStdKeyDelete:
       
   819                 {
       
   820                 if ( ( iDialogType == EEditor && 
       
   821                        !emptySlide ) ||
       
   822                      ( iDialogType == EForward && 
       
   823                        iDataModel.AttachmentList().Count() != 0 &&
       
   824                        SlideNumber( CurrentListItemIndex() == SlideNumber( iAttachmentModel.NumberOfItems() - 1 ) ) ) )
       
   825                     {
       
   826                     // Delete object if in editor mode and something else that empty slide is focuse.
       
   827                     // On forward mode deleting is enabled when attachment is focused.
       
   828                     ProcessCommandL(EMsgViewAttachmentCmdRemove);
       
   829                     }
       
   830                 // else - No operation
       
   831                 return EKeyWasConsumed;
       
   832                 }
       
   833             case EStdKeyYes:
       
   834             case EStdKeyNo:
       
   835                 {
       
   836                 // No operation
       
   837                 return EKeyWasConsumed;
       
   838                 }
       
   839             default:
       
   840                 {
       
   841                 // No operation by default
       
   842                 break;
       
   843                 }
       
   844             }
       
   845         }
       
   846 
       
   847     return CMsgViewAttachmentsDialog::OfferKeyEventL(aKeyEvent, aType);
       
   848     }
       
   849 
       
   850 // ---------------------------------------------------------
       
   851 // CUniObjectsViewDialog::DynInitMenuPaneL
       
   852 // ---------------------------------------------------------
       
   853 //
       
   854 void CUniObjectsViewDialog::DynInitMenuPaneL( TInt aMenuId, 
       
   855                                               CEikMenuPane* aMenuPane)
       
   856     {
       
   857     CMsgViewAttachmentsDialog::DynInitMenuPaneL( aMenuId, aMenuPane );
       
   858 
       
   859     TInt index = CurrentListItemIndex();
       
   860     TInt currentSlide = SlideNumber( index );
       
   861 
       
   862     if ( !(iSupportedFeatures & EUniFeatureHelp) )
       
   863         {
       
   864         aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   865         }
       
   866 
       
   867     switch ( aMenuId )
       
   868         {
       
   869         case R_MEB_ATTACHMENTS_MENUPANE:
       
   870             if ( index == -1 || ! iAttachmentModel.NumberOfItems() )
       
   871                 {
       
   872                 // no selection or empty list.
       
   873 
       
   874                 aMenuPane->SetItemDimmed( EMsgViewAttachmentCmdOpen, ETrue );
       
   875 
       
   876                 if ( iDialogType == EEditor )
       
   877                     {
       
   878                     aMenuPane->SetItemDimmed( EMsgViewAttachmentCmdRemove, ETrue );
       
   879                     }
       
   880                 else if ( iDialogType == EViewer )
       
   881                     {
       
   882                     aMenuPane->SetItemDimmed( EMsgViewAttachmentCmdSave, ETrue );
       
   883                     }
       
   884                 }
       
   885             else
       
   886                 {
       
   887                 CUniObjectsInfo& selectedObject = static_cast<CUniObjectsInfo&>
       
   888                     ( iAttachmentModel.AttachmentInfoAt( index ) );
       
   889 
       
   890                 if ( iDialogType == EEditor )
       
   891                     {
       
   892                     if ( selectedObject.Flags() & CUniObjectsInfo::EMmsSlide )
       
   893                         {
       
   894                         aMenuPane->SetItemDimmed( EMsgViewAttachmentCmdOpen, ETrue );
       
   895                         aMenuPane->SetItemDimmed( EMsgViewAttachmentCmdRemove, ETrue );
       
   896                         }
       
   897                     TUniLayout layout = iDataModel.SmilModel().Layout();
       
   898                     if ( layout == EUniTextFirst )
       
   899                         {
       
   900                         aMenuPane->SetItemDimmed( EMmsObjectsTextFirst, ETrue );
       
   901                         }
       
   902                     else if ( layout == EUniImageFirst )
       
   903                         {
       
   904                         aMenuPane->SetItemDimmed( EMmsObjectsTextSecond,  ETrue );
       
   905                         }
       
   906                     
       
   907                     // either image or text object present but no both: no order menus.
       
   908                     // Not shown on Japanese variant ever.
       
   909                     if ( !IsImageAndTextPresent() ||
       
   910                          iSupportedFeatures & EUniFeatureJapanese )
       
   911                         {
       
   912                         aMenuPane->SetItemDimmed( EMmsObjectsTextFirst, ETrue );
       
   913                         aMenuPane->SetItemDimmed( EMmsObjectsTextSecond, ETrue );
       
   914                         }
       
   915                     }
       
   916                 else if ( iDialogType == EViewer )
       
   917                     {
       
   918                     CUniObject* obj = selectedObject.Object();
       
   919                     TBool showSendMenu = ETrue;
       
   920 
       
   921                     if ( selectedObject.Flags() & CUniObjectsInfo::EMmsSlide )
       
   922                         {
       
   923                         aMenuPane->SetItemDimmed( EMsgViewAttachmentCmdOpen, ETrue );
       
   924                         aMenuPane->SetItemDimmed( EMsgViewAttachmentCmdSave, ETrue );
       
   925                         showSendMenu = EFalse;
       
   926                         }
       
   927                     if ( index != -1 )
       
   928                         {
       
   929                         // Catch this leave. If something peculiar coming in msg headers
       
   930                         // and atta not natively handled by viewer CanSave might leave.
       
   931                         // ETC. application/x-epocinstall
       
   932                         TBool canSave = EFalse;
       
   933                         TRAPD( err, canSave = iDocHandler->CanSaveL( selectedObject.DataType() ) );
       
   934                         if ( err )
       
   935                             {
       
   936                             canSave = EFalse;
       
   937                             }
       
   938                         if ( !canSave )
       
   939                             {
       
   940                             aMenuPane->SetItemDimmed( EMsgViewAttachmentCmdSave, ETrue );
       
   941                             }
       
   942 
       
   943                         // Send menu if full OMA DRM and mime type does not belong to CCL
       
   944                         if ( !obj ||  
       
   945                             ( ! ( iSupportedFeatures & EUniFeatureDrmFull ) && 
       
   946                                   obj->MediaInfo()->Protection() != EFileProtNoProtection )
       
   947                             // SD closed content objects can be forwarded.
       
   948                             // UI spec allows FL items to be sent from objects view,
       
   949                             // however, Send UI blocks sending.
       
   950                             ||  ( iSupportedFeatures & EUniFeatureDrmFull && 
       
   951                                 obj->MediaInfo()->Protection() == EFileProtClosedContent ) )
       
   952                               {
       
   953                             showSendMenu = EFalse;
       
   954                             }
       
   955                         }
       
   956 
       
   957                     if ( iSendUi && showSendMenu )
       
   958                         {
       
   959                         TInt pos = 0;
       
   960                         aMenuPane->ItemAndPos( EAknCmdExit, pos );
       
   961 
       
   962                         if ( iSupportedFeatures & EUniFeatureHelp )
       
   963                             {
       
   964                             pos -= 1;
       
   965                             }
       
   966                         // TSendingCapabilities::ESupportsAttachments is enough
       
   967                         // although bio and body text are possible but they are 
       
   968                         // subset of attachment support
       
   969                         iSendUi->AddSendMenuItemL(
       
   970                             *aMenuPane,
       
   971                             pos,
       
   972                             EMmsObjectsSendVia,
       
   973                             TSendingCapabilities( 
       
   974                                 0, 
       
   975                                 0, 
       
   976                                 TSendingCapabilities::ESupportsAttachments )
       
   977                             );
       
   978                         }
       
   979                     }
       
   980                 else if ( iDialogType == EForward )
       
   981                     {
       
   982                     // show remove for attachments...
       
   983                     if ( !( iDataModel.AttachmentList().Count() &&
       
   984                             currentSlide == SlideNumber( iAttachmentModel.NumberOfItems() - 1 ) ) )
       
   985                         {
       
   986                         // the attachments are in the last "slide"
       
   987                         aMenuPane->SetItemDimmed( EMsgViewAttachmentCmdRemove, ETrue );
       
   988                         }
       
   989                     }
       
   990                 }
       
   991             break;
       
   992 
       
   993         default:
       
   994             break;
       
   995         }
       
   996     }
       
   997 
       
   998 // ---------------------------------------------------------
       
   999 // CUniObjectsViewDialog::HandleServerAppExit
       
  1000 // ---------------------------------------------------------
       
  1001 //
       
  1002 void CUniObjectsViewDialog::HandleServerAppExit( TInt aReason )
       
  1003     {
       
  1004     CMsgViewAttachmentsDialog::HandleServerAppExit( aReason );
       
  1005  
       
  1006     TInt currentIndex( CurrentListItemIndex() );
       
  1007     
       
  1008     CUniObjectsInfo& selectedObject = 
       
  1009         static_cast<CUniObjectsInfo&>( iAttachmentModel.AttachmentInfoAt( currentIndex ) );
       
  1010     CUniObject* obj = selectedObject.Object();
       
  1011     
       
  1012     CMsgAttachmentInfo::TDRMDataType drmType = CMsgAttachmentInfo::ENoLimitations;
       
  1013     TRAPD( error, drmType = static_cast<CMsgAttachmentInfo::TDRMDataType>( GetObjectsInfoDRMTypeL( *obj ) ) );
       
  1014                         
       
  1015     if ( error == KErrNone && 
       
  1016          drmType != selectedObject.DRMDataType() )
       
  1017         {
       
  1018         selectedObject.SetDRMDataType( drmType );
       
  1019         UpdateIcon( currentIndex );
       
  1020         }
       
  1021     }
       
  1022 
       
  1023 // ---------------------------------------------------------
       
  1024 // CUniObjectsViewDialog::SlideNumber
       
  1025 // ---------------------------------------------------------
       
  1026 //
       
  1027 TInt CUniObjectsViewDialog::SlideNumber( TInt aIndex )
       
  1028     {
       
  1029     TInt currentSlide = 0;
       
  1030     for ( TInt i = 0; i <= aIndex; i++ )
       
  1031         {
       
  1032         CUniObjectsInfo& object = static_cast<CUniObjectsInfo&>
       
  1033             ( iAttachmentModel.AttachmentInfoAt( i ) );
       
  1034         if ( object.IsSeparator() )
       
  1035             {
       
  1036             currentSlide++;
       
  1037             }
       
  1038         }
       
  1039     return currentSlide;
       
  1040     }
       
  1041 
       
  1042 // ---------------------------------------------------------
       
  1043 // CUniObjectsViewDialog::IsImageAndTextPresent
       
  1044 // ---------------------------------------------------------
       
  1045 //
       
  1046 TBool CUniObjectsViewDialog::IsImageAndTextPresent()
       
  1047     {
       
  1048     TBool textFound = EFalse;
       
  1049     TBool imageFound = EFalse;
       
  1050     TInt slides = iDataModel.SmilModel().SlideCount();
       
  1051     for ( TInt i = 0; i < slides && !( textFound && imageFound ); i++ )
       
  1052         {
       
  1053         if ( !textFound && iDataModel.SmilModel().GetObject( i, EUniRegionText ) )
       
  1054             {
       
  1055             textFound = ETrue;
       
  1056             }
       
  1057         if ( !imageFound && iDataModel.SmilModel().GetObject( i, EUniRegionImage ) )
       
  1058             {
       
  1059             imageFound = ETrue;
       
  1060             }
       
  1061         }
       
  1062     return ( textFound && imageFound );
       
  1063     }
       
  1064 
       
  1065 
       
  1066 // ---------------------------------------------------------
       
  1067 // CUniObjectsViewDialog::RemoveAttachmentL
       
  1068 // ---------------------------------------------------------
       
  1069 //
       
  1070 void CUniObjectsViewDialog::RemoveAttachmentL( TInt aIndex )
       
  1071     {
       
  1072     CUniObjectsModel& objModel = static_cast<CUniObjectsModel&>( iAttachmentModel );
       
  1073 
       
  1074     // delete item from attachment model (notifies its observer about deletion).
       
  1075     objModel.DeleteObjectL( aIndex, ETrue );
       
  1076     }
       
  1077 
       
  1078 // ---------------------------------------------------------
       
  1079 // CUniObjectsViewDialog::ChangeOrderL
       
  1080 // ---------------------------------------------------------
       
  1081 //
       
  1082 void CUniObjectsViewDialog::ChangeOrderL( TInt aCommandId, 
       
  1083                                           TInt /*aNewPosition*/ )
       
  1084     {
       
  1085     CUniObjectsModel& objModel = static_cast<CUniObjectsModel&>( iAttachmentModel );
       
  1086 
       
  1087     TInt count = iAttachmentModel.NumberOfItems();
       
  1088     TInt currentSlide = 0;
       
  1089     TInt i = 0;
       
  1090 
       
  1091     while ( i < count )
       
  1092         {
       
  1093         CUniObjectsInfo& firstObject = static_cast<CUniObjectsInfo&>
       
  1094             ( iAttachmentModel.AttachmentInfoAt( i ) );
       
  1095         i++;
       
  1096         if ( i < count )
       
  1097             {
       
  1098             if ( currentSlide == SlideNumber( i ) )
       
  1099                 {
       
  1100                 CUniObjectsInfo& secondObject = static_cast<CUniObjectsInfo&>
       
  1101                     ( iAttachmentModel.AttachmentInfoAt( i ) );
       
  1102                 if ( secondObject.Type() != MsgAttachmentUtils::EAudio )
       
  1103                     {
       
  1104                     if ( firstObject.IsSeparator() )
       
  1105                         {
       
  1106                         firstObject.SetSeparator( EFalse );
       
  1107                         secondObject.SetSeparator( ETrue );
       
  1108                         }
       
  1109                     objModel.ChangeOrderL( i, i - 1 );
       
  1110                     iListBox->HandleItemAdditionL();
       
  1111                     i++;
       
  1112                     if ( i < count )
       
  1113                         {
       
  1114                         if ( currentSlide == SlideNumber( i ) )
       
  1115                             {
       
  1116                             // there was 3rd object on the same slide
       
  1117                             i++;
       
  1118                             }
       
  1119                         }
       
  1120                     }
       
  1121                 else
       
  1122                     {
       
  1123                     // second object was audio
       
  1124                     // its always the last object of the slide
       
  1125                     i++;
       
  1126                     }
       
  1127                 }
       
  1128             }
       
  1129         currentSlide++;
       
  1130         }
       
  1131     
       
  1132     TUniLayout layout( EUniTextFirst );
       
  1133     if ( aCommandId == EMmsObjectsTextSecond )
       
  1134         {
       
  1135         layout = EUniImageFirst;
       
  1136         }
       
  1137     objModel.NotifyChangeOrderL( layout );
       
  1138     }
       
  1139 
       
  1140 // ----------------------------------------------------
       
  1141 // CUniObjectsViewDialog::LaunchHelpL
       
  1142 // launch help using context
       
  1143 // ----------------------------------------------------
       
  1144 //
       
  1145 void CUniObjectsViewDialog::LaunchHelpL()
       
  1146     {
       
  1147     if ( iSupportedFeatures & EUniFeatureHelp )
       
  1148         {
       
  1149         CCoeAppUi* editorAppUi = static_cast<CCoeAppUi*>( ControlEnv()->AppUi() );
       
  1150 
       
  1151         CArrayFix<TCoeHelpContext>* helpContext = editorAppUi->AppHelpContextL();
       
  1152         HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), helpContext );
       
  1153         }
       
  1154     }
       
  1155 
       
  1156 // ----------------------------------------------------
       
  1157 // CUniObjectsViewDialog::GetHelpContext
       
  1158 // returns helpcontext as aContext
       
  1159 // ----------------------------------------------------
       
  1160 //
       
  1161 void CUniObjectsViewDialog::GetHelpContext( TCoeHelpContext& aContext ) const
       
  1162     {
       
  1163     if ( iSupportedFeatures & EUniFeatureHelp )
       
  1164         {
       
  1165         if ( iDialogType == EViewer )
       
  1166             {
       
  1167             aContext.iContext = KMMS_HLP_OBJECTS_VIEW_VIEWER;
       
  1168 	        aContext.iMajor = KUidMmsViewer;
       
  1169             }
       
  1170         else
       
  1171             {
       
  1172             aContext.iContext = KUNIFIED_HLP_ED_OBJECTS;
       
  1173 			aContext.iMajor = KUniEditorAppId; 
       
  1174             }
       
  1175         }
       
  1176     }
       
  1177 
       
  1178 // ---------------------------------------------------------
       
  1179 // CUniObjectsViewDialog::BioMessageTypeL
       
  1180 // ---------------------------------------------------------
       
  1181 //
       
  1182 TBool CUniObjectsViewDialog::BioMessageTypeL( TPtrC8    aMimeType,
       
  1183                                               TUid&     aBioUid )
       
  1184     {
       
  1185     // Check bio message type
       
  1186     TBool isBio = EFalse;
       
  1187     HBufC* sample = HBufC::NewLC( aMimeType.Length() );
       
  1188     TPtr samplePtr = sample->Des();
       
  1189     samplePtr.Copy( aMimeType );
       
  1190     
       
  1191     // need to create local RFs for BIO otherwise raises exception
       
  1192     RFs& fs( CCoeEnv::Static()->FsSession() );
       
  1193     CBIODatabase* bioDB = CBIODatabase::NewLC( fs );
       
  1194 
       
  1195     // IsBioMessageL returns KErrNone if found or KErrNotFound if not found 
       
  1196     if ( bioDB->IsBioMessageL( EBioMsgIdIana, samplePtr, NULL, aBioUid ) == KErrNone)
       
  1197         {
       
  1198         isBio = ETrue;
       
  1199         }
       
  1200     CleanupStack::PopAndDestroy( 2, sample ); // + bioDb
       
  1201 
       
  1202     return isBio;
       
  1203     }
       
  1204 
       
  1205 // ---------------------------------------------------------
       
  1206 // CUniObjectsViewDialog::PopulateAttachmentModelL
       
  1207 //
       
  1208 // Creates new attachment model from smilmodel content for 
       
  1209 // objectsview usage
       
  1210 // ---------------------------------------------------------
       
  1211 //
       
  1212 void CUniObjectsViewDialog::PopulateAttachmentModelL( CUniObjectsModel& aObjectsViewModel,
       
  1213                                                       CUniDataModel& aUniDataModel )
       
  1214     {
       
  1215     TInt slideCount = 0;
       
  1216     TUniSmilType smilType( aUniDataModel.SmilType() );
       
  1217     
       
  1218     if ( smilType == EMmsSmil ||
       
  1219          smilType == ENoSmil ||
       
  1220          smilType == EMultipleSmil )
       
  1221         {
       
  1222         slideCount = aUniDataModel.SmilModel().SlideCount();
       
  1223         // Populate attamodel from smilmodel
       
  1224         for ( TInt i = 0; i < slideCount; i++ )
       
  1225             {
       
  1226             if ( !aUniDataModel.SmilModel().SlideObjectCount( i ) )
       
  1227                 {
       
  1228                 CUniObjectsInfo* info = aObjectsViewModel.AddEmptySlideL(
       
  1229                                             aUniDataModel.DataUtils().EmptyPageString() );
       
  1230                 if ( i ) // no separator for first slide
       
  1231                     {
       
  1232                     info->SetSeparator(ETrue);
       
  1233                     }
       
  1234                 }
       
  1235                 
       
  1236             for ( TInt ii = 0; ii < aUniDataModel.SmilModel().SlideObjectCount( i ); ii++ )
       
  1237                 {
       
  1238                 CUniObjectsInfo* info = CreateObjectsInfoL( 
       
  1239                                             aObjectsViewModel,
       
  1240                                             *aUniDataModel.SmilModel().GetObjectByIndex( i, ii ),
       
  1241                                             EFalse,
       
  1242                                             i );
       
  1243                 // Slide separators. Drawn on top of list item -> needs to be drawn for
       
  1244                 // first item in slide. Don't draw for the first slide.
       
  1245                 if ( info && i > 0 && ii == 0 )
       
  1246                     {
       
  1247                     info->SetSeparator( ETrue );
       
  1248                     }
       
  1249                 }
       
  1250             }
       
  1251         }
       
  1252     else
       
  1253         {
       
  1254         slideCount = Max( aUniDataModel.ObjectList().Count(), 1 ); 
       
  1255         for ( TInt j = 0; j < aUniDataModel.ObjectList().Count(); j++ )
       
  1256             {
       
  1257             CreateObjectsInfoL( aObjectsViewModel, 
       
  1258                                 *aUniDataModel.ObjectList().GetByIndex( j ),
       
  1259                                 EFalse,
       
  1260                                 0 );
       
  1261             }
       
  1262         }
       
  1263 
       
  1264     //add attachments to the end
       
  1265     for ( TInt k = 0; k < aUniDataModel.AttachmentList().Count(); k++ )
       
  1266         {
       
  1267         CUniObjectsInfo* info = CreateObjectsInfoL( aObjectsViewModel, 
       
  1268                                                     *aUniDataModel.AttachmentList().GetByIndex( k ),
       
  1269                                                     ETrue,
       
  1270                                                     -1 );
       
  1271         info->SetSupported( EFalse );
       
  1272         if ( k == 0 && slideCount )
       
  1273             {
       
  1274             info->SetSeparator( ETrue );
       
  1275             }
       
  1276         }
       
  1277     }
       
  1278 
       
  1279 // ---------------------------------------------------------
       
  1280 // CUniObjectsViewDialog::CreateObjectsInfoL
       
  1281 //
       
  1282 // Creates CUniObjectsInfo object ands it to objects view
       
  1283 // model. Objects view model has the ownership of the
       
  1284 // new CUniObjectsInfo object.
       
  1285 // ---------------------------------------------------------
       
  1286 //
       
  1287 CUniObjectsInfo* CUniObjectsViewDialog::CreateObjectsInfoL( CUniObjectsModel& aObjectsViewModel,
       
  1288                                                             CUniObject& aObject,
       
  1289                                                             TBool aAttachmentObject,
       
  1290                                                             TInt aSlideNumber )
       
  1291     {
       
  1292     CUniObjectsInfo* info = NULL;
       
  1293     TInt drmType = GetObjectsInfoDRMTypeL( aObject );
       
  1294     info = aObjectsViewModel.AddObjectL( aObject, drmType, aAttachmentObject, aSlideNumber );
       
  1295 
       
  1296     TBool supported = ETrue;
       
  1297     switch ( aObject.MediaType() )
       
  1298         {
       
  1299         case EMsgMediaText:
       
  1300             info->SetType( MsgAttachmentUtils::ENote );
       
  1301             break;
       
  1302         case EMsgMediaImage:
       
  1303             info->SetType( MsgAttachmentUtils::EImage );
       
  1304             break;
       
  1305         case EMsgMediaVideo:
       
  1306             info->SetType( MsgAttachmentUtils::EVideo );
       
  1307             break;
       
  1308         case EMsgMediaAudio:
       
  1309             info->SetType( MsgAttachmentUtils::EAudio );
       
  1310             break;
       
  1311 #ifdef RD_SVGT_IN_MESSAGING            
       
  1312         case EMsgMediaSvg:
       
  1313             {
       
  1314             info->SetType( MsgAttachmentUtils::ESVG );
       
  1315             break;
       
  1316             }
       
  1317 #endif
       
  1318         default:
       
  1319             info->SetType( MsgAttachmentUtils::EUnknown );
       
  1320             supported = EFalse;
       
  1321             break;
       
  1322         }
       
  1323     info->SetSupported( supported );
       
  1324     return info;
       
  1325     }
       
  1326 
       
  1327 // ---------------------------------------------------------
       
  1328 // CUniObjectsViewDialog::GetObjectsInfoDRMTypeL
       
  1329 // ---------------------------------------------------------
       
  1330 //
       
  1331 TInt CUniObjectsViewDialog::GetObjectsInfoDRMTypeL( CUniObject& aObject )
       
  1332     {
       
  1333     if ( aObject.DrmInfo() &&
       
  1334          ( aObject.MediaInfo()->Protection() &
       
  1335            ( EFileProtForwardLocked | EFileProtSuperDistributable ) ) )
       
  1336         {
       
  1337         // Changed EFalse->ETrue. 
       
  1338         // Use case to motivate this: object has not no rights -> Objects view ->
       
  1339         // player launched -> rights are retrieved -> back to objects view ->
       
  1340         // back to viewer -> object view again: in this phase wrong icon
       
  1341         // would be shown unless rights are resolved again
       
  1342         if ( aObject.DrmInfo()->RightsValidL( ETrue ) )
       
  1343             {
       
  1344             if ( aObject.MediaInfo()->Protection() & EFileProtForwardLocked )
       
  1345                 {
       
  1346                 return CMsgAttachmentInfo::EForwardLockedOrCombinedDelivery;
       
  1347                 }
       
  1348             else // EMmsSuperDistributable
       
  1349                 {
       
  1350                 return CMsgAttachmentInfo::ESeparateDeliveryValidRights;
       
  1351                 }
       
  1352             }
       
  1353         else
       
  1354             {
       
  1355             if ( aObject.MediaInfo()->Protection() & EFileProtForwardLocked )
       
  1356                 {
       
  1357                 return CMsgAttachmentInfo::ECombinedDeliveryInvalidRights;
       
  1358                 }
       
  1359             else // EMmsSuperDistributable
       
  1360                 {
       
  1361                 return CMsgAttachmentInfo::ESeparateDeliveryInvalidRights;
       
  1362                 }
       
  1363             }
       
  1364         }
       
  1365     return CMsgAttachmentInfo::ENoLimitations;
       
  1366     }
       
  1367 
       
  1368 // ---------------------------------------------------------
       
  1369 // CUniObjectsViewDialog::GetObjectsInfoDRMTypeL
       
  1370 // ---------------------------------------------------------
       
  1371 //
       
  1372 void CUniObjectsViewDialog::HandleUniObjectEvent(   CUniObject&  aUniObject,
       
  1373                                                     TUniObjectEvent aUniEvent )
       
  1374     {
       
  1375     UNILOGGER_ENTERFN( "CUniObjectsViewDialog::HandleUniObjectEvent" );
       
  1376     if (    aUniEvent == EUniObjectEventDrmRightsChanged
       
  1377         &&  aUniObject.DrmInfo()
       
  1378         &&  (   (   IsDrmRightsWhenLoaded( aUniObject )
       
  1379                 &&  !IsRightsNow( aUniObject ) )
       
  1380             ||  (   !IsDrmRightsWhenLoaded( aUniObject )
       
  1381                 &&  IsRightsNow( aUniObject ) )
       
  1382             )
       
  1383         )
       
  1384         {        
       
  1385         CMsgAttachmentInfo::TDRMDataType drmType = CMsgAttachmentInfo::ENoLimitations;
       
  1386         if ( IsRightsNow( aUniObject ) )
       
  1387             {
       
  1388             if ( aUniObject.MediaInfo()->Protection() & EFileProtForwardLocked )
       
  1389                 {
       
  1390                 drmType = CMsgAttachmentInfo::EForwardLockedOrCombinedDelivery;
       
  1391                 }
       
  1392             else // EMmsSuperDistributable
       
  1393                 {
       
  1394                 drmType = CMsgAttachmentInfo::ESeparateDeliveryValidRights;
       
  1395                 }
       
  1396             }
       
  1397         else
       
  1398             {
       
  1399             if ( aUniObject.MediaInfo()->Protection() & EFileProtForwardLocked )
       
  1400                 {
       
  1401                 drmType = CMsgAttachmentInfo::ECombinedDeliveryInvalidRights;
       
  1402                 }
       
  1403             else // EMmsSuperDistributable
       
  1404                 {
       
  1405                 drmType = CMsgAttachmentInfo::ESeparateDeliveryInvalidRights;
       
  1406                 }
       
  1407             }
       
  1408         UNILOGGER_WRITEF( _L("CUniObjectsViewDialog::HandleUniObjectEvent: drmType = %d "), drmType );
       
  1409 
       
  1410         // when 'DRM rights when loaded info'
       
  1411         aUniObject.SetDrmRightsWhenLoadedObjects( IsRightsNow( aUniObject ) );
       
  1412 
       
  1413         // search for the CUniObjectsInfo 
       
  1414         CUniObjectsModel& model( static_cast<CUniObjectsModel&>( iAttachmentModel ) );
       
  1415         TInt countObjects = model.NumberOfItems( );
       
  1416         for ( TInt i = 0; i < countObjects; i++ )
       
  1417             {
       
  1418             CUniObjectsInfo&  uniObjectInfo =
       
  1419                 static_cast<CUniObjectsInfo&>( model.AttachmentInfoAt( i ) );
       
  1420 
       
  1421             CUniObject* obj = uniObjectInfo.Object();
       
  1422             if ( obj == &aUniObject )
       
  1423                 {
       
  1424                 if ( drmType != uniObjectInfo.DRMDataType() )
       
  1425                     {
       
  1426                     UNILOGGER_WRITE( "CUniObjectsViewDialog::HandleUniObjectEvent setting new icon " );
       
  1427                     uniObjectInfo.SetDRMDataType( drmType );
       
  1428                     }
       
  1429                 }
       
  1430             }
       
  1431         DrawNow( );
       
  1432         }
       
  1433     }
       
  1434     
       
  1435 // ---------------------------------------------------------
       
  1436 // IsRightsNow
       
  1437 // ---------------------------------------------------------
       
  1438 //
       
  1439 TBool CUniObjectsViewDialog::IsRightsNow( CUniObject& aObject ) const
       
  1440     {
       
  1441     TBool rightsNow( EFalse );
       
  1442     if (  aObject.DrmInfo( ) )
       
  1443         {
       
  1444         TInt consumed( EFalse );
       
  1445         // KErrNone: rights exist
       
  1446         rightsNow = !aObject.DrmInfo( )->EvaluateRights( consumed );
       
  1447         }
       
  1448     UNILOGGER_WRITEF( _L("CUniObjectsViewDialog::IsRightsNow: rightsNow = %d "), rightsNow );
       
  1449     return rightsNow;
       
  1450     }
       
  1451     
       
  1452 // ---------------------------------------------------------
       
  1453 // IsDrmRightsWhenLoaded
       
  1454 // ---------------------------------------------------------
       
  1455 //
       
  1456 TBool CUniObjectsViewDialog::IsDrmRightsWhenLoaded( CUniObject& aObject ) const
       
  1457     {
       
  1458     // Separate function just because of LOG traces
       
  1459     TBool rightsWhenLoaded = aObject.IsDrmRightsWhenLoadedObjects();
       
  1460     UNILOGGER_WRITEF( _L("CUniObjectsViewDialog::IsDrmRightsWhenLoaded: rightsWhenLoaded = %d "), rightsWhenLoaded );
       
  1461     return rightsWhenLoaded;
       
  1462     }
       
  1463 
       
  1464 // End of File