Commit 92fb680b authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

Provide a kcm module to choose a virtual keyboard

BUG: 430850
parent 2c052291
......@@ -9,6 +9,7 @@ add_subdirectory(kwinscreenedges)
add_subdirectory(kwinscripts)
add_subdirectory(kwindesktop)
add_subdirectory(kwineffects)
add_subdirectory(kwinvirtualkeyboard)
if (KWIN_BUILD_TABBOX)
add_subdirectory(kwintabbox)
......
#SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalzez <aleixpol@kde.org>
#SPDX-License-Identifier: BSD-3-Clause
add_definitions(-DTRANSLATION_DOMAIN=\"kcm_virtualkeyboard\")
kcmutils_generate_module_data(
kcm_virtualkeyboard_PART_SRCS
MODULE_DATA_HEADER virtualkeyboarddata.h
MODULE_DATA_CLASS_NAME VirtualKeyboardData
SETTINGS_HEADERS virtualkeyboardsettings.h
SETTINGS_CLASSES VirtualKeyboardSettings
)
kconfig_add_kcfg_files(kcm_virtualkeyboard_PART_SRCS virtualkeyboardsettings.kcfgc GENERATE_MOC)
add_library(kcm_virtualkeyboard MODULE kcmvirtualkeyboard.cpp ${kcm_virtualkeyboard_PART_SRCS})
target_include_directories(kcm_virtualkeyboard PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(kcm_virtualkeyboard
KF5::I18n
KF5::KCMUtils
KF5::QuickAddons
)
kcoreaddons_desktop_to_json(kcm_virtualkeyboard "kcm_virtualkeyboard.desktop")
install(TARGETS kcm_virtualkeyboard DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms)
install(FILES kcm_virtualkeyboard.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
kpackage_install_package(package kcm_virtualkeyboard kcms)
#! /usr/bin/env bash
$XGETTEXT `find . -name \*.cpp -o -name \*.h -o -name \*.qml` -o $podir/kcm_virtualkeyboard.pot
#SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalzez <aleixpol@kde.org>
#SPDX-License-Identifier: BSD-3-Clause
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KCModule
Icon=input-keyboard-virtual
X-KDE-Library=kcm_virtualkeyboard
X-KDE-ParentApp=kcontrol
X-KDE-System-Settings-Parent-Category=input-devices
X-KDE-OnlyShowOnQtPlatforms=wayland;
Name=Virtual Keyboard
Comment=Select which virtual keyboard to use
Categories=Qt;KDE;
/*
SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kcmvirtualkeyboard.h"
#include <KAboutData>
#include <KApplicationTrader>
#include <KConfigGroup>
#include <KDesktopFile>
#include <KLocalizedString>
#include <KPluginFactory>
#include <virtualkeyboarddata.h>
#include <virtualkeyboardsettings.h>
K_PLUGIN_FACTORY_WITH_JSON(KcmVirtualKeyboardFactory, "kcm_virtualkeyboard.json", registerPlugin<KcmVirtualKeyboard>(); registerPlugin<VirtualKeyboardData>();)
KcmVirtualKeyboard::KcmVirtualKeyboard(QObject *parent, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent)
, m_data(new VirtualKeyboardData(this))
, m_model(new VirtualKeyboardsModel(this))
{
Q_UNUSED(args)
qmlRegisterAnonymousType<VirtualKeyboardSettings>("org.kde.kwin.virtualkeyboardsettings", 1);
setAboutData(new KAboutData(QStringLiteral("kcm_virtualkeyboard"),
i18n("Virtual Keyboard"),
QStringLiteral("1.0"),
i18n("Choose Virtual Keyboard"),
KAboutLicense::GPL));
}
KcmVirtualKeyboard::~KcmVirtualKeyboard() = default;
VirtualKeyboardSettings *KcmVirtualKeyboard::settings() const
{
return m_data->settings();
}
VirtualKeyboardsModel::VirtualKeyboardsModel(QObject *parent)
: QAbstractListModel(parent)
{
m_services = KApplicationTrader::query([](const KService::Ptr &service) {
return service->property("X-KDE-Wayland-VirtualKeyboard", QVariant::Bool).toBool();
});
m_services.prepend({});
}
QHash<int, QByteArray> VirtualKeyboardsModel::roleNames() const
{
QHash<int, QByteArray> ret = QAbstractListModel::roleNames();
ret.insert(DesktopFileNameRole, "desktopFileName");
return ret;
}
QVariant VirtualKeyboardsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.parent().isValid() || index.row() > m_services.count()) {
return {};
}
const KService::Ptr service = m_services[index.row()];
switch (role) {
case Qt::DisplayRole:
return service ? service->name() : i18n("None");
case Qt::DecorationRole:
return service ? service->icon() : QStringLiteral("edit-none");
case Qt::ToolTipRole:
return service ? service->comment() : i18n("Do not use any virtual keyboard");
case DesktopFileNameRole:
return service ? QStandardPaths::locate(QStandardPaths::ApplicationsLocation, service->desktopEntryName() + QLatin1String(".desktop")) : QString();
}
return {};
}
int VirtualKeyboardsModel::inputMethodIndex(const QString &desktopFile) const
{
if (desktopFile.isEmpty()) {
return 0;
}
int i = 0;
for (const auto &service : m_services) {
if (service && desktopFile.endsWith(service->desktopEntryName() + QLatin1String(".desktop"))) {
return i;
}
++i;
}
return -1;
}
int VirtualKeyboardsModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_services.count();
}
#include "kcmvirtualkeyboard.moc"
/*
SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <KQuickAddons/ManagedConfigModule>
#include <KService>
class KDesktopFile;
class VirtualKeyboardData;
class VirtualKeyboardSettings;
class VirtualKeyboardsModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Roles { DesktopFileNameRole = Qt::UserRole + 1 };
Q_ENUM(Roles);
VirtualKeyboardsModel(QObject *parent = nullptr);
QVariant data(const QModelIndex &index, int role) const override;
int rowCount(const QModelIndex &parent) const override;
QHash<int, QByteArray> roleNames() const override;
Q_SCRIPTABLE int inputMethodIndex(const QString &desktopFile) const;
private:
KService::List m_services;
};
class KcmVirtualKeyboard : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
Q_PROPERTY(VirtualKeyboardSettings *settings READ settings CONSTANT)
Q_PROPERTY(QAbstractItemModel *model READ keyboardsModel CONSTANT)
public:
explicit KcmVirtualKeyboard(QObject *parent = nullptr, const QVariantList &list = QVariantList());
~KcmVirtualKeyboard() override;
VirtualKeyboardSettings *settings() const;
VirtualKeyboardsModel *keyboardsModel() const
{
return m_model;
}
private:
VirtualKeyboardData *m_data;
VirtualKeyboardsModel *const m_model;
};
/*
SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import QtQuick 2.1
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.3 as QQC2
import org.kde.kirigami 2.6 as Kirigami
import org.kde.kcm 1.3 as KCM
KCM.GridViewKCM {
id: root
KCM.ConfigModule.quickHelp: i18n("This module lets you choose the virtual keyboard to use.")
view.model: kcm.model
view.currentIndex: kcm.model.inputMethodIndex(kcm.settings.inputMethod)
KCM.SettingStateBinding {
configObject: kcm.settings
settingName: "InputMethod"
}
view.delegate: KCM.GridDelegate {
text: model.display
toolTip: model.toolTip
thumbnailAvailable: model.decoration
thumbnail: Kirigami.Icon {
anchors.fill: parent
source: model.decoration
}
onClicked: {
kcm.settings.inputMethod = model.desktopFileName;
}
}
}
#SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalzez <aleixpol@kde.org>
#SPDX-License-Identifier: BSD-3-Clause
[Desktop Entry]
Name=Virtual Keyboard
Icon=input-keyboard-virtual
Type=Service
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-Name=kcm_virtualkeyboard
X-KDE-ServiceTypes=Plasma/Generic
X-Plasma-MainScript=ui/main.qml
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kwinrc"/>
<group name="Wayland">
<entry name="InputMethod" type="Path" />
</group>
</kcfg>
File=virtualkeyboardsettings.kcfg
ClassName=VirtualKeyboardSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
Supports Markdown
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