1
/* gb-command-gaction.c
3
* Copyright (C) 2014 Christian Hergert <christian@hergert.me>
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#define G_LOG_DOMAIN "command-gaction"
21
#include <glib/gi18n.h>
24
#include "gb-command-gaction.h"
26
struct _GbCommandGaction
28
GbCommand parent_instance;
30
GActionGroup *action_group;
35
G_DEFINE_TYPE (GbCommandGaction, gb_command_gaction, GB_TYPE_COMMAND)
45
static GParamSpec *gParamSpecs [LAST_PROP];
48
gb_command_gaction_set_action_group (GbCommandGaction *gaction,
49
GActionGroup *action_group)
51
g_return_if_fail (GB_IS_COMMAND_GACTION (gaction));
52
g_return_if_fail (G_IS_ACTION_GROUP (action_group));
54
if (gaction->action_group != action_group)
56
g_clear_object (&gaction->action_group);
57
gaction->action_group = g_object_ref (action_group);
62
gb_command_gaction_set_action_name (GbCommandGaction *gaction,
63
const gchar *action_name)
65
g_return_if_fail (GB_IS_COMMAND_GACTION (gaction));
67
if (gaction->action_name != action_name)
69
g_clear_pointer (&gaction->action_name, g_free);
70
gaction->action_name = g_strdup (action_name);
75
gb_command_gaction_set_parameters (GbCommandGaction *gaction,
78
g_return_if_fail (GB_IS_COMMAND_GACTION (gaction));
80
if (gaction->parameters != variant)
82
g_clear_pointer (&gaction->parameters, g_variant_unref);
83
gaction->parameters = g_variant_ref (variant);
87
static GbCommandResult *
88
gb_command_gaction_execute (GbCommand *command)
90
GbCommandGaction *self = (GbCommandGaction *)command;
92
g_return_val_if_fail (GB_IS_COMMAND_GACTION (self), NULL);
94
if (self->action_group &&
96
g_action_group_has_action (self->action_group,
99
g_action_group_activate_action (self->action_group,
108
gb_command_gaction_finalize (GObject *object)
110
GbCommandGaction *self = GB_COMMAND_GACTION (object);
112
g_clear_object (&self->action_group);
113
g_clear_pointer (&self->action_name, g_free);
114
g_clear_pointer (&self->parameters, g_variant_unref);
116
G_OBJECT_CLASS (gb_command_gaction_parent_class)->finalize (object);
120
gb_command_gaction_get_property (GObject *object,
125
GbCommandGaction *self = GB_COMMAND_GACTION (object);
129
case PROP_ACTION_GROUP:
130
g_value_set_object (value, self->action_group);
133
case PROP_ACTION_NAME:
134
g_value_set_string (value, self->action_name);
137
case PROP_PARAMETERS:
138
g_value_set_variant (value, self->parameters);
142
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
147
gb_command_gaction_set_property (GObject *object,
152
GbCommandGaction *self = GB_COMMAND_GACTION (object);
156
case PROP_ACTION_GROUP:
157
gb_command_gaction_set_action_group (self, g_value_get_object (value));
160
case PROP_ACTION_NAME:
161
gb_command_gaction_set_action_name (self, g_value_get_string (value));
164
case PROP_PARAMETERS:
165
gb_command_gaction_set_parameters (self, g_value_get_variant (value));
169
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
174
gb_command_gaction_class_init (GbCommandGactionClass *klass)
176
GObjectClass *object_class = G_OBJECT_CLASS (klass);
177
GbCommandClass *command_class = GB_COMMAND_CLASS (klass);
179
object_class->finalize = gb_command_gaction_finalize;
180
object_class->get_property = gb_command_gaction_get_property;
181
object_class->set_property = gb_command_gaction_set_property;
183
command_class->execute = gb_command_gaction_execute;
185
gParamSpecs [PROP_ACTION_GROUP] =
186
g_param_spec_object ("action-group",
188
_("The GActionGroup containing the action."),
190
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
192
gParamSpecs [PROP_ACTION_NAME] =
193
g_param_spec_string ("action-name",
195
_("The name of the action to execute."),
197
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
199
gParamSpecs [PROP_PARAMETERS] =
200
g_param_spec_variant ("parameters",
202
_("The parameters for the action."),
205
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
207
g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
211
gb_command_gaction_init (GbCommandGaction *self)