Commit 310b6512 authored by Nicolas Fella's avatar Nicolas Fella

Work work work work work

parent 82589730
......@@ -28,6 +28,8 @@
#include <KPluginFactory>
#include <KNotification>
#include <core/notificationserverinfo.h>
K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_telephony.json", registerPlugin< TelephonyPlugin >(); )
Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY, "kdeconnect.plugin.telephony")
......@@ -41,60 +43,70 @@ TelephonyPlugin::~TelephonyPlugin()
{
}
KNotification* TelephonyPlugin::createNotification(const NetworkPacket& np)
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 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"), ""));
QString content, type, icon;
KNotification::NotificationFlags flags = KNotification::CloseOnTimeout;
KNotification::NotificationFlags flags = KNotification::Persistent;
const QString title = device()->name();
const QString deviceName = device()->name();
if (event == QLatin1String("ringing")) {
type = QStringLiteral("callReceived");
icon = QStringLiteral("call-start");
content = i18n("Incoming call from %1", contactName);
m_currentNotification = new KNotification(type, KNotification::Persistent, this);
m_currentNotification->setComponentName(QStringLiteral("kdeconnect"));
m_currentNotification->setTitle(content);
m_currentNotification->sendEvent();
} else if (event == QLatin1String("missedCall")) {
type = QStringLiteral("missedCall");
icon = QStringLiteral("call-start");
content = i18n("Missed call from %1", contactName);
flags |= KNotification::Persistent; //Note that in Unity this generates a message box!
} else if (event == QLatin1String("talking")) {
return nullptr;
} else {
#ifndef NDEBUG
return nullptr;
#else
type = QStringLiteral("callReceived");
icon = QStringLiteral("phone");
content = i18n("Unknown telephony event: %1", event);
#endif
}
Q_EMIT callReceived(type, phoneNumber, contactName);
qCDebug(KDECONNECT_PLUGIN_TELEPHONY) << "Creating notification with type:" << type;
if (m_currentNotification) {
qDebug() << "Close";
m_currentNotification->close();
} else {
qDebug() << "Or not?";
}
KNotification* notification = new KNotification(type, flags, this);
if (!phoneThumbnail.isEmpty()) {
QPixmap photo;
photo.loadFromData(phoneThumbnail, "JPEG");
notification->setPixmap(photo);
} else {
notification->setIconName(icon);
} else if (event == QLatin1String("talking")) {
return;
}
notification->setComponentName(QStringLiteral("kdeconnect"));
notification->setTitle(title);
notification->setText(content);
if (event == QLatin1String("ringing")) {
notification->setActions( QStringList(i18n("Mute Call")) );
connect(notification, &KNotification::action1Activated, this, &TelephonyPlugin::sendMutePacket);
}
return notification;
// Q_EMIT callReceived(type, phoneNumber, contactName);
//
// qCDebug(KDECONNECT_PLUGIN_TELEPHONY) << "Creating notification with type:" << type;
//
// KNotification* notification = new KNotification(type, flags, this);
// if (!phoneThumbnail.isEmpty()) {
// QPixmap photo;
// photo.loadFromData(phoneThumbnail, "JPEG");
// notification->setPixmap(photo);
// } else {
// notification->setIconName(icon);
// }
// notification->setComponentName(QStringLiteral("kdeconnect"));
//
// if (NotificationServerInfo::instance().supportedHints().testFlag(NotificationServerInfo::Hint::X_KDE_ORIGIN_NAME)) {
// notification->setHint(QStringLiteral("x-kde-origin-name"), deviceName);
// }
// notification->setTitle(content);
//
//
// // notification->setText(content);
//
// if (event == QLatin1String("ringing")) {
// notification->setActions( QStringList(i18n("Mute Call")) );
// connect(notification, &KNotification::action1Activated, this, &TelephonyPlugin::sendMutePacket);
// }
}
bool TelephonyPlugin::receivePacket(const NetworkPacket& np)
......@@ -112,9 +124,7 @@ bool TelephonyPlugin::receivePacket(const NetworkPacket& np)
if (event == QLatin1String("sms")) {
return false;
}
KNotification* n = createNotification(np);
if (n != nullptr) n->sendEvent();
return true;
createNotification(np);
}
return true;
......
......@@ -24,6 +24,7 @@
#include <QLoggingCategory>
#include <QDBusInterface>
#include <QPointer>
#include <KNotification>
......@@ -74,7 +75,9 @@ private:
* - Incoming call (with the option to mute the ringing)
* - Missed call
*/
KNotification* createNotification(const NetworkPacket& np);
void createNotification(const NetworkPacket& np);
QPointer<KNotification> m_currentNotification;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment