[gtk+/multiroot-filechooser: 4/15] Make the local_only property wrap root_uri.
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/multiroot-filechooser: 4/15] Make the local_only property wrap root_uri.
- Date: Thu, 17 Jun 2010 17:30:33 +0000 (UTC)
commit 80ba31d9d7c5ccbcf495bfde0f6b7da010702e7f
Author: Christian Hammond <chipx86 chipx86 com>
Date: Tue Feb 2 03:43:49 2010 -0800
Make the local_only property wrap root_uri.
Root URI and Local Only properties are very similar, so this change combines
them into one concept. A root URI of "file://" is now the same as the old
Local Only. The old Local Only property remains, and we may even want to keep
it around indefinitely, but it just simply wraps a root URI of "file://".
The set_local_only and set_root_uri functions have been merged, and improved
logic for setting the current folder on root URI/local-only property changes
has been added.
gtk/gtkfilechooserdefault.c | 129 ++++++++++++++++++++++++-------------------
gtk/gtkfilechooserprivate.h | 1 -
2 files changed, 72 insertions(+), 58 deletions(-)
---
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index db8cf71..2594ffa 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -714,8 +714,7 @@ _gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
#ifdef PROFILE_FILE_CHOOSER
access ("MARK: *** CREATE FILE CHOOSER", F_OK);
#endif
- impl->local_only = TRUE;
- impl->root_uri = NULL;
+ impl->root_uri = g_strdup ("file://");
impl->preview_widget_active = TRUE;
impl->use_preview_label = TRUE;
impl->select_multiple = FALSE;
@@ -1947,20 +1946,23 @@ shortcuts_append_bookmarks (GtkFileChooserDefault *impl,
int start_row;
int num_inserted;
gchar *label;
+ gboolean local_only;
profile_start ("start", NULL);
start_row = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR) + 1;
num_inserted = 0;
+ local_only = gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (impl));
+
for (; bookmarks; bookmarks = bookmarks->next)
{
GFile *file;
file = bookmarks->data;
- if (impl->local_only && !g_file_is_native (file))
- continue;
+ if (local_only && !g_file_is_native (file))
+ continue;
if (!_gtk_file_chooser_is_file_in_root (GTK_FILE_CHOOSER (impl), file))
continue;
@@ -2059,6 +2061,7 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
GSList *list, *l;
int n;
gboolean old_changing_folders;
+ gboolean local_only;
profile_start ("start", NULL);
@@ -2071,6 +2074,8 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
list = _gtk_file_system_list_volumes (impl->file_system);
+ local_only = gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (impl));
+
n = 0;
for (l = list; l; l = l->next)
@@ -2083,7 +2088,8 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
base_file = _gtk_file_system_volume_get_root (volume);
- if (impl->local_only &&
+ if (local_only &&
+ base_file != NULL &&
_gtk_file_system_volume_is_mounted (volume) &&
!g_file_is_native (base_file))
skip = TRUE;
@@ -4891,7 +4897,9 @@ save_widgets_create (GtkFileChooserDefault *impl)
impl->location_entry = _gtk_file_chooser_entry_new (TRUE);
_gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
impl->file_system);
- _gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->local_only);
+ _gtk_file_chooser_entry_set_local_only (
+ GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
+ gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (impl)));
_gtk_file_chooser_entry_set_root_uri (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->root_uri);
gtk_entry_set_width_chars (GTK_ENTRY (impl->location_entry), 45);
gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
@@ -5331,45 +5339,6 @@ set_extra_widget (GtkFileChooserDefault *impl,
}
static void
-set_local_only (GtkFileChooserDefault *impl,
- gboolean local_only)
-{
- if (local_only != impl->local_only)
- {
- impl->local_only = local_only;
-
- if (impl->location_entry)
- _gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), local_only);
-
- if (impl->shortcuts_model && impl->file_system)
- {
- shortcuts_model_create (impl);
- shortcuts_add_bookmarks (impl);
- }
-
- if (local_only && impl->current_folder &&
- !g_file_is_native (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 ();
- GFile *home_file;
-
- if (home == NULL)
- return;
-
- home_file = g_file_new_for_path (home);
-
- gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (impl), home_file, NULL);
-
- g_object_unref (home_file);
- }
- }
-}
-
-static void
set_root_uri (GtkFileChooserDefault *impl,
const gchar *root_uri)
{
@@ -5381,15 +5350,21 @@ set_root_uri (GtkFileChooserDefault *impl,
GtkTreeIter iter;
GFile *list_selected = NULL;
ShortcutType shortcut_type = -1;
+ gboolean local_only;
g_free (impl->root_uri);
impl->root_uri = (root_uri == NULL ? NULL : g_strdup (root_uri));
+ local_only = gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (impl));
+
if (impl->location_entry)
{
_gtk_file_chooser_entry_set_root_uri (
GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
impl->root_uri);
+ _gtk_file_chooser_entry_set_local_only (
+ GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
+ local_only);
}
/* Attempt to preserve the sidebar selection if possible. */
@@ -5419,16 +5394,53 @@ set_root_uri (GtkFileChooserDefault *impl,
shortcuts_add_bookmarks (impl);
}
- if (impl->current_folder &&
- _gtk_file_chooser_is_file_in_root (GTK_FILE_CHOOSER (impl),
- impl->current_folder))
+ if (impl->current_folder != NULL)
{
- /*
- * If we are pointing to a folder outside of the root URI, set the
- * folder to the root URI.
- */
- gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (impl),
- impl->root_uri);
+ if (local_only && !g_file_is_native (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 ();
+ GFile *home_file;
+
+ if (home != NULL)
+ {
+ home_file = g_file_new_for_path (home);
+ gtk_file_chooser_set_current_folder_file (
+ GTK_FILE_CHOOSER (impl),
+ home_file, NULL);
+
+ g_object_unref (home_file);
+ }
+ }
+ else if (impl->root_uri != NULL &&
+ !_gtk_file_chooser_is_file_in_root (GTK_FILE_CHOOSER (impl),
+ impl->current_folder))
+ {
+ /*
+ * If we are pointing to a folder outside of the root URI,
+ * set the folder to the root URI.
+ */
+
+ /*
+ * Clear the list first, in case we can't load this path.
+ * We don't want to show files they shouldn't be able to access.
+ */
+ if (impl->operation_mode == OPERATION_MODE_BROWSE)
+ stop_operation (impl, impl->operation_mode);
+
+ gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (impl),
+ impl->root_uri);
+ }
+ else
+ {
+ /* Re-set the current folder so we'll display it properly. */
+ gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (impl),
+ impl->current_folder,
+ NULL);
+ }
}
if (shortcut_type != -1)
@@ -5644,7 +5656,7 @@ gtk_file_chooser_default_set_property (GObject *object,
break;
case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
- set_local_only (impl, g_value_get_boolean (value));
+ set_root_uri (impl, g_value_get_boolean (value) ? "file://" : NULL);
break;
case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
@@ -5739,7 +5751,9 @@ gtk_file_chooser_default_get_property (GObject *object,
break;
case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
- g_value_set_boolean (value, impl->local_only);
+ g_value_set_boolean (value,
+ impl->root_uri != NULL &&
+ g_str_has_prefix (impl->root_uri, "file://"));
break;
case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
@@ -7402,7 +7416,8 @@ gtk_file_chooser_default_update_current_folder (GtkFileChooser *chooser,
break;
}
- if (impl->local_only && !g_file_is_native (file))
+ if (gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (impl)) &&
+ !g_file_is_native (file))
{
g_set_error_literal (error,
GTK_FILE_CHOOSER_ERROR,
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index 377a1b2..38f86b1 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -297,7 +297,6 @@ struct _GtkFileChooserDefault
/* Flags */
- guint local_only : 1;
guint preview_widget_active : 1;
guint use_preview_label : 1;
guint select_multiple : 1;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]