SVN commit 768811 by dfaure: Patch from Aurélien which brings the empty actions (like KWin actions) back. He wrote: "I had to rework the way the kcm initializes itself. "The new implementation asks KdedGlobalAccel for the list of components, then for "the list of actions for each component. To do so it adds two methods to "KdedGlobalAccel: allComponents() and allActionsForComponent(). I also had "to remove all the "remove empty shortcuts" code from KdedGlobalAccel. M +28 -33 kdebase/workspace/kcontrol/keys/globalshortcuts.cpp M +11 -21 kdelibs/kdeui/shortcuts/kdedglobalaccel.cpp M +3 -0 kdelibs/kdeui/shortcuts/kdedglobalaccel.h M +4 -0 kdelibs/kdeui/shortcuts/kdedglobalaccel_adaptor.h --- branches/KDE/4.0/kdebase/workspace/kcontrol/keys/globalshortcuts.cpp #768810:768811 @@ -38,22 +38,22 @@ K_EXPORT_PLUGIN(GlobalShortcutsModuleFactory("kcmkeys")) Q_DECLARE_METATYPE( QList ) - + GlobalShortcutsModule::GlobalShortcutsModule( QWidget * parent, const QVariantList & args ) - : KCModule(GlobalShortcutsModuleFactory::componentData(), parent, args), ui(0), + : KCModule(GlobalShortcutsModuleFactory::componentData(), parent, args), ui(0), editor(0), saved(false) { ui = new Ui::GlobalShortcuts(); ui->setupUi(this); layout()->setMargin(0); - + KCModule::setButtons( KCModule::Buttons(KCModule::Default) ); - + editor = new KShortcutsEditor(this, KShortcutsEditor::GlobalAction); layout()->addWidget(editor); - + connect(editor, SIGNAL(keyChange()), this, SLOT(changed())); - connect(ui->components, SIGNAL(activated(const QString&)), + connect(ui->components, SIGNAL(activated(const QString&)), this, SLOT(componentChanged(const QString&))); load(); } @@ -72,36 +72,31 @@ qDBusRegisterMetaType >(); QDBusConnection bus = QDBusConnection::sessionBus(); QDBusInterface* iface = new QDBusInterface( "org.kde.kded", "/KdedGlobalAccel", "org.kde.KdedGlobalAccel", bus, this ); - - QDBusReply > l = iface->call("allKeys"); - QHash shortcuts; - foreach( int i, l.value() ) - { - QDBusReply actionid = iface->call("action", qVariantFromValue(i)); - QStringList actionlist = actionid.value(); - if( !actionCollections.contains( actionlist.first() ) ) - { - actionCollections[actionlist.first()] = new KActionCollection(this); - } - QDBusReply > shortcut = iface->call("shortcut", qVariantFromValue(actionid.value())); - KAction *action = new KAction(actionlist.at(1), this); - action->setProperty("isConfigurationAction", QVariant(true)); - KActionCollection* col = actionCollections[actionlist.first()]; - QString actionname = QString("%1_%2").arg(actionlist.first()).arg(col->count()); - shortcuts[actionname] = shortcut.value().first(); - col->addAction(actionname, action); - } + + QDBusReply components = iface->call("allComponents"); KComponentData curcomp = KGlobal::mainComponent(); - foreach(QString title, actionCollections.keys()) + foreach(const QString &component, components.value() ) { - KGlobalAccel::self()->overrideMainComponentData(KComponentData(title.toAscii())); - KActionCollection* ac = actionCollections[title]; - foreach( QString s, shortcuts.keys() ) + kDebug() << "component:" << component; + KGlobalAccel::self()->overrideMainComponentData(KComponentData(component.toAscii())); + KActionCollection* col = new KActionCollection(this); + actionCollections[component] = col; + + QDBusReply actions = iface->call("allActionsForComponent", qVariantFromValue(component) ); + foreach(const QString &actionText, actions.value() ) { - if( s.startsWith(title) ) - { - qobject_cast(ac->action(s))->setGlobalShortcut(KShortcut(shortcuts[s])); - qobject_cast(ac->action(s))->setGlobalShortcutAllowed(true,KAction::NoAutoloading); + kDebug() << "- action:" << actionText; + QStringList actionId; + actionId << component << actionText; + QDBusReply > shortcut = iface->call("shortcut", qVariantFromValue(actionId)); + QString actionName = QString("%1_%2").arg(component).arg(col->count()); + KAction *action = col->addAction(actionName); + action->setProperty("isConfigurationAction", QVariant(true)); + action->setText(actionText); + if (!shortcut.value().empty()) { + int key = shortcut.value().first(); + action->setGlobalShortcut(KShortcut(key)); + action->setGlobalShortcutAllowed(true, KAction::NoAutoloading); } } } --- branches/KDE/4.0/kdelibs/kdeui/shortcuts/kdedglobalaccel.cpp #768810:768811 @@ -88,7 +88,6 @@ QHash keyToAction; QHash *> mainComponentHashes; - QList deletionQueue; KConfig config; KConfigGroup configGroup; @@ -204,6 +203,16 @@ delete d; } +QStringList KdedGlobalAccel::allComponents() +{ + return d->mainComponentHashes.keys(); +} + +QStringList KdedGlobalAccel::allActionsForComponent(const QString& component) +{ + return d->mainComponentHashes[component]->keys(); +} + QList KdedGlobalAccel::allKeys() { QList ret = d->keyToAction.keys(); @@ -266,10 +275,9 @@ //now we are actually changing the shortcut of the action QList added = d->nonemptyOnly(keys); - bool emptyShortcut = added.isEmpty(); bool didCreate = false; - if (!ad && (!emptyShortcut || !isDefaultEmpty)) { + if (!ad) { didCreate = true; ad = d->addAction(actionId); ad->isPresent = false; @@ -334,16 +342,6 @@ scheduleWriteSettings(); - if (isDefaultEmpty && d->isEmpty(ad->keys)) { - d->takeAction(actionId); - if (didCreate) - delete ad; - else - d->deletionQueue.append(ad); - - return QList(); - } - return ad->keys; } @@ -390,14 +388,6 @@ //slot void KdedGlobalAccel::writeSettings() { - //entries scheduled for deletion are in deletionQueue - foreach (const actionData *const ad, d->deletionQueue) { - QString confKey = ad->actionId.join("\01"); - d->configGroup.deleteEntry(confKey); - delete ad; - } - d->deletionQueue.clear(); - typedef QHash adHash; //avoid comma in macro arguments foreach (const adHash *const mc, d->mainComponentHashes) { foreach (const actionData *const ad, *mc) { --- branches/KDE/4.0/kdelibs/kdeui/shortcuts/kdedglobalaccel.h #768810:768811 @@ -43,6 +43,9 @@ KdedGlobalAccel(QObject*, const QList&); ~KdedGlobalAccel(); + QStringList allComponents(); + QStringList allActionsForComponent(const QString& component); + QList allKeys(); QStringList allKeysAsString(); --- branches/KDE/4.0/kdelibs/kdeui/shortcuts/kdedglobalaccel_adaptor.h #768810:768811 @@ -52,6 +52,10 @@ inline KdedGlobalAccel *p() { return static_cast(parent()); } public Q_SLOTS: + inline QStringList allComponents() + { return p()->allComponents(); } + inline QStringList allActionsForComponent(const QString &component) + { return p()->allActionsForComponent(component); } //get all registered keys (mainly for debugging) inline QList allKeys() { return p()->allKeys(); }