[balsa/wip/gtk4: 117/351] Use libbalsa_clear_source_id()



commit 56000fc4fa13debb590a428cecb4bc2b136e0644
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Tue Jan 9 09:01:37 2018 -0500

    Use libbalsa_clear_source_id()
    
    It is a convenience function to remove a GSource id and clear it, when
    it is non-zero, similar to g_clear_object.

 libbalsa/address-view.c      |    9 ++-------
 libbalsa/identity.c          |    5 +----
 libbalsa/libbalsa-conf.c     |    5 +----
 libbalsa/libbalsa-progress.c |   15 +++------------
 libbalsa/mailbox.c           |    7 ++-----
 libbalsa/mailbox_imap.c      |    5 +----
 libbalsa/mailbox_local.c     |   14 ++++----------
 libbalsa/misc.c              |    4 ++--
 libbalsa/send.c              |    5 +----
 src/balsa-app.c              |   12 ++++++------
 src/balsa-app.h              |    2 +-
 src/balsa-mime-widget.c      |    5 ++---
 src/main-window.c            |    8 ++------
 src/message-window.c         |    9 ++++-----
 src/sendmsg-window.c         |    5 +----
 src/spell-check.c            |    5 +----
 16 files changed, 34 insertions(+), 81 deletions(-)
---
diff --git a/libbalsa/address-view.c b/libbalsa/address-view.c
index 0cd6966..a816c6d 100644
--- a/libbalsa/address-view.c
+++ b/libbalsa/address-view.c
@@ -101,13 +101,8 @@ libbalsa_address_view_finalize(GObject * object)
     g_free(address_view->domain);
     g_free(address_view->path_string);
 
-    if (address_view->focus_row != NULL) {
-        gtk_tree_row_reference_free(address_view->focus_row);
-    }
-
-    if (address_view->focus_idle_id != 0) {
-        g_source_remove(address_view->focus_idle_id);
-    }
+    g_clear_pointer(&address_view->focus_row, (GDestroyNotify) gtk_tree_row_reference_free);
+    libbalsa_clear_source_id(&address_view->focus_idle_id);
 
     G_OBJECT_CLASS(libbalsa_address_view_parent_class)->finalize(object);
 }
diff --git a/libbalsa/identity.c b/libbalsa/identity.c
index 9b94b4b..d9c3e34 100644
--- a/libbalsa/identity.c
+++ b/libbalsa/identity.c
@@ -508,10 +508,7 @@ libbalsa_identity_select_dialog(GtkWindow * parent,
 static void
 sd_destroy_notify(SelectDialogInfo * sdi)
 {
-    if (sdi->idle_handler_id) {
-        g_source_remove(sdi->idle_handler_id);
-        sdi->idle_handler_id = 0;
-    }
+    libbalsa_clear_source_id(&sdi->idle_handler_id);
     g_free(sdi);
 }
 
diff --git a/libbalsa/libbalsa-conf.c b/libbalsa/libbalsa-conf.c
index 9d1a271..f1539f4 100644
--- a/libbalsa/libbalsa-conf.c
+++ b/libbalsa/libbalsa-conf.c
@@ -530,10 +530,7 @@ libbalsa_conf_sync(void)
 #if DEBUG
     g_print("%s id %d, will be cleared\n", __func__, lbc_sync_idle_id);
 #endif                          /* DEBUG */
-    if (lbc_sync_idle_id) {
-        g_source_remove(lbc_sync_idle_id);
-        lbc_sync_idle_id = 0;
-    }
+    libbalsa_clear_source_id(&lbc_sync_idle_id);
     G_UNLOCK(lbc_sync_idle_id);
     lbc_lock();
     lbc_sync(&lbc_conf);
diff --git a/libbalsa/libbalsa-progress.c b/libbalsa/libbalsa-progress.c
index 632c0a2..31c1dcd 100644
--- a/libbalsa/libbalsa-progress.c
+++ b/libbalsa/libbalsa-progress.c
@@ -245,14 +245,8 @@ static void
 progress_data_destroy_cb(GtkWidget G_GNUC_UNUSED *widget,
                                                 progress_widget_data_t  *progress_data)
 {
-       if (progress_data->activity_id != 0U) {
-               g_source_remove(progress_data->activity_id);
-               progress_data->activity_id = 0U;
-       }
-       if (progress_data->fadeout_id != 0U) {
-               g_source_remove(progress_data->fadeout_id);
-               progress_data->fadeout_id = 0U;
-       }
+       libbalsa_clear_source_id(&progress_data->activity_id);
+       libbalsa_clear_source_id(&progress_data->fadeout_id);
 }
 
 
@@ -392,10 +386,7 @@ libbalsa_progress_dialog_update_real(ProgressDialog *progress_dialog,
                                                        g_timeout_add(ACTIVITY_DURATION, (GSourceFunc) 
progress_activity, progress_data->progress);
                                        }
                                } else {
-                                       if (progress_data->activity_id != 0U) {
-                                               g_source_remove(progress_data->activity_id);
-                                               progress_data->activity_id = 0U;
-                                       }
+                                       libbalsa_clear_source_id(&progress_data->activity_id);
                                        
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_data->progress), fraction);
                                }
                        }
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index c1e217b..c14011d 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -675,11 +675,8 @@ libbalsa_mailbox_check(LibBalsaMailbox * mailbox)
 
     libbalsa_lock_mailbox(mailbox);
 
-    if (mailbox->queue_check_idle_id) {
-       /* Remove scheduled idle callback. */
-        g_source_remove(mailbox->queue_check_idle_id);
-        mailbox->queue_check_idle_id = 0;
-    }
+    /* Remove any scheduled idle callback. */
+    libbalsa_clear_source_id(&mailbox->queue_check_idle_id);
 
     LIBBALSA_MAILBOX_GET_CLASS(mailbox)->check(mailbox);
 
diff --git a/libbalsa/mailbox_imap.c b/libbalsa/mailbox_imap.c
index 397022c..568f550 100644
--- a/libbalsa/mailbox_imap.c
+++ b/libbalsa/mailbox_imap.c
@@ -319,10 +319,7 @@ libbalsa_mailbox_imap_dispose(GObject * object)
     }
 
     mailbox = LIBBALSA_MAILBOX_IMAP(object);
-    if (mailbox->unread_update_id != 0) {
-        g_source_remove(mailbox->unread_update_id);
-        mailbox->unread_update_id = 0;
-    }
+    libbalsa_clear_source_id(&mailbox->unread_update_id);
 
     G_OBJECT_CLASS(parent_class)->dispose(object);
 }
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 070c9ea..848e32d 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -743,10 +743,7 @@ libbalsa_mailbox_local_close_mailbox(LibBalsaMailbox * mailbox,
     guint i;
     LibBalsaMailboxLocalPool *item;
 
-    if(local->sync_id) {
-        g_source_remove(local->sync_id);
-        local->sync_id = 0;
-    }
+    libbalsa_clear_source_id(&local->sync_id);
 
     /* Restore the persistent view before saving the tree. */
     libbalsa_mailbox_set_view_filter(mailbox,
@@ -756,16 +753,13 @@ libbalsa_mailbox_local_close_mailbox(LibBalsaMailbox * mailbox,
         /* Rethread immediately. */
         LibBalsaMailboxThreadingType cur_type =
             libbalsa_mailbox_get_threading_type(mailbox);
-        g_source_remove(local->thread_id);
-        local->thread_id = 0;
+
+        libbalsa_clear_source_id(&local->thread_id);
         libbalsa_mailbox_set_threading(mailbox, cur_type);
     }
 
-    if (local->save_tree_id) {
         /* Save immediately. */
-        g_source_remove(local->save_tree_id);
-        local->save_tree_id = 0;
-    }
+    libbalsa_clear_source_id(&local->save_tree_id);
     lbm_local_save_tree(local);
 
     if (local->threading_info) {
diff --git a/libbalsa/misc.c b/libbalsa/misc.c
index 41f23e5..e490266 100644
--- a/libbalsa/misc.c
+++ b/libbalsa/misc.c
@@ -1219,8 +1219,8 @@ libbalsa_clear_source_id(guint * tag)
 {
     g_return_if_fail(tag != NULL);
 
-    if (*tag != 0) {
+    if (*tag != 0U) {
         g_source_remove(*tag);
-        *tag = 0;
+        *tag = 0U;
     }
 }
diff --git a/libbalsa/send.c b/libbalsa/send.c
index 75eca44..bb234b9 100644
--- a/libbalsa/send.c
+++ b/libbalsa/send.c
@@ -106,10 +106,7 @@ static ProgressDialog send_progress_dialog;
 static void
 update_send_timer(gboolean start)
 {
-    if (send_mail_timer_id != 0U) {
-        g_source_remove(send_mail_timer_id);
-        send_mail_timer_id = 0U;
-    }
+    libbalsa_clear_source_id(&send_mail_timer_id);
 
     if (start && send_mail_auto && (auto_send_cb != NULL)) {
        send_mail_timer_id = g_timeout_add_seconds(send_mail_time, auto_send_cb, NULL);
diff --git a/src/balsa-app.c b/src/balsa-app.c
index 569da5f..f8b18c6 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -455,13 +455,13 @@ check_new_messages_auto_cb(gpointer data)
 void
 update_timer(gboolean update, guint minutes)
 {
-    if (balsa_app.check_mail_timer_id)
-        g_source_remove(balsa_app.check_mail_timer_id);
+    libbalsa_clear_source_id(&balsa_app.check_mail_timer_id);
 
-    balsa_app.check_mail_timer_id = update ?
-        g_timeout_add_seconds(minutes * 60,
-                              check_new_messages_auto_cb,
-                              NULL) : 0;
+    if (update) {
+        balsa_app.check_mail_timer_id =
+            g_timeout_add_seconds(minutes * 60, check_new_messages_auto_cb,
+                                  NULL);
+    }
 }
 
 
diff --git a/src/balsa-app.h b/src/balsa-app.h
index 27a401d..985a905 100644
--- a/src/balsa-app.h
+++ b/src/balsa-app.h
@@ -165,7 +165,7 @@ extern struct BalsaApplication {
     /* timer for checking mail every xx minutes */
     gboolean check_mail_auto;
     gint check_mail_timer;
-    gint check_mail_timer_id;
+    guint check_mail_timer_id;
 
     /* This can be configured from the gnome control panel */
     /* It's here just in case some other app also uses the same */
diff --git a/src/balsa-mime-widget.c b/src/balsa-mime-widget.c
index efeba1f..07062d0 100644
--- a/src/balsa-mime-widget.c
+++ b/src/balsa-mime-widget.c
@@ -290,7 +290,7 @@ balsa_mime_widget_new_unknown(BalsaMessage * bm,
 }
 
 
-static gint resize_idle_id;
+static guint resize_idle_id;
 
 static GtkWidget *old_widget, *new_widget;
 static gdouble old_upper, new_upper;
@@ -331,7 +331,6 @@ vadj_change_cb(GtkAdjustment *vadj, GtkWidget *widget)
         return;
     new_widget = widget;
     new_upper = upper;
-    if (resize_idle_id) 
-        g_source_remove(resize_idle_id);
+    libbalsa_clear_source_id(&resize_idle_id);
     balsa_mime_widget_schedule_resize(widget);
 }
diff --git a/src/main-window.c b/src/main-window.c
index 9f8995c..25440d7 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -4293,10 +4293,7 @@ bw_idle_replace(BalsaWindow * window, BalsaIndex * bindex)
 static void
 bw_idle_remove(BalsaWindow * window)
 {
-    if (window->set_message_id) {
-        g_source_remove(window->set_message_id);
-        window->set_message_id = 0;
-    }
+    libbalsa_clear_source_id(&window->set_message_id);
 }
 
 
@@ -4542,8 +4539,7 @@ balsa_window_decrease_activity(BalsaWindow * window, const gchar * message)
     /* decrement the counter if positive */
     if (window->activity_counter > 0 && --window->activity_counter == 0) {
         /* clear the bar and make it available for others to use */
-        g_source_remove(window->activity_handler);
-        window->activity_handler = 0;
+        libbalsa_clear_source_id(&window->activity_handler);
         if (window->progress_type == BALSA_PROGRESS_ACTIVITY) {
             window->progress_type = BALSA_PROGRESS_NONE;
             gtk_progress_bar_set_fraction(progress_bar, 0);
diff --git a/src/message-window.c b/src/message-window.c
index 90af556..5fbd82b 100644
--- a/src/message-window.c
+++ b/src/message-window.c
@@ -331,10 +331,9 @@ mw_set_buttons_sensitive(MessageWindow * mw)
 static void
 mw_set_message(MessageWindow * mw, LibBalsaMessage * message)
 {
-    if (mw->idle_handler_id && !message) {
-       g_source_remove(mw->idle_handler_id);
-       mw->idle_handler_id = 0;
-    } 
+    if (message == NULL) {
+       libbalsa_clear_source_id(&mw->idle_handler_id);
+    }
 
     if (mw->message) {
         g_object_set_data(G_OBJECT(mw->message), BALSA_MESSAGE_WINDOW_KEY, NULL);
@@ -345,7 +344,7 @@ mw_set_message(MessageWindow * mw, LibBalsaMessage * message)
 
     if (message) {
         g_object_set_data(G_OBJECT(message), BALSA_MESSAGE_WINDOW_KEY, mw);
-        if (!mw->idle_handler_id)
+        if (mw->idle_handler_id == 0U)
             mw->idle_handler_id =
                 g_idle_add((GSourceFunc) message_window_idle_handler, mw);
         mw_set_buttons_sensitive(mw);
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 4688a52..f44dab6 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -637,10 +637,7 @@ balsa_sendmsg_destroy_handler(BalsaSendmsg * bsmsg)
     if (bsmsg->spell_checker)
         gtk_widget_destroy(bsmsg->spell_checker);
 #endif                          /* HAVE_GTKSPELL */
-    if (bsmsg->autosave_timeout_id) {
-        g_source_remove(bsmsg->autosave_timeout_id);
-        bsmsg->autosave_timeout_id = 0;
-    }
+    libbalsa_clear_source_id(&bsmsg->autosave_timeout_id);
 
 #if !HAVE_GTKSOURCEVIEW
     g_object_unref(bsmsg->buffer2);
diff --git a/src/spell-check.c b/src/spell-check.c
index 2ad477e..7fa7f14 100644
--- a/src/spell-check.c
+++ b/src/spell-check.c
@@ -826,10 +826,7 @@ balsa_spell_check_destroy(GObject * object)
        spch_finish(spell_check, FALSE);
     }
 
-    if (spell_check->highlight_idle_id) {
-        g_source_remove(spell_check->highlight_idle_id);
-        spell_check->highlight_idle_id = 0;
-    }
+    libbalsa_clear_source_id(&spell_check->highlight_idle_id);
 
     g_clear_pointer(&spell_check->language_tag, g_free);
     g_clear_pointer(&quoted_rex, g_regex_unref);


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