Compare commits

...

2 Commits

Author SHA1 Message Date
Matthias Clasen
4d2a869817 filechooserbutton: Use GIcons
This should work, but doesn't.
2017-11-08 20:54:48 -05:00
Matthias Clasen
9f40c22b8c filesystem: Add GIcon getters
We want to move away from surfaces, and instead pass
GIcons and GdkTextures around.
2017-11-08 20:53:49 -05:00
3 changed files with 147 additions and 119 deletions

View File

@@ -283,7 +283,6 @@ static void gtk_file_chooser_button_state_flags_changed (GtkWidget *wi
GtkStateFlags previous_state); GtkStateFlags previous_state);
/* Utility Functions */ /* Utility Functions */
static GtkIconTheme *get_icon_theme (GtkWidget *widget);
static void set_info_for_file_at_iter (GtkFileChooserButton *fs, static void set_info_for_file_at_iter (GtkFileChooserButton *fs,
GFile *file, GFile *file,
GtkTreeIter *iter); GtkTreeIter *iter);
@@ -518,9 +517,8 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
gtk_widget_set_parent (priv->button, GTK_WIDGET (button)); gtk_widget_set_parent (priv->button, GTK_WIDGET (button));
priv->model = GTK_TREE_MODEL (gtk_list_store_new (NUM_COLUMNS, priv->model = GTK_TREE_MODEL (gtk_list_store_new (NUM_COLUMNS,
CAIRO_GOBJECT_TYPE_SURFACE, G_TYPE_ICON,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_CHAR, G_TYPE_CHAR,
G_TYPE_POINTER, G_TYPE_POINTER,
@@ -538,11 +536,11 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->combo_box), priv->icon_cell, FALSE); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->combo_box), priv->icon_cell, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->combo_box), gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->combo_box),
priv->icon_cell, "surface", 0, NULL); priv->icon_cell, "gicon", ICON_COLUMN, NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->combo_box), priv->name_cell, FALSE); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->combo_box), priv->name_cell, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->combo_box), gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->combo_box),
priv->name_cell, "text", 1, NULL); priv->name_cell, "text", DISPLAY_NAME_COLUMN, NULL);
gtk_widget_hide (priv->combo_box); gtk_widget_hide (priv->combo_box);
gtk_widget_set_parent (priv->combo_box, GTK_WIDGET (button)); gtk_widget_set_parent (priv->combo_box, GTK_WIDGET (button));
@@ -1373,7 +1371,7 @@ change_icon_theme_get_info_cb (GCancellable *cancellable,
gpointer user_data) gpointer user_data)
{ {
gboolean cancelled = g_cancellable_is_cancelled (cancellable); gboolean cancelled = g_cancellable_is_cancelled (cancellable);
cairo_surface_t *surface; GIcon *icon;
struct ChangeIconThemeData *data = user_data; struct ChangeIconThemeData *data = user_data;
if (!g_slist_find (data->button->priv->change_icon_theme_cancellables, cancellable)) if (!g_slist_find (data->button->priv->change_icon_theme_cancellables, cancellable))
@@ -1385,9 +1383,8 @@ change_icon_theme_get_info_cb (GCancellable *cancellable,
if (cancelled || error) if (cancelled || error)
goto out; goto out;
surface = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size); icon = _gtk_file_info_get_icon (info, data->button->priv->icon_size, gtk_widget_get_scale_factor (GTK_WIDGET (data->button)));
if (icon)
if (surface)
{ {
gint width = 0; gint width = 0;
GtkTreeIter iter; GtkTreeIter iter;
@@ -1401,15 +1398,18 @@ change_icon_theme_get_info_cb (GCancellable *cancellable,
gtk_tree_model_get_iter (data->button->priv->model, &iter, path); gtk_tree_model_get_iter (data->button->priv->model, &iter, path);
gtk_tree_path_free (path); gtk_tree_path_free (path);
g_assert (G_IS_ICON (icon));
g_print ("refcount before: %d\n", G_OBJECT (icon)->ref_count);
gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter, gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
ICON_COLUMN, surface, ICON_COLUMN, icon,
-1); -1);
g_print ("refcount after: %d\n", G_OBJECT (icon)->ref_count);
g_object_set (data->button->priv->icon_cell, g_object_set (data->button->priv->icon_cell,
"width", width, "width", width,
NULL); NULL);
} }
cairo_surface_destroy (surface); g_object_unref (icon);
} }
out: out:
@@ -1424,7 +1424,6 @@ static void
change_icon_theme (GtkFileChooserButton *button) change_icon_theme (GtkFileChooserButton *button)
{ {
GtkFileChooserButtonPrivate *priv = button->priv; GtkFileChooserButtonPrivate *priv = button->priv;
GtkIconTheme *theme;
GtkTreeIter iter; GtkTreeIter iter;
GSList *l; GSList *l;
gint width = 0, height = 0; gint width = 0, height = 0;
@@ -1446,11 +1445,9 @@ change_icon_theme (GtkFileChooserButton *button)
gtk_tree_model_get_iter_first (priv->model, &iter); gtk_tree_model_get_iter_first (priv->model, &iter);
theme = get_icon_theme (GTK_WIDGET (button));
do do
{ {
cairo_surface_t *surface = NULL; GIcon *icon = NULL;
gchar type; gchar type;
gpointer data; gpointer data;
@@ -1487,7 +1484,7 @@ change_icon_theme (GtkFileChooserButton *button)
info); info);
button->priv->change_icon_theme_cancellables = button->priv->change_icon_theme_cancellables =
g_slist_append (button->priv->change_icon_theme_cancellables, cancellable); g_slist_append (button->priv->change_icon_theme_cancellables, cancellable);
surface = NULL; icon = NULL;
} }
else else
{ {
@@ -1496,22 +1493,13 @@ change_icon_theme (GtkFileChooserButton *button)
* If we switch to a better bookmarks file format (XBEL), we * If we switch to a better bookmarks file format (XBEL), we
* should use mime info to get a better icon. * should use mime info to get a better icon.
*/ */
surface = gtk_icon_theme_load_surface (theme, "folder-remote", icon = g_themed_icon_new ("folder-remote");
priv->icon_size,
gtk_widget_get_scale_factor (GTK_WIDGET (button)),
gtk_widget_get_window (GTK_WIDGET (button)),
0, NULL);
} }
} }
break; break;
case ROW_TYPE_VOLUME: case ROW_TYPE_VOLUME:
if (data) if (data)
{ icon = _gtk_file_system_volume_get_icon (data);
surface = _gtk_file_system_volume_render_icon (data,
GTK_WIDGET (button),
priv->icon_size,
NULL);
}
break; break;
default: default:
@@ -1519,15 +1507,20 @@ change_icon_theme (GtkFileChooserButton *button)
break; break;
} }
if (surface) if (icon)
width = MAX (width, priv->icon_size); width = MAX (width, priv->icon_size);
g_assert (icon == NULL || G_IS_ICON (icon));
if (icon)
g_print ("refcount before: %d\n", G_OBJECT (icon)->ref_count);
gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
ICON_COLUMN, surface, ICON_COLUMN, icon,
-1); -1);
if (icon)
g_print ("refcount before: %d\n", G_OBJECT (icon)->ref_count);
if (surface) if (icon)
cairo_surface_destroy (surface); g_object_unref (icon);
} }
while (gtk_tree_model_iter_next (priv->model, &iter)); while (gtk_tree_model_iter_next (priv->model, &iter));
@@ -1566,13 +1559,6 @@ gtk_file_chooser_button_display_changed (GtkWidget *widget,
* ******************* */ * ******************* */
/* General */ /* General */
static GtkIconTheme *
get_icon_theme (GtkWidget *widget)
{
return gtk_css_icon_theme_value_get_icon_theme
(_gtk_style_context_peek_property (gtk_widget_get_style_context (widget), GTK_CSS_PROPERTY_ICON_THEME));
}
struct SetDisplayNameData struct SetDisplayNameData
{ {
@@ -1588,7 +1574,7 @@ set_info_get_info_cb (GCancellable *cancellable,
gpointer callback_data) gpointer callback_data)
{ {
gboolean cancelled = g_cancellable_is_cancelled (cancellable); gboolean cancelled = g_cancellable_is_cancelled (cancellable);
cairo_surface_t *surface; GIcon *icon;
GtkTreePath *path; GtkTreePath *path;
GtkTreeIter iter; GtkTreeIter iter;
GCancellable *model_cancellable = NULL; GCancellable *model_cancellable = NULL;
@@ -1622,21 +1608,26 @@ set_info_get_info_cb (GCancellable *cancellable,
/* There was an error, leave the fallback name in there */ /* There was an error, leave the fallback name in there */
goto out; goto out;
surface = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size); icon = _gtk_file_info_get_icon (info, data->button->priv->icon_size, gtk_widget_get_scale_factor (GTK_WIDGET (data->button)));
if (!data->label) if (!data->label)
data->label = g_strdup (g_file_info_get_display_name (info)); data->label = g_strdup (g_file_info_get_display_name (info));
is_folder = _gtk_file_info_consider_as_directory (info); is_folder = _gtk_file_info_consider_as_directory (info);
g_assert (icon == NULL || G_IS_ICON (icon));
if (icon)
g_print ("refcount before: %d\n", G_OBJECT (icon)->ref_count);
gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter, gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
ICON_COLUMN, surface, ICON_COLUMN, icon,
DISPLAY_NAME_COLUMN, data->label, DISPLAY_NAME_COLUMN, data->label,
IS_FOLDER_COLUMN, is_folder, IS_FOLDER_COLUMN, is_folder,
-1); -1);
if (icon)
g_print ("refcount after: %d\n", G_OBJECT (icon)->ref_count);
if (surface) if (icon)
cairo_surface_destroy (surface); g_object_unref (icon);
out: out:
g_object_unref (data->button); g_object_unref (data->button);
@@ -1774,7 +1765,7 @@ model_add_special_get_info_cb (GCancellable *cancellable,
gboolean cancelled = g_cancellable_is_cancelled (cancellable); gboolean cancelled = g_cancellable_is_cancelled (cancellable);
GtkTreeIter iter; GtkTreeIter iter;
GtkTreePath *path; GtkTreePath *path;
cairo_surface_t *surface; GIcon *icon;
GCancellable *model_cancellable = NULL; GCancellable *model_cancellable = NULL;
struct ChangeIconThemeData *data = user_data; struct ChangeIconThemeData *data = user_data;
gchar *name; gchar *name;
@@ -1804,13 +1795,16 @@ model_add_special_get_info_cb (GCancellable *cancellable,
if (cancelled || error) if (cancelled || error)
goto out; goto out;
surface = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size); icon = _gtk_file_info_get_icon (info, data->button->priv->icon_size, gtk_widget_get_scale_factor (GTK_WIDGET (data->button)));
if (surface) if (icon)
{ {
g_assert (icon == NULL || G_IS_ICON (icon));
g_print ("refcount before: %d\n", G_OBJECT (icon)->ref_count);
gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter, gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
ICON_COLUMN, surface, ICON_COLUMN, icon,
-1); -1);
cairo_surface_destroy (surface); g_print ("refcount after: %d\n", G_OBJECT (icon)->ref_count);
g_object_unref (icon);
} }
gtk_tree_model_get (data->button->priv->model, &iter, gtk_tree_model_get (data->button->priv->model, &iter,
@@ -1937,7 +1931,7 @@ model_add_volumes (GtkFileChooserButton *button,
{ {
GtkFileSystemVolume *volume; GtkFileSystemVolume *volume;
GtkTreeIter iter; GtkTreeIter iter;
cairo_surface_t *surface; GIcon *icon;
gchar *display_name; gchar *display_name;
volume = l->data; volume = l->data;
@@ -1962,23 +1956,25 @@ model_add_volumes (GtkFileChooserButton *button,
} }
} }
surface = _gtk_file_system_volume_render_icon (volume, icon = _gtk_file_system_volume_get_icon (volume);
GTK_WIDGET (button),
button->priv->icon_size,
NULL);
display_name = _gtk_file_system_volume_get_display_name (volume); display_name = _gtk_file_system_volume_get_display_name (volume);
g_assert (icon == NULL || G_IS_ICON (icon));
if (icon)
g_print ("refcount before: %d\n", G_OBJECT (icon)->ref_count);
gtk_list_store_insert (store, &iter, pos); gtk_list_store_insert (store, &iter, pos);
gtk_list_store_set (store, &iter, gtk_list_store_set (store, &iter,
ICON_COLUMN, surface, ICON_COLUMN, icon,
DISPLAY_NAME_COLUMN, display_name, DISPLAY_NAME_COLUMN, display_name,
TYPE_COLUMN, ROW_TYPE_VOLUME, TYPE_COLUMN, ROW_TYPE_VOLUME,
DATA_COLUMN, _gtk_file_system_volume_ref (volume), DATA_COLUMN, _gtk_file_system_volume_ref (volume),
IS_FOLDER_COLUMN, TRUE, IS_FOLDER_COLUMN, TRUE,
-1); -1);
if (icon)
g_print ("refcount after: %d\n", G_OBJECT (icon)->ref_count);
if (surface) if (icon)
cairo_surface_destroy (surface); g_object_unref (icon);
g_free (display_name); g_free (display_name);
button->priv->n_volumes++; button->priv->n_volumes++;
@@ -2024,8 +2020,7 @@ model_add_bookmarks (GtkFileChooserButton *button,
else else
{ {
gchar *label; gchar *label;
GtkIconTheme *icon_theme; GIcon *icon;
cairo_surface_t *surface = NULL;
if (local_only) if (local_only)
continue; continue;
@@ -2039,25 +2034,25 @@ model_add_bookmarks (GtkFileChooserButton *button,
if (!label) if (!label)
label = _gtk_file_chooser_label_for_file (file); label = _gtk_file_chooser_label_for_file (file);
icon_theme = get_icon_theme (GTK_WIDGET (button)); icon = g_themed_icon_new ("folder-remote");
surface = gtk_icon_theme_load_surface (icon_theme, "folder-remote",
button->priv->icon_size,
gtk_widget_get_scale_factor (GTK_WIDGET (button)),
gtk_widget_get_window (GTK_WIDGET (button)),
0, NULL);
g_assert (icon == NULL || G_IS_ICON (icon));
if (icon)
g_print ("refcount before: %d\n", G_OBJECT (icon)->ref_count);
gtk_list_store_insert (store, &iter, pos); gtk_list_store_insert (store, &iter, pos);
gtk_list_store_set (store, &iter, gtk_list_store_set (store, &iter,
ICON_COLUMN, surface, ICON_COLUMN, icon,
DISPLAY_NAME_COLUMN, label, DISPLAY_NAME_COLUMN, label,
TYPE_COLUMN, ROW_TYPE_BOOKMARK, TYPE_COLUMN, ROW_TYPE_BOOKMARK,
DATA_COLUMN, g_object_ref (file), DATA_COLUMN, g_object_ref (file),
IS_FOLDER_COLUMN, TRUE, IS_FOLDER_COLUMN, TRUE,
-1); -1);
if (icon)
g_print ("refcount before: %d\n", G_OBJECT (icon)->ref_count);
g_free (label); g_free (label);
if (surface) if (icon)
cairo_surface_destroy (surface); g_object_unref (icon);
} }
button->priv->n_bookmarks++; button->priv->n_bookmarks++;
@@ -2134,8 +2129,7 @@ model_update_current_folder (GtkFileChooserButton *button,
else else
{ {
gchar *label; gchar *label;
GtkIconTheme *icon_theme; GIcon *icon;
cairo_surface_t *surface;
/* Don't call get_info for remote paths to avoid latency and /* Don't call get_info for remote paths to avoid latency and
* auth dialogs. * auth dialogs.
@@ -2146,32 +2140,26 @@ model_update_current_folder (GtkFileChooserButton *button,
if (!label) if (!label)
label = _gtk_file_chooser_label_for_file (file); label = _gtk_file_chooser_label_for_file (file);
icon_theme = get_icon_theme (GTK_WIDGET (button));
if (g_file_is_native (file)) if (g_file_is_native (file))
surface = gtk_icon_theme_load_surface (icon_theme, "folder", icon = g_themed_icon_new ("folder");
button->priv->icon_size,
gtk_widget_get_scale_factor (GTK_WIDGET (button)),
gtk_widget_get_window (GTK_WIDGET (button)),
0, NULL);
else else
surface = gtk_icon_theme_load_surface (icon_theme, "folder-remote", icon = g_themed_icon_new ("folder-remote");
button->priv->icon_size,
gtk_widget_get_scale_factor (GTK_WIDGET (button)),
gtk_widget_get_window (GTK_WIDGET (button)),
0, NULL);
if (icon)
g_print ("refcount before: %d\n", G_OBJECT (icon)->ref_count);
gtk_list_store_set (store, &iter, gtk_list_store_set (store, &iter,
ICON_COLUMN, surface, ICON_COLUMN, icon,
DISPLAY_NAME_COLUMN, label, DISPLAY_NAME_COLUMN, label,
TYPE_COLUMN, ROW_TYPE_CURRENT_FOLDER, TYPE_COLUMN, ROW_TYPE_CURRENT_FOLDER,
DATA_COLUMN, g_object_ref (file), DATA_COLUMN, g_object_ref (file),
IS_FOLDER_COLUMN, TRUE, IS_FOLDER_COLUMN, TRUE,
-1); -1);
if (icon)
g_print ("refcount after: %d\n", G_OBJECT (icon)->ref_count);
g_free (label); g_free (label);
if (surface) if (icon)
cairo_surface_destroy (surface); g_object_unref (icon);
} }
} }
@@ -2509,7 +2497,7 @@ update_label_get_info_cb (GCancellable *cancellable,
gpointer data) gpointer data)
{ {
gboolean cancelled = g_cancellable_is_cancelled (cancellable); gboolean cancelled = g_cancellable_is_cancelled (cancellable);
cairo_surface_t *surface; GIcon *icon;
GtkFileChooserButton *button = data; GtkFileChooserButton *button = data;
GtkFileChooserButtonPrivate *priv = button->priv; GtkFileChooserButtonPrivate *priv = button->priv;
@@ -2523,10 +2511,11 @@ update_label_get_info_cb (GCancellable *cancellable,
gtk_label_set_text (GTK_LABEL (priv->label), g_file_info_get_display_name (info)); gtk_label_set_text (GTK_LABEL (priv->label), g_file_info_get_display_name (info));
surface = _gtk_file_info_render_icon (info, GTK_WIDGET (priv->image), priv->icon_size); icon = _gtk_file_info_get_icon (info, priv->icon_size, gtk_widget_get_scale_factor (GTK_WIDGET (button)));
gtk_image_set_from_surface (GTK_IMAGE (priv->image), surface); gtk_image_set_from_gicon (GTK_IMAGE (priv->image), icon, GTK_ICON_SIZE_BUTTON);
if (surface) gtk_image_set_pixel_size (GTK_IMAGE (priv->image), priv->icon_size);
cairo_surface_destroy (surface); if (icon)
g_object_unref (icon);
out: out:
emit_selection_changed_if_changing_selection (button); emit_selection_changed_if_changing_selection (button);
@@ -2566,16 +2555,14 @@ update_label_and_image (GtkFileChooserButton *button)
base_file = _gtk_file_system_volume_get_root (volume); base_file = _gtk_file_system_volume_get_root (volume);
if (base_file && g_file_equal (base_file, file)) if (base_file && g_file_equal (base_file, file))
{ {
cairo_surface_t *surface; GIcon *icon;
label_text = _gtk_file_system_volume_get_display_name (volume); label_text = _gtk_file_system_volume_get_display_name (volume);
surface = _gtk_file_system_volume_render_icon (volume, icon = _gtk_file_system_volume_get_icon (volume);
GTK_WIDGET (button), gtk_image_set_from_gicon (GTK_IMAGE (priv->image), icon, GTK_ICON_SIZE_BUTTON);
priv->icon_size, gtk_image_set_pixel_size (GTK_IMAGE (priv->image), priv->icon_size);
NULL); if (icon)
gtk_image_set_from_surface (GTK_IMAGE (priv->image), surface); g_object_unref (icon);
if (surface)
cairo_surface_destroy (surface);
} }
if (base_file) if (base_file)
@@ -2600,18 +2587,14 @@ update_label_and_image (GtkFileChooserButton *button)
} }
else else
{ {
cairo_surface_t *surface; GIcon *icon;
label_text = _gtk_bookmarks_manager_get_bookmark_label (button->priv->bookmarks_manager, file); label_text = _gtk_bookmarks_manager_get_bookmark_label (button->priv->bookmarks_manager, file);
surface = gtk_icon_theme_load_surface (get_icon_theme (GTK_WIDGET (priv->image)), icon = g_themed_icon_new ("text-x-generic");
"text-x-generic", gtk_image_set_from_gicon (GTK_IMAGE (priv->image), icon, GTK_ICON_SIZE_BUTTON);
priv->icon_size, gtk_image_set_pixel_size (GTK_IMAGE (priv->image), priv->icon_size);
gtk_widget_get_scale_factor (GTK_WIDGET (button)), if (icon)
gtk_widget_get_window (GTK_WIDGET (button)), g_object_unref (icon);
0, NULL);
gtk_image_set_from_surface (GTK_IMAGE (priv->image), surface);
if (surface)
cairo_surface_destroy (surface);
done_changing_selection = TRUE; done_changing_selection = TRUE;
} }
@@ -2635,7 +2618,7 @@ out:
else else
{ {
gtk_label_set_text (GTK_LABEL (priv->label), _(FALLBACK_DISPLAY_NAME)); gtk_label_set_text (GTK_LABEL (priv->label), _(FALLBACK_DISPLAY_NAME));
gtk_image_set_from_surface (GTK_IMAGE (priv->image), NULL); gtk_image_set_from_gicon (GTK_IMAGE (priv->image), NULL, priv->icon_size);
} }
if (done_changing_selection) if (done_changing_selection)

View File

@@ -745,14 +745,10 @@ get_surface_from_gicon (GIcon *icon,
return surface; return surface;
} }
cairo_surface_t * GIcon *
_gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume, _gtk_file_system_volume_get_icon (GtkFileSystemVolume *volume)
GtkWidget *widget,
gint icon_size,
GError **error)
{ {
GIcon *icon = NULL; GIcon *icon = NULL;
cairo_surface_t *surface;
if (IS_ROOT_VOLUME (volume)) if (IS_ROOT_VOLUME (volume))
icon = g_themed_icon_new ("drive-harddisk"); icon = g_themed_icon_new ("drive-harddisk");
@@ -763,6 +759,20 @@ _gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume,
else if (G_IS_MOUNT (volume)) else if (G_IS_MOUNT (volume))
icon = g_mount_get_icon (G_MOUNT (volume)); icon = g_mount_get_icon (G_MOUNT (volume));
return icon;
}
cairo_surface_t *
_gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume,
GtkWidget *widget,
gint icon_size,
GError **error)
{
GIcon *icon = NULL;
cairo_surface_t *surface;
icon = _gtk_file_system_volume_get_icon (volume);
if (!icon) if (!icon)
return NULL; return NULL;
@@ -870,6 +880,37 @@ _gtk_file_info_render_icon_internal (GFileInfo *info,
return surface; return surface;
} }
GIcon *
_gtk_file_info_get_icon (GFileInfo *info,
int icon_size,
int scale)
{
GIcon *icon;
GdkPixbuf *pixbuf;
const gchar *thumbnail_path;
thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
if (thumbnail_path)
{
pixbuf = gdk_pixbuf_new_from_file_at_size (thumbnail_path,
icon_size*scale, icon_size*scale,
NULL);
if (pixbuf != NULL)
return G_ICON (pixbuf);
}
icon = g_file_info_get_icon (info);
if (icon)
return icon;
/* Use general fallback for all files without icon */
icon = g_themed_icon_new ("text-x-generic");
return icon;
}
cairo_surface_t * cairo_surface_t *
_gtk_file_info_render_icon (GFileInfo *info, _gtk_file_info_render_icon (GFileInfo *info,
GtkWidget *widget, GtkWidget *widget,

View File

@@ -94,6 +94,7 @@ gchar * _gtk_file_system_volume_get_display_name (GtkFileSystemVol
gboolean _gtk_file_system_volume_is_mounted (GtkFileSystemVolume *volume); gboolean _gtk_file_system_volume_is_mounted (GtkFileSystemVolume *volume);
GFile * _gtk_file_system_volume_get_root (GtkFileSystemVolume *volume); GFile * _gtk_file_system_volume_get_root (GtkFileSystemVolume *volume);
GIcon * _gtk_file_system_volume_get_symbolic_icon (GtkFileSystemVolume *volume); GIcon * _gtk_file_system_volume_get_symbolic_icon (GtkFileSystemVolume *volume);
GIcon * _gtk_file_system_volume_get_icon (GtkFileSystemVolume *volume);
cairo_surface_t * _gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume, cairo_surface_t * _gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume,
GtkWidget *widget, GtkWidget *widget,
gint icon_size, gint icon_size,
@@ -106,6 +107,9 @@ void _gtk_file_system_volume_unref (GtkFileSystemVol
cairo_surface_t * _gtk_file_info_render_icon (GFileInfo *info, cairo_surface_t * _gtk_file_info_render_icon (GFileInfo *info,
GtkWidget *widget, GtkWidget *widget,
gint icon_size); gint icon_size);
GIcon * _gtk_file_info_get_icon (GFileInfo *info,
int icon_size,
int scale);
gboolean _gtk_file_info_consider_as_directory (GFileInfo *info); gboolean _gtk_file_info_consider_as_directory (GFileInfo *info);