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