Qt 4.8
Classes | Macros | Functions | Variables
qlocale_win.cpp File Reference
#include "qlocale_p.h"
#include "qlocale_tools_p.h"
#include "qstringlist.h"
#include "qvariant.h"
#include "qdatetime.h"
#include "private/qsystemlibrary_p.h"
#include "qdebug.h"
#include "qt_windows.h"
#include <time.h>

Go to the source code of this file.

Classes

struct  QSystemLocalePrivate
 
struct  WindowsToISOListElt
 

Macros

#define LOCALE_SNATIVECOUNTRYNAME   0x00000008
 
#define LOCALE_SNATIVELANGUAGENAME   0x00000004
 
#define LOCALE_SSHORTESTDAYNAME1   0x0060
 
#define LOCALE_SSHORTESTDAYNAME2   0x0061
 
#define LOCALE_SSHORTESTDAYNAME3   0x0062
 
#define LOCALE_SSHORTESTDAYNAME4   0x0063
 
#define LOCALE_SSHORTESTDAYNAME5   0x0064
 
#define LOCALE_SSHORTESTDAYNAME6   0x0065
 
#define LOCALE_SSHORTESTDAYNAME7   0x0066
 
#define MUI_LANGUAGE_NAME   0x8
 

Functions

static QByteArray getWinLocaleName (LCID id=LOCALE_USER_DEFAULT)
 
Q_CORE_EXPORT QLocale qt_localeFromLCID (LCID id)
 
static QString winIso3116CtryName (LCID id=LOCALE_USER_DEFAULT)
 
static QString winIso639LangName (LCID id=LOCALE_USER_DEFAULT)
 
static const char * winLangCodeToIsoName (int code)
 

Variables

static const int windows_to_iso_count = sizeof(windows_to_iso_list)/sizeof(WindowsToISOListElt)
 
static const WindowsToISOListElt windows_to_iso_list []
 

Macro Definition Documentation

◆ LOCALE_SNATIVECOUNTRYNAME

#define LOCALE_SNATIVECOUNTRYNAME   0x00000008

Definition at line 83 of file qlocale_win.cpp.

Referenced by QSystemLocalePrivate::nativeCountryName().

◆ LOCALE_SNATIVELANGUAGENAME

#define LOCALE_SNATIVELANGUAGENAME   0x00000004

Definition at line 80 of file qlocale_win.cpp.

Referenced by QSystemLocalePrivate::nativeLanguageName().

◆ LOCALE_SSHORTESTDAYNAME1

#define LOCALE_SSHORTESTDAYNAME1   0x0060

Definition at line 71 of file qlocale_win.cpp.

Referenced by QSystemLocalePrivate::dayName().

◆ LOCALE_SSHORTESTDAYNAME2

#define LOCALE_SSHORTESTDAYNAME2   0x0061

Definition at line 72 of file qlocale_win.cpp.

Referenced by QSystemLocalePrivate::dayName().

◆ LOCALE_SSHORTESTDAYNAME3

#define LOCALE_SSHORTESTDAYNAME3   0x0062

Definition at line 73 of file qlocale_win.cpp.

Referenced by QSystemLocalePrivate::dayName().

◆ LOCALE_SSHORTESTDAYNAME4

#define LOCALE_SSHORTESTDAYNAME4   0x0063

Definition at line 74 of file qlocale_win.cpp.

Referenced by QSystemLocalePrivate::dayName().

◆ LOCALE_SSHORTESTDAYNAME5

#define LOCALE_SSHORTESTDAYNAME5   0x0064

Definition at line 75 of file qlocale_win.cpp.

Referenced by QSystemLocalePrivate::dayName().

◆ LOCALE_SSHORTESTDAYNAME6

#define LOCALE_SSHORTESTDAYNAME6   0x0065

Definition at line 76 of file qlocale_win.cpp.

Referenced by QSystemLocalePrivate::dayName().

◆ LOCALE_SSHORTESTDAYNAME7

#define LOCALE_SSHORTESTDAYNAME7   0x0066

Definition at line 77 of file qlocale_win.cpp.

Referenced by QSystemLocalePrivate::dayName().

◆ MUI_LANGUAGE_NAME

#define MUI_LANGUAGE_NAME   0x8

Definition at line 68 of file qlocale_win.cpp.

Referenced by QSystemLocalePrivate::uiLanguages().

Function Documentation

◆ getWinLocaleName()

static QByteArray getWinLocaleName ( LCID  id = LOCALE_USER_DEFAULT)
static

Definition at line 949 of file qlocale_win.cpp.

Referenced by qt_localeFromLCID(), and QSystemLocalePrivate::winToQtFormat().

950 {
951  QByteArray result;
952  if (id == LOCALE_USER_DEFAULT) {
953  static QByteArray langEnvVar = qgetenv("LANG");
954  result = langEnvVar;
955  QString lang, script, cntry;
956  if ( result == "C" || (!result.isEmpty()
957  && qt_splitLocaleName(QString::fromLocal8Bit(result), lang, script, cntry)) ) {
958  long id = 0;
959  bool ok = false;
960  id = qstrtoll(result.data(), 0, 0, &ok);
961  if ( !ok || id == 0 || id < INT_MIN || id > INT_MAX )
962  return result;
963  else
964  return winLangCodeToIsoName( (int)id );
965  }
966  }
967 
968 #if defined(Q_OS_WINCE)
969  result = winLangCodeToIsoName(id != LOCALE_USER_DEFAULT ? id : GetUserDefaultLCID());
970 #else
971  if (id == LOCALE_USER_DEFAULT)
972  id = GetUserDefaultLCID();
973  QString resultuage = winIso639LangName(id);
975  result = resultuage.toLatin1();
976  if (!country.isEmpty()) {
977  result += '_';
978  result += country.toLatin1();
979  }
980 #endif
981 
982  return result;
983 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static QString winIso639LangName(LCID id=LOCALE_USER_DEFAULT)
static const char * winLangCodeToIsoName(int code)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool qt_splitLocaleName(const QString &name, QString &lang, QString &script, QString &cntry)
Definition: qlocale.cpp:302
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
qlonglong qstrtoll(const char *nptr, const char **endptr, register int base, bool *ok)
static QString winIso3116CtryName(LCID id=LOCALE_USER_DEFAULT)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QLocale::Country country
#define INT_MAX

◆ qt_localeFromLCID()

Q_CORE_EXPORT QLocale qt_localeFromLCID ( LCID  id)

Definition at line 985 of file qlocale_win.cpp.

986 {
988 }
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static QByteArray getWinLocaleName(LCID id=LOCALE_USER_DEFAULT)

◆ winIso3116CtryName()

static QString winIso3116CtryName ( LCID  id = LOCALE_USER_DEFAULT)
static

Definition at line 938 of file qlocale_win.cpp.

Referenced by getWinLocaleName().

939 {
940  QString result;
941 
942  wchar_t out[256];
943  if (GetLocaleInfo(id, LOCALE_SISO3166CTRYNAME, out, 255))
944  result = QString::fromWCharArray(out);
945 
946  return result;
947 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ winIso639LangName()

static QString winIso639LangName ( LCID  id = LOCALE_USER_DEFAULT)
static

Definition at line 901 of file qlocale_win.cpp.

Referenced by getWinLocaleName().

902 {
903  QString result;
904 
905  // Windows returns the wrong ISO639 for some languages, we need to detect them here using
906  // the language code
907  QString lang_code;
908  wchar_t out[256];
909  if (GetLocaleInfo(id, LOCALE_ILANGUAGE, out, 255)) // ### shouldn't use them according to msdn
910  lang_code = QString::fromWCharArray(out);
911 
912  if (!lang_code.isEmpty()) {
913  const char *endptr;
914  bool ok;
915  QByteArray latin1_lang_code = lang_code.toLatin1();
916  int i = qstrtoull(latin1_lang_code, &endptr, 16, &ok);
917  if (ok && *endptr == '\0') {
918  switch (i) {
919  case 0x814:
920  result = QLatin1String("nn"); // Nynorsk
921  break;
922  default:
923  break;
924  }
925  }
926  }
927 
928  if (!result.isEmpty())
929  return result;
930 
931  // not one of the problematic languages - do the usual lookup
932  if (GetLocaleInfo(id, LOCALE_SISO639LANGNAME , out, 255))
933  result = QString::fromWCharArray(out);
934 
935  return result;
936 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
qulonglong qstrtoull(const char *nptr, const char **endptr, register int base, bool *ok)

◆ winLangCodeToIsoName()

static const char * winLangCodeToIsoName ( int  code)
static

Definition at line 872 of file qlocale_win.cpp.

Referenced by getWinLocaleName(), and QSystemLocalePrivate::uiLanguages().

873 {
874  int cmp = code - windows_to_iso_list[0].windows_code;
875  if (cmp < 0)
876  return 0;
877 
878  if (cmp == 0)
879  return windows_to_iso_list[0].iso_name;
880 
881  int begin = 0;
883 
884  while (end - begin > 1) {
885  uint mid = (begin + end)/2;
886 
887  const WindowsToISOListElt *elt = windows_to_iso_list + mid;
888  int cmp = code - elt->windows_code;
889  if (cmp < 0)
890  end = mid;
891  else if (cmp > 0)
892  begin = mid;
893  else
894  return elt->iso_name;
895  }
896 
897  return 0;
898 
899 }
static const WindowsToISOListElt windows_to_iso_list[]
unsigned int uint
Definition: qglobal.h:996
static int cmp(const ushort *s1, const ushort *s2, size_t len)
static const int windows_to_iso_count
static const KeyPair *const end

Variable Documentation

◆ windows_to_iso_count

const int windows_to_iso_count = sizeof(windows_to_iso_list)/sizeof(WindowsToISOListElt)
static

Definition at line 870 of file qlocale_win.cpp.

Referenced by winLangCodeToIsoName().

◆ windows_to_iso_list

const WindowsToISOListElt windows_to_iso_list[]
static

Definition at line 758 of file qlocale_win.cpp.