Changeset View
Changeset View
Standalone View
Standalone View
plugins/notifications/notificationsdbusinterface.cpp
Context not available. | |||||
32 | 32 | | |||
---|---|---|---|---|---|
33 | NotificationsDbusInterface::NotificationsDbusInterface(KdeConnectPlugin* plugin) | 33 | NotificationsDbusInterface::NotificationsDbusInterface(KdeConnectPlugin* plugin) | ||
34 | : QDBusAbstractAdaptor(const_cast<Device*>(plugin->device())) | 34 | : QDBusAbstractAdaptor(const_cast<Device*>(plugin->device())) | ||
35 | , mDevice(plugin->device()) | 35 | , m_device(plugin->device()) | ||
36 | , mPlugin(plugin) | 36 | , m_plugin(plugin) | ||
37 | , mLastId(0) | 37 | , m_lastId(0) | ||
38 | { | 38 | { | ||
39 | 39 | | |||
40 | } | 40 | } | ||
Context not available. | |||||
46 | 46 | | |||
47 | void NotificationsDbusInterface::clearNotifications() | 47 | void NotificationsDbusInterface::clearNotifications() | ||
48 | { | 48 | { | ||
49 | qDeleteAll(mNotifications); | 49 | qDeleteAll(m_notifications); | ||
50 | mNotifications.clear(); | 50 | m_notifications.clear(); | ||
51 | Q_EMIT allNotificationsRemoved(); | 51 | Q_EMIT allNotificationsRemoved(); | ||
52 | } | 52 | } | ||
53 | 53 | | |||
54 | QStringList NotificationsDbusInterface::activeNotifications() | 54 | QStringList NotificationsDbusInterface::activeNotifications() | ||
55 | { | 55 | { | ||
56 | return mNotifications.keys(); | 56 | return m_notifications.keys(); | ||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | void NotificationsDbusInterface::processPackage(const NetworkPackage& np) | 59 | void NotificationsDbusInterface::processPackage(const NetworkPackage& np) | ||
Context not available. | |||||
65 | id = id.mid(id.indexOf(QLatin1String("::")) + 2); | 65 | id = id.mid(id.indexOf(QLatin1String("::")) + 2); | ||
66 | removeNotification(id); | 66 | removeNotification(id); | ||
67 | } else if (np.get<bool>(QStringLiteral("isRequest"))) { | 67 | } else if (np.get<bool>(QStringLiteral("isRequest"))) { | ||
68 | for (const auto& n : qAsConst(mNotifications)) { | 68 | for (const auto& n : qAsConst(m_notifications)) { | ||
69 | NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST, { | 69 | NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST, { | ||
70 | {"id", n->internalId()}, | 70 | {"id", n->internalId()}, | ||
71 | {"appName", n->appName()}, | 71 | {"appName", n->appName()}, | ||
Context not available. | |||||
73 | {"isClearable", n->dismissable()}, | 73 | {"isClearable", n->dismissable()}, | ||
74 | {"requestAnswer", true} | 74 | {"requestAnswer", true} | ||
75 | }); | 75 | }); | ||
76 | mPlugin->sendPackage(np); | 76 | m_plugin->sendPackage(np); | ||
77 | } | 77 | } | ||
78 | } else if(np.get<bool>(QStringLiteral("requestAnswer"), false)) { | 78 | } else if(np.get<bool>(QStringLiteral("requestAnswer"), false)) { | ||
79 | 79 | | |||
80 | } else { | 80 | } else { | ||
81 | QString id = np.get<QString>(QStringLiteral("id")); | 81 | QString id = np.get<QString>(QStringLiteral("id")); | ||
82 | 82 | | |||
83 | Notification* noti; | 83 | if (!m_internalIdToPublicId.contains(id)) { | ||
84 | 84 | Notification* noti = new Notification(np, this); | |||
85 | if (!mInternalIdToPublicId.contains(id)) { | 85 | addNotification(noti); | ||
86 | noti = new Notification(np, this); | | |||
87 | } else { | 86 | } else { | ||
88 | QString pubId = mInternalIdToPublicId[id]; | 87 | QString pubId = m_internalIdToPublicId[id]; | ||
89 | noti = mNotifications[pubId]; | 88 | m_notifications[pubId]->update(np); | ||
90 | noti->update(np); | | |||
91 | } | 89 | } | ||
92 | | ||||
93 | connect(noti, &Notification::ready, this, [this, noti]{ | | |||
94 | addNotification(noti); | | |||
95 | }); | | |||
96 | } | 90 | } | ||
97 | } | 91 | } | ||
98 | 92 | | |||
Context not available. | |||||
100 | { | 94 | { | ||
101 | const QString& internalId = noti->internalId(); | 95 | const QString& internalId = noti->internalId(); | ||
102 | 96 | | |||
103 | if (mInternalIdToPublicId.contains(internalId)) { | 97 | if (m_internalIdToPublicId.contains(internalId)) { | ||
104 | removeNotification(internalId, KeepNotification); | 98 | removeNotification(internalId); | ||
105 | } | 99 | } | ||
106 | 100 | | |||
107 | //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "addNotification" << internalId; | 101 | //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "addNotification" << internalId; | ||
108 | 102 | | |||
109 | connect(noti, &Notification::dismissRequested, | 103 | connect(noti, &Notification::dismissRequested, | ||
110 | this, &NotificationsDbusInterface::dismissRequested); | 104 | this, &NotificationsDbusInterface::dismissRequested); | ||
111 | 105 | | |||
112 | connect(noti, &Notification::replyRequested, this, [this,noti]{ | 106 | connect(noti, &Notification::replyRequested, this, [this,noti]{ | ||
113 | replyRequested(noti); | 107 | replyRequested(noti); | ||
114 | }); | 108 | }); | ||
115 | 109 | | |||
116 | const QString& publicId = newId(); | 110 | const QString& publicId = newId(); | ||
117 | mNotifications[publicId] = noti; | 111 | m_notifications[publicId] = noti; | ||
118 | mInternalIdToPublicId[internalId] = publicId; | 112 | m_internalIdToPublicId[internalId] = publicId; | ||
119 | 113 | | |||
120 | QDBusConnection::sessionBus().registerObject(mDevice->dbusPath()+"/notifications/"+publicId, noti, QDBusConnection::ExportScriptableContents); | 114 | QDBusConnection::sessionBus().registerObject(m_device->dbusPath()+"/notifications/"+publicId, noti, QDBusConnection::ExportScriptableContents); | ||
121 | Q_EMIT notificationPosted(publicId); | 115 | Q_EMIT notificationPosted(publicId); | ||
122 | } | 116 | } | ||
123 | 117 | | |||
124 | void NotificationsDbusInterface::removeNotification(const QString& internalId, RemoveType removetype) | 118 | void NotificationsDbusInterface::removeNotification(const QString& internalId) | ||
125 | { | 119 | { | ||
126 | //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "removeNotification" << internalId; | 120 | //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "removeNotification" << internalId; | ||
127 | 121 | | |||
128 | if (!mInternalIdToPublicId.contains(internalId)) { | 122 | if (!m_internalIdToPublicId.contains(internalId)) { | ||
129 | //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found noti by internal Id: " << internalId; | 123 | qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found noti by internal Id: " << internalId; | ||
130 | return; | 124 | return; | ||
131 | } | 125 | } | ||
132 | 126 | | |||
133 | QString publicId = mInternalIdToPublicId.take(internalId); | 127 | QString publicId = m_internalIdToPublicId.take(internalId); | ||
134 | 128 | | |||
135 | Notification* noti = mNotifications.take(publicId); | 129 | Notification* noti = m_notifications.take(publicId); | ||
136 | if (!noti) { | 130 | if (!noti) { | ||
137 | //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found noti by public Id: " << publicId; | 131 | qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found noti by public Id: " << publicId; | ||
138 | return; | 132 | return; | ||
139 | } | 133 | } | ||
140 | 134 | | |||
141 | //Deleting the notification will unregister it automatically | 135 | //Deleting the notification will unregister it automatically | ||
142 | if (removetype==KeepNotification){ | 136 | //QDBusConnection::sessionBus().unregisterObject(mDevice->dbusPath()+"/notifications/"+publicId); | ||
143 | QDBusConnection::sessionBus().unregisterObject(mDevice->dbusPath()+"/notifications/"+publicId); | 137 | noti->deleteLater(); | ||
144 | } else if (removetype==DestroyNotification){ | | |||
145 | noti->deleteLater(); | | |||
146 | } | | |||
147 | 138 | | |||
148 | Q_EMIT notificationRemoved(publicId); | 139 | Q_EMIT notificationRemoved(publicId); | ||
149 | } | 140 | } | ||
Context not available. | |||||
152 | { | 143 | { | ||
153 | NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST); | 144 | NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REQUEST); | ||
154 | np.set<QString>(QStringLiteral("cancel"), internalId); | 145 | np.set<QString>(QStringLiteral("cancel"), internalId); | ||
155 | mPlugin->sendPackage(np); | 146 | m_plugin->sendPackage(np); | ||
156 | 147 | | |||
157 | //Workaround: we erase notifications without waiting a repsonse from the | 148 | //Workaround: we erase notifications without waiting a repsonse from the | ||
158 | //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 | ||
Context not available. | |||||
176 | NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REPLY); | 167 | NetworkPackage np(PACKAGE_TYPE_NOTIFICATION_REPLY); | ||
177 | np.set<QString>(QStringLiteral("requestReplyId"), replyId); | 168 | np.set<QString>(QStringLiteral("requestReplyId"), replyId); | ||
178 | np.set<QString>(QStringLiteral("message"), message); | 169 | np.set<QString>(QStringLiteral("message"), message); | ||
179 | mPlugin->sendPackage(np); | 170 | m_plugin->sendPackage(np); | ||
180 | } | 171 | } | ||
181 | 172 | | |||
182 | QString NotificationsDbusInterface::newId() | 173 | QString NotificationsDbusInterface::newId() | ||
183 | { | 174 | { | ||
184 | return QString::number(++mLastId); | 175 | return QString::number(++m_lastId); | ||
185 | } | 176 | } | ||
Context not available. |