Changeset View
Changeset View
Standalone View
Standalone View
sfos/sailfishdaemon.cpp
- This file was added.
1 | /** | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Adam Pigg <adam@piggz.co.uk> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
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/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include <QCoreApplication> | ||||
22 | #include <QNetworkAccessManager> | ||||
23 | | ||||
24 | #include <KDBusService> | ||||
25 | #include <KLocalizedString> | ||||
26 | | ||||
27 | #include "core/daemon.h" | ||||
28 | #include "core/device.h" | ||||
29 | #include "core/backends/pairinghandler.h" | ||||
30 | #include "kdeconnect-version.h" | ||||
31 | | ||||
32 | #include <notification.h> | ||||
33 | | ||||
34 | class SailfishDaemon : public Daemon | ||||
35 | { | ||||
36 | Q_OBJECT | ||||
37 | Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.daemon") | ||||
38 | public: | ||||
39 | SailfishDaemon(QObject* parent = Q_NULLPTR) | ||||
40 | : Daemon(parent) | ||||
41 | , m_nam(Q_NULLPTR) | ||||
42 | {} | ||||
43 | | ||||
44 | void askPairingConfirmation(Device* device) override | ||||
45 | { | ||||
46 | qDebug() << "Pairing request from " << device->name().toHtmlEscaped(); | ||||
47 | | ||||
48 | Notification *notification = new Notification(this); | ||||
49 | | ||||
50 | notification->setAppName(QCoreApplication::applicationName()); | ||||
51 | notification->setPreviewSummary(i18n("Pairing request from %1", device->name().toHtmlEscaped())); | ||||
52 | notification->setPreviewBody(i18n("Click here to pair")); | ||||
53 | notification->setIcon("icon-s-sync"); | ||||
54 | notification->setExpireTimeout(10000); | ||||
55 | | ||||
56 | connect(notification, &Notification::closed, | ||||
57 | [=]( uint reason ) { | ||||
58 | qDebug() << "Notification closed" << reason; | ||||
59 | if (reason == 2) { //clicked | ||||
60 | device->acceptPairing(); | ||||
61 | } else { | ||||
62 | device->rejectPairing(); | ||||
63 | } | ||||
64 | }); | ||||
65 | | ||||
66 | notification->publish(); | ||||
67 | } | ||||
68 | | ||||
69 | void reportError(const QString & title, const QString & description) override | ||||
70 | { | ||||
71 | qDebug() << "Error: " << title << ":" << description; | ||||
72 | } | ||||
73 | | ||||
74 | QNetworkAccessManager* networkAccessManager() override | ||||
75 | { | ||||
76 | if (!m_nam) { | ||||
77 | m_nam = new QNetworkAccessManager(this); | ||||
78 | } | ||||
79 | return m_nam; | ||||
80 | } | ||||
81 | | ||||
82 | void sendSimpleNotification(const QString &eventId, const QString &title, const QString &text, const QString &iconName) override | ||||
83 | { | ||||
84 | Q_UNUSED(eventId); | ||||
85 | Notification *notification = new Notification(this); | ||||
86 | | ||||
87 | notification->setAppName(QCoreApplication::applicationName()); | ||||
88 | notification->setPreviewSummary(title); | ||||
89 | notification->setPreviewBody(text); | ||||
90 | notification->setIcon(iconName); | ||||
91 | notification->publish(); | ||||
92 | } | ||||
93 | | ||||
94 | | ||||
95 | private: | ||||
96 | QNetworkAccessManager* m_nam; | ||||
97 | }; | ||||
98 | | ||||
99 | int main(int argc, char* argv[]) | ||||
100 | { | ||||
101 | QCoreApplication app(argc, argv); | ||||
102 | | ||||
103 | app.setApplicationName(QStringLiteral("kdeconnectd")); | ||||
104 | app.setApplicationVersion(QStringLiteral(KDECONNECT_VERSION_STRING)); | ||||
105 | app.setOrganizationDomain(QStringLiteral("kde.org")); | ||||
106 | | ||||
107 | KDBusService dbusService(KDBusService::Unique); | ||||
108 | | ||||
109 | Daemon* daemon = new SailfishDaemon; | ||||
110 | | ||||
111 | QObject::connect(daemon, SIGNAL(destroyed(QObject*)), &app, SLOT(quit())); | ||||
112 | | ||||
113 | return app.exec(); | ||||
114 | } | ||||
115 | | ||||
116 | #include "sailfishdaemon.moc" |