[gtk/wip/ebassi/filechooser-new] Remove GtkFileChooser:local-only



commit ef825f78222d31a363ad5086096557ed6c82eff6
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Fri Feb 21 16:44:39 2020 +0000

    Remove GtkFileChooser:local-only
    
    Now that the whole API goes through GFile we don't have the weird split
    between local-only and non-local-only modes.

 demos/gtk-demo/pickers.c             |   1 -
 docs/reference/gtk/gtk4-sections.txt |   2 -
 gtk/gtkfilechooser.c                 |  53 ----------------
 gtk/gtkfilechooser.h                 |   5 --
 gtk/gtkfilechooserbutton.c           | 117 +----------------------------------
 gtk/gtkfilechooserutils.c            |   3 -
 gtk/gtkfilechooserutils.h            |   1 -
 gtk/gtkfilechooserwidget.c           |  56 +----------------
 gtk/ui/gtkfilechooserwidget.ui       |   4 +-
 9 files changed, 7 insertions(+), 235 deletions(-)
---
diff --git a/demos/gtk-demo/pickers.c b/demos/gtk-demo/pickers.c
index fe739f7671..0aebc46809 100644
--- a/demos/gtk-demo/pickers.c
+++ b/demos/gtk-demo/pickers.c
@@ -50,7 +50,6 @@ do_pickers (GtkWidget *do_widget)
     gtk_widget_set_hexpand (label, TRUE);
     picker = gtk_file_chooser_button_new ("Pick a File",
                                           GTK_FILE_CHOOSER_ACTION_OPEN);
-    gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (picker), FALSE);
     gtk_grid_attach (GTK_GRID (table), label, 0, 2, 1, 1);
     gtk_grid_attach (GTK_GRID (table), picker, 1, 2, 1, 1);
 
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index aae163d54c..3a0e4ac22b 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -1128,8 +1128,6 @@ GTK_FILE_CHOOSER_ERROR
 GtkFileChooserError
 gtk_file_chooser_set_action
 gtk_file_chooser_get_action
-gtk_file_chooser_set_local_only
-gtk_file_chooser_get_local_only
 gtk_file_chooser_set_select_multiple
 gtk_file_chooser_get_select_multiple
 gtk_file_chooser_set_create_folders
diff --git a/gtk/gtkfilechooser.c b/gtk/gtkfilechooser.c
index dc72b5b8fa..0dbb05581d 100644
--- a/gtk/gtkfilechooser.c
+++ b/gtk/gtkfilechooser.c
@@ -250,12 +250,6 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
                                                             P_("The current filter for selecting which files 
are displayed"),
                                                             GTK_TYPE_FILE_FILTER,
                                                             GTK_PARAM_READWRITE));
-  g_object_interface_install_property (iface,
-                                       g_param_spec_boolean ("local-only",
-                                                             P_("Local Only"),
-                                                             P_("Whether the selected file(s) should be 
limited to local file: URLs"),
-                                                             FALSE,
-                                                             GTK_PARAM_READWRITE));
   g_object_interface_install_property (iface,
                                        g_param_spec_object ("preview-widget",
                                                             P_("Preview widget"),
@@ -350,53 +344,6 @@ gtk_file_chooser_get_action (GtkFileChooser *chooser)
   return action;
 }
 
-/**
- * gtk_file_chooser_set_local_only:
- * @chooser: a #GtkFileChooser
- * @local_only: %TRUE if only local files can be selected
- * 
- * Sets whether only local files can be selected in the
- * file selector. If @local_only is %TRUE (the default is %FALSE),
- * then the selected file or files are guaranteed to be
- * accessible through the operating system’s native file
- * system and therefore the application only
- * needs to worry about the filename functions in
- * #GtkFileChooser, like gtk_file_chooser_get_file().
- *
- * On some systems non-native files may still be
- * available using the native filesystem via a userspace
- * filesystem (FUSE).
- **/
-void
-gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
-                                 gboolean        local_only)
-{
-  g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
-
-  g_object_set (chooser, "local-only", local_only, NULL);
-}
-
-/**
- * gtk_file_chooser_get_local_only:
- * @chooser: a #GtkFileChooser
- * 
- * Gets whether only local files can be selected in the
- * file selector. See gtk_file_chooser_set_local_only()
- * 
- * Returns: %TRUE if only local files can be selected.
- **/
-gboolean
-gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
-{
-  gboolean local_only;
-  
-  g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
-
-  g_object_get (chooser, "local-only", &local_only, NULL);
-
-  return local_only;
-}
-
 /**
  * gtk_file_chooser_set_select_multiple:
  * @chooser: a #GtkFileChooser
diff --git a/gtk/gtkfilechooser.h b/gtk/gtkfilechooser.h
index 79589ee5d4..c641cba86c 100644
--- a/gtk/gtkfilechooser.h
+++ b/gtk/gtkfilechooser.h
@@ -99,11 +99,6 @@ void                 gtk_file_chooser_set_action          (GtkFileChooser
 GDK_AVAILABLE_IN_ALL
 GtkFileChooserAction gtk_file_chooser_get_action          (GtkFileChooser       *chooser);
 GDK_AVAILABLE_IN_ALL
-void                 gtk_file_chooser_set_local_only      (GtkFileChooser       *chooser,
-                                                          gboolean              local_only);
-GDK_AVAILABLE_IN_ALL
-gboolean             gtk_file_chooser_get_local_only      (GtkFileChooser       *chooser);
-GDK_AVAILABLE_IN_ALL
 void                 gtk_file_chooser_set_select_multiple (GtkFileChooser       *chooser,
                                                           gboolean              select_multiple);
 GDK_AVAILABLE_IN_ALL
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index 19e29efd03..1a1ad54089 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -334,9 +334,6 @@ static void     button_clicked_cb                (GtkButton      *real_button,
 
 static void     chooser_update_preview_cb        (GtkFileChooser *dialog,
                                                  gpointer        user_data);
-static void     chooser_notify_cb                (GObject        *dialog,
-                                                 GParamSpec     *pspec,
-                                                 gpointer        user_data);
 static void     dialog_response_cb               (GtkDialog      *dialog,
                                                  gint            response,
                                                  gpointer        user_data);
@@ -811,9 +808,6 @@ gtk_file_chooser_button_constructed (GObject *object)
                                  (gpointer) (&priv->dialog));
     }
 
-  g_signal_connect (priv->chooser, "notify",
-                    G_CALLBACK (chooser_notify_cb), object);
-
   /* This is used, instead of the standard delegate, to ensure that signals are only
    * delegated when the OK button is pressed. */
   g_object_set_qdata (object, GTK_FILE_CHOOSER_DELEGATE_QUARK, priv->chooser);
@@ -929,12 +923,6 @@ gtk_file_chooser_button_set_property (GObject      *object,
       g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value);
       break;
 
-    case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
-      g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value);
-      fs_volumes_changed_cb (priv->fs, button);
-      bookmarks_changed_cb (button);
-      break;
-
     case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
       g_warning ("%s: Choosers of type '%s' do not support selecting multiple files.",
                 G_STRFUNC, G_OBJECT_TYPE_NAME (object));
@@ -964,7 +952,6 @@ gtk_file_chooser_button_get_property (GObject    *object,
     case PROP_TITLE:
     case GTK_FILE_CHOOSER_PROP_ACTION:
     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:
@@ -1828,7 +1815,6 @@ model_add_volumes (GtkFileChooserButton *button,
   GtkFileChooserButtonPrivate *priv = gtk_file_chooser_button_get_instance_private (button);
   GtkListStore *store;
   gint pos;
-  gboolean local_only;
   GSList *l;
 
   if (!volumes)
@@ -1836,7 +1822,6 @@ model_add_volumes (GtkFileChooserButton *button,
 
   store = GTK_LIST_STORE (priv->model);
   pos = model_get_type_position (button, ROW_TYPE_VOLUME);
-  local_only = gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (priv->chooser));
 
   for (l = volumes; l; l = l->next)
     {
@@ -1846,27 +1831,6 @@ model_add_volumes (GtkFileChooserButton *button,
       gchar *display_name;
 
       volume = l->data;
-
-      if (local_only)
-        {
-          if (_gtk_file_system_volume_is_mounted (volume))
-            {
-              GFile *base_file;
-
-              base_file = _gtk_file_system_volume_get_root (volume);
-              if (base_file != NULL)
-                {
-                  if (!_gtk_file_has_native_path (base_file))
-                    {
-                      g_object_unref (base_file);
-                      continue;
-                    }
-                  else
-                    g_object_unref (base_file);
-                }
-            }
-        }
-
       icon = _gtk_file_system_volume_get_icon (volume);
       display_name = _gtk_file_system_volume_get_display_name (volume);
 
@@ -1896,7 +1860,6 @@ model_add_bookmarks (GtkFileChooserButton *button,
   GtkListStore *store;
   GtkTreeIter iter;
   gint pos;
-  gboolean local_only;
   GSList *l;
 
   if (!bookmarks)
@@ -1904,7 +1867,6 @@ model_add_bookmarks (GtkFileChooserButton *button,
 
   store = GTK_LIST_STORE (priv->model);
   pos = model_get_type_position (button, ROW_TYPE_BOOKMARK);
-  local_only = gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (priv->chooser));
 
   for (l = bookmarks; l; l = l->next)
     {
@@ -1929,9 +1891,6 @@ model_add_bookmarks (GtkFileChooserButton *button,
          gchar *label;
          GIcon *icon;
 
-         if (local_only)
-           continue;
-
          /* Don't call get_info for remote paths to avoid latency and
           * auth dialogs.
           * If we switch to a better bookmarks file format (XBEL), we
@@ -2129,15 +2088,11 @@ model_remove_rows (GtkFileChooserButton *button,
 static gboolean
 test_if_file_is_visible (GtkFileSystem *fs,
                         GFile         *file,
-                        gboolean       local_only,
                         gboolean       is_folder)
 {
   if (!file)
     return FALSE;
 
-  if (local_only && !_gtk_file_has_native_path (file))
-    return FALSE;
-
   if (!is_folder)
     return FALSE;
 
@@ -2153,11 +2108,10 @@ filter_model_visible_func (GtkTreeModel *model,
   GtkFileChooserButtonPrivate *priv = gtk_file_chooser_button_get_instance_private (button);
   gchar type;
   gpointer data;
-  gboolean local_only, retval, is_folder;
+  gboolean retval, is_folder;
 
   type = ROW_TYPE_INVALID;
   data = NULL;
-  local_only = gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (priv->chooser));
 
   gtk_tree_model_get (model, iter,
                      TYPE_COLUMN, &type,
@@ -2173,30 +2127,10 @@ filter_model_visible_func (GtkTreeModel *model,
     case ROW_TYPE_SPECIAL:
     case ROW_TYPE_SHORTCUT:
     case ROW_TYPE_BOOKMARK:
-      retval = test_if_file_is_visible (priv->fs, data, local_only, is_folder);
+      retval = test_if_file_is_visible (priv->fs, data, is_folder);
       break;
     case ROW_TYPE_VOLUME:
-      {
-       retval = TRUE;
-       if (local_only)
-         {
-           if (_gtk_file_system_volume_is_mounted (data))
-             {
-               GFile *base_file;
-
-               base_file = _gtk_file_system_volume_get_root (data);
-
-               if (base_file)
-                 {
-                   if (!_gtk_file_has_native_path (base_file))
-                     retval = FALSE;
-                    g_object_unref (base_file);
-                 }
-               else
-                 retval = FALSE;
-             }
-         }
-      }
+      retval = TRUE;
       break;
     default:
       retval = TRUE;
@@ -2710,51 +2644,6 @@ chooser_update_preview_cb (GtkFileChooser *dialog,
   g_signal_emit_by_name (user_data, "update-preview");
 }
 
-static void
-chooser_notify_cb (GObject    *dialog,
-                   GParamSpec *pspec,
-                   gpointer    user_data)
-{
-  gpointer iface;
-
-  iface = g_type_interface_peek (g_type_class_peek (G_OBJECT_TYPE (dialog)),
-                                GTK_TYPE_FILE_CHOOSER);
-  if (g_object_interface_find_property (iface, pspec->name))
-    g_object_notify (user_data, pspec->name);
-
-  if (g_ascii_strcasecmp (pspec->name, "local-only") == 0)
-    {
-      GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
-      GtkFileChooserButtonPrivate *priv = gtk_file_chooser_button_get_instance_private (button);
-
-      if (priv->has_current_folder)
-       {
-         GtkTreeIter iter;
-         gint pos;
-         gpointer data;
-
-         pos = model_get_type_position (user_data,
-                                        ROW_TYPE_CURRENT_FOLDER);
-         gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, pos);
-
-         data = NULL;
-         gtk_tree_model_get (priv->model, &iter, DATA_COLUMN, &data, -1);
-
-         /* If the path isn't local but we're in local-only mode now, remove
-          * the custom-folder row */
-         if (data && _gtk_file_has_native_path (G_FILE (data)) &&
-             gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (priv->chooser)))
-           {
-             pos--;
-             model_remove_rows (user_data, pos, 2);
-           }
-       }
-
-      gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
-      update_combo_box (user_data);
-    }
-}
-
 static void
 common_response_cb (GtkFileChooserButton *button,
                    gint       response)
diff --git a/gtk/gtkfilechooserutils.c b/gtk/gtkfilechooserutils.c
index 571a02f084..3a4241dabe 100644
--- a/gtk/gtkfilechooserutils.c
+++ b/gtk/gtkfilechooserutils.c
@@ -100,9 +100,6 @@ _gtk_file_chooser_install_properties (GObjectClass *klass)
   g_object_class_override_property (klass,
                                    GTK_FILE_CHOOSER_PROP_FILTER,
                                    "filter");
-  g_object_class_override_property (klass,
-                                   GTK_FILE_CHOOSER_PROP_LOCAL_ONLY,
-                                   "local-only");
   g_object_class_override_property (klass,
                                    GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET,
                                    "preview-widget");
diff --git a/gtk/gtkfilechooserutils.h b/gtk/gtkfilechooserutils.h
index 4de4c6a44e..38341f2d72 100644
--- a/gtk/gtkfilechooserutils.h
+++ b/gtk/gtkfilechooserutils.h
@@ -30,7 +30,6 @@ typedef enum {
   GTK_FILE_CHOOSER_PROP_FIRST                  = 0x1000,
   GTK_FILE_CHOOSER_PROP_ACTION                 = GTK_FILE_CHOOSER_PROP_FIRST,
   GTK_FILE_CHOOSER_PROP_FILTER,
-  GTK_FILE_CHOOSER_PROP_LOCAL_ONLY,
   GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET,
   GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE,
   GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL,
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index fe71728ddf..4ace72d9c5 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -359,7 +359,6 @@ struct _GtkFileChooserWidgetPrivate {
 
   /* Flags */
 
-  guint local_only : 1;
   guint preview_widget_active : 1;
   guint use_preview_label : 1;
   guint select_multiple : 1;
@@ -2480,7 +2479,7 @@ location_entry_setup (GtkFileChooserWidget *impl)
   g_signal_connect_swapped (priv->location_entry, "hide-entry",
                             G_CALLBACK (location_entry_close_clicked), impl);
 
-  _gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (priv->location_entry), priv->local_only);
+  _gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (priv->location_entry), FALSE);
   _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (priv->location_entry), priv->action);
   _gtk_file_chooser_entry_set_file_filter (GTK_FILE_CHOOSER_ENTRY (priv->location_entry),
                                            priv->current_filter);
@@ -2835,33 +2834,6 @@ switch_to_home_dir (GtkFileChooserWidget *impl)
   g_object_unref (home_file);
 }
 
-static void
-set_local_only (GtkFileChooserWidget *impl,
-                gboolean               local_only)
-{
-  GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
-
-  if (local_only != priv->local_only)
-    {
-      priv->local_only = local_only;
-
-      if (priv->location_entry)
-        _gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (priv->location_entry), local_only);
-
-      gtk_places_sidebar_set_local_only (GTK_PLACES_SIDEBAR (priv->places_sidebar), local_only);
-
-      if (local_only && priv->current_folder &&
-           !_gtk_file_has_native_path (priv->current_folder))
-        {
-          /* If we are pointing to a non-local folder, make an effort to change
-           * back to a local folder, but it's really up to the app to not cause
-           * such a situation, so we ignore errors.
-           */
-          switch_to_home_dir (impl);
-        }
-    }
-}
-
 /* Sets the file chooser to multiple selection mode */
 static void
 set_select_multiple (GtkFileChooserWidget *impl,
@@ -3209,10 +3181,7 @@ gtk_file_chooser_widget_get_subtitle (GtkFileChooserWidget *impl)
            (priv->operation_mode == OPERATION_MODE_BROWSE &&
             priv->location_mode == LOCATION_MODE_FILENAME_ENTRY))
     {
-      if (priv->local_only)
-        subtitle = g_strdup (_("Enter location"));
-      else
-        subtitle = g_strdup (_("Enter location or URL"));
+      subtitle = g_strdup (_("Enter location or URL"));
     }
 
   return subtitle;
@@ -3295,10 +3264,6 @@ gtk_file_chooser_widget_set_property (GObject      *object,
       set_current_filter (impl, g_value_get_object (value));
       break;
 
-    case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
-      set_local_only (impl, g_value_get_boolean (value));
-      break;
-
     case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
       set_preview_widget (impl, g_value_get_object (value));
       break;
@@ -3371,10 +3336,6 @@ gtk_file_chooser_widget_get_property (GObject    *object,
       g_value_set_object (value, priv->current_filter);
       break;
 
-    case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
-      g_value_set_boolean (value, priv->local_only);
-      break;
-
     case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
       g_value_set_object (value, priv->preview_widget);
       break;
@@ -5477,18 +5438,6 @@ gtk_file_chooser_widget_update_current_folder (GtkFileChooser  *chooser,
 
   operation_mode_set (impl, OPERATION_MODE_BROWSE);
 
-  if (priv->local_only && !_gtk_file_has_native_path (file))
-    {
-      g_set_error_literal (error,
-                           GTK_FILE_CHOOSER_ERROR,
-                           GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
-                           _("Cannot change to folder because it is not local"));
-
-      g_object_unref (file);
-      profile_end ("end - not local", NULL);
-      return FALSE;
-    }
-
   if (priv->update_current_folder_cancellable)
     g_cancellable_cancel (priv->update_current_folder_cancellable);
 
@@ -8392,7 +8341,6 @@ gtk_file_chooser_widget_init (GtkFileChooserWidget *impl)
   access ("MARK: *** CREATE FILE CHOOSER", F_OK);
 #endif
 
-  priv->local_only = FALSE;
   priv->preview_widget_active = TRUE;
   priv->use_preview_label = TRUE;
   priv->select_multiple = FALSE;
diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui
index a1ee4f8573..039b5043f9 100644
--- a/gtk/ui/gtkfilechooserwidget.ui
+++ b/gtk/ui/gtkfilechooserwidget.ui
@@ -16,7 +16,7 @@
                 <property name="vexpand">1</property>
                 <child>
                   <object class="GtkPlacesSidebar" id="places_sidebar">
-                    <property name="local-only">1</property>
+                    <property name="local-only">0</property>
                     <property name="show-other-locations">1</property>
                     <style>
                       <class name="sidebar"/>
@@ -263,7 +263,7 @@
                                 <property name="name">other_locations</property>
                                 <property name="child">
                                   <object class="GtkPlacesView" id="places_view">
-                                    <property name="local-only" bind-source="GtkFileChooserWidget" 
bind-property="local-only" bind-flags="default|sync-create"/>
+                                    <property name="local-only">0</property>
                                     <signal name="open-location" handler="places_sidebar_open_location_cb" 
swapped="no"/>
                                     <signal name="show-error-message" 
handler="places_sidebar_show_error_message_cb" swapped="no"/>
                                   </object>


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