diff options
author | Not Zed <NotZed@Ximian.com> | 2001-02-08 09:42:53 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2001-02-08 09:42:53 +0800 |
commit | 49f8a687a41e635cd83807d33c74afe8e55fb3df (patch) | |
tree | 4162f19a2db18ff787386c7c97a98e5e8a5e7744 /camel/providers | |
parent | 1290da3f286a31745b1814610c16918c2e84e140 (diff) | |
download | gsoc2013-evolution-49f8a687a41e635cd83807d33c74afe8e55fb3df.tar.gz gsoc2013-evolution-49f8a687a41e635cd83807d33c74afe8e55fb3df.tar.zst gsoc2013-evolution-49f8a687a41e635cd83807d33c74afe8e55fb3df.zip |
Changed to push the operation into a status stack.
2001-02-07 Not Zed <NotZed@Ximian.com>
* camel-operation.c (camel_operation_start): Changed to push the
operation into a status stack.
(camel_operation_progress): Changed to only accept % complete.
(camel_operation_reset): Free status stack as well.
* providers/pop3/camel-pop3-folder.c (pop3_get_message): Get the
octect count from the return line, and pass it to
get_additional_data().
(pop3_refresh_info): Added status stuff.
* providers/pop3/camel-pop3-store.c
(camel_pop3_command_get_additional_data): Added a total bytes
expected argument for progress reporting & fixed callers.
(camel_pop3_command_get_additional_data): Added progress
reporting.
* providers/local/camel-mbox-summary.c (mbox_summary_sync_full):
(mbox_summary_sync_quick):
(summary_rebuild): Added progress reporting stuff.
svn path=/trunk/; revision=8095
Diffstat (limited to 'camel/providers')
-rw-r--r-- | camel/providers/local/camel-mbox-summary.c | 42 | ||||
-rw-r--r-- | camel/providers/pop3/camel-pop3-folder.c | 31 | ||||
-rw-r--r-- | camel/providers/pop3/camel-pop3-store.c | 15 | ||||
-rw-r--r-- | camel/providers/pop3/camel-pop3-store.h | 3 |
4 files changed, 77 insertions, 14 deletions
diff --git a/camel/providers/local/camel-mbox-summary.c b/camel/providers/local/camel-mbox-summary.c index ab42e10df7..b8219b4c78 100644 --- a/camel/providers/local/camel-mbox-summary.c +++ b/camel/providers/local/camel-mbox-summary.c @@ -21,7 +21,8 @@ */ #include "camel-mbox-summary.h" -#include <camel/camel-mime-message.h> +#include "camel/camel-mime-message.h" +#include "camel/camel-operation.h" #include <sys/stat.h> #include <sys/uio.h> @@ -230,18 +231,26 @@ summary_rebuild(CamelMboxSummary *mbs, off_t offset, CamelException *ex) CamelMimeParser *mp; int fd; int ok = 0; + struct stat st; + off_t size = 0; /* FIXME: If there is a failure, it shouldn't clear the summary and restart, it should try and merge the summary info's. This is a bit tricky. */ + camel_operation_start(NULL, _("Summarising folder")); + fd = open(cls->folder_path, O_RDONLY); if (fd == -1) { printf("%s failed to open: %s", cls->folder_path, strerror(errno)); camel_exception_setv(ex, 1, _("Could not open folder: %s: summarising from position %ld: %s"), cls->folder_path, offset, strerror(errno)); + camel_operation_end(NULL); return -1; } + if (fstat(fd, &st) == 0) + size = st.st_size; + mp = camel_mime_parser_new(); camel_mime_parser_init_with_fd(mp, fd); camel_mime_parser_scan_from(mp, TRUE); @@ -262,12 +271,16 @@ summary_rebuild(CamelMboxSummary *mbs, off_t offset, CamelException *ex) d(printf("mime parser state ran out? state is %d\n", camel_mime_parser_state(mp))); camel_object_unref(CAMEL_OBJECT(mp)); /* end of file - no content? no error either */ + camel_operation_end(NULL); return 0; } } while (camel_mime_parser_step(mp, NULL, NULL) == HSCAN_FROM) { CamelMessageInfo *info; + int pc = (camel_mime_parser_tell(mp)+1) * 100/size; + + camel_operation_progress(NULL, pc); info = camel_folder_summary_add_from_parser(s, mp); if (info == NULL) { @@ -284,8 +297,6 @@ summary_rebuild(CamelMboxSummary *mbs, off_t offset, CamelException *ex) /* update the file size/mtime in the summary */ if (ok != -1) { - struct stat st; - if (stat(cls->folder_path, &st) == 0) { camel_folder_summary_touch(s); mbs->folder_size = st.st_size; @@ -293,6 +304,8 @@ summary_rebuild(CamelMboxSummary *mbs, off_t offset, CamelException *ex) } } + camel_operation_end(NULL); + return ok; } @@ -477,11 +490,14 @@ mbox_summary_sync_full(CamelLocalSummary *cls, gboolean expunge, CamelFolderChan d(printf("performing full summary/sync\n")); + camel_operation_start(NULL, _("Synchronising folder")); + fd = open(cls->folder_path, O_RDONLY); if (fd == -1) { camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Could not open folder to summarise: %s: %s"), cls->folder_path, strerror(errno)); + camel_operation_end(NULL); return -1; } @@ -502,6 +518,10 @@ mbox_summary_sync_full(CamelLocalSummary *cls, gboolean expunge, CamelFolderChan count = camel_folder_summary_count(s); for (i = 0; i < count; i++) { + int pc = (i+1)*100/count; + + camel_operation_progress(NULL, pc); + info = (CamelMboxMessageInfo *)camel_folder_summary_index(s, i); g_assert(info); @@ -630,7 +650,8 @@ mbox_summary_sync_full(CamelLocalSummary *cls, gboolean expunge, CamelFolderChan tmpname = NULL; camel_object_unref((CamelObject *)mp); - + camel_operation_end(NULL); + return 0; error: if (fd != -1) @@ -648,6 +669,8 @@ mbox_summary_sync_full(CamelLocalSummary *cls, gboolean expunge, CamelFolderChan if (info) camel_folder_summary_info_free(s, (CamelMessageInfo *)info); + camel_operation_end(NULL); + return -1; } @@ -668,11 +691,15 @@ mbox_summary_sync_quick(CamelLocalSummary *cls, gboolean expunge, CamelFolderCha d(printf("Performing quick summary sync\n")); + camel_operation_start(NULL, _("Synchronising folder")); + fd = open(cls->folder_path, O_RDWR); if (fd == -1) { camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Could not open folder to summarise: %s: %s"), cls->folder_path, strerror(errno)); + + camel_operation_end(NULL); return -1; } @@ -684,6 +711,9 @@ mbox_summary_sync_quick(CamelLocalSummary *cls, gboolean expunge, CamelFolderCha count = camel_folder_summary_count(s); for (i = 0; i < count; i++) { int xevoffset; + int pc = (i+1)*100/count; + + camel_operation_progress(NULL, pc); info = (CamelMboxMessageInfo *)camel_folder_summary_index(s, i); @@ -769,6 +799,8 @@ mbox_summary_sync_quick(CamelLocalSummary *cls, gboolean expunge, CamelFolderCha } camel_object_unref((CamelObject *)mp); + + camel_operation_end(NULL); return 0; error: @@ -779,6 +811,8 @@ mbox_summary_sync_quick(CamelLocalSummary *cls, gboolean expunge, CamelFolderCha if (info) camel_folder_summary_info_free(s, (CamelMessageInfo *)info); + camel_operation_end(NULL); + return -1; } diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c index cf55a95661..810faed846 100644 --- a/camel/providers/pop3/camel-pop3-folder.c +++ b/camel/providers/pop3/camel-pop3-folder.c @@ -29,6 +29,7 @@ #include "camel-stream-mem.h" #include "camel-stream-filter.h" #include "camel-mime-message.h" +#include "camel-operation.h" #include <stdlib.h> #include <string.h> @@ -141,9 +142,13 @@ pop3_refresh_info (CamelFolder *folder, CamelException *ex) CamelPop3Folder *pop3_folder = (CamelPop3Folder *) folder; CamelPop3Store *pop3_store = CAMEL_POP3_STORE (folder->parent_store); + camel_operation_start(NULL, _("Retrieving POP summary")); + status = camel_pop3_command (pop3_store, &data, ex, "STAT"); - if (status != CAMEL_POP3_OK) + if (status != CAMEL_POP3_OK) { + camel_operation_end(NULL); return; + } count = atoi (data); g_free (data); @@ -155,6 +160,7 @@ pop3_refresh_info (CamelFolder *folder, CamelException *ex) pop3_store->supports_uidl = FALSE; break; case CAMEL_POP3_FAIL: + camel_operation_end(NULL); return; } } @@ -167,8 +173,10 @@ pop3_refresh_info (CamelFolder *folder, CamelException *ex) for (i = 0; i < count; i++) uids->pdata[i] = g_strdup_printf ("%d", i + 1); + camel_operation_end(NULL); } else { - data = camel_pop3_command_get_additional_data (pop3_store, ex); + data = camel_pop3_command_get_additional_data (pop3_store, 0, ex); + camel_operation_end(NULL); if (camel_exception_is_set (ex)) return; @@ -263,7 +271,7 @@ uid_to_number (CamelPop3Folder *pop3_folder, const char *uid) static CamelMimeMessage * pop3_get_message (CamelFolder *folder, const char *uid, CamelException *ex) { - int status, num; + int status, num, total; char *result, *body; CamelStream *msgstream; CamelMimeMessage *msg; @@ -275,19 +283,28 @@ pop3_get_message (CamelFolder *folder, const char *uid, CamelException *ex) return NULL; } + camel_operation_start(NULL, _("Retrieving POP message %d"), num); + status = camel_pop3_command (CAMEL_POP3_STORE (folder->parent_store), &result, ex, "RETR %d", num); - if (status != CAMEL_POP3_OK) + if (status != CAMEL_POP3_OK) { + camel_operation_end(NULL); return NULL; - g_free (result); + } + + /* this should be "nnn octets" ? */ + if (sscanf(result, "%d", &total) != 1) + total = 0; - body = camel_pop3_command_get_additional_data (CAMEL_POP3_STORE (folder->parent_store), ex); + g_free (result); + body = camel_pop3_command_get_additional_data (CAMEL_POP3_STORE (folder->parent_store), total, ex); if (!body) { CamelService *service = CAMEL_SERVICE (folder->parent_store); camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, _("Could not retrieve message from POP " "server %s: %s"), service->url->host, camel_exception_get_description (ex)); + camel_operation_end(NULL); return NULL; } @@ -300,6 +317,8 @@ pop3_get_message (CamelFolder *folder, const char *uid, CamelException *ex) camel_object_unref (CAMEL_OBJECT (msgstream)); + camel_operation_end(NULL); + return msg; } diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c index aefabebfa4..f0338a8584 100644 --- a/camel/providers/pop3/camel-pop3-store.c +++ b/camel/providers/pop3/camel-pop3-store.c @@ -35,6 +35,8 @@ #include <unistd.h> #include <errno.h> +#include "camel-operation.h" + #ifdef HAVE_KRB4 /* Specified nowhere */ #define KPOP_PORT 1109 @@ -250,7 +252,7 @@ connect_to_server (CamelService *service, /*gboolean real, */CamelException *ex) char *p; int len; - buf = camel_pop3_command_get_additional_data (store, ex); + buf = camel_pop3_command_get_additional_data (store, 0, ex); if (camel_exception_is_set (ex)) return FALSE; @@ -632,6 +634,7 @@ pop3_get_response (CamelPop3Store *store, char **ret, CamelException *ex) * camel_pop3_command_get_additional_data: get "additional data" from * a POP3 command. * @store: the POP3 store + * @total: Total bytes expected (for progress reporting), use 0 for 'unknown'. * * This command gets the additional data returned by "multi-line" POP * commands, such as LIST, RETR, TOP, and UIDL. This command _must_ @@ -643,11 +646,12 @@ pop3_get_response (CamelPop3Store *store, char **ret, CamelException *ex) * Return value: the data, which the caller must free. **/ char * -camel_pop3_command_get_additional_data (CamelPop3Store *store, CamelException *ex) +camel_pop3_command_get_additional_data (CamelPop3Store *store, int total, CamelException *ex) { GPtrArray *data; char *buf, *p; int i, len = 0, status = CAMEL_POP3_OK; + int pc = 0; data = g_ptr_array_new (); while (1) { @@ -661,6 +665,13 @@ camel_pop3_command_get_additional_data (CamelPop3Store *store, CamelException *e g_ptr_array_add (data, buf); len += strlen (buf) + 1; + + if (total) { + pc = (len+1) * 100 / total; + camel_operation_progress(NULL, pc); + } else { + camel_operation_progress_count(NULL, len); + } } if (buf) diff --git a/camel/providers/pop3/camel-pop3-store.h b/camel/providers/pop3/camel-pop3-store.h index 65bf1cbdba..078a317a14 100644 --- a/camel/providers/pop3/camel-pop3-store.h +++ b/camel/providers/pop3/camel-pop3-store.h @@ -65,8 +65,7 @@ void camel_pop3_store_expunge (CamelPop3Store *store, CamelException *ex); /* support functions */ enum { CAMEL_POP3_OK, CAMEL_POP3_ERR, CAMEL_POP3_FAIL }; int camel_pop3_command (CamelPop3Store *store, char **ret, CamelException *ex, char *fmt, ...); -char *camel_pop3_command_get_additional_data (CamelPop3Store *store, - CamelException *ex); +char *camel_pop3_command_get_additional_data (CamelPop3Store *store, int total, CamelException *ex); /* Standard Camel function */ CamelType camel_pop3_store_get_type (void); |