* [PATCH] Write "time left" in human readable terms
@ 2008-09-24 21:34 Bastien Nocera
2008-09-27 4:25 ` Marcel Holtmann
0 siblings, 1 reply; 2+ messages in thread
From: Bastien Nocera @ 2008-09-24 21:34 UTC (permalink / raw)
To: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 159 bytes --]
Rather than using numbers, use full words, like minutes/seconds/etc.
Trivial code copied from nautilus itself
http://bugzilla.gnome.org/show_bug.cgi?id=513714
[-- Attachment #2: 0001-Write-time-left-in-human-readable-terms.patch --]
[-- Type: text/x-patch, Size: 2383 bytes --]
>From da739e86900f440a1056e6d720e5014439ea168a Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 24 Sep 2008 14:30:12 -0700
Subject: [PATCH] Write "time left" in human readable terms
Rather than using numbers, use full words, like minutes/seconds/etc.
Trivial code copied from nautilus itself
http://bugzilla.gnome.org/show_bug.cgi?id=513714
---
sendto/main.c | 49 +++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 41 insertions(+), 8 deletions(-)
diff --git a/sendto/main.c b/sendto/main.c
index b01dafc..0972ac8 100644
--- a/sendto/main.c
+++ b/sendto/main.c
@@ -69,6 +69,46 @@ static gint64 get_system_time(void)
(gint64) tmp.tv_sec * G_GINT64_CONSTANT(1000000);
}
+/* Copied from nautilus/libnautilus-private/nautilus-file-operations.c */
+static gchar *format_time(int seconds)
+{
+ int minutes;
+ int hours;
+ char *res;
+
+ if (seconds < 0) {
+ /* Just to make sure... */
+ seconds = 0;
+ }
+
+ if (seconds < 60)
+ return g_strdup_printf(ngettext ("%'d second","%'d seconds", seconds), seconds);
+
+ if (seconds < 60*60) {
+ minutes = (seconds + 30) / 60;
+ return g_strdup_printf(ngettext ("%'d minute", "%'d minutes", minutes), minutes);
+ }
+
+ hours = seconds / (60*60);
+
+ if (seconds < 60*60*4) {
+ char *h, *m;
+
+ minutes = (seconds - hours * 60 * 60 + 30) / 60;
+
+ h = g_strdup_printf(ngettext ("%'d hour", "%'d hours", hours), hours);
+ m = g_strdup_printf(ngettext ("%'d minute", "%'d minutes", minutes), minutes);
+ res = g_strconcat(h, ", ", m, NULL);
+ g_free(h);
+ g_free(m);
+ return res;
+ }
+
+ return g_strdup_printf(ngettext ("approximately %'d hour",
+ "approximately %'d hours",
+ hours), hours);
+}
+
static void response_callback(GtkWidget *dialog,
gint response, gpointer user_data)
{
@@ -265,14 +305,7 @@ static void transfer_progress(DBusGProxy *proxy,
remaining_time = (total_size - current_sent) / transfer_rate;
- if (remaining_time >= 3600)
- time = g_strdup_printf(_("%d:%02d:%02d Remaining"),
- remaining_time / 3600,
- (remaining_time % 3600) / 60,
- (remaining_time % 3600) % 60);
- else
- time = g_strdup_printf(_("%d:%02d Remaining"),
- remaining_time / 60, remaining_time % 60);
+ time = format_time (remaining_time);
if (transfer_rate >= 3000)
rate = g_strdup_printf(_("%d KB/s"), transfer_rate / 1000);
--
1.6.0.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-09-27 4:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-24 21:34 [PATCH] Write "time left" in human readable terms Bastien Nocera
2008-09-27 4:25 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox