talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit e895ed1467f5f85a663dbd4af529d681456cebbb
parent 61383c66ea45ad4e17efce4c59441b35bae5ff25
Author: Andrej Kacian <ticho@claws-mail.org>
Date:   Fri, 22 Apr 2016 20:04:02 +0200

More fixes for the Windows native file choosers.

Filter string should be terminated with two nuls.
Save dialog did not show for message parts which have no
attachment name.

Diffstat:
Msrc/gtk/w32_filesel.c | 32+++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/src/gtk/w32_filesel.c b/src/gtk/w32_filesel.c @@ -245,7 +245,8 @@ gchar *filesel_select_file_open_with_filter(const gchar *title, const gchar *pat o.Flags = OFN_LONGNAMES; if (filter != NULL && strlen(filter) > 0) { - win_filter = g_strdup_printf("%s%c%s%c", filter, '\0', filter, '\0'); + win_filter = g_strdup_printf("%s%c%s%c%c", + filter, '\0', filter, '\0', '\0'); win_filter16 = g_utf8_to_utf16(win_filter, -1, NULL, NULL, &error); g_free(win_filter); if (error != NULL) { @@ -317,8 +318,8 @@ GList *filesel_select_multiple_files_open_with_filter(const gchar *title, gchar *filesel_select_file_save(const gchar *title, const gchar *path) { gboolean ret; - gchar *str; - gunichar2 *path16, *title16; + gchar *str, *filename = NULL; + gunichar2 *filename16, *path16, *title16; glong conv_items; GError *error = NULL; WinChooserCtx *ctx; @@ -326,14 +327,34 @@ gchar *filesel_select_file_save(const gchar *title, const gchar *path) pthread_t pt; #endif + /* Find the filename part, if any */ + if (path[strlen(path)-1] == G_DIR_SEPARATOR) { + filename = ""; + } else if ((filename = strrchr(path, G_DIR_SEPARATOR)) != NULL) { + filename++; + } else { + filename = (char *) path; + } + + /* Convert it to UTF-16. */ + filename16 = g_utf8_to_utf16(filename, -1, NULL, &conv_items, &error); + if (error != NULL) { + alertpanel_error(_("Could not convert attachment name to UTF-16:\n\n%s"), + error->message); + debug_print("filename '%s' conversion to UTF-16 failed\n", filename); + g_error_free(error); + return NULL; + } + /* Path needs to be converted to UTF-16, so that the native chooser * can understand it. */ - path16 = g_utf8_to_utf16(path, -1, NULL, &conv_items, &error); + path16 = g_utf8_to_utf16(path, -1, NULL, NULL, &error); if (error != NULL) { alertpanel_error(_("Could not convert file path to UTF-16:\n\n%s"), error->message); debug_print("file path '%s' conversion to UTF-16 failed\n", path); g_error_free(error); + g_free(filename16); return NULL; } @@ -353,7 +374,7 @@ gchar *filesel_select_file_save(const gchar *title, const gchar *path) o.lpstrCustomFilter = NULL; o.lpstrFile = g_malloc0(MAXPATHLEN); if (path16 != NULL) - memcpy(o.lpstrFile, path16, conv_items * sizeof(gunichar2)); + memcpy(o.lpstrFile, filename16, conv_items * sizeof(gunichar2)); o.nMaxFile = MAXPATHLEN; o.lpstrFileTitle = NULL; o.lpstrInitialDir = path16; @@ -382,6 +403,7 @@ gchar *filesel_select_file_save(const gchar *title, const gchar *path) ret = GetSaveFileName(&o); #endif + g_free(filename16); g_free(path16); g_free(title16); g_free(ctx);