Changeset 2444
- Timestamp:
- 07/10/07 16:29:30
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/libtinymail-camel/tny-camel-account.c (modified) (1 diff)
- trunk/libtinymail-camel/tny-session-camel-priv.h (modified) (1 diff)
- trunk/libtinymail-camel/tny-session-camel.c (modified) (13 diffs)
- trunk/libtinymail-camel/tny-session-camel.h (modified) (1 diff)
- trunk/libtinymail-gnome-desktop/tny-gnome-account-store.c (modified) (1 diff)
- trunk/libtinymail-gnome-desktop/tny-gnome-device.c (modified) (2 diffs)
- trunk/libtinymail-gpe/tny-gpe-account-store.c (modified) (1 diff)
- trunk/libtinymail-maemo/tny-maemo-account-store.c (modified) (1 diff)
- trunk/libtinymail-olpc/tny-olpc-account-store.c (modified) (1 diff)
- trunk/libtinymail/tny-account-store.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r2443 r2444 1 2007-07-10 Philip Van Hoof <pvanhoof@gnome.org> 2 3 * Made the connecting of accounts more finegrained (once more) 4 * Introduced the required tny_session_camel_set_initialized API 5 6 * This was a major change in behaviour when connecting and at 7 initialization 8 * This was a major API change 9 1 10 2007-07-10 Murray Cumming <murrayc@murrayc.com> 2 11 trunk/libtinymail-camel/tny-camel-account.c
r2437 r2444 148 148 camel_exception_clear (&ex); 149 149 150 camel_service_connect (apriv->service, &ex);150 camel_service_connect (apriv->service, apriv->ex); 151 151 if (apriv->service->reconnection) 152 152 { 153 if (!camel_exception_is_set ( &ex))153 if (!camel_exception_is_set (apriv->ex)) 154 154 apriv->service->reconnection (apriv->service, TRUE, apriv->service->data); 155 155 else trunk/libtinymail-camel/tny-session-camel-priv.h
r2423 r2444 17 17 GMutex *conlock, *queue_lock; 18 18 GThread *conthread; 19 gboolean stop_now, initialized; 19 20 gboolean is_inuse, background_thread_running; 20 21 GList *regged_queues; trunk/libtinymail-camel/tny-session-camel.c
r2443 r2444 113 113 114 114 if (cancel || retval == NULL) { 115 116 GError *err = NULL; 117 118 _tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (account), FALSE, &err); 119 120 if (err) 121 g_error_free (err); 122 115 123 camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, 116 124 _("You cancelled when you had to enter a password")); … … 375 383 priv = instance->priv; 376 384 385 priv->initialized = FALSE; 386 priv->stop_now = FALSE; 377 387 priv->regged_queues = NULL; 378 388 priv->background_thread_running = FALSE; … … 394 404 } 395 405 396 void397 _tny_session_camel_add_account (TnySessionCamel *self, TnyCamelAccount *account)398 {399 TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (account);400 TnySessionCamelPriv *priv = self->priv;401 402 if (apriv->cache_location)403 g_free (apriv->cache_location);404 apriv->cache_location = g_strdup (priv->camel_dir);405 406 priv->current_accounts = g_list_prepend (priv->current_accounts, account);407 }408 409 void410 _tny_session_camel_forget_account (TnySessionCamel *self, TnyCamelAccount *account)411 {412 TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (account);413 TnySessionCamelPriv *priv = self->priv;414 415 if (apriv->cache_location)416 g_free (apriv->cache_location);417 apriv->cache_location = NULL;418 419 priv->current_accounts = g_list_remove (priv->current_accounts, account);420 421 return;422 }423 424 406 typedef struct 425 407 { … … 429 411 TnySessionCamelPriv *priv; 430 412 } BackgroundConnectInfo; 413 414 static gboolean 415 background_connect_idle (gpointer data) 416 { 417 BackgroundConnectInfo *info = data; 418 TnySessionCamel *self = info->user_data; 419 TnySessionCamelPriv *priv = self->priv; 420 421 if (priv->account_store) 422 { 423 g_signal_emit (priv->account_store, 424 tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNTS_RELOADED], 0); 425 g_signal_emit (priv->account_store, 426 tny_account_store_signals [TNY_ACCOUNT_STORE_CONNECTING_FINISHED], 0); 427 } 428 429 return FALSE; 430 } 431 432 433 434 static void 435 background_connect_destroy (gpointer data) 436 { 437 BackgroundConnectInfo *info = data; 438 439 g_object_unref (G_OBJECT (info->device)); 440 g_slice_free (BackgroundConnectInfo, data); 441 442 return; 443 } 444 445 431 446 432 447 static void … … 455 470 apriv->is_connecting = TRUE; 456 471 457 _tny_camel_account_try_connect (account, info->online, &err);472 _tny_camel_account_try_connect (account, FALSE /* info->online */, &err); 458 473 459 474 if (err == NULL) … … 480 495 } 481 496 482 483 static void 484 background_connect_destroy (gpointer data) 485 { 486 BackgroundConnectInfo *info = data; 487 488 g_object_unref (G_OBJECT (info->device)); 489 g_slice_free (BackgroundConnectInfo, data); 490 491 return; 492 } 493 494 static gboolean 495 background_connect_idle (gpointer data) 496 { 497 BackgroundConnectInfo *info = data; 498 TnySessionCamel *self = info->user_data; 499 TnySessionCamelPriv *priv = self->priv; 500 501 if (priv->account_store) 502 { 503 g_signal_emit (priv->account_store, 504 tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNTS_RELOADED], 0); 505 g_signal_emit (priv->account_store, 506 tny_account_store_signals [TNY_ACCOUNT_STORE_CONNECTING_FINISHED], 0); 507 } 508 509 return FALSE; 510 } 497 typedef struct { 498 BackgroundConnectInfo *info; 499 TnyCamelAccount *account; 500 } AccGoOnlineInfo; 501 502 static gpointer 503 account_go_online (gpointer data) 504 { 505 AccGoOnlineInfo *ainfo = (AccGoOnlineInfo *) data; 506 TnySessionCamel *self = ainfo->info->user_data; 507 TnySessionCamelPriv *priv = self->priv; 508 509 priv->is_connecting = TRUE; 510 511 foreach_account_set_connectivity (ainfo->account, ainfo->info); 512 513 priv->is_connecting = FALSE; 514 515 camel_object_unref (ainfo->info->user_data); 516 g_object_unref (ainfo->account); 517 518 g_idle_add_full (G_PRIORITY_HIGH, 519 background_connect_idle, 520 ainfo->info, background_connect_destroy); 521 522 g_slice_free (AccGoOnlineInfo, ainfo); 523 /* ainfo->info is freed in the background_connect_destroy */ 524 525 g_thread_exit (NULL); 526 return NULL; 527 } 528 529 530 void 531 _tny_session_camel_add_account (TnySessionCamel *self, TnyCamelAccount *account) 532 { 533 TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (account); 534 TnySessionCamelPriv *priv = self->priv; 535 gboolean doit = FALSE; 536 537 if (priv->initialized) 538 { 539 g_mutex_lock (priv->conlock); 540 doit = (priv->conthread == NULL); 541 g_mutex_unlock (priv->conlock); 542 } 543 544 if (apriv->cache_location) 545 g_free (apriv->cache_location); 546 apriv->cache_location = g_strdup (priv->camel_dir); 547 priv->current_accounts = g_list_prepend (priv->current_accounts, account); 548 549 if (priv->initialized && !priv->background_thread_running && doit) 550 { 551 if (priv->device && TNY_IS_DEVICE (priv->device)) 552 { 553 AccGoOnlineInfo *ainfo = g_slice_new (AccGoOnlineInfo); 554 ainfo->info = g_slice_new (BackgroundConnectInfo); 555 556 ainfo->info->online = tny_device_is_online (priv->device); 557 ainfo->info->as_thread = TRUE; 558 ainfo->info->priv = priv; 559 560 ainfo->info->device = g_object_ref (priv->device); 561 camel_object_ref (self); 562 ainfo->info->user_data = self; 563 ainfo->account = TNY_CAMEL_ACCOUNT (g_object_ref (account)); 564 565 camel_session_set_online ((CamelSession *) self, TRUE); 566 567 if (priv->account_store) 568 { 569 g_signal_emit (priv->account_store, 570 tny_account_store_signals [TNY_ACCOUNT_STORE_CONNECTING_STARTED], 0); 571 } 572 573 g_mutex_lock (priv->conlock); 574 if (priv->conthread) 575 g_thread_join (priv->conthread); 576 priv->conthread = g_thread_create (account_go_online, ainfo, TRUE, NULL); 577 g_mutex_unlock (priv->conlock); 578 } 579 } 580 } 581 582 void 583 _tny_session_camel_forget_account (TnySessionCamel *self, TnyCamelAccount *account) 584 { 585 TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (account); 586 TnySessionCamelPriv *priv = self->priv; 587 588 if (apriv->cache_location) 589 g_free (apriv->cache_location); 590 apriv->cache_location = NULL; 591 592 priv->current_accounts = g_list_remove (priv->current_accounts, account); 593 594 return; 595 } 596 597 598 511 599 512 600 static gpointer … … 524 612 priv->background_thread_running = TRUE; 525 613 526 g_mutex_lock (priv->queue_lock); 527 /*g_list_foreach (priv->regged_queues, (GFunc) 528 tny_camel_send_queue_join_worker, NULL);*/ 529 g_mutex_unlock (priv->queue_lock); 614 if (priv->stop_now) 615 goto stop_now; 530 616 531 617 priv->is_connecting = TRUE; 532 618 533 if (priv->current_accounts && priv->prev_constat != info->online && priv->account_store) { 534 g_list_foreach (priv->current_accounts, 535 foreach_account_set_connectivity, info); 536 } 619 if (priv->current_accounts && priv->prev_constat != info->online && priv->account_store) 620 { 621 GList *copy = priv->current_accounts; 622 while (copy) 623 { 624 if (priv->stop_now) 625 goto stop_now; 626 foreach_account_set_connectivity (copy->data, info); 627 if (priv->stop_now) 628 goto stop_now; 629 copy = g_list_next (copy); 630 } 631 } 632 633 stop_now: 537 634 538 635 priv->is_connecting = FALSE; … … 544 641 priv->prev_constat = info->online; 545 642 546 g_mutex_lock (priv->conlock);547 643 priv->conthread = NULL; 548 g_mutex_unlock (priv->conlock);549 550 644 priv->background_thread_running = FALSE; 645 646 priv->stop_now = FALSE; 551 647 552 648 g_thread_exit (NULL); … … 555 651 556 652 static gboolean 557 d elayed_background_connect_thread (gpointer data)653 do_background_connect_thread (gpointer data) 558 654 { 559 655 BackgroundConnectInfo *info = data; 656 TnySessionCamel *self = info->user_data; 657 TnySessionCamelPriv *priv = self->priv; 560 658 561 659 g_mutex_lock (info->priv->conlock); … … 567 665 568 666 static void 569 connection_changed (TnyDevice *device, gboolean online, gpointer user_data)667 tny_session_camel_connection_changed (TnyDevice *device, gboolean online, gpointer user_data) 570 668 { 571 669 TnySessionCamel *self = user_data; … … 593 691 594 692 595 if (priv->async_connect) { 693 if (priv->async_connect) 694 { 695 gboolean doit = FALSE; 696 596 697 info->as_thread = TRUE; 597 698 598 699 g_mutex_lock (priv->conlock); 599 if (priv->conthread) 600 g_timeout_add (5000, delayed_background_connect_thread, info); 601 else 602 priv->conthread = g_thread_create (background_connect_thread, info, TRUE, NULL); 700 doit = (priv->conthread == NULL); 603 701 g_mutex_unlock (priv->conlock); 702 703 if (doit) 704 do_background_connect_thread (info); 604 705 605 706 } else { … … 628 729 } 629 730 630 /* 631 static gboolean 632 emit_accounts_reloaded (gpointer user_data) 633 { 634 g_signal_emit (G_OBJECT (user_data), 635 tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNTS_RELOADED], 0); 636 return FALSE; 637 } 638 */ 639 640 static gboolean 641 after_one_second (gpointer data) 642 { 643 TnySessionCamel *self = data; 644 TnySessionCamelPriv *priv = self->priv; 645 646 if (priv->device && TNY_IS_DEVICE (priv->device) && tny_device_is_online (priv->device)) 647 connection_changed (priv->device, TRUE, self); 648 649 camel_object_unref (self); 650 651 return FALSE; 731 /** 732 * tny_session_camel_set_initialized: 733 * @self: the #TnySessionCamel instance 734 * 735 * This method must be called one the initial accounts are created in your 736 * #TnyAccountStore implementation. 737 **/ 738 void 739 tny_session_camel_set_initialized (TnySessionCamel *self) 740 { 741 TnySessionCamelPriv *priv = self->priv; 742 TnyDevice *device = NULL; 743 744 if (priv->initialized) 745 return; 746 747 device = priv->device; 748 749 if (!device || !TNY_IS_DEVICE (device)) 750 { 751 g_critical ("Please use tny_session_camel_set_device " 752 "before tny_session_camel_set_initialized"); 753 return; 754 } 755 756 priv->initialized = TRUE; 757 758 priv->connchanged_signal = g_signal_connect ( 759 G_OBJECT (device), "connection_changed", 760 G_CALLBACK (tny_session_camel_connection_changed), self); 761 762 tny_session_camel_connection_changed (device, 763 tny_device_is_online (device), self); 652 764 } 653 765 … … 673 785 674 786 priv->device = device; 675 priv->connchanged_signal = g_signal_connect (676 G_OBJECT (device), "connection_changed",677 G_CALLBACK (connection_changed), self);678 679 if (tny_device_is_online (device) == FALSE)680 {681 priv->prev_constat = TRUE;682 connection_changed (device, FALSE, self);683 } else {684 priv->prev_constat = FALSE;685 camel_object_ref (self);686 g_timeout_add (5000, after_one_second, self);687 }688 787 689 788 return; trunk/libtinymail-camel/tny-session-camel.h
r1521 r2444 55 55 void tny_session_camel_set_async_connecting (TnySessionCamel *self, gboolean enable); 56 56 57 void tny_session_camel_set_initialized (TnySessionCamel *self); 58 57 59 G_END_DECLS 58 60 trunk/libtinymail-gnome-desktop/tny-gnome-account-store.c
r2443 r2444 324 324 g_free (proto); 325 325 } 326 327 tny_session_camel_set_initialized (priv->session); 326 328 } 327 329 trunk/libtinymail-gnome-desktop/tny-gnome-device.c
r2384 r2444 167 167 } 168 168 169 /* #define IMMEDIATE_ONLINE_TEST */ 169 170 170 171 static void … … 177 178 priv->forced = FALSE; 178 179 180 #ifdef IMMEDIATE_ONLINE_TEST 181 priv->fset = TRUE; 182 priv->forced = TRUE; 183 #endif 184 179 185 #ifdef GNOME 180 186 priv->invnm = FALSE; 181 187 priv->nm_ctx = libnm_glib_init (); 188 #ifndef IMMEDIATE_ONLINE_TEST 182 189 priv->callback_id = libnm_glib_register_callback 183 190 (priv->nm_ctx, nm_callback, self, NULL); 191 #endif 184 192 #endif 185 193 trunk/libtinymail-gpe/tny-gpe-account-store.c
r2443 r2444 323 323 if (mech) 324 324 g_free (mech); 325 326 } 325 } 326 327 tny_session_camel_set_initialized (priv->session); 328 327 329 } 328 330 trunk/libtinymail-maemo/tny-maemo-account-store.c
r2443 r2444 328 328 if (mech) 329 329 g_free (mech); 330 331 } 330 } 331 332 tny_session_camel_set_initialized (priv->session); 332 333 } 333 334 trunk/libtinymail-olpc/tny-olpc-account-store.c
r2443 r2444 280 280 } 281 281 g_dir_close (dir); 282 283 tny_session_camel_set_initialized (priv->session); 282 284 } 283 285 trunk/libtinymail/tny-account-store.c
r2443 r2444 273 273 * register the created accounts with a #TnySessionCamel instance using the 274 274 * libtinymail-camel specific tny_session_camel_set_current_accounts API. 275 * 276 * If you use the #TnySessionCamel to register accounts, you must after 277 * registering your last initial account call the tny_session_camel_set_initialized 278 * API. 275 279 * 276 280 * The implementation must fillup @list with available accounts. Note that if … … 340 344 * } 341 345 * g_object_unref (G_OBJECT (iter)); 346 * tny_session_camel_set_initialized (session); 342 347 * } 343 348 * </programlisting></informalexample>
