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); }
/** * pk_package_sack_add_packages_from_file: * @sack: a valid #PkPackageSack instance * @file: a valid package-list file * @error: a %GError to put the error code and message in, or %NULL * * Adds packages from package-list file to a PkPackageSack. * * Return value: %TRUE if there were no errors. * **/ gboolean pk_package_sack_add_packages_from_file (PkPackageSack *sack, GFile *file, GError **error) { GError *error_local = NULL; g_autoptr(GFileInputStream) is = NULL; g_autoptr(GDataInputStream) input = NULL; g_return_val_if_fail (PK_IS_PACKAGE_SACK (sack), FALSE); is = g_file_read (file, NULL, &error_local); if (is == NULL) { g_propagate_error (error, error_local); return FALSE; } input = g_data_input_stream_new (G_INPUT_STREAM (is)); /* read package info file line by line */ while (TRUE) { gchar *line; line = g_data_input_stream_read_line (input, NULL, NULL, NULL); if (line == NULL) break; g_strstrip (line); if (!pk_package_sack_add_packages_from_line (sack, line, error)) return FALSE; } return TRUE; }
static void read_file (GFile *scratch_file) { GInputStream *input_stream; GError *error = NULL; gint i; input_stream = (GInputStream *) g_file_read (scratch_file, NULL, &error); if (!input_stream) { g_printerr ("Failed to open scratch file: %s\n", error->message); return; } for (i = 0; i < FILE_SIZE; i += BUFFER_SIZE) { gchar buffer [BUFFER_SIZE]; gsize bytes_read; if (!g_input_stream_read_all (input_stream, buffer, BUFFER_SIZE, &bytes_read, NULL, &error) || bytes_read < BUFFER_SIZE) { g_printerr ("Failed to read back scratch file: %s\n", error->message); g_input_stream_close (input_stream, NULL, NULL); g_object_unref (input_stream); } } g_object_unref (input_stream); }
static gboolean do_hash_job_incoming (GIOSchedulerJob *job, GCancellable *cancellable, gpointer user_data) { HashingData *hash_data = user_data; EmpathyFTHandler *handler = hash_data->handler; EmpathyFTHandlerPriv *priv = handler->priv; GError *error = NULL; DEBUG ("checking integrity for incoming handler"); /* need to get the stream first */ hash_data->stream = G_INPUT_STREAM (g_file_read (priv->gfile, cancellable, &error)); if (error != NULL) { hash_data->error = error; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" g_io_scheduler_job_send_to_mainloop_async (job, hash_job_done, hash_data, NULL); #pragma GCC diagnostic pop return FALSE; } return do_hash_job (job, cancellable, user_data); }
static gboolean do_hash_job_incoming (GIOSchedulerJob *job, GCancellable *cancellable, gpointer user_data) { HashingData *hash_data = user_data; EmpathyFTHandler *handler = hash_data->handler; EmpathyFTHandlerPriv *priv = GET_PRIV (handler); GError *error = NULL; DEBUG ("checking integrity for incoming handler"); /* need to get the stream first */ hash_data->stream = G_INPUT_STREAM (g_file_read (priv->gfile, cancellable, &error)); if (error != NULL) { hash_data->error = error; g_io_scheduler_job_send_to_mainloop_async (job, hash_job_done, hash_data, NULL); return FALSE; } return do_hash_job (job, cancellable, user_data); }
gboolean _rpmostree_util_update_checksum_from_file (GChecksum *checksum, GFile *src, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; gsize bytes_read; char buf[4096]; gs_unref_object GInputStream *filein = NULL; filein = (GInputStream*)g_file_read (src, cancellable, error); if (!filein) goto out; do { if (!g_input_stream_read_all (filein, buf, sizeof(buf), &bytes_read, cancellable, error)) goto out; g_checksum_update (checksum, (guint8*)buf, bytes_read); } while (bytes_read > 0); ret = TRUE; out: return ret; }
static GdkPixbuf * about_dialog_load_logo (void) { GdkPixbuf *pixbuf = NULL; GFile *file; GInputStream *input; file = gimp_data_directory_file ("images", #ifdef GIMP_UNSTABLE "gimp-devel-logo.png", #else "gimp-logo.png", #endif NULL); input = G_INPUT_STREAM (g_file_read (file, NULL, NULL)); g_object_unref (file); if (input) { pixbuf = gdk_pixbuf_new_from_stream (input, NULL, NULL); g_object_unref (input); } return pixbuf; }
/** * mongo_bson_stream_load_from_file: * @stream: (in): A #MongoBsonStream. * @file: (in): A #GFile containing the BSON stream. * @cancellable: (in) (allow-none): A #GCancellable or %NULL. * @error: (out): A location for a #GError, or %NULL. * * Load a #GFile containing a BSON stream to be used for iterating BSON * documents. * * Returns: %TRUE if successful; otherwise %FALSE and @error is set. */ gboolean mongo_bson_stream_load_from_file (MongoBsonStream *stream, GFile *file, GCancellable *cancellable, GError **error) { MongoBsonStreamPrivate *priv; GFileInputStream *file_stream; g_return_val_if_fail(MONGO_IS_BSON_STREAM(stream), FALSE); g_return_val_if_fail(G_IS_FILE(file), FALSE); g_return_val_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable), FALSE); priv = stream->priv; if (priv->stream || priv->channel) { g_set_error(error, MONGO_BSON_STREAM_ERROR, MONGO_BSON_STREAM_ERROR_ALREADY_LOADED, _("Cannot load stream, one is already loaded.")); return FALSE; } if (!(file_stream = g_file_read(file, cancellable, error))) { return FALSE; } priv->stream = G_INPUT_STREAM(file_stream); return TRUE; }
void sourceview_io_open (SourceviewIO* sio, GFile* file) { GFileInputStream* input_stream; GError* err = NULL; g_return_if_fail (file != NULL); if (sio->file) g_object_unref (sio->file); sio->file = file; g_object_ref (sio->file); set_display_name(sio); input_stream = g_file_read (file, NULL, &err); if (!input_stream) { g_signal_emit_by_name (sio, "open-failed", err); g_error_free (err); return; } sio->read_buffer = g_realloc (sio->read_buffer, READ_SIZE); g_input_stream_read_async (G_INPUT_STREAM (input_stream), sio->read_buffer, READ_SIZE, G_PRIORITY_LOW, sio->cancel, on_read_finished, sio); }
IOChannel::IOChannel(const String& filePath, Type type) : m_path(filePath) , m_type(type) { auto path = WebCore::fileSystemRepresentation(filePath); GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(path.data())); switch (m_type) { case Type::Create: { g_file_delete(file.get(), nullptr, nullptr); m_outputStream = adoptGRef(G_OUTPUT_STREAM(g_file_create(file.get(), static_cast<GFileCreateFlags>(G_FILE_CREATE_PRIVATE), nullptr, nullptr))); ASSERT(m_outputStream); GUniquePtr<char> birthtimeString(g_strdup_printf("%" G_GUINT64_FORMAT, std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()))); g_file_set_attribute_string(file.get(), "xattr::birthtime", birthtimeString.get(), G_FILE_QUERY_INFO_NONE, nullptr, nullptr); break; } case Type::Write: { m_ioStream = adoptGRef(g_file_open_readwrite(file.get(), nullptr, nullptr)); ASSERT(m_ioStream); break; } case Type::Read: m_inputStream = adoptGRef(G_INPUT_STREAM(g_file_read(file.get(), nullptr, nullptr))); ASSERT(m_inputStream); break; } }
/** * Create file stream and set mime type for channel * @param info file info used to determine mime type * @return NS_OK when file stream created successfuly, error code otherwise */ nsresult nsGIOInputStream::DoOpenFile(GFileInfo *info) { GError *error = nullptr; mStream = g_file_read(mHandle, nullptr, &error); if (!mStream) { nsresult rv = MapGIOResult(error); g_warning("Cannot read from file: %s", error->message); g_error_free(error); return rv; } const char * content_type = g_file_info_get_content_type(info); if (content_type) { char *mime_type = g_content_type_get_mime_type(content_type); if (mime_type) { if (strcmp(mime_type, APPLICATION_OCTET_STREAM) != 0) { SetContentTypeOfChannel(mime_type); } g_free(mime_type); } } else { g_warning("Missing content type."); } mBytesRemaining = g_file_info_get_size(info); // Update the content length attribute on the channel. We do this // synchronously without proxying. This hack is not as bad as it looks! mChannel->SetContentLength(mBytesRemaining); return NS_OK; }
static GstylePalette * gstyle_palette_new_from_gpl (GFile *file, GCancellable *cancellable, GError **error) { g_autoptr(GDataInputStream) data_stream = NULL; g_autoptr (GInputStream) stream = NULL; GstylePalette *palette = NULL; g_autofree gchar *palette_name = NULL; g_autofree gchar *id = NULL; GstyleColor *color; gchar *color_name; GdkRGBA rgba; GError *tmp_error = NULL; gint line_count = 1; gboolean has_colors = FALSE; g_assert (G_IS_FILE (file)); if ((stream = G_INPUT_STREAM (g_file_read (file, cancellable, &tmp_error)))) { data_stream = g_data_input_stream_new (stream); if (read_gpl_header (data_stream, &palette_name, &line_count, &tmp_error)) { id = g_strcanon (g_strdup (palette_name), GSTYLE_PALETTE_ID_CHARSET, '_'); palette = g_object_new (GSTYLE_TYPE_PALETTE, "id", id, "name", palette_name, "file", file, NULL); while (read_gpl_color_line (data_stream, &rgba, &color_name, &line_count, &tmp_error)) { has_colors = TRUE; color = gstyle_color_new_from_rgba (color_name, GSTYLE_COLOR_KIND_RGB_HEX6, &rgba); gstyle_palette_add (palette, color, &tmp_error); g_object_unref (color); g_free (color_name); if (tmp_error != NULL) break; } } } if (tmp_error == NULL && !has_colors) { g_autofree gchar *uri = g_file_get_uri (file); g_set_error (&tmp_error, GSTYLE_PALETTE_ERROR, GSTYLE_PALETTE_ERROR_EMPTY, _("%s: palette is empty\n"), uri); } if (tmp_error != NULL) { g_clear_object (&palette); g_propagate_error (error, tmp_error); } return palette; }
static void load_file (GTask *task, MetaBackgroundImage *image, gpointer task_data, GCancellable *cancellable) { GError *error = NULL; GdkPixbuf *pixbuf; GFileInputStream *stream; stream = g_file_read (image->file, NULL, &error); if (stream == NULL) { g_task_return_error (task, error); return; } pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream), NULL, &error); g_object_unref (stream); if (pixbuf == NULL) { g_task_return_error (task, error); return; } g_task_return_pointer (task, pixbuf, (GDestroyNotify) g_object_unref); }
static GList * parse_keyboards (const gchar *path, GError **error) { KeyboardsParseData *data; GMarkupParseContext *pcontext; GFile *file; GFileInputStream *input; GList *keyboards; gboolean retval; file = g_file_new_for_path (path); input = g_file_read (file, NULL, error); g_object_unref (file); if (input == NULL) return NULL; data = keyboards_parse_data_new (); pcontext = g_markup_parse_context_new (&keyboards_parser, 0, data, NULL); retval = parse (pcontext, G_INPUT_STREAM (input), error); g_object_unref (input); g_markup_parse_context_free (pcontext); if (!retval) { keyboards_parse_data_free (data); return NULL; } keyboards = data->keyboards; data->keyboards = NULL; keyboards_parse_data_free (data); return keyboards; }
static guint16 * read_file_to_buffer (const gchar *name, gsize count, GError *e) { GError *error = NULL; guint16 *depth = NULL; GFile *new_file = g_file_new_for_path (name); GFileInputStream *input_stream = g_file_read (new_file, NULL, &error); if (error != NULL) { g_debug ("ERROR: %s", error->message); } else { gsize bread = 0; depth = g_slice_alloc (count); g_input_stream_read_all ((GInputStream *) input_stream, depth, count, &bread, NULL, &error); if (error != NULL) { g_debug ("ERROR: %s", error->message); } } return depth; }
static gboolean parse_symbols (const gchar *path, EekKeyboard *keyboard, GError **error) { SymbolsParseData *data; GMarkupParseContext *pcontext; GFile *file; GFileInputStream *input; gboolean retval; file = g_file_new_for_path (path); input = g_file_read (file, NULL, error); g_object_unref (file); if (input == NULL) return FALSE; data = symbols_parse_data_new (keyboard); pcontext = g_markup_parse_context_new (&symbols_parser, 0, data, NULL); retval = parse (pcontext, G_INPUT_STREAM (input), error); g_markup_parse_context_free (pcontext); g_object_unref (input); if (!retval) { symbols_parse_data_free (data); return FALSE; } symbols_parse_data_free (data); return TRUE; }
static GList * parse_prerequisites (const gchar *path, GError **error) { PrerequisitesParseData *data; GMarkupParseContext *pcontext; GFile *file; GFileInputStream *input; GList *prerequisites; gboolean retval; file = g_file_new_for_path (path); input = g_file_read (file, NULL, error); g_object_unref (file); if (input == NULL) return FALSE; data = prerequisites_parse_data_new (); pcontext = g_markup_parse_context_new (&prerequisites_parser, 0, data, NULL); retval = parse (pcontext, G_INPUT_STREAM (input), error); g_markup_parse_context_free (pcontext); g_object_unref (input); if (!retval) { prerequisites_parse_data_free (data); return NULL; } prerequisites = data->prerequisites; data->prerequisites = NULL; prerequisites_parse_data_free (data); return prerequisites; }
static gboolean dump_data (GFile *file, struct archive *archive, GCancellable *cancellable, GError **error) { char buffer[32*1024]; g_autoptr(GFileInputStream) in = NULL; gssize in_buffer; in = g_file_read (file, cancellable, error); if (in == NULL) return FALSE; while (TRUE) { in_buffer = g_input_stream_read (G_INPUT_STREAM (in), buffer, sizeof (buffer), cancellable, error); if (in_buffer == -1) return FALSE; if (in_buffer == 0) break; if (archive_write_data (archive, buffer, in_buffer) < ARCHIVE_OK) return xdg_app_fail (error, "Can't write tar data"); } return TRUE; }
static gchar *readall(const gchar *path, GError **error) { GFile *f = g_file_new_for_path(path); GFileInputStream *fis = NULL; GFileInfo *info; int len; gchar *ret = NULL; if (!(info = g_file_query_info(f, "standard::*", G_FILE_QUERY_INFO_NONE, NULL, error))) goto cleanup; len = g_file_info_get_size(info); ret = g_new0(gchar, len+1); if (!(fis = g_file_read(f, NULL, error))) goto cleanup; if (!g_input_stream_read_all(G_INPUT_STREAM(fis), ret, len, NULL, NULL, error)) goto cleanup; ret[len] = '\0'; *error = NULL; cleanup: if (*error) { g_free(ret); ret = NULL; } g_object_unref(f); if (fis) g_object_unref(fis); return ret; }
int main (int argc, char **argv) { GConverter *converter; GFile *file; GFileInputStream *file_stream; GInputStream *stream; gchar buf[1024]; gssize bytes; if (argc < 2) { g_printerr ("Usage: test-bz2 FILE\n"); return 1; } file = g_file_new_for_path (argv[1]); file_stream = g_file_read (file, NULL, NULL); converter = G_CONVERTER (yelp_bz2_decompressor_new ()); stream = g_converter_input_stream_new (G_INPUT_STREAM (file_stream), converter); while ((bytes = g_input_stream_read (stream, buf, 1024, NULL, NULL)) > 0) { gchar *out = g_strndup (buf, bytes); puts (out); g_free (out); } return 0; }
static void _configfile (CustomData *data, gboolean writemode) { gchar *filename = g_strdup_printf("file://%s/.4deckradio", g_get_home_dir()); g_print ("config file: %s\n", filename); GFile *file = g_file_new_for_uri (filename); if (TRUE == writemode) { /* Save the last folder locations to ~/.4deckradio */ GString *configstring = g_string_new(""); for (int i=0; i < NUM_PLAYERS; i++) { g_print ("deck %i folder %s\n", i, data[i].last_folder_uri); g_string_append_printf (configstring, "%s\n", data[i].last_folder_uri); } g_file_replace_contents (file, configstring->str, configstring->len, NULL, /* old etag */ FALSE, /* backup */ G_FILE_CREATE_PRIVATE, NULL, /* new etag */ NULL, /* cancellable */ NULL); g_string_free (configstring, TRUE); } else { /* load config file */ GFileInputStream *inputstream = g_file_read (file, NULL, NULL); if (NULL == inputstream) { return; } GDataInputStream *config = g_data_input_stream_new (G_INPUT_STREAM (inputstream)); if (NULL == config) { return; } GError *error = NULL; for (int i = 0; i < NUM_PLAYERS; i++) { gsize length; data[i].last_folder_uri = g_data_input_stream_read_line_utf8(config, &length, NULL, &error); if (NULL != error) { g_print ("Error reading config file: %s\n", error->message); } g_clear_error (&error); g_print ("Will use %s for deck %i\n", data[i].last_folder_uri, i); } g_input_stream_close (G_INPUT_STREAM (config), NULL, NULL); g_input_stream_close (G_INPUT_STREAM (inputstream), NULL, NULL); g_object_unref (config); g_object_unref (inputstream); } g_free (filename); g_object_unref (file); }
/** * camel_stream_vfs_new_with_uri: * @uri: a file uri * @mode: opening mode for the uri file * * Creates a new #CamelStreamVFS corresponding to the named file and mode. * * Returns the new stream, or %NULL on error. **/ CamelStream * camel_stream_vfs_new_with_uri (const char *uri, CamelStreamVFSOpenMethod mode) { GFile *file; GObject *stream; GError *error = NULL; file = g_file_new_for_uri (uri); switch (mode) { case CAMEL_STREAM_VFS_CREATE: stream = G_OBJECT (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error)); break; case CAMEL_STREAM_VFS_APPEND: stream = G_OBJECT (g_file_append_to (file, G_FILE_CREATE_NONE, NULL, &error)); break; case CAMEL_STREAM_VFS_READ: stream = G_OBJECT (g_file_read (file, NULL, &error)); break; default: errno = EINVAL; g_return_val_if_reached (NULL); } g_object_unref (file); if (error) { errno = error->code; g_warning ("%s", error->message); g_error_free (error); return NULL; } return camel_stream_vfs_new_with_stream (stream); }
/** * gdk_texture_new_from_file: * @file: #GFile to load * @error: Return location for an error * * Creates a new texture by loading an image from a file. The file format is * detected automatically. If %NULL is returned, then @error will be set. * * Return value: A newly-created #GdkTexture or %NULL if an error occured. **/ GdkTexture * gdk_texture_new_from_file (GFile *file, GError **error) { GdkTexture *texture; GdkPixbuf *pixbuf; GInputStream *stream; g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); stream = G_INPUT_STREAM (g_file_read (file, NULL, error)); if (stream == NULL) return NULL; pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error); g_object_unref (stream); if (pixbuf == NULL) return NULL; texture = gdk_texture_new_for_pixbuf (pixbuf); g_object_unref (pixbuf); return texture; }
gboolean _ostree_static_delta_part_validate (OstreeRepo *repo, GFile *part_path, guint part_offset, const char *expected_checksum, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; gs_unref_object GInputStream *tmp_in = NULL; gs_free guchar *actual_checksum_bytes = NULL; gs_free gchar *actual_checksum = NULL; tmp_in = (GInputStream*)g_file_read (part_path, cancellable, error); if (!tmp_in) goto out; if (!ot_gio_checksum_stream (tmp_in, &actual_checksum_bytes, cancellable, error)) goto out; actual_checksum = ostree_checksum_from_bytes (actual_checksum_bytes); if (strcmp (actual_checksum, expected_checksum) != 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Checksum mismatch in static delta part %u; expected=%s actual=%s", part_offset, expected_checksum, actual_checksum); goto out; } ret = TRUE; out: return ret; }
GdkPixbuf * eel_gdk_pixbuf_load (const char *uri) { GdkPixbuf *pixbuf; GFile *file; GFileInputStream *stream; g_return_val_if_fail (uri != NULL, NULL); file = g_file_new_for_uri (uri); stream = g_file_read (file, NULL, NULL); g_object_unref (file); if (stream == NULL) { return NULL; } pixbuf = eel_gdk_pixbuf_load_from_stream (G_INPUT_STREAM (stream)); g_object_unref (stream); return pixbuf; }
static gboolean send_files (NstPlugin *plugin, GtkWidget *contact_widget, GList *file_list) { GList *l; for (l = file_list; l != NULL; l = l->next) { // Open file GError *error = NULL; GFile *source = g_file_new_for_commandline_arg (l->data); GFileInputStream *in = g_file_read (source, NULL, &error); if (!in) { handle_error(error, "could not get input stream for file"); g_object_unref (source); return FALSE; } // Read file contents GByteArray *data = g_byte_array_new (); guint8 buffer[1024]; gssize len = g_input_stream_read (G_INPUT_STREAM(in), buffer, 1024, NULL, &error); while (len > 0) { g_byte_array_append (data, buffer, len); len = g_input_stream_read (G_INPUT_STREAM(in), buffer, 1024, NULL, &error); } if (len < 0) { handle_error(error, "could not read file"); g_byte_array_free (data, TRUE); g_object_unref (in); g_object_unref (source); return FALSE; } // XMLRPC request to attach the file to the ticket GValue result; gchar *err = send_xmlrpc(gtk_entry_get_text(GTK_ENTRY(url_field)), "ticket.putAttachment", &result, G_TYPE_INT, strtol(gtk_entry_get_text(GTK_ENTRY(ticket_field)), NULL, 10), G_TYPE_STRING, g_file_get_basename(source), G_TYPE_STRING, gtk_entry_get_text(GTK_ENTRY(description_field)), SOUP_TYPE_BYTE_ARRAY, data, G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID); g_byte_array_free (data, TRUE); g_object_unref (in); if (err) { handle_error(NULL, err); g_free (err); g_object_unref (source); return FALSE; } g_object_unref (source); } return TRUE; }
bool ImageHandler::insertImage(GFile * file, double x, double y) { XOJ_CHECK_TYPE(ImageHandler); GError * err = NULL; GFileInputStream * in = g_file_read(file, NULL, &err); g_object_unref(file); GdkPixbuf * pixbuf = NULL; if (!err) { pixbuf = gdk_pixbuf_new_from_stream(G_INPUT_STREAM(in), NULL, &err); g_input_stream_close(G_INPUT_STREAM(in), NULL, NULL); } else { GtkWidget * dialog = gtk_message_dialog_new((GtkWindow*) *control->getWindow(), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("This image could not be loaded. Error message: %s"), err->message); gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(this->control->getWindow()->getWindow())); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); g_error_free(err); return false; } Image * img = new Image(); img->setX(x); img->setY(y); img->setImage(pixbuf); int width = gdk_pixbuf_get_width(pixbuf); int height = gdk_pixbuf_get_height(pixbuf); gdk_pixbuf_unref(pixbuf); double zoom = 1; PageRef page = view->getPage(); if (x + width > page.getWidth() || y + height > page.getHeight()) { double maxZoomX = (page.getWidth() - x) / width; double maxZoomY = (page.getHeight() - y) / height; if (maxZoomX < maxZoomY) { zoom = maxZoomX; } else { zoom = maxZoomY; } } img->setWidth(width * zoom); img->setHeight(height * zoom); page.getSelectedLayer()->addElement(img); InsertUndoAction * insertUndo = new InsertUndoAction(page, page.getSelectedLayer(), img, view); control->getUndoRedoHandler()->addUndoAction(insertUndo); view->rerenderElement(img); return true; }
static void extract_gibest_hash (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable) { GFile *file = source_object; guint64 buffer[2][CHUNK_N_BYTES/8]; GInputStream *stream = NULL; gssize n_bytes, file_size; GError *error = NULL; guint64 hash = 0; gint i; char *str; ResolveData *resolve_data = task_data; GrlLocalMetadataSourcePriv *priv; priv = GRL_LOCAL_METADATA_SOURCE_GET_PRIVATE (resolve_data->source); stream = G_INPUT_STREAM (g_file_read (file, cancellable, &error)); if (stream == NULL) goto fail; /* Extract start/end chunks of the file */ n_bytes = g_input_stream_read (stream, buffer[0], CHUNK_N_BYTES, cancellable, &error); if (n_bytes == -1) goto fail; if (!g_seekable_seek (G_SEEKABLE (stream), -CHUNK_N_BYTES, G_SEEK_END, cancellable, &error)) goto fail; n_bytes = g_input_stream_read (stream, buffer[1], CHUNK_N_BYTES, cancellable, &error); if (n_bytes == -1) goto fail; for (i = 0; i < G_N_ELEMENTS (buffer[0]); i++) hash += buffer[0][i] + buffer[1][i]; file_size = g_seekable_tell (G_SEEKABLE (stream)); if (file_size < CHUNK_N_BYTES) goto fail; /* Include file size */ hash += file_size; g_object_unref (stream); str = g_strdup_printf ("%" G_GINT64_FORMAT, hash); grl_data_set_string (GRL_DATA (resolve_data->rs->media), priv->hash_keyid, str); g_free (str); g_task_return_boolean (task, TRUE); return; fail: GRL_DEBUG ("Could not get file hash: %s\n", error ? error->message : "Unknown error"); g_task_return_error (task, error); g_clear_object (&stream); }
/* send a chunk of the file from server to client */ static int clipboard_send_file_data(int streamId, int lindex, int nPositionLow, int cbRequested) { struct stream *s; int size; int rv; int fd; char full_fn[256]; struct cb_file_info *cfi; if (g_files_list == 0) { LLOGLN(10, ("clipboard_send_file_data: error g_files_list is nil")); return 1; } cfi = (struct cb_file_info *)list_get_item(g_files_list, lindex); if (cfi == 0) { LLOGLN(10, ("clipboard_send_file_data: error cfi is nil")); return 1; } LLOGLN(10, ("clipboard_send_file_data: streamId %d lindex %d " "nPositionLow %d cbRequested %d", streamId, lindex, nPositionLow, cbRequested)); g_snprintf(full_fn, 255, "%s/%s", cfi->pathname, cfi->filename); fd = g_file_open_ex(full_fn, 1, 0, 0, 0); if (fd == -1) { LLOGLN(0, ("clipboard_send_file_data: file open [%s] failed", full_fn)); return 1; } g_file_seek(fd, nPositionLow); make_stream(s); init_stream(s, cbRequested + 64); size = g_file_read(fd, s->data + 12, cbRequested); if (size < 1) { LLOGLN(0, ("clipboard_send_file_data: read error, want %d got %d", cbRequested, size)); free_stream(s); g_file_close(fd); return 1; } out_uint16_le(s, CB_FILECONTENTS_RESPONSE); /* 9 */ out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */ out_uint32_le(s, size + 4); out_uint32_le(s, streamId); s->p += size; out_uint32_le(s, 0); s_mark_end(s); size = (int)(s->end - s->data); rv = send_channel_data(g_cliprdr_chan_id, s->data, size); free_stream(s); g_file_close(fd); return rv; }
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; }