29#include <osl/diagnose.h>
32#include <com/sun/star/uno/Any.hxx>
33#include <com/sun/star/uno/Sequence.hxx>
34#include <com/sun/star/beans/PropertyValue.hpp>
35#include <com/sun/star/container/XNameAccess.hpp>
36#include <com/sun/star/frame/XModel.hpp>
37#include <com/sun/star/lang/XServiceInfo.hpp>
38#include <com/sun/star/document/XTypeDetection.hpp>
39#include <com/sun/star/util/PathSubstitution.hpp>
40#include <com/sun/star/util/XStringSubstitution.hpp>
56#define PATHSEPARATOR "/"
60#define PROPERTYNAME_SHORTNAME "ooSetupFactoryShortName"
61#define PROPERTYNAME_TEMPLATEFILE "ooSetupFactoryTemplateFile"
62#define PROPERTYNAME_WINDOWATTRIBUTES "ooSetupFactoryWindowAttributes"
63#define PROPERTYNAME_EMPTYDOCUMENTURL "ooSetupFactoryEmptyDocumentURL"
64#define PROPERTYNAME_DEFAULTFILTER "ooSetupFactoryDefaultFilter"
65#define PROPERTYNAME_ICON "ooSetupFactoryIcon"
67#define PROPERTYHANDLE_SHORTNAME 0
68#define PROPERTYHANDLE_TEMPLATEFILE 1
69#define PROPERTYHANDLE_WINDOWATTRIBUTES 2
70#define PROPERTYHANDLE_EMPTYDOCUMENTURL 3
71#define PROPERTYHANDLE_DEFAULTFILTER 4
72#define PROPERTYHANDLE_ICON 5
74#define PROPERTYCOUNT 6
88#define FACTORYCOUNT 11
112 sTemplateFile.clear();
113 sDefaultFilter.clear();
115 bChangedTemplateFile =
false;
116 bChangedDefaultFilter =
false;
117 bDefaultFilterReadonly =
false;
123 css::uno::Sequence< css::beans::PropertyValue > getChangedProperties( std::u16string_view sNodeBase )
128 css::uno::Sequence< css::beans::PropertyValue > lProperties ( 4 );
129 auto plProperties = lProperties.getArray();
132 if( bChangedTemplateFile )
134 plProperties[nRealyChanged].Name
137 if ( !sTemplateFile.isEmpty() )
139 plProperties[nRealyChanged].Value
140 <<= getStringSubstitution()
141 ->reSubstituteVariables( sTemplateFile );
145 plProperties[nRealyChanged].Value <<= sTemplateFile;
150 if( bChangedDefaultFilter )
152 plProperties[nRealyChanged].Name
154 plProperties[nRealyChanged].Value <<= sDefaultFilter;
159 bChangedTemplateFile =
false;
160 bChangedDefaultFilter =
false;
162 lProperties.realloc( nRealyChanged );
169 bool getInstalled ()
const {
return bInstalled; };
170 const OUString& getFactory ()
const {
return sFactory; };
171 const OUString& getTemplateFile ()
const {
return sTemplateFile; };
172 const OUString& getDefaultFilter ()
const {
return sDefaultFilter; };
173 bool isDefaultFilterReadonly()
const {
return bDefaultFilterReadonly; }
174 sal_Int32 getIcon ()
const {
return nIcon; };
178 void initInstalled () { bInstalled =
true; }
179 void initFactory (
const OUString& sNewFactory ) { sFactory = sNewFactory; }
180 void initDefaultFilter (
const OUString& sNewDefaultFilter ) { sDefaultFilter = sNewDefaultFilter; }
181 void setDefaultFilterReadonly(
const bool bVal){bDefaultFilterReadonly = bVal;}
182 void initIcon ( sal_Int32 nNewIcon ) { nIcon = nNewIcon; }
184 void initTemplateFile(
const OUString& sNewTemplateFile )
186 if ( !sNewTemplateFile.isEmpty() )
188 sTemplateFile= getStringSubstitution()->substituteVariables( sNewTemplateFile,
false );
192 sTemplateFile = sNewTemplateFile;
196 void setTemplateFile(
const OUString& sNewTemplateFile )
198 if( sTemplateFile != sNewTemplateFile )
200 sTemplateFile = sNewTemplateFile;
201 bChangedTemplateFile =
true;
205 void setDefaultFilter(
const OUString& sNewDefaultFilter )
207 if( sDefaultFilter != sNewDefaultFilter )
209 sDefaultFilter = sNewDefaultFilter;
210 bChangedDefaultFilter =
true;
215 css::uno::Reference< css::util::XStringSubstitution >
const & getStringSubstitution()
217 if ( !xSubstVars.is() )
219 xSubstVars.set( css::util::PathSubstitution::create(::comphelper::getProcessComponentContext()) );
226 OUString sTemplateFile;
227 OUString sDefaultFilter;
230 bool bChangedTemplateFile :1;
231 bool bChangedDefaultFilter :1;
232 bool bDefaultFilterReadonly :1;
234 css::uno::Reference< css::util::XStringSubstitution > xSubstVars;
253 virtual void Notify(
const css::uno::Sequence< OUString >& lPropertyNames )
override;
268 const OUString& sTemplate );
270 const OUString& sFilter );
276 static css::uno::Sequence< OUString >
impl_ExpandSetNames (
const css::uno::Sequence< OUString >& lSetNames );
277 void impl_Read (
const css::uno::Sequence< OUString >& lSetNames );
299 , m_bReadOnlyStatesWellKnown( false )
307 const css::uno::Sequence< OUString > lFactories =
GetNodeNames( OUString() );
338 OSL_FAIL(
"SvtModuleOptions_Impl::Notify() Not implemented yet!" );
359 sal_Int32 nRealCount = 0;
367 const css::uno::Sequence< css::beans::PropertyValue > lChangedProperties = rInfo.getChangedProperties ( sBasePath );
368 std::copy(lChangedProperties.begin(), lChangedProperties.end(), std::next(lCommitProperties.getArray(), nRealCount));
369 nRealCount += lChangedProperties.getLength();
376 lCommitProperties.realloc( nRealCount );
428 std::vector<OUString> aVec;
431 if( rFactory.getInstalled() )
432 aVec.push_back( rFactory.getFactory() );
475 OSL_FAIL(
"unknown factory" );
518 OSL_FAIL(
"unknown factory" );
531 return m_lFactories[eFactory].isDefaultFilterReadonly();
540 const OUString& sTemplate )
547 const OUString& sFilter )
567 sal_Int32
nCount = lSetNames.getLength();
569 OUString* pPropNames = lPropNames.getArray();
570 sal_Int32 nPropStart = 0;
572 for(
const auto& rSetName : lSetNames )
690 const css::uno::Sequence< css::uno::Any > lValues =
GetProperties( lProperties );
695 OSL_ENSURE( !(lProperties.getLength()!=lValues.getLength()),
"SvtModuleOptions_Impl::impl_Read()\nI miss some values of configuration keys!" );
708 sal_Int32 nPropertyStart = 0;
709 FactoryInfo* pInfo =
nullptr;
712 for(
const OUString& sFactoryName : lFactories )
722 pInfo->initInstalled();
723 pInfo->initFactory ( sFactoryName );
726 pInfo->initTemplateFile( sTemp );
728 pInfo->initDefaultFilter( sTemp );
730 pInfo->initIcon( nTemp );
741 css::uno::Sequence< OUString > lFactories =
GetNodeNames(OUString());
742 for (OUString& rFactory : asNonConstRange(lFactories))
746 sal_Int32 c = lFactories.getLength();
747 for (sal_Int32
i=0;
i<c; ++
i)
749 const OUString& rFactoryName = std::as_const(lFactories)[
i];
756 rInfo.setDefaultFilterReadonly(lReadonlyStates[
i]);
764 std::weak_ptr<SvtModuleOptions_Impl> g_pModuleOptions;
784 m_pImpl = g_pModuleOptions.lock();
789 std::unique_lock aGuard( impl_GetOwnStaticMutex() );
791 m_pImpl = g_pModuleOptions.lock();
794 m_pImpl = std::make_shared<SvtModuleOptions_Impl>();
817 return m_pImpl->IsModuleInstalled( eModule );
823 return m_pImpl->GetFactoryName( eFactory );
828 std::unique_lock aGuard( impl_GetOwnStaticMutex() );
829 return m_pImpl->GetFactoryStandardTemplate( eFactory );
834 std::unique_lock aGuard( impl_GetOwnStaticMutex() );
840 std::unique_lock aGuard( impl_GetOwnStaticMutex() );
841 return m_pImpl->GetFactoryDefaultFilter( eFactory );
846 std::unique_lock aGuard( impl_GetOwnStaticMutex() );
847 m_pImpl->MakeReadonlyStatesAvailable();
848 return m_pImpl->IsDefaultFilterReadonly( eFactory );
853 std::unique_lock aGuard( impl_GetOwnStaticMutex() );
854 return m_pImpl->GetFactoryIcon( eFactory );
865 const OUString& sTemplate )
867 std::unique_lock aGuard( impl_GetOwnStaticMutex() );
868 m_pImpl->SetFactoryStandardTemplate( eFactory, sTemplate );
872 const OUString& sFilter )
874 std::unique_lock aGuard( impl_GetOwnStaticMutex() );
875 m_pImpl->SetFactoryDefaultFilter( eFactory, sFilter );
904 std::unique_lock aGuard( impl_GetOwnStaticMutex() );
935 OSL_FAIL(
"unknown module" );
944 if (
sName ==
u"swriter" )
954 if (
sName ==
u"simpress" )
962 if (
sName ==
u"sdatabase" )
997 const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor)
999 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1001 css::uno::Reference< css::container::XNameAccess > xFilterCfg;
1002 css::uno::Reference< css::container::XNameAccess > xTypeCfg;
1006 xContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.document.FilterFactory", xContext), css::uno::UNO_QUERY);
1008 xContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.document.TypeDetection", xContext), css::uno::UNO_QUERY);
1010 catch(
const css::uno::RuntimeException&)
1012 catch(
const css::uno::Exception&)
1019 if (!sFilterName.isEmpty())
1030 catch(
const css::uno::RuntimeException&)
1032 catch(
const css::uno::Exception&)
1038 if (sTypeName.isEmpty())
1042 css::uno::Reference< css::document::XTypeDetection > xDetect(xTypeCfg, css::uno::UNO_QUERY);
1043 sTypeName = xDetect->queryTypeByURL(sURL);
1046 if (sTypeName.isEmpty())
1062 catch(
const css::uno::RuntimeException&)
1064 catch(
const css::uno::Exception&)
1073 css::uno::Reference< css::lang::XServiceInfo > xInfo(
xModel, css::uno::UNO_QUERY);
1077 const css::uno::Sequence< OUString > lServices = xInfo->getSupportedServiceNames();
1079 for (
const OUString& rService : lServices)
1091 std::unique_lock aGuard( impl_GetOwnStaticMutex() );
1092 return m_pImpl->GetAllServiceNames();
constexpr OUStringLiteral sDocumentService
static void holdConfigItem(EItem eItem)
o3tl::enumarray< SvtModuleOptions::EFactory, FactoryInfo > m_lFactories
virtual void Notify(const css::uno::Sequence< OUString > &lPropertyNames) override
is called from the ConfigManager before application ends of from the PropertyChangeListener if the su...
void SetFactoryDefaultFilter(SvtModuleOptions::EFactory eFactory, const OUString &sFilter)
OUString const & GetFactoryDefaultFilter(SvtModuleOptions::EFactory eFactory) const
static OUString GetFactoryEmptyDocumentURL(SvtModuleOptions::EFactory eFactory)
bool m_bReadOnlyStatesWellKnown
bool IsDefaultFilterReadonly(SvtModuleOptions::EFactory eFactory) const
void impl_Read(const css::uno::Sequence< OUString > &lSetNames)
sal_Int32 GetFactoryIcon(SvtModuleOptions::EFactory eFactory) const
virtual void ImplCommit() override
writes the changed values into the sub tree.
void MakeReadonlyStatesAvailable()
css::uno::Sequence< OUString > GetAllServiceNames()
void SetFactoryStandardTemplate(SvtModuleOptions::EFactory eFactory, const OUString &sTemplate)
OUString const & GetFactoryName(SvtModuleOptions::EFactory eFactory) const
static bool ClassifyFactoryByName(std::u16string_view sName, SvtModuleOptions::EFactory &eFactory)
static css::uno::Sequence< OUString > impl_ExpandSetNames(const css::uno::Sequence< OUString > &lSetNames)
virtual ~SvtModuleOptions_Impl() override
bool IsModuleInstalled(SvtModuleOptions::EModule eModule) const
OUString const & GetFactoryStandardTemplate(SvtModuleOptions::EFactory eFactory) const
bool IsModuleInstalled(EModule eModule) const
OUString GetDefaultModuleName() const
virtual ~SvtModuleOptions() override
OUString GetModuleName(EModule eModule) const
bool IsDefaultFilterReadonly(EFactory eFactory) const
static EFactory ClassifyFactoryByURL(const OUString &sURL, const css::uno::Sequence< css::beans::PropertyValue > &lMediaDescriptor)
return the corresponding application ID for the given properties.
OUString GetFactoryEmptyDocumentURL(EFactory eFactory) const
OUString GetFactoryStandardTemplate(EFactory eFactory) const
const OUString & GetFactoryName(EFactory eFactory) const
css::uno::Sequence< OUString > GetAllServiceNames()
static OUString GetFactoryShortName(EFactory eFactory)
void SetFactoryStandardTemplate(EFactory eFactory, const OUString &sTemplate)
static EFactory ClassifyFactoryByShortName(std::u16string_view sName)
return the corresponding application ID for the given short name.
void SetFactoryDefaultFilter(EFactory eFactory, const OUString &sFilter)
sal_Int32 GetFactoryIcon(EFactory eFactory) const
static EFactory ClassifyFactoryByModel(const css::uno::Reference< css::frame::XModel > &xModel)
return the corresponding application ID for the given properties.
static bool ClassifyFactoryByName(std::u16string_view sName, EFactory &eFactory)
OUString GetFactoryDefaultFilter(EFactory eFactory) const
std::shared_ptr< SvtModuleOptions_Impl > m_pImpl
static EFactory ClassifyFactoryByServiceName(std::u16string_view sName)
return the corresponding application ID for the given document service name.
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
css::uno::Sequence< css::uno::Any > GetProperties(const css::uno::Sequence< OUString > &rNames)
bool SetSetProperties(const OUString &rNode, const css::uno::Sequence< css::beans::PropertyValue > &rValues)
css::uno::Sequence< OUString > GetNodeNames(const OUString &rNode)
bool EnableNotification(const css::uno::Sequence< OUString > &rNames, bool bEnableInternalNotification=false)
enables notifications about changes on selected sub nodes/values
css::uno::Sequence< sal_Bool > GetReadOnlyStates(const css::uno::Sequence< OUString > &rNames)
constexpr OUStringLiteral FACTORYNAME_WRITERWEB
constexpr OUStringLiteral FACTORYNAME_STARTMODULE
#define PROPERTYHANDLE_SHORTNAME
#define PROPERTYNAME_DEFAULTFILTER
#define PROPERTYNAME_SHORTNAME
#define PROPERTYHANDLE_TEMPLATEFILE
constexpr OUStringLiteral FACTORYNAME_CHART
constexpr OUStringLiteral FACTORYNAME_WRITER
constexpr OUStringLiteral FACTORYNAME_IMPRESS
constexpr OUStringLiteral FACTORYNAME_DRAW
constexpr OUStringLiteral ROOTNODE_FACTORIES
constexpr OUStringLiteral FACTORYNAME_WRITERGLOBAL
#define PROPERTYHANDLE_DEFAULTFILTER
#define PROPERTYHANDLE_EMPTYDOCUMENTURL
constexpr OUStringLiteral FACTORYNAME_BASIC
#define PROPERTYHANDLE_WINDOWATTRIBUTES
constexpr OUStringLiteral FACTORYNAME_MATH
constexpr OUStringLiteral FACTORYNAME_CALC
#define PROPERTYNAME_EMPTYDOCUMENTURL
#define PROPERTYNAME_ICON
constexpr OUStringLiteral FACTORYNAME_DATABASE
#define PROPERTYHANDLE_ICON
#define PROPERTYNAME_TEMPLATEFILE
#define PROPERTYNAME_WINDOWATTRIBUTES
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
Reference< XModel > xModel