]> Pileus Git - ~andy/gtk/commitdiff
Don't add remote volumes and bookmarks to the model in local-only mode, to
authorMatthias Clasen <mclasen@redhat.com>
Sun, 17 Sep 2006 03:34:17 +0000 (03:34 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sun, 17 Sep 2006 03:34:17 +0000 (03:34 +0000)
2006-09-16  Matthias Clasen  <mclasen@redhat.com>

* gtk/gtkfilechooserbutton.c: Don't add remote volumes and
bookmarks to the model in local-only mode, to avoid
authentication dialogs pop up for invisible bookmarks, and
to fix issues with separators not being hidden when
they should.  (#354887, Dennis Cranston)

ChangeLog
gtk/gtkfilechooserbutton.c

index 823c293eb9bf6adfe37e517b15d182fd291816ea..b4f1c985d5b2a6e7b43d4861d8908acb30f47cd7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-09-16  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtkfilechooserbutton.c: Don't add remote volumes and 
+       bookmarks to the model in local-only mode, to avoid 
+       authentication dialogs pop up for invisible bookmarks, and
+       to fix issues with separators not being hidden when
+       they should.  (#354887, Dennis Cranston)
+
 2006-09-16  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkcombobox.c (gtk_combo_box_finalize): Unref the
index 8b3d78edc90d258bdfb756925af61b30116d8aa8..e8ca3a4f8516c531f588d27b69e856302d132c59 100644 (file)
@@ -797,7 +797,6 @@ gtk_file_chooser_button_set_property (GObject      *object,
       priv->has_title = TRUE;
       /* Intentionally fall through instead of breaking here, to actually set the property. */
     case GTK_FILE_CHOOSER_PROP_FILTER:
-    case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
     case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
     case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
     case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
@@ -807,6 +806,12 @@ gtk_file_chooser_button_set_property (GObject      *object,
       g_object_set_property (G_OBJECT (priv->dialog), pspec->name, value);
       break;
 
+    case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
+      g_object_set_property (G_OBJECT (priv->dialog), pspec->name, value);
+      fs_volumes_changed_cb (priv->fs, button);
+      fs_bookmarks_changed_cb (priv->fs, button);
+      break;
+
     case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
       /* Construct-only */
       priv->backend = g_value_dup_string (value);
@@ -1714,33 +1719,61 @@ model_add_volumes (GtkFileChooserButton *button,
 {
   GtkListStore *store;
   gint pos;
-
+  gboolean local_only;
+  GtkFileSystem *file_system;
+  GSList *l;
+  
   if (!volumes)
     return;
 
   store = GTK_LIST_STORE (button->priv->model);
   pos = model_get_type_position (button, ROW_TYPE_VOLUME);
+  local_only = gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (button->priv->dialog));
+  file_system = button->priv->fs;
 
-  do
+  for (l = volumes; l; l = l->next)
     {
+      GtkFileSystemVolume *volume;
       GtkTreeIter iter;
       GdkPixbuf *pixbuf;
       gchar *display_name;
 
-      pixbuf = gtk_file_system_volume_render_icon (button->priv->fs,
-                                                  volumes->data,
+      volume = l->data;
+
+      if (local_only)
+       {
+         if (gtk_file_system_volume_get_is_mounted (file_system, volume))
+           {
+             GtkFilePath *base_path;
+
+             base_path = gtk_file_system_volume_get_base_path (file_system, volume);
+             if (base_path != NULL)
+               {
+                 gboolean is_local = gtk_file_system_path_is_local (file_system, base_path);
+                 gtk_file_path_free (base_path);
+
+                 if (!is_local)
+                   {
+                     gtk_file_system_volume_free (file_system, volume);
+                     continue;
+                   }
+               }
+           }
+       }
+
+      pixbuf = gtk_file_system_volume_render_icon (file_system,
+                                                  volume,
                                                   GTK_WIDGET (button),
                                                   button->priv->icon_size,
                                                   NULL);
-      display_name = gtk_file_system_volume_get_display_name (button->priv->fs,
-                                                             volumes->data);
+      display_name = gtk_file_system_volume_get_display_name (file_system, volume);
 
       gtk_list_store_insert (store, &iter, pos);
       gtk_list_store_set (store, &iter,
                          ICON_COLUMN, pixbuf,
                          DISPLAY_NAME_COLUMN, display_name,
                          TYPE_COLUMN, ROW_TYPE_VOLUME,
-                         DATA_COLUMN, volumes->data,
+                         DATA_COLUMN, volume,
                          IS_FOLDER_COLUMN, TRUE,
                          -1);
 
@@ -1750,9 +1783,7 @@ model_add_volumes (GtkFileChooserButton *button,
 
       button->priv->n_volumes++;
       pos++;
-      volumes = volumes->next;
     }
-  while (volumes);
 }
 
 static void
@@ -1762,44 +1793,55 @@ model_add_bookmarks (GtkFileChooserButton *button,
   GtkListStore *store;
   GtkTreeIter iter;
   gint pos;
+  gboolean local_only;
+  GSList *l;
 
   if (!bookmarks)
     return;
 
   store = GTK_LIST_STORE (button->priv->model);
-  pos = model_get_type_position (button, ROW_TYPE_BOOKMARK_SEPARATOR);
+  pos = model_get_type_position (button, ROW_TYPE_BOOKMARK);
+  local_only = gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (button->priv->dialog));
 
-  if (!button->priv->has_bookmark_separator)
+  for (l = bookmarks; l; l = l->next)
     {
+      GtkFilePath *path;
+
+      path = l->data;
+
+      if (local_only &&
+         !gtk_file_system_path_is_local (button->priv->fs, path))
+       continue;
+
       gtk_list_store_insert (store, &iter, pos);
       gtk_list_store_set (store, &iter,
                          ICON_COLUMN, NULL,
-                         DISPLAY_NAME_COLUMN, NULL,
-                         TYPE_COLUMN, ROW_TYPE_BOOKMARK_SEPARATOR,
-                         DATA_COLUMN, NULL,
+                         DISPLAY_NAME_COLUMN, _(FALLBACK_DISPLAY_NAME),
+                         TYPE_COLUMN, ROW_TYPE_BOOKMARK,
+                         DATA_COLUMN, gtk_file_path_copy (path),
                          IS_FOLDER_COLUMN, FALSE,
                          -1);
-      button->priv->has_bookmark_separator = TRUE;
+      set_info_for_path_at_iter (button, path, &iter);
+
+      button->priv->n_bookmarks++;
+      pos++;
     }
 
-  do
+  if (button->priv->n_bookmarks > 0 && 
+      !button->priv->has_bookmark_separator)
     {
-      pos++;
+      pos = model_get_type_position (button, ROW_TYPE_BOOKMARK_SEPARATOR);
 
       gtk_list_store_insert (store, &iter, pos);
       gtk_list_store_set (store, &iter,
                          ICON_COLUMN, NULL,
-                         DISPLAY_NAME_COLUMN, _(FALLBACK_DISPLAY_NAME),
-                         TYPE_COLUMN, ROW_TYPE_BOOKMARK,
-                         DATA_COLUMN, gtk_file_path_copy (bookmarks->data),
+                         DISPLAY_NAME_COLUMN, NULL,
+                         TYPE_COLUMN, ROW_TYPE_BOOKMARK_SEPARATOR,
+                         DATA_COLUMN, NULL,
                          IS_FOLDER_COLUMN, FALSE,
                          -1);
-      set_info_for_path_at_iter (button, bookmarks->data, &iter);
-
-      button->priv->n_bookmarks++;
-      bookmarks = bookmarks->next;
+      button->priv->has_bookmark_separator = TRUE;
     }
-  while (bookmarks);
 }
 
 static void
@@ -1960,17 +2002,26 @@ filter_model_visible_func (GtkTreeModel *model,
       break;
     case ROW_TYPE_VOLUME:
       {
-       GtkFilePath *base_path;
-
-       base_path = gtk_file_system_volume_get_base_path (priv->fs, data);
-       if (base_path)
+       if (local_only)
          {
-           retval = (!local_only ||
-                     gtk_file_system_path_is_local (priv->fs, base_path));
-           gtk_file_path_free (base_path);
+           if (gtk_file_system_volume_get_is_mounted (priv->fs, data))
+             {
+               GtkFilePath *base_path;
+               
+               base_path = gtk_file_system_volume_get_base_path (priv->fs, data);
+               if (base_path)
+                 {
+                   gboolean is_local = gtk_file_system_path_is_local (priv->fs, base_path);
+                   
+                   gtk_file_path_free (base_path);
+
+                   if (!is_local)
+                     retval = FALSE;
+                 }
+               else
+                 retval = FALSE;
+             }
          }
-       else
-         retval = FALSE;
       }
       break;
     default:
@@ -2245,19 +2296,11 @@ fs_bookmarks_changed_cb (GtkFileSystem *fs,
   GSList *bookmarks;
 
   bookmarks = gtk_file_system_list_bookmarks (fs);
-  if (!bookmarks)
-    {
-      model_remove_rows (user_data,
-                        model_get_type_position (user_data,
-                                                 ROW_TYPE_BOOKMARK_SEPARATOR),
-                        (priv->n_bookmarks + priv->has_bookmark_separator));
-      priv->has_bookmark_separator = FALSE;
-    }
-  else
-    model_remove_rows (user_data,
-                      model_get_type_position (user_data, ROW_TYPE_BOOKMARK),
-                      priv->n_bookmarks);
-
+  model_remove_rows (user_data,
+                    model_get_type_position (user_data,
+                                             ROW_TYPE_BOOKMARK_SEPARATOR),
+                    (priv->n_bookmarks + priv->has_bookmark_separator));
+  priv->has_bookmark_separator = FALSE;
   priv->n_bookmarks = 0;
   model_add_bookmarks (user_data, bookmarks);
   gtk_file_paths_free (bookmarks);