Пример #1
0
static GFileInputStream *
g_resource_file_read (GFile         *file,
		      GCancellable  *cancellable,
		      GError       **error)
{
  GResourceFile *resource = G_RESOURCE_FILE (file);
  GError *my_error = NULL;
  GInputStream *stream;
  GFileInputStream *res;

  stream = g_resources_open_stream (resource->path, 0, &my_error);

  if (stream == NULL)
    {
      if (g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
	{
	  g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
		       _("The resource at '%s' does not exist"),
		       resource->path);
	}
      else
	g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                             my_error->message);
      g_clear_error (&my_error);
      return NULL;
    }

  res = _g_resource_file_input_stream_new (stream, file);
  g_object_unref (stream);
  return res;
}
Пример #2
0
static GdkPixbuf *
nemo_get_thumbnail_frame (void)
{
	static GdkPixbuf *thumbnail_frame = NULL;

	if (thumbnail_frame == NULL) {
		GInputStream *stream = g_resources_open_stream ("/org/nemo/icons/thumbnail_frame.png", 0, NULL);
		if (stream != NULL) {
			thumbnail_frame = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
			g_object_unref (stream);
		}
	}
	
	return thumbnail_frame;
}
static GInputStream *
tmpl_template_locator_locate_in_path (TmplTemplateLocator *self,
                                      const gchar         *path_base,
                                      const gchar         *path)
{
  GInputStream *ret = NULL;
  gchar *full_path;

  g_assert (TMPL_IS_TEMPLATE_LOCATOR (self));
  g_assert (path_base != NULL);
  g_assert (path != NULL);

  full_path = g_build_path (path_base, path, NULL);

  if (g_str_has_prefix (full_path, "resource://"))
    {
      /*
       * A mediocre attempt to prevent escapes using ../
       */
      if (strstr (full_path, "..") == NULL)
        ret = g_resources_open_stream (full_path + strlen ("resource://"), 0, NULL);
    }
  else
    {
      GFile *parent = g_file_new_for_path (path_base);
      GFile *file = g_file_new_for_path (full_path);
      gchar *relative;

      /*
       * If the path tries to escape the search path, using ../../ or
       * something clever, we will get an invalid path here.
       */
      if ((relative = g_file_get_relative_path (parent, file)))
        {
          g_free (relative);
          ret = (GInputStream *)g_file_read (file, NULL, NULL);
        }

      g_object_unref (parent);
      g_object_unref (file);
    }

  g_free (full_path);

  return ret;
}
Пример #4
0
static void
fr_application_register_archive_manager_service (FrApplication *self)
{
	gsize         size;
	guchar       *buffer;
	GInputStream *stream;
	gsize         bytes_read;
	GError       *error = NULL;

	g_application_hold (G_APPLICATION (self));

	g_resources_get_info (ORG_GNOME_ARCHIVEMANAGER_XML, 0, &size, NULL, NULL);
	buffer = g_new (guchar, size + 1);
	stream = g_resources_open_stream (ORG_GNOME_ARCHIVEMANAGER_XML, 0, NULL);
	if (g_input_stream_read_all (stream, buffer, size, &bytes_read, NULL, NULL)) {
		buffer[bytes_read] = '\0';

		self->introspection_data = g_dbus_node_info_new_for_xml ((gchar *) buffer, &error);
		if (self->introspection_data != NULL) {
			self->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
							 "org.gnome.ArchiveManager1",
							 G_BUS_NAME_OWNER_FLAGS_NONE,
							 on_bus_acquired_for_archive_manager,
							 NULL /*on_name_acquired*/,
							 NULL /*on_name_lost*/,
							 self,
							 NULL);
		}
		else {
			g_warning ("%s", error->message);
			g_clear_error (&error);
		}
	}

	g_timeout_add_seconds (SERVICE_TIMEOUT, service_timeout_cb, self);

	g_free (buffer);
}
Пример #5
0
static void
ephy_resource_request_cb (WebKitURISchemeRequest *request)
{
  const char *path;
  GInputStream *stream;
  gsize size;
  GError *error = NULL;

  path = webkit_uri_scheme_request_get_path (request);
  if (!g_resources_get_info (path, 0, &size, NULL, &error)) {
    webkit_uri_scheme_request_finish_error (request, error);
    g_error_free (error);
    return;
  }

  stream = g_resources_open_stream (path, 0, &error);
  if (stream) {
    webkit_uri_scheme_request_finish (request, stream, size, NULL);
    g_object_unref (stream);
  } else {
    webkit_uri_scheme_request_finish_error (request, error);
    g_error_free (error);
  }
}
Пример #6
0
Файл: images.c Проект: GNOME/gtk
static gint
progressive_timeout (gpointer data)
{
  GtkWidget *picture;

  picture = GTK_WIDGET (data);

  /* This shows off fully-paranoid error handling, so looks scary.
   * You could factor out the error handling code into a nice separate
   * function to make things nicer.
   */

  if (image_stream)
    {
      gssize bytes_read;
      guchar buf[256];
      GError *error = NULL;

      bytes_read = g_input_stream_read (image_stream, buf, 256, NULL, &error);

      if (bytes_read < 0)
        {
          GtkWidget *dialog;

          dialog = gtk_message_dialog_new (GTK_WINDOW (window),
                                           GTK_DIALOG_DESTROY_WITH_PARENT,
                                           GTK_MESSAGE_ERROR,
                                           GTK_BUTTONS_CLOSE,
                                           "Failure reading image file 'alphatest.png': %s",
                                           error->message);
          g_error_free (error);

          g_signal_connect (dialog, "response",
                            G_CALLBACK (gtk_widget_destroy), NULL);

          g_object_unref (image_stream);
          image_stream = NULL;

          gtk_widget_show (dialog);

          load_timeout = 0;

          return FALSE; /* uninstall the timeout */
        }

      if (!gdk_pixbuf_loader_write (pixbuf_loader,
                                    buf, bytes_read,
                                    &error))
        {
          GtkWidget *dialog;

          dialog = gtk_message_dialog_new (GTK_WINDOW (window),
                                           GTK_DIALOG_DESTROY_WITH_PARENT,
                                           GTK_MESSAGE_ERROR,
                                           GTK_BUTTONS_CLOSE,
                                           "Failed to load image: %s",
                                           error->message);

          g_error_free (error);

          g_signal_connect (dialog, "response",
                            G_CALLBACK (gtk_widget_destroy), NULL);

          g_object_unref (image_stream);
          image_stream = NULL;

          gtk_widget_show (dialog);

          load_timeout = 0;

          return FALSE; /* uninstall the timeout */
        }

      if (bytes_read == 0)
        {
          /* Errors can happen on close, e.g. if the image
           * file was truncated we'll know on close that
           * it was incomplete.
           */
          error = NULL;
          if (!g_input_stream_close (image_stream, NULL, &error))
            {
              GtkWidget *dialog;

              dialog = gtk_message_dialog_new (GTK_WINDOW (window),
                                               GTK_DIALOG_DESTROY_WITH_PARENT,
                                               GTK_MESSAGE_ERROR,
                                               GTK_BUTTONS_CLOSE,
                                               "Failed to load image: %s",
                                               error->message);

              g_error_free (error);

              g_signal_connect (dialog, "response",
                                G_CALLBACK (gtk_widget_destroy), NULL);

              gtk_widget_show (dialog);

              g_object_unref (image_stream);
              image_stream = NULL;
              g_object_unref (pixbuf_loader);
              pixbuf_loader = NULL;

              load_timeout = 0;

              return FALSE; /* uninstall the timeout */
            }

          g_object_unref (image_stream);
          image_stream = NULL;

          /* Errors can happen on close, e.g. if the image
           * file was truncated we'll know on close that
           * it was incomplete.
           */
          error = NULL;
          if (!gdk_pixbuf_loader_close (pixbuf_loader,
                                        &error))
            {
              GtkWidget *dialog;

              dialog = gtk_message_dialog_new (GTK_WINDOW (window),
                                               GTK_DIALOG_DESTROY_WITH_PARENT,
                                               GTK_MESSAGE_ERROR,
                                               GTK_BUTTONS_CLOSE,
                                               "Failed to load image: %s",
                                               error->message);

              g_error_free (error);

              g_signal_connect (dialog, "response",
                                G_CALLBACK (gtk_widget_destroy), NULL);

              gtk_widget_show (dialog);

              g_object_unref (pixbuf_loader);
              pixbuf_loader = NULL;

              load_timeout = 0;

              return FALSE; /* uninstall the timeout */
            }

          g_object_unref (pixbuf_loader);
          pixbuf_loader = NULL;
        }
    }
  else
    {
      GError *error = NULL;

      image_stream = g_resources_open_stream ("/images/alphatest.png", 0, &error);

      if (image_stream == NULL)
        {
          GtkWidget *dialog;

          dialog = gtk_message_dialog_new (GTK_WINDOW (window),
                                           GTK_DIALOG_DESTROY_WITH_PARENT,
                                           GTK_MESSAGE_ERROR,
                                           GTK_BUTTONS_CLOSE,
                                           "%s", error->message);
          g_error_free (error);

          g_signal_connect (dialog, "response",
                            G_CALLBACK (gtk_widget_destroy), NULL);

          gtk_widget_show (dialog);

          load_timeout = 0;

          return FALSE; /* uninstall the timeout */
        }

      if (pixbuf_loader)
        {
          gdk_pixbuf_loader_close (pixbuf_loader, NULL);
          g_object_unref (pixbuf_loader);
        }

      pixbuf_loader = gdk_pixbuf_loader_new ();

      g_signal_connect (pixbuf_loader, "area-prepared",
                        G_CALLBACK (progressive_prepared_callback), picture);

      g_signal_connect (pixbuf_loader, "area-updated",
                        G_CALLBACK (progressive_updated_callback), picture);
    }

  /* leave timeout installed */
  return TRUE;
}