static int64_t ddb_gvfs_getlength (DB_FILE *stream) { vfs_gvfs_data_t *data = (vfs_gvfs_data_t *) stream; g_return_val_if_fail (data != NULL, -1); g_return_val_if_fail (! g_input_stream_is_closed (data->handle), -1); GError *error = NULL; GFileInfo *info; info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM(data->handle), G_FILE_ATTRIBUTE_STANDARD_SIZE, NULL, &error); if (info == NULL) { g_warning ("Could not read stream info: %s", error->message); g_error_free (error); return -1; } gint64 size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE); g_object_unref (info); return size; }
static void trash_backend_query_info_on_read (GVfsBackend *backend, GVfsJobQueryInfoRead *job, GVfsBackendHandle handle, GFileInfo *info, GFileAttributeMatcher *matcher) { GError *error = NULL; GFileInfo *real_info; real_info = g_file_input_stream_query_info (handle, job->attributes, G_VFS_JOB (job)->cancellable, &error); if (real_info) { g_file_info_copy_into (real_info, info); g_vfs_job_succeeded (G_VFS_JOB (job)); g_object_unref (real_info); } else { g_vfs_job_failed_from_error (G_VFS_JOB (job), error); g_error_free (error); } }
static gpointer stlink_gui_populate_filemem_view (STlinkGUI *gui) { guchar buffer[MEM_READ_SIZE]; GFile *file; GFileInfo *file_info; GInputStream *input_stream; gint off; GError *err = NULL; g_return_val_if_fail (gui != NULL, NULL); g_return_val_if_fail (gui->filename != NULL, NULL); file = g_file_new_for_path (gui->filename); input_stream = G_INPUT_STREAM (g_file_read (file, NULL, &err)); if (err) { stlink_gui_set_info_error_message (gui, err->message); g_error_free (err); goto out; } file_info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (input_stream), G_FILE_ATTRIBUTE_STANDARD_SIZE, NULL, &err); if (err) { stlink_gui_set_info_error_message (gui, err->message); g_error_free (err); goto out_input; } if (gui->file_mem.memory) { g_free (gui->file_mem.memory); } gui->file_mem.size = g_file_info_get_size (file_info); gui->file_mem.memory = g_malloc (gui->file_mem.size); for (off = 0; off < gui->file_mem.size; off += MEM_READ_SIZE) { guint n_read = MEM_READ_SIZE; if (off + MEM_READ_SIZE > gui->file_mem.size) { n_read = gui->file_mem.size - off; } if (g_input_stream_read (G_INPUT_STREAM (input_stream), &buffer, n_read, NULL, &err) == -1) { stlink_gui_set_info_error_message (gui, err->message); g_error_free (err); goto out_input; } memcpy (gui->file_mem.memory + off, buffer, n_read); gui->progress.fraction = (gdouble) (off + n_read) / gui->file_mem.size; } g_idle_add ((GSourceFunc) stlink_gui_update_filemem_view, gui); out_input: g_object_unref (input_stream); out: g_object_unref (file); return NULL; }
static GInputStream * rsvg_acquire_gvfs_stream (const char *uri, const char *base_uri, char **out_mime_type, GCancellable *cancellable, GError **error) { GFile *base, *file; GFileInputStream *stream; GError *err = NULL; file = g_file_new_for_uri (uri); stream = g_file_read (file, cancellable, &err); g_object_unref (file); if (stream == NULL && g_error_matches (err, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_clear_error (&err); base = g_file_new_for_uri (base_uri); file = g_file_resolve_relative_path (base, uri); g_object_unref (base); stream = g_file_read (file, cancellable, &err); g_object_unref (file); } if (stream == NULL) { g_propagate_error (error, err); return NULL; } if (out_mime_type) { GFileInfo *file_info; const char *content_type; file_info = g_file_input_stream_query_info (stream, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, cancellable, NULL /* error */); if (file_info && (content_type = g_file_info_get_content_type (file_info))) *out_mime_type = g_content_type_get_mime_type (content_type); else *out_mime_type = NULL; if (file_info) g_object_unref (file_info); } return G_INPUT_STREAM (stream); }
/** * ev_document_factory_get_document_for_stream: * @stream: a #GInputStream * @mime_type: (allow-none): a mime type hint * @flags: flags from #EvDocumentLoadFlags * @cancellable: (allow-none): a #GCancellable, or %NULL * @error: (allow-none): a #GError location to store an error, or %NULL * * Synchronously creates a #EvDocument for the document from @stream; or, if no * backend handling the document's type is found, or an error occurred * on opening the document, returns %NULL and fills in @error. * If the document is encrypted, it is returned but also @error is set to * %EV_DOCUMENT_ERROR_ENCRYPTED. * * If @mime_type is non-%NULL, this overrides any type inferred from the stream. * If the mime type cannot be inferred from the stream, and @mime_type is %NULL, * an error is returned. * * Returns: (transfer full): a new #EvDocument, or %NULL * * Since: 3.6 */ EvDocument* ev_document_factory_get_document_for_stream (GInputStream *stream, const char *mime_type, EvDocumentLoadFlags flags, GCancellable *cancellable, GError **error) { EvDocument *document; char *mime = NULL; g_return_val_if_fail (G_IS_INPUT_STREAM (stream), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); if (mime_type == NULL && G_IS_FILE_INPUT_STREAM (stream)) { GFileInfo *file_info; const char *content_type; file_info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (stream), G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, cancellable, error); if (file_info != NULL) { content_type = g_file_info_get_content_type (file_info); if (content_type) mime_type = mime = g_content_type_get_mime_type (content_type); g_object_unref (file_info); } } if (mime_type == NULL) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Cannot query mime type from stream"); return NULL; } document = ev_document_factory_new_document_for_mime_type (mime_type, error); g_free (mime); if (document == NULL) return NULL; if (!ev_document_load_stream (document, stream, flags, cancellable, error)) { g_object_unref (document); return NULL; } return document; }
static VALUE rg_query_info(int argc, VALUE *argv, VALUE self) { VALUE attributes, cancellable; GError *error = NULL; GFileInfo *info; rb_scan_args(argc, argv, "02", &attributes, &cancellable); info = g_file_input_stream_query_info(_SELF(self), RVAL2ATTRIBUTESDEFAULT(attributes), RVAL2GCANCELLABLE(cancellable), &error); if (info == NULL) rbgio_raise_error(error); return GOBJ2RVAL_UNREF(info); }
static gboolean get_etag_from_file_input_stream (GFileInputStream *stream, char **etag, GCancellable *cancellable, GError **error) { GFileInfo *info; info = g_file_input_stream_query_info (stream, G_FILE_ATTRIBUTE_ETAG_VALUE, cancellable, error); if (!info) return FALSE; if (etag) *etag = g_strdup (g_file_info_get_etag (info)); g_object_unref (info); return TRUE; }
static gboolean gst_split_file_src_start (GstBaseSrc * basesrc) { GstSplitFileSrc *src = GST_SPLIT_FILE_SRC (basesrc); GCancellable *cancel; gboolean ret = FALSE; guint64 offset; GError *err = NULL; gchar *basename = NULL; gchar *dirname = NULL; gchar **files; guint i; GST_OBJECT_LOCK (src); if (src->location != NULL && src->location[0] != '\0') { basename = g_path_get_basename (src->location); dirname = g_path_get_dirname (src->location); } GST_OBJECT_UNLOCK (src); files = gst_split_file_src_find_files (src, dirname, basename, &err); if (files == NULL || *files == NULL) goto no_files; src->num_parts = g_strv_length (files); src->parts = g_new0 (GstFilePart, src->num_parts); cancel = src->cancellable; offset = 0; for (i = 0; i < src->num_parts; ++i) { GFileInputStream *stream; GFileInfo *info; goffset size; GFile *file; file = g_file_new_for_path (files[i]); stream = g_file_read (file, cancel, &err); g_object_unref (file); if (err != NULL) goto open_read_error; info = g_file_input_stream_query_info (stream, "standard::*", NULL, &err); if (err != NULL) { g_object_unref (stream); goto query_info_error; } size = g_file_info_get_size (info); g_object_unref (info); src->parts[i].stream = stream; src->parts[i].path = g_strdup (files[i]); src->parts[i].start = offset; src->parts[i].stop = offset + size - 1; GST_DEBUG ("[%010" G_GUINT64_FORMAT "-%010" G_GUINT64_FORMAT "] %s", src->parts[i].start, src->parts[i].stop, src->parts[i].path); offset += size; } GST_INFO ("Successfully opened %u file parts for reading", src->num_parts); src->cur_part = 0; src->cancellable = g_cancellable_new (); ret = TRUE; done: if (err != NULL) g_error_free (err); g_strfreev (files); g_free (basename); g_free (dirname); return ret; /* ERRORS */ no_files: { if (err->code == G_IO_ERROR_CANCELLED) goto cancelled; GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, ("%s", err->message), ("Failed to find files in '%s' for pattern '%s'", GST_STR_NULL (dirname), GST_STR_NULL (basename))); goto done; } open_read_error: { if (err->code == G_IO_ERROR_CANCELLED) goto cancelled; GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, ("%s", err->message), ("Failed to open file '%s' for reading", files[i])); goto done; } query_info_error: { if (err->code == G_IO_ERROR_CANCELLED) goto cancelled; GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, ("%s", err->message), ("Failed to query info for file '%s'", files[i])); goto done; } cancelled: { GST_DEBUG_OBJECT (src, "I/O operation cancelled from another thread"); goto done; } }
static gboolean xmms_gvfs_init (xmms_xform_t *xform) { xmms_gvfs_data_t *data; GFile *file; GFileInfo *info; GFileInputStream *handle; GError *error = NULL; const gchar *url; url = xmms_xform_indata_get_str (xform, XMMS_STREAM_TYPE_URL); g_return_val_if_fail (url, FALSE); /* This is an ugly hack to handle files with chars needing url encoding */ if (!g_ascii_strncasecmp (url, "file://", 7)) { file = g_file_new_for_path (url+7); } else { file = g_file_new_for_uri (url); } handle = g_file_read (file, NULL, &error); g_object_unref (file); if (!handle) { xmms_log_error ("Failed to upen url %s for reading: %s", url, error->message); return FALSE; } data = g_new (xmms_gvfs_data_t, 1); data->handle = G_INPUT_STREAM (handle); xmms_xform_private_data_set (xform, data); info = g_file_input_stream_query_info (handle, (char *)query_attributes, NULL, &error); if (!info) { xmms_log_info ("failed to query information for %s", url); } else { int i; for (i = 0; i < G_N_ELEMENTS (attr_map); i++) { if (!g_file_info_has_attribute (info, attr_map[i].gvfs)) { continue; } switch (attr_map[i].type) { case XMMSV_TYPE_STRING: { gchar *attr = g_file_info_get_attribute_as_string (info, attr_map[i].gvfs); xmms_xform_metadata_set_str (xform, attr_map[i].mlib, attr); g_free (attr); break; } case XMMSV_TYPE_INT32: { /* right now the xform metadata api only handles strings * and 32 bit ints. however the gvfs api returns uint64 for * the numeric attributes we're interested in and we just * pass that to the xform and pray that it doesn't overflow * as we know it's unsafe. */ gint64 attr = g_file_info_get_attribute_uint64 (info, attr_map[i].gvfs); xmms_xform_metadata_set_int (xform, attr_map[i].mlib, attr); break; } default: g_assert_not_reached (); } } g_object_unref (info); } xmms_xform_outdata_type_add (xform, XMMS_STREAM_TYPE_MIMETYPE, "application/octet-stream", XMMS_STREAM_TYPE_END); return TRUE; }
void Tetris::dragDrop(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, Tetris * t) { const char *fileuri; GError *error = NULL; GFile *file; GFile *outfile; GFileInfo *fileinfo; GFileInputStream *istream; GFileOutputStream *outstream; goffset filesize; gssize bytesread, byteswrote; GdkPixbufLoader *loader; GdkPixbuf *pixbuf; guchar *buffer; /* Accept a dropped filename and try and load it as the background image. In the event of any kind of failure we silently ignore it. */ /* FIXME: We don't handle colour gradients (e.g. from the gimp) */ /* FIXME: Dropped URLs from mozilla don't work (see below). */ if (data->length < 0) { gtk_drag_finish (context, FALSE, FALSE, time); return; } gtk_drag_finish (context, TRUE, FALSE, time); if (info == COLOUR) { if (data->length == 8) decodeColour ((guint16 *)data->data, t); return; } if (info == RESET) { resetColour (t); return; } fileuri = decodeDropData ((char *)data->data, info); /* Silently ignore bad data. */ if (fileuri == NULL) goto error_exit; /* Now that we have a URI we load it and test it to see if it is * an image file. */ file = g_file_new_for_uri (fileuri); istream = g_file_read (file, NULL, &error); if (error) goto error_exit; fileinfo = g_file_input_stream_query_info (istream, (char *)G_FILE_ATTRIBUTE_STANDARD_SIZE, NULL, &error); if (error) goto error_exit_handle; filesize = g_file_info_get_size (fileinfo); buffer = (guchar *)g_malloc (filesize); if (buffer == NULL) goto error_exit_handle; bytesread = g_input_stream_read (G_INPUT_STREAM (istream), buffer, filesize, NULL, &error); /* FIXME: We should reread if not enough was read. */ if (error || (bytesread != filesize)) goto error_exit_buffer; loader = gdk_pixbuf_loader_new (); if (!gdk_pixbuf_loader_write (loader, buffer, filesize, NULL)) goto error_exit_loader; gdk_pixbuf_loader_close (loader, NULL); pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf == NULL) goto error_exit_loader; g_object_ref (pixbuf); /* We now have an image file, in memory, that we know gdk-pixbuf * can handle. Now we save it to disk. This is necessary so that * "slow" URIs (e.g. http) behave well in the long run. */ outfile = g_file_new_for_path (t->bgPixmap); outstream = g_file_replace (outfile, NULL, FALSE, G_FILE_CREATE_PRIVATE, NULL, &error); if (error) goto error_exit_loader; byteswrote = g_output_stream_write (G_OUTPUT_STREAM (outstream), buffer, bytesread, NULL, &error); if (byteswrote != filesize) goto error_exit_saver; t->usebg = TRUE; t->saveBgOptions (); error_exit_saver: g_object_unref(outstream); error_exit_loader: g_object_unref (loader); error_exit_buffer: g_free (buffer); error_exit_handle: g_object_unref(istream); error_exit: if(error) g_error_free(error); return; }
static gboolean gst_gio_base_src_get_size (GstBaseSrc * base_src, guint64 * size) { GstGioBaseSrc *src = GST_GIO_BASE_SRC (base_src); if (G_IS_FILE_INPUT_STREAM (src->stream)) { GFileInfo *info; GError *err = NULL; info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (src->stream), G_FILE_ATTRIBUTE_STANDARD_SIZE, src->cancel, &err); if (info != NULL) { *size = g_file_info_get_size (info); g_object_unref (info); GST_DEBUG_OBJECT (src, "found size: %" G_GUINT64_FORMAT, *size); return TRUE; } if (!gst_gio_error (src, "g_file_input_stream_query_info", &err, NULL)) { if (GST_GIO_ERROR_MATCHES (err, NOT_SUPPORTED)) GST_DEBUG_OBJECT (src, "size information not available"); else GST_WARNING_OBJECT (src, "size information retrieval failed: %s", err->message); g_clear_error (&err); } } if (GST_GIO_STREAM_IS_SEEKABLE (src->stream)) { goffset old; goffset stream_size; gboolean ret; GSeekable *seekable = G_SEEKABLE (src->stream); GError *err = NULL; old = g_seekable_tell (seekable); ret = g_seekable_seek (seekable, 0, G_SEEK_END, src->cancel, &err); if (!ret) { if (!gst_gio_error (src, "g_seekable_seek", &err, NULL)) { if (GST_GIO_ERROR_MATCHES (err, NOT_SUPPORTED)) GST_DEBUG_OBJECT (src, "Seeking to the end of stream is not supported"); else GST_WARNING_OBJECT (src, "Seeking to end of stream failed: %s", err->message); g_clear_error (&err); } else { GST_WARNING_OBJECT (src, "Seeking to end of stream failed"); } return FALSE; } stream_size = g_seekable_tell (seekable); ret = g_seekable_seek (seekable, old, G_SEEK_SET, src->cancel, &err); if (!ret) { if (!gst_gio_error (src, "g_seekable_seek", &err, NULL)) { if (GST_GIO_ERROR_MATCHES (err, NOT_SUPPORTED)) GST_ERROR_OBJECT (src, "Seeking to the old position not supported"); else GST_ERROR_OBJECT (src, "Seeking to the old position failed: %s", err->message); g_clear_error (&err); } else { GST_ERROR_OBJECT (src, "Seeking to the old position faile"); } return FALSE; } if (stream_size >= 0) { *size = stream_size; return TRUE; } } return FALSE; }