4
* Copyright (C) 2005 The GNOME Foundation
5
* Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
6
* Copyright (C) 2009 Pierre Wieser and others (see AUTHORS)
8
* This Program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public License as
10
* published by the Free Software Foundation; either version 2 of
11
* the License, or (at your option) any later version.
13
* This Program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public
19
* License along with this Library; see the file COPYING. If not,
20
* write to the Free Software Foundation, Inc., 59 Temple Place,
21
* Suite 330, Boston, MA 02111-1307, USA.
24
* Frederic Ruaudel <grumz@grumz.net>
25
* Rodrigo Moya <rodrigo@gnome-db.org>
26
* Pierre Wieser <pwieser@trychlos.org>
27
* ... and many others (see AUTHORS)
31
#include <uuid/uuid.h>
33
#include "nautilus-actions-config-gconf-reader.h"
34
#include "nautilus-actions-config-gconf-private.h"
36
static GObjectClass *parent_class = NULL;
39
save_action (NautilusActionsConfig *self, NautilusActionsConfigAction *action)
41
g_return_val_if_fail (NAUTILUS_ACTIONS_IS_CONFIG_GCONF_READER (self), FALSE);
43
/* Nothing to do, it has already been done by the GConf notification handler */
45
/* Return TRUE to allow the signals to be emited */
50
remove_action (NautilusActionsConfig *self, NautilusActionsConfigAction* action)
52
g_return_val_if_fail (NAUTILUS_ACTIONS_IS_CONFIG_GCONF_READER (self), FALSE);
54
/* Nothing to do, it has already been done by the GConf notification handler */
56
/* Return TRUE to allow the signals to be emited */
61
nautilus_actions_config_gconf_reader_finalize (GObject *object)
63
NautilusActionsConfigGconfReader *config = NAUTILUS_ACTIONS_CONFIG_GCONF_READER (object);
65
g_return_if_fail (NAUTILUS_ACTIONS_IS_CONFIG_GCONF_READER (config));
68
if (NAUTILUS_ACTIONS_CONFIG_GCONF (config)->conf_client) {
69
gconf_client_remove_dir (NAUTILUS_ACTIONS_CONFIG_GCONF (config)->conf_client, ACTIONS_CONFIG_DIR, NULL);
70
gconf_client_notify_remove (NAUTILUS_ACTIONS_CONFIG_GCONF (config)->conf_client, config->actions_notify_id);
73
/* chain call to parent class */
74
if (parent_class->finalize)
76
parent_class->finalize (object);
81
nautilus_actions_config_gconf_reader_class_init (NautilusActionsConfigGconfReaderClass *klass)
83
GObjectClass *object_class = G_OBJECT_CLASS (klass);
84
NautilusActionsConfigClass* config_class;
86
parent_class = g_type_class_peek_parent (klass);
87
config_class = NAUTILUS_ACTIONS_CONFIG_CLASS (klass);
90
object_class->finalize = nautilus_actions_config_gconf_reader_finalize;
92
config_class->save_action = save_action;
93
config_class->remove_action = remove_action;
97
static gchar* get_action_profile_name_from_key (const gchar* key, const gchar* uuid)
99
gchar* prefix = g_strdup_printf ("%s/%s/%s", ACTIONS_CONFIG_DIR, uuid, ACTIONS_PROFILE_PREFIX);
100
gchar* profile_name = NULL;
102
if (g_str_has_prefix (key, prefix))
105
profile_name = g_strdup (key + strlen (prefix));
106
gchar* pos = g_strrstr (profile_name, "/");
121
copy_list (GConfValue* value, GSList** list)
123
(*list) = g_slist_append ((*list), g_strdup (gconf_value_get_string (value)));
128
actions_changed_cb (GConfClient *client,
133
NautilusActionsConfig *config = NAUTILUS_ACTIONS_CONFIG (user_data);
136
/* The Key value format is XXX:YYYY-YYYY-... where XXX is an number incremented to make key
137
* effectively changed each time and YYYY-YYYY-... is the modified uuid */
138
const GConfValue* value = gconf_entry_get_value (entry);
139
const gchar* notify_value = gconf_value_get_string (value);
140
const gchar* uuid = notify_value + 4;
142
/* Get the modified action from the internal list if any */
143
NautilusActionsConfigAction *old_action = nautilus_actions_config_get_action (config, uuid);
145
/* Get the new version from GConf if any */
146
NautilusActionsConfigAction *new_action = nautilus_actions_config_gconf_get_action (NAUTILUS_ACTIONS_CONFIG_GCONF (config), uuid);
148
/* If modified action is unknown internally */
149
if (old_action == NULL)
151
if (new_action != NULL)
154
nautilus_actions_config_add_action (config, new_action, NULL);
158
/* This case should not happen */
159
g_assert_not_reached ();
164
if (new_action != NULL)
166
/* action modified */
167
nautilus_actions_config_update_action (config, new_action);
172
nautilus_actions_config_remove_action (config, uuid);
176
/* Add & change handler duplicate actions before adding them,
177
* so we can free the new action
179
nautilus_actions_config_action_free (new_action);
183
nautilus_actions_config_gconf_reader_init (NautilusActionsConfigGconfReader *config, NautilusActionsConfigGconfReaderClass *klass)
185
/* install notification callbacks */
186
gconf_client_add_dir (NAUTILUS_ACTIONS_CONFIG_GCONF (config)->conf_client, ACTIONS_CONFIG_DIR, GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
187
config->actions_notify_id = gconf_client_notify_add (NAUTILUS_ACTIONS_CONFIG_GCONF (config)->conf_client,
188
ACTIONS_CONFIG_NOTIFY_KEY,
189
(GConfClientNotifyFunc) actions_changed_cb, config,
194
nautilus_actions_config_gconf_reader_get_type (void)
196
static GType type = 0;
199
static GTypeInfo info = {
200
sizeof (NautilusActionsConfigGconfReaderClass),
201
(GBaseInitFunc) NULL,
202
(GBaseFinalizeFunc) NULL,
203
(GClassInitFunc) nautilus_actions_config_gconf_reader_class_init,
205
sizeof (NautilusActionsConfigGconfReader),
207
(GInstanceInitFunc) nautilus_actions_config_gconf_reader_init
209
type = g_type_register_static (NAUTILUS_ACTIONS_TYPE_CONFIG_GCONF, "NautilusActionsConfigGconfReader", &info, 0);
214
NautilusActionsConfigGconfReader *
215
nautilus_actions_config_gconf_reader_get (void)
217
static NautilusActionsConfigGconfReader *config = NULL;
219
/* we share one NautilusActionsConfigGconfReader object for all */
221
config = g_object_new (NAUTILUS_ACTIONS_TYPE_CONFIG_GCONF_READER, NULL);
225
return NAUTILUS_ACTIONS_CONFIG_GCONF_READER (g_object_ref (G_OBJECT (config)));