[evince/wip/chpe/export-print-portal: 982/985] libdocument: Add portal helper function




commit d97a4b990689bca8a14bee7f2968e714e0de647b
Author: Christian Persch <chpe src gnome org>
Date:   Sat Nov 13 16:40:52 2021 +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.

 help/reference/libdocument/libevdocument-docs.xml  |  4 ++
 .../libdocument/libevdocument-sections.txt         |  5 ++
 libdocument/ev-portal.c                            | 53 ++++++++++++++++++++++
 libdocument/ev-portal.h                            | 33 ++++++++++++++
 libdocument/meson.build                            |  2 +
 5 files changed, 97 insertions(+)
---
diff --git a/help/reference/libdocument/libevdocument-docs.xml 
b/help/reference/libdocument/libevdocument-docs.xml
index baaca8a62..1125e3e84 100644
--- a/help/reference/libdocument/libevdocument-docs.xml
+++ b/help/reference/libdocument/libevdocument-docs.xml
@@ -172,6 +172,10 @@
     <title>Index of new symbols in 3.18</title>
     <xi:include href="xml/api-index-3.18.xml"><xi:fallback /></xi:include>
   </index>
+  <index id="api-index-3-30" role="3.30">
+    <title>Index of new symbols in 3.30</title>
+    <xi:include href="xml/api-index-3.30.xml"><xi:fallback /></xi:include>
+  </index>
 
   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
 
diff --git a/help/reference/libdocument/libevdocument-sections.txt 
b/help/reference/libdocument/libevdocument-sections.txt
index 54095eda7..3fdb8bde8 100644
--- a/help/reference/libdocument/libevdocument-sections.txt
+++ b/help/reference/libdocument/libevdocument-sections.txt
@@ -784,6 +784,11 @@ ev_init
 ev_shutdown
 </SECTION>
 
+<SECTION>
+<FILE>ev-portal</FILE>
+ev_should_use_portal
+</SECTION>
+
 <SECTION>
 <FILE>ev-mapping</FILE>
 EvMapping
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..799c1b2fc
--- /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/>.
+ */
+
+#if !defined (__EV_EVINCE_DOCUMENT_H_INSIDE__) && !defined (EVINCE_COMPILATION)
+#error "Only <evince-document.h> can be included directly."
+#endif
+
+#ifndef EV_PORTAL_H
+#define EV_PORTAL_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gboolean ev_should_use_portal (void);
+
+G_END_DECLS
+
+#endif /* EV_PORTAL_H */
diff --git a/libdocument/meson.build b/libdocument/meson.build
index e09de7fcb..ec7d01082 100644
--- a/libdocument/meson.build
+++ b/libdocument/meson.build
@@ -38,6 +38,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]