~ubuntu-branches/ubuntu/precise/nautilus-actions/precise

« back to all changes in this revision

Viewing changes to libnautilus-actions/nautilus-actions-config-gconf-reader.c

  • Committer: Bazaar Package Importer
  • Author(s): Christine Spang
  • Date: 2009-08-12 14:04:00 UTC
  • mfrom: (1.1.6 upstream) (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090812140400-ufe3o3jvr62lf0sf
Tags: 1.12.0-1
* New upstream stable release.
  - Actions can now be enabled/disabled: disabled actions will
    never show up in the nautilus context menu
  - Gnome Bugzilla bugs fixed:
    - #325519 asked by Frederic Ruaudel (enabled property)
    - #590398 reported by Pierre Wieser (install doc)
    - #590399 reported by Pierre Wieser (gtk_image_menu_item_set_image)
    - #590709 reported by Claude Paroz (markup in translatable strings)
    - #590711 reported by Claude Paroz (pipe char is ambiguous to translate)
 - Do not install GConf schemas if --disable-schemas-install option has
   been specified
 - New/updated es and fr translations

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Nautilus Actions
3
 
 *
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)
7
 
 *
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.
12
 
 *
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.
17
 
 *
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.
22
 
 *
23
 
 * Authors:
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)
28
 
 */
29
 
 
30
 
#include <config.h>
31
 
#include <uuid/uuid.h>
32
 
#include <string.h>
33
 
#include "nautilus-actions-config-gconf-reader.h"
34
 
#include "nautilus-actions-config-gconf-private.h"
35
 
 
36
 
static GObjectClass *parent_class = NULL;
37
 
 
38
 
static gboolean
39
 
save_action (NautilusActionsConfig *self, NautilusActionsConfigAction *action)
40
 
{
41
 
        g_return_val_if_fail (NAUTILUS_ACTIONS_IS_CONFIG_GCONF_READER (self), FALSE);
42
 
 
43
 
        /* Nothing to do, it has already been done by the GConf notification handler */
44
 
 
45
 
        /* Return TRUE to allow the signals to be emited */
46
 
        return TRUE;
47
 
}
48
 
 
49
 
static gboolean
50
 
remove_action (NautilusActionsConfig *self, NautilusActionsConfigAction* action)
51
 
{
52
 
        g_return_val_if_fail (NAUTILUS_ACTIONS_IS_CONFIG_GCONF_READER (self), FALSE);
53
 
 
54
 
        /* Nothing to do, it has already been done by the GConf notification handler */
55
 
 
56
 
        /* Return TRUE to allow the signals to be emited */
57
 
        return TRUE;
58
 
}
59
 
 
60
 
static void
61
 
nautilus_actions_config_gconf_reader_finalize (GObject *object)
62
 
{
63
 
        NautilusActionsConfigGconfReader *config = NAUTILUS_ACTIONS_CONFIG_GCONF_READER (object);
64
 
 
65
 
        g_return_if_fail (NAUTILUS_ACTIONS_IS_CONFIG_GCONF_READER (config));
66
 
 
67
 
        /* free all memory */
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);
71
 
        }
72
 
 
73
 
        /* chain call to parent class */
74
 
        if (parent_class->finalize)
75
 
        {
76
 
                parent_class->finalize (object);
77
 
        }
78
 
}
79
 
 
80
 
static void
81
 
nautilus_actions_config_gconf_reader_class_init (NautilusActionsConfigGconfReaderClass *klass)
82
 
{
83
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
84
 
        NautilusActionsConfigClass* config_class;
85
 
 
86
 
        parent_class = g_type_class_peek_parent (klass);
87
 
        config_class = NAUTILUS_ACTIONS_CONFIG_CLASS (klass);
88
 
 
89
 
 
90
 
        object_class->finalize = nautilus_actions_config_gconf_reader_finalize;
91
 
 
92
 
        config_class->save_action = save_action;
93
 
        config_class->remove_action = remove_action;
94
 
}
95
 
 
96
 
/*
97
 
static gchar* get_action_profile_name_from_key (const gchar* key, const gchar* uuid)
98
 
{
99
 
        gchar* prefix = g_strdup_printf ("%s/%s/%s", ACTIONS_CONFIG_DIR, uuid, ACTIONS_PROFILE_PREFIX);
100
 
        gchar* profile_name = NULL;
101
 
 
102
 
        if (g_str_has_prefix (key, prefix))
103
 
        {
104
 
 
105
 
                profile_name = g_strdup (key + strlen (prefix));
106
 
                gchar* pos = g_strrstr (profile_name, "/");
107
 
                if (pos != NULL)
108
 
                {
109
 
                        *pos = '\0';
110
 
                }
111
 
        }
112
 
 
113
 
        g_free (prefix);
114
 
 
115
 
        return profile_name;
116
 
}
117
 
*/
118
 
 
119
 
/*
120
 
static void
121
 
copy_list (GConfValue* value, GSList** list)
122
 
{
123
 
           (*list) = g_slist_append ((*list), g_strdup (gconf_value_get_string (value)));
124
 
}
125
 
*/
126
 
 
127
 
static void
128
 
actions_changed_cb (GConfClient *client,
129
 
                    guint cnxn_id,
130
 
                    GConfEntry *entry,
131
 
                    gpointer user_data)
132
 
{
133
 
        NautilusActionsConfig *config = NAUTILUS_ACTIONS_CONFIG (user_data);
134
 
 
135
 
 
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;
141
 
 
142
 
        /* Get the modified action from the internal list if any */
143
 
        NautilusActionsConfigAction *old_action = nautilus_actions_config_get_action (config, uuid);
144
 
 
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);
147
 
 
148
 
        /* If modified action is unknown internally */
149
 
        if (old_action == NULL)
150
 
        {
151
 
                if (new_action != NULL)
152
 
                {
153
 
                        /* new action */
154
 
                        nautilus_actions_config_add_action (config, new_action, NULL);
155
 
                }
156
 
                else
157
 
                {
158
 
                        /* This case should not happen */
159
 
                        g_assert_not_reached ();
160
 
                }
161
 
        }
162
 
        else
163
 
        {
164
 
                if (new_action != NULL)
165
 
                {
166
 
                        /* action modified */
167
 
                        nautilus_actions_config_update_action (config, new_action);
168
 
                }
169
 
                else
170
 
                {
171
 
                        /* action removed */
172
 
                        nautilus_actions_config_remove_action (config, uuid);
173
 
                }
174
 
        }
175
 
 
176
 
        /* Add & change handler duplicate actions before adding them,
177
 
         * so we can free the new action
178
 
         */
179
 
        nautilus_actions_config_action_free (new_action);
180
 
}
181
 
 
182
 
static void
183
 
nautilus_actions_config_gconf_reader_init (NautilusActionsConfigGconfReader *config, NautilusActionsConfigGconfReaderClass *klass)
184
 
{
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,
190
 
                                                             NULL, NULL);
191
 
}
192
 
 
193
 
GType
194
 
nautilus_actions_config_gconf_reader_get_type (void)
195
 
{
196
 
   static GType type = 0;
197
 
 
198
 
        if (type == 0) {
199
 
                static GTypeInfo info = {
200
 
                                        sizeof (NautilusActionsConfigGconfReaderClass),
201
 
                                        (GBaseInitFunc) NULL,
202
 
                                        (GBaseFinalizeFunc) NULL,
203
 
                                        (GClassInitFunc) nautilus_actions_config_gconf_reader_class_init,
204
 
                                        NULL, NULL,
205
 
                                        sizeof (NautilusActionsConfigGconfReader),
206
 
                                        0,
207
 
                                        (GInstanceInitFunc) nautilus_actions_config_gconf_reader_init
208
 
                };
209
 
                type = g_type_register_static (NAUTILUS_ACTIONS_TYPE_CONFIG_GCONF, "NautilusActionsConfigGconfReader", &info, 0);
210
 
        }
211
 
        return type;
212
 
}
213
 
 
214
 
NautilusActionsConfigGconfReader *
215
 
nautilus_actions_config_gconf_reader_get (void)
216
 
{
217
 
        static NautilusActionsConfigGconfReader *config = NULL;
218
 
 
219
 
        /* we share one NautilusActionsConfigGconfReader object for all */
220
 
        if (!config) {
221
 
                config = g_object_new (NAUTILUS_ACTIONS_TYPE_CONFIG_GCONF_READER, NULL);
222
 
                return config;
223
 
        }
224
 
 
225
 
        return NAUTILUS_ACTIONS_CONFIG_GCONF_READER (g_object_ref (G_OBJECT (config)));
226
 
}