[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kdeui/shortcuts
From:       Michael Jansen <kde () michael-jansen ! biz>
Date:       2010-03-28 21:33:09
Message-ID: 20100328213309.7BC5CAC883 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1108432 by mjansen:

Change the signal about triggered global Shortcuts from a broadcast one to a
component specific location.

Prevents all application handling global shortcuts from waking up whenever a
global shortcut is pressed. Even if it belongs to another app.

 M  +42 -17    kglobalaccel.cpp  
 M  +5 -1      kglobalaccel.h  
 M  +12 -1     kglobalaccel_p.h  
 M  +0 -4      org.kde.KGlobalAccel.xml  
 M  +5 -0      org.kde.kglobalaccel.Component.xml  


--- trunk/KDE/kdelibs/kdeui/shortcuts/kglobalaccel.cpp #1108431:1108432
@@ -40,11 +40,14 @@
 #include "kaction_p.h"
 #include "kmessagebox.h"
 #include "kshortcut.h"
-#include "kglobalaccel_component_interface.h"
-#include "kglobalaccel_interface.h"
 
-static org::kde::kglobalaccel::Component *getComponent(const QString \
                &componentUnique)
-    {
+org::kde::kglobalaccel::Component *KGlobalAccelPrivate::getComponent(const QString \
&componentUnique, bool remember = false) +{
+    // Check if we already have this component
+    if (components.contains(componentUnique)) {
+        return components[componentUnique];
+    }
+
     // Connect to the kglobalaccel daemon
     org::kde::KGlobalAccel kglobalaccel(
             "org.kde.kglobalaccel",
@@ -74,7 +77,8 @@
     org::kde::kglobalaccel::Component *component = new \
org::kde::kglobalaccel::Component(  "org.kde.kglobalaccel",
         reply.value().path(),
-        QDBusConnection::sessionBus());
+        QDBusConnection::sessionBus(),
+        q);
 
     // No component no cleaning
     if (!component->isValid()) {
@@ -82,6 +86,15 @@
         return NULL;
     }
 
+    if (remember)
+        {
+        // Connect to the signals we are interested in.
+        q->connect(component, SIGNAL(globalShortcutPressed(const QString &, const \
QString &, qlonglong)), +                SLOT(_k_invokeAction(const QString &, const \
QString &, qlonglong))); +
+        components[componentUnique] = component;
+        }
+
     return component;
 }
 
@@ -90,7 +103,8 @@
 KGlobalAccelPrivate::KGlobalAccelPrivate(KGlobalAccel *q)
      :  isUsingForeignComponentName(false),
         enabled(true),
-        iface("org.kde.kglobalaccel", "/kglobalaccel", \
QDBusConnection::sessionBus()) +        iface("org.kde.kglobalaccel", \
"/kglobalaccel", QDBusConnection::sessionBus()), +        q(q)
 {
     // Make sure kded is running. The iface declaration above somehow
     // works anyway.
@@ -134,8 +148,6 @@
     qDBusRegisterMetaType<KGlobalShortcutInfo>();
     qDBusRegisterMetaType<QList<KGlobalShortcutInfo> >();
 
-    connect(&d->iface, SIGNAL(invokeAction(const QStringList &, qlonglong)),
-            SLOT(_k_invokeAction(const QStringList &, qlonglong)));
     connect(&d->iface, SIGNAL(yourShortcutGotChanged(const QStringList &, const \
                QList<int> &)),
             SLOT(_k_shortcutGotChanged(const QStringList &, const QList<int> &)));
 
@@ -166,8 +178,8 @@
 // static
 bool KGlobalAccel::cleanComponent(const QString &componentUnique)
 {
-    std::auto_ptr<org::kde::kglobalaccel::Component> \
                component(getComponent(componentUnique));
-    if (!component.get()) return false;
+    org::kde::kglobalaccel::Component* component = \
self()->getComponent(componentUnique); +    if (!component) return false;
 
     return component->cleanUp();
 }
@@ -176,8 +188,8 @@
 // static
 bool KGlobalAccel::isComponentActive(const QString &componentUnique)
 {
-    std::auto_ptr<org::kde::kglobalaccel::Component> \
                component(getComponent(componentUnique));
-    if (!component.get()) return false;
+    org::kde::kglobalaccel::Component* component = \
self()->getComponent(componentUnique); +    if (!component) return false;
 
     return component->isActive();
 }
@@ -189,6 +201,12 @@
 }
 
 
+org::kde::kglobalaccel::Component *KGlobalAccel::getComponent(const QString \
&componentUnique) +{
+    return d->getComponent(componentUnique);
+}
+
+
 void KGlobalAccel::setEnabled(bool enabled)
 {
     d->enabled = enabled;
@@ -297,6 +315,10 @@
                 actionId,
                 intListFromShortcut(activeShortcut),
                 activeSetterFlags);
+
+        // Make sure we get informed about changes in the component by kglobalaccel
+        getComponent(componentUniqueForAction(action), true);
+
         // Create a shortcut from the result
         const KShortcut scResult(shortcutFromIntList(result));
 
@@ -375,7 +397,10 @@
 }
 
 
-void KGlobalAccelPrivate::_k_invokeAction(const QStringList &actionId, qlonglong \
timestamp) +void KGlobalAccelPrivate::_k_invokeAction(
+        const QString &componentUnique,
+        const QString &actionUnique,
+        qlonglong timestamp)
 {
     // If overrideMainComponentData() is active the app can only have
     // configuration actions.
@@ -384,9 +409,9 @@
     }
 
     KAction *action = 0;
-    QList<KAction *> candidates = \
nameToAction.values(actionId.at(KGlobalAccel::ActionUnique)); +    QList<KAction *> \
candidates = nameToAction.values(actionUnique);  foreach (KAction *const a, \
                candidates) {
-        if (componentUniqueForAction(a) == \
actionId.at(KGlobalAccel::ComponentUnique)) { +        if \
(componentUniqueForAction(a) == componentUnique) {  action = a;
         }
     }
@@ -395,8 +420,7 @@
     // - there is no action
     // - the action is not enabled
     // - the action is an configuration action
-    if (!action || !action->isEnabled()
-            || action->property("isConfigurationAction").toBool()) {
+    if (!action || !action->isEnabled() || \
action->property("isConfigurationAction").toBool()) {  return;
     }
 
@@ -416,6 +440,7 @@
     action->trigger();
 }
 
+
 void KGlobalAccelPrivate::_k_shortcutGotChanged(const QStringList &actionId,
                                                 const QList<int> &keys)
 {
--- trunk/KDE/kdelibs/kdeui/shortcuts/kglobalaccel.h #1108431:1108432
@@ -31,6 +31,7 @@
 class QWidget;
 class KShortcut;
 class KComponentData;
+class OrgKdeKglobalaccelComponentInterface;
 
 /**
  * @short Configurable global shortcut support
@@ -231,9 +232,12 @@
     /// Destructor
     ~KGlobalAccel();
 
+    //! get component @p componentUnique
+    OrgKdeKglobalaccelComponentInterface* getComponent(const QString \
&componentUnique); +
     class KGlobalAccelPrivate *const d;
 
-    Q_PRIVATE_SLOT(d, void _k_invokeAction(const QStringList&,qlonglong))
+    Q_PRIVATE_SLOT(d, void _k_invokeAction(const QString &, const QString &, \
                qlonglong))
     Q_PRIVATE_SLOT(d, void _k_shortcutGotChanged(const QStringList&, const \
                QList<int>&))
     Q_PRIVATE_SLOT(d, void _k_serviceOwnerChanged(const QString&, const QString&, \
const QString&))  };
--- trunk/KDE/kdelibs/kdeui/shortcuts/kglobalaccel_p.h #1108431:1108432
@@ -27,6 +27,7 @@
 
 #include "kcomponentdata.h"
 #include "kglobalaccel_interface.h"
+#include "kglobalaccel_component_interface.h"
 
 class KAction;
 class KShortcut;
@@ -66,7 +67,7 @@
     void readComponentData(const KComponentData &component);
 
     //private slot implementations
-    void _k_invokeAction(const QStringList&,qlonglong);
+    void _k_invokeAction(const QString &, const QString &,qlonglong);
     void _k_shortcutGotChanged(const QStringList&, const QList<int>&);
     void _k_serviceOwnerChanged(const QString& name, const QString& oldOwner, const \
QString& newOwner);  void reRegisterAll();
@@ -81,6 +82,16 @@
     bool enabled;
 
     org::kde::KGlobalAccel iface;
+
+    //! Get the component @p componentUnique. If @p remember is true the instance is \
cached and we +    //! subscribe to signals about changes to the component.
+    org::kde::kglobalaccel::Component *getComponent(const QString &componentUnique, \
bool remember); +
+    //! Our owner
+    KGlobalAccel *q;
+
+    //! The components the application is using
+    QHash<QString, org::kde::kglobalaccel::Component *> components;
 };
 
 #endif
--- trunk/KDE/kdelibs/kdeui/shortcuts/org.kde.KGlobalAccel.xml #1108431:1108432
@@ -2,10 +2,6 @@
 "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
 <node>
   <interface name="org.kde.KGlobalAccel">
-    <signal name="invokeAction">
-      <arg name="actionId" type="as" direction="out"/>
-      <arg name="timestamp" type="x" direction="out"/>
-    </signal>
     <signal name="yourShortcutGotChanged">
       <arg name="actionId" type="as" direction="out"/>
       <arg name="newKeys" type="ai" direction="out"/>
--- trunk/KDE/kdelibs/kdeui/shortcuts/org.kde.kglobalaccel.Component.xml \
#1108431:1108432 @@ -4,6 +4,11 @@
   <interface name="org.kde.kglobalaccel.Component">
     <property name="friendlyName" type="s" access="read"/>
     <property name="uniqueName" type="s" access="read"/>
+    <signal name="globalShortcutPressed">
+      <arg name="componentUnique" type="s" direction="out"/>
+      <arg name="actionUnique" type="s" direction="out"/>
+      <arg name="timestamp" type="x" direction="out"/>
+    </signal>
     <method name="cleanUp">
       <arg type="b" direction="out"/>
     </method>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic