[gtk+] gtk-demo: Load icon from resource



commit 75937d925cb216a20a7753597d3c8b63d43ebe3e
Author: Benjamin Otte <otte redhat com>
Date:   Fri Feb 1 14:46:13 2013 +0100

    gtk-demo: Load icon from resource

 demos/gtk-demo/demo.gresource.xml |    9 +++---
 demos/gtk-demo/main.c             |   55 +++++++------------------------------
 2 files changed, 15 insertions(+), 49 deletions(-)
---
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index 6cad4d7..752bf04 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -1,5 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
+  <gresource prefix="/">
+    <file>cssview.css</file>
+    <file>gtk-logo-rgb.gif</file>
+    <file>reset.css</file>
+  </gresource>
   <gresource prefix="/application">
     <file preprocess="to-pixdata">gtk-logo-24.png</file>
     <file preprocess="to-pixdata">gtk-logo-48.png</file>
@@ -9,10 +14,6 @@
   <gresource prefix="/appwindow">
     <file preprocess="to-pixdata">gtk-logo-rgb.gif</file>
   </gresource>
-  <gresource prefix="/">
-    <file>cssview.css</file>
-    <file>reset.css</file>
-  </gresource>
   <gresource prefix="/builder">
     <file>demo.ui</file>
   </gresource>
diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c
index 74aed4e..d9e090e 100644
--- a/demos/gtk-demo/main.c
+++ b/demos/gtk-demo/main.c
@@ -877,54 +877,19 @@ create_tree (void)
 static void
 setup_default_icon (void)
 {
-  GdkPixbuf *pixbuf;
-  char *filename;
-  GError *err;
+  GdkPixbuf *pixbuf, *transparent;
 
-  err = NULL;
+  pixbuf = gdk_pixbuf_new_from_resource ("/gtk-logo-rgb.gif", NULL);
+  /* We load a resource, so we can guarantee that loading it is successful */
+  g_assert (pixbuf);
 
-  pixbuf = NULL;
-  filename = demo_find_file ("gtk-logo-rgb.gif", &err);
-  if (filename)
-    {
-      pixbuf = gdk_pixbuf_new_from_file (filename, &err);
-      g_free (filename);
-    }
-
-  /* Ignoring this error (passing NULL instead of &err above)
-   * would probably be reasonable for most apps.  We're just
-   * showing off.
-   */
-  if (err)
-    {
-      GtkWidget *dialog;
+  /* The gtk-logo-rgb icon has a white background, make it transparent */
+  transparent = gdk_pixbuf_add_alpha (pixbuf, TRUE, 0xff, 0xff, 0xff);
 
-      dialog = gtk_message_dialog_new (NULL, 0,
-                                       GTK_MESSAGE_ERROR,
-                                       GTK_BUTTONS_CLOSE,
-                                       "Failed to read icon file: %s",
-                                       err->message);
-      g_error_free (err);
-
-      g_signal_connect (dialog, "response",
-                        G_CALLBACK (gtk_widget_destroy), NULL);
-    }
-
-  if (pixbuf)
-    {
-      GList *list;
-      GdkPixbuf *transparent;
-
-      /* The gtk-logo-rgb icon has a white background, make it transparent */
-      transparent = gdk_pixbuf_add_alpha (pixbuf, TRUE, 0xff, 0xff, 0xff);
-
-      list = NULL;
-      list = g_list_append (list, transparent);
-      gtk_window_set_default_icon_list (list);
-      g_list_free (list);
-      g_object_unref (pixbuf);
-      g_object_unref (transparent);
-    }
+  gtk_window_set_default_icon (transparent);
+  
+  g_object_unref (pixbuf);
+  g_object_unref (transparent);
 }
 
 int



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