SVN commit 768814 by dfaure: # 2_{kdelibs,kdebase}_default_shortcuts.diff by Aurélien "This makes KdedGlobalAccel aware of the concept of default and active shortcuts. "It adds a new method: defaultShortcut(), which is used by the kcm to initialize the KAction correctly. M +14 -6 kdebase/workspace/kcontrol/keys/globalshortcuts.cpp M +20 -1 kdelibs/kdeui/shortcuts/kdedglobalaccel.cpp M +4 -1 kdelibs/kdeui/shortcuts/kdedglobalaccel.h M +3 -0 kdelibs/kdeui/shortcuts/kdedglobalaccel_adaptor.h M +10 -2 kdelibs/kdeui/shortcuts/kglobalaccel.cpp --- branches/KDE/4.0/kdebase/workspace/kcontrol/keys/globalshortcuts.cpp #768813:768814 @@ -86,17 +86,25 @@ foreach(const QString &actionText, actions.value() ) { 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()) { + QStringList actionId; + actionId << component << actionText; + QDBusReply > defaultShortcut = iface->call("defaultShortcut", qVariantFromValue(actionId)); + QDBusReply > shortcut = iface->call("shortcut", qVariantFromValue(actionId)); + if (!defaultShortcut.value().empty()) + { + int key = defaultShortcut.value().first(); + kDebug() << "-- defaultShortcut" << KShortcut(key).toString(); + action->setGlobalShortcut(KShortcut(key), KAction::DefaultShortcut, KAction::NoAutoloading); + } + if (!shortcut.value().empty()) + { int key = shortcut.value().first(); - action->setGlobalShortcut(KShortcut(key)); - action->setGlobalShortcutAllowed(true, KAction::NoAutoloading); + kDebug() << "-- shortcut" << KShortcut(key).toString(); + action->setGlobalShortcut(KShortcut(key), KAction::ActiveShortcut, KAction::NoAutoloading); } } } --- branches/KDE/4.0/kdelibs/kdeui/shortcuts/kdedglobalaccel.cpp #768813:768814 @@ -60,6 +60,7 @@ bool isDefaultEmpty : 1; QStringList actionId; QList keys; + QList defaultKeys; }; enum IdField @@ -246,6 +247,15 @@ } +QList KdedGlobalAccel::defaultShortcut(const QStringList &action) +{ + actionData *ad = d->findAction(action); + if (ad) + return ad->defaultKeys; + return QList(); +} + + //TODO: make sure and document that we don't want trailing zero shortcuts in the list QList KdedGlobalAccel::setShortcut(const QStringList &actionId, const QList &keys, uint flags) @@ -254,6 +264,7 @@ const bool isDefaultEmpty = (flags & IsDefaultEmpty); const bool setPresent = (flags & SetPresent); const bool isAutoloading = !(flags & NoAutoloading); + const bool isDefault = (flags & IsDefault); actionData *ad = d->findAction(actionId); @@ -311,6 +322,8 @@ ad->isDefaultEmpty = isDefaultEmpty; if (setPresent) ad->isPresent = true; + if (isDefault) + ad->defaultKeys = keys; ad->keys = keys; //update keyToAction and find conflicts with other actions @@ -392,7 +405,13 @@ foreach (const adHash *const mc, d->mainComponentHashes) { foreach (const actionData *const ad, *mc) { QString confKey = ad->actionId.join("\01"); - if (!d->isEmpty(ad->keys)) + if (ad->keys == ad->defaultKeys) + { + // If this is a default key, make sure we don't keep an old + // custom key in the config file + d->configGroup.deleteEntry(confKey); + } + else if (!d->isEmpty(ad->keys)) d->configGroup.writeEntry(confKey, stringFromKeys(ad->keys)); else d->configGroup.writeEntry(confKey, "none"); --- branches/KDE/4.0/kdelibs/kdeui/shortcuts/kdedglobalaccel.h #768813:768814 @@ -37,7 +37,8 @@ { IsDefaultEmpty = 1, SetPresent = 2, - NoAutoloading = 4 + NoAutoloading = 4, + IsDefault = 8 }; KdedGlobalAccel(QObject*, const QList&); @@ -52,6 +53,8 @@ QStringList actionId(int key); //to be called by main components not owning the action QList shortcut(const QStringList &actionId); + //to be called by main components not owning the action + QList defaultShortcut(const QStringList &actionId); //to be called by main components owning the action QList setShortcut(const QStringList &actionId, const QList &keys, uint flags); --- branches/KDE/4.0/kdelibs/kdeui/shortcuts/kdedglobalaccel_adaptor.h #768813:768814 @@ -68,6 +68,9 @@ //get the keys registered to action inline QList shortcut(const QStringList &actionId) { return p()->shortcut(actionId); } + //get the default keys registered to action + inline QList defaultShortcut(const QStringList &actionId) + { return p()->defaultShortcut(actionId); } //to be called by main components owning the action inline QList setShortcut(const QStringList &actionId, const QList &keys, uint flags) { return p()->setShortcut(actionId, keys, flags); } --- branches/KDE/4.0/kdelibs/kdeui/shortcuts/kglobalaccel.cpp #768813:768814 @@ -152,10 +152,14 @@ if (!oldEnabled && newEnabled) { uint setterFlags = KdedGlobalAccel::SetPresent; + KShortcut defaultShortcut = action->globalShortcut(KAction::DefaultShortcut); + KShortcut activeShortcut = action->globalShortcut(); if (flags & KAction::NoAutoloading) setterFlags |= KdedGlobalAccel::NoAutoloading; - if (action->globalShortcut(KAction::DefaultShortcut).isEmpty()) + if (defaultShortcut.isEmpty()) setterFlags |= KdedGlobalAccel::IsDefaultEmpty; + if (defaultShortcut == activeShortcut) + setterFlags |= KdedGlobalAccel::IsDefault; nameToAction.insert(actionId.at(1), action); actionToName.insert(action, actionId.at(1)); @@ -187,10 +191,14 @@ //TODO: what about i18ned names? uint setterFlags = 0; + KShortcut defaultShortcut = action->globalShortcut(KAction::DefaultShortcut); + KShortcut activeShortcut = action->globalShortcut(); if (flags & KAction::NoAutoloading) setterFlags |= KdedGlobalAccel::NoAutoloading; - if (action->globalShortcut(KAction::DefaultShortcut).isEmpty()) + if (defaultShortcut.isEmpty()) setterFlags |= KdedGlobalAccel::IsDefaultEmpty; + if (defaultShortcut == activeShortcut) + setterFlags |= KdedGlobalAccel::IsDefault; QList result = iface.setShortcut(actionId, intListFromShortcut(action->globalShortcut()),