]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-window.c
Use GdkAppLaunchContext when available to launch external uris.
[evince.git] / shell / ev-window.c
index 9f27479c7f6c496228344c2538b4fcbe194eac66..fc8cc8dc2ba3838002b529af113903e9fbc0517a 100644 (file)
@@ -4884,25 +4884,34 @@ static void
 launch_external_uri (EvWindow *window, EvLinkAction *action)
 {
        const gchar *uri = ev_link_action_get_uri (action);
+       GAppLaunchContext *context = NULL;
        GError *error = NULL;
        gboolean ret;
+
+#if GTK_CHECK_VERSION (2, 14, 0)
+       context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+       gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
+                                          gtk_window_get_screen (GTK_WINDOW (window)));
+       gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
+                                             GDK_CURRENT_TIME);
+#endif
+
+       if (!g_strstr_len (uri, strlen (uri), "://")) {
+               gchar *http;
+               
+               /* Not a valid uri, assuming it's http */
+               http = g_strdup_printf ("http://%s", uri);
+               ret = g_app_info_launch_default_for_uri (http, NULL, &error);
+               g_free (http);
+       } else {
+               ret = g_app_info_launch_default_for_uri (uri, NULL, &error);
+       }
        
-       ret = g_app_info_launch_default_for_uri (uri, NULL, &error);
        if (ret == FALSE) {
-               GtkWidget *dialog;
-       
-               dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-                                                GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                GTK_MESSAGE_ERROR,
-                                                GTK_BUTTONS_CLOSE,
-                                                _("Unable to open external link"));
-               gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                                         error->message, uri);
-               g_signal_connect (dialog, "response",
-                                 G_CALLBACK (gtk_widget_destroy),
-                                 NULL);
-               gtk_widget_show (dialog);
-               g_error_free(error);
+               ev_window_error_message (GTK_WINDOW (window),
+                                        _("Unable to open external link"),
+                                        error);
+               g_error_free (error);
        }
 }