Changeset View
Changeset View
Standalone View
Standalone View
plugins/telephony/telephonyplugin.h
- This file was copied to plugins/sms/smsplugin.h.
Show All 16 Lines | |||||
17 | * | 17 | * | ||
18 | * You should have received a copy of the GNU General Public License | 18 | * 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/>. | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #ifndef TELEPHONYPLUGIN_H | 22 | #ifndef TELEPHONYPLUGIN_H | ||
23 | #define TELEPHONYPLUGIN_H | 23 | #define TELEPHONYPLUGIN_H | ||
24 | 24 | | |||
25 | #include "conversationsdbusinterface.h" | | |||
26 | #include "interfaces/conversationmessage.h" | | |||
27 | | ||||
28 | #include <QLoggingCategory> | 25 | #include <QLoggingCategory> | ||
29 | #include <QDBusInterface> | 26 | #include <QDBusInterface> | ||
30 | 27 | | |||
31 | #include <KNotification> | 28 | #include <KNotification> | ||
32 | 29 | | |||
33 | #include <core/kdeconnectplugin.h> | 30 | #include <core/kdeconnectplugin.h> | ||
34 | 31 | | |||
35 | /** | 32 | /** | ||
36 | * Packet used to indicate a batch of messages has been pushed from the remote device | | |||
37 | * | | |||
38 | * The body should contain the key "messages" mapping to an array of messages | | |||
39 | * | | |||
40 | * For example: | | |||
41 | * { "messages" : [ | | |||
42 | * { "event" : "sms", | | |||
43 | * "messageBody" : "Hello", | | |||
44 | * "phoneNumber" : "2021234567", | | |||
45 | * "messageDate" : "1518846484880", | | |||
46 | * "messageType" : "2", | | |||
47 | * "threadID" : "132" | | |||
48 | * }, | | |||
49 | * { ... }, | | |||
50 | * ... | | |||
51 | * ] | | |||
52 | * } | | |||
53 | */ | | |||
54 | #define PACKET_TYPE_TELEPHONY_MESSAGE QStringLiteral("kdeconnect.telephony.message") | | |||
55 | | ||||
56 | /** | | |||
57 | * Packet used for simple telephony events | 33 | * Packet used for simple telephony events | ||
58 | * | 34 | * | ||
59 | * It contains the key "event" which maps to a string indicating the type of event: | 35 | * It contains the key "event" which maps to a string indicating the type of event: | ||
60 | * - "ringing" - A phone call is incoming | 36 | * - "ringing" - A phone call is incoming | ||
61 | * - "missedCall" - An incoming call was not answered | 37 | * - "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 | * | 38 | * | ||
66 | * Depending on the event, other fields may be defined | 39 | * Depending on the event, other fields may be defined | ||
67 | */ | 40 | */ | ||
68 | #define PACKET_TYPE_TELEPHONY QStringLiteral("kdeconnect.telephony") | 41 | #define PACKET_TYPE_TELEPHONY QStringLiteral("kdeconnect.telephony") | ||
69 | 42 | | |||
70 | #define PACKET_TYPE_TELEPHONY_REQUEST QStringLiteral("kdeconnect.telephony.request") | 43 | #define PACKET_TYPE_TELEPHONY_REQUEST QStringLiteral("kdeconnect.telephony.request") | ||
71 | #define PACKET_TYPE_SMS_REQUEST QStringLiteral("kdeconnect.sms.request") | | |||
72 | | ||||
73 | /** | | |||
74 | * Packet sent to request all the most-recent messages in all conversations on the device | | |||
75 | * | | |||
76 | * The request packet shall contain no body | | |||
77 | */ | | |||
78 | #define PACKET_TYPE_TELEPHONY_REQUEST_CONVERSATIONS QStringLiteral("kdeconnect.telephony.request_conversations") | | |||
79 | | ||||
80 | /** | | |||
81 | * Packet sent to request all the messages in a particular conversation | | |||
82 | * | | |||
83 | * The body should contain the key "threadID" mapping to the threadID (as a string) being requested | | |||
84 | * For example: | | |||
85 | * { "threadID": 203 } | | |||
86 | */ | | |||
87 | #define PACKET_TYPE_TELEPHONY_REQUEST_CONVERSATION QStringLiteral("kdeconnect.telephony.request_conversation") | | |||
88 | 44 | | |||
89 | Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY) | 45 | Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY) | ||
90 | 46 | | |||
91 | class TelephonyPlugin | 47 | class TelephonyPlugin | ||
92 | : public KdeConnectPlugin | 48 | : public KdeConnectPlugin | ||
93 | { | 49 | { | ||
94 | Q_OBJECT | 50 | Q_OBJECT | ||
95 | Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.telephony") | 51 | Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.telephony") | ||
96 | 52 | | |||
97 | public: | 53 | public: | ||
98 | explicit TelephonyPlugin(QObject* parent, const QVariantList& args); | 54 | explicit TelephonyPlugin(QObject* parent, const QVariantList& args); | ||
99 | ~TelephonyPlugin() override; | 55 | ~TelephonyPlugin() override; | ||
100 | 56 | | |||
101 | bool receivePacket(const NetworkPacket& np) override; | 57 | bool receivePacket(const NetworkPacket& np) override; | ||
102 | void connected() override {} | 58 | void connected() override {} | ||
103 | QString dbusPath() const override; | 59 | QString dbusPath() const override; | ||
104 | 60 | | |||
105 | public Q_SLOTS: | | |||
106 | Q_SCRIPTABLE void sendSms(const QString& phoneNumber, const QString& messageBody); | | |||
107 | | ||||
108 | /** | | |||
109 | * Send a request to the remote for all of its conversations | | |||
110 | */ | | |||
111 | Q_SCRIPTABLE void requestAllConversations(); | | |||
112 | | ||||
113 | /** | | |||
114 | * Send a request to the remote for a particular conversation | | |||
115 | */ | | |||
116 | Q_SCRIPTABLE void requestConversation(const QString& conversationID) const; | | |||
117 | | ||||
118 | public: | 61 | public: | ||
119 | Q_SIGNALS: | 62 | Q_SIGNALS: | ||
120 | 63 | | |||
121 | private Q_SLOTS: | 64 | private Q_SLOTS: | ||
122 | void sendMutePacket(); | 65 | void sendMutePacket(); | ||
123 | void showSendSmsDialog(); | | |||
124 | | ||||
125 | protected: | | |||
126 | /** | | |||
127 | * Send to the telepathy plugin if it is available | | |||
128 | */ | | |||
129 | void forwardToTelepathy(const ConversationMessage& message); | | |||
130 | | ||||
131 | /** | | |||
132 | * Handle a packet which contains many messages, such as PACKET_TYPE_TELEPHONY_MESSAGE | | |||
133 | */ | | |||
134 | bool handleBatchMessages(const NetworkPacket& np); | | |||
135 | 66 | | |||
136 | private: | 67 | private: | ||
137 | /** | 68 | /** | ||
138 | * Create a notification for: | 69 | * Create a notification for: | ||
139 | * - Incoming call (with the option to mute the ringing) | 70 | * - Incoming call (with the option to mute the ringing) | ||
140 | * - Missed call | 71 | * - 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 | */ | 72 | */ | ||
145 | KNotification* createNotification(const NetworkPacket& np); | 73 | KNotification* createNotification(const NetworkPacket& np); | ||
146 | | ||||
147 | QDBusInterface m_telepathyInterface; | | |||
148 | ConversationsDbusInterface* m_conversationInterface; | | |||
149 | }; | 74 | }; | ||
150 | 75 | | |||
151 | #endif | 76 | #endif |