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