From 4e98233a4d7f8e06736b716c92a04f7e0709e16e Mon Sep 17 00:00:00 2001 From: Ettore Perazzoli Date: Wed, 24 Jan 2001 00:56:21 +0000 Subject: Fix the logic for updating the shortuct labels when the display names of the corresponding folders change, so that it doesn't crash. I have removed the redundant "folder_updated" signal on `ELocalStorage' and changed EStorage so that it emits "updated_folder" automatically when any of the folders changes its properties. svn path=/trunk/; revision=7770 --- shell/e-folder-tree.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'shell/e-folder-tree.c') diff --git a/shell/e-folder-tree.c b/shell/e-folder-tree.c index 9962fa508f..a3f5d661ee 100644 --- a/shell/e-folder-tree.c +++ b/shell/e-folder-tree.c @@ -41,6 +41,7 @@ typedef struct _Folder Folder; struct _EFolderTree { GHashTable *path_to_folder; + GHashTable *data_to_path; EFolderDestroyNotify folder_destroy_notify; void *folder_destroy_notify_closure; @@ -149,6 +150,7 @@ remove_folder (EFolderTree *folder_tree, } g_hash_table_remove (folder_tree->path_to_folder, folder->path); + g_hash_table_remove (folder_tree->data_to_path, folder->data); if (folder_tree->folder_destroy_notify != NULL) (* folder_tree->folder_destroy_notify) (folder_tree, @@ -182,9 +184,11 @@ e_folder_tree_new (EFolderDestroyNotify folder_destroy_notify, new->folder_destroy_notify_closure = closure; new->path_to_folder = g_hash_table_new (g_str_hash, g_str_equal); + new->data_to_path = g_hash_table_new (g_direct_hash, g_direct_equal); root_folder = folder_new (G_DIR_SEPARATOR_S, NULL); g_hash_table_insert (new->path_to_folder, root_folder->path, root_folder); + g_hash_table_insert (new->data_to_path, root_folder->data, root_folder->path); return new; } @@ -206,6 +210,7 @@ e_folder_tree_destroy (EFolderTree *folder_tree) remove_folder (folder_tree, root_folder); g_hash_table_destroy (folder_tree->path_to_folder); + g_hash_table_destroy (folder_tree->data_to_path); g_free (folder_tree); } @@ -227,6 +232,7 @@ e_folder_tree_add (EFolderTree *folder_tree, { Folder *parent_folder; Folder *folder; + const char *existing_path; char *parent_path; g_return_val_if_fail (folder_tree != NULL, FALSE); @@ -249,10 +255,18 @@ e_folder_tree_add (EFolderTree *folder_tree, return FALSE; } + existing_path = g_hash_table_lookup (folder_tree->data_to_path, data); + if (existing_path != NULL) { + g_warning ("%s: Trying to add a folder with duplicate data -- %s", + __FUNCTION__, path); + return FALSE; + } + folder = folder_new (path, data); folder_add_subfolder (parent_folder, folder); g_hash_table_insert (folder_tree->path_to_folder, folder->path, folder); + g_hash_table_insert (folder_tree->data_to_path, data, folder->path); g_free (parent_path); @@ -378,3 +392,23 @@ e_folder_tree_foreach (EFolderTree *folder_tree, traverse_subtree (folder_tree, root_node, foreach_func, data); } + + +/** + * e_folder_tree_get_path_for_data: + * @folder_tree: A pointer to an EFolderTree + * @data: The data for the folder for which the path is needed + * + * Look up the path for the specified @data. + * + * Return value: The path for the folder that holds that @data. + **/ +const char * +e_folder_tree_get_path_for_data (EFolderTree *folder_tree, + const void *data) +{ + g_return_val_if_fail (folder_tree != NULL, NULL); + g_return_val_if_fail (data != NULL, NULL); + + return (const char *) g_hash_table_lookup (folder_tree->data_to_path, data); +} -- cgit v1.2.3