From 7ac8a9c5e8bc272a75bed0c2509b525b907753ba Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 15 Feb 2001 23:54:16 +0000 Subject: Use mail_storage_create_folder 2001-02-15 Jeffrey Stedfast * mail-ops.c (do_scan_subfolders): Use mail_storage_create_folder * mail-callbacks.c (mail_storage_create_folder): Convenience function so we can keep all the evolution_storage_add_new_folder() code in one place as much as possible. * subscribe-dialog.c (recursive_add_folder): Use 'name' rather than the no-description bs since that's what all the other places do. * mail-callbacks.c (folder_created): New callback to handle the "folder_created" signal - handles CamelFolderInfo's recursively. (folder_deleted): Same but for "folder_deleted". * component-factory.c (storage_create_folder): Instead of doing the evolution_storage_new_folder() stuff by hand, pass it off to the new callback: folder_created(). At some point this will be unecessary as we'll attach this callback to the "folder_created" signal. svn path=/trunk/; revision=8247 --- mail/mail-callbacks.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'mail/mail-callbacks.c') diff --git a/mail/mail-callbacks.c b/mail/mail-callbacks.c index e166871550..f4fa4f06cd 100644 --- a/mail/mail-callbacks.c +++ b/mail/mail-callbacks.c @@ -1334,3 +1334,90 @@ stop_threads(BonoboUIComponent *uih, void *user_data, const char *path) camel_operation_cancel(NULL); } + +static void +create_folders (EvolutionStorage *storage, CamelFolderInfo *fi) +{ + char *name, *path; + + if (fi->unread_message_count > 0) + name = g_strdup_printf ("%s (%d)", fi->name, + fi->unread_message_count); + else + name = g_strdup (fi->name); + + path = g_strdup_printf ("/%s", fi->full_name); + evolution_storage_new_folder (storage, path, name, + "mail", fi->url ? fi->url : "", + fi->name, /* description */ + fi->unread_message_count > 0); + g_free (name); + g_free (path); + + if (fi->child) + create_folders (storage, fi->child); + + if (fi->sibling) + create_folders (storage, fi->sibling); +} + +void +folder_created (CamelStore *store, CamelFolderInfo *fi) +{ + EvolutionStorage *storage; + + if ((storage = mail_lookup_storage (store))) { + if (fi) + create_folders (storage, fi); + + gtk_object_unref (GTK_OBJECT (storage)); + } +} + +void +mail_storage_create_folder (EvolutionStorage *storage, CamelStore *store, CamelFolderInfo *fi) +{ + gboolean unref = FALSE; + + if (!storage && store) { + storage = mail_lookup_storage (store); + unref = TRUE; + } + + if (storage) { + if (fi) + create_folders (storage, fi); + + if (unref) + gtk_object_unref (GTK_OBJECT (storage)); + } +} + +static void +delete_folders (EvolutionStorage *storage, CamelFolderInfo *fi) +{ + char *path; + + if (fi->child) + delete_folders (storage, fi->child); + + path = g_strdup_printf ("/%s", fi->full_name); + evolution_storage_removed_folder (storage, path); + g_free (path); + + if (fi->sibling) + delete_folders (storage, fi->sibling); +} + +void +folder_deleted (CamelStore *store, CamelFolderInfo *fi) +{ + EvolutionStorage *storage; + + if ((storage = mail_lookup_storage (store))) { + if (fi) + delete_folders (storage, fi); + + gtk_object_unref (GTK_OBJECT (storage)); + } +} -- cgit v1.2.3