/cpw/tomkiewicz/gg11: 6c08701e549f: Better display of file trans...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Tue Oct 23 06:53:17 EDT 2012


Changeset: 6c08701e549fa54c40a3e57520c2814541ee7d44
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-10-23 12:53 +0200
Branch:	 default
URL: http://hg.pidgin.im/cpw/tomkiewicz/gg11/rev/6c08701e549f

Description:

Better display of file transfer progress

diffstat:

 libpurple/protocols/gg/edisc.c |  33 ++++++++++++++++++++++++++++-----
 libpurple/protocols/gg/utils.c |  10 ----------
 libpurple/protocols/gg/utils.h |   2 --
 3 files changed, 28 insertions(+), 17 deletions(-)

diffs (90 lines):

diff --git a/libpurple/protocols/gg/edisc.c b/libpurple/protocols/gg/edisc.c
--- a/libpurple/protocols/gg/edisc.c
+++ b/libpurple/protocols/gg/edisc.c
@@ -346,7 +346,6 @@ static void ggp_edisc_xfer_reader(Purple
 	}
 
 	stored = fread(buffer, 1, length, xfer->dest_fp);
-	purple_debug_info("gg", "READ: %d\n", stored);
 	if (stored < 0)
 		success = FALSE;
 	else {
@@ -355,11 +354,32 @@ static void ggp_edisc_xfer_reader(Purple
 		eof = (edisc_xfer->already_read >= purple_xfer_get_size(xfer));
 	}
 
-	/* TODO: this is a cheat, watch http connection to do it well */
-	purple_xfer_set_bytes_sent(xfer, edisc_xfer->already_read); 
+	cb(hc, success, eof, stored);
+}
+
+static void ggp_edisc_xfer_progress_watcher(PurpleHttpConnection *hc,
+	gboolean reading_state, int processed, int total, gpointer _xfer)
+{
+	PurpleXfer *xfer = _xfer;
+	gboolean eof;
+	int total_real;
+
+	if (purple_xfer_get_type(xfer) != PURPLE_XFER_SEND) {
+		purple_debug_error("gg", "ggp_edisc_xfer_start: "
+			"Not yet implemented\n");
+		return;
+	}
+
+	if (reading_state)
+		return;
+
+	eof = (processed >= total);
+	total_real = purple_xfer_get_size(xfer);
+	if (eof || processed > total_real)
+		processed = total_real; /* just to be sure */
+
+	purple_xfer_set_bytes_sent(xfer, processed);
 	purple_xfer_update_progress(xfer);
-
-	cb(hc, success, eof, stored);
 }
 
 static void ggp_edisc_xfer_start(PurpleXfer *xfer)
@@ -404,6 +424,9 @@ static void ggp_edisc_xfer_start(PurpleX
 	edisc_xfer->hc = purple_http_request(edisc_xfer->gc, req,
 		ggp_edisc_xfer_sent, xfer);
 	purple_http_request_unref(req);
+
+	purple_http_conn_set_progress_watcher(edisc_xfer->hc,
+		ggp_edisc_xfer_progress_watcher, xfer, 250000);
 }
 
 static void ggp_edisc_xfer_sent(PurpleHttpConnection *hc,
diff --git a/libpurple/protocols/gg/utils.c b/libpurple/protocols/gg/utils.c
--- a/libpurple/protocols/gg/utils.c
+++ b/libpurple/protocols/gg/utils.c
@@ -102,16 +102,6 @@ gboolean ggp_password_validate(const gch
 		"<>\\\\|-]+$", password, 0, 0);
 }
 
-guint64 ggp_microtime(void)
-{
-	// replace with g_get_monotonic_time, when gtk 2.28 will be available
-	GTimeVal time_s;
-	
-	g_get_current_time(&time_s);
-	
-	return ((guint64)time_s.tv_sec << 32) | time_s.tv_usec;
-}
-
 gchar * ggp_utf8_strndup(const gchar *str, gsize n)
 {
 	int raw_len = strlen(str);
diff --git a/libpurple/protocols/gg/utils.h b/libpurple/protocols/gg/utils.h
--- a/libpurple/protocols/gg/utils.h
+++ b/libpurple/protocols/gg/utils.h
@@ -74,8 +74,6 @@ gchar * ggp_convert_from_cp1250(const gc
 
 gboolean ggp_password_validate(const gchar *password);
 
-guint64 ggp_microtime(void);
-
 gchar * ggp_utf8_strndup(const gchar *str, gsize n);
 
 GSList * ggp_list_copy_to_slist_deep(GList *list, GCopyFunc func,



More information about the Commits mailing list