static void
on_replace_file_ready (GObject *source, GAsyncResult *res, gpointer user_data)
{
	GcrCertificateExporter *self = GCR_CERTIFICATE_EXPORTER (user_data);
	GFile *file = G_FILE (source);
	GFileOutputStream *os;

	os = g_file_replace_finish (file, res, &self->pv->error);

	if (self->pv->error) {
		complete_async_result (self);
		return;
	}

	write_to_outputstream (self, G_OUTPUT_STREAM (os));
}
    void didReceiveData(ResourceHandle*, const char* data, int length, int /*encodedDataLength*/)
    {
        if (m_handleResponseLaterID) {
            g_source_remove(m_handleResponseLaterID);
            handleResponse();
        }

        gsize bytesWritten;
        GOwnPtr<GError> error;
        g_output_stream_write_all(G_OUTPUT_STREAM(m_outputStream.get()), data, length, &bytesWritten, 0, &error.outPtr());
        if (error) {
            downloadFailed(platformDownloadDestinationError(ResourceResponse(m_response.get()), error->message));
            return;
        }
        m_download->didReceiveData(bytesWritten);
    }
Exemple #3
0
static gssize
g_pollable_output_stream_default_write_nonblocking (GPollableOutputStream  *stream,
						    const void             *buffer,
						    gsize                   count,
						    GError                **error)
{
  if (!g_pollable_output_stream_is_writable (stream))
    {
      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK,
                           g_strerror (EAGAIN));
      return -1;
    }

  return G_OUTPUT_STREAM_GET_CLASS (stream)->
    write_fn (G_OUTPUT_STREAM (stream), buffer, count, NULL, error);
}
/* called in an I/O thread */
static GOutputStream *
get_stream_for_unique_path (const gchar *path,
                            const gchar *filename,
                            gchar **filename_used)
{
  GOutputStream *stream;
  GFile *file;
  gchar *real_path, *real_filename, *name, *ptr;
  gint idx;

  ptr = g_strrstr (filename, ".png");

  if (ptr != NULL)
    real_filename = g_strndup (filename, ptr - filename);
  else
    real_filename = g_strdup (filename);

  idx = 0;
  real_path = NULL;

  do
    {
      if (idx == 0)
        name = g_strdup_printf ("%s.png", real_filename);
      else
        name = g_strdup_printf ("%s - %d.png", real_filename, idx);

      real_path = g_build_filename (path, name, NULL);
      g_free (name);

      file = g_file_new_for_path (real_path);
      stream = G_OUTPUT_STREAM (g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL));
      g_object_unref (file);

      if (stream != NULL)
        *filename_used = real_path;
      else
        g_free (real_path);

      idx++;
    }
  while (stream == NULL);

  g_free (real_filename);

  return stream;
}
Exemple #5
0
static tsize_t
write_to_stream(thandle_t handle,
                tdata_t buffer,
                tsize_t size)
{
  Priv *p = (Priv*) handle;
  GError *error = NULL;
  gchar *new_buffer;
  gsize new_size;
  gssize written = -1;

  g_assert(p->stream);

  if (p->can_seek)
    {
      written = g_output_stream_write(G_OUTPUT_STREAM(p->stream),
                                      (void *) buffer, (gsize) size,
                                      NULL, &error);
      if (written < 0)
        {
          g_warning("%s", error->message);
          g_error_free(error);
        }
    }
  else
    {
      if (p->position + size > p->allocated)
        {
          new_size = p->position + size;
          new_buffer = g_try_realloc(p->buffer, new_size);
          if (!new_buffer)
            return -1;

          p->allocated = new_size;
          p->buffer = new_buffer;
        }

      g_assert(p->position + size >= p->allocated);

      memcpy(p->buffer + p->position, buffer, size);
      p->position += size;
      written = size;
    }

  return (tsize_t) written;
}
static void
cache_splice_ready_cb (GObject *source,
                       GAsyncResult *res,
                       gpointer user_data)
{
  GError *error = NULL;

  g_output_stream_splice_finish (G_OUTPUT_STREAM (source),
                                 res, &error);

  if (error != NULL) {
    g_warning ("Can't save the cover art image in the cache: %s\n", error->message);
    g_error_free (error);

    return;
  }
}
static gboolean
debug_dialog_store_filter_foreach (GtkTreeModel *model,
    GtkTreePath *path,
    GtkTreeIter *iter,
    gpointer user_data)
{
  GFileOutputStream *output_stream = (GFileOutputStream *) user_data;
  gchar *domain, *category, *message, *level_str, *level_upper;
  gdouble timestamp;
  gchar *line;
  GError *error = NULL;
  gboolean out = FALSE;

  gtk_tree_model_get (model, iter,
      COL_DEBUG_TIMESTAMP, &timestamp,
      COL_DEBUG_DOMAIN, &domain,
      COL_DEBUG_CATEGORY, &category,
      COL_DEBUG_LEVEL_STRING, &level_str,
      COL_DEBUG_MESSAGE, &message,
      -1);

  level_upper = g_ascii_strup (level_str, -1);

  line = g_strdup_printf ("%s%s%s-%s: %e: %s\n",
      domain, EMP_STR_EMPTY (category) ? "" : "/",
      category, level_upper, timestamp, message);

  g_output_stream_write (G_OUTPUT_STREAM (output_stream), line,
      strlen (line), NULL, &error);

  if (error != NULL)
    {
      DEBUG ("Failed to write to file: %s", error->message);
      g_error_free (error);
      out = TRUE;
    }

  g_free (line);
  g_free (level_upper);
  g_free (level_str);
  g_free (domain);
  g_free (category);
  g_free (message);

  return out;
}
static void
os_splice_ready_cb (GObject *source,
                    GAsyncResult *res,
                    gpointer user_data)
{
  GError *error = NULL;
  PdfLoadJob *job = user_data;

  g_output_stream_splice_finish (G_OUTPUT_STREAM (source), res, &error);

  if (error != NULL) {
    pdf_load_job_complete_error (job, error);
    return;
  }

  pdf_load_job_cache_set_attributes (job);
}
static gboolean
nice_output_stream_is_writable (GPollableOutputStream *stream)
{
  NiceOutputStreamPrivate *priv = NICE_OUTPUT_STREAM (stream)->priv;
  NiceComponent *component = NULL;
  NiceStream *_stream = NULL;
  gboolean retval = FALSE;
  NiceAgent *agent;  /* owned */

  /* Closed streams are not writeable. */
  if (g_output_stream_is_closed (G_OUTPUT_STREAM (stream)))
    return FALSE;

  /* Has the agent disappeared? */
  agent = g_weak_ref_get (&priv->agent_ref);
  if (agent == NULL)
    return FALSE;

  agent_lock ();

  if (!agent_find_component (agent, priv->stream_id, priv->component_id,
          &_stream, &component)) {
    g_warning ("Could not find component %u in stream %u", priv->component_id,
        priv->stream_id);
    goto done;
  }
  if (component->selected_pair.local != NULL) {
    NiceSocket *sockptr = component->selected_pair.local->sockptr;

    /* If it’s a reliable agent, see if there’s any space in the pseudo-TCP
     * output buffer. */
    if (!nice_socket_is_reliable (sockptr)) {
      retval = pseudo_tcp_socket_can_send (component->tcp);
    } else {
      retval = (g_socket_condition_check (sockptr->fileno, G_IO_OUT) != 0);
    }
  }

done:
  agent_unlock ();

  g_object_unref (agent);

  return retval;
}
static GFile *
create_file (GFile *base_dir)
{
  GFile         *scratch_file;
  gchar         *scratch_name;
  GOutputStream *output_stream;
  gint           pid;
  GError        *error = NULL;
  gchar          buffer [BUFFER_SIZE];
  gint           i;

  pid = getpid ();
  scratch_name = g_strdup_printf ("gvfs-benchmark-scratch-%d", pid);
  scratch_file = g_file_resolve_relative_path (base_dir, scratch_name);
  g_free (scratch_name);

  if (!scratch_file)
    return NULL;

  output_stream = G_OUTPUT_STREAM (g_file_replace (scratch_file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error));
  if (!output_stream)
    {
      g_printerr ("Failed to create scratch file: %s\n", error->message);
      g_object_unref (scratch_file);
      return NULL;
    }

  memset (buffer, 0xaa, BUFFER_SIZE);

  for (i = 0; i < FILE_SIZE; i += BUFFER_SIZE)
    {
      if (g_output_stream_write (output_stream, buffer, BUFFER_SIZE, NULL, &error) < BUFFER_SIZE)
        {
          g_printerr ("Failed to populate scratch file: %s\n", error->message);
          g_output_stream_close (output_stream, NULL, NULL);
          g_object_unref (output_stream);
          g_object_unref (scratch_file);
          return NULL;
        }
    }

  g_output_stream_close (output_stream, NULL, NULL);
  g_object_unref (output_stream);
  return scratch_file;
}
Exemple #11
0
static void
tunnel_wrote_cb (GObject      *object,
		 GAsyncResult *result,
		 gpointer      user_data)
{
	Tunnel *tunnel = user_data;
	TunnelEnd *write_end, *read_end;
	GError *error = NULL;
	gssize nwrote;

	nwrote = g_output_stream_write_finish (G_OUTPUT_STREAM (object), result, &error);
	if (nwrote <= 0) {
		if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
			g_error_free (error);
			return;
		} else if (error) {
			g_print ("Tunnel write failed: %s\n", error->message);
			g_error_free (error);
		}
		tunnel_close (tunnel);
		return;
	}

	if (object == (GObject *)tunnel->client.ostream) {
		write_end = &tunnel->client;
		read_end = &tunnel->server;
	} else {
		write_end = &tunnel->server;
		read_end = &tunnel->client;
	}

	write_end->nwrote += nwrote;
	if (write_end->nwrote < read_end->nread) {
		g_output_stream_write_async (write_end->ostream,
					     read_end->buffer + write_end->nwrote,
					     read_end->nread - write_end->nwrote,
					     G_PRIORITY_DEFAULT, tunnel->cancellable,
					     tunnel_wrote_cb, tunnel);
	} else {
		g_input_stream_read_async (read_end->istream,
					   read_end->buffer, BUFSIZE,
					   G_PRIORITY_DEFAULT, tunnel->cancellable,
					   tunnel_read_cb, tunnel);
	}
}
static ssize_t
stream_write (CamelStream *stream, const char *buffer, size_t n)
{
	gssize nwritten;
	GError *error = NULL;
	CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream);

	g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream_vfs->stream), 0);

	nwritten = g_output_stream_write (G_OUTPUT_STREAM (stream_vfs->stream), buffer, n, NULL, &error);

	if (error) {
		g_warning ("%s", error->message);
		g_error_free (error);
	}

	return nwritten;
}
Exemple #13
0
static void ekg_connection_remove(struct ekg_connection *c) {
	if (g_input_stream_has_pending(G_INPUT_STREAM(c->instream))) {
		debug_warn("ekg_connection_remove(%x) input stream has pending!\n", c);
		g_input_stream_clear_pending(G_INPUT_STREAM(c->instream));
	}
#if 0 /* XXX */
	g_assert(!g_output_stream_has_pending(
				G_OUTPUT_STREAM(c->outstream)));
#endif

	connections = g_slist_remove(connections, c);

	g_string_free(c->wr_buffer, TRUE);
	g_object_unref(c->cancellable);
	g_object_unref(c->instream);
	g_object_unref(c->outstream);
	g_slice_free(struct ekg_connection, c);
}
Exemple #14
0
static void
on_output_closed (GObject *object,
                  GAsyncResult *result,
                  gpointer user_data)
{
  CockpitStream *self = COCKPIT_STREAM (user_data);
  GError *error = NULL;

  g_output_stream_close_finish (G_OUTPUT_STREAM (object), result, &error);
  if (error)
    {
      g_warning ("%s: couldn't close output stream: %s", self->priv->name, error->message);
      close_immediately (self, "internal-error");
    }

  close_maybe (self);
  g_object_unref (self);
}
Exemple #15
0
/**
 * soup_output_stream_new:
 * @session: the #SoupSession to use
 * @msg: the #SoupMessage whose request will be streamed
 * @size: the total size of the request body, or -1 if not known
 * 
 * Prepares to send @msg over @session, and returns a #GOutputStream
 * that can be used to write the response. The server's response will
 * be available in @msg after calling soup_output_stream_close()
 * (which will return a %SOUP_OUTPUT_STREAM_HTTP_ERROR #GError if the
 * status is not 2xx).
 *
 * If you know the total number of bytes that will be written, pass
 * that in @size. Otherwise, pass -1. (If you pass a size, you MUST
 * write that many bytes to the stream; Trying to write more than
 * that, or closing the stream without having written enough, will
 * result in an error.
 *
 * In some situations, the request will not actually be sent until you
 * call g_output_stream_close(). (In fact, currently this is *always*
 * true.)
 *
 * Internally, #SoupOutputStream is implemented using asynchronous
 * I/O, so if you are using the synchronous API (eg,
 * g_output_stream_write()), you should create a new #GMainContext and
 * set it as the %SOUP_SESSION_ASYNC_CONTEXT property on @session. (If
 * you don't, then synchronous #GOutputStream calls will cause the
 * main loop to be run recursively.) The async #GOutputStream API
 * works fine with %SOUP_SESSION_ASYNC_CONTEXT either set or unset.
 *
 * Returns: a new #GOutputStream.
 **/
GOutputStream *
soup_output_stream_new (SoupSession *session, SoupMessage *msg, goffset size)
{
  SoupOutputStream *stream;
  SoupOutputStreamPrivate *priv;

  g_return_val_if_fail (SOUP_IS_MESSAGE (msg), NULL);

  stream = g_object_new (SOUP_TYPE_OUTPUT_STREAM, NULL);
  priv = SOUP_OUTPUT_STREAM_GET_PRIVATE (stream);

  priv->session = g_object_ref (session);
  priv->async_context = soup_session_get_async_context (session);
  priv->msg = g_object_ref (msg);
  priv->size = size;

  return G_OUTPUT_STREAM (stream);
}
static void
splice_stream_ready_cb (GObject *source,
    GAsyncResult *res,
    gpointer user_data)
{
  EmpathyTpFile *self = user_data;
  GError *error = NULL;

  g_output_stream_splice_finish (G_OUTPUT_STREAM (source), res, &error);

  DEBUG ("Splice stream ready cb, error %p", error);

  if (error != NULL && !self->priv->is_closing)
    {
      ft_operation_close_with_error (self, error);
      g_clear_error (&error);
      return;
    }
}
Exemple #17
0
static void
write_buf_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
  GOutputStream *output = G_OUTPUT_STREAM (object);
  RequestData *req_data = user_data;
  GVfsAfpConnection *afp_conn = req_data->conn;
  GVfsAfpConnectionPrivate *priv = afp_conn->priv;
  
  HANDLE_RES ();

  g_hash_table_insert (priv->request_hash,
                       GUINT_TO_POINTER ((guint)GUINT16_FROM_BE (priv->write_dsi_header.requestID)),
                       req_data);


  g_mutex_lock (&priv->mutex);
  send_request_unlocked (afp_conn);
  g_mutex_unlock (&priv->mutex);
}
Exemple #18
0
static void
gdav_request_splice_cb (GObject *source_object,
                        GAsyncResult *result,
                        gpointer user_data)
{
	SoupMessage *message;
	GTask *task = G_TASK (user_data);
	GError *local_error = NULL;

	message = g_task_get_task_data (task);

	g_output_stream_splice_finish (
		G_OUTPUT_STREAM (source_object), result, &local_error);

	if (local_error != NULL) {
		g_task_return_error (task, local_error);

	/* XXX That the input stream's content is not automatically
	 *     copied to the SoupMessage's response_body is a known
	 *     libsoup bug which may be fixed in a future release.
	 *     Check that the response body is empty so we don't
	 *     accidentally duplicate the body. */
	} else if (message->response_body->data == NULL) {
		GMemoryOutputStream *output_stream;
		gpointer data;
		gsize size;

		output_stream = G_MEMORY_OUTPUT_STREAM (source_object);
		size = g_memory_output_stream_get_data_size (output_stream);
		data = g_memory_output_stream_steal_data (output_stream);

		soup_message_body_append_take (
			message->response_body, data, size);
		soup_message_body_flatten (message->response_body);
		soup_message_finished (message);

		g_task_return_boolean (task, TRUE);
	} else {
		g_task_return_boolean (task, TRUE);
	}

	g_object_unref (task);
}
/* Called when a file open completes */
static void
vfs_data_open_done (GObject *source, GAsyncResult *res, gpointer callback_data)
{
    VfsAsyncHandle* ah = (VfsAsyncHandle*)callback_data;

    if(ah->state == VFS_ASYNC_PROCESSING) {
        g_assert (ah->operation == VFS_OP_OPENING);
	g_clear_error (&ah->error);
	
        if (ah->writer)
            ah->ostream = G_OUTPUT_STREAM (g_file_replace_finish (ah->file, res, &ah->error));
        else
            ah->istream = G_INPUT_STREAM (g_file_read_finish (ah->file, res, &ah->error));
    
        ah->state = VFS_ASYNC_READY;
        ah->total = 0;
        ah->last = 0;
    }
}
Exemple #20
0
static void on_input_stream_read_ready (GObject * object, GAsyncResult * res, gpointer data)
{
	GError * error = NULL;
	GDownloadable *download = G_DOWNLOADABLE (data);
	GioDownload *gio_download = GIO_DOWNLOAD (data);
	g_assert (download != NULL);
	
	gssize size = g_input_stream_read_finish (G_INPUT_STREAM(object), res, &error);
	handle_critical_error (error);
	
	if (size < 0)  {
		g_downloadable_set_status (download, G_DOWNLOADABLE_NETWORK_ERROR);
		return;
	}
	
	if (size == 0 && download->priv->size == download->priv->downloaded_size) {
		/* Download Completed */
		write_chunks_to_output_stream (gio_download);

		g_input_stream_close_async (G_INPUT_STREAM(gio_download->priv->input), G_PRIORITY_DEFAULT,
									NULL, on_input_stream_close_ready, NULL);
		g_output_stream_close_async (G_OUTPUT_STREAM(gio_download->priv->output), G_PRIORITY_DEFAULT,
									 NULL, on_output_stream_close_ready, NULL);
		
		g_downloadable_set_status (download, G_DOWNLOADABLE_COMPLETED); 
		g_signal_emit_by_name (download, "download-completed");
			
		return;
	}

	if (gio_download->priv->num_chunks == NUM_OF_CHUNKS) {
		write_chunks_to_output_stream (gio_download);
		gio_download->priv->num_chunks = 0;
	} 

	MemChunk *chunk = mem_chunk_new_from_buffer (size, gio_download->priv->chunk_buff);
	gio_download->priv->chunks = g_slist_prepend (gio_download->priv->chunks, chunk);
	gio_download->priv->num_chunks++;

	g_signal_emit_by_name (data, "download-progressed", size);
	read_input_stream (download);
}
static int
stream_flush (CamelStream *stream)
{
	CamelStreamVFS *stream_vfs = CAMEL_STREAM_VFS (stream);
	GError *error = NULL;

	g_return_val_if_fail (CAMEL_IS_STREAM_VFS (stream) && stream_vfs != NULL, -1);
	g_return_val_if_fail (stream_vfs->stream != NULL, -1);
	g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream_vfs->stream), -1);

	g_output_stream_flush (G_OUTPUT_STREAM (stream_vfs->stream), NULL, &error);

	if (error) {
		g_warning ("%s", error->message);
		g_error_free (error);
		return -1;
	}

	return 0;
}
Exemple #22
0
static void
write_buf_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
  GOutputStream *output = G_OUTPUT_STREAM (object);
  GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (user_data);
  GVfsAfpConnectionPrivate *priv = afp_conn->priv;

  RequestData *req_data;

  req_data = g_queue_peek_head (priv->request_queue);
  
  HANDLE_RES ();

  g_hash_table_insert (priv->request_hash,
                       GUINT_TO_POINTER ((guint)GUINT16_FROM_BE (priv->write_dsi_header.requestID)),
                       req_data);
  g_queue_pop_head (priv->request_queue);

  send_request (afp_conn);
}
Exemple #23
0
static void
cleanup(GeglOperation *operation)
{
  GeglProperties *o = GEGL_PROPERTIES(operation);
  Priv *p = (Priv*) o->user_data;

  if (p != NULL)
    {
      if (p->tiff != NULL)
        TIFFClose(p->tiff);
      else if (p->stream != NULL)
        g_output_stream_close(G_OUTPUT_STREAM(p->stream), NULL, NULL);
      if (p->stream != NULL)
        g_clear_object(&p->stream);
      p->tiff = NULL;

      if (p->file != NULL)
        g_clear_object(&p->file);
    }
}
static gssize
nice_output_stream_write_nonblocking (GPollableOutputStream *stream,
    const void *buffer, gsize count, GError **error)
{
  NiceOutputStreamPrivate *priv = NICE_OUTPUT_STREAM (stream)->priv;
  NiceAgent *agent;  /* owned */
  gint n_sent;

  /* Closed streams are not writeable. */
  if (g_output_stream_is_closed (G_OUTPUT_STREAM (stream))) {
    g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CLOSED,
        "Stream is closed.");
    return -1;
  }

  /* Has the agent disappeared? */
  agent = g_weak_ref_get (&priv->agent_ref);
  if (agent == NULL) {
    g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CLOSED,
        "Stream is closed due to the NiceAgent being finalised.");
    return -1;
  }

  if (count == 0) {
    n_sent = 0;
    goto done;
  }

  n_sent = nice_agent_send (agent, priv->stream_id, priv->component_id,
      count, buffer);

  if (n_sent == -1)
    g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK,
        g_strerror (EAGAIN));

 done:

  g_object_unref (agent);

  return n_sent;
}
static void
on_outputstream_write_ready (GObject *source, GAsyncResult *res, gpointer user_data)
{
	GcrCertificateExporter *self = GCR_CERTIFICATE_EXPORTER (user_data);
	GOutputStream *os = G_OUTPUT_STREAM (source);
	gssize written;

	written = g_output_stream_write_finish (os, res, &self->pv->error);

	if (self->pv->error) {
		complete_async_result (self);
		return;
	}

	g_return_if_fail (written >= 0);
	g_return_if_fail (written <= self->pv->buffer->len - self->pv->buffer_at);
	self->pv->buffer_at += written;

	/* Write next bit, or finished */
	write_to_outputstream (self, os);
}
static GOutputStream *
prepare_write_stream (const gchar *filename,
                      gchar **filename_used)
{
  GOutputStream *stream;
  GFile *file;

  if (g_path_is_absolute (filename))
    {
      file = g_file_new_for_path (filename);
      *filename_used = g_strdup (filename);
      stream = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL));
      g_object_unref (file);
    }
  else
    {
      stream = get_stream_for_filename (filename, filename_used);
    }

  return stream;
}
static void
on_create_file_ready (GObject *source, GAsyncResult *res, gpointer user_data)
{
	GcrCertificateExporter *self = GCR_CERTIFICATE_EXPORTER (user_data);
	GFileOutputStream *os;
	GtkWidget *dialog;

	os = g_file_create_finish (self->pv->output_file, res, &self->pv->error);

	/* Try again this time replacing the file */
	if (g_error_matches (self->pv->error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
		g_clear_error (&self->pv->error);

		dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (self->pv->chooser_dialog),
		     GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION,
		     GTK_BUTTONS_NONE, "<b>%s</b>\n\n%s",
		     _("A file already exists with this name."),
		     _("Do you want to replace it with a new file?"));
		gtk_dialog_add_buttons (GTK_DIALOG (dialog),
		                        _("_Cancel"), GTK_RESPONSE_CANCEL,
		                        _("_Replace"), GTK_RESPONSE_ACCEPT, NULL);

		g_signal_connect (dialog, "response",
		                  G_CALLBACK (on_replace_dialog_response), self);
		if (self->pv->cancellable)
			g_cancellable_connect (self->pv->cancellable,
			                       G_CALLBACK (on_cancel_replace_dialog),
			                       g_object_ref (dialog), g_object_unref);
		gtk_widget_show (dialog);

		return;
	}

	if (self->pv->error) {
		complete_async_result (self);
		return;
	}

	write_to_outputstream (self, G_OUTPUT_STREAM (os));
}
static void
disabled_repos_free (GHashTable *disabled)
{
	GHashTableIter iter;
	GFile *file;

	GFileOutputStream *file_stream;
	GDataOutputStream *data_stream;

	const gchar *line = PACMAN_REPO_LIST_HEADER "\n";

	g_return_if_fail (disabled != NULL);

	g_debug ("pacman: storing disabled repos in %s", PACMAN_REPO_LIST);
	file = g_file_new_for_path (PACMAN_REPO_LIST);
	file_stream = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL);

	if (file_stream == NULL) {
		g_object_unref (file);
		g_hash_table_unref (disabled);
		return;
	}

	g_hash_table_iter_init (&iter, disabled);
	data_stream = g_data_output_stream_new (G_OUTPUT_STREAM (file_stream));

	/* write header, then all disabled repos line by line */
	if (g_data_output_stream_put_string (data_stream, line, NULL, NULL)) {
		while (g_hash_table_iter_next (&iter, (gpointer *) &line, NULL) &&
			g_data_output_stream_put_string (data_stream, line, NULL, NULL) &&
			g_data_output_stream_put_string (data_stream, "\n", NULL, NULL));
	}

	g_object_unref (data_stream);
	g_object_unref (file_stream);
	g_object_unref (file);
	g_hash_table_unref (disabled);
}
Exemple #29
-1
void
arv_dom_document_save_to_url (ArvDomDocument *document, const char *path, GError **error)
{
	GFile *file;
	GFileOutputStream *stream;

	g_return_if_fail (path != NULL);

	file = g_file_new_for_uri (path);
	stream = g_file_create (file, G_FILE_CREATE_REPLACE_DESTINATION, NULL, error);
	if (stream != NULL) {
		arv_dom_document_save_to_stream (document, G_OUTPUT_STREAM (stream), error);
		g_object_unref (stream);
	}
	g_object_unref (file);
}
Exemple #30
-2
    void didReceiveData(ResourceHandle*, const char* data, unsigned length, int /*encodedDataLength*/)
    {
        if (m_handleResponseLater.isScheduled()) {
            m_handleResponseLater.cancel();
            handleResponse();
        }

        gsize bytesWritten;
        GUniqueOutPtr<GError> error;
        g_output_stream_write_all(G_OUTPUT_STREAM(m_outputStream.get()), data, length, &bytesWritten, 0, &error.outPtr());
        if (error) {
            downloadFailed(platformDownloadDestinationError(m_response, error->message));
            return;
        }
        m_download->didReceiveData(bytesWritten);
    }