Reply
Thread Tools
sakya's Avatar
Posts: 533 | Thanked: 1,341 times | Joined on Dec 2010 @ Italy
#1
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

Last edited by sakya; 2011-05-26 at 12:28.
 
sakya's Avatar
Posts: 533 | Thanked: 1,341 times | Joined on Dec 2010 @ Italy
#2
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
 

The Following User Says Thank You to sakya For This Useful Post:
MohammadAG's Avatar
Posts: 2,473 | Thanked: 12,265 times | Joined on Oct 2009 @ Jerusalem, PS/IL
#3
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)
 

The Following User Says Thank You to MohammadAG For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 09:57.