File indexing completed on 2023-09-24 04:04:52
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 2010 John Layt <john@layt.net> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "kkernel_mac.h" 0021 #include "klocale_mac_p.h" 0022 #include <CoreFoundation/CFString.h> 0023 0024 KLocaleMacPrivate::KLocaleMacPrivate(KLocale *q_ptr, KSharedConfig::Ptr config) 0025 : KLocalePrivate(q_ptr) 0026 { 0027 // Lock in the current Mac Locale settings 0028 m_macLocale = CFLocaleCopyCurrent(); 0029 init(QString(), QString(), config, 0); 0030 } 0031 0032 KLocaleMacPrivate::KLocaleMacPrivate(KLocale *q_ptr, 0033 const QString &language, const QString &country, KConfig *config) 0034 : KLocalePrivate(q_ptr) 0035 { 0036 // Lock in the current Mac Locale settings 0037 m_macLocale = CFLocaleCopyCurrent(); 0038 init(language, country, KSharedConfig::Ptr(), config); 0039 } 0040 0041 KLocaleMacPrivate::KLocaleMacPrivate(const KLocaleMacPrivate &rhs) 0042 : KLocalePrivate(rhs) 0043 { 0044 KLocalePrivate::copy(rhs); 0045 m_macLocale = rhs.m_macLocale; 0046 } 0047 0048 KLocaleMacPrivate &KLocaleMacPrivate::operator=(const KLocaleMacPrivate &rhs) 0049 { 0050 KLocalePrivate::copy(rhs); 0051 m_macLocale = rhs.m_macLocale; 0052 return *this; 0053 } 0054 0055 KLocaleMacPrivate::~KLocaleMacPrivate() 0056 { 0057 } 0058 0059 QString KLocaleMacPrivate::macLocaleValue(CFStringRef key) const 0060 { 0061 return convert_CFString_to_QString(CFStringRef(CFLocaleGetValue(m_macLocale, key))); 0062 } 0063 0064 QString KLocaleMacPrivate::systemCountry() const 0065 { 0066 return macLocaleValue(kCFLocaleCountryCode); 0067 } 0068 0069 QByteArray KLocaleMacPrivate::systemCodeset() const 0070 { 0071 return QByteArray("UTF-8"); 0072 } 0073 0074 /* 0075 These functions are commented out for now until all required Date/Time functions are implemented 0076 to ensure consistent behaviour, i.e. all KDE format or all Mac format, not some invalid mixture 0077 0078 QString KLocaleMacPrivate::macDateFormatterValue(CFStringRef key) const 0079 { 0080 CFDateFormatterRef formatter = CFDateFormatterCreate(kCFAllocatorDefault, m_macLocale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle); 0081 return convert_CFString_to_QString(CFStringRef(CFDateFormatterCopyProperty(formatter, key))); 0082 } 0083 0084 void KLocaleMacPrivate::initDayPeriods(const KConfigGroup &cg) 0085 { 0086 QString amText = macDateFormatterValue(kCFDateFormatterAMSymbol); 0087 QString pmText = macDateFormatterValue(kCFDateFormatterPMSymbol); 0088 0089 m_dayPeriods.clear(); 0090 m_dayPeriods.append(KDayPeriod("am", amText, amText, amText 0091 QTime(0, 0, 0), QTime(11, 59, 59, 999), 0, 12)); 0092 m_dayPeriods.append(KDayPeriod("pm", pmText, pmText, pmText, 0093 QTime(12, 0, 0), QTime(23, 59, 59, 999), 0, 12)); 0094 } 0095 */