106bcd5d2SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 306bcd5d2SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 406bcd5d2SAndrew Rist * or more contributor license agreements. See the NOTICE file 506bcd5d2SAndrew Rist * distributed with this work for additional information 606bcd5d2SAndrew Rist * regarding copyright ownership. The ASF licenses this file 706bcd5d2SAndrew Rist * to you under the Apache License, Version 2.0 (the 806bcd5d2SAndrew Rist * "License"); you may not use this file except in compliance 906bcd5d2SAndrew Rist * with the License. You may obtain a copy of the License at 1006bcd5d2SAndrew Rist * 1106bcd5d2SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1206bcd5d2SAndrew Rist * 1306bcd5d2SAndrew Rist * Unless required by applicable law or agreed to in writing, 1406bcd5d2SAndrew Rist * software distributed under the License is distributed on an 1506bcd5d2SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1606bcd5d2SAndrew Rist * KIND, either express or implied. See the License for the 1706bcd5d2SAndrew Rist * specific language governing permissions and limitations 1806bcd5d2SAndrew Rist * under the License. 1906bcd5d2SAndrew Rist * 2006bcd5d2SAndrew Rist *************************************************************/ 2106bcd5d2SAndrew Rist 2206bcd5d2SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SDEXT_PRESENTER_CONFIGURATION_ACCESS_HXX 25cdf0e10cSrcweir #define SDEXT_PRESENTER_CONFIGURATION_ACCESS_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <rtl/ustring.hxx> 28cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 29cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 30cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp> 31cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 32cdf0e10cSrcweir #include <vector> 33cdf0e10cSrcweir #include <boost/function.hpp> 34cdf0e10cSrcweir 35cdf0e10cSrcweir namespace css = ::com::sun::star; 36cdf0e10cSrcweir 37cdf0e10cSrcweir namespace sdext { namespace presenter { 38cdf0e10cSrcweir 39cdf0e10cSrcweir /** This class gives access to the configuration. Create an object of this 40cdf0e10cSrcweir class for one node of the configuration. This will be the root node. 41cdf0e10cSrcweir From this one you can use this class in two ways. 42cdf0e10cSrcweir 43cdf0e10cSrcweir <p>In a stateless mode (with exception of the root node) you can use static 44cdf0e10cSrcweir methods for obtaining child nodes, get values from properties at leaf 45cdf0e10cSrcweir nodes and iterate over children of inner nodes.</p> 46cdf0e10cSrcweir 47cdf0e10cSrcweir <p>In a stateful mode use non-static methods like GoToChild() to 48cdf0e10cSrcweir navigate to children.</p> 49cdf0e10cSrcweir 50cdf0e10cSrcweir <p>Note to call CommitChanges() after making changes to 51cdf0e10cSrcweir PresenterConfigurationAccess object that was opened in READ_WRITE mode.</p> 52cdf0e10cSrcweir */ 53cdf0e10cSrcweir class PresenterConfigurationAccess 54cdf0e10cSrcweir { 55cdf0e10cSrcweir public: 56cdf0e10cSrcweir enum WriteMode { READ_WRITE, READ_ONLY }; 57cdf0e10cSrcweir typedef ::boost::function<bool( 58cdf0e10cSrcweir const ::rtl::OUString&, 59cdf0e10cSrcweir const css::uno::Reference<css::beans::XPropertySet>&)> Predicate; 60cdf0e10cSrcweir static const ::rtl::OUString msPresenterScreenRootName; 61cdf0e10cSrcweir 62cdf0e10cSrcweir /** Create a new object to access the configuration entries below the 63cdf0e10cSrcweir given root. 64cdf0e10cSrcweir @param rsRootName 65cdf0e10cSrcweir Name of the root. You can use msPresenterScreenRootName to 66cdf0e10cSrcweir access the configuration of the presenter screen. 67cdf0e10cSrcweir @param eMode 68cdf0e10cSrcweir This flag specifies whether to give read-write or read-only 69cdf0e10cSrcweir access. 70cdf0e10cSrcweir */ 71cdf0e10cSrcweir PresenterConfigurationAccess( 72cdf0e10cSrcweir const css::uno::Reference<css::uno::XComponentContext>& rxContext, 73cdf0e10cSrcweir const ::rtl::OUString& rsRootName, 74cdf0e10cSrcweir WriteMode eMode); 75cdf0e10cSrcweir 76cdf0e10cSrcweir ~PresenterConfigurationAccess (void); 77cdf0e10cSrcweir 78cdf0e10cSrcweir /** Return a configuration node below the root of the called object. 79cdf0e10cSrcweir @param rsPathToNode 80cdf0e10cSrcweir The relative path from the root (as given the constructor) to the node. 81cdf0e10cSrcweir */ 82cdf0e10cSrcweir css::uno::Any GetConfigurationNode ( 83cdf0e10cSrcweir const ::rtl::OUString& rsPathToNode); 84cdf0e10cSrcweir css::uno::Reference<css::beans::XPropertySet> GetNodeProperties ( 85cdf0e10cSrcweir const ::rtl::OUString& rsPathToNode); 86cdf0e10cSrcweir 87cdf0e10cSrcweir /** Return <TRUE/> when opening the configuration (via creating a new 88cdf0e10cSrcweir PresenterConfigurationAccess object) or previous calls to 89cdf0e10cSrcweir GoToChild() left the called PresenterConfigurationAccess object in a 90cdf0e10cSrcweir valid state. 91cdf0e10cSrcweir */ 92cdf0e10cSrcweir bool IsValid (void) const; 93cdf0e10cSrcweir 94cdf0e10cSrcweir /** Move the focused node to the (possibly indirect) child specified by the given path. 95cdf0e10cSrcweir */ 96cdf0e10cSrcweir bool GoToChild (const ::rtl::OUString& rsPathToNode); 97cdf0e10cSrcweir 98*fb0b81f5Smseidel /** Move the focused node to the first direct child that fulfills the given predicate. 99cdf0e10cSrcweir */ 100cdf0e10cSrcweir bool GoToChild (const Predicate& rPredicate); 101cdf0e10cSrcweir 102cdf0e10cSrcweir /** Modify the property child of the currently focused node. Keep in 103cdf0e10cSrcweir mind to call CommitChanges() to write the change back to the 104cdf0e10cSrcweir configuration. 105cdf0e10cSrcweir */ 106cdf0e10cSrcweir bool SetProperty (const ::rtl::OUString& rsPropertyName, const css::uno::Any& rValue); 107cdf0e10cSrcweir 108cdf0e10cSrcweir /** Return a configuration node below the given node. 109cdf0e10cSrcweir @param rxNode 110cdf0e10cSrcweir The node that acts as root to the given relative path. 111cdf0e10cSrcweir @param rsPathToNode 112cdf0e10cSrcweir The relative path from the given node to the requested node. 113cdf0e10cSrcweir When this string is empty then rxNode is returned. 114cdf0e10cSrcweir @return 115cdf0e10cSrcweir The type of the returned node varies with the requested node. 116cdf0e10cSrcweir It is empty when the node was not found. 117cdf0e10cSrcweir */ 118cdf0e10cSrcweir static css::uno::Any GetConfigurationNode ( 119cdf0e10cSrcweir const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode, 120cdf0e10cSrcweir const ::rtl::OUString& rsPathToNode); 121cdf0e10cSrcweir 122cdf0e10cSrcweir static css::uno::Reference<css::beans::XPropertySet> GetNodeProperties ( 123cdf0e10cSrcweir const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode, 124cdf0e10cSrcweir const ::rtl::OUString& rsPathToNode); 125cdf0e10cSrcweir 126cdf0e10cSrcweir /** Write any changes that have been made back to the configuration. 127cdf0e10cSrcweir This call is ignored when the called ConfigurationAccess object was 128cdf0e10cSrcweir not create with read-write mode. 129cdf0e10cSrcweir */ 130cdf0e10cSrcweir void CommitChanges (void); 131cdf0e10cSrcweir 132cdf0e10cSrcweir css::uno::Any GetValue (const rtl::OUString& sKey); 133cdf0e10cSrcweir 134cdf0e10cSrcweir typedef ::boost::function<void( 135cdf0e10cSrcweir const ::rtl::OUString&, 136cdf0e10cSrcweir const ::std::vector<css::uno::Any>&) > ItemProcessor; 137cdf0e10cSrcweir typedef ::boost::function<void( 138cdf0e10cSrcweir const ::rtl::OUString&, 139cdf0e10cSrcweir const ::css::uno::Reference<css::beans::XPropertySet>&) > PropertySetProcessor; 140cdf0e10cSrcweir 141cdf0e10cSrcweir /** Execute a functor for all elements of the given container. 142cdf0e10cSrcweir @param rxContainer 143cdf0e10cSrcweir The container is a XNameAccess to a list of the configuration. 144cdf0e10cSrcweir This can be a node returned by GetConfigurationNode(). 145cdf0e10cSrcweir @param rArguments 146cdf0e10cSrcweir The functor is called with arguments that are children of each 147cdf0e10cSrcweir element of the container. The set of children is specified this 148cdf0e10cSrcweir list. 149cdf0e10cSrcweir @param rFunctor 150cdf0e10cSrcweir The functor to be executed for some or all of the elements in 151cdf0e10cSrcweir the given container. 152cdf0e10cSrcweir */ 153cdf0e10cSrcweir static void ForAll ( 154cdf0e10cSrcweir const css::uno::Reference<css::container::XNameAccess>& rxContainer, 155cdf0e10cSrcweir const ::std::vector<rtl::OUString>& rArguments, 156cdf0e10cSrcweir const ItemProcessor& rProcessor); 157cdf0e10cSrcweir static void ForAll ( 158cdf0e10cSrcweir const css::uno::Reference<css::container::XNameAccess>& rxContainer, 159cdf0e10cSrcweir const PropertySetProcessor& rProcessor); 160cdf0e10cSrcweir 161cdf0e10cSrcweir /** Fill a list with the string contents of all sub-elements in the given container. 162cdf0e10cSrcweir @param rxContainer 163cdf0e10cSrcweir The container is a XNameAccess to a list of the configuration. 164cdf0e10cSrcweir This can be a node returned by GetConfigurationNode(). 165cdf0e10cSrcweir @param rsArgument 166cdf0e10cSrcweir This specifies which string children of the elements in the 167cdf0e10cSrcweir container are to be inserted into the list. The specified child 168cdf0e10cSrcweir has to be of type string. 169cdf0e10cSrcweir @param rList 170cdf0e10cSrcweir The list to be filled. 171cdf0e10cSrcweir */ 172cdf0e10cSrcweir static void FillList( 173cdf0e10cSrcweir const css::uno::Reference<css::container::XNameAccess>& rxContainer, 174cdf0e10cSrcweir const ::rtl::OUString& rsArgument, 175cdf0e10cSrcweir ::std::vector<rtl::OUString>& rList); 176cdf0e10cSrcweir 177cdf0e10cSrcweir static css::uno::Any Find ( 178cdf0e10cSrcweir const css::uno::Reference<css::container::XNameAccess>& rxContainer, 179cdf0e10cSrcweir const Predicate& rPredicate); 180cdf0e10cSrcweir 181cdf0e10cSrcweir static bool IsStringPropertyEqual ( 182cdf0e10cSrcweir const ::rtl::OUString& rsValue, 183cdf0e10cSrcweir const ::rtl::OUString& rsPropertyName, 184cdf0e10cSrcweir const css::uno::Reference<css::beans::XPropertySet>& rxNode); 185cdf0e10cSrcweir 186cdf0e10cSrcweir /** This method wraps a call to getPropertyValue() and returns an empty 187cdf0e10cSrcweir Any instead of throwing an exception when the property does not 188cdf0e10cSrcweir exist. 189cdf0e10cSrcweir */ 190cdf0e10cSrcweir static css::uno::Any GetProperty ( 191cdf0e10cSrcweir const css::uno::Reference<css::beans::XPropertySet>& rxProperties, 192cdf0e10cSrcweir const ::rtl::OUString& rsKey); 193cdf0e10cSrcweir 194cdf0e10cSrcweir private: 195cdf0e10cSrcweir css::uno::Reference<css::uno::XInterface> mxRoot; 196cdf0e10cSrcweir css::uno::Any maNode; 197cdf0e10cSrcweir }; 198cdf0e10cSrcweir 199cdf0e10cSrcweir } } // end of namespace sdext::tools 200cdf0e10cSrcweir 201cdf0e10cSrcweir #endif 202