2 This file is part of GammaRay, the Qt application inspection and
5 Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
6 Author: Stephen Kelly <stephen.kelly@kdab.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "localedataaccessor.h"
24 #include <QStringList>
26 using namespace GammaRay
;
28 Q_GLOBAL_STATIC(LocaleDataAccessorRegistry
, instance
)
30 LocaleDataAccessorRegistry::LocaleDataAccessorRegistry()
34 LocaleDataAccessorRegistry
*LocaleDataAccessorRegistry::instance()
39 QVector
< LocaleDataAccessor
* > LocaleDataAccessorRegistry::accessors()
41 return ::instance()->m_accessors
;
44 QVector
< LocaleDataAccessor
* > LocaleDataAccessorRegistry::enabledAccessors()
46 return ::instance()->m_enabledAccessors
;
49 void LocaleDataAccessorRegistry::registerAccessor(LocaleDataAccessor
*accessor
)
51 ::instance()->m_accessors
.push_back(accessor
);
54 void LocaleDataAccessorRegistry::setAccessorEnabled(LocaleDataAccessor
*accessor
, bool enabled
)
56 QVector
< LocaleDataAccessor
* > &accessors
= ::instance()->m_enabledAccessors
;
57 if (enabled
&& !accessors
.contains(accessor
)) {
58 accessors
.push_back(accessor
);
60 int idx
= accessors
.indexOf(accessor
);
62 accessors
.remove(idx
);
65 emit ::instance()->accessorsChanged();
68 LOCALE_SIMPLE_DEFAULT_ACCESSOR(Name
,
72 LOCALE_SIMPLE_DEFAULT_ACCESSOR(Language
,
73 return QLocale::languageToString(locale
.language());
76 LOCALE_SIMPLE_DEFAULT_ACCESSOR(Country
,
77 return QLocale::countryToString(locale
.country());
80 #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
81 LOCALE_SIMPLE_ACCESSOR(Script
,
82 return QLocale::scriptToString(locale
.script());
85 LOCALE_SIMPLE_ACCESSOR(Currency
,
86 return locale
.currencySymbol(QLocale::CurrencySymbol
) +
88 locale
.currencySymbol(QLocale::CurrencyIsoCode
) +
89 QLatin1String(") - ") +
90 locale
.currencySymbol(QLocale::CurrencyDisplayName
);
94 LOCALE_SIMPLE_ACCESSOR(TextDirection
,
95 return locale
.textDirection() == Qt::LeftToRight
? "LTR" : "RTL";
98 LOCALE_SIMPLE_DEFAULT_ACCESSOR(TimeFormatLong
,
99 return locale
.timeFormat(QLocale::LongFormat
);
102 LOCALE_SIMPLE_ACCESSOR(TimeFormatShort
,
103 return locale
.timeFormat(QLocale::ShortFormat
);
106 LOCALE_SIMPLE_ACCESSOR(TimeFormatNarrow
,
107 return locale
.timeFormat(QLocale::NarrowFormat
);
110 LOCALE_SIMPLE_DEFAULT_ACCESSOR(DateFormatLong
,
111 return locale
.dateFormat(QLocale::LongFormat
);
114 LOCALE_SIMPLE_ACCESSOR(DateFormatShort
,
115 return locale
.dateFormat(QLocale::ShortFormat
);
118 LOCALE_SIMPLE_ACCESSOR(DateFormatNarrow
,
119 return locale
.dateFormat(QLocale::NarrowFormat
);
122 LOCALE_SIMPLE_DEFAULT_ACCESSOR(DateTimeFormatLong
,
123 return locale
.dateTimeFormat(QLocale::LongFormat
);
126 LOCALE_SIMPLE_ACCESSOR(DateTimeFormatShort
,
127 return locale
.dateTimeFormat(QLocale::ShortFormat
);
130 LOCALE_SIMPLE_ACCESSOR(DateTimeFormatNarrow
,
131 return locale
.dateTimeFormat(QLocale::NarrowFormat
);
134 LOCALE_SIMPLE_DEFAULT_ACCESSOR(MeasurementSystem
,
135 return locale
.measurementSystem() == QLocale::ImperialSystem
? "Imperial" : "Metric";
138 LOCALE_SIMPLE_ACCESSOR(AmText
,
139 return locale
.amText();
142 LOCALE_SIMPLE_ACCESSOR(PmText
,
143 return locale
.pmText();
146 LOCALE_SIMPLE_DEFAULT_ACCESSOR(FloatFormat
,
147 return locale
.toString(10000.1);
150 #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
151 LOCALE_SIMPLE_ACCESSOR(NativeCountry
,
152 return locale
.nativeCountryName();
155 LOCALE_SIMPLE_ACCESSOR(NativeLanguage
,
156 return locale
.nativeLanguageName();
159 LOCALE_SIMPLE_DEFAULT_ACCESSOR(FirstDayOfWeek
,
160 return QLocale().dayName(locale
.firstDayOfWeek());
163 LOCALE_SIMPLE_DEFAULT_ACCESSOR(WeekDays
,
164 QStringList resultList
;
165 Q_FOREACH (const Qt::DayOfWeek
&dayNumber
, locale
.weekdays()) {
166 resultList
<< QLocale().dayName(dayNumber
);
168 return QLocale().createSeparatedList(resultList
);
172 #include "localedataaccessor.moc"