Changeset View
Changeset View
Standalone View
Standalone View
plugins/findthisdevice/findthisdeviceplugin.cpp
Show All 32 Lines | |||||
33 | 33 | | |||
34 | K_PLUGIN_FACTORY_WITH_JSON(KdeConnectPluginFactory, "kdeconnect_findthisdevice.json", | 34 | K_PLUGIN_FACTORY_WITH_JSON(KdeConnectPluginFactory, "kdeconnect_findthisdevice.json", | ||
35 | registerPlugin<FindThisDevicePlugin>();) | 35 | registerPlugin<FindThisDevicePlugin>();) | ||
36 | 36 | | |||
37 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_FINDTHISDEVICE, "kdeconnect.plugin.findthisdevice") | 37 | Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_FINDTHISDEVICE, "kdeconnect.plugin.findthisdevice") | ||
38 | 38 | | |||
39 | namespace { | 39 | namespace { | ||
40 | namespace Strings { | 40 | namespace Strings { | ||
41 | inline QString defaultSound() { return QStringLiteral("Oxygen-Im-Phone-Ring.ogg"); } | 41 | inline QString defaultSound() { | ||
42 | #ifdef Q_OS_WIN | ||||
43 | return QStringLiteral("Ring01.wav"); | ||||
44 | #else | ||||
45 | return QStringLiteral("Oxygen-Im-Phone-Ring.ogg"); | ||||
46 | #endif | ||||
47 | } | ||||
42 | } | 48 | } | ||
43 | } | 49 | } | ||
44 | 50 | | |||
45 | FindThisDevicePlugin::FindThisDevicePlugin(QObject* parent, const QVariantList& args) | 51 | FindThisDevicePlugin::FindThisDevicePlugin(QObject* parent, const QVariantList& args) | ||
46 | : KdeConnectPlugin(parent, args) | 52 | : KdeConnectPlugin(parent, args) | ||
47 | { | 53 | { | ||
48 | } | 54 | } | ||
49 | 55 | | |||
50 | FindThisDevicePlugin::~FindThisDevicePlugin() = default; | 56 | FindThisDevicePlugin::~FindThisDevicePlugin() = default; | ||
51 | 57 | | |||
52 | void FindThisDevicePlugin::connected() | 58 | void FindThisDevicePlugin::connected() | ||
53 | { | 59 | { | ||
54 | } | 60 | } | ||
55 | 61 | | |||
56 | bool FindThisDevicePlugin::receivePacket(const NetworkPacket& np) | 62 | bool FindThisDevicePlugin::receivePacket(const NetworkPacket& np) | ||
57 | { | 63 | { | ||
58 | Q_UNUSED(np); | 64 | Q_UNUSED(np); | ||
59 | 65 | | |||
60 | const QString soundFilename = config()->get<QString>(QStringLiteral("ringtone"), Strings::defaultSound()); | 66 | const QString soundFilename = config()->get<QString>(QStringLiteral("ringtone"), Strings::defaultSound()); | ||
61 | 67 | | |||
62 | QUrl soundURL; | 68 | QUrl soundURL; | ||
63 | const auto dataLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); | 69 | const auto dataLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); | ||
70 | #ifdef Q_OS_WIN | ||||
71 | soundURL = QUrl::fromUserInput(soundFilename, | ||||
72 | QStringLiteral("C:/Windows/media"), | ||||
73 | QUrl::AssumeLocalFile); | ||||
74 | #else | ||||
64 | for (const QString &dataLocation : dataLocations) { | 75 | for (const QString &dataLocation : dataLocations) { | ||
65 | soundURL = QUrl::fromUserInput(soundFilename, | 76 | soundURL = QUrl::fromUserInput(soundFilename, | ||
66 | dataLocation + QStringLiteral("/sounds"), | 77 | dataLocation + QStringLiteral("/sounds"), | ||
67 | QUrl::AssumeLocalFile); | 78 | QUrl::AssumeLocalFile); | ||
68 | if (soundURL.isLocalFile()) { | 79 | if (soundURL.isLocalFile()) { | ||
69 | if (QFile::exists(soundURL.toLocalFile())) { | 80 | if (QFile::exists(soundURL.toLocalFile())) { | ||
70 | break; | 81 | break; | ||
71 | } | 82 | } | ||
72 | } else { | 83 | } else { | ||
73 | if (soundURL.isValid()) { | 84 | if (soundURL.isValid()) { | ||
74 | break; | 85 | break; | ||
75 | } | 86 | } | ||
76 | } | 87 | } | ||
77 | soundURL.clear(); | 88 | soundURL.clear(); | ||
78 | } | 89 | } | ||
90 | #endif | ||||
79 | if (soundURL.isEmpty()) { | 91 | if (soundURL.isEmpty()) { | ||
80 | qCWarning(KDECONNECT_PLUGIN_FINDTHISDEVICE) << "Not playing sounds, could not find ring tone" << soundFilename; | 92 | qCWarning(KDECONNECT_PLUGIN_FINDTHISDEVICE) << "Not playing sounds, could not find ring tone" << soundFilename; | ||
81 | return true; | 93 | return true; | ||
82 | } | 94 | } | ||
83 | 95 | | |||
84 | Phonon::MediaObject *media = Phonon::createPlayer(Phonon::NotificationCategory, soundURL); // or CommunicationCategory? | 96 | Phonon::MediaObject *media = Phonon::createPlayer(Phonon::NotificationCategory, soundURL); // or CommunicationCategory? | ||
85 | media->play(); | 97 | media->play(); | ||
86 | connect(media, &Phonon::MediaObject::finished, media, &QObject::deleteLater); | 98 | connect(media, &Phonon::MediaObject::finished, media, &QObject::deleteLater); | ||
Show All 14 Lines |