2013-08-20 12:55:03 +01:00
|
|
|
/**
|
|
|
|
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License or (at your option) version 3 or any later version
|
|
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
|
|
* defined in Section 14 of version 3 of the license.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-03-23 16:29:26 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2013-08-20 12:55:03 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "notificationsdbusinterface.h"
|
2014-09-21 23:45:06 +01:00
|
|
|
#include "notification_debug.h"
|
2017-04-13 20:31:46 +01:00
|
|
|
#include "notification.h"
|
2013-08-20 12:55:03 +01:00
|
|
|
|
2014-07-01 00:23:21 +01:00
|
|
|
#include <core/device.h>
|
|
|
|
#include <core/kdeconnectplugin.h>
|
2019-06-09 16:28:49 +01:00
|
|
|
#include <dbushelper.h>
|
2014-07-01 00:23:21 +01:00
|
|
|
|
2013-11-06 21:16:55 +00:00
|
|
|
#include "notificationsplugin.h"
|
2017-05-31 14:33:21 +01:00
|
|
|
#include "sendreplydialog.h"
|
2013-11-06 21:16:55 +00:00
|
|
|
|
Build kdeconnect on sailfish and port some simple plugins
Summary:
Below is a lost of the commits, but, in summary
Port the build system for Sailfish, which means selectively building only the bits we need/can, and only against the KF5 libs that are available.
Allow to build on Qt 5.6
Switch from knotification to nemo notification (not complete!)
Add a very simple example sailfish app.
Note, there is still much missing functionality. Notifications dont work, pairing sort of works but not really, but when it is paired you can send a ping to the desktop client
Dont build kio for Sailfish
Port core build system
Port daemon buld system
Require CoreAddons on Sailfish
Port plugins build for sailfish and include the ping plugin for now
Final build changes for sailfish.
Disable tests and other not needed parts
Add includes for QCA
Fix build errors on sailfish
Get core/ to build on sailfish
Get interfaces/ to build on sailfish
Build daemon on sailfish
On sailfish, dont install the kcm file
Start port plugin to sailfish
Fixup installed files
Add sfos app
Hack declarative plugin to give a public interface
Build sfos app
Compile declarativeplugin into the sfos app for now
Redefine qAsConst for qt 5.6
Packaging fixes
Use official icon
Package .desktop
Reviewers: #kde_connect, apol, nicolasfella, albertvaka
Reviewed By: #kde_connect, apol, nicolasfella, albertvaka
Subscribers: kdeconnect, andyholmes, albertvaka, kossebau, mtijink, vonreth, apol, #kde_connect, nicolasfella
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D10703
2018-08-02 20:10:59 +01:00
|
|
|
//In older Qt released, qAsConst isnt available
|
|
|
|
#include "qtcompat_p.h"
|
|
|
|
|
2014-06-14 19:35:00 +01:00
|
|
|
NotificationsDbusInterface::NotificationsDbusInterface(KdeConnectPlugin* plugin)
|
2014-07-01 00:23:21 +01:00
|
|
|
: QDBusAbstractAdaptor(const_cast<Device*>(plugin->device()))
|
2017-09-03 20:39:44 +01:00
|
|
|
, m_device(plugin->device())
|
|
|
|
, m_plugin(plugin)
|
|
|
|
, m_lastId(0)
|
2013-08-20 12:55:03 +01:00
|
|
|
{
|
2017-04-13 20:31:46 +01:00
|
|
|
|
2013-08-20 12:55:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
NotificationsDbusInterface::~NotificationsDbusInterface()
|
2015-06-15 02:59:53 +01:00
|
|
|
{
|
2015-09-10 15:36:03 +01:00
|
|
|
qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Destroying NotificationsDbusInterface";
|
2015-06-15 02:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationsDbusInterface::clearNotifications()
|
2013-08-20 12:55:03 +01:00
|
|
|
{
|
2017-09-03 20:39:44 +01:00
|
|
|
qDeleteAll(m_notifications);
|
|
|
|
m_notifications.clear();
|
2016-04-05 23:25:12 +01:00
|
|
|
Q_EMIT allNotificationsRemoved();
|
2013-08-20 12:55:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList NotificationsDbusInterface::activeNotifications()
|
|
|
|
{
|
2017-09-03 20:39:44 +01:00
|
|
|
return m_notifications.keys();
|
2013-08-20 12:55:03 +01:00
|
|
|
}
|
|
|
|
|
2018-03-24 20:28:35 +00:00
|
|
|
void NotificationsDbusInterface::notificationReady()
|
|
|
|
{
|
|
|
|
Notification* noti = static_cast<Notification*>(sender());
|
|
|
|
disconnect(noti, &Notification::ready, this, &NotificationsDbusInterface::notificationReady);
|
|
|
|
addNotification(noti);
|
|
|
|
}
|
|
|
|
|
2018-03-04 19:48:51 +00:00
|
|
|
void NotificationsDbusInterface::processPacket(const NetworkPacket& np)
|
2013-08-20 12:55:03 +01:00
|
|
|
{
|
2016-11-26 14:38:08 +00:00
|
|
|
if (np.get<bool>(QStringLiteral("isCancel"))) {
|
|
|
|
QString id = np.get<QString>(QStringLiteral("id"));
|
2015-09-10 15:36:03 +01:00
|
|
|
// cut off kdeconnect-android's prefix if there:
|
2016-11-26 14:38:08 +00:00
|
|
|
if (id.startsWith(QLatin1String("org.kde.kdeconnect_tp::")))
|
|
|
|
id = id.mid(id.indexOf(QLatin1String("::")) + 2);
|
2015-09-10 15:36:03 +01:00
|
|
|
removeNotification(id);
|
2019-01-24 08:11:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString id = np.get<QString>(QStringLiteral("id"));
|
2013-09-20 14:54:30 +01:00
|
|
|
|
2019-01-24 08:11:24 +00:00
|
|
|
Notification* noti = nullptr;
|
2017-11-06 03:12:16 +00:00
|
|
|
|
2019-01-24 08:11:24 +00:00
|
|
|
if (!m_internalIdToPublicId.contains(id)) {
|
2019-06-02 15:03:11 +01:00
|
|
|
noti = new Notification(np, m_plugin->device(), this);
|
2019-01-24 08:11:24 +00:00
|
|
|
|
|
|
|
if (noti->isReady()) {
|
|
|
|
addNotification(noti);
|
2017-04-13 20:31:46 +01:00
|
|
|
} else {
|
2019-01-24 08:11:24 +00:00
|
|
|
connect(noti, &Notification::ready, this, &NotificationsDbusInterface::notificationReady);
|
2013-08-22 03:39:04 +01:00
|
|
|
}
|
2019-01-24 08:11:24 +00:00
|
|
|
} else {
|
|
|
|
QString pubId = m_internalIdToPublicId.value(id);
|
|
|
|
noti = m_notifications.value(pubId);
|
2013-08-20 12:55:03 +01:00
|
|
|
}
|
2019-01-24 08:11:24 +00:00
|
|
|
noti->update(np);
|
2013-08-20 12:55:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationsDbusInterface::addNotification(Notification* noti)
|
|
|
|
{
|
|
|
|
const QString& internalId = noti->internalId();
|
|
|
|
|
2017-09-03 20:39:44 +01:00
|
|
|
if (m_internalIdToPublicId.contains(internalId)) {
|
2013-08-20 12:55:03 +01:00
|
|
|
removeNotification(internalId);
|
|
|
|
}
|
|
|
|
|
2016-05-25 21:33:58 +01:00
|
|
|
//qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "addNotification" << internalId;
|
2016-03-08 00:01:44 +00:00
|
|
|
|
2015-10-17 23:32:13 +01:00
|
|
|
connect(noti, &Notification::dismissRequested,
|
|
|
|
this, &NotificationsDbusInterface::dismissRequested);
|
Build kdeconnect on sailfish and port some simple plugins
Summary:
Below is a lost of the commits, but, in summary
Port the build system for Sailfish, which means selectively building only the bits we need/can, and only against the KF5 libs that are available.
Allow to build on Qt 5.6
Switch from knotification to nemo notification (not complete!)
Add a very simple example sailfish app.
Note, there is still much missing functionality. Notifications dont work, pairing sort of works but not really, but when it is paired you can send a ping to the desktop client
Dont build kio for Sailfish
Port core build system
Port daemon buld system
Require CoreAddons on Sailfish
Port plugins build for sailfish and include the ping plugin for now
Final build changes for sailfish.
Disable tests and other not needed parts
Add includes for QCA
Fix build errors on sailfish
Get core/ to build on sailfish
Get interfaces/ to build on sailfish
Build daemon on sailfish
On sailfish, dont install the kcm file
Start port plugin to sailfish
Fixup installed files
Add sfos app
Hack declarative plugin to give a public interface
Build sfos app
Compile declarativeplugin into the sfos app for now
Redefine qAsConst for qt 5.6
Packaging fixes
Use official icon
Package .desktop
Reviewers: #kde_connect, apol, nicolasfella, albertvaka
Reviewed By: #kde_connect, apol, nicolasfella, albertvaka
Subscribers: kdeconnect, andyholmes, albertvaka, kossebau, mtijink, vonreth, apol, #kde_connect, nicolasfella
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D10703
2018-08-02 20:10:59 +01:00
|
|
|
|
|
|
|
connect(noti, &Notification::replyRequested, this, [this,noti]{
|
|
|
|
replyRequested(noti);
|
2017-05-31 14:33:21 +01:00
|
|
|
});
|
2013-08-20 12:55:03 +01:00
|
|
|
|
2019-02-08 22:47:41 +00:00
|
|
|
connect(noti, &Notification::actionTriggered, this, &NotificationsDbusInterface::sendAction);
|
|
|
|
|
2013-08-20 12:55:03 +01:00
|
|
|
const QString& publicId = newId();
|
2017-09-03 20:39:44 +01:00
|
|
|
m_notifications[publicId] = noti;
|
|
|
|
m_internalIdToPublicId[internalId] = publicId;
|
2013-08-20 12:55:03 +01:00
|
|
|
|
2019-06-10 15:40:28 +01:00
|
|
|
DbusHelper::sessionBus().registerObject(m_device->dbusPath() + QStringLiteral("/notifications/") + publicId, noti, QDBusConnection::ExportScriptableContents);
|
2013-08-20 12:55:03 +01:00
|
|
|
Q_EMIT notificationPosted(publicId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationsDbusInterface::removeNotification(const QString& internalId)
|
|
|
|
{
|
2016-05-25 21:33:58 +01:00
|
|
|
//qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "removeNotification" << internalId;
|
2013-08-20 12:55:03 +01:00
|
|
|
|
2017-09-03 20:39:44 +01:00
|
|
|
if (!m_internalIdToPublicId.contains(internalId)) {
|
2016-05-25 21:33:58 +01:00
|
|
|
qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found noti by internal Id: " << internalId;
|
2013-08-20 12:55:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-03 20:39:44 +01:00
|
|
|
QString publicId = m_internalIdToPublicId.take(internalId);
|
2013-08-20 12:55:03 +01:00
|
|
|
|
2017-09-03 20:39:44 +01:00
|
|
|
Notification* noti = m_notifications.take(publicId);
|
2013-10-11 14:19:23 +01:00
|
|
|
if (!noti) {
|
2016-05-25 21:33:58 +01:00
|
|
|
qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found noti by public Id: " << publicId;
|
2013-08-20 12:55:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-20 13:05:22 +01:00
|
|
|
//Deleting the notification will unregister it automatically
|
2019-06-09 16:28:49 +01:00
|
|
|
//DbusHelper::sessionBus().unregisterObject(mDevice->dbusPath()+"/notifications/"+publicId);
|
2013-08-20 12:55:03 +01:00
|
|
|
noti->deleteLater();
|
|
|
|
|
|
|
|
Q_EMIT notificationRemoved(publicId);
|
|
|
|
}
|
|
|
|
|
2015-10-17 23:32:13 +01:00
|
|
|
void NotificationsDbusInterface::dismissRequested(const QString& internalId)
|
2013-08-20 12:55:03 +01:00
|
|
|
{
|
2018-03-04 19:48:51 +00:00
|
|
|
NetworkPacket np(PACKET_TYPE_NOTIFICATION_REQUEST);
|
2016-11-26 14:38:08 +00:00
|
|
|
np.set<QString>(QStringLiteral("cancel"), internalId);
|
2018-03-04 19:48:51 +00:00
|
|
|
m_plugin->sendPacket(np);
|
2013-08-20 12:55:03 +01:00
|
|
|
|
2018-10-07 19:23:20 +01:00
|
|
|
//Workaround: we erase notifications without waiting a response from the
|
2014-06-15 20:39:23 +01:00
|
|
|
//phone because we won't receive a response if we are out of sync and this
|
|
|
|
//notification no longer exists. Ideally, each time we reach the phone
|
|
|
|
//after some time disconnected we should re-sync all the notifications.
|
|
|
|
removeNotification(internalId);
|
2013-08-20 12:55:03 +01:00
|
|
|
}
|
|
|
|
|
2017-05-31 14:33:21 +01:00
|
|
|
void NotificationsDbusInterface::replyRequested(Notification* noti)
|
|
|
|
{
|
|
|
|
QString replyId = noti->replyId();
|
|
|
|
QString appName = noti->appName();
|
|
|
|
QString originalMessage = noti->ticker();
|
|
|
|
SendReplyDialog* dialog = new SendReplyDialog(originalMessage, replyId, appName);
|
|
|
|
connect(dialog, &SendReplyDialog::sendReply, this, &NotificationsDbusInterface::sendReply);
|
|
|
|
dialog->show();
|
2017-08-03 16:23:12 +01:00
|
|
|
dialog->raise();
|
2017-05-31 14:33:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationsDbusInterface::sendReply(const QString& replyId, const QString& message)
|
|
|
|
{
|
2018-03-04 19:48:51 +00:00
|
|
|
NetworkPacket np(PACKET_TYPE_NOTIFICATION_REPLY);
|
2017-05-31 14:33:21 +01:00
|
|
|
np.set<QString>(QStringLiteral("requestReplyId"), replyId);
|
|
|
|
np.set<QString>(QStringLiteral("message"), message);
|
2018-03-04 19:48:51 +00:00
|
|
|
m_plugin->sendPacket(np);
|
2017-05-31 14:33:21 +01:00
|
|
|
}
|
|
|
|
|
2019-02-08 22:47:41 +00:00
|
|
|
void NotificationsDbusInterface::sendAction(const QString& key, const QString& action)
|
|
|
|
{
|
|
|
|
NetworkPacket np(PACKET_TYPE_NOTIFICATION_ACTION);
|
2019-06-10 15:40:28 +01:00
|
|
|
np.set<QString>(QStringLiteral("key"), key);
|
|
|
|
np.set<QString>(QStringLiteral("action"), action);
|
2019-02-08 22:47:41 +00:00
|
|
|
m_plugin->sendPacket(np);
|
|
|
|
}
|
|
|
|
|
2013-08-20 12:55:03 +01:00
|
|
|
QString NotificationsDbusInterface::newId()
|
|
|
|
{
|
2017-09-03 20:39:44 +01:00
|
|
|
return QString::number(++m_lastId);
|
2013-08-20 12:55:03 +01:00
|
|
|
}
|