7c753278db1e0596430999673d4545658758a105 src/biff.cc | 23 ++++++++++++++++++++--- src/imap4.cc | 6 +++--- src/local.cc | 24 ++++++++++++++---------- src/pop.cc | 8 ++++---- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/biff.cc b/src/biff.cc index 60cf9d3..142770e 100644 --- a/src/biff.cc +++ b/src/biff.cc @@ -322,6 +322,23 @@ Biff::get_number_of_unread_messages (guint &num) return newmail; } +struct temp_mailbox_struct { + Applet * applet ; + Mailbox * mailbox ; + temp_mailbox_struct(Applet *a, Mailbox *m) : applet(a), mailbox(m) {} +}; + +gboolean +get_mailbox_password_in_main_thread (gpointer user_data) +{ + temp_mailbox_struct * temp = (temp_mailbox_struct*)user_data; + Applet * applet_ = temp->applet; + Mailbox * m = temp->mailbox; + delete temp; + applet_->get_password_for_mailbox (m); + return G_SOURCE_REMOVE ; +} + /** * Determine if a password for the given mailbox {\em m} exists. If no * password exists yet this function tries to obtain it by: @@ -365,9 +382,9 @@ Biff::get_password_for_mailbox (Mailbox *m) // Ask the user if password is still not known if (m->password().empty()) { - gdk_threads_enter (); - applet_->get_password_for_mailbox (m); - gdk_threads_leave (); + temp_mailbox_struct * t = new temp_mailbox_struct(applet_,m); + g_idle_add(get_mailbox_password_in_main_thread,(gpointer)t); + } g_mutex_unlock (auth_mutex_); diff --git a/src/imap4.cc b/src/imap4.cc index dbcb9e4..9d30acc 100644 --- a/src/imap4.cc +++ b/src/imap4.cc @@ -179,6 +179,8 @@ Imap4::fetch (void) /* throw(imap_err) */ command_logout(); } +gboolean update_applet_in_main_thread (gpointer user_data); + /** * Update the applet with any new information about this mailbox. This * includes new or removed mail, for a new mail count. @@ -186,9 +188,7 @@ Imap4::fetch (void) /* throw(imap_err) */ void Imap4::update_applet (void) { - gdk_threads_enter(); - biff_->applet()->update(); - gdk_threads_leave(); + g_idle_add(update_applet_in_main_thread,biff_); } /** diff --git a/src/local.cc b/src/local.cc index fb969a0..32baa57 100644 --- a/src/local.cc +++ b/src/local.cc @@ -73,6 +73,14 @@ Local::~Local (void) g_mutex_free (fam_mutex_); } +gboolean +update_applet_in_main_thread(gpointer user_data) +{ + Biff * biff_ = (Biff*) user_data; + biff_->applet()->update (); + return G_SOURCE_REMOVE ; +} + // ======================================================================== // main // ======================================================================== @@ -94,9 +102,8 @@ Local::start (void) else { try { start_checking (); - gdk_threads_enter(); - biff_->applet()->update(); - gdk_threads_leave(); + g_idle_add(update_applet_in_main_thread,biff_); + } catch (local_err &err) { // Catch all errors that are un-recoverable @@ -325,10 +332,8 @@ Local::fam_monitoring (void) /* throw(local_err) */ // monitoring will start from now on. Even if the mailbox was full, // no change appears yet, so we force it. start_checking (); - gdk_threads_enter(); - biff_->applet()->update(); - gdk_threads_leave(); - + g_idle_add(update_applet_in_main_thread,biff_); + // Wait for and handle FAM events status = 1; while (status == 1) { @@ -351,9 +356,8 @@ Local::fam_monitoring (void) /* throw(local_err) */ || (fam_event_.code == FAMCreated) || (fam_event_.code == FAMDeleted)) { start_checking (); - gdk_threads_enter(); - biff_->applet()->update(); - gdk_threads_leave(); + g_idle_add(update_applet_in_main_thread,biff_); + } else if (fam_event_.code == FAMAcknowledge) break; diff --git a/src/pop.cc b/src/pop.cc index f2278b0..c29807b 100644 --- a/src/pop.cc +++ b/src/pop.cc @@ -89,6 +89,8 @@ Pop::threaded_start (guint delay) Mailbox::threaded_start (delay); } +gboolean update_applet_in_main_thread(gpointer user_data); + /** * Method to be called by a new thread for monitoring the mailbox. The status * of the mailbox will be updated, new mails fetched and idle state entered @@ -117,10 +119,8 @@ Pop::start (void) /* throw(pop_err) */ socket_->close (); } - gdk_threads_enter (); - biff_->applet()->update (); - gdk_threads_leave (); - + g_idle_add(update_applet_in_main_thread,biff_); + g_mutex_unlock (monitor_mutex_); threaded_start (delay());