diff options
author | George Lebl <jirka@5z.com> | 2001-09-19 06:18:30 +0000 |
---|---|---|
committer | George Lebl <jirka@src.gnome.org> | 2001-09-19 06:18:30 +0000 |
commit | e7ae2da74891b59cea44887ea56c35c9ce3e980b (patch) | |
tree | b09a4129c19ba4515f670b6b0f55b9f6534f0b6d | |
parent | 093ddf4e78525b2c9b03305fbc88ffec20355434 (diff) | |
download | gnome-desktop-e7ae2da74891b59cea44887ea56c35c9ce3e980b.tar.gz |
Few more accessors, whack the push/pop of sections. Keys can now include
Tue Sep 18 23:11:33 2001 George Lebl <jirka@5z.com>
* gnome-desktop-item.[ch]: Few more accessors, whack the push/pop
of sections. Keys can now include sections, add actual error
returns
* gnome-ditem-edit.[ch]: whack crack entries, make compile, and port
to new desktop item.
* Makefile.am: add the ditem-edit
-rw-r--r-- | libgnome-desktop/ChangeLog | 11 | ||||
-rw-r--r-- | libgnome-desktop/Makefile.am | 6 | ||||
-rw-r--r-- | libgnome-desktop/gnome-desktop-item.c | 586 | ||||
-rw-r--r-- | libgnome-desktop/gnome-desktop-item.h | 61 | ||||
-rw-r--r-- | libgnome-desktop/gnome-ditem-edit.c | 595 | ||||
-rw-r--r-- | libgnome-desktop/gnome-ditem-edit.h | 13 | ||||
-rw-r--r-- | libgnome-desktop/libgnome/gnome-desktop-item.h | 61 | ||||
-rw-r--r-- | libgnome-desktop/libgnomeui/gnome-ditem-edit.h | 13 |
8 files changed, 743 insertions, 603 deletions
diff --git a/libgnome-desktop/ChangeLog b/libgnome-desktop/ChangeLog index 37d40c43..1ef4d3f7 100644 --- a/libgnome-desktop/ChangeLog +++ b/libgnome-desktop/ChangeLog @@ -1,3 +1,14 @@ +Tue Sep 18 23:11:33 2001 George Lebl <jirka@5z.com> + + * gnome-desktop-item.[ch]: Few more accessors, whack the push/pop + of sections. Keys can now include sections, add actual error + returns + + * gnome-ditem-edit.[ch]: whack crack entries, make compile, and port + to new desktop item. + + * Makefile.am: add the ditem-edit + Sat Sep 08 01:55:29 2001 George Lebl <jirka@5z.com> * All bonobo stuff. Removed for now. This is in bonobo somewhere diff --git a/libgnome-desktop/Makefile.am b/libgnome-desktop/Makefile.am index 4cbb5526..4da90314 100644 --- a/libgnome-desktop/Makefile.am +++ b/libgnome-desktop/Makefile.am @@ -8,6 +8,7 @@ INCLUDES = \ -I$(top_builddir)/panel \ -I$(includedir) \ -DGNOME_DESKTOP_SYSCONFDIR=\""$(sysconfdir)"\" \ + -DGNOME_CORE_INTERNAL \ $(GNOME_DESKTOP_CFLAGS) lib_LTLIBRARIES = libgnome-desktop-2.la @@ -15,9 +16,8 @@ lib_LTLIBRARIES = libgnome-desktop-2.la noinst_PROGRAMS = test-ditem libgnome_desktop_2_la_SOURCES = \ - gnome-desktop-item.c - -# gnome-ditem-edit.c + gnome-desktop-item.c \ + gnome-ditem-edit.c libgnome_desktopdir = $(includedir)/gnome-desktop-2.0/libgnome libgnome_desktop_HEADERS = \ diff --git a/libgnome-desktop/gnome-desktop-item.c b/libgnome-desktop/gnome-desktop-item.c index b1c8c065..86d057c4 100644 --- a/libgnome-desktop/gnome-desktop-item.c +++ b/libgnome-desktop/gnome-desktop-item.c @@ -2,11 +2,12 @@ /* gnome-desktop-item.c - GNOME Desktop File Representation Copyright (C) 1999, 2000 Red Hat Inc. + Copyright (C) 2001 Sid Vicious All rights reserved. This file is part of the Gnome Library. - Developed by Elliot Lee <sopwith@redhat.com> + Developed by Elliot Lee <sopwith@redhat.com> and Sid Vicious The Gnome Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as @@ -68,9 +69,6 @@ struct _GnomeDesktopItem { GList *sections; - /* push pop of sections */ - GList *section_stack; - /* This includes ALL keys, including * other sections, separated by '/' */ GHashTable *main_hash; @@ -80,6 +78,10 @@ struct _GnomeDesktopItem { time_t mtime; }; +/* If mtime is set to this, set_location won't update mtime, + * this is to be used internally only. */ +#define DONT_UPDATE_MTIME ((time_t)-2) + typedef struct { char *name; GList *keys; @@ -175,12 +177,13 @@ copy_string_hash (gpointer key, gpointer value, gpointer user_data) * Returns: The new copy */ GnomeDesktopItem * -gnome_desktop_item_copy (GnomeDesktopItem *item) +gnome_desktop_item_copy (const GnomeDesktopItem *item) { GList *li; GnomeDesktopItem *retval; g_return_val_if_fail (item != NULL, NULL); + g_return_val_if_fail (item->refcount > 0, NULL); retval = gnome_desktop_item_new (); @@ -210,6 +213,59 @@ gnome_desktop_item_copy (GnomeDesktopItem *item) return retval; } +static void +read_sort_order (GnomeDesktopItem *item, const char *dir) +{ + char *file; + FILE *fp; + char buf[BUFSIZ]; + GString *str; + + file = g_build_filename (dir, ".order", NULL); + fp = fopen (file, "r"); + g_free (file); + if (fp == NULL) { + return; + } + + str = NULL; + while (fgets (buf, sizeof (buf), fp) != NULL) { + char *p; + p = strchr (buf, '\n'); + if (p != NULL) + *p = '\0'; + if (str == NULL) + str = g_string_new (buf); + else + g_string_append (str, buf); + g_string_append_c (str, ';'); + } + fclose (fp); + if (str != NULL) { + gnome_desktop_item_set_string (item, GNOME_DESKTOP_ITEM_SORT_ORDER, + str->str); + g_string_free (str, TRUE); + } +} + +static GnomeDesktopItem * +make_fake_directory (const char *dir) +{ + GnomeDesktopItem *item; + char *file; + + item = gnome_desktop_item_new (); + gnome_desktop_item_set_entry_type (item, + GNOME_DESKTOP_ITEM_TYPE_DIRECTORY); + file = g_build_filename (dir, ".directory", NULL); + item->mtime = DONT_UPDATE_MTIME; /* it doesn't exist, we know that */ + gnome_desktop_item_set_location (item, file); + item->mtime = 0; + g_free (file); + + read_sort_order (item, dir); +} + /** * gnome_desktop_item_new_from_file: * @file: The filename or directory path to load the GnomeDesktopItem from @@ -227,26 +283,28 @@ gnome_desktop_item_new_from_file (const char *file, GError **error) { GnomeDesktopItem *retval; - char *subfn; + char *subfn, *dir; struct stat sbuf; g_return_val_if_fail (file != NULL, NULL); if (stat (file, &sbuf) != 0) { - /* FIXME: use GError */ + g_set_error (error, + G_FILE_ERROR, + g_file_error_from_errno (errno), + _("Error reading file '%s': %s"), + file, strerror (errno)); + return NULL; } /* Step one - figure out what type of file this is */ if (S_ISDIR (sbuf.st_mode)) { - subfn = g_strdup_printf ("%s/.directory", file); + subfn = g_build_filename (file, ".directory", NULL); /* get the correct time for this file */ if (stat (subfn, &sbuf) != 0) { g_free (subfn); - /* FIXME: if .order exists make a fake .directory with that - * order */ - /* FIXME: use GError */ - return NULL; + return make_fake_directory (file); } } else { subfn = g_strdup (file); @@ -266,17 +324,14 @@ gnome_desktop_item_new_from_file (const char *file, return NULL; } - if (subfn[0] == '/') { - retval->location = subfn; - subfn = NULL; - } else { - char *curdir = g_get_current_dir (); - retval->location = g_concat_dir_and_file (curdir, subfn); - g_free (curdir); - } - + retval->mtime = DONT_UPDATE_MTIME; + gnome_desktop_item_set_location (retval, subfn); retval->mtime = sbuf.st_mtime; + dir = g_path_get_dirname (retval->location); + read_sort_order (retval, dir); + g_free (dir); + g_free (subfn); return retval; @@ -313,7 +368,10 @@ gnome_desktop_item_save (GnomeDesktopItem *item, file_name = under; if (file_name == NULL) { - /* FIXME: GError return */ + g_set_error (error, + GNOME_DESKTOP_ITEM_ERROR, + GNOME_DESKTOP_ITEM_ERROR_NO_FILENAME, + _("No filename to save to")); return FALSE; } @@ -388,9 +446,6 @@ gnome_desktop_item_unref (GnomeDesktopItem *item) g_list_free (item->sections); item->sections = NULL; - g_list_free (item->section_stack); - item->section_stack = NULL; - g_hash_table_destroy (item->main_hash); item->main_hash = NULL; @@ -400,24 +455,77 @@ gnome_desktop_item_unref (GnomeDesktopItem *item) g_free (item); } -static const char * -lookup (GnomeDesktopItem *item, const char *key) +static Section * +find_section (GnomeDesktopItem *item, const char *section) { - if (item->section_stack != NULL && - item->section_stack->data != NULL) { - const char *ret; - Section *sec = item->section_stack->data; - char *full = g_strdup_printf ("%s/%s", sec->name, key); - ret = g_hash_table_lookup (item->main_hash, full); - g_free (full); - return ret; - } else { - return g_hash_table_lookup (item->main_hash, key); + GList *li; + Section *sec; + + if (section == NULL) + return NULL; + if (strcmp (section, "Desktop Entry") == 0) + return NULL; + + for (li = item->sections; li != NULL; li = li->next) { + sec = li->data; + if (strcmp (sec->name, section) == 0) + return sec; } + + sec = g_new0 (Section, 1); + sec->name = g_strdup (section); + sec->keys = NULL; + + item->sections = g_list_append (item->sections, sec); + + /* Don't mark the item modified, this is just an empty section, + * it won't be saved even */ + + return sec; +} + +static Section * +section_from_key (GnomeDesktopItem *item, const char *key) +{ + char *p; + char *name; + Section *sec; + + if (key == NULL) + return NULL; + + p = strchr (key, '/'); + if (p == NULL) + return NULL; + + name = g_strndup (key, p - key); + + sec = find_section (item, name); + + g_free (name); + + return sec; +} + +static const char * +key_basename (const char *key) +{ + char *p = strrchr (key, '/'); + if (p != NULL) + return p+1; + else + return key; } + static const char * -lookup_locale (GnomeDesktopItem *item, const char *key, const char *locale) +lookup (const GnomeDesktopItem *item, const char *key) +{ + return g_hash_table_lookup (item->main_hash, key); +} + +static const char * +lookup_locale (const GnomeDesktopItem *item, const char *key, const char *locale) { if (locale == NULL || strcmp (locale, "C") == 0) { @@ -432,7 +540,7 @@ lookup_locale (GnomeDesktopItem *item, const char *key, const char *locale) } static const char * -lookup_best_locale (GnomeDesktopItem *item, const char *key) +lookup_best_locale (const GnomeDesktopItem *item, const char *key) { const GList *list = gnome_i18n_get_language_list ("LC_MESSAGES"); while (list != NULL) { @@ -452,28 +560,28 @@ lookup_best_locale (GnomeDesktopItem *item, const char *key) static void set (GnomeDesktopItem *item, const char *key, const char *value) { - if (item->section_stack != NULL && - item->section_stack->data != NULL) { - Section *sec = item->section_stack->data; - char *full = g_strdup_printf ("%s/%s", sec->name, key); + Section *sec = section_from_key (item, key); + if (sec != NULL) { if (value != NULL) { - if (g_hash_table_lookup (item->main_hash, - full) == NULL) - sec->keys = g_list_append (sec->keys, - g_strdup (key)); + if (g_hash_table_lookup (item->main_hash, key) == NULL) + sec->keys = g_list_append + (sec->keys, + g_strdup (key_basename (key))); - g_hash_table_replace (item->main_hash, full, + g_hash_table_replace (item->main_hash, + g_strdup (key), g_strdup (value)); } else { GList *list = g_list_find_custom - (sec->keys, key, (GCompareFunc)strcmp); + (sec->keys, key_basename (key), + (GCompareFunc)strcmp); if (list != NULL) { g_free (list->data); sec->keys = g_list_delete_link (sec->keys, list); } - g_hash_table_remove (item->main_hash, full); + g_hash_table_remove (item->main_hash, key); } } else { if (value != NULL) { @@ -553,7 +661,7 @@ replace_percentsign(int argc, char **argv, const char *ps, /* the appargv, will get modified but not freed, the replacekdefiles tells us to replace the %f %u and %F for kde files with nothing */ static int -ditem_execute(GnomeDesktopItem *item, int appargc, const char *appargv[], int argc, const char *argv[], gboolean replacekdefiles) +ditem_execute(const GnomeDesktopItem *item, int appargc, const char *appargv[], int argc, const char *argv[], gboolean replacekdefiles) { /*FIXME: */ #if 0 @@ -675,7 +783,7 @@ strip_the_amp (char *exec) * entry. */ int -gnome_desktop_item_launch (GnomeDesktopItem *item, +gnome_desktop_item_launch (const GnomeDesktopItem *item, int argc, const char **argv, GError **error) @@ -938,7 +1046,7 @@ ditem_exec_multiple_files (GnomeDesktopItem *item, const char *exec, /*FIXME: perhaps we should be able to handle mixed url/file lists better rather then treating it as a list of urls */ int -gnome_desktop_item_drop_uri_list (GnomeDesktopItem *item, +gnome_desktop_item_drop_uri_list (const GnomeDesktopItem *item, GList *uri_list, GError **error) { @@ -1009,7 +1117,7 @@ gnome_desktop_item_drop_uri_list (GnomeDesktopItem *item, * Returns: A boolean, %TRUE if it exists, %FALSE otherwise. */ gboolean -gnome_desktop_item_exists (GnomeDesktopItem *item) +gnome_desktop_item_exists (const GnomeDesktopItem *item) { const char *try_exec; const char *exec; @@ -1072,7 +1180,7 @@ gnome_desktop_item_exists (GnomeDesktopItem *item) } /** - * gnome_desktop_item_get_type: + * gnome_desktop_item_get_entry_type: * @item: A desktop item * * Gets the type attribute (the 'Type' field) of the item. This should @@ -1085,7 +1193,7 @@ gnome_desktop_item_exists (GnomeDesktopItem *item) * memory remains owned by the GnomeDesktopItem and should not be freed. */ GnomeDesktopItemType -gnome_desktop_item_get_type (GnomeDesktopItem *item) +gnome_desktop_item_get_entry_type (const GnomeDesktopItem *item) { g_return_val_if_fail (item != NULL, 0); g_return_val_if_fail (item->refcount > 0, 0); @@ -1094,16 +1202,14 @@ gnome_desktop_item_get_type (GnomeDesktopItem *item) } void -gnome_desktop_item_set_type (GnomeDesktopItem *item, - GnomeDesktopItemType type) +gnome_desktop_item_set_entry_type (GnomeDesktopItem *item, + GnomeDesktopItemType type) { g_return_if_fail (item != NULL); g_return_if_fail (item->refcount > 0); item->type = type; - gnome_desktop_item_push_section (item, NULL); - switch (type) { case GNOME_DESKTOP_ITEM_TYPE_NULL: set (item, GNOME_DESKTOP_ITEM_TYPE, NULL); @@ -1132,8 +1238,6 @@ gnome_desktop_item_set_type (GnomeDesktopItem *item, default: break; } - - gnome_desktop_item_pop_section (item); } @@ -1148,7 +1252,7 @@ gnome_desktop_item_set_type (GnomeDesktopItem *item, * Returns: An enum value that specifies whether the item has changed since being loaded. */ GnomeDesktopItemStatus -gnome_desktop_item_get_file_status (GnomeDesktopItem *item) +gnome_desktop_item_get_file_status (const GnomeDesktopItem *item) { struct stat sbuf; GnomeDesktopItemStatus retval; @@ -1169,6 +1273,47 @@ gnome_desktop_item_get_file_status (GnomeDesktopItem *item) } /** + * gnome_desktop_item_get_icon: + * @item: A desktop item + * + * Description: This function goes and looks for the icon file. If the icon + * is not set as an absolute filename, this will look for it in the standard places. + * If it can't find the icon, it will return %NULL + * + * Returns: A newly allocated string + */ +char * +gnome_desktop_item_get_icon (const GnomeDesktopItem *item) +{ + const char *icon; + + g_return_val_if_fail (item != NULL, NULL); + g_return_val_if_fail (item->refcount > 0, NULL); + + icon = gnome_desktop_item_get_string (item, GNOME_DESKTOP_ITEM_ICON); + + if (icon == NULL) { + return NULL; + } else if (icon[0] == G_DIR_SEPARATOR) { + if (g_file_test (icon, G_FILE_TEST_EXISTS)) { + return g_strdup (icon); + } else { + return NULL; + } + } else { + char *full = gnome_program_locate_file (NULL, + GNOME_FILE_DOMAIN_PIXMAP, + icon, + TRUE /* only_if_exists */, + NULL /* ret_locations */); + + /* FIXME: Maybe check elsewhere, this could be from KDE + * or some such */ + return full; + } +} + +/** * gnome_desktop_item_get_location: * @item: A desktop item * @@ -1176,8 +1321,11 @@ gnome_desktop_item_get_file_status (GnomeDesktopItem *item) * */ char * -gnome_desktop_item_get_location (GnomeDesktopItem *item) +gnome_desktop_item_get_location (const GnomeDesktopItem *item) { + g_return_val_if_fail (item != NULL, NULL); + g_return_val_if_fail (item->refcount > 0, NULL); + return g_strdup (item->location); } @@ -1187,87 +1335,46 @@ gnome_desktop_item_get_location (GnomeDesktopItem *item) * @location: A string specifying the file location of this particular item. * * Set's the 'location' of this item. It should be a full path to the item. + * If it is a relative path, the current * * Returns: */ void gnome_desktop_item_set_location (GnomeDesktopItem *item, const char *location) { - g_free(item->location); - item->location = g_strdup(location); -} - -static Section * -find_section (GnomeDesktopItem *item, const char *section) -{ - GList *li; - Section *sec; - - if (section == NULL) - return NULL; - if (strcmp (section, "Desktop Entry") == 0) - return NULL; + g_return_if_fail (item != NULL); + g_return_if_fail (item->refcount > 0); - for (li = item->sections; li != NULL; li = li->next) { - sec = li->data; - if (strcmp (sec->name, section) == 0) - return sec; + g_free (item->location); + if (location == NULL) { + item->location = NULL; + } else if (location[0] == G_DIR_SEPARATOR) { + item->location = g_strdup (location); + } else { + char *curdir = g_get_current_dir (); + item->location = g_build_filename (curdir, location, NULL); + g_free (curdir); } - sec = g_new0 (Section, 1); - sec->name = g_strdup (section); - sec->keys = NULL; - - item->sections = g_list_append (item->sections, sec); - - /* Don't mark the item modified, this is just an empty section, - * it won't be saved even */ + /* This is ugly, but useful internally */ + if (item->mtime != DONT_UPDATE_MTIME) { + struct stat sbuf; + item->mtime = 0; - return sec; + if (item->location == NULL || + stat (item->location, &sbuf) != 0) { + item->mtime = sbuf.st_mtime; + } + + } } /* * Reading/Writing different sections, NULL is the standard section */ -void -gnome_desktop_item_push_section (GnomeDesktopItem *item, - const char *section) -{ - Section *sec; - - g_return_if_fail (item != NULL); - g_return_if_fail (item->refcount > 0); - - /* we're pushing NULL onto an empty stack, this - * can be a no op, and it's the common case too */ - if (section == NULL && - item->section_stack == NULL) - return; - - sec = find_section (item, section); - item->section_stack = g_list_prepend (item->section_stack, sec); -} - -void -gnome_desktop_item_pop_section (GnomeDesktopItem *item) -{ - GList *list; - - g_return_if_fail (item != NULL); - g_return_if_fail (item->refcount > 0); - - /* We probably pushed a NULL onto empty stack */ - if (item->section_stack == NULL) - return; - - list = item->section_stack; - - item->section_stack = g_list_remove_link (item->section_stack, list); - g_list_free_1 (list); -} gboolean -gnome_desktop_item_attr_exists (GnomeDesktopItem *item, +gnome_desktop_item_attr_exists (const GnomeDesktopItem *item, const char *attr) { g_return_val_if_fail (item != NULL, FALSE); @@ -1281,7 +1388,7 @@ gnome_desktop_item_attr_exists (GnomeDesktopItem *item, * String type */ const char * -gnome_desktop_item_get_string (GnomeDesktopItem *item, +gnome_desktop_item_get_string (const GnomeDesktopItem *item, const char *attr) { g_return_val_if_fail (item != NULL, NULL); @@ -1310,7 +1417,7 @@ gnome_desktop_item_set_string (GnomeDesktopItem *item, * LocaleString type */ const char * -gnome_desktop_item_get_localestring (GnomeDesktopItem *item, +gnome_desktop_item_get_localestring (const GnomeDesktopItem *item, const char *attr) { g_return_val_if_fail (item != NULL, NULL); @@ -1321,7 +1428,7 @@ gnome_desktop_item_get_localestring (GnomeDesktopItem *item, } const char * -gnome_desktop_item_get_localestring_lang (GnomeDesktopItem *item, +gnome_desktop_item_get_localestring_lang (const GnomeDesktopItem *item, const char *attr, const char *language) { @@ -1333,7 +1440,7 @@ gnome_desktop_item_get_localestring_lang (GnomeDesktopItem *item, } GList * -gnome_desktop_item_get_languages (GnomeDesktopItem *item, +gnome_desktop_item_get_languages (const GnomeDesktopItem *item, const char *attr) { GList *li; @@ -1341,11 +1448,11 @@ gnome_desktop_item_get_languages (GnomeDesktopItem *item, g_return_val_if_fail (item != NULL, NULL); g_return_val_if_fail (item->refcount > 0, NULL); - g_return_val_if_fail (attr != NULL, NULL); for (li = item->languages; li != NULL; li = li->next) { char *language = li->data; - if (lookup_locale (item, attr, language) != NULL) { + if (attr == NULL || + lookup_locale (item, attr, language) != NULL) { list = g_list_prepend (list, language); } } @@ -1353,25 +1460,68 @@ gnome_desktop_item_get_languages (GnomeDesktopItem *item, return g_list_reverse (list); } +const char * +get_language (void) +{ + const GList *list = gnome_i18n_get_language_list ("LC_MESSAGES"); + while (list != NULL) { + const char *lang = list->data; + /* find first without encoding */ + if (strchr (lang, '.') == NULL) + return lang; + } + return NULL; +} + void gnome_desktop_item_set_localestring (GnomeDesktopItem *item, const char *attr, - const char *language, const char *value) { g_return_if_fail (item != NULL); g_return_if_fail (item->refcount > 0); g_return_if_fail (attr != NULL); + set_locale (item, attr, get_language (), value); +} + +void +gnome_desktop_item_set_localestring_lang (GnomeDesktopItem *item, + const char *attr, + const char *language, + const char *value) +{ + g_return_if_fail (item != NULL); + g_return_if_fail (item->refcount > 0); + g_return_if_fail (attr != NULL); + set_locale (item, attr, language, value); } +void +gnome_desktop_item_clear_localestring (GnomeDesktopItem *item, + const char *attr) +{ + GList *li; + GList *list = NULL; + + g_return_if_fail (item != NULL); + g_return_if_fail (item->refcount > 0); + g_return_if_fail (attr != NULL); + + for (li = item->languages; li != NULL; li = li->next) { + char *language = li->data; + set_locale (item, attr, language, NULL); + } + set (item, attr, NULL); +} + /* * Strings, Regexps types */ char ** -gnome_desktop_item_get_strings (GnomeDesktopItem *item, +gnome_desktop_item_get_strings (const GnomeDesktopItem *item, const char *attr) { const char *value; @@ -1411,7 +1561,7 @@ gnome_desktop_item_set_strings (GnomeDesktopItem *item, * Boolean type */ gboolean -gnome_desktop_item_get_boolean (GnomeDesktopItem *item, +gnome_desktop_item_get_boolean (const GnomeDesktopItem *item, const char *attr) { const char *value; @@ -2010,6 +2160,79 @@ setup_type (GnomeDesktopItem *item, const char *filename) } } +/* fallback to find something suitable for C locale */ +static char * +try_english_key (GnomeDesktopItem *item, const char *key) +{ + char *str; + char *locales[] = { "en_US", "en_GB", "en_AU", "en", NULL }; + int i; + + str = NULL; + for (i = 0; locales[i] != NULL && str == NULL; i++) { + str = g_strdup (lookup_locale (item, key, locales[i])); + } + if (str != NULL) { + /* We need a 7-bit ascii string, so whack all + * above 127 chars */ + guchar *p; + for (p = (guchar *)str; *p != '\0'; p++) { + if (*p > 127) + *p = '?'; + } + } + return str; +} + + +static void +sanitize (GnomeDesktopItem *item, const char *file) +{ + const char *type; + + type = lookup (item, GNOME_DESKTOP_ITEM_TYPE); + + /* understand old gnome style url exec thingies */ + if (type != NULL && strcmp (type, "URL") == 0) { + const char *exec = lookup (item, GNOME_DESKTOP_ITEM_EXEC); + set (item, GNOME_DESKTOP_ITEM_TYPE, "Link"); + if (exec != NULL) { + /* Note, this must be in this order */ + set (item, GNOME_DESKTOP_ITEM_URL, exec); + set (item, GNOME_DESKTOP_ITEM_EXEC, NULL); + } + } + + /* we make sure we have Name, Encoding and Version */ + if (lookup (item, GNOME_DESKTOP_ITEM_NAME) == NULL) { + char *name = try_english_key (item, GNOME_DESKTOP_ITEM_NAME); + /* If no name, use the basename */ + if (name == NULL) + name = g_path_get_basename (file); + g_hash_table_replace (item->main_hash, + g_strdup (GNOME_DESKTOP_ITEM_NAME), + g_path_get_basename (file)); + item->keys = g_list_prepend + (item->keys, g_strdup (GNOME_DESKTOP_ITEM_NAME)); + } + if (lookup (item, GNOME_DESKTOP_ITEM_ENCODING) == NULL) { + /* We store everything in UTF-8 so write that down */ + g_hash_table_replace (item->main_hash, + g_strdup (GNOME_DESKTOP_ITEM_ENCODING), + g_strdup ("UTF-8")); + item->keys = g_list_prepend + (item->keys, g_strdup (GNOME_DESKTOP_ITEM_ENCODING)); + } + if (lookup (item, GNOME_DESKTOP_ITEM_VERSION) == NULL) { + /* this is the version that we follow, so write it down */ + g_hash_table_replace (item->main_hash, + g_strdup (GNOME_DESKTOP_ITEM_VERSION), + g_strdup ("1.0")); + item->keys = g_list_prepend + (item->keys, g_strdup (GNOME_DESKTOP_ITEM_VERSION)); + } +} + enum { FirstBrace, OnSecHeader, @@ -2036,7 +2259,11 @@ ditem_load (const char *file, gboolean old_kde = FALSE; if ((f = fopen (file, "r")) == NULL) { - /* FIXME: use GError */ + g_set_error (error, + G_FILE_ERROR, + g_file_error_from_errno (errno), + _("Error reading file '%s': %s"), + file, strerror (errno)); return NULL; } @@ -2044,7 +2271,11 @@ ditem_load (const char *file, if (encoding == ENCODING_UNKNOWN) { fclose (f); /* spec says, don't read this file */ - /* FIXME: use GError */ + g_set_error (error, + GNOME_DESKTOP_ITEM_ERROR, + GNOME_DESKTOP_ITEM_ERROR_UNKNOWN_ENCODING, + _("Unknown encoding of: %s"), + file); return NULL; } @@ -2204,38 +2435,11 @@ ditem_load (const char *file, /* Here we do a little bit of sanitazition */ - /* First make sure that we set up the type */ - setup_type (item, file); + /* sanitize some things */ + sanitize (item, file); - /* Then we make sure we have Name, Encoding and Version */ - if (g_hash_table_lookup (item->main_hash, - GNOME_DESKTOP_ITEM_NAME) == NULL) { - /* FIXME: try the en, en_US, ... whatever name first */ - /* If no name, use the basename */ - g_hash_table_replace (item->main_hash, - g_strdup (GNOME_DESKTOP_ITEM_NAME), - g_path_get_basename (file)); - item->keys = g_list_prepend - (item->keys, g_strdup (GNOME_DESKTOP_ITEM_NAME)); - } - if (g_hash_table_lookup (item->main_hash, - GNOME_DESKTOP_ITEM_ENCODING) == NULL) { - /* We store everything in UTF-8 so write that down */ - g_hash_table_replace (item->main_hash, - g_strdup (GNOME_DESKTOP_ITEM_ENCODING), - g_strdup ("UTF-8")); - item->keys = g_list_prepend - (item->keys, g_strdup (GNOME_DESKTOP_ITEM_ENCODING)); - } - if (g_hash_table_lookup (item->main_hash, - GNOME_DESKTOP_ITEM_VERSION) == NULL) { - /* this is the version that we follow, so write it down */ - g_hash_table_replace (item->main_hash, - g_strdup (GNOME_DESKTOP_ITEM_VERSION), - g_strdup ("1.0")); - item->keys = g_list_prepend - (item->keys, g_strdup (GNOME_DESKTOP_ITEM_VERSION)); - } + /* make sure that we set up the type */ + setup_type (item, file); return item; } @@ -2267,7 +2471,11 @@ ditem_save (GnomeDesktopItem *item, const char *file_name, GError **error) fp = fopen (file_name, "w"); if (fp == NULL) { - /* FIXME: use GError */ + g_set_error (error, + G_FILE_ERROR, + g_file_error_from_errno (errno), + _("Error writing file '%s': %s"), + file_name, strerror (errno)); return FALSE; } @@ -2302,3 +2510,39 @@ ditem_save (GnomeDesktopItem *item, const char *file_name, GError **error) return TRUE; } + +static gpointer +_gnome_desktop_item_copy (gpointer boxed) +{ + return gnome_desktop_item_copy (boxed); +} + +static void +_gnome_desktop_item_free (gpointer boxed) +{ + gnome_desktop_item_unref (boxed); +} + +GType +gnome_desktop_item_get_type (void) +{ + static GType type = 0; + + if (type == 0) { + type = g_boxed_type_register_static ("GnomeDesktopItem", + _gnome_desktop_item_copy, + _gnome_desktop_item_free); + } + + return type; +} + +GQuark +gnome_desktop_item_error_quark (void) +{ + static GQuark q = 0; + if (q == 0) + q = g_quark_from_static_string ("g-file-error-quark"); + + return q; +} diff --git a/libgnome-desktop/gnome-desktop-item.h b/libgnome-desktop/gnome-desktop-item.h index 67c4fda0..635c8ea8 100644 --- a/libgnome-desktop/gnome-desktop-item.h +++ b/libgnome-desktop/gnome-desktop-item.h @@ -2,6 +2,7 @@ /* gnome-ditem.h - GNOME Desktop File Representation Copyright (C) 1999, 2000 Red Hat Inc. + Copyright (C) 2001 Sid Vicious All rights reserved. This file is part of the Gnome Library. @@ -54,6 +55,9 @@ typedef enum { GNOME_DESKTOP_ITEM_DISAPPEARED = 2 } GnomeDesktopItemStatus; +#define GNOME_TYPE_DESKTOP_ITEM (gnome_desktop_item_get_type ()) +GType gnome_desktop_item_get_type (void); + typedef struct _GnomeDesktopItem GnomeDesktopItem; #define GNOME_DESKTOP_ITEM_ENCODING "Encoding" /* string */ @@ -90,12 +94,22 @@ typedef enum { GNOME_DESKTOP_ITEM_LOAD_ONLY_IF_EXISTS = 1<<0 } GnomeDesktopItemLoadFlags; +typedef enum { + GNOME_DESKTOP_ITEM_ERROR_NO_FILENAME /* No filename set or given on save */, + GNOME_DESKTOP_ITEM_ERROR_UNKNOWN_ENCODING /* Unknown encoding of the file */, +} GnomeDesktopItemError; + +/* Note that functions can also return the G_FILE_ERROR_* errors */ + +#define GNOME_DESKTOP_ITEM_ERROR gnome_desktop_item_error_quark () +GQuark gnome_desktop_item_error_quark (void); + /* Returned item from new*() and copy() methods have a refcount of 1 */ GnomeDesktopItem * gnome_desktop_item_new (void); GnomeDesktopItem * gnome_desktop_item_new_from_file (const char *file, GnomeDesktopItemLoadFlags flags, GError **error); -GnomeDesktopItem * gnome_desktop_item_copy (GnomeDesktopItem *item); +GnomeDesktopItem * gnome_desktop_item_copy (const GnomeDesktopItem *item); /* if under is NULL save in original location */ gboolean gnome_desktop_item_save (GnomeDesktopItem *item, @@ -104,7 +118,7 @@ gboolean gnome_desktop_item_save (GnomeDesktopItem GError **error); GnomeDesktopItem * gnome_desktop_item_ref (GnomeDesktopItem *item); void gnome_desktop_item_unref (GnomeDesktopItem *item); -int gnome_desktop_item_launch (GnomeDesktopItem *item, +int gnome_desktop_item_launch (const GnomeDesktopItem *item, int argc, const char **argv, GError **error); @@ -112,40 +126,40 @@ int gnome_desktop_item_launch (GnomeDesktopItem /* A list of files or urls dropped onto an icon, the proper (Url or File exec is run you can pass directly the output of gnome_uri_list_extract_filenames) */ -int gnome_desktop_item_drop_uri_list (GnomeDesktopItem *item, +int gnome_desktop_item_drop_uri_list (const GnomeDesktopItem *item, GList *uri_list, GError **error); -gboolean gnome_desktop_item_exists (GnomeDesktopItem *item); +gboolean gnome_desktop_item_exists (const GnomeDesktopItem *item); -GnomeDesktopItemType gnome_desktop_item_get_type (GnomeDesktopItem *item); +GnomeDesktopItemType gnome_desktop_item_get_entry_type (const GnomeDesktopItem *item); /* You could also just use the set_string on the TYPE argument */ -void gnome_desktop_item_set_type (GnomeDesktopItem *item, +void gnome_desktop_item_set_entry_type (GnomeDesktopItem *item, GnomeDesktopItemType type); /* Get current location on disk */ -char * gnome_desktop_item_get_location (GnomeDesktopItem *item); +char * gnome_desktop_item_get_location (const GnomeDesktopItem *item); void gnome_desktop_item_set_location (GnomeDesktopItem *item, const char *location); -GnomeDesktopItemStatus gnome_desktop_item_get_file_status (GnomeDesktopItem *item); +GnomeDesktopItemStatus gnome_desktop_item_get_file_status (const GnomeDesktopItem *item); +/* + * Get the icon, this is not as simple as getting the Icon attr as it actually tries to find + * it and returns %NULL if it can't + */ +char * gnome_desktop_item_get_icon (const GnomeDesktopItem *item); /* * Reading/Writing different sections, NULL is the standard section */ -void gnome_desktop_item_push_section (GnomeDesktopItem *item, - const char *section); -void gnome_desktop_item_pop_section (GnomeDesktopItem *item); - - -gboolean gnome_desktop_item_attr_exists (GnomeDesktopItem *item, +gboolean gnome_desktop_item_attr_exists (const GnomeDesktopItem *item, const char *attr); /* * String type */ -const char * gnome_desktop_item_get_string (GnomeDesktopItem *item, +const char * gnome_desktop_item_get_string (const GnomeDesktopItem *item, const char *attr); void gnome_desktop_item_set_string (GnomeDesktopItem *item, @@ -155,26 +169,31 @@ void gnome_desktop_item_set_string (GnomeDesktopItem /* * LocaleString type */ -const char * gnome_desktop_item_get_localestring (GnomeDesktopItem *item, +const char * gnome_desktop_item_get_localestring (const GnomeDesktopItem *item, const char *attr); -const char * gnome_desktop_item_get_localestring_lang (GnomeDesktopItem *item, +const char * gnome_desktop_item_get_localestring_lang (const GnomeDesktopItem *item, const char *attr, const char *language); /* use g_list_free only */ -GList * gnome_desktop_item_get_languages (GnomeDesktopItem *item, +GList * gnome_desktop_item_get_languages (const GnomeDesktopItem *item, const char *attr); void gnome_desktop_item_set_localestring (GnomeDesktopItem *item, const char *attr, - const char *language, const char *value); +void gnome_desktop_item_set_localestring_lang (GnomeDesktopItem *item, + const char *attr, + const char *language, + const char *value); +void gnome_desktop_item_clear_localestring(GnomeDesktopItem *item, + const char *attr); /* * Strings, Regexps types */ /* use gnome_desktop_item_free_string_list */ -char ** gnome_desktop_item_get_strings (GnomeDesktopItem *item, +char ** gnome_desktop_item_get_strings (const GnomeDesktopItem *item, const char *attr); void gnome_desktop_item_set_strings (GnomeDesktopItem *item, @@ -184,7 +203,7 @@ void gnome_desktop_item_set_strings (GnomeDesktopItem *item, /* * Boolean type */ -gboolean gnome_desktop_item_get_boolean (GnomeDesktopItem *item, +gboolean gnome_desktop_item_get_boolean (const GnomeDesktopItem *item, const char *attr); void gnome_desktop_item_set_boolean (GnomeDesktopItem *item, diff --git a/libgnome-desktop/gnome-ditem-edit.c b/libgnome-desktop/gnome-ditem-edit.c index 3dd82c20..6c8f4bc8 100644 --- a/libgnome-desktop/gnome-ditem-edit.c +++ b/libgnome-desktop/gnome-ditem-edit.c @@ -24,26 +24,22 @@ */ #include <config.h> -#include "gnome-macros.h" #include <ctype.h> #include <string.h> -#include "gnome-ditem-edit.h" +#include <gtk/gtk.h> +#include <libgnome/gnome-macros.h> +/* FIXME: this needs to be localized */ #include <libgnome/gnome-i18n.h> -#include "gnome-uidefs.h" -#include "gnome-pixmap.h" -#include "gnome-image-entry.h" -#include "libgnomeuiP.h" +#include <libgnomeui/gnome-uidefs.h> +#include <libgnomeui/gnome-icon-entry.h> -#include <bonobo/bonobo-win.h> +#include "gnome-desktop-item.h" +#include "gnome-ditem-edit.h" struct _GnomeDItemEditPrivate { - GtkWidget *child1; /* basic */ - GtkWidget *child2; /* DND */ - GtkWidget *child3; /* Advanced */ - /* we keep a ditem around, since we can never have absolutely everything in the display so we load a file, or get a ditem, sync the display and ref the ditem */ @@ -56,15 +52,6 @@ struct _GnomeDItemEditPrivate { GtkWidget *exec_entry; GtkWidget *tryexec_entry; GtkWidget *doc_entry; - GtkWidget *wmtitles_entry; - - GtkWidget *simple_dnd_toggle; - - GtkWidget *file_drop_entry; - GtkWidget *single_file_drop_toggle; - - GtkWidget *url_drop_entry; - GtkWidget *single_url_drop_toggle; GtkWidget *type_combo; @@ -76,14 +63,10 @@ struct _GnomeDItemEditPrivate { GtkWidget *transl_lang_entry; GtkWidget *transl_name_entry; GtkWidget *transl_comment_entry; - - /* we store this so we can set sensitive the - drag and drop stuff, no point in an accessor */ - GtkWidget *dndtable; }; static void gnome_ditem_edit_class_init (GnomeDItemEditClass *klass); -static void gnome_ditem_edit_init (GnomeDItemEdit *messagebox); +static void gnome_ditem_edit_instance_init(GnomeDItemEdit *dee); static void gnome_ditem_edit_destroy (GtkObject *object); static void gnome_ditem_edit_finalize (GObject *object); @@ -106,7 +89,8 @@ static gint ditem_edit_signals[LAST_SIGNAL] = { 0 }; /* The following defines the get_type */ GNOME_CLASS_BOILERPLATE (GnomeDItemEdit, gnome_ditem_edit, - GtkNotebook, gtk_notebook) + GtkNotebook, gtk_notebook, + GTK_TYPE_NOTEBOOK) static void gnome_ditem_edit_class_init (GnomeDItemEditClass *klass) @@ -151,6 +135,38 @@ gnome_ditem_edit_class_init (GnomeDItemEditClass *klass) ditem_edit_class->changed = NULL; } +enum { + ALL_TYPES, + ONLY_DIRECTORY, + ALL_EXCEPT_DIRECTORY +}; + +static void +setup_combo (GnomeDItemEdit *dee, int type, const char *extra) +{ + GList *types = NULL; + + if (type == ONLY_DIRECTORY) { + types = g_list_prepend (types, "Directory"); + } else { + types = g_list_prepend (types, "Application"); + types = g_list_prepend (types, "Link"); + types = g_list_prepend (types, "FSDevice"); + types = g_list_prepend (types, "MimeType"); + if (type != ALL_EXCEPT_DIRECTORY) + types = g_list_prepend (types, "Directory"); + types = g_list_prepend (types, "Service"); + types = g_list_prepend (types, "ServiceType"); + } + if (extra != NULL) + types = g_list_prepend (types, (char *)extra); + + gtk_combo_set_popdown_strings + (GTK_COMBO (dee->_priv->type_combo), types); + + g_list_free (types); +} + static void table_attach_entry(GtkTable * table, GtkWidget * w, gint l, gint r, gint t, gint b) @@ -182,7 +198,7 @@ table_attach_list(GtkTable * table, GtkWidget * w, } static GtkWidget * -label_new (char *text) +label_new (const char *text) { GtkWidget *label; @@ -195,7 +211,6 @@ static void fill_easy_page(GnomeDItemEdit * dee, GtkWidget * table) { GtkWidget *label; - GList *types = NULL; GtkWidget *hbox; GtkWidget *align; @@ -235,12 +250,8 @@ fill_easy_page(GnomeDItemEdit * dee, GtkWidget * table) label = label_new(_("Type:")); table_attach_label(GTK_TABLE(table), label, 0, 1, 3, 4); - types = g_list_prepend (types, "Directory"); - types = g_list_prepend (types, "URL"); - types = g_list_prepend (types, "Application"); dee->_priv->type_combo = gtk_combo_new(); - gtk_combo_set_popdown_strings(GTK_COMBO(dee->_priv->type_combo), types); - g_list_free(types); + setup_combo (dee, ALL_TYPES, NULL); gtk_combo_set_value_in_list(GTK_COMBO(dee->_priv->type_combo), FALSE, TRUE); table_attach_entry(GTK_TABLE(table),dee->_priv->type_combo, 1, 2, 3, 4); @@ -259,137 +270,26 @@ fill_easy_page(GnomeDItemEdit * dee, GtkWidget * table) 0, 0, 0); - dee->_priv->icon_entry = gnome_image_entry_new_icon_entry (); - /* FIXME: !!! */ - /* - gtk_signal_connect_object_while_alive(GTK_OBJECT(dee->_priv->icon_entry),"changed", - GTK_SIGNAL_FUNC(gnome_ditem_edit_changed), - GTK_OBJECT(dee)); - gtk_signal_connect_object_while_alive(GTK_OBJECT(dee->_priv->icon_entry),"changed", - GTK_SIGNAL_FUNC(gnome_ditem_edit_icon_changed), - GTK_OBJECT(dee)); - */ - gtk_box_pack_start(GTK_BOX(hbox), dee->_priv->icon_entry, FALSE, FALSE, 0); + dee->_priv->icon_entry = gnome_icon_entry_new ("desktop-icon", _("Browse icons")); + gtk_signal_connect_object (GTK_OBJECT (dee->_priv->icon_entry), "changed", + GTK_SIGNAL_FUNC (gnome_ditem_edit_changed), + GTK_OBJECT (dee)); + gtk_signal_connect_object (GTK_OBJECT (dee->_priv->icon_entry), "changed", + GTK_SIGNAL_FUNC (gnome_ditem_edit_icon_changed), + GTK_OBJECT (dee)); + gtk_box_pack_start (GTK_BOX (hbox), dee->_priv->icon_entry, + FALSE, FALSE, 0); - align = gtk_alignment_new(0.0, 0.5, 0.0, 0.0); - gtk_box_pack_start(GTK_BOX(hbox), align, FALSE, FALSE, 0); + align = gtk_alignment_new (0.0, 0.5, 0.0, 0.0); + gtk_box_pack_start (GTK_BOX (hbox), align, FALSE, FALSE, 0); dee->_priv->terminal_button = gtk_check_button_new_with_label (_("Run in Terminal")); - gtk_signal_connect_object(GTK_OBJECT(dee->_priv->terminal_button), - "clicked", - GTK_SIGNAL_FUNC(gnome_ditem_edit_changed), - GTK_OBJECT(dee)); - gtk_container_add(GTK_CONTAINER(align), dee->_priv->terminal_button); -} - -static void -simple_drag_and_drop_toggled(GtkToggleButton *tb, GnomeDItemEdit *dee) -{ - if(tb->active) { - gtk_widget_set_sensitive(dee->_priv->dndtable,FALSE); - } else { - gtk_widget_set_sensitive(dee->_priv->dndtable,TRUE); - } - gnome_ditem_edit_changed(dee); -} - -static void -fill_dnd_page(GnomeDItemEdit * dee, GtkWidget * bigtable) -{ - GtkWidget *label; - GtkWidget *table; - - dee->_priv->simple_dnd_toggle = - gtk_check_button_new_with_label (_("Simple drag and drop")); - gtk_signal_connect(GTK_OBJECT(dee->_priv->simple_dnd_toggle), - "toggled", - GTK_SIGNAL_FUNC(simple_drag_and_drop_toggled), - dee); - gtk_table_attach(GTK_TABLE(bigtable), dee->_priv->simple_dnd_toggle, - 0, 2, 0, 1, - GTK_EXPAND | GTK_FILL, - 0, - 0, 0); - - table = dee->_priv->dndtable = gtk_table_new (5, 2, FALSE); - gtk_container_set_border_width (GTK_CONTAINER (table), GNOME_PAD_SMALL); - gtk_table_set_row_spacings (GTK_TABLE (table), GNOME_PAD_SMALL); - gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD_SMALL); - - gtk_table_attach(GTK_TABLE(bigtable), table, - 0, 2, 1, 2, - GTK_EXPAND | GTK_FILL, - GTK_EXPAND | GTK_FILL, - 0, 0); - - label = label_new(_("In the following commands you should use %s in " - "the spot where the\nfilename/URL should be " - "substituted. If you leave the field blank\n" - "drops will not be accepted. If this application " - "can accept\nmultiple files or URLs as arguments " - "after its command name check the box above.")); - gtk_table_attach(GTK_TABLE(table), label, - 0, 2, 1, 2, - 0, - 0, - 0, 0); - - label = label_new(_("Command for file drops:")); - table_attach_label(GTK_TABLE(table),label, 0, 1, 2, 3); - - dee->_priv->file_drop_entry = gtk_entry_new(); - table_attach_entry(GTK_TABLE(table),dee->_priv->file_drop_entry, 1, 2, 2, 3); - gtk_signal_connect_object_while_alive(GTK_OBJECT(dee->_priv->file_drop_entry), "changed", - GTK_SIGNAL_FUNC(gnome_ditem_edit_changed), - GTK_OBJECT(dee)); - - dee->_priv->single_file_drop_toggle = - gtk_check_button_new_with_label (_("Drop one file at a time " - "only.")); - gtk_signal_connect_object(GTK_OBJECT(dee->_priv->single_file_drop_toggle), - "clicked", - GTK_SIGNAL_FUNC(gnome_ditem_edit_changed), - GTK_OBJECT(dee)); - gtk_table_attach(GTK_TABLE(table), dee->_priv->single_file_drop_toggle, - 1, 2, 3, 4, - GTK_EXPAND | GTK_FILL, - 0, - 0, 0); - - label = label_new(_("Command for URL drops:")); - table_attach_label(GTK_TABLE(table),label, 0, 1, 4, 5); - - dee->_priv->url_drop_entry = gtk_entry_new(); - table_attach_entry(GTK_TABLE(table),dee->_priv->url_drop_entry, 1, 2, 4, 5); - gtk_signal_connect_object_while_alive(GTK_OBJECT(dee->_priv->url_drop_entry), "changed", - GTK_SIGNAL_FUNC(gnome_ditem_edit_changed), - GTK_OBJECT(dee)); - - dee->_priv->single_url_drop_toggle = - gtk_check_button_new_with_label (_("Drop one URL at a time " - "only.")); - gtk_signal_connect_object(GTK_OBJECT(dee->_priv->single_url_drop_toggle), - "clicked", - GTK_SIGNAL_FUNC(gnome_ditem_edit_changed), - GTK_OBJECT(dee)); - gtk_table_attach(GTK_TABLE(table), dee->_priv->single_url_drop_toggle, - 1, 2, 5, 6, - GTK_EXPAND | GTK_FILL, - 0, - 0, 0); -} - -static void -set_list_width(GtkWidget *clist, const char * const text[]) -{ - int i; - int cols = GTK_CLIST(clist)->columns; - GtkCList *cl = GTK_CLIST(clist); - for(i=0;i<cols;i++) { - int w = gdk_string_width(clist->style->font,text[i]); - if(cl->column[i].width < w) - gtk_clist_set_column_width(cl,i,w); - } + gtk_signal_connect_object (GTK_OBJECT (dee->_priv->terminal_button), + "clicked", + GTK_SIGNAL_FUNC (gnome_ditem_edit_changed), + GTK_OBJECT (dee)); + gtk_container_add (GTK_CONTAINER (align), + dee->_priv->terminal_button); } static void @@ -447,7 +347,6 @@ translations_add(GtkWidget *button, GnomeDItemEdit *dee) text[0] = s; text[1] = name; text[2] = comment; - set_list_width (GTK_WIDGET(cl), text); gtk_signal_emit (GTK_OBJECT(dee), ditem_edit_signals[CHANGED], NULL); return; @@ -456,7 +355,6 @@ translations_add(GtkWidget *button, GnomeDItemEdit *dee) text[0]=lang; text[1]=name; text[2]=comment; - set_list_width(GTK_WIDGET(cl),text); gtk_clist_append(cl,(char**)text); gtk_signal_emit(GTK_OBJECT(dee), ditem_edit_signals[CHANGED], NULL); } @@ -499,24 +397,19 @@ fill_advanced_page(GnomeDItemEdit * dee, GtkWidget * page) GTK_SIGNAL_FUNC(gnome_ditem_edit_changed), GTK_OBJECT(dee)); - label = label_new(_("Window titles to wait for (comma separated):")); - table_attach_label(GTK_TABLE(page),label, 0, 2, 2, 3); - - dee->_priv->wmtitles_entry = gtk_entry_new_with_max_length(255); - table_attach_entry(GTK_TABLE(page),dee->_priv->wmtitles_entry, 0, 2, 3, 4); - gtk_signal_connect_object(GTK_OBJECT(dee->_priv->wmtitles_entry), - "changed", - GTK_SIGNAL_FUNC(gnome_ditem_edit_changed), - GTK_OBJECT(dee)); - label = gtk_label_new(_("Name/Comment translations:")); - table_attach_label(GTK_TABLE(page),label, 0, 2, 4, 5); + table_attach_label(GTK_TABLE(page),label, 0, 2, 2, 3); transl[0] = _("Language"); transl[1] = _("Name"); transl[2] = _("Comment"); dee->_priv->translations = gtk_clist_new_with_titles(3,(char**)transl); - set_list_width(dee->_priv->translations,transl); + gtk_clist_set_column_auto_resize (GTK_CLIST (dee->_priv->translations), + 0, TRUE); + gtk_clist_set_column_auto_resize (GTK_CLIST (dee->_priv->translations), + 1, TRUE); + gtk_clist_set_column_auto_resize (GTK_CLIST (dee->_priv->translations), + 2, TRUE); box = gtk_scrolled_window_new(NULL,NULL); gtk_widget_set_usize(box,0,120); gtk_container_add(GTK_CONTAINER(box),dee->_priv->translations); @@ -527,7 +420,7 @@ fill_advanced_page(GnomeDItemEdit * dee, GtkWidget * page) dee); box = gtk_hbox_new(FALSE,GNOME_PAD_SMALL); - table_attach_entry(GTK_TABLE(page),box, 0, 2, 6, 7); + table_attach_entry(GTK_TABLE(page),box, 0, 2, 3, 4); dee->_priv->transl_lang_entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(box),dee->_priv->transl_lang_entry,FALSE,FALSE,0); @@ -540,7 +433,7 @@ fill_advanced_page(GnomeDItemEdit * dee, GtkWidget * page) gtk_box_pack_start(GTK_BOX(box),dee->_priv->transl_comment_entry,TRUE,TRUE,0); box = gtk_hbox_new(FALSE,GNOME_PAD_SMALL); - table_attach_entry(GTK_TABLE(page),box, 0, 2, 7, 8); + table_attach_entry(GTK_TABLE(page),box, 0, 2, 4, 5); button = gtk_button_new_with_label(_("Add/Set")); gtk_box_pack_start(GTK_BOX(box),button,FALSE,FALSE,0); @@ -573,34 +466,28 @@ make_page (void) } static void -gnome_ditem_edit_init (GnomeDItemEdit *dee) +gnome_ditem_edit_instance_init (GnomeDItemEdit *dee) { + GtkWidget *child1, *child2; dee->_priv = g_new0(GnomeDItemEditPrivate, 1); - dee->_priv->child1 = make_page(); - fill_easy_page(dee, GTK_BIN(dee->_priv->child1)->child); - gtk_widget_show_all(dee->_priv->child1); + child1 = make_page(); + fill_easy_page (dee, GTK_BIN (child1)->child); + gtk_widget_show_all (child1); - dee->_priv->child2 = make_page(); - fill_dnd_page(dee, GTK_BIN(dee->_priv->child2)->child); - gtk_widget_show_all(dee->_priv->child2); - - dee->_priv->child3 = make_page(); - fill_advanced_page(dee, GTK_BIN(dee->_priv->child3)->child); - gtk_widget_show_all(dee->_priv->child3); - - gtk_notebook_append_page (GTK_NOTEBOOK (dee), - dee->_priv->child1, - gtk_label_new (_("Basic"))); + child2 = make_page(); + fill_advanced_page (dee, GTK_BIN(child2)->child); + gtk_widget_show_all (child2); gtk_notebook_append_page (GTK_NOTEBOOK (dee), - dee->_priv->child2, - gtk_label_new (_("Drag and Drop"))); + child1, + gtk_label_new (_("Basic"))); gtk_notebook_append_page (GTK_NOTEBOOK (dee), - dee->_priv->child3, - gtk_label_new (_("Advanced"))); + child2, + gtk_label_new (_("Advanced"))); + /* FIXME: There needs to be a way to edit ALL keys/sections */ } @@ -659,146 +546,129 @@ gnome_ditem_edit_finalize (GObject *object) /* set sensitive for directory/other type of a ditem */ static void -gnome_ditem_set_directory_sensitive(GnomeDItemEdit *dee, - gboolean is_directory) +gnome_ditem_set_directory_sensitive (GnomeDItemEdit *dee, + gboolean is_directory) { - gtk_widget_set_sensitive(dee->_priv->exec_entry, !is_directory); - gtk_widget_set_sensitive(dee->_priv->type_combo, !is_directory); - gtk_widget_set_sensitive(dee->_priv->terminal_button, !is_directory); - gtk_widget_set_sensitive(dee->_priv->tryexec_entry, !is_directory); - gtk_widget_set_sensitive(dee->_priv->wmtitles_entry, !is_directory); - gtk_widget_set_sensitive(dee->_priv->simple_dnd_toggle, !is_directory); - gtk_widget_set_sensitive(dee->_priv->dndtable, !is_directory); + gtk_widget_set_sensitive (dee->_priv->exec_entry, ! is_directory); + gtk_widget_set_sensitive (dee->_priv->type_combo, ! is_directory); + gtk_widget_set_sensitive (dee->_priv->terminal_button, ! is_directory); + gtk_widget_set_sensitive (dee->_priv->tryexec_entry, ! is_directory); } /* Conform display to ditem */ static void gnome_ditem_edit_sync_display (GnomeDItemEdit *dee) { - GSList *i18n_list,*li; + GList *i18n_list, *li; + GnomeDesktopItemType type; const gchar* cs; GnomeDesktopItem *ditem; - g_return_if_fail(dee != NULL); - g_return_if_fail(GNOME_IS_DITEM_EDIT(dee)); + g_return_if_fail (dee != NULL); + g_return_if_fail (GNOME_IS_DITEM_EDIT (dee)); ditem = dee->_priv->ditem; - g_assert (ditem != NULL); + if (ditem == NULL) { + gnome_ditem_edit_clear (dee); + return; + } - cs = gnome_desktop_item_get_type(ditem); - if(cs && strcmp(cs,"Directory")==0) { - GList *types = NULL; - gnome_ditem_set_directory_sensitive(dee, TRUE); - types = g_list_prepend(types, "Directory"); - gtk_combo_set_popdown_strings(GTK_COMBO(dee->_priv->type_combo), - types); - g_list_free(types); + type = gnome_desktop_item_get_entry_type (ditem); + if (type == GNOME_DESKTOP_ITEM_TYPE_DIRECTORY) { + gnome_ditem_set_directory_sensitive (dee, TRUE); + setup_combo (dee, ONLY_DIRECTORY, NULL); } else { - GList *types = NULL; - gnome_ditem_set_directory_sensitive(dee, FALSE); - types = g_list_prepend(types, "URL"); - types = g_list_prepend(types, "PanelApplet"); - types = g_list_prepend(types, "Application"); - if(cs && - strcmp(cs,"URL") != 0 && - strcmp(cs,"PanelApplet") != 0 && - strcmp(cs,"Application") != 0) - types = g_list_prepend(types, (char *)cs); - gtk_combo_set_popdown_strings(GTK_COMBO(dee->_priv->type_combo), - types); - g_list_free(types); + const char *extra = NULL; + gnome_ditem_set_directory_sensitive (dee, FALSE); + if (type == GNOME_DESKTOP_ITEM_TYPE_OTHER) { + extra = gnome_desktop_item_get_string + (ditem, GNOME_DESKTOP_ITEM_TYPE); + } + setup_combo (dee, ALL_EXCEPT_DIRECTORY, extra); } - cs = gnome_desktop_item_get_local_name(ditem); + cs = gnome_desktop_item_get_localestring + (ditem, GNOME_DESKTOP_ITEM_NAME); gtk_entry_set_text(GTK_ENTRY(dee->_priv->name_entry), cs ? cs : ""); - cs = gnome_desktop_item_get_local_comment(ditem); + cs = gnome_desktop_item_get_localestring + (ditem, GNOME_DESKTOP_ITEM_COMMENT); gtk_entry_set_text(GTK_ENTRY(dee->_priv->comment_entry), cs ? cs : ""); - cs = gnome_desktop_item_get_command(ditem); + cs = gnome_desktop_item_get_string (ditem, + GNOME_DESKTOP_ITEM_EXEC); gtk_entry_set_text(GTK_ENTRY(dee->_priv->exec_entry), cs ? cs : ""); - cs = gnome_desktop_item_get_attribute(ditem, "TryExec"); + cs = gnome_desktop_item_get_string (ditem, + GNOME_DESKTOP_ITEM_TRY_EXEC); gtk_entry_set_text(GTK_ENTRY(dee->_priv->tryexec_entry), cs ? cs : ""); - cs = gnome_desktop_item_get_icon_path(ditem); - gnome_selector_set_uri(GNOME_SELECTOR(dee->_priv->icon_entry), - NULL, cs, NULL, NULL); + cs = gnome_desktop_item_get_icon (ditem); + gnome_icon_entry_set_filename (GNOME_ICON_ENTRY (dee->_priv->icon_entry), cs); - cs = gnome_desktop_item_get_attribute(ditem, "DocPath"); /* FIXME check name */ - gtk_entry_set_text(GTK_ENTRY(dee->_priv->doc_entry), - cs ? cs : ""); + cs = gnome_desktop_item_get_string (ditem, "DocPath"); /* FIXME check name */ + gtk_entry_set_text (GTK_ENTRY (dee->_priv->doc_entry), cs ? cs : ""); - cs = gnome_desktop_item_get_attribute(ditem, "WMTitles"); - gtk_entry_set_text(GTK_ENTRY(dee->_priv->wmtitles_entry), - cs ? cs : ""); + cs = gnome_desktop_item_get_string (ditem, GNOME_DESKTOP_ITEM_TYPE); + gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (dee->_priv->type_combo)->entry), + cs ? cs : ""); - cs = gnome_desktop_item_get_type(ditem); - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(dee->_priv->type_combo)->entry), - cs ? cs : ""); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dee->_priv->terminal_button), - gnome_desktop_item_get_flags(ditem) & - GNOME_DESKTOP_ITEM_RUN_IN_TERMINAL); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dee->_priv->simple_dnd_toggle), - gnome_desktop_item_get_flags(ditem) & - GNOME_DESKTOP_ITEM_OLD_STYLE_DROP); - - cs = gnome_desktop_item_get_attribute(ditem, "FileDropExec"); - gtk_entry_set_text(GTK_ENTRY(dee->_priv->file_drop_entry), - cs ? cs : ""); + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (dee->_priv->terminal_button), + gnome_desktop_item_get_boolean (ditem, + GNOME_DESKTOP_ITEM_TERMINAL)); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dee->_priv->single_file_drop_toggle), - gnome_desktop_item_get_flags(ditem) & - GNOME_DESKTOP_ITEM_SINGLE_FILE_DROP_ONLY); - - cs = gnome_desktop_item_get_attribute(ditem, "URLDropExec"); - gtk_entry_set_text(GTK_ENTRY(dee->_priv->url_drop_entry), - cs ? cs : ""); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dee->_priv->single_url_drop_toggle), - gnome_desktop_item_get_flags(ditem) & - GNOME_DESKTOP_ITEM_SINGLE_URL_DROP_ONLY); - /*set the names and comments from our i18n list*/ gtk_clist_clear (GTK_CLIST(dee->_priv->translations)); - i18n_list = gnome_desktop_item_get_languages(ditem); - for (li=i18n_list; li; li=li->next) { + i18n_list = gnome_desktop_item_get_languages (ditem, NULL); + for (li = i18n_list; li != NULL; li = li->next) { const char *text[3]; const gchar* lang = li->data; cs = lang; text[0] = cs ? cs : ""; - cs = gnome_desktop_item_get_name(ditem, lang); + cs = gnome_desktop_item_get_localestring_lang + (ditem, GNOME_DESKTOP_ITEM_NAME, lang); text[1] = cs ? cs : ""; - cs = gnome_desktop_item_get_comment(ditem, lang); + cs = gnome_desktop_item_get_localestring_lang + (ditem, GNOME_DESKTOP_ITEM_COMMENT, lang); text[2] = cs ? cs : ""; - set_list_width (dee->_priv->translations,text); - gtk_clist_append (GTK_CLIST(dee->_priv->translations),(char**)text); + gtk_clist_append (GTK_CLIST (dee->_priv->translations), (char**)text); } - g_slist_free(i18n_list); + g_list_free (i18n_list); /* clear the entries for add/remove */ - gtk_entry_set_text(GTK_ENTRY(dee->_priv->transl_lang_entry), ""); - gtk_entry_set_text(GTK_ENTRY(dee->_priv->transl_name_entry), ""); - gtk_entry_set_text(GTK_ENTRY(dee->_priv->transl_comment_entry), ""); + gtk_entry_set_text (GTK_ENTRY (dee->_priv->transl_lang_entry), ""); + gtk_entry_set_text (GTK_ENTRY (dee->_priv->transl_name_entry), ""); + gtk_entry_set_text (GTK_ENTRY (dee->_priv->transl_comment_entry), ""); /* ui can't be dirty, I mean, damn we just synced it from the ditem */ dee->_priv->ui_dirty = FALSE; } +const char * +get_language (void) +{ + const GList *list = gnome_i18n_get_language_list ("LC_MESSAGES"); + while (list != NULL) { + const char *lang = list->data; + /* find first without encoding */ + if (strchr (lang, '.') == NULL) + return lang; + } + return NULL; +} + /* Conform ditem to display */ static void gnome_ditem_edit_sync_ditem (GnomeDItemEdit *dee) { const gchar * text; + gchar *file; int i; - const gchar* lang; - gint curflags; GnomeDesktopItem *ditem; g_return_if_fail (dee != NULL); @@ -806,72 +676,42 @@ gnome_ditem_edit_sync_ditem (GnomeDItemEdit *dee) ditem = dee->_priv->ditem; - g_assert (ditem != NULL); - - lang = gnome_i18n_get_preferred_language(); - - text = gtk_entry_get_text(GTK_ENTRY(dee->_priv->name_entry)); - gnome_desktop_item_set_name(ditem, lang, text); - - text = gtk_entry_get_text(GTK_ENTRY(dee->_priv->comment_entry)); - gnome_desktop_item_set_comment(ditem, lang, text); + if (ditem == NULL) { + ditem = gnome_desktop_item_new (); + dee->_priv->ditem = ditem; + } text = gtk_entry_get_text(GTK_ENTRY(dee->_priv->exec_entry)); - gnome_desktop_item_set_command(ditem, text); + gnome_desktop_item_set_string (ditem, GNOME_DESKTOP_ITEM_EXEC, text); text = gtk_entry_get_text(GTK_ENTRY(dee->_priv->tryexec_entry)); - gnome_desktop_item_set_attribute(ditem, "TryExec", text); + gnome_desktop_item_set_string (ditem, GNOME_DESKTOP_ITEM_TRY_EXEC, text); text = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(dee->_priv->type_combo)->entry)); - gnome_desktop_item_set_type(ditem, text); + gnome_desktop_item_set_string (ditem, GNOME_DESKTOP_ITEM_TYPE, text); - gnome_desktop_item_set_icon_path(ditem, - gnome_selector_get_uri(GNOME_SELECTOR(dee->_priv->icon_entry))); - - text = gtk_entry_get_text(GTK_ENTRY(dee->_priv->doc_entry)); - gnome_desktop_item_set_attribute(ditem, "DocPath", text); - - text = gtk_entry_get_text(GTK_ENTRY(dee->_priv->wmtitles_entry)); - gnome_desktop_item_set_attribute(ditem, "WMTitles", text); - - curflags = gnome_desktop_item_get_flags(ditem); - if (GTK_TOGGLE_BUTTON(dee->_priv->terminal_button)->active) - curflags |= GNOME_DESKTOP_ITEM_RUN_IN_TERMINAL; - else - curflags &= ~GNOME_DESKTOP_ITEM_RUN_IN_TERMINAL; - gnome_desktop_item_set_flags(ditem, curflags); - - curflags = gnome_desktop_item_get_flags(ditem); - if (GTK_TOGGLE_BUTTON(dee->_priv->simple_dnd_toggle)->active) - curflags |= GNOME_DESKTOP_ITEM_OLD_STYLE_DROP; - else - curflags &= ~GNOME_DESKTOP_ITEM_OLD_STYLE_DROP; - gnome_desktop_item_set_flags(ditem, curflags); - - text = gtk_entry_get_text(GTK_ENTRY(dee->_priv->file_drop_entry)); - gnome_desktop_item_set_attribute(ditem, "FileDropExec", text); - - curflags = gnome_desktop_item_get_flags(ditem); - if (GTK_TOGGLE_BUTTON(dee->_priv->single_file_drop_toggle)->active) - curflags |= GNOME_DESKTOP_ITEM_SINGLE_FILE_DROP_ONLY; - else - curflags &= ~GNOME_DESKTOP_ITEM_SINGLE_FILE_DROP_ONLY; - gnome_desktop_item_set_flags(ditem, curflags); + file = gnome_icon_entry_get_filename (GNOME_ICON_ENTRY (dee->_priv->icon_entry)); + gnome_desktop_item_set_string (ditem, GNOME_DESKTOP_ITEM_ICON, file); + g_free (file); - text = gtk_entry_get_text(GTK_ENTRY(dee->_priv->url_drop_entry)); - gnome_desktop_item_set_attribute(ditem, "URLDropExec", text); + text = gtk_entry_get_text (GTK_ENTRY (dee->_priv->doc_entry)); + gnome_desktop_item_set_string (ditem, "DocPath", text); - curflags = gnome_desktop_item_get_flags(ditem); - if (GTK_TOGGLE_BUTTON(dee->_priv->single_url_drop_toggle)->active) - curflags |= GNOME_DESKTOP_ITEM_SINGLE_URL_DROP_ONLY; + if (GTK_TOGGLE_BUTTON (dee->_priv->terminal_button)->active) + gnome_desktop_item_set_boolean (ditem, + GNOME_DESKTOP_ITEM_TERMINAL, + TRUE); else - curflags &= ~GNOME_DESKTOP_ITEM_SINGLE_URL_DROP_ONLY; - gnome_desktop_item_set_flags(ditem, curflags); - - gnome_desktop_item_clear_name(ditem); - gnome_desktop_item_clear_comment(ditem); - for(i=0;i<GTK_CLIST(dee->_priv->translations)->rows;i++) { - const char *lang,*name,*comment; + gnome_desktop_item_set_boolean (ditem, + GNOME_DESKTOP_ITEM_TERMINAL, + FALSE); + + gnome_desktop_item_clear_localestring (ditem, + GNOME_DESKTOP_ITEM_NAME); + gnome_desktop_item_clear_localestring (ditem, + GNOME_DESKTOP_ITEM_COMMENT); + for (i = 0; i < GTK_CLIST (dee->_priv->translations)->rows; i++) { + const char *lang, *name, *comment; gtk_clist_get_text(GTK_CLIST(dee->_priv->translations),i,0,(gchar**)&lang); gtk_clist_get_text(GTK_CLIST(dee->_priv->translations),i,1,(gchar**)&name); gtk_clist_get_text(GTK_CLIST(dee->_priv->translations),i,2,(gchar**)&comment); @@ -882,14 +722,23 @@ gnome_ditem_edit_sync_ditem (GnomeDItemEdit *dee) continue; if (lang == NULL) - lang = gnome_i18n_get_preferred_language(); + lang = get_language (); - g_assert(lang != NULL); + g_assert (lang != NULL); - gnome_desktop_item_set_name(ditem, lang, name); - gnome_desktop_item_set_comment(ditem, lang, comment); + gnome_desktop_item_set_localestring_lang + (ditem, GNOME_DESKTOP_ITEM_NAME, lang, name); + gnome_desktop_item_set_localestring_lang + (ditem, GNOME_DESKTOP_ITEM_NAME, lang, comment); } + /* This always overrides the above in case of conflict */ + text = gtk_entry_get_text(GTK_ENTRY(dee->_priv->name_entry)); + gnome_desktop_item_set_localestring (ditem, GNOME_DESKTOP_ITEM_NAME, text); + + text = gtk_entry_get_text(GTK_ENTRY(dee->_priv->comment_entry)); + gnome_desktop_item_set_localestring (ditem, GNOME_DESKTOP_ITEM_COMMENT, text); + /* ui not dirty any more, we just synced it */ dee->_priv->ui_dirty = FALSE; } @@ -905,8 +754,9 @@ gnome_ditem_edit_sync_ditem (GnomeDItemEdit *dee) * Returns: %TRUE if successful, %FALSE otherwise */ gboolean -gnome_ditem_edit_load_file(GnomeDItemEdit *dee, - const gchar *path) +gnome_ditem_edit_load_file (GnomeDItemEdit *dee, + const gchar *path, + GError **error) { GnomeDesktopItem * newentry; @@ -914,7 +764,7 @@ gnome_ditem_edit_load_file(GnomeDItemEdit *dee, g_return_val_if_fail (GNOME_IS_DITEM_EDIT (dee), FALSE); g_return_val_if_fail (path != NULL, FALSE); - newentry = gnome_desktop_item_new_from_file (path, 0); + newentry = gnome_desktop_item_new_from_file (path, 0, error); if (newentry != NULL) { if (dee->_priv->ditem != NULL) @@ -951,9 +801,6 @@ gnome_ditem_edit_set_ditem (GnomeDItemEdit *dee, if (dee->_priv->ditem != NULL) gnome_desktop_item_unref (dee->_priv->ditem); dee->_priv->ditem = gnome_desktop_item_copy (ditem); - gnome_desktop_item_set_format (dee->_priv->ditem, - GNOME_DESKTOP_ITEM_GNOME); - dee->_priv->ui_dirty = TRUE; gnome_ditem_edit_sync_display (dee); } @@ -963,18 +810,17 @@ gnome_ditem_edit_set_ditem (GnomeDItemEdit *dee, * @dee: #GnomeDItemEdit object to work with * * Description: Get the current status of the editting areas - * as a #GnomeDesktopItem structure. It will give you a new - * reference of the internal structure. If you wish to modify it, - * make a copy of it with #gnome_desktop_item_copy and release this - * reference. + * as a #GnomeDesktopItem structure. It will give you a pointer + * to the internal structure. If you wish to modify it, + * make a copy of it with #gnome_desktop_item_copy * - * Returns: a reference to a #GnomeDesktopItem structure. + * Returns: a pointer to the internal #GnomeDesktopItem structure. */ GnomeDesktopItem * -gnome_ditem_edit_get_ditem(GnomeDItemEdit *dee) +gnome_ditem_edit_get_ditem (GnomeDItemEdit *dee) { - g_return_val_if_fail(dee != NULL, NULL); - g_return_val_if_fail(GNOME_IS_DITEM_EDIT(dee), NULL); + g_return_val_if_fail (dee != NULL, NULL); + g_return_val_if_fail (GNOME_IS_DITEM_EDIT (dee), NULL); if (dee->_priv->ditem == NULL) { dee->_priv->ditem = gnome_desktop_item_new (); @@ -982,7 +828,7 @@ gnome_ditem_edit_get_ditem(GnomeDItemEdit *dee) } if (dee->_priv->ui_dirty) gnome_ditem_edit_sync_ditem (dee); - return gnome_desktop_item_ref (dee->_priv->ditem); + return dee->_priv->ditem; } /** @@ -995,15 +841,13 @@ gnome_ditem_edit_get_ditem(GnomeDItemEdit *dee) * Returns: */ void -gnome_ditem_edit_clear(GnomeDItemEdit *dee) +gnome_ditem_edit_clear (GnomeDItemEdit *dee) { - GList *types = NULL; - - g_return_if_fail(dee != NULL); - g_return_if_fail(GNOME_IS_DITEM_EDIT(dee)); + g_return_if_fail (dee != NULL); + g_return_if_fail (GNOME_IS_DITEM_EDIT (dee)); - if(dee->_priv->ditem) - gnome_desktop_item_unref(dee->_priv->ditem); + if (dee->_priv->ditem != NULL) + gnome_desktop_item_unref (dee->_priv->ditem); dee->_priv->ditem = NULL; dee->_priv->ui_dirty = TRUE; @@ -1012,24 +856,17 @@ gnome_ditem_edit_clear(GnomeDItemEdit *dee) gtk_entry_set_text(GTK_ENTRY(dee->_priv->exec_entry), ""); gtk_entry_set_text(GTK_ENTRY(dee->_priv->tryexec_entry), ""); gtk_entry_set_text(GTK_ENTRY(dee->_priv->doc_entry), ""); - gnome_selector_set_uri(GNOME_SELECTOR(dee->_priv->icon_entry), NULL, - "", NULL, NULL); + gnome_icon_entry_set_filename (GNOME_ICON_ENTRY (dee->_priv->icon_entry), ""); gtk_entry_set_text(GTK_ENTRY(dee->_priv->transl_lang_entry), ""); gtk_entry_set_text(GTK_ENTRY(dee->_priv->transl_name_entry), ""); gtk_entry_set_text(GTK_ENTRY(dee->_priv->transl_comment_entry), ""); gtk_clist_clear(GTK_CLIST(dee->_priv->translations)); /* set everything to non-directory type which means any type */ - gnome_ditem_set_directory_sensitive(dee, FALSE); + gnome_ditem_set_directory_sensitive (dee, FALSE); /* put all our possibilities here */ - types = g_list_prepend(types, "Application"); - types = g_list_prepend(types, "PanelApplet"); - types = g_list_prepend(types, "URL"); - types = g_list_prepend(types, "Directory"); - gtk_combo_set_popdown_strings(GTK_COMBO(dee->_priv->type_combo), - types); - g_list_free(types); + setup_combo (dee, ALL_TYPES, NULL); } static void @@ -1067,7 +904,7 @@ gnome_ditem_edit_get_icon (GnomeDItemEdit *dee) g_return_val_if_fail (dee != NULL, NULL); g_return_val_if_fail (GNOME_IS_DITEM_EDIT (dee), NULL); - return gnome_selector_get_uri (GNOME_SELECTOR (dee->_priv->icon_entry)); + return gnome_icon_entry_get_filename (GNOME_ICON_ENTRY (dee->_priv->icon_entry)); } /** @@ -1083,11 +920,11 @@ gnome_ditem_edit_get_name (GnomeDItemEdit *dee) { const char * name; - g_return_val_if_fail(dee != NULL, NULL); - g_return_val_if_fail(GNOME_IS_DITEM_EDIT(dee), NULL); + g_return_val_if_fail (dee != NULL, NULL); + g_return_val_if_fail (GNOME_IS_DITEM_EDIT (dee), NULL); - name = gtk_entry_get_text(GTK_ENTRY(dee->_priv->name_entry)); - return g_strdup(name); + name = gtk_entry_get_text (GTK_ENTRY (dee->_priv->name_entry)); + return g_strdup (name); } #ifdef TEST_DITEM_EDIT diff --git a/libgnome-desktop/gnome-ditem-edit.h b/libgnome-desktop/gnome-ditem-edit.h index 81d1c047..ff822c06 100644 --- a/libgnome-desktop/gnome-ditem-edit.h +++ b/libgnome-desktop/gnome-ditem-edit.h @@ -36,7 +36,11 @@ #include <gtk/gtk.h> -#include <libgnome/gnome-ditem.h> +#ifdef GNOME_CORE_INTERNAL +# include "gnome-desktop-item.h" +#else +# include <libgnome/gnome-desktop-item.h> +#endif G_BEGIN_DECLS @@ -63,7 +67,7 @@ struct _GnomeDItemEditClass { /* Any information changed */ void (* changed) (GnomeDItemEdit * gee); - /* These two more specific signals are provided since they + /* These more specific signals are provided since they will likely require a display update */ /* The icon in particular has changed. */ void (* icon_changed) (GnomeDItemEdit * gee); @@ -71,7 +75,7 @@ struct _GnomeDItemEditClass { void (* name_changed) (GnomeDItemEdit * gee); }; -guint gnome_ditem_edit_get_type (void) G_GNUC_CONST; +GType gnome_ditem_edit_get_type (void) G_GNUC_CONST; /*create a new ditem and get the children using the below functions or use the utility new_notebook below*/ @@ -81,7 +85,8 @@ void gnome_ditem_edit_clear (GnomeDItemEdit *dee); /* Make the display reflect ditem at path */ gboolean gnome_ditem_edit_load_file (GnomeDItemEdit *dee, - const gchar *path); + const gchar *path, + GError **error); /* Copy the contents of this ditem into the display */ void gnome_ditem_edit_set_ditem (GnomeDItemEdit *dee, diff --git a/libgnome-desktop/libgnome/gnome-desktop-item.h b/libgnome-desktop/libgnome/gnome-desktop-item.h index 67c4fda0..635c8ea8 100644 --- a/libgnome-desktop/libgnome/gnome-desktop-item.h +++ b/libgnome-desktop/libgnome/gnome-desktop-item.h @@ -2,6 +2,7 @@ /* gnome-ditem.h - GNOME Desktop File Representation Copyright (C) 1999, 2000 Red Hat Inc. + Copyright (C) 2001 Sid Vicious All rights reserved. This file is part of the Gnome Library. @@ -54,6 +55,9 @@ typedef enum { GNOME_DESKTOP_ITEM_DISAPPEARED = 2 } GnomeDesktopItemStatus; +#define GNOME_TYPE_DESKTOP_ITEM (gnome_desktop_item_get_type ()) +GType gnome_desktop_item_get_type (void); + typedef struct _GnomeDesktopItem GnomeDesktopItem; #define GNOME_DESKTOP_ITEM_ENCODING "Encoding" /* string */ @@ -90,12 +94,22 @@ typedef enum { GNOME_DESKTOP_ITEM_LOAD_ONLY_IF_EXISTS = 1<<0 } GnomeDesktopItemLoadFlags; +typedef enum { + GNOME_DESKTOP_ITEM_ERROR_NO_FILENAME /* No filename set or given on save */, + GNOME_DESKTOP_ITEM_ERROR_UNKNOWN_ENCODING /* Unknown encoding of the file */, +} GnomeDesktopItemError; + +/* Note that functions can also return the G_FILE_ERROR_* errors */ + +#define GNOME_DESKTOP_ITEM_ERROR gnome_desktop_item_error_quark () +GQuark gnome_desktop_item_error_quark (void); + /* Returned item from new*() and copy() methods have a refcount of 1 */ GnomeDesktopItem * gnome_desktop_item_new (void); GnomeDesktopItem * gnome_desktop_item_new_from_file (const char *file, GnomeDesktopItemLoadFlags flags, GError **error); -GnomeDesktopItem * gnome_desktop_item_copy (GnomeDesktopItem *item); +GnomeDesktopItem * gnome_desktop_item_copy (const GnomeDesktopItem *item); /* if under is NULL save in original location */ gboolean gnome_desktop_item_save (GnomeDesktopItem *item, @@ -104,7 +118,7 @@ gboolean gnome_desktop_item_save (GnomeDesktopItem GError **error); GnomeDesktopItem * gnome_desktop_item_ref (GnomeDesktopItem *item); void gnome_desktop_item_unref (GnomeDesktopItem *item); -int gnome_desktop_item_launch (GnomeDesktopItem *item, +int gnome_desktop_item_launch (const GnomeDesktopItem *item, int argc, const char **argv, GError **error); @@ -112,40 +126,40 @@ int gnome_desktop_item_launch (GnomeDesktopItem /* A list of files or urls dropped onto an icon, the proper (Url or File exec is run you can pass directly the output of gnome_uri_list_extract_filenames) */ -int gnome_desktop_item_drop_uri_list (GnomeDesktopItem *item, +int gnome_desktop_item_drop_uri_list (const GnomeDesktopItem *item, GList *uri_list, GError **error); -gboolean gnome_desktop_item_exists (GnomeDesktopItem *item); +gboolean gnome_desktop_item_exists (const GnomeDesktopItem *item); -GnomeDesktopItemType gnome_desktop_item_get_type (GnomeDesktopItem *item); +GnomeDesktopItemType gnome_desktop_item_get_entry_type (const GnomeDesktopItem *item); /* You could also just use the set_string on the TYPE argument */ -void gnome_desktop_item_set_type (GnomeDesktopItem *item, +void gnome_desktop_item_set_entry_type (GnomeDesktopItem *item, GnomeDesktopItemType type); /* Get current location on disk */ -char * gnome_desktop_item_get_location (GnomeDesktopItem *item); +char * gnome_desktop_item_get_location (const GnomeDesktopItem *item); void gnome_desktop_item_set_location (GnomeDesktopItem *item, const char *location); -GnomeDesktopItemStatus gnome_desktop_item_get_file_status (GnomeDesktopItem *item); +GnomeDesktopItemStatus gnome_desktop_item_get_file_status (const GnomeDesktopItem *item); +/* + * Get the icon, this is not as simple as getting the Icon attr as it actually tries to find + * it and returns %NULL if it can't + */ +char * gnome_desktop_item_get_icon (const GnomeDesktopItem *item); /* * Reading/Writing different sections, NULL is the standard section */ -void gnome_desktop_item_push_section (GnomeDesktopItem *item, - const char *section); -void gnome_desktop_item_pop_section (GnomeDesktopItem *item); - - -gboolean gnome_desktop_item_attr_exists (GnomeDesktopItem *item, +gboolean gnome_desktop_item_attr_exists (const GnomeDesktopItem *item, const char *attr); /* * String type */ -const char * gnome_desktop_item_get_string (GnomeDesktopItem *item, +const char * gnome_desktop_item_get_string (const GnomeDesktopItem *item, const char *attr); void gnome_desktop_item_set_string (GnomeDesktopItem *item, @@ -155,26 +169,31 @@ void gnome_desktop_item_set_string (GnomeDesktopItem /* * LocaleString type */ -const char * gnome_desktop_item_get_localestring (GnomeDesktopItem *item, +const char * gnome_desktop_item_get_localestring (const GnomeDesktopItem *item, const char *attr); -const char * gnome_desktop_item_get_localestring_lang (GnomeDesktopItem *item, +const char * gnome_desktop_item_get_localestring_lang (const GnomeDesktopItem *item, const char *attr, const char *language); /* use g_list_free only */ -GList * gnome_desktop_item_get_languages (GnomeDesktopItem *item, +GList * gnome_desktop_item_get_languages (const GnomeDesktopItem *item, const char *attr); void gnome_desktop_item_set_localestring (GnomeDesktopItem *item, const char *attr, - const char *language, const char *value); +void gnome_desktop_item_set_localestring_lang (GnomeDesktopItem *item, + const char *attr, + const char *language, + const char *value); +void gnome_desktop_item_clear_localestring(GnomeDesktopItem *item, + const char *attr); /* * Strings, Regexps types */ /* use gnome_desktop_item_free_string_list */ -char ** gnome_desktop_item_get_strings (GnomeDesktopItem *item, +char ** gnome_desktop_item_get_strings (const GnomeDesktopItem *item, const char *attr); void gnome_desktop_item_set_strings (GnomeDesktopItem *item, @@ -184,7 +203,7 @@ void gnome_desktop_item_set_strings (GnomeDesktopItem *item, /* * Boolean type */ -gboolean gnome_desktop_item_get_boolean (GnomeDesktopItem *item, +gboolean gnome_desktop_item_get_boolean (const GnomeDesktopItem *item, const char *attr); void gnome_desktop_item_set_boolean (GnomeDesktopItem *item, diff --git a/libgnome-desktop/libgnomeui/gnome-ditem-edit.h b/libgnome-desktop/libgnomeui/gnome-ditem-edit.h index 81d1c047..ff822c06 100644 --- a/libgnome-desktop/libgnomeui/gnome-ditem-edit.h +++ b/libgnome-desktop/libgnomeui/gnome-ditem-edit.h @@ -36,7 +36,11 @@ #include <gtk/gtk.h> -#include <libgnome/gnome-ditem.h> +#ifdef GNOME_CORE_INTERNAL +# include "gnome-desktop-item.h" +#else +# include <libgnome/gnome-desktop-item.h> +#endif G_BEGIN_DECLS @@ -63,7 +67,7 @@ struct _GnomeDItemEditClass { /* Any information changed */ void (* changed) (GnomeDItemEdit * gee); - /* These two more specific signals are provided since they + /* These more specific signals are provided since they will likely require a display update */ /* The icon in particular has changed. */ void (* icon_changed) (GnomeDItemEdit * gee); @@ -71,7 +75,7 @@ struct _GnomeDItemEditClass { void (* name_changed) (GnomeDItemEdit * gee); }; -guint gnome_ditem_edit_get_type (void) G_GNUC_CONST; +GType gnome_ditem_edit_get_type (void) G_GNUC_CONST; /*create a new ditem and get the children using the below functions or use the utility new_notebook below*/ @@ -81,7 +85,8 @@ void gnome_ditem_edit_clear (GnomeDItemEdit *dee); /* Make the display reflect ditem at path */ gboolean gnome_ditem_edit_load_file (GnomeDItemEdit *dee, - const gchar *path); + const gchar *path, + GError **error); /* Copy the contents of this ditem into the display */ void gnome_ditem_edit_set_ditem (GnomeDItemEdit *dee, |