Changeset View
Changeset View
Standalone View
Standalone View
sfos/sailfishdaemon.h
- 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 | #include <QTimer> | ||||
24 | | ||||
25 | #include <KDBusService> | ||||
26 | #include <KLocalizedString> | ||||
27 | | ||||
28 | #include "core/daemon.h" | ||||
29 | #include "core/device.h" | ||||
30 | #include "core/backends/pairinghandler.h" | ||||
31 | #include "kdeconnect-version.h" | ||||
32 | | ||||
33 | #include <notification.h> | ||||
34 | | ||||
35 | class SailfishDaemon : public Daemon | ||||
36 | { | ||||
37 | Q_OBJECT | ||||
38 | Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.daemon") | ||||
39 | public: | ||||
40 | SailfishDaemon(QObject* parent = Q_NULLPTR) | ||||
41 | : Daemon(parent) | ||||
42 | , m_nam(Q_NULLPTR) | ||||
43 | {} | ||||
44 | | ||||
45 | void askPairingConfirmation(Device* device) override | ||||
46 | { | ||||
47 | qDebug() << "Pairing request from " << device->name().toHtmlEscaped(); | ||||
48 | | ||||
49 | Notification *notification = new Notification(this); | ||||
50 | | ||||
51 | notification->setAppName(QCoreApplication::applicationName()); | ||||
52 | notification->setPreviewSummary(i18n("Pairing request from %1", device->name().toHtmlEscaped())); | ||||
53 | notification->setPreviewBody(i18n("Click here to pair")); | ||||
54 | notification->setIcon("icon-s-sync"); | ||||
55 | notification->setExpireTimeout(10000); | ||||
56 | | ||||
57 | connect(notification, &Notification::closed, | ||||
58 | [=]( uint reason ) { | ||||
59 | qDebug() << "Notification closed" << reason; | ||||
60 | if (reason == 2) { //clicked | ||||
61 | device->acceptPairing(); | ||||
62 | } else { | ||||
63 | device->rejectPairing(); | ||||
64 | } | ||||
65 | }); | ||||
66 | | ||||
67 | notification->publish(); | ||||
68 | } | ||||
69 | | ||||
70 | void reportError(const QString & title, const QString & description) override | ||||
71 | { | ||||
72 | qDebug() << "Error: " << title << ":" << description; | ||||
73 | } | ||||
74 | | ||||
75 | QNetworkAccessManager* networkAccessManager() override | ||||
76 | { | ||||
77 | if (!m_nam) { | ||||
78 | m_nam = new QNetworkAccessManager(this); | ||||
79 | } | ||||
80 | return m_nam; | ||||
81 | } | ||||
82 | | ||||
83 | private: | ||||
84 | QNetworkAccessManager* m_nam; | ||||
85 | }; |