24#include <com/sun/star/configuration/theDefaultProvider.hpp>
25#include <com/sun/star/container/XNameAccess.hpp>
26#include <com/sun/star/container/XContainer.hpp>
27#include <com/sun/star/lang/XServiceInfo.hpp>
37#include <unordered_map>
48class ConfigurationAccess_UICategory :
public ::cppu::WeakImplHelper<XNameAccess,XContainerListener>
53 virtual ~ConfigurationAccess_UICategory()
override;
56 virtual css::uno::Any SAL_CALL getByName(
const OUString& aName )
override;
58 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames()
override;
60 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override;
63 virtual css::uno::Type SAL_CALL getElementType()
override;
65 virtual sal_Bool SAL_CALL hasElements()
override;
68 virtual void SAL_CALL
elementInserted(
const ContainerEvent& aEvent )
override;
69 virtual void SAL_CALL
elementRemoved (
const ContainerEvent& aEvent )
override;
70 virtual void SAL_CALL
elementReplaced(
const ContainerEvent& aEvent )
override;
73 virtual void SAL_CALL disposing(
const EventObject& aEvent )
override;
76 Any getUINameFromID(
const OUString& rId );
77 Any getUINameFromCache(
const OUString& rId );
82 typedef std::unordered_map< OUString,
83 OUString > IdToInfoCache;
85 void initializeConfigAccess();
87 OUString m_aConfigCategoryAccess;
88 OUString m_aPropUIName;
95 IdToInfoCache m_aIdCache;
102 m_aConfigCategoryAccess(
103 OUString::
Concat(
"/org.openoffice.Office.UI.") + aModuleName +
"/Commands/Categories"),
104 m_aPropUIName(
"Name" ),
105 m_xGenericUICategories( rGenericUICategories ),
112ConfigurationAccess_UICategory::~ConfigurationAccess_UICategory()
115 std::unique_lock g(aMutex);
117 if ( xContainer.is() )
122Any SAL_CALL ConfigurationAccess_UICategory::getByName(
const OUString& rId )
124 std::unique_lock g(aMutex);
127 initializeConfigAccess();
133 Any a = getUINameFromID( rId );
136 throw NoSuchElementException();
146sal_Bool SAL_CALL ConfigurationAccess_UICategory::hasByName(
const OUString& rId )
148 return getByName( rId ).hasValue();
152Type SAL_CALL ConfigurationAccess_UICategory::getElementType()
157sal_Bool SAL_CALL ConfigurationAccess_UICategory::hasElements()
163void ConfigurationAccess_UICategory::fillCache()
165 SAL_INFO(
"fwk",
"framework (cd100003) ::ConfigurationAccess_UICategory::fillCache" );
173 for ( OUString
const & rName : aNameSeq )
178 if ( xNameAccess.is() )
180 xNameAccess->getByName( m_aPropUIName ) >>=
aUIName;
182 m_aIdCache.emplace( rName,
aUIName );
185 catch (
const css::lang::WrappedTargetException& )
188 catch (
const css::container::NoSuchElementException& )
196Any ConfigurationAccess_UICategory::getUINameFromID(
const OUString& rId )
202 a = getUINameFromCache( rId );
206 if ( m_xGenericUICategories.is() )
210 return m_xGenericUICategories->getByName( rId );
212 catch (
const css::lang::WrappedTargetException& )
215 catch (
const css::container::NoSuchElementException& )
221 catch(
const css::container::NoSuchElementException& )
224 catch (
const css::lang::WrappedTargetException& )
231Any ConfigurationAccess_UICategory::getUINameFromCache(
const OUString& rId )
235 IdToInfoCache::const_iterator pIter = m_aIdCache.find( rId );
236 if ( pIter != m_aIdCache.end() )
245 std::unique_lock g(aMutex);
249 initializeConfigAccess();
260 if ( m_xGenericUICategories.is() )
264 sal_uInt32 nCount1 = aNameSeq.getLength();
265 sal_uInt32 nCount2 = aGenericNameSeq.getLength();
267 aNameSeq.realloc( nCount1 + nCount2 );
268 OUString* pNameSeq = aNameSeq.getArray();
269 const OUString* pGenericSeq = aGenericNameSeq.getConstArray();
270 for ( sal_uInt32 i = 0;
i < nCount2;
i++ )
271 pNameSeq[nCount1+i] = pGenericSeq[i];
276 catch(
const css::container::NoSuchElementException& )
279 catch (
const css::lang::WrappedTargetException& )
287void ConfigurationAccess_UICategory::initializeConfigAccess()
293 {
"nodepath",
Any(m_aConfigCategoryAccess)}
297 "com.sun.star.configuration.ConfigurationAccess", aArgs ),UNO_QUERY );
302 if ( xContainer.is() )
309 catch (
const WrappedTargetException& )
312 catch (
const Exception& )
318void SAL_CALL ConfigurationAccess_UICategory::elementInserted(
const ContainerEvent& )
322void SAL_CALL ConfigurationAccess_UICategory::elementRemoved (
const ContainerEvent& )
326void SAL_CALL ConfigurationAccess_UICategory::elementReplaced(
const ContainerEvent& )
331void SAL_CALL ConfigurationAccess_UICategory::disposing(
const EventObject& aEvent )
335 std::unique_lock g(aMutex);
339 if ( xIfac1 == xIfac2 )
346 explicit UICategoryDescription(
const css::uno::Reference< css::uno::XComponentContext >& rxContext );
350 return "com.sun.star.comp.framework.UICategoryDescription";
360 return {
"com.sun.star.ui.UICategoryDescription"};
371 OUString aGenericCategories(
"GenericCategories" );
372 m_xGenericUICommands[rCurrentLanguage] =
new ConfigurationAccess_UICategory( aGenericCategories, xEmpty, rxContext );
375 m_aModuleToCommandFileMap.emplace( OUString(
"generic"), aGenericCategories );
377 auto& rMap = m_aUICommandsHashMap[rCurrentLanguage];
378 UICommandsHashMap::iterator pCatIter = rMap.find( aGenericCategories );
379 if ( pCatIter != rMap.end() )
382 impl_fillElements(
"ooSetupFactoryCmdCategoryConfigRef");
387extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
389 css::uno::XComponentContext *context,
390 css::uno::Sequence<css::uno::Any>
const &)
392 return cppu::acquire(
new UICategoryDescription(context));
const LanguageTag & GetUILanguageTag() const
css::uno::Type const & get()
virtual sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::container::XNameAccess > m_xConfigAccess
void SAL_CALL elementReplaced(const css::container::ContainerEvent &Event) override
void SAL_CALL elementRemoved(const css::container::ContainerEvent &Event) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL elementInserted(const css::container::ContainerEvent &Event) override
#define SAL_INFO(area, stream)
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_framework_UICategoryDescription_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Reference< XMultiServiceFactory > m_xConfigProvider
Reference< XNameAccess > m_xGenericUICommands
Reference< XContainerListener > m_xConfigListener
bool m_bConfigAccessInitialized