[Xfce4-commits] r29764 - in thunar/branches/migration-to-gio: . thunar
Jannis Pohlmann
jannis at xfce.org
Sat Apr 11 18:33:07 CEST 2009
Author: jannis
Date: 2009-04-11 16:33:07 +0000 (Sat, 11 Apr 2009)
New Revision: 29764
Modified:
thunar/branches/migration-to-gio/ChangeLog
thunar/branches/migration-to-gio/thunar/thunar-file.c
thunar/branches/migration-to-gio/thunar/thunar-file.h
thunar/branches/migration-to-gio/thunar/thunar-icon-factory.c
thunar/branches/migration-to-gio/thunar/thunar-launcher.c
thunar/branches/migration-to-gio/thunar/thunar-location-button.c
thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c
thunar/branches/migration-to-gio/thunar/thunar-sendto-model.c
Log:
* thunar/thunar-file.{c,h}: Change thunar_file_get_custom_icon() to
return a newly allocated string instead of a const one. Re-implement
thunar_file_get_icon_name() based on GFileInfo and GThemedIcon. It
now returns a string that has to be freed.
* thunar/thunar-icon-factory.c, thunar/thunar-location-button.c,
thunar/thunar-properties-dialog.c: Avoid leaks by freeing the
strings returned by thunar_file_get_custom_icon() and
thunar_file_get_icon_name().
* thunar/thunar-launcher.c, thunar/thunar-sendto-model.c: Remove debug
statements.
Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog 2009-04-11 15:36:06 UTC (rev 29763)
+++ thunar/branches/migration-to-gio/ChangeLog 2009-04-11 16:33:07 UTC (rev 29764)
@@ -1,5 +1,18 @@
2009-04-11 Jannis Pohlmann <jannis at xfce.org>
+ * thunar/thunar-file.{c,h}: Change thunar_file_get_custom_icon() to
+ return a newly allocated string instead of a const one. Re-implement
+ thunar_file_get_icon_name() based on GFileInfo and GThemedIcon. It
+ now returns a string that has to be freed.
+ * thunar/thunar-icon-factory.c, thunar/thunar-location-button.c,
+ thunar/thunar-properties-dialog.c: Avoid leaks by freeing the
+ strings returned by thunar_file_get_custom_icon() and
+ thunar_file_get_icon_name().
+ * thunar/thunar-launcher.c, thunar/thunar-sendto-model.c: Remove debug
+ statements.
+
+2009-04-11 Jannis Pohlmann <jannis at xfce.org>
+
* configure.in.in, thunar/Makefile.am: Add optional dependency on
gio-unix-2.0.
* thunar/thunar-launcher.c, thunar/thunar-sendto-model.c: Load sendto
Modified: thunar/branches/migration-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.c 2009-04-11 15:36:06 UTC (rev 29763)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.c 2009-04-11 16:33:07 UTC (rev 29764)
@@ -1692,55 +1692,72 @@
* @icon_theme : the #GtkIconTheme on which to lookup up the icon name.
*
* Returns the name of the icon that can be used to present @file, based
- * on the given @icon_state and @icon_theme.
+ * on the given @icon_state and @icon_theme. The returned string has to
+ * be freed using g_free().
*
* Return value: the icon name for @file in @icon_theme.
**/
-const gchar*
+gchar*
thunar_file_get_icon_name (const ThunarFile *file,
ThunarFileIconState icon_state,
GtkIconTheme *icon_theme)
{
- const gchar *icon_name;
+ GIcon *icon;
+ gchar **themed_icon_names;
+ gchar *icon_name = NULL;
+ gint i;
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
_thunar_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
- /* special icon for the home node */
- if (G_UNLIKELY (thunar_file_is_home (file))
- && gtk_icon_theme_has_icon (icon_theme, "gnome-fs-home"))
+ icon = g_file_info_get_icon (file->ginfo);
+
+ if (icon != NULL && G_IS_THEMED_ICON (icon))
{
- return "gnome-fs-home";
- }
+ g_object_get (icon, "names", &themed_icon_names, NULL);
- /* special icon for the desktop node */
- if (G_UNLIKELY (thunar_file_is_desktop (file))
- && gtk_icon_theme_has_icon (icon_theme, "gnome-fs-desktop"))
- {
- return "gnome-fs-desktop";
- }
+ for (i = 0; icon_name == NULL && themed_icon_names[i] != NULL; ++i)
+ {
+ if (gtk_icon_theme_has_icon (icon_theme, themed_icon_names[i]))
+ icon_name = g_strdup (themed_icon_names[i]);
+ }
- /* try to be smart when determining icons for executable files
- * in that we use the name of the file as icon name (which will
- * work for quite a lot of binaries, e.g. 'Terminal', 'mousepad',
- * 'Thunar', 'xfmedia', etc.).
- */
- if (G_UNLIKELY (thunar_file_is_executable (file)))
+ g_strfreev (themed_icon_names);
+ }
+
+ if (icon_name == NULL)
{
- icon_name = thunar_vfs_path_get_name (file->info->path);
- if (G_UNLIKELY (gtk_icon_theme_has_icon (icon_theme, icon_name)))
- return icon_name;
+ /* try to be smart when determining icons for executable files
+ * in that we use the name of the file as icon name (which will
+ * work for quite a lot of binaries, e.g. 'Terminal', 'mousepad',
+ * 'Thunar', 'xfmedia', etc.).
+ */
+ if (G_UNLIKELY (thunar_file_is_executable (file)))
+ {
+ icon_name = g_file_get_basename (file->gfile);
+ if (G_LIKELY (!gtk_icon_theme_has_icon (icon_theme, icon_name)))
+ {
+ g_free (icon_name);
+ icon_name = NULL;
+ }
+ }
}
- /* default is the mime type icon */
- icon_name = thunar_vfs_mime_info_lookup_icon_name (file->info->mime_info, icon_theme);
-
/* check if we have an accept icon for the icon we found */
- if ((icon_state == THUNAR_FILE_ICON_STATE_DROP || icon_state == THUNAR_FILE_ICON_STATE_OPEN)
- && strcmp (icon_name, "gnome-fs-directory") == 0
- && gtk_icon_theme_has_icon (icon_theme, "gnome-fs-directory-accept"))
+ if (icon_name != NULL &&
+ (g_str_equal (icon_name, "inode-directory")
+ || g_str_equal (icon_name, "folder")))
{
- return "gnome-fs-directory-accept";
+ if (icon_state == THUNAR_FILE_ICON_STATE_DROP)
+ {
+ g_free (icon_name);
+ icon_name = g_strdup ("folder-drag-accept");
+ }
+ else if (icon_state == THUNAR_FILE_ICON_STATE_OPEN)
+ {
+ g_free (icon_name);
+ icon_name = g_strdup ("folder-open");
+ }
}
return icon_name;
Modified: thunar/branches/migration-to-gio/thunar/thunar-file.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.h 2009-04-11 15:36:06 UTC (rev 29763)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.h 2009-04-11 16:33:07 UTC (rev 29764)
@@ -206,7 +206,7 @@
const gchar *custom_icon,
GError **error) G_GNUC_WARN_UNUSED_RESULT;
-const gchar *thunar_file_get_icon_name (const ThunarFile *file,
+gchar *thunar_file_get_icon_name (const ThunarFile *file,
ThunarFileIconState icon_state,
GtkIconTheme *icon_theme);
@@ -405,7 +405,7 @@
* Return value: the custom icon for @file
* or %NULL.
**/
-#define thunar_file_get_custom_icon(file) (thunar_vfs_info_get_custom_icon (THUNAR_FILE ((file))->info))
+#define thunar_file_get_custom_icon(file) (g_strdup (thunar_vfs_info_get_custom_icon (THUNAR_FILE ((file))->info)))
Modified: thunar/branches/migration-to-gio/thunar/thunar-icon-factory.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-icon-factory.c 2009-04-11 15:36:06 UTC (rev 29763)
+++ thunar/branches/migration-to-gio/thunar/thunar-icon-factory.c 2009-04-11 16:33:07 UTC (rev 29764)
@@ -925,7 +925,7 @@
ThunarVfsInfo *info;
ThunarVfsPath *path;
ThunarIconKey key;
- const gchar *icon_name;
+ gchar *icon_name;
GdkPixbuf *icon;
gchar *thumb_path;
@@ -939,6 +939,7 @@
{
/* try to load the icon */
icon = thunar_icon_factory_lookup_icon (factory, icon_name, icon_size, FALSE);
+ g_free (icon_name);
if (G_LIKELY (icon != NULL))
return icon;
}
@@ -1042,11 +1043,11 @@
}
}
- /* lookup the icon name for the icon in the given state */
+ /* lookup the icon name for the icon in the given state and load the icon */
icon_name = thunar_file_get_icon_name (file, icon_state, factory->icon_theme);
-
- /* load the icon of the given name */
- return thunar_icon_factory_load_icon (factory, icon_name, icon_size, NULL, TRUE);
+ icon = thunar_icon_factory_load_icon (factory, icon_name, icon_size, NULL, TRUE);
+ g_free (icon_name);
+ return icon;
}
Modified: thunar/branches/migration-to-gio/thunar/thunar-launcher.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-launcher.c 2009-04-11 15:36:06 UTC (rev 29763)
+++ thunar/branches/migration-to-gio/thunar/thunar-launcher.c 2009-04-11 16:33:07 UTC (rev 29764)
@@ -1361,14 +1361,12 @@
* has been added to GtkAction in GTK+ 2.16 though. For now, this hack will have to do: */
ui_path = g_strconcat ("/main-menu/file-menu/sendto-menu/placeholder-sendto-actions/", name, NULL);
- g_debug ("name = %s, ui_path = %s", name, ui_path);
menu_item = gtk_ui_manager_get_widget (launcher->ui_manager, ui_path);
image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (menu_item));
gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (lp->data), GTK_ICON_SIZE_MENU);
g_free (ui_path);
ui_path = g_strconcat ("/file-context-menu/sendto-menu/placeholder-sendto-actions/", name, NULL);
- g_debug ("name = %s, ui_path = %s", name, ui_path);
menu_item = gtk_ui_manager_get_widget (launcher->ui_manager, ui_path);
image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (menu_item));
gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (lp->data), GTK_ICON_SIZE_MENU);
Modified: thunar/branches/migration-to-gio/thunar/thunar-location-button.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-location-button.c 2009-04-11 15:36:06 UTC (rev 29763)
+++ thunar/branches/migration-to-gio/thunar/thunar-location-button.c 2009-04-11 16:33:07 UTC (rev 29764)
@@ -452,9 +452,7 @@
ThunarIconFactory *icon_factory;
GtkIconTheme *icon_theme;
GtkSettings *settings;
-#if GTK_CHECK_VERSION(2,8,0)
- const gchar *icon_name;
-#endif
+ gchar *icon_name;
GdkPixbuf *icon;
gint height;
gint width;
@@ -506,13 +504,12 @@
gtk_widget_hide (location_button->image);
}
-#if GTK_CHECK_VERSION(2,8,0)
/* setup the DnD icon for the button */
icon_name = thunar_file_get_custom_icon (file);
if (G_LIKELY (icon_name == NULL))
icon_name = thunar_file_get_icon_name (file, location_button->file_icon_state, icon_theme);
gtk_drag_source_set_icon_name (GTK_BIN (location_button)->child, icon_name);
-#endif
+ g_free (icon_name);
}
Modified: thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c 2009-04-11 15:36:06 UTC (rev 29763)
+++ thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c 2009-04-11 16:33:07 UTC (rev 29764)
@@ -679,11 +679,11 @@
thunar_properties_dialog_icon_button_clicked (GtkWidget *button,
ThunarPropertiesDialog *dialog)
{
- const gchar *custom_icon;
- GtkWidget *chooser;
- GError *err = NULL;
- gchar *title;
- gchar *icon;
+ GtkWidget *chooser;
+ GError *err = NULL;
+ gchar *custom_icon;
+ gchar *title;
+ gchar *icon;
_thunar_return_if_fail (THUNAR_IS_PROPERTIES_DIALOG (dialog));
_thunar_return_if_fail (GTK_IS_BUTTON (button));
@@ -706,6 +706,7 @@
custom_icon = thunar_file_get_custom_icon (dialog->file);
if (G_LIKELY (custom_icon != NULL && *custom_icon != '\0'))
exo_icon_chooser_dialog_set_icon (EXO_ICON_CHOOSER_DIALOG (chooser), custom_icon);
+ g_free (custom_icon);
/* run the icon chooser dialog and make sure the dialog still has a file */
if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT && dialog->file != NULL)
Modified: thunar/branches/migration-to-gio/thunar/thunar-sendto-model.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-sendto-model.c 2009-04-11 15:36:06 UTC (rev 29763)
+++ thunar/branches/migration-to-gio/thunar/thunar-sendto-model.c 2009-04-11 16:33:07 UTC (rev 29764)
@@ -142,7 +142,6 @@
g_app_info_compare (gpointer a,
gpointer b)
{
- g_debug ("a = %s, b = %s", g_app_info_get_name (a), g_app_info_get_name (b));
return g_utf8_collate (g_app_info_get_name (b),
g_app_info_get_name (a));
}
More information about the Xfce4-commits
mailing list