diff --git a/capplets/file-types/ChangeLog b/capplets/file-types/ChangeLog index d5a6f64f4..c036d1045 100644 --- a/capplets/file-types/ChangeLog +++ b/capplets/file-types/ChangeLog @@ -1,5 +1,14 @@ 2002-02-17 Bradford Hovinen + * mime-type-info.c (get_icon_pixbuf): Try to find the icon from + the MIME type. + (mime_type_info_get_icon_path): Fetch the icon name from the MIME + type if necessary + (get_icon_pixbuf): Call get_real_icon_path + (get_real_icon_path): Implement. Factor from + mime_type_info_get_icon_path + (mime_type_info_get_icon_path): Call get_real_icon_path + * mime-types-model.c (mime_types_model_get_value): Set the object value to NULL if the icon is NULL diff --git a/capplets/file-types/mime-type-info.c b/capplets/file-types/mime-type-info.c index 15865c1b8..d5b972275 100644 --- a/capplets/file-types/mime-type-info.c +++ b/capplets/file-types/mime-type-info.c @@ -55,6 +55,9 @@ static MimeCategoryInfo *get_category (const gchar *category_name, const gchar *category_desc, GtkTreeModel *model); +gchar *get_real_icon_path (const MimeTypeInfo *info, + const gchar *icon_name); + void @@ -140,38 +143,10 @@ mime_type_info_get_icon (MimeTypeInfo *info) const gchar * mime_type_info_get_icon_path (MimeTypeInfo *info) { - gchar *tmp; - if (info->icon_name == NULL) info->icon_name = g_strdup (gnome_vfs_mime_get_icon (info->mime_type)); - if (g_file_test (info->icon_name, G_FILE_TEST_EXISTS)) { - info->icon_path = g_strdup (info->icon_name); - return info->icon_path; - } - - info->icon_path = gnome_vfs_icon_path_from_filename (info->icon_name); - - if (info->icon_path == NULL) { - tmp = g_strconcat (info->icon_name, ".png", NULL); - info->icon_path = gnome_vfs_icon_path_from_filename (tmp); - g_free (tmp); - } - - if (info->icon_path == NULL) { - tmp = g_strconcat ("nautilus/", info->icon_name, NULL); - info->icon_path = gnome_vfs_icon_path_from_filename (tmp); - g_free (tmp); - } - - if (info->icon_path == NULL) { - tmp = g_strconcat ("nautilus/", info->icon_name, ".png", NULL); - info->icon_path = gnome_vfs_icon_path_from_filename (tmp); - g_free (tmp); - } - - if (info->icon_path == NULL) - info->icon_path = gnome_vfs_icon_path_from_filename ("nautilus/i-regular-24.png"); + info->icon_path = get_real_icon_path (info, info->icon_name); return info->icon_path; } @@ -816,6 +791,48 @@ form_extensions_string (const MimeTypeInfo *info, gchar *sep, gchar *prepend) return tmp; } +gchar *get_real_icon_path (const MimeTypeInfo *info, const gchar *icon_name) +{ + gchar *tmp, *tmp1, *ret, *real_icon_name; + + if (icon_name == NULL || *icon_name == '\0') { + tmp = g_strdup (info->mime_type); + tmp1 = strchr (tmp, '/'); + if (tmp1 != NULL) *tmp1 = '-'; + real_icon_name = g_strconcat ("document-icons/gnome-", tmp, ".png", NULL); + g_free (tmp); + } else { + real_icon_name = g_strdup (icon_name); + } + + ret = gnome_vfs_icon_path_from_filename (real_icon_name); + + if (ret == NULL && strstr (real_icon_name, ".png") == NULL) { + tmp = g_strconcat (real_icon_name, ".png", NULL); + ret = gnome_vfs_icon_path_from_filename (tmp); + g_free (tmp); + } + + if (ret == NULL) { + tmp = g_strconcat ("nautilus/", real_icon_name, NULL); + ret = gnome_vfs_icon_path_from_filename (tmp); + g_free (tmp); + } + + if (ret == NULL && strstr (real_icon_name, ".png") == NULL) { + tmp = g_strconcat ("nautilus/", real_icon_name, ".png", NULL); + ret = gnome_vfs_icon_path_from_filename (tmp); + g_free (tmp); + } + + if (ret == NULL) + ret = gnome_vfs_icon_path_from_filename ("nautilus/i-regular-24.png"); + + g_free (real_icon_name); + + return ret; +} + /* Loads a pixbuf for the icon, falling back on the default icon if * necessary */ @@ -826,7 +843,7 @@ get_icon_pixbuf (MimeTypeInfo *info, const gchar *icon_path, gboolean want_large static GHashTable *icon_table = NULL; if (icon_path == NULL) - icon_path = gnome_vfs_icon_path_from_filename ("nautilus/i-regular-24.png"); + icon_path = get_real_icon_path (info, NULL); if (icon_path == NULL) return;