email/mail/EditorSrc/MsgMailEditorDocument.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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:  Implements document class of Mail Editor
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "MsgMailEditorDocument.h"
       
    21 #include "MsgMailEditorAppUi.h"
       
    22 #include "MsgMailPreferences.h"
       
    23 #include "MsgMailDRMHandler.h"
       
    24 #include "MailUtils.h"
       
    25 #include "CMailCRHandler.h"
       
    26 
       
    27 #include <cntdef.h>
       
    28 #include <mtclreg.h>                 // for CClientMtmRegistry
       
    29 #include <mtmuibas.h>                // for CBaseMtmUi
       
    30 #include <miutmsg.h>
       
    31 #include <akninputblock.h>           // CAknInputBlock
       
    32 #include <MuiuOperationWait.h> // CMuiuOperationWait
       
    33 #include <MuiuMsgEditorLauncher.h>
       
    34 #include <MuiuMsvUiServiceUtilities.h>
       
    35 #include <mmsvattachmentmanager.h>
       
    36 #include <coeutils.h>
       
    37 #include <featmgr.h>
       
    38 #include <bldvariant.hrh>
       
    39 #include <MsgEditor.hrh>
       
    40 #include <MsgAttachmentInfo.h>
       
    41 #include <MsgAttachmentModel.h>
       
    42 #include <MsgMailEditor.rsg>
       
    43 #include <mtmuibas.h>
       
    44 #include <MTMStore.h>
       
    45 #include <SendUiConsts.h>
       
    46 
       
    47 // ================= MEMBER FUNCTIONS =======================
       
    48 
       
    49 // Constructor
       
    50 CMsgMailEditorDocument::CMsgMailEditorDocument( CEikApplication& aApp )
       
    51     : CMsgMailDocument( aApp )
       
    52     { 
       
    53     }
       
    54 
       
    55 // destructor
       
    56 CMsgMailEditorDocument::~CMsgMailEditorDocument()
       
    57     {
       
    58     delete iPrefs;
       
    59     iPrefs = NULL; // owned by CMsgMailDocument
       
    60     delete iMailCRHandler;
       
    61     delete iEmailApi;
       
    62     iEmailApi = NULL;
       
    63     iMailboxArray.Close();    
       
    64     }
       
    65 // ----------------------------------------------------------------------------
       
    66 // CMsgMailEditorDocument::ConstructL()
       
    67 // Symbian OS constructor can leave.
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 void CMsgMailEditorDocument::ConstructL()
       
    71     {
       
    72     CMsgEditorDocument::ConstructL();
       
    73     iMailCRHandler = CMailCRHandler::NewL( this );
       
    74     iEmailApi = CreateEmailApiL( &(Session()) );
       
    75 
       
    76     iPrefs = new (ELeave) CMsgMailPreferences();
       
    77     iPrefs->SetEncodingSupport( iMailCRHandler->MailEncodingSetting() );
       
    78     
       
    79     PrepareMtmL( KSenduiMtmSmtpUid );
       
    80     }
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // CMsgMailEditorDocument::NewL()
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 CMsgMailEditorDocument* CMsgMailEditorDocument::NewL( 
       
    87         CEikApplication& aApp )     // CMsgMailEditorApp reference
       
    88     {
       
    89     CMsgMailEditorDocument* self = 
       
    90         new (ELeave) CMsgMailEditorDocument( aApp );
       
    91     CleanupStack::PushL( self );
       
    92     self->ConstructL();
       
    93     CleanupStack::Pop( self );
       
    94 
       
    95     return self;
       
    96     }
       
    97    
       
    98 // ----------------------------------------------------------------------------
       
    99 // CMsgMailEditorDocument::CreateAppUiL()
       
   100 // ----------------------------------------------------------------------------
       
   101 //
       
   102 CEikAppUi* CMsgMailEditorDocument::CreateAppUiL()
       
   103     {
       
   104     return new(ELeave) CMsgMailEditorAppUi;
       
   105     }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // CMsgMailEditorDocument::NotifyChanges()
       
   109 // ----------------------------------------------------------------------------
       
   110 //
       
   111 void CMsgMailEditorDocument::NotifyChanges(TMsgAttachmentCommand aCommand, 
       
   112                                            CMsgAttachmentInfo* aAttachmentInfo)
       
   113     { 
       
   114     TRAP_IGNORE(NotifyChangesL(aCommand, aAttachmentInfo));
       
   115     }
       
   116 
       
   117 // ----------------------------------------------------------------------------
       
   118 // CMsgMailEditorDocument::GetAttachmentFileL()
       
   119 // ----------------------------------------------------------------------------
       
   120 //
       
   121 RFile CMsgMailEditorDocument::GetAttachmentFileL( TMsvAttachmentId aId )
       
   122 	{
       
   123 	return GetAttachmentManagerL().GetAttachmentFileL( aId );
       
   124 	}
       
   125 // ----------------------------------------------------------------------------
       
   126 // CMsgMailEditorDocument::NotifyChangesL()
       
   127 // ----------------------------------------------------------------------------
       
   128 //
       
   129 void CMsgMailEditorDocument::NotifyChangesL(TMsgAttachmentCommand aCommand, 
       
   130                                            CMsgAttachmentInfo* aAttachmentInfo)
       
   131     {
       
   132     // block key events while handling with attachments.
       
   133     CAknInputBlock::NewLC();
       
   134     switch (aCommand)
       
   135         {
       
   136         case EMsgAttachmentAdded:
       
   137             {
       
   138             // don't show confirmation when restoring message
       
   139             if (ShowConfirmation())
       
   140                 {             
       
   141                 SetChanged(ETrue);
       
   142                 }            
       
   143             break;
       
   144             }
       
   145         case EMsgAttachmentRemoved:
       
   146             {  
       
   147             CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
       
   148 			
       
   149 			TMsvAttachmentId attachmentId = aAttachmentInfo->AttachmentId();
       
   150 			MMsvAttachmentManager& manager = MessageL().AttachmentManager();
       
   151 			manager.RemoveAttachmentL(attachmentId, wait->iStatus);
       
   152             
       
   153             wait->Start();
       
   154             CleanupStack::PopAndDestroy( wait );
       
   155             SetChanged(ETrue);
       
   156             break;
       
   157             }
       
   158         default:
       
   159 
       
   160         break;
       
   161         }   
       
   162     CleanupStack::PopAndDestroy();  // CSI: 12 # CAknInputBlock    
       
   163     }
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // CMsgMailEditorDocument::IsNewMessage()
       
   167 // ----------------------------------------------------------------------------
       
   168 //    
       
   169 TBool CMsgMailEditorDocument::IsNewMessage() const
       
   170     {
       
   171     return (!CurrentEntry().Entry().Visible());
       
   172     }
       
   173 
       
   174 // ----------------------------------------------------------------------------
       
   175 // CMsgMailEditorDocument::IsReplyMessage()
       
   176 // ----------------------------------------------------------------------------
       
   177 //
       
   178 TBool CMsgMailEditorDocument::IsReplyMessage() const
       
   179     {
       
   180     return ( (LaunchFlags() & EMsgReplyToMessageSender) ||
       
   181         (LaunchFlags() & EMsgReplyToMessageAll));
       
   182     }
       
   183 
       
   184 // ----------------------------------------------------------------------------
       
   185 // CMsgMailEditorDocument::IsForwardMessage()
       
   186 // ----------------------------------------------------------------------------
       
   187 //
       
   188 TBool CMsgMailEditorDocument::IsForwardMessage() const
       
   189 	{
       
   190 	return ( LaunchFlags() & EMsgForwardMessage );
       
   191 	}
       
   192 
       
   193 void CMsgMailEditorDocument::ReadSendOptionsL()
       
   194     {
       
   195     if (!CurrentEntry().Entry().Visible())
       
   196         {
       
   197         // get default send options from default account
       
   198         SendOptions().DefaultAccountSettingsL(
       
   199             CurrentEntry().Entry().iServiceId,
       
   200             Session());
       
   201         }
       
   202     else
       
   203         {
       
   204         // opening old message
       
   205         SendOptions().ExportSendOptionsL(Entry());
       
   206         }        
       
   207     }
       
   208 
       
   209 // ----------------------------------------------------------------------------
       
   210 // CMsgMailEditorDocument::IsOnlineL()
       
   211 // ----------------------------------------------------------------------------
       
   212 //
       
   213 TBool CMsgMailEditorDocument::IsOnlineL()
       
   214     {
       
   215     CMsvEntrySelection* accounts = MsvUiServiceUtilities::GetListOfAccountsL(
       
   216         Session() );
       
   217     CleanupStack::PushL(accounts);
       
   218 
       
   219     CMsvEntry* rootEntry = Session().GetEntryL(KMsvRootIndexEntryId);
       
   220     CleanupStack::PushL(rootEntry);
       
   221 
       
   222     TBool active = EFalse;
       
   223     for (TInt cc=0; cc<accounts->Count(); cc++)
       
   224         {
       
   225         TMsvEntry tentry;
       
   226         TRAPD( err, tentry=rootEntry->ChildDataL(accounts->At(cc)) );
       
   227 
       
   228         if ( err==KErrNone && tentry.Connected() )
       
   229             {
       
   230             active = ETrue;
       
   231             break;
       
   232             }
       
   233         }
       
   234     CleanupStack::PopAndDestroy( 2, accounts );				// CSI: 47,12 # rootEntry, accounts
       
   235     return active;
       
   236     }
       
   237 
       
   238 // ----------------------------------------------------------------------------
       
   239 // CMsgMailEditorDocument::OpenMailMessageEntryL()
       
   240 // ----------------------------------------------------------------------------
       
   241 //
       
   242 void CMsgMailEditorDocument::OpenMailMessageEntryL( TMsvEntry aEntry )
       
   243     {
       
   244     CMtmStore* store = CMtmStore::NewL( Session() );
       
   245     CleanupStack::PushL(store);
       
   246     CBaseMtmUi& mtmUi=store->GetMtmUiAndSetContextLC( aEntry );
       
   247     CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
       
   248     CMsvOperation* op=mtmUi.EditL( wait->iStatus );
       
   249     wait->Start();
       
   250     CleanupStack::PopAndDestroy( 3, store );				// CSI: 47,12 # store, ContextLC, wait
       
   251     delete op;    
       
   252     }
       
   253 
       
   254 // ----------------------------------------------------------------------------
       
   255 // CMsgMailEditorDocument::SendImmediatelyL()
       
   256 // ----------------------------------------------------------------------------
       
   257 //
       
   258 void CMsgMailEditorDocument::SendImmediatelyL( const TMsvId aMsgId )
       
   259     {
       
   260     CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   261     CleanupStack::PushL(selection);
       
   262     selection->AppendL( aMsgId );
       
   263 
       
   264     CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
       
   265 
       
   266     // Switch MTM context to the service to send to.
       
   267     const TMsvEntry entry( Entry() );
       
   268     Mtm().SwitchCurrentEntryL( entry.iServiceId );
       
   269 
       
   270     CBaseMtmUi& ui= MtmUi();
       
   271     CMsvOperation* op=ui.CopyToL(*selection, wait->iStatus);
       
   272 
       
   273     CleanupStack::PushL( op );
       
   274     wait->Start(); // wait for asynch operation
       
   275 
       
   276     const TDesC8& finalBuf = op->ProgressL();
       
   277 
       
   278     ui.DisplayProgressSummary(finalBuf);
       
   279 
       
   280     CleanupStack::PopAndDestroy(3, selection);				// CSI: 47,12 # op, wait, selection
       
   281     }
       
   282     
       
   283 // ----------------------------------------------------------------------------
       
   284 // CMsgMailEditorDocument::GetHealthyMailboxListL()
       
   285 // ----------------------------------------------------------------------------
       
   286 //  
       
   287 MImumInHealthServices::RMailboxIdArray 
       
   288         CMsgMailEditorDocument::GetHealthyMailboxListL(
       
   289         const TInt64& aFlags )
       
   290     {    
       
   291     // The list of mailboxes must be updated. 
       
   292     User::LeaveIfError( 
       
   293         iEmailApi->HealthServicesL().GetMailboxList( 
       
   294             iMailboxArray, aFlags ) );
       
   295     
       
   296     return iMailboxArray;
       
   297     }
       
   298         
       
   299 // ----------------------------------------------------------------------------
       
   300 // CMsgMailEditorDocument::GetAttachmentManagerL()
       
   301 // ----------------------------------------------------------------------------
       
   302 //
       
   303 MMsvAttachmentManager& CMsgMailEditorDocument::GetAttachmentManagerL()
       
   304     {
       
   305 	// Load Attachment list
       
   306 	MessageL().GetAttachmentsListL(iMessageID, 
       
   307 		CImEmailMessage::EAllAttachments, 
       
   308 		CImEmailMessage::EThisMessageAndEmbeddedMessages);
       
   309 	
       
   310 	return MessageL().AttachmentManager();       
       
   311     }
       
   312     
       
   313 // End of File