fix Ring for Windows port

This commit is contained in:
Piyush Aggarwal 2019-03-21 22:26:32 +00:00 committed by Albert Vaca Cintora
parent e5e740437f
commit b6f61e097f
3 changed files with 25 additions and 15 deletions

View file

@ -19,6 +19,7 @@
*/
#include "findthisdevice_config.h"
#include "findthisdeviceplugin.h"
#include "ui_findthisdevice_config.h"
// Phonon
@ -33,12 +34,6 @@
K_PLUGIN_FACTORY(FindThisDeviceConfigFactory, registerPlugin<FindThisDeviceConfig>();)
namespace {
namespace Strings {
inline QString defaultSound() { return QStringLiteral("Oxygen-Im-Phone-Ring.ogg"); }
}
}
FindThisDeviceConfig::FindThisDeviceConfig(QWidget* parent, const QVariantList& args)
: KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_findthisdevice_config"))
, m_ui(new Ui::FindThisDeviceConfigUi())
@ -68,7 +63,7 @@ void FindThisDeviceConfig::defaults()
{
KCModule::defaults();
m_ui->soundFileRequester->setText(Strings::defaultSound());
m_ui->soundFileRequester->setText(defaultSound());
Q_EMIT changed(true);
}
@ -77,7 +72,7 @@ void FindThisDeviceConfig::load()
{
KCModule::load();
const QString ringTone = config()->get<QString>(QStringLiteral("ringtone"), Strings::defaultSound());
const QString ringTone = config()->get<QString>(QStringLiteral("ringtone"), defaultSound());
m_ui->soundFileRequester->setText(ringTone);
Q_EMIT changed(false);

View file

@ -36,12 +36,6 @@ K_PLUGIN_FACTORY_WITH_JSON(KdeConnectPluginFactory, "kdeconnect_findthisdevice.j
Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_FINDTHISDEVICE, "kdeconnect.plugin.findthisdevice")
namespace {
namespace Strings {
inline QString defaultSound() { return QStringLiteral("Oxygen-Im-Phone-Ring.ogg"); }
}
}
FindThisDevicePlugin::FindThisDevicePlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args)
{
@ -57,9 +51,21 @@ bool FindThisDevicePlugin::receivePacket(const NetworkPacket& np)
{
Q_UNUSED(np);
const QString soundFilename = config()->get<QString>(QStringLiteral("ringtone"), Strings::defaultSound());
const QString soundFilename = config()->get<QString>(QStringLiteral("ringtone"), defaultSound());
QUrl soundURL;
#ifdef Q_OS_WIN
QString winDirPath = qEnvironmentVariable("WINDIR") + QStringLiteral("/media");
if (!winDirPath.isEmpty()) {
soundURL = QUrl::fromUserInput(soundFilename,
winDirPath,
QUrl::AssumeLocalFile);
}
else {
qCWarning(KDECONNECT_PLUGIN_FINDTHISDEVICE) << "Not playing sounds, system doesn't know WINDIR : " << soundFilename;
}
#else
const auto dataLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
for (const QString &dataLocation : dataLocations) {
soundURL = QUrl::fromUserInput(soundFilename,
@ -76,6 +82,7 @@ bool FindThisDevicePlugin::receivePacket(const NetworkPacket& np)
}
soundURL.clear();
}
#endif
if (soundURL.isEmpty()) {
qCWarning(KDECONNECT_PLUGIN_FINDTHISDEVICE) << "Not playing sounds, could not find ring tone" << soundFilename;
return true;

View file

@ -29,6 +29,14 @@
Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_FINDTHISDEVICE)
inline QString defaultSound(){
#ifdef Q_OS_WIN
return QStringLiteral("Ring01.wav");
#else
return QStringLiteral("Oxygen-Im-Phone-Ring.ogg");
#endif
}
class FindThisDevicePlugin
: public KdeConnectPlugin
{