Unify opening URIs externally with good fallbacks
This commit is contained in:
parent
574fccf445
commit
ca8d181329
5 changed files with 56 additions and 38 deletions
|
@ -939,15 +939,8 @@ midori_browser_download_button_clicked_cb (GtkWidget* button,
|
|||
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;
|
||||
}
|
||||
|
@ -2402,8 +2395,6 @@ midori_browser_source_transfer_cb (KatzeNetRequest* request,
|
|||
{
|
||||
if ((fp = fdopen (fd, "w")))
|
||||
{
|
||||
gboolean success;
|
||||
|
||||
ret = fwrite (request->data, 1, request->length, fp);
|
||||
fclose (fp);
|
||||
if ((ret - request->length) != 0)
|
||||
|
@ -2415,13 +2406,10 @@ midori_browser_source_transfer_cb (KatzeNetRequest* request,
|
|||
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);
|
||||
|
@ -3100,13 +3088,7 @@ _action_about_activate_email (GtkAboutDialog* about,
|
|||
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
|
||||
|
|
|
@ -1847,13 +1847,7 @@ midori_view_set_uri (MidoriView* view,
|
|||
}
|
||||
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
|
||||
{
|
||||
|
|
|
@ -93,6 +93,48 @@ error_dialog (const gchar* short_message,
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
|
|
|
@ -26,6 +26,12 @@ sokoke_js_script_eval (JSContextRef js_context,
|
|||
/* 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);
|
||||
|
|
|
@ -329,14 +329,8 @@ midori_transfers_treeview_row_activated_cb (GtkTreeView* treeview,
|
|||
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:
|
||||
|
|
Loading…
Reference in a new issue