Changeset View
Changeset View
Standalone View
Standalone View
plugins/sms/smsplugin.h
- This file was copied from plugins/telephony/telephonyplugin.h.
1 | /** | 1 | /** | ||
---|---|---|---|---|---|
2 | * Copyright 2013 Albert Vaca <albertvaka@gmail.com> | 2 | * Copyright 2013 Albert Vaca <albertvaka@gmail.com> | ||
3 | * Copyright 2018 Simon Redman <simon@ergotech.com> | | |||
4 | * | 3 | * | ||
5 | * This program is free software; you can redistribute it and/or | 4 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU General Public License as | 5 | * modify it under the terms of the GNU General Public License as | ||
7 | * published by the Free Software Foundation; either version 2 of | 6 | * published by the Free Software Foundation; either version 2 of | ||
8 | * the License or (at your option) version 3 or any later version | 7 | * the License or (at your option) version 3 or any later version | ||
9 | * accepted by the membership of KDE e.V. (or its successor approved | 8 | * accepted by the membership of KDE e.V. (or its successor approved | ||
10 | * by the membership of KDE e.V.), which shall act as a proxy | 9 | * by the membership of KDE e.V.), which shall act as a proxy | ||
11 | * defined in Section 14 of version 3 of the license. | 10 | * defined in Section 14 of version 3 of the license. | ||
12 | * | 11 | * | ||
13 | * This program is distributed in the hope that it will be useful, | 12 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. | ||
17 | * | 16 | * | ||
18 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | */ | 19 | */ | ||
21 | 20 | | |||
22 | #ifndef TELEPHONYPLUGIN_H | 21 | #ifndef SMSPLUGIN_H | ||
23 | #define TELEPHONYPLUGIN_H | 22 | #define SMSPLUGIN_H | ||
24 | 23 | | |||
25 | #include "conversationsdbusinterface.h" | 24 | #include <QObject> | ||
26 | #include "interfaces/conversationmessage.h" | | |||
27 | | ||||
28 | #include <QLoggingCategory> | | |||
29 | #include <QDBusInterface> | | |||
30 | 25 | | |||
31 | #include <KNotification> | 26 | #include <KNotification> | ||
32 | 27 | | |||
33 | #include <core/kdeconnectplugin.h> | 28 | #include <core/kdeconnectplugin.h> | ||
34 | 29 | | |||
30 | #include "conversationsdbusinterface.h" | ||||
31 | #include "interfaces/conversationmessage.h" | ||||
32 | | ||||
33 | #include "sendreplydialog.h" | ||||
34 | | ||||
35 | #define PACKET_TYPE_TELEPHONY QStringLiteral("kdeconnect.telephony") | ||||
36 | | ||||
35 | /** | 37 | /** | ||
36 | * Packet used to indicate a batch of messages has been pushed from the remote device | 38 | * Packet used to indicate a batch of messages has been pushed from the remote device | ||
37 | * | 39 | * | ||
38 | * The body should contain the key "messages" mapping to an array of messages | 40 | * The body should contain the key "messages" mapping to an array of messages | ||
39 | * | 41 | * | ||
40 | * For example: | 42 | * For example: | ||
41 | * { "messages" : [ | 43 | * { "messages" : [ | ||
42 | * { "event" : "sms", | 44 | * { "event" : "sms", | ||
43 | * "messageBody" : "Hello", | 45 | * "messageBody" : "Hello", | ||
44 | * "phoneNumber" : "2021234567", | 46 | * "phoneNumber" : "2021234567", | ||
45 | * "messageDate" : "1518846484880", | 47 | * "messageDate" : "1518846484880", | ||
46 | * "messageType" : "2", | 48 | * "messageType" : "2", | ||
47 | * "threadID" : "132" | 49 | * "threadID" : "132" | ||
48 | * }, | 50 | * }, | ||
49 | * { ... }, | 51 | * { ... }, | ||
50 | * ... | 52 | * ... | ||
51 | * ] | 53 | * ] | ||
52 | * } | 54 | * } | ||
53 | */ | 55 | */ | ||
54 | #define PACKET_TYPE_TELEPHONY_MESSAGE QStringLiteral("kdeconnect.telephony.message") | | |||
55 | 56 | | |||
56 | /** | 57 | #define PACKET_TYPE_TELEPHONY_MESSAGE QStringLiteral("kdeconnect.telephony.message") | ||
57 | * Packet used for simple telephony events | | |||
58 | * | | |||
59 | * It contains the key "event" which maps to a string indicating the type of event: | | |||
60 | * - "ringing" - A phone call is incoming | | |||
61 | * - "missedCall" - An incoming call was not answered | | |||
62 | * - "sms" - An incoming SMS message | | |||
63 | * - Note: As of this writing (15 May 2018) the SMS interface is being improved and this type of event | | |||
64 | * is no longer the preferred way of retrieving SMS. Use PACKET_TYPE_TELEPHONY_MESSAGE instead. | | |||
65 | * | | |||
66 | * Depending on the event, other fields may be defined | | |||
67 | */ | | |||
68 | #define PACKET_TYPE_TELEPHONY QStringLiteral("kdeconnect.telephony") | | |||
69 | 58 | | |||
70 | #define PACKET_TYPE_TELEPHONY_REQUEST QStringLiteral("kdeconnect.telephony.request") | | |||
71 | #define PACKET_TYPE_SMS_REQUEST QStringLiteral("kdeconnect.sms.request") | 59 | #define PACKET_TYPE_SMS_REQUEST QStringLiteral("kdeconnect.sms.request") | ||
72 | 60 | | |||
73 | /** | 61 | /** | ||
74 | * Packet sent to request all the most-recent messages in all conversations on the device | 62 | * Packet sent to request all the most-recent messages in all conversations on the device | ||
75 | * | 63 | * | ||
76 | * The request packet shall contain no body | 64 | * The request packet shall contain no body | ||
77 | */ | 65 | */ | ||
78 | #define PACKET_TYPE_TELEPHONY_REQUEST_CONVERSATIONS QStringLiteral("kdeconnect.telephony.request_conversations") | 66 | #define PACKET_TYPE_TELEPHONY_REQUEST_CONVERSATIONS QStringLiteral("kdeconnect.telephony.request_conversations") | ||
79 | 67 | | |||
80 | /** | 68 | /** | ||
81 | * Packet sent to request all the messages in a particular conversation | 69 | * Packet sent to request all the messages in a particular conversation | ||
82 | * | 70 | * | ||
83 | * The body should contain the key "threadID" mapping to the threadID (as a string) being requested | 71 | * The body should contain the key "threadID" mapping to the threadID (as a string) being requested | ||
84 | * For example: | 72 | * For example: | ||
85 | * { "threadID": 203 } | 73 | * { "threadID": 203 } | ||
86 | */ | 74 | */ | ||
87 | #define PACKET_TYPE_TELEPHONY_REQUEST_CONVERSATION QStringLiteral("kdeconnect.telephony.request_conversation") | 75 | #define PACKET_TYPE_TELEPHONY_REQUEST_CONVERSATION QStringLiteral("kdeconnect.telephony.request_conversation") | ||
88 | 76 | | |||
89 | Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY) | 77 | Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_SMS) | ||
90 | 78 | | |||
91 | class TelephonyPlugin | 79 | class Q_DECL_EXPORT SmsPlugin | ||
92 | : public KdeConnectPlugin | 80 | : public KdeConnectPlugin | ||
93 | { | 81 | { | ||
94 | Q_OBJECT | 82 | Q_OBJECT | ||
95 | Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.telephony") | 83 | Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.sms") | ||
96 | 84 | | |||
97 | public: | 85 | public: | ||
98 | explicit TelephonyPlugin(QObject* parent, const QVariantList& args); | 86 | explicit SmsPlugin(QObject* parent, const QVariantList& args); | ||
99 | ~TelephonyPlugin() override; | 87 | ~SmsPlugin() override; | ||
100 | 88 | | |||
101 | bool receivePacket(const NetworkPacket& np) override; | 89 | bool receivePacket(const NetworkPacket& np) override; | ||
102 | void connected() override {} | 90 | void connected() override {} | ||
91 | | ||||
103 | QString dbusPath() const override; | 92 | QString dbusPath() const override; | ||
104 | 93 | | |||
105 | public Q_SLOTS: | 94 | public Q_SLOTS: | ||
106 | Q_SCRIPTABLE void sendSms(const QString& phoneNumber, const QString& messageBody); | 95 | Q_SCRIPTABLE void sendSms(const QString& phoneNumber, const QString& messageBody); | ||
107 | 96 | | |||
108 | /** | 97 | /** | ||
109 | * Send a request to the remote for all of its conversations | 98 | * Send a request to the remote for all of its conversations | ||
110 | */ | 99 | */ | ||
111 | Q_SCRIPTABLE void requestAllConversations(); | 100 | Q_SCRIPTABLE void requestAllConversations(); | ||
112 | 101 | | |||
113 | /** | 102 | /** | ||
114 | * Send a request to the remote for a particular conversation | 103 | * Send a request to the remote for a particular conversation | ||
115 | */ | 104 | */ | ||
116 | Q_SCRIPTABLE void requestConversation(const QString& conversationID) const; | 105 | Q_SCRIPTABLE void requestConversation(const QString& conversationID) const; | ||
117 | 106 | | |||
118 | public: | | |||
119 | Q_SIGNALS: | | |||
120 | | ||||
121 | private Q_SLOTS: | 107 | private Q_SLOTS: | ||
122 | void sendMutePacket(); | | |||
123 | void showSendSmsDialog(); | 108 | void showSendSmsDialog(); | ||
124 | 109 | | |||
125 | protected: | 110 | private: | ||
111 | | ||||
126 | /** | 112 | /** | ||
127 | * Send to the telepathy plugin if it is available | 113 | * Send to the telepathy plugin if it is available | ||
128 | */ | 114 | */ | ||
129 | void forwardToTelepathy(const ConversationMessage& message); | 115 | void forwardToTelepathy(const ConversationMessage& message); | ||
130 | 116 | | |||
131 | /** | 117 | /** | ||
132 | * Handle a packet which contains many messages, such as PACKET_TYPE_TELEPHONY_MESSAGE | 118 | * Create a notification for incoming SMS (with the option to reply) | ||
119 | * This comment is being written while SMS handling is in the process of being improved. | ||||
120 | * As such, any code in createNotification which deals with SMS is legacy support | ||||
133 | */ | 121 | */ | ||
134 | bool handleBatchMessages(const NetworkPacket& np); | 122 | KNotification* createNotification(const NetworkPacket& np); | ||
135 | 123 | | |||
136 | private: | | |||
137 | /** | 124 | /** | ||
138 | * Create a notification for: | 125 | * Handle a packet which contains many messages, such as PACKET_TYPE_TELEPHONY_MESSAGE | ||
139 | * - Incoming call (with the option to mute the ringing) | | |||
140 | * - Missed call | | |||
141 | * - Incoming SMS (with the option to reply) | | |||
142 | * - This comment is being written while SMS handling is in the process of being improved. | | |||
143 | * As such, any code in createNotification which deals with SMS is legacy support | | |||
144 | */ | 126 | */ | ||
145 | KNotification* createNotification(const NetworkPacket& np); | 127 | bool handleBatchMessages(const NetworkPacket& np); | ||
128 | | ||||
146 | 129 | | |||
147 | QDBusInterface m_telepathyInterface; | 130 | QDBusInterface m_telepathyInterface; | ||
148 | ConversationsDbusInterface* m_conversationInterface; | 131 | ConversationsDbusInterface* m_conversationInterface; | ||
132 | | ||||
149 | }; | 133 | }; | ||
150 | 134 | | |||
151 | #endif | 135 | #endif |