Skip to content

Commit

Permalink
Extend the character encoding check.
Browse files Browse the repository at this point in the history
Extend the character-encoding check from 0fd3987 to better approximate
the approach that Qt uses internally to determine the encoding.  Qt has
a much more complex process than is reflected, here, but the approach
below pretty much lines up with "standard" *nix programming and if users
follow the instructions, Qt should use the encoding they specify.  This
also changes the check to specifically look for the string UTF-8
somewhere in the checked environment variables and warns if it's not
there.

This may actually warn in cases where Qt still manages to use a UTF-8
encoding, but since we can't directly find out which encoding Qt is
using and since it's better for users to explicitly request a UTF-8
encoding than rely on some strange fallback that gets them there, this
seems reasonable.
  • Loading branch information
sphery committed Aug 30, 2011
1 parent f19e8b9 commit b82c53a
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions mythtv/libs/libmythbase/mythcorecontext.cpp
Expand Up @@ -193,12 +193,29 @@ bool MythCoreContext::Init(void)
}

#ifndef _WIN32
char *lang = getenv("LANG");
if (!lang || !strcmp(lang, "C") || (strlen(lang) == 0))
LOG(VB_GENERAL, LOG_WARNING,
"This application expects to be running a UTF locale, and "
"many features may behave improperly with your current LANG "
"set to 'C' (or unset). Please consider correcting this.");
QString lang_variables("");
QString lc_value = getenv("LC_ALL");
if (lc_value.isEmpty())
{
// LC_ALL is undefined or empty, so check "sub-variable"
lc_value = getenv("LC_CTYPE");
}
if (!lc_value.contains("UTF-8", Qt::CaseInsensitive))
lang_variables.append("LC_ALL or LC_CTYPE");
lc_value = getenv("LANG");
if (!lc_value.contains("UTF-8", Qt::CaseInsensitive))
{
if (!lang_variables.isEmpty())
lang_variables.append(", and ");
lang_variables.append("LANG");
}
if (!lang_variables.isEmpty())
LOG(VB_GENERAL, LOG_WARNING, QString("This application expects to "
"be running a locale that specifies a UTF-8 codeset, and many "
"features may behave improperly with your current language "
"settings. Please set the %1 variable(s) in the environment "
"in which this program is executed to include a UTF-8 codeset "
"(such as 'en_US.UTF-8').").arg(lang_variables));
#endif

// If any of the IPs on any interfaces look like IPv6 addresses, assume IPv6
Expand Down

0 comments on commit b82c53a

Please sign in to comment.