[balsa] main-window: Simplify and make more robust



commit c930181794c439f593360cea727e9128d49bdd93
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sun Feb 2 16:15:14 2020 -0500

    main-window: Simplify and make more robust
    
    * src/main-window.c (balsa_window_destroy): bw_idle_remove() has
        been removed, so remove the GSource directly;
      (bw_idle_replace): ditto;
      (bw_idle_cb): scrap some useless tests;
      (bw_index_changed_cb): check that priv->preview is non-NULL.

 ChangeLog         | 10 ++++++++++
 src/main-window.c | 40 +++++++++++++---------------------------
 2 files changed, 23 insertions(+), 27 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 00be7999d..7d8847b1e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-02-02  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       main-window: Simplify and make more robust
+
+       * src/main-window.c (balsa_window_destroy): bw_idle_remove() has
+       been removed, so remove the GSource directly;
+       (bw_idle_replace): ditto;
+       (bw_idle_cb): scrap some useless tests;
+       (bw_index_changed_cb): check that priv->preview is non-NULL.
+
 2020-02-02  Peter Bloomfield  <pbloomfield bellsouth net>
 
        mailbox: Reset messages-threaded in the open method instead of
diff --git a/src/main-window.c b/src/main-window.c
index bd4ebe84a..7c205de98 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -115,7 +115,6 @@ static gboolean bw_close_mailbox_on_timer(BalsaWindow * window);
 
 static void bw_index_changed_cb(GtkWidget * widget, gpointer data);
 static void bw_idle_replace(BalsaWindow * window, BalsaIndex * bindex);
-static void bw_idle_remove(BalsaWindow * window);
 static gboolean bw_idle_cb(BalsaWindow * window);
 
 
@@ -3173,11 +3172,15 @@ balsa_window_destroy(GObject * object)
     BalsaWindow *window = BALSA_WINDOW(object);
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
 
-    bw_idle_remove(window);
     /* The preview window seems to get finalized without notification;
      * we no longer need it, so we just drop our pointer: */
     priv->preview = NULL;
 
+    if (priv->set_message_id != 0) {
+        g_source_remove(priv->set_message_id);
+        priv->set_message_id = 0;
+    }
+
     if (priv->network_changed_source_id != 0) {
         g_source_remove(priv->network_changed_source_id);
         priv->network_changed_source_id = 0;
@@ -4281,6 +4284,9 @@ bw_index_changed_cb(GtkWidget * widget, gpointer user_data)
     LibBalsaMessage *message;
     guint current_msgno;
 
+    if (priv->preview == NULL)
+        return;
+
     if (widget != priv->current_index)
         return;
 
@@ -4300,8 +4306,12 @@ bw_idle_replace(BalsaWindow * window, BalsaIndex * bindex)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
 
+    if (priv->set_message_id != 0) {
+        g_source_remove(priv->set_message_id);
+        priv->set_message_id = 0;
+    }
+
     if (balsa_app.previewpane) {
-        bw_idle_remove(window);
         /* Skip if the window is being destroyed: */
         if (priv->preview != NULL) {
             priv->set_message_id = g_idle_add((GSourceFunc) bw_idle_cb, window);
@@ -4311,34 +4321,12 @@ bw_idle_replace(BalsaWindow * window, BalsaIndex * bindex)
     }
 }
 
-static void
-bw_idle_remove(BalsaWindow * window)
-{
-    BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
-
-    if (priv->set_message_id) {
-        g_source_remove(priv->set_message_id);
-        priv->set_message_id = 0;
-    }
-}
-
-
-static volatile gboolean bw_idle_cb_active = FALSE;
-
 static gboolean
 bw_idle_cb(BalsaWindow * window)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
     BalsaIndex *index;
 
-    if (priv->set_message_id == 0) {
-        return FALSE;
-    }
-    if (bw_idle_cb_active) {
-       return TRUE;
-    }
-    bw_idle_cb_active = TRUE;
-
     priv->set_message_id = 0;
 
     index = (BalsaIndex *) priv->current_index;
@@ -4355,8 +4343,6 @@ bw_idle_cb(BalsaWindow * window)
         g_object_set_data(G_OBJECT(window), BALSA_INDEX_GRAB_FOCUS, NULL);
     }
 
-    bw_idle_cb_active = FALSE;
-
     return FALSE;
 }
 


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