[balsa/wip/gtk4] main: Use g_get_monotonic_time()



commit ccd0e34cd0a032ab4e41dae1aadfb15f88fb041d
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Tue May 7 12:31:31 2019 -0400

    main: Use g_get_monotonic_time()
    
    … instead of soon-to-be-deprecated GTimeVal.

 src/main.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
---
diff --git a/src/main.c b/src/main.c
index 57343babd..7a798fd39 100644
--- a/src/main.c
+++ b/src/main.c
@@ -372,7 +372,7 @@ periodic_expunge_cb(void)
 /*
  * Initialize the progress bar and set text.
  */
-static GTimeVal prev_time_val;
+static gint64   prev_time_val;
 static gdouble  min_fraction;
 static void
 balsa_progress_set_text(LibBalsaProgress * progress, const gchar * text,
@@ -388,7 +388,7 @@ balsa_progress_set_text(LibBalsaProgress * progress, const gchar * text,
      * for a subthread */
     if (!text || total >= LIBBALSA_PROGRESS_MIN_COUNT)
         rc = balsa_window_setup_progress(balsa_app.main_window, text);
-    g_get_current_time(&prev_time_val);
+    prev_time_val = g_get_monotonic_time();
     min_fraction = LIBBALSA_PROGRESS_MIN_UPDATE_STEP;
 
     *progress = (text && rc) ?
@@ -402,8 +402,8 @@ balsa_progress_set_text(LibBalsaProgress * progress, const gchar * text,
 static void
 balsa_progress_set_fraction(LibBalsaProgress * progress, gdouble fraction)
 {
-    GTimeVal time_val;
-    guint elapsed;
+    gint64 time_val;
+    gint elapsed;
 
     if (*progress == LIBBALSA_PROGRESS_NO)
         return;
@@ -411,15 +411,13 @@ balsa_progress_set_fraction(LibBalsaProgress * progress, gdouble fraction)
     if (fraction > 0.0 && fraction < min_fraction)
         return;
 
-    g_get_current_time(&time_val);
-    elapsed = time_val.tv_sec - prev_time_val.tv_sec;
-    elapsed *= G_USEC_PER_SEC;
-    elapsed += time_val.tv_usec - prev_time_val.tv_usec;
+    time_val = g_get_monotonic_time();
+    elapsed = time_val - prev_time_val;
     if (elapsed < LIBBALSA_PROGRESS_MIN_UPDATE_USECS)
         return;
 
-    g_time_val_add(&time_val, LIBBALSA_PROGRESS_MIN_UPDATE_USECS);
-    min_fraction += LIBBALSA_PROGRESS_MIN_UPDATE_STEP;
+    prev_time_val += LIBBALSA_PROGRESS_MIN_UPDATE_USECS;
+    min_fraction  += LIBBALSA_PROGRESS_MIN_UPDATE_STEP;
 
     if (balsa_app.main_window)
         balsa_window_increment_progress(balsa_app.main_window, fraction,


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