KDECore
klocale_win.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 * Copyright 2005, 2008 Jaroslaw Staniek <staniek@kde.org> 00003 * Copyright 2010 John Layt <john@layt.net> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "klocale_win_p.h" 00022 00023 #include <QtCore/QLocale> 00024 #include <QtCore/QTextCodec> 00025 00026 KLocaleWindowsPrivate::KLocaleWindowsPrivate(KLocale *q_ptr, const QString &catalogName, KSharedConfig::Ptr config) 00027 :KLocalePrivate(q_ptr) 00028 { 00029 // Lock in the current Windows Locale ID 00030 // Can we also lock in the actual settings like we do for Mac? 00031 m_winLocaleId = GetUserDefaultLCID(); 00032 init(catalogName, QString(), QString(), config, 0); 00033 } 00034 00035 KLocaleWindowsPrivate::KLocaleWindowsPrivate(KLocale *q_ptr, const QString& catalogName, 00036 const QString &language, const QString &country, KConfig *config) 00037 :KLocalePrivate(q_ptr) 00038 { 00039 // Lock in the current Windows Locale ID 00040 // Can we also lock in the actual settings like we do for Mac? 00041 m_winLocaleId = GetUserDefaultLCID(); 00042 init(catalogName, language, country, KSharedConfig::Ptr(), config); 00043 } 00044 00045 KLocaleWindowsPrivate::KLocaleWindowsPrivate( const KLocaleWindowsPrivate &rhs ) 00046 :KLocalePrivate( rhs ) 00047 { 00048 KLocalePrivate::copy( rhs ); 00049 m_winLocaleId = rhs.m_winLocaleId; 00050 strcpy( m_win32SystemEncoding, rhs.m_win32SystemEncoding ); 00051 } 00052 00053 KLocaleWindowsPrivate &KLocaleWindowsPrivate::operator=( const KLocaleWindowsPrivate &rhs ) 00054 { 00055 KLocalePrivate::copy( rhs ); 00056 m_winLocaleId = rhs.m_winLocaleId; 00057 strcpy( m_win32SystemEncoding, rhs.m_win32SystemEncoding ); 00058 return *this; 00059 } 00060 00061 KLocaleWindowsPrivate::~KLocaleWindowsPrivate() 00062 { 00063 } 00064 00065 QString KLocaleWindowsPrivate::windowsLocaleValue( LCTYPE key ) const 00066 { 00067 // Find out how big the buffer needs to be 00068 int size = GetLocaleInfoW( m_winLocaleId, key, 0, 0 ); 00069 00070 QString result; 00071 if ( size ) { 00072 wchar_t* buffer = new wchar_t[size]; 00073 if ( GetLocaleInfoW( m_winLocaleId, key, buffer, size ) ) 00074 result = QString::fromWCharArray( buffer ); 00075 delete[] buffer; 00076 } 00077 return result; 00078 } 00079 00080 QString KLocaleWindowsPrivate::systemCountry() const 00081 { 00082 return windowsLocaleValue( LOCALE_SISO3166CTRYNAME ); 00083 } 00084 00085 QStringList KLocaleWindowsPrivate::systemLanguageList() const 00086 { 00087 QStringList list; 00088 getLanguagesFromVariable( list, QLocale::system().name().toLocal8Bit().data() ); 00089 return list; 00090 } 00091 00092 QByteArray KLocaleWindowsPrivate::systemCodeset() const 00093 { 00094 return QByteArray(); 00095 } 00096 00097 const QByteArray KLocaleWindowsPrivate::encoding() 00098 { 00099 if ( qstrcmp( codecForEncoding()->name(), "System" ) == 0 ) { 00100 //win32 returns "System" codec name here but KDE apps expect a real name: 00101 strcpy( m_win32SystemEncoding, "cp " ); 00102 // MSDN says the returned string for LOCALE_IDEFAULTANSICODEPAGE is max 6 char including '\0' 00103 char buffer[6]; 00104 if ( GetLocaleInfoA( MAKELCID( MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT ), SORT_DEFAULT ), 00105 LOCALE_IDEFAULTANSICODEPAGE, buffer, sizeof( buffer ) ) ) { 00106 strcpy( m_win32SystemEncoding + 3, buffer ); 00107 return m_win32SystemEncoding; 00108 } 00109 } 00110 return KLocalePrivate::encoding(); 00111 } 00112 00113 /* 00114 These functions are commented out for now until all required Date/Time functions are implemented 00115 to ensure consistent behaviour, i.e. all KDE format or all Windows format, not some invalid mixture 00116 00117 void KLocaleMacPrivate::initDayPeriods(const KConfigGroup &cg) 00118 { 00119 QString amText = windowsLocaleValue(LOCALE_S1159); 00120 QString pmText = windowsLocaleValue(LOCALE_S2359); 00121 00122 m_dayPeriods.clear(); 00123 m_dayPeriods.append(KDayPeriod("am", amText, amText, amText 00124 QTime(0, 0, 0), QTime(11, 59, 59, 999), 0, 12)); 00125 m_dayPeriods.append(KDayPeriod("pm", pmText, pmText, pmText, 00126 QTime(12, 0, 0), QTime(23, 59, 59, 999), 0, 12)); 00127 } 00128 00129 */
KDE 4.6 API Reference