[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdeconnect-kde/sms-history] plugins/telephony: Reenable telepathy handling
From:       Simon Redman <null () kde ! org>
Date:       2018-04-01 3:20:57
Message-ID: E1f2TY9-0005kJ-Vl () code ! kde ! org
[Download RAW message or body]

Git commit 3617de2d416f84ba7e003b5e32cd8fe1b61ff2d4 by Simon Redman.
Committed on 01/04/2018 at 03:20.
Pushed by sredman into branch 'sms-history'.

Reenable telepathy handling

(Hopefully, I am not set up to test this at the moment)

M  +2    -1    plugins/telephony/kdeconnect_telephony.json
M  +28   -0    plugins/telephony/telephonyplugin.cpp
M  +29   -0    plugins/telephony/telephonyplugin.h

https://commits.kde.org/kdeconnect-kde/3617de2d416f84ba7e003b5e32cd8fe1b61ff2d4

diff --git a/plugins/telephony/kdeconnect_telephony.json \
b/plugins/telephony/kdeconnect_telephony.json index 817ed94e..aac7435e 100644
--- a/plugins/telephony/kdeconnect_telephony.json
+++ b/plugins/telephony/kdeconnect_telephony.json
@@ -93,6 +93,7 @@
         "kdeconnect.telephony.request_conversations"
     ],
     "X-KdeConnect-SupportedPacketType": [
-        "kdeconnect.telephony"
+        "kdeconnect.telephony",
+        "kdeconnect.telephony.message"
     ]
 }
diff --git a/plugins/telephony/telephonyplugin.cpp \
b/plugins/telephony/telephonyplugin.cpp index 6f20100d..d128ab69 100644
--- a/plugins/telephony/telephonyplugin.cpp
+++ b/plugins/telephony/telephonyplugin.cpp
@@ -22,6 +22,7 @@
 
 #include "sendreplydialog.h"
 
+#include <KLocalizedString>
 #include <QDebug>
 #include <QDBusReply>
 
@@ -45,6 +46,13 @@ bool TelephonyPlugin::receivePacket(const NetworkPacket& np)
         return true;
     }
 
+    const QString& event = np.get<QString>(QStringLiteral("event"), \
QStringLiteral("unknown")); +
+    if (np.type() == PACKET_TYPE_TELEPHONY_MESSAGE || event == QLatin1String("sms"))
+    {
+        this->forwardToTelepathy(np);
+    }
+
     return true;
 }
 
@@ -83,6 +91,26 @@ void TelephonyPlugin::sendAllConversationsRequest()
     sendPacket(np);
 }
 
+bool TelephonyPlugin::forwardToTelepathy(const NetworkPacket& np)
+{
+    // In case telepathy can handle the message, don't do anything else
+    if (m_telepathyInterface.isValid()) {
+        qCDebug(KDECONNECT_PLUGIN_TELEPHONY) << "Passing a text message to the \
telepathy interface"; +        connect(&m_telepathyInterface, \
SIGNAL(messageReceived(QString,QString)), SLOT(sendSms(QString,QString)), \
Qt::UniqueConnection); +        const QString messageBody = \
np.get<QString>(QStringLiteral("messageBody"),QLatin1String("")); +        const \
QString contactName = ""; +        const QString phoneNumber = \
np.get<QString>(QStringLiteral("phoneNumber"), i18n("unknown number")); +        \
QDBusReply<bool> reply = m_telepathyInterface.call(QStringLiteral("sendMessage"), \
phoneNumber, contactName, messageBody); +        if (reply) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    return false;
+}
+
 QString TelephonyPlugin::dbusPath() const
 {
     return "/modules/kdeconnect/devices/" + device()->id() + "/telephony";
diff --git a/plugins/telephony/telephonyplugin.h \
b/plugins/telephony/telephonyplugin.h index c07c4fd2..2fc57549 100644
--- a/plugins/telephony/telephonyplugin.h
+++ b/plugins/telephony/telephonyplugin.h
@@ -26,9 +26,32 @@
 
 #include <core/kdeconnectplugin.h>
 
+/**
+ * Packet used to indicate a message has been pushed from the remote device
+ *
+ * The body should contain a mapping of all fields of the message to their values
+ *
+ * For example:
+ * { "event" : "sms",
+ *   "messageBody" : "Hello",
+ *   "phoneNumber" : "2021234567",
+ *   "messageDate" : "20150321434",
+ *   "messageType" : "-1",
+ *   "threadID" : "132"
+ * }
+ */
+#define PACKET_TYPE_TELEPHONY_MESSAGE QStringLiteral("kdeconnect.telephony.message")
+
+#define PACKET_TYPE_TELEPHONY QStringLiteral("kdeconnect.telephony")
+
 #define PACKET_TYPE_TELEPHONY_REQUEST QStringLiteral("kdeconnect.telephony.request")
 #define PACKET_TYPE_SMS_REQUEST QStringLiteral("kdeconnect.sms.request")
 
+/**
+ * Packet sent to request all the most-recent messages in all conversations on the \
device + *
+ * The request packet shall contain no body
+ */
 #define PACKET_TYPE_TELEPHONY_REQUEST_CONVERSATIONS \
QStringLiteral("kdeconnect.telephony.request_conversations")  
 Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY)
@@ -57,6 +80,12 @@ private Q_SLOTS:
     void sendMutePacket();
     void showSendSmsDialog();
 
+protected:
+    /**
+     * Send to the telepathy plugin if it is available
+     */
+    bool forwardToTelepathy(const NetworkPacket& np);
+
 private:
     QDBusInterface m_telepathyInterface;
 };


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic