[Xfce4-commits] <thunar:master> Return const string in thunar_file_get_custom_icon.
Nick Schermer
noreply at xfce.org
Tue Oct 30 22:06:01 CET 2012
Updating branch refs/heads/master
to b6ce9c30fb184db37cd50566d2f6c10220504747 (commit)
from 93095e43dd059d5474e1bf52f698e5357b7fd632 (commit)
commit b6ce9c30fb184db37cd50566d2f6c10220504747
Author: Nick Schermer <nick at xfce.org>
Date: Tue Oct 30 17:47:46 2012 +0100
Return const string in thunar_file_get_custom_icon.
Not needed to duplicate it, although the string is
almost never set.
thunar/thunar-file.c | 4 +-
thunar/thunar-file.h | 2 +-
thunar/thunar-icon-factory.c | 43 ++++++++++++++++--------------------
thunar/thunar-location-button.c | 16 ++++++++-----
thunar/thunar-properties-dialog.c | 13 +++++------
5 files changed, 38 insertions(+), 40 deletions(-)
diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index f885d27..a4e5967 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -3218,11 +3218,11 @@ thunar_file_set_thumb_state (ThunarFile *file,
*
* Return value: the custom icon for @file or %NULL.
**/
-gchar *
+const gchar *
thunar_file_get_custom_icon (const ThunarFile *file)
{
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
- return g_strdup (file->custom_icon_name);
+ return file->custom_icon_name;
}
diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h
index be742a9..d78b612 100644
--- a/thunar/thunar-file.h
+++ b/thunar/thunar-file.h
@@ -217,7 +217,7 @@ GList *thunar_file_get_emblem_names (ThunarFile *fil
void thunar_file_set_emblem_names (ThunarFile *file,
GList *emblem_names);
-gchar *thunar_file_get_custom_icon (const ThunarFile *file);
+const gchar *thunar_file_get_custom_icon (const ThunarFile *file);
gboolean thunar_file_set_custom_icon (ThunarFile *file,
const gchar *custom_icon,
GError **error);
diff --git a/thunar/thunar-icon-factory.c b/thunar/thunar-icon-factory.c
index 9a58c95..2079a0a 100644
--- a/thunar/thunar-icon-factory.c
+++ b/thunar/thunar-icon-factory.c
@@ -618,7 +618,7 @@ thunar_icon_key_equal (gconstpointer a,
return FALSE;
/* do a full string comparison on the names */
- return (strcmp (a_key->name, b_key->name) == 0);
+ return exo_str_is_equal (a_key->name, b_key->name);
}
@@ -776,24 +776,24 @@ thunar_icon_factory_load_file_icon (ThunarIconFactory *factory,
ThunarFileIconState icon_state,
gint icon_size)
{
- GInputStream *stream;
- GtkIconInfo *icon_info;
- const gchar *thumbnail_path;
- GdkPixbuf *icon = NULL;
- GIcon *gicon;
- gchar *icon_name;
+ GInputStream *stream;
+ GtkIconInfo *icon_info;
+ const gchar *thumbnail_path;
+ GdkPixbuf *icon = NULL;
+ GIcon *gicon;
+ gchar *icon_name;
+ const gchar *custom_icon;
_thunar_return_val_if_fail (THUNAR_IS_ICON_FACTORY (factory), NULL);
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
_thunar_return_val_if_fail (icon_size > 0, NULL);
/* check if we have a custom icon for this file */
- icon_name = thunar_file_get_custom_icon (file);
- if (icon_name != NULL)
+ custom_icon = thunar_file_get_custom_icon (file);
+ if (custom_icon != NULL)
{
/* try to load the icon */
- icon = thunar_icon_factory_lookup_icon (factory, icon_name, icon_size, FALSE);
- g_free (icon_name);
+ icon = thunar_icon_factory_lookup_icon (factory, custom_icon, icon_size, FALSE);
if (G_LIKELY (icon != NULL))
return icon;
}
@@ -854,23 +854,18 @@ thunar_icon_factory_load_file_icon (ThunarIconFactory *factory,
if (thumbnail_path != NULL)
{
/* try to load the thumbnail */
- icon = thunar_icon_factory_load_from_file (factory, thumbnail_path,
- icon_size);
-
- /* return the thumbnail if it could be loaded */
- if (icon != NULL)
- return icon;
+ icon = thunar_icon_factory_load_from_file (factory, thumbnail_path, icon_size);
}
}
}
/* 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);
- icon = thunar_icon_factory_load_icon (factory, icon_name, icon_size, NULL, TRUE);
- g_free (icon_name);
+ if (G_LIKELY (icon == NULL))
+ {
+ icon_name = thunar_file_get_icon_name (file, icon_state, factory->icon_theme);
+ icon = thunar_icon_factory_load_icon (factory, icon_name, icon_size, NULL, TRUE);
+ g_free (icon_name);
+ }
+
return icon;
}
-
-
-
-
diff --git a/thunar/thunar-location-button.c b/thunar/thunar-location-button.c
index 50a7ead..37e493e 100644
--- a/thunar/thunar-location-button.c
+++ b/thunar/thunar-location-button.c
@@ -428,6 +428,7 @@ thunar_location_button_file_changed (ThunarLocationButton *location_button,
gint height;
gint width;
gint size;
+ const gchar *custom_icon;
_thunar_return_if_fail (THUNAR_IS_LOCATION_BUTTON (location_button));
_thunar_return_if_fail (location_button->file == file);
@@ -479,14 +480,17 @@ thunar_location_button_file_changed (ThunarLocationButton *location_button,
}
/* setup the DnD icon for the button */
- icon_name = thunar_file_get_custom_icon (file);
- if (icon_name == NULL)
+ custom_icon = thunar_file_get_custom_icon (file);
+ if (custom_icon != 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, custom_icon);
+ }
+ else
+ {
+ 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);
+ g_free (icon_name);
}
- gtk_drag_source_set_icon_name (GTK_BIN (location_button)->child, icon_name);
- g_free (icon_name);
}
diff --git a/thunar/thunar-properties-dialog.c b/thunar/thunar-properties-dialog.c
index 07fda40..34cf2e6 100644
--- a/thunar/thunar-properties-dialog.c
+++ b/thunar/thunar-properties-dialog.c
@@ -744,12 +744,12 @@ static void
thunar_properties_dialog_icon_button_clicked (GtkWidget *button,
ThunarPropertiesDialog *dialog)
{
- GtkWidget *chooser;
- GError *err = NULL;
- gchar *custom_icon;
- gchar *title;
- gchar *icon;
- ThunarFile *file;
+ GtkWidget *chooser;
+ GError *err = NULL;
+ const gchar *custom_icon;
+ gchar *title;
+ gchar *icon;
+ ThunarFile *file;
_thunar_return_if_fail (THUNAR_IS_PROPERTIES_DIALOG (dialog));
_thunar_return_if_fail (GTK_IS_BUTTON (button));
@@ -775,7 +775,6 @@ thunar_properties_dialog_icon_button_clicked (GtkWidget *button,
custom_icon = thunar_file_get_custom_icon (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 && file != NULL)
More information about the Xfce4-commits
mailing list