[eog/make-libportal-dep-optional: 2/2] build: Make libportal dependency optional



commit ca73abc36d3704c216e213642b4c5b370a55a279
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Jul 14 10:47:14 2020 +0200

    build: Make libportal dependency optional
    
    libportal makes a containerised instance of Eog able to talk to
    xdg-desktop-portals in order to integrate with the host system
    outside the container sandbox.
    
    When installed in bare-metal, Eog doesn't need to resort to portals
    to be integrated with the host system.
    
    Fixes: #137

 meson.build       | 13 ++++++++++++-
 meson_options.txt |  1 +
 src/eog-util.c    |  4 ++++
 src/eog-util.h    |  2 ++
 src/eog-window.c  |  7 +++++--
 src/meson.build   |  1 -
 6 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/meson.build b/meson.build
index e91e1e4fe..a11ffe035 100644
--- a/meson.build
+++ b/meson.build
@@ -109,7 +109,6 @@ gio_dep = dependency('gio-2.0', version: glib_req_version)
 gio_unix_dep = dependency('gio-unix-2.0', version: glib_req_version)
 gnome_desktop_dep = dependency('gnome-desktop-3.0', version: '>= 2.91.2')
 libpeas_gtk_dep = dependency('libpeas-gtk-1.0', version: peas_req_version)
-libportal_dep = dependency('libportal', version: '>= 0.3')
 
 m_dep = cc.find_library('m')
 
@@ -163,6 +162,17 @@ if enable_xmp
 endif
 config_h.set('HAVE_EXEMPI', enable_xmp)
 
+# xdg-desktop-portal support with libportal (optional)
+enable_libportal = get_option('libportal')
+if enable_libportal
+  libportal_dep = dependency('libportal', version: '>= 0.3', required: false)
+  assert(libportal_dep.found() and cc.has_header('libportal/portal.h', dependencies: libportal_dep),
+         'xdg-desktop-portal support requested but library not found. Please use -Dlibportal=false')
+
+  common_deps += libportal_dep
+endif
+config_h.set('HAVE_LIBPORTAL', enable_libportal)
+
 # Jpeg (semi-optional)
 enable_libjpeg = get_option('libjpeg')
 if enable_libjpeg
@@ -248,4 +258,5 @@ output += '  XMP support ................:  ' + enable_xmp.to_string() + '\n'
 output += '  JPEG support ...............:  ' + enable_libjpeg.to_string() + '\n'
 output += '  Colour management support ..:  ' + enable_cms.to_string() + '\n'
 output += '  GObject Introspection.......:  ' + enable_introspection.to_string() + '\n'
+output += '  xdg-desktop-portal support..:  ' + enable_libportal.to_string() + '\n'
 message(output)
diff --git a/meson_options.txt b/meson_options.txt
index 850525361..80b73c4b1 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -6,4 +6,5 @@ option('librsvg', type: 'boolean', value: true, description: 'enable RSVG suppor
 option('gtk_doc', type: 'boolean', value: false, description: 'use gtk-doc to build documentation')
 option('introspection', type: 'boolean', value: true, description: 'Enable GObject Introspection (depends on 
GObject)')
 option('installed_tests', type: 'boolean', value: false, description: 'enable installed unit tests')
+option('libportal', type: 'boolean', value: true, description: 'Enable xdg-desktop-portal support')
 option('profile', type: 'combo', choices: ['default', 'Devel'], value: 'default', description: 'Build 
profile')
diff --git a/src/eog-util.c b/src/eog-util.c
index 02cc802cc..076fe1084 100644
--- a/src/eog-util.c
+++ b/src/eog-util.c
@@ -43,8 +43,10 @@
 #include <gtk/gtk.h>
 #include <gio/gio.h>
 #include <glib/gi18n.h>
+#ifdef HAVE_LIBPORTAL
 #include <libportal/portal.h>
 #include <libportal/portal-gtk3.h>
+#endif
 
 void
 eog_util_show_help (const gchar *section, GtkWindow *parent)
@@ -508,6 +510,7 @@ eog_util_show_file_in_filemanager (GFile *file, GtkWindow *toplevel)
 
 /* Portal */
 
+#ifdef HAVE_LIBPORTAL
 gboolean
 eog_util_is_running_inside_flatpak (void)
 {
@@ -547,3 +550,4 @@ eog_util_open_file_with_flatpak_portal (GFile *file, GtkWindow *window)
                             NULL);
        xdp_parent_free (parent);
 }
+#endif
diff --git a/src/eog-util.h b/src/eog-util.h
index a87c97c3d..c3a2150fb 100644
--- a/src/eog-util.h
+++ b/src/eog-util.h
@@ -69,12 +69,14 @@ G_GNUC_INTERNAL
 void     eog_util_show_file_in_filemanager   (GFile *file,
                                               GtkWindow *toplevel);
 
+#ifdef HAVE_LIBPORTAL
 G_GNUC_INTERNAL
 gboolean eog_util_is_running_inside_flatpak  (void);
 
 G_GNUC_INTERNAL
 void     eog_util_open_file_with_flatpak_portal (GFile *file,
                                                  GtkWindow *window);
+#endif
 
 G_END_DECLS
 
diff --git a/src/eog-window.c b/src/eog-window.c
index 76844556f..afbf5e3a9 100644
--- a/src/eog-window.c
+++ b/src/eog-window.c
@@ -1106,14 +1106,17 @@ eog_window_action_open_with (GSimpleAction *action,
        g_return_if_fail (EOG_IS_WINDOW (user_data));
        window = EOG_WINDOW (user_data);
 
+#ifdef HAVE_LIBPORTAL
        if (eog_util_is_running_inside_flatpak ()) {
                GFile *file = eog_image_get_file (window->priv->image);
 
                eog_util_open_file_with_flatpak_portal (file, GTK_WINDOW (window));
                g_object_unref (file);
-       } else {
-               eog_window_open_file_chooser_dialog (window);
+
+               return;
        }
+#endif
+       eog_window_open_file_chooser_dialog (window);
 }
 
 static void
diff --git a/src/meson.build b/src/meson.build
index 4c0f35c50..7416a2080 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -128,7 +128,6 @@ deps = common_deps + [
   gio_unix_dep,
   gnome_desktop_dep,
   libpeas_gtk_dep,
-  libportal_dep,
   m_dep,
   zlib_dep,
 ]


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