From 125ee37681ef893ceee444a0896b01e183925881 Mon Sep 17 00:00:00 2001 From: Nick Schermer <nick@xfce.org> Date: Sun, 22 Jan 2012 13:26:37 +0100 Subject: [PATCH] Use new time function in progress view. This makes the code a bit easier to read. --- thunar/thunar-progress-view.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/thunar/thunar-progress-view.c b/thunar/thunar-progress-view.c index a1daf2bcd..8d0f1e667 100644 --- a/thunar/thunar-progress-view.c +++ b/thunar/thunar-progress-view.c @@ -29,6 +29,7 @@ #include <thunar/thunar-job.h> #include <thunar/thunar-pango-extensions.h> #include <thunar/thunar-private.h> +#include <thunar/thunar-util.h> #include <thunar/thunar-progress-view.h> @@ -86,8 +87,8 @@ struct _ThunarProgressView ThunarJob *job; - GTimeVal start_time; - GTimeVal last_update_time; + gint64 start_time; + gint64 last_update_time; GtkWidget *progress_bar; GtkWidget *progress_label; @@ -174,7 +175,7 @@ thunar_progress_view_init (ThunarProgressView *view) GtkWidget *hbox; /* remember the current time as start time */ - g_get_current_time (&view->start_time); + view->start_time = thunar_util_get_real_time (); vbox = gtk_vbox_new (FALSE, 6); gtk_container_add (GTK_CONTAINER (view), vbox); @@ -435,39 +436,29 @@ thunar_progress_view_info_message (ThunarProgressView *view, -static inline guint64 -time_diff (const GTimeVal *now, - const GTimeVal *last) -{ - return ((guint64) now->tv_sec - last->tv_sec) * G_USEC_PER_SEC - + ((guint64) last->tv_usec - last->tv_usec); -} - - - static void thunar_progress_view_percent (ThunarProgressView *view, gdouble percent, ExoJob *job) { - GTimeVal current_time; - gulong remaining_time; - gulong elapsed_time; - gchar text[512]; + gint64 current_time; + gulong remaining_time; + gint64 elapsed_time; + gchar text[512]; _thunar_return_if_fail (THUNAR_IS_PROGRESS_VIEW (view)); _thunar_return_if_fail (percent >= 0.0 && percent <= 100.0); _thunar_return_if_fail (THUNAR_IS_JOB (job)); _thunar_return_if_fail (view->job == THUNAR_JOB (job)); - + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (view->progress_bar), percent / 100.0); /* check if we should update the time display (every 400ms) */ - g_get_current_time (¤t_time); - if (time_diff (¤t_time, &view->last_update_time) > 400 * 1000) + current_time = thunar_util_get_real_time (); + if (current_time - view->last_update_time > (400 * 1000)) { /* calculate the remaining time (in seconds) */ - elapsed_time = time_diff (¤t_time, &view->start_time) / 1000; + elapsed_time = (current_time - view->start_time) / 1000; remaining_time = ((100 * elapsed_time) / percent - elapsed_time) / 1000; /* setup the time label */ -- GitLab