# HG changeset patch # User Ethan Blanton # Date 1081196129 0 # Node ID e4087b5c0627cf7ce6e4c179404018704e5d8388 # Parent 058efd3cb86ff1ffcb672aa2f9f74ca432bc68b0 [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 diff -r 058efd3cb86f -r e4087b5c0627 src/ft.c --- a/src/ft.c Mon Apr 05 17:33:34 2004 +0000 +++ b/src/ft.c Mon Apr 05 20:15:29 2004 +0000 @@ -123,12 +123,17 @@ { GaimXferType type; - if (xfer == NULL || filename == NULL) { + if (xfer == NULL) + return; + + type = gaim_xfer_get_type(xfer); + + if (!filename && type == GAIM_XFER_RECEIVE) { + xfer->status = GAIM_XFER_STATUS_ACCEPTED; + xfer->ops.init(xfer); return; } - type = gaim_xfer_get_type(xfer); - if (type == GAIM_XFER_SEND) { struct stat sb; @@ -324,7 +329,6 @@ if (ui_ops != NULL && ui_ops->update_progress != NULL) ui_ops->update_progress(xfer, gaim_xfer_get_progress(xfer)); - } void @@ -672,6 +676,19 @@ } void +gaim_xfer_add(GaimXfer *xfer) +{ + GaimXferUiOps *ui_ops; + + g_return_if_fail(xfer != NULL); + + ui_ops = gaim_xfer_get_ui_ops(xfer); + + if (ui_ops != NULL && ui_ops->add_xfer != NULL) + ui_ops->add_xfer(xfer); +} + +void gaim_xfer_cancel_local(GaimXfer *xfer) { GaimXferUiOps *ui_ops; @@ -775,6 +792,19 @@ g_free(title); } +void +gaim_xfer_update_progress(GaimXfer *xfer) +{ + GaimXferUiOps *ui_ops; + + g_return_if_fail(xfer != NULL); + + ui_ops = gaim_xfer_get_ui_ops(xfer); + if (ui_ops != NULL && ui_ops->update_progress != NULL) + ui_ops->update_progress(xfer, gaim_xfer_get_progress(xfer)); +} + + /************************************************************************** * File Transfer Subsystem API **************************************************************************/ @@ -790,4 +820,3 @@ { return xfer_ui_ops; } - diff -r 058efd3cb86f -r e4087b5c0627 src/ft.h --- a/src/ft.h Mon Apr 05 17:33:34 2004 +0000 +++ b/src/ft.h Mon Apr 05 20:15:29 2004 +0000 @@ -50,6 +50,7 @@ { GAIM_XFER_STATUS_UNKNOWN = 0, /**< Unknown, the xfer may be null. */ GAIM_XFER_STATUS_NOT_STARTED, /**< It hasn't started yet. */ + GAIM_XFER_STATUS_ACCEPTED, /**< Receive accepted, but destination file not selected yet */ GAIM_XFER_STATUS_STARTED, /**< gaim_xfer_start has been called. */ GAIM_XFER_STATUS_DONE, /**< The xfer completed successfully. */ GAIM_XFER_STATUS_CANCEL_LOCAL, /**< The xfer was canceled by us. */ @@ -172,7 +173,11 @@ void gaim_xfer_unref(GaimXfer *xfer); /** - * Requests confirmation for a file transfer from the user. + * Requests confirmation for a file transfer from the user. If receiving + * a file which is known at this point, this requests user to accept and + * save the file. If the filename is unknown (not set) this only requests user + * to accept the file transfer. In this case protocol must call this function + * again once the filename is available. * * @param xfer The file transfer to request confirmation on. */ @@ -485,6 +490,14 @@ void gaim_xfer_end(GaimXfer *xfer); /** + * Adds a new file transfer to the list of file transfers. Call this only + * if you are not using gaim_xfer_start. + * + * @param xfer The file transfer. + */ +void gaim_xfer_add(GaimXfer *xfer); + +/** * Cancels a file transfer on the local end. * * @param xfer The file transfer. @@ -511,6 +524,13 @@ */ void gaim_xfer_error(GaimXferType type, const char *who, const char *msg); +/** + * Updates file transfer progress. + * + * @param xfer The file transfer. + */ +void gaim_xfer_update_progress(GaimXfer *xfer); + /*@}*/ /**************************************************************************/ diff -r 058efd3cb86f -r e4087b5c0627 src/gtkft.c --- 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); }