// Attention: The property "ooSetupFactoryEmptyDocumentURL" is read from configuration but not used! There is // special code that uses hard coded strings to return them. #define PROPERTYNAME_SHORTNAME "ooSetupFactoryShortName" #define PROPERTYNAME_TEMPLATEFILE "ooSetupFactoryTemplateFile" #define PROPERTYNAME_WINDOWATTRIBUTES "ooSetupFactoryWindowAttributes" #define PROPERTYNAME_EMPTYDOCUMENTURL "ooSetupFactoryEmptyDocumentURL" #define PROPERTYNAME_DEFAULTFILTER "ooSetupFactoryDefaultFilter" #define PROPERTYNAME_ICON "ooSetupFactoryIcon"
// returns list of properties, which has changed only! // We use given value of sNodeBase to build full qualified paths ... // Last sign of it must be "/". because we use it directly, without any additional things!
css::uno::Sequence< css::beans::PropertyValue > getChangedProperties( std::u16string_view sNodeBase )
{ // a) reserve memory for max. count of changed properties // b) add names and values of changed ones only and count it // c) resize return list by using count
css::uno::Sequence< css::beans::PropertyValue > lProperties ( 4 ); auto plProperties = lProperties.getArray();
sal_Int8 nRealyChanged = 0;
// We must support setting AND marking of changed values. // That's why we can't make our member public. We must use get/set/init methods // to control access on it! bool getInstalled () const { return bInstalled; }; const OUString& getFactory () const { return sFactory; }; const OUString& getTemplateFile () const { return sTemplateFile; }; const OUString& getDefaultFilter () const { return sDefaultFilter; }; bool isDefaultFilterReadonly() const { return bDefaultFilterReadonly; }
sal_Int32 getIcon () const { return nIcon; };
// If you call set-methods - we check for changes of values and mark it. // But if you wish to set it without that... you must initialize it! void initInstalled () { bInstalled = true; } void initFactory ( const OUString& sNewFactory ) { sFactory = sNewFactory; } void initDefaultFilter ( const OUString& sNewDefaultFilter ) { sDefaultFilter = sNewDefaultFilter; } void setDefaultFilterReadonly( constbool bVal){bDefaultFilterReadonly = bVal;} void initIcon ( sal_Int32 nNewIcon ) { nIcon = nNewIcon; }
@seealsobaseclassConfigItem @seealsomethodimpl_Read() @threadsafeno
*//*-*************************************************************************************************************/
SvtModuleOptions_Impl::SvtModuleOptions_Impl()
: ::utl::ConfigItem( ROOTNODE_FACTORIES )
, m_bReadOnlyStatesWellKnown( false )
{ // First initialize list of factory infos! Otherwise we couldn't guarantee right working of these class. for( auto & rFactory : m_lFactories )
rFactory.free();
// Get name list of all existing set node names in configuration to read her properties in impl_Read(). // These list is a list of long names of our factories. const css::uno::Sequence< OUString > lFactories = GetNodeNames( OUString() );
impl_Read( lFactories );
// Enable notification for changes by using configuration directly. // So we can update our internal values immediately.
EnableNotification( lFactories );
}
SvtModuleOptions_Impl::~SvtModuleOptions_Impl()
{
assert(!IsModified()); // should have been committed
}
@seealsobaseclassConfigItem @threadsafeno
*//*-*****************************************************************************************************/ void SvtModuleOptions_Impl::ImplCommit()
{ // Reserve memory for ALL possible factory properties! // Step over all factories and get her really changed values only. // Build list of these ones and use it for commit.
css::uno::Sequence< css::beans::PropertyValue > lCommitProperties( FACTORYCOUNT*PROPERTYCOUNT );
sal_Int32 nRealCount = 0;
OUString sBasePath; for( FactoryInfo & rInfo : m_lFactories )
{ // These path is used to build full qualified property names... // See pInfo->getChangedProperties() for further information
sBasePath = PATHSEPARATOR + rInfo.getFactory() + PATHSEPARATOR;
const css::uno::Sequence< css::beans::PropertyValue > lChangedProperties = rInfo.getChangedProperties ( sBasePath );
std::copy(lChangedProperties.begin(), lChangedProperties.end(), std::next(lCommitProperties.getArray(), nRealCount));
nRealCount += lChangedProperties.getLength();
} // Resize commit list to real size. // If nothing to do - suppress calling of configuration... // It could be too expensive :-) if( nRealCount > 0 )
{
lCommitProperties.realloc( nRealCount );
SetSetProperties( OUString(), lCommitProperties );
}
}
@onerrorWereturndefaultvalues.(mostly"notinstalled"!) @threadsafeno
*//*-*****************************************************************************************************/ bool SvtModuleOptions_Impl::IsModuleInstalled( SvtModuleOptions::EModule eModule ) const
{ switch( eModule )
{ case SvtModuleOptions::EModule::WRITER: return m_lFactories[SvtModuleOptions::EFactory::WRITER].getInstalled(); case SvtModuleOptions::EModule::WEB: return m_lFactories[SvtModuleOptions::EFactory::WRITERWEB].getInstalled(); case SvtModuleOptions::EModule::GLOBAL: return m_lFactories[SvtModuleOptions::EFactory::WRITERGLOBAL].getInstalled(); case SvtModuleOptions::EModule::CALC: return m_lFactories[SvtModuleOptions::EFactory::CALC].getInstalled(); case SvtModuleOptions::EModule::DRAW: return m_lFactories[SvtModuleOptions::EFactory::DRAW].getInstalled(); case SvtModuleOptions::EModule::IMPRESS: return m_lFactories[SvtModuleOptions::EFactory::IMPRESS].getInstalled(); case SvtModuleOptions::EModule::MATH: return m_lFactories[SvtModuleOptions::EFactory::MATH].getInstalled(); case SvtModuleOptions::EModule::CHART: return m_lFactories[SvtModuleOptions::EFactory::CHART].getInstalled(); case SvtModuleOptions::EModule::STARTMODULE: return m_lFactories[SvtModuleOptions::EFactory::STARTMODULE].getInstalled(); case SvtModuleOptions::EModule::BASIC: returntrue; // Couldn't be deselected by setup yet! case SvtModuleOptions::EModule::DATABASE: return m_lFactories[SvtModuleOptions::EFactory::DATABASE].getInstalled();
}
OUString SvtModuleOptions::GetFactoryShortName(SvtModuleOptions::EFactory eFactory)
{ // Attention: Hard configured yet ... because it's not fine to make changes possible by xml file yet. // But it's good to plan further possibilities!
//return m_lFactories[eFactory].sShortName;
OUString sShortName; switch( eFactory )
{ case SvtModuleOptions::EFactory::WRITER : sShortName = "swriter"; break; case SvtModuleOptions::EFactory::WRITERWEB: sShortName = "swriter/web"; break; case SvtModuleOptions::EFactory::WRITERGLOBAL: sShortName = "swriter/GlobalDocument"; break; case SvtModuleOptions::EFactory::CALC : sShortName = "scalc"; break; case SvtModuleOptions::EFactory::DRAW : sShortName = "sdraw"; break; case SvtModuleOptions::EFactory::IMPRESS : sShortName = "simpress"; break; case SvtModuleOptions::EFactory::MATH : sShortName = "smath"; break; case SvtModuleOptions::EFactory::CHART : sShortName = "schart"; break; case SvtModuleOptions::EFactory::BASIC : sShortName = "sbasic"; break; case SvtModuleOptions::EFactory::DATABASE : sShortName = "sdatabase"; break; case SvtModuleOptions::EFactory::STARTMODULE : sShortName = "startmodule"; break; default:
OSL_FAIL( "unknown factory" ); break;
}
OUString SvtModuleOptions_Impl::GetFactoryEmptyDocumentURL( SvtModuleOptions::EFactory eFactory )
{ // Attention: Hard configured yet ... because it's not fine to make changes possible by xml file yet. // But it's good to plan further possibilities!
@param"lFactories"isthelistofsetnodeentrieswhichshouldberead. @onerrorWedonothing. @threadsafeno
*//*-*************************************************************************************************************/ void SvtModuleOptions_Impl::impl_Read( const css::uno::Sequence< OUString >& lFactories )
{ // Expand every set node name in lFactories to full qualified paths to its properties // and get right values from configuration. const css::uno::Sequence< OUString > lProperties = impl_ExpandSetNames( lFactories ); const css::uno::Sequence< css::uno::Any > lValues = GetProperties( lProperties );
// Safe impossible cases. // We need values from ALL configuration keys. // Follow assignment use order of values in relation to our list of key names!
OSL_ENSURE( !(lProperties.getLength()!=lValues.getLength()), "SvtModuleOptions_Impl::impl_Read()\nI miss some values of configuration keys!" );
// Algorithm: We step over all given factory names and classify it. These enum value can be used as direct index // in our member list m_lFactories! VAriable nPropertyStart marks start position of every factory // and her properties in expanded property/value list. The defines PROPERTHANDLE_xxx are used as offset values // added to nPropertyStart. So we can address every property relative in these lists. // If we found any valid values ... we reset all existing information for corresponding m_lFactories-entry and // use a pointer to these struct in memory directly to set new values. // But we set it only, if bInstalled is true. Otherwise all other values of a factory can be undeclared .. They // shouldn't be used then. // Attention: If a propertyset of a factory will be ignored we must step to next start position of next factory infos! // see "nPropertyStart += PROPERTYCOUNT" ...
@seealsomethodimpl_GetOwnStaticMutex() @threadsafeyes
*//*-*************************************************************************************************************/
SvtModuleOptions::SvtModuleOptions()
{ // no need to take the mutex yet, shared_ptr/weak_ptr are thread-safe
m_pImpl = g_pModuleOptions.lock(); if( m_pImpl ) return;
// take the mutex, so we don't accidentally create more than one
std::unique_lock aGuard( impl_GetOwnStaticMutex() );
m_pImpl = g_pModuleOptions.lock(); if( !m_pImpl )
{
m_pImpl = std::make_shared<SvtModuleOptions_Impl>();
g_pModuleOptions = m_pImpl;
aGuard.unlock(); // because holdConfigItem will call this constructor
ItemHolder1::holdConfigItem(EItem::ModuleOptions);
}
}
bool SvtModuleOptions::ClassifyFactoryByName( std::u16string_view sName ,
EFactory& eFactory )
{ // We don't need any mutex here ... because we don't use any member here! return SvtModuleOptions_Impl::ClassifyFactoryByName( sName, eFactory );
}
// is there already a filter inside the descriptor?
OUString sFilterName = stlDesc.getUnpackedValueOrDefault(u"FilterName"_ustr, OUString()); if (!sFilterName.isEmpty())
{ try
{
::comphelper::SequenceAsHashMap stlFilterProps (xFilterCfg->getByName(sFilterName));
OUString sDocumentService = stlFilterProps.getUnpackedValueOrDefault(u"DocumentService"_ustr, OUString());
SvtModuleOptions::EFactory eApp = SvtModuleOptions::ClassifyFactoryByServiceName(sDocumentService);
if (eApp != EFactory::UNKNOWN_FACTORY) return eApp;
} catch(const css::uno::RuntimeException&)
{ throw; } catch(const css::uno::Exception&)
{ /* do nothing here ... may the following code can help!*/ }
}
// is there already a type inside the descriptor?
OUString sTypeName = stlDesc.getUnpackedValueOrDefault(u"TypeName"_ustr, OUString()); if (sTypeName.isEmpty())
{ // no :-( // start flat detection of URL
css::uno::Reference< css::document::XTypeDetection > xDetect(xTypeCfg, css::uno::UNO_QUERY);
sTypeName = xDetect->queryTypeByURL(sURL);
}
if (sTypeName.isEmpty()) return EFactory::UNKNOWN_FACTORY;
// yes - there is a type info // Try to find the preferred filter. try
{
::comphelper::SequenceAsHashMap stlTypeProps (xTypeCfg->getByName(sTypeName));
OUString sPreferredFilter = stlTypeProps.getUnpackedValueOrDefault(u"PreferredFilter"_ustr, OUString());
::comphelper::SequenceAsHashMap stlFilterProps (xFilterCfg->getByName(sPreferredFilter));
OUString sDocumentService = stlFilterProps.getUnpackedValueOrDefault(u"DocumentService"_ustr, OUString());
SvtModuleOptions::EFactory eApp = SvtModuleOptions::ClassifyFactoryByServiceName(sDocumentService);
if (eApp != EFactory::UNKNOWN_FACTORY) return eApp;
} catch(const css::uno::RuntimeException&)
{ throw; } catch(const css::uno::Exception&)
{ /* do nothing here ... may the following code can help!*/ }
// no filter/no type/no detection result => no fun :-) return EFactory::UNKNOWN_FACTORY;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.