The goal of this patch is to do less D-BUS calls as possible.
-- 
Michaël Larouche (Shock The Dark Mage)
KDE developer working on Kopete, Kamefu...on dial-up :P
--------------------------------------
Blog: http://mlarouche.blogspot.com/
MSN/Email: [EMAIL PROTECTED]
IRC: irc.freenode.org/DarkShock on #kopete,#solid,#kamefu,#plasma
Jabber: [EMAIL PROTECTED]
Index: backends/hal/haldevice.cpp
===================================================================
--- backends/hal/haldevice.cpp	(revision 517073)
+++ backends/hal/haldevice.cpp	(working copy)
@@ -36,6 +36,7 @@
     QDBusConnection connection;
     QString udi;
     QMap<Capability::Type,Capability*> ifaces;
+    QMap<QString, QVariant> properties;
 
     QDBusMessage callHalMethod( const QString &methodName,
                                 const QList<QVariant> &parameters = QList<QVariant>() ) const;
@@ -55,6 +56,8 @@
                            udi, "org.freedesktop.Hal.Device",
                            "Condition",
                            this, SLOT( slotCondition( const QString&, const QString& ) ) );
+
+    d->properties = allProperties();
 }
 
 HalDevice::~HalDevice()
@@ -103,51 +106,67 @@
 
 QVariant HalDevice::property( const QString &key ) const
 {
-    QList<QVariant> params;
-    params << key;
-    QDBusMessage reply = d->callHalMethod( "GetProperty", params );
+    if ( !d->properties.contains(key) )
+    {
+        QList<QVariant> params;
+        params << key;
+        QDBusMessage reply = d->callHalMethod( "GetProperty", params );
 
-    if ( reply.type() != QDBusMessage::ReplyMessage )
-    {
-        return QVariant();
+        if ( reply.type() != QDBusMessage::ReplyMessage )
+        {
+            d->properties[key] = QVariant();
+            return QVariant();
+        }
+
+        if ( reply.size() != 1 )
+        {
+            kDebug() << "Looks like the HAL protocol changed" << endl;
+            return false;
+        }
+
+        d->properties[key] = reply[0];
+        return reply[0];
     }
-
-    if ( reply.size() != 1 )
+    else
     {
-        kDebug() << "Looks like the HAL protocol changed" << endl;
-        return false;
+        return d->properties[key];
     }
-
-    return reply[0];
 }
 
 QMap<QString, QVariant> HalDevice::allProperties() const
 {
-    QDBusMessage reply = d->callHalMethod( "GetAllProperties" );
-
-    if ( reply.size() != 1 || !reply[0].canConvert( QVariant::Map ))
+    if( d->properties.isEmpty() )
     {
-        kDebug() << "Looks like the HAL protocol changed" << endl;
-        return QMap<QString, QVariant>();
-    }
+        QDBusMessage reply = d->callHalMethod( "GetAllProperties" );
 
-    // Post process to avoid QDBusVariant
-    QMap<QString, QVariant> properties = reply[0].toMap();
+        if ( reply.size() != 1 || !reply[0].canConvert( QVariant::Map ))
+        {
+            kDebug() << "Looks like the HAL protocol changed" << endl;
+            return QMap<QString, QVariant>();
+        }
 
-    QMap<QString, QVariant>::ConstIterator it = properties.begin();
-    QMap<QString, QVariant>::ConstIterator end = properties.end();
+        // Post process to avoid QDBusVariant
+        QMap<QString, QVariant> properties = reply[0].toMap();
 
-    for ( ; it!=end; ++it )
-    {
-        QDBusVariant casted = qvariant_cast<QDBusVariant>( it.value() );
+        QMap<QString, QVariant>::ConstIterator it = properties.begin();
+        QMap<QString, QVariant>::ConstIterator end = properties.end();
 
-        if ( casted.value.type()!=QVariant::UserType )
+        for ( ; it!=end; ++it )
         {
-            properties[it.key()] = casted.value;
+            QDBusVariant casted = qvariant_cast<QDBusVariant>( it.value() );
+
+            if ( casted.value.type()!=QVariant::UserType )
+            {
+                properties[it.key()] = casted.value;
+            }
         }
+
+        return properties;
     }
-
-    return properties;
+    else
+    {
+        return d->properties;
+    }
 }
 
 bool HalDevice::removeProperty( const QString &key )
@@ -166,17 +185,24 @@
 
 bool HalDevice::propertyExists( const QString &key ) const
 {
-    QList<QVariant> params;
-    params << key;
-    QDBusMessage reply = d->callHalMethod( "PropertyExists", params );
+    if( !d->properties.contains(key) )
+    {
+        QList<QVariant> params;
+        params << key;
+        QDBusMessage reply = d->callHalMethod( "PropertyExists", params );
 
-    if ( reply.size() != 1 || !reply[0].canConvert( QVariant::Bool ) )
+        if ( reply.size() != 1 || !reply[0].canConvert( QVariant::Bool ) )
+        {
+            kDebug() << "Looks like the HAL protocol changed" << endl;
+            return false;
+        }
+
+        return reply[0].toBool();
+    }
+    else
     {
-        kDebug() << "Looks like the HAL protocol changed" << endl;
-        return false;
+        return d->properties.contains(key);
     }
-
-    return reply[0].toBool();
 }
 
 bool HalDevice::addCapability( const KDEHW::Ifaces::Capability::Type &capability )
@@ -315,6 +341,7 @@
             type = Device::PropertyRemoved;
         }
 
+        d->properties.remove(key);
         result[key] = type;
     }
 
_______________________________________________
Kde-hardware-devel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-hardware-devel

Reply via email to