Changeset View
Standalone View
plugins/findthisdevice/findthisdeviceplugin.cpp
- This file was added.
1 | /** | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org> | ||||
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 "findthisdeviceplugin.h" | ||||
22 | | ||||
23 | // Phonon | ||||
24 | #include <phonon/mediaobject.h> | ||||
25 | // KF | ||||
26 | #include <KPluginFactory> | ||||
27 | // Qt | ||||
28 | #include <QDBusConnection> | ||||
29 | #include <QStandardPaths> | ||||
30 | #include <QFile> | ||||
31 | #include <QUrl> | ||||
32 | | ||||
33 | | ||||
34 | K_PLUGIN_FACTORY_WITH_JSON(KdeConnectPluginFactory, "kdeconnect_findthisdevice.json", | ||||
35 | registerPlugin<FindThisDevicePlugin>();) | ||||
36 | | ||||
37 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_FINDTHISDEVICE, "kdeconnect.plugin.findthisdevice") | ||||
38 | | ||||
39 | namespace { | ||||
40 | namespace Strings { | ||||
41 | inline QString defaultSound() { return QStringLiteral("Oxygen-Im-Phone-Ring.ogg"); } | ||||
42 | } | ||||
apol: Looks to me as good as any, I'd remove the TODO. I think this one is okay, if we ever want to… | |||||
43 | } | ||||
44 | | ||||
45 | FindThisDevicePlugin::FindThisDevicePlugin(QObject* parent, const QVariantList& args) | ||||
46 | : KdeConnectPlugin(parent, args) | ||||
47 | { | ||||
48 | } | ||||
49 | | ||||
50 | FindThisDevicePlugin::~FindThisDevicePlugin() = default; | ||||
51 | | ||||
52 | void FindThisDevicePlugin::connected() | ||||
53 | { | ||||
54 | } | ||||
55 | | ||||
56 | bool FindThisDevicePlugin::receivePacket(const NetworkPacket& np) | ||||
57 | { | ||||
58 | Q_UNUSED(np); | ||||
59 | | ||||
60 | const QString soundFilename = config()->get<QString>(QStringLiteral("ringtone"), Strings::defaultSound()); | ||||
61 | | ||||
62 | QUrl soundURL; | ||||
I'm not sure it makes sense to send which ringtone needs to be sounding on the other side. Is this how we do it for Android? apol: I'm not sure it makes sense to send which ringtone needs to be sounding on the other side. Is… | |||||
This defines the ring tone for this device when being called/pinged, not the other :) With the Android version this is done the same, cmp. https://phabricator.kde.org/R225:4d5d7449200a240ebc05aa71a60e7f53f03bde7b Ideally this could be configured once per this device (think family members connecting all their mobiles to the family laptop to be able to find it*), right now it needs to be configured for any connection. But there is no way yet to do such global connection-independent config of a plugin, right?
kossebau: This defines the ring tone for this device when being called/pinged, not the other :)
With the… | |||||
63 | const auto dataLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); | ||||
64 | for (const QString &dataLocation : dataLocations) { | ||||
65 | soundURL = QUrl::fromUserInput(soundFilename, | ||||
66 | dataLocation + QStringLiteral("/sounds"), | ||||
67 | QUrl::AssumeLocalFile); | ||||
apol: fromLocalFile | |||||
I followed here the code from knotification / knotifyconfig which both use QUrl::fromUserInput. See also related commit messages ( 1 2. Not sure what fancy usages people might have or want to enter, but given the examples in the commit messages, I should be safe to stay consistent with that other code. kossebau: I followed here the code from [[ https://phabricator.kde. | |||||
68 | if (soundURL.isLocalFile()) { | ||||
69 | if (QFile::exists(soundURL.toLocalFile())) { | ||||
70 | break; | ||||
71 | } | ||||
72 | } else { | ||||
73 | if (soundURL.isValid()) { | ||||
74 | break; | ||||
75 | } | ||||
76 | } | ||||
77 | soundURL.clear(); | ||||
78 | } | ||||
79 | if (soundURL.isEmpty()) { | ||||
80 | qCWarning(KDECONNECT_PLUGIN_FINDTHISDEVICE) << "Not playing sounds, could not find ring tone" << soundFilename; | ||||
81 | return true; | ||||
82 | } | ||||
83 | | ||||
84 | Phonon::MediaObject *media = Phonon::createPlayer(Phonon::NotificationCategory, soundURL); // or CommunicationCategory? | ||||
85 | media->play(); | ||||
86 | connect(media, &Phonon::MediaObject::finished, media, &QObject::deleteLater); | ||||
87 | | ||||
88 | // TODO: by-pass volume settings in case it is muted | ||||
89 | // TODO: ensure to use built-in loudspeakers | ||||
90 | | ||||
91 | return true; | ||||
92 | } | ||||
93 | | ||||
94 | QString FindThisDevicePlugin::dbusPath() const | ||||
95 | { | ||||
96 | return "/modules/kdeconnect/devices/" + device()->id() + "/findthisdevice"; | ||||
97 | } | ||||
98 | | ||||
99 | #include "findthisdeviceplugin.moc" | ||||
100 | |
Looks to me as good as any, I'd remove the TODO. I think this one is okay, if we ever want to change we change.