LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File gnome-panel-run-fixes.patch of Package gnome-panel-nld (Project home:winddss:gnome-panel-nld)

Index: gnome-panel/panel-run-dialog.c
================================================================================
--- gnome-panel/panel-run-dialog.c
+++ gnome-panel/panel-run-dialog.c
@@ -102,7 +102,7 @@
 	gboolean	  completion_started;
 	
 	char		 *icon_path;
-	char		 *item_name;	
+	char		 *item_path;
 } PanelRunDialog;
 
 enum {
@@ -131,7 +131,7 @@
 	dialog->add_icon_paths = NULL;
 
 	g_free (dialog->icon_path);
-	g_free (dialog->item_name);
+	g_free (dialog->item_path);
 
 	if (dialog->add_icons_idle_id)
 		g_source_remove (dialog->add_icons_idle_id);
@@ -257,6 +257,101 @@
 	return TRUE;
 }
 
+static char *
+fuzzy_command_merge (const char *ditem_cmd,
+		     const char *user_cmd)
+{
+	char **tokens;
+	char  *path, *basename, *new_cmd;
+
+	if (!strcmp (ditem_cmd, user_cmd) ||
+	    !g_path_is_absolute (ditem_cmd) ||
+	    g_path_is_absolute (user_cmd))
+		return g_strdup (user_cmd);
+
+	/* find path from desktop item */
+	tokens = g_strsplit (ditem_cmd, " ", -1);
+	if (!tokens || !tokens [0]) {
+		g_strfreev (tokens);
+		return g_strdup (user_cmd);
+	}
+
+	path = g_path_get_dirname (tokens [0]);
+	g_strfreev (tokens);
+
+	/* merge it with basename from user_cmd */
+	tokens = g_strsplit (user_cmd, " ", -1);
+	if (!tokens || !tokens [0]) {
+		g_free (path);
+		g_strfreev (tokens);
+		return g_strdup (user_cmd);
+	}
+	basename = g_path_get_basename (tokens [0]);
+	g_free (tokens [0]);
+	tokens [0] = g_build_filename (path, basename, NULL);
+
+	new_cmd = g_strjoinv (" ", tokens);
+
+	g_free (path);
+	g_free (basename);
+	g_strfreev (tokens);
+
+	return new_cmd;
+}
+
+static gboolean
+panel_run_dialog_launch_ditem (PanelRunDialog *dialog,
+			       const char     *ditem_path,
+			       const char     *command,
+			       const char     *escaped)
+{
+	GdkScreen *screen;
+	GnomeDesktopItem *ditem;
+	int result;
+	char *merged_command;
+	GError *error = NULL;
+	
+	screen = gtk_window_get_screen (GTK_WINDOW (dialog->run_dialog));
+	
+	ditem = gnome_desktop_item_new_from_file (ditem_path,
+						  GNOME_DESKTOP_ITEM_LOAD_ONLY_IF_EXISTS,
+						  &error);
+	if (!ditem) {
+		panel_error_dialog (screen, "cannot_open_desktop_item", TRUE,
+				    _("Cannot open desktop item '%s'"),
+				    "%s",
+				    ditem_path,
+				    error ? error->message : g_strerror (ENOENT));
+
+		g_error_free (error);
+		return FALSE;
+	}
+
+	merged_command = fuzzy_command_merge (
+		gnome_desktop_item_get_string (ditem, GNOME_DESKTOP_ITEM_EXEC),
+		command);
+	gnome_desktop_item_set_string (ditem, GNOME_DESKTOP_ITEM_EXEC, merged_command);
+	g_free (merged_command);
+
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->terminal_checkbox))) {
+		gnome_desktop_item_set_string (ditem, GNOME_DESKTOP_ITEM_TERMINAL,
+					       "true");
+	}
+		   
+	result = panel_ditem_launch (ditem, NULL, 0, screen, &error);
+	if (result == -1) {
+		panel_error_dialog (screen, "cannot_spawn_command", TRUE,
+				    _("Cannot launch command '%s'"),
+				    "%s",
+				    escaped,
+				    error->message);
+
+		g_error_free (error);
+	}
+	
+	return result != -1;
+}
+
 static gboolean
 panel_run_dialog_launch_command (PanelRunDialog *dialog,
 				 const char     *command,
@@ -268,9 +363,6 @@
 	char      **argv;
 	int         argc;
 	
-	if (!command_is_executable (command))
-		return FALSE;
-
 	argc = 3;
 	argv = g_new0 (char *, 4);
 	argv [0] = gnome_util_user_shell ();
@@ -385,19 +477,14 @@
 						       GNOME_VFS_MAKE_URI_DIR_HOMEDIR);
 	escaped = g_markup_escape_text (url, -1);
 	scheme = gnome_vfs_get_uri_scheme (url);
-	result = FALSE;
 	
-	if (!g_ascii_strcasecmp (scheme, "http") ||
-	    !g_ascii_strcasecmp (scheme, "file"))
-		/* If this returns an http or file url, the url might refer to a
-		 * command that is somewhere in the path or an executable file.
-		 * So try executing it before displaying it. We execute the 
-		 * command in the user's shell so that it can do all the parameter
-		 * expansion and other magic for us.
-		 */
+	if (dialog->item_path)
+		result = panel_run_dialog_launch_ditem (dialog, dialog->item_path, disk, escaped);
+	else if ((!g_ascii_strcasecmp (scheme, "http") ||
+		  !g_ascii_strcasecmp (scheme, "file")) &&
+		 command_is_executable (disk))
 		result = panel_run_dialog_launch_command (dialog, disk, escaped);
