Fallback on the "open with" dialog when no "open" action is available

This commit is contained in:
Pierre Pronchery 2007-06-29 15:15:37 +00:00
parent 2ed2e22d4a
commit 5328dbab77
2 changed files with 14 additions and 6 deletions

View File

@ -747,6 +747,7 @@ void on_detail_default(GtkTreeView * view, GtkTreePath * path,
_default_do(browser, path); _default_do(browser, path);
} }
static void _do_open_with(Browser * browser, char const * location);
static void _default_do(Browser * browser, GtkTreePath * path) static void _default_do(Browser * browser, GtkTreePath * path)
{ {
char * location; char * location;
@ -758,8 +759,9 @@ static void _default_do(Browser * browser, GtkTreePath * path)
&location, BR_COL_IS_DIRECTORY, &is_dir, -1); &location, BR_COL_IS_DIRECTORY, &is_dir, -1);
if(is_dir) if(is_dir)
browser_set_location(browser, location); browser_set_location(browser, location);
else if(browser->mime != NULL) else if(browser->mime == NULL
mime_action(browser->mime, "open", location); || mime_action(browser->mime, "open", location) != 0)
_do_open_with(browser, location);
g_free(location); g_free(location);
} }
@ -1089,12 +1091,18 @@ static void _on_icon_edit(GtkWidget * widget, gpointer data)
static void _on_icon_open_with(GtkWidget * widget, gpointer data) static void _on_icon_open_with(GtkWidget * widget, gpointer data)
{ {
IconCallback * cb = data; IconCallback * cb = data;
_do_open_with(cb->browser, cb->path);
}
static void _do_open_with(Browser * browser, char const * location)
{
GtkWidget * dialog; GtkWidget * dialog;
char * filename = NULL; char * filename = NULL;
pid_t pid; pid_t pid;
dialog = gtk_file_chooser_dialog_new("Open with...", dialog = gtk_file_chooser_dialog_new("Open with...",
GTK_WINDOW(cb->browser->window), GTK_WINDOW(browser->window),
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN,
GTK_RESPONSE_ACCEPT, NULL); GTK_RESPONSE_ACCEPT, NULL);
@ -1105,10 +1113,10 @@ static void _on_icon_open_with(GtkWidget * widget, gpointer data)
if(filename == NULL) if(filename == NULL)
return; return;
if((pid = fork()) == -1) if((pid = fork()) == -1)
browser_error(cb->browser, "fork", 0); browser_error(browser, "fork", 0);
else if(pid == 0) else if(pid == 0)
{ {
execlp(filename, filename, cb->path, NULL); execlp(filename, filename, location, NULL);
browser_error(NULL, filename, 0); browser_error(NULL, filename, 0);
exit(2); exit(2);
} }

View File

@ -70,7 +70,7 @@ Mime * mime_new(void)
glob = strchr(buf, ':'); glob = strchr(buf, ':');
*(glob++) = '\0'; *(glob++) = '\0';
if((p = realloc(mime->types, sizeof(*(mime->types)) if((p = realloc(mime->types, sizeof(*(mime->types))
* (mime->types_cnt+1))) == NULL) *(mime->types_cnt+1))) == NULL)
break; break;
mime->types = p; mime->types = p;
p[mime->types_cnt].type = strdup(buf); p[mime->types_cnt].type = strdup(buf);