"Fossies" - the Fresh Open Source Software Archive

Member "glibmm-2.74.0/gio/src/actiongroup.hg" (19 Sep 2022, 9353 Bytes) of package /linux/misc/glibmm-2.74.0.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.


    1 /* Copyright (C) 2010 The giomm Development Team
    2  *
    3  * This library is free software; you can redistribute it and/or
    4  * modify it under the terms of the GNU Lesser General Public
    5  * License as published by the Free Software Foundation; either
    6  * version 2.1 of the License, or (at your option) any later version.
    7  *
    8  * This library is distributed in the hope that it will be useful,
    9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11  * Lesser General Public License for more details.
   12  *
   13  * You should have received a copy of the GNU Lesser General Public
   14  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
   15  */
   16 
   17 _CONFIGINCLUDE(giommconfig.h)
   18 
   19 #include <glibmm/interface.h>
   20 #include <glibmm/varianttype.h>
   21 #include <gio/gio.h> //To declare g_action_group_get_action_state_type().
   22 
   23 _DEFS(giomm,gio)
   24 _PINCLUDE(glibmm/private/interface_p.h)
   25 _PINCLUDE(gio/gio.h)
   26 
   27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
   28 typedef struct _GActionGroupInterface GActionGroupInterface;
   29 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
   30 
   31 namespace Glib
   32 {
   33 
   34 class GIOMM_API VariantBase;
   35 class GIOMM_API VariantContainerBase;
   36 class GIOMM_API VariantType;
   37 
   38 }
   39 
   40 namespace Gio
   41 {
   42 
   43 /** ActionGroup - a group of actions.
   44  * ActionGroup represents a group of actions.
   45  *
   46  * Each action in the group has a unique name (which is a string). All method
   47  * calls, except list_actions() take the name of an action as an argument.
   48  *
   49  * The GActionGroup API is meant to be the 'public' API to the action group.
   50  * The calls here are exactly the interaction that 'external forces' (eg: UI,
   51  * incoming D-Bus messages, etc.) are supposed to have with actions.
   52  * 'Internal' APIs (ie: ones meant only to be accessed by the action group
   53  * implementation) are found on subclasses. This is why you will find -- for
   54  * example -- get_action_enabled() but not an equivalent @c set() call.
   55  *
   56  * Signals are emitted on the action group in response to state changes on
   57  * individual actions.
   58  */
   59 class GIOMM_API ActionGroup : public Glib::Interface
   60 {
   61   _CLASS_INTERFACE(ActionGroup, GActionGroup, G_ACTION_GROUP, GActionGroupInterface, , , GIOMM_API)
   62 
   63 public:
   64   _WRAP_METHOD(bool has_action(const Glib::ustring& action_name) const, g_action_group_has_action)
   65 
   66 #m4 _CONVERSION(`gchar**',`std::vector<Glib::ustring>',`Glib::ArrayHandler<Glib::ustring>::array_to_vector($3, Glib::OWNERSHIP_DEEP)')
   67   _WRAP_METHOD(std::vector<Glib::ustring> list_actions() const, g_action_group_list_actions)
   68 
   69   //TODO: Add templated method, renaming this to query_action_variant).
   70   _WRAP_METHOD(bool query_action(const Glib::ustring& action_name, bool& enabled{>>}, Glib::VariantType& parameter_type{>>?}, Glib::VariantBase& state_hint{.>>}, Glib::VariantType& state_type{.>>?}, Glib::VariantBase& state{.>>?}), g_action_group_query_action)
   71 
   72   _WRAP_METHOD(bool get_action_enabled(const Glib::ustring& action_name) const, g_action_group_get_action_enabled)
   73 
   74   _WRAP_METHOD(Glib::VariantType get_action_parameter_type(const Glib::ustring& action_name) const, g_action_group_get_action_parameter_type)
   75   _WRAP_METHOD(Glib::VariantType get_action_state_type(const Glib::ustring& action_name) const, g_action_group_get_action_state_type)
   76 
   77   //TODO: How do we check for a nullptr Variant?
   78   /**
   79    * Requests a hint about the valid range of values for the state of the
   80    * named action within the action group
   81    *
   82    * If a null Variant is returned it either means that the action is not stateful
   83    * or that there is no hint about the valid range of values for the
   84    * state of the action.
   85    *
   86    * If a ariant array is returned then each item in the array is a
   87    * possible value for the state.  If Variant pair (ie: two-tuple) is
   88    * returned then the tuple specifies the inclusive lower and upper bound
   89    * of valid values for the state.
   90    *
   91    * In any case, the information is merely a hint.  It may be possible to
   92    * have a state value outside of the hinted range and setting a value
   93    * within the range may fail.
   94    *
   95    * @param action_name The name of the action to query.
   96    * @param value This will be set to the state range hint.
   97    */
   98   template <typename T_Value>
   99   void get_action_state_hint(const Glib::ustring& action_name, T_Value& value) const;
  100 
  101   _WRAP_METHOD(Glib::VariantContainerBase get_action_state_hint_variant(const Glib::ustring& action_name) const, g_action_group_get_action_state_hint)
  102 
  103   //TODO: How do we check for a nullptr Variant?
  104   /** Queries the current state of the named action within the action group.
  105    *
  106    * If the action is not stateful then a null Variant will be returned.  If the
  107    * action is stateful then the type of the return value is the type
  108    * given by get_action_state_type().
  109    *
  110    * @param action_name The name of the action to query.
  111    * @param value This will be set to the current state of the action.
  112    */
  113   template <typename T_Value>
  114   void get_action_state(const Glib::ustring& action_name, T_Value& value) const;
  115 
  116   _WRAP_METHOD(Glib::VariantBase get_action_state_variant(const Glib::ustring& action_name) const, g_action_group_get_action_state)
  117 
  118   //TODO: Add templated method, renaming this to change_action_state_variant().
  119   _WRAP_METHOD(void change_action_state(const Glib::ustring& action_name, const Glib::VariantBase& value), g_action_group_change_action_state)
  120 
  121   //TODO: Add templated method, renaming this to activate_action_variant().
  122   _WRAP_METHOD(void activate_action(const Glib::ustring& action_name, const Glib::VariantBase& parameter{?}), g_action_group_activate_action)
  123 
  124   _WRAP_METHOD(void action_added(const Glib::ustring& action_name), g_action_group_action_added)
  125   _WRAP_METHOD(void action_removed(const Glib::ustring& action_name), g_action_group_action_removed)
  126   _WRAP_METHOD(void action_enabled_changed(const Glib::ustring& action_name, bool enabled), g_action_group_action_enabled_changed)
  127 
  128   //TODO: Add templated method, renaming this to action_state_changed_variant).
  129   _WRAP_METHOD(void action_state_changed (const Glib::ustring& action_name, const Glib::VariantBase& state), g_action_group_action_state_changed)
  130 
  131   _WRAP_SIGNAL(void action_added(const Glib::ustring& action_name), "action-added", detail_name action_name)
  132   _WRAP_SIGNAL(void action_enabled_changed(const Glib::ustring& action_name, bool enabled), "action-enabled-changed", detail_name action_name)
  133   _WRAP_SIGNAL(void action_removed(const Glib::ustring& action_name), "action-removed", detail_name action_name)
  134 
  135 #m4 _CONVERSION(`GVariant*', `const Glib::VariantBase&', `Glib::wrap($3, true)')
  136 
  137   _WRAP_SIGNAL(void action_state_changed(const Glib::ustring& action_name, const Glib::VariantBase& value), "action-state-changed", detail_name action_name)
  138 
  139 protected:
  140   _WRAP_VFUNC(bool has_action(const Glib::ustring& name) const, "has_action")
  141 
  142 #m4 _CONVERSION(`std::vector<Glib::ustring>',`gchar**',`g_strdupv(const_cast<gchar**>(Glib::ArrayHandler<Glib::ustring>::vector_to_array($3).data()))')
  143   _WRAP_VFUNC(std::vector<Glib::ustring> list_actions() const, "list_actions")
  144 
  145   _WRAP_VFUNC(bool get_action_enabled(const Glib::ustring& name) const, "get_action_enabled")
  146 
  147 #m4 _CONVERSION(`Glib::VariantType',`const GVariantType*',`$3.gobj()')
  148   _WRAP_VFUNC(Glib::VariantType get_action_parameter_type(const Glib::ustring& name) const, "get_action_parameter_type", keep_return)
  149   _WRAP_VFUNC(Glib::VariantType get_action_state_type(const Glib::ustring& name) const, "get_action_state_type", keep_return)
  150 
  151   _WRAP_VFUNC(Glib::VariantBase get_action_state_hint(const Glib::ustring& name) const, "get_action_state_hint", refreturn_ctype)
  152   _WRAP_VFUNC(Glib::VariantBase get_action_state(const Glib::ustring& name) const, "get_action_state", refreturn_ctype)
  153 
  154   _WRAP_VFUNC(void change_action_state(const Glib::ustring& name, const Glib::VariantBase& value), "change_action_state")
  155   _WRAP_VFUNC(void activate_action(const Glib::ustring& name, const Glib::VariantBase& parameter), "activate_action")
  156 };
  157 
  158 template <typename T_Value>
  159 void ActionGroup::get_action_state(const Glib::ustring& action_name, T_Value& value) const
  160 {
  161   value = T_Value(); //Make sure that it is initialized.
  162 
  163   using type_glib_variant = Glib::Variant<T_Value>;
  164 
  165   g_return_if_fail(
  166     g_variant_type_equal(g_action_group_get_action_state_type(const_cast<GActionGroup*>(gobj()), action_name.c_str()), type_glib_variant::variant_type().gobj()));
  167 
  168   const auto variantBase = get_action_state_variant(action_name);
  169 
  170   //TODO: Add a bool return instead of letting a std::bad_cast from the cast_dynamic() be thrown up to the caller?
  171   const auto variantDerived = variantBase.cast_dynamic<type_glib_variant>(variantBase);
  172   value = variantDerived.get();
  173 }
  174 
  175 template <typename T_Value>
  176 void ActionGroup::get_action_state_hint(const Glib::ustring& action_name, T_Value& value) const
  177 {
  178   value = T_Value(); //Make sure that it is initialized.
  179 
  180   using type_glib_variant = Glib::Variant<T_Value>;
  181 
  182   const auto variantBase = get_action_state_hint_variant(action_name);
  183 
  184   // We can't check the type (a range) that will be returned before getting the range hint.
  185   g_return_if_fail(
  186     variantBase.is_of_type(type_glib_variant::variant_type()) );
  187 
  188   const auto variantDerived = variantBase.cast_dynamic<type_glib_variant>(variantBase);
  189   value = variantDerived.get();
  190 }
  191 
  192 } // namespace Gio