[gnome-builder] gtk: extract xdg-open helper into new function



commit 4ac5e28a8294ef69cbe2073a7fd8f2732f3266da
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 16 12:57:01 2018 -0700

    gtk: extract xdg-open helper into new function
    
    This makes it easier for us to drop this in the future once things work as
    we expect them to.

 src/libide/application/ide-application-actions.c | 28 ++-------------
 src/libide/util/ide-gtk.c                        | 43 ++++++++++++++++++++++++
 src/libide/util/ide-gtk.h                        |  5 +++
 3 files changed, 51 insertions(+), 25 deletions(-)
---
diff --git a/src/libide/application/ide-application-actions.c 
b/src/libide/application/ide-application-actions.c
index cecb74633..480b2f01b 100644
--- a/src/libide/application/ide-application-actions.c
+++ b/src/libide/application/ide-application-actions.c
@@ -38,6 +38,7 @@
 #include "subprocess/ide-subprocess-launcher.h"
 #include "workbench/ide-workbench.h"
 #include "util/ide-flatpak.h"
+#include "util/ide-gtk.h"
 
 static void
 ide_application_actions_preferences (GSimpleAction *action,
@@ -212,31 +213,8 @@ ide_application_actions_help_cb (GObject      *object,
 
       g_debug ("Documentation URI: %s", uri);
 
-      if (ide_is_flatpak ())
-        {
-          g_autoptr(IdeSubprocessLauncher) launcher = NULL;
-          g_autoptr(IdeSubprocess) subprocess = NULL;
-
-          /* We can't currently trust gtk_show_uri_on_window() because it tries
-           * to open our HTML page with Builder inside our current flatpak
-           * environment! We need to ensure this is fixed upstream, but it's
-           * currently unclear how to do so since we register handles for html.
-           */
-
-          launcher = ide_subprocess_launcher_new (0);
-          ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
-          ide_subprocess_launcher_set_clear_env (launcher, FALSE);
-          ide_subprocess_launcher_push_argv (launcher, "xdg-open");
-          ide_subprocess_launcher_push_argv (launcher, uri);
-
-          if (!(subprocess = ide_subprocess_launcher_spawn (launcher, NULL, &error)))
-            g_warning ("Failed to spawn xdg-open for documentation: %s", error->message);
-        }
-      else
-        {
-          if (!gtk_show_uri_on_window (focused_window, uri, gtk_get_current_event_time (), &error))
-            g_warning ("Failed to load documentation: %s", error->message);
-        }
+      if (!ide_gtk_show_uri_on_window (focused_window, uri, gtk_get_current_event_time (), &error))
+        g_warning ("Failed to load documentation: %s", error->message);
 
       IDE_EXIT;
     }
diff --git a/src/libide/util/ide-gtk.c b/src/libide/util/ide-gtk.c
index a9d78a1f4..9fc9c284b 100644
--- a/src/libide/util/ide-gtk.c
+++ b/src/libide/util/ide-gtk.c
@@ -20,7 +20,12 @@
 
 #include "config.h"
 
+#include <gtk/gtk.h>
+
 #include "application/ide-application.h"
+#include "subprocess/ide-subprocess.h"
+#include "subprocess/ide-subprocess-launcher.h"
+#include "util/ide-flatpak.h"
 #include "util/ide-gtk.h"
 
 static GQuark quark_handler;
@@ -225,3 +230,41 @@ ide_widget_warning (gpointer     instance,
   else
     g_warning ("%s", str);
 }
+
+gboolean
+ide_gtk_show_uri_on_window (GtkWindow    *window,
+                            const gchar  *uri,
+                            guint32       timestamp,
+                            GError      **error)
+{
+  g_return_val_if_fail (!window || GTK_IS_WINDOW (window), FALSE);
+  g_return_val_if_fail (uri != NULL, FALSE);
+
+  if (ide_is_flatpak ())
+    {
+      g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+      g_autoptr(IdeSubprocess) subprocess = NULL;
+
+      /* We can't currently trust gtk_show_uri_on_window() because it tries
+       * to open our HTML page with Builder inside our current flatpak
+       * environment! We need to ensure this is fixed upstream, but it's
+       * currently unclear how to do so since we register handles for html.
+       */
+
+      launcher = ide_subprocess_launcher_new (0);
+      ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
+      ide_subprocess_launcher_set_clear_env (launcher, FALSE);
+      ide_subprocess_launcher_push_argv (launcher, "xdg-open");
+      ide_subprocess_launcher_push_argv (launcher, uri);
+
+      if (!(subprocess = ide_subprocess_launcher_spawn (launcher, NULL, error)))
+        return FALSE;
+    }
+  else
+    {
+      if (!gtk_show_uri_on_window (window, uri, gtk_get_current_event_time (), error))
+        return FALSE;
+    }
+
+  return TRUE;
+}
diff --git a/src/libide/util/ide-gtk.h b/src/libide/util/ide-gtk.h
index bacfc7e5c..c9c5173fb 100644
--- a/src/libide/util/ide-gtk.h
+++ b/src/libide/util/ide-gtk.h
@@ -46,5 +46,10 @@ IDE_AVAILABLE_IN_3_28
 void          ide_widget_warning             (gpointer                 instance,
                                               const gchar             *format,
                                               ...) G_GNUC_PRINTF (2, 3);
+IDE_AVAILABLE_IN_3_30
+gboolean      ide_gtk_show_uri_on_window     (GtkWindow               *window,
+                                              const gchar             *uri,
+                                              guint32                  timestamp,
+                                              GError                 **error);
 
 G_END_DECLS


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