[gnome-software/gnome-3-22] Use gtk_show_uri_on_window() with newer GTK+



commit 9de66e480d06c297aa32106e6e99d4a52e943195
Author: Kalev Lember <klember redhat com>
Date:   Tue Mar 7 19:51:55 2017 +0100

    Use gtk_show_uri_on_window() with newer GTK+
    
    The gtk_show_uri() function won't work correctly inside a sandbox, and
    has been deprecated in GTK+ 3.22.

 src/gs-auth-dialog.c   |   10 ++++++++++
 src/gs-common.c        |   11 -----------
 src/gs-common.h        |    2 --
 src/gs-shell-details.c |    5 +++--
 src/gs-shell-extras.c  |    3 ++-
 src/gs-shell-search.c  |    3 ++-
 src/gs-shell-updates.c |    3 +--
 src/gs-shell.c         |   25 +++++++++++++++++++++++++
 src/gs-shell.h         |    2 ++
 9 files changed, 45 insertions(+), 19 deletions(-)
---
diff --git a/src/gs-auth-dialog.c b/src/gs-auth-dialog.c
index 21743da..3ffbfec 100644
--- a/src/gs-auth-dialog.c
+++ b/src/gs-auth-dialog.c
@@ -134,10 +134,20 @@ gs_auth_dialog_authenticate_cb (GObject *source,
                if (url != NULL) {
                        g_autoptr(GError) error_local = NULL;
                        g_debug ("showing link in: %s", error->message);
+#if GTK_CHECK_VERSION (3, 22, 0)
+                       if (!gtk_show_uri_on_window (GTK_WINDOW (dialog),
+                                                    url,
+                                                    GDK_CURRENT_TIME,
+                                                    &error)) {
+                               g_warning ("failed to show URI %s: %s",
+                                          url, error_local->message);
+                       }
+#else
                        if (!gtk_show_uri (NULL, url, GDK_CURRENT_TIME, &error_local)) {
                                g_warning ("failed to show URI %s: %s",
                                           url, error_local->message);
                        }
+#endif
                        return;
                }
 
diff --git a/src/gs-common.c b/src/gs-common.c
index 336b22c..30b20b0 100644
--- a/src/gs-common.c
+++ b/src/gs-common.c
@@ -357,17 +357,6 @@ gs_app_notify_unavailable (GsApp *app, GtkWindow *parent)
 }
 
 void
-gs_app_show_url (GsApp *app, AsUrlKind kind)
-{
-       const gchar *url;
-       g_autoptr(GError) error = NULL;
-
-       url = gs_app_get_url (app, kind);
-       if (!gtk_show_uri (NULL, url, GDK_CURRENT_TIME, &error))
-               g_warning ("spawn of '%s' failed", url);
-}
-
-void
 gs_image_set_from_pixbuf_with_scale (GtkImage *image, const GdkPixbuf *pixbuf, gint scale)
 {
        cairo_surface_t *surface;
diff --git a/src/gs-common.h b/src/gs-common.h
index d7009ad..e721119 100644
--- a/src/gs-common.h
+++ b/src/gs-common.h
@@ -43,8 +43,6 @@ void   gs_app_notify_failed_modal     (GsApp          *app,
 GtkResponseType
        gs_app_notify_unavailable       (GsApp          *app,
                                         GtkWindow      *parent);
-void    gs_app_show_url                (GsApp          *app,
-                                        AsUrlKind       kind);
 
 void   gs_image_set_from_pixbuf_with_scale     (GtkImage               *image,
                                                 const GdkPixbuf        *pixbuf,
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 3abc0b6..bb64352 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -642,7 +642,8 @@ gs_shell_details_refresh_screenshots (GsShellDetails *self)
 static void
 gs_shell_details_website_cb (GtkWidget *widget, GsShellDetails *self)
 {
-       gs_app_show_url (self->app, AS_URL_KIND_HOMEPAGE);
+       gs_shell_show_uri (self->shell,
+                          gs_app_get_url (self->app, AS_URL_KIND_HOMEPAGE));
 }
 
 static void
@@ -1744,7 +1745,7 @@ gs_shell_details_activate_link_cb (GtkLabel *label,
                                   const gchar *uri,
                                   GsShellDetails *self)
 {
-       gtk_show_uri (NULL, uri, GDK_CURRENT_TIME, NULL);
+       gs_shell_show_uri (self->shell, uri);
        return TRUE;
 }
 
diff --git a/src/gs-shell-extras.c b/src/gs-shell-extras.c
index 0451822..6710431 100644
--- a/src/gs-shell-extras.c
+++ b/src/gs-shell-extras.c
@@ -1045,7 +1045,8 @@ row_activated_cb (GtkListBox *list_box,
 
        if (gs_app_get_state (app) == AS_APP_STATE_UNAVAILABLE &&
            gs_app_get_url (app, AS_URL_KIND_MISSING) != NULL) {
-               gs_app_show_url (app, AS_URL_KIND_MISSING);
+               gs_shell_show_uri (self->shell,
+                                  gs_app_get_url (app, AS_URL_KIND_MISSING));
        } else {
                gs_shell_show_app (self->shell, app);
        }
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index af94727..d1b3b05 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -78,7 +78,8 @@ gs_shell_search_app_row_clicked_cb (GsAppRow *app_row,
                        gs_page_install_app (GS_PAGE (self), app, self->cancellable);
                        return;
                }
-               gs_app_show_url (app, AS_URL_KIND_MISSING);
+               gs_shell_show_uri (self->shell,
+                                  gs_app_get_url (app, AS_URL_KIND_MISSING));
        }
 }
 
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index a74a3b0..0706d03 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -1223,8 +1223,7 @@ gs_shell_updates_upgrade_help_cb (GsUpgradeBanner *upgrade_banner,
 
        /* open the link */
        uri = gs_app_get_url (app, AS_URL_KIND_HOMEPAGE);
-       if (!gtk_show_uri (NULL, uri, GDK_CURRENT_TIME, &error))
-               g_warning ("failed to open %s: %s", uri, error->message);
+       gs_shell_show_uri (self->shell, uri);
 }
 
 static void
diff --git a/src/gs-shell.c b/src/gs-shell.c
index bb5104d..88e701c 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -946,6 +946,31 @@ gs_shell_show_search_result (GsShell *shell, const gchar *id, const gchar *searc
                              (gpointer) search, TRUE);
 }
 
+void
+gs_shell_show_uri (GsShell *shell, const gchar *url)
+{
+       GsShellPrivate *priv = gs_shell_get_instance_private (shell);
+       g_autoptr(GError) error = NULL;
+
+#if GTK_CHECK_VERSION (3, 22, 0)
+       if (!gtk_show_uri_on_window (priv->main_window,
+                                    url,
+                                    GDK_CURRENT_TIME,
+                                    &error)) {
+               g_warning ("failed to show URI %s: %s",
+                          url, error->message);
+       }
+#else
+       if (!gtk_show_uri (NULL,
+                          url,
+                          GDK_CURRENT_TIME,
+                          &error)) {
+               g_warning ("failed to show URI %s: %s",
+                          url, error->message);
+       }
+#endif
+}
+
 static void
 gs_shell_dispose (GObject *object)
 {
diff --git a/src/gs-shell.h b/src/gs-shell.h
index 629c631..d948486 100644
--- a/src/gs-shell.h
+++ b/src/gs-shell.h
@@ -86,6 +86,8 @@ void           gs_shell_show_search_result    (GsShell        *shell,
 void            gs_shell_show_extras_search    (GsShell        *shell,
                                                 const gchar    *mode,
                                                 gchar          **resources);
+void            gs_shell_show_uri              (GsShell        *shell,
+                                                const gchar    *url);
 void            gs_shell_setup                 (GsShell        *shell,
                                                 GsPluginLoader *plugin_loader,
                                                 GCancellable   *cancellable);


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