forked from KDE/kdeconnect-kde
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split DesktopDaemon into its own files
- Loading branch information
1 parent
5af9a33
commit da07bce
Showing
4 changed files
with
114 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Albert Vaca <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL | ||
*/ | ||
|
||
#include "desktop_daemon.h" | ||
|
||
#include <QApplication> | ||
#include <QIcon> | ||
#include <QStandardPaths> | ||
#include <QTimer> | ||
|
||
#include <KDBusService> | ||
#include <KIO/Global> | ||
#include <KIO/JobTracker> | ||
#include <KLocalizedString> | ||
#include <KNotification> | ||
|
||
#include "core/backends/pairinghandler.h" | ||
#include "core/device.h" | ||
#include "core/openconfig.h" | ||
|
||
DesktopDaemon::DesktopDaemon(QObject *parent) | ||
: Daemon(parent) | ||
{ | ||
qApp->setWindowIcon(QIcon(QStringLiteral(":/icons/kdeconnect/kdeconnect.png"))); | ||
} | ||
|
||
void DesktopDaemon::askPairingConfirmation(Device *device) | ||
{ | ||
KNotification *notification = new KNotification(QStringLiteral("pairingRequest"), KNotification::NotificationFlag::Persistent); | ||
QTimer::singleShot(PairingHandler::pairingTimeoutMsec, notification, &KNotification::close); | ||
notification->setIconName(QStringLiteral("dialog-information")); | ||
notification->setComponentName(QStringLiteral("kdeconnect")); | ||
notification->setTitle(QStringLiteral("KDE Connect")); | ||
notification->setText(i18n("Pairing request from %1\nKey: %2", device->name().toHtmlEscaped(), device->verificationKey())); | ||
QString deviceId = device->id(); | ||
auto openSettings = [deviceId, notification] { | ||
OpenConfig oc; | ||
oc.setXdgActivationToken(notification->xdgActivationToken()); | ||
oc.openConfiguration(deviceId); | ||
}; | ||
|
||
KNotificationAction *openSettingsAction = notification->addDefaultAction(i18n("Open")); | ||
connect(openSettingsAction, &KNotificationAction::activated, openSettings); | ||
|
||
KNotificationAction *acceptAction = notification->addAction(i18n("Accept")); | ||
connect(acceptAction, &KNotificationAction::activated, device, &Device::acceptPairing); | ||
|
||
KNotificationAction *rejectAction = notification->addAction(i18n("Reject")); | ||
connect(rejectAction, &KNotificationAction::activated, device, &Device::cancelPairing); | ||
|
||
KNotificationAction *viewKeyAction = notification->addAction(i18n("View key")); | ||
connect(viewKeyAction, &KNotificationAction::activated, openSettings); | ||
notification->sendEvent(); | ||
} | ||
|
||
void DesktopDaemon::reportError(const QString &title, const QString &description) | ||
{ | ||
qWarning() << title << ":" << description; | ||
KNotification::event(KNotification::Error, title, description); | ||
} | ||
|
||
KJobTrackerInterface *DesktopDaemon::jobTracker() | ||
{ | ||
return KIO::getJobTracker(); | ||
} | ||
|
||
Q_SCRIPTABLE void DesktopDaemon::sendSimpleNotification(const QString &eventId, const QString &title, const QString &text, const QString &iconName) | ||
{ | ||
KNotification *notification = new KNotification(eventId); // KNotification::Persistent | ||
notification->setIconName(iconName); | ||
notification->setComponentName(QStringLiteral("kdeconnect")); | ||
notification->setTitle(title); | ||
notification->setText(text); | ||
notification->sendEvent(); | ||
} | ||
|
||
void DesktopDaemon::quit() | ||
{ | ||
QApplication::quit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Albert Vaca Cintora <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <QString> | ||
#include <QObject> | ||
|
||
#include "daemon.h" | ||
|
||
class Device; | ||
class KJobTrackerInterface; | ||
|
||
class DesktopDaemon : public Daemon | ||
{ | ||
Q_OBJECT | ||
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.daemon") | ||
public: | ||
DesktopDaemon(QObject *parent = nullptr); | ||
|
||
void askPairingConfirmation(Device *device) override; | ||
void reportError(const QString &title, const QString &description) override; | ||
KJobTrackerInterface *jobTracker() override; | ||
Q_SCRIPTABLE void sendSimpleNotification(const QString &eventId, const QString &title, const QString &text, const QString &iconName) override; | ||
void quit() override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters