1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef SDEXT_PRESENTER_CONFIGURATION_ACCESS_HXX 29*cdf0e10cSrcweir #define SDEXT_PRESENTER_CONFIGURATION_ACCESS_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <rtl/ustring.hxx> 32*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 36*cdf0e10cSrcweir #include <vector> 37*cdf0e10cSrcweir #include <boost/function.hpp> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir namespace css = ::com::sun::star; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir namespace sdext { namespace presenter { 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir /** This class gives access to the configuration. Create an object of this 44*cdf0e10cSrcweir class for one node of the configuration. This will be the root node. 45*cdf0e10cSrcweir From this one you can use this class in two ways. 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir <p>In a stateless mode (with exception of the root node) you can use static 48*cdf0e10cSrcweir methods for obtaining child nodes, get values from properties at leaf 49*cdf0e10cSrcweir nodes and iterate over children of inner nodes.</p> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir <p>In a stateful mode use non-static methods like GoToChild() to 52*cdf0e10cSrcweir navigate to children.</p> 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir <p>Note to call CommitChanges() after making changes to 55*cdf0e10cSrcweir PresenterConfigurationAccess object that was opened in READ_WRITE mode.</p> 56*cdf0e10cSrcweir */ 57*cdf0e10cSrcweir class PresenterConfigurationAccess 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir public: 60*cdf0e10cSrcweir enum WriteMode { READ_WRITE, READ_ONLY }; 61*cdf0e10cSrcweir typedef ::boost::function<bool( 62*cdf0e10cSrcweir const ::rtl::OUString&, 63*cdf0e10cSrcweir const css::uno::Reference<css::beans::XPropertySet>&)> Predicate; 64*cdf0e10cSrcweir static const ::rtl::OUString msPresenterScreenRootName; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir /** Create a new object to access the configuration entries below the 67*cdf0e10cSrcweir given root. 68*cdf0e10cSrcweir @param rsRootName 69*cdf0e10cSrcweir Name of the root. You can use msPresenterScreenRootName to 70*cdf0e10cSrcweir access the configuration of the presenter screen. 71*cdf0e10cSrcweir @param eMode 72*cdf0e10cSrcweir This flag specifies whether to give read-write or read-only 73*cdf0e10cSrcweir access. 74*cdf0e10cSrcweir */ 75*cdf0e10cSrcweir PresenterConfigurationAccess( 76*cdf0e10cSrcweir const css::uno::Reference<css::uno::XComponentContext>& rxContext, 77*cdf0e10cSrcweir const ::rtl::OUString& rsRootName, 78*cdf0e10cSrcweir WriteMode eMode); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir ~PresenterConfigurationAccess (void); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir /** Return a configuration node below the root of the called object. 83*cdf0e10cSrcweir @param rsPathToNode 84*cdf0e10cSrcweir The relative path from the root (as given the constructor) to the node. 85*cdf0e10cSrcweir */ 86*cdf0e10cSrcweir css::uno::Any GetConfigurationNode ( 87*cdf0e10cSrcweir const ::rtl::OUString& rsPathToNode); 88*cdf0e10cSrcweir css::uno::Reference<css::beans::XPropertySet> GetNodeProperties ( 89*cdf0e10cSrcweir const ::rtl::OUString& rsPathToNode); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir /** Return <TRUE/> when opening the configuration (via creating a new 92*cdf0e10cSrcweir PresenterConfigurationAccess object) or previous calls to 93*cdf0e10cSrcweir GoToChild() left the called PresenterConfigurationAccess object in a 94*cdf0e10cSrcweir valid state. 95*cdf0e10cSrcweir */ 96*cdf0e10cSrcweir bool IsValid (void) const; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir /** Move the focused node to the (possibly indirect) child specified by the given path. 99*cdf0e10cSrcweir */ 100*cdf0e10cSrcweir bool GoToChild (const ::rtl::OUString& rsPathToNode); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir /** Move the focused node to the first direct child that fulfills the the given predicate. 103*cdf0e10cSrcweir */ 104*cdf0e10cSrcweir bool GoToChild (const Predicate& rPredicate); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir /** Modify the property child of the currently focused node. Keep in 107*cdf0e10cSrcweir mind to call CommitChanges() to write the change back to the 108*cdf0e10cSrcweir configuration. 109*cdf0e10cSrcweir */ 110*cdf0e10cSrcweir bool SetProperty (const ::rtl::OUString& rsPropertyName, const css::uno::Any& rValue); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir /** Return a configuration node below the given node. 113*cdf0e10cSrcweir @param rxNode 114*cdf0e10cSrcweir The node that acts as root to the given relative path. 115*cdf0e10cSrcweir @param rsPathToNode 116*cdf0e10cSrcweir The relative path from the given node to the requested node. 117*cdf0e10cSrcweir When this string is empty then rxNode is returned. 118*cdf0e10cSrcweir @return 119*cdf0e10cSrcweir The type of the returned node varies with the requested node. 120*cdf0e10cSrcweir It is empty when the node was not found. 121*cdf0e10cSrcweir */ 122*cdf0e10cSrcweir static css::uno::Any GetConfigurationNode ( 123*cdf0e10cSrcweir const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode, 124*cdf0e10cSrcweir const ::rtl::OUString& rsPathToNode); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir static css::uno::Reference<css::beans::XPropertySet> GetNodeProperties ( 127*cdf0e10cSrcweir const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode, 128*cdf0e10cSrcweir const ::rtl::OUString& rsPathToNode); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir /** Write any changes that have been made back to the configuration. 131*cdf0e10cSrcweir This call is ignored when the called ConfigurationAccess object was 132*cdf0e10cSrcweir not create with read-write mode. 133*cdf0e10cSrcweir */ 134*cdf0e10cSrcweir void CommitChanges (void); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir css::uno::Any GetValue (const rtl::OUString& sKey); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir typedef ::boost::function<void( 139*cdf0e10cSrcweir const ::rtl::OUString&, 140*cdf0e10cSrcweir const ::std::vector<css::uno::Any>&) > ItemProcessor; 141*cdf0e10cSrcweir typedef ::boost::function<void( 142*cdf0e10cSrcweir const ::rtl::OUString&, 143*cdf0e10cSrcweir const ::css::uno::Reference<css::beans::XPropertySet>&) > PropertySetProcessor; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir /** Execute a functor for all elements of the given container. 146*cdf0e10cSrcweir @param rxContainer 147*cdf0e10cSrcweir The container is a XNameAccess to a list of the configuration. 148*cdf0e10cSrcweir This can be a node returned by GetConfigurationNode(). 149*cdf0e10cSrcweir @param rArguments 150*cdf0e10cSrcweir The functor is called with arguments that are children of each 151*cdf0e10cSrcweir element of the container. The set of children is specified this 152*cdf0e10cSrcweir list. 153*cdf0e10cSrcweir @param rFunctor 154*cdf0e10cSrcweir The functor to be executed for some or all of the elements in 155*cdf0e10cSrcweir the given container. 156*cdf0e10cSrcweir */ 157*cdf0e10cSrcweir static void ForAll ( 158*cdf0e10cSrcweir const css::uno::Reference<css::container::XNameAccess>& rxContainer, 159*cdf0e10cSrcweir const ::std::vector<rtl::OUString>& rArguments, 160*cdf0e10cSrcweir const ItemProcessor& rProcessor); 161*cdf0e10cSrcweir static void ForAll ( 162*cdf0e10cSrcweir const css::uno::Reference<css::container::XNameAccess>& rxContainer, 163*cdf0e10cSrcweir const PropertySetProcessor& rProcessor); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir /** Fill a list with the string contents of all sub-elements in the given container. 166*cdf0e10cSrcweir @param rxContainer 167*cdf0e10cSrcweir The container is a XNameAccess to a list of the configuration. 168*cdf0e10cSrcweir This can be a node returned by GetConfigurationNode(). 169*cdf0e10cSrcweir @param rsArgument 170*cdf0e10cSrcweir This specifies which string children of the elements in the 171*cdf0e10cSrcweir container are to be inserted into the list. The specified child 172*cdf0e10cSrcweir has to be of type string. 173*cdf0e10cSrcweir @param rList 174*cdf0e10cSrcweir The list to be filled. 175*cdf0e10cSrcweir */ 176*cdf0e10cSrcweir static void FillList( 177*cdf0e10cSrcweir const css::uno::Reference<css::container::XNameAccess>& rxContainer, 178*cdf0e10cSrcweir const ::rtl::OUString& rsArgument, 179*cdf0e10cSrcweir ::std::vector<rtl::OUString>& rList); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir static css::uno::Any Find ( 182*cdf0e10cSrcweir const css::uno::Reference<css::container::XNameAccess>& rxContainer, 183*cdf0e10cSrcweir const Predicate& rPredicate); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir static bool IsStringPropertyEqual ( 186*cdf0e10cSrcweir const ::rtl::OUString& rsValue, 187*cdf0e10cSrcweir const ::rtl::OUString& rsPropertyName, 188*cdf0e10cSrcweir const css::uno::Reference<css::beans::XPropertySet>& rxNode); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir /** This method wraps a call to getPropertyValue() and returns an empty 191*cdf0e10cSrcweir Any instead of throwing an exception when the property does not 192*cdf0e10cSrcweir exist. 193*cdf0e10cSrcweir */ 194*cdf0e10cSrcweir static css::uno::Any GetProperty ( 195*cdf0e10cSrcweir const css::uno::Reference<css::beans::XPropertySet>& rxProperties, 196*cdf0e10cSrcweir const ::rtl::OUString& rsKey); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir private: 199*cdf0e10cSrcweir css::uno::Reference<css::uno::XInterface> mxRoot; 200*cdf0e10cSrcweir css::uno::Any maNode; 201*cdf0e10cSrcweir }; 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir } } // end of namespace sdext::tools 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir #endif 206