Commit 2c9d190c authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

Implement local_only by filtering the shortcuts and bookmarks list by

Sun Mar 14 23:36:15 2004  Owen Taylor  <otaylor@redhat.com>

        * gtk/gtkfilechooserdefault.c: Implement local_only by
        filtering the shortcuts and bookmarks list by
        gtk_file_system_path_to_filename (file_system, path) != NULL.
        (#132894)

        * gtk/gtkfilesystem.c (gtk_file_system_path_is_local): Add
        a convenience function, may by interesting to push to the
        file system vtable later for performance.
parent 084bb2fe
Sun Mar 14 23:36:15 2004 Owen Taylor <otaylor@redhat.com>
* gtk/gtkfilechooserdefault.c: Implement local_only by
filtering the shortcuts and bookmarks list by
gtk_file_system_path_to_filename (file_system, path) != NULL.
(#132894)
* gtk/gtkfilesystem.c (gtk_file_system_path_is_local): Add
a convenience function, may by interesting to push to the
file system vtable later for performance.
2004-03-14 Federico Mena Quintero <federico@ximian.com> 2004-03-14 Federico Mena Quintero <federico@ximian.com>
* gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path * gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path
......
Sun Mar 14 23:36:15 2004 Owen Taylor <otaylor@redhat.com>
* gtk/gtkfilechooserdefault.c: Implement local_only by
filtering the shortcuts and bookmarks list by
gtk_file_system_path_to_filename (file_system, path) != NULL.
(#132894)
* gtk/gtkfilesystem.c (gtk_file_system_path_is_local): Add
a convenience function, may by interesting to push to the
file system vtable later for performance.
2004-03-14 Federico Mena Quintero <federico@ximian.com> 2004-03-14 Federico Mena Quintero <federico@ximian.com>
* gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path * gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path
......
Sun Mar 14 23:36:15 2004 Owen Taylor <otaylor@redhat.com>
* gtk/gtkfilechooserdefault.c: Implement local_only by
filtering the shortcuts and bookmarks list by
gtk_file_system_path_to_filename (file_system, path) != NULL.
(#132894)
* gtk/gtkfilesystem.c (gtk_file_system_path_is_local): Add
a convenience function, may by interesting to push to the
file system vtable later for performance.
2004-03-14 Federico Mena Quintero <federico@ximian.com> 2004-03-14 Federico Mena Quintero <federico@ximian.com>
* gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path * gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path
......
Sun Mar 14 23:36:15 2004 Owen Taylor <otaylor@redhat.com>
* gtk/gtkfilechooserdefault.c: Implement local_only by
filtering the shortcuts and bookmarks list by
gtk_file_system_path_to_filename (file_system, path) != NULL.
(#132894)
* gtk/gtkfilesystem.c (gtk_file_system_path_is_local): Add
a convenience function, may by interesting to push to the
file system vtable later for performance.
2004-03-14 Federico Mena Quintero <federico@ximian.com> 2004-03-14 Federico Mena Quintero <federico@ximian.com>
* gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path * gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path
......
Sun Mar 14 23:36:15 2004 Owen Taylor <otaylor@redhat.com>
* gtk/gtkfilechooserdefault.c: Implement local_only by
filtering the shortcuts and bookmarks list by
gtk_file_system_path_to_filename (file_system, path) != NULL.
(#132894)
* gtk/gtkfilesystem.c (gtk_file_system_path_is_local): Add
a convenience function, may by interesting to push to the
file system vtable later for performance.
2004-03-14 Federico Mena Quintero <federico@ximian.com> 2004-03-14 Federico Mena Quintero <federico@ximian.com>
* gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path * gtk/gtkfilesystem.c (gtk_file_folder_get_info): Allow the path
......
...@@ -1065,6 +1065,10 @@ shortcuts_append_paths (GtkFileChooserDefault *impl, ...@@ -1065,6 +1065,10 @@ shortcuts_append_paths (GtkFileChooserDefault *impl,
path = paths->data; path = paths->data;
error = NULL; error = NULL;
if (impl->local_only &&
!gtk_file_system_path_is_local (impl->file_system, path))
continue;
/* NULL GError, but we don't really want to show error boxes here */ /* NULL GError, but we don't really want to show error boxes here */
if (shortcuts_insert_path (impl, start_row + num_inserted, FALSE, NULL, path, NULL, TRUE, NULL)) if (shortcuts_insert_path (impl, start_row + num_inserted, FALSE, NULL, path, NULL, TRUE, NULL))
num_inserted++; num_inserted++;
...@@ -1192,6 +1196,17 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl) ...@@ -1192,6 +1196,17 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
GtkFileSystemVolume *volume; GtkFileSystemVolume *volume;
volume = l->data; volume = l->data;
if (impl->local_only)
{
GtkFilePath *base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
gboolean is_local = gtk_file_system_path_is_local (impl->file_system, base_path);
gtk_file_path_free (base_path);
if (!is_local)
continue;
}
shortcuts_insert_path (impl, start_row + n, TRUE, volume, NULL, NULL, FALSE, NULL); shortcuts_insert_path (impl, start_row + n, TRUE, volume, NULL, NULL, FALSE, NULL);
n++; n++;
} }
...@@ -2909,6 +2924,37 @@ set_extra_widget (GtkFileChooserDefault *impl, ...@@ -2909,6 +2924,37 @@ set_extra_widget (GtkFileChooserDefault *impl,
impl->extra_widget = extra_widget; impl->extra_widget = extra_widget;
} }
static void
set_local_only (GtkFileChooserDefault *impl,
gboolean local_only)
{
if (local_only != impl->local_only)
{
impl->local_only = local_only;
if (impl->shortcuts_model && impl->file_system)
{
shortcuts_add_volumes (impl);
shortcuts_add_bookmarks (impl);
}
if (local_only &&
!gtk_file_system_path_is_local (impl->file_system, impl->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.
*/
const gchar *home = g_get_home_dir ();
GtkFilePath *home_path = gtk_file_system_filename_to_path (impl->file_system, home);
_gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), home_path, NULL);
gtk_file_path_free (home_path);
}
}
}
static void static void
volumes_changed_cb (GtkFileSystem *file_system, volumes_changed_cb (GtkFileSystem *file_system,
GtkFileChooserDefault *impl) GtkFileChooserDefault *impl)
...@@ -3160,7 +3206,7 @@ gtk_file_chooser_default_set_property (GObject *object, ...@@ -3160,7 +3206,7 @@ gtk_file_chooser_default_set_property (GObject *object,
set_current_filter (impl, g_value_get_object (value)); set_current_filter (impl, g_value_get_object (value));
break; break;
case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY: case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
impl->local_only = g_value_get_boolean (value); set_local_only (impl, g_value_get_boolean (value));
break; break;
case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET: case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
set_preview_widget (impl, g_value_get_object (value)); set_preview_widget (impl, g_value_get_object (value));
...@@ -3605,6 +3651,17 @@ gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser, ...@@ -3605,6 +3651,17 @@ gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
if (!check_is_folder (impl->file_system, path, error)) if (!check_is_folder (impl->file_system, path, error))
return FALSE; return FALSE;
if (impl->local_only &&
!gtk_file_system_path_is_local (impl->file_system, path))
{
g_set_error (error,
GTK_FILE_SYSTEM_ERROR,
GTK_FILE_SYSTEM_ERROR_FAILED,
_("Can't change to folder because it isn't local"));
return FALSE;
}
if (!_gtk_path_bar_set_path (GTK_PATH_BAR (impl->browse_path_bar), path, error)) if (!_gtk_path_bar_set_path (GTK_PATH_BAR (impl->browse_path_bar), path, error))
return FALSE; return FALSE;
......
...@@ -654,6 +654,33 @@ gtk_file_system_filename_to_path (GtkFileSystem *file_system, ...@@ -654,6 +654,33 @@ gtk_file_system_filename_to_path (GtkFileSystem *file_system,
return GTK_FILE_SYSTEM_GET_IFACE (file_system)->filename_to_path (file_system, filename); return GTK_FILE_SYSTEM_GET_IFACE (file_system)->filename_to_path (file_system, filename);
} }
/**
* gtk_file_system_path_is_local:
* @filesystem: a #GtkFileSystem
* @path: A #GtkFilePath from that filesystem
*
* Checks whether a #GtkFilePath is local; that is whether
* gtk_file_system_path_to_filename would return non-%NULL.
*
* Return value: %TRUE if the path is loca
**/
gboolean
gtk_file_system_path_is_local (GtkFileSystem *file_system,
const GtkFilePath *path)
{
gchar *filename;
gboolean result;
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
g_return_val_if_fail (path != NULL, FALSE);
filename = gtk_file_system_path_to_filename (file_system, path);
result = filename != NULL;
g_free (filename);
return result;
}
GdkPixbuf * GdkPixbuf *
gtk_file_system_render_icon (GtkFileSystem *file_system, gtk_file_system_render_icon (GtkFileSystem *file_system,
const GtkFilePath *path, const GtkFilePath *path,
......
...@@ -256,6 +256,9 @@ GtkFilePath *gtk_file_system_uri_to_path (GtkFileSystem *file_system, ...@@ -256,6 +256,9 @@ GtkFilePath *gtk_file_system_uri_to_path (GtkFileSystem *file_system,
GtkFilePath *gtk_file_system_filename_to_path (GtkFileSystem *file_system, GtkFilePath *gtk_file_system_filename_to_path (GtkFileSystem *file_system,
const gchar *filename); const gchar *filename);
gboolean gtk_file_system_path_is_local (GtkFileSystem *filesystem,
const GtkFilePath *path);
GdkPixbuf *gtk_file_system_render_icon (GtkFileSystem *file_system, GdkPixbuf *gtk_file_system_render_icon (GtkFileSystem *file_system,
const GtkFilePath *path, const GtkFilePath *path,
GtkWidget *widget, GtkWidget *widget,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment