Commit 25fed034 authored by Matthias Clasen's avatar Matthias Clasen

Add portal support to GtkPrintOperation

Make GtkPrintOperation talk to org.freedesktop.portal.Print when
running in a sandbox.

https://bugzilla.gnome.org/show_bug.cgi?id=768499
parent 56ebfc6c
......@@ -987,9 +987,12 @@ gtk_os_unix_c_sources = \
gtkprinteroptionwidget.c \
gtkprintjob.c \
gtkprintoperation-unix.c \
gtkprintoperation-portal.h \
gtkprintoperation-portal.c \
gtkprintunixdialog.c \
gtkprintbackend.c \
gtksearchenginetracker.c
if OS_UNIX
gtk_private_h_sources += \
gtkiconcachevalidator.h \
......@@ -999,6 +1002,7 @@ gtk_private_h_sources += \
gtkprinteroptionset.h \
gtkprinteroptionwidget.h \
gtksearchenginetracker.h
gtk_c_sources += $(gtk_os_unix_c_sources)
endif
......@@ -1143,6 +1147,7 @@ gtk_extra_sources = \
MAINTAINERCLEANFILES = \
$(gtk_built_sources) \
$(gtk_dbus_built_sources) \
$(print_portal_built_sources) \
$(stamp_files)
DISTCLEANFILES =
......@@ -1208,7 +1213,8 @@ CLEANFILES = $(gen_sources)
BUILT_SOURCES = \
$(gtk_built_sources) \
$(gtk_dbus_built_sources)
$(gtk_dbus_built_sources) \
$(print_portal_built_sources)
# all autogenerated files need to be generated in the srcdir,
# so old versions get remade and are not confused with newer
......
This diff is collapsed.
/* GTK - The GIMP Toolkit
* Copyright (C) 2016, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_PRINT_OPERATION_PORTAL_H__
#define __GTK_PRINT_OPERATION_PORTAL_H__
#include "gtkprintoperation.h"
G_BEGIN_DECLS
GtkPrintOperationResult gtk_print_operation_portal_run_dialog (GtkPrintOperation *op,
gboolean show_dialog,
GtkWindow *parent,
gboolean *do_print);
void gtk_print_operation_portal_run_dialog_async (GtkPrintOperation *op,
gboolean show_dialog,
GtkWindow *parent,
GtkPrintOperationPrintFunc print_cb);
void gtk_print_operation_portal_launch_preview (GtkPrintOperation *op,
cairo_surface_t *surface,
GtkWindow *parent,
const char *filename);
G_END_DECLS
#endif /* __GTK_PRINT_OPERATION_PORTAL_H__ */
......@@ -30,6 +30,7 @@
#include <glib/gstdio.h>
#include "gtkprintoperation-private.h"
#include "gtkprintoperation-portal.h"
#include "gtkmessagedialog.h"
#include <cairo-pdf.h>
......@@ -199,11 +200,11 @@ shell_command_substitute_file (const gchar *cmd,
return g_string_free (final, FALSE);
}
void
_gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
cairo_surface_t *surface,
GtkWindow *parent,
const gchar *filename)
static void
gtk_print_operation_unix_launch_preview (GtkPrintOperation *op,
cairo_surface_t *surface,
GtkWindow *parent,
const gchar *filename)
{
GAppInfo *appinfo;
GdkAppLaunchContext *context;
......@@ -703,11 +704,11 @@ found_printer (GtkPrinter *printer,
g_object_unref (page_setup);
}
void
_gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op,
gboolean show_dialog,
GtkWindow *parent,
GtkPrintOperationPrintFunc print_cb)
static void
gtk_print_operation_unix_run_dialog_async (GtkPrintOperation *op,
gboolean show_dialog,
GtkWindow *parent,
GtkPrintOperationPrintFunc print_cb)
{
GtkWidget *pd;
PrintResponseData *rdata;
......@@ -778,12 +779,12 @@ close_preview (void *data)
close (fd);
}
cairo_surface_t *
_gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation *op,
GtkPageSetup *page_setup,
gdouble *dpi_x,
gdouble *dpi_y,
gchar **target)
static cairo_surface_t *
gtk_print_operation_unix_create_preview_surface (GtkPrintOperation *op,
GtkPageSetup *page_setup,
gdouble *dpi_x,
gdouble *dpi_y,
gchar **target)
{
gchar *filename;
gint fd;
......@@ -815,25 +816,25 @@ _gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation
return surface;
}
void
_gtk_print_operation_platform_backend_preview_start_page (GtkPrintOperation *op,
cairo_surface_t *surface,
cairo_t *cr)
static void
gtk_print_operation_unix_preview_start_page (GtkPrintOperation *op,
cairo_surface_t *surface,
cairo_t *cr)
{
}
void
_gtk_print_operation_platform_backend_preview_end_page (GtkPrintOperation *op,
cairo_surface_t *surface,
cairo_t *cr)
static void
gtk_print_operation_unix_preview_end_page (GtkPrintOperation *op,
cairo_surface_t *surface,
cairo_t *cr)
{
cairo_show_page (cr);
}
void
_gtk_print_operation_platform_backend_resize_preview_surface (GtkPrintOperation *op,
GtkPageSetup *page_setup,
cairo_surface_t *surface)
static void
gtk_print_operation_unix_resize_preview_surface (GtkPrintOperation *op,
GtkPageSetup *page_setup,
cairo_surface_t *surface)
{
gdouble w, h;
......@@ -842,12 +843,11 @@ _gtk_print_operation_platform_backend_resize_preview_surface (GtkPrintOperation
cairo_pdf_surface_set_size (surface, w, h);
}
GtkPrintOperationResult
_gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
gboolean show_dialog,
GtkWindow *parent,
gboolean *do_print)
static GtkPrintOperationResult
gtk_print_operation_unix_run_dialog (GtkPrintOperation *op,
gboolean show_dialog,
GtkWindow *parent,
gboolean *do_print)
{
GtkWidget *pd;
PrintResponseData rdata;
......@@ -1218,3 +1218,73 @@ find_printer (const gchar *printer,
if (finder->backends == NULL && !finder->found_printer)
g_idle_add (find_printer_idle, finder);
}
GtkPrintOperationResult
_gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
gboolean show_dialog,
GtkWindow *parent,
gboolean *do_print)
{
if (gtk_should_use_portal ())
return gtk_print_operation_portal_run_dialog (op, show_dialog, parent, do_print);
else
return gtk_print_operation_unix_run_dialog (op, show_dialog, parent, do_print);
}
void
_gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op,
gboolean show_dialog,
GtkWindow *parent,
GtkPrintOperationPrintFunc print_cb)
{
if (gtk_should_use_portal ())
gtk_print_operation_portal_run_dialog_async (op, show_dialog, parent, print_cb);
else
gtk_print_operation_unix_run_dialog_async (op, show_dialog, parent, print_cb);
}
void
_gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
cairo_surface_t *surface,
GtkWindow *parent,
const gchar *filename)
{
if (gtk_should_use_portal ())
gtk_print_operation_portal_launch_preview (op, surface, parent, filename);
else
gtk_print_operation_unix_launch_preview (op, surface, parent, filename);
}
cairo_surface_t *
_gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation *op,
GtkPageSetup *page_setup,
gdouble *dpi_x,
gdouble *dpi_y,
gchar **target)
{
return gtk_print_operation_unix_create_preview_surface (op, page_setup, dpi_x, dpi_y, target);
}
void
_gtk_print_operation_platform_backend_resize_preview_surface (GtkPrintOperation *op,
GtkPageSetup *page_setup,
cairo_surface_t *surface)
{
gtk_print_operation_unix_resize_preview_surface (op, page_setup, surface);
}
void
_gtk_print_operation_platform_backend_preview_start_page (GtkPrintOperation *op,
cairo_surface_t *surface,
cairo_t *cr)
{
gtk_print_operation_unix_preview_start_page (op, surface, cr);
}
void
_gtk_print_operation_platform_backend_preview_end_page (GtkPrintOperation *op,
cairo_surface_t *surface,
cairo_t *cr)
{
gtk_print_operation_unix_preview_end_page (op, surface, cr);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment