mirror of
https://github.com/KDE/konsole.git
synced 2025-12-23 23:38:08 -05:00
Register global shortcut using KGlobalAccel
khotkeys is obsolete.
This commit is contained in:
@@ -116,6 +116,7 @@ option(ENABLE_PLUGIN_SSHMANAGER "Build the SSHManager plugin" ON)
|
||||
add_subdirectory( src )
|
||||
add_subdirectory( data )
|
||||
add_subdirectory( desktop )
|
||||
add_subdirectory( kconf_update )
|
||||
if (KF5DocTools_FOUND)
|
||||
add_subdirectory( doc/manual )
|
||||
endif()
|
||||
|
||||
@@ -11,5 +11,4 @@ if(KF5KIO_VERSION VERSION_GREATER_EQUAL "5.85.0")
|
||||
else()
|
||||
install( FILES konsolerun.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}/ServiceMenus )
|
||||
endif()
|
||||
install( FILES konsole.khotkeys DESTINATION ${KDE_INSTALL_DATADIR}/khotkeys )
|
||||
install( FILES konsole.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFY5RCDIR} )
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
[Main]
|
||||
ImportId=konsole
|
||||
Version=2
|
||||
Autostart=true
|
||||
Disabled=false
|
||||
|
||||
[Data]
|
||||
DataCount=1
|
||||
|
||||
[Data_1]
|
||||
Comment=Global keyboard shortcut to launch Konsole
|
||||
Enabled=true
|
||||
Name=Launch Konsole
|
||||
Type=MENUENTRY_SHORTCUT_ACTION_DATA
|
||||
|
||||
[Data_1Actions]
|
||||
ActionsCount=1
|
||||
|
||||
[Data_1Actions0]
|
||||
CommandURL=org.kde.konsole.desktop
|
||||
Type=MENUENTRY
|
||||
|
||||
[Data_1Conditions]
|
||||
Comment=
|
||||
ConditionsCount=0
|
||||
|
||||
[Data_1Triggers]
|
||||
Comment=Simple_action
|
||||
TriggersCount=1
|
||||
|
||||
[Data_1Triggers0]
|
||||
Key=Ctrl+Alt+T
|
||||
Type=SHORTCUT
|
||||
@@ -10,6 +10,7 @@ X-DocPath=konsole/index.html
|
||||
X-DBUS-StartupType=Unique
|
||||
StartupNotify=true
|
||||
X-KDE-AuthorizeAction=shell_access
|
||||
X-KDE-Shortcuts=Ctrl+Alt+T
|
||||
StartupWMClass=konsole
|
||||
Keywords=terminal;console;script;run;execute;command;command-line;commandline;cli;bash;sh;shell;zsh
|
||||
Keywords[ar]=طرفية;كونسول;سكربت;شغل;نفذ;أوامر;سطر-الأوامر;سطر الأوامر;cli;باش;صدفة;شل;zsh
|
||||
|
||||
12
kconf_update/CMakeLists.txt
Normal file
12
kconf_update/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
add_executable(konsole_globalaccel
|
||||
konsole_globalaccel.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(konsole_globalaccel PRIVATE
|
||||
KF5::ConfigCore
|
||||
KF5::GlobalAccel
|
||||
KF5::Service
|
||||
)
|
||||
|
||||
install(TARGETS konsole_globalaccel DESTINATION ${KDE_INSTALL_LIBDIR}/kconf_update_bin)
|
||||
install(FILES konsole_globalaccel.upd DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR})
|
||||
76
kconf_update/konsole_globalaccel.cpp
Normal file
76
kconf_update/konsole_globalaccel.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <QAction>
|
||||
#include <QCoreApplication>
|
||||
#include <QKeySequence>
|
||||
|
||||
#include <KConfig>
|
||||
#include <KConfigGroup>
|
||||
#include <KGlobalAccel>
|
||||
#include <KService>
|
||||
|
||||
static void migrateShortcut(const QString &desktopFile, const QList<QKeySequence> &shortcuts)
|
||||
{
|
||||
const KService::Ptr service = KService::serviceByStorageId(desktopFile);
|
||||
QAction action(service->name());
|
||||
action.setProperty("componentName", desktopFile);
|
||||
action.setProperty("componentDisplayName", service->name());
|
||||
action.setObjectName(QStringLiteral("_launch"));
|
||||
// Tell kglobalaccel that the action is active.
|
||||
KGlobalAccel::self()->setShortcut(&action, shortcuts);
|
||||
action.setProperty("isConfigurationAction", true);
|
||||
KGlobalAccel::self()->setShortcut(&action, shortcuts, KGlobalAccel::NoAutoloading);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
KConfig khotkeysrc(QStringLiteral("khotkeysrc"), KConfig::SimpleConfig);
|
||||
const int dataCount = KConfigGroup(&khotkeysrc, "Data").readEntry("DataCount", 0);
|
||||
bool foundKmenuedit = false;
|
||||
int kmenueditIndex;
|
||||
KConfigGroup kmenueditGroup;
|
||||
for (int i = 1; i <= dataCount; ++i) {
|
||||
kmenueditGroup = KConfigGroup(&khotkeysrc, QStringLiteral("Data_%1").arg(i));
|
||||
if (kmenueditGroup.readEntry("Name") == QLatin1String("KMenuEdit")) {
|
||||
foundKmenuedit = true;
|
||||
kmenueditIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundKmenuedit) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const int shortcutCount = kmenueditGroup.readEntry("DataCount", 0);
|
||||
for (int i = 1; i <= shortcutCount; ++i) {
|
||||
const QString groupName = QStringLiteral("Data_%1_%2").arg(kmenueditIndex).arg(i);
|
||||
if (KConfigGroup(&khotkeysrc, groupName).readEntry("Type") == QLatin1String("MENUENTRY_SHORTCUT_ACTION_DATA")) {
|
||||
const QString desktopFile = KConfigGroup(&khotkeysrc, groupName + QStringLiteral("Actions0")).readEntry("CommandURL");
|
||||
if (desktopFile == QLatin1String("org.kde.konsole.desktop")) {
|
||||
const QString shortcutId = KConfigGroup(&khotkeysrc, groupName + QStringLiteral("Triggers0")).readEntry("Uuid");
|
||||
const QList<QKeySequence> shortcuts = KGlobalAccel::self()->globalShortcut(QStringLiteral("khotkeys"), shortcutId);
|
||||
|
||||
// Unset old shortcut. setShortcut() is needed to make the action active.
|
||||
QAction action;
|
||||
action.setObjectName(shortcutId);
|
||||
action.setProperty("componentName", QStringLiteral("khotkeys"));
|
||||
KGlobalAccel::self()->setShortcut(&action, {});
|
||||
KGlobalAccel::self()->removeAllShortcuts(&action);
|
||||
|
||||
// Migrate to kglobalaccel.
|
||||
migrateShortcut(desktopFile, shortcuts);
|
||||
|
||||
// khotkeys will automagically update the DataCount key.
|
||||
khotkeysrc.deleteGroup(groupName);
|
||||
khotkeysrc.deleteGroup(groupName + QStringLiteral("Actions"));
|
||||
khotkeysrc.deleteGroup(groupName + QStringLiteral("Actions0"));
|
||||
khotkeysrc.deleteGroup(groupName + QStringLiteral("Conditions"));
|
||||
khotkeysrc.deleteGroup(groupName + QStringLiteral("Triggers"));
|
||||
khotkeysrc.deleteGroup(groupName + QStringLiteral("Triggers0"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
khotkeysrc.sync();
|
||||
return 0;
|
||||
}
|
||||
4
kconf_update/konsole_globalaccel.upd
Normal file
4
kconf_update/konsole_globalaccel.upd
Normal file
@@ -0,0 +1,4 @@
|
||||
Version=5
|
||||
Id=konsole_globalaccel
|
||||
File=khotkeysrc
|
||||
Script=konsole_globalaccel
|
||||
Reference in New Issue
Block a user