[evince/wip/chpe/export-print-portal: 7/8] libdocument: Add portal helper function




commit fdc8c4375d5cd7b1d24ca0c94dd9de959d666fc9
Author: Christian Persch <chpe src gnome org>
Date:   Tue Jan 11 18:25:31 2022 +0100

    libdocument: Add portal helper function
    
    Add ev_should_use_portal() copied from gtk+, which tries to find
    out whether the portal should be used.

 libdocument/ev-portal.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
 libdocument/ev-portal.h | 33 ++++++++++++++++++++++++++++++
 libdocument/meson.build |  2 ++
 3 files changed, 88 insertions(+)
---
diff --git a/libdocument/ev-portal.c b/libdocument/ev-portal.c
new file mode 100644
index 000000000..e357731cf
--- /dev/null
+++ b/libdocument/ev-portal.c
@@ -0,0 +1,53 @@
+/*
+ * Evince 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.1 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince 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 General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "ev-portal.h"
+
+/* Copied from gtk+, under LGPL2.1+ */
+
+/**
+ * ev_should_use_portal:
+ *
+ * Checks whether evince should use the portal.
+ *
+ * Returns: whether evince should use the portal
+ *
+ * Since: 3.30
+ */
+gboolean
+ev_should_use_portal (void)
+{
+        static const char *use_portal = NULL;
+
+        if (G_UNLIKELY (use_portal == NULL))
+                {
+                        char *path;
+
+                        path = g_build_filename (g_get_user_runtime_dir (), "flatpak-info", NULL);
+                        if (g_file_test (path, G_FILE_TEST_EXISTS))
+                                use_portal = "1";
+                        else
+                                {
+                                        use_portal = g_getenv ("GTK_USE_PORTAL");
+                                        if (!use_portal)
+                                                use_portal = "";
+                                }
+                        g_free (path);
+                }
+
+        return use_portal[0] == '1';
+}
diff --git a/libdocument/ev-portal.h b/libdocument/ev-portal.h
new file mode 100644
index 000000000..a8fa27d99
--- /dev/null
+++ b/libdocument/ev-portal.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright © 2018 Christian Persch
+ *
+ * Evince 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.1 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince 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 General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#if !defined (EVINCE_COMPILATION)
+#error "This is a private header."
+#endif
+
+#include <glib.h>
+
+#include "ev-macros.h"
+
+G_BEGIN_DECLS
+
+EV_PRIVATE
+gboolean ev_should_use_portal (void);
+
+G_END_DECLS
diff --git a/libdocument/meson.build b/libdocument/meson.build
index 2f04fa1dd..a1e292cdc 100644
--- a/libdocument/meson.build
+++ b/libdocument/meson.build
@@ -37,6 +37,7 @@ headers = files(
   'ev-mapping-list.h',
   'ev-media.h',
   'ev-page.h',
+  'ev-portal.h',
   'ev-render-context.h',
   'ev-selection.h',
   'ev-transition-effect.h',
@@ -83,6 +84,7 @@ sources = files(
   'ev-media.c',
   'ev-module.c',
   'ev-page.c',
+  'ev-portal.c',
   'ev-render-context.c',
   'ev-selection.c',
   'ev-transition-effect.c',


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