[gtk/modern-testsuite: 1/9] API: Add gdk_texture_new_from_filename()




commit 93d95f9e1ecc0414c18a0aed7d9bc714d633675e
Author: Benjamin Otte <otte redhat com>
Date:   Wed Sep 15 22:08:33 2021 +0200

    API: Add gdk_texture_new_from_filename()
    
    There are quite a few places where we can make use of it, in particular
    in the testsuite and icontheme.

 gdk/gdktexture.c | 33 +++++++++++++++++++++++++++++++++
 gdk/gdktexture.h |  3 +++
 2 files changed, 36 insertions(+)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 7b055238fd..6b630400fc 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -405,6 +405,39 @@ gdk_texture_new_from_file (GFile   *file,
   return texture;
 }
 
+/**
+ * gdk_texture_new_from_filename:
+ * @path: (type filename): the filename to load
+ * @error: Return location for an error
+ *
+ * Creates a new texture by loading an image from a file.
+ *
+ * The file format is detected automatically. The supported formats
+ * are PNG and JPEG, though more formats might be available.
+ *
+ * If %NULL is returned, then @error will be set.
+ *
+ * Return value: A newly-created `GdkTexture`
+ */
+GdkTexture *
+gdk_texture_new_from_filename (const char  *path,
+                               GError     **error)
+{
+  GdkTexture *texture;
+  GFile *file;
+
+  g_return_val_if_fail (path, NULL);
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+  file = g_file_new_for_path (path);
+
+  texture = gdk_texture_new_from_file (file, error);
+
+  g_object_unref (file);
+
+  return texture;
+}
+
 /**
  * gdk_texture_get_width: (attributes org.gtk.Method.get_property=width)
  * @texture: a `GdkTexture`
diff --git a/gdk/gdktexture.h b/gdk/gdktexture.h
index 9e3b7a93fa..52d0fbd05f 100644
--- a/gdk/gdktexture.h
+++ b/gdk/gdktexture.h
@@ -49,6 +49,9 @@ GdkTexture *            gdk_texture_new_from_resource          (const char
 GDK_AVAILABLE_IN_ALL
 GdkTexture *            gdk_texture_new_from_file              (GFile           *file,
                                                                 GError         **error);
+GDK_AVAILABLE_IN_4_6
+GdkTexture *            gdk_texture_new_from_filename          (const char      *filename,
+                                                                GError         **error);
 
 GDK_AVAILABLE_IN_ALL
 int                     gdk_texture_get_width                  (GdkTexture      *texture) G_GNUC_PURE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]