comparison src/editors.c @ 1479:d062522699dc

added simple desktop file editor
author nadvornik
date Fri, 27 Mar 2009 08:05:14 +0000
parents 3cc98d5c6907
children 1b2ddc6b2b27
comparison
equal deleted inserted replaced
1478:3cc98d5c6907 1479:d062522699dc
65 * external editor routines 65 * external editor routines
66 *----------------------------------------------------------------------------- 66 *-----------------------------------------------------------------------------
67 */ 67 */
68 68
69 GHashTable *editors = NULL; 69 GHashTable *editors = NULL;
70 GtkListStore *desktop_file_list;
71
70 72
71 #ifdef G_KEY_FILE_DESKTOP_GROUP 73 #ifdef G_KEY_FILE_DESKTOP_GROUP
72 #define DESKTOP_GROUP G_KEY_FILE_DESKTOP_GROUP 74 #define DESKTOP_GROUP G_KEY_FILE_DESKTOP_GROUP
73 #else 75 #else
74 #define DESKTOP_GROUP "Desktop Entry" 76 #define DESKTOP_GROUP "Desktop Entry"
181 gchar *extensions; 183 gchar *extensions;
182 gchar *type; 184 gchar *type;
183 const gchar *key = filename_from_path(path); 185 const gchar *key = filename_from_path(path);
184 gchar **categories, **only_show_in, **not_show_in; 186 gchar **categories, **only_show_in, **not_show_in;
185 gchar *try_exec; 187 gchar *try_exec;
188 GtkTreeIter iter;
186 189
187 if (g_hash_table_lookup(editors, key)) return FALSE; /* the file found earlier wins */ 190 if (g_hash_table_lookup(editors, key)) return FALSE; /* the file found earlier wins */
188 191
189 key_file = g_key_file_new(); 192 key_file = g_key_file_new();
190 if (!g_key_file_load_from_file(key_file, path, 0, NULL)) 193 if (!g_key_file_load_from_file(key_file, path, 0, NULL))
227 strcmp(categories[i], "X-Geeqie") == 0) 230 strcmp(categories[i], "X-Geeqie") == 0)
228 { 231 {
229 found = TRUE; 232 found = TRUE;
230 break; 233 break;
231 } 234 }
232 if (!found) editor->hidden = TRUE; 235 if (!found) editor->ignored = TRUE;
233 g_strfreev(categories); 236 g_strfreev(categories);
234 } 237 }
235 else 238 else
236 { 239 {
237 editor->hidden = TRUE; 240 editor->ignored = TRUE;
238 } 241 }
239 242
240 only_show_in = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "OnlyShowIn", NULL, NULL); 243 only_show_in = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "OnlyShowIn", NULL, NULL);
241 if (only_show_in) 244 if (only_show_in)
242 { 245 {
246 if (strcmp(only_show_in[i], "X-Geeqie") == 0) 249 if (strcmp(only_show_in[i], "X-Geeqie") == 0)
247 { 250 {
248 found = TRUE; 251 found = TRUE;
249 break; 252 break;
250 } 253 }
251 if (!found) editor->hidden = TRUE; 254 if (!found) editor->ignored = TRUE;
252 g_strfreev(only_show_in); 255 g_strfreev(only_show_in);
253 } 256 }
254 257
255 not_show_in = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "NotShowIn", NULL, NULL); 258 not_show_in = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "NotShowIn", NULL, NULL);
256 if (not_show_in) 259 if (not_show_in)
261 if (strcmp(not_show_in[i], "X-Geeqie") == 0) 264 if (strcmp(not_show_in[i], "X-Geeqie") == 0)
262 { 265 {
263 found = TRUE; 266 found = TRUE;
264 break; 267 break;
265 } 268 }
266 if (found) editor->hidden = TRUE; 269 if (found) editor->ignored = TRUE;
267 g_strfreev(not_show_in); 270 g_strfreev(not_show_in);
268 } 271 }
269 272
270 273
271 try_exec = g_key_file_get_string(key_file, DESKTOP_GROUP, "TryExec", NULL); 274 try_exec = g_key_file_get_string(key_file, DESKTOP_GROUP, "TryExec", NULL);
272 if (try_exec && !editor->hidden) 275 if (try_exec && !editor->hidden && !editor->ignored)
273 { 276 {
274 gchar *try_exec_res = g_find_program_in_path(try_exec); 277 gchar *try_exec_res = g_find_program_in_path(try_exec);
275 if (!try_exec_res) editor->hidden = TRUE; 278 if (!try_exec_res) editor->hidden = TRUE;
276 g_free(try_exec_res); 279 g_free(try_exec_res);
277 g_free(try_exec); 280 g_free(try_exec);
278 } 281 }
279 282
280 if (editor->hidden) 283 if (editor->ignored)
281 { 284 {
282 /* hidden editors will be deleted, no need to parse the rest */ 285 /* ignored editors will be deleted, no need to parse the rest */
283 g_key_file_free(key_file); 286 g_key_file_free(key_file);
284 return TRUE; 287 return TRUE;
285 } 288 }
286 289
287 editor->name = g_key_file_get_locale_string(key_file, DESKTOP_GROUP, "Name", NULL, NULL); 290 editor->name = g_key_file_get_locale_string(key_file, DESKTOP_GROUP, "Name", NULL, NULL);
335 if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Filter", NULL)) editor->flags |= EDITOR_DEST; 338 if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Filter", NULL)) editor->flags |= EDITOR_DEST;
336 if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "Terminal", NULL)) editor->flags |= EDITOR_TERMINAL; 339 if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "Terminal", NULL)) editor->flags |= EDITOR_TERMINAL;
337 340
338 editor->flags |= editor_command_parse(editor, NULL, NULL); 341 editor->flags |= editor_command_parse(editor, NULL, NULL);
339 g_key_file_free(key_file); 342 g_key_file_free(key_file);
343
344 if (editor->ignored) return TRUE;
345
346 gtk_list_store_append(desktop_file_list, &iter);
347 gtk_list_store_set(desktop_file_list, &iter,
348 DESKTOP_FILE_COLUMN_KEY, key,
349 DESKTOP_FILE_COLUMN_NAME, editor->name,
350 DESKTOP_FILE_COLUMN_HIDDEN, editor->hidden,
351 DESKTOP_FILE_COLUMN_WRITABLE, access_file(path, W_OK),
352 DESKTOP_FILE_COLUMN_PATH, path, -1);
340 353
341 return TRUE; 354 return TRUE;
342 } 355 }
343 356
344 static gboolean editor_remove_desktop_file_cb(gpointer key, gpointer value, gpointer user_data) 357 static gboolean editor_remove_desktop_file_cb(gpointer key, gpointer value, gpointer user_data)
345 { 358 {
346 EditorDescription *editor = value; 359 EditorDescription *editor = value;
347 return editor->hidden; 360 return editor->hidden || editor->ignored;
348 } 361 }
349 362
350 static void editor_read_desktop_dir(const gchar *path) 363 static void editor_read_desktop_dir(const gchar *path)
351 { 364 {
352 DIR *dp; 365 DIR *dp;
383 gchar *xdg_data_dirs; 396 gchar *xdg_data_dirs;
384 gchar *all_dirs; 397 gchar *all_dirs;
385 gchar **split_dirs; 398 gchar **split_dirs;
386 gint i; 399 gint i;
387 400
401 if (desktop_file_list)
402 {
403 gtk_list_store_clear(desktop_file_list);
404 }
405 else
406 {
407 desktop_file_list = gtk_list_store_new(DESKTOP_FILE_COLUMN_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING);
408 }
388 if (editors) 409 if (editors)
389 { 410 {
390 g_hash_table_destroy(editors); 411 g_hash_table_destroy(editors);
391 } 412 }
392 editors = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)editor_description_free); 413 editors = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)editor_description_free);