diff src/gtkft.c @ 8585:e4087b5c0627

[gaim-migrate @ 9335] Patch from Pekka Riikonen to allow a prpl to accept a file transfer without choosing the save filename, and then to later complete this selection. This also provides some API extension to allow a prpl to handle its own connection setups and a posteriori add the connection to gaim's file transfer list. committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Mon, 05 Apr 2004 20:15:29 +0000
parents 5956297c6bcc
children 8db7732df1fd
line wrap: on
line diff
--- a/src/gtkft.c	Mon Apr 05 17:33:34 2004 +0000
+++ b/src/gtkft.c	Mon Apr 05 20:15:29 2004 +0000
@@ -1174,29 +1174,71 @@
 	char *buf, *size_buf;
 	size_t size;
 
-	size = gaim_xfer_get_size(xfer);
+	/* If we have already accepted the request, ask the destination file
+	   name directly */
+	if (gaim_xfer_get_status(xfer) != GAIM_XFER_STATUS_ACCEPTED) {
+		size = gaim_xfer_get_size(xfer);
+		size_buf = gaim_str_size_to_units(size);
+
+		buf = g_strdup_printf(_("%s wants to send you %s (%s)"),
+				      xfer->who, gaim_xfer_get_filename(xfer),
+				      size_buf);
+		g_free(size_buf);
 
-	size_buf = gaim_str_size_to_units(size);
+		gaim_request_accept_cancel(NULL, NULL, buf, NULL, 0, xfer,
+					   G_CALLBACK(choose_file),
+					   G_CALLBACK(cancel_recv_cb));
+		g_free(buf);
+	} else
+		choose_file(xfer);
+}
 
-	buf = g_strdup_printf(_("%s wants to send you %s (%s)"),
-						  xfer->who, gaim_xfer_get_filename(xfer), size_buf);
+static int
+ask_accept_ok(GaimXfer *xfer)
+{
+	gaim_xfer_request_accepted(xfer, NULL);
+	return 0;
+}
 
-	g_free(size_buf);
+static int
+ask_accept_cancel(GaimXfer *xfer)
+{
+	gaim_xfer_request_denied(xfer);
+	gaim_xfer_unref(xfer);
+	return 0;
+}
+
+static void
+gaim_gtkxfer_ask_accept(GaimXfer *xfer)
+{
+	char *buf, *buf2 = NULL;
 
-	gaim_request_accept_cancel(NULL, NULL, buf, NULL, 0, xfer,
-							   G_CALLBACK(choose_file),
-							   G_CALLBACK(cancel_recv_cb));
-
+	buf = g_strdup_printf(_("Accept file transfer request from %s?"),
+			      xfer->who);
+	if (gaim_xfer_get_remote_ip(xfer) &&
+	    gaim_xfer_get_remote_port(xfer))
+		buf2 = g_strdup_printf(_("A file is available for download from:\n"
+					 "Remote host: %s\nRemote port: %d"),
+				       gaim_xfer_get_remote_ip(xfer),
+				       gaim_xfer_get_remote_port(xfer));
+	gaim_request_accept_cancel(NULL, NULL, buf, buf2, 0, xfer,
+				   G_CALLBACK(ask_accept_ok),
+				   G_CALLBACK(ask_accept_cancel));
 	g_free(buf);
+	g_free(buf2);
 }
 
 static void
 gaim_gtkxfer_request_file(GaimXfer *xfer)
 {
 	gaim_xfer_ref(xfer);
-	if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE)
-		gaim_gtkxfer_ask_recv(xfer);
-	else
+	if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) {
+		if (gaim_xfer_get_filename(xfer) ||
+		    gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_ACCEPTED)
+			gaim_gtkxfer_ask_recv(xfer);
+		else
+			gaim_gtkxfer_ask_accept(xfer);
+	} else
 		choose_file(xfer);
 }