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 "sendreplydialog.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) | ||
35 | , mLastId(0) | 37 | , mLastId(0) | ||
apol: Why do you need telepathy here? This looks like it belongs to the telephony plugin | |||||
36 | { | 38 | { | ||
37 | 39 | | |||
38 | } | 40 | } | ||
39 | 41 | | |||
40 | NotificationsDbusInterface::~NotificationsDbusInterface() | 42 | NotificationsDbusInterface::~NotificationsDbusInterface() | ||
41 | { | 43 | { | ||
42 | qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Destroying NotificationsDbusInterface"; | 44 | qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Destroying NotificationsDbusInterface"; | ||
43 | } | 45 | } | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 97 | if (mInternalIdToPublicId.contains(internalId)) { | |||
96 | removeNotification(internalId); | 98 | removeNotification(internalId); | ||
97 | } | 99 | } | ||
98 | 100 | | |||
99 | //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "addNotification" << internalId; | 101 | //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "addNotification" << internalId; | ||
100 | 102 | | |||
101 | connect(noti, &Notification::dismissRequested, | 103 | connect(noti, &Notification::dismissRequested, | ||
102 | this, &NotificationsDbusInterface::dismissRequested); | 104 | this, &NotificationsDbusInterface::dismissRequested); | ||
103 | 105 | | |||
106 | connect(noti, &Notification::replyRequested, this, [this,noti]{ | ||||
107 | replyRequested(noti); | ||||
108 | }); | ||||
109 | | ||||
104 | const QString& publicId = newId(); | 110 | const QString& publicId = newId(); | ||
105 | mNotifications[publicId] = noti; | 111 | mNotifications[publicId] = noti; | ||
106 | mInternalIdToPublicId[internalId] = publicId; | 112 | mInternalIdToPublicId[internalId] = publicId; | ||
107 | 113 | | |||
108 | QDBusConnection::sessionBus().registerObject(mDevice->dbusPath()+"/notifications/"+publicId, noti, QDBusConnection::ExportScriptableContents); | 114 | QDBusConnection::sessionBus().registerObject(mDevice->dbusPath()+"/notifications/"+publicId, noti, QDBusConnection::ExportScriptableContents); | ||
109 | Q_EMIT notificationPosted(publicId); | 115 | Q_EMIT notificationPosted(publicId); | ||
110 | } | 116 | } | ||
111 | 117 | | |||
Show All 29 Lines | 143 | { | |||
141 | 147 | | |||
142 | //Workaround: we erase notifications without waiting a repsonse from the | 148 | //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 | 149 | //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 | 150 | //notification no longer exists. Ideally, each time we reach the phone | ||
145 | //after some time disconnected we should re-sync all the notifications. | 151 | //after some time disconnected we should re-sync all the notifications. | ||
146 | removeNotification(internalId); | 152 | removeNotification(internalId); | ||
147 | } | 153 | } | ||
148 | 154 | | |||
155 | void NotificationsDbusInterface::replyRequested(Notification* noti) | ||||
156 | { | ||||
157 | QString replyId = noti->replyId(); | ||||
158 | QString appName = noti->appName(); | ||||
159 | QString originalMessage = noti->ticker(); | ||||
160 | SendReplyDialog* dialog = new SendReplyDialog(originalMessage, replyId, appName); | ||||
161 | connect(dialog, &SendReplyDialog::sendReply, this, &NotificationsDbusInterface::sendReply); | ||||
162 | dialog->show(); | ||||
163 | } | ||||
164 | | ||||
165 | void NotificationsDbusInterface::sendReply(const QString& replyId, const QString& message) | ||||
166 | { | ||||
167 | NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REPLY); | ||||
168 | np.set<QString>(QStringLiteral("requestReplyId"), replyId); | ||||
169 | np.set<QString>(QStringLiteral("message"), message); | ||||
170 | mPlugin->sendPackage(np); | ||||
171 | } | ||||
172 | | ||||
149 | QString NotificationsDbusInterface::newId() | 173 | QString NotificationsDbusInterface::newId() | ||
150 | { | 174 | { | ||
151 | return QString::number(++mLastId); | 175 | return QString::number(++mLastId); | ||
152 | } | 176 | } |
Why do you need telepathy here? This looks like it belongs to the telephony plugin