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.
This commit is contained in:
Emmanuele Bassi
2020-02-21 16:44:39 +00:00
parent 516eab5c43
commit b09e7df81b
11 changed files with 7 additions and 241 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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 systems 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

View File

@@ -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

View File

@@ -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)

View File

@@ -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");

View File

@@ -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,

View File

@@ -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;

View File

@@ -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>

View File

@@ -500,7 +500,6 @@ main (int argc, char **argv)
GtkFileFilter *filter;
gboolean force_rtl = FALSE;
gboolean multiple = FALSE;
gboolean local_only = FALSE;
char *action_arg = NULL;
char *initial_filename = NULL;
char *initial_folder = NULL;
@@ -509,7 +508,6 @@ main (int argc, char **argv)
GOptionEntry options[] = {
{ "action", 'a', 0, G_OPTION_ARG_STRING, &action_arg, "Filechooser action", "ACTION" },
{ "multiple", 'm', 0, G_OPTION_ARG_NONE, &multiple, "Select multiple", NULL },
{ "local-only", 'l', 0, G_OPTION_ARG_NONE, &local_only, "Local only", NULL },
{ "right-to-left", 'r', 0, G_OPTION_ARG_NONE, &force_rtl, "Force right-to-left layout.", NULL },
{ "initial-filename", 'f', 0, G_OPTION_ARG_FILENAME, &initial_filename, "Initial filename to select", "FILENAME" },
{ "initial-folder", 'F', 0, G_OPTION_ARG_FILENAME, &initial_folder, "Initial folder to show", "FILENAME" },
@@ -563,7 +561,6 @@ main (int argc, char **argv)
dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
"action", action,
"select-multiple", multiple,
"local-only", local_only,
NULL);
switch (action)

View File

@@ -81,9 +81,6 @@ list_ignore_properties (gboolean buglist)
static const IgnoreProperty bug_properties[] = {
{ "GtkComboBox", "active", (void*) MATCH_ANY_VALUE }, /* FIXME: triggers NULL model bug */
{ "GtkCTree", "spacing", (void*) MATCH_ANY_VALUE }, /* FIXME: triggers signedness bug */
{ "GtkFileChooserButton", "local-only", (void*) MATCH_ANY_VALUE }, /* FIXME: triggers NULL path assertion */
{ "GtkFileChooserDialog", "local-only", (void*) MATCH_ANY_VALUE }, /* FIXME: triggers NULL path assertion */
{ "GtkFileChooserWidget", "local-only", (void*) MATCH_ANY_VALUE }, /* FIXME: triggers NULL path assertion */
{ "GtkText", "text-position", (void*) MATCH_ANY_VALUE }, /* FIXME: segfaults, fix property minimum/maximum */
{ NULL, NULL, NULL }
};