changeset 17054:21830d70709b

Patch from sourceforge tracker 1652005 from wabz to fix displaying file transfer progress for MSN transfers. Fixes #595.
author Stu Tomlinson <stu@nosnilmot.com>
date Sat, 12 May 2007 13:20:04 +0000
parents 53e757c37e06
children 8ee93c68ced0
files libpurple/ft.c libpurple/protocols/msn/msn.c libpurple/protocols/msn/slp.c libpurple/protocols/msn/slplink.c
diffstat 4 files changed, 18 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/ft.c	Fri May 11 20:06:57 2007 +0000
+++ b/libpurple/ft.c	Sat May 12 13:20:04 2007 +0000
@@ -972,7 +972,8 @@
 
 	fseek(xfer->dest_fp, xfer->bytes_sent, SEEK_SET);
 
-	xfer->watcher = purple_input_add(xfer->fd, cond, transfer_cb, xfer);
+	if (xfer->fd)
+		xfer->watcher = purple_input_add(xfer->fd, cond, transfer_cb, xfer);
 
 	xfer->start_time = time(NULL);
 
--- a/libpurple/protocols/msn/msn.c	Fri May 11 20:06:57 2007 +0000
+++ b/libpurple/protocols/msn/msn.c	Sat May 12 13:20:04 2007 +0000
@@ -409,33 +409,7 @@
 static void
 t_msn_xfer_init(PurpleXfer *xfer)
 {
-	MsnSlpLink *slplink;
-	const char *filename;
-	FILE *fp;
-
-	filename = purple_xfer_get_local_filename(xfer);
-
-	slplink = xfer->data;
-
-	if ((fp = g_fopen(filename, "rb")) == NULL)
-	{
-		PurpleAccount *account;
-		const char *who;
-		char *msg;
-
-		account = slplink->session->account;
-		who = slplink->remote_user;
-
-		msg = g_strdup_printf(_("Error reading %s: \n%s.\n"),
-							  filename, strerror(errno));
-		purple_xfer_error(purple_xfer_get_type(xfer), account, xfer->who, msg);
-		purple_xfer_cancel_local(xfer);
-		g_free(msg);
-
-		return;
-	}
-	fclose(fp);
-
+	MsnSlpLink *slplink = xfer->data;
 	msn_slplink_request_ft(slplink, xfer);
 }
 
--- a/libpurple/protocols/msn/slp.c	Fri May 11 20:06:57 2007 +0000
+++ b/libpurple/protocols/msn/slp.c	Sat May 12 13:20:04 2007 +0000
@@ -158,7 +158,9 @@
 msn_xfer_completed_cb(MsnSlpCall *slpcall, const guchar *body,
 					  gsize size)
 {
-	purple_xfer_set_completed(slpcall->xfer, TRUE);
+	PurpleXfer *xfer = slpcall->xfer;
+	purple_xfer_set_completed(xfer, TRUE);
+	purple_xfer_end(xfer);
 }
 
 /**************************************************************************
--- a/libpurple/protocols/msn/slplink.c	Fri May 11 20:06:57 2007 +0000
+++ b/libpurple/protocols/msn/slplink.c	Sat May 12 13:20:04 2007 +0000
@@ -482,6 +482,8 @@
 {
 	MsnSlpCall *slpcall;
 	MsnSlpMessage *slpmsg;
+	struct stat st;
+	PurpleXfer *xfer;
 
 	slpcall = slpsession->slpcall;
 	slpmsg = msn_slpmsg_new(slpcall->slplink);
@@ -491,7 +493,12 @@
 #ifdef MSN_DEBUG_SLP
 	slpmsg->info = "SLP FILE";
 #endif
-	msn_slpmsg_open_file(slpmsg, purple_xfer_get_local_filename(slpcall->xfer));
+	xfer = (PurpleXfer *)slpcall->xfer;
+	purple_xfer_start(slpcall->xfer, 0, NULL, 0);
+	slpmsg->fp = xfer->dest_fp;
+	if (g_stat(purple_xfer_get_local_filename(xfer), &st) == 0)
+		slpmsg->size = st.st_size;
+	xfer->dest_fp = NULL; /* Disable double fclose() */
 
 	msn_slplink_send_slpmsg(slpcall->slplink, slpmsg);
 }
@@ -551,9 +558,10 @@
 
 					if (xfer != NULL)
 					{
-						slpmsg->fp =
-							g_fopen(purple_xfer_get_local_filename(slpmsg->slpcall->xfer),
-								  "wb");
+						purple_xfer_start(slpmsg->slpcall->xfer,
+							0, NULL, 0);
+						slpmsg->fp = ((PurpleXfer *)slpmsg->slpcall->xfer)->dest_fp;
+						xfer->dest_fp = NULL; /* Disable double fclose() */
 					}
 				}
 			}