~ubuntu-branches/ubuntu/maverick/nautilus-actions/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-04-07 17:10:19 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090407171019-xls2ugvapdmtvily
Tags: 1.4.1+svn521-0ubuntu1
Take SVN version to fix SIGSEGV crash in
gconf_client_remove_dir and autilus_actions_config_gconf_reader_finalize
(LP: #182345, #271114)

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
 
66
66
}
67
67
 
 
68
static gchar *
 
69
get_action_profile_name (const gchar *parent_dir, const gchar *profile_dir)
 
70
{
 
71
        gchar* prefix = g_strdup_printf ("%s/%s", parent_dir, ACTIONS_PROFILE_PREFIX);
 
72
        gchar* profile_name = NULL;
 
73
 
 
74
        if (g_str_has_prefix (profile_dir, prefix))
 
75
        {
 
76
                profile_name = g_strdup (profile_dir + strlen (prefix));
 
77
                gchar* pos = g_strrstr (profile_name, "/");
 
78
                if (pos != NULL)
 
79
                {
 
80
                        *pos = '\0';
 
81
                }
 
82
        }
 
83
 
 
84
        g_free (prefix);
 
85
 
 
86
        return profile_name;
 
87
}
 
88
 
68
89
static gboolean
69
90
get_action_bool_value (GConfClient *client, const gchar *dir, const gchar *value)
70
91
{
118
139
 
119
140
}*/
120
141
 
 
142
NautilusActionsConfigAction* 
 
143
nautilus_actions_config_gconf_get_action (NautilusActionsConfigGconf* config, const gchar* uuid)
 
144
{       
 
145
        g_assert (NAUTILUS_ACTIONS_IS_CONFIG_GCONF (config));
 
146
 
 
147
        g_return_val_if_fail (NAUTILUS_ACTIONS_IS_CONFIG_GCONF (config), NULL);
 
148
 
 
149
        GSList* iter;
 
150
        GSList* profile_list = NULL;
 
151
        gchar* profile_dir;
 
152
        gchar* profile_name;
 
153
        gchar* stmp;
 
154
        GSList* ltmp;
 
155
        gchar* gconf_action_dir = g_strdup_printf ("%s/%s", ACTIONS_CONFIG_DIR, uuid);
 
156
        NautilusActionsConfigActionProfile* action_profile;
 
157
 
 
158
        NautilusActionsConfigAction *action = nautilus_actions_config_action_new ();
 
159
 
 
160
        stmp = get_action_string_value (config->conf_client, gconf_action_dir, ACTION_LABEL_ENTRY);
 
161
        if (!stmp) 
 
162
        {
 
163
                nautilus_actions_config_action_free (action);
 
164
                return NULL;
 
165
        }
 
166
        nautilus_actions_config_action_set_label (action, stmp);
 
167
        g_free (stmp);
 
168
 
 
169
        nautilus_actions_config_action_set_uuid (action, uuid);
 
170
 
 
171
        stmp = get_action_string_value (config->conf_client, gconf_action_dir, ACTION_TOOLTIP_ENTRY);
 
172
        nautilus_actions_config_action_set_tooltip (action, stmp);
 
173
        g_free (stmp);
 
174
 
 
175
        stmp = get_action_string_value (config->conf_client, gconf_action_dir, ACTION_ICON_ENTRY);
 
176
        nautilus_actions_config_action_set_icon (action, stmp);
 
177
        g_free (stmp);
 
178
 
 
179
        action->version = get_action_string_value (config->conf_client, gconf_action_dir, ACTION_VERSION_ENTRY);
 
180
 
 
181
        if (g_ascii_strcasecmp (action->version, "2.0") < 0)
 
182
        {
 
183
                action_profile = nautilus_actions_config_action_profile_new ();
 
184
 
 
185
                //--> manage backward compatibility
 
186
                stmp = get_action_string_value (config->conf_client, gconf_action_dir, ACTION_PATH_ENTRY);
 
187
                nautilus_actions_config_action_profile_set_path (action_profile, stmp);
 
188
                g_free (stmp);
 
189
 
 
190
                stmp = get_action_string_value (config->conf_client, gconf_action_dir, ACTION_PARAMS_ENTRY);
 
191
                nautilus_actions_config_action_profile_set_parameters (action_profile, stmp);
 
192
                g_free (stmp);
 
193
 
 
194
                ltmp = get_action_list_value (config->conf_client, gconf_action_dir, ACTION_BASENAMES_ENTRY);
 
195
                nautilus_actions_config_action_profile_set_basenames (action_profile, ltmp);
 
196
                g_slist_foreach (ltmp, (GFunc) g_free, NULL);
 
197
                g_slist_free (ltmp);
 
198
 
 
199
                nautilus_actions_config_action_profile_set_is_file (action_profile, get_action_bool_value (config->conf_client, gconf_action_dir, ACTION_ISFILE_ENTRY));
 
200
 
 
201
                nautilus_actions_config_action_profile_set_is_dir (action_profile, get_action_bool_value (config->conf_client, gconf_action_dir, ACTION_ISDIR_ENTRY));
 
202
 
 
203
                nautilus_actions_config_action_profile_set_accept_multiple (action_profile, get_action_bool_value (config->conf_client, gconf_action_dir, ACTION_MULTIPLE_ENTRY));
 
204
 
 
205
                ltmp = get_action_list_value (config->conf_client, gconf_action_dir, ACTION_SCHEMES_ENTRY);
 
206
                nautilus_actions_config_action_profile_set_schemes (action_profile, ltmp);
 
207
                g_slist_foreach (ltmp, (GFunc) g_free, NULL);
 
208
                g_slist_free (ltmp);
 
209
 
 
210
                if (g_ascii_strcasecmp (action->version, "1.0") == 0)
 
211
                {
 
212
                        nautilus_actions_config_action_profile_set_match_case (action_profile, TRUE);
 
213
 
 
214
                        ltmp = g_slist_append (action_profile->mimetypes, g_strdup ("*/*"));
 
215
                        nautilus_actions_config_action_profile_set_mimetypes (action_profile, ltmp);
 
216
                        g_slist_foreach (ltmp, (GFunc) g_free, NULL);
 
217
                        g_slist_free (ltmp);
 
218
 
 
219
                }
 
220
                else
 
221
                {
 
222
 
 
223
                        nautilus_actions_config_action_profile_set_match_case (action_profile, get_action_bool_value (config->conf_client, gconf_action_dir, ACTION_MATCHCASE_ENTRY));
 
224
 
 
225
                        ltmp = get_action_list_value (config->conf_client, gconf_action_dir, ACTION_MIMETYPES_ENTRY);
 
226
                        nautilus_actions_config_action_profile_set_mimetypes (action_profile, ltmp);
 
227
                        g_slist_foreach (ltmp, (GFunc) g_free, NULL);
 
228
                        g_slist_free (ltmp);
 
229
 
 
230
                }
 
231
 
 
232
                nautilus_actions_config_action_profile_set_desc_name (action_profile, NAUTILUS_ACTIONS_DEFAULT_PROFILE_DESC_NAME);
 
233
                nautilus_actions_config_action_add_profile (action, NAUTILUS_ACTIONS_DEFAULT_PROFILE_NAME, action_profile, NULL);
 
234
        }
 
235
        else
 
236
        {
 
237
                /* load all defined profiles */
 
238
                profile_list = gconf_client_all_dirs (config->conf_client, gconf_action_dir, NULL);
 
239
 
 
240
                for (iter = profile_list; iter; iter = iter->next)
 
241
                {
 
242
                        profile_dir = (gchar*)iter->data;
 
243
                        profile_name = get_action_profile_name (gconf_action_dir, (gchar*)iter->data);
 
244
                        action_profile = nautilus_actions_config_action_profile_new ();
 
245
 
 
246
                        stmp = get_action_string_value (config->conf_client, profile_dir, ACTION_PROFILE_DESC_NAME_ENTRY);
 
247
                        if (stmp == NULL)
 
248
                        {
 
249
                                stmp = g_strdup (profile_name);
 
250
                        }
 
251
                        nautilus_actions_config_action_profile_set_desc_name (action_profile, stmp);
 
252
                        g_free (stmp);
 
253
 
 
254
                        stmp = get_action_string_value (config->conf_client, profile_dir, ACTION_PATH_ENTRY);
 
255
                        nautilus_actions_config_action_profile_set_path (action_profile, stmp);
 
256
                        g_free (stmp);
 
257
 
 
258
                        stmp = get_action_string_value (config->conf_client, profile_dir, ACTION_PARAMS_ENTRY);
 
259
                        nautilus_actions_config_action_profile_set_parameters (action_profile, stmp);
 
260
                        g_free (stmp);
 
261
 
 
262
                        ltmp = get_action_list_value (config->conf_client, profile_dir, ACTION_BASENAMES_ENTRY);
 
263
                        nautilus_actions_config_action_profile_set_basenames (action_profile, ltmp);
 
264
                        g_slist_foreach (ltmp, (GFunc) g_free, NULL);
 
265
                        g_slist_free (ltmp);
 
266
 
 
267
                        nautilus_actions_config_action_profile_set_match_case (action_profile, get_action_bool_value (config->conf_client, profile_dir, ACTION_MATCHCASE_ENTRY));
 
268
 
 
269
                        ltmp = get_action_list_value (config->conf_client, profile_dir, ACTION_MIMETYPES_ENTRY);
 
270
                        nautilus_actions_config_action_profile_set_mimetypes (action_profile, ltmp);
 
271
                        g_slist_foreach (ltmp, (GFunc) g_free, NULL);
 
272
                        g_slist_free (ltmp);
 
273
 
 
274
                        nautilus_actions_config_action_profile_set_is_file (action_profile, get_action_bool_value (config->conf_client, profile_dir, ACTION_ISFILE_ENTRY));
 
275
 
 
276
                        nautilus_actions_config_action_profile_set_is_dir (action_profile, get_action_bool_value (config->conf_client, profile_dir, ACTION_ISDIR_ENTRY));
 
277
 
 
278
                        nautilus_actions_config_action_profile_set_accept_multiple (action_profile, get_action_bool_value (config->conf_client, profile_dir, ACTION_MULTIPLE_ENTRY));
 
279
 
 
280
                        ltmp = get_action_list_value (config->conf_client, profile_dir, ACTION_SCHEMES_ENTRY);
 
281
                        nautilus_actions_config_action_profile_set_schemes (action_profile, ltmp);
 
282
                        g_slist_foreach (ltmp, (GFunc) g_free, NULL);
 
283
                        g_slist_free (ltmp);
 
284
 
 
285
                        nautilus_actions_config_action_add_profile (action, profile_name, action_profile, NULL);
 
286
 
 
287
                        g_free (profile_name);
 
288
                        g_free (profile_dir);
 
289
                }
 
290
 
 
291
                g_slist_free (profile_list);
 
292
        }
 
293
 
 
294
        g_free (gconf_action_dir);
 
295
 
 
296
        return action;
 
297
}
 
298
 
 
299
static gchar* get_action_uuid_from_key (const gchar* key)
 
300
{
 
301
        g_return_val_if_fail (g_str_has_prefix (key, ACTIONS_CONFIG_DIR), NULL);
 
302
        
 
303
        gchar* uuid = g_strdup (key + strlen (ACTIONS_CONFIG_DIR "/"));
 
304
        gchar* pos = g_strstr_len (uuid, strlen (uuid), "/");
 
305
        if (pos != NULL)
 
306
        {
 
307
                *pos = '\0';
 
308
        }
 
309
 
 
310
        return uuid;
 
311
}
 
312
 
121
313
static void
122
314
nautilus_actions_config_gconf_init (NautilusActionsConfigGconf *config, NautilusActionsConfigGconfClass *klass)
123
315
{
124
316
        GSList* node;
 
317
        
 
318
        g_type_init ();
125
319
        config->conf_client = gconf_client_get_default ();
126
320
 
127
321
        /* load all defined actions */
128
322
        GSList* list = gconf_client_all_dirs (config->conf_client, ACTIONS_CONFIG_DIR, NULL);
129
323
 
130
 
        for (node = list; node != NULL; node = node->next) {
131
 
                NautilusActionsConfigAction *action = nautilus_actions_config_action_new ();
132
 
 
133
 
                action->conf_section = node->data;
134
 
                action->label = get_action_string_value (config->conf_client, node->data, ACTION_LABEL_ENTRY);
135
 
                if (!action->label) {
136
 
                        nautilus_actions_config_action_free (action);
137
 
                        continue;
138
 
                }
139
 
 
140
 
                action->uuid = g_path_get_basename (action->conf_section); // Get the last part of the config section dir
141
 
                action->tooltip = get_action_string_value (config->conf_client, node->data, ACTION_TOOLTIP_ENTRY);
142
 
                action->icon = get_action_string_value (config->conf_client, node->data, ACTION_ICON_ENTRY);
143
 
                action->path = get_action_string_value (config->conf_client, node->data, ACTION_PATH_ENTRY);
144
 
                action->parameters = get_action_string_value (config->conf_client, node->data, ACTION_PARAMS_ENTRY);
145
 
                action->basenames = get_action_list_value (config->conf_client, node->data, ACTION_BASENAMES_ENTRY);
146
 
                action->match_case = get_action_bool_value (config->conf_client, node->data, ACTION_MATCHCASE_ENTRY);
147
 
                action->mimetypes = get_action_list_value (config->conf_client, node->data, ACTION_MIMETYPES_ENTRY);
148
 
                action->is_file = get_action_bool_value (config->conf_client, node->data, ACTION_ISFILE_ENTRY);
149
 
                action->is_dir = get_action_bool_value (config->conf_client, node->data, ACTION_ISDIR_ENTRY);
150
 
                action->accept_multiple_files = get_action_bool_value (config->conf_client, node->data, ACTION_MULTIPLE_ENTRY);
151
 
                action->schemes = get_action_list_value (config->conf_client, node->data, ACTION_SCHEMES_ENTRY);
152
 
                action->version = get_action_string_value (config->conf_client, node->data, ACTION_VERSION_ENTRY);
153
 
 
154
 
                if (g_ascii_strcasecmp (action->version, "1.0") == 0)
155
 
                {
156
 
                        //--> manage backward compatibility
157
 
                        action->match_case = TRUE;
158
 
                        action->mimetypes = g_slist_append (action->mimetypes, g_strdup ("*/*"));
159
 
                }
160
 
                else
161
 
                {
162
 
                        action->mimetypes = get_action_list_value (config->conf_client, node->data, ACTION_MIMETYPES_ENTRY);
163
 
                        action->match_case = get_action_bool_value (config->conf_client, node->data, ACTION_MATCHCASE_ENTRY);
164
 
                }
165
 
 
166
 
                /* add the new action to the hash table */
167
 
                g_hash_table_insert (NAUTILUS_ACTIONS_CONFIG (config)->actions, g_strdup (action->uuid), action);
 
324
        for (node = list; node != NULL; node = node->next) 
 
325
        {
 
326
                gchar* uuid = get_action_uuid_from_key ((gchar*)node->data);
 
327
                NautilusActionsConfigAction *action = nautilus_actions_config_gconf_get_action (config, uuid);
 
328
 
 
329
                if (action != NULL)
 
330
                {
 
331
                        /* add the new action to the hash table */
 
332
                        g_hash_table_insert (NAUTILUS_ACTIONS_CONFIG (config)->actions, g_strdup (action->uuid), action);
 
333
                }
 
334
 
 
335
                // Free the gconf dir string once used
 
336
                g_free (node->data);
168
337
        }
169
338
 
170
339
        g_slist_free (list);