1*d119d52dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*d119d52dSAndrew Rist * distributed with this work for additional information 6*d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*d119d52dSAndrew Rist * "License"); you may not use this file except in compliance 9*d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*d119d52dSAndrew Rist * software distributed under the License is distributed on an 15*d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*d119d52dSAndrew Rist * KIND, either express or implied. See the License for the 17*d119d52dSAndrew Rist * specific language governing permissions and limitations 18*d119d52dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*d119d52dSAndrew Rist *************************************************************/ 21*d119d52dSAndrew Rist 22*d119d52dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 26cdf0e10cSrcweir // includes -------------------------------------------------------------- 27cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 28cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyAccess.hpp> 29cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 30cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 31cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 32cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp> 33cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h> 34cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 35cdf0e10cSrcweir #include <com/sun/star/system/XSimpleMailClientSupplier.hpp> 36cdf0e10cSrcweir #include <com/sun/star/system/SimpleMailClientFlags.hpp> 37cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp> 38cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 39cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp> 40cdf0e10cSrcweir #include <com/sun/star/container/XContainerQuery.hpp> 41cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 42cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp> 43cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp> 44cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 45cdf0e10cSrcweir #include <com/sun/star/security/CertificateValidity.hpp> 46cdf0e10cSrcweir #include <com/sun/star/security/DocumentSignatureInformation.hpp> 47cdf0e10cSrcweir #include <com/sun/star/security/XDocumentDigitalSignatures.hpp> 48cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 49cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp> 50cdf0e10cSrcweir #include <com/sun/star/frame/XStatusListener.hpp> 51cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp> 52cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 53cdf0e10cSrcweir #include <com/sun/star/document/XExporter.hpp> 54cdf0e10cSrcweir #include <rtl/textenc.h> 55cdf0e10cSrcweir #include <rtl/uri.h> 56cdf0e10cSrcweir #include <rtl/uri.hxx> 57cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 58cdf0e10cSrcweir #include <vcl/msgbox.hxx> 59cdf0e10cSrcweir 60cdf0e10cSrcweir #include <sfx2/mailmodelapi.hxx> 61cdf0e10cSrcweir #include "sfxtypes.hxx" 62cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 63cdf0e10cSrcweir #include <sfx2/sfxsids.hrc> 64cdf0e10cSrcweir #include "dialog.hrc" 65cdf0e10cSrcweir 66cdf0e10cSrcweir #include <unotools/tempfile.hxx> 67cdf0e10cSrcweir #include <unotools/configitem.hxx> 68cdf0e10cSrcweir #include <ucbhelper/content.hxx> 69cdf0e10cSrcweir #include <tools/urlobj.hxx> 70cdf0e10cSrcweir #include <unotools/useroptions.hxx> 71cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 72cdf0e10cSrcweir #include <comphelper/extract.hxx> 73cdf0e10cSrcweir #include <comphelper/storagehelper.hxx> 74cdf0e10cSrcweir #include <comphelper/sequenceasvector.hxx> 75cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx> 76cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx> 77cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 78cdf0e10cSrcweir #include <vcl/svapp.hxx> 79cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 80cdf0e10cSrcweir 81cdf0e10cSrcweir // -------------------------------------------------------------- 82cdf0e10cSrcweir using namespace ::com::sun::star; 83cdf0e10cSrcweir using namespace ::com::sun::star::beans; 84cdf0e10cSrcweir using namespace ::com::sun::star::frame; 85cdf0e10cSrcweir using namespace ::com::sun::star::io; 86cdf0e10cSrcweir using namespace ::com::sun::star::lang; 87cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 88cdf0e10cSrcweir using namespace ::com::sun::star::uno; 89cdf0e10cSrcweir using namespace ::com::sun::star::util; 90cdf0e10cSrcweir using namespace ::com::sun::star::system; 91cdf0e10cSrcweir using namespace ::rtl; 92cdf0e10cSrcweir 93cdf0e10cSrcweir namespace css = ::com::sun::star; 94cdf0e10cSrcweir // - class PrepareListener_Impl ------------------------------------------ 95cdf0e10cSrcweir class PrepareListener_Impl : public ::cppu::WeakImplHelper1< css::frame::XStatusListener > 96cdf0e10cSrcweir { 97cdf0e10cSrcweir bool m_bState; 98cdf0e10cSrcweir public: 99cdf0e10cSrcweir PrepareListener_Impl(); 100cdf0e10cSrcweir virtual ~PrepareListener_Impl(); 101cdf0e10cSrcweir 102cdf0e10cSrcweir // css.frame.XStatusListener 103cdf0e10cSrcweir virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& aEvent) 104cdf0e10cSrcweir throw(css::uno::RuntimeException); 105cdf0e10cSrcweir 106cdf0e10cSrcweir // css.lang.XEventListener 107cdf0e10cSrcweir virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) 108cdf0e10cSrcweir throw(css::uno::RuntimeException); 109cdf0e10cSrcweir 110cdf0e10cSrcweir bool IsSet() const {return m_bState;} 111cdf0e10cSrcweir }; 112cdf0e10cSrcweir 113cdf0e10cSrcweir /*-- 25.08.2010 14:32:49--------------------------------------------------- 114cdf0e10cSrcweir 115cdf0e10cSrcweir -----------------------------------------------------------------------*/ 116cdf0e10cSrcweir PrepareListener_Impl::PrepareListener_Impl() : 117cdf0e10cSrcweir m_bState( false ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir } 120cdf0e10cSrcweir /*-- 25.08.2010 14:32:51--------------------------------------------------- 121cdf0e10cSrcweir 122cdf0e10cSrcweir -----------------------------------------------------------------------*/ 123cdf0e10cSrcweir PrepareListener_Impl::~PrepareListener_Impl() 124cdf0e10cSrcweir { 125cdf0e10cSrcweir } 126cdf0e10cSrcweir /*-- 25.08.2010 14:32:51--------------------------------------------------- 127cdf0e10cSrcweir 128cdf0e10cSrcweir -----------------------------------------------------------------------*/ 129cdf0e10cSrcweir void PrepareListener_Impl::statusChanged(const css::frame::FeatureStateEvent& rEvent) throw(css::uno::RuntimeException) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir if( rEvent.IsEnabled ) 132cdf0e10cSrcweir rEvent.State >>= m_bState; 133cdf0e10cSrcweir else 134cdf0e10cSrcweir m_bState = sal_False; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir /*-- 25.08.2010 14:32:52--------------------------------------------------- 137cdf0e10cSrcweir 138cdf0e10cSrcweir -----------------------------------------------------------------------*/ 139cdf0e10cSrcweir void PrepareListener_Impl::disposing(const css::lang::EventObject& /*rEvent*/) throw(css::uno::RuntimeException) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir // class AddressList_Impl ------------------------------------------------ 144cdf0e10cSrcweir 145cdf0e10cSrcweir typedef String* AddressItemPtr_Impl; 146cdf0e10cSrcweir DECLARE_LIST( AddressList_Impl, AddressItemPtr_Impl ) 147cdf0e10cSrcweir 148cdf0e10cSrcweir // class SfxMailModel ----------------------------------------------- 149cdf0e10cSrcweir 150cdf0e10cSrcweir static const char PDF_DOCUMENT_TYPE[] = "pdf_Portable_Document_Format"; 151cdf0e10cSrcweir static const sal_uInt32 PDF_DOCUMENT_TYPE_LEN = 28; 152cdf0e10cSrcweir 153cdf0e10cSrcweir void SfxMailModel::ClearList( AddressList_Impl* pList ) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir if ( pList ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir sal_uIntPtr i, nCount = pList->Count(); 158cdf0e10cSrcweir for ( i = 0; i < nCount; ++i ) 159cdf0e10cSrcweir delete pList->GetObject(i); 160cdf0e10cSrcweir pList->Clear(); 161cdf0e10cSrcweir } 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir void SfxMailModel::MakeValueList( AddressList_Impl* pList, String& rValueList ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir rValueList.Erase(); 167cdf0e10cSrcweir if ( pList ) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir sal_uIntPtr i, nCount = pList->Count(); 170cdf0e10cSrcweir for ( i = 0; i < nCount; ++i ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir if ( rValueList.Len() > 0 ) 173cdf0e10cSrcweir rValueList += ','; 174cdf0e10cSrcweir rValueList += *pList->GetObject(i); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir sal_Bool HasDocumentValidSignature( const css::uno::Reference< css::frame::XModel >& xModel ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir try 182cdf0e10cSrcweir { 183cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xPropSet( xModel, css::uno::UNO_QUERY ); 184cdf0e10cSrcweir if ( xPropSet.is() ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir Any a = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasValidSignatures" ))); 187cdf0e10cSrcweir sal_Bool bReturn = sal_Bool(); 188cdf0e10cSrcweir if ( a >>= bReturn ) 189cdf0e10cSrcweir return bReturn; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir } 192cdf0e10cSrcweir catch ( css::uno::RuntimeException& ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir throw; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir catch ( css::uno::Exception& ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir return sal_False; 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir SfxMailModel::SaveResult SfxMailModel::ShowFilterOptionsDialog( 204cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xSMGR, 205cdf0e10cSrcweir uno::Reference< frame::XModel > xModel, 206cdf0e10cSrcweir const rtl::OUString& rFilterName, 207cdf0e10cSrcweir const rtl::OUString& rType, 208cdf0e10cSrcweir bool bModified, 209cdf0e10cSrcweir sal_Int32& rNumArgs, 210cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs ) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir SaveResult eRet( SAVE_ERROR ); 213cdf0e10cSrcweir 214cdf0e10cSrcweir try 215cdf0e10cSrcweir { 216cdf0e10cSrcweir uno::Sequence < beans::PropertyValue > aProps; 217cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xFilterCFG = 218cdf0e10cSrcweir uno::Reference< container::XNameAccess >( 219cdf0e10cSrcweir xSMGR->createInstance( 220cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ), uno::UNO_QUERY ); 221cdf0e10cSrcweir css::uno::Reference< css::util::XModifiable > xModifiable( xModel, css::uno::UNO_QUERY ); 222cdf0e10cSrcweir 223cdf0e10cSrcweir if ( !xFilterCFG.is() ) 224cdf0e10cSrcweir return eRet; 225cdf0e10cSrcweir 226cdf0e10cSrcweir uno::Any aAny = xFilterCFG->getByName( rFilterName ); 227cdf0e10cSrcweir 228cdf0e10cSrcweir if ( aAny >>= aProps ) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir sal_Int32 nPropertyCount = aProps.getLength(); 231cdf0e10cSrcweir for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir if( aProps[nProperty].Name.equals( ::rtl::OUString::createFromAscii( "UIComponent" )) ) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir ::rtl::OUString aServiceName; 236cdf0e10cSrcweir aProps[nProperty].Value >>= aServiceName; 237cdf0e10cSrcweir if( aServiceName.getLength() ) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir uno::Reference< ui::dialogs::XExecutableDialog > xFilterDialog( 240cdf0e10cSrcweir xSMGR->createInstance( aServiceName ), uno::UNO_QUERY ); 241cdf0e10cSrcweir uno::Reference< beans::XPropertyAccess > xFilterProperties( 242cdf0e10cSrcweir xFilterDialog, uno::UNO_QUERY ); 243cdf0e10cSrcweir 244cdf0e10cSrcweir if( xFilterDialog.is() && xFilterProperties.is() ) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aPropsForDialog(1); 247cdf0e10cSrcweir uno::Reference< document::XExporter > xExporter( xFilterDialog, uno::UNO_QUERY ); 248cdf0e10cSrcweir 249cdf0e10cSrcweir if ( rType.equalsAsciiL( PDF_DOCUMENT_TYPE, PDF_DOCUMENT_TYPE_LEN )) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir //add an internal property, used to tell the dialog we want to set a different 252cdf0e10cSrcweir //string for the ok button 253cdf0e10cSrcweir //used in filter/source/pdf/impdialog.cxx 254cdf0e10cSrcweir String aOkSendText( SfxResId( STR_PDF_EXPORT_SEND )); 255cdf0e10cSrcweir 256cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aFilterDataValue(1); 257cdf0e10cSrcweir aFilterDataValue[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_OkButtonString" )); 258cdf0e10cSrcweir aFilterDataValue[0].Value = css::uno::makeAny( ::rtl::OUString( aOkSendText )); 259cdf0e10cSrcweir 260cdf0e10cSrcweir //add to the filterdata property, the only one the PDF export filter dialog will care for 261cdf0e10cSrcweir aPropsForDialog[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterData" )); 262cdf0e10cSrcweir aPropsForDialog[0].Value = css::uno::makeAny( aFilterDataValue ); 263cdf0e10cSrcweir 264cdf0e10cSrcweir //when executing the dialog will merge the persistent FilterData properties 265cdf0e10cSrcweir xFilterProperties->setPropertyValues( aPropsForDialog ); 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir if( xExporter.is() ) 269cdf0e10cSrcweir xExporter->setSourceDocument( 270cdf0e10cSrcweir uno::Reference< lang::XComponent >( xModel, uno::UNO_QUERY ) ); 271cdf0e10cSrcweir 272cdf0e10cSrcweir if( xFilterDialog->execute() ) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir //get the filter data 275cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aPropsFromDialog = xFilterProperties->getPropertyValues(); 276cdf0e10cSrcweir 277cdf0e10cSrcweir //add them to the args 278cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aPropsFromDialog.getLength(); nInd++ ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir if( aPropsFromDialog[ nInd ].Name.equals( ::rtl::OUString::createFromAscii( "FilterData" ) ) ) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir //found the filterdata, add to the storing argument 283cdf0e10cSrcweir rArgs.realloc( ++rNumArgs ); 284cdf0e10cSrcweir rArgs[rNumArgs-1].Name = aPropsFromDialog[ nInd ].Name; 285cdf0e10cSrcweir rArgs[rNumArgs-1].Value = aPropsFromDialog[ nInd ].Value; 286cdf0e10cSrcweir break; 287cdf0e10cSrcweir } 288cdf0e10cSrcweir } 289cdf0e10cSrcweir eRet = SAVE_SUCCESSFULL; 290cdf0e10cSrcweir } 291cdf0e10cSrcweir else 292cdf0e10cSrcweir { 293cdf0e10cSrcweir // cancel from dialog, then do not send 294cdf0e10cSrcweir // If the model is not modified, it could be modified by the dispatch calls. 295cdf0e10cSrcweir // Therefore set back to modified = false. This should not hurt if we call 296cdf0e10cSrcweir // on a non-modified model. 297cdf0e10cSrcweir if ( !bModified ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir try 300cdf0e10cSrcweir { 301cdf0e10cSrcweir xModifiable->setModified( sal_False ); 302cdf0e10cSrcweir } 303cdf0e10cSrcweir catch( com::sun::star::beans::PropertyVetoException& ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir } 306cdf0e10cSrcweir } 307cdf0e10cSrcweir eRet = SAVE_CANCELLED; 308cdf0e10cSrcweir } 309cdf0e10cSrcweir } 310cdf0e10cSrcweir break; 311cdf0e10cSrcweir } 312cdf0e10cSrcweir } 313cdf0e10cSrcweir } 314cdf0e10cSrcweir } 315cdf0e10cSrcweir } 316cdf0e10cSrcweir catch( css::uno::RuntimeException& ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir throw; 319cdf0e10cSrcweir } 320cdf0e10cSrcweir catch( uno::Exception& ) 321cdf0e10cSrcweir { 322cdf0e10cSrcweir } 323cdf0e10cSrcweir 324cdf0e10cSrcweir return eRet; 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir sal_Int32 SfxMailModel::GetCount() const 328cdf0e10cSrcweir { 329cdf0e10cSrcweir return maAttachedDocuments.size(); 330cdf0e10cSrcweir } 331cdf0e10cSrcweir 332cdf0e10cSrcweir sal_Bool SfxMailModel::IsEmpty() const 333cdf0e10cSrcweir { 334cdf0e10cSrcweir return maAttachedDocuments.empty(); 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir SfxMailModel::SaveResult SfxMailModel::SaveDocumentAsFormat( 338cdf0e10cSrcweir const rtl::OUString& aSaveFileName, 339cdf0e10cSrcweir const css::uno::Reference< css::uno::XInterface >& xFrameOrModel, 340cdf0e10cSrcweir const rtl::OUString& rType, 341cdf0e10cSrcweir rtl::OUString& rFileNamePath ) 342cdf0e10cSrcweir { 343cdf0e10cSrcweir SaveResult eRet( SAVE_ERROR ); 344cdf0e10cSrcweir bool bSendAsPDF = (rType.equalsAsciiL( PDF_DOCUMENT_TYPE, PDF_DOCUMENT_TYPE_LEN )); 345cdf0e10cSrcweir 346cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 347cdf0e10cSrcweir if (!xSMGR.is()) 348cdf0e10cSrcweir return eRet; 349cdf0e10cSrcweir 350cdf0e10cSrcweir const rtl::OUString aModuleManager( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" )); 351cdf0e10cSrcweir css::uno::Reference< css::frame::XModuleManager > xModuleManager( xSMGR->createInstance( aModuleManager ), css::uno::UNO_QUERY_THROW ); 352cdf0e10cSrcweir if ( !xModuleManager.is() ) 353cdf0e10cSrcweir return eRet; 354cdf0e10cSrcweir 355cdf0e10cSrcweir rtl::OUString aModule; 356cdf0e10cSrcweir try 357cdf0e10cSrcweir { 358cdf0e10cSrcweir aModule = xModuleManager->identify( xFrameOrModel ); 359cdf0e10cSrcweir } 360cdf0e10cSrcweir catch ( css::uno::RuntimeException& ) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir throw; 363cdf0e10cSrcweir } 364cdf0e10cSrcweir catch ( css::uno::Exception& ) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir } 367cdf0e10cSrcweir 368cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > xFrame( xFrameOrModel, css::uno::UNO_QUERY ); 369cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xModel( xFrameOrModel, css::uno::UNO_QUERY ); 370cdf0e10cSrcweir if ( xFrame.is() ) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir css::uno::Reference< css::frame::XController > xController = xFrame->getController(); 373cdf0e10cSrcweir if ( xController.is() ) 374cdf0e10cSrcweir xModel = xController->getModel(); 375cdf0e10cSrcweir } 376cdf0e10cSrcweir 377cdf0e10cSrcweir // We need at least a valid module name and model reference 378cdf0e10cSrcweir if (( aModule.getLength() > 0 ) && xModel.is() ) 379cdf0e10cSrcweir { 380cdf0e10cSrcweir bool bModified( false ); 381cdf0e10cSrcweir bool bHasLocation( false ); 382cdf0e10cSrcweir bool bStoreTo( false ); 383cdf0e10cSrcweir 384cdf0e10cSrcweir css::uno::Reference< css::util::XModifiable > xModifiable( xModel, css::uno::UNO_QUERY ); 385cdf0e10cSrcweir css::uno::Reference< css::frame::XStorable > xStorable( xModel, css::uno::UNO_QUERY ); 386cdf0e10cSrcweir 387cdf0e10cSrcweir if ( xModifiable.is() ) 388cdf0e10cSrcweir bModified = xModifiable->isModified(); 389cdf0e10cSrcweir if ( xStorable.is() ) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir rtl::OUString aLocation = xStorable->getLocation(); 392cdf0e10cSrcweir INetURLObject aFileObj( aLocation ); 393cdf0e10cSrcweir 394cdf0e10cSrcweir bool bPrivateProtocol = ( aFileObj.GetProtocol() == INET_PROT_PRIV_SOFFICE ); 395cdf0e10cSrcweir 396cdf0e10cSrcweir bHasLocation = ( aLocation.getLength() > 0 ) && !bPrivateProtocol; 397cdf0e10cSrcweir OSL_ASSERT( !bPrivateProtocol ); 398cdf0e10cSrcweir } 399cdf0e10cSrcweir if ( rType.getLength() > 0 ) 400cdf0e10cSrcweir bStoreTo = true; 401cdf0e10cSrcweir 402cdf0e10cSrcweir if ( xStorable.is() ) 403cdf0e10cSrcweir { 404cdf0e10cSrcweir rtl::OUString aFilterName; 405cdf0e10cSrcweir rtl::OUString aTypeName( rType ); 406cdf0e10cSrcweir rtl::OUString aFileName; 407cdf0e10cSrcweir rtl::OUString aExtension; 408cdf0e10cSrcweir 409cdf0e10cSrcweir css::uno::Reference< css::container::XContainerQuery > xContainerQuery( 410cdf0e10cSrcweir xSMGR->createInstance( rtl::OUString( 411cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ))), 412cdf0e10cSrcweir css::uno::UNO_QUERY ); 413cdf0e10cSrcweir 414cdf0e10cSrcweir if ( bStoreTo ) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir // Retrieve filter from type 417cdf0e10cSrcweir css::uno::Sequence< css::beans::NamedValue > aQuery( bSendAsPDF ? 3 : 2 ); 418cdf0e10cSrcweir aQuery[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" )); 419cdf0e10cSrcweir aQuery[0].Value = css::uno::makeAny( aTypeName ); 420cdf0e10cSrcweir aQuery[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentService" )); 421cdf0e10cSrcweir aQuery[1].Value = css::uno::makeAny( aModule ); 422cdf0e10cSrcweir if( bSendAsPDF ) 423cdf0e10cSrcweir { 424cdf0e10cSrcweir // #i91419# 425cdf0e10cSrcweir // FIXME: we want just an export filter. However currently we need 426cdf0e10cSrcweir // exact flag value as detailed in the filter configuration to get it 427cdf0e10cSrcweir // this seems to be a bug 428cdf0e10cSrcweir // without flags we get an import filter here, which is also unwanted 429cdf0e10cSrcweir aQuery[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Flags" )); 430cdf0e10cSrcweir aQuery[2].Value = css::uno::makeAny( sal_Int32(0x80042) ); // EXPORT ALIEN 3RDPARTY 431cdf0e10cSrcweir } 432cdf0e10cSrcweir 433cdf0e10cSrcweir css::uno::Reference< css::container::XEnumeration > xEnumeration = 434cdf0e10cSrcweir xContainerQuery->createSubSetEnumerationByProperties( aQuery ); 435cdf0e10cSrcweir 436cdf0e10cSrcweir if ( xEnumeration->hasMoreElements() ) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir ::comphelper::SequenceAsHashMap aFilterPropsHM( xEnumeration->nextElement() ); 439cdf0e10cSrcweir aFilterName = aFilterPropsHM.getUnpackedValueOrDefault( 440cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Name" ), 441cdf0e10cSrcweir ::rtl::OUString() ); 442cdf0e10cSrcweir } 443cdf0e10cSrcweir 444cdf0e10cSrcweir if ( bHasLocation ) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir // Retrieve filter from media descriptor 447cdf0e10cSrcweir ::comphelper::SequenceAsHashMap aMediaDescrPropsHM( xModel->getArgs() ); 448cdf0e10cSrcweir rtl::OUString aOrgFilterName = aMediaDescrPropsHM.getUnpackedValueOrDefault( 449cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" )), 450cdf0e10cSrcweir ::rtl::OUString() ); 451cdf0e10cSrcweir if ( aOrgFilterName == aFilterName ) 452cdf0e10cSrcweir { 453cdf0e10cSrcweir // We should save the document in the original format. Therefore this 454cdf0e10cSrcweir // is not a storeTo operation. To support signing in this case, reset 455cdf0e10cSrcweir // bStoreTo flag. 456cdf0e10cSrcweir bStoreTo = false; 457cdf0e10cSrcweir } 458cdf0e10cSrcweir } 459cdf0e10cSrcweir } 460cdf0e10cSrcweir else 461cdf0e10cSrcweir { 462cdf0e10cSrcweir if ( bHasLocation ) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir // Retrieve filter from media descriptor 465cdf0e10cSrcweir ::comphelper::SequenceAsHashMap aMediaDescrPropsHM( xModel->getArgs() ); 466cdf0e10cSrcweir aFilterName = aMediaDescrPropsHM.getUnpackedValueOrDefault( 467cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" )), 468cdf0e10cSrcweir ::rtl::OUString() ); 469cdf0e10cSrcweir } 470cdf0e10cSrcweir 471cdf0e10cSrcweir if ( !bHasLocation || ( aFilterName.getLength() == 0 )) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir // Retrieve the user defined default filter 474cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xNameAccess( xModuleManager, css::uno::UNO_QUERY ); 475cdf0e10cSrcweir try 476cdf0e10cSrcweir { 477cdf0e10cSrcweir ::comphelper::SequenceAsHashMap aFilterPropsHM( xNameAccess->getByName( aModule ) ); 478cdf0e10cSrcweir aFilterName = aFilterPropsHM.getUnpackedValueOrDefault( 479cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "ooSetupFactoryDefaultFilter" ), 480cdf0e10cSrcweir ::rtl::OUString() ); 481cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xNameAccess2( 482cdf0e10cSrcweir xContainerQuery, css::uno::UNO_QUERY ); 483cdf0e10cSrcweir if ( xNameAccess2.is() ) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir ::comphelper::SequenceAsHashMap aFilterPropsHM2( xNameAccess2->getByName( aFilterName ) ); 486cdf0e10cSrcweir aTypeName = aFilterPropsHM2.getUnpackedValueOrDefault( 487cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Type" ), 488cdf0e10cSrcweir ::rtl::OUString() ); 489cdf0e10cSrcweir } 490cdf0e10cSrcweir } 491cdf0e10cSrcweir catch ( css::container::NoSuchElementException& ) 492cdf0e10cSrcweir { 493cdf0e10cSrcweir } 494cdf0e10cSrcweir catch ( css::beans::UnknownPropertyException& ) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir } 497cdf0e10cSrcweir } 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500cdf0e10cSrcweir // No filter found => error 501cdf0e10cSrcweir // No type and no location => error 502cdf0e10cSrcweir if (( aFilterName.getLength() == 0 ) || 503cdf0e10cSrcweir (( aTypeName.getLength() == 0 ) && !bHasLocation )) 504cdf0e10cSrcweir return eRet; 505cdf0e10cSrcweir 506cdf0e10cSrcweir // Determine filen name and extension 507cdf0e10cSrcweir if ( bHasLocation && !bStoreTo ) 508cdf0e10cSrcweir { 509cdf0e10cSrcweir INetURLObject aFileObj( xStorable->getLocation() ); 510cdf0e10cSrcweir aExtension = (rtl::OUString)aFileObj.getExtension(); 511cdf0e10cSrcweir } 512cdf0e10cSrcweir else 513cdf0e10cSrcweir { 514cdf0e10cSrcweir css::uno::Reference< container::XNameAccess > xTypeDetection( 515cdf0e10cSrcweir xSMGR->createInstance( ::rtl::OUString( 516cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.TypeDetection" ))), 517cdf0e10cSrcweir css::uno::UNO_QUERY ); 518cdf0e10cSrcweir 519cdf0e10cSrcweir 520cdf0e10cSrcweir if ( xTypeDetection.is() ) 521cdf0e10cSrcweir { 522cdf0e10cSrcweir try 523cdf0e10cSrcweir { 524cdf0e10cSrcweir ::comphelper::SequenceAsHashMap aTypeNamePropsHM( xTypeDetection->getByName( aTypeName ) ); 525cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aExtensions = aTypeNamePropsHM.getUnpackedValueOrDefault( 526cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Extensions" ), 527cdf0e10cSrcweir ::uno::Sequence< ::rtl::OUString >() ); 528cdf0e10cSrcweir if ( aExtensions.getLength() ) 529cdf0e10cSrcweir aExtension = aExtensions[0]; 530cdf0e10cSrcweir } 531cdf0e10cSrcweir catch ( css::container::NoSuchElementException& ) 532cdf0e10cSrcweir { 533cdf0e10cSrcweir } 534cdf0e10cSrcweir } 535cdf0e10cSrcweir } 536cdf0e10cSrcweir 537cdf0e10cSrcweir // Use provided save file name. If empty determine file name 538cdf0e10cSrcweir aFileName = aSaveFileName; 539cdf0e10cSrcweir if ( aFileName.getLength() == 0 ) 540cdf0e10cSrcweir { 541cdf0e10cSrcweir if ( !bHasLocation ) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir // Create a noname file name with the correct extension 544cdf0e10cSrcweir const rtl::OUString aNoNameFileName( RTL_CONSTASCII_USTRINGPARAM( "noname" )); 545cdf0e10cSrcweir aFileName = aNoNameFileName; 546cdf0e10cSrcweir } 547cdf0e10cSrcweir else 548cdf0e10cSrcweir { 549cdf0e10cSrcweir // Determine file name from model 550cdf0e10cSrcweir INetURLObject aFileObj( xStorable->getLocation() ); 551cdf0e10cSrcweir aFileName = aFileObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::NO_DECODE ); 552cdf0e10cSrcweir } 553cdf0e10cSrcweir } 554cdf0e10cSrcweir 555cdf0e10cSrcweir // No file name => error 556cdf0e10cSrcweir if ( aFileName.getLength() == 0 ) 557cdf0e10cSrcweir return eRet; 558cdf0e10cSrcweir 559cdf0e10cSrcweir OSL_ASSERT( aFilterName.getLength() > 0 ); 560cdf0e10cSrcweir OSL_ASSERT( aFileName.getLength() > 0 ); 561cdf0e10cSrcweir 562cdf0e10cSrcweir // Creates a temporary directory to store a predefined file into it. 563cdf0e10cSrcweir // This makes it possible to store the file for "send document as e-mail" 564cdf0e10cSrcweir // with the original file name. We cannot use the original file as 565cdf0e10cSrcweir // some mail programs need exclusive access. 566cdf0e10cSrcweir ::utl::TempFile aTempDir( NULL, sal_True ); 567cdf0e10cSrcweir 568cdf0e10cSrcweir INetURLObject aFilePathObj( aTempDir.GetURL() ); 569cdf0e10cSrcweir aFilePathObj.insertName( aFileName ); 570cdf0e10cSrcweir aFilePathObj.setExtension( aExtension ); 571cdf0e10cSrcweir 572cdf0e10cSrcweir rtl::OUString aFileURL = aFilePathObj.GetMainURL( INetURLObject::NO_DECODE ); 573cdf0e10cSrcweir 574cdf0e10cSrcweir sal_Int32 nNumArgs(0); 575cdf0e10cSrcweir const rtl::OUString aPasswordPropName( RTL_CONSTASCII_USTRINGPARAM( "Password" )); 576cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > aArgs( ++nNumArgs ); 577cdf0e10cSrcweir aArgs[nNumArgs-1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" )); 578cdf0e10cSrcweir aArgs[nNumArgs-1].Value = css::uno::makeAny( aFilterName ); 579cdf0e10cSrcweir 580cdf0e10cSrcweir ::comphelper::SequenceAsHashMap aMediaDescrPropsHM( xModel->getArgs() ); 581cdf0e10cSrcweir rtl::OUString aPassword = aMediaDescrPropsHM.getUnpackedValueOrDefault( 582cdf0e10cSrcweir aPasswordPropName, 583cdf0e10cSrcweir ::rtl::OUString() ); 584cdf0e10cSrcweir if ( aPassword.getLength() > 0 ) 585cdf0e10cSrcweir { 586cdf0e10cSrcweir aArgs.realloc( ++nNumArgs ); 587cdf0e10cSrcweir aArgs[nNumArgs-1].Name = aPasswordPropName; 588cdf0e10cSrcweir aArgs[nNumArgs-1].Value = css::uno::makeAny( aPassword ); 589cdf0e10cSrcweir } 590cdf0e10cSrcweir 591cdf0e10cSrcweir bool bNeedsPreparation = false; 592cdf0e10cSrcweir css::util::URL aPrepareURL; 593cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > xPrepareDispatch; 594cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider( xFrame, css::uno::UNO_QUERY ); 595cdf0e10cSrcweir css::uno::Reference< css::util::XURLTransformer > xURLTransformer( 596cdf0e10cSrcweir xSMGR->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))), 597cdf0e10cSrcweir css::uno::UNO_QUERY ); 598cdf0e10cSrcweir if( !bSendAsPDF ) 599cdf0e10cSrcweir { 600cdf0e10cSrcweir try 601cdf0e10cSrcweir { 602cdf0e10cSrcweir // check if the document needs to be prepared for sending as mail (embedding of links, removal of invisible content) 603cdf0e10cSrcweir 604cdf0e10cSrcweir if ( xURLTransformer.is() ) 605cdf0e10cSrcweir { 606cdf0e10cSrcweir aPrepareURL.Complete = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PrepareMailExport" )); 607cdf0e10cSrcweir xURLTransformer->parseStrict( aPrepareURL ); 608cdf0e10cSrcweir } 609cdf0e10cSrcweir 610cdf0e10cSrcweir if ( xDispatchProvider.is() ) 611cdf0e10cSrcweir { 612cdf0e10cSrcweir xPrepareDispatch = css::uno::Reference< css::frame::XDispatch >( 613cdf0e10cSrcweir xDispatchProvider->queryDispatch( aPrepareURL, ::rtl::OUString(), 0 )); 614cdf0e10cSrcweir if ( xPrepareDispatch.is() ) 615cdf0e10cSrcweir { 616cdf0e10cSrcweir PrepareListener_Impl* pPrepareListener; 617cdf0e10cSrcweir uno::Reference< css::frame::XStatusListener > xStatusListener = pPrepareListener = new PrepareListener_Impl; 618cdf0e10cSrcweir xPrepareDispatch->addStatusListener( xStatusListener, aPrepareURL ); 619cdf0e10cSrcweir bNeedsPreparation = pPrepareListener->IsSet(); 620cdf0e10cSrcweir xPrepareDispatch->removeStatusListener( xStatusListener, aPrepareURL ); 621cdf0e10cSrcweir } 622cdf0e10cSrcweir } 623cdf0e10cSrcweir } 624cdf0e10cSrcweir catch ( css::uno::RuntimeException& ) 625cdf0e10cSrcweir { 626cdf0e10cSrcweir throw; 627cdf0e10cSrcweir } 628cdf0e10cSrcweir catch ( css::uno::Exception& ) 629cdf0e10cSrcweir { 630cdf0e10cSrcweir } 631cdf0e10cSrcweir } 632cdf0e10cSrcweir 633cdf0e10cSrcweir if ( bModified || !bHasLocation || bStoreTo || bNeedsPreparation ) 634cdf0e10cSrcweir { 635cdf0e10cSrcweir // Document is modified, is newly created or should be stored in a special format 636cdf0e10cSrcweir try 637cdf0e10cSrcweir { 638cdf0e10cSrcweir if( bNeedsPreparation && xPrepareDispatch.is() ) 639cdf0e10cSrcweir { 640cdf0e10cSrcweir if ( xPrepareDispatch.is() ) 641cdf0e10cSrcweir { 642cdf0e10cSrcweir try 643cdf0e10cSrcweir { 644cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > aDispatchArgs; 645cdf0e10cSrcweir xPrepareDispatch->dispatch( aPrepareURL, aDispatchArgs ); 646cdf0e10cSrcweir } 647cdf0e10cSrcweir catch ( css::uno::RuntimeException& ) 648cdf0e10cSrcweir { 649cdf0e10cSrcweir throw; 650cdf0e10cSrcweir } 651cdf0e10cSrcweir catch ( css::uno::Exception& ) 652cdf0e10cSrcweir { 653cdf0e10cSrcweir } 654cdf0e10cSrcweir } 655cdf0e10cSrcweir } 656cdf0e10cSrcweir 657cdf0e10cSrcweir //check if this is the pdf otput filter (i#64555) 658cdf0e10cSrcweir if( bSendAsPDF ) 659cdf0e10cSrcweir { 660cdf0e10cSrcweir SaveResult eShowPDFFilterDialog = ShowFilterOptionsDialog( 661cdf0e10cSrcweir xSMGR, xModel, aFilterName, rType, bModified, nNumArgs, aArgs ); 662cdf0e10cSrcweir 663cdf0e10cSrcweir // don't continue on dialog cancel or error 664cdf0e10cSrcweir if ( eShowPDFFilterDialog != SAVE_SUCCESSFULL ) 665cdf0e10cSrcweir return eShowPDFFilterDialog; 666cdf0e10cSrcweir } 667cdf0e10cSrcweir 668cdf0e10cSrcweir xStorable->storeToURL( aFileURL, aArgs ); 669cdf0e10cSrcweir rFileNamePath = aFileURL; 670cdf0e10cSrcweir eRet = SAVE_SUCCESSFULL; 671cdf0e10cSrcweir 672cdf0e10cSrcweir if( !bSendAsPDF ) 673cdf0e10cSrcweir { 674cdf0e10cSrcweir css::util::URL aURL; 675cdf0e10cSrcweir // #i30432# notify that export is finished - the Writer may want to restore removed content 676cdf0e10cSrcweir if ( xURLTransformer.is() ) 677cdf0e10cSrcweir { 678cdf0e10cSrcweir aURL.Complete = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:MailExportFinished" )); 679cdf0e10cSrcweir xURLTransformer->parseStrict( aURL ); 680cdf0e10cSrcweir } 681cdf0e10cSrcweir 682cdf0e10cSrcweir if ( xDispatchProvider.is() ) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > xDispatch = css::uno::Reference< css::frame::XDispatch >( 685cdf0e10cSrcweir xDispatchProvider->queryDispatch( aURL, ::rtl::OUString(), 0 )); 686cdf0e10cSrcweir if ( xDispatch.is() ) 687cdf0e10cSrcweir { 688cdf0e10cSrcweir try 689cdf0e10cSrcweir { 690cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > aDispatchArgs; 691cdf0e10cSrcweir xDispatch->dispatch( aURL, aDispatchArgs ); 692cdf0e10cSrcweir } 693cdf0e10cSrcweir catch ( css::uno::RuntimeException& ) 694cdf0e10cSrcweir { 695cdf0e10cSrcweir throw; 696cdf0e10cSrcweir } 697cdf0e10cSrcweir catch ( css::uno::Exception& ) 698cdf0e10cSrcweir { 699cdf0e10cSrcweir } 700cdf0e10cSrcweir } 701cdf0e10cSrcweir } 702cdf0e10cSrcweir } 703cdf0e10cSrcweir // If the model is not modified, it could be modified by the dispatch calls. 704cdf0e10cSrcweir // Therefore set back to modified = false. This should not hurt if we call 705cdf0e10cSrcweir // on a non-modified model. 706cdf0e10cSrcweir if ( !bModified ) 707cdf0e10cSrcweir { 708cdf0e10cSrcweir try 709cdf0e10cSrcweir { 710cdf0e10cSrcweir xModifiable->setModified( sal_False ); 711cdf0e10cSrcweir } 712cdf0e10cSrcweir catch( com::sun::star::beans::PropertyVetoException& ) 713cdf0e10cSrcweir { 714cdf0e10cSrcweir } 715cdf0e10cSrcweir } 716cdf0e10cSrcweir } 717cdf0e10cSrcweir catch ( com::sun::star::io::IOException& ) 718cdf0e10cSrcweir { 719cdf0e10cSrcweir eRet = SAVE_ERROR; 720cdf0e10cSrcweir } 721cdf0e10cSrcweir } 722cdf0e10cSrcweir else 723cdf0e10cSrcweir { 724cdf0e10cSrcweir // We need 1:1 copy of the document to preserve an added signature. 725cdf0e10cSrcweir aArgs.realloc( ++nNumArgs ); 726cdf0e10cSrcweir aArgs[nNumArgs-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CopyStreamIfPossible" ) ); 727cdf0e10cSrcweir aArgs[nNumArgs-1].Value = css::uno::makeAny( (sal_Bool)sal_True ); 728cdf0e10cSrcweir 729cdf0e10cSrcweir try 730cdf0e10cSrcweir { 731cdf0e10cSrcweir xStorable->storeToURL( aFileURL, aArgs ); 732cdf0e10cSrcweir rFileNamePath = aFileURL; 733cdf0e10cSrcweir eRet = SAVE_SUCCESSFULL; 734cdf0e10cSrcweir } 735cdf0e10cSrcweir catch ( com::sun::star::io::IOException& ) 736cdf0e10cSrcweir { 737cdf0e10cSrcweir eRet = SAVE_ERROR; 738cdf0e10cSrcweir } 739cdf0e10cSrcweir } 740cdf0e10cSrcweir } 741cdf0e10cSrcweir } 742cdf0e10cSrcweir 743cdf0e10cSrcweir return eRet; 744cdf0e10cSrcweir } 745cdf0e10cSrcweir 746cdf0e10cSrcweir SfxMailModel::SfxMailModel() : 747cdf0e10cSrcweir mpToList ( NULL ), 748cdf0e10cSrcweir mpCcList ( NULL ), 749cdf0e10cSrcweir mpBccList ( NULL ), 750cdf0e10cSrcweir mePriority ( PRIO_NORMAL ), 751cdf0e10cSrcweir mbLoadDone ( sal_True ) 752cdf0e10cSrcweir { 753cdf0e10cSrcweir } 754cdf0e10cSrcweir 755cdf0e10cSrcweir SfxMailModel::~SfxMailModel() 756cdf0e10cSrcweir { 757cdf0e10cSrcweir ClearList( mpToList ); 758cdf0e10cSrcweir delete mpToList; 759cdf0e10cSrcweir ClearList( mpCcList ); 760cdf0e10cSrcweir delete mpCcList; 761cdf0e10cSrcweir ClearList( mpBccList ); 762cdf0e10cSrcweir delete mpBccList; 763cdf0e10cSrcweir } 764cdf0e10cSrcweir 765cdf0e10cSrcweir void SfxMailModel::AddAddress( const String& rAddress, AddressRole eRole ) 766cdf0e10cSrcweir { 767cdf0e10cSrcweir // don't add a empty address 768cdf0e10cSrcweir if ( rAddress.Len() > 0 ) 769cdf0e10cSrcweir { 770cdf0e10cSrcweir AddressList_Impl* pList = NULL; 771cdf0e10cSrcweir if ( ROLE_TO == eRole ) 772cdf0e10cSrcweir { 773cdf0e10cSrcweir if ( !mpToList ) 774cdf0e10cSrcweir // create the list 775cdf0e10cSrcweir mpToList = new AddressList_Impl; 776cdf0e10cSrcweir pList = mpToList; 777cdf0e10cSrcweir } 778cdf0e10cSrcweir else if ( ROLE_CC == eRole ) 779cdf0e10cSrcweir { 780cdf0e10cSrcweir if ( !mpCcList ) 781cdf0e10cSrcweir // create the list 782cdf0e10cSrcweir mpCcList = new AddressList_Impl; 783cdf0e10cSrcweir pList = mpCcList; 784cdf0e10cSrcweir } 785cdf0e10cSrcweir else if ( ROLE_BCC == eRole ) 786cdf0e10cSrcweir { 787cdf0e10cSrcweir if ( !mpBccList ) 788cdf0e10cSrcweir // create the list 789cdf0e10cSrcweir mpBccList = new AddressList_Impl; 790cdf0e10cSrcweir pList = mpBccList; 791cdf0e10cSrcweir } 792cdf0e10cSrcweir else 793cdf0e10cSrcweir { 794cdf0e10cSrcweir DBG_ERRORFILE( "invalid address role" ); 795cdf0e10cSrcweir } 796cdf0e10cSrcweir 797cdf0e10cSrcweir if ( pList ) 798cdf0e10cSrcweir { 799cdf0e10cSrcweir // add address to list 800cdf0e10cSrcweir AddressItemPtr_Impl pAddress = new String( rAddress ); 801cdf0e10cSrcweir pList->Insert( pAddress, LIST_APPEND ); 802cdf0e10cSrcweir } 803cdf0e10cSrcweir } 804cdf0e10cSrcweir } 805cdf0e10cSrcweir 806cdf0e10cSrcweir SfxMailModel::SendMailResult SfxMailModel::AttachDocument( 807cdf0e10cSrcweir const ::rtl::OUString& sDocumentType, 808cdf0e10cSrcweir const css::uno::Reference< css::uno::XInterface >& xFrameOrModel, 809cdf0e10cSrcweir const ::rtl::OUString& sAttachmentTitle ) 810cdf0e10cSrcweir { 811cdf0e10cSrcweir rtl::OUString sFileName; 812cdf0e10cSrcweir 813cdf0e10cSrcweir SaveResult eSaveResult = SaveDocumentAsFormat( sAttachmentTitle, xFrameOrModel, sDocumentType, sFileName ); 814cdf0e10cSrcweir if ( eSaveResult == SAVE_SUCCESSFULL && ( sFileName.getLength() > 0 ) ) 815cdf0e10cSrcweir maAttachedDocuments.push_back(sFileName); 816cdf0e10cSrcweir return eSaveResult == SAVE_SUCCESSFULL ? SEND_MAIL_OK : SEND_MAIL_ERROR; 817cdf0e10cSrcweir } 818cdf0e10cSrcweir 819cdf0e10cSrcweir SfxMailModel::SendMailResult SfxMailModel::Send( const css::uno::Reference< css::frame::XFrame >& xFrame ) 820cdf0e10cSrcweir { 821cdf0e10cSrcweir OSL_ENSURE(!maAttachedDocuments.empty(),"No document added!"); 822cdf0e10cSrcweir SendMailResult eResult = SEND_MAIL_ERROR; 823cdf0e10cSrcweir if ( !maAttachedDocuments.empty() ) 824cdf0e10cSrcweir { 825cdf0e10cSrcweir css::uno::Reference < XMultiServiceFactory > xMgr = ::comphelper::getProcessServiceFactory(); 826cdf0e10cSrcweir if ( xMgr.is() ) 827cdf0e10cSrcweir { 828cdf0e10cSrcweir css::uno::Reference< XSimpleMailClientSupplier > xSimpleMailClientSupplier; 829cdf0e10cSrcweir 830cdf0e10cSrcweir // Prefer the SimpleSystemMail service if available 831cdf0e10cSrcweir xSimpleMailClientSupplier = css::uno::Reference< XSimpleMailClientSupplier >( 832cdf0e10cSrcweir xMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SimpleSystemMail" ))), 833cdf0e10cSrcweir UNO_QUERY ); 834cdf0e10cSrcweir 835cdf0e10cSrcweir if ( ! xSimpleMailClientSupplier.is() ) 836cdf0e10cSrcweir { 837cdf0e10cSrcweir xSimpleMailClientSupplier = css::uno::Reference< XSimpleMailClientSupplier >( 838cdf0e10cSrcweir xMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SimpleCommandMail" ))), 839cdf0e10cSrcweir UNO_QUERY ); 840cdf0e10cSrcweir } 841cdf0e10cSrcweir 842cdf0e10cSrcweir if ( xSimpleMailClientSupplier.is() ) 843cdf0e10cSrcweir { 844cdf0e10cSrcweir css::uno::Reference< XSimpleMailClient > xSimpleMailClient = xSimpleMailClientSupplier->querySimpleMailClient(); 845cdf0e10cSrcweir 846cdf0e10cSrcweir if ( !xSimpleMailClient.is() ) 847cdf0e10cSrcweir { 848cdf0e10cSrcweir // no mail client support => message box! 849cdf0e10cSrcweir return SEND_MAIL_ERROR; 850cdf0e10cSrcweir } 851cdf0e10cSrcweir 852cdf0e10cSrcweir // we have a simple mail client 853cdf0e10cSrcweir css::uno::Reference< XSimpleMailMessage > xSimpleMailMessage = xSimpleMailClient->createSimpleMailMessage(); 854cdf0e10cSrcweir if ( xSimpleMailMessage.is() ) 855cdf0e10cSrcweir { 856cdf0e10cSrcweir sal_Int32 nSendFlags = SimpleMailClientFlags::DEFAULTS; 857cdf0e10cSrcweir if ( maFromAddress.Len() == 0 ) 858cdf0e10cSrcweir { 859cdf0e10cSrcweir // from address not set, try figure out users e-mail address 860cdf0e10cSrcweir CreateFromAddress_Impl( maFromAddress ); 861cdf0e10cSrcweir } 862cdf0e10cSrcweir xSimpleMailMessage->setOriginator( maFromAddress ); 863cdf0e10cSrcweir 864cdf0e10cSrcweir sal_Int32 nToCount = mpToList ? mpToList->Count() : 0; 865cdf0e10cSrcweir sal_Int32 nCcCount = mpCcList ? mpCcList->Count() : 0; 866cdf0e10cSrcweir sal_Int32 nCcSeqCount = nCcCount; 867cdf0e10cSrcweir 868cdf0e10cSrcweir // set recipient (only one) for this simple mail server!! 869cdf0e10cSrcweir if ( nToCount > 1 ) 870cdf0e10cSrcweir { 871cdf0e10cSrcweir nCcSeqCount = nToCount - 1 + nCcCount; 872cdf0e10cSrcweir xSimpleMailMessage->setRecipient( *mpToList->GetObject( 0 )); 873cdf0e10cSrcweir nSendFlags = SimpleMailClientFlags::NO_USER_INTERFACE; 874cdf0e10cSrcweir } 875cdf0e10cSrcweir else if ( nToCount == 1 ) 876cdf0e10cSrcweir { 877cdf0e10cSrcweir xSimpleMailMessage->setRecipient( *mpToList->GetObject( 0 )); 878cdf0e10cSrcweir nSendFlags = SimpleMailClientFlags::NO_USER_INTERFACE; 879cdf0e10cSrcweir } 880cdf0e10cSrcweir 881cdf0e10cSrcweir // all other recipient must be handled with CC recipients! 882cdf0e10cSrcweir if ( nCcSeqCount > 0 ) 883cdf0e10cSrcweir { 884cdf0e10cSrcweir sal_Int32 nIndex = 0; 885cdf0e10cSrcweir Sequence< OUString > aCcRecipientSeq; 886cdf0e10cSrcweir 887cdf0e10cSrcweir aCcRecipientSeq.realloc( nCcSeqCount ); 888cdf0e10cSrcweir if ( nCcSeqCount > nCcCount ) 889cdf0e10cSrcweir { 890cdf0e10cSrcweir for ( sal_Int32 i = 1; i < nToCount; ++i ) 891cdf0e10cSrcweir { 892cdf0e10cSrcweir aCcRecipientSeq[nIndex++] = *mpToList->GetObject(i); 893cdf0e10cSrcweir } 894cdf0e10cSrcweir } 895cdf0e10cSrcweir 896cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCcCount; i++ ) 897cdf0e10cSrcweir { 898cdf0e10cSrcweir aCcRecipientSeq[nIndex++] = *mpCcList->GetObject(i); 899cdf0e10cSrcweir } 900cdf0e10cSrcweir xSimpleMailMessage->setCcRecipient( aCcRecipientSeq ); 901cdf0e10cSrcweir } 902cdf0e10cSrcweir 903cdf0e10cSrcweir sal_Int32 nBccCount = mpBccList ? mpBccList->Count() : 0; 904cdf0e10cSrcweir if ( nBccCount > 0 ) 905cdf0e10cSrcweir { 906cdf0e10cSrcweir Sequence< OUString > aBccRecipientSeq( nBccCount ); 907cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nBccCount; ++i ) 908cdf0e10cSrcweir { 909cdf0e10cSrcweir aBccRecipientSeq[i] = *mpBccList->GetObject(i); 910cdf0e10cSrcweir } 911cdf0e10cSrcweir xSimpleMailMessage->setBccRecipient( aBccRecipientSeq ); 912cdf0e10cSrcweir } 913cdf0e10cSrcweir 914cdf0e10cSrcweir Sequence< OUString > aAttachmentSeq(&(maAttachedDocuments[0]),maAttachedDocuments.size()); 915cdf0e10cSrcweir 916cdf0e10cSrcweir xSimpleMailMessage->setSubject( maSubject ); 917cdf0e10cSrcweir xSimpleMailMessage->setAttachement( aAttachmentSeq ); 918cdf0e10cSrcweir 919cdf0e10cSrcweir sal_Bool bSend( sal_False ); 920cdf0e10cSrcweir try 921cdf0e10cSrcweir { 922cdf0e10cSrcweir xSimpleMailClient->sendSimpleMailMessage( xSimpleMailMessage, nSendFlags ); 923cdf0e10cSrcweir bSend = sal_True; 924cdf0e10cSrcweir } 925cdf0e10cSrcweir catch ( IllegalArgumentException& ) 926cdf0e10cSrcweir { 927cdf0e10cSrcweir } 928cdf0e10cSrcweir catch ( Exception& ) 929cdf0e10cSrcweir { 930cdf0e10cSrcweir } 931cdf0e10cSrcweir 932cdf0e10cSrcweir if ( bSend == sal_False ) 933cdf0e10cSrcweir { 934cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xParentWindow = xFrame->getContainerWindow(); 935cdf0e10cSrcweir 936cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 937cdf0e10cSrcweir Window* pParentWindow = VCLUnoHelper::GetWindow( xParentWindow ); 938cdf0e10cSrcweir 939cdf0e10cSrcweir ErrorBox aBox( pParentWindow, SfxResId( RID_ERRBOX_MAIL_CONFIG )); 940cdf0e10cSrcweir aBox.Execute(); 941cdf0e10cSrcweir eResult = SEND_MAIL_CANCELLED; 942cdf0e10cSrcweir } 943cdf0e10cSrcweir else 944cdf0e10cSrcweir eResult = SEND_MAIL_OK; 945cdf0e10cSrcweir } 946cdf0e10cSrcweir } 947cdf0e10cSrcweir } 948cdf0e10cSrcweir } 949cdf0e10cSrcweir else 950cdf0e10cSrcweir eResult = SEND_MAIL_CANCELLED; 951cdf0e10cSrcweir 952cdf0e10cSrcweir return eResult; 953cdf0e10cSrcweir } 954cdf0e10cSrcweir 955cdf0e10cSrcweir SfxMailModel::SendMailResult SfxMailModel::SaveAndSend( const css::uno::Reference< css::frame::XFrame >& xFrame, const rtl::OUString& rTypeName ) 956cdf0e10cSrcweir { 957cdf0e10cSrcweir SaveResult eSaveResult; 958cdf0e10cSrcweir SendMailResult eResult = SEND_MAIL_ERROR; 959cdf0e10cSrcweir rtl::OUString aFileName; 960cdf0e10cSrcweir 961cdf0e10cSrcweir eSaveResult = SaveDocumentAsFormat( rtl::OUString(), xFrame, rTypeName, aFileName ); 962cdf0e10cSrcweir 963cdf0e10cSrcweir if ( eSaveResult == SAVE_SUCCESSFULL ) 964cdf0e10cSrcweir { 965cdf0e10cSrcweir maAttachedDocuments.push_back( aFileName ); 966cdf0e10cSrcweir return Send( xFrame ); 967cdf0e10cSrcweir } 968cdf0e10cSrcweir else if ( eSaveResult == SAVE_CANCELLED ) 969cdf0e10cSrcweir eResult = SEND_MAIL_CANCELLED; 970cdf0e10cSrcweir 971cdf0e10cSrcweir return eResult; 972cdf0e10cSrcweir } 973cdf0e10cSrcweir 974cdf0e10cSrcweir // functions ------------------------------------------------------------- 975cdf0e10cSrcweir 976cdf0e10cSrcweir sal_Bool CreateFromAddress_Impl( String& rFrom ) 977cdf0e10cSrcweir 978cdf0e10cSrcweir /* [Beschreibung] 979cdf0e10cSrcweir 980cdf0e10cSrcweir Diese Funktion versucht mit Hilfe des IniManagers eine From-Adresse 981cdf0e10cSrcweir zu erzeugen. daf"ur werden die Felder 'Vorname', 'Name' und 'EMail' 982cdf0e10cSrcweir aus der Applikations-Ini-Datei ausgelesen. Sollten diese Felder 983cdf0e10cSrcweir nicht gesetzt sein, wird FALSE zur"uckgegeben. 984cdf0e10cSrcweir 985cdf0e10cSrcweir [R"uckgabewert] 986cdf0e10cSrcweir 987cdf0e10cSrcweir sal_True: Adresse konnte erzeugt werden. 988cdf0e10cSrcweir sal_False: Adresse konnte nicht erzeugt werden. 989cdf0e10cSrcweir */ 990cdf0e10cSrcweir 991cdf0e10cSrcweir { 992cdf0e10cSrcweir SvtUserOptions aUserCFG; 993cdf0e10cSrcweir String aName = aUserCFG.GetLastName (); 994cdf0e10cSrcweir String aFirstName = aUserCFG.GetFirstName (); 995cdf0e10cSrcweir if ( aFirstName.Len() || aName.Len() ) 996cdf0e10cSrcweir { 997cdf0e10cSrcweir if ( aFirstName.Len() ) 998cdf0e10cSrcweir { 999cdf0e10cSrcweir rFrom = TRIM( aFirstName ); 1000cdf0e10cSrcweir 1001cdf0e10cSrcweir if ( aName.Len() ) 1002cdf0e10cSrcweir rFrom += ' '; 1003cdf0e10cSrcweir } 1004cdf0e10cSrcweir rFrom += TRIM( aName ); 1005cdf0e10cSrcweir // unerlaubte Zeichen entfernen 1006cdf0e10cSrcweir rFrom.EraseAllChars( '<' ); 1007cdf0e10cSrcweir rFrom.EraseAllChars( '>' ); 1008cdf0e10cSrcweir rFrom.EraseAllChars( '@' ); 1009cdf0e10cSrcweir } 1010cdf0e10cSrcweir String aEmailName = aUserCFG.GetEmail(); 1011cdf0e10cSrcweir 1012cdf0e10cSrcweir // unerlaubte Zeichen entfernen 1013cdf0e10cSrcweir aEmailName.EraseAllChars( '<' ); 1014cdf0e10cSrcweir aEmailName.EraseAllChars( '>' ); 1015cdf0e10cSrcweir 1016cdf0e10cSrcweir if ( aEmailName.Len() ) 1017cdf0e10cSrcweir { 1018cdf0e10cSrcweir if ( rFrom.Len() ) 1019cdf0e10cSrcweir rFrom += ' '; 1020cdf0e10cSrcweir ( ( rFrom += '<' ) += TRIM( aEmailName ) ) += '>'; 1021cdf0e10cSrcweir } 1022cdf0e10cSrcweir else 1023cdf0e10cSrcweir rFrom.Erase(); 1024cdf0e10cSrcweir return ( rFrom.Len() > 0 ); 1025cdf0e10cSrcweir } 1026