[Spice-devel] [spice-gtk][PATCH v2] Added INFO messages about a file transfer
Pavel Grunt
pgrunt at redhat.com
Thu Sep 18 01:14:19 PDT 2014
Hi,
Thanks for the review. I made changes according to your suggestions. Also all the logging is now placed just in 'gtk/spice-widget.c'.
Pavel
---
gtk/spice-widget.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 68 insertions(+), 2 deletions(-)
diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 1220030..ee344f8 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -473,6 +473,61 @@ static gboolean grab_broken(SpiceDisplay *self, GdkEventGrabBroken *event,
return false;
}
+typedef struct FileTransferInfo {
+ gchar *basename;
+ GDateTime *start_time;
+ GDateTime *last_update;
+} FileTransferInfo;
+
+static void file_progress_callback(goffset current_num_bytes,
+ goffset total_num_bytes,
+ gpointer user_data)
+{
+ GDateTime *now;
+ GTimeSpan diff;
+ const GTimeSpan interval = 20 * G_TIME_SPAN_SECOND;
+ FileTransferInfo *file_transfer_info = user_data;
+
+ if (file_transfer_info == NULL)
+ return;
+
+ now = g_date_time_new_now_local();
+
+ if (current_num_bytes == total_num_bytes) {
+ const double mega = 1048576;
+ double seconds, speed_mbps;
+
+ diff = g_date_time_difference(now, file_transfer_info->start_time);
+ seconds = (double) diff / G_TIME_SPAN_SECOND;
+ speed_mbps = (double) total_num_bytes / mega / seconds;
+
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO,
+ "transferred file %s of %.2f kB size in %.2f seconds (%.2f MB/s)",
+ file_transfer_info->basename, total_num_bytes / 1000.0,
+ seconds, speed_mbps);
+
+ g_free(file_transfer_info->basename);
+ g_date_time_unref(file_transfer_info->start_time);
+ g_date_time_unref(file_transfer_info->last_update);
+ g_date_time_unref(now);
+ g_free(file_transfer_info);
+ file_transfer_info = NULL;
+ return;
+ }
+
+ diff = g_date_time_difference(now, file_transfer_info->last_update);
+ if (diff < interval) {
+ g_date_time_unref(now);
+ return;
+ }
+
+ g_date_time_unref(file_transfer_info->last_update);
+ file_transfer_info->last_update = now;
+
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "transferred %.2f%% of the file %s",
+ 100.0 * current_num_bytes / total_num_bytes, file_transfer_info->basename);
+}
+
static void drag_data_received_callback(SpiceDisplay *self,
GdkDragContext *drag_context,
gint x,
@@ -488,6 +543,7 @@ static void drag_data_received_callback(SpiceDisplay *self,
SpiceDisplayPrivate *d = self->priv;
int i = 0;
GFile **files;
+ FileTransferInfo *file_transfer_info = NULL;
/* We get a buf like:
* file:///root/a.txt\r\nfile:///root/b.txt\r\n
@@ -504,8 +560,18 @@ static void drag_data_received_callback(SpiceDisplay *self,
}
g_strfreev(file_urls);
- spice_main_file_copy_async(d->main, files, 0, NULL, NULL,
- NULL, NULL, NULL);
+ if (n_files == 1) {
+ file_transfer_info = g_malloc0(sizeof(FileTransferInfo));
+ file_transfer_info->basename = g_file_get_basename(files[0]);
+ file_transfer_info->start_time = g_date_time_new_now_local();
+ file_transfer_info->last_update = g_date_time_ref(file_transfer_info->start_time);
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "transfer of file %s has started",
+ file_transfer_info->basename);
+ }
+
+ spice_main_file_copy_async(d->main, files, 0, NULL,
+ file_progress_callback, file_transfer_info,
+ NULL, NULL);
for (i = 0; i < n_files; i++) {
g_object_unref(files[i]);
}
--
1.9.3
More information about the Spice-devel
mailing list