Index: gtkfilechooserentry.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilechooserentry.c,v
retrieving revision 1.40
diff -u -p -r1.40 gtkfilechooserentry.c
--- gtkfilechooserentry.c	8 Oct 2006 05:06:54 -0000	1.40
+++ gtkfilechooserentry.c	13 Nov 2006 01:09:28 -0000
@@ -1,3 +1,4 @@
+/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
 /* GTK - The GIMP Toolkit
  * gtkfilechooserentry.c: Entry with filename completion
  * Copyright (C) 2003, Red Hat, Inc.
@@ -22,6 +23,7 @@
 #include <string.h>
 
 #include "gtkcelllayout.h"
+#include "gtkfilesystemmodel.h"
 #include "gtkcellrenderertext.h"
 #include "gtkentry.h"
 #include "gtkfilechooserentry.h"
@@ -64,17 +66,11 @@ struct _GtkFileChooserEntry
   guint eat_tabs       : 1;
 };
 
-enum
-{
-  DISPLAY_NAME_COLUMN,
-  PATH_COLUMN,
-  N_COLUMNS
-};
-
 static void     gtk_file_chooser_entry_iface_init     (GtkEditableClass *iface);
 
 static void     gtk_file_chooser_entry_finalize       (GObject          *object);
 static void     gtk_file_chooser_entry_dispose        (GObject          *object);
+static void     gtk_file_chooser_entry_grab_focus     (GtkWidget        *widget);
 static gboolean gtk_file_chooser_entry_focus          (GtkWidget        *widget,
 						       GtkDirectionType  direction);
 static void     gtk_file_chooser_entry_activate       (GtkEntry         *entry);
@@ -94,14 +90,8 @@ static gboolean completion_match_func   
 					   const char          *key,
 					   GtkTreeIter         *iter,
 					   gpointer             data);
-static void     files_added_cb            (GtkFileSystem       *file_system,
-					   GSList              *added_uris,
-					   GtkFileChooserEntry *chooser_entry);
-static void     files_deleted_cb          (GtkFileSystem       *file_system,
-					   GSList              *deleted_uris,
-					   GtkFileChooserEntry *chooser_entry);
 static char    *maybe_append_separator_to_path (GtkFileChooserEntry *chooser_entry,
-						GtkFilePath         *path,
+						GtkFileInfo         *info,
 						gchar               *display_name);
 
 static GtkEditableClass *parent_editable_iface;
@@ -155,7 +145,7 @@ _gtk_file_chooser_entry_init (GtkFileCho
                               cell, TRUE);
   gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (comp),
                                  cell,
-                                 "text", 0);
+                                 "text", GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
 
   g_signal_connect (comp, "match_selected",
 		    G_CALLBACK (match_selected_callback), chooser_entry);
@@ -200,10 +190,6 @@ gtk_file_chooser_entry_dispose (GObject 
 
   if (chooser_entry->current_folder)
     {
-      g_signal_handlers_disconnect_by_func (chooser_entry->current_folder,
-					    G_CALLBACK (files_added_cb), chooser_entry);
-      g_signal_handlers_disconnect_by_func (chooser_entry->current_folder,
-					    G_CALLBACK (files_deleted_cb), chooser_entry);
       g_object_unref (chooser_entry->current_folder);
       chooser_entry->current_folder = NULL;
     }
@@ -237,23 +223,24 @@ match_selected_callback (GtkEntryComplet
 			 GtkFileChooserEntry *chooser_entry)
 {
   char *display_name;
-  GtkFilePath *path;
+  GtkFileInfo *info;
   gint pos;
   
   gtk_tree_model_get (model, iter,
-		      DISPLAY_NAME_COLUMN, &display_name,
-		      PATH_COLUMN, &path,
+		      GTK_FILE_SYSTEM_MODEL_INFO, &info,
+		      GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME, &display_name,
 		      -1);
 
-  if (!display_name || !path)
+  if (!display_name || !info)
     {
-      /* these shouldn't complain if passed NULL */
-      gtk_file_path_free (path);
+      if (info)
+	gtk_file_info_free (info);
+
       g_free (display_name);
       return FALSE;
     }
 
-  display_name = maybe_append_separator_to_path (chooser_entry, path, display_name);
+  display_name = maybe_append_separator_to_path (chooser_entry, info, display_name);
 
   pos = chooser_entry->file_part_pos;
 
@@ -266,7 +253,7 @@ match_selected_callback (GtkEntryComplet
 			    &pos);
   gtk_editable_set_position (GTK_EDITABLE (chooser_entry), -1);
 
