kdeconnect-kde/plugins/telephony/telephonyplugin.cpp

100 lines
3.3 KiB
C++
Raw Permalink Normal View History

2013-06-06 04:57:06 +01:00
/**
* SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
* SPDX-FileCopyrightText: 2018 Simon Redman <simon@ergotech.com>
2013-06-06 04:57:06 +01:00
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
2013-06-06 04:57:06 +01:00
*/
#include "telephonyplugin.h"
2013-06-06 04:57:06 +01:00
2013-09-04 20:19:02 +01:00
#include <KLocalizedString>
#include <QDBusReply>
#include <QDebug>
#include "plugin_telephony_debug.h"
#include <KNotification>
#include <KPluginFactory>
2019-06-12 21:16:54 +01:00
K_PLUGIN_CLASS_WITH_JSON(TelephonyPlugin, "kdeconnect_telephony.json")
void TelephonyPlugin::createNotification(const NetworkPacket &np)
{
const QString event = np.get<QString>(QStringLiteral("event"));
const QString phoneNumber = np.get<QString>(QStringLiteral("phoneNumber"), i18n("unknown number"));
const QString contactName = np.get<QString>(QStringLiteral("contactName"), phoneNumber);
const QByteArray phoneThumbnail = QByteArray::fromBase64(np.get<QByteArray>(QStringLiteral("phoneThumbnail"), ""));
2013-06-06 04:57:06 +01:00
2014-03-04 01:34:09 +00:00
QString content, type, icon;
2013-08-07 10:29:56 +01:00
if (event == QLatin1String("ringing")) {
type = QStringLiteral("callReceived");
icon = QStringLiteral("call-start");
content = i18n("Incoming call from %1", contactName);
} else if (event == QLatin1String("missedCall")) {
type = QStringLiteral("missedCall");
icon = QStringLiteral("call-start");
content = i18n("Missed call from %1", contactName);
} else if (event == QLatin1String("talking")) {
if (m_currentCallNotification) {
m_currentCallNotification->close();
}
return;
2013-06-06 04:57:06 +01:00
}
2019-02-17 01:41:42 +00:00
Q_EMIT callReceived(type, phoneNumber, contactName);
qCDebug(KDECONNECT_PLUGIN_TELEPHONY) << "Creating notification with type:" << type;
2013-06-06 04:57:06 +01:00
if (!m_currentCallNotification) {
m_currentCallNotification = new KNotification(type, KNotification::Persistent);
}
if (!phoneThumbnail.isEmpty()) {
QPixmap photo;
photo.loadFromData(phoneThumbnail, "JPEG");
m_currentCallNotification->setPixmap(photo);
} else {
m_currentCallNotification->setIconName(icon);
}
m_currentCallNotification->setComponentName(QStringLiteral("kdeconnect"));
m_currentCallNotification->setTitle(device()->name());
m_currentCallNotification->setText(content);
2013-06-06 04:57:06 +01:00
if (event == QLatin1String("ringing")) {
m_currentCallNotification->clearActions();
2023-07-23 21:52:52 +01:00
KNotificationAction *muteAction = m_currentCallNotification->addAction(i18n("Mute Call"));
connect(muteAction, &KNotificationAction::activated, this, &TelephonyPlugin::sendMutePacket);
}
m_currentCallNotification->sendEvent();
2013-06-06 04:57:06 +01:00
}
void TelephonyPlugin::receivePacket(const NetworkPacket &np)
{
if (np.get<bool>(QStringLiteral("isCancel"))) {
if (m_currentCallNotification) {
m_currentCallNotification->close();
}
return;
}
// ignore old style sms packet
if (np.get<QString>(QStringLiteral("event")) != QLatin1String("sms")) {
createNotification(np);
(WIP) Upgrade Telephony plugin to read SMS history (KDE side) Summary: For real usecases of SMS support, we will almost always need access to the message history in some way Specifically resolve T8338 Incidentally resolve T6651 since Telephony shall no longer create a notification Test Plan: Setup: - Build corresponding Android-side diff (D11698) - Build this diff Step 1: Does anything at all work? - Put a breakpoint in the handleBatchMessages method of the telephony plugin, ideally after constructing a Message object - Use DBus to poke /modules/kdeconnect/devices/<deviceID>/telephony.requestAllConversations() - Verify that the constructed Message is one you sent or received and that it is the most recent in the corresponding conversation Step 2: DBus - Open the Interface org.kde.kdeconnect.device.conversations of /modules/kdeconnect/devices/<deviceId> - Poke activeConversations and verify an empty array is returned - Poke requestAllConversationThreads - Poke activeConversations and verify that a list of numbers has been returned. These are conversationIds - Use a conversationId to call getFirstFromConversation - Verify that the returned Message object is one which you recognize - Note that if the message is an MMS it will be blank and meaningless. Try a different conversationId. MMS support "coming soon!" Step 3: SMS App - Use ccmake (or similar) to set SMSAPP_ENABLE to ON - Build the project - Run ./bin/kdeconnect-sms - Verify that the app shows a list of everyone you have an SMS conversation with (MMS messages are stripped out) - If you have the Contacts plugin working, verify that most contacts have their name and photo instead of their phone number Reviewers: #kde_connect, nicolasfella, apol Reviewed By: #kde_connect, nicolasfella, apol Subscribers: andyholmes, apol, nicolasfella, #kde_connect Tags: #kde_connect Maniphest Tasks: T8338, T6651 Differential Revision: https://phabricator.kde.org/D11854
2018-05-25 15:21:56 +01:00
}
2013-06-06 04:57:06 +01:00
}
void TelephonyPlugin::sendMutePacket()
{
NetworkPacket packet(PACKET_TYPE_TELEPHONY_REQUEST_MUTE, {{QStringLiteral("action"), QStringLiteral("mute")}});
sendPacket(packet);
}
QString TelephonyPlugin::dbusPath() const
{
return QLatin1String("/modules/kdeconnect/devices/%1/telepony").arg(device()->id());
}
#include "moc_telephonyplugin.cpp"
#include "telephonyplugin.moc"