From dcec12da938bc94ac09d0aad5632bedc39cd96b7 Mon Sep 17 00:00:00 2001 From: Kristian Rietveld Date: Tue, 13 Dec 2005 16:12:15 +0000 Subject: [PATCH] replace gtk_file_system_render_icon() call with 2005-12-13 Kristian Rietveld * gtk/gtkfilechooserdefault.c (get_file_info_finished), (shortcuts_insert_path): replace gtk_file_system_render_icon() call with gtk_file_system_get_file_info(), (gtk_file_chooser_default_add_shortcut_folder), (gtk_file_chooser_default_remove_shortcut_folder): handle shortcuts which are still loading. * gtk/gtkfilechooserprivate.h: add shortcuts_loading field to struct _GtkFileChooserDefault. * gtk/gtkfilechooserbutton.c (set_info_get_info_cb), (set_info_for_path_at_iter), (model_free_row_data): keep handle and path together; now supports adding/removing shortcuts which are still loading. --- ChangeLog | 17 ++++++++++ ChangeLog.pre-2-10 | 17 ++++++++++ gtk/gtkfilechooserbutton.c | 24 +++++++++++--- gtk/gtkfilechooserdefault.c | 66 +++++++++++++++++++++++++++++++++---- gtk/gtkfilechooserprivate.h | 1 + 5 files changed, 114 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 775058ebc6..37964368c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2005-12-13 Kristian Rietveld + + * gtk/gtkfilechooserdefault.c (get_file_info_finished), + (shortcuts_insert_path): replace gtk_file_system_render_icon() call + with gtk_file_system_get_file_info(), + (gtk_file_chooser_default_add_shortcut_folder), + (gtk_file_chooser_default_remove_shortcut_folder): handle shortcuts + which are still loading. + + * gtk/gtkfilechooserprivate.h: add shortcuts_loading field to + struct _GtkFileChooserDefault. + + * gtk/gtkfilechooserbutton.c (set_info_get_info_cb), + (set_info_for_path_at_iter), (model_free_row_data): keep handle + and path together; now supports adding/removing shortcuts + which are still loading. + 2005-12-13 Kristian Rietveld * gtk/gtkfilesystem.c: make the cancelled field an GObject property. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 775058ebc6..37964368c6 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,20 @@ +2005-12-13 Kristian Rietveld + + * gtk/gtkfilechooserdefault.c (get_file_info_finished), + (shortcuts_insert_path): replace gtk_file_system_render_icon() call + with gtk_file_system_get_file_info(), + (gtk_file_chooser_default_add_shortcut_folder), + (gtk_file_chooser_default_remove_shortcut_folder): handle shortcuts + which are still loading. + + * gtk/gtkfilechooserprivate.h: add shortcuts_loading field to + struct _GtkFileChooserDefault. + + * gtk/gtkfilechooserbutton.c (set_info_get_info_cb), + (set_info_for_path_at_iter), (model_free_row_data): keep handle + and path together; now supports adding/removing shortcuts + which are still loading. + 2005-12-13 Kristian Rietveld * gtk/gtkfilesystem.c: make the cancelled field an GObject property. diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c index 65e435ca6d..1bef33a4fd 100644 --- a/gtk/gtkfilechooserbutton.c +++ b/gtk/gtkfilechooserbutton.c @@ -95,6 +95,7 @@ enum TYPE_COLUMN, DATA_COLUMN, IS_FOLDER_COLUMN, + HANDLE_COLUMN, NUM_COLUMNS }; @@ -452,7 +453,8 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button) G_TYPE_STRING, /* Display Name */ G_TYPE_CHAR, /* Row Type */ G_TYPE_POINTER /* Volume || Path */, - G_TYPE_BOOLEAN /* Is Folder? */)); + G_TYPE_BOOLEAN /* Is Folder? */, + G_TYPE_OBJECT /* handle */)); priv->combo_box = gtk_combo_box_new (); priv->combo_box_changed_id = @@ -1294,6 +1296,10 @@ set_info_get_info_cb (GtkFileSystemHandle *handle, GdkPixbuf *pixbuf; struct SetDisplayNameData *data = callback_data; + gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &data->iter, + HANDLE_COLUMN, NULL, + -1); + if (error) { /* There was an error, leave the fallback name in there */ @@ -1322,14 +1328,19 @@ set_info_for_path_at_iter (GtkFileChooserButton *button, GtkTreeIter *iter) { struct SetDisplayNameData *data; + GtkFileSystemHandle *handle; data = g_new0 (struct SetDisplayNameData, 1); data->button = button; data->iter = *iter; - gtk_file_system_get_info (button->priv->fs, path, - GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_FOLDER | GTK_FILE_INFO_ICON, - set_info_get_info_cb, data); + handle = gtk_file_system_get_info (button->priv->fs, path, + GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_FOLDER | GTK_FILE_INFO_ICON, + set_info_get_info_cb, data); + + gtk_list_store_set (GTK_LIST_STORE (button->priv->model), &data->iter, + HANDLE_COLUMN, handle, + -1); } /* Shortcuts Model */ @@ -1392,12 +1403,17 @@ model_free_row_data (GtkFileChooserButton *button, { gchar type; gpointer data; + GtkFileSystemHandle *handle; gtk_tree_model_get (button->priv->model, iter, TYPE_COLUMN, &type, DATA_COLUMN, &data, + HANDLE_COLUMN, &handle, -1); + if (handle) + gtk_file_system_cancel_operation (handle); + switch (type) { case ROW_TYPE_SPECIAL: diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index cff0cbb116..0f03476763 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -1275,7 +1275,6 @@ get_file_info_finished (GtkFileSystemHandle *handle, const GError *error, gpointer data) { - gpointer item_data; gboolean is_volume = FALSE; GdkPixbuf *pixbuf; GtkTreePath *path; @@ -1290,8 +1289,6 @@ get_file_info_finished (GtkFileSystemHandle *handle, pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (request->impl), request->impl->icon_size, NULL); - item_data = gtk_file_path_copy (request->path); - path = gtk_tree_row_reference_get_path (request->row_ref); gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->shortcuts_model), &iter, path); @@ -1301,7 +1298,6 @@ get_file_info_finished (GtkFileSystemHandle *handle, SHORTCUTS_COL_PIXBUF, pixbuf, SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE, SHORTCUTS_COL_NAME, request->label_copy, - SHORTCUTS_COL_DATA, item_data, SHORTCUTS_COL_IS_VOLUME, is_volume, SHORTCUTS_COL_REMOVABLE, request->removable, -1); @@ -1310,6 +1306,8 @@ get_file_info_finished (GtkFileSystemHandle *handle, request->impl->loading_bookmarks = g_slist_remove (request->impl->loading_bookmarks, handle); else if (request->type == SHORTCUTS_VOLUMES) request->impl->loading_volumes = g_slist_remove (request->impl->loading_volumes, handle); + else if (request->type == SHORTCUTS_SHORTCUTS) + request->impl->loading_shortcuts = g_slist_remove (request->impl->loading_shortcuts, handle); if (request->impl->shortcuts_filter_model) gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (request->impl->shortcuts_filter_model)); @@ -1348,6 +1346,8 @@ shortcuts_update_count (GtkFileChooserDefault *impl, case SHORTCUTS_SHORTCUTS: impl->num_shortcuts++; + if (handle) + impl->loading_shortcuts = g_slist_append (impl->loading_shortcuts, handle); break; case SHORTCUTS_BOOKMARKS: @@ -1415,6 +1415,11 @@ shortcuts_insert_path (GtkFileChooserDefault *impl, else gtk_list_store_insert (impl->shortcuts_model, &iter, pos); + gtk_list_store_set (impl->shortcuts_model, &iter, + SHORTCUTS_COL_DATA, gtk_file_path_copy (path), + SHORTCUTS_COL_IS_VOLUME, is_volume, + -1); + p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter); request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->shortcuts_model), p); gtk_tree_path_free (p); @@ -6152,6 +6157,8 @@ add_shortcut_get_info_cb (GtkFileSystemHandle *handle, int pos; struct AddShortcutData *data = user_data; + data->impl->loading_shortcuts = g_slist_remove (data->impl->loading_shortcuts, handle); + if (error || !gtk_file_info_get_is_folder (info)) goto out; @@ -6169,8 +6176,10 @@ gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser, const GtkFilePath *path, GError **error) { + GtkFileSystemHandle *handle; GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser); struct AddShortcutData *data; + GSList *l; int pos; /* Avoid adding duplicates */ @@ -6190,12 +6199,41 @@ gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser, return FALSE; } + for (l = impl->loading_shortcuts; l; l = l->next) + { + GtkFileSystemHandle *h = l->data; + GtkFilePath *p; + + p = g_object_get_data (G_OBJECT (h), "add-shortcut-path-key"); + if (p && !gtk_file_path_compare (path, p)) + { + gchar *uri; + + uri = gtk_file_system_path_to_uri (impl->file_system, path); + g_set_error (error, + GTK_FILE_CHOOSER_ERROR, + GTK_FILE_CHOOSER_ERROR_ALREADY_EXISTS, + _("shortcut %s already exists"), + uri); + g_free (uri); + + return FALSE; + } + } + data = g_new0 (struct AddShortcutData, 1); data->impl = impl; data->path = gtk_file_path_copy (path); - gtk_file_system_get_info (impl->file_system, path, GTK_FILE_INFO_IS_FOLDER, - add_shortcut_get_info_cb, data); + handle = gtk_file_system_get_info (impl->file_system, path, + GTK_FILE_INFO_IS_FOLDER, + add_shortcut_get_info_cb, data); + + if (!handle) + return FALSE; + + impl->loading_shortcuts = g_slist_append (impl->loading_shortcuts, handle); + g_object_set_data (G_OBJECT (handle), "add-shortcut-path-key", data->path); return TRUE; } @@ -6208,9 +6246,24 @@ gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser, GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser); int pos; GtkTreeIter iter; + GSList *l; char *uri; int i; + for (l = impl->loading_shortcuts; l; l = l->next) + { + GtkFileSystemHandle *h = l->data; + GtkFilePath *p; + + p = g_object_get_data (G_OBJECT (h), "add-shortcut-path-key"); + if (p && !gtk_file_path_compare (path, p)) + { + impl->loading_shortcuts = g_slist_remove (impl->loading_shortcuts, h); + gtk_file_system_cancel_operation (h); + return TRUE; + } + } + if (impl->num_shortcuts == 0) goto out; @@ -6228,7 +6281,6 @@ gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser, SHORTCUTS_COL_DATA, &col_data, SHORTCUTS_COL_IS_VOLUME, &is_volume, -1); - /* FIXME: this assert is triggered if the thing is still loading */ g_assert (col_data != NULL); g_assert (!is_volume); diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h index 0c0f93fea5..27d762afe8 100644 --- a/gtk/gtkfilechooserprivate.h +++ b/gtk/gtkfilechooserprivate.h @@ -187,6 +187,7 @@ struct _GtkFileChooserDefault GSList *loading_volumes; GSList *loading_bookmarks; + GSList *loading_shortcuts; GtkTreeModelSort *sort_model;