diff options
author | Ross Lagerwall <rosslagerwall@gmail.com> | 2014-04-17 08:40:00 +0100 |
---|---|---|
committer | Ross Lagerwall <rosslagerwall@gmail.com> | 2014-04-18 20:31:43 +0100 |
commit | ee19f369476c6b24892bcb9b50f9041d65d570ac (patch) | |
tree | be9502d294dcdfca7adb866059490a99a9ed2e35 /programs | |
parent | d1138fb4fe1ce8c0c13a1a8541682a0d59da50ef (diff) | |
download | gvfs-ee19f369476c6b24892bcb9b50f9041d65d570ac.tar.gz |
gvfs-move: Improve progress output
Rather than spamming the screen with output, rate-limit the updates and
make them display over each other. Also calculate the speed of
transfer.
https://bugzilla.gnome.org/show_bug.cgi?id=637543
Diffstat (limited to 'programs')
-rw-r--r-- | programs/gvfs-move.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/programs/gvfs-move.c b/programs/gvfs-move.c index 0ad3d635..22978748 100644 --- a/programs/gvfs-move.c +++ b/programs/gvfs-move.c @@ -61,14 +61,34 @@ is_dir (GFile *file) return res; } +static gint64 start_time; +static gint64 previous_time; static void show_progress (goffset current_num_bytes, goffset total_num_bytes, gpointer user_data) { - g_print (_("progress")); - g_print (" %"G_GINT64_FORMAT"/%"G_GINT64_FORMAT"\n", - current_num_bytes, total_num_bytes); + gint64 tv; + char *current_size, *total_size, *rate; + + tv = g_get_monotonic_time (); + if (tv - previous_time < (G_USEC_PER_SEC / 5) && + current_num_bytes != total_num_bytes) + return; + + current_size = g_format_size (current_num_bytes); + total_size = g_format_size (total_num_bytes); + rate = g_format_size (current_num_bytes / + MAX ((tv - start_time) / G_USEC_PER_SEC, 1)); + g_print ("\r\033[K"); + g_print (_("Transferred %s out of %s (%s/s)"), + current_size, total_size, rate); + + previous_time = tv; + + g_free (current_size); + g_free (total_size); + g_free (rate); } static void @@ -178,6 +198,7 @@ main (int argc, char *argv[]) flags |= G_FILE_COPY_OVERWRITE; error = NULL; + start_time = g_get_monotonic_time (); if (!g_file_move (source, target, flags, NULL, progress?show_progress:NULL, NULL, &error)) { if (interactive && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) @@ -207,6 +228,8 @@ main (int argc, char *argv[]) retval = 1; } } + if (progress && retval == 0) + g_print("\n"); g_object_unref (source); g_object_unref (target); |