diff --git a/containmentactions/contextmenu/menu.cpp b/containmentactions/contextmenu/menu.cpp index 7dbd236f1..6bad29751 100644 --- a/containmentactions/contextmenu/menu.cpp +++ b/containmentactions/contextmenu/menu.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -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"))) { diff --git a/containmentactions/contextmenu/menu.h b/containmentactions/contextmenu/menu.h index 348180163..c22f3800b 100644 --- a/containmentactions/contextmenu/menu.h +++ b/containmentactions/contextmenu/menu.h @@ -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;