Commit 4cb70f6f authored by Lamarque Souza's avatar Lamarque Souza

Add Locale module to active-settings.

Still needs to add a warning dialog that the current running
applications need to be restarted for the setting to take effect.

CCBUG: 298850
parent 5deb48ef
# Install the packages, also make it known to the system
add_subdirectory(time)
add_subdirectory(locale)
# Web
install(DIRECTORY web/ DESTINATION ${DATA_INSTALL_DIR}/plasma/packages/org.kde.active.settings.web)
......
project( active_settings_locale )
find_package(KDE4 REQUIRED)
include(KDE4Defaults)
add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
include_directories(${KDE4_INCLUDES} ../../../../components/settings)
set(localesettings_SRCS
localesettingsplugin.cpp
localesettings.cpp
languagesmodel.cpp
)
kde4_add_plugin(active_settings_locale ${localesettings_SRCS})
target_link_libraries(active_settings_locale ${KDE4_PLASMA_LIBS} ${QT_QTDECLARATIVE_LIBRARY})
install(TARGETS active_settings_locale DESTINATION ${PLUGIN_INSTALL_DIR})
# Locale
install(DIRECTORY package/ DESTINATION ${DATA_INSTALL_DIR}/plasma/packages/org.kde.active.settings.locale)
install(FILES package/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME plasma-package-org.kde.active.settings.locale.desktop)
/* Copyright (C) 2012 basysKom GmbH <info@basyskom.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "languagesmodel.h"
LanguagesModel::LanguagesModel(QObject *parent)
: QStandardItemModel(parent)
{
QHash<int, QByteArray> roleNames;
roleNames[Qt::DisplayRole] = "display";
roleNames[Qt::UserRole+1] = "langCode";
setRoleNames(roleNames);
connect(this, SIGNAL(modelReset()), this, SIGNAL(countChanged()));
connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(countChanged()));
connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(countChanged()));
}
QVariantHash LanguagesModel::get(int i) const
{
QModelIndex idx = index(i, 0);
QVariantHash hash;
hash["display"] = data(idx, Qt::DisplayRole);
hash["langCode"] = data(idx, Qt::UserRole+1);
return hash;
}
#include "languagesmodel.moc"
/* Copyright (C) 2012 basysKom GmbH <info@basyskom.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LANGUAGESMODEL_H
#define LANGUAGESMODEL_H
#include <QStandardItemModel>
class LanguagesModel: public QStandardItemModel
{
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
LanguagesModel(QObject *parent=0);
Q_INVOKABLE QVariantHash get(int i) const;
int count() const {return rowCount();}
Q_SIGNALS:
void countChanged();
};
#endif
/* Copyright (C) 2012 basysKom GmbH <info@basyskom.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "localesettings.h"
#include "languagesmodel.h"
#include <KDebug>
#include <KConfigGroup>
#include <KGlobal>
#include <KGlobalSettings>
#include <KLocale>
class LocaleSettingsPrivate {
public:
LocaleSettings *q;
QString language;
QObject *languagesModel;
QString languageFilter;
KSharedConfigPtr globalConfig;
KConfigGroup localeConfigGroup;
void initLanguages();
};
LocaleSettings::LocaleSettings()
{
d = new LocaleSettingsPrivate;
d->q = this;
d->languagesModel = 0;
d->initLanguages();
kDebug() << "LocaleSettings module loaded.";
}
LocaleSettings::~LocaleSettings()
{
kDebug() << "========================== LocaleSettings destroyed";
delete d;
}
void LocaleSettingsPrivate::initLanguages()
{
globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::SimpleConfig);
localeConfigGroup = KConfigGroup(globalConfig, "Locale");
QStandardItemModel * _languagesModel = new LanguagesModel(q);
//kDebug() << "Language list" << KGlobal::locale()->languageList();
//foreach (const QString &langCode, KGlobal::locale()->allLanguagesList()) {
foreach (const QString &langCode, KGlobal::locale()->installedLanguages()) {
QStandardItem *item = new QStandardItem(KGlobal::locale()->languageCodeToName(langCode));
item->setData(langCode, Qt::UserRole+1);
_languagesModel->appendRow(item);
}
languagesModel = _languagesModel;
language = localeConfigGroup.readEntry("Language", QString()).split(':').first();
language = KGlobal::locale()->languageCodeToName(language);
}
QString LocaleSettings::language()
{
return d->language;
}
void LocaleSettings::setLanguage(const QString &language)
{
// save new setting to $KDEHOME/.kde/share/config/kdeglobals.
d->localeConfigGroup.writeEntry("Language", language);
d->globalConfig->sync();
// set language for this program.
KGlobal::locale()->setLanguage(QStringList() << language);
//KGlobal::locale()->reparseConfiguration();
// cache the new language setting.
//d->language = d->localeConfigGroup.readEntry("Language", QString()).split(':').first();
//d->language = KGlobal::locale()->languageCodeToName(d->language);
d->language = KGlobal::locale()->languageCodeToName(language);
//kDebug() << "new language" << d->language;
// signal other KDE programs that locale settings has changed.
KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_LOCALE);
// signal the QML part of active-settings that the language has changed.
emit languageChanged();
}
QObject* LocaleSettings::languagesModel()
{
return d->languagesModel;
}
void LocaleSettings::setLanguagesModel(QObject* languagesModel)
{
if ( d->languagesModel != languagesModel) {
d->languagesModel = languagesModel;
emit languagesModelChanged();
}
}
#include "localesettings.moc"
/* Copyright (C) 2012 basysKom GmbH <info@basyskom.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LOCALESETTINGS_H
#define LOCALESETTINGS_H
#include <QObject>
class LocaleSettingsPrivate;
/**
* @class A class to manage time and date related settings. This class serves two functions:
* - Provide a plugin implementation
* - Provide a settings module
* This is done from one class in order to simplify the code. You can export any QObject-based
* class through qmlRegisterType(), however.
*/
class LocaleSettings : public QObject
{
Q_OBJECT
Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged)
Q_PROPERTY(QObject* languagesModel READ languagesModel WRITE setLanguagesModel NOTIFY languagesModelChanged)
public:
/**
* @name Settings Module Constructor
*
* @arg parent The parent object
* @arg list Arguments, currently unused
*/
LocaleSettings();
virtual ~LocaleSettings();
QString language();
QObject* languagesModel();
public Q_SLOTS:
void setLanguage(const QString &language);
void setLanguagesModel(QObject* languages);
Q_SIGNALS:
void languageChanged();
void languagesModelChanged();
private:
LocaleSettingsPrivate* d;
};
#endif // LOCALESETTINGS_H
/* Copyright (C) 2012 basysKom GmbH <info@basyskom.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "localesettingsplugin.h"
#include "localesettings.h"
#include <QDeclarativeComponent>
#include <KDebug>
#include <KPluginFactory>
K_PLUGIN_FACTORY(LocaleSettingsFactory, registerPlugin<LocaleSettingsPlugin>();)
K_EXPORT_PLUGIN(LocaleSettingsFactory("active_settings_locale"))
LocaleSettingsPlugin::LocaleSettingsPlugin(QObject *parent, const QVariantList &list)
: QObject(parent)
{
Q_UNUSED(list)
kDebug() << "LocaleSettingsPlugin created:)";
qmlRegisterType<LocaleSettings>();
qmlRegisterType<LocaleSettings>("org.kde.active.settings", 0, 1, "LocaleSettings");
}
LocaleSettingsPlugin::~LocaleSettingsPlugin()
{
}
#include "localesettingsplugin.moc"
/* Copyright (C) 2012 basysKom GmbH <info@basyskom.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LOCALESETTINGSPLUGIN_H
#define LOCALESETTINGSPLUGIN_H
#include "localesettingsplugin.h"
#include <QtCore/QObject>
#include <QtCore/QVariantList>
class LocaleSettingsPlugin : public QObject
{
Q_OBJECT
public:
explicit LocaleSettingsPlugin(QObject *parent, const QVariantList &list = QVariantList());
virtual ~LocaleSettingsPlugin();
};
#endif // LOCALESETTINGSPLUGIN_H
/* Copyright (C) 2012 basysKom GmbH <info@basyskom.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
import QtQuick 1.0
import org.kde.plasma.core 0.1 as PlasmaCore
import org.kde.plasma.components 0.1 as PlasmaComponents
import org.kde.plasma.mobilecomponents 0.1 as MobileComponents
import org.kde.active.settings 0.1
import org.kde.qtextracomponents 0.1
Item {
id: languagePicker
objectName: "languagePicker"
anchors.fill: parent
signal filterChanged(string filter)
function focusTextInput()
{
focusTimer.running = true
}
Timer {
id: focusTimer
interval: 100
onTriggered: {
langFilter.forceActiveFocus()
}
}
Text {
id: languageLabel
color: theme.textColor
anchors.right: parent.horizontalCenter
anchors.top: parent.top
text: i18n("Current Language:")
anchors.rightMargin: 12
//opacity: 1
}
Text {
anchors.left: parent.horizontalCenter
anchors.verticalCenter: languageLabel.verticalCenter
text: localeSettings.language
}
PlasmaComponents.TextField {
id: langFilter
width: parent.width
placeholderText: "Filter..."
clearButtonShown: true
//Keys.onTabPressed: tf2.forceActiveFocus();
anchors {
//verticalCenter: parent.verticalCenter
top: languageLabel.bottom
//topMargin: 32;
//bottom: parent.bottom
}
onTextChanged: {
console.log("update filter" + text);
filterModel.filterRegExp = ".*"+text+".*"
}
}
PlasmaCore.SortFilterModel {
id: filterModel
sourceModel: localeSettings.languagesModel
filterRole: "display"
sortRole: "display"
sortOrder: "AscendingOrder"
}
ListView {
id: languageList
currentIndex: -1
clip: true
cacheBuffer: 90000
anchors {
//verticalCenter: parent.verticalCenter
top: langFilter.bottom
topMargin: 8
bottom: parent.bottom
left: parent.left
right: parent.right
}
delegate: languageDelegate
model: filterModel
}
PlasmaComponents.SectionScroller {
id: sectionScroller
listView: languageList
}
Component {
id: languageDelegate
PlasmaComponents.ListItem {
PlasmaComponents.Label {
text: display
}
enabled: true
checked: localeSettings.language == display
onClicked: {
console.log(" save: " + langCode + " (" + display + ")");
localeSettings.language = langCode
languagePickerDialog.close()
}
}
}
}
/* Copyright (C) 2012 basysKom GmbH <info@basyskom.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
import QtQuick 1.0
import org.kde.plasma.core 0.1 as PlasmaCore
import org.kde.plasma.components 0.1 as PlasmaComponents
import org.kde.plasma.extras 0.1 as PlasmaExtras
import org.kde.plasma.mobilecomponents 0.1 as MobileComponents
import org.kde.active.settings 0.1
Item {
id: localeModule
objectName: "localeModule"
LocaleSettings {
id: localeSettings
}
width: 800; height: 500
MobileComponents.Package {
id: localePackage
name: "org.kde.active.settings.locale"
}
Column {
id: titleCol
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
PlasmaExtras.Title {
text: settingsComponent.name
opacity: 1
}
PlasmaComponents.Label {
id: descriptionLabel
text: settingsComponent.description
opacity: .4
}
}
Grid {
id: formLayout
columns: 2
rows: 4
spacing: theme.defaultFont.mSize.height
anchors {
top: titleCol.bottom
horizontalCenter: parent.horizontalCenter
topMargin: theme.defaultFont.mSize.height
}
PlasmaComponents.Label {
id: languageLabel
text: i18n("Language:")
anchors {
right: languageButton.left
rightMargin: theme.defaultFont.mSize.width
}
}
PlasmaComponents.Button {
id: languageButton
text: localeSettings.language
onClicked: languagePickerDialog.open()
}
}
PlasmaComponents.CommonDialog {
id: languagePickerDialog
titleText: i18n("Select a Language")
buttonTexts: [i18n("Cancel")]
onButtonClicked: close()
content: Loader {
id: languagePickerLoader
width: theme.defaultFont.mSize.width*22
height: theme.defaultFont.mSize.height*25
}
onStatusChanged: {
if (status == PlasmaComponents.DialogStatus.Open) {
languagePickerLoader.source = "LanguagePicker.qml"
languagePickerLoader.item.focusTextInput()
}
}
}
Component.onCompleted: {
print("Loaded Locale.qml successfully.");
}
}
[Desktop Entry]
Name=Locale
Comment=Settings for locale
Encoding=UTF-8
Type=Service
Icon=preferences-desktop-locale
X-KDE-ServiceTypes=Active/SettingsModule
X-KDE-Library=active_settings_locale
X-KDE-PluginInfo-Author=Lamarque V. Souza
X-KDE-PluginInfo-Email=lamarque@kde.org
X-KDE-PluginInfo-Name=org.kde.active.settings.locale
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Website=http://plasma-active.org
X-KDE-PluginInfo-Category=Language
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
X-Plasma-Package=org.kde.active.settings.locale
X-Plasma-MainScript=ui/Locale.qml
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment