The Following User Says Thank You to chrm For This Useful Post: | ||
![]() |
2015-08-26
, 12:08
|
|
Posts: 2,448 |
Thanked: 9,523 times |
Joined on Aug 2010
@ Wigan, UK
|
#2
|
void ImControlThread::telepathyMessageReceived(const QDBusMessage &reply) { foreach (QVariant arg, reply.arguments()) { if (arg.canConvert<QDBusArgument>()) { qDebug() << dbusArgumentToVariant(arg.value<QDBusArgument>()); } else { qDebug() << arg; } } } QVariant dbusArgumentToVariant(const QDBusArgument &arg) { switch (arg.currentType()) { case QDBusArgument::BasicType: case QDBusArgument::VariantType: return basicTypeToVariant(arg); case QDBusArgument::ArrayType: return arrayTypeToVariant(arg); case QDBusArgument::MapType: return mapTypeToVariant(arg); default: return QVariant(); } } QVariant basicTypeToVariant(const QDBusArgument &arg) { return arg.asVariant(); } QVariant arrayTypeToVariant(const QDBusArgument &arg) { QVariantList list; arg.beginArray(); while (!arg.atEnd()) { list << dbusArgumentToVariant(arg); } arg.endArray(); return list; } QVariant mapTypeToVariant(const QDBusArgument &arg) { QVariantMap map; arg.beginMap(); while (!arg.atEnd()) { arg.beginMapEntry(); map[basicTypeToVariant(arg).toString()] = dbusArgumentToVariant(arg); arg.endMapEntry(); } arg.endMap(); return map; }
The Following 3 Users Say Thank You to marxian For This Useful Post: | ||
![]() |
2015-08-26
, 13:05
|
Posts: 133 |
Thanked: 405 times |
Joined on Mar 2012
@ Europe
|
#3
|
![]() |
2015-08-27
, 08:19
|
Posts: 133 |
Thanked: 405 times |
Joined on Mar 2012
@ Europe
|
#4
|
map[basicTypeToVariant(arg).toString()] = busArgumentToVariant(arg);
![]() |
2015-08-27
, 11:07
|
|
Posts: 2,448 |
Thanked: 9,523 times |
Joined on Aug 2010
@ Wigan, UK
|
#5
|
QVariant dbusArgumentToVariant(const QDBusArgument &arg) { qDebug() << "dbusArgumentToVariant. Current type is" << arg.currentType(); switch (arg.currentType()) { case QDBusArgument::BasicType: case QDBusArgument::VariantType: return basicTypeToVariant(arg); case QDBusArgument::ArrayType: return arrayTypeToVariant(arg); case QDBusArgument::MapType: return mapTypeToVariant(arg); default: qDebug() << "dbusArgumentToVariant. Type not handled."; return QVariant(); } }
The Following User Says Thank You to marxian For This Useful Post: | ||
![]() |
2015-08-28
, 08:42
|
Posts: 133 |
Thanked: 405 times |
Joined on Mar 2012
@ Europe
|
#6
|
![]() |
2015-08-28
, 13:49
|
Posts: 133 |
Thanked: 405 times |
Joined on Mar 2012
@ Europe
|
#7
|
![]() |
2015-09-05
, 19:07
|
Posts: 133 |
Thanked: 405 times |
Joined on Mar 2012
@ Europe
|
#8
|
QList<QVariant> args; QDBusObjectPath path("/org/freedesktop/Telepathy/Connection/gabble/jabber/XXX"); QString targetID = "XXX@jabberes.org"; args << qVariantFromValue(path); args << targetID; QMap<QString, QVariant> message; message["content"] = QVariant(qVariantFromValue("Message Content")); message["content-type"] = QVariant(qVariantFromValue(QString("text/plain"))); QList<QVariant> msgList; msgList << qVariantFromValue(message); args << msgList; uint flags = 0; args << flags; m.setArguments(args); QDBusMessage retVal = QDBusConnection::sessionBus().call(m);
QDBusMessage(type=Error, service="", error name="org.freedesktop.DBus.Error.UnknownMethod", error message="Method "SendMessage" with signature "osa{sv}u" on interface "org.freedesktop.Telepathy.ChannelDispatcher.Interface.Messages1" doesn't exist"
The Following User Says Thank You to chrm For This Useful Post: | ||
![]() |
2015-09-09
, 11:56
|
Posts: 133 |
Thanked: 405 times |
Joined on Mar 2012
@ Europe
|
#9
|
typedef QMap<QString, QVariant> KeyVarPair; typedef QList<KeyVarPair> KeyVarPairList; Q_DECLARE_METATYPE(KeyVarPair) Q_DECLARE_METATYPE(KeyVarPairList)
qDBusRegisterMetaType<KeyVarPair>(); qDBusRegisterMetaType<KeyVarPairList>();
bool MyClass::telepathySendDBusMessage(QString _receiver, QString _account, QString _content) { QString dbus_service = "org.freedesktop.Telepathy.ChannelDispatcher"; QString dbus_path = "/org/freedesktop/Telepathy/ChannelDispatcher"; QString dbus_interface = "org.freedesktop.Telepathy.ChannelDispatcher.Interface.Messages.DRAFT"; QDBusMessage m = QDBusMessage::createMethodCall( dbus_service, dbus_path, dbus_interface, "SendMessage"); QList<QVariant> args; // Path and targetID QDBusObjectPath path(_account); QString targetID = _receiver; args << qVariantFromValue(path); args << targetID; // Message Parts KeyVarPair message1; int type = 0; message1["message-type"] = qVariantFromValue(type); KeyVarPair message2; message2["content"] = qVariantFromValue(_content); message2["content-type"] = qVariantFromValue(QString("text/plain")); KeyVarPairList messageData; messageData << message1; messageData << message2; args << qVariantFromValue(messageData); // Flags uint flags = 0; args << flags; m.setArguments(args); QDBusMessage retVal = QDBusConnection::sessionBus().call(m); return true; }
myClassObj->telepathySendDBusMessage( "to.jabber.account@jabber.server.tld", "/org/freedesktop/Telepathy/Account/gabble/jabber/ACCOUNT_NAME", "It works!");
The Following 4 Users Say Thank You to chrm For This Useful Post: | ||
![]() |
2015-09-09
, 13:52
|
|
Posts: 878 |
Thanked: 2,535 times |
Joined on Feb 2012
@ Germany
|
#10
|
I'm working on OTR integration for Harmattans conversations UI.
It should be fine by using D-Bus but I have a problem with D-Bus objects converting to Qt-Classes.
But let me explain.
I would like to connect to the interface "org.freedesktop.Telepathy.Channel.Interface.Messa ges" and method "MessageReceived".
dbus-monitor shows this structure:
But now, I'm out of idea. I'm just not able to parse the D-Bus structure from QList<QVariant>.
The debug output in my SLOT shows for _content.size() == 2. But for _content.at(0).typeName() == "void*".
No chance to cast it in something I can extract the data from.
Do you have an idea? Thank you very much for any hint!
Last edited by chrm; 2015-09-05 at 19:15.