Changeset View
Changeset View
Standalone View
Standalone View
plugins/ping/pingplugin.cpp
Show All 14 Lines | |||||
15 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. | ||
16 | * | 16 | * | ||
17 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License | ||
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 "pingplugin.h" | 21 | #include "pingplugin.h" | ||
22 | 22 | | |||
23 | #include <KNotification> | | |||
24 | #include <KLocalizedString> | 23 | #include <KLocalizedString> | ||
25 | #include <KPluginFactory> | 24 | #include <KPluginFactory> | ||
26 | 25 | | |||
27 | #include <QDebug> | 26 | #include <QDebug> | ||
28 | #include <QDBusConnection> | 27 | #include <QDBusConnection> | ||
29 | #include <QLoggingCategory> | 28 | #include <QLoggingCategory> | ||
30 | 29 | | |||
31 | #include <core/device.h> | 30 | #include <core/device.h> | ||
31 | #include <core/daemon.h> | ||||
32 | 32 | | |||
33 | K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_ping.json", registerPlugin< PingPlugin >(); ) | 33 | K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_ping.json", registerPlugin< PingPlugin >(); ) | ||
34 | 34 | | |||
35 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_PING, "kdeconnect.plugin.ping") | 35 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_PING, "kdeconnect.plugin.ping") | ||
36 | 36 | | |||
37 | PingPlugin::PingPlugin(QObject* parent, const QVariantList& args) | 37 | PingPlugin::PingPlugin(QObject* parent, const QVariantList& args) | ||
38 | : KdeConnectPlugin(parent, args) | 38 | : KdeConnectPlugin(parent, args) | ||
39 | { | 39 | { | ||
40 | // qCDebug(KDECONNECT_PLUGIN_PING) << "Ping plugin constructor for device" << device()->name(); | 40 | // qCDebug(KDECONNECT_PLUGIN_PING) << "Ping plugin constructor for device" << device()->name(); | ||
41 | } | 41 | } | ||
42 | 42 | | |||
43 | PingPlugin::~PingPlugin() | 43 | PingPlugin::~PingPlugin() | ||
44 | { | 44 | { | ||
45 | // qCDebug(KDECONNECT_PLUGIN_PING) << "Ping plugin destructor for device" << device()->name(); | 45 | // qCDebug(KDECONNECT_PLUGIN_PING) << "Ping plugin destructor for device" << device()->name(); | ||
46 | } | 46 | } | ||
47 | 47 | | |||
48 | bool PingPlugin::receivePacket(const NetworkPacket& np) | 48 | bool PingPlugin::receivePacket(const NetworkPacket& np) | ||
49 | { | 49 | { | ||
50 | KNotification* notification = new KNotification(QStringLiteral("pingReceived")); //KNotification::Persistent | 50 | Daemon::instance()->sendSimpleNotification(QStringLiteral("pingReceived"), device()->name(), np.get<QString>(QStringLiteral("message"),i18n("Ping!")), QStringLiteral("dialog-ok")); | ||
51 | notification->setIconName(QStringLiteral("dialog-ok")); | | |||
52 | notification->setComponentName(QStringLiteral("kdeconnect")); | | |||
53 | notification->setTitle(device()->name()); | | |||
54 | notification->setText(np.get<QString>(QStringLiteral("message"),i18n("Ping!"))); //This can be a source of spam | | |||
55 | notification->sendEvent(); | | |||
56 | 51 | | |||
57 | return true; | 52 | return true; | ||
58 | } | 53 | } | ||
59 | 54 | | |||
60 | void PingPlugin::sendPing() | 55 | void PingPlugin::sendPing() | ||
61 | { | 56 | { | ||
62 | NetworkPacket np(PACKET_TYPE_PING); | 57 | NetworkPacket np(PACKET_TYPE_PING); | ||
63 | bool success = sendPacket(np); | 58 | bool success = sendPacket(np); | ||
Show All 20 Lines |