changeset 13598:41e40b323dc3

[gaim-migrate @ 15984] Previously our file transfer dialog showed "time elapsed" as the current time minus the time when the transfer was added to the ft dialog. When sending a file, the transfer is added when you offer the file to the remote user, not when the transfer actually starts. This meant the "time elapsed" was longer than it should have been, which threw off the transfer rate. This should fix that. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 09 Apr 2006 17:38:38 +0000
parents 4d8927a4f1ef
children 9f633bd09463
files src/ft.c src/ft.h src/gtkft.c
diffstat 3 files changed, 26 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/ft.c	Sun Apr 09 17:33:25 2006 +0000
+++ b/src/ft.c	Sun Apr 09 17:38:38 2006 +0000
@@ -909,6 +909,8 @@
 
 	xfer->watcher = gaim_input_add(xfer->fd, cond, transfer_cb, xfer);
 
+	xfer->start_time = time(NULL);
+
 	if (xfer->ops.start != NULL)
 		xfer->ops.start(xfer);
 }
@@ -977,6 +979,7 @@
 		return;
 	}
 
+	xfer->end_time = time(NULL);
 	if (xfer->ops.end != NULL)
 		xfer->ops.end(xfer);
 
@@ -1018,6 +1021,7 @@
 	g_return_if_fail(xfer != NULL);
 
 	gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_CANCEL_LOCAL);
+	xfer->end_time = time(NULL);
 
 	if (gaim_xfer_get_filename(xfer) != NULL)
 	{
@@ -1077,6 +1081,7 @@
 
 	gaim_request_close_with_handle(xfer);
 	gaim_xfer_set_status(xfer, GAIM_XFER_STATUS_CANCEL_REMOTE);
+	xfer->end_time = time(NULL);
 
 	account = gaim_xfer_get_account(xfer);
 	buddy = gaim_find_buddy(account, xfer->who);
--- a/src/ft.h	Sun Apr 09 17:33:25 2006 +0000
+++ b/src/ft.h	Sun Apr 09 17:38:38 2006 +0000
@@ -106,6 +106,8 @@
 
 	size_t bytes_sent;            /**< The number of bytes sent.           */
 	size_t bytes_remaining;       /**< The number of bytes remaining.      */
+	time_t start_time;            /**< When the transfer of data began.    */
+	time_t end_time;              /**< When the transfer of data ended.    */
 
 	GaimXferStatusType status;    /**< File Transfer's status.             */
 
--- a/src/gtkft.c	Sun Apr 09 17:33:25 2006 +0000
+++ b/src/gtkft.c	Sun Apr 09 17:38:38 2006 +0000
@@ -84,9 +84,7 @@
 typedef struct
 {
 	GtkTreeIter iter;
-	time_t start_time;
 	time_t last_updated_time;
-	time_t end_time;
 	gboolean in_list;
 
 	char *name;
@@ -121,35 +119,39 @@
 
 	data = GAIM_GTKXFER(xfer);
 
-	if (data->end_time == -1 &&
-		(gaim_xfer_is_canceled(xfer) || gaim_xfer_is_completed(xfer)))
-		data->end_time = time(NULL);
-
-	if (data->end_time != -1)
-		now = data->end_time;
+	if (xfer->end_time != 0)
+		now = xfer->end_time;
 	else
 		now = time(NULL);
 
 	kb_sent = gaim_xfer_get_bytes_sent(xfer) / 1024.0;
 	kb_rem  = gaim_xfer_get_bytes_remaining(xfer) / 1024.0;
-	elapsed = (now - data->start_time);
+	elapsed = (xfer->start_time > 0 ? now - xfer->start_time : 0);
 	kbps    = (elapsed > 0 ? (kb_sent / elapsed) : 0);
 
 	if (kbsec != NULL) {
 		*kbsec = g_strdup_printf(_("%.2f KB/s"), kbps);
 	}
 
-	if (time_elapsed != NULL) {
+	if (time_elapsed != NULL)
+	{
 		int h, m, s;
 		int secs_elapsed;
 
-		secs_elapsed = now - data->start_time;
+		if (xfer->start_time > 0)
+		{
+			secs_elapsed = now - xfer->start_time;
 
-		h = secs_elapsed / 3600;
-		m = (secs_elapsed % 3600) / 60;
-		s = secs_elapsed % 60;
+			h = secs_elapsed / 3600;
+			m = (secs_elapsed % 3600) / 60;
+			s = secs_elapsed % 60;
 
-		*time_elapsed = g_strdup_printf("%d:%02d:%02d", h, m, s);
+			*time_elapsed = g_strdup_printf("%d:%02d:%02d", h, m, s);
+		}
+		else
+		{
+			*time_elapsed = g_strdup(_("Not started"));
+		}
 	}
 
 	if (time_remaining != NULL) {
@@ -227,10 +229,10 @@
 							 _("<b>Sending As:</b>"));
 	}
 
-	gtk_label_set_text(GTK_LABEL(dialog->local_user_label), 
+	gtk_label_set_text(GTK_LABEL(dialog->local_user_label),
 								 gaim_account_get_username(xfer->account));
 	gtk_label_set_text(GTK_LABEL(dialog->remote_user_label), xfer->who);
-	gtk_label_set_text(GTK_LABEL(dialog->protocol_label), 
+	gtk_label_set_text(GTK_LABEL(dialog->protocol_label),
 								 gaim_account_get_protocol_name(xfer->account));
 
 	if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) {
@@ -892,9 +894,7 @@
 
 	gaim_gtkxfer_dialog_show(dialog);
 
-	data->start_time = time(NULL);
 	data->last_updated_time = 0;
-	data->end_time = -1;
 
 	type = gaim_xfer_get_type(xfer);