]> Pileus Git - ~andy/gtk/commitdiff
gtk-demo: Load icon from resource
authorBenjamin Otte <otte@redhat.com>
Fri, 1 Feb 2013 13:46:13 +0000 (14:46 +0100)
committerBenjamin Otte <otte@redhat.com>
Fri, 1 Feb 2013 16:42:45 +0000 (17:42 +0100)
demos/gtk-demo/demo.gresource.xml
demos/gtk-demo/main.c

index 6cad4d7e0cc76c8dee745fe6c197dcf5080931dd..752bf0498b29a1fcc7bc6519ef7e7a44f7a038a0 100644 (file)
@@ -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>
index 74aed4edcd554e15e557b3cbe43a960bcaa5b8d6..d9e090eb917427a56a350c45c15bff097d92d4d8 100644 (file)
@@ -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