← Back to team overview

ayatana-commits team mailing list archive

[Branch ~agateau/libindicate-qt/trunk] Rev 106: Added getIndicatorPropertyAsVariant

 

------------------------------------------------------------
revno: 106
committer: Aurelien Gateau <aurelien.gateau@xxxxxxxxxxxxx>
branch nick: libindicate-qt
timestamp: Mon 2010-02-15 18:46:17 +0100
message:
  Added getIndicatorPropertyAsVariant
modified:
  src/qindicatelistener.cpp
  src/qindicatelistener.h


--
lp:libindicate-qt
https://code.launchpad.net/~agateau/libindicate-qt/trunk

Your team ayatana-commits is subscribed to branch lp:libindicate-qt.
To unsubscribe from this branch go to https://code.launchpad.net/~agateau/libindicate-qt/trunk/+edit-subscription.
=== modified file 'src/qindicatelistener.cpp'
--- src/qindicatelistener.cpp	2010-02-10 15:46:12 +0000
+++ src/qindicatelistener.cpp	2010-02-15 17:46:17 +0000
@@ -15,6 +15,7 @@
 #include <QDateTime>
 #include <QDebug>
 #include <QPointer>
+#include <QVariant>
 
 // libindicate
 #include <libindicate/listener.h>
@@ -152,6 +153,25 @@
     return &instance;
 }
 
+static QVariant variantFromGValue(const GValue* value)
+{
+    if (!value) {
+        qWarning() << "variantFromGValue(): value is NULL";
+        return QVariant();
+    }
+    if (G_VALUE_HOLDS_STRING(value)) {
+        return QVariant(QByteArray(g_value_get_string(value)));
+    }
+    if (G_VALUE_HOLDS_INT(value)) {
+        return QVariant(g_value_get_int(value));
+    }
+    if (G_VALUE_HOLDS_BOOLEAN(value)) {
+        return QVariant(g_value_get_boolean(value));
+    }
+    qWarning() << "variantFromGValue(): don't know how to handle GValue of type " << G_VALUE_TYPE_NAME(value);
+    return QVariant();
+}
+
 struct GetPropertyHelper {
     QPointer<QObject> mReceiver;
     QByteArray mMethod;
@@ -181,6 +201,27 @@
         delete helper;
     }
 
+    static void indicatorGetPropertyAsVariantCB(IndicateListener* listener,
+        IndicateListenerServer* _server, IndicateListenerIndicator* _indicator,
+        gchar* _key, const GValue* value, gpointer data)
+    {
+        GetPropertyHelper* helper = static_cast<GetPropertyHelper*>(data);
+        if (helper->mReceiver) {
+            Listener::Server* server = reinterpret_cast<Listener::Server*>(_server);
+            Listener::Indicator* indicator = reinterpret_cast<Listener::Indicator*>(_indicator);
+            QString key = QString::fromUtf8(_key);
+
+            QVariant variant = variantFromGValue(value);
+
+            QMetaObject::invokeMethod(helper->mReceiver, helper->mMethod.data(),
+                Q_ARG(QIndicate::Listener::Server*, server),
+                Q_ARG(QIndicate::Listener::Indicator*, indicator),
+                Q_ARG(QString, key),
+                Q_ARG(QVariant, variant));
+        }
+        delete helper;
+    }
+
     static void serverGetQByteArrayPropertyCB(IndicateListener* listener,
         IndicateListenerServer* server, gchar* value, gpointer data)
     {
@@ -223,6 +264,21 @@
         key.toUtf8().data(), GetPropertyHelper::indicatorGetPropertyCB, helper);
 }
 
+void Listener::getIndicatorPropertyAsVariant(
+    QIndicate::Listener::Server* server,
+    QIndicate::Listener::Indicator* indicator,
+    const QString& key,
+    QObject* receiver,
+    const char* slot)
+{
+    GetPropertyHelper* helper = new GetPropertyHelper(receiver, slot);
+
+    indicate_listener_get_property_value(d->mGListener,
+        reinterpret_cast<IndicateListenerServer*>(server),
+        reinterpret_cast<IndicateListenerIndicator*>(indicator),
+        key.toUtf8().data(), GetPropertyHelper::indicatorGetPropertyAsVariantCB, helper);
+}
+
 void Listener::getServerDesktopFile(
     QIndicate::Listener::Server* server,
     QObject* receiver,

=== modified file 'src/qindicatelistener.h'
--- src/qindicatelistener.h	2010-02-12 13:42:17 +0000
+++ src/qindicatelistener.h	2010-02-15 17:46:17 +0000
@@ -66,6 +66,19 @@
                               QObject* receiver, const char* slot);
 
     /**
+     * Ask an indicator for the value of a property. Result will be sent to
+     * receiver slot, which should have the following signature:
+     *
+     *   QIndicate::Listener::Server*,
+     *   QIndicate::Listener::Indicator*,
+     *   const QString& key,
+     *   const QVariant& value
+     */
+    void getIndicatorPropertyAsVariant(QIndicate::Listener::Server* server, QIndicate::Listener::Indicator* indicator,
+                                       const QString& property,
+                                       QObject* receiver, const char* slot);
+
+    /**
      * Ask a server for its desktop file. Result will be sent to
      * receiver slot, which should have the following signature:
      *