Пример #1
1
void init_enumeration( FilebrowserBackend *filebackend)
{
  FilebrowserBackendDetails *directory = FILEBROWSER_BACKEND_GET_PRIVATE(filebackend);
  if (g_cancellable_is_cancelled (directory->cancellable)) return ; /* remove source */
  GFile *file = get_gfile_from_filename (directory->current_folder);
  GError *error=NULL;
  directory->enumerator =  g_file_enumerate_children (file,FOLDER_INFOFLAGS,G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, directory->cancellable,&error);
  if (!directory->enumerator){
    g_print(_("Error getting file browser files. GIO Error:%s\t"),error->message);
    g_error_free (error);
    filebrowser_backend_restore(filebackend);
    return ;
  }
 directory->idle_id = gdk_threads_add_idle_full (G_PRIORITY_DEFAULT, populate_files,  filebackend,  clean_enumerate);
}
Пример #2
0
static gboolean
on_immediate_wakeup_source_ready (GoaAlarm *self)
{
  g_return_val_if_fail (self->priv->type != GOA_ALARM_TYPE_UNSCHEDULED, FALSE);

  g_rec_mutex_lock (&self->priv->lock);
  if (g_cancellable_is_cancelled (self->priv->cancellable))
    goto out;

  fire_or_rearm_alarm (self);

out:
  g_rec_mutex_unlock (&self->priv->lock);
  return FALSE;
}
Пример #3
0
static void gtkhash_hash_file_close_finish(
	G_GNUC_UNUSED GObject *source, GAsyncResult *res, struct hash_file_s *data)
{
	if (G_UNLIKELY(!g_input_stream_close_finish(G_INPUT_STREAM(data->stream), res, NULL) &&
		!g_cancellable_is_cancelled(data->cancellable)))
	{
		g_warning("failed to close file (%s)", data->uri);
	}

	g_object_unref(data->stream);

	gtkhash_hash_file_remove_report_source(data);
	gtkhash_hash_file_set_state(data, HASH_FILE_STATE_FINISH);
	gtkhash_hash_file_add_source(data);
}
Пример #4
0
int
main(int argc, char *argv[])
{
    GSoundContext *ctx;
    GCancellable *cancellable;
    GMainLoop *main_loop;
    GThread *thread;
    GError *error = NULL;

    g_set_application_name ("GSound Test");

    cancellable = g_cancellable_new();
    
    ctx = gsound_context_new(cancellable, &error);
    check_error(error);

    gsound_context_set_driver (ctx, CANBERRA_DRIVER, &error);
    check_error(error);
    
    gsound_context_open (ctx, &error);
    check_error(error);

    g_assert(!g_cancellable_is_cancelled (cancellable));

    main_loop = g_main_loop_new (NULL, TRUE);

    gsound_context_play_simple (ctx, cancellable, &error,
                                GSOUND_ATTR_MEDIA_FILENAME,
                                "/usr/share/sounds/alsa/Front_Right.wav",
                                NULL);
    check_error (error);

    gsound_context_play_full(ctx, cancellable,
                             on_play_finished, main_loop,
                             GSOUND_ATTR_MEDIA_FILENAME, "/usr/share/sounds/alsa/Front_Center.wav",
                             NULL);

    thread = g_thread_new("Thread2", thread_func, cancellable);

    g_main_loop_run(main_loop);

    /* FIXME: We seem to leak the cancellable, but I can't for the life of me
     * see why or how. Valgrind is no help. */
    g_object_unref(cancellable);
    g_object_unref(ctx);

    return 0;
}
Пример #5
0
static gboolean
uri_recurse_func (GFile *file, gboolean dir, RhythmDBImportJob *job)
{
	RhythmDBEntry *entry;
	char *uri;

	if (dir) {
		return TRUE;
	}

	if (g_cancellable_is_cancelled (job->priv->cancel))
		return FALSE;

	uri = g_file_get_uri (file);

	/* if it's not already in the db, add it to the list of things to process */
	entry = rhythmdb_entry_lookup_by_location (job->priv->db, uri);
	if (entry == NULL) {
		rb_debug ("waiting for entry %s", uri);
		g_mutex_lock (&job->priv->lock);
		job->priv->total++;
		g_queue_push_tail (job->priv->outstanding, g_strdup (uri));

		if (job->priv->status_changed_id == 0) {
			job->priv->status_changed_id = g_idle_add ((GSourceFunc) emit_status_changed, job);
		}

		maybe_start_more (job);

		g_mutex_unlock (&job->priv->lock);
	} else {
		/* skip it if it's a different entry type */
		RhythmDBEntryType *et;
		et = rhythmdb_entry_get_entry_type (entry);
		if (et == job->priv->entry_type ||
		    et == job->priv->ignore_type ||
		    et == job->priv->error_type) {
			rhythmdb_add_uri_with_types (job->priv->db,
						     uri,
						     job->priv->entry_type,
						     job->priv->ignore_type,
						     job->priv->error_type);
		}
	}

	g_free (uri);
	return TRUE;
}
Пример #6
0
void
fetch_cover_image_from_album_info (GooWindow       *window,
				   AlbumInfo       *album,
				   FetchCoverStage  after_stage,
				   GCancellable    *cancellable)
{
	if ((cancellable != NULL) && g_cancellable_is_cancelled (cancellable))
		return;

#if HAVE_LIBCOVERART

	if ((FETCH_COVER_STAGE_AFTER_LIBCOVERART > after_stage)
	    && (album != NULL)
	    && (album->id != NULL))
	{
		CoverArtData *data;

		data = g_new0 (CoverArtData, 1);
		data->window = g_object_ref (window);
		data->album = album_info_ref (album);
		data->cancellable = _g_object_ref (cancellable);
		metadata_get_coverart (data->window,
				       data->album,
				       data->cancellable,
				       metadata_get_coverart_cb,
				       data);

		return;
	}

#endif

	if ((FETCH_COVER_STAGE_AFTER_ASIN > after_stage)
	    && (album != NULL)
	    && (album->asin != NULL))
	{
		fetch_cover_image_from_asin (window, album->asin, cancellable);
		return;
	}

	if ((FETCH_COVER_STAGE_AFTER_WEB_SEARCH > after_stage)
	    && (album != NULL)
	    && (album->title != NULL)
	    && (album->artist != NULL))
	{
		fetch_cover_image_from_name (window, album->title, album->artist, cancellable);
	}
}
Пример #7
0
static gpointer
pragha_scanner_scan_worker(gpointer data)
{
	GSList *list;

	PraghaScanner *scanner = data;

	for(list = scanner->folder_list ; list != NULL; list = list->next) {
		if(g_cancellable_is_cancelled (scanner->cancellable))
			break;

		pragha_scanner_scan_handler(scanner, list->data);
	}

	return scanner;
}
Пример #8
0
gboolean GSourceWrap::dynamicDelayBasedVoidCallback(gpointer data)
{
    auto& dispatch = *reinterpret_cast<DispatchContext*>(data);
    auto& callback = *reinterpret_cast<DelayBased::CallbackContext<void ()>*>(dispatch.second);
    if (g_cancellable_is_cancelled(callback.second.cancellable.get()))
        return G_SOURCE_CONTINUE;

    callback.second.dispatching = true;
    g_source_set_ready_time(dispatch.first, -1);
    g_source_set_callback(dispatch.first, nullptr, nullptr, nullptr);

    callback.first();

    callback.second.dispatching = false;
    return G_SOURCE_CONTINUE;
}
Пример #9
0
static gboolean
search_thread_done_idle (gpointer user_data)
{
	SearchThreadData *data;

	data = user_data;

	if (!g_cancellable_is_cancelled (data->cancellable)) {
		nemo_search_engine_finished (NEMO_SEARCH_ENGINE (data->engine));
		data->engine->details->active_search = NULL;
	}
	
	search_thread_data_free (data);
	
	return FALSE;
}
void GThreadSafeMainLoopSource::voidCallback()
{
    Context context;
    if (!prepareVoidCallback(context))
        return;

    context.voidCallback();

    if (g_cancellable_is_cancelled(context.cancellable.get())) {
        context.destroySource();
        return;
    }

    finishVoidCallback();
    context.destroySource();
}
static void
gb_rename_file_popover_finalize (GObject *object)
{
  GbRenameFilePopover *self = (GbRenameFilePopover *)object;

  if (self->cancellable != NULL)
    {
      if (!g_cancellable_is_cancelled (self->cancellable))
        g_cancellable_cancel (self->cancellable);
      g_clear_object (&self->cancellable);
    }

  g_clear_object (&self->file);

  G_OBJECT_CLASS (gb_rename_file_popover_parent_class)->finalize (object);
}
Пример #12
0
void SocketStreamHandle::readReadyCallback(GInputStream* stream, GAsyncResult* result, SocketStreamHandle* handle)
{
    RefPtr<SocketStreamHandle> protectedThis = adoptRef(handle);

    // Always finish the read, even if this SocketStreamHandle was cancelled earlier.
    GUniqueOutPtr<GError> error;
    gssize bytesRead = g_input_stream_read_finish(stream, result, &error.outPtr());

    if (g_cancellable_is_cancelled(handle->m_cancellable.get()))
        return;

    if (error)
        handle->didFail(SocketStreamError(error->code, error->message));
    else
        handle->readBytes(bytesRead);
}
Пример #13
0
gboolean
pk_backend_cancelled (PkBackend *self)
{
	gboolean cancelled;

	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (cancellable != NULL, FALSE);

	g_static_mutex_lock (&mutex);

	cancelled = g_cancellable_is_cancelled (cancellable);

	g_static_mutex_unlock (&mutex);

	return cancelled;
}
Пример #14
0
void
seahorse_progress_end (GCancellable *cancellable,
                       gconstpointer progress_tag)
{
	TrackedTask *task = NULL;
	TrackedPart *part;

	if (!cancellable)
		return;

	g_return_if_fail (G_IS_CANCELLABLE (cancellable));
	if (g_cancellable_is_cancelled (cancellable))
		return;

	if (tracked_tasks)
		task = g_hash_table_lookup (tracked_tasks, cancellable);
	if (task == NULL) {
		g_warning ("caller is trying to end part for task that does not exist");
		return;
	}

	part = tracked_part_find (task, find_part_progress_tag, progress_tag);
	if (part == NULL) {
		g_warning ("caller is trying to end part of task that does not exist");
		return;
	}

	switch (part->state) {
	case TASK_PART_PREPPED:
		g_warning ("caller is trying to end part of task that has not begun");
		return;
	case TASK_PART_BEGUN:
		part->state = TASK_PART_ENDED;
		task->parts_begun--;
		task->parts_ended++;
		break;
	case TASK_PART_ENDED:
		g_warning ("caller is trying to end part of task that has already ended");
		return;
	default:
		g_assert_not_reached ();
		break;
	}

	g_assert (task->parts_prepped + task->parts_begun + task->parts_ended == (gint)task->parts->length);
	progress_update_display (task);
}
Пример #15
0
static void
news_sync_task_fetch_cb (GObject      *object,
                         GAsyncResult *result,
                         gpointer      user_data)
{
   NewsSyncTaskPrivate *priv;
   GSimpleAsyncResult *simple = (GSimpleAsyncResult *)user_data;
   GInputStream *stream;
   NewsSyncTask *task;
   NewsSource *source = (NewsSource *)object;
   NewsParser *parser;
   GError *error = NULL;

   g_assert(NEWS_IS_SOURCE(source));
   g_assert(G_IS_SIMPLE_ASYNC_RESULT(simple));
   task = (NewsSyncTask *)g_async_result_get_source_object(G_ASYNC_RESULT(simple));
   g_assert(NEWS_IS_SYNC_TASK(task));

   priv = task->priv;

   priv->fraction = 0.333;
   g_object_notify_by_pspec(G_OBJECT(task), gParamSpecs[PROP_FRACTION]);

   if (!(stream = news_source_fetch_finish(source, result, &error))) {
      g_simple_async_result_take_error(simple, error);
      g_simple_async_result_complete_in_idle(simple);
      g_object_unref(simple);
      return;
   }

   if (g_cancellable_is_cancelled(priv->cancellable)) {
      g_simple_async_result_set_error(simple, NEWS_SYNC_TASK_ERROR,
                                      NEWS_SYNC_TASK_ERROR_CANCELLED,
                                      _("The task was cancelled."));
      g_simple_async_result_complete_in_idle(simple);
      g_object_unref(simple);
      return;
   }

   parser = g_object_new(NEWS_TYPE_PARSER,
                         "adapter", priv->adapter,
                         "source", priv->source,
                         NULL);
   news_parser_parse_async(parser, stream, priv->cancellable,
                           news_sync_task_parse_cb, simple);
   g_object_unref(parser);
}
Пример #16
0
static void
custom_init_step (CustomInitContext *ctx)
{
    /* If cancelled, end */
    if (g_cancellable_is_cancelled (ctx->cancellable)) {
        mm_dbg ("(Novatel) no need to keep on running custom init in (%s)",
                mm_port_get_device (MM_PORT (ctx->port)));
        g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
        custom_init_context_complete_and_free (ctx);
        return;
    }

    /* If device has a QMI port, don't run $NWDMAT */
    if (mm_port_probe_list_has_qmi_port (mm_device_peek_port_probe_list (mm_port_probe_peek_device (ctx->probe)))) {
        mm_dbg ("(Novatel) no need to run custom init in (%s): device has QMI port",
                mm_port_get_device (MM_PORT (ctx->port)));
        g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
        custom_init_context_complete_and_free (ctx);
        return;
    }

    if (ctx->wait_time > 0) {
        ctx->wait_time--;
        g_timeout_add_seconds (1, (GSourceFunc)custom_init_wait_cb, ctx);
        return;
    }

    if (ctx->nwdmat_retries > 0) {
        ctx->nwdmat_retries--;
        mm_port_serial_at_command (ctx->port,
                                   "$NWDMAT=1",
                                   3,
                                   FALSE, /* raw */
                                   FALSE, /* allow_cached */
                                   ctx->cancellable,
                                   (GAsyncReadyCallback)nwdmat_ready,
                                   ctx);
        return;
    }

    /* Finish custom_init */
    mm_dbg ("(Novatel) couldn't flip secondary port to AT in (%s): all retries consumed",
            mm_port_get_device (MM_PORT (ctx->port)));
    g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
    custom_init_context_complete_and_free (ctx);
}
Пример #17
0
static void g_simple_async_write_thread_handler(GSimpleAsyncResult *simple,
			GObject *object, GCancellable *cancellable)
{
	HevSerialPort *self = HEV_SERIAL_PORT(object);
	HevSerialPortPrivate *priv = HEV_SERIAL_PORT_GET_PRIVATE(self);
	HevSerialPortReadWriteData *data = NULL;
	gssize i = 0, w = 0;
	GPollFD fds[] =
	{
		{priv->fd, G_IO_OUT, G_IO_NVAL}
	};

	g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	data = g_simple_async_result_get_op_res_gpointer(simple);

	while(1)
	{
		gint rfds = g_poll(fds, 1, 200);
		
		if(0 < rfds)
		{
			i = write(priv->fd, data->buffer+w, data->count-w);

			if(-1 == i)
			{
				g_simple_async_result_set_error(simple, G_IO_ERROR,
							g_io_error_from_errno(errno), "%s", strerror(errno));
				break;
			}
			else
			  w += i;
		}

		if(data->count == w)
		  break;

		if(g_cancellable_is_cancelled(cancellable))
		  goto ret;
	}

	g_simple_async_result_set_op_res_gssize(simple, w);

ret:
	g_free(data);
}
Пример #18
0
static void
file_load_cb (GObject      *source_object,
              GAsyncResult *res,
              gpointer      user_data)
{
  GError *error = NULL;
  DQTask *task = user_data;
  gchar *contents = NULL;
  gsize length = 0;

  g_file_load_contents_finish (task->gio.file,
                               res,
                               &contents,
                               &length,
                               NULL,
                               &error);

  if (!g_cancellable_is_cancelled (task->gio.cancellable))
    {
      if (error)
        {
          task->any.callback (task->any.queue, task->any.uri,
                              NULL, 0,
                              error,
                              task->any.userdata);
        }
      else
        {
          task->any.callback (task->any.queue, task->any.uri,
                              contents, length,
                              NULL,
                              task->any.userdata);

          mex_download_queue_cache_insert (task->any.queue, task->any.uri,
                                           contents, length);
        }
    }

  if (error)
    g_error_free (error);

  g_object_unref (task->gio.cancellable);
  task->gio.cancellable = NULL;

  mex_download_queue_free (task);
}
Пример #19
0
static void on_session_completed(PolkitAgentSession* session,
				 gboolean authorized, AuthDlgData* d)
{
	gtk_widget_set_sensitive(d->auth_dlg, TRUE);
	if (authorized || g_cancellable_is_cancelled(d->cancellable)) {
		gtk_label_set_text(GTK_LABEL(d->status), NULL);
		g_task_return_pointer(d->task, NULL, NULL);
		auth_dlg_data_free(d);
		return;
	}
	gtk_label_set_text(GTK_LABEL(d->status), "Failed. Wrong password?");
	g_object_unref(d->session);
	d->session = NULL;
	gtk_entry_set_text(GTK_ENTRY(d->entry), "");
	gtk_widget_grab_focus(d->entry);
	on_id_combo_user_changed(GTK_COMBO_BOX(d->id_combo), d);
}
static void
check_authorization_ready (PolkitAuthority *authority,
                           GAsyncResult *res,
                           AuthorizeContext *ctx)
{
	PolkitAuthorizationResult *pk_result;
	GError *error = NULL;

    if (g_cancellable_is_cancelled (ctx->cancellable)) {
        g_simple_async_result_set_error (ctx->result,
                                         MM_CORE_ERROR,
                                         MM_CORE_ERROR_CANCELLED,
                                         "PolicyKit authorization attempt cancelled");
        authorize_context_complete_and_free (ctx);
        return;
    }

    pk_result = polkit_authority_check_authorization_finish (authority, res, &error);
    if (!pk_result) {
        g_simple_async_result_set_error (ctx->result,
                                         MM_CORE_ERROR,
                                         MM_CORE_ERROR_FAILED,
                                         "PolicyKit authorization failed: '%s'",
                                         error->message);
        g_error_free (error);
    } else {
        if (polkit_authorization_result_get_is_authorized (pk_result))
            /* Good! */
            g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
        else if (polkit_authorization_result_get_is_challenge (pk_result))
            g_simple_async_result_set_error (ctx->result,
                                             MM_CORE_ERROR,
                                             MM_CORE_ERROR_UNAUTHORIZED,
                                             "PolicyKit authorization failed: challenge needed for '%s'",
                                             ctx->authorization);
        else
            g_simple_async_result_set_error (ctx->result,
                                             MM_CORE_ERROR,
                                             MM_CORE_ERROR_UNAUTHORIZED,
                                             "PolicyKit authorization failed: not authorized for '%s'",
                                             ctx->authorization);
        g_object_unref (pk_result);
    }

    authorize_context_complete_and_free (ctx);
}
static void
cal_searching_instances_done_cb (gpointer user_data)
{
	struct GenerateInstancesData *gid = user_data;

	g_return_if_fail (gid != NULL);
	g_return_if_fail (gid->cal_shell_view != NULL);

	if (!g_cancellable_is_cancelled (gid->cancellable)) {
		gid->cal_shell_view->priv->search_pending_count--;
		if (!gid->cal_shell_view->priv->search_pending_count)
			cal_iterate_searching (gid->cal_shell_view);
	}

	g_object_unref (gid->cancellable);
	g_free (gid);
}
static void
request_free (Request *r)
{
	if (!g_cancellable_is_cancelled (r->cancellable))
		g_hash_table_remove (APPLET_AGENT_GET_PRIVATE (r->agent)->requests, GUINT_TO_POINTER (r->id));

	/* By the time the request is freed, all keyring calls should be completed */
	g_warn_if_fail (r->keyring_calls == 0);

	g_object_unref (r->connection);
	g_free (r->path);
	g_free (r->setting_name);
	g_strfreev (r->hints);
	g_object_unref (r->cancellable);
	memset (r, 0, sizeof (*r));
	g_slice_free (Request, r);
}
Пример #23
0
static gboolean
search_thread_add_hits_idle (gpointer user_data)
{
	SearchHits *hits;

	hits = user_data;

	if (!g_cancellable_is_cancelled (hits->thread_data->cancellable)) {
		nemo_search_engine_hits_added (NEMO_SEARCH_ENGINE (hits->thread_data->engine),
						   hits->uris);
	}

	g_list_free_full (hits->uris, g_free);
	g_free (hits);
	
	return FALSE;
}
Пример #24
0
void
restraint_queue_message (SoupSession *session,
                         SoupMessage *msg,
                         gpointer msg_data,
                         MessageFinishCallback finish_callback,
                         GCancellable *cancellable,
                         gpointer user_data)
{
    //g_print ("restraint_queue_message->enter\n");
    MessageData *message_data;
    message_data = g_slice_new0 (MessageData);
    message_data->msg = msg;
    message_data->session = session;
    message_data->user_data = user_data;
    message_data->finish_callback = finish_callback;

    if (g_cancellable_is_cancelled (cancellable)) {
        if (finish_callback) {
            g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
                             message_finish,
                             message_data,
                             message_destroy);
        }
        return;
    }

    // Initialize the queue if needed
    if (!message_queue) {
        message_queue = g_queue_new ();
    }

    // push the message onto the queue.
    g_queue_push_tail (message_queue, message_data);

    // Add the message handler to the main loop if it isn't running already.
    if (!queue_active) {
        //g_print ("restraint_queue_message->add message_handler\n");
        g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
                         message_handler,
                         NULL,
                         NULL);
        queue_active = TRUE;
    }
    //g_print ("restraint_queue_message->exit\n");
}
Пример #25
0
/**
 * hif_state_check:
 * @state: a #HifState instance.
 * @error: A #GError or %NULL
 *
 * Do any checks to see if the task has been cancelled.
 *
 * Returns: %TRUE for success, %FALSE otherwise
 *
 * Since: 0.1.0
 **/
gboolean
hif_state_check(HifState *state, GError **error)
{
    HifStatePrivate *priv = GET_PRIVATE(state);

    g_return_val_if_fail(state != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

    /* are we cancelled */
    if (g_cancellable_is_cancelled(priv->cancellable)) {
        g_set_error_literal(error,
                            HIF_ERROR,
                            HIF_ERROR_CANCELLED,
                            "cancelled by user action");
        return FALSE;
    }
    return TRUE;
}
bool GThreadSafeMainLoopSource::boolCallback()
{
    Context context;
    if (!prepareBoolCallback(context))
        return Stop;

    bool retval = context.boolCallback();

    if (g_cancellable_is_cancelled(context.cancellable.get())) {
        context.destroySource();
        return Stop;
    }

    finishBoolCallback(retval, context);
    if (context.source)
        context.destroySource();
    return retval;
}
static gboolean
pulse (PulseData *data)
{
	gint status;
	GCancellable *cancellable;

	gtk_tree_model_get (GTK_TREE_MODEL (data->plugin->priv->uploads_store), &(data->iter), 3, &status, 4, &cancellable, -1);

	if (0 <= status && status < G_MAXINT && g_cancellable_is_cancelled (cancellable) == FALSE) {
		/* TODO: consider potential for races and how g_timeout_add works wrt threading; none seen in testing, though */
		gtk_list_store_set (data->plugin->priv->uploads_store, &(data->iter), 3, status+1, -1);
		return TRUE;
	} else {
		/* either we've failed, <0, or we're done, G_MAX_INT */
		g_slice_free (PulseData, data);
		return FALSE;
	}
}
Пример #28
0
static void
ev_job_thread (EvJob *job)
{
	gboolean result;

	ev_debug_message (DEBUG_JOBS, "%s", EV_GET_TYPE_NAME (job));

	do {
		if (g_cancellable_is_cancelled (job->cancellable))
			result = FALSE;
		else {
                        g_atomic_pointer_set (&running_job, job);
			result = ev_job_run (job);
                }
	} while (result);

        g_atomic_pointer_set (&running_job, NULL);
}
Пример #29
0
static void
check_hashing (CallbacksData *data)
{
  EmpathyFTHandler *handler = data->handler;
  EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
  GError *myerr = NULL;
  TpCapabilities *caps;
  GPtrArray *classes;
  TpConnection *conn;

  conn = empathy_contact_get_connection (priv->contact);

  caps = tp_connection_get_capabilities (conn);
  if (caps == NULL)
    {
      data->callback (handler, NULL, data->user_data);
      goto out;
    }

  classes = tp_capabilities_get_channel_classes (caps);

  /* set whether we support hash and the type of it */
  if (!set_content_hash_type_from_classes (handler, classes))
    {
      g_set_error_literal (&myerr, EMPATHY_FT_ERROR_QUARK,
          EMPATHY_FT_ERROR_NOT_SUPPORTED,
          _("File transfer not supported by remote contact"));

      if (!g_cancellable_is_cancelled (priv->cancellable))
        g_cancellable_cancel (priv->cancellable);

      data->callback (handler, myerr, data->user_data);
      g_clear_error (&myerr);
    }
  else
    {
      /* get back to the caller now */
      data->callback (handler, NULL, data->user_data);
    }

out:
  callbacks_data_free (data);
}
Пример #30
0
static void
news_sync_task_parse_cb (GObject      *object,
                         GAsyncResult *result,
                         gpointer      user_data)
{
   NewsSyncTaskPrivate *priv;
   GSimpleAsyncResult *simple = user_data;
   NewsSyncTask *task;
   NewsParser *parser = (NewsParser *)object;
   GError *error = NULL;

   g_assert(NEWS_IS_PARSER(parser));
   g_assert(G_IS_SIMPLE_ASYNC_RESULT(simple));
   task = (NewsSyncTask *)g_async_result_get_source_object(G_ASYNC_RESULT(simple));
   g_assert(NEWS_IS_SYNC_TASK(task));

   priv = task->priv;

   priv->fraction = 0.666;
   g_object_notify_by_pspec(G_OBJECT(task), gParamSpecs[PROP_FRACTION]);

   if (!(priv->feed = news_parser_parse_finish(parser, result, &error))) {
      g_simple_async_result_take_error(simple, error);
      g_simple_async_result_complete_in_idle(simple);
      g_object_unref(simple);
      return;
   }

   if (g_cancellable_is_cancelled(priv->cancellable)) {
      g_simple_async_result_set_error(simple, NEWS_SYNC_TASK_ERROR,
                                      NEWS_SYNC_TASK_ERROR_CANCELLED,
                                      _("The task was cancelled."));
      g_simple_async_result_complete_in_idle(simple);
      g_object_unref(simple);
      return;
   }

   news_sync_task_prepare_save(task);

   gom_adapter_sqlite_begin(GOM_ADAPTER_SQLITE(priv->adapter));
   gom_resource_save_async(GOM_RESOURCE(priv->feed), priv->cancellable,
                           news_sync_task_save_cb, simple);
}