Changeset View
Changeset View
Standalone View
Standalone View
plugins/notifications/notificationsdbusinterface.cpp
Show All 17 Lines | |||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "notificationsdbusinterface.h" | 21 | #include "notificationsdbusinterface.h" | ||
22 | #include "notification_debug.h" | 22 | #include "notification_debug.h" | ||
23 | #include "notification.h" | 23 | #include "notification.h" | ||
24 | 24 | | |||
25 | #include <QDBusConnection> | 25 | #include <QDBusConnection> | ||
26 | #include <QDBusReply> | ||||
26 | #include <core/device.h> | 27 | #include <core/device.h> | ||
27 | #include <core/kdeconnectplugin.h> | 28 | #include <core/kdeconnectplugin.h> | ||
28 | 29 | | |||
29 | #include "notificationsplugin.h" | 30 | #include "notificationsplugin.h" | ||
31 | #include "sendsmsdialog.h" | ||||
30 | 32 | | |||
31 | NotificationsDbusInterface::NotificationsDbusInterface(KdeConnectPlugin* plugin) | 33 | NotificationsDbusInterface::NotificationsDbusInterface(KdeConnectPlugin* plugin) | ||
32 | : QDBusAbstractAdaptor(const_cast<Device*>(plugin->device())) | 34 | : QDBusAbstractAdaptor(const_cast<Device*>(plugin->device())) | ||
33 | , mDevice(plugin->device()) | 35 | , mDevice(plugin->device()) | ||
34 | , mPlugin(plugin) | 36 | , mPlugin(plugin) | ||
37 | , m_telepathyInterface(QStringLiteral("org.freedesktop.Telepathy.ConnectionManager.kdeconnect"), QStringLiteral("/kdeconnect")) | ||||
apol: Why do you need telepathy here? This looks like it belongs to the telephony plugin | |||||
35 | , mLastId(0) | 38 | , mLastId(0) | ||
36 | { | 39 | { | ||
37 | 40 | | |||
38 | } | 41 | } | ||
39 | 42 | | |||
40 | NotificationsDbusInterface::~NotificationsDbusInterface() | 43 | NotificationsDbusInterface::~NotificationsDbusInterface() | ||
41 | { | 44 | { | ||
42 | qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Destroying NotificationsDbusInterface"; | 45 | qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Destroying NotificationsDbusInterface"; | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 98 | if (mInternalIdToPublicId.contains(internalId)) { | |||
96 | removeNotification(internalId); | 99 | removeNotification(internalId); | ||
97 | } | 100 | } | ||
98 | 101 | | |||
99 | //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "addNotification" << internalId; | 102 | //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "addNotification" << internalId; | ||
100 | 103 | | |||
101 | connect(noti, &Notification::dismissRequested, | 104 | connect(noti, &Notification::dismissRequested, | ||
102 | this, &NotificationsDbusInterface::dismissRequested); | 105 | this, &NotificationsDbusInterface::dismissRequested); | ||
103 | 106 | | |||
107 | connect(noti, &Notification::replyRequested, this, [this,noti]{ | ||||
108 | replyRequested(noti); | ||||
109 | }); | ||||
110 | | ||||
104 | const QString& publicId = newId(); | 111 | const QString& publicId = newId(); | ||
105 | mNotifications[publicId] = noti; | 112 | mNotifications[publicId] = noti; | ||
106 | mInternalIdToPublicId[internalId] = publicId; | 113 | mInternalIdToPublicId[internalId] = publicId; | ||
107 | 114 | | |||
108 | QDBusConnection::sessionBus().registerObject(mDevice->dbusPath()+"/notifications/"+publicId, noti, QDBusConnection::ExportScriptableContents); | 115 | QDBusConnection::sessionBus().registerObject(mDevice->dbusPath()+"/notifications/"+publicId, noti, QDBusConnection::ExportScriptableContents); | ||
109 | Q_EMIT notificationPosted(publicId); | 116 | Q_EMIT notificationPosted(publicId); | ||
110 | } | 117 | } | ||
111 | 118 | | |||
Show All 29 Lines | 144 | { | |||
141 | 148 | | |||
142 | //Workaround: we erase notifications without waiting a repsonse from the | 149 | //Workaround: we erase notifications without waiting a repsonse from the | ||
143 | //phone because we won't receive a response if we are out of sync and this | 150 | //phone because we won't receive a response if we are out of sync and this | ||
144 | //notification no longer exists. Ideally, each time we reach the phone | 151 | //notification no longer exists. Ideally, each time we reach the phone | ||
145 | //after some time disconnected we should re-sync all the notifications. | 152 | //after some time disconnected we should re-sync all the notifications. | ||
146 | removeNotification(internalId); | 153 | removeNotification(internalId); | ||
147 | } | 154 | } | ||
148 | 155 | | |||
156 | void NotificationsDbusInterface::replyRequested(Notification* noti) | ||||
157 | { | ||||
158 | QString phoneNumber = noti->replyId(); | ||||
159 | QString contactName = noti->appName(); | ||||
160 | QString originalMessage = noti->ticker(); | ||||
161 | SendSmsDialog* dialog = new SendSmsDialog(originalMessage, phoneNumber, contactName); | ||||
162 | connect(dialog, &SendSmsDialog::sendSms, this, &NotificationsDbusInterface::sendReply); | ||||
163 | dialog->show(); | ||||
164 | } | ||||
165 | | ||||
166 | void NotificationsDbusInterface::sendReply(const QString& replyId, const QString& message) | ||||
167 | { | ||||
168 | NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REPLY); | ||||
169 | np.set<QString>(QStringLiteral("requestReplyId"), replyId); | ||||
170 | np.set<QString>(QStringLiteral("message"), message); | ||||
171 | mPlugin->sendPackage(np); | ||||
172 | } | ||||
173 | | ||||
149 | QString NotificationsDbusInterface::newId() | 174 | QString NotificationsDbusInterface::newId() | ||
150 | { | 175 | { | ||
151 | return QString::number(++mLastId); | 176 | return QString::number(++mLastId); | ||
152 | } | 177 | } |
Why do you need telepathy here? This looks like it belongs to the telephony plugin