• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • localization
klocale_win.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  * Copyright 2005, 2008 Jaroslaw Staniek <staniek@kde.org>
3  * Copyright 2010 John Layt <john@layt.net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "klocale_win_p.h"
22 
23 #include <QtCore/QLocale>
24 #include <QtCore/QTextCodec>
25 
26 KLocaleWindowsPrivate::KLocaleWindowsPrivate(KLocale *q_ptr, const QString &catalogName, KSharedConfig::Ptr config)
27  :KLocalePrivate(q_ptr)
28 {
29  // Lock in the current Windows Locale ID
30  // Can we also lock in the actual settings like we do for Mac?
31  m_winLocaleId = GetUserDefaultLCID();
32  init(catalogName, QString(), QString(), config, 0);
33 }
34 
35 KLocaleWindowsPrivate::KLocaleWindowsPrivate(KLocale *q_ptr, const QString& catalogName,
36  const QString &language, const QString &country, KConfig *config)
37  :KLocalePrivate(q_ptr)
38 {
39  // Lock in the current Windows Locale ID
40  // Can we also lock in the actual settings like we do for Mac?
41  m_winLocaleId = GetUserDefaultLCID();
42  init(catalogName, language, country, KSharedConfig::Ptr(), config);
43 }
44 
45 KLocaleWindowsPrivate::KLocaleWindowsPrivate( const KLocaleWindowsPrivate &rhs )
46  :KLocalePrivate( rhs )
47 {
48  KLocalePrivate::copy( rhs );
49  m_winLocaleId = rhs.m_winLocaleId;
50  strcpy( m_win32SystemEncoding, rhs.m_win32SystemEncoding );
51 }
52 
53 KLocaleWindowsPrivate &KLocaleWindowsPrivate::operator=( const KLocaleWindowsPrivate &rhs )
54 {
55  KLocalePrivate::copy( rhs );
56  m_winLocaleId = rhs.m_winLocaleId;
57  strcpy( m_win32SystemEncoding, rhs.m_win32SystemEncoding );
58  return *this;
59 }
60 
61 KLocaleWindowsPrivate::~KLocaleWindowsPrivate()
62 {
63 }
64 
65 QString KLocaleWindowsPrivate::windowsLocaleValue( LCTYPE key ) const
66 {
67  // Find out how big the buffer needs to be
68  int size = GetLocaleInfoW( m_winLocaleId, key, 0, 0 );
69 
70  QString result;
71  if ( size ) {
72  wchar_t* buffer = new wchar_t[size];
73  if ( GetLocaleInfoW( m_winLocaleId, key, buffer, size ) )
74  result = QString::fromWCharArray( buffer );
75  delete[] buffer;
76  }
77  return result;
78 }
79 
80 QString KLocaleWindowsPrivate::systemCountry() const
81 {
82  return windowsLocaleValue( LOCALE_SISO3166CTRYNAME );
83 }
84 
85 QStringList KLocaleWindowsPrivate::systemLanguageList() const
86 {
87  QStringList list;
88  getLanguagesFromVariable( list, QLocale::system().name().toLocal8Bit().data() );
89  return list;
90 }
91 
92 QByteArray KLocaleWindowsPrivate::systemCodeset() const
93 {
94  return QByteArray();
95 }
96 
97 const QByteArray KLocaleWindowsPrivate::encoding()
98 {
99  if ( qstrcmp( codecForEncoding()->name(), "System" ) == 0 ) {
100  //win32 returns "System" codec name here but KDE apps expect a real name:
101  strcpy( m_win32SystemEncoding, "cp " );
102  // MSDN says the returned string for LOCALE_IDEFAULTANSICODEPAGE is max 6 char including '\0'
103  char buffer[6];
104  if ( GetLocaleInfoA( MAKELCID( MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT ), SORT_DEFAULT ),
105  LOCALE_IDEFAULTANSICODEPAGE, buffer, sizeof( buffer ) ) ) {
106  strcpy( m_win32SystemEncoding + 3, buffer );
107  return m_win32SystemEncoding;
108  }
109  }
110  return KLocalePrivate::encoding();
111 }
112 
113 /*
114 These functions are commented out for now until all required Date/Time functions are implemented
115 to ensure consistent behaviour, i.e. all KDE format or all Windows format, not some invalid mixture
116 
117 void KLocaleMacPrivate::initDayPeriods(const KConfigGroup &cg)
118 {
119  QString amText = windowsLocaleValue(LOCALE_S1159);
120  QString pmText = windowsLocaleValue(LOCALE_S2359);
121 
122  m_dayPeriods.clear();
123  m_dayPeriods.append(KDayPeriod("am", amText, amText, amText
124  QTime(0, 0, 0), QTime(11, 59, 59, 999), 0, 12));
125  m_dayPeriods.append(KDayPeriod("pm", pmText, pmText, pmText,
126  QTime(12, 0, 0), QTime(23, 59, 59, 999), 0, 12));
127 }
128 
129 */
QString::fromWCharArray
QString fromWCharArray(const wchar_t *string, int size)
KSharedPtr< KSharedConfig >
KLocaleWindowsPrivate::systemCodeset
virtual QByteArray systemCodeset() const
Definition: klocale_win.cpp:92
KLocaleWindowsPrivate::systemCountry
virtual QString systemCountry() const
Definition: klocale_win.cpp:80
QByteArray
KLocalePrivate::init
virtual void init(const QString &catalogName, const QString &language, const QString &country, KSharedConfig::Ptr persistantconfig, KConfig *tempConfig)
Definition: klocale_kde.cpp:229
KLocalePrivate::copy
virtual void copy(const KLocalePrivate &rhs)
Definition: klocale_kde.cpp:139
KLocaleWindowsPrivate::KLocaleWindowsPrivate
KLocaleWindowsPrivate(KLocale *q_ptr, const QString &catalogName, KSharedConfig::Ptr config)
Definition: klocale_win.cpp:26
KGlobal::config
KSharedConfigPtr config()
Returns the general config object.
Definition: kglobal.cpp:139
QLocale::system
QLocale system()
KLocaleWindowsPrivate
Definition: klocale_win_p.h:27
QString
QStringList
KLocalePrivate::encoding
virtual const QByteArray encoding()
Definition: klocale_kde.cpp:3050
KLocaleWindowsPrivate::~KLocaleWindowsPrivate
virtual ~KLocaleWindowsPrivate()
Definition: klocale_win.cpp:61
KLocaleWindowsPrivate::systemLanguageList
virtual QStringList systemLanguageList() const
Definition: klocale_win.cpp:85
KLocalePrivate::getLanguagesFromVariable
static void getLanguagesFromVariable(QStringList &list, const char *variable, bool isLanguageList=false)
Definition: klocale_kde.cpp:329
KConfig
The central class of the KDE configuration data system.
Definition: kconfig.h:70
KLocale
KLocale provides support for country specific stuff like the national language.
Definition: klocale.h:69
klocale_win_p.h
KLocaleWindowsPrivate::encoding
virtual const QByteArray encoding()
Definition: klocale_win.cpp:97
KLocaleWindowsPrivate::operator=
KLocaleWindowsPrivate & operator=(const KLocaleWindowsPrivate &rhs)
Definition: klocale_win.cpp:53
KLocalePrivate
Definition: klocale_p.h:34
KLocalePrivate::codecForEncoding
virtual QTextCodec * codecForEncoding() const
Definition: klocale_kde.cpp:3068
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal