[balsa] Manage sensitivity of "Get New Mail" action



commit 4fb60cf86d8c2a73fed4afc65a5c55e7b6925fdb
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Aug 19 19:14:10 2009 -0400

    Manage sensitivity of "Get New Mail" action

 ChangeLog         |    6 ++++++
 src/main-window.c |   26 +++++++++++++++++++++++---
 src/main.c        |    5 +++--
 3 files changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1e382aa..f081d2b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-08-19  Peter Bloomfield
 
+	* src/main-window.c: Manage sensitivity of "Get New Mail"
+	action.
+	* src/main.c (mw_message_received_cb, main): ditto.
+
+2009-08-19  Peter Bloomfield
+
 	Allow only one compose window per draft message.
 
 	* src/balsa-index.c (bndx_row_activated): check for NULL return
diff --git a/src/main-window.c b/src/main-window.c
index 0e1b803..2135c0b 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -102,7 +102,12 @@ GtkWidget *progress_dialog_bar = NULL;
 GSList *list = NULL;
 static int quiet_check=0;
 
-static void bw_check_messages_thread(GSList * list);
+struct check_messages_thread_info {
+    BalsaWindow *window;
+    GSList *list;
+};
+static void bw_check_messages_thread(struct check_messages_thread_info
+                                     *info);
 
 #endif
 static void bw_display_new_mail_notification(int num_new, int has_new);
@@ -1800,6 +1805,9 @@ balsa_window_new()
     g_signal_connect(window, "notify::is-active",
                      G_CALLBACK(bw_is_active_notify), NULL);
 
+    /* set initial state of Get-New-Mail button */
+    bw_set_sensitive(window, "GetNewMail", !checking_mail);
+
     gtk_widget_show(GTK_WIDGET(window));
     return GTK_WIDGET(window);
 }
@@ -2777,6 +2785,7 @@ check_new_messages_real(BalsaWindow * window, int type)
 {
     GSList *list = NULL;
 #ifdef BALSA_USE_THREADS
+    struct check_messages_thread_info *info;
     /*  Only Run once -- If already checking mail, return.  */
     pthread_mutex_lock(&mailbox_lock);
     if (checking_mail) {
@@ -2787,6 +2796,8 @@ check_new_messages_real(BalsaWindow * window, int type)
         return;
     }
     checking_mail = 1;
+    if (window)
+        bw_set_sensitive(window, "GetNewMail", FALSE);
 
     quiet_check = (type == TYPE_CALLBACK) 
         ? 0 : balsa_app.quiet_background_check;
@@ -2803,8 +2814,11 @@ check_new_messages_real(BalsaWindow * window, int type)
 			   &list);
 
     /* initiate threads */
+    info = g_new(struct check_messages_thread_info, 1);
+    info->list = list;
+    info->window = window ? g_object_ref(window) : window;
     pthread_create(&get_mail_thread,
-                   NULL, (void *) &bw_check_messages_thread, (void *) list);
+                   NULL, (void *) &bw_check_messages_thread, info);
     
     /* Detach so we don't need to pthread_join
      * This means that all resources will be
@@ -2952,7 +2966,7 @@ bw_mailbox_check(LibBalsaMailbox * mailbox)
 }
 
 static void
-bw_check_messages_thread(GSList * list)
+bw_check_messages_thread(struct check_messages_thread_info *info)
 {
     /*  
      *  It is assumed that this will always be called as a pthread,
@@ -2960,6 +2974,7 @@ bw_check_messages_thread(GSList * list)
      *  and set checking_mail to true before calling.
      */
     MailThreadMessage *threadmessage;
+    GSList *list = info->list;
     
     pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
 
@@ -2975,8 +2990,13 @@ bw_check_messages_thread(GSList * list)
     
     pthread_mutex_lock(&mailbox_lock);
     checking_mail = 0;
+    if (info->window) {
+        bw_set_sensitive(info->window, "GetNewMail", TRUE);
+        g_object_unref(info->window);
+    }
     pthread_mutex_unlock(&mailbox_lock);
     
+    g_free(info);
     pthread_exit(0);
 }
 
diff --git a/src/main.c b/src/main.c
index 177faaa..1e54854 100644
--- a/src/main.c
+++ b/src/main.c
@@ -189,7 +189,7 @@ mw_message_received_cb(UniqueApp         *app,
         gtk_window_present(window);
         break;
     case COMMAND_CHECK_MAIL:
-        balsa_main_check_new_messages(NULL);
+        balsa_main_check_new_messages(balsa_app.main_window);
         break;
     case COMMAND_GET_STATS:
         balsa_get_stats(&unread, &unsent);
@@ -1142,7 +1142,8 @@ main(int argc, char *argv[])
     g_timeout_add(1801*1000, (GSourceFunc) periodic_expunge_cb, NULL);
 
     if (cmd_check_mail_on_startup || balsa_app.check_mail_upon_startup)
-        g_idle_add((GSourceFunc) balsa_main_check_new_messages, NULL);
+        g_idle_add((GSourceFunc) balsa_main_check_new_messages,
+                   balsa_app.main_window);
 
     accel_map_load();
     gdk_threads_enter();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]