Changeset 3283
- Timestamp:
- 01/21/08 15:43:40
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/libtinymail-camel/tny-camel-send-queue.c (modified) (12 diffs)
- trunk/libtinymail-camel/tny-camel-send-queue.h (modified) (1 diff)
- trunk/libtinymail/tny-send-queue.c (modified) (3 diffs)
- trunk/libtinymail/tny-send-queue.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r3280 r3283 1 2008-01-21 Sergio Villar Senin <svillar@igalia.com> 2 3 * libtinymail/tny-send-queue.c 4 libtinymail/tny-send-queue.h 5 libtinymail-camel/tny-camel-send-queue.c 6 libtinymail-camel/tny-camel-send-queue.c: 7 (tny_send_queue_cancel): API change, now the cancel method receives a 8 flag specifying the action that should be performed on cancelations, 9 to remove the messages or just to suspend them 10 (emit_error): now the send queue waits until the callback of this 11 signal is properly processed by the user 12 1 13 2008-01-20 Philip Van Hoof <pvanhoof@gnome.org> 2 14 trunk/libtinymail-camel/tny-camel-send-queue.c
r3280 r3283 58 58 GError *error; 59 59 gint i, total; 60 GCond *condition; 61 GMutex *mutex; 62 gboolean had_callback; 60 63 } ErrorInfo; 61 64 … … 115 118 if (info->error) 116 119 g_error_free (info->error); 117 g_slice_free (ErrorInfo, info); 120 121 122 g_mutex_lock (info->mutex); 123 g_cond_broadcast (info->condition); 124 info->had_callback = TRUE; 125 g_mutex_unlock (info->mutex); 118 126 119 127 return; … … 135 143 info->i = i; 136 144 info->total = total; 145 info->had_callback = FALSE; 146 info->mutex = g_mutex_new (); 147 info->condition = g_cond_new (); 148 137 149 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, 138 150 emit_error_on_mainloop, info, destroy_error_info); 151 152 g_mutex_lock (info->mutex); 153 if (!info->had_callback) 154 g_cond_wait (info->condition, info->mutex); 155 g_mutex_unlock (info->mutex); 156 157 g_mutex_free (info->mutex); 158 g_cond_free (info->condition); 159 160 g_slice_free (ErrorInfo, info); 139 161 140 162 return; … … 275 297 TnyList *list = NULL; 276 298 TnyDevice *device = info->device; 299 GHashTable *failed_headers; 277 300 278 301 priv->is_running = TRUE; … … 317 340 g_object_unref (list); 318 341 319 priv->do_continue = TRUE;320 321 while ( length > 0 && priv->do_continue&& tny_device_is_online (device))342 failed_headers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); 343 344 while ((length - g_hash_table_size (failed_headers)) > 0 && tny_device_is_online (device)) 322 345 { 323 346 TnyHeader *header = NULL; … … 369 392 g_object_unref (giter); 370 393 394 /* Some code to remove the previously failed items */ 395 giter = tny_list_create_iterator (headers); 396 while (!tny_iterator_is_done (giter)) 397 { 398 TnyHeader *curhdr = TNY_HEADER (tny_iterator_get_current (giter)); 399 400 if (g_hash_table_lookup_extended (failed_headers, tny_header_get_uid (curhdr), 401 NULL, NULL)) 402 to_remove = g_list_prepend (to_remove, curhdr); 403 404 g_object_unref (curhdr); 405 tny_iterator_next (giter); 406 } 407 g_object_unref (giter); 408 371 409 while (to_remove) { 372 410 tny_list_remove (headers, G_OBJECT (to_remove->data)); … … 413 451 if (err != NULL) { 414 452 emit_error (self, header, msg, err, i, priv->total); 415 priv->do_continue = FALSE; 453 g_hash_table_insert (failed_headers, 454 g_strdup (tny_header_get_uid (header)), NULL); 416 455 } 417 456 } else { 418 457 emit_error (self, header, msg, err, i, priv->total); 419 priv->do_continue = FALSE; 458 g_hash_table_insert (failed_headers, 459 g_strdup (tny_header_get_uid (header)), NULL); 420 460 } 421 461 … … 428 468 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN); 429 469 tny_folder_transfer_msgs (outbox, hassent, sentbox, TRUE, &newerr); 430 if (newerr != NULL) 431 { 470 if (newerr != NULL) { 432 471 emit_error (self, header, msg, newerr, i, priv->total); 433 priv->do_continue = FALSE;434 472 g_error_free (newerr); 435 473 } … … 466 504 } 467 505 506 errorhandler: 507 468 508 priv->is_running = FALSE; 469 509 470 errorhandler: 471 472 priv->is_running = FALSE; 510 g_hash_table_destroy (failed_headers); 473 511 474 512 g_object_unref (sentbox); … … 507 545 508 546 static void 509 tny_camel_send_queue_cancel (TnySendQueue *self, gboolean remove, GError **err)510 { 511 TNY_CAMEL_SEND_QUEUE_GET_CLASS (self)->cancel_func (self, remove, err);512 } 513 514 static void 515 tny_camel_send_queue_cancel_default (TnySendQueue *self, gboolean remove, GError **err)547 tny_camel_send_queue_cancel (TnySendQueue *self, TnySendQueueCancelAction cancel_action, GError **err) 548 { 549 TNY_CAMEL_SEND_QUEUE_GET_CLASS (self)->cancel_func (self, cancel_action, err); 550 } 551 552 static void 553 tny_camel_send_queue_cancel_default (TnySendQueue *self, TnySendQueueCancelAction cancel_action, GError **err) 516 554 { 517 555 TnyCamelSendQueuePriv *priv = TNY_CAMEL_SEND_QUEUE_GET_PRIVATE (self); 556 TnyFolder *outbox; 557 TnyList *headers = tny_simple_list_new (); 558 TnyIterator *iter; 518 559 519 560 g_mutex_lock (priv->sending_lock); 520 561 521 562 priv->is_running = FALSE; 522 priv->do_continue = FALSE; 523 524 if (remove) 525 { 526 TnyFolder *outbox; 527 TnyList *headers = tny_simple_list_new (); 528 TnyIterator *iter; 529 530 outbox = tny_send_queue_get_outbox (self); 531 532 tny_folder_get_headers (outbox, headers, TRUE, err); 533 563 564 outbox = tny_send_queue_get_outbox (self); 565 566 tny_folder_get_headers (outbox, headers, TRUE, err); 567 568 if (err != NULL && *err != NULL) 569 { 570 g_object_unref (headers); 571 g_object_unref (outbox); 572 g_mutex_unlock (priv->sending_lock); 573 return; 574 } 575 576 iter = tny_list_create_iterator (headers); 577 while (!tny_iterator_is_done (iter)) 578 { 579 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter)); 580 581 /* Remove or suspend the message */ 582 if (cancel_action == TNY_SEND_QUEUE_CANCEL_ACTION_REMOVE) 583 tny_folder_remove_msg (outbox, header, err); 584 else if (cancel_action == TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND) 585 tny_header_set_flag (header, TNY_HEADER_FLAG_SUSPENDED); 586 534 587 if (err != NULL && *err != NULL) 535 588 { 589 g_object_unref (header); 590 g_object_unref (iter); 536 591 g_object_unref (headers); 537 592 g_object_unref (outbox); … … 540 595 } 541 596 542 iter = tny_list_create_iterator (headers); 543 544 while (!tny_iterator_is_done (iter)) 545 { 546 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter)); 547 tny_folder_remove_msg (outbox, header, err); 548 549 if (err != NULL && *err != NULL) 550 { 551 g_object_unref (header); 552 g_object_unref (iter); 553 g_object_unref (headers); 554 g_object_unref (outbox); 555 g_mutex_unlock (priv->sending_lock); 556 return; 557 } 558 559 g_object_unref (header); 560 tny_iterator_next (iter); 561 } 562 g_object_unref (iter); 563 g_object_unref (headers); 564 565 tny_folder_sync (outbox, TRUE, err); 566 g_object_unref (outbox); 567 } 597 g_object_unref (header); 598 tny_iterator_next (iter); 599 } 600 g_object_unref (iter); 601 g_object_unref (headers); 602 603 tny_folder_sync (outbox, TRUE, err); 604 g_object_unref (outbox); 568 605 569 606 g_mutex_unlock (priv->sending_lock); … … 1053 1090 priv->todo_lock = g_mutex_new (); 1054 1091 priv->sending_lock = g_mutex_new (); 1055 priv->do_continue = FALSE;1056 1092 priv->is_running = FALSE; 1057 1093 priv->thread = NULL; trunk/libtinymail-camel/tny-camel-send-queue.h
r2825 r3283 53 53 TnyFolder* (*get_sentbox_func) (TnySendQueue *self); 54 54 TnyFolder* (*get_outbox_func) (TnySendQueue *self); 55 void (*cancel_func) (TnySendQueue *self, gboolean remove, GError **err);55 void (*cancel_func) (TnySendQueue *self, TnySendQueueCancelAction cancel_action, GError **err); 56 56 57 57 void (*add_async_func) (TnyCamelSendQueue *self, TnyMsg *msg, TnySendQueueAddCallback callback, TnyStatusCallback status_callback, gpointer user_data); trunk/libtinymail/tny-send-queue.c
r3161 r3283 39 39 * tny_send_queue_cancel: 40 40 * @self: a #TnySendQueue 41 * @ remove: also remove queued messages41 * @cancel_action: a #TnySendQueueCancelAction, it could remove messages or just mark them as suspended 42 42 * @err: (null-ok): a #GError or NULL 43 43 * … … 48 48 **/ 49 49 void 50 tny_send_queue_cancel (TnySendQueue *self, gboolean remove, GError **err)50 tny_send_queue_cancel (TnySendQueue *self, TnySendQueueCancelAction cancel_action, GError **err) 51 51 { 52 52 #ifdef DBC /* require */ … … 55 55 #endif 56 56 57 TNY_SEND_QUEUE_GET_IFACE (self)->cancel_func (self, remove, err);57 TNY_SEND_QUEUE_GET_IFACE (self)->cancel_func (self, cancel_action, err); 58 58 return; 59 59 } trunk/libtinymail/tny-send-queue.h
r2825 r3283 49 49 }; 50 50 51 typedef enum 52 { 53 TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, 54 TNY_SEND_QUEUE_CANCEL_ACTION_REMOVE 55 } TnySendQueueCancelAction; 56 51 57 extern guint tny_send_queue_signals[TNY_SEND_QUEUE_LAST_SIGNAL]; 52 58 … … 65 71 TnyFolder* (*get_sentbox_func) (TnySendQueue *self); 66 72 TnyFolder* (*get_outbox_func) (TnySendQueue *self); 67 void (*cancel_func) (TnySendQueue *self, gboolean remove, GError **err);73 void (*cancel_func) (TnySendQueue *self, TnySendQueueCancelAction cancel_action, GError **err); 68 74 69 75 }; … … 74 80 TnyFolder* tny_send_queue_get_sentbox (TnySendQueue *self); 75 81 TnyFolder* tny_send_queue_get_outbox (TnySendQueue *self); 76 void tny_send_queue_cancel (TnySendQueue *self, gboolean remove, GError **err);82 void tny_send_queue_cancel (TnySendQueue *self, TnySendQueueCancelAction cancel_action, GError **err); 77 83 78 84 G_END_DECLS
