meetingrequest/mrguicommon/src/cesmrsendui.cpp
branchRCL_3
changeset 12 4ce476e64c59
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  ESMR send ui wrapper
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmrsendui.h"
       
    20 #include "esmrvcalexport.h"
       
    21 
       
    22 #include <caleninterimutils2.h>
       
    23 #include <eikenv.h>
       
    24 #include <msgbiouids.h>
       
    25 #include <sendui.h>
       
    26 #include <tsendingcapabilities.h>
       
    27 #include <cmessagedata.h>
       
    28 #include <cmessageaddress.h>
       
    29 #include <senduiconsts.h>
       
    30 #include <sysutil.h>
       
    31 #include <txtrich.h>
       
    32 #include <calsession.h>
       
    33 //<cmail> hardcoded paths removal
       
    34 #include <pathinfo.h>
       
    35 //</cmail>
       
    36 
       
    37 // Unnamed namespace for local definitions
       
    38 namespace {
       
    39 //<cmail> hardcoded paths removal from cmail
       
    40 _LIT( KVCalAttachmentFile, 
       
    41 	  "\\private\\10005901\\Calendar.vcs" );
       
    42 //</cmail>
       
    43 
       
    44 _LIT( KCalendarDatabaseFilePath, "c:Calendar" );
       
    45 
       
    46 const TInt KNumMtmsToDim =6;
       
    47 
       
    48 }//namespace
       
    49 
       
    50 // ======== MEMBER FUNCTIONS ========
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CESMRSendUI::NewL()
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CESMRSendUI* CESMRSendUI::NewL(TInt aMenuCommandId)
       
    57     {
       
    58     FUNC_LOG;
       
    59     CESMRSendUI* self = new (ELeave) CESMRSendUI();
       
    60     CleanupStack::PushL(self);
       
    61     self->ConstructL(aMenuCommandId);
       
    62     CleanupStack::Pop(self);
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CESMRSendUI::CESMRSendUI()
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CESMRSendUI::CESMRSendUI()
       
    71     {
       
    72     FUNC_LOG;
       
    73     // Do nothing
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CESMRSendUI::ConstructL()
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CESMRSendUI::ConstructL(TInt aMenuCommandId)
       
    81     {
       
    82     FUNC_LOG;
       
    83     iSession = CCalSession::NewL();
       
    84     iSession->OpenL( KCalendarDatabaseFilePath );
       
    85     iSendUi = CSendUi::NewL();
       
    86     iSendAsCmdId=aMenuCommandId;
       
    87     iSendMtmsToDim = new (ELeave) CArrayFixFlat<TUid>(2);
       
    88 
       
    89     iSendMtmsToDim->SetReserveL( KNumMtmsToDim );  
       
    90     // Always disable sending via Audio message
       
    91     iSendMtmsToDim->AppendL( KSenduiMtmAudioMessageUid );
       
    92     iSendMtmsToDim->AppendL( KSenduiMtmPostcardUid );
       
    93     iSendMtmsToDim->AppendL( KMmsDirectUpload );
       
    94     iSendMtmsToDim->AppendL( KMmsIndirectUpload );
       
    95     iSendMtmsToDim->AppendL( KSenduiMtmOnlineAlbumUid );
       
    96     
       
    97     if( ! iSendUi->CanSendBioMessage( KMsgBioUidVCalendar ) )
       
    98         {
       
    99         // This disables sending of vCalendars via SMS
       
   100         iSendMtmsToDim->AppendL(KSenduiMtmSmsUid);
       
   101         }
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CESMRSendUI::~CESMRSendUI()
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 EXPORT_C CESMRSendUI::~CESMRSendUI()
       
   109     {
       
   110     FUNC_LOG;
       
   111     delete iSession;
       
   112     delete iSendUi;
       
   113     delete iSendMtmsToDim;
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CESMRSendUI::CanSendL()
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 EXPORT_C TBool CESMRSendUI::CanSendL(TInt /*aCommandId*/)
       
   121     {
       
   122     FUNC_LOG;
       
   123 
       
   124     if( iSelectedMtmUid != KNullUid )
       
   125         {
       
   126         return ETrue;
       
   127         }
       
   128     else
       
   129         {
       
   130         return EFalse;
       
   131         }
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CESMRSendUI::DisplaySendMenuItemL()
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 EXPORT_C void CESMRSendUI::DisplaySendMenuItemL(CEikMenuPane& aMenuPane,
       
   139                                                TInt aIndex)
       
   140     {
       
   141     FUNC_LOG;
       
   142     iSendUi->AddSendMenuItemL( 
       
   143     		aMenuPane, aIndex, iSendAsCmdId, TSendingCapabilities() );
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CESMRSendUI::DisplaySendCascadeMenuL()
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 EXPORT_C void CESMRSendUI::DisplaySendCascadeMenuL(CEikMenuPane& /*aMenuPane*/)
       
   151     {
       
   152     FUNC_LOG;
       
   153     iSelectedMtmUid = iSendUi->ShowSendQueryL( 
       
   154     		NULL, KCapabilitiesForAllServices, iSendMtmsToDim, KNullDesC );
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CESMRSendUI::SendAsVCalendarL()
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 EXPORT_C void CESMRSendUI::SendAsVCalendarL(
       
   162 		TInt /*aCommand*/, 
       
   163 		CCalEntry& aEntry)
       
   164     {
       
   165     FUNC_LOG;
       
   166 
       
   167     // If the user selected email as their protocol, 
       
   168     // and the entry is a MR, send using MR utils.
       
   169 
       
   170     CEikonEnv* eikonEnv = CEikonEnv::Static();// codescanner::eikonenvstatic
       
   171     CRichText* text = CRichText::NewL(
       
   172         eikonEnv->SystemParaFormatLayerL(),
       
   173         eikonEnv->SystemCharFormatLayerL());
       
   174     CleanupStack::PushL(text);
       
   175 
       
   176     TESMRVCalExport exporter(*iSession, eikonEnv->FsSession());
       
   177     HBufC8* vcal = exporter.ExportVCalLC(aEntry);
       
   178 
       
   179     TUid mtmUid = iSelectedMtmUid;
       
   180     TSendingCapabilities capabilities;
       
   181     iSendUi->ServiceCapabilitiesL( mtmUid, capabilities );
       
   182 
       
   183     if (capabilities.iFlags & TSendingCapabilities::ESupportsAttachments)
       
   184         {
       
   185         RFs fs;
       
   186         User::LeaveIfError( fs.Connect() );
       
   187         CleanupClosePushL( fs );
       
   188         // must share the handle between processes
       
   189         User::LeaveIfError( fs.ShareProtected() );
       
   190         //<cmail> hardcoded paths removal from cmail
       
   191         TFileName fileName(PathInfo::PhoneMemoryRootPath().Left(2));
       
   192         fileName.Append(KVCalAttachmentFile);
       
   193         fs.MkDirAll(fileName);
       
   194         //</cmail>
       
   195         RFile file;
       
   196         User::LeaveIfError(file.Replace(//<cmail>
       
   197 					fs,fileName,EFileWrite | EFileShareAny ));//</cmail>
       
   198         CleanupClosePushL(file);
       
   199         TInt spaceNeeded = vcal->Size();
       
   200         if ( SysUtil::FFSSpaceBelowCriticalLevelL( &fs, spaceNeeded ) )
       
   201             {
       
   202             // don't show any own notes here
       
   203             User::Leave( KErrDiskFull );
       
   204             }
       
   205 
       
   206         User::LeaveIfError(file.Write(*vcal));
       
   207 
       
   208         TParse parse;//<cmail>
       
   209         User::LeaveIfError(parse.SetNoWild(fileName,//</cmail>
       
   210                                            NULL, NULL));
       
   211 
       
   212         TRAPD(err, DoSendAsAttachmentHandleL(file));
       
   213 
       
   214         CleanupStack::PopAndDestroy(&file);
       
   215         fs.Delete(parse.FullName());
       
   216         CleanupStack::PopAndDestroy( &fs );
       
   217         User::LeaveIfError(err);
       
   218         }
       
   219     else
       
   220         {
       
   221         TPtrC8 p8(*vcal);
       
   222         HBufC* bufCnv = HBufC::NewLC(p8.Length());
       
   223         TPtr16 des(bufCnv->Des());
       
   224         des.Copy(p8);
       
   225         text->InsertL(0, des);
       
   226 
       
   227         CMessageData* messageData = CMessageData::NewL();
       
   228         CleanupStack::PushL( messageData );
       
   229         messageData->SetBodyTextL( text );
       
   230         iSendUi->CreateAndSendMessageL( 
       
   231         		iSelectedMtmUid, messageData, KMsgBioUidVCalendar, ETrue );
       
   232         CleanupStack::PopAndDestroy(); // messagedata
       
   233         CleanupStack::PopAndDestroy(bufCnv);
       
   234         }
       
   235     CleanupStack::PopAndDestroy(vcal);
       
   236     CleanupStack::PopAndDestroy(text);
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CESMRSendUI::DoSendAsAttachmentFileL()
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CESMRSendUI::DoSendAsAttachmentFileL(TInt /*aCommand*/, TParse& aFilename)
       
   244     {
       
   245     FUNC_LOG;
       
   246     CMessageData* messageData = CMessageData::NewL();
       
   247     CleanupStack::PushL( messageData );
       
   248     messageData->AppendAttachmentL( aFilename.FullName() );
       
   249     iSendUi->CreateAndSendMessageL( 
       
   250     		iSelectedMtmUid, messageData, KMsgBioUidVCalendar, ETrue );
       
   251     CleanupStack::PopAndDestroy(); // messagedata
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // CESMRSendUI::DoSendAsAttachmentHandleL()
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void CESMRSendUI::DoSendAsAttachmentHandleL(const RFile& aHandle)
       
   259     {
       
   260     FUNC_LOG;
       
   261     CMessageData* messageData = CMessageData::NewL();
       
   262     CleanupStack::PushL( messageData );
       
   263     messageData->AppendAttachmentHandleL(aHandle);
       
   264     iSendUi->CreateAndSendMessageL( 
       
   265     		iSelectedMtmUid, messageData, KMsgBioUidVCalendar, ETrue );
       
   266     CleanupStack::PopAndDestroy( messageData );
       
   267     }
       
   268 
       
   269 
       
   270 // End of File
       
   271