-  gtk_file_path_free (path);
+  gtk_file_info_free (info);
   g_free (display_name);
 
   return TRUE;
@@ -295,7 +282,9 @@ completion_match_func (GtkEntryCompletio
       return FALSE;
     }
 
-  gtk_tree_model_get (GTK_TREE_MODEL (chooser_entry->completion_store), iter, DISPLAY_NAME_COLUMN, &name, -1);
+  gtk_tree_model_get (GTK_TREE_MODEL (chooser_entry->completion_store), iter,
+		      GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME, &name, -1);
+
   if (!name)
     {
       return FALSE; /* Uninitialized row, ugh */
@@ -350,34 +339,23 @@ completion_match_func (GtkEntryCompletio
  * return a new one if needed.  Otherwise, it will return the old one.
  * You should be safe calling
  *
- * display_name = maybe_append_separator_to_path (entry, path, display_name);
+ * display_name = maybe_append_separator_to_path (entry, info, display_name);
  * ...
  * g_free (display_name);
  */
 static char *
 maybe_append_separator_to_path (GtkFileChooserEntry *chooser_entry,
-				GtkFilePath         *path,
+				GtkFileInfo         *info,
 				gchar               *display_name)
 {
-  if (path)
+  if (info)
     {
-      GtkFileInfo *info;
-	    
-      info = gtk_file_folder_get_info (chooser_entry->current_folder,
-				       path, NULL); /* NULL-GError */
-
-      if (info)
+      if (gtk_file_info_get_is_folder (info))
 	{
-	  if (gtk_file_info_get_is_folder (info))
-	    {
-	      gchar *tmp = display_name;
-	      display_name = g_strconcat (tmp, G_DIR_SEPARATOR_S, NULL);
-	      g_free (tmp);
-	    }
-	  
-	  gtk_file_info_free (info);
+	  gchar *tmp = display_name;
+	  display_name = g_strconcat (tmp, G_DIR_SEPARATOR_S, NULL);
+	  g_free (tmp);
 	}
-
     }
 
   return display_name;
@@ -390,13 +368,13 @@ maybe_append_separator_to_path (GtkFileC
 static void
 find_common_prefix (GtkFileChooserEntry *chooser_entry,
 		    gchar               **common_prefix_ret,
-		    GtkFilePath         **unique_path_ret)
+		    GtkFileInfo         **info_ret)
 {
   GtkTreeIter iter;
   gboolean valid;
 
   *common_prefix_ret = NULL;
-  *unique_path_ret = NULL;
+  *info_ret = NULL;
 
   if (chooser_entry->completion_store == NULL)
     return;
@@ -406,12 +384,12 @@ find_common_prefix (GtkFileChooserEntry 
   while (valid)
     {
       gchar *display_name;
-      GtkFilePath *path;
+      GtkFileInfo *info;
 
       gtk_tree_model_get (GTK_TREE_MODEL (chooser_entry->completion_store),
 			  &iter,
-			  DISPLAY_NAME_COLUMN, &display_name,
-			  PATH_COLUMN, &path,
+			  GTK_FILE_SYSTEM_MODEL_INFO, &info,
+			  GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME, &display_name,
 			  -1);
 
       if (g_str_has_prefix (display_name, chooser_entry->file_part))
@@ -419,7 +397,7 @@ find_common_prefix (GtkFileChooserEntry 
 	  if (!*common_prefix_ret)
 	    {
 	      *common_prefix_ret = g_strdup (display_name);
-	      *unique_path_ret = gtk_file_path_copy (path);
+	      *info_ret = gtk_file_info_copy (info);
 	    }
 	  else
 	    {
@@ -434,13 +412,16 @@ find_common_prefix (GtkFileChooserEntry 
 		  
 	      *p = '\0';
 
-	      gtk_file_path_free (*unique_path_ret);
-	      *unique_path_ret = NULL;
+	      if (*info_ret)
+		{
+		  gtk_file_info_free (*info_ret);
+		  *info_ret = NULL;
+		}
 	    }
 	}
 
       g_free (display_name);
-      gtk_file_path_free (path);
+      gtk_file_info_free (info);
       valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser_entry->completion_store), &iter);
     }
 }
@@ -451,16 +432,16 @@ append_common_prefix (GtkFileChooserEntr
 		      gboolean             highlight)
 {
   gchar *common_prefix;
-  GtkFilePath *unique_path;
+  GtkFileInfo *info;
 
-  find_common_prefix (chooser_entry, &common_prefix, &unique_path);
+  find_common_prefix (chooser_entry, &common_prefix, &info);
 
-  if (unique_path)
+  if (info)
     {
       common_prefix = maybe_append_separator_to_path (chooser_entry,
-						      unique_path,
+						      info,
 						      common_prefix);
-      gtk_file_path_free (unique_path);
+      gtk_file_info_free (info);
     }
 
   if (common_prefix)
@@ -550,64 +531,6 @@ add_completion_idle (GtkFileChooserEntry
       idle_add (chooser_entry, G_CALLBACK (check_completion_callback));
 }
 
-
-static void
-update_current_folder_files (GtkFileChooserEntry *chooser_entry,
-			     GSList              *added_uris)
-{
-  GSList *tmp_list;
-
-  g_assert (chooser_entry->completion_store != NULL);
-
-  /* Bah.  Need to turn off sorting */
-  for (tmp_list = added_uris; tmp_list; tmp_list = tmp_list->next)
-    {
-      GtkFileInfo *info;
-      GtkFilePath *path;
-
-      path = tmp_list->data;
-
-      info = gtk_file_folder_get_info (chooser_entry->current_folder,
-				       path,
-				       NULL); /* NULL-GError */
-      if (info)
-	{
-	  const gchar *display_name = gtk_file_info_get_display_name (info);
-	  GtkTreeIter iter;
-
-	  gtk_list_store_append (chooser_entry->completion_store, &iter);
-	  gtk_list_store_set (chooser_entry->completion_store, &iter,
-			      DISPLAY_NAME_COLUMN, display_name,
-			      PATH_COLUMN, path,
-			      -1);
-
-	  gtk_file_info_free (info);
-	}
-    }
-
-  /* FIXME: we want to turn off sorting temporarily.  I suck... */
-  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (chooser_entry->completion_store),
-					DISPLAY_NAME_COLUMN, GTK_SORT_ASCENDING);
-
-  add_completion_idle (chooser_entry);
-}
-
-static void
-files_added_cb (GtkFileSystem       *file_system,
-		GSList              *added_uris,
-		GtkFileChooserEntry *chooser_entry)
-{
-  update_current_folder_files (chooser_entry, added_uris);
-}
-
-static void
-files_deleted_cb (GtkFileSystem       *file_system,
-		  GSList              *deleted_uris,
-		  GtkFileChooserEntry *chooser_entry)
-{
-  /* FIXME: gravy... */
-}
-
 static void
 load_directory_get_folder_callback (GtkFileSystemHandle *handle,
 				    GtkFileFolder       *folder,
@@ -626,14 +549,10 @@ load_directory_get_folder_callback (GtkF
     goto out;
 
   chooser_entry->current_folder = folder;
-  g_signal_connect (chooser_entry->current_folder, "files-added",
-		    G_CALLBACK (files_added_cb), chooser_entry);
-  g_signal_connect (chooser_entry->current_folder, "files-removed",
-		    G_CALLBACK (files_deleted_cb), chooser_entry);
-  
-  chooser_entry->completion_store = gtk_list_store_new (N_COLUMNS,
-							G_TYPE_STRING,
-							GTK_TYPE_FILE_PATH);
+  chooser_entry->completion_store = _gtk_file_system_model_new (chooser_entry->file_system,
+								chooser_entry->current_folder_path, 0,
+								GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_FOLDER,
+								NULL);
 
   gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)),
 				  GTK_TREE_MODEL (chooser_entry->completion_store));
@@ -754,7 +673,7 @@ gtk_file_chooser_entry_activate (GtkEntr
       gtk_editable_set_position (GTK_EDITABLE (entry),
 				 entry->text_length);
     }
-  
+
   GTK_ENTRY_CLASS (_gtk_file_chooser_entry_parent_class)->activate (entry);
 }
 
@@ -777,11 +696,6 @@ gtk_file_chooser_entry_maybe_update_dire
 	   */
 	  if (chooser_entry->current_folder)
 	    {
-	      g_signal_handlers_disconnect_by_func (chooser_entry->current_folder,
-						    G_CALLBACK (files_added_cb), chooser_entry);
-	      g_signal_handlers_disconnect_by_func (chooser_entry->current_folder,
-						    G_CALLBACK (files_deleted_cb), chooser_entry);
-
 	      g_object_unref (chooser_entry->current_folder);
 	      chooser_entry->current_folder = NULL;
 	    }
