2 * Copyright © 2012 Canonical Limited
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * licence or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
19 * Authors: Ryan Lortie <desrt@desrt.ca>
24 #include "gtkactionable.h"
26 #include "gtkwidget.h"
29 G_DEFINE_INTERFACE (GtkActionable, gtk_actionable, GTK_TYPE_WIDGET)
32 gtk_actionable_default_init (GtkActionableInterface *iface)
34 g_object_interface_install_property (iface,
35 g_param_spec_string ("action-name", P_("action name"),
36 P_("The name of the associated action, like 'app.quit'"),
37 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
39 g_object_interface_install_property (iface,
40 g_param_spec_variant ("action-target", P_("action target value"),
41 P_("The parameter for action invocations"),
42 G_VARIANT_TYPE_ANY, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
46 gtk_actionable_get_action_name (GtkActionable *actionable)
48 g_return_val_if_fail (GTK_IS_ACTIONABLE (actionable), NULL);
50 return GTK_ACTIONABLE_GET_IFACE (actionable)
51 ->get_action_name (actionable);
55 gtk_actionable_set_action_name (GtkActionable *actionable,
56 const gchar *action_name)
58 g_return_if_fail (GTK_IS_ACTIONABLE (actionable));
60 GTK_ACTIONABLE_GET_IFACE (actionable)
61 ->set_action_name (actionable, action_name);
65 gtk_actionable_get_action_target_value (GtkActionable *actionable)
67 g_return_val_if_fail (GTK_IS_ACTIONABLE (actionable), NULL);
69 return GTK_ACTIONABLE_GET_IFACE (actionable)
70 ->get_action_target_value (actionable);
74 gtk_actionable_set_action_target_value (GtkActionable *actionable,
75 GVariant *target_value)
77 g_return_if_fail (GTK_IS_ACTIONABLE (actionable));
79 GTK_ACTIONABLE_GET_IFACE (actionable)
80 ->set_action_target_value (actionable, target_value);
84 gtk_actionable_set_action_target (GtkActionable *actionable,
85 const gchar *format_string,
90 va_start (ap, format_string);
91 gtk_actionable_set_action_target_value (actionable, g_variant_new_va (format_string, NULL, &ap));
96 gtk_actionable_set_detailed_action_name (GtkActionable *actionable,
97 const gchar *detailed_action_name)
101 g_return_if_fail (GTK_IS_ACTIONABLE (actionable));
103 if (detailed_action_name == NULL)
105 gtk_actionable_set_action_name (actionable, NULL);
106 gtk_actionable_set_action_target_value (actionable, NULL);
110 parts = g_strsplit (detailed_action_name, "::", 2);
111 gtk_actionable_set_action_name (actionable, parts[0]);
112 if (parts[0] && parts[1])
113 gtk_actionable_set_action_target (actionable, "s", parts[1]);
115 gtk_actionable_set_action_target_value (actionable, NULL);