changeset 10919:9695281b1aa1

[gaim-migrate @ 12683] Better handling of filenames in file transfers when using a non-UTF8 filename encoding on the filesyste. This should fix a number of bugs. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Sun, 15 May 2005 18:16:20 +0000
parents 893921a6cc6e
children 6a8440e9edba
files src/ft.c src/gtkft.c
diffstat 2 files changed, 36 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/ft.c	Sun May 15 13:28:11 2005 +0000
+++ b/src/ft.c	Sun May 15 18:16:20 2005 +0000
@@ -140,24 +140,27 @@
 
 static void gaim_xfer_show_file_error(GaimXfer *xfer, const char *filename)
 {
-	gchar *msg = NULL;
+	int err = errno;
+	gchar *msg = NULL, *utf8;
 	GaimXferType xfer_type = gaim_xfer_get_type(xfer);
 	GaimAccount *account = gaim_xfer_get_account(xfer);
 
+	utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
 	switch(xfer_type) {
 		case GAIM_XFER_SEND:
 			msg = g_strdup_printf(_("Error reading %s: \n%s.\n"),
-								  filename, strerror(errno));
+								  utf8, strerror(err));
 			break;
 		case GAIM_XFER_RECEIVE:
 			msg = g_strdup_printf(_("Error writing %s: \n%s.\n"),
-								  filename, strerror(errno));
+								  utf8, strerror(err));
 			break;
 		default:
 			msg = g_strdup_printf(_("Error accessing %s: \n%s.\n"),
-								  filename, strerror(errno));
+								  utf8, strerror(err));
 			break;
-		}
+	}
+	g_free(utf8);
 
 	gaim_xfer_conversation_write(xfer, msg, TRUE);
 	gaim_xfer_error(xfer_type, account, xfer->who, msg);
@@ -202,8 +205,11 @@
 	}
 	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);
+		char *msg, *utf8;
+		utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
+		msg = g_strdup_printf(
+					_("%s is not a regular file. Cowardly refusing to overwrite it.\n"), utf8);
+		g_free(utf8);
 		gaim_notify_error(NULL, NULL, msg, NULL);
 		g_free(msg);
 		gaim_xfer_request_denied(xfer);
@@ -347,7 +353,7 @@
 {
 	GaimXferType type;
 	struct stat st;
-	char *msg;
+	char *msg, *utf8;
 	GaimAccount *account;
 	GaimBuddy *buddy;
 
@@ -368,9 +374,11 @@
 	if (type == GAIM_XFER_SEND) {
 		/* Check the filename. */
 		if (g_strrstr(filename, "..")) {
+			char *utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
 
-			msg = g_strdup_printf(_("%s is not a valid filename.\n"), filename);
+			msg = g_strdup_printf(_("%s is not a valid filename.\n"), utf8);
 			gaim_xfer_error(type, account, xfer->who, msg);
+			g_free(utf8);
 			g_free(msg);
 
 			gaim_xfer_unref(xfer);
@@ -384,11 +392,15 @@
 		}
 
 		gaim_xfer_set_local_filename(xfer, filename);
-		gaim_xfer_set_filename(xfer, g_basename(filename));
 		gaim_xfer_set_size(xfer, st.st_size);
 
+		utf8 = g_filename_to_utf8(g_basename(filename), -1, NULL, NULL, NULL);
+		gaim_xfer_set_filename(xfer, utf8);
+
 		msg = g_strdup_printf(_("Offering to send %s to %s"),
-				filename, buddy ? gaim_buddy_get_alias(buddy) : xfer->who);
+				utf8, buddy ? gaim_buddy_get_alias(buddy) : xfer->who);
+		g_free(utf8);
+
 		gaim_xfer_conversation_write(xfer, msg, FALSE);
 		g_free(msg);
 	}
--- a/src/gtkft.c	Sun May 15 13:28:11 2005 +0000
+++ b/src/gtkft.c	Sun May 15 18:16:20 2005 +0000
@@ -187,7 +187,7 @@
 {
 	GaimGtkXferUiData *data;
 	char *kbsec, *time_elapsed, *time_remaining;
-	char *status;
+	char *status, *utf8;
 
 	if (dialog == NULL || xfer == NULL)
 		return;
@@ -240,13 +240,18 @@
 					   gaim_xfer_get_filename(xfer));
 	} else {
 		char *tmp;
+
 		tmp = g_path_get_basename(gaim_xfer_get_local_filename(xfer));
-		gtk_label_set_text(GTK_LABEL(dialog->filename_label), tmp);
+		utf8 = g_filename_to_utf8(tmp, -1, NULL, NULL, NULL);
 		g_free(tmp);
+
+		gtk_label_set_text(GTK_LABEL(dialog->filename_label), utf8);
+		g_free(utf8);
 	}
 
-	gtk_label_set_text(GTK_LABEL(dialog->localfile_label),
-			gaim_xfer_get_local_filename(xfer));
+	utf8 = g_filename_to_utf8((gaim_xfer_get_local_filename(xfer)), -1, NULL, NULL, NULL);
+	gtk_label_set_text(GTK_LABEL(dialog->localfile_label), utf8);
+	g_free(utf8);
 
 	gtk_label_set_text(GTK_LABEL(dialog->status_label), status);
 
@@ -803,7 +808,7 @@
 	GaimXferType type;
 	GdkPixbuf *pixbuf;
 	char *size_str, *remaining_str;
-	char *lfilename;
+	char *lfilename, *utf8;
 
 	g_return_if_fail(dialog != NULL);
 	g_return_if_fail(xfer != NULL);
@@ -831,6 +836,9 @@
 
 	gtk_list_store_append(dialog->model, &data->iter);
 	lfilename = g_path_get_basename(gaim_xfer_get_local_filename(xfer));
+	utf8 = g_filename_to_utf8(lfilename, -1, NULL, NULL, NULL);
+	g_free(lfilename);
+	lfilename = utf8;
 	gtk_list_store_set(dialog->model, &data->iter,
 					   COLUMN_STATUS, pixbuf,
 					   COLUMN_PROGRESS, 0.0,