[evince/wip/chpe/export-print-portal-custom-options: 1/2] libview: Add custom options when printing through the portal




commit 2095853480a67fd7218bb2497dd8946cf6176875
Author: Christian Persch <chpe src gnome org>
Date:   Sat Nov 13 16:40:52 2021 +0100

    libview: Add custom options when printing through the portal
    
    This depends on a host of branches to gtk3/4, xdg-desktop-portal, and
    xdg-desktop-portal-gtk/gnome, so enable this by adding
    -DWITH_CUSTOM_OPTIONS to CFLAGS.

 libview/ev-print-operation.c | 98 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 88 insertions(+), 10 deletions(-)
---
diff --git a/libview/ev-print-operation.c b/libview/ev-print-operation.c
index b377f8290..1e5e94c0d 100644
--- a/libview/ev-print-operation.c
+++ b/libview/ev-print-operation.c
@@ -34,6 +34,15 @@
 #define PORTAL_ENABLED
 #endif
 
+#if defined (WITH_CUSTOM_OPTIONS) // && GTK_CHECK_VERSION (3, 24, 30)
+#define CUSTOM_OPTIONS_ENABLED
+#endif
+
+#define EV_PRINT_SETTING_PAGE_SCALE   "xdp-custom-evince-print-setting-page-scale"
+#define EV_PRINT_SETTING_AUTOROTATE   "xdp-custom-evince-print-setting-page-autorotate"
+#define EV_PRINT_SETTING_PAGE_SIZE    "xdp-custom-evince-print-setting-page-size"
+#define EV_PRINT_SETTING_DRAW_BORDERS "xdp-custom-evince-print-setting-page-draw-borders"
+
 enum {
        PROP_0,
        PROP_DOCUMENT
@@ -374,6 +383,73 @@ ev_print_operation_update_status (EvPrintOperation *op,
        g_signal_emit (op, signals[STATUS_CHANGED], 0);
 }
 
+
+static GVariant *
+ev_print_operation_get_custom_options (void)
+{
+        GVariantBuilder builder, abuilder;
+
+        g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
+
+        g_variant_builder_open (&builder, G_VARIANT_TYPE ("(sa*)")); /* page */
+        g_variant_builder_add (&builder, "s", _("Page Handling"));
+
+        g_variant_builder_open (&builder, G_VARIANT_TYPE_ARRAY); /* sections */
+        g_variant_builder_open (&builder, G_VARIANT_TYPE ("(sa*)")); /* section */
+        g_variant_builder_add (&builder, "s", "");
+        g_variant_builder_open (&builder, G_VARIANT_TYPE_ARRAY); /* options */
+
+        /* Page Scaling option */
+        g_variant_builder_open (&builder, G_VARIANT_TYPE ("(ssssa(ss))")); /* option */
+        g_variant_builder_add (&builder, "s", "pickone"); /* type */
+        g_variant_builder_add (&builder, "s", EV_PRINT_SETTING_PAGE_SCALE); /* key */
+        g_variant_builder_add (&builder, "s", "1"); /* default */
+        g_variant_builder_add (&builder, "s", _("Page Scaling")); /* label */
+
+        g_variant_builder_open (&builder, G_VARIANT_TYPE ("a(ss)"));
+       /* translators: Value for 'Page Scaling:' to not scale the document pages on printing */
+        g_variant_builder_add (&builder, "(ss)", "0", _("None"));
+        g_variant_builder_add (&builder, "(ss)", "1",  _("Shrink to Printable Area"));
+        g_variant_builder_add (&builder, "(ss)", "2", _("Fit to Printable Area"));
+
+        g_variant_builder_close (&builder); /* a(ss) */
+        g_variant_builder_close (&builder); /* option */
+
+        /* Autorotate option */
+        g_variant_builder_init (&abuilder, G_VARIANT_TYPE ("a(ss)"));
+        g_variant_builder_add (&builder, "(ssssa(ss))",
+                               "bool",
+                               EV_PRINT_SETTING_AUTOROTATE,
+                               "True",
+                               _("Auto Rotate and Center"),
+                               &abuilder);
+
+        /* Page Size option */
+        g_variant_builder_init (&abuilder, G_VARIANT_TYPE ("a(ss)"));
+        g_variant_builder_add (&builder, "(ssssa(ss))",
+                               "bool",
+                               EV_PRINT_SETTING_PAGE_SIZE,
+                               "False",
+                               _("Select page size using document page size"),
+                               &abuilder);
+
+        /* Draw Borders option */
+        g_variant_builder_init (&abuilder, G_VARIANT_TYPE ("a(ss)"));
+        g_variant_builder_add (&builder, "(ssssa(ss))",
+                               "bool",
+                               EV_PRINT_SETTING_DRAW_BORDERS,
+                               "False",
+                               _("Draw border around pages"),
+                               &abuilder);
+
+        g_variant_builder_close (&builder); // options
+        g_variant_builder_close (&builder); // section
+        g_variant_builder_close (&builder); // sections
+        g_variant_builder_close (&builder); // page
+
+        return g_variant_builder_end (&builder);
+}
+
 /* Export interface */
 #define EV_TYPE_PRINT_OPERATION_EXPORT            (ev_print_operation_export_get_type())
 #define EV_PRINT_OPERATION_EXPORT(object)         (G_TYPE_CHECK_INSTANCE_CAST((object), 
EV_TYPE_PRINT_OPERATION_EXPORT, EvPrintOperationExport))
@@ -1684,18 +1760,18 @@ export_portal_create_proxy_cb (GObject *source,
         export_portal_subscribe_response (export_portal);
 
 #if 0
-        /* FIXMEchpe: There is no way to specify the GtkPrintCapabilities
-         * and the custom options. Needs to be fixed in the Portal!
+        /* FIXMEchpe: Do we need to pass the GtkPrintCapabilities also with the portal?
+         * If so, needs to be added to the Portal first.
          */
         capabilities = GTK_PRINT_CAPABILITY_PREVIEW |
                 ev_file_exporter_get_capabilities (EV_FILE_EXPORTER (op->document));
         /* ... */
-        /* install custom options... */
 #endif
 
         g_variant_builder_init (&options_builder, G_VARIANT_TYPE_VARDICT);
         g_variant_builder_add (&options_builder, "{sv}", "handle_token", g_variant_new_string (token));
         g_variant_builder_add (&options_builder, "{sv}", "modal", g_variant_new_boolean (TRUE));
+        g_variant_builder_add (&options_builder, "{sv}", "custom-options", 
ev_print_operation_get_custom_options ());
         g_free (token);
 
         options_variant = g_variant_builder_end (&options_builder);
@@ -2283,11 +2359,6 @@ typedef enum {
        EV_SCALE_FIT_TO_PRINTABLE_AREA
 } EvPrintScale;
 
-#define EV_PRINT_SETTING_PAGE_SCALE   "evince-print-setting-page-scale"
-#define EV_PRINT_SETTING_AUTOROTATE   "evince-print-setting-page-autorotate"
-#define EV_PRINT_SETTING_PAGE_SIZE    "evince-print-setting-page-size"
-#define EV_PRINT_SETTING_DRAW_BORDERS "evince-print-setting-page-draw-borders"
-
 struct _EvPrintOperationPrint {
        EvPrintOperation parent;
 
@@ -2850,6 +2921,11 @@ ev_print_operation_print_init (EvPrintOperationPrint *print)
        gtk_print_operation_set_unit (print->op, GTK_UNIT_POINTS);
        gtk_print_operation_set_custom_tab_label (print->op, _("Page Handling"));
 
+#ifdef CUSTOM_OPTIONS_ENABLED
+        gtk_print_operation_set_custom_options (print->op,
+                                                ev_print_operation_get_custom_options ());
+#endif
+
        application = g_application_get_default ();
        if (application)
                g_application_hold (application);
@@ -2888,10 +2964,12 @@ ev_print_operation_get_gtype_for_document (EvDocument *document)
         /* Allow to override the selection by an env var */
         env = g_getenv ("EV_PRINT");
 
-        if (EV_IS_DOCUMENT_PRINT (document) && g_strcmp0 (env, "export") != 0) {
+        if (EV_IS_DOCUMENT_PRINT (document) &&
+            g_strcmp0 (env, "export") != 0 &&
+            g_strcmp0 (env, "export-portal") != 0) {
                 type = EV_TYPE_PRINT_OPERATION_PRINT;
         } else if (EV_IS_FILE_EXPORTER (document)) {
-                if (ev_should_use_portal ()) {
+                if (ev_should_use_portal () || g_strcmp0 (env, "export-portal") == 0) {
 #ifdef PORTAL_ENABLED
                         type = EV_TYPE_PRINT_OPERATION_EXPORT_PORTAL;
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]