Commit 34d59409 authored by Christian Neumair's avatar Christian Neumair Committed by Christian Neumair

Use vararg list for nautilus_launch_application_from_command(). Add

2008-08-20  Christian Neumair  <cneumair@gnome.org>

	* libnautilus-private/nautilus-program-choosing.c
	(nautilus_launch_application_from_command),
	(nautilus_launch_application_from_command_array):
	* libnautilus-private/nautilus-program-choosing.h:
	Use vararg list for nautilus_launch_application_from_command().
	Add nautilus_launch_application_from_command_array() which takes a
	parameter string array. Quote each parameter separately.

	* libnautilus-private/nautilus-mime-actions.c (activate_files):
	* src/file-manager/fm-desktop-icon-view.c
	(action_new_launcher_callback),
	(action_change_background_callback):
	* src/file-manager/fm-directory-view.c
	(action_new_launcher_callback),
	(get_file_names_as_parameter_array), (run_script_callback):
	* src/file-manager/fm-tree-view.c (got_activation_uri_callback):
	Pass each parameter separately to
	nautilus_launch_application_from_command(_array)().
	The _array() variant is used for running scripts, where the file names
	of the selection are passed separately.

	Fixes #341657. Thanks to Cosimo Cecchi.

svn path=/trunk/; revision=14502
parent e9d505c9
2008-08-20 Christian Neumair <cneumair@gnome.org>
* libnautilus-private/nautilus-program-choosing.c
(nautilus_launch_application_from_command),
(nautilus_launch_application_from_command_array):
* libnautilus-private/nautilus-program-choosing.h:
Use vararg list for nautilus_launch_application_from_command().
Add nautilus_launch_application_from_command_array() which takes a
parameter string array. Quote each parameter separately.
* libnautilus-private/nautilus-mime-actions.c (activate_files):
* src/file-manager/fm-desktop-icon-view.c
(action_new_launcher_callback),
(action_change_background_callback):
* src/file-manager/fm-directory-view.c
(action_new_launcher_callback),
(get_file_names_as_parameter_array), (run_script_callback):
* src/file-manager/fm-tree-view.c (got_activation_uri_callback):
Pass each parameter separately to
nautilus_launch_application_from_command(_array)().
The _array() variant is used for running scripts, where the file names
of the selection are passed separately.
Fixes #341657. Thanks to Cosimo Cecchi.
2008-08-20 Christian Neumair <cneumair@gnome.org>
* libnautilus-private/nautilus-search-engine-simple.c
......
......@@ -1109,7 +1109,7 @@ activate_files (ActivateParameters *parameters)
"directory view activate_callback launch_file window=%p: %s",
parameters->parent_window, quoted_path);
nautilus_launch_application_from_command (screen, name, quoted_path, NULL, FALSE);
nautilus_launch_application_from_command (screen, name, quoted_path, FALSE, NULL);
g_free (name);
g_free (quoted_path);
g_free (executable_path);
......@@ -1130,7 +1130,7 @@ activate_files (ActivateParameters *parameters)
"directory view activate_callback launch_in_terminal window=%p: %s",
parameters->parent_window, quoted_path);
nautilus_launch_application_from_command (screen, name, quoted_path, NULL, TRUE);
nautilus_launch_application_from_command (screen, name, quoted_path, TRUE, NULL);
g_free (name);
g_free (quoted_path);
g_free (executable_path);
......
......@@ -251,24 +251,77 @@ nautilus_launch_application (GAppInfo *application,
*
* @command_string: The application to be launched, with any desired
* command-line options.
* @parameter: Passed as a parameter to the application as is.
* @...: Passed as parameters to the application after quoting each of them.
*/
void
nautilus_launch_application_from_command (GdkScreen *screen,
const char *name,
const char *command_string,
const char *parameter,
gboolean use_terminal)
gboolean use_terminal,
...)
{
char *full_command;
char *full_command, *tmp;
char *quoted_parameter;
char *parameter;
va_list ap;
if (parameter != NULL) {
full_command = g_strdup (command_string);
va_start (ap, use_terminal);
while ((parameter = va_arg (ap, char *)) != NULL) {
quoted_parameter = g_shell_quote (parameter);
full_command = g_strconcat (command_string, " ", quoted_parameter, NULL);
tmp = g_strconcat (full_command, " ", quoted_parameter, NULL);
g_free (quoted_parameter);
g_free (full_command);
full_command = tmp;
}
va_end (ap);
if (use_terminal) {
eel_gnome_open_terminal_on_screen (full_command, screen);
} else {
full_command = g_strdup (command_string);
gdk_spawn_command_line_on_screen (screen, full_command, NULL);
}
g_free (full_command);
}
/**
* nautilus_launch_application_from_command:
*
* Fork off a process to launch an application with a given uri as
* a parameter.
*
* @command_string: The application to be launched, with any desired
* command-line options.
* @parameters: Passed as parameters to the application after quoting each of them.
*/
void
nautilus_launch_application_from_command_array (GdkScreen *screen,
const char *name,
const char *command_string,
gboolean use_terminal,
const char * const * parameters)
{
char *full_command, *tmp;
char *quoted_parameter;
const char * const *p;
full_command = g_strdup (command_string);
if (parameters != NULL) {
for (p = parameters; *p != NULL; p++) {
quoted_parameter = g_shell_quote (*p);
tmp = g_strconcat (full_command, " ", quoted_parameter, NULL);
g_free (quoted_parameter);
g_free (full_command);
full_command = tmp;
}
}
if (use_terminal) {
......
......@@ -39,8 +39,13 @@ void nautilus_launch_application (GAppInfo
void nautilus_launch_application_from_command (GdkScreen *screen,
const char *name,
const char *command_string,
const char *parameter,
gboolean use_terminal);
gboolean use_terminal,
...) G_GNUC_NULL_TERMINATED;
void nautilus_launch_application_from_command_array (GdkScreen *screen,
const char *name,
const char *command_string,
gboolean use_terminal,
const char * const * parameters);
void nautilus_launch_desktop_file (GdkScreen *screen,
const char *desktop_file_uri,
const GList *parameter_uris,
......
......@@ -599,9 +599,9 @@ action_new_launcher_callback (GtkAction *action, gpointer data)
nautilus_launch_application_from_command (gtk_widget_get_screen (GTK_WIDGET (data)),
"gnome-desktop-item-edit",
"gnome-desktop-item-edit --create-new",
desktop_directory,
FALSE);
"gnome-desktop-item-edit",
FALSE,
"--create-new", desktop_directory, NULL);
g_free (desktop_directory);
}
......@@ -615,8 +615,8 @@ action_change_background_callback (GtkAction *action,
nautilus_launch_application_from_command (gtk_widget_get_screen (GTK_WIDGET (data)),
_("Background"),
"gnome-appearance-properties",
"--show-page=background",
FALSE);
FALSE,
"--show-page=background", NULL);
}
static void
......
......@@ -1397,9 +1397,9 @@ action_new_launcher_callback (GtkAction *action,
"directory view create new launcher in window=%p: %s", window, parent_uri);
nautilus_launch_application_from_command (gtk_widget_get_screen (GTK_WIDGET (view)),
"gnome-desktop-item-edit",
"gnome-desktop-item-edit --create-new",
parent_uri,
FALSE);
"gnome-desktop-item-edit",
FALSE,
"--create-new", parent_uri, NULL);
g_free (parent_uri);
}
......@@ -4778,28 +4778,37 @@ change_to_view_directory (FMDirectoryView *view)
return old_path;
}
static char *
get_file_names_as_parameter_string (GList *selection)
static char **
get_file_names_as_parameter_array (GList *selection)
{
char *name, *quoted_name;
char *result;
GString *parameter_string;
NautilusFile *file;
char *name;
char **parameters;
GList *node;
int i;
parameters = g_new (char *, g_list_length (selection) + 1);
for (node = selection, i = 0; node != NULL; node = node->next, i++) {
file = NAUTILUS_FILE (node->data);
if (!nautilus_file_is_local (file)) {
parameters[i] = NULL;
g_strfreev (parameters);
return NULL;
}
/* TODO get name with respect to base directory,
* which may be different from file's parent directory
* in list view with nested subdirectories.
*/
parameter_string = g_string_new ("");
for (node = selection; node != NULL; node = node->next) {
name = nautilus_file_get_name (NAUTILUS_FILE (node->data));
quoted_name = g_shell_quote (name);
g_string_append (parameter_string, quoted_name);
g_string_append (parameter_string, " ");
g_free (name);
g_free (quoted_name);
parameters[i] = name;
}
result = parameter_string->str;
g_string_free (parameter_string, FALSE);
return result;
parameters[i] = NULL;
return parameters;
}
static char *
......@@ -4930,7 +4939,7 @@ run_script_callback (GtkAction *action, gpointer callback_data)
char *local_file_path;
char *quoted_path;
char *old_working_dir;
char *parameters, *command, *name;
char **parameters, *name;
GtkWindow *window;
launch_parameters = (ScriptLaunchParameters *) callback_data;
......@@ -4948,21 +4957,7 @@ run_script_callback (GtkAction *action, gpointer callback_data)
selected_files = fm_directory_view_get_selection (launch_parameters->directory_view);
set_script_environment_variables (launch_parameters->directory_view, selected_files);
if (nautilus_directory_is_local (launch_parameters->directory_view->details->model)) {
parameters = get_file_names_as_parameter_string (selected_files);
/* FIXME: must append command and parameters here, because nautilus_launch_application_from_command
* quotes all parameters as if they are a single parameter. Should add or change API in
* nautilus-program-choosing.c to support multiple parameters.
*/
command = g_strconcat (quoted_path, " ", parameters, NULL);
g_free (parameters);
} else {
/* We pass no parameters in the remote case. It's up to scripts to be smart
* and check the environment variables.
*/
command = g_strdup (quoted_path);
}
parameters = get_file_names_as_parameter_array (selected_files);
screen = gtk_widget_get_screen (GTK_WIDGET (launch_parameters->directory_view));
......@@ -4970,11 +4965,12 @@ run_script_callback (GtkAction *action, gpointer callback_data)
/* FIXME: handle errors with dialog? Or leave up to each script? */
window = fm_directory_view_get_containing_window (launch_parameters->directory_view);
nautilus_debug_log (FALSE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
"directory view run_script_callback, window=%p, name=\"%s\", command=\"%s\"",
window, name, command);
nautilus_launch_application_from_command (screen, name, command, NULL, FALSE);
"directory view run_script_callback, window=%p, name=\"%s\", script_path=\"%s\" (omitting script parameters)",
window, name, local_file_path);
nautilus_launch_application_from_command_array (screen, name, quoted_path, FALSE,
(const char * const *) parameters);
g_free (name);
g_free (command);
g_strfreev (parameters);
nautilus_file_list_free (selected_files);
unset_script_environment_variables ();
......
......@@ -369,7 +369,7 @@ got_activation_uri_callback (NautilusFile *file, gpointer callback_data)
nautilus_debug_log (FALSE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
"tree view launch_application_from_command window=%p: %s",
view->details->window, file_uri);
nautilus_launch_application_from_command (screen, NULL, file_uri, NULL, FALSE);
nautilus_launch_application_from_command (screen, NULL, file_uri, FALSE, NULL);
g_free (file_uri);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment