Fix use of deprecated GTimeVal since glib 2.61.2
authorMichael Rasmussen <mir@datanom.net>
Mon, 11 Nov 2019 22:27:08 +0000 (23:27 +0100)
committerMichael Rasmussen <mir@datanom.net>
Mon, 11 Nov 2019 22:27:08 +0000 (23:27 +0100)
Signed-off-by: Michael Rasmussen <mir@datanom.net>
src/common/session.c
src/common/session.h
src/inc.c
src/inc.h

index 2da8e16..c7a42f0 100644 (file)
@@ -75,7 +75,11 @@ void session_init(Session *session, const void *prefs_account, gboolean is_smtp)
        session->state = SESSION_READY;
        session->last_access_time = time(NULL);
 
+#if GLIB_CHECK_VERSION(2,61,2)
+       session->tv_prev = g_date_time_new_now_local();
+#else
        g_get_current_time(&session->tv_prev);
+#endif
 
        session->conn_id = 0;
 
@@ -264,7 +268,9 @@ void session_destroy(Session *session)
 #ifdef USE_GNUTLS
        g_free(session->gnutls_priority);
 #endif
-
+#if GLIB_CHECK_VERSION(2,61,2)
+       g_date_time_unref(session->tv_prev);
+#endif
        debug_print("session (%p): destroyed\n", session);
 
        g_free(session);
@@ -500,7 +506,12 @@ gint session_send_data(Session *session, const guchar *data, guint size)
        session->write_data = data;
        session->write_data_p = session->write_data;
        session->write_data_len = size;
-       g_get_current_time(&session->tv_prev);
+#if GLIB_CHECK_VERSION(2,61,2)
+       g_date_time_unref(session->tv_prev);
+        session->tv_prev = g_date_time_new_now_local();
+#else
+        g_get_current_time(&session->tv_prev);
+#endif
 
        ret = session_write_data_cb(session->sock, G_IO_OUT, session);
 
@@ -522,7 +533,12 @@ gint session_recv_data(Session *session, guint size, const gchar *terminator)
 
        g_free(session->read_data_terminator);
        session->read_data_terminator = g_strdup(terminator);
-       g_get_current_time(&session->tv_prev);
+#if GLIB_CHECK_VERSION(2,61,2)
+       g_date_time_unref(session->tv_prev);
+        session->tv_prev = g_date_time_new_now_local();
+#else
+        g_get_current_time(&session->tv_prev);
+#endif
 
        if (session->read_buf_len > 0)
                g_idle_add(session_recv_data_idle_cb, session);
@@ -711,17 +727,31 @@ static gboolean session_read_data_cb(SockInfo *source, GIOCondition condition,
 
        /* incomplete read */
        if (!complete) {
+#if GLIB_CHECK_VERSION(2,61,2)
+               GDateTime *tv_cur = g_date_time_new_now_local();
+
+               GTimeSpan ts = g_date_time_difference(tv_cur, session->tv_prev);
+                if (1000 - ts < 0 || ts > UI_REFRESH_INTERVAL) {
+                        session->recv_data_progressive_notify
+                                (session, data_buf->len, 0,
+                                 session->recv_data_progressive_notify_data);
+                       g_date_time_unref(session->tv_prev);
+                        session->tv_prev = g_date_time_new_now_local();
+                }
+               g_date_time_unref(tv_cur);
+#else
                GTimeVal tv_cur;
 
                g_get_current_time(&tv_cur);
-               if (tv_cur.tv_sec - session->tv_prev.tv_sec > 0 ||
-                   tv_cur.tv_usec - session->tv_prev.tv_usec >
-                   UI_REFRESH_INTERVAL) {
-                       session->recv_data_progressive_notify
-                               (session, data_buf->len, 0,
-                                session->recv_data_progressive_notify_data);
-                       g_get_current_time(&session->tv_prev);
-               }
+                if (tv_cur.tv_sec - session->tv_prev.tv_sec > 0 ||
+                    tv_cur.tv_usec - session->tv_prev.tv_usec >
+                    UI_REFRESH_INTERVAL) {
+                        session->recv_data_progressive_notify
+                                (session, data_buf->len, 0,
+                                 session->recv_data_progressive_notify_data);
+                        g_get_current_time(&session->tv_prev);
+                }
+#endif
                return TRUE;
        }
 
@@ -882,20 +912,38 @@ static gboolean session_write_data_cb(SockInfo *source,
                session->state = SESSION_ERROR;
                return FALSE;
        } else if (ret > 0) {
+#if GLIB_CHECK_VERSION(2,61,2)
+                GDateTime *tv_cur = g_date_time_new_now_local();
+
+                GTimeSpan ts = g_date_time_difference(tv_cur, session->tv_prev);
+                if (1000 - ts < 0 || ts > UI_REFRESH_INTERVAL) {
+                        session_set_timeout(session, session->timeout_interval);
+                        session->send_data_progressive_notify
+                                (session,
+                                 session->write_data_p - session->write_data,
+                                 write_data_len,
+                                 session->send_data_progressive_notify_data);
+                       g_date_time_unref(session->tv_prev);
+                        session->tv_prev = g_date_time_new_now_local();
+                }
+                g_date_time_unref(tv_cur);
+#else
                GTimeVal tv_cur;
 
-               g_get_current_time(&tv_cur);
-               if (tv_cur.tv_sec - session->tv_prev.tv_sec > 0 ||
-                   tv_cur.tv_usec - session->tv_prev.tv_usec >
-                   UI_REFRESH_INTERVAL) {
-                       session_set_timeout(session, session->timeout_interval);
-                       session->send_data_progressive_notify
-                               (session,
-                                session->write_data_p - session->write_data,
-                                write_data_len,
-                                session->send_data_progressive_notify_data);
-                       g_get_current_time(&session->tv_prev);
-               }
+                g_get_current_time(&tv_cur);
+                if (tv_cur.tv_sec - session->tv_prev.tv_sec > 0 ||
+                    tv_cur.tv_usec - session->tv_prev.tv_usec >
+                    UI_REFRESH_INTERVAL) {
+                        session_set_timeout(session, session->timeout_interval);
+                        session->send_data_progressive_notify
+                                (session,
+                                 session->write_data_p - session->write_data,
+                                 write_data_len,
+                                 session->send_data_progressive_notify_data);
+                        g_get_current_time(&session->tv_prev);
+                }
+
+#endif
                return TRUE;
        }
 
index 13a56c9..d24e750 100644 (file)
@@ -88,8 +88,11 @@ struct _Session
        SessionState state;
 
        time_t last_access_time;
+#if GLIB_CHECK_VERSION(2,61,2)
+       GDateTime *tv_prev;
+#else
        GTimeVal tv_prev;
-
+#endif
        gint conn_id;
 
        gint io_tag;
index 5a0bdff..48098c6 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -508,8 +508,13 @@ static IncProgressDialog *inc_progress_dialog_create(gboolean autocheck)
        }
 
        dialog->dialog = progress;
+#if GLIB_CHECK_VERSION(2,61,2)
+       dialog->progress_tv = g_date_time_new_now_local();
+       dialog->folder_tv = g_date_time_new_now_local();
+#else
        g_get_current_time(&dialog->progress_tv);
        g_get_current_time(&dialog->folder_tv);
+#endif
        dialog->queue_list = NULL;
        dialog->cur_row = 0;
 
@@ -553,6 +558,11 @@ static void inc_progress_dialog_destroy(IncProgressDialog *inc_dialog)
                main_window_progress_off(inc_dialog->mainwin);
        progress_dialog_destroy(inc_dialog->dialog);
 
+#if GLIB_CHECK_VERSION(2,61,2)
+       g_date_time_unref(inc_dialog->progress_tv);
+       g_date_time_unref(inc_dialog->folder_tv);
+#endif
+
        g_free(inc_dialog);
 }
 
@@ -1081,25 +1091,44 @@ static void inc_progress_dialog_set_progress(IncProgressDialog *inc_dialog,
 static void inc_progress_dialog_update_periodic(IncProgressDialog *inc_dialog,
                                                IncSession *inc_session)
 {
+#if GLIB_CHECK_VERSION(2,61,2)
+       GDateTime *tv_cur = g_date_time_new_now_local();
+       GTimeSpan tv_result;
+
+       tv_result = g_date_time_difference(tv_cur, inc_dialog->progress_tv);
+       g_date_time_unref(tv_cur);
+       if (tv_result < 0) {
+           tv_result += G_USEC_PER_SEC;
+       }
+
+       if (tv_result > PROGRESS_UPDATE_INTERVAL) {
+                inc_progress_dialog_update(inc_dialog, inc_session);
+               tv_cur = g_date_time_add(inc_dialog->progress_tv, tv_result);
+               g_date_time_unref(inc_dialog->progress_tv);
+                inc_dialog->progress_tv = tv_cur;
+       }
+#else
        GTimeVal tv_cur;
        GTimeVal tv_result;
-       gint msec;
 
-       g_get_current_time(&tv_cur);
+        gint msec;
 
-       tv_result.tv_sec = tv_cur.tv_sec - inc_dialog->progress_tv.tv_sec;
-       tv_result.tv_usec = tv_cur.tv_usec - inc_dialog->progress_tv.tv_usec;
-       if (tv_result.tv_usec < 0) {
-               tv_result.tv_sec--;
-               tv_result.tv_usec += G_USEC_PER_SEC;
-       }
+        g_get_current_time(&tv_cur);
 
-       msec = tv_result.tv_sec * 1000 + tv_result.tv_usec / 1000;
-       if (msec > PROGRESS_UPDATE_INTERVAL) {
-               inc_progress_dialog_update(inc_dialog, inc_session);
-               inc_dialog->progress_tv.tv_sec = tv_cur.tv_sec;
-               inc_dialog->progress_tv.tv_usec = tv_cur.tv_usec;
-       }
+        tv_result.tv_sec = tv_cur.tv_sec - inc_dialog->progress_tv.tv_sec;
+        tv_result.tv_usec = tv_cur.tv_usec - inc_dialog->progress_tv.tv_usec;
+        if (tv_result.tv_usec < 0) {
+                tv_result.tv_sec--;
+                tv_result.tv_usec += G_USEC_PER_SEC;
+        }
+
+        msec = tv_result.tv_sec * 1000 + tv_result.tv_usec / 1000;
+        if (msec > PROGRESS_UPDATE_INTERVAL) {
+                inc_progress_dialog_update(inc_dialog, inc_session);
+                inc_dialog->progress_tv.tv_sec = tv_cur.tv_sec;
+                inc_dialog->progress_tv.tv_usec = tv_cur.tv_usec;
+        }
+#endif
 }
 
 static gint inc_recv_data_progressive(Session *session, guint cur_len,
index c440c8f..c8d38b6 100644 (file)
--- a/src/inc.h
+++ b/src/inc.h
@@ -58,8 +58,13 @@ struct _IncProgressDialog
 
        gboolean show_dialog;
 
+#if GLIB_CHECK_VERSION(2,61,2)
+       GDateTime *progress_tv;
+       GDateTime *folder_tv;
+#else
        GTimeVal progress_tv;
        GTimeVal folder_tv;
+#endif
 
        GList *queue_list;      /* list of IncSession */
        gint cur_row;