-	
-	if (!result)
+	else
 		result = panel_run_dialog_show_url (dialog, url, escaped);
 		
 	if (result) {
@@ -561,13 +648,13 @@
 	GtkTreePath  *path;
 	const char   *text;
 	char         *found_icon;
-	char         *found_name;
+	char         *found_ditem;
 	
 	model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->program_list));
 	path = gtk_tree_path_new_first ();
 	text = gtk_entry_get_text (GTK_ENTRY (dialog->gtk_entry));
 	found_icon = NULL;
-	found_name = NULL;
+	found_ditem = NULL;
 	
 	if (!path || !gtk_tree_model_get_iter (model, &iter, path)) {
 		if (path)
@@ -584,6 +671,7 @@
 		char *icon = NULL;
 		char *name = NULL;
 		char *path = NULL;
+		gboolean fuzzy = FALSE;
 
 		gtk_tree_model_get (model, &iter,
 				    COLUMN_EXEC,      &exec,
@@ -593,27 +681,12 @@
 				    -1);
 
         	if (exec && icon) {
-			gboolean fuzzy = FALSE;
-
 			if (fuzzy_command_match (sure_string (text), exec, &fuzzy)) {
 				g_free (found_icon);
-				g_free (found_name);
-				
+				g_free (found_ditem);
+
 				found_icon = g_strdup (icon);
-				found_name = g_strdup (name);
-				
-				if (!fuzzy) {
-					/*
-					 * if not fuzzy then we have a precise
-					 * match and we can quit, else keep
-					 * searching for a better match
-					 */
-					g_free (exec);
-					g_free (icon);
-					g_free (name);
-					g_free (path);
-					break;
-				}
+				found_ditem = g_strdup (path);
 			}
 		}
 
@@ -621,6 +694,9 @@
 		g_free (icon);
 		g_free (name);
 		g_free (path);
+
+		if (found_ditem && !fuzzy)
+			break;
 	
         } while (gtk_tree_model_iter_next (model, &iter));
 
@@ -630,8 +706,8 @@
 
 	g_free (found_icon);
 	
-	g_free (dialog->item_name);
-	dialog->item_name = found_name;
+	g_free (dialog->item_path);
+	dialog->item_path = found_ditem;
 	
 	dialog->find_command_icon_idle_id = 0;
 	return FALSE;
@@ -1118,13 +1194,10 @@
 			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->terminal_checkbox),
 						      terminal);
 
-			if (dialog->item_name)
-				g_free (dialog->item_name);
-
-			dialog->item_name = g_strdup (gnome_desktop_item_get_string (
-							      ditem,
-							      GNOME_DESKTOP_ITEM_NAME));
-
+			if (dialog->item_path)
+				g_free (dialog->item_path);
+			dialog->item_path = g_strdup (path);
+			
 			gnome_desktop_item_unref (ditem);
                 }
 
@@ -1648,9 +1721,9 @@
 				    _("Select an application to view its description."));
 
 	/* update item name to use for dnd */
-	if (!dialog->use_program_list && dialog->item_name) {
-		g_free (dialog->item_name);
-		dialog->item_name = NULL;
+	if (!dialog->use_program_list && dialog->item_path) {
+		g_free (dialog->item_path);
+		dialog->item_path = NULL;
 	}
 
 	/* look up icon for the command */
@@ -1770,7 +1843,10 @@
 	if (!text || !text [0])
 		return;
 		
-	ditem = gnome_desktop_item_new ();
+	if (dialog->item_path)
+		ditem = gnome_desktop_item_new_from_file (dialog->item_path, 0, NULL);
+	else
+		ditem = gnome_desktop_item_new ();
 
 	disk = g_locale_from_utf8 (text, -1, NULL, NULL, NULL);
 	uri = gnome_vfs_make_uri_from_input_with_dirs (disk,
@@ -1791,18 +1867,20 @@
 		gnome_desktop_item_set_string (ditem, GNOME_DESKTOP_ITEM_URL, uri);
 	}
 		
-	gnome_desktop_item_set_string (ditem,
-				       GNOME_DESKTOP_ITEM_NAME, (dialog->item_name) ?
-				              dialog->item_name : text);
+	if (!dialog->item_path) {
+		gnome_desktop_item_set_string (ditem,
+					       GNOME_DESKTOP_ITEM_NAME,
+					       text);
+		gnome_desktop_item_set_string (ditem,
+					       GNOME_DESKTOP_ITEM_ICON, 
+					       dialog->icon_path);
+	}
 
 	gnome_desktop_item_set_boolean (ditem,
 					GNOME_DESKTOP_ITEM_TERMINAL,
 					gtk_toggle_button_get_active (
 						 GTK_TOGGLE_BUTTON (dialog->terminal_checkbox)));
 
-	gnome_desktop_item_set_string (ditem,
-				       GNOME_DESKTOP_ITEM_ICON, 
-				       dialog->icon_path);
 	
 	g_free (uri);