maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Help with QDBusPendingCall (https://talk.maemo.org/showthread.php?t=73471)

sakya 2011-05-26 10:40

Help with QDBusPendingCall
 
Hi!

I tried to call this method with Qt using QDBusPendingCall, but I always receive an error in the reply.

The message I'm trying to call is this:
Code:

method call sender=:1.50 -> dest=org.freedesktop.Tracker serial=5264 path=/org/freedesktop/Tracker/Metadata; interface=org.freedesktop.Tracker.Metadata; member=GetUniqueValuesWithAggregates
  string "Music"
  array [
      string "Audio:Artist"
  ]
  string ""
  array [
      string "SUM"
      string "COUNT"
      string "COUNT"
      string "CONCAT"
  ]
  array [
      string "Audio:Duration"
      string "Audio:Album"
      string "*"
      string "Audio:Album"
  ]
  boolean false
  int32 0
  int32 10

And this is the reply I should receive:
Code:

method return sender=:1.1317 -> dest=:1.50 reply_serial=5264
  array [
      array [
        string "Affinity"
        string "4307"
        string "1"
        string "15"
        string "Affinity"
      ]
      array [
        string "Alanis Morissette"
        string "3645"
        string "1"
        string "13"
        string "Jagged Little Pill"
      ]
      array [
        string "Al Di Meola"
        string "2312"
        string "1"
        string "6"
        string "Casino"
      ]
      ...
  ]

I tried to use this code, but as I said I always receive an error (reply.isError() is true):
Code:

void MafwHelper::GetCatalog(QString aggregate, int index, int count)
{
#ifdef Q_WS_MAEMO_5
    QDBusConnection conn = QDBusConnection::sessionBus();
    QDBusInterface device("org.freedesktop.Tracker",
                          "/org/freedesktop/Tracker/Metadata", "org.freedesktop.Tracker.Metadata", conn);

    QStringList par1 = QStringList() << aggregate;
    QStringList par2 = QStringList() << "SUM" << "COUNT" << "COUNT" << "CONCAT";
    QStringList par3 = QStringList() << "Audio:Duration" << "Audio:Album" << "*" << "Audio:Album";

    qDebug() << "DBusMessage: GetUniqueValuesWithAggregates";
    QDBusPendingCall pcall = device.asyncCall("GetUniqueValuesWithAggregates",
                                              "Music", par1, "",
                                              par2, par3, false, index, count);
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);

    connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
            this, SLOT(GetCatalogFinishedSlot(QDBusPendingCallWatcher*)));
#endif
}

#ifdef Q_WS_MAEMO_5
void MafwHelper::GetCatalogFinishedSlot(QDBusPendingCallWatcher* call)
{
    QDBusPendingReply<QDBusVariant> reply = *call;
    if (reply.isError()) {
        qWarning() << "QDBusPendingReply error";
    } else {
        for(int i=0; i<reply.count(); i++){
          QVariant val = qvariant_cast<QDBusVariant>(reply.argumentAt(i)).variant();
          qDebug() << val;
        }
    }
    call->deleteLater();
}
#endif

Can someone point me in the right direction? :)
I'm not even sure that a QStringList parameter is correct for the array in dbusmessage...

Many thanks

sakya 2011-05-26 19:56

Re: Help with QDBusPendingCall
 
Ok, I don't know what I'm doing wrong, but asyncCall doesn't work for me.
callWithCallback works perfectly. ;)
Code:

void MafwHelper::GetCatalog(QString aggregate, int index, int count)
{
#ifdef Q_WS_MAEMO_5
    QDBusInterface device(QLatin1String("org.freedesktop.Tracker"),
                          QLatin1String("/org/freedesktop/Tracker/Metadata"),
                          QLatin1String("org.freedesktop.Tracker.Metadata"),
                          QDBusConnection::sessionBus());

    QStringList par1 = QStringList() << aggregate;
    QStringList par2 = QStringList() << "SUM" << "COUNT" << "COUNT" << "CONCAT";
    QStringList par3 = QStringList() << "Audio:Duration" << "Audio:Album" << "*" << "Audio:Album";

    qDebug() << "DBusMessage: org.freedesktop.Tracker.Metadata::GetUniqueValuesWithAggregates";

    QList<QVariant> args = QList<QVariant>() << "Music" << par1 << "" << par2 << par3 << false << index << count;
    device.callWithCallback(QLatin1String("GetUniqueValuesWithAggregates"), args,
                                          this, SLOT(GetCatalogFinishedSlot(QDBusMessage)));
#endif
}

#ifdef Q_WS_MAEMO_5
void MafwHelper::GetCatalogFinishedSlot(QDBusMessage msg)
{
    QVariant val = msg.arguments()[0];
    QDBusArgument arg = qvariant_cast<QDBusArgument>(val);

    arg.beginArray();
    while (!arg.atEnd()) {
        QList<QString> element;
        arg >> element;
        qDebug() << element;
    }
    arg.endArray();
}
#endif


MohammadAG 2011-05-26 21:57

Re: Help with QDBusPendingCall
 
You might wanna have a look here https://gitorious.org/qt-mediaplayer...es/master/mafw (if it's only mafw you want to use from tracker).
(MafwSource and MafwRenderer classes were written by nicolai)


All times are GMT. The time now is 03:42.

vBulletin® Version 3.8.8