diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -39,6 +39,7 @@ ../src/platformtheme/kdeplatformsystemtrayicon.cpp ../src/platformtheme/kdirselectdialog.cpp ../src/platformtheme/kfiletreeview.cpp + ../src/platformtheme/kioskintegration.cpp ../src/platformtheme/kwaylandintegration.cpp ../src/platformtheme/x11integration.cpp ) diff --git a/src/platformtheme/CMakeLists.txt b/src/platformtheme/CMakeLists.txt --- a/src/platformtheme/CMakeLists.txt +++ b/src/platformtheme/CMakeLists.txt @@ -19,6 +19,7 @@ kdeplatformsystemtrayicon.cpp kfiletreeview.cpp kdirselectdialog.cpp + kioskintegration.cpp kwaylandintegration.cpp x11integration.cpp main.cpp diff --git a/src/platformtheme/kdeplatformtheme.h b/src/platformtheme/kdeplatformtheme.h --- a/src/platformtheme/kdeplatformtheme.h +++ b/src/platformtheme/kdeplatformtheme.h @@ -29,6 +29,7 @@ class KHintsSettings; class KFontSettingsData; +class KioskIntegration; class KWaylandIntegration; class X11Integration; class QIconEngine; @@ -57,6 +58,7 @@ KHintsSettings *m_hints; KFontSettingsData *m_fontsData; + QScopedPointer m_kioskIntegration; QScopedPointer m_kwaylandIntegration; QScopedPointer m_x11Integration; }; diff --git a/src/platformtheme/kdeplatformtheme.cpp b/src/platformtheme/kdeplatformtheme.cpp --- a/src/platformtheme/kdeplatformtheme.cpp +++ b/src/platformtheme/kdeplatformtheme.cpp @@ -25,6 +25,8 @@ #include "khintssettings.h" #include "kdeplatformfiledialoghelper.h" #include "kdeplatformsystemtrayicon.h" + +#include "kioskintegration.h" #include "kwaylandintegration.h" #include "x11integration.h" @@ -47,6 +49,10 @@ KdePlatformTheme::KdePlatformTheme() { loadSettings(); + + m_kioskIntegration.reset(new KioskIntegration()); + m_kioskIntegration->init(); + if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"))) { m_kwaylandIntegration.reset(new KWaylandIntegration()); m_kwaylandIntegration->init(); diff --git a/src/platformtheme/kioskintegration.h b/src/platformtheme/kioskintegration.h new file mode 100644 --- /dev/null +++ b/src/platformtheme/kioskintegration.h @@ -0,0 +1,37 @@ +/* + * Copyright 2016 Kai Uwe Broulik + * + * 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 of the License or ( at + * your option ) version 3 or, at the discretion of KDE e.V. ( which shall + * act as a proxy as in section 14 of the GPLv3 ), 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 Lesser 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. + */ + +#pragma once + +#include + +class KioskIntegration : public QObject +{ + Q_OBJECT + +public: + explicit KioskIntegration(); + virtual ~KioskIntegration(); + + void init(); + + bool eventFilter(QObject *watched, QEvent *event) override; + +}; diff --git a/src/platformtheme/kioskintegration.cpp b/src/platformtheme/kioskintegration.cpp new file mode 100644 --- /dev/null +++ b/src/platformtheme/kioskintegration.cpp @@ -0,0 +1,78 @@ +/* + * Copyright 2016 Kai Uwe Broulik + * + * 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 of the License or ( at + * your option ) version 3 or, at the discretion of KDE e.V. ( which shall + * act as a proxy as in section 14 of the GPLv3 ), 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 Lesser 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 "kioskintegration.h" + +#include +#include +#include +#include + +#include + +KioskIntegration::KioskIntegration() : QObject() +{ + +} + +KioskIntegration::~KioskIntegration() = default; + +void KioskIntegration::init() +{ + // avoid performance penalty of an event filter if restriction isn't enforced + if (!KAuthorized::authorizeKAction(QStringLiteral("options_show_toolbar"))) { + QCoreApplication::instance()->installEventFilter(this); + } +} + +bool KioskIntegration::eventFilter(QObject *watched, QEvent *event) +{ + Q_UNUSED(watched); + + // Disable toggle action for toolbars when the action/options_show_toolbar + // KIOSK Restriction is enforced. + // + // Qt shows the toggleViewAction of all toolbars in the QMainWindow context menu + // which we have no control of. + // + // What this code does: + // When an action is added, we look if its parent is QToolBar and if so + // we check whether it actually is the toggleViewAction(), if so disable it + // + // TODO KF6: Subclass createPopupMenu() of QMainWindow in KMainWindow and + // return a custom context menu that enforces this policy + + if (event->type() == QEvent::ActionAdded) { + auto *e = static_cast(event); + auto *action = e->action(); + + if (auto *actionParent = action->parent()) { + if (actionParent->inherits("QToolBar")) { + auto *toolbar = static_cast(actionParent); + if (action == toolbar->toggleViewAction()) { + action->setEnabled(false); + } + } + } + } + + return false; +} +