Changeset View
Changeset View
Standalone View
Standalone View
plugins/telephony/telephonyplugin.cpp
Show All 33 Lines | |||||
34 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY, "kdeconnect.plugin.telephony") | 34 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY, "kdeconnect.plugin.telephony") | ||
35 | 35 | | |||
36 | TelephonyPlugin::TelephonyPlugin(QObject* parent, const QVariantList& args) | 36 | TelephonyPlugin::TelephonyPlugin(QObject* parent, const QVariantList& args) | ||
37 | : KdeConnectPlugin(parent, args) | 37 | : KdeConnectPlugin(parent, args) | ||
38 | , m_telepathyInterface(QStringLiteral("org.freedesktop.Telepathy.ConnectionManager.kdeconnect"), QStringLiteral("/kdeconnect")) | 38 | , m_telepathyInterface(QStringLiteral("org.freedesktop.Telepathy.ConnectionManager.kdeconnect"), QStringLiteral("/kdeconnect")) | ||
39 | { | 39 | { | ||
40 | } | 40 | } | ||
41 | 41 | | |||
42 | KNotification* TelephonyPlugin::createNotification(const NetworkPackage& np) | 42 | KNotification* TelephonyPlugin::createNotification(const NetworkPacket& np) | ||
43 | { | 43 | { | ||
44 | const QString event = np.get<QString>(QStringLiteral("event")); | 44 | const QString event = np.get<QString>(QStringLiteral("event")); | ||
45 | const QString phoneNumber = np.get<QString>(QStringLiteral("phoneNumber"), i18n("unknown number")); | 45 | const QString phoneNumber = np.get<QString>(QStringLiteral("phoneNumber"), i18n("unknown number")); | ||
46 | const QString contactName = np.get<QString>(QStringLiteral("contactName"), phoneNumber); | 46 | const QString contactName = np.get<QString>(QStringLiteral("contactName"), phoneNumber); | ||
47 | const QByteArray phoneThumbnail = QByteArray::fromBase64(np.get<QByteArray>(QStringLiteral("phoneThumbnail"), "")); | 47 | const QByteArray phoneThumbnail = QByteArray::fromBase64(np.get<QByteArray>(QStringLiteral("phoneThumbnail"), "")); | ||
48 | 48 | | |||
49 | // In case telepathy can handle the message, don't do anything else | 49 | // In case telepathy can handle the message, don't do anything else | ||
50 | if (event == QLatin1String("sms") && m_telepathyInterface.isValid()) { | 50 | if (event == QLatin1String("sms") && m_telepathyInterface.isValid()) { | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 101 | } else { | |||
102 | notification->setIconName(icon); | 102 | notification->setIconName(icon); | ||
103 | } | 103 | } | ||
104 | notification->setComponentName(QStringLiteral("kdeconnect")); | 104 | notification->setComponentName(QStringLiteral("kdeconnect")); | ||
105 | notification->setTitle(title); | 105 | notification->setTitle(title); | ||
106 | notification->setText(content); | 106 | notification->setText(content); | ||
107 | 107 | | |||
108 | if (event == QLatin1String("ringing")) { | 108 | if (event == QLatin1String("ringing")) { | ||
109 | notification->setActions( QStringList(i18n("Mute Call")) ); | 109 | notification->setActions( QStringList(i18n("Mute Call")) ); | ||
110 | connect(notification, &KNotification::action1Activated, this, &TelephonyPlugin::sendMutePackage); | 110 | connect(notification, &KNotification::action1Activated, this, &TelephonyPlugin::sendMutePacket); | ||
111 | } else if (event == QLatin1String("sms")) { | 111 | } else if (event == QLatin1String("sms")) { | ||
112 | const QString messageBody = np.get<QString>(QStringLiteral("messageBody"),QLatin1String("")); | 112 | const QString messageBody = np.get<QString>(QStringLiteral("messageBody"),QLatin1String("")); | ||
113 | notification->setActions( QStringList(i18n("Reply")) ); | 113 | notification->setActions( QStringList(i18n("Reply")) ); | ||
114 | notification->setProperty("phoneNumber", phoneNumber); | 114 | notification->setProperty("phoneNumber", phoneNumber); | ||
115 | notification->setProperty("contactName", contactName); | 115 | notification->setProperty("contactName", contactName); | ||
116 | notification->setProperty("originalMessage", messageBody); | 116 | notification->setProperty("originalMessage", messageBody); | ||
117 | connect(notification, &KNotification::action1Activated, this, &TelephonyPlugin::showSendSmsDialog); | 117 | connect(notification, &KNotification::action1Activated, this, &TelephonyPlugin::showSendSmsDialog); | ||
118 | } | 118 | } | ||
119 | 119 | | |||
120 | return notification; | 120 | return notification; | ||
121 | 121 | | |||
122 | } | 122 | } | ||
123 | 123 | | |||
124 | bool TelephonyPlugin::receivePackage(const NetworkPackage& np) | 124 | bool TelephonyPlugin::receivePacket(const NetworkPacket& np) | ||
125 | { | 125 | { | ||
126 | if (np.get<bool>(QStringLiteral("isCancel"))) { | 126 | if (np.get<bool>(QStringLiteral("isCancel"))) { | ||
127 | 127 | | |||
128 | //TODO: Clear the old notification | 128 | //TODO: Clear the old notification | ||
129 | return true; | 129 | return true; | ||
130 | } | 130 | } | ||
131 | 131 | | |||
132 | KNotification* n = createNotification(np); | 132 | KNotification* n = createNotification(np); | ||
133 | if (n != nullptr) n->sendEvent(); | 133 | if (n != nullptr) n->sendEvent(); | ||
134 | 134 | | |||
135 | return true; | 135 | return true; | ||
136 | } | 136 | } | ||
137 | 137 | | |||
138 | void TelephonyPlugin::sendMutePackage() | 138 | void TelephonyPlugin::sendMutePacket() | ||
139 | { | 139 | { | ||
140 | NetworkPackage package(PACKAGE_TYPE_TELEPHONY_REQUEST, {{"action", "mute"}}); | 140 | NetworkPacket packet(PACKET_TYPE_TELEPHONY_REQUEST, {{"action", "mute"}}); | ||
141 | sendPackage(package); | 141 | sendPacket(packet); | ||
142 | } | 142 | } | ||
143 | 143 | | |||
144 | void TelephonyPlugin::sendSms(const QString& phoneNumber, const QString& messageBody) | 144 | void TelephonyPlugin::sendSms(const QString& phoneNumber, const QString& messageBody) | ||
145 | { | 145 | { | ||
146 | NetworkPackage np(PACKAGE_TYPE_SMS_REQUEST, { | 146 | NetworkPacket np(PACKET_TYPE_SMS_REQUEST, { | ||
147 | {"sendSms", true}, | 147 | {"sendSms", true}, | ||
148 | {"phoneNumber", phoneNumber}, | 148 | {"phoneNumber", phoneNumber}, | ||
149 | {"messageBody", messageBody} | 149 | {"messageBody", messageBody} | ||
150 | }); | 150 | }); | ||
151 | sendPackage(np); | 151 | sendPacket(np); | ||
152 | } | 152 | } | ||
153 | 153 | | |||
154 | void TelephonyPlugin::showSendSmsDialog() | 154 | void TelephonyPlugin::showSendSmsDialog() | ||
155 | { | 155 | { | ||
156 | QString phoneNumber = sender()->property("phoneNumber").toString(); | 156 | QString phoneNumber = sender()->property("phoneNumber").toString(); | ||
157 | QString contactName = sender()->property("contactName").toString(); | 157 | QString contactName = sender()->property("contactName").toString(); | ||
158 | QString originalMessage = sender()->property("originalMessage").toString(); | 158 | QString originalMessage = sender()->property("originalMessage").toString(); | ||
159 | SendReplyDialog* dialog = new SendReplyDialog(originalMessage, phoneNumber, contactName); | 159 | SendReplyDialog* dialog = new SendReplyDialog(originalMessage, phoneNumber, contactName); | ||
Show All 11 Lines |