summaryrefslogtreecommitdiff
path: root/gtk/gtkfilechooserbutton.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2006-09-22 16:11:04 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2006-09-22 16:11:04 +0000
commit09f461b01e3eed0cca58e786d08628195a4ae16e (patch)
tree3e9e35fc1239b65f5f9a61dca3cce80510bc1eb7 /gtk/gtkfilechooserbutton.c
parent2f50232a4258c27e793db55c0ab26ab5009432ad (diff)
downloadgtk+-09f461b01e3eed0cca58e786d08628195a4ae16e.tar.gz
Make remote bookmarks work better (#354887)
2006-09-22 Matthias Clasen <mclasen@redhat.com> Make remote bookmarks work better (#354887) * gtk/gtkfilechooserdefault.c (shortcuts_reload_icons): (shortcuts_insert_path): * gtk/gtkfilechooserbutton.c (change_icon_theme): (model_add_bookmarks): (model_update_current_folder): (update_label_and_image): If the bookmark points to a remote file, don't call get_info(), since that may a) take a long time and b) pop up an auth dialog. Instead, just use a folder icon and create a display name from the uri. * gtk/gtkfilechooserdefault.c (_gtk_file_chooser_label_for_uri): New function to create a suitable display name for a remote uri. This should really be done in GtkFileSystem.
Diffstat (limited to 'gtk/gtkfilechooserbutton.c')
-rw-r--r--gtk/gtkfilechooserbutton.c202
1 files changed, 157 insertions, 45 deletions
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index b99274f095..f00339f1ef 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -1290,23 +1290,34 @@ change_icon_theme (GtkFileChooserButton *button)
case ROW_TYPE_CURRENT_FOLDER:
if (data)
{
- GtkTreePath *path;
- GtkFileSystemHandle *handle;
- struct ChangeIconThemeData *info;
-
- info = g_new0 (struct ChangeIconThemeData, 1);
- info->button = g_object_ref (button);
- path = gtk_tree_model_get_path (priv->model, &iter);
- info->row_ref = gtk_tree_row_reference_new (priv->model, path);
- gtk_tree_path_free (path);
-
- handle =
- gtk_file_system_get_info (priv->fs, data, GTK_FILE_INFO_ICON,
- change_icon_theme_get_info_cb,
- info);
- button->priv->change_icon_theme_handles =
- g_slist_append (button->priv->change_icon_theme_handles, handle);
- pixbuf = NULL;
+ if (gtk_file_system_path_is_local (priv->fs, (GtkFilePath *)data))
+ {
+ GtkTreePath *path;
+ GtkFileSystemHandle *handle;
+ struct ChangeIconThemeData *info;
+
+ info = g_new0 (struct ChangeIconThemeData, 1);
+ info->button = g_object_ref (button);
+ path = gtk_tree_model_get_path (priv->model, &iter);
+ info->row_ref = gtk_tree_row_reference_new (priv->model, path);
+ gtk_tree_path_free (path);
+
+ handle =
+ gtk_file_system_get_info (priv->fs, data, GTK_FILE_INFO_ICON,
+ change_icon_theme_get_info_cb,
+ info);
+ button->priv->change_icon_theme_handles =
+ g_slist_append (button->priv->change_icon_theme_handles, handle);
+ pixbuf = NULL;
+ }
+ else
+ /* 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
+ * should use mime info to get a better icon.
+ */
+ pixbuf = gtk_icon_theme_load_icon (theme, "gnome-fs-regular",
+ priv->icon_size, 0, NULL);
}
else
pixbuf = gtk_icon_theme_load_icon (theme, FALLBACK_ICON_NAME,
@@ -1465,7 +1476,6 @@ set_info_for_path_at_iter (GtkFileChooserButton *button,
data = g_new0 (struct SetDisplayNameData, 1);
data->button = g_object_ref (button);
-
data->label = gtk_file_system_get_bookmark_label (button->priv->fs, path);
tree_path = gtk_tree_model_get_path (button->priv->model, iter);
@@ -1793,6 +1803,8 @@ model_add_volumes (GtkFileChooserButton *button,
}
}
+extern gchar * _gtk_file_chooser_label_for_uri (const gchar *uri);
+
static void
model_add_bookmarks (GtkFileChooserButton *button,
GSList *bookmarks)
@@ -1816,19 +1828,58 @@ model_add_bookmarks (GtkFileChooserButton *button,
path = l->data;
- if (local_only &&
- !gtk_file_system_path_is_local (button->priv->fs, path))
- continue;
+ if (gtk_file_system_path_is_local (button->priv->fs, path))
+ {
+ 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 (path),
+ IS_FOLDER_COLUMN, FALSE,
+ -1);
+ set_info_for_path_at_iter (button, path, &iter);
+ }
+ else
+ {
+ gchar *label;
+ GtkIconTheme *icon_theme;
+ GdkPixbuf *pixbuf;
+
+ 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
+ * should use mime info to get a better icon.
+ */
+ label = gtk_file_system_get_bookmark_label (button->priv->fs, path);
+ if (!label)
+ {
+ gchar *uri;
- 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 (path),
- IS_FOLDER_COLUMN, FALSE,
- -1);
- set_info_for_path_at_iter (button, path, &iter);
+ uri = gtk_file_system_path_to_uri (button->priv->fs, path);
+ label = _gtk_file_chooser_label_for_uri (uri);
+ g_free (uri);
+ }
+
+ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (button)));
+ pixbuf = gtk_icon_theme_load_icon (icon_theme, "gnome-fs-directory",
+ button->priv->icon_size, 0, NULL);
+
+ gtk_list_store_insert (store, &iter, pos);
+ gtk_list_store_set (store, &iter,
+ ICON_COLUMN, pixbuf,
+ DISPLAY_NAME_COLUMN, label,
+ TYPE_COLUMN, ROW_TYPE_BOOKMARK,
+ DATA_COLUMN, gtk_file_path_copy (path),
+ IS_FOLDER_COLUMN, TRUE,
+ -1);
+
+ g_free (label);
+ g_object_unref (pixbuf);
+ }
button->priv->n_bookmarks++;
pos++;
@@ -1890,14 +1941,53 @@ model_update_current_folder (GtkFileChooserButton *button,
model_free_row_data (button, &iter);
}
- gtk_list_store_set (store, &iter,
- ICON_COLUMN, NULL,
- DISPLAY_NAME_COLUMN, _(FALLBACK_DISPLAY_NAME),
- TYPE_COLUMN, ROW_TYPE_CURRENT_FOLDER,
- DATA_COLUMN, gtk_file_path_copy (path),
- IS_FOLDER_COLUMN, FALSE,
- -1);
- set_info_for_path_at_iter (button, path, &iter);
+ if (gtk_file_system_path_is_local (button->priv->fs, path))
+ {
+ gtk_list_store_set (store, &iter,
+ ICON_COLUMN, NULL,
+ DISPLAY_NAME_COLUMN, _(FALLBACK_DISPLAY_NAME),
+ TYPE_COLUMN, ROW_TYPE_CURRENT_FOLDER,
+ DATA_COLUMN, gtk_file_path_copy (path),
+ IS_FOLDER_COLUMN, FALSE,
+ -1);
+ set_info_for_path_at_iter (button, path, &iter);
+ }
+ else
+ {
+ gchar *label;
+ GtkIconTheme *icon_theme;
+ GdkPixbuf *pixbuf;
+
+ /* 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
+ * should use mime info to get a better icon.
+ */
+ label = gtk_file_system_get_bookmark_label (button->priv->fs, path);
+ if (!label)
+ {
+ gchar *uri;
+
+ uri = gtk_file_system_path_to_uri (button->priv->fs, path);
+ label = _gtk_file_chooser_label_for_uri (uri);
+ g_free (uri);
+ }
+
+ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (button)));
+ pixbuf = gtk_icon_theme_load_icon (icon_theme, "gnome-fs-directory",
+ button->priv->icon_size, 0, NULL);
+
+ gtk_list_store_set (store, &iter,
+ ICON_COLUMN, pixbuf,
+ DISPLAY_NAME_COLUMN, label,
+ TYPE_COLUMN, ROW_TYPE_CURRENT_FOLDER,
+ DATA_COLUMN, gtk_file_path_copy (path),
+ IS_FOLDER_COLUMN, TRUE,
+ -1);
+
+ g_free (label);
+ g_object_unref (pixbuf);
+ }
}
static inline void
@@ -2009,6 +2099,7 @@ filter_model_visible_func (GtkTreeModel *model,
break;
case ROW_TYPE_VOLUME:
{
+ retval = TRUE;
if (local_only)
{
if (gtk_file_system_volume_get_is_mounted (priv->fs, data))
@@ -2244,13 +2335,34 @@ update_label_and_image (GtkFileChooserButton *button)
}
if (priv->update_button_handle)
- gtk_file_system_cancel_operation (priv->update_button_handle);
-
- priv->update_button_handle =
- gtk_file_system_get_info (priv->fs, path,
- GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_ICON,
- update_label_get_info_cb,
- g_object_ref (button));
+ {
+ gtk_file_system_cancel_operation (priv->update_button_handle);
+ priv->upate_button_handle = NULL;
+ }
+
+ if (gtk_file_system_path_is_local (priv->fs, path))
+ {
+ priv->update_button_handle =
+ gtk_file_system_get_info (priv->fs, path,
+ GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_ICON,
+ update_label_get_info_cb,
+ g_object_ref (button));
+ }
+ else
+ {
+ GdkPixbuf *pixbuf;
+
+ label_text = gtk_file_system_get_bookmark_label (button->priv->fs, path);
+
+ pixbuf = gtk_icon_theme_load_icon (get_icon_theme (GTK_WIDGET (priv->image)),
+ "gnome-fs-regular",
+ priv->icon_size, 0, NULL);
+
+ gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
+
+ if (pixbuf)
+ g_object_unref (pixbuf);
+ }
}
out:
gtk_file_paths_free (paths);