]> git.street.me.uk Git - andy/viking.git/commitdiff
Improved usage of GTK+2.14 features for URIs.
authorRob Norris <rw_norris@hotmail.com>
Mon, 18 Mar 2013 20:32:01 +0000 (20:32 +0000)
committerRob Norris <rw_norris@hotmail.com>
Wed, 10 Apr 2013 17:54:23 +0000 (18:54 +0100)
Use gtk_show_uri() rather than own specific functions.

src/util.c

index 92457b82526049bd3e44c22050a0a29a38300179..5d329d7807d906b4f44b501ea8843b9d8fdd4b60 100644 (file)
 #include "config.h"
 #endif
 
-#ifdef WINDOWS
-#include <windows.h>
-#endif
-
 #include <glib/gi18n.h>
 #include <glib/gprintf.h>
 
 #include "util.h"
 #include "dialog.h"
 
+/*
+#ifdef WINDOWS
+#include <windows.h>
+#endif
+
 #ifndef WINDOWS
 static gboolean spawn_command_line_async(const gchar * cmd,
                                          const gchar * arg)
@@ -48,53 +49,38 @@ static gboolean spawn_command_line_async(const gchar * cmd,
   return status;
 }
 #endif
+*/
 
 void open_url(GtkWindow *parent, const gchar * url)
 {
-#ifdef WINDOWS
-  ShellExecute(NULL, NULL, (char *) url, NULL, ".\\", 0);
-#else /* WINDOWS */
-  const gchar *browsers[] = {
-    "xdg-open", "gnome-open", "kfmclient openURL",
-    "sensible-browser", "firefox", "epiphany",
-    "iceweasel", "seamonkey", "galeon", "mozilla",
-    "opera", "konqueror", "netscape", "links -g",
-    "chromium-browser", "chromium", "chrome",
-    "safari", "camino", "omniweb", "icab",
-    NULL
-  };
-  gint i=0;
-  
-  const gchar *browser = g_getenv("BROWSER");
-  if (browser == NULL || browser[0] == '\0') {
-    /* $BROWSER not set -> use first entry */
-    browser = browsers[i++];
+  GError *error = NULL;
+  gtk_show_uri ( gtk_widget_get_screen (GTK_WIDGET(parent)), url, GDK_CURRENT_TIME, &error );
+  if ( error ) {
+    a_dialog_error_msg_extra ( parent, _("Could not launch web browser. %s"), error->message );
+    g_error_free ( error );
   }
-  do {
-    if (spawn_command_line_async(browser, url)) {
-      return;
-    }
-
-    browser = browsers[i++];
-  } while(browser);
-  
-  a_dialog_error_msg ( parent, _("Could not launch web browser.") );
-#endif /* WINDOWS */
 }
 
 void new_email(GtkWindow *parent, const gchar * address)
 {
   gchar *uri = g_strdup_printf("mailto:%s", address);
+  GError *error = NULL;
+  gtk_show_uri ( gtk_widget_get_screen (GTK_WIDGET(parent)), uri, GDK_CURRENT_TIME, &error );
+  if ( error ) {
+    a_dialog_error_msg_extra ( parent, _("Could not create new email. %s"), error->message );
+    g_error_free ( error );
+  }
+  /*
 #ifdef WINDOWS
   ShellExecute(NULL, NULL, (char *) uri, NULL, ".\\", 0);
-#else /* WINDOWS */
+#else
   if (!spawn_command_line_async("xdg-email", uri))
     a_dialog_error_msg ( parent, _("Could not create new email.") );
-#endif /* WINDOWS */
+#endif
+  */
   g_free(uri);
   uri = NULL;
 }
-
 gchar *uri_escape(gchar *str)
 {
   gchar *esc_str = g_malloc(3*strlen(str));