From 6d05ff46d08c35d4e442f1f5c88c5abc9aef1273 Mon Sep 17 00:00:00 2001 From: Kristian Rietveld Date: Mon, 19 Dec 2005 19:43:32 +0000 Subject: [PATCH] add handle fields to ButtonData and GtkPathBar; do correct handle 2005-12-19 Kristian Rietveld * gtk/gtkpathbar.[ch]: add handle fields to ButtonData and GtkPathBar; do correct handle bookkeeping. * gtk/gtkfilesystemunix.c (load_folder), (gtk_file_system_unix_get_folder), (gtk_file_folder_unix_is_finished_loading): add is_finished_loading field to GtkFileFolderUnix, which is set to true once we are really finished with loading (previous assumption that we are always finshed loading is not true anymore). * gtk/gtkfilesystemmodel.c (got_root_folder_cb): if the folder is finished loading, list the children and update the root level. * gtk/gtkfilechooserdefault.c (update_current_folder_get_info_cb): handle cancellation. --- ChangeLog | 18 ++++++++ ChangeLog.pre-2-10 | 18 ++++++++ gtk/gtkfilechooserdefault.c | 8 ++++ gtk/gtkfilesystemmodel.c | 13 ++---- gtk/gtkfilesystemunix.c | 6 ++- gtk/gtkpathbar.c | 83 ++++++++++++++++++++++++++++--------- gtk/gtkpathbar.h | 2 + 7 files changed, 118 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index dfdd350d3e..2eb31698a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2005-12-19 Kristian Rietveld + + * gtk/gtkpathbar.[ch]: add handle fields to ButtonData and + GtkPathBar; do correct handle bookkeeping. + + * gtk/gtkfilesystemunix.c (load_folder), + (gtk_file_system_unix_get_folder), + (gtk_file_folder_unix_is_finished_loading): add is_finished_loading + field to GtkFileFolderUnix, which is set to true once we are + really finished with loading (previous assumption that we are + always finshed loading is not true anymore). + + * gtk/gtkfilesystemmodel.c (got_root_folder_cb): if the folder is + finished loading, list the children and update the root level. + + * gtk/gtkfilechooserdefault.c (update_current_folder_get_info_cb): + handle cancellation. + 2005-12-19 Kristian Rietveld * gtk/gtktreeview.c: small fix to make it actually work in this diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index dfdd350d3e..2eb31698a2 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,21 @@ +2005-12-19 Kristian Rietveld + + * gtk/gtkpathbar.[ch]: add handle fields to ButtonData and + GtkPathBar; do correct handle bookkeeping. + + * gtk/gtkfilesystemunix.c (load_folder), + (gtk_file_system_unix_get_folder), + (gtk_file_folder_unix_is_finished_loading): add is_finished_loading + field to GtkFileFolderUnix, which is set to true once we are + really finished with loading (previous assumption that we are + always finshed loading is not true anymore). + + * gtk/gtkfilesystemmodel.c (got_root_folder_cb): if the folder is + finished loading, list the children and update the root level. + + * gtk/gtkfilechooserdefault.c (update_current_folder_get_info_cb): + handle cancellation. + 2005-12-19 Kristian Rietveld * gtk/gtktreeview.c: small fix to make it actually work in this diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 43a6e7bccc..5ffe092827 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -5590,11 +5590,19 @@ update_current_folder_get_info_cb (GtkFileSystemHandle *handle, const GError *error, gpointer user_data) { + gboolean cancelled = handle->cancelled; struct UpdateCurrentFolderData *data = user_data; GtkFileChooserDefault *impl = data->impl; + if (handle != impl->update_current_folder_handle) + goto out; + + g_object_unref (handle); impl->update_current_folder_handle = NULL; + if (cancelled) + goto out; + if (error) { error_changing_folder_dialog (impl, data->path, g_error_copy (error)); diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c index f048f34aef..df7ae67740 100644 --- a/gtk/gtkfilesystemmodel.c +++ b/gtk/gtkfilesystemmodel.c @@ -672,18 +672,13 @@ got_root_folder_cb (GtkFileSystemHandle *handle, if (!folder) return; -#if 0 - if (!gtk_file_folder_list_children (root_folder, &roots, error)) - { - g_object_unref (folder); - return; - } -#endif - model->root_folder = folder; if (gtk_file_folder_is_finished_loading (model->root_folder)) - queue_finished_loading (model); /* done in an idle because we are being created */ + { + queue_finished_loading (model); /* done in an idle because we are being created */ + gtk_file_folder_list_children (model->root_folder, &roots, NULL); + } else g_signal_connect_object (model->root_folder, "finished-loading", G_CALLBACK (root_folder_finished_loading_cb), model, 0); diff --git a/gtk/gtkfilesystemunix.c b/gtk/gtkfilesystemunix.c index ff69585933..e2f7b0986f 100644 --- a/gtk/gtkfilesystemunix.c +++ b/gtk/gtkfilesystemunix.c @@ -115,6 +115,7 @@ struct _GtkFileFolderUnix guint have_mime_type : 1; guint is_network_dir : 1; guint have_hidden : 1; + guint is_finished_loading : 1; time_t asof; }; @@ -787,6 +788,7 @@ load_folder (gpointer data) if (gtk_file_folder_unix_list_children (GTK_FILE_FOLDER (folder_unix), &children, NULL)) { + folder_unix->is_finished_loading = TRUE; g_signal_emit_by_name (folder_unix, "files-added", children); gtk_file_paths_free (children); } @@ -899,6 +901,7 @@ gtk_file_system_unix_get_folder (GtkFileSystem *file_system, folder_unix->have_mime_type = FALSE; folder_unix->have_stat = FALSE; folder_unix->have_hidden = FALSE; + folder_unix->is_finished_loading = FALSE; set_asof = TRUE; if ((system_unix->have_afs && @@ -2524,8 +2527,7 @@ gtk_file_folder_unix_list_children (GtkFileFolder *folder, static gboolean gtk_file_folder_unix_is_finished_loading (GtkFileFolder *folder) { - /* Since we don't do asynchronous loads, we are always finished loading */ - return TRUE; + return GTK_FILE_FOLDER_UNIX (folder)->is_finished_loading; } static void diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c index da4ee002e6..4fc916c558 100644 --- a/gtk/gtkpathbar.c +++ b/gtk/gtkpathbar.c @@ -65,6 +65,7 @@ struct _ButtonData GtkFilePath *path; GtkWidget *image; GtkWidget *label; + GtkFileSystemHandle *handle; guint ignore_changes : 1; guint file_is_hidden : 1; }; @@ -140,6 +141,8 @@ gtk_path_bar_init (GtkPathBar *path_bar) GTK_WIDGET_SET_FLAGS (path_bar, GTK_NO_WINDOW); gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE); + path_bar->set_path_handle = NULL; + path_bar->spacing = 3; path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT); path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT); @@ -207,6 +210,10 @@ gtk_path_bar_finalize (GObject *object) gtk_path_bar_stop_scrolling (path_bar); + if (path_bar->set_path_handle) + gtk_file_system_cancel_operation (path_bar->set_path_handle); + path_bar->set_path_handle = NULL; + g_list_free (path_bar->button_list); if (path_bar->root_path) gtk_file_path_free (path_bar->root_path); @@ -993,14 +1000,18 @@ set_button_image_get_info_cb (GtkFileSystemHandle *handle, const GError *error, gpointer user_data) { + gboolean cancelled = handle->cancelled; GdkPixbuf *pixbuf; struct SetButtonImageData *data = user_data; - if (error) - { - g_free (data); - return; - } + if (handle != data->button_data->handle) + goto out; + + g_object_unref (handle); + data->button_data->handle = NULL; + + if (cancelled || error) + goto out; pixbuf = gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar), data->path_bar->icon_size, NULL); @@ -1026,6 +1037,7 @@ set_button_image_get_info_cb (GtkFileSystemHandle *handle, break; }; +out: g_free (data); } @@ -1071,11 +1083,15 @@ set_button_image (GtkPathBar *path_bar, data->path_bar = path_bar; data->button_data = button_data; - gtk_file_system_get_info (path_bar->file_system, - path_bar->home_path, - GTK_FILE_INFO_ICON, - set_button_image_get_info_cb, - data); + if (button_data->handle) + gtk_file_system_cancel_operation (button_data->handle); + + button_data->handle = + gtk_file_system_get_info (path_bar->file_system, + path_bar->home_path, + GTK_FILE_INFO_ICON, + set_button_image_get_info_cb, + data); break; case DESKTOP_BUTTON: @@ -1089,11 +1105,15 @@ set_button_image (GtkPathBar *path_bar, data->path_bar = path_bar; data->button_data = button_data; - gtk_file_system_get_info (path_bar->file_system, - path_bar->desktop_path, - GTK_FILE_INFO_ICON, - set_button_image_get_info_cb, - data); + if (button_data->handle) + gtk_file_system_cancel_operation (button_data->handle); + + button_data->handle = + gtk_file_system_get_info (path_bar->file_system, + path_bar->desktop_path, + GTK_FILE_INFO_ICON, + set_button_image_get_info_cb, + data); break; default: break; @@ -1103,6 +1123,9 @@ set_button_image (GtkPathBar *path_bar, static void button_data_free (ButtonData *button_data) { + if (button_data->handle) + gtk_file_system_cancel_operation (button_data->handle); + gtk_file_path_free (button_data->path); g_free (button_data->dir_name); g_free (button_data); @@ -1420,14 +1443,23 @@ gtk_path_bar_get_info_callback (GtkFileSystemHandle *handle, const GError *error, gpointer data) { + gboolean cancelled = handle->cancelled; struct SetPathInfo *path_info = data; - ButtonData *button_data; const gchar *display_name; gboolean is_hidden; gboolean valid; - if (!file_info) + if (handle != path_info->path_bar->set_path_handle) + { + gtk_path_bar_set_path_finish (path_info, FALSE); + return; + } + + g_object_unref (handle); + path_info->path_bar->set_path_handle = NULL; + + if (cancelled || !file_info) { gtk_path_bar_set_path_finish (path_info, FALSE); return; @@ -1467,7 +1499,12 @@ gtk_path_bar_get_info_callback (GtkFileSystemHandle *handle, return; } - gtk_file_system_get_info (handle->file_system, path_info->path, GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_HIDDEN, gtk_path_bar_get_info_callback, path_info); + path_info->path_bar->set_path_handle = + gtk_file_system_get_info (handle->file_system, + path_info->path, + GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_HIDDEN, + gtk_path_bar_get_info_callback, + path_info); } gboolean @@ -1505,7 +1542,15 @@ _gtk_path_bar_set_path (GtkPathBar *path_bar, return result; } - gtk_file_system_get_info (path_bar->file_system, info->path, GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_HIDDEN, gtk_path_bar_get_info_callback, info); + if (path_bar->set_path_handle) + gtk_file_system_cancel_operation (path_bar->set_path_handle); + + path_bar->set_path_handle = + gtk_file_system_get_info (path_bar->file_system, + info->path, + GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_HIDDEN, + gtk_path_bar_get_info_callback, + info); return TRUE; } diff --git a/gtk/gtkpathbar.h b/gtk/gtkpathbar.h index e395ccc0b0..9474427b59 100644 --- a/gtk/gtkpathbar.h +++ b/gtk/gtkpathbar.h @@ -45,6 +45,8 @@ struct _GtkPathBar GtkFilePath *home_path; GtkFilePath *desktop_path; + GtkFileSystemHandle *set_path_handle; + GdkPixbuf *root_icon; GdkPixbuf *home_icon; GdkPixbuf *desktop_icon;