Commit 03b750a4 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

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.
parent 4a8ee7f3
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
......
......@@ -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);
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);
gchar *hours = NULL;
gchar *minutes = NULL;
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;
*minutes = NULL;
*hours = NULL;
g_return_val_if_fail (now >= then, NULL);
g_return_if_fail (now >= then);
/* one second, the time period */
if (diff < 60)
return g_strdup_printf (ngettext ("second", "%d seconds", diff), diff);
/* first round up to the nearest minute */
diff = (diff + 59) / 60;
/* round to the nearest minute */
diff = (diff + 30) / 60;
/* 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);
}
return g_strdup_printf (ngettext ("minute", "%d minutes", diff), diff);
if (diff > 0)
*minutes = g_strdup_printf (ngettext ("minute", "%d minutes", diff), diff);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment