@ -14,6 +14,7 @@
# include <KActionCollection>
# include <KActionCollection>
# include <KAuthorized>
# include <KAuthorized>
# include <KGlobalAccel>
# include <KGlobalAccel>
# include <KIO/CommandLauncherJob>
# include <KLocalizedString>
# include <KLocalizedString>
# include <QDebug>
# include <QDebug>
# include <QIcon>
# include <QIcon>
@ -30,6 +31,7 @@ ContextMenu::ContextMenu(QObject *parent, const QVariantList &args)
, m_runCommandAction ( nullptr )
, m_runCommandAction ( nullptr )
, m_lockScreenAction ( nullptr )
, m_lockScreenAction ( nullptr )
, m_logoutAction ( nullptr )
, m_logoutAction ( nullptr )
, m_configureDisplaysAction ( nullptr )
, m_separator1 ( nullptr )
, m_separator1 ( nullptr )
, m_separator2 ( nullptr )
, m_separator2 ( nullptr )
, m_separator3 ( nullptr )
, m_separator3 ( nullptr )
@ -52,6 +54,8 @@ void ContextMenu::restore(const KConfigGroup &config)
QHash < QString , bool > actions ;
QHash < QString , bool > actions ;
QSet < QString > disabled ;
QSet < QString > disabled ;
// clang-format off
// because it really wants to mangle this nice aligned list
if ( c - > containmentType ( ) = = Plasma : : Types : : PanelContainment | | c - > containmentType ( ) = = Plasma : : Types : : CustomPanelContainment ) {
if ( c - > containmentType ( ) = = Plasma : : Types : : PanelContainment | | c - > containmentType ( ) = = Plasma : : Types : : CustomPanelContainment ) {
m_actionOrder < < QStringLiteral ( " add widgets " )
m_actionOrder < < QStringLiteral ( " add widgets " )
< < QStringLiteral ( " _add panel " )
< < QStringLiteral ( " _add panel " )
@ -61,6 +65,7 @@ void ContextMenu::restore(const KConfigGroup &config)
} else {
} else {
actions . insert ( QStringLiteral ( " configure shortcuts " ) , false ) ;
actions . insert ( QStringLiteral ( " configure shortcuts " ) , false ) ;
m_actionOrder < < QStringLiteral ( " configure " )
m_actionOrder < < QStringLiteral ( " configure " )
< < QStringLiteral ( " _display_settings " )
< < QStringLiteral ( " run associated application " )
< < QStringLiteral ( " run associated application " )
< < QStringLiteral ( " configure shortcuts " )
< < QStringLiteral ( " configure shortcuts " )
< < QStringLiteral ( " _sep1 " )
< < QStringLiteral ( " _sep1 " )
@ -79,6 +84,7 @@ void ContextMenu::restore(const KConfigGroup &config)
disabled . insert ( QStringLiteral ( " configure shortcuts " ) ) ;
disabled . insert ( QStringLiteral ( " configure shortcuts " ) ) ;
disabled . insert ( QStringLiteral ( " _run_command " ) ) ;
disabled . insert ( QStringLiteral ( " _run_command " ) ) ;
}
}
// clang-format on
for ( const QString & name : qAsConst ( m_actionOrder ) ) {
for ( const QString & name : qAsConst ( m_actionOrder ) ) {
actions . insert ( name , ! disabled . contains ( name ) ) ;
actions . insert ( name , ! disabled . contains ( name ) ) ;
@ -115,6 +121,10 @@ void ContextMenu::restore(const KConfigGroup &config)
} ) ;
} ) ;
connect ( m_logoutAction , & QAction : : triggered , this , & ContextMenu : : startLogout ) ;
connect ( m_logoutAction , & QAction : : triggered , this , & ContextMenu : : startLogout ) ;
m_configureDisplaysAction = new QAction ( i18nc ( " plasma_containmentactions_contextmenu " , " Configure Display Settings… " ) , this ) ;
m_configureDisplaysAction - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " preferences-desktop-display " ) ) ) ;
connect ( m_configureDisplaysAction , & QAction : : triggered , this , & ContextMenu : : configureDisplays ) ;
m_separator1 = new QAction ( this ) ;
m_separator1 = new QAction ( this ) ;
m_separator1 - > setSeparator ( true ) ;
m_separator1 - > setSeparator ( true ) ;
m_separator2 = new QAction ( this ) ;
m_separator2 = new QAction ( this ) ;
@ -183,6 +193,10 @@ QAction *ContextMenu::action(const QString &name)
if ( KAuthorized : : authorize ( QStringLiteral ( " logout " ) ) ) {
if ( KAuthorized : : authorize ( QStringLiteral ( " logout " ) ) ) {
return m_logoutAction ;
return m_logoutAction ;
}
}
} else if ( name = = QLatin1String ( " _display_settings " ) ) {
if ( KAuthorized : : authorizeControlModule ( QStringLiteral ( " kcm_kscreen.desktop " ) ) & & KService : : serviceByStorageId ( QStringLiteral ( " kcm_kscreen " ) ) ) {
return m_configureDisplaysAction ;
}
} else if ( name = = QLatin1String ( " edit mode " ) ) {
} else if ( name = = QLatin1String ( " edit mode " ) ) {
if ( c - > corona ( ) ) {
if ( c - > corona ( ) ) {
return c - > corona ( ) - > actions ( ) - > action ( QStringLiteral ( " edit mode " ) ) ;
return c - > corona ( ) - > actions ( ) - > action ( QStringLiteral ( " edit mode " ) ) ;
@ -226,6 +240,27 @@ void ContextMenu::startLogout()
}
}
}
}
// FIXME: this function contains some code copied from KCMShell::openSystemSettings()
// which is not publicly available to C++ code right now. Eventually we should
// move that code into KIO so it's accessible to everyone, and then call that
// function instead of this one
void ContextMenu : : configureDisplays ( )
{
const QString systemSettings = QStringLiteral ( " systemsettings " ) ;
const QString kscreenKCM = QStringLiteral ( " kcm_kscreen " ) ;
KIO : : CommandLauncherJob * job = nullptr ;
// Open in System Settings if it's available
if ( KService : : serviceByDesktopName ( systemSettings ) ) {
job = new KIO : : CommandLauncherJob ( QStringLiteral ( " systemsettings5 " ) , { kscreenKCM } ) ;
job - > setDesktopName ( systemSettings ) ;
} else {
job = new KIO : : CommandLauncherJob ( QStringLiteral ( " kcmshell5 " ) , { kscreenKCM } ) ;
}
job - > start ( ) ;
}
QWidget * ContextMenu : : createConfigurationInterface ( QWidget * parent )
QWidget * ContextMenu : : createConfigurationInterface ( QWidget * parent )
{
{
QWidget * widget = new QWidget ( parent ) ;
QWidget * widget = new QWidget ( parent ) ;