diff options
author | Jody Goldberg <jody@gnome.org> | 2004-02-13 14:29:11 +0000 |
---|---|---|
committer | Jody Goldberg <jody@src.gnome.org> | 2004-02-13 14:29:11 +0000 |
commit | ff003126bb01e6cda57b233ceef7a8297177cea8 (patch) | |
tree | ce3c5435a6d5f38d95cf0d43f89037b0ec2bb43d /capplets | |
parent | a9c54dd7e92de1a7a086b4c27c9ddc5ed8540c05 (diff) | |
download | gnome-control-center-ff003126bb01e6cda57b233ceef7a8297177cea8.tar.gz |
rework to match nautilus and use icon themes somewhat. There is some
2004-02-10 Jody Goldberg <jody@gnome.org>
* mime-type-info.c : rework to match nautilus and use icon themes
somewhat. There is some serious cruft left in here.
2004-02-04 Jody Goldberg <jody@gnome.org>
* mime-edit-dialog.c (mime_edit_dialog_class_init) : do not call these
construct only properties so that the info can change later.
Diffstat (limited to 'capplets')
-rw-r--r-- | capplets/file-types/ChangeLog | 10 | ||||
-rw-r--r-- | capplets/file-types/mime-edit-dialog.c | 4 | ||||
-rw-r--r-- | capplets/file-types/mime-type-info.c | 188 |
3 files changed, 109 insertions, 93 deletions
diff --git a/capplets/file-types/ChangeLog b/capplets/file-types/ChangeLog index 8a69e2d2a..f461b64e2 100644 --- a/capplets/file-types/ChangeLog +++ b/capplets/file-types/ChangeLog @@ -1,3 +1,13 @@ +2004-02-10 Jody Goldberg <jody@gnome.org> + + * mime-type-info.c : rework to match nautilus and use icon themes + somewhat. There is some serious cruft left in here. + +2004-02-04 Jody Goldberg <jody@gnome.org> + + * mime-edit-dialog.c (mime_edit_dialog_class_init) : do not call these + construct only properties so that the info can change later. + 2004-02-12 Mark McLoughlin <mark@skynet.ie> * file-types-capplet.c: (cb_file_type_dialog_response): Update help diff --git a/capplets/file-types/mime-edit-dialog.c b/capplets/file-types/mime-edit-dialog.c index bc096a0a8..c3e837e30 100644 --- a/capplets/file-types/mime-edit-dialog.c +++ b/capplets/file-types/mime-edit-dialog.c @@ -262,7 +262,7 @@ mime_edit_dialog_class_init (MimeEditDialogClass *class) g_param_spec_pointer ("mime-type-info", _("MIME type information"), _("Structure with data on the MIME type"), - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_IS_ADD, @@ -270,7 +270,7 @@ mime_edit_dialog_class_init (MimeEditDialogClass *class) _("Is add dialog"), _("True if this dialog is for adding a MIME type"), FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + G_PARAM_READWRITE)); dialog_signals[DONE] = g_signal_new ("done", diff --git a/capplets/file-types/mime-type-info.c b/capplets/file-types/mime-type-info.c index e4b7cdcca..dac80b433 100644 --- a/capplets/file-types/mime-type-info.c +++ b/capplets/file-types/mime-type-info.c @@ -46,19 +46,110 @@ static GSList *get_lang_list (void); static gchar *form_extensions_string (const MimeTypeInfo *info, gchar *sep, gchar *prepend); -static void get_icon_pixbuf (MimeTypeInfo *info, - const gchar *icon_path, - gboolean want_large); 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); - +static 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 ("gnome-mime-", tmp, 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) { + GtkIconInfo *info; + + info = gtk_icon_theme_lookup_icon ( + gtk_icon_theme_get_default (), real_icon_name, 48, 0); + if (info != NULL) + ret = g_strdup (gtk_icon_info_get_filename (info)); + else if (icon_name != NULL) { + info = gtk_icon_theme_lookup_icon ( + gtk_icon_theme_get_default (), icon_name, 48, 0); + if (info != NULL) + ret = g_strdup (gtk_icon_info_get_filename (info)); + } + } + + 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); + } + g_free (real_icon_name); + + if (ret == NULL) + ret = gnome_vfs_icon_path_from_filename ("nautilus/i-regular-24.png"); + + return ret; +} + +/* Loads a pixbuf for the icon, falling back on the default icon if + * necessary + */ +static void +get_icon_pixbuf (MimeTypeInfo *info, const gchar *icon_path, gboolean want_large) +{ + static GHashTable *icon_table = NULL; + + if (icon_path == NULL) + icon_path = get_real_icon_path (info, NULL); + + if (icon_path == NULL) + return; + + if ((want_large && info->icon_pixbuf != NULL) || info->small_icon_pixbuf != NULL) + return; + + if (icon_table == NULL) + icon_table = g_hash_table_new (g_str_hash, g_str_equal); + + if (!want_large) + info->small_icon_pixbuf = g_hash_table_lookup (icon_table, icon_path); + + if (info->small_icon_pixbuf != NULL) { + g_object_ref (G_OBJECT (info->small_icon_pixbuf)); + } else { + info->icon_pixbuf = gdk_pixbuf_new_from_file (icon_path, NULL); + + if (info->icon_pixbuf == NULL) { + get_icon_pixbuf (info, NULL, want_large); + } + else if (!want_large) { + info->small_icon_pixbuf = + gdk_pixbuf_scale_simple (info->icon_pixbuf, 16, 16, GDK_INTERP_HYPER); + + g_hash_table_insert (icon_table, g_strdup (icon_path), info->small_icon_pixbuf); + } + } +} + + void load_all_mime_types (GtkTreeModel *model) { @@ -140,10 +231,8 @@ mime_type_info_get_icon (MimeTypeInfo *info) { if (info->small_icon_pixbuf == NULL) get_icon_pixbuf (info, mime_type_info_get_icon_path (info), FALSE); - if (info->small_icon_pixbuf != NULL) g_object_ref (G_OBJECT (info->small_icon_pixbuf)); - return info->small_icon_pixbuf; } @@ -707,89 +796,6 @@ 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 - */ - -void -get_icon_pixbuf (MimeTypeInfo *info, const gchar *icon_path, gboolean want_large) -{ - static GHashTable *icon_table = NULL; - - if (icon_path == NULL) - icon_path = get_real_icon_path (info, NULL); - - if (icon_path == NULL) - return; - - if ((want_large && info->icon_pixbuf != NULL) || info->small_icon_pixbuf != NULL) - return; - - if (icon_table == NULL) - icon_table = g_hash_table_new (g_str_hash, g_str_equal); - - if (!want_large) - info->small_icon_pixbuf = g_hash_table_lookup (icon_table, icon_path); - - if (info->small_icon_pixbuf != NULL) { - g_object_ref (G_OBJECT (info->small_icon_pixbuf)); - } else { - info->icon_pixbuf = gdk_pixbuf_new_from_file (icon_path, NULL); - - if (info->icon_pixbuf == NULL) { - get_icon_pixbuf (info, NULL, want_large); - } - else if (!want_large) { - info->small_icon_pixbuf = - gdk_pixbuf_scale_simple (info->icon_pixbuf, 16, 16, GDK_INTERP_HYPER); - - g_hash_table_insert (icon_table, g_strdup (icon_path), info->small_icon_pixbuf); - } - } -} - static MimeCategoryInfo * get_category (const gchar *category_name, const gchar *category_desc, GtkTreeModel *model) { |