From 19e30d41a545e0a71060234e3ffc40282bf5fc25 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 8 May 2007 18:01:13 +0100 Subject: Get file and folder informations for the recent files list items Use GtkFileSystem API to get informations on each item inside the recent files list when in OPERATION_MODE_RECENT. Retrieve whether the recent item is a folder and follow the link into OPERATION_MODE_BROWSE if the item is activated by the user. Signed-off-by: Emmanuele Bassi --- gtk/gtkfilechooserdefault.c | 113 ++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 105 insertions(+), 8 deletions(-) diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index db1101d..f699e48 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -221,6 +221,8 @@ enum { RECENT_MODEL_COL_PATH, RECENT_MODEL_COL_DISPLAY_NAME, RECENT_MODEL_COL_INFO, + RECENT_MODEL_COL_IS_FOLDER, + RECENT_MODEL_COL_HANDLE, RECENT_MODEL_COL_NUM_COLUMNS }; @@ -7273,9 +7275,9 @@ gtk_file_chooser_default_get_paths (GtkFileChooser *chooser) goto file_entry; else { - /* The focus is on a dialog's action area button or something else */ - if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE - || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) + /* The focus is on a dialog's action area button or something else */ + if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE || + impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) goto file_entry; else goto file_list; @@ -9054,14 +9056,19 @@ recent_clear_model (GtkFileChooserDefault *impl, do { GtkFilePath *file_path; + GtkFileSystemHandle *handle; GtkRecentInfo *recent_info; gchar *display_name; gtk_tree_model_get (model, &iter, RECENT_MODEL_COL_DISPLAY_NAME, &display_name, RECENT_MODEL_COL_PATH, &file_path, + RECENT_MODEL_COL_HANDLE, &handle, RECENT_MODEL_COL_INFO, &recent_info, -1); + + if (handle) + gtk_file_system_cancel_operation (handle); gtk_file_path_free (file_path); gtk_recent_info_unref (recent_info); @@ -9152,6 +9159,9 @@ recent_setup_model (GtkFileChooserDefault *impl) * stored as a pointer and not as a G_TYPE_STRING; * RECENT_MODEL_COL_INFO - GtkRecentInfo, stored as a pointer and not * as a GTK_TYPE_RECENT_INFO; + * RECENT_MODEL_COL_IS_FOLDER - boolean flag; + * RECENT_MODEL_COL_HANDLE - GtkFileSystemHandle, stored as a pointer + * and not as a GTK_TYPE_FILE_SYSTEM_HANDLE; * * Keep this in sync with the enumeration defined near the beginning of * this file. @@ -9159,7 +9169,9 @@ recent_setup_model (GtkFileChooserDefault *impl) impl->recent_model = gtk_list_store_new (RECENT_MODEL_COL_NUM_COLUMNS, G_TYPE_POINTER, G_TYPE_POINTER, - G_TYPE_POINTER); + G_TYPE_POINTER, + G_TYPE_BOOLEAN, + G_TYPE_POINTER); gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model), RECENT_MODEL_COL_INFO, @@ -9201,15 +9213,80 @@ recent_idle_cleanup (gpointer data) g_free (load_data); } +struct RecentItemInsertRequest +{ + GtkFileChooserDefault *impl; + GtkFilePath *path; + GtkTreeRowReference *row_ref; +}; + +static void +recent_item_get_info_cb (GtkFileSystemHandle *handle, + const GtkFileInfo *info, + const GError *error, + gpointer data) +{ + gboolean cancelled = handle->cancelled; + GtkTreePath *path; + GtkTreeIter iter; + GtkFileSystemHandle *model_handle; + gboolean is_folder = FALSE; + struct RecentItemInsertRequest *request = data; + + path = gtk_tree_row_reference_get_path (request->row_ref); + if (!path) + goto out; + + gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->recent_model), + &iter, path); + gtk_tree_path_free (path); + + gtk_tree_model_get (GTK_TREE_MODEL (request->impl->recent_model), &iter, + RECENT_MODEL_COL_HANDLE, &model_handle, + -1); + if (handle != model_handle) + goto out; + + gtk_list_store_set (request->impl->recent_model, &iter, + RECENT_MODEL_COL_HANDLE, NULL, + -1); + + if (cancelled) + goto out; + + if (!info) + { + gtk_list_store_remove (request->impl->recent_model, &iter); + goto out; + } + + is_folder = gtk_file_info_get_is_folder (info); + + gtk_list_store_set (request->impl->recent_model, &iter, + RECENT_MODEL_COL_IS_FOLDER, is_folder, + -1); + +out: + g_object_unref (request->impl); + gtk_file_path_free (request->path); + gtk_tree_row_reference_free (request->row_ref); + g_free (request); + + g_object_unref (handle); +} + static gboolean recent_idle_load (gpointer data) { RecentLoadData *load_data = data; GtkFileChooserDefault *impl = load_data->impl; GtkTreeIter iter; + GtkTreePath *p; GtkRecentInfo *info; const gchar *uri, *display_name; GtkFilePath *path; + GtkFileSystemHandle *handle; + struct RecentItemInsertRequest *request; if (!impl->recent_manager) return FALSE; @@ -9229,14 +9306,32 @@ recent_idle_load (gpointer data) uri = gtk_recent_info_get_uri (info); display_name = gtk_recent_info_get_display_name (info); path = gtk_file_system_uri_to_path (impl->file_system, uri); + if (!path) + goto load_next; gtk_list_store_append (impl->recent_model, &iter); + p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->recent_model), &iter); + + request = g_new0 (struct RecentItemInsertRequest, 1); + request->impl = g_object_ref (impl); + request->path = gtk_file_path_copy (path); + request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->recent_model), p); + gtk_tree_path_free (p); + + handle = gtk_file_system_get_info (impl->file_system, path, + GTK_FILE_INFO_IS_FOLDER, + recent_item_get_info_cb, + request); + gtk_list_store_set (impl->recent_model, &iter, RECENT_MODEL_COL_PATH, path, RECENT_MODEL_COL_DISPLAY_NAME, g_strdup (display_name), RECENT_MODEL_COL_INFO, gtk_recent_info_ref (info), + RECENT_MODEL_COL_HANDLE, handle, -1); +load_next: + load_data->n_loaded_items += 1; /* finished loading items */ @@ -9847,22 +9942,24 @@ list_row_activated (GtkTreeView *tree_view, case OPERATION_MODE_RECENT: { + GtkFilePath *file_path; + gboolean is_folder; + if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_model), &iter, path)) return; -#if 0 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &iter, RECENT_MODEL_COL_PATH, &file_path, - RECENT_MODEL_COL_MIME_TYPE, &mime_type, + RECENT_MODEL_COL_IS_FOLDER, &is_folder, -1); - if (strcmp (mime_type, "inode/x-folder") == 0) + if (is_folder) { change_folder_and_display_error (impl, file_path, FALSE); recent_switch_to_browse_mode (impl); return; } -#endif + g_signal_emit_by_name (impl, "file-activated"); } break; -- 1.4.4.2