Revert "wip: print op implementation"

This reverts commit 2e95b13be5.
This commit is contained in:
Matthias Clasen 2023-02-06 23:17:00 +01:00
parent 2e95b13be5
commit 6d547bb3f7
5 changed files with 46 additions and 243 deletions

View File

@ -25,9 +25,6 @@
#include "gtkdialogerror.h"
#include "gtkprivate.h"
#include "gtkprintoperation.h"
#include "gtkprintoperation-private.h"
#include <glib/gi18n-lib.h>
#include <gio/gfiledescriptorbased.h>
#include <gio/gunixfdlist.h>
@ -55,18 +52,17 @@ struct _GtkPrintDialog
GtkPrintSettings *print_settings;
GtkPageSetup *default_page_setup;
GtkWindow *exported_window;
char *title;
unsigned int modal : 1;
/* portal implementation */
GDBusProxy *portal;
GtkWindow *exported_window;
char *portal_handle;
unsigned int token;
unsigned int response_signal_id;
/* print operation implementation */
GtkPrintOperation *op;
char *title;
unsigned int modal : 1;
};
enum
@ -101,8 +97,6 @@ gtk_print_dialog_finalize (GObject *object)
g_clear_object (&self->default_page_setup);
g_free (self->title);
g_clear_object (&self->op);
G_OBJECT_CLASS (gtk_print_dialog_parent_class)->finalize (object);
}
@ -384,7 +378,7 @@ gtk_print_dialog_set_title (GtkPrintDialog *self,
}
/* }}} */
/* {{{ Async implementation, portal */
/* {{{ Async implementation */
static void
send_close (GTask *task)
@ -415,11 +409,9 @@ send_close (GTask *task)
}
static gboolean
ensure_portal_proxy (GtkPrintDialog *self)
ensure_portal_proxy (GtkPrintDialog *self,
GError **error)
{
if (gdk_display_get_debug_flags (NULL) & GDK_DEBUG_NO_PORTALS)
return FALSE;
if (!self->portal)
self->portal = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
@ -428,7 +420,7 @@ ensure_portal_proxy (GtkPrintDialog *self)
PORTAL_OBJECT_PATH,
PORTAL_PRINT_INTERFACE,
NULL,
NULL);
error);
return self->portal != NULL;
}
@ -801,54 +793,6 @@ print_window_handle_exported (GtkWindow *window,
g_free (token);
}
/* }}} */
/* {{{ Async implementation, op */
static void
ensure_print_op (GtkPrintDialog *self)
{
if (!self->op)
{
self->op = gtk_print_operation_new ();
gtk_print_operation_set_allow_async (self->op, TRUE);
}
}
static void
print_pages (GtkPrintOperation *op,
GtkWindow *parent,
gboolean do_print,
GtkPrintOperationResult result)
{
GtkPrintOperationPrivate *priv = op->priv;
GTask *task = g_object_get_data (G_OBJECT (op), "task");
GtkPrintDialog *self = GTK_PRINT_DIALOG (g_task_get_source_object (task));
g_print ("print_pages do_print == %d, result %d\n", do_print, result);
g_print ("op refcount %d\n", G_OBJECT (self->op)->ref_count);
if (!do_print)
{
if (priv->error)
g_task_return_error (task, g_error_copy (priv->error));
else if (priv->cancelled)
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_DISMISSED, "Dismissed by user");
else
{
gtk_print_dialog_set_print_settings (self, gtk_print_operation_get_print_settings (op));
gtk_print_dialog_set_default_page_setup (self, gtk_print_operation_get_default_page_setup (op));
g_task_return_boolean (task, TRUE);
}
}
else
{
gtk_print_dialog_set_print_settings (self, gtk_print_operation_get_print_settings (op));
gtk_print_dialog_set_default_page_setup (self, gtk_print_operation_get_default_page_setup (op));
g_task_return_boolean (task, TRUE);
}
g_object_unref (task);
}
/* }}} */
/* {{{ Async API */
@ -878,6 +822,7 @@ gtk_print_dialog_prepare_print (GtkPrintDialog *self,
gpointer user_data)
{
GTask *task;
GError *error = NULL;
g_return_if_fail (GTK_IS_PRINT_DIALOG (self));
g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
@ -888,16 +833,10 @@ gtk_print_dialog_prepare_print (GtkPrintDialog *self,
g_task_set_check_cancellable (task, FALSE);
g_task_set_source_tag (task, gtk_print_dialog_prepare_print);
if (!ensure_portal_proxy (self))
if (!ensure_portal_proxy (self, &error))
{
ensure_print_op (self);
g_object_set_data_full (G_OBJECT (self->op), "task", task, g_object_unref);
g_print ("op refcount %d\n", G_OBJECT (self->op)->ref_count);
_gtk_print_operation_platform_backend_run_dialog_async (self->op,
TRUE,
parent,
print_pages);
g_task_return_error (task, error);
g_object_unref (task);
return;
}
@ -967,6 +906,7 @@ gtk_print_dialog_print_stream (GtkPrintDialog *self,
gpointer user_data)
{
GTask *task;
GError *error = NULL;
g_return_if_fail (GTK_IS_PRINT_DIALOG (self));
g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
@ -979,33 +919,10 @@ gtk_print_dialog_print_stream (GtkPrintDialog *self,
g_task_set_source_tag (task, gtk_print_dialog_print_stream);
g_task_set_task_data (task, g_object_ref (content), g_object_unref);
if (!ensure_portal_proxy (self))
if (!ensure_portal_proxy (self, &error))
{
GError *error = NULL;
int fd;
ensure_print_op (self);
fd = get_content_fd (G_OBJECT (content), &error);
if (fd == -1)
{
g_task_return_error (task, error);
g_object_unref (task);
}
else if (self->print_settings == NULL)
{
g_object_set_data (G_OBJECT (task), "fd", GINT_TO_POINTER (fd));
g_object_set_data_full (G_OBJECT (self->op), "task", task, g_object_unref);
_gtk_print_operation_platform_backend_run_dialog_async (self->op,
TRUE,
parent,
print_pages);
}
else
{
gtk_print_operation_platform_backend_print_file (self->op, "", self->title, fd, task);
g_object_unref (task);
}
g_task_return_error (task, error);
g_object_unref (task);
return;
}
@ -1096,35 +1013,10 @@ gtk_print_dialog_print_file (GtkPrintDialog *self,
g_task_set_task_data (task, content, g_object_unref);
if (!ensure_portal_proxy (self))
if (!ensure_portal_proxy (self, &error))
{
int fd;
ensure_print_op (self);
fd = get_content_fd (G_OBJECT (content), &error);
g_print ("print file, op, fd == %d\n", fd);
if (fd == -1)
{
g_task_return_error (task, error);
g_object_unref (task);
}
else if (self->print_settings == NULL)
{
g_print ("show dialog first\n");
g_print ("op refcount %d\n", G_OBJECT (self->op)->ref_count);
g_object_set_data (G_OBJECT (task), "fd", GINT_TO_POINTER (fd));
g_object_set_data_full (G_OBJECT (self->op), "task", task, g_object_unref);
_gtk_print_operation_platform_backend_run_dialog_async (self->op,
TRUE,
parent,
print_pages);
}
else
{
gtk_print_operation_platform_backend_print_file (self->op, "", self->title, fd, task);
g_object_unref (task);
}
g_task_return_error (task, error);
g_object_unref (task);
return;
}

View File

@ -172,52 +172,36 @@ print_file_done (GObject *source,
GtkPrintOperationPortal *op_portal = op->priv->platform_data;
GError *error = NULL;
GVariant *ret;
GTask *task;
task = g_object_get_data (G_OBJECT (op), "task");
ret = g_dbus_proxy_call_finish (op_portal->proxy,
result,
&error);
if (ret == NULL)
{
if (task)
g_task_return_error (task, g_error_copy (error));
else if (op->priv->error == NULL)
if (op->priv->error == NULL)
op->priv->error = g_error_copy (error);
g_warning ("Print file failed: %s", error->message);
g_error_free (error);
}
else
{
if (task)
g_task_return_boolean (task, TRUE);
g_variant_unref (ret);
}
g_variant_unref (ret);
if (op_portal->loop)
g_main_loop_quit (op_portal->loop);
g_object_set_data (G_OBJECT (op), "task", NULL);
g_object_unref (op);
}
void
gtk_print_operation_portal_print_file (GtkPrintOperation *op,
const char *window_handle,
const char *title,
int fd,
GTask *task)
GtkWindow *parent,
int fd)
{
GtkPrintOperationPortal *op_portal = op->priv->platform_data;
int idx;
GVariantBuilder opt_builder;
GUnixFDList *fd_list;
if (task)
g_object_set_data_full (G_OBJECT (op), "task", g_object_ref (task), g_object_unref);
fd_list = g_unix_fd_list_new ();
idx = g_unix_fd_list_append (fd_list, fd, NULL);
@ -227,8 +211,8 @@ gtk_print_operation_portal_print_file (GtkPrintOperation *op,
g_dbus_proxy_call_with_unix_fd_list (op_portal->proxy,
"Print",
g_variant_new ("(ssh@a{sv})",
window_handle,
title,
"", /* window */
_("Print"), /* title */
idx,
g_variant_builder_end (&opt_builder)),
G_DBUS_CALL_FLAGS_NONE,
@ -268,7 +252,7 @@ portal_job_complete (GtkPrintJob *job,
fd = open (filename, O_RDONLY|O_CLOEXEC);
g_free (filename);
gtk_print_operation_portal_print_file (op, "", _("Print"), fd, NULL);
gtk_print_operation_portal_print_file (op, NULL, fd);
}
static void

View File

@ -36,10 +36,8 @@ void gtk_print_operation_portal_launch_preview (GtkPr
const char *filename);
void gtk_print_operation_portal_print_file (GtkPrintOperation *op,
const char *window_handle,
const char *title,
int fd,
GTask *task);
GtkWindow *parent,
int fd);
G_END_DECLS

View File

@ -128,10 +128,8 @@ void _gtk_print_operation_platform_backend_preview_end_page
cairo_t *cr);
void gtk_print_operation_platform_backend_print_file (GtkPrintOperation *op,
const char *window_handle,
const char *title,
int fd,
GTask *task);
GtkWindow *parent,
int fd);
void _gtk_print_operation_set_status (GtkPrintOperation *op,
GtkPrintStatus status,

View File

@ -510,7 +510,6 @@ print_response_data_free (gpointer data)
{
PrintResponseData *rdata = data;
g_print ("free rdata: op refcount %d\n", G_OBJECT (rdata->op)->ref_count);
g_object_unref (rdata->op);
g_free (rdata);
}
@ -527,7 +526,6 @@ finish_print (PrintResponseData *rdata,
GtkPrintJob *job;
double top, bottom, left, right;
g_print ("finish_print: op refcount %d\n", G_OBJECT (rdata->op)->ref_count);
if (rdata->do_print)
{
gtk_print_operation_set_print_settings (op, settings);
@ -901,88 +899,23 @@ gtk_print_operation_unix_run_dialog (GtkPrintOperation *op,
return rdata.result;
}
typedef struct {
GtkPrintOperation *op;
int fd;
GTask *task;
} PrintFileData;
static void
free_print_file_data (gpointer data)
{
PrintFileData *f = data;
g_object_unref (f->op);
g_clear_object (&f->task);
g_free (f);
}
static void
complete_func (GtkPrintJob *job,
gpointer data,
const GError *error)
{
PrintFileData *f = data;
GtkPrintOperationPrivate *priv = f->op->priv;
if (error)
{
if (f->task)
g_task_return_error (f->task, g_error_copy (error));
else if (priv->error == NULL)
priv->error = g_error_copy (error);
}
else if (f->task)
g_task_return_boolean (f->task, TRUE);
free_print_file_data (data);
}
static void
print_file (GtkPrinter *printer,
gpointer data)
{
PrintFileData *f = data;
GtkPrintOperationPrivate *priv = f->op->priv;
GtkPrintSettings *print_settings;
GtkPageSetup *default_page_setup;
GtkPrintJob *job;
if (priv->print_settings)
print_settings = g_object_ref (priv->print_settings);
else
print_settings = gtk_print_settings_new ();
if (priv->default_page_setup)
default_page_setup = g_object_ref (priv->default_page_setup);
else
default_page_setup = gtk_page_setup_new ();
job = gtk_print_job_new ("printjob", printer, print_settings, default_page_setup);
gtk_print_job_set_source_fd (job, f->fd, NULL);
gtk_print_job_send (job, complete_func, data, free_print_file_data);
g_object_unref (print_settings);
g_object_unref (default_page_setup);
}
static void
gtk_print_operation_unix_print_file (GtkPrintOperation *op,
int fd,
GTask *task)
GtkWindow *parent,
int fd)
{
PrintFileData *data;
#if 0
const char *printer_name = NULL;
data = g_new (PrintFileData, 1);
data->op = g_object_ref (op);
data->fd = fd;
data->task = task ? g_object_ref (task) : NULL;
if (op->priv->print_settings)
printer_name = gtk_print_settings_get_printer (op->priv->print_settings);
find_printer (printer_name, (GFunc) print_file, data);
find_printer (printer_name, (GFunc) found_printer, rdata);
job = gtk_print_job_new (priv->job_name, printer, settings, page_setup);
op_unix->job = job;
gtk_print_job_set_track_print_status (job, priv->track_print_status);
#endif
}
typedef struct
@ -1358,15 +1291,13 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
void
gtk_print_operation_platform_backend_print_file (GtkPrintOperation *op,
const char *window_handle,
const char *title,
int fd,
GTask *task)
GtkWindow *parent,
int fd)
{
if (gdk_display_get_debug_flags (NULL) & GDK_DEBUG_PORTALS)
gtk_print_operation_portal_print_file (op, window_handle, title, fd, task);
if (gdk_should_use_portal ())
gtk_print_operation_portal_print_file (op, parent, fd);
else
gtk_print_operation_unix_print_file (op, fd, task);
gtk_print_operation_unix_print_file (op, parent, fd);
}
cairo_surface_t *