gnome-utils r8515 - trunk/gsearchtool



Author: dcransto
Date: Thu Mar 19 04:38:25 2009
New Revision: 8515
URL: http://svn.gnome.org/viewvc/gnome-utils?rev=8515&view=rev

Log:
2009-03-18  Dennis Cranston  <dennis_cranston yahoo com>

        * gsearchtool-callbacks.c (open_file_cb), (open_folder_cb),
        (move_to_trash_cb), (file_button_release_event_cb), 
        (drag_file_cb), (save_results_cb):
        * gsearchtool-support.c (open_file_with_filemanager),
        (open_file_with_application):
        * gsearchtool-support.h:
        * gsearchtool.c (add_file_to_search_results),
        (add_no_files_found_message), (handle_goption_args),
        (handle_search_command_stdout_io), 
        (create_search_results_section):
        * gsearchtool.h:
        Bug 557256: Find results missing files with incorrect 
        filename encoding



Modified:
   trunk/gsearchtool/ChangeLog
   trunk/gsearchtool/gsearchtool-callbacks.c
   trunk/gsearchtool/gsearchtool-support.c
   trunk/gsearchtool/gsearchtool-support.h
   trunk/gsearchtool/gsearchtool.c
   trunk/gsearchtool/gsearchtool.h

Modified: trunk/gsearchtool/gsearchtool-callbacks.c
==============================================================================
--- trunk/gsearchtool/gsearchtool-callbacks.c	(original)
+++ trunk/gsearchtool/gsearchtool-callbacks.c	Thu Mar 19 04:38:25 2009
@@ -468,7 +468,7 @@
 
 		gboolean no_files_found = FALSE;
 		gchar * utf8_name;
-		gchar * utf8_path;
+		gchar * locale_file;
 		GtkTreeIter iter;
 
 		gtk_tree_model_get_iter (GTK_TREE_MODEL (gsearch->search_results_list_store), &iter,
@@ -476,20 +476,16 @@
 
 		gtk_tree_model_get (GTK_TREE_MODEL (gsearch->search_results_list_store), &iter,
     		                    COLUMN_NAME, &utf8_name,
-		                    COLUMN_PATH, &utf8_path,
+				    COLUMN_LOCALE_FILE, &locale_file,
 		                    COLUMN_NO_FILES_FOUND, &no_files_found,
 		                    -1);
 
 		if (!no_files_found) {
-			gchar * file;
-			gchar * locale_file;
 			GAppInfo * app = NULL;
 
 			if (GTK_IS_OBJECT (action)) {
 				app = g_object_get_data (G_OBJECT (action), "app");
 			}
-			file = g_build_filename (utf8_path, utf8_name, NULL);
-			locale_file = g_locale_from_utf8 (file, -1, NULL, NULL, NULL);
 
 			if (!g_file_test (locale_file, G_FILE_TEST_EXISTS)) {
 				gtk_tree_selection_unselect_iter (GTK_TREE_SELECTION (gsearch->search_results_selection),
@@ -504,7 +500,7 @@
 
 					if (g_file_test (locale_file, G_FILE_TEST_IS_DIR)) {
 
-						if (open_file_with_nautilus (gsearch->window, locale_file) == FALSE) {
+						if (open_file_with_filemanager (gsearch->window, locale_file) == FALSE) {
 							display_dialog_could_not_open_folder (gsearch->window, utf8_name);
 						}
 					}
@@ -515,11 +511,9 @@
 					}
 				}
 			}
-			g_free (file);
-			g_free (locale_file);
 		}
 		g_free (utf8_name);
-		g_free (utf8_path);
+		g_free (locale_file);
 	}
 	g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
 	g_list_free (list);
@@ -605,43 +599,46 @@
 
 	for (index = 0; index < g_list_length (list); index++) {
 
-		gchar * folder_locale;
-		gchar * folder_utf8;
+		gchar * locale_folder;
+		gchar * utf8_folder;
+		gchar * locale_file;
 		GtkTreeIter iter;
 
 		gtk_tree_model_get_iter (GTK_TREE_MODEL (gsearch->search_results_list_store), &iter,
 					 g_list_nth (list, index)->data);
 
 		gtk_tree_model_get (GTK_TREE_MODEL (gsearch->search_results_list_store), &iter,
-				    COLUMN_PATH, &folder_utf8,
+				    COLUMN_RELATIVE_PATH, &utf8_folder,
+				    COLUMN_LOCALE_FILE, &locale_file,
 				    -1);
 
-		folder_locale = g_filename_from_utf8 (folder_utf8, -1, NULL, NULL, NULL);
+		locale_folder = g_path_get_dirname (locale_file);
 
 		if (index == 0) {
-			g_file = g_file_new_for_path (folder_locale);
+			g_file = g_file_new_for_path (locale_folder);
 			g_file_info = g_file_query_info (g_file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
 			g_app_info = g_app_info_get_default_for_type (g_file_info_get_content_type (g_file_info), FALSE);
 		}
 
-		if (open_file_with_application (gsearch->window, folder_locale, g_app_info) == FALSE) {
+		if (open_file_with_application (gsearch->window, locale_folder, g_app_info) == FALSE) {
 
-			if (open_file_with_nautilus (gsearch->window, folder_locale) == FALSE) {
+			if (open_file_with_filemanager (gsearch->window, locale_folder) == FALSE) {
 
-				display_dialog_could_not_open_folder (gsearch->window, folder_utf8);
+				display_dialog_could_not_open_folder (gsearch->window, utf8_folder);
 
 				g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
 				g_list_free (list);
-				g_free (folder_locale);
-				g_free (folder_utf8);
+				g_free (locale_folder);
+				g_free (utf8_folder);
 				g_object_unref (g_file);
 				g_object_unref (g_file_info);
 				g_object_unref (g_app_info);
 				return;
 			}
 		}
-		g_free (folder_locale);
-		g_free (folder_utf8);
+		g_free (locale_folder);
+		g_free (locale_file);
+		g_free (utf8_folder);
 	}
 	g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
 	g_list_free (list);
@@ -802,7 +799,6 @@
 		GFile * g_file;
 		GError * error;
 		gchar * utf8_basename;
-		gchar * utf8_basepath;
 		gchar * utf8_filename;
 		gchar * locale_filename;
 		gboolean result;
@@ -815,13 +811,14 @@
 
 		gtk_tree_model_get (GTK_TREE_MODEL (gsearch->search_results_list_store), &iter,
     				    COLUMN_NAME, &utf8_basename,
-			    	    COLUMN_PATH, &utf8_basepath,
+				    COLUMN_LOCALE_FILE, &locale_filename,
 			   	    COLUMN_NO_FILES_FOUND, &no_files_found,
 			   	    -1);
+		utf8_filename = g_filename_display_name (locale_filename);
 
 		if (no_files_found) {
 			g_free (utf8_basename);
-			g_free (utf8_basepath);
+			g_free (locale_filename);
 			return;
 		}
 		
@@ -829,9 +826,6 @@
 			last_selected_path = gtk_tree_model_get_path (GTK_TREE_MODEL (gsearch->search_results_list_store), &iter);
 		}
 
-		utf8_filename = g_build_filename (utf8_basepath, utf8_basename, NULL);
-		locale_filename = g_locale_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
-
 		if ((!g_file_test (locale_filename, G_FILE_TEST_EXISTS)) &&
 		    (!g_file_test (locale_filename, G_FILE_TEST_IS_SYMLINK))) {
 			gtk_tree_selection_unselect_iter (GTK_TREE_SELECTION (gsearch->search_results_selection), &iter);
@@ -899,7 +893,6 @@
 		g_free (locale_filename);
 		g_free (utf8_filename);
 		g_free (utf8_basename);
-		g_free (utf8_basepath);
 	}
 
 	/* Bugzilla #397945: Select next row in the search results list */
@@ -1220,7 +1213,7 @@
 		GtkTreeIter iter;
 		GList * list;
 		gchar * utf8_name_first;
-		gchar * utf8_path_first;
+		gchar * locale_file_first;
 
 		list = gtk_tree_selection_get_selected_rows (GTK_TREE_SELECTION (gsearch->search_results_selection),
 		                                             &model);
@@ -1230,7 +1223,7 @@
 
 		gtk_tree_model_get (GTK_TREE_MODEL (gsearch->search_results_list_store), &iter,
 		                    COLUMN_NAME, &utf8_name_first,
-		                    COLUMN_PATH, &utf8_path_first,
+				    COLUMN_LOCALE_FILE, &locale_file_first,
 			    	    COLUMN_NO_FILES_FOUND, &no_files_found,
 			   	    -1);
 
@@ -1240,13 +1233,9 @@
 			GAppInfo * first_app_info = NULL;
 			GTimer * timer;
 			GList * tmp;
-			gchar * utf8_name_tmp;
-			gchar * utf8_path_tmp;
-			gchar * utf8_file;
-			gint index;
-			gchar * utf8_filename;
-			gchar * locale_filename;
+			gchar * locale_file_tmp;
 			gchar * file = NULL;
+			gint index;
 
 			timer = g_timer_new ();
 			g_timer_start (timer);
@@ -1258,19 +1247,15 @@
 			
 					GFile * g_file;
 					GAppInfo * app_info;
-					gchar * locale_file;
 
 					gtk_tree_model_get_iter (GTK_TREE_MODEL (gsearch->search_results_list_store), &iter,
 					                         tmp->data);
 
 					gtk_tree_model_get (GTK_TREE_MODEL (gsearch->search_results_list_store), &iter,
-					                    COLUMN_NAME, &utf8_name_tmp,
-					                    COLUMN_PATH, &utf8_path_tmp,
+							    COLUMN_LOCALE_FILE, &locale_file_tmp,
 					                    -1);
 
-					utf8_file = g_build_filename (utf8_path_tmp, utf8_name_tmp, NULL);
-					locale_file = g_filename_from_utf8 (utf8_file, -1, NULL, NULL, NULL);
-					g_file = g_file_new_for_path (locale_file);
+					g_file = g_file_new_for_path (locale_file_tmp);
 					app_info = g_file_query_default_handler (g_file, NULL, NULL);
 
 					if (G_IS_APP_INFO (app_info) == FALSE) {
@@ -1292,9 +1277,7 @@
 						}
 					}
 					g_object_unref (g_file);
-					g_free (utf8_name_tmp);
-					g_free (utf8_path_tmp);
-					g_free (utf8_file);
+					g_free (locale_file_tmp);
 
 					if (show_app_list == FALSE) {
 						break;
@@ -1305,20 +1288,17 @@
 					g_object_unref (first_app_info);
 				}
 			}
-			utf8_filename = g_build_filename (utf8_path_first, utf8_name_first, NULL);
-			locale_filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
 			
-			file = g_strdup (((show_app_list == TRUE) ? locale_filename : NULL));
+			file = g_strdup (((show_app_list == TRUE) ? locale_file_first : NULL));
 
 			build_popup_menu_for_file (gsearch, file);
 			gtk_menu_popup (GTK_MENU (gsearch->search_results_popup_menu), NULL, NULL, NULL, NULL,
 			                event->button, event->time);
-
-			g_free (utf8_filename);
-			g_free (locale_filename);
 			g_free (file);
 
 		}
+		g_free (locale_file_first);
+		g_free (utf8_name_first);
 		g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
 		g_list_free (list);
 	}
@@ -1507,8 +1487,6 @@
 
 		gboolean no_files_found = FALSE;
 		gchar * utf8_name;
-		gchar * utf8_path;
-		gchar * utf8_file;
 		gchar * locale_file;
 
 		gtk_tree_model_get_iter (GTK_TREE_MODEL (gsearch->search_results_list_store), &iter,
@@ -1516,13 +1494,10 @@
 
 		gtk_tree_model_get (GTK_TREE_MODEL (gsearch->search_results_list_store), &iter,
 		                    COLUMN_NAME, &utf8_name,
-		                    COLUMN_PATH, &utf8_path,
+		                    COLUMN_LOCALE_FILE, &locale_file,
 		                    COLUMN_NO_FILES_FOUND, &no_files_found,
 		                    -1);
 
-		utf8_file = g_build_filename (utf8_path, utf8_name, NULL);
-		locale_file = g_filename_from_utf8 (utf8_file, -1, NULL, NULL, NULL);
-
 		if (!no_files_found) {
 			gchar * tmp_uri = g_filename_to_uri (locale_file, NULL, NULL);
 
@@ -1543,8 +1518,6 @@
 			gtk_selection_data_set_text (selection_data, utf8_name, -1);
 		}
 		g_free (utf8_name);
-		g_free (utf8_path);
-		g_free (utf8_file);
 		g_free (locale_file);
 	}
 	g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
@@ -1752,21 +1725,10 @@
 		{
 			if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter, NULL, index) == TRUE) {
 
-				gchar * utf8_path;
-				gchar * utf8_name;
-				gchar * utf8_file;
 				gchar * locale_file;
 
-				gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, COLUMN_PATH, &utf8_path, -1);
-				gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, COLUMN_NAME, &utf8_name, -1);
-
-				utf8_file = g_build_filename (utf8_path, utf8_name, NULL);
-				locale_file = g_filename_from_utf8 (utf8_file, -1, NULL, NULL, NULL);
+				gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, COLUMN_LOCALE_FILE, &locale_file, -1);
 				fprintf (fp, "%s\n", locale_file);
-
-				g_free (utf8_path);
-				g_free (utf8_name);
-				g_free (utf8_file);
 				g_free (locale_file);
 			}
 		}

Modified: trunk/gsearchtool/gsearchtool-support.c
==============================================================================
--- trunk/gsearchtool/gsearchtool-support.c	(original)
+++ trunk/gsearchtool/gsearchtool-support.c	Thu Mar 19 04:38:25 2009
@@ -1191,24 +1191,37 @@
 }
 
 gboolean
-open_file_with_nautilus (GtkWidget * window,
-                         const gchar * file)
+open_file_with_filemanager (GtkWidget * window,
+                            const gchar * file)
 {
 	GnomeDesktopItem * ditem;
  	GdkScreen * screen;
-	GError *error = NULL;
+	GError * error = NULL;
+	GList * list = NULL;
+	GAppInfo * g_app_info;
+	GFile * g_file;
 	gchar * command;
 	gchar * contents;
-	gchar * escaped;
+	gchar * uri;
+	gboolean result = TRUE;
 
-	escaped = g_shell_quote (file);
+	uri = g_filename_to_uri (file, NULL, NULL);
+	list = g_list_prepend (list, uri);
 
-	command = g_strconcat ("nautilus ",
-	                       "--sm-disable ",
-	                       "--no-desktop ",
-	                       "--no-default-window ",
-	                       escaped,
-	                       NULL);
+	g_file = g_file_new_for_path (file);
+	g_app_info = g_file_query_default_handler (g_file, NULL, NULL);
+
+	if (strcmp (g_app_info_get_executable (g_app_info), "nautilus") == 0) {
+		command = g_strconcat ("nautilus ",
+		                       "--sm-disable ",
+		                       "--no-desktop ",
+		                       "--no-default-window ",
+		                       NULL);
+	}
+	else {
+		command = g_strconcat (g_app_info_get_executable (g_app_info),
+		                       " ", NULL);
+	}
 
 	contents = g_strdup_printf ("[Desktop Entry]\n"
 				    "Name=Nautilus\n"
@@ -1222,35 +1235,36 @@
 	ditem = gnome_desktop_item_new_from_string (NULL,
 	                                            contents,
 	                                            strlen (contents),
-	                                            GNOME_DESKTOP_ITEM_LOAD_NO_TRANSLATIONS ,
+	                                            GNOME_DESKTOP_ITEM_LOAD_NO_TRANSLATIONS,
 	                                            NULL);
+	if (ditem != NULL) {
+		screen = gtk_widget_get_screen (window);
 
-	if (ditem == NULL) {
-		g_free (contents);
-		g_free (command);
-		g_free (escaped);
-		return FALSE;
-	}
-
-	screen = gtk_widget_get_screen (window);
+		gnome_desktop_item_set_launch_time (ditem,
+		                                    gtk_get_current_event_time ());
 
-	gnome_desktop_item_set_launch_time (ditem,
-	                                    gtk_get_current_event_time ());
+		gnome_desktop_item_launch_on_screen (ditem, list,
+		                                     GNOME_DESKTOP_ITEM_LAUNCH_APPEND_URIS | GNOME_DESKTOP_ITEM_LAUNCH_ONLY_ONE,
+						     screen, -1, &error);
+		gnome_desktop_item_unref (ditem);
 
-	gnome_desktop_item_launch_on_screen (ditem, NULL,
-	                                     GNOME_DESKTOP_ITEM_LAUNCH_ONLY_ONE,
-					     screen, -1, &error);
+		if (error) {
+			g_error_free (error);
+			result = FALSE;
+		}
+	}
+	else {
+		result = FALSE;
+	}
 
-	gnome_desktop_item_unref (ditem);
+	g_object_unref (g_file);
+	g_object_unref (g_app_info);
+	g_list_free (list);
 	g_free (contents);
 	g_free (command);
-	g_free (escaped);
+	g_free (uri);
 
-	if (error) {
-		g_error_free (error);
-		return FALSE;
-	}
-	return TRUE;
+	return result;
 }
 
 gboolean
@@ -1259,9 +1273,16 @@
                             GAppInfo * app)
 {
 	GdkAppLaunchContext * context;
+	GdkScreen * screen;
 	gboolean result;
 
+	if (g_file_test (file, G_FILE_TEST_IS_DIR) == TRUE) {
+		return FALSE;
+	}
+
 	context = gdk_app_launch_context_new ();
+	screen = gtk_widget_get_screen (window);
+	gdk_app_launch_context_set_screen (context, screen);
 
 	if (app == NULL) {
 		gchar * uri;

Modified: trunk/gsearchtool/gsearchtool-support.h
==============================================================================
--- trunk/gsearchtool/gsearchtool-support.h	(original)
+++ trunk/gsearchtool/gsearchtool-support.h	Thu Mar 19 04:38:25 2009
@@ -114,8 +114,8 @@
 get_file_pixbuf (GSearchWindow * gsearch,
                  GFileInfo * file_info);
 gboolean
-open_file_with_nautilus (GtkWidget * window,
-                         const gchar * file);
+open_file_with_filemanager (GtkWidget * window,
+                            const gchar * file);
 gboolean
 open_file_with_application (GtkWidget * window,
                             const gchar * file,

Modified: trunk/gsearchtool/gsearchtool.c
==============================================================================
--- trunk/gsearchtool/gsearchtool.c	(original)
+++ trunk/gsearchtool/gsearchtool.c	Thu Mar 19 04:38:25 2009
@@ -816,7 +816,6 @@
 	gchar * readable_size;
 	gchar * readable_date;
 	gchar * utf8_base_name;
-	gchar * utf8_dir_name;
 	gchar * utf8_relative_dir_name;
 	gchar * base_name;
 	gchar * dir_name;
@@ -871,16 +870,15 @@
 		relative_dir_name = g_strdup (dir_name);
 	}
 
-	utf8_base_name = g_locale_to_utf8 (base_name, -1, NULL, NULL, NULL);
-	utf8_dir_name = g_locale_to_utf8 (dir_name, -1, NULL, NULL, NULL);
-	utf8_relative_dir_name = g_locale_to_utf8 (relative_dir_name, -1, NULL, NULL, NULL);
+	utf8_base_name = g_filename_display_basename (file);
+	utf8_relative_dir_name = g_filename_display_name (relative_dir_name);
 
 	gtk_list_store_append (GTK_LIST_STORE (store), iter);
 	gtk_list_store_set (GTK_LIST_STORE (store), iter,
 			    COLUMN_ICON, pixbuf,
 			    COLUMN_NAME, utf8_base_name,
 			    COLUMN_RELATIVE_PATH, utf8_relative_dir_name,
-			    COLUMN_PATH, utf8_dir_name,
+			    COLUMN_LOCALE_FILE, file,
 			    COLUMN_READABLE_SIZE, readable_size,
 			    COLUMN_SIZE, (-1) * (gdouble) g_file_info_get_size(file_info),
 			    COLUMN_TYPE, (description != NULL) ? description : g_strdup (g_file_info_get_content_type (file_info)),
@@ -920,7 +918,6 @@
 	g_free (dir_name);
 	g_free (relative_dir_name);
 	g_free (utf8_base_name);
-	g_free (utf8_dir_name);
 	g_free (utf8_relative_dir_name);
 	g_free (look_in_folder);
 	g_free (description);
@@ -944,7 +941,7 @@
 		    	    COLUMN_ICON, NULL,
 			    COLUMN_NAME, _("No files found"),
 			    COLUMN_RELATIVE_PATH, "",
-		    	    COLUMN_PATH, "",
+			    COLUMN_LOCALE_FILE, "",
 			    COLUMN_READABLE_SIZE, "",
 			    COLUMN_SIZE, (gdouble) 0,
 			    COLUMN_TYPE, "",
@@ -1376,7 +1373,7 @@
 			sort_by = COLUMN_NAME;
 		}
 		else if (strcmp (GSearchGOptionArguments.sortby, "folder") == 0) {
-			sort_by = COLUMN_PATH;
+			sort_by = COLUMN_RELATIVE_PATH;
 		}
 		else if (strcmp (GSearchGOptionArguments.sortby, "size") == 0) {
 			sort_by = COLUMN_SIZE;
@@ -1485,7 +1482,7 @@
 				continue;
 			}
 
-			utf8 = g_locale_to_utf8 (string->str, -1, NULL, NULL, NULL);
+			utf8 = g_filename_display_name (string->str);
 			if (utf8 == NULL) {
 				continue;
 			}
@@ -2386,7 +2383,7 @@
 							   NULL);
 	gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
 	gtk_tree_view_column_set_resizable (column, TRUE);
-	gtk_tree_view_column_set_sort_column_id (column, COLUMN_PATH);
+	gtk_tree_view_column_set_sort_column_id (column, COLUMN_RELATIVE_PATH);
 	gtk_tree_view_column_set_reorderable (column, TRUE);
 	gtk_tree_view_append_column (GTK_TREE_VIEW (gsearch->search_results_tree_view), column);
 

Modified: trunk/gsearchtool/gsearchtool.h
==============================================================================
--- trunk/gsearchtool/gsearchtool.h	(original)
+++ trunk/gsearchtool/gsearchtool.h	Thu Mar 19 04:38:25 2009
@@ -68,7 +68,7 @@
 	COLUMN_ICON,
 	COLUMN_NAME,
 	COLUMN_RELATIVE_PATH,
-	COLUMN_PATH,
+	COLUMN_LOCALE_FILE,
 	COLUMN_READABLE_SIZE,
 	COLUMN_SIZE,
 	COLUMN_TYPE,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]