Esempio n. 1
0
static void
avatar_cache_close_cb (GObject      *object,
                       GAsyncResult *result,
                       gpointer      user_data)
{
	GiggleAvatarCacheLoader *loader = user_data;
	GInputStream            *stream = G_INPUT_STREAM (object);
	GError                  *error = NULL;

	if (g_input_stream_close_finish (stream, result, &error) &&
	    gdk_pixbuf_loader_close (loader->pixbuf_loader, &error)) {
		loader->pixbuf = gdk_pixbuf_loader_get_pixbuf (loader->pixbuf_loader);
		avatar_cache_insert (loader->cache, loader->uri, loader->pixbuf);
		g_object_unref (loader->pixbuf_loader);
		loader->pixbuf_loader = NULL;
	}

	if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
		g_warning ("%s: %s", G_STRFUNC, error->message);

	avatar_cache_loader_finish (loader, error);
}
static gboolean
g_tls_output_stream_gnutls_write_ready (GIOStreamAdapter *adapter,
					gpointer          user_data)
{
  GTlsOutputStreamGnutls *tls_stream;
  GSimpleAsyncResult *simple = user_data;
  gssize nwrote;
  GError *error = NULL;

  tls_stream = G_TLS_OUTPUT_STREAM_GNUTLS (g_async_result_get_source_object (G_ASYNC_RESULT (simple)));
  g_object_unref (tls_stream);

  nwrote = g_tls_connection_gnutls_write (tls_stream->priv->conn,
					  tls_stream->priv->buffer,
					  tls_stream->priv->count, FALSE,
					  tls_stream->priv->cancellable,
					  &error);
  if (nwrote == -1 &&
      g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
    {
      g_error_free (error);
      return TRUE;
    }

  if (error)
    {
      g_simple_async_result_set_from_error (simple, error);
      g_error_free (error);
    }
  else
    g_simple_async_result_set_op_res_gssize (simple, nwrote);

  if (tls_stream->priv->cancellable)
    g_object_unref (tls_stream->priv->cancellable);
  g_simple_async_result_complete (simple);
  g_object_unref (simple);

  return FALSE;
}
Esempio n. 3
0
static void
modem_secrets_cb (NMActRequest *req,
                  NMActRequestGetSecretsCallId call_id,
                  NMSettingsConnection *connection,
                  GError *error,
                  gpointer user_data)
{
	NMModem *self = NM_MODEM (user_data);
	NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self);

	g_return_if_fail (call_id == priv->secrets_id);

	priv->secrets_id = NULL;

	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
		return;

	if (error)
		nm_log_warn (LOGD_MB, "(%s): %s", nm_modem_get_uid (self), error->message);

	g_signal_emit (self, signals[AUTH_RESULT], 0, error);
}
Esempio n. 4
0
static void
rb_removable_media_manager_unmount_cb (GObject *object,
				       GAsyncResult *result,
				       RBRemovableMediaManager *mgr)
{
	GMount *mount = G_MOUNT (object);
	GError *error = NULL;

	rb_debug ("finishing unmount of mount");
	g_mount_unmount_finish (mount, result, &error);
	if (error != NULL) {
		if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED)) {
			rb_error_dialog (NULL, _("Unable to unmount"), "%s", error->message);
		} else {
			rb_debug ("unmount failure has already been handled");
		}
		g_error_free (error);
	} else {
		rb_removable_media_manager_remove_mount (mgr, mount);
	}
	g_object_unref (mgr);
}
Esempio n. 5
0
static GBookmarkFile *
ide_recent_projects_get_bookmarks (IdeRecentProjects  *self,
                                   GError            **error)
{
  g_autoptr(GBookmarkFile) bookmarks = NULL;
  g_autoptr(GError) local_error = NULL;

  g_assert (IDE_IS_RECENT_PROJECTS (self));

  bookmarks = g_bookmark_file_new ();

  if (!g_bookmark_file_load_from_file (bookmarks, self->file_uri, &local_error))
    {
      if (!g_error_matches (local_error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
        {
          g_propagate_error (error, g_steal_pointer (&local_error));
          return NULL;
        }
    }

  return g_steal_pointer (&bookmarks);
}
Esempio n. 6
0
static void
stop_network_ready (QmiClientWds *client,
                    GAsyncResult *res,
                    DisconnectContext *ctx)
{
    GError *error = NULL;
    QmiMessageWdsStopNetworkOutput *output;

    output = qmi_client_wds_stop_network_finish (client, res, &error);
    if (output &&
        !qmi_message_wds_stop_network_output_get_result (output, &error)) {
        /* No effect error, we're already disconnected */
        if (g_error_matches (error,
                             QMI_PROTOCOL_ERROR,
                             QMI_PROTOCOL_ERROR_NO_EFFECT)) {
            g_error_free (error);
            error = NULL;
        }
    }

    if (error) {
        if (ctx->running_ipv4)
            ctx->error_ipv4 = error;
        else
            ctx->error_ipv6 = error;
    } else {
        /* Clear internal status */
        reset_bearer_connection (ctx->self,
                                 ctx->running_ipv4,
                                 ctx->running_ipv6);
    }

    if (output)
        qmi_message_wds_stop_network_output_unref (output);

    /* Keep on */
    ctx->step++;
    disconnect_context_step (ctx);
}
Esempio n. 7
0
static void
pixbuf_task_completed_cb (GthTask  *task,
			  GError   *error,
			  gpointer  user_data)
{
	GthPixbufListTask *self = user_data;

	if (g_error_matches (error, GTH_TASK_ERROR, GTH_TASK_ERROR_SKIP_TO_NEXT_FILE)) {
		process_next_file (self);
		return;
	}

	if (error != NULL) {
		gth_task_completed (GTH_TASK (self), error);
		return;
	}

	set_current_destination_file (self);
	pixbuf_task_save_current_pixbuf (self,
					 NULL,
					 (self->priv->overwrite_mode == GTH_OVERWRITE_OVERWRITE));
}
static void
picture_opened_for_read (GObject *source_object,
                         GAsyncResult *res,
                         gpointer user_data)
{
  BgPicturesSource *bg_source;
  CcBackgroundItem *item;
  GFileInputStream *stream;
  GError *error = NULL;

  item = g_object_get_data (source_object, "item");
  stream = g_file_read_finish (G_FILE (source_object), res, &error);
  if (stream == NULL)
    {
      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
        {
          char *filename = g_file_get_path (G_FILE (source_object));
          g_warning ("Failed to load picture '%s': %s", filename, error->message);
          g_free (filename);
        }

      g_error_free (error);
      g_object_unref (item);
      return;
    }

  /* since we were not cancelled, we can now cast user_data
   * back to BgPicturesSource.
   */
  bg_source = BG_PICTURES_SOURCE (user_data);

  g_object_set_data (G_OBJECT (stream), "item", item);
  gdk_pixbuf_new_from_stream_at_scale_async (G_INPUT_STREAM (stream),
                                             THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT,
                                             TRUE,
                                             bg_source->priv->cancellable,
                                             picture_scaled, bg_source);
  g_object_unref (stream);
}
static void
album_art_received (GObject      *object,
                    GAsyncResult *result,
                    gpointer      user_data)
{
  IdoMediaPlayerMenuItem *self = user_data;
  GdkPixbuf *pixbuf;
  GError *error = NULL;

  pixbuf = gdk_pixbuf_new_from_stream_finish (result, &error);
  if (pixbuf == NULL)
    {
      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
        g_warning ("unable to fetch album art: %s", error->message);

      g_error_free (error);
      return;
    }

  gtk_image_set_from_pixbuf (GTK_IMAGE (self->album_art), pixbuf);
  g_object_unref (pixbuf);
}
Esempio n. 10
0
static void
tunnel_read_cb (GObject      *object,
		GAsyncResult *result,
		gpointer      user_data)
{
	Tunnel *tunnel = user_data;
	TunnelEnd *read_end, *write_end;
	GError *error = NULL;
	gssize nread;

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

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

	read_end->nread = nread;
	write_end->nwrote = 0;
	g_output_stream_write_async (write_end->ostream,
				     read_end->buffer, read_end->nread,
				     G_PRIORITY_DEFAULT, tunnel->cancellable,
				     tunnel_wrote_cb, tunnel);
}
Esempio n. 11
0
static void
do_cancel_while_reading_req_test_for_session (SoupSession *session)
{
	SoupRequest *req;
	SoupURI *uri;
	GCancellable *cancellable;
	GError *error = NULL;

	uri = soup_uri_new_with_base (base_uri, "/slow");
	req = soup_session_request_uri (session, uri, NULL);
	soup_uri_free (uri);

	cancellable = g_cancellable_new ();

	if (SOUP_IS_SESSION_ASYNC (soup_request_get_session (req))) {
		g_timeout_add (100, cancel_request_timeout, cancellable);
		soup_test_request_send (req, cancellable, &error);
	} else {
		GThread *thread;

		thread = g_thread_new ("cancel_request_thread", cancel_request_thread, g_object_ref (cancellable));
		soup_test_request_send (req, cancellable, &error);
		g_thread_unref (thread);
	}

	if (!error) {
		debug_printf (1, "  Request succeeded?\n");
		errors++;
	} else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
		debug_printf (1, "  Unexpected error: %s\n",
			      error->message);
		errors++;
	}
	g_clear_error (&error);

	g_object_unref (req);
	g_object_unref (cancellable);
}
Esempio n. 12
0
static void
on_poke_proxy (GObject *source_object,
               GAsyncResult *result,
               gpointer user_data)
{
  PokeContext *poke = user_data;
  CockpitFakeManager *self = poke->manager;
  GError *error = NULL;
  GDBusProxy *proxy;

  g_assert (poke->outstanding > 0);
  poke->outstanding--;

  proxy = g_dbus_proxy_new_finish (result, &error);

  /* Bail fast if cancelled */
  if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
    {
      if (poke->outstanding == 0)
        poke_context_finish (self, poke);
      return;
    }

  if (error)
    {
      g_warning ("Couldn't create proxy: %s", error->message);
      g_error_free (error);
    }
  else
    {
      g_debug ("fakemanager: proxy created: %s %s", poke->object_path,
               g_dbus_proxy_get_interface_name (proxy));
      poke->added = g_list_prepend (poke->added, proxy);
    }

  if (poke->outstanding == 0)
    poke_apply_changes_and_finish (self, poke);
}
Esempio n. 13
0
GFile *
fetch_archive (const gchar  *url,
               const gchar  *sha,
               const gchar  *module_name,
               GFile        *destination,
               guint         strip_components,
               GError      **error)
{
  g_autoptr(GFile) archive_file = NULL;
  g_autoptr(GFile) source_dir = NULL;
  g_autoptr(SoupURI) uri = NULL;
  g_autofree char *archive_name = NULL;
  GError *local_error = NULL;

  source_dir = g_file_get_child (destination, module_name);
  if (!g_file_make_directory_with_parents (source_dir, NULL, &local_error))
    {
      if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
        {
          g_propagate_error (error, local_error);
          return NULL;
        }

      g_error_free (local_error);
    }

  uri = soup_uri_new (url);
  archive_name = g_path_get_basename (soup_uri_get_path (uri));
  archive_file = g_file_get_child (source_dir, archive_name);

  if (!download_archive (uri, sha, archive_file, error))
    return NULL;

  if (!extract_archive (source_dir, archive_file, strip_components, error))
    return NULL;

  return g_steal_pointer (&source_dir);
}
static void
on_bss_proxy_acquired (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data)
{
	NMSupplicantInterface *self;
	NMSupplicantInterfacePrivate *priv;
	gs_free_error GError *error = NULL;
	gs_strfreev char **properties = NULL;
	gs_unref_variant GVariant *props = NULL;
	GVariantBuilder builder;
	char **iter;

	if (!g_async_initable_init_finish (G_ASYNC_INITABLE (proxy), result, &error)) {
		if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
			nm_log_dbg (LOGD_SUPPLICANT, "Failed to acquire BSS proxy: (%s)", error->message);
			g_hash_table_remove (NM_SUPPLICANT_INTERFACE_GET_PRIVATE (user_data)->bss_proxies,
			                     g_dbus_proxy_get_object_path (proxy));
		}
		return;
	}

	self = NM_SUPPLICANT_INTERFACE (user_data);
	priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);

	g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));

	iter = properties = g_dbus_proxy_get_cached_property_names (proxy);
	while (iter && *iter) {
		GVariant *copy = g_dbus_proxy_get_cached_property (proxy, *iter);

		g_variant_builder_add (&builder, "{sv}", *iter++, copy);
		g_variant_unref (copy);
	}

	props = g_variant_builder_end (&builder);
	g_signal_emit (self, signals[NEW_BSS], 0,
	               g_dbus_proxy_get_object_path (proxy),
	               g_variant_ref_sink (props));
}
Esempio n. 15
0
static void
on_enumerator_ready (GObject *source_object,
                     GAsyncResult *res,
                     gpointer user_data)
{
  GError *error = NULL;
  GFileEnumerator *enumerator;
  JsonObject *options;
  const gchar *problem;

  enumerator = g_file_enumerate_children_finish (G_FILE (source_object), res, &error);
  if (enumerator == NULL)
    {
      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
        {
          CockpitFslist *self = COCKPIT_FSLIST (user_data);
          problem = error_to_problem (error);
          if (problem)
            g_debug ("%s: couldn't list directory: %s", self->path, error->message);
          else
            g_warning ("%s: couldn't list directory: %s", self->path, error->message);
          options = cockpit_channel_close_options (COCKPIT_CHANNEL (self));
          json_object_set_string_member (options, "message", error->message);
          cockpit_channel_close (COCKPIT_CHANNEL (self), problem ? problem : "internal-error");
        }
      g_clear_error (&error);
      return;
    }

  CockpitFslist *self = COCKPIT_FSLIST (user_data);

  g_file_enumerator_next_files_async (enumerator,
                                      10,
                                      G_PRIORITY_DEFAULT,
                                      self->cancellable,
                                      on_files_listed,
                                      self);
}
Esempio n. 16
0
/**
 * seahorse_util_handle_error:
 * @error: The #GError to print, and clear
 * @desc: The heading of the box
 * @...: Parameters to insert into the format string desc.
 *
 * Displays an error box. The message is the error message.
 * Won't display cancel errors.
 */
void
seahorse_util_handle_error (GError **error,
                            gpointer parent,
                            const char* description,
                            ...)
{
	gchar *text = NULL;
	GtkWidget *widget = NULL;
	va_list ap;

	if (!error || !(*error) ||
	    g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
		g_clear_error (error);
		return;
	}

	va_start (ap, description);
	if (description)
		text = g_strdup_vprintf (description, ap);
	va_end (ap);

	if (parent == NULL)
		widget = NULL;
	else if (GTK_IS_WIDGET (parent))
		widget = GTK_WIDGET (parent);
	else if (GTK_IS_WINDOW (parent))
		widget = GTK_WIDGET (parent);
	else if (SEAHORSE_IS_WIDGET (parent))
		widget = seahorse_widget_get_toplevel (parent);
	else
		g_warning ("unsupported 'parent' argument passed to seahorse_util_handle_error() ");

	g_dbus_error_strip_remote_error (*error);
	seahorse_util_show_error (widget, text,
	                          (*error)->message ? (*error)->message : "");
	g_free (text);
	g_clear_error (error);
}
Esempio n. 17
0
static void
photos_source_manager_goa_client (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  PhotosSourceManager *self;
  PhotosSourceManagerPrivate *priv;
  GError *error;
  GoaClient *client;

  error = NULL;
  client = goa_client_new_finish (res, &error);
  if (error != NULL)
    {
      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
        g_warning ("Unable to create GoaClient: %s", error->message);

      g_error_free (error);
      return;
    }

  self = PHOTOS_SOURCE_MANAGER (user_data);
  priv = self->priv;

  priv->client = client;
  g_signal_connect_swapped (priv->client,
                            "account-added",
                            G_CALLBACK (photos_source_manager_refresh_accounts),
                            self);
  g_signal_connect_swapped (priv->client,
                            "account-changed",
                            G_CALLBACK (photos_source_manager_refresh_accounts),
                            self);
  g_signal_connect_swapped (priv->client,
                            "account-removed",
                            G_CALLBACK (photos_source_manager_refresh_accounts),
                            self);

  photos_source_manager_refresh_accounts (self);
}
Esempio n. 18
0
static void
set_problem_from_error (CockpitStream *self,
                        const gchar *summary,
                        GError *error)
{
  const gchar *problem;

  if (g_error_matches (error, G_TLS_ERROR, G_TLS_ERROR_MISC))
    {
      g_message ("%s: %s: %s", self->priv->name, summary, error->message);
      if (self->priv->received)
        problem = "disconnected";
      else
        problem = "protocol-error";
    }
  else
    {
      problem = cockpit_stream_problem (error, self->priv->name, summary, self->priv->io);
    }

  g_free (self->priv->problem);
  self->priv->problem = g_strdup (problem);
}
Esempio n. 19
0
static gchar *
get_service_description (const gchar *file)
{
  GError *error = NULL;
  GKeyFile *kf = g_key_file_new ();
  g_key_file_load_from_file (kf, file, 0, &error);
  if (error)
    goto out;

  gchar *description = g_key_file_get_string (kf, "Unit", "Description", &error);
  if (error)
    goto out;

  g_key_file_free (kf);
  return description;

out:
  if (g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
    g_warning ("Failed to load '%s': %s", file, error->message);
  g_error_free (error);
  g_key_file_free (kf);
  return g_strdup ("Unknown");
}
int SocketStreamHandle::platformSend(const char* data, int length)
{
    LOG(Network, "SocketStreamHandle %p platformSend", this);
    if (!m_outputStream || !data)
        return 0;

    GOwnPtr<GError> error;
    gssize written = g_pollable_output_stream_write_nonblocking(m_outputStream.get(), data, length, 0, &error.outPtr());
    if (error) {
        if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
            beginWaitingForSocketWritability();
        else
            m_client->didFailSocketStream(this, SocketStreamError(error->code, error->message));
        return 0;
    }

    // If we did not send all the bytes we were given, we know that
    // SocketStreamHandleBase will need to send more in the future.
    if (written < length)
        beginWaitingForSocketWritability();

    return written;
}
static void
encoder_completed_cb (RBEncoder *encoder,
		      guint64 dest_size,
		      const char *mediatype,
		      GError *error,
		      RBTrackTransferBatch *batch)
{
	g_object_unref (batch->priv->current_encoder);
	batch->priv->current_encoder = NULL;

	if (error == NULL) {
		rb_debug ("encoder finished (size %" G_GUINT64_FORMAT ")", dest_size);
	} else if (g_error_matches (error, RB_ENCODER_ERROR, RB_ENCODER_ERROR_DEST_EXISTS)) {
		rb_debug ("encoder stopped because destination %s already exists",
			  batch->priv->current_dest_uri);
		g_signal_emit (batch, signals[OVERWRITE_PROMPT], 0, batch->priv->current_dest_uri);
		return;
	} else {
		rb_debug ("encoder finished (error: %s)", error->message);
	}

	track_transfer_completed (batch, dest_size, mediatype, FALSE, error);
}
Esempio n. 22
0
/**
 * fu_util_install_with_fallback:
 **/
static gboolean
fu_util_install_with_fallback (FuUtilPrivate *priv, const gchar *id,
			       const gchar *filename, GError **error)
{
	_cleanup_error_free_ GError *error_local = NULL;

	/* install with flags chosen by the user */
	if (fu_util_install_internal (priv, id, filename, &error_local))
		return TRUE;

	/* some other failure */
	if ((priv->flags & FU_PROVIDER_UPDATE_FLAG_OFFLINE) > 0 ||
	    !g_error_matches (error_local, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) {
		g_propagate_error (error, error_local);
		error_local = NULL;
		return FALSE;
	}

	/* TRANSLATOR: the provider only supports offline */
	g_print ("%s...\n", _("Retrying as an offline update"));
	priv->flags |= FU_PROVIDER_UPDATE_FLAG_OFFLINE;
	return fu_util_install_internal (priv, id, filename, error);
}
Esempio n. 23
0
static void
on_ipclient_search_ready (GObject      *source_object,
                          GAsyncResult *res,
                          gpointer      user_data)
{
        GClueIpclient *ipclient = GCLUE_IPCLIENT (source_object);
        GClueLocator *locator = GCLUE_LOCATOR (user_data);
        GClueLocationInfo *location;
        GError *error = NULL;

        location = gclue_ipclient_search_finish (ipclient, res, &error);
        if (location == NULL) {
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
                        g_warning ("Error fetching location from geoip server: %s",
                                   error->message);
                g_error_free (error);
                return;
        }

        g_debug ("New location available");
        gclue_locator_update_location (locator, location);
        g_object_unref (location);
}
static void
photos_properties_dialog_pipeline_is_edited (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  PhotosPropertiesDialog *self;
  PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
  gboolean is_edited;

  {
    g_autoptr (GError) error = NULL;

    is_edited = photos_base_item_pipeline_is_edited_finish (item, res, &error);
    if (error != NULL)
      {
        if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
          g_warning ("Unable to check if item has been edited or not: %s", error->message);
        return;
      }
  }

  self = PHOTOS_PROPERTIES_DIALOG (user_data);

  photos_properties_dialog_modified_updated (self, is_edited);
}
static void
gbp_git_buffer_change_monitor_wait_cb (GObject      *object,
                                       GAsyncResult *result,
                                       gpointer      user_data)
{
  IpcGitChangeMonitor *proxy = (IpcGitChangeMonitor *)object;
  g_autoptr(GVariant) changes = NULL;
  g_autoptr(IdeTask) task = user_data;
  g_autoptr(GError) error = NULL;
  GbpGitBufferChangeMonitor *self;

  g_assert (IDE_IS_MAIN_THREAD ());
  g_assert (IPC_IS_GIT_CHANGE_MONITOR (proxy));
  g_assert (G_IS_ASYNC_RESULT (result));
  g_assert (IDE_IS_TASK (task));

  self = ide_task_get_source_object (task);

  if (!ipc_git_change_monitor_call_list_changes_finish (proxy, &changes, result, &error))
    {
      g_clear_pointer (&self->cache, line_cache_free);
      self->not_found = TRUE;

      if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_FILE_NOT_FOUND))
        ide_task_return_boolean (task, TRUE);
      else
        ide_task_return_error (task, g_steal_pointer (&error));
    }
  else
    {
      g_clear_pointer (&self->cache, line_cache_free);
      self->not_found = FALSE;
      self->cache = line_cache_new_from_variant (changes);
      ide_buffer_change_monitor_emit_changed (IDE_BUFFER_CHANGE_MONITOR (self));
      ide_task_return_boolean (task, TRUE);
    }
}
static void
select_area_done (GObject *source_object,
                  GAsyncResult *res,
                  gpointer user_data)
{
  CallbackData *cb_data = user_data;
  GError *error = NULL;
  GVariant *ret;

  ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, &error);
  if (error != NULL)
    {
      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
        {
          g_error_free (error);
          cb_data->aborted = TRUE;
          g_idle_add (emit_select_callback_in_idle, cb_data);
          return;
        }

      g_message ("Unable to select area using GNOME Shell's builtin screenshot "
                 "interface, resorting to fallback X11.");
      g_error_free (error);

      screenshot_select_area_x11_async (cb_data);
      return;
    }

  g_variant_get (ret, "(iiii)",
                 &cb_data->rectangle.x,
                 &cb_data->rectangle.y,
                 &cb_data->rectangle.width,
                 &cb_data->rectangle.height);
  g_variant_unref (ret);

  g_idle_add (emit_select_callback_in_idle, cb_data);
}
static void
ep_forget_passwords_keyfile (EPassMsg *msg)
{
	gchar **groups;
	gsize length = 0, ii;

	if (!check_key_file (G_STRFUNC))
		return;

	groups = g_key_file_get_groups (key_file, &length);

	if (!groups)
		return;

	for (ii = 0; ii < length; ii++) {
		GError *error = NULL;

		if (!g_str_has_prefix (groups[ii], KEY_FILE_GROUP_PREFIX))
			continue;

		g_key_file_remove_group (key_file, groups[ii], &error);

		/* Not finding the requested group is acceptable, but we still
		 * want to leave an informational message on the terminal. */
		if (g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) {
			g_message ("%s", error->message);
			g_error_free (error);

		/* Issue a warning if anything else goes wrong. */
		} else if (error != NULL) {
			g_warning ("%s", error->message);
			g_error_free (error);
		}
	}
	ep_key_file_save ();
	g_strfreev (groups);
}
static void
ide_git_buffer_change_monitor__calculate_cb (GObject      *object,
                                             GAsyncResult *result,
                                             gpointer      user_data_unused)
{
  IdeGitBufferChangeMonitor *self = (IdeGitBufferChangeMonitor *)object;
  g_autoptr(GHashTable) ret = NULL;
  g_autoptr(GError) error = NULL;

  g_assert (IDE_IS_GIT_BUFFER_CHANGE_MONITOR (self));

  self->in_calculation = FALSE;

  ret = ide_git_buffer_change_monitor_calculate_finish (self, result, &error);

  if (!ret)
    {
      if (!g_error_matches (error, GGIT_ERROR, GGIT_ERROR_NOTFOUND))
        g_message ("%s", error->message);
    }
  else
    {
      g_clear_pointer (&self->state, g_hash_table_unref);
      self->state = g_hash_table_ref (ret);
    }

  ide_buffer_change_monitor_emit_changed (IDE_BUFFER_CHANGE_MONITOR (self));

  /*
   * Recalculate the state if the buffer has changed since we submitted our request.
   */
  if (self->state_dirty)
    ide_git_buffer_change_monitor_calculate_async (self,
                                                   NULL,
                                                   ide_git_buffer_change_monitor__calculate_cb,
                                                   NULL);
}
/*static*/ void
uGlobalMenuService::RegisterWindowCallback(GObject *object,
                                           GAsyncResult *res,
                                           gpointer userdata)
{
  GError *error = NULL;
  GVariant *result = g_dbus_proxy_call_finish(G_DBUS_PROXY(object), res, &error);
  if (result) {
    g_variant_unref(result);
  }

  RegisterWindowCbData *data = static_cast<RegisterWindowCbData *>(userdata);

  if (error && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
    // If the request was cancelled, then the menubar has definitely been
    // deleted already
    g_error_free(error);
    delete data;
    return;
  }

  uGlobalMenuBar *menu = data->GetMenuBar();

  // We don't assume that GDbus cancellation is reliable
  // see https://launchpad.net/bugs/953562
  if (menu && !error) {
    menu->NotifyMenuBarRegistered();
  } else if (menu && sService) {
    sService->mMenus.RemoveElement(menu);
  }

  if (error) {
    g_error_free(error);
  }

  delete data;
}
Esempio n. 30
0
static void
avatar_cache_read_cb (GObject      *object,
                      GAsyncResult *result,
                      gpointer      user_data)
{
	GiggleAvatarCacheLoader *loader = user_data;
	GInputStream            *stream = G_INPUT_STREAM (object);
	GError                  *error = NULL;
	gssize                   len;

	len = g_input_stream_read_finish (stream, result, &error);

	if (len > 0) {
	       if (gdk_pixbuf_loader_write (loader->pixbuf_loader, (gpointer)
					    loader->buffer, len, &error)) {
			g_input_stream_read_async
				(stream, loader->buffer, sizeof loader->buffer,
				 G_PRIORITY_DEFAULT, loader->cancellable,
				 avatar_cache_read_cb, loader);
		} else {
			len = -2;
		}
	}

	if (0 >= len) {
		g_input_stream_close_async
			(stream, G_PRIORITY_DEFAULT, loader->cancellable,
			 avatar_cache_close_cb, loader);
	}

	if (error) {
		if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
			g_warning ("%s: %s", G_STRFUNC, error->message);

		g_error_free (error);
	}
}