From efe73b08dc955779e7fab8a6e8ecb60d61c05a6e Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 21 Feb 2016 18:28:23 +0100 Subject: [PATCH 1/3] Fix the file dialog on Linux being case sensitive --- src/platform/linux.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/platform/linux.c b/src/platform/linux.c index 0eddce4344..b87c39d1b0 100644 --- a/src/platform/linux.c +++ b/src/platform/linux.c @@ -219,6 +219,7 @@ int platform_open_common_file_dialog(filedialog_type type, utf8 *title, utf8 *fi char *action; char *flags; char *filter = NULL; + char *filterPatternRegex; size = MAX_PATH; dtype = get_dialog_app(executable, &size); @@ -235,11 +236,11 @@ int platform_open_common_file_dialog(filedialog_type type, utf8 *title, utf8 *fi } if (filterPattern && filterName) { - filter = (char*) malloc(strlen(filterPattern) + 3 + strlen(filterName) + 1); + filter = (char*) malloc(1 + strlen(filterPattern) + 3 + strlen(filterName) + 1); sprintf(filter, "\"%s | %s\"", filterPattern, filterName); } - snprintf(cmd, MAX_PATH, "%s --title \"%s\" %s / %s", executable, title, action, filter?filter:""); + snprintf(cmd, MAX_PATH, "%s --title \"%s\" %s ~ %s", executable, title, action, filter?filter:""); break; case DT_ZENITY: action = "--file-selection"; @@ -252,9 +253,27 @@ int platform_open_common_file_dialog(filedialog_type type, utf8 *title, utf8 *fi break; } + // Zenity seems to be case sensitive, while Kdialog isn't. if (filterPattern && filterName) { - filter = (char*) malloc(strlen("--file-filter=\"") + strlen(filterPattern) + 3 + strlen(filterName) + 2); - sprintf(filter, "--file-filter=\"%s | %s\"", filterName, filterPattern); + if(strcmp(filterPattern, "*.sv6") == 0) + filterPatternRegex = "*.[Ss][Vv]6"; + else if(strcmp(filterPattern, "*.sc6") == 0) + filterPatternRegex = "*.[Ss][Cc]6"; + else if(strcmp(filterPattern, ".td6") == 0) + filterPatternRegex = "*.[Tt][Dd]6"; + else if(strcmp(filterPattern, "*.sv4") == 0) + filterPatternRegex = "*.[Ss][Vv]4"; + else if(strcmp(filterPattern, "*.sc4") == 0) + filterPatternRegex = "*.[Ss][Cc]4"; + else if(strcmp(filterPattern, "*.td4") == 0) + filterPatternRegex = "*.[Tt][Dd]4"; + else if(strcmp(filterPattern, "*.dat") == 0) + filterPatternRegex = "*.[Dd][Aa][Tt]"; + else + filterPatternRegex = (char *)filterPattern; + + filter = (char*) malloc(strlen("--file-filter=\"") + strlen(filterPatternRegex) + 3 + strlen(filterName) + 2 + strlen(" --file-filter=\"All files | *\"")); + sprintf(filter, "--file-filter=\"%s | %s\" --file-filter=\"All files | *\"", filterName, filterPatternRegex); } snprintf(cmd, MAX_PATH, "%s %s %s --title=\"%s\" / %s", executable, action, flags, title, filter?filter:""); From 21cb7a948b0d30276efa90a23241b0cdfe7d87c3 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 21 Feb 2016 18:42:55 +0100 Subject: [PATCH 2/3] Make 'All files' translatable --- data/language/english_uk.txt | 1 + src/localisation/string_ids.h | 2 ++ src/platform/linux.c | 8 ++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index 6a4848a534..d0e55a898d 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -4067,6 +4067,7 @@ STR_5759 :Downloading map ... ({INT32} / {INT32}) STR_5760 :Hong Kong Dollars (HK$) STR_5761 :New Taiwan Dollar (NT$) STR_5762 :Chinese Yuan (CN{YEN}) +STR_5763 :All files ############# # Scenarios # diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index b2420cc64e..a84b047462 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -2370,6 +2370,8 @@ enum { STR_NEW_TAIWAN_DOLLAR = 5761, STR_CHINESE_YUAN = 5762, + STR_ALL_FILES = 5763, + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working STR_COUNT = 32768 }; diff --git a/src/platform/linux.c b/src/platform/linux.c index b87c39d1b0..7580338e8f 100644 --- a/src/platform/linux.c +++ b/src/platform/linux.c @@ -26,6 +26,8 @@ #include #include +#include "../localisation/language.h" +#include "../localisation/string_ids.h" #include "../util/util.h" #include "platform.h" @@ -220,6 +222,7 @@ int platform_open_common_file_dialog(filedialog_type type, utf8 *title, utf8 *fi char *flags; char *filter = NULL; char *filterPatternRegex; + char *allFilesPatternDescription; size = MAX_PATH; dtype = get_dialog_app(executable, &size); @@ -272,8 +275,9 @@ int platform_open_common_file_dialog(filedialog_type type, utf8 *title, utf8 *fi else filterPatternRegex = (char *)filterPattern; - filter = (char*) malloc(strlen("--file-filter=\"") + strlen(filterPatternRegex) + 3 + strlen(filterName) + 2 + strlen(" --file-filter=\"All files | *\"")); - sprintf(filter, "--file-filter=\"%s | %s\" --file-filter=\"All files | *\"", filterName, filterPatternRegex); + allFilesPatternDescription = (char *)language_get_string(STR_ALL_FILES); + filter = (char*) malloc(strlen("--file-filter=\"") + strlen(filterPatternRegex) + 3 + strlen(filterName) + 2 + strlen(" --file-filter=\"") + strlen(allFilesPatternDescription) + strlen(" | *\"")); + sprintf(filter, "--file-filter=\"%s | %s\" --file-filter=\"%s | *\"", filterName, filterPatternRegex, allFilesPatternDescription); } snprintf(cmd, MAX_PATH, "%s %s %s --title=\"%s\" / %s", executable, action, flags, title, filter?filter:""); From 7c33ff502b2db8b5d0a5aaca539261b97249fef4 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 21 Feb 2016 21:42:37 +0100 Subject: [PATCH 3/3] Don't use hardcoded filter pattern conversions --- src/platform/linux.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/platform/linux.c b/src/platform/linux.c index 7580338e8f..5c9da46087 100644 --- a/src/platform/linux.c +++ b/src/platform/linux.c @@ -22,6 +22,7 @@ #ifdef __LINUX__ +#include #include #include #include @@ -221,7 +222,7 @@ int platform_open_common_file_dialog(filedialog_type type, utf8 *title, utf8 *fi char *action; char *flags; char *filter = NULL; - char *filterPatternRegex; + char filterPatternRegex[64]; char *allFilesPatternDescription; size = MAX_PATH; @@ -258,22 +259,21 @@ int platform_open_common_file_dialog(filedialog_type type, utf8 *title, utf8 *fi // Zenity seems to be case sensitive, while Kdialog isn't. if (filterPattern && filterName) { - if(strcmp(filterPattern, "*.sv6") == 0) - filterPatternRegex = "*.[Ss][Vv]6"; - else if(strcmp(filterPattern, "*.sc6") == 0) - filterPatternRegex = "*.[Ss][Cc]6"; - else if(strcmp(filterPattern, ".td6") == 0) - filterPatternRegex = "*.[Tt][Dd]6"; - else if(strcmp(filterPattern, "*.sv4") == 0) - filterPatternRegex = "*.[Ss][Vv]4"; - else if(strcmp(filterPattern, "*.sc4") == 0) - filterPatternRegex = "*.[Ss][Cc]4"; - else if(strcmp(filterPattern, "*.td4") == 0) - filterPatternRegex = "*.[Tt][Dd]4"; - else if(strcmp(filterPattern, "*.dat") == 0) - filterPatternRegex = "*.[Dd][Aa][Tt]"; - else - filterPatternRegex = (char *)filterPattern; + int regexIterator = 0; + for(int i = 0; i <= sizeof(filterPattern); i++) { + if (isalpha(filterPattern[i])) { + filterPatternRegex[regexIterator+0] = '['; + filterPatternRegex[regexIterator+1] = (char)toupper(filterPattern[i]); + filterPatternRegex[regexIterator+2] = (char)tolower(filterPattern[i]); + filterPatternRegex[regexIterator+3] = ']'; + regexIterator += 3; + } + else { + filterPatternRegex[regexIterator] = (char)filterPattern[i]; + } + regexIterator++; + } + filterPatternRegex[regexIterator+1] = 0; allFilesPatternDescription = (char *)language_get_string(STR_ALL_FILES); filter = (char*) malloc(strlen("--file-filter=\"") + strlen(filterPatternRegex) + 3 + strlen(filterName) + 2 + strlen(" --file-filter=\"") + strlen(allFilesPatternDescription) + strlen(" | *\""));