| | 393 | |
|---|
| | 394 | |
|---|
| | 395 | typedef struct { |
|---|
| | 396 | TnyFolder *from, *to; |
|---|
| | 397 | TnyList *list; |
|---|
| | 398 | GError **err; |
|---|
| | 399 | |
|---|
| | 400 | GCond* condition; |
|---|
| | 401 | gboolean had_callback; |
|---|
| | 402 | GMutex *mutex; |
|---|
| | 403 | |
|---|
| | 404 | } TransferSync; |
|---|
| | 405 | |
|---|
| | 406 | static void |
|---|
| | 407 | transfer_async (TnyFolder *folder, gboolean cancelled, GError *err, gpointer user_data) |
|---|
| | 408 | { |
|---|
| | 409 | TransferSync *info = (TransferSync *) user_data; |
|---|
| | 410 | |
|---|
| | 411 | if (err && info->err) |
|---|
| | 412 | *info->err = g_error_copy (err); |
|---|
| | 413 | |
|---|
| | 414 | g_mutex_lock (info->mutex); |
|---|
| | 415 | g_cond_broadcast (info->condition); |
|---|
| | 416 | info->had_callback = TRUE; |
|---|
| | 417 | g_mutex_unlock (info->mutex); |
|---|
| | 418 | } |
|---|
| | 419 | |
|---|
| | 420 | static void |
|---|
| | 421 | transfer_sync (TnyFolder *from, TnyList *list, TnyFolder *to, gboolean delete_originals, GError **err) |
|---|
| | 422 | { |
|---|
| | 423 | TransferSync *info = g_slice_new0 (TransferSync); |
|---|
| | 424 | |
|---|
| | 425 | info->mutex = g_mutex_new (); |
|---|
| | 426 | info->condition = g_cond_new (); |
|---|
| | 427 | info->had_callback = FALSE; |
|---|
| | 428 | |
|---|
| | 429 | info->from = g_object_ref (from); |
|---|
| | 430 | info->to = g_object_ref (from); |
|---|
| | 431 | info->list = g_object_ref (list); |
|---|
| | 432 | info->err = err; |
|---|
| | 433 | |
|---|
| | 434 | tny_folder_transfer_msgs_async (info->from, info->list, info->to, |
|---|
| | 435 | delete_originals, transfer_async, NULL, info); |
|---|
| | 436 | |
|---|
| | 437 | g_mutex_lock (info->mutex); |
|---|
| | 438 | if (!info->had_callback) |
|---|
| | 439 | g_cond_wait (info->condition, info->mutex); |
|---|
| | 440 | g_mutex_unlock (info->mutex); |
|---|
| | 441 | |
|---|
| | 442 | g_mutex_free (info->mutex); |
|---|
| | 443 | g_cond_free (info->condition); |
|---|
| | 444 | |
|---|
| | 445 | g_object_unref (info->from); |
|---|
| | 446 | g_object_unref (info->to); |
|---|
| | 447 | g_object_unref (info->list); |
|---|
| | 448 | g_slice_free (TransferSync, info); |
|---|
| | 449 | } |
|---|
| | 450 | |
|---|
| | 451 | |
|---|
| | 452 | typedef struct { |
|---|
| | 453 | TnyFolder *folder; |
|---|
| | 454 | TnyHeader *header; |
|---|
| | 455 | TnyMsg *msg; |
|---|
| | 456 | GError **err; |
|---|
| | 457 | |
|---|
| | 458 | GCond* condition; |
|---|
| | 459 | gboolean had_callback; |
|---|
| | 460 | GMutex *mutex; |
|---|
| | 461 | |
|---|
| | 462 | } GetSync; |
|---|
| | 463 | |
|---|
| | 464 | static void |
|---|
| | 465 | get_async (TnyFolder *folder, gboolean cancelled, TnyMsg *msg, GError *err, gpointer user_data) |
|---|
| | 466 | { |
|---|
| | 467 | GetSync *info = (GetSync *) user_data; |
|---|
| | 468 | |
|---|
| | 469 | if (err && info->err) |
|---|
| | 470 | *info->err = g_error_copy (err); |
|---|
| | 471 | |
|---|
| | 472 | if (msg) |
|---|
| | 473 | info->msg = g_object_ref (msg); |
|---|
| | 474 | |
|---|
| | 475 | g_mutex_lock (info->mutex); |
|---|
| | 476 | g_cond_broadcast (info->condition); |
|---|
| | 477 | info->had_callback = TRUE; |
|---|
| | 478 | g_mutex_unlock (info->mutex); |
|---|
| | 479 | } |
|---|
| | 480 | |
|---|
| | 481 | static TnyMsg* |
|---|
| | 482 | get_sync (TnyFolder *folder, TnyHeader *header, GError **err) |
|---|
| | 483 | { |
|---|
| | 484 | GetSync *info = g_slice_new0 (GetSync); |
|---|
| | 485 | TnyMsg *retval = NULL; |
|---|
| | 486 | |
|---|
| | 487 | info->mutex = g_mutex_new (); |
|---|
| | 488 | info->condition = g_cond_new (); |
|---|
| | 489 | info->had_callback = FALSE; |
|---|
| | 490 | |
|---|
| | 491 | info->folder = g_object_ref (folder); |
|---|
| | 492 | info->header = g_object_ref (header); |
|---|
| | 493 | info->err = err; |
|---|
| | 494 | |
|---|
| | 495 | tny_folder_get_msg_async (info->folder, info->header, |
|---|
| | 496 | get_async, NULL, info); |
|---|
| | 497 | |
|---|
| | 498 | g_mutex_lock (info->mutex); |
|---|
| | 499 | if (!info->had_callback) |
|---|
| | 500 | g_cond_wait (info->condition, info->mutex); |
|---|
| | 501 | g_mutex_unlock (info->mutex); |
|---|
| | 502 | |
|---|
| | 503 | g_mutex_free (info->mutex); |
|---|
| | 504 | g_cond_free (info->condition); |
|---|
| | 505 | |
|---|
| | 506 | if (info->msg) |
|---|
| | 507 | retval = g_object_ref (info->msg); |
|---|
| | 508 | |
|---|
| | 509 | g_object_unref (info->folder); |
|---|
| | 510 | g_object_unref (info->header); |
|---|
| | 511 | g_object_unref (info->msg); |
|---|
| | 512 | |
|---|
| | 513 | g_slice_free (GetSync, info); |
|---|
| | 514 | return retval; |
|---|
| | 515 | } |
|---|
| | 516 | |
|---|
| | 517 | |
|---|
| | 518 | |
|---|
| | 519 | |
|---|
| | 520 | typedef struct { |
|---|
| | 521 | TnyFolder *folder; |
|---|
| | 522 | GError **err; |
|---|
| | 523 | |
|---|
| | 524 | GCond* condition; |
|---|
| | 525 | gboolean had_callback; |
|---|
| | 526 | GMutex *mutex; |
|---|
| | 527 | |
|---|
| | 528 | } SyncSync; |
|---|
| | 529 | |
|---|
| | 530 | static void |
|---|
| | 531 | sync_async (TnyFolder *folder, gboolean cancelled, GError *err, gpointer user_data) |
|---|
| | 532 | { |
|---|
| | 533 | SyncSync *info = (SyncSync *) user_data; |
|---|
| | 534 | |
|---|
| | 535 | if (err && info->err) |
|---|
| | 536 | *info->err = g_error_copy (err); |
|---|
| | 537 | |
|---|
| | 538 | g_mutex_lock (info->mutex); |
|---|
| | 539 | g_cond_broadcast (info->condition); |
|---|
| | 540 | info->had_callback = TRUE; |
|---|
| | 541 | g_mutex_unlock (info->mutex); |
|---|
| | 542 | } |
|---|
| | 543 | |
|---|
| | 544 | static void |
|---|
| | 545 | sync_sync (TnyFolder *self, gboolean expunge, GError **err) |
|---|
| | 546 | { |
|---|
| | 547 | SyncSync *info = g_slice_new0 (SyncSync); |
|---|
| | 548 | |
|---|
| | 549 | info->mutex = g_mutex_new (); |
|---|
| | 550 | info->condition = g_cond_new (); |
|---|
| | 551 | info->had_callback = FALSE; |
|---|
| | 552 | |
|---|
| | 553 | info->folder = g_object_ref (self); |
|---|
| | 554 | info->err = err; |
|---|
| | 555 | |
|---|
| | 556 | tny_folder_sync_async (info->folder, expunge, sync_async, NULL, info); |
|---|
| | 557 | |
|---|
| | 558 | g_mutex_lock (info->mutex); |
|---|
| | 559 | if (!info->had_callback) |
|---|
| | 560 | g_cond_wait (info->condition, info->mutex); |
|---|
| | 561 | g_mutex_unlock (info->mutex); |
|---|
| | 562 | |
|---|
| | 563 | g_mutex_free (info->mutex); |
|---|
| | 564 | g_cond_free (info->condition); |
|---|
| | 565 | |
|---|
| | 566 | g_object_unref (info->folder); |
|---|
| | 567 | g_slice_free (SyncSync, info); |
|---|
| | 568 | } |
|---|
| | 569 | |
|---|