1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #pragma once
21 
22 #include <com/sun/star/container/XContainerListener.hpp>
23 #include <com/sun/star/container/XNameAccess.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 
27 #include <cppuhelper/implbase.hxx>
28 #include <rtl/ustring.hxx>
29 
30 #include <string_view>
31 #include <unordered_map>
32 
33 //  Namespace
34 
35 namespace framework
36 {
37 
38 //  Configuration access class for PopupMenuControllerFactory implementation
39 
40 class ConfigurationAccess_ControllerFactory final : // interfaces
41                                                     public  ::cppu::WeakImplHelper< css::container::XContainerListener>
42 {
43 public:
44                     ConfigurationAccess_ControllerFactory( const css::uno::Reference< css::uno::XComponentContext >& rxContext, const OUString& _sRoot );
45     virtual       ~ConfigurationAccess_ControllerFactory() override;
46 
47     void          readConfigurationData();
48     void          updateConfigurationData();
49 
50     OUString getServiceFromCommandModule( std::u16string_view rCommandURL, std::u16string_view rModule ) const;
51     OUString getValueFromCommandModule( std::u16string_view rCommandURL, std::u16string_view rModule ) const;
52     void          addServiceToCommandModule( std::u16string_view rCommandURL, std::u16string_view rModule, const OUString& rServiceSpecifier );
53     void          removeServiceFromCommandModule( std::u16string_view rCommandURL, std::u16string_view rModule );
54 
55     // container.XContainerListener
56     virtual void SAL_CALL elementInserted( const css::container::ContainerEvent& Event ) override;
57     virtual void SAL_CALL elementRemoved( const css::container::ContainerEvent& Event ) override;
58     virtual void SAL_CALL elementReplaced( const css::container::ContainerEvent& Event ) override;
59 
60     // lang.XEventListener
61     virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
62 
63 private:
64     struct ControllerInfo
65     {
66         OUString m_aImplementationName;
67         OUString m_aValue;
ControllerInfoframework::ConfigurationAccess_ControllerFactory::ControllerInfo68         ControllerInfo(const OUString& _aImplementationName,const OUString& _aValue) : m_aImplementationName(_aImplementationName),m_aValue(_aValue){}
ControllerInfoframework::ConfigurationAccess_ControllerFactory::ControllerInfo69         ControllerInfo(){}
70     };
71     class MenuControllerMap : public std::unordered_map< OUString,
72                                                          ControllerInfo >
73     {
74     };
75 
76     bool impl_getElementProps( const css::uno::Any& aElement, OUString& aCommand, OUString& aModule, OUString& aServiceSpecifier,OUString& aValue ) const;
77 
78     mutable osl::Mutex           m_mutex;
79     OUString                     m_aPropCommand;
80     OUString                     m_aPropModule;
81     OUString                     m_aPropController;
82     OUString                     m_aPropValue;
83     OUString                     m_sRoot;
84     MenuControllerMap            m_aMenuControllerMap;
85     css::uno::Reference< css::lang::XMultiServiceFactory >    m_xConfigProvider;
86     css::uno::Reference< css::container::XNameAccess >        m_xConfigAccess;
87     css::uno::Reference< css::container::XContainerListener > m_xConfigAccessListener;
88     bool                          m_bConfigAccessInitialized;
89 };
90 
91 } // namespace framework
92 
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
94