case WEBKIT_DOWNLOAD_STATUS_FINISHED:
{
const gchar* uri = webkit_download_get_destination_uri (download);
- gboolean success = gtk_show_uri (gtk_widget_get_screen (button),
- uri, gtk_get_current_event_time (), NULL);
- if (!success)
- {
- gchar* command = g_strconcat ("exo-open ", uri, NULL);
- success = g_spawn_command_line_async (command, NULL);
- g_free (command);
- }
- if (success)
+ if (sokoke_show_uri (gtk_widget_get_screen (button),
+ uri, gtk_get_current_event_time (), NULL))
gtk_widget_destroy (gtk_widget_get_parent (button));
break;
}
{
if ((fp = fdopen (fd, "w")))
{
- gboolean success;
-
ret = fwrite (request->data, 1, request->length, fp);
fclose (fp);
if ((ret - request->length) != 0)
g_object_get (browser->settings,
"text-editor", &text_editor, NULL);
if (text_editor && *text_editor)
- success = sokoke_spawn_program (text_editor, unique_filename);
+ sokoke_spawn_program (text_editor, unique_filename);
else
- {
- gchar* command = g_strconcat ("exo-open ", unique_filename, NULL);
- success = g_spawn_command_line_async (command, NULL);
- g_free (command);
- }
+ sokoke_show_uri (NULL, unique_filename,
+ gtk_get_current_event_time (), NULL);
g_free (unique_filename);
g_free (text_editor);
const gchar* uri,
gpointer user_data)
{
- if (!gtk_show_uri (NULL, uri, GDK_CURRENT_TIME, NULL))
- {
- /* Fallback to Exo for example if GConf isn't setup */
- gchar* command = g_strconcat ("exo-open ", uri, NULL);
- g_spawn_command_line_async (command, NULL);
- g_free (command);
- }
+ sokoke_show_uri (NULL, uri, GDK_CURRENT_TIME, NULL);
}
static void
}
else if (g_str_has_prefix (uri, "mailto:"))
{
- if (!gtk_show_uri (NULL, uri, GDK_CURRENT_TIME, NULL))
- {
- /* Fallback to Exo for example if GConf isn't setup */
- gchar* command = g_strconcat ("exo-open ", uri, NULL);
- g_spawn_command_line_async (command, NULL);
- g_free (command);
- }
+ sokoke_show_uri (NULL, uri, GDK_CURRENT_TIME, NULL);
}
else
{
}
+/**
+ * sokoke_show_uri:
+ * @screen: a #GdkScreen, or %NULL
+ * @uri: the URI to show
+ * @timestamp: the timestamp of the event
+ * @error: the location of a #GError, or %NULL
+ *
+ * Shows the specified URI with an appropriate application. This
+ * supports xdg-open, exo-open and gnome-open as fallbacks if
+ * GIO doesn't do the trick.
+ *
+ * Return value: %TRUE on success, %FALSE if an error occurred
+ **/
+gboolean
+sokoke_show_uri (GdkScreen* screen,
+ const gchar* uri,
+ guint32 timestamp,
+ GError** error)
+{
+ const gchar* fallbacks [] = { "xdg-open", "exo-open", "gnome-open" };
+ gsize i;
+
+ g_return_val_if_fail (GDK_IS_SCREEN (screen) || !screen, FALSE);
+ g_return_val_if_fail (uri != NULL, FALSE);
+ g_return_val_if_fail (!error || !*error, FALSE);
+
+ if (gtk_show_uri (screen, uri, timestamp, error))
+ return TRUE;
+
+ for (i = 0; i < G_N_ELEMENTS (fallbacks); i++)
+ {
+ gchar* command = g_strconcat (fallbacks[i], " ", uri, NULL);
+ gboolean result = g_spawn_command_line_async (command, error);
+ g_free (command);
+ if (result)
+ return TRUE;
+ *error = NULL;
+ }
+
+ return FALSE;
+}
+
gboolean
sokoke_spawn_program (const gchar* command,
const gchar* argument)
/* Many themes need this hack for small toolbars to work */
#define GTK_ICON_SIZE_SMALL_TOOLBAR GTK_ICON_SIZE_BUTTON
+gboolean
+sokoke_show_uri (GdkScreen* screen,
+ const gchar* uri,
+ guint32 timestamp,
+ GError** error);
+
gboolean
sokoke_spawn_program (const gchar* command,
const gchar* argument);
gboolean success;
uri = webkit_download_get_destination_uri (download);
- success = gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (
+ sokoke_show_uri (gtk_widget_get_screen (GTK_WIDGET (
treeview)), uri, gtk_get_current_event_time (), NULL);
- if (!success)
- {
- gchar* command = g_strconcat ("exo-open ", uri, NULL);
- success = g_spawn_command_line_async (command, NULL);
- g_free (command);
- }
break;
}
case WEBKIT_DOWNLOAD_STATUS_CANCELLED: