gtk-demo: Port images example to resources
This commit is contained in:
		@ -53,6 +53,11 @@
 | 
				
			|||||||
    <file preprocess="to-pixdata">gnome-fs-directory.png</file>
 | 
					    <file preprocess="to-pixdata">gnome-fs-directory.png</file>
 | 
				
			||||||
    <file preprocess="to-pixdata">gnome-fs-regular.png</file>
 | 
					    <file preprocess="to-pixdata">gnome-fs-regular.png</file>
 | 
				
			||||||
  </gresource>
 | 
					  </gresource>
 | 
				
			||||||
 | 
					  <gresource prefix="/images">
 | 
				
			||||||
 | 
					    <file>alphatest.png</file>
 | 
				
			||||||
 | 
					    <file>floppybuddy.gif</file>
 | 
				
			||||||
 | 
					    <file>gtk-logo-rgb.gif</file>
 | 
				
			||||||
 | 
					  </gresource>
 | 
				
			||||||
  <gresource prefix="/sources">
 | 
					  <gresource prefix="/sources">
 | 
				
			||||||
    <file>application.c</file>
 | 
					    <file>application.c</file>
 | 
				
			||||||
    <file>appwindow.c</file>
 | 
					    <file>appwindow.c</file>
 | 
				
			||||||
 | 
				
			|||||||
@ -214,22 +214,9 @@ progressive_timeout (gpointer data)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      gchar *filename;
 | 
					 | 
				
			||||||
      GError *error = NULL;
 | 
					      GError *error = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /* demo_find_file() looks in the current directory first,
 | 
					      image_stream = g_resources_open_stream ("/images/alphatest.png", 0, &error);
 | 
				
			||||||
       * so you can run gtk-demo without installing GTK, then looks
 | 
					 | 
				
			||||||
       * in the location where the file is installed.
 | 
					 | 
				
			||||||
       */
 | 
					 | 
				
			||||||
      filename = demo_find_file ("alphatest.png", &error);
 | 
					 | 
				
			||||||
      if (error == NULL)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
          GFile *file = g_file_new_for_path (filename);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          image_stream = G_INPUT_STREAM (g_file_read (file, NULL, &error));
 | 
					 | 
				
			||||||
          g_object_unref (file);
 | 
					 | 
				
			||||||
          g_free (filename);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (image_stream == NULL)
 | 
					      if (image_stream == NULL)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@ -345,8 +332,6 @@ do_images (GtkWidget *do_widget)
 | 
				
			|||||||
  GtkWidget *button;
 | 
					  GtkWidget *button;
 | 
				
			||||||
  GdkPixbuf *pixbuf;
 | 
					  GdkPixbuf *pixbuf;
 | 
				
			||||||
  GIcon     *gicon;
 | 
					  GIcon     *gicon;
 | 
				
			||||||
  GError *error = NULL;
 | 
					 | 
				
			||||||
  char *filename;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!window)
 | 
					  if (!window)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -377,41 +362,9 @@ do_images (GtkWidget *do_widget)
 | 
				
			|||||||
      gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
 | 
					      gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
 | 
				
			||||||
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
 | 
					      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /* demo_find_file() looks in the current directory first,
 | 
					      pixbuf = gdk_pixbuf_new_from_resource ("/images/gtk-logo-rgb.gif", NULL);
 | 
				
			||||||
       * so you can run gtk-demo without installing GTK, then looks
 | 
					      /* The image loading must work, we ensure that the resources are valid. */
 | 
				
			||||||
       * in the location where the file is installed.
 | 
					      g_assert (pixbuf);
 | 
				
			||||||
       */
 | 
					 | 
				
			||||||
      pixbuf = NULL;
 | 
					 | 
				
			||||||
      filename = demo_find_file ("gtk-logo-rgb.gif", &error);
 | 
					 | 
				
			||||||
      if (filename)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
          pixbuf = gdk_pixbuf_new_from_file (filename, &error);
 | 
					 | 
				
			||||||
          g_free (filename);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (error)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
          /* This code shows off error handling. You can just use
 | 
					 | 
				
			||||||
           * gtk_image_new_from_file() instead if you don't want to report
 | 
					 | 
				
			||||||
           * errors to the user. If the file doesn't load when using
 | 
					 | 
				
			||||||
           * gtk_image_new_from_file(), a "missing image" icon will
 | 
					 | 
				
			||||||
           * be displayed instead.
 | 
					 | 
				
			||||||
           */
 | 
					 | 
				
			||||||
          GtkWidget *dialog;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          dialog = gtk_message_dialog_new (GTK_WINDOW (window),
 | 
					 | 
				
			||||||
                                           GTK_DIALOG_DESTROY_WITH_PARENT,
 | 
					 | 
				
			||||||
                                           GTK_MESSAGE_ERROR,
 | 
					 | 
				
			||||||
                                           GTK_BUTTONS_CLOSE,
 | 
					 | 
				
			||||||
                                           "Unable to open image file 'gtk-logo-rgb.gif': %s",
 | 
					 | 
				
			||||||
                                           error->message);
 | 
					 | 
				
			||||||
          g_error_free (error);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          g_signal_connect (dialog, "response",
 | 
					 | 
				
			||||||
                            G_CALLBACK (gtk_widget_destroy), NULL);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          gtk_widget_show (dialog);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      image = gtk_image_new_from_pixbuf (pixbuf);
 | 
					      image = gtk_image_new_from_pixbuf (pixbuf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -431,9 +384,7 @@ do_images (GtkWidget *do_widget)
 | 
				
			|||||||
      gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
 | 
					      gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
 | 
				
			||||||
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
 | 
					      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      filename = demo_find_file ("floppybuddy.gif", NULL);
 | 
					      image = gtk_image_new_from_resource ("/images/floppybuddy.gif");
 | 
				
			||||||
      image = gtk_image_new_from_file (filename);
 | 
					 | 
				
			||||||
      g_free (filename);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      gtk_container_add (GTK_CONTAINER (frame), image);
 | 
					      gtk_container_add (GTK_CONTAINER (frame), image);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -455,8 +406,8 @@ do_images (GtkWidget *do_widget)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      gtk_container_add (GTK_CONTAINER (frame), image);
 | 
					      gtk_container_add (GTK_CONTAINER (frame), image);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /* Progressive */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      /* Progressive */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      label = gtk_label_new (NULL);
 | 
					      label = gtk_label_new (NULL);
 | 
				
			||||||
      gtk_label_set_markup (GTK_LABEL (label),
 | 
					      gtk_label_set_markup (GTK_LABEL (label),
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user