2023-07-26 09:52:37 +03:00
|
|
|
/* This file is part of the KDE project
|
|
|
|
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
2014-11-15 03:14:34 +02:00
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License version 2, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
2014-11-15 03:14:34 +02:00
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kcmlocale.h"
|
2014-11-15 03:14:34 +02:00
|
|
|
|
|
|
|
#include <KAboutData>
|
|
|
|
#include <KLocale>
|
2023-07-26 09:52:37 +03:00
|
|
|
#include <KConfigGroup>
|
2014-11-15 03:14:34 +02:00
|
|
|
#include <KMessageBox>
|
2023-07-26 09:52:37 +03:00
|
|
|
#include <KBuildSycocaProgressDialog>
|
|
|
|
#include <KGlobalSettings>
|
2014-11-15 03:14:34 +02:00
|
|
|
#include <KPluginFactory>
|
2023-07-26 09:52:37 +03:00
|
|
|
#include <KDebug>
|
2014-11-15 03:14:34 +02:00
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
K_PLUGIN_FACTORY(KCMLocaleFactory, registerPlugin<KCMLocale>();)
|
|
|
|
K_EXPORT_PLUGIN(KCMLocaleFactory("kcmlocale"))
|
|
|
|
|
2023-07-27 02:57:02 +03:00
|
|
|
static const Qt::Alignment s_labelsalignment = (Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
|
2023-07-26 09:52:37 +03:00
|
|
|
// NOTE: keep in sync with:
|
|
|
|
// kdelibs/kdecore/localization/klocale.cpp
|
|
|
|
static const QString s_defaultlanguage = KLocale::defaultLanguage();
|
|
|
|
static const int s_defaultbinary = static_cast<int>(KLocale::IECBinaryDialect);
|
|
|
|
|
|
|
|
KCMLocale::KCMLocale(QWidget *parent, const QVariantList &args)
|
|
|
|
: KCModule(KCMLocaleFactory::componentData(), parent, args),
|
|
|
|
m_layout(nullptr),
|
|
|
|
m_languagelabel(nullptr),
|
|
|
|
m_languagebox(nullptr),
|
|
|
|
m_binarylabel(nullptr),
|
|
|
|
m_binarybox(nullptr),
|
|
|
|
m_measurelabel(nullptr),
|
|
|
|
m_measurebox(nullptr),
|
|
|
|
m_dateshortlabel(nullptr),
|
|
|
|
m_dateshortedit(nullptr),
|
|
|
|
m_datelonglabel(nullptr),
|
|
|
|
m_datelongedit(nullptr),
|
|
|
|
m_datenarrowlabel(nullptr),
|
|
|
|
m_datenarrowedit(nullptr),
|
2023-07-27 01:00:36 +03:00
|
|
|
m_timeshortlabel(nullptr),
|
|
|
|
m_timeshortedit(nullptr),
|
|
|
|
m_timelonglabel(nullptr),
|
|
|
|
m_timelongedit(nullptr),
|
|
|
|
m_timenarrowlabel(nullptr),
|
|
|
|
m_timenarrowedit(nullptr),
|
|
|
|
m_datetimeshortlabel(nullptr),
|
|
|
|
m_datetimeshortedit(nullptr),
|
|
|
|
m_datetimelonglabel(nullptr),
|
|
|
|
m_datetimelongedit(nullptr),
|
|
|
|
m_datetimenarrowlabel(nullptr),
|
|
|
|
m_datetimenarrowedit(nullptr),
|
2023-07-26 09:52:37 +03:00
|
|
|
m_spacer(nullptr)
|
|
|
|
{
|
|
|
|
KAboutData *about = new KAboutData(
|
|
|
|
"kcmlocale", 0, ki18n("Localization options for KDE applications"),
|
|
|
|
0, KLocalizedString(), KAboutData::License_GPL,
|
|
|
|
ki18n("Copyright 2023 Ivailo Monev")
|
|
|
|
);
|
|
|
|
|
|
|
|
about->addAuthor(ki18n("Ivailo Monev"), ki18n("Maintainer"), "xakepa10@gmail.com");
|
|
|
|
|
|
|
|
setAboutData(about);
|
|
|
|
|
|
|
|
m_layout = new QGridLayout(this);
|
|
|
|
|
|
|
|
m_languagelabel = new QLabel(this);
|
|
|
|
m_languagelabel->setText(i18n("Language:"));
|
2023-07-27 02:57:02 +03:00
|
|
|
m_layout->addWidget(m_languagelabel, 0, 0, s_labelsalignment);
|
2023-07-26 09:52:37 +03:00
|
|
|
m_languagebox = new KComboBox(this);
|
2023-07-27 07:58:13 +03:00
|
|
|
// temporary map to sort by the displayed text
|
|
|
|
QMap<QString, QString> languagesmap;
|
2023-07-26 09:52:37 +03:00
|
|
|
foreach (const QString &language, KLocale::allLanguagesList()) {
|
|
|
|
QString languagelang;
|
|
|
|
QString languagecntry;
|
|
|
|
QString languagemod;
|
|
|
|
QString languagechar;
|
|
|
|
KLocale::splitLocale(language, languagelang, languagecntry, languagemod, languagechar);
|
|
|
|
if (languagecntry.isEmpty()) {
|
2023-07-27 07:58:13 +03:00
|
|
|
const QString languagetext = KGlobal::locale()->languageCodeToName(languagelang);
|
|
|
|
languagesmap.insert(languagetext, language);
|
2014-11-15 03:14:34 +02:00
|
|
|
} else {
|
2023-07-26 09:52:37 +03:00
|
|
|
const QString languagetext = QString::fromLatin1("%1 - %2").arg(
|
|
|
|
KGlobal::locale()->languageCodeToName(languagelang),
|
|
|
|
KGlobal::locale()->countryCodeToName(languagecntry)
|
|
|
|
);
|
2023-07-27 07:58:13 +03:00
|
|
|
languagesmap.insert(languagetext, language);
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
}
|
2023-07-27 07:58:13 +03:00
|
|
|
foreach (const QString &languagetext, languagesmap.keys()) {
|
|
|
|
m_languagebox->addItem(languagetext, languagesmap.value(languagetext));
|
|
|
|
}
|
2023-07-26 09:52:37 +03:00
|
|
|
const QString languagehelp = i18n(
|
|
|
|
"<p>This is the list of languages KDE Workspace can use for converting "
|
|
|
|
"date, time and numbers. Changing the language will also change the "
|
|
|
|
"translations language, however each application can specify additional "
|
|
|
|
"translation languages."
|
|
|
|
"</p>"
|
|
|
|
);
|
|
|
|
m_languagebox->setToolTip(languagehelp);
|
|
|
|
m_languagebox->setWhatsThis(languagehelp);
|
|
|
|
connect(m_languagebox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotLanguageChanged(int)));
|
|
|
|
m_layout->addWidget(m_languagebox, 0, 1);
|
|
|
|
|
|
|
|
m_binarylabel = new QLabel(this);
|
|
|
|
m_binarylabel->setText(i18n("Byte size units:"));
|
2023-07-27 02:57:02 +03:00
|
|
|
m_layout->addWidget(m_binarylabel, 1, 0, s_labelsalignment);
|
2023-07-26 09:52:37 +03:00
|
|
|
m_binarybox = new KComboBox(this);
|
|
|
|
Q_ASSERT(int(KLocale::LastBinaryDialect) == int(KLocale::MetricBinaryDialect));
|
|
|
|
m_binarybox->addItem(
|
|
|
|
i18nc("Unit of binary measurement", "IEC Units (KiB, MiB, etc)"),
|
|
|
|
static_cast<int>(KLocale::IECBinaryDialect)
|
|
|
|
);
|
|
|
|
m_binarybox->addItem(
|
|
|
|
i18nc("Unit of binary measurement", "JEDEC Units (KB, MB, etc)"),
|
|
|
|
static_cast<int>(KLocale::JEDECBinaryDialect)
|
|
|
|
);
|
|
|
|
m_binarybox->addItem(
|
|
|
|
i18nc("Unit of binary measurement", "Metric Units (kB, MB, etc)"),
|
|
|
|
static_cast<int>(KLocale::MetricBinaryDialect)
|
|
|
|
);
|
|
|
|
const QString binaryhelp = i18n(
|
|
|
|
"<p>This changes the units used by most KDE programs to display "
|
|
|
|
"numbers counted in bytes. Traditionally \"kilobytes\" meant units "
|
|
|
|
"of 1024, instead of the metric 1000, for most (but not all) byte "
|
|
|
|
"sizes."
|
|
|
|
"<ul>"
|
|
|
|
"<li>To reduce confusion you can use the recently standardized IEC "
|
|
|
|
"units which are always in multiples of 1024.</li>"
|
|
|
|
"<li>You can also select metric, which is always in units of 1000.</li>"
|
|
|
|
"<li>Selecting JEDEC restores the older-style units used in KDE 3.5 "
|
|
|
|
"and some other operating systems.</li>"
|
|
|
|
"</ul>"
|
|
|
|
"</p>"
|
|
|
|
);
|
|
|
|
m_binarybox->setToolTip(binaryhelp);
|
|
|
|
m_binarybox->setWhatsThis(binaryhelp);
|
|
|
|
connect(m_binarybox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotBinaryChanged(int)));
|
|
|
|
m_layout->addWidget(m_binarybox, 1, 1);
|
|
|
|
|
|
|
|
m_measurelabel = new QLabel(this);
|
|
|
|
m_measurelabel->setText(i18n("Measurement system:"));
|
2023-07-27 02:57:02 +03:00
|
|
|
m_layout->addWidget(m_measurelabel, 2, 0, s_labelsalignment);
|
2023-07-26 09:52:37 +03:00
|
|
|
m_measurebox = new KComboBox(this);
|
|
|
|
Q_ASSERT(int(QLocale::MetricSystem) == 0);
|
|
|
|
Q_ASSERT(int(QLocale::UKSystem) == 2);
|
|
|
|
m_measurebox->addItem(
|
|
|
|
i18n("Metric System"),
|
|
|
|
static_cast<int>(QLocale::MetricSystem)
|
|
|
|
);
|
|
|
|
m_measurebox->addItem(
|
|
|
|
i18n("Imperial System"),
|
|
|
|
static_cast<int>(QLocale::ImperialSystem)
|
|
|
|
);
|
|
|
|
m_measurebox->addItem(
|
|
|
|
i18n("UK System"),
|
|
|
|
static_cast<int>(QLocale::UKSystem)
|
|
|
|
);
|
|
|
|
const QString measurehelp = i18n("<p>Here you can define the measurement system to use.</p>");
|
|
|
|
m_measurebox->setToolTip(measurehelp);
|
|
|
|
m_measurebox->setWhatsThis(measurehelp);
|
|
|
|
connect(m_measurebox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotMeasureChanged(int)));
|
|
|
|
m_layout->addWidget(m_measurebox, 2, 1);
|
|
|
|
|
2023-07-27 02:57:02 +03:00
|
|
|
// TODO: tooltips and whatsthis
|
2023-07-27 03:08:50 +03:00
|
|
|
// TODO: validate date and time format, user usually has no clue what to enter and invalid
|
|
|
|
// format will result in all sorts of bad stuff
|
2023-07-27 02:57:02 +03:00
|
|
|
int groupsalignment = 0;
|
2023-07-26 09:52:37 +03:00
|
|
|
QGroupBox* dategroup = new QGroupBox(this);
|
2023-07-27 02:57:02 +03:00
|
|
|
QFontMetrics groupsmetrics = QFontMetrics(dategroup->font());
|
2023-07-26 09:52:37 +03:00
|
|
|
dategroup->setTitle(i18n("Date format"));
|
|
|
|
QGridLayout* datelayout = new QGridLayout(dategroup);
|
|
|
|
dategroup->setLayout(datelayout);
|
|
|
|
m_dateshortlabel = new QLabel(dategroup);
|
2023-07-27 02:57:02 +03:00
|
|
|
m_dateshortlabel->setText(i18n("Short date:"));
|
|
|
|
groupsalignment = qMax(groupsalignment, groupsmetrics.width(m_dateshortlabel->text()));
|
|
|
|
datelayout->addWidget(m_dateshortlabel, 0, 0, s_labelsalignment);
|
2023-07-26 09:52:37 +03:00
|
|
|
m_dateshortedit = new KLineEdit(dategroup);
|
|
|
|
connect(m_dateshortedit, SIGNAL(textChanged(QString)), this, SLOT(slotDateOrTimeChanged(QString)));
|
|
|
|
datelayout->addWidget(m_dateshortedit, 0, 1);
|
|
|
|
m_datelonglabel = new QLabel(dategroup);
|
2023-07-27 02:57:02 +03:00
|
|
|
m_datelonglabel->setText(i18n("Long date:"));
|
|
|
|
groupsalignment = qMax(groupsalignment, groupsmetrics.width(m_datelonglabel->text()));
|
|
|
|
datelayout->addWidget(m_datelonglabel, 1, 0, s_labelsalignment);
|
2023-07-26 09:52:37 +03:00
|
|
|
m_datelongedit = new KLineEdit(dategroup);
|
|
|
|
connect(m_datelongedit, SIGNAL(textChanged(QString)), this, SLOT(slotDateOrTimeChanged(QString)));
|
|
|
|
datelayout->addWidget(m_datelongedit, 1, 1);
|
|
|
|
m_datenarrowlabel = new QLabel(dategroup);
|
2023-07-27 02:57:02 +03:00
|
|
|
m_datenarrowlabel->setText(i18n("Narrow date:"));
|
|
|
|
groupsalignment = qMax(groupsalignment, groupsmetrics.width(m_datenarrowlabel->text()));
|
|
|
|
datelayout->addWidget(m_datenarrowlabel, 2, 0, s_labelsalignment);
|
2023-07-26 09:52:37 +03:00
|
|
|
m_datenarrowedit = new KLineEdit(dategroup);
|
|
|
|
connect(m_datenarrowedit, SIGNAL(textChanged(QString)), this, SLOT(slotDateOrTimeChanged(QString)));
|
|
|
|
datelayout->addWidget(m_datenarrowedit, 2, 1);
|
|
|
|
m_layout->addWidget(dategroup, 3, 0, 1, 2);
|
|
|
|
|
2023-07-27 01:00:36 +03:00
|
|
|
QGroupBox* timegroup = new QGroupBox(this);
|
|
|
|
timegroup->setTitle(i18n("Time format"));
|
|
|
|
QGridLayout* timelayout = new QGridLayout(timegroup);
|
|
|
|
timegroup->setLayout(timelayout);
|
|
|
|
m_timeshortlabel = new QLabel(timegroup);
|
2023-07-27 02:57:02 +03:00
|
|
|
m_timeshortlabel->setText(i18n("Short time:"));
|
|
|
|
groupsalignment = qMax(groupsalignment, groupsmetrics.width(m_timeshortlabel->text()));
|
|
|
|
timelayout->addWidget(m_timeshortlabel, 0, 0, s_labelsalignment);
|
2023-07-27 01:00:36 +03:00
|
|
|
m_timeshortedit = new KLineEdit(timegroup);
|
|
|
|
connect(m_timeshortedit, SIGNAL(textChanged(QString)), this, SLOT(slotDateOrTimeChanged(QString)));
|
|
|
|
timelayout->addWidget(m_timeshortedit, 0, 1);
|
|
|
|
m_timelonglabel = new QLabel(timegroup);
|
2023-07-27 02:57:02 +03:00
|
|
|
m_timelonglabel->setText(i18n("Long time:"));
|
|
|
|
groupsalignment = qMax(groupsalignment, groupsmetrics.width(m_timelonglabel->text()));
|
|
|
|
timelayout->addWidget(m_timelonglabel, 1, 0, s_labelsalignment);
|
2023-07-27 01:00:36 +03:00
|
|
|
m_timelongedit = new KLineEdit(timegroup);
|
|
|
|
connect(m_timelongedit, SIGNAL(textChanged(QString)), this, SLOT(slotDateOrTimeChanged(QString)));
|
|
|
|
timelayout->addWidget(m_timelongedit, 1, 1);
|
|
|
|
m_timenarrowlabel = new QLabel(timegroup);
|
2023-07-27 02:57:02 +03:00
|
|
|
m_timenarrowlabel->setText(i18n("Narrow time:"));
|
|
|
|
groupsalignment = qMax(groupsalignment, groupsmetrics.width(m_timenarrowlabel->text()));
|
|
|
|
timelayout->addWidget(m_timenarrowlabel, 2, 0, s_labelsalignment);
|
2023-07-27 01:00:36 +03:00
|
|
|
m_timenarrowedit = new KLineEdit(timegroup);
|
|
|
|
connect(m_timenarrowedit, SIGNAL(textChanged(QString)), this, SLOT(slotDateOrTimeChanged(QString)));
|
|
|
|
timelayout->addWidget(m_timenarrowedit, 2, 1);
|
|
|
|
m_layout->addWidget(timegroup, 4, 0, 1, 2);
|
|
|
|
|
|
|
|
QGroupBox* datetimegroup = new QGroupBox(this);
|
|
|
|
datetimegroup->setTitle(i18n("Date and time format"));
|
|
|
|
QGridLayout* datetimelayout = new QGridLayout(datetimegroup);
|
|
|
|
datetimegroup->setLayout(datetimelayout);
|
|
|
|
m_datetimeshortlabel = new QLabel(datetimegroup);
|
2023-07-27 02:57:02 +03:00
|
|
|
m_datetimeshortlabel->setText(i18n("Short date and time:"));
|
|
|
|
groupsalignment = qMax(groupsalignment, groupsmetrics.width(m_datetimeshortlabel->text()));
|
|
|
|
datetimelayout->addWidget(m_datetimeshortlabel, 0, 0, s_labelsalignment);
|
2023-07-27 01:00:36 +03:00
|
|
|
m_datetimeshortedit = new KLineEdit(datetimegroup);
|
|
|
|
connect(m_datetimeshortedit, SIGNAL(textChanged(QString)), this, SLOT(slotDateOrTimeChanged(QString)));
|
|
|
|
datetimelayout->addWidget(m_datetimeshortedit, 0, 1);
|
|
|
|
m_datetimelonglabel = new QLabel(datetimegroup);
|
2023-07-27 02:57:02 +03:00
|
|
|
m_datetimelonglabel->setText(i18n("Long date and time:"));
|
|
|
|
groupsalignment = qMax(groupsalignment, groupsmetrics.width(m_datetimelonglabel->text()));
|
|
|
|
datetimelayout->addWidget(m_datetimelonglabel, 1, 0, s_labelsalignment);
|
2023-07-27 01:00:36 +03:00
|
|
|
m_datetimelongedit = new KLineEdit(datetimegroup);
|
|
|
|
connect(m_datetimelongedit, SIGNAL(textChanged(QString)), this, SLOT(slotDateOrTimeChanged(QString)));
|
|
|
|
datetimelayout->addWidget(m_datetimelongedit, 1, 1);
|
|
|
|
m_datetimenarrowlabel = new QLabel(datetimegroup);
|
2023-07-27 02:57:02 +03:00
|
|
|
m_datetimenarrowlabel->setText(i18n("Narrow date and time:"));
|
|
|
|
groupsalignment = qMax(groupsalignment, groupsmetrics.width(m_datetimenarrowlabel->text()));
|
|
|
|
datetimelayout->addWidget(m_datetimenarrowlabel, 2, 0, s_labelsalignment);
|
2023-07-27 01:00:36 +03:00
|
|
|
m_datetimenarrowedit = new KLineEdit(datetimegroup);
|
|
|
|
connect(m_datetimenarrowedit, SIGNAL(textChanged(QString)), this, SLOT(slotDateOrTimeChanged(QString)));
|
|
|
|
datetimelayout->addWidget(m_datetimenarrowedit, 2, 1);
|
|
|
|
m_layout->addWidget(datetimegroup, 5, 0, 1, 2);
|
2023-07-26 09:52:37 +03:00
|
|
|
|
2023-07-27 02:57:02 +03:00
|
|
|
datelayout->setColumnMinimumWidth(0, groupsalignment);
|
|
|
|
timelayout->setColumnMinimumWidth(0, groupsalignment);
|
|
|
|
datetimelayout->setColumnMinimumWidth(0, groupsalignment);
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
m_spacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2023-07-27 01:00:36 +03:00
|
|
|
m_layout->addItem(m_spacer, 6, 1, 2);
|
2023-07-26 09:52:37 +03:00
|
|
|
|
|
|
|
setLayout(m_layout);
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
KCMLocale::~KCMLocale()
|
2014-11-15 03:14:34 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
void KCMLocale::load()
|
2014-11-15 03:14:34 +02:00
|
|
|
{
|
2023-07-26 09:52:37 +03:00
|
|
|
KConfig localeconfig = KConfig("kdeglobals", KConfig::FullConfig);
|
|
|
|
KConfigGroup localegroup = localeconfig.group("Locale");
|
2014-11-15 03:14:34 +02:00
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
const QString localelanguage = localegroup.readEntry("Language", s_defaultlanguage);
|
|
|
|
const int languageindex = m_languagebox->findData(localelanguage);
|
|
|
|
if (languageindex >= 0) {
|
|
|
|
m_languagebox->setCurrentIndex(languageindex);
|
|
|
|
emit changed(true);
|
|
|
|
} else {
|
|
|
|
kWarning() << "Could not find the language index for" << localelanguage;
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
const int localebinary = localegroup.readEntry("BinaryUnitDialect", s_defaultbinary);
|
|
|
|
const int binaryindex = m_binarybox->findData(localebinary);
|
|
|
|
if (binaryindex >= 0) {
|
|
|
|
m_binarybox->setCurrentIndex(binaryindex);
|
|
|
|
emit changed(true);
|
|
|
|
} else {
|
|
|
|
kWarning() << "Could not find the binary index for" << localebinary;
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
// NOTE: KLocale defaults to what QLocale returns
|
|
|
|
const QLocale locale(localelanguage);
|
|
|
|
const int localemeasure = localegroup.readEntry("MeasurementSystem", int(locale.measurementSystem()));
|
|
|
|
const int measureindex = m_measurebox->findData(localemeasure);
|
|
|
|
if (measureindex >= 0) {
|
|
|
|
m_measurebox->setCurrentIndex(measureindex);
|
|
|
|
emit changed(true);
|
2014-11-15 03:14:34 +02:00
|
|
|
} else {
|
2023-07-26 09:52:37 +03:00
|
|
|
kWarning() << "Could not find the measure index for" << localemeasure;
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
const QString localedateshort = localegroup.readEntry("ShortDateFormat", locale.dateFormat(QLocale::ShortFormat));
|
|
|
|
m_dateshortedit->setText(localedateshort);
|
|
|
|
const QString localedatelong = localegroup.readEntry("LongDateFormat", locale.dateFormat(QLocale::LongFormat));
|
|
|
|
m_datelongedit->setText(localedatelong);
|
|
|
|
const QString localedatenarrow = localegroup.readEntry("NarrowDateFormat", locale.dateFormat(QLocale::NarrowFormat));
|
|
|
|
m_datenarrowedit->setText(localedatenarrow);
|
2014-11-15 03:14:34 +02:00
|
|
|
|
2023-07-27 01:00:36 +03:00
|
|
|
const QString localetimeshort = localegroup.readEntry("ShortTimeFormat", locale.timeFormat(QLocale::ShortFormat));
|
|
|
|
m_timeshortedit->setText(localetimeshort);
|
|
|
|
const QString localetimelong = localegroup.readEntry("LongTimeFormat", locale.timeFormat(QLocale::LongFormat));
|
|
|
|
m_timelongedit->setText(localetimelong);
|
|
|
|
const QString localetimenarrow = localegroup.readEntry("NarrowTimeFormat", locale.timeFormat(QLocale::NarrowFormat));
|
|
|
|
m_timenarrowedit->setText(localetimenarrow);
|
|
|
|
|
|
|
|
const QString localedatetimeshort = localegroup.readEntry("ShortDateTimeFormat", locale.dateTimeFormat(QLocale::ShortFormat));
|
|
|
|
m_datetimeshortedit->setText(localedatetimeshort);
|
|
|
|
const QString localedatetimelong = localegroup.readEntry("LongDateTimeFormat", locale.dateTimeFormat(QLocale::LongFormat));
|
|
|
|
m_datetimelongedit->setText(localedatetimelong);
|
|
|
|
const QString localedatetimenarrow = localegroup.readEntry("NarrowDateTimeFormat", locale.dateTimeFormat(QLocale::NarrowFormat));
|
|
|
|
m_datetimenarrowedit->setText(localedatetimenarrow);
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
emit changed(false);
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KCMLocale::save()
|
|
|
|
{
|
2023-07-26 09:52:37 +03:00
|
|
|
KConfig localeconfig = KConfig("kdeglobals", KConfig::FullConfig);
|
|
|
|
KConfigGroup localegroup = localeconfig.group("Locale");
|
|
|
|
const QString localelanguage = m_languagebox->itemData(m_languagebox->currentIndex()).toString();
|
|
|
|
localegroup.writeEntry("Language", localelanguage);
|
|
|
|
const int localebinary = m_binarybox->itemData(m_binarybox->currentIndex()).toInt();
|
|
|
|
localegroup.writeEntry("BinaryUnitDialect", localebinary);
|
|
|
|
const int localemeasure = m_measurebox->itemData(m_measurebox->currentIndex()).toInt();
|
|
|
|
localegroup.writeEntry("MeasurementSystem", localemeasure);
|
|
|
|
// TODO: when the format is same as the default do not write it to the config (it may change)
|
|
|
|
localegroup.writeEntry("ShortDateFormat", m_dateshortedit->text());
|
|
|
|
localegroup.writeEntry("LongDateFormat", m_datelongedit->text());
|
|
|
|
localegroup.writeEntry("NarrowDateFormat", m_datenarrowedit->text());
|
2023-07-27 01:00:36 +03:00
|
|
|
localegroup.writeEntry("ShortTimeFormat", m_timeshortedit->text());
|
|
|
|
localegroup.writeEntry("LongTimeFormat", m_timelongedit->text());
|
|
|
|
localegroup.writeEntry("NarrowTimeFormat", m_timenarrowedit->text());
|
|
|
|
localegroup.writeEntry("ShortDateTimeFormat", m_datetimeshortedit->text());
|
|
|
|
localegroup.writeEntry("LongDateTimeFormat", m_datetimelongedit->text());
|
|
|
|
localegroup.writeEntry("NarrowDateTimeFormat", m_datetimenarrowedit->text());
|
2023-07-26 09:52:37 +03:00
|
|
|
localegroup.sync();
|
|
|
|
emit changed(false);
|
|
|
|
|
|
|
|
KMessageBox::information(this,
|
|
|
|
i18n(
|
|
|
|
"Changed language settings apply only to "
|
|
|
|
"newly started applications.\nTo change the "
|
|
|
|
"language of all programs, you will have to "
|
|
|
|
"logout first."
|
|
|
|
),
|
|
|
|
i18n("Applying Language Settings"),
|
|
|
|
QLatin1String("LanguageChangesApplyOnlyToNewlyStartedPrograms")
|
|
|
|
);
|
|
|
|
|
|
|
|
KBuildSycocaProgressDialog::rebuildKSycoca(this);
|
2014-11-15 03:14:34 +02:00
|
|
|
KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_LOCALE);
|
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
void KCMLocale::defaults()
|
2014-11-15 03:14:34 +02:00
|
|
|
{
|
2023-07-26 09:52:37 +03:00
|
|
|
const int languageindex = m_languagebox->findData(s_defaultlanguage);
|
|
|
|
if (languageindex >= 0) {
|
|
|
|
m_languagebox->setCurrentIndex(languageindex);
|
|
|
|
emit changed(true);
|
2014-11-15 03:14:34 +02:00
|
|
|
} else {
|
2023-07-26 09:52:37 +03:00
|
|
|
kWarning() << "Could not find the language index for" << s_defaultlanguage;
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
const int binaryindex = m_binarybox->findData(s_defaultbinary);
|
|
|
|
if (binaryindex >= 0) {
|
|
|
|
m_binarybox->setCurrentIndex(binaryindex);
|
|
|
|
emit changed(true);
|
2014-11-15 03:14:34 +02:00
|
|
|
} else {
|
2023-07-26 09:52:37 +03:00
|
|
|
kWarning() << "Could not find the binary index for" << s_defaultbinary;
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
loadLocaleSettings();
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
QString KCMLocale::quickHelp() const
|
2014-11-15 03:14:34 +02:00
|
|
|
{
|
2023-07-26 09:52:37 +03:00
|
|
|
return i18n(
|
|
|
|
"<h1>Country/Region & Language</h1>\n"
|
|
|
|
"<p>Here you can set your localization settings such as language, "
|
|
|
|
"numeric formats, date and time formats, etc. Choosing a country "
|
|
|
|
"will load a set of default formats which you can then change to "
|
|
|
|
"your personal preferences. These personal preferences will remain "
|
|
|
|
"set even if you change the country. The reset buttons allow you "
|
|
|
|
"to easily see where you have personal settings and to restore "
|
|
|
|
"those items to the country's default value.</p>"
|
|
|
|
);
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
void KCMLocale::loadLocaleSettings()
|
2014-11-15 03:14:34 +02:00
|
|
|
{
|
2023-07-26 09:52:37 +03:00
|
|
|
const QString localelanguage = m_languagebox->itemData(m_languagebox->currentIndex()).toString();
|
|
|
|
const QLocale locale(localelanguage);
|
2023-07-27 01:07:39 +03:00
|
|
|
m_measurebox->setCurrentIndex(int(locale.measurementSystem()));
|
2023-07-26 09:52:37 +03:00
|
|
|
m_dateshortedit->setText(locale.dateFormat(QLocale::ShortFormat));
|
|
|
|
m_datelongedit->setText(locale.dateFormat(QLocale::LongFormat));
|
|
|
|
m_datenarrowedit->setText(locale.dateFormat(QLocale::NarrowFormat));
|
2023-07-27 01:00:36 +03:00
|
|
|
m_timeshortedit->setText(locale.timeFormat(QLocale::ShortFormat));
|
|
|
|
m_timelongedit->setText(locale.timeFormat(QLocale::LongFormat));
|
|
|
|
m_timenarrowedit->setText(locale.timeFormat(QLocale::NarrowFormat));
|
|
|
|
m_datetimeshortedit->setText(locale.dateTimeFormat(QLocale::ShortFormat));
|
|
|
|
m_datetimelongedit->setText(locale.dateTimeFormat(QLocale::LongFormat));
|
|
|
|
m_datetimenarrowedit->setText(locale.dateTimeFormat(QLocale::NarrowFormat));
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
void KCMLocale::slotLanguageChanged(const int index)
|
2014-11-15 03:14:34 +02:00
|
|
|
{
|
2023-07-26 09:52:37 +03:00
|
|
|
Q_UNUSED(index);
|
|
|
|
loadLocaleSettings();
|
|
|
|
emit changed(true);
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
void KCMLocale::slotBinaryChanged(const int index)
|
2014-11-15 03:14:34 +02:00
|
|
|
{
|
2023-07-26 09:52:37 +03:00
|
|
|
Q_UNUSED(index);
|
|
|
|
emit changed(true);
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
void KCMLocale::slotMeasureChanged(const int index)
|
2014-11-15 03:14:34 +02:00
|
|
|
{
|
2023-07-26 09:52:37 +03:00
|
|
|
Q_UNUSED(index);
|
|
|
|
emit changed(true);
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:52:37 +03:00
|
|
|
void KCMLocale::slotDateOrTimeChanged(const QString &text)
|
2014-11-15 03:14:34 +02:00
|
|
|
{
|
2023-07-26 09:52:37 +03:00
|
|
|
Q_UNUSED(text);
|
|
|
|
emit changed(true);
|
2014-11-15 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
2015-02-27 09:28:46 +00:00
|
|
|
#include "moc_kcmlocale.cpp"
|