reduced precision of the display of time since the last change.

2006-04-03  Sven Neumann  <sven@gimp.org>

	* app/display/gimpdisplayshell-close.c: reduced precision of the
	display of time since the last change.
This commit is contained in:
Sven Neumann 2006-04-03 10:13:41 +00:00 committed by Sven Neumann
parent 4a8ee7f392
commit 03b750a40e
2 changed files with 55 additions and 19 deletions

View File

@ -1,3 +1,8 @@
2006-04-03 Sven Neumann <sven@gimp.org>
* app/display/gimpdisplayshell-close.c: reduced precision of the
display of time since the last change.
2006-04-03 Sven Neumann <sven@gimp.org>
* app/tools/gimpscaletool.c: added a GimpSizeBox as a replacement

View File

@ -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);
}