From cdea22d886c2547288e24129b14399eeed08cd17 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Thu, 19 Jul 2001 11:50:49 +0000 Subject: partial checkin before completing the changes 2001-07-18 Not Zed * mail-local.c (reconfigure_folder_reconfigure): Changed to use camel_operation rathre than mail_status. (reconfigure_folder_describe): re-enabled this function. * mail-ops.c (get_messages_get): Changed to use camel-progress for status reporting. (save_messages_save): Likewise. 2001-07-17 Not Zed * mail-mt.c (struct _mail_msg_priv, destroy_objects, mail_msg_new, mail_msg_free, do_op_status): Changed to use an EvolutionActivityClient for progress. svn path=/trunk/; revision=11223 --- mail/ChangeLog | 16 +++++ mail/Makefile.am | 2 +- mail/mail-local.c | 41 ++++--------- mail/mail-mt.c | 181 +++++++++++++++++++++++++++--------------------------- mail/mail-mt.h | 2 + mail/mail-ops.c | 22 +++++-- 6 files changed, 137 insertions(+), 127 deletions(-) (limited to 'mail') diff --git a/mail/ChangeLog b/mail/ChangeLog index 4735b615db..ead11f74ca 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,19 @@ +2001-07-18 Not Zed + + * mail-local.c (reconfigure_folder_reconfigure): Changed to use + camel_operation rathre than mail_status. + (reconfigure_folder_describe): re-enabled this function. + + * mail-ops.c (get_messages_get): Changed to use camel-progress for + status reporting. + (save_messages_save): Likewise. + +2001-07-17 Not Zed + + * mail-mt.c (struct _mail_msg_priv, destroy_objects, mail_msg_new, + mail_msg_free, do_op_status): Changed to use an EvolutionActivityClient for + progress. + 2001-07-18 Jason Leach * mail-tools.h (mail_tool_get_local_inbox_url): Remove this diff --git a/mail/Makefile.am b/mail/Makefile.am index b29861960c..004ed4e932 100644 --- a/mail/Makefile.am +++ b/mail/Makefile.am @@ -106,7 +106,7 @@ evolution_mail_SOURCES = \ message-list.h \ subscribe-dialog.c \ subscribe-dialog.h \ - mail.h + mail.h mcheck.c evolution_mail_LDADD = \ $(top_builddir)/camel/libcamel.la \ diff --git a/mail/mail-local.c b/mail/mail-local.c index 3372754fcd..3a6f409eb9 100644 --- a/mail/mail-local.c +++ b/mail/mail-local.c @@ -717,14 +717,6 @@ mail_local_storage_startup (EvolutionShellClient *shellclient, */ -static void -update_progress(char *fmt, float percent) -{ - if (fmt) - mail_status(fmt); - /*mail_op_set_percentage (percent);*/ -} - /* ******************** */ /* we should have our own progress bar for this */ @@ -733,29 +725,22 @@ struct _reconfigure_msg { struct _mail_msg msg; FolderBrowser *fb; - gchar *newtype; + char *newtype; GtkWidget *frame; GtkWidget *apply; GtkWidget *cancel; GtkOptionMenu *optionlist; }; -#if 0 -static gchar * -describe_reconfigure_folder (gpointer in_data, gboolean gerund) +static char * +reconfigure_folder_describe(struct _mail_msg *mm, int done) { - reconfigure_folder_input_t *input = (reconfigure_folder_input_t *) in_data; + struct _reconfigure_msg *m = (struct _reconfigure_msg *)mm; - if (gerund) - return g_strdup_printf (_("Changing folder \"%s\" to \"%s\" format"), - input->fb->uri, - input->newtype); - else - return g_strdup_printf (_("Change folder \"%s\" to \"%s\" format"), - input->fb->uri, - input->newtype); + return g_strdup_printf (_("Changing folder \"%s\" to \"%s\" format"), + m->fb->uri, + m->newtype); } -#endif static void reconfigure_folder_reconfigure(struct _mail_msg *mm) @@ -774,7 +759,8 @@ reconfigure_folder_reconfigure(struct _mail_msg *mm) d(printf("reconfiguring folder: %s to type %s\n", m->fb->uri, m->newtype)); - mail_status (_("Reconfiguring folder")); + camel_operation_register(mm->cancel); + camel_operation_start(mm->cancel, _("Reconfiguring folder")); /* NOTE: This var is cleared by the folder_browser via the set_uri method */ m->fb->reconfigure = TRUE; @@ -803,7 +789,6 @@ reconfigure_folder_reconfigure(struct _mail_msg *mm) g_free(metapath); /* first, 'close' the old folder */ - update_progress(_("Closing current folder"), 0.0); camel_folder_sync(local_folder->folder, FALSE, &mm->ex); /* Once for the FolderBrowser, once for the local store */ @@ -830,7 +815,6 @@ reconfigure_folder_reconfigure(struct _mail_msg *mm) /* rename the old mbox and open it again, without indexing */ tmpname = g_strdup_printf("%s_reconfig", meta->name); d(printf("renaming %s to %s, and opening it\n", meta->name, tmpname)); - update_progress(_("Renaming old folder and opening"), 0.0); camel_store_rename_folder(fromstore, meta->name, tmpname, &mm->ex); if (camel_exception_is_set(&mm->ex)) { @@ -848,7 +832,6 @@ reconfigure_folder_reconfigure(struct _mail_msg *mm) /* create a new mbox */ d(printf("Creating the destination mbox\n")); - update_progress(_("Creating new folder"), 0.0); flags = CAMEL_STORE_FOLDER_CREATE; if (meta->indexed) @@ -862,7 +845,6 @@ reconfigure_folder_reconfigure(struct _mail_msg *mm) goto cleanup; } - update_progress (_("Copying messages"), 0.0); uids = camel_folder_get_uids (fromfolder); camel_folder_move_messages_to (fromfolder, uids, tofolder, &mm->ex); camel_folder_free_uids (fromfolder, uids); @@ -909,6 +891,9 @@ reconfigure_folder_reconfigure(struct _mail_msg *mm) g_free(tourl); if (url) camel_url_free (url); + + camel_operation_end(mm->cancel); + camel_operation_unregister(mm->cancel); } static void @@ -939,7 +924,7 @@ reconfigure_folder_free(struct _mail_msg *mm) } static struct _mail_msg_op reconfigure_folder_op = { - NULL, + reconfigure_folder_describe, reconfigure_folder_reconfigure, reconfigure_folder_reconfigured, reconfigure_folder_free, diff --git a/mail/mail-mt.c b/mail/mail-mt.c index b43af083d2..a18ef1899e 100644 --- a/mail/mail-mt.c +++ b/mail/mail-mt.c @@ -27,8 +27,12 @@ #include "e-util/e-msgport.h" #include "camel/camel-operation.h" +#include "evolution-activity-client.h" + #include "mail-mt.h" +#include "art/mail-new.xpm" + /*#define MALLOC_CHECK*/ #define d(x) @@ -41,19 +45,22 @@ static void mail_operation_status(struct _CamelOperation *op, const char *what, #define MAIL_MT_LOCK(x) pthread_mutex_lock(&x) #define MAIL_MT_UNLOCK(x) pthread_mutex_unlock(&x) +extern EvolutionShellClient *global_shell_client; + /* background operation status stuff */ struct _mail_msg_priv { - GtkProgressBar *bar; - GtkLabel *label; - - /* for pending requests, before timeout_id is activated (then bar will be ! NULL) */ - char *what; - int pc; int timeout_id; + int activity_state; /* sigh sigh sigh, we need to keep track of the state external to the + pointer itself for locking/race conditions */ + EvolutionActivityClient *activity; + char *what; + unsigned int pc; }; -static GtkWindow *progress_dialogue; -static int progress_row; +/*static GtkWindow *progress_dialogue;*/ +/*static int progress_row;*/ + +static GdkPixbuf *progress_icon[2] = { NULL, NULL }; /* mail_msg stuff */ static unsigned int mail_msg_seq; /* sequence number of each message */ @@ -87,12 +94,10 @@ void *mail_msg_new(mail_msg_op_t *ops, EMsgPort *reply_port, size_t size) } /* either destroy the progress (in event_data), or the whole dialogue (in data) */ -static void destroy_widgets(CamelObject *o, void *event_data, void *data) +static void destroy_objects(CamelObject *o, void *event_data, void *data) { - if (data) - gtk_widget_destroy((GtkWidget *)data); if (event_data) - gtk_widget_destroy((GtkWidget *)event_data); + gtk_object_unref(event_data); } #ifdef MALLOC_CHECK @@ -122,7 +127,7 @@ checkmem(void *p) void mail_msg_free(void *msg) { struct _mail_msg *m = msg; - void *bar = NULL, *label = NULL; + void *activity = NULL; #ifdef MALLOC_CHECK checkmem(m); @@ -139,6 +144,7 @@ void mail_msg_free(void *msg) g_hash_table_remove(mail_msg_active, (void *)m->seq); pthread_cond_broadcast(&mail_msg_cond); +#if 0 /* this closes the bar, and/or the whole progress dialogue, once we're out of things to do */ if (g_hash_table_size(mail_msg_active) == 0) { if (progress_dialogue != NULL) { @@ -150,20 +156,31 @@ void mail_msg_free(void *msg) bar = m->priv->bar; label = m->priv->label; } +#endif if (m->priv->timeout_id > 0) gtk_timeout_remove(m->priv->timeout_id); + /* We need to make sure we dont lose a reference here YUCK YUCK */ + if (m->priv->activity_state == 1) { + m->priv->activity_state = 3; /* tell the other thread + * to free it itself (yuck yuck) */ + MAIL_MT_UNLOCK(mail_msg_lock); + return; + } else { + activity = m->priv->activity; + } + MAIL_MT_UNLOCK(mail_msg_lock); camel_operation_unref(m->cancel); camel_exception_clear(&m->ex); - g_free(m->priv->what); + /*g_free(m->priv->what);*/ g_free(m->priv); g_free(m); - if (bar || label) - mail_proxy_event(destroy_widgets, NULL, bar, label); + if (activity) + mail_proxy_event(destroy_objects, NULL, activity, NULL); } void mail_msg_check_error(void *msg) @@ -839,72 +856,14 @@ struct _op_status_msg { void *data; }; -GtkTable *progress_table; - -static int op_status_timeout(void *d) -{ - int id = (int)d; - struct _mail_msg *msg; - struct _mail_msg_priv *data; - - MAIL_MT_LOCK(mail_msg_lock); - - msg = g_hash_table_lookup(mail_msg_active, (void *)id); - if (msg == NULL) { - MAIL_MT_UNLOCK(mail_msg_lock); - return FALSE; - } - - data = msg->priv; - - if (progress_dialogue == NULL) { - if (data->pc == 100) { - MAIL_MT_UNLOCK(mail_msg_lock); - return FALSE; - } - - progress_dialogue = (GtkWindow *)gtk_window_new(GTK_WINDOW_DIALOG); - gtk_window_set_title(progress_dialogue, _("Evolution progress")); - gtk_window_set_policy(progress_dialogue, 0, 0, 1); - gtk_window_set_position(progress_dialogue, GTK_WIN_POS_CENTER); - progress_table = (GtkTable *)gtk_table_new(1, 2, FALSE); - gtk_container_add((GtkContainer *)progress_dialogue, (GtkWidget *)progress_table); - } - - data->bar = (GtkProgressBar *)gtk_progress_bar_new(); - gtk_progress_set_show_text((GtkProgress *)data->bar, TRUE); - - gtk_progress_set_percentage((GtkProgress *)data->bar, (gfloat)(data->pc/100.0)); - gtk_progress_set_format_string((GtkProgress *)data->bar, data->what); - - if (msg->ops->describe_msg) { - char *desc = msg->ops->describe_msg(msg, FALSE); - data->label = (GtkLabel *)gtk_label_new(desc); - g_free(desc); - } else { - data->label = (GtkLabel *)gtk_label_new(_("Working")); - } - - gtk_table_attach(progress_table, (GtkWidget *)data->label, 0, 1, progress_row, progress_row+1, GTK_EXPAND|GTK_FILL, 0, 3, 1); - gtk_table_attach(progress_table, (GtkWidget *)data->bar, 1, 2, progress_row, progress_row+1, GTK_EXPAND|GTK_FILL, 0, 3, 1); - progress_row++; - - gtk_widget_show_all((GtkWidget *)progress_table); - gtk_widget_show((GtkWidget *)progress_dialogue); - - data->timeout_id = -1; - - MAIL_MT_UNLOCK(mail_msg_lock); - - return FALSE; -} - static void do_op_status(struct _mail_msg *mm) { struct _op_status_msg *m = (struct _op_status_msg *)mm; struct _mail_msg *msg; struct _mail_msg_priv *data; char *out, *p, *o, c; + int pc; + EvolutionActivityClient *activity; g_assert(mail_gui_thread == pthread_self()); @@ -928,26 +887,64 @@ static void do_op_status(struct _mail_msg *mm) } *o = 0; - if (data->timeout_id == 0) { - data->what = g_strdup(out); - data->pc = m->pc; - data->timeout_id = gtk_timeout_add(2000, op_status_timeout, m->data); - MAIL_MT_UNLOCK(mail_msg_lock); - return; - } + pc = m->pc; + + /* so whats all this crap about: + * When we call activity_client, we have a chance of coming + * back to code that will call mail_msg_new or one of many + * calls which may deadlock us. So we need to call corba + * outside of the lock. The activity_state thing is so we can + * properly lock data->activity without having to hold a lock + * ... of course we have to be careful in the free function to + * keep track of it too. + */ + if (data->activity == NULL) { + char *clientid, *what; + int display; + + /* its being created/removed? well leave it be */ + if (data->activity_state == 1 || data->activity_state == 3) { + MAIL_MT_UNLOCK(mail_msg_lock); + return; + } else { + data->activity_state = 1; - if (data->bar == NULL) { - g_free(data->what); - data->what = g_strdup(out); - data->pc = m->pc; - MAIL_MT_UNLOCK(mail_msg_lock); - return; - } + if (progress_icon[0] == NULL) + progress_icon[0] = gdk_pixbuf_new_from_xpm_data((const char **)mail_new_xpm); - gtk_progress_set_percentage((GtkProgress *)data->bar, (gfloat)(m->pc/100.0)); - gtk_progress_set_format_string((GtkProgress *)data->bar, out); + MAIL_MT_UNLOCK(mail_msg_lock); + clientid = g_strdup_printf("%p", msg); + if (msg->ops->describe_msg) + what = msg->ops->describe_msg(msg, FALSE); + else + what = _("Working"); + activity = evolution_activity_client_new(global_shell_client, clientid, + progress_icon, what, TRUE, &display); + if (msg->ops->describe_msg) + g_free(what); + g_free(clientid); + MAIL_MT_LOCK(mail_msg_lock); + if (data->activity_state == 3) { + MAIL_MT_UNLOCK(mail_msg_lock); + gtk_object_unref((GtkObject *)activity); + camel_operation_unref(msg->cancel); + camel_exception_clear(&msg->ex); + g_free(msg->priv); + g_free(msg); + } else { + data->activity_state = 2; + data->activity = activity; + MAIL_MT_UNLOCK(mail_msg_lock); + } + return; + } + } + activity = data->activity; + gtk_object_ref((GtkObject *)activity); MAIL_MT_UNLOCK(mail_msg_lock); + evolution_activity_client_update(activity, out, (double)(pc/100.0)); + gtk_object_unref((GtkObject *)activity); } static void do_op_status_free(struct _mail_msg *mm) diff --git a/mail/mail-mt.h b/mail/mail-mt.h index 8619642a07..e0d1fc35f7 100644 --- a/mail/mail-mt.h +++ b/mail/mail-mt.h @@ -59,11 +59,13 @@ void mail_msg_wait(unsigned int msgid); /* set the status-bar message */ /* start/end a new op */ +#if 0 void mail_status_start(const char *msg); void mail_status_end(void); /* set a status during an op */ void mail_statusf(const char *fmt, ...); void mail_status(const char *msg); +#endif /* request a string/password */ char *mail_get_password (const char *prompt, gboolean secret); diff --git a/mail/mail-ops.c b/mail/mail-ops.c index b9553d7570..0dc4cec42b 100644 --- a/mail/mail-ops.c +++ b/mail/mail-ops.c @@ -1714,16 +1714,21 @@ static void get_messages_get(struct _mail_msg *mm) int i; CamelMimeMessage *message; + camel_operation_register(mm->cancel); + camel_operation_start(mm->cancel, _("Retrieving %d messsage(s)"), m->uids->len); for (i=0; iuids->len; i++) { - mail_statusf(_("Retrieving message number %d of %d (uid \"%s\")"), - i+1, m->uids->len, (char *) m->uids->pdata[i]); + int pc = ((i+1) * 100) / m->uids->len; message = camel_folder_get_message(m->folder, m->uids->pdata[i], &mm->ex); + camel_operation_progress(mm->cancel, pc); if (message == NULL) break; g_ptr_array_add(m->messages, message); } + + camel_operation_end(mm->cancel); + camel_operation_unregister(mm->cancel); } static void get_messages_got(struct _mail_msg *mm) @@ -1878,14 +1883,16 @@ static void save_messages_save(struct _mail_msg *mm) camel_stream_filter_add(filtered_stream, (CamelMimeFilter *)from_filter); camel_object_unref((CamelObject *)from_filter); + camel_operation_register(mm->cancel); + camel_operation_start(mm->cancel, _("Saving %d messsage(s)"), m->uids->len); + for (i=0; iuids->len; i++) { CamelMimeMessage *message; + int pc = ((i+1) * 100) / m->uids->len; - mail_statusf(_("Saving message %d of %d (uid \"%s\")"), - i+1, m->uids->len, (char *)m->uids->pdata[i]); - message = camel_folder_get_message(m->folder, m->uids->pdata[i], &mm->ex); - if (!message) + camel_operation_progress(mm->cancel, pc); + if (message == NULL) break; /* we need to flush after each stream write since we are writing to the same fd */ @@ -1906,6 +1913,9 @@ static void save_messages_save(struct _mail_msg *mm) camel_object_unref((CamelObject *)filtered_stream); camel_object_unref((CamelObject *)stream); + + camel_operation_end(mm->cancel); + camel_operation_unregister(mm->cancel); } static void save_messages_saved(struct _mail_msg *mm) -- cgit v1.2.3