containmentactions/contextmenu: Add "Open Terminal" action

This adds the ability to open the terminal from the main Plasma Shell
context menu. It was originally written as a Red Hat/Fedora patch
for KDE Workspace 4 to open Konsole from the desktop context menu
when Fedora switched to KDE 4, and ported forward to KDE Plasma 5
when Fedora Linux switched to Plasma 5 in Fedora 22.

It has been maintained as a downstream patch since then.

This version of the patch genericizes the patch by not implying that
Konsole is the user's terminal (it actually opens the user's chosen
terminal anyway), can be restricted via the desktop kiosk mode
settings, and is disabled by default.

The major maintainers of this patch are being honored as co-authors
for this patch. They have all helped keep this functionality working
across two KDE major versions for a decade.

Co-authored-by: Daniel Vrátil <dvratil@redhat.com>
Co-authored-by: Jan Grulich <jgrulich@redhat.com>
Co-authored-by: Marc Deop <marcdeop@fedoraproject.org>
Co-authored-by: Rex Dieter <rdieter@fedoraproject.org>

BUG: 451217
wilder-5.26
Neal Gompa 4 years ago
parent d8be398bd1
commit a91ff4e4b6
  1. 21
      containmentactions/contextmenu/menu.cpp
  2. 2
      containmentactions/contextmenu/menu.h

@ -18,6 +18,7 @@
#include <KIO/CommandLauncherJob>
#include <KLocalizedString>
#include <KService>
#include <KTerminalLauncherJob>
#include <QDebug>
#include <QIcon>
@ -62,6 +63,7 @@ void ContextMenu::restore(const KConfigGroup &config)
<< QStringLiteral("configure shortcuts")
<< QStringLiteral("_sep1")
<< QStringLiteral("_context")
<< QStringLiteral("_open_terminal")
<< QStringLiteral("_run_command")
<< QStringLiteral("add widgets")
<< QStringLiteral("_add panel")
@ -74,6 +76,7 @@ void ContextMenu::restore(const KConfigGroup &config)
<< QStringLiteral("_sep3")
<< QStringLiteral("_wallpaper");
disabled.insert(QStringLiteral("configure shortcuts"));
disabled.insert(QStringLiteral("_open_terminal"));
disabled.insert(QStringLiteral("_run_command"));
disabled.insert(QStringLiteral("run associated application"));
disabled.insert(QStringLiteral("_lock_screen"));
@ -98,6 +101,10 @@ void ContextMenu::restore(const KConfigGroup &config)
m_runCommandAction->setShortcut(KGlobalAccel::self()->globalShortcut(QStringLiteral("krunner.desktop"), QStringLiteral("_launch")).value(0));
connect(m_runCommandAction, &QAction::triggered, this, &ContextMenu::runCommand);
m_openTerminalAction = new QAction(i18n("Open Terminal"), this);
m_openTerminalAction->setIcon(QIcon::fromTheme("utilities-terminal"));
connect(m_openTerminalAction, &QAction::triggered, this, &ContextMenu::openTerminal);
m_lockScreenAction = new QAction(i18nc("plasma_containmentactions_contextmenu", "Lock Screen"), this);
m_lockScreenAction->setIcon(QIcon::fromTheme(QStringLiteral("system-lock-screen")));
m_lockScreenAction->setShortcut(KGlobalAccel::self()->globalShortcut(QStringLiteral("ksmserver"), QStringLiteral("Lock Session")).value(0));
@ -180,6 +187,10 @@ QAction *ContextMenu::action(const QString &name)
if (KAuthorized::authorizeAction(QStringLiteral("run_command")) && KAuthorized::authorize(QStringLiteral("run_command"))) {
return m_runCommandAction;
}
} else if (name == QLatin1String("_open_terminal")) {
if (KAuthorized::authorizeAction(QStringLiteral("shell_access"))) {
return m_openTerminalAction;
}
} else if (name == QLatin1String("_lock_screen")) {
if (KAuthorized::authorizeAction(QStringLiteral("lock_screen"))) {
return m_lockScreenAction;
@ -213,6 +224,16 @@ QAction *ContextMenu::action(const QString &name)
return nullptr;
}
void ContextMenu::openTerminal()
{
if (!KAuthorized::authorizeAction(QStringLiteral("shell_access"))) {
return;
}
auto job = new KTerminalLauncherJob(QString());
job->setWorkingDirectory(QDir::homePath());
job->start();
}
void ContextMenu::runCommand()
{
if (!KAuthorized::authorizeAction(QStringLiteral("run_command"))) {

@ -29,11 +29,13 @@ public:
void save(KConfigGroup &config) override;
public Q_SLOTS:
void openTerminal();
void runCommand();
void startLogout();
void configureDisplays();
private:
QAction *m_openTerminalAction = nullptr;
QAction *m_runCommandAction = nullptr;
QAction *m_lockScreenAction = nullptr;
QAction *m_logoutAction = nullptr;

Loading…
Cancel
Save