diff options
author | Not Zed <NotZed@Ximian.com> | 2001-03-31 01:24:51 +0000 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2001-03-31 01:24:51 +0000 |
commit | 9b231fbdec88493883035382e7fe1a1c6a47c94b (patch) | |
tree | 8ae08d9ae0086019b595e4264a83fb8be9874045 | |
parent | 6e8dbdd8ba0222914a979d62db58cec800b6f524 (diff) | |
download | evolution-data-server-9b231fbdec88493883035382e7fe1a1c6a47c94b.tar.gz |
Change the pop download into a transient event.
2001-03-30 Not Zed <NotZed@Ximian.com>
* providers/pop3/camel-pop3-folder.c (pop3_get_message): Change
the pop download into a transient event.
* camel-operation.c (stamp): Get a timestamp that changes 4x a
second (or rather, arbitrarily more often than 1/second).
(camel_operation_progress): Use stamp() for time updates.
(camel_operation_progress_count): "
(camel_operation_start): Store the status as a struct status_stack
item.
(camel_operation_start_transient): New function to start a
transient event, which is only reported if it runs for too
long/and is reset afterwards.
(camel_operation_progress):
(camel_operation_progress_count): Fix for status_stack changes,
and account for transient updates.
* camel-filter-driver.c (camel_filter_driver_filter_folder): When
we remove things (set deleted), always set seen too, to mirror
interface behaviour when you delete.
(camel_filter_driver_filter_message): And same here too.
-rw-r--r-- | camel/ChangeLog | 23 | ||||
-rw-r--r-- | camel/camel-filter-driver.c | 4 | ||||
-rw-r--r-- | camel/camel-operation.c | 164 | ||||
-rw-r--r-- | camel/camel-operation.h | 1 | ||||
-rw-r--r-- | camel/providers/pop3/camel-pop3-folder.c | 2 |
5 files changed, 170 insertions, 24 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 2b7de843a..5dd62b470 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,26 @@ +2001-03-30 Not Zed <NotZed@Ximian.com> + + * providers/pop3/camel-pop3-folder.c (pop3_get_message): Change + the pop download into a transient event. + + * camel-operation.c (stamp): Get a timestamp that changes 4x a + second (or rather, arbitrarily more often than 1/second). + (camel_operation_progress): Use stamp() for time updates. + (camel_operation_progress_count): " + (camel_operation_start): Store the status as a struct status_stack + item. + (camel_operation_start_transient): New function to start a + transient event, which is only reported if it runs for too + long/and is reset afterwards. + (camel_operation_progress): + (camel_operation_progress_count): Fix for status_stack changes, + and account for transient updates. + + * camel-filter-driver.c (camel_filter_driver_filter_folder): When + we remove things (set deleted), always set seen too, to mirror + interface behaviour when you delete. + (camel_filter_driver_filter_message): And same here too. + 2001-03-30 Dan Winship <danw@ximian.com> * providers/pop3/camel-pop3-store.c (connect_to_server, diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c index 3fa703848..262a9717a 100644 --- a/camel/camel-filter-driver.c +++ b/camel/camel-filter-driver.c @@ -771,7 +771,7 @@ camel_filter_driver_filter_folder (CamelFilterDriver *driver, CamelFolder *folde if (remove) camel_folder_set_message_flags (folder, uids->pdata[i], - CAMEL_MESSAGE_DELETED, CAMEL_MESSAGE_DELETED); + CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_SEEN); camel_object_unref (CAMEL_OBJECT (message)); } @@ -874,7 +874,7 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver, CamelMimeMessage /* *Now* we can set the DELETED flag... */ if (p->deleted) - info->flags = info->flags | CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_FOLDER_FLAGGED; + info->flags = info->flags | CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_FOLDER_FLAGGED | CAMEL_MESSAGE_SEEN; /* Logic: if !Moved and there exists a default folder... */ if (!(p->copied && p->deleted) && p->defaultfolder) { diff --git a/camel/camel-operation.c b/camel/camel-operation.c index 9d631fca7..c36fabe27 100644 --- a/camel/camel-operation.c +++ b/camel/camel-operation.c @@ -6,6 +6,9 @@ #include <pthread.h> #endif +#include <sys/time.h> +#include <unistd.h> + #include <glib.h> #include "camel-operation.h" #include "e-util/e-msgport.h" @@ -14,6 +17,13 @@ /* ********************************************************************** */ +struct _status_stack { + guint32 flags; + char *msg; + int pc; /* last pc reported */ + int stamp; /* last stamp reported */ +}; + struct _CamelOperation { pthread_t id; /* id of running thread */ guint32 flags; /* cancelled ? */ @@ -22,10 +32,11 @@ struct _CamelOperation { CamelOperationStatusFunc status; void *status_data; - time_t status_update; + unsigned int status_update; - /* stack of status messages (char *) */ + /* stack of status messages (struct _status_stack *) */ GSList *status_stack; + struct _status_stack *lastreport; #ifdef ENABLE_THREADS EMsgPort *cancel_port; @@ -35,6 +46,7 @@ struct _CamelOperation { }; #define CAMEL_OPERATION_CANCELLED (1<<0) +#define CAMEL_OPERATION_TRANSIENT (1<<1) #ifdef ENABLE_THREADS #define CAMEL_OPERATION_LOCK(cc) pthread_mutex_lock(&cc->lock) @@ -404,6 +416,7 @@ void camel_operation_start(CamelOperation *cc, char *what, ...) { va_list ap; char *msg; + struct _status_stack *s; if (operation_active == NULL) return; @@ -424,10 +437,67 @@ void camel_operation_start(CamelOperation *cc, char *what, ...) va_end(ap); cc->status(cc, msg, CAMEL_OPERATION_START, cc->status_data); cc->status_update = 0; - cc->status_stack = g_slist_prepend(cc->status_stack, msg); + s = g_malloc0(sizeof(*s)); + s->msg = msg; + s->flags = 0; + cc->lastreport = s; + cc->status_stack = g_slist_prepend(cc->status_stack, s); + d(printf("start '%s'\n", msg, pc)); +} + +/** + * camel_operation_start_transient: + * @cc: + * @what: + * @: + * + * Start a transient event. We only update this to the display if it + * takes very long to process, and if we do, we then go back to the + * previous state when finished. + **/ +void camel_operation_start_transient(CamelOperation *cc, char *what, ...) +{ + va_list ap; + char *msg; + struct _status_stack *s; + + if (operation_active == NULL) + return; + + if (cc == NULL) { + CAMEL_ACTIVE_LOCK(); + cc = g_hash_table_lookup(operation_active, (void *)pthread_self()); + CAMEL_ACTIVE_UNLOCK(); + if (cc == NULL) + return; + } + + if (cc->status == NULL) + return; + + va_start(ap, what); + msg = g_strdup_vprintf(what, ap); + va_end(ap); + /* we dont report it yet */ + /*cc->status(cc, msg, CAMEL_OPERATION_START, cc->status_data);*/ + cc->status_update = 0; + s = g_malloc0(sizeof(*s)); + s->msg = msg; + s->flags = CAMEL_OPERATION_TRANSIENT; + s->stamp = stamp(); + cc->status_stack = g_slist_prepend(cc->status_stack, s); d(printf("start '%s'\n", msg, pc)); } +static unsigned int stamp(void) +{ + struct timeval tv; + + gettimeofday(&tv, NULL); + /* update 4 times/second */ + return (tv.tv_sec * 4) + tv.tv_usec / (1000000/4); +} + /** * camel_operation_progress: * @cc: Operation to report to. @@ -442,8 +512,8 @@ void camel_operation_start(CamelOperation *cc, char *what, ...) **/ void camel_operation_progress(CamelOperation *cc, int pc) { - char *msg; - time_t now; + unsigned int now; + struct _status_stack *s; if (operation_active == NULL) return; @@ -462,19 +532,31 @@ void camel_operation_progress(CamelOperation *cc, int pc) if (cc->status_stack == NULL) return; - now = time(0); + s = cc->status_stack->data; + s->pc = pc; + + now = stamp(); if (cc->status_update != now) { - msg =cc->status_stack->data; - cc->status(cc, msg, pc, cc->status_data); - d(printf("progress '%s' %d %%\n", msg, pc)); - cc->status_update = now; + if (s->flags & CAMEL_OPERATION_TRANSIENT) { + if (s->stamp/8 < now/8) { + s->stamp = now; + cc->status(cc, s->msg, pc, cc->status_data); + cc->status_update = now; + cc->lastreport = s; + } + } else { + cc->status(cc, s->msg, pc, cc->status_data); + d(printf("progress '%s' %d %%\n", s->msg, pc)); + s->stamp = cc->status_update = now; + cc->lastreport = s; + } } } void camel_operation_progress_count(CamelOperation *cc, int sofar) { - char *msg; - time_t now; + unsigned int now; + struct _status_stack *s; if (operation_active == NULL) return; @@ -494,12 +576,23 @@ void camel_operation_progress_count(CamelOperation *cc, int sofar) return; /* FIXME: generate some meaningful pc value */ - now = time(0); + s = cc->status_stack->data; + s->pc = sofar; + now = stamp(); if (cc->status_update != now) { - msg =cc->status_stack->data; - cc->status(cc, msg, sofar, cc->status_data); - d(printf("progress '%s' %d done\n", msg, sofar)); - cc->status_update = now; + if (s->flags & CAMEL_OPERATION_TRANSIENT) { + if (s->stamp/8 < now/8) { + s->stamp = now; + cc->status(cc, s->msg, sofar, cc->status_data); + cc->status_update = now; + cc->lastreport = s; + } + } else { + cc->status(cc, s->msg, sofar, cc->status_data); + d(printf("progress '%s' %d done\n", msg, sofar)); + s->stamp = cc->status_update = now; + cc->lastreport = s; + } } } @@ -514,7 +607,8 @@ void camel_operation_progress_count(CamelOperation *cc, int sofar) **/ void camel_operation_end(CamelOperation *cc) { - char *msg; + struct _status_stack *s, *p; + unsigned int now; if (operation_active == NULL) return; @@ -533,8 +627,36 @@ void camel_operation_end(CamelOperation *cc) if (cc->status_stack == NULL) return; - msg = cc->status_stack->data; - cc->status(cc, msg, CAMEL_OPERATION_END, cc->status_data); - g_free(msg); + /* so what we do here is this. If the operation that just + * ended was transient, see if we have any other transient + * messages that haven't been updated yet above us, otherwise, + * re-update as a non-transient at the last reported pc */ + now = stamp(); + s = cc->status_stack->data; + if (s->flags & CAMEL_OPERATION_TRANSIENT) { + if (cc->lastreport == s) { + GSList *l = cc->status_stack->next; + while (l) { + p = l->data; + if (p->flags & CAMEL_OPERATION_TRANSIENT) { + if (p->stamp/8 < now/8) { + cc->status(cc, p->msg, p->pc, cc->status_data); + cc->lastreport = p; + break; + } + } else { + cc->status(cc, p->msg, p->pc, cc->status_data); + cc->lastreport = p; + break; + } + l = l->next; + } + } + } else { + cc->status(cc, s->msg, CAMEL_OPERATION_END, cc->status_data); + cc->lastreport = s; + } + g_free(s->msg); + g_free(s); cc->status_stack = g_slist_remove_link(cc->status_stack, cc->status_stack); } diff --git a/camel/camel-operation.h b/camel/camel-operation.h index 4a61b40df..8bf5cfa2d 100644 --- a/camel/camel-operation.h +++ b/camel/camel-operation.h @@ -55,6 +55,7 @@ int camel_operation_cancel_check(CamelOperation *cc); int camel_operation_cancel_fd(CamelOperation *cc); void camel_operation_start(CamelOperation *cc, char *what, ...); +void camel_operation_start_transient(CamelOperation *cc, char *what, ...); void camel_operation_progress(CamelOperation *cc, int pc); void camel_operation_progress_count(CamelOperation *cc, int sofar); void camel_operation_end(CamelOperation *cc); diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c index 3b1366ba2..96b547182 100644 --- a/camel/providers/pop3/camel-pop3-folder.c +++ b/camel/providers/pop3/camel-pop3-folder.c @@ -286,7 +286,7 @@ pop3_get_message (CamelFolder *folder, const char *uid, CamelException *ex) return NULL; } - camel_operation_start(NULL, _("Retrieving POP message %d"), num); + camel_operation_start_transient(NULL, _("Retrieving POP message %d"), num); status = camel_pop3_command (CAMEL_POP3_STORE (folder->parent_store), &result, ex, "RETR %d", num); |