From 03b750a40e31fed4b0b94d670f09007ed5fb34f6 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Mon, 3 Apr 2006 10:13:41 +0000 Subject: [PATCH] reduced precision of the display of time since the last change. 2006-04-03 Sven Neumann * app/display/gimpdisplayshell-close.c: reduced precision of the display of time since the last change. --- ChangeLog | 5 ++ app/display/gimpdisplayshell-close.c | 69 ++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c1ab5df98..d06c240f29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-04-03 Sven Neumann + + * app/display/gimpdisplayshell-close.c: reduced precision of the + display of time since the last change. + 2006-04-03 Sven Neumann * app/tools/gimpscaletool.c: added a GimpSizeBox as a replacement diff --git a/app/display/gimpdisplayshell-close.c b/app/display/gimpdisplayshell-close.c index 2d04b9e0b6..2f1511fbc9 100644 --- a/app/display/gimpdisplayshell-close.c +++ b/app/display/gimpdisplayshell-close.c @@ -56,7 +56,9 @@ static void gimp_display_shell_close_response (GtkWidget *widget gboolean close, GimpDisplayShell *shell); -static gchar * gimp_time_since (guint then); +static void gimp_time_since (guint then, + gchar **hours, + gchar **minutes); /* public functions */ @@ -170,7 +172,8 @@ gimp_display_shell_close_dialog (GimpDisplayShell *shell, g_cclosure_new_object (G_CALLBACK (gimp_display_shell_close_time_changed), G_OBJECT (box)); - source = g_timeout_source_new (1000); + /* update every 10 seconds */ + source = g_timeout_source_new (10 * 1000); g_source_set_closure (source, closure); g_source_attach (source, NULL); g_source_unref (source); @@ -217,13 +220,26 @@ gimp_display_shell_close_time_changed (GimpMessageBox *box) if (image->dirty_time) { - gchar *period = gimp_time_since (image->dirty_time); + gchar *hours = NULL; + gchar *minutes = NULL; - gimp_message_box_set_text (box, - _("If you don't save the image, " - "changes from the last %s will be lost."), - period); - g_free (period); + gimp_time_since (image->dirty_time, &hours, &minutes); + + if (hours && minutes) + /* time period ("... from the last 3 hours and 20 minutes ...") */ + gimp_message_box_set_text (box, + _("If you don't save the image, changes " + "from the last %s and %s will be lost."), + hours, minutes); + else + /* time period ("... from the last 20 minutes ...") */ + gimp_message_box_set_text (box, + _("If you don't save the image, changes " + "from the last %s will be lost."), + hours ? hours : minutes); + + g_free (hours); + g_free (minutes); } else { @@ -267,20 +283,35 @@ gimp_display_shell_close_response (GtkWidget *widget, } } -static gchar * -gimp_time_since (guint then) +static void +gimp_time_since (guint then, + gchar **hours, + gchar **minutes) { - guint now = time (NULL); - guint diff = 1 + now - then; + guint now = time (NULL); + guint diff = 1 + now - then; - g_return_val_if_fail (now >= then, NULL); + *minutes = NULL; + *hours = NULL; - /* one second, the time period */ - if (diff < 60) - return g_strdup_printf (ngettext ("second", "%d seconds", diff), diff); + g_return_if_fail (now >= then); - /* round to the nearest minute */ - diff = (diff + 30) / 60; + /* first round up to the nearest minute */ + diff = (diff + 59) / 60; - return g_strdup_printf (ngettext ("minute", "%d minutes", diff), diff); + /* then optionally round minutes to multiples of 5 or 10 */ + if (diff > 50) + diff = ((diff + 8) / 10) * 10; + else if (diff > 20) + diff = ((diff + 3) / 5) * 5; + + if (diff >= 120) + { + *hours = g_strdup_printf (ngettext ("%d hour", "%d hours", + diff / 60), diff / 60); + diff = (diff % 60); + } + + if (diff > 0) + *minutes = g_strdup_printf (ngettext ("minute", "%d minutes", diff), diff); }