Commit 255bcdbf authored by Sebastian Kügler's avatar Sebastian Kügler
Browse files

Locale KCM is replaced by Formats KCM

BUG:331930
REVIEW:118063
parent 7760b870
......@@ -46,7 +46,6 @@ add_subdirectory(emoticons)
add_subdirectory(icons)
add_subdirectory(kded)
add_subdirectory(knotify)
#add_subdirectory(locale)
add_subdirectory(formats)
add_subdirectory(spellchecking)
add_subdirectory(phonon)
......
......@@ -347,19 +347,19 @@ void KCMFormats::updateExample()
const QString timeExample = tloc.toString(QDateTime::currentDateTime());
const QString currencyExample = cloc.toCurrencyString(24);
QString measurementExample;
QString measurementSetting;
if (mloc.measurementSystem() == QLocale::ImperialUKSystem) {
measurementExample = i18nc("Measurement combobox", "Imperial UK");
measurementSetting = i18nc("Measurement combobox", "Imperial UK");
} else if (mloc.measurementSystem() == QLocale::ImperialUSSystem) {
measurementExample = i18nc("Measurement combobox", "Imperial US");
measurementSetting = i18nc("Measurement combobox", "Imperial US");
} else {
measurementExample = i18nc("Measurement combobox", "Metric");
measurementSetting = i18nc("Measurement combobox", "Metric");
}
m_ui->exampleNumbers->setText(numberExample);
m_ui->exampleTime->setText(timeExample);
m_ui->exampleCurrency->setText(currencyExample);
m_ui->exampleMeasurement->setText(measurementExample);
m_ui->exampleMeasurement->setText(measurementSetting);
}
#include "kcmformats.moc"
Matthias Hoelzer (hoelzer@physik.uni-wuerzburg.de)
Hans Petter Bieker <bieker@kde.org>
add_subdirectory( pics )
########### next target ###############
set(kcm_locale_PART_SRCS kcmlocale.cpp)
qt5_wrap_ui(kcm_locale_PART_SRCS kcmlocalewidget.ui )
add_library(kcm_locale MODULE ${kcm_locale_PART_SRCS})
target_link_libraries(kcm_locale
Qt5::Widgets
KF5::KCMUtils
KF5::I18n
KF5::UnitConversion
${X11_LIBRARIES}
KF5::KDELibs4Support
)
install(TARGETS kcm_locale DESTINATION ${PLUGIN_INSTALL_DIR} )
########### install files ###############
install( FILES language.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
#! /usr/bin/env bash
$EXTRACTRC *.ui >> rc.cpp
$XGETTEXT -ktranslate:1,1t -ktranslate:1c,2,2t *.cpp -o $podir/kcmlocale.pot
/***************************************************************************
* Copyright (C) 2007 by Albert Astals Cid <aacid@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "countryselectordialog.h"
#include "kcontrollocale.h"
#include <KStandardDirs>
#include <QAbstractItemModel>
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QListView>
#include <QScrollBar>
#include <QStandardPaths>
struct CountryModelItem
{
CountryModelItem()
{
}
CountryModelItem( CountryModelItem *p, const QString &theText, const QString &theTag )
: parent(p), text(theText), tag(theTag)
{
}
~CountryModelItem()
{
qDeleteAll(children);
}
int row() const
{
if (parent) return parent->children.indexOf(const_cast<CountryModelItem*>(this));
return 0;
}
CountryModelItem *parent;
QList< CountryModelItem* > children;
QString text, tag;
KIcon icon;
};
bool CountryModelItemLessThan(CountryModelItem *s1, CountryModelItem *s2)
{
return s1->text < s2->text;
}
class CountryModel : public QAbstractItemModel
{
public:
CountryModel(QObject *parent) : QAbstractItemModel(parent)
{
m_rootItem = new CountryModelItem(NULL, QString(), QString());
}
CountryModel(CountryModelItem *rootItem, QObject *parent) : QAbstractItemModel(parent)
{
m_rootItem = rootItem;
}
~CountryModel()
{
if (m_rootItem->parent == NULL) delete m_rootItem;
}
void addRegion(const QString &name, const QString &tag)
{
CountryModelItem *cmi = new CountryModelItem(m_rootItem, name, tag);
m_rootItem->children.append(cmi);
}
void addSubRegion(const KIcon &flag, const QString &name, const QString &tag, const QString &superRegion)
{
CountryModelItem *parent = NULL;
foreach(CountryModelItem *cm, m_rootItem->children)
{
if (cm->tag == superRegion) parent = cm;
}
if (parent)
{
CountryModelItem *cmi = new CountryModelItem(parent, name, tag);
cmi->icon = flag;
parent->children.append(cmi);
}
}
void sort()
{
qSort(m_rootItem->children.begin(), m_rootItem->children.end(), CountryModelItemLessThan);
foreach(CountryModelItem *cm, m_rootItem->children)
{
qSort(cm->children.begin(), cm->children.end(), CountryModelItemLessThan);
}
}
int rowCount(const QModelIndex &parent) const
{
if (parent.column() > 0)
return 0;
CountryModelItem *parentItem;
if (!parent.isValid())
parentItem = m_rootItem;
else
parentItem = static_cast<CountryModelItem*>(parent.internalPointer());
return parentItem->children.count();
}
int columnCount(const QModelIndex &parent) const
{
if (!parent.isValid()) return 1;
else
{
CountryModelItem *p = static_cast<CountryModelItem*>(parent.internalPointer());
if (p->parent) return 1;
else return 0;
}
}
QModelIndex index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
CountryModelItem *parentItem;
if (!parent.isValid())
parentItem = m_rootItem;
else
parentItem = static_cast<CountryModelItem*>(parent.internalPointer());
CountryModelItem *childItem = parentItem->children.at(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
CountryModelItem *childItem = static_cast<CountryModelItem*>(index.internalPointer());
CountryModelItem *parentItem = childItem->parent;
if (parentItem == m_rootItem)
return QModelIndex();
return createIndex(parentItem->row(), 0, parentItem);
}
QVariant data(const QModelIndex &index, int role) const
{
if (index.isValid())
{
CountryModelItem *cmi = static_cast<CountryModelItem*>(index.internalPointer());
if (role == Qt::DisplayRole)
{
return cmi->text;
}
else if (role == Qt::DecorationRole)
{
if (cmi->parent->parent) return cmi->icon;
}
}
return QVariant();
}
private:
CountryModelItem *m_rootItem;
};
class CSDListView : public QListView
{
public:
CSDListView(QWidget *parent) : QListView(parent)
{
}
void setOtherWidget(QWidget *widget, Qt::Key key)
{
m_other = widget;
m_key = key;
}
protected:
void keyPressEvent(QKeyEvent *event)
{
if (event->key() == m_key) m_other->setFocus();
else QListView::keyPressEvent(event);
}
private:
QWidget *m_other;
Qt::Key m_key;
};
CountrySelectorDialog::CountrySelectorDialog(QWidget *parent) : KDialog(parent)
{
setCaption( i18n("Country Selector") );
setButtons( KDialog::Ok | KDialog::Cancel );
QWidget *widget = new QWidget(this);
setMainWidget(widget);
}
bool CountrySelectorDialog::editCountry(KControlLocale *locale)
{
QHBoxLayout *hbl = new QHBoxLayout(mainWidget());
CSDListView *lv1 = new CSDListView(mainWidget());
m_countriesView = new CSDListView(mainWidget());
hbl->addWidget(lv1);
hbl->addWidget(m_countriesView);
lv1->setOtherWidget(m_countriesView, Qt::Key_Right);
m_countriesView->setOtherWidget(lv1, Qt::Key_Left);
QString country, region;
country = locale->country();
CountryModel *cm = new CountryModel(this);
const QString &sub = QString::fromLatin1("l10n/");
QStringList regionlist = KGlobal::dirs()->findAllResources("locale",
sub + QString::fromLatin1("*.desktop"),
KStandardDirs::NoDuplicates);
QFontMetrics fm(lv1->font());
int lv1Width = 0;
foreach(const QString &region, regionlist)
{
QString tag = region;
int index;
index = tag.lastIndexOf('/');
if (index != -1)
tag = tag.mid(index + 1);
index = tag.lastIndexOf('.');
if (index != -1)
tag.truncate(index);
KConfig entry(region);
KConfigGroup cg = entry.group("KCM Locale");
QString name = cg.readEntry("Name", ki18n("without name").toString(locale));
cm->addRegion(name, tag);
QString spacedName = name + " ";
lv1Width = qMax(lv1Width, fm.width(spacedName));
}
// add all languages to the list
QStringList countrylist = KGlobal::dirs()->findAllResources("locale",
sub + QString::fromLatin1("*/kf5_entry.desktop"),
KStandardDirs::NoDuplicates);
foreach(const QString &countryFile, countrylist)
{
KConfig entry(countryFile);
KConfigGroup cg = entry.group("KCM Locale");
QString name = cg.readEntry("Name", ki18n("without name").toString(locale));
QString parentRegion = cg.readEntry("Region");
QString tag = countryFile;
int index = tag.lastIndexOf('/');
tag.truncate(index);
index = tag.lastIndexOf('/');
tag = tag.mid(index + 1);
QString flag( QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("locale/") + QString::fromLatin1( "l10n/%1/flag.png" ).arg(tag) ) );
cm->addSubRegion(KIcon(flag), name, tag, parentRegion);
if (tag == country) region = parentRegion;
}
cm->sort();
cm->addRegion(i18nc("@item:inlistbox Country", "Not set (Generic English)"), "C");
if (country == "C") region = "C";
lv1->setModel(cm);
lv1->setFixedWidth(lv1Width + lv1->verticalScrollBar()->height());
// + 2 because 1 is "Not set (Generic English)" and the other is for spacing
lv1->setMinimumHeight((regionlist.count() + 2) * fm.height());
connect(lv1->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), SLOT(regionChanged(const QModelIndex &)));
connect(lv1, SIGNAL(activated(const QModelIndex &)), SLOT(regionActivated()));
connect(m_countriesView, SIGNAL(activated(const QModelIndex &)), SLOT(accept()));
for(int i = 0; i < lv1->model()->rowCount(); ++i)
{
const QModelIndex &current = lv1->model()->index(i, 0);
CountryModelItem *cmi = static_cast<CountryModelItem*>(current.internalPointer());
if (cmi->tag == region)
{
lv1->selectionModel()->setCurrentIndex(current, QItemSelectionModel::SelectCurrent);
}
}
if (m_countriesView->model() != NULL)
{
for(int i = 0; i < m_countriesView->model()->rowCount(); ++i)
{
const QModelIndex &current = m_countriesView->model()->index(i, 0);
CountryModelItem *cmi = static_cast<CountryModelItem*>(current.internalPointer());
if (cmi->tag == country)
{
m_countriesView->selectionModel()->setCurrentIndex(current, QItemSelectionModel::SelectCurrent);
}
}
m_countriesView->setFocus();
}
else lv1->setFocus();
if (exec() == QDialog::Accepted)
{
const QModelIndex &current = m_countriesView->currentIndex();
if (current.isValid())
{
CountryModelItem *cmi = static_cast<CountryModelItem*>(current.internalPointer());
return locale->setCountry(cmi->tag);
}
else if (m_countriesView->model() == NULL)
{
return locale->setCountry("C");
}
}
return false;
}
void CountrySelectorDialog::regionChanged(const QModelIndex &current)
{
delete m_countriesView->model();
CountryModelItem *cmi = static_cast<CountryModelItem*>(current.internalPointer());
if (!cmi->children.isEmpty())
{
CountryModel *cm = new CountryModel(cmi, this);
m_countriesView->setModel(cm);
}
else
{
m_countriesView->setModel(NULL);
}
}
void CountrySelectorDialog::regionActivated()
{
if (m_countriesView->model() != NULL) m_countriesView->setFocus();
else accept();
}
/***************************************************************************
* Copyright (C) 2007 by Albert Astals Cid <aacid@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef COUNTRYSELECTORDIALOG_H
#define COUNTRYSELECTORDIALOG_H
#include <KDialog>
class CSDListView;
class KControlLocale;
class QModelIndex;
class CountrySelectorDialog : public KDialog
{
Q_OBJECT
public:
CountrySelectorDialog(QWidget *parent);
bool editCountry(KControlLocale *locale);
private slots:
void regionChanged(const QModelIndex &current);
void regionActivated();
private:
CSDListView *m_countriesView;
};
#endif
This diff is collapsed.
/* This file is part of the KDE libraries
* Copyright 2010 John Layt <john@layt.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* 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.
*
* 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.
*/
#ifndef KCMLOCALE_H
#define KCMLOCALE_H
#include <QMap>
#include <KCModule>
#include <KSharedConfig>
#include <KConfigGroup>
#include <KLocale>
class QListWidgetItem;
class QCheckBox;
class KPushButton;
class KComboBox;
class KIntNumInput;
namespace Ui {
class KCMLocaleWidget;
}
/**
* @short A KCM to configure locale settings
*
* This module is for changing the User's Locale settings, which may override their Group and
* Country defaults.
*
* The settings hierarchy is as follows:
* - User settings from kdeglobals
* - Group settings from $KDEDIRS
* - Country settings from l10n
* - C default settings from l10n
*
* The settings that apply to the User are a merger of all these.
*
* This may be restricted by Kiosk Group settings locking the user from updating some/all settings.
*
* The KCM starts by loading the fully merged settings including the User settings
* In KCM terms, to Reload is to load the fully merged settings including the User settings
* In KCM terms, to reset to Defaults is to remove the User settings only.
* The user can also reset to Default each individual setting.
*/
class KCMLocale : public KCModule
{
Q_OBJECT
public:
KCMLocale(QWidget *parent, const QVariantList &);
virtual ~KCMLocale();
virtual void load();
virtual void save();
virtual void defaults();
virtual QString quickHelp() const;
private:
//Common load/save utilities
// Initialise the different settings groups
void initSettings();
void initCountrySettings( const QString &countryCode );
void initCalendarSettings();
// Merge the different settings groups into the effective settings
void mergeSettings();
void mergeCalendarSettings();
// Copy the supported settings between settings groups
void copySettings( KConfigGroup *fromGroup, KConfigGroup *toGroup,
KConfig::WriteConfigFlags flags = KConfig::Normal );
void copyCalendarSettings( KConfigGroup *fromGroup, KConfigGroup *toGroup,
KConfig::WriteConfigFlags flags = KConfig::Normal );
void copySetting( KConfigGroup *fromGroup, KConfigGroup *toGroup, const QString &key,
KConfig::WriteConfigFlags flags = KConfig::Normal );
// Enable / Disable an item in the gui
void enableItemWidgets( const QString &itemKey, KConfigGroup *userSettings,
KConfigGroup *kcmSettings, KConfigGroup *defaultSettings,
QWidget *itemWidget, KPushButton *itemDefaultButton );
// Set the item value in the required settings groups
void setItemValue( const QString &itemKey, const QString &itemValue,
KConfigGroup *userSettings, KConfigGroup *kcmSettings, KConfigGroup *defaultSettings );
// Set an item: set the item value, enable the widgets, set the changed flag, don't update the widget
void setItem( const QString &itemKey, const QString &itemValue,
QWidget *itemWidget, KPushButton *itemDefaultButton );
void setItem( const QString &itemKey, int itemValue,
QWidget *itemWidget, KPushButton *itemDefaultButton );
void setItem( const QString &itemKey, bool itemValue,
QWidget *itemWidget, KPushButton *itemDefaultButton );
void setCalendarItem( const QString &itemKey, const QString &itemValue,
QWidget *itemWidget, KPushButton *itemDefaultButton );
void setCalendarItem( const QString &itemKey, int itemValue,
QWidget *itemWidget, KPushButton *itemDefaultButton );
void setCalendarItem( const QString &itemKey, bool itemValue,
QWidget *itemWidget, KPushButton *itemDefaultButton );
// Set an item: set the item value, enable the widgets, set the changed flag, update the widget
void setComboItem( const QString &itemKey, const QString &itemValue,
KComboBox *itemCombo, KPushButton *itemDefaultButton );
void setComboItem( const QString &itemKey, int itemValue,
KComboBox *itemCombo, KPushButton *itemDefaultButton );
void setEditComboItem( const QString &itemKey, const QString &itemValue,
KComboBox *itemCombo, KPushButton *itemDefaultButton );
void setIntItem( const QString &itemKey, int itemValue,
KIntNumInput *itemInput, KPushButton *itemDefaultButton );
void setCheckItem( const QString &itemKey, bool itemValue,
QCheckBox *itemCheck, KPushButton *itemDefaultButton );