[gtk: 8/40] icons: Convert use of load() to download_texture()
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 8/40] icons: Convert use of load() to download_texture()
- Date: Thu, 30 Jan 2020 17:31:49 +0000 (UTC)
commit dbe021239f4555375350998591995676885fab08
Author: Alexander Larsson <alexl redhat com>
Date: Tue Jan 28 10:30:01 2020 +0100
icons: Convert use of load() to download_texture()
demos/gtk-demo/textview.c | 12 ++++++-----
gtk/gtkbuilder.c | 15 +++++++-------
gtk/gtkmountoperation.c | 2 +-
gtk/gtkwindow.c | 6 +++---
tests/testclipboard2.c | 12 ++++++++---
tests/testdnd2.c | 53 ++++++++++++++++++++++++++---------------------
testsuite/gtk/icontheme.c | 2 +-
7 files changed, 58 insertions(+), 44 deletions(-)
---
diff --git a/demos/gtk-demo/textview.c b/demos/gtk-demo/textview.c
index c28312a517..f55fa510e0 100644
--- a/demos/gtk-demo/textview.c
+++ b/demos/gtk-demo/textview.c
@@ -130,13 +130,15 @@ insert_text (GtkTextBuffer *buffer)
GtkTextIter start, end;
GdkTexture *texture;
GtkIconTheme *icon_theme;
+ GtkIconInfo *icon;
icon_theme = gtk_icon_theme_get_default ();
- texture = GDK_TEXTURE (gtk_icon_theme_load_icon (icon_theme,
- "gtk3-demo",
- 32,
- GTK_ICON_LOOKUP_GENERIC_FALLBACK,
- NULL));
+ icon = gtk_icon_theme_lookup_icon (icon_theme,
+ "gtk3-demo",
+ 32,
+ GTK_ICON_LOOKUP_GENERIC_FALLBACK);
+ texture = gtk_icon_info_download_texture (icon, NULL);
+ g_object_unref (icon);
g_assert (texture);
/* get start of buffer; each insertion will revalidate the
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index b98ab3566c..7e962e0b31 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -2157,7 +2157,8 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
if (pixbuf == NULL)
{
GtkIconTheme *theme;
- GdkPaintable *texture;
+ GtkIconInfo *icon;
+ GdkTexture *texture;
g_warning ("Could not load image '%s': %s",
string, tmp_error->message);
@@ -2165,12 +2166,12 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
/* fall back to a missing image */
theme = gtk_icon_theme_get_default ();
- texture = gtk_icon_theme_load_icon (theme,
- "image-missing",
- 16,
- GTK_ICON_LOOKUP_USE_BUILTIN,
- NULL);
- pixbuf = gdk_pixbuf_get_from_texture (GDK_TEXTURE (texture));
+
+ icon = gtk_icon_theme_lookup_icon (theme, "image-missing", 16,
+ GTK_ICON_LOOKUP_USE_BUILTIN);
+ texture = gtk_icon_info_download_texture (icon, NULL);
+ pixbuf = gdk_pixbuf_get_from_texture (texture);
+ g_object_unref (icon);
g_object_unref (texture);
}
diff --git a/gtk/gtkmountoperation.c b/gtk/gtkmountoperation.c
index ebcdba0f2b..e9981387c5 100644
--- a/gtk/gtkmountoperation.c
+++ b/gtk/gtkmountoperation.c
@@ -1175,7 +1175,7 @@ add_pid_to_process_list_store (GtkMountOperation *mount_operation,
(_gtk_style_context_peek_property (gtk_widget_get_style_context (GTK_WIDGET
(mount_operation->priv->dialog)),
GTK_CSS_PROPERTY_ICON_THEME));
info = gtk_icon_theme_lookup_icon (theme, "application-x-executable", 24, 0);
- texture = GDK_TEXTURE (gtk_icon_info_load_icon (info, NULL));
+ texture = gtk_icon_info_download_texture (info, NULL);
g_object_unref (info);
}
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 8846f57820..6cf0598c15 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -4036,9 +4036,9 @@ icon_list_from_theme (GtkWindow *window,
0);
if (info)
{
- GdkPaintable *paintable = gtk_icon_info_load_icon (info, NULL);
- if (paintable && GDK_IS_TEXTURE (paintable))
- list = g_list_insert_sorted (list, GDK_TEXTURE (paintable), (GCompareFunc) icon_size_compare);
+ GdkTexture *texture = gtk_icon_info_download_texture (info, NULL);
+ if (texture)
+ list = g_list_insert_sorted (list, texture, (GCompareFunc) icon_size_compare);
g_object_unref (info);
}
diff --git a/tests/testclipboard2.c b/tests/testclipboard2.c
index 432cbfc4bf..c7073bd5ea 100644
--- a/tests/testclipboard2.c
+++ b/tests/testclipboard2.c
@@ -272,6 +272,8 @@ get_button_list (GdkClipboard *clipboard,
0xc9, 'g', 'a', 'l', 'i', 't', 0xe9, ',', ' ',
'F', 'r', 'a', 't', 'e', 'r', 'n', 'i', 't', 0xe9, 0 };
GtkWidget *box;
+ GtkIconInfo *icon;
+ GdkTexture *texture;
GValue value = G_VALUE_INIT;
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
@@ -284,9 +286,13 @@ get_button_list (GdkClipboard *clipboard,
"Empty");
g_value_init (&value, GDK_TYPE_PIXBUF);
- g_value_take_object (&value, gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
- "utilities-terminal",
- 48, 0, NULL));
+ icon = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
+ "utilities-terminal",
+ 48, 0);
+ texture = gtk_icon_info_download_texture (icon, NULL);
+ g_value_take_object (&value, gdk_pixbuf_get_from_texture (texture));
+ g_object_unref (texture);
+ g_object_unref (icon);
add_provider_button (box,
gdk_content_provider_new_for_value (&value),
clipboard,
diff --git a/tests/testdnd2.c b/tests/testdnd2.c
index ecf5a95551..2b4c5fcb96 100644
--- a/tests/testdnd2.c
+++ b/tests/testdnd2.c
@@ -1,35 +1,40 @@
#include <unistd.h>
#include <gtk/gtk.h>
-static GdkPaintable *
-get_image_paintable (GtkImage *image,
- int *out_size)
+static GdkTexture *
+get_image_texture (GtkImage *image,
+ int *out_size)
{
GtkIconTheme *icon_theme;
const char *icon_name;
int width = 48;
GdkPaintable *paintable;
+ GdkTexture *texture = NULL;
GtkIconInfo *icon_info;
switch (gtk_image_get_storage_type (image))
{
case GTK_IMAGE_PAINTABLE:
paintable = gtk_image_get_paintable (image);
- *out_size = gdk_paintable_get_intrinsic_width (paintable);
- return g_object_ref (paintable);
+ if (GDK_IS_TEXTURE (paintable))
+ {
+ *out_size = gdk_paintable_get_intrinsic_width (paintable);
+ texture = g_object_ref (GDK_TEXTURE (paintable));
+ }
case GTK_IMAGE_ICON_NAME:
icon_name = gtk_image_get_icon_name (image);
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (image)));
*out_size = width;
icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, width,
GTK_ICON_LOOKUP_GENERIC_FALLBACK);
- paintable = gtk_icon_info_load_icon (icon_info, NULL);
+ if (icon_info)
+ texture = gtk_icon_info_download_texture (icon_info, NULL);
g_object_unref (icon_info);
- return paintable;
default:
g_warning ("Image storage type %d not handled",
gtk_image_get_storage_type (image));
- return NULL;
}
+
+ return texture;
}
enum {
@@ -44,17 +49,18 @@ image_drag_data_get (GtkWidget *widget,
GtkSelectionData *selection_data,
gpointer data)
{
- GdkPaintable *paintable;
+ GdkTexture *texture;
const gchar *name;
int size;
if (gtk_selection_data_targets_include_image (selection_data, TRUE))
{
- paintable = get_image_paintable (GTK_IMAGE (data), &size);
- if (GDK_IS_TEXTURE (paintable))
- gtk_selection_data_set_texture (selection_data, GDK_TEXTURE (paintable));
- if (paintable)
- g_object_unref (paintable);
+ texture = get_image_texture (GTK_IMAGE (data), &size);
+ if (texture)
+ {
+ gtk_selection_data_set_texture (selection_data, texture);
+ g_object_unref (texture);
+ }
}
else if (gtk_selection_data_targets_include_text (selection_data))
{
@@ -217,12 +223,12 @@ update_source_icon (GtkDragSource *source,
const char *icon_name,
int hotspot)
{
- GdkPaintable *paintable;
+ GtkIconInfo *icon;
int hot_x, hot_y;
int size = 48;
- paintable = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
- icon_name, size, 0, NULL);
+ icon = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
+ icon_name, size, 0);
switch (hotspot)
{
default:
@@ -239,8 +245,8 @@ update_source_icon (GtkDragSource *source,
hot_y = size;
break;
}
- gtk_drag_source_set_icon (source, paintable, hot_x, hot_y);
- g_object_unref (paintable);
+ gtk_drag_source_set_icon (source, GDK_PAINTABLE (icon), hot_x, hot_y);
+ g_object_unref (icon);
}
static GBytes *
@@ -265,8 +271,8 @@ get_data (const char *mimetype,
else if (strcmp (mimetype, "image/png") == 0)
{
int size;
- GdkPaintable *paintable = get_image_paintable (GTK_IMAGE (image), &size);
- if (GDK_IS_TEXTURE (paintable))
+ GdkTexture *texture = get_image_texture (GTK_IMAGE (image), &size);
+ if (texture)
{
char *name = g_strdup ("drag-data-XXXXXX");
int fd;
@@ -278,15 +284,14 @@ get_data (const char *mimetype,
fd = g_mkstemp (name);
close (fd);
- gdk_texture_save_to_png (GDK_TEXTURE (paintable), name);
+ gdk_texture_save_to_png (texture, name);
+ g_object_unref (texture);
g_file_get_contents (name, &data, &size, NULL);
g_free (name);
return g_bytes_new_take (data, size);
}
-
- g_clear_object (&paintable);
}
return NULL;
}
diff --git a/testsuite/gtk/icontheme.c b/testsuite/gtk/icontheme.c
index 0260e1625c..927eab9839 100644
--- a/testsuite/gtk/icontheme.c
+++ b/testsuite/gtk/icontheme.c
@@ -85,7 +85,7 @@ assert_icon_lookup_size (const char *icon_name,
GdkTexture *texture;
GError *error = NULL;
- texture = GDK_TEXTURE (gtk_icon_info_load_icon (info, &error));
+ texture = gtk_icon_info_download_texture (info, &error);
g_assert_no_error (error);
g_assert_cmpint (gdk_texture_get_width (texture), ==, pixbuf_size);
g_object_unref (texture);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]