Mercurial > pidgin
changeset 9785:2356d2153c94
[gaim-migrate @ 10653]
Dave West made us check errno and give better file related errors for
file transfers.
He also added some information to the xfer dialog, like the protocol
and account name.
He also made the initial status of xfers added to the dialog be "waiting
for transfer to start"
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Thu, 19 Aug 2004 22:46:08 +0000 |
parents | d7cc09a9da4c |
children | 3e7e294f56f3 |
files | src/ft.c src/gtkft.c |
diffstat | 2 files changed, 108 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ft.c Thu Aug 19 18:28:03 2004 +0000 +++ b/src/ft.c Thu Aug 19 22:46:08 2004 +0000 @@ -107,6 +107,59 @@ gaim_xfer_destroy(xfer); } +static void gaim_xfer_show_file_error(const char *filename) +{ + char *msg = NULL; + + switch(errno) + { + case ENOENT: + msg = g_strdup_printf(_("%s does not exist.\n"), filename); + break; + case EISDIR: + msg = g_strdup_printf(_("%s is a directory, not a file.\n"), filename); + break; + case ENOTDIR: + msg = g_strdup_printf( _("A component of %s is not a directory.\n"), filename); + break; + case ELOOP: + msg = g_strdup_printf( _("Too many symbolic links in path for %s\n"), filename); + break; + case EACCES: + msg = g_strdup_printf( _("Permission denied accessing %s\n"), filename); + break; + case ENAMETOOLONG: + msg = g_strdup_printf(_("File name too long: %s\n"), filename); + break; + case EROFS: + msg = g_strdup_printf(_("Cannot write %s: Read only filesystem\n"), filename); + break; + case ENOSPC: + msg = g_strdup_printf(_("Cannot write %s: No space on filesystem\n"), filename); + break; + case ETXTBSY: + msg = g_strdup_printf(_("Cannot write %s: File is in use\n"), filename); + break; + case EMFILE: + msg = g_strdup_printf(_("Cannot open %s: Gaim has too many files open\n"), filename); + break; + case ENFILE: + msg = g_strdup_printf(_("Cannot open %s: Your user or system has too many files open\n"), filename); + break; + case ENOMEM: + msg = g_strdup_printf(_("Cannot open %s: Not enough memory\n"), filename); + break; + default: + msg = NULL; + break; + } + + if( msg != NULL ) { + gaim_notify_error(NULL, NULL, msg, NULL); + g_free(msg); + } +} + static void gaim_xfer_choose_file_ok_cb(void *user_data, const char *filename) { @@ -121,9 +174,7 @@ gaim_xfer_request_accepted(xfer, filename); } else { - gaim_notify_error(NULL, NULL, - _("That file does not exist."), NULL); - + gaim_xfer_show_file_error(filename); gaim_xfer_request_denied(xfer); } } @@ -135,19 +186,26 @@ gaim_xfer_request_denied(xfer); } + else if ((gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) && + S_ISDIR(st.st_mode)) { + /* + * XXX - Sending a directory should be valid for some protocols. + */ + gaim_notify_error(NULL, NULL, + _("Cannot send a directory."), NULL); + + gaim_xfer_request_denied(xfer); + } + else if ((gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) && + S_ISDIR(st.st_mode)) { + char *msg = g_strdup_printf( + _("%s is not a regular file. Cowardly refusing to overwrite it.\n"), filename); + gaim_notify_error(NULL, NULL, msg, NULL); + g_free(msg); + gaim_xfer_request_denied(xfer); + } else { - if (S_ISDIR(st.st_mode)) { - /* - * XXX - Sending a directory should be valid for some protocols. - */ - gaim_xfer_request_denied(xfer); - } - else if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { - gaim_xfer_request_accepted(xfer, filename); - } - else { - gaim_xfer_request_accepted(xfer, filename); - } + gaim_xfer_request_accepted(xfer, filename); } gaim_xfer_unref(xfer); @@ -265,6 +323,7 @@ gaim_xfer_request_accepted(GaimXfer *xfer, const char *filename) { GaimXferType type; + struct stat st; if (xfer == NULL) return; @@ -278,8 +337,6 @@ } if (type == GAIM_XFER_SEND) { - struct stat sb; - /* Check the filename. */ if (g_strrstr(filename, "..")) { char *msg; @@ -294,24 +351,17 @@ return; } - if (stat(filename, &sb) == -1) { - char *msg; - - msg = g_strdup_printf(_("%s was not found.\n"), filename); - - gaim_xfer_error(type, xfer->who, msg); - - g_free(msg); + if (stat(filename, &st) == -1) { + gaim_xfer_show_file_error(filename); gaim_xfer_unref(xfer); return; } gaim_xfer_set_local_filename(xfer, filename); - gaim_xfer_set_size(xfer, sb.st_size); + gaim_xfer_set_size(xfer, st.st_size); } else { - /* TODO: Sanity checks and file overwrite checks. */ - + xfer->status = GAIM_XFER_STATUS_ACCEPTED; gaim_xfer_set_local_filename(xfer, filename); } @@ -710,16 +760,12 @@ { GaimXferType type = gaim_xfer_get_type(xfer); - /* - * We'll have already tried to open this earlier to make sure we can - * read/write here. Should be safe. - */ xfer->dest_fp = fopen(gaim_xfer_get_local_filename(xfer), type == GAIM_XFER_RECEIVE ? "wb" : "rb"); - /* Just in case, though. */ if (xfer->dest_fp == NULL) { - gaim_xfer_cancel_local(xfer); /* ? */ + gaim_xfer_show_file_error(gaim_xfer_get_local_filename(xfer)); + gaim_xfer_cancel_local(xfer); return; }
--- a/src/gtkft.c Thu Aug 19 18:28:03 2004 +0000 +++ b/src/gtkft.c Thu Aug 19 22:46:08 2004 +0000 @@ -57,8 +57,11 @@ GtkWidget *table; - GtkWidget *user_desc_label; - GtkWidget *user_label; + GtkWidget *local_user_desc_label; + GtkWidget *local_user_label; + GtkWidget *remote_user_desc_label; + GtkWidget *remote_user_label; + GtkWidget *protocol_label; GtkWidget *filename_label; GtkWidget *status_label; GtkWidget *speed_label; @@ -211,14 +214,24 @@ g_object_unref(pixbuf); } - if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) - gtk_label_set_markup(GTK_LABEL(dialog->user_desc_label), + if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { + gtk_label_set_markup(GTK_LABEL(dialog->local_user_desc_label), + _("<b>Receiving As:</b>")); + gtk_label_set_markup(GTK_LABEL(dialog->remote_user_desc_label), _("<b>Receiving From:</b>")); - else - gtk_label_set_markup(GTK_LABEL(dialog->user_desc_label), + } + else { + gtk_label_set_markup(GTK_LABEL(dialog->remote_user_desc_label), _("<b>Sending To:</b>")); + gtk_label_set_markup(GTK_LABEL(dialog->local_user_desc_label), + _("<b>Sending As:</b>")); + } - gtk_label_set_text(GTK_LABEL(dialog->user_label), xfer->who); + 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), + gaim_account_get_protocol_name(xfer->account)); if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { gtk_label_set_text(GTK_LABEL(dialog->filename_label), @@ -536,7 +549,9 @@ } labels[] = { - { &dialog->user_desc_label, &dialog->user_label, NULL }, + { &dialog->local_user_desc_label, &dialog->local_user_label, NULL }, + { &dialog->remote_user_desc_label, &dialog->remote_user_label, NULL }, + { &label, &dialog->protocol_label, _("Protocol:") }, { &label, &dialog->filename_label, _("Filename:") }, { &label, &dialog->status_label, _("Status:") }, { &label, &dialog->speed_label, _("Speed:") }, @@ -545,7 +560,7 @@ }; /* Setup the initial table */ - dialog->table = table = gtk_table_new(8, 2, FALSE); + dialog->table = table = gtk_table_new(10, 2, FALSE); gtk_table_set_row_spacings(GTK_TABLE(table), 6); gtk_table_set_col_spacings(GTK_TABLE(table), 6); @@ -574,12 +589,12 @@ /* Setup the progress bar */ dialog->progress = gtk_progress_bar_new(); - gtk_table_attach(GTK_TABLE(table), dialog->progress, 0, 2, 6, 7, + gtk_table_attach(GTK_TABLE(table), dialog->progress, 0, 2, 8, 9, GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show(dialog->progress); sep = gtk_hseparator_new(); - gtk_table_attach(GTK_TABLE(table), sep, 0, 2, 7, 8, + gtk_table_attach(GTK_TABLE(table), sep, 0, 2, 9, 10, GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show(sep); @@ -829,7 +844,7 @@ ? gaim_xfer_get_filename(xfer) : lfilename, COLUMN_SIZE, size_str, - COLUMN_REMAINING, remaining_str, + COLUMN_REMAINING, _("Waiting for transfer to begin"), COLUMN_DATA, xfer, -1); g_free(lfilename); @@ -963,7 +978,7 @@ -1); g_object_unref(pixbuf); - } + } selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(xfer_dialog->tree));