diff options
author | Michael Stahl <mstahl@redhat.com> | 2012-11-21 22:21:40 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-11-22 12:10:30 +0100 |
commit | 117fdb9898dcc379b4f83437e858c57fd1d11911 (patch) | |
tree | 809d9346dd75a6317f9f726a27b06807781c86e0 /sfx2 | |
parent | fe3303b3dce8f4cecf15b859c465ced6ff547386 (diff) |
convert users of XDocumentInfo to XDocumentProperties
Change-Id: I10f395f90d554d0ec26fe9f2654ae839e21c7ee5
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/inc/guisaveas.hxx | 5 | ||||
-rw-r--r-- | sfx2/source/appl/appopen.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/doc/doctemplates.cxx | 56 | ||||
-rw-r--r-- | sfx2/source/doc/guisaveas.cxx | 74 | ||||
-rw-r--r-- | sfx2/source/doc/objcont.cxx | 32 | ||||
-rw-r--r-- | sfx2/source/doc/objxtor.cxx | 1 |
6 files changed, 80 insertions, 90 deletions
diff --git a/sfx2/inc/guisaveas.hxx b/sfx2/inc/guisaveas.hxx index 689c237a9b52..514508745d79 100644 --- a/sfx2/inc/guisaveas.hxx +++ b/sfx2/inc/guisaveas.hxx @@ -35,7 +35,7 @@ namespace com { namespace sun { namespace star { namespace document { - class XDocumentInfo; + class XDocumentProperties; } } } } @@ -75,7 +75,8 @@ public: static void SetDocInfoState( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel, - const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentInfo>& i_xOldDocInfo, + const ::com::sun::star::uno::Reference< + ::com::sun::star::document::XDocumentProperties>& i_xOldDocInfo, sal_Bool bNoModify ); static sal_Bool WarnUnacceptableFormat( diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx index 348f1c11f172..6c764b8a2dc8 100644 --- a/sfx2/source/appl/appopen.cxx +++ b/sfx2/source/appl/appopen.cxx @@ -223,7 +223,7 @@ void SetTemplate_Impl( const String &rFileName, const String &rLongName, SfxObjectShell *pDoc) { - // write TemplateName to DocumentInfo of document + // write TemplateName to DocumentProperties of document // TemplateDate stays as default (=current date) pDoc->ResetFromTemplate( rLongName, rFileName ); } diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx index 92b91947e841..a724dea9f236 100644 --- a/sfx2/source/doc/doctemplates.cxx +++ b/sfx2/source/doc/doctemplates.cxx @@ -42,7 +42,7 @@ #include <com/sun/star/configuration/theDefaultProvider.hpp> #include <com/sun/star/container/XContainerQuery.hpp> #include <com/sun/star/document/XTypeDetection.hpp> -#include <com/sun/star/document/XStandaloneDocumentInfo.hpp> +#include <com/sun/star/document/DocumentProperties.hpp> #include <com/sun/star/io/TempFile.hpp> #include <com/sun/star/sdbc/XResultSet.hpp> #include <com/sun/star/sdbc/XRow.hpp> @@ -75,7 +75,6 @@ #define TEMPLATE_IMPLEMENTATION_NAME "com.sun.star.comp.sfx2.DocumentTemplates" #define SERVICENAME_TYPEDETECTION "com.sun.star.document.TypeDetection" -#define SERVICENAME_DOCINFO "com.sun.star.document.StandaloneDocumentInfo" #define TEMPLATE_ROOT_URL "vnd.sun.star.hier:/templates" #define TITLE "Title" @@ -177,7 +176,7 @@ class SfxDocTplService_Impl { uno::Reference< XMultiServiceFactory > mxFactory; uno::Reference< XCommandEnvironment > maCmdEnv; - uno::Reference< XStandaloneDocumentInfo > mxInfo; + uno::Reference<XDocumentProperties> m_xDocProps; uno::Reference< XTypeDetection > mxType; ::osl::Mutex maMutex; @@ -441,16 +440,15 @@ void SfxDocTplService_Impl::init_Impl() if ( bIsInitialized ) { - OUString aService( SERVICENAME_DOCINFO ); try { - mxInfo = uno::Reference< XStandaloneDocumentInfo > ( - mxFactory->createInstance( aService ), UNO_QUERY ); - } catch (uno::RuntimeException &) { - OSL_FAIL("SfxDocTplService_Impl::init_Impl: " - "cannot create DocumentProperties service"); + m_xDocProps.set(document::DocumentProperties::create( + ::comphelper::getProcessComponentContext())); + } catch (uno::RuntimeException const& e) { + SAL_WARN("sfx.doc", "SfxDocTplService_Impl::init_Impl: " + "cannot create DocumentProperties service:" << e.Message); } - aService = OUString( SERVICENAME_TYPEDETECTION ); + OUString const aService = OUString( SERVICENAME_TYPEDETECTION ); mxType = uno::Reference< XTypeDetection > ( mxFactory->createInstance( aService ), UNO_QUERY ); getDirList(); @@ -643,24 +641,20 @@ sal_Bool SfxDocTplService_Impl::needsUpdate() // ----------------------------------------------------------------------- sal_Bool SfxDocTplService_Impl::setTitleForURL( const OUString& rURL, const OUString& aTitle ) { - sal_Bool bResult = sal_False; - if ( mxInfo.is() ) + if (m_xDocProps.is()) { try { - mxInfo->loadFromURL( rURL ); - uno::Reference< XPropertySet > xPropSet( mxInfo, UNO_QUERY_THROW ); - OUString aPropName( TITLE ); - xPropSet->setPropertyValue( aPropName, uno::makeAny( aTitle ) ); - mxInfo->storeIntoURL( rURL ); - bResult = sal_True; + m_xDocProps->loadFromMedium(rURL, Sequence<PropertyValue>()); + m_xDocProps->setTitle(aTitle ); + m_xDocProps->storeToMedium(rURL, Sequence<PropertyValue>()); + return true; } catch ( Exception& ) { } } - - return bResult; + return false; } // ----------------------------------------------------------------------- @@ -668,32 +662,16 @@ sal_Bool SfxDocTplService_Impl::getTitleFromURL( const OUString& rURL, OUString& { bDocHasTitle = sal_False; - if ( mxInfo.is() ) + if (m_xDocProps.is()) { try { - mxInfo->loadFromURL( rURL ); + m_xDocProps->loadFromMedium(rURL, Sequence<PropertyValue>()); + aTitle = m_xDocProps->getTitle(); } catch ( Exception& ) { } - - try - { - uno::Reference< XPropertySet > aPropSet( mxInfo, UNO_QUERY ); - if ( aPropSet.is() ) - { - OUString aPropName( TITLE ); - Any aValue = aPropSet->getPropertyValue( aPropName ); - aValue >>= aTitle; - - aPropName = OUString( "MIMEType" ); - aValue = aPropSet->getPropertyValue( aPropName ); - aValue >>= aType; - } - } - catch ( UnknownPropertyException& ) {} - catch ( Exception& ) {} } if ( aType.isEmpty() && mxType.is() ) diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx index f90432f12006..c6af31615da8 100644 --- a/sfx2/source/doc/guisaveas.cxx +++ b/sfx2/source/doc/guisaveas.cxx @@ -29,8 +29,8 @@ #include <com/sun/star/beans/XPropertyContainer.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/document/XExporter.hpp> -#include <com/sun/star/document/XDocumentInfoSupplier.hpp> -#include <com/sun/star/document/XDocumentInfo.hpp> +#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> +#include <com/sun/star/document/XDocumentProperties.hpp> #include <com/sun/star/task/InteractionHandler.hpp> #include <com/sun/star/util/DateTime.hpp> #include <com/sun/star/util/URLTransformer.hpp> @@ -1579,11 +1579,11 @@ sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& // so the document info can be updated // on export document info must be preserved - uno::Reference<document::XDocumentInfoSupplier> xDIS( + uno::Reference<document::XDocumentPropertiesSupplier> xDPS( aModelData.GetModel(), uno::UNO_QUERY_THROW); uno::Reference<util::XCloneable> xCloneable( - xDIS->getDocumentInfo(), uno::UNO_QUERY_THROW); - uno::Reference<document::XDocumentInfo> xOldDocInfo( + xDPS->getDocumentProperties(), uno::UNO_QUERY_THROW); + uno::Reference<document::XDocumentProperties> xOldDocProps( xCloneable->createClone(), uno::UNO_QUERY_THROW); // use dispatch API to show document info dialog @@ -1605,13 +1605,16 @@ sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& catch( const uno::Exception& ) { if ( ( nStoreMode & EXPORT_REQUESTED ) ) - SetDocInfoState( aModelData.GetModel(), xOldDocInfo, sal_True ); - + { + SetDocInfoState(aModelData.GetModel(), xOldDocProps, sal_True); + } throw; } if ( ( nStoreMode & EXPORT_REQUESTED ) ) - SetDocInfoState( aModelData.GetModel(), xOldDocInfo, sal_True ); + { + SetDocInfoState(aModelData.GetModel(), xOldDocProps, sal_True); + } } else { @@ -1665,16 +1668,15 @@ sal_Bool SfxStoringHelper::CheckFilterOptionsAppearence( // static void SfxStoringHelper::SetDocInfoState( const uno::Reference< frame::XModel >& xModel, - const uno::Reference< document::XDocumentInfo >& i_xOldDocInfo, + const uno::Reference< document::XDocumentProperties>& i_xOldDocProps, sal_Bool bNoModify ) { - uno::Reference< document::XDocumentInfoSupplier > xModelDocInfoSupplier( xModel, uno::UNO_QUERY ); - if ( !xModelDocInfoSupplier.is() ) - throw uno::RuntimeException(); // TODO: - - uno::Reference< document::XDocumentInfo > xDocInfoToFill = xModelDocInfoSupplier->getDocumentInfo(); - uno::Reference< beans::XPropertySet > xPropSet( i_xOldDocInfo, - uno::UNO_QUERY_THROW ); + uno::Reference<document::XDocumentPropertiesSupplier> const + xModelDocPropsSupplier(xModel, uno::UNO_QUERY_THROW); + uno::Reference<document::XDocumentProperties> const xDocPropsToFill = + xModelDocPropsSupplier->getDocumentProperties(); + uno::Reference< beans::XPropertySet > const xPropSet( + i_xOldDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); uno::Reference< util::XModifiable > xModifiable( xModel, uno::UNO_QUERY ); if ( bNoModify && !xModifiable.is() ) @@ -1684,7 +1686,8 @@ void SfxStoringHelper::SetDocInfoState( try { - uno::Reference< beans::XPropertySet > xSet( xDocInfoToFill, uno::UNO_QUERY ); + uno::Reference< beans::XPropertySet > const xSet( + xDocPropsToFill->getUserDefinedProperties(), uno::UNO_QUERY); uno::Reference< beans::XPropertyContainer > xContainer( xSet, uno::UNO_QUERY ); uno::Reference< beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo(); uno::Sequence< beans::Property > lProps = xSetInfo->getProperties(); @@ -1695,8 +1698,12 @@ void SfxStoringHelper::SetDocInfoState( { uno::Any aValue = xPropSet->getPropertyValue( pProps[i].Name ); if ( pProps[i].Attributes & ::com::sun::star::beans::PropertyAttribute::REMOVABLE ) + try + { // QUESTION: DefaultValue?! xContainer->addProperty( pProps[i].Name, pProps[i].Attributes, aValue ); + } + catch (beans::PropertyExistException const&) {} try { // it is possible that the propertysets from XML and binary files differ; we shouldn't break then @@ -1705,17 +1712,30 @@ void SfxStoringHelper::SetDocInfoState( catch ( const uno::Exception& ) {} } - sal_Int16 nCount = i_xOldDocInfo->getUserFieldCount(); - sal_Int16 nSupportedCount = xDocInfoToFill->getUserFieldCount(); - for ( sal_Int16 nInd = 0; nInd < nCount && nInd < nSupportedCount; nInd++ ) - { - ::rtl::OUString aPropName = i_xOldDocInfo->getUserFieldName( nInd ); - xDocInfoToFill->setUserFieldName( nInd, aPropName ); - ::rtl::OUString aPropVal = i_xOldDocInfo->getUserFieldValue( nInd ); - xDocInfoToFill->setUserFieldValue( nInd, aPropVal ); - } + // sigh... have to set these manually i'm afraid... wonder why + // SfxObjectShell doesn't handle this internally, should be easier + xDocPropsToFill->setAuthor(i_xOldDocProps->getAuthor()); + xDocPropsToFill->setGenerator(i_xOldDocProps->getGenerator()); + xDocPropsToFill->setCreationDate(i_xOldDocProps->getCreationDate()); + xDocPropsToFill->setTitle(i_xOldDocProps->getTitle()); + xDocPropsToFill->setSubject(i_xOldDocProps->getSubject()); + xDocPropsToFill->setDescription(i_xOldDocProps->getDescription()); + xDocPropsToFill->setKeywords(i_xOldDocProps->getKeywords()); + xDocPropsToFill->setModifiedBy(i_xOldDocProps->getModifiedBy()); + xDocPropsToFill->setModificationDate(i_xOldDocProps->getModificationDate()); + xDocPropsToFill->setPrintedBy(i_xOldDocProps->getPrintedBy()); + xDocPropsToFill->setPrintDate(i_xOldDocProps->getPrintDate()); + xDocPropsToFill->setAutoloadURL(i_xOldDocProps->getAutoloadURL()); + xDocPropsToFill->setAutoloadSecs(i_xOldDocProps->getAutoloadSecs()); + xDocPropsToFill->setDefaultTarget(i_xOldDocProps->getDefaultTarget()); + xDocPropsToFill->setEditingCycles(i_xOldDocProps->getEditingCycles()); + xDocPropsToFill->setEditingDuration(i_xOldDocProps->getEditingDuration()); + // other attributes e.g. DocumentStatistics are not editable from dialog + } + catch (const uno::Exception& e) + { + SAL_INFO("sfx.doc", "SetDocInfoState: caught exception: " << e.Message); } - catch ( const uno::Exception& ) {} // set the modified flag back if required if ( bNoModify && bIsModified != xModifiable->isModified() ) diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx index c96162e454d1..8511f63354e9 100644 --- a/sfx2/source/doc/objcont.cxx +++ b/sfx2/source/doc/objcont.cxx @@ -20,12 +20,11 @@ #include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/document/DocumentProperties.hpp> #include <com/sun/star/document/XDocumentProperties.hpp> #include <com/sun/star/document/UpdateDocMode.hpp> #include <com/sun/star/frame/XLayoutManager.hpp> #include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/document/XStandaloneDocumentInfo.hpp> -#include <com/sun/star/beans/XFastPropertySet.hpp> #include <vcl/msgbox.hxx> #include <svl/style.hxx> #include <vcl/wrkwin.hxx> @@ -893,29 +892,22 @@ void SfxObjectShell::UpdateFromTemplate_Impl( ) // should the document checked against changes in the template ? if ( IsQueryLoadTemplate() ) { - // load document info of template - sal_Bool bOK = sal_False; + // load document properties of template + bool bOK = false; util::DateTime aTemplDate; try { - Reference < document::XStandaloneDocumentInfo > xDocInfo ( - ::comphelper::getProcessServiceFactory()->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.document.StandaloneDocumentInfo") ) ), - UNO_QUERY_THROW ); - Reference < beans::XFastPropertySet > xSet( xDocInfo, - UNO_QUERY_THROW ); - xDocInfo->loadFromURL( aTemplURL ); - Any aAny = xSet->getFastPropertyValue( WID_DATE_MODIFIED ); - ::com::sun::star::util::DateTime aTmp; - if ( aAny >>= aTemplDate ) - { - // get modify date from document info - bOK = sal_True; - } + Reference<document::XDocumentProperties> const + xTemplateDocProps( document::DocumentProperties::create( + ::comphelper::getProcessComponentContext())); + xTemplateDocProps->loadFromMedium(aTemplURL, + Sequence<beans::PropertyValue>()); + aTemplDate = xTemplateDocProps->getModificationDate(); + bOK = true; } - catch (const Exception&) + catch (const Exception& e) { + SAL_INFO("sfx.doc", "caught exception" << e.Message); } // if modify date was read successfully diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index deee41ba3368..08b2743acc7f 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -110,7 +110,6 @@ using ::basic::BasicManagerRepository; DBG_NAME(SfxObjectShell) -#define DocumentInfo #include "sfxslots.hxx" namespace { |