void TelephonyPlugin::createNotification(const NetworkPacket &np)
{
const QString event = np.get(QStringLiteral("event"));
const QString phoneNumber = np.get(QStringLiteral("phoneNumber"), i18n("unknown number"));
const QString contactName = np.get(QStringLiteral("contactName"), phoneNumber);
const QByteArray phoneThumbnail = QByteArray::fromBase64(np.get(QStringLiteral("phoneThumbnail"), ""));
QString content, type, icon;
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;
}
Q_EMIT callReceived(type, phoneNumber, contactName);
qCDebug(KDECONNECT_PLUGIN_TELEPHONY) << "Creating notification with type:" << type;
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);
if (event == QLatin1String("ringing")) {
m_currentCallNotification->setActions(QStringList(i18n("Mute Call")));
connect(m_currentCallNotification, &KNotification::action1Activated, this, &TelephonyPlugin::sendMutePacket);
}
m_currentCallNotification->sendEvent();
}
This creates a notification object from an existing network packet. It takes the event, phone number, contact name, and thumbnail data, and sets the title, icon and content of the current call notification.