gnucash stable: Replace deprecated gdk_pixbuf_new_from_xpm_data

John Ralls jralls at code.gnucash.org
Tue Sep 23 17:11:35 EDT 2025


Updated	 via  https://github.com/Gnucash/gnucash/commit/5b0d70b7 (commit)
	from  https://github.com/Gnucash/gnucash/commit/ac4a6808 (commit)



commit 5b0d70b7aa4f9439c60881784b5e1c391d8de9f1
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Sep 23 14:10:47 2025 -0700

    Replace deprecated gdk_pixbuf_new_from_xpm_data

diff --git a/gnucash/import-export/import-backend.cpp b/gnucash/import-export/import-backend.cpp
index d333d7bfbb..6c818d3176 100644
--- a/gnucash/import-export/import-backend.cpp
+++ b/gnucash/import-export/import-backend.cpp
@@ -362,7 +362,8 @@ GdkPixbuf* gen_probability_pixbuf(gint score_original, GNCImportSettings *settin
     constexpr gint width_each_bar = 7;
     constexpr gint width_first_bar = 1;
     constexpr gint num_colors = 5;
-    gchar * xpm[2 + num_colors + height];
+    constexpr size_t xpm_size = 2 + num_colors + height;
+    gchar * xpm[xpm_size];
 
     g_assert(settings);
     g_assert(widget);
@@ -398,10 +399,26 @@ GdkPixbuf* gen_probability_pixbuf(gint score_original, GNCImportSettings *settin
                 strcat(xpm[num_colors+1+i], "byyyyb ");
         }
     }
+    GError *err = nullptr;
+    std::string xpm_str = "/* XPM */\nstatic char * XFACE[] = {\n";
 
-    auto retval = gdk_pixbuf_new_from_xpm_data((const gchar **)xpm);
-    for (int i = 0; i <= num_colors + height; i++)
+    for (int i = 0; i < xpm_size - 1; i++)
+    {
+       xpm_str += "\"";
+        xpm_str += xpm[i];
+        xpm_str += "\",\n";
         g_free(xpm[i]);
+    }
+    xpm_str += "};";
+
+    auto gstream = g_memory_input_stream_new_from_data(xpm_str.c_str(), -1,
+                                                       nullptr);
+    auto retval =
+        gdk_pixbuf_new_from_stream(G_INPUT_STREAM(gstream), nullptr, &err);
+    g_object_unref(gstream);
+
+    if (!retval && err)
+        PERR("Failed to create pixbuf from XPM data: %s", err->message);
 
     return retval;
 }
diff --git a/gnucash/import-export/test/gtest-import-backend.cpp b/gnucash/import-export/test/gtest-import-backend.cpp
index 9a055b0f6d..cca303c106 100644
--- a/gnucash/import-export/test/gtest-import-backend.cpp
+++ b/gnucash/import-export/test/gtest-import-backend.cpp
@@ -324,3 +324,13 @@ TEST_F(ImportBackendBayesTest, CreateTransInfo)
     // delete transaction info
     gnc_import_TransInfo_delete(trans_info);
 };
+
+TEST_F(ImportBackendBayesTest, gen_probability_pixbuf_test)
+{
+    auto settings = gnc_import_Settings_new();
+    GObject parent;
+    auto pixbuf = gen_probability_pixbuf(8, settings, (GtkWidget*)&parent);
+    EXPECT_NE(pixbuf, nullptr);
+    g_object_unref(pixbuf);
+    g_free(settings);
+}



Summary of changes:
 gnucash/import-export/import-backend.cpp           | 23 +++++++++++++++++++---
 .../import-export/test/gtest-import-backend.cpp    | 10 ++++++++++
 2 files changed, 30 insertions(+), 3 deletions(-)



More information about the gnucash-changes mailing list