diff --git a/applications/settings/modules/CMakeLists.txt b/applications/settings/modules/CMakeLists.txt index 0820aade..2a89f5ad 100644 --- a/applications/settings/modules/CMakeLists.txt +++ b/applications/settings/modules/CMakeLists.txt @@ -1,15 +1,16 @@ # 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) install(FILES web/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME plasma-package-org.kde.active.settings.web.desktop) #Power install(DIRECTORY powermanagement/ DESTINATION ${DATA_INSTALL_DIR}/plasma/packages/org.kde.active.settings.powermanagement) install(FILES powermanagement/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME plasma-package-org.kde.active.settings.powermanagement.desktop) # ConfigTest #install(DIRECTORY configtest/ DESTINATION ${DATA_INSTALL_DIR}/plasma/packages/org.kde.active.settings.configtest) #install(FILES configtest/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME plasma-package-org.kde.active.settings.configtest.desktop) diff --git a/applications/settings/modules/locale/CMakeLists.txt b/applications/settings/modules/locale/CMakeLists.txt new file mode 100644 index 00000000..f4fa44ec --- /dev/null +++ b/applications/settings/modules/locale/CMakeLists.txt @@ -0,0 +1,20 @@ +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) diff --git a/applications/settings/modules/locale/languagesmodel.cpp b/applications/settings/modules/locale/languagesmodel.cpp new file mode 100644 index 00000000..10e61673 --- /dev/null +++ b/applications/settings/modules/locale/languagesmodel.cpp @@ -0,0 +1,42 @@ +/* Copyright (C) 2012 basysKom GmbH + * + * 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 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" diff --git a/applications/settings/modules/locale/languagesmodel.h b/applications/settings/modules/locale/languagesmodel.h new file mode 100644 index 00000000..0a759ba2 --- /dev/null +++ b/applications/settings/modules/locale/languagesmodel.h @@ -0,0 +1,38 @@ +/* Copyright (C) 2012 basysKom GmbH + * + * 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 + +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 diff --git a/applications/settings/modules/locale/localesettings.cpp b/applications/settings/modules/locale/localesettings.cpp new file mode 100644 index 00000000..23039dd5 --- /dev/null +++ b/applications/settings/modules/locale/localesettings.cpp @@ -0,0 +1,118 @@ +/* Copyright (C) 2012 basysKom GmbH + * + * 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 +#include +#include +#include +#include + +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" diff --git a/applications/settings/modules/locale/localesettings.h b/applications/settings/modules/locale/localesettings.h new file mode 100644 index 00000000..5ea0687f --- /dev/null +++ b/applications/settings/modules/locale/localesettings.h @@ -0,0 +1,64 @@ +/* Copyright (C) 2012 basysKom GmbH + * + * 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 + +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 diff --git a/applications/settings/modules/locale/localesettingsplugin.cpp b/applications/settings/modules/locale/localesettingsplugin.cpp new file mode 100644 index 00000000..a86f1a38 --- /dev/null +++ b/applications/settings/modules/locale/localesettingsplugin.cpp @@ -0,0 +1,43 @@ +/* Copyright (C) 2012 basysKom GmbH + * + * 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 + +#include +#include + +K_PLUGIN_FACTORY(LocaleSettingsFactory, registerPlugin();) +K_EXPORT_PLUGIN(LocaleSettingsFactory("active_settings_locale")) + +LocaleSettingsPlugin::LocaleSettingsPlugin(QObject *parent, const QVariantList &list) + : QObject(parent) +{ + Q_UNUSED(list) + + kDebug() << "LocaleSettingsPlugin created:)"; + qmlRegisterType(); + qmlRegisterType("org.kde.active.settings", 0, 1, "LocaleSettings"); +} + +LocaleSettingsPlugin::~LocaleSettingsPlugin() +{ +} + +#include "localesettingsplugin.moc" diff --git a/applications/settings/modules/locale/localesettingsplugin.h b/applications/settings/modules/locale/localesettingsplugin.h new file mode 100644 index 00000000..1491976f --- /dev/null +++ b/applications/settings/modules/locale/localesettingsplugin.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2012 basysKom GmbH + * + * 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 +#include + +class LocaleSettingsPlugin : public QObject +{ + Q_OBJECT + + public: + explicit LocaleSettingsPlugin(QObject *parent, const QVariantList &list = QVariantList()); + virtual ~LocaleSettingsPlugin(); + +}; + +#endif // LOCALESETTINGSPLUGIN_H diff --git a/applications/settings/modules/locale/package/contents/images/throbber.svgz b/applications/settings/modules/locale/package/contents/images/throbber.svgz new file mode 100644 index 00000000..12886ef8 Binary files /dev/null and b/applications/settings/modules/locale/package/contents/images/throbber.svgz differ diff --git a/applications/settings/modules/locale/package/contents/ui/LanguagePicker.qml b/applications/settings/modules/locale/package/contents/ui/LanguagePicker.qml new file mode 100644 index 00000000..7540e1b4 --- /dev/null +++ b/applications/settings/modules/locale/package/contents/ui/LanguagePicker.qml @@ -0,0 +1,123 @@ +/* Copyright (C) 2012 basysKom GmbH + * + * 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() + } + } + } +} diff --git a/applications/settings/modules/locale/package/contents/ui/Locale.qml b/applications/settings/modules/locale/package/contents/ui/Locale.qml new file mode 100644 index 00000000..f0c30918 --- /dev/null +++ b/applications/settings/modules/locale/package/contents/ui/Locale.qml @@ -0,0 +1,104 @@ +/* Copyright (C) 2012 basysKom GmbH + * + * 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."); + } +} diff --git a/applications/settings/modules/locale/package/metadata.desktop b/applications/settings/modules/locale/package/metadata.desktop new file mode 100644 index 00000000..4bcca49c --- /dev/null +++ b/applications/settings/modules/locale/package/metadata.desktop @@ -0,0 +1,19 @@ +[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