From 50e6527820f4921e5648d38a712bfc43e1d3f835 Mon Sep 17 00:00:00 2001 From: Iain Holmes Date: Wed, 8 May 2002 14:29:05 +0000 Subject: Change so there's no race conditions between the folder info and the session stuff svn path=/trunk/; revision=16723 --- mail/ChangeLog | 15 +++++ mail/component-factory.c | 3 + mail/folder-info.c | 145 +++++++++++++++++++++++++++++++++-------------- 3 files changed, 119 insertions(+), 44 deletions(-) diff --git a/mail/ChangeLog b/mail/ChangeLog index a412c3dfe2..83e8b92d66 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,18 @@ +2002-05-08 Iain Holmes + + * component-factory.c (owner_set_cb): Tell the folder info listeners + that they're ready. + + * folder-info.c: Add a property bag to the CORBAObject. + (do_get_info): Remove a load of cruft. Add some error checks. + (do_free_info): Unref the listener. + (destroy): Unref the propertybag. + (set_prop): Set the property. + (get_prop): Get the property. + (evolution_folder_info_factory_fn): Create a propertybag. + (evolution_folder_info_notify_ready): Notify all the listeners that + the folder info is ready for querying. + 2002-05-08 Not Zed * mail-autofilter.c (mail_filter_rename_uri): Changed for diff --git a/mail/component-factory.c b/mail/component-factory.c index 05e3bef466..8559898510 100644 --- a/mail/component-factory.c +++ b/mail/component-factory.c @@ -769,6 +769,9 @@ owner_set_cb (EvolutionShellComponent *shell_component, gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); gtk_widget_show (dialog); } + + /* Everything should be ready now */ + evolution_folder_info_notify_ready (); } static void diff --git a/mail/folder-info.c b/mail/folder-info.c index b916f2fb16..87ca367dac 100644 --- a/mail/folder-info.c +++ b/mail/folder-info.c @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -32,11 +33,15 @@ #define PARENT_TYPE BONOBO_X_OBJECT_TYPE static BonoboObjectClass *parent_class = NULL; +static GSList *folder_infos; + typedef struct _EvolutionFolderInfo EvolutionFolderInfo; typedef struct _EvolutionFolderInfoClass EvolutionFolderInfoClass; struct _EvolutionFolderInfo { BonoboXObject parent; + + BonoboPropertyBag *pb; }; struct _EvolutionFolderInfoClass { @@ -57,6 +62,7 @@ struct _folder_info_msg { }; static GtkType evolution_folder_info_get_type (void); +gboolean ready; static char * do_describe_info (struct _mail_msg *mm, gint complete) @@ -70,47 +76,6 @@ do_get_info (struct _mail_msg *mm) struct _folder_info_msg *m = (struct _folder_info_msg *) mm; CamelFolder *folder; CamelException *ex; -#if 0 - char *uri_dup; - char *foldername, *start, *end; - char *storage, *protocol, *uri; - /* Fixme: Do other stuff. Different stuff to the stuff below */ - uri_dup = g_strdup (m->foldername); - start = uri_dup + 11; - g_warning ("Start: %s", start); - - end = strrchr (start, '/'); - if (end == NULL) { - g_warning ("Bugger"); - return; - } - - storage = g_strndup (start, end - start); - start = end + 1; - foldername = g_strdup (start); - - g_free (uri_dup); - - /* Work out the protocol. - The storage is going to start as local, or vfolder, or an imap - server. */ - g_warning ("Storage: %s", storage); - if (strncmp (storage, "local", 5) == 0) { - char *evolution_dir; - char *proto; - - evolution_dir = gnome_util_prepend_user_home ("evolution/local"); - proto = g_strconcat ("file://", evolution_dir, NULL); - uri = e_path_to_physical (proto, foldername); - g_free (evolution_dir); - g_free (proto); - - } else if (strncmp (storage, "vfolder", 7) == 0) { - uri = g_strconcat ("vfolder://", foldername, NULL); - } else { - uri = g_strconcat ("imap://", storage, foldername, NULL); - } -#endif ex = camel_exception_new (); folder = mail_tool_uri_to_folder (m->foldername, 0, ex); @@ -120,6 +85,10 @@ do_get_info (struct _mail_msg *mm) camel_exception_free (ex); + if (folder == NULL) { + g_warning ("Camel returned NULL for %s\n", m->foldername); + } + m->read = camel_folder_get_message_count (folder); m->unread = camel_folder_get_unread_message_count (folder); } @@ -132,7 +101,7 @@ do_got_info (struct _mail_msg *mm) CORBA_any a; GNOME_Evolution_FolderInfo_MessageCount count; - /*g_print ("You've got mail: %d, %d\n", m->read, m->unread);*/ +/* g_print ("You've got mail: %d, %d\n", m->read, m->unread); */ count.path = m->foldername; count.count = m->read; @@ -154,6 +123,7 @@ do_free_info (struct _mail_msg *mm) { struct _folder_info_msg *m = (struct _folder_info_msg *) mm; + bonobo_object_release_unref (m->listener, NULL); g_free (m->foldername); } @@ -179,7 +149,7 @@ mail_get_info (const char *foldername, m = mail_msg_new (&get_info_op, NULL, sizeof (*m)); - /*g_print ("Folder: %s", foldername);*/ +/* g_print ("Folder: %s", foldername); */ m->foldername = g_strdup (foldername); CORBA_exception_init (&ev); @@ -198,6 +168,14 @@ impl_GNOME_Evolution_FolderInfo_getInfo (PortableServer_Servant servant, mail_get_info (foldername, listener); } +static void +destroy (GtkObject *object) +{ + EvolutionFolderInfo *info = (EvolutionFolderInfo *) object; + + bonobo_object_unref (BONOBO_OBJECT (info->pb)); +} + static void evolution_folder_info_class_init (EvolutionFolderInfoClass *klass) { @@ -217,13 +195,70 @@ BONOBO_X_TYPE_FUNC_FULL (EvolutionFolderInfo, PARENT_TYPE, evolution_folder_info); +enum { + PROP_FOLDER_INFO_READY +}; + +static void +set_prop (BonoboPropertyBag *bag, + const BonoboArg *arg, + guint arg_id, + CORBA_Environment *ev, + gpointer user_data) +{ + g_print ("Set!\n"); + switch (arg_id) { + case PROP_FOLDER_INFO_READY: + ready = BONOBO_ARG_GET_BOOLEAN (arg); + break; + + default: + bonobo_exception_set (ev, ex_Bonobo_PropertyBag_NotFound); + break; + } +} + +static void +get_prop (BonoboPropertyBag *bag, + BonoboArg *arg, + guint arg_id, + CORBA_Environment *ev, + gpointer user_data) +{ + g_print ("Get!\n"); + switch (arg_id) { + case PROP_FOLDER_INFO_READY: + BONOBO_ARG_SET_BOOLEAN (arg, ready); + break; + + default: + bonobo_exception_set (ev, ex_Bonobo_PropertyBag_NotFound); + break; + } +} + static BonoboObject * evolution_folder_info_factory_fn (BonoboGenericFactory *factory, void *closure) { EvolutionFolderInfo *info; - + BonoboPropertyBag *pb; + info = gtk_type_new (evolution_folder_info_get_type ()); + pb = bonobo_property_bag_new (get_prop, set_prop, info); + info->pb = pb; + /* Add properties */ + bonobo_property_bag_add (pb, "folder-info-ready", + PROP_FOLDER_INFO_READY, + BONOBO_ARG_BOOLEAN, NULL, FALSE, + BONOBO_PROPERTY_READABLE | + BONOBO_PROPERTY_WRITEABLE); + + bonobo_object_add_interface (BONOBO_OBJECT (info), BONOBO_OBJECT (pb)); + + /* Add to the folder info list so we can get at them all afterwards */ + folder_infos = g_slist_append (folder_infos, info); + return BONOBO_OBJECT (info); } @@ -231,6 +266,9 @@ gboolean evolution_folder_info_factory_init (void) { BonoboGenericFactory *factory; + + folder_infos = NULL; + ready = FALSE; factory = bonobo_generic_factory_new (FOLDER_INFO_IID, evolution_folder_info_factory_fn, @@ -244,3 +282,22 @@ evolution_folder_info_factory_init (void) bonobo_running_context_auto_exit_unref (BONOBO_OBJECT (factory)); return TRUE; } + +void +evolution_folder_info_notify_ready (void) +{ + GSList *p; + + ready = TRUE; + + for (p = folder_infos; p; p = p->next) { + BonoboArg arg; + CORBA_boolean b = ready; + EvolutionFolderInfo *info = p->data; + + arg._value = &b; + arg._type = (CORBA_TypeCode) TC_boolean; + bonobo_property_bag_set_value (BONOBO_PROPERTY_BAG (info->pb), + "folder-info-ready", &arg, NULL); + } +} -- cgit v1.2.3