Exemple #1
0
static void
mail_printer_load_changed_cb (WebKitWebView *web_view,
                              WebKitLoadEvent load_event,
                              GTask *task)
{
	AsyncContext *async_context;

	/* Note: we disregard WEBKIT_LOAD_FAILED and print what we can. */
	if (load_event != WEBKIT_LOAD_FINISHED)
		return;

	async_context = g_task_get_task_data (task);

	g_return_if_fail (async_context != NULL);

	/* WebKit reloads the page once more right before starting to print,
	 * so disconnect this handler after the first time to avoid starting
	 * another print operation. */
	g_signal_handler_disconnect (
		async_context->web_view,
		async_context->load_status_handler_id);
	async_context->load_status_handler_id = 0;

	/* Check if we've been cancelled. */
	if (g_task_return_error_if_cancelled (task)) {
		return;
	} else {
		GSource *timeout_source;

		/* Give WebKit some time to perform layouting and rendering before
		 * we start printing. 500ms should be enough in most cases. */
		timeout_source = g_timeout_source_new (500);
		g_task_attach_source (
			task,
			timeout_source,
			(GSourceFunc) mail_printer_print_timeout_cb);
		g_source_unref (timeout_source);
	}
}
static gboolean
on_main_thread_to_register_driver (GTask *task)
{
        GsdSmartcardManager *self;
        GsdSmartcardManagerPrivate *priv;
        DriverRegistrationOperation *operation;
        GSource *source;

        self = g_task_get_source_object (task);
        priv = self->priv;
        operation = g_task_get_task_data (task);

        gsd_smartcard_service_register_driver (priv->service,
                                               operation->driver);

        source = g_idle_source_new ();
        g_task_attach_source (task,
                              source,
                              (GSourceFunc) on_task_thread_to_complete_driver_registration);
        g_source_unref (source);

        return G_SOURCE_REMOVE;
}