From 2650dc1e6cb379b093975f262f26277a5a25e3f4 Mon Sep 17 00:00:00 2001
From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
Date: Fri, 5 Jan 2018 12:05:16 -0500
Subject: [PATCH] new libring XML API support
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add support the new libring data-transfer feature (DBus/wrapper).
This patch fixes only the build and doesn't add full support
for the data-transfer feature (come later),

Change-Id: If98966e28bf324260dcfc55760e11bda3e21f62b
Reviewed-by: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
---
 src/dbus/metatypes.h | 31 +++++++++++++++++++++++++++++++
 src/typedefs.h       | 11 +++++++++++
 2 files changed, 42 insertions(+)

diff --git a/src/dbus/metatypes.h b/src/dbus/metatypes.h
index 7b70745c..363d451c 100644
--- a/src/dbus/metatypes.h
+++ b/src/dbus/metatypes.h
@@ -40,6 +40,7 @@ Q_DECLARE_METATYPE(VectorUInt)
 Q_DECLARE_METATYPE(VectorString)
 Q_DECLARE_METATYPE(MapStringVectorString)
 Q_DECLARE_METATYPE(VectorVectorByte)
+Q_DECLARE_METATYPE(DataTransferInfo)
 
 #ifndef ENABLE_LIBWRAP
 static bool dbus_metaTypeInit = false;
@@ -55,10 +56,40 @@ inline void registerCommTypes() {
    qDBusRegisterMetaType<VectorString>                  ();
    qDBusRegisterMetaType<MapStringVectorString>         ();
    qDBusRegisterMetaType<VectorVectorByte>              ();
+   qDBusRegisterMetaType<DataTransferInfo>              ();
    dbus_metaTypeInit = true;
 #endif
 }
 
+#ifndef ENABLE_LIBWRAP
+static inline QDBusArgument &operator<<(QDBusArgument& argument, const DataTransferInfo& info)
+{
+    argument.beginStructure();
+    argument << info.isOutgoing;
+    argument << info.lastEvent;
+    argument << info.totalSize;
+    argument << info.bytesProgress;
+    argument << info.displayName;
+    argument << info.path;
+    argument.endStructure();
+
+    return argument;
+}
+
+static inline const QDBusArgument &operator>>(const QDBusArgument& argument, DataTransferInfo& info)
+{
+    argument.beginStructure();
+    argument >> info.isOutgoing;
+    argument >> info.lastEvent;
+    argument >> info.totalSize;
+    argument >> info.bytesProgress;
+    argument >> info.displayName;
+    argument >> info.path;
+    argument.endStructure();
+
+    return argument;
+}
+#endif
 
 #pragma GCC diagnostic pop
 
diff --git a/src/typedefs.h b/src/typedefs.h
index 59f73425..df1d542d 100644
--- a/src/typedefs.h
+++ b/src/typedefs.h
@@ -38,6 +38,17 @@ typedef QMap< QString, QMap< QString, QStringList > >       MapStringMapStringSt
 typedef QMap< QString, QStringList >                        MapStringStringList           ;
 typedef QVector< QByteArray >                               VectorVectorByte              ;
 
+// Adapted from libring DRing::DataTransferInfo
+struct DataTransferInfo
+{
+    bool isOutgoing;
+    uint lastEvent;
+    qulonglong totalSize;
+    qulonglong bytesProgress;
+    QString displayName;
+    QString path;
+};
+
 /**
  * This function add a safe way to get an enum class size
  * @note it cannot be "const" due to some compiler issues
-- 
GitLab