Reformat project with clang-format

This commit is contained in:
Alexander Lohnau 2023-09-25 06:31:46 +02:00
parent a8adedd100
commit dc8f3e209e
11 changed files with 178 additions and 113 deletions

View file

@ -47,8 +47,8 @@ void BluetoothLinkProvider::onStart()
mKdeconnectService = mBluetoothServer->listen(mServiceUuid, QStringLiteral("KDE Connect")); mKdeconnectService = mBluetoothServer->listen(mServiceUuid, QStringLiteral("KDE Connect"));
// Disabled for the moment as once the server is listening, the client will not be able to connect anyway // Disabled for the moment as once the server is listening, the client will not be able to connect anyway
//mServiceDiscoveryAgent->start(); // mServiceDiscoveryAgent->start();
//connectTimer->start(); // connectTimer->start();
} }
void BluetoothLinkProvider::onStop() void BluetoothLinkProvider::onStop()
@ -105,7 +105,9 @@ void BluetoothLinkProvider::serviceDiscovered(const QBluetoothServiceInfo &old_i
{ {
qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::serviceDiscovered executed "; qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::serviceDiscovered executed ";
qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::serviceDiscovered info: " << old_info.device().address() << old_info.serviceName() << old_info.serviceDescription() << old_info.socketProtocol() << old_info.isValid() << old_info.isComplete() << old_info.isRegistered() << old_info.serviceClassUuids(); qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::serviceDiscovered info: " << old_info.device().address() << old_info.serviceName()
<< old_info.serviceDescription() << old_info.socketProtocol() << old_info.isValid() << old_info.isComplete()
<< old_info.isRegistered() << old_info.serviceClassUuids();
auto info = *(new QBluetoothServiceInfo(old_info)); auto info = *(new QBluetoothServiceInfo(old_info));
info.setServiceUuid(mServiceUuid); info.setServiceUuid(mServiceUuid);

View file

@ -128,13 +128,13 @@ bool ConnectionMultiplexer::tryParseMessage()
uint16_t message_length = qFromBigEndian<uint16_t>(&header.data()[1]); uint16_t message_length = qFromBigEndian<uint16_t>(&header.data()[1]);
quint128 message_uuid_raw; quint128 message_uuid_raw;
#ifndef QT_SUPPORTS_INT128 #ifndef QT_SUPPORTS_INT128
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
message_uuid_raw.data[i] = header[3 + i]; message_uuid_raw.data[i] = header[3 + i];
} }
#else #else
message_uuid_raw = qFromBigEndian<quint128>(&header.data()[3]); message_uuid_raw = qFromBigEndian<quint128>(&header.data()[3]);
#endif #endif
QBluetoothUuid message_uuid = QBluetoothUuid(message_uuid_raw); QBluetoothUuid message_uuid = QBluetoothUuid(message_uuid_raw);
// Check if we have the full message including its data // Check if we have the full message including its data

View file

@ -18,7 +18,6 @@
namespace MdnsWrapper namespace MdnsWrapper
{ {
const char *recordTypeToStr(int rtype) const char *recordTypeToStr(int rtype)
{ {
switch (rtype) { switch (rtype) {
@ -79,10 +78,22 @@ static sockaddr_in6 qHostAddressToSockaddr6(QHostAddress hostAddress)
} }
// Callback that handles responses to a query // Callback that handles responses to a query
static int query_callback(int sock, const struct sockaddr* from, size_t addrlen, mdns_entry_type_t entry_type, static int query_callback(int sock,
uint16_t query_id, uint16_t record_type, uint16_t rclass, uint32_t ttl, const void* data, const struct sockaddr *from,
size_t size, size_t name_offset, size_t name_length, size_t record_offset, size_t addrlen,
size_t record_length, void* user_data) { mdns_entry_type_t entry_type,
uint16_t query_id,
uint16_t record_type,
uint16_t rclass,
uint32_t ttl,
const void *data,
size_t size,
size_t name_offset,
size_t name_length,
size_t record_offset,
size_t record_length,
void *user_data)
{
Q_UNUSED(sock); Q_UNUSED(sock);
Q_UNUSED(addrlen); Q_UNUSED(addrlen);
Q_UNUSED(query_id); Q_UNUSED(query_id);
@ -92,18 +103,20 @@ static int query_callback(int sock, const struct sockaddr* from, size_t addrlen,
Q_UNUSED(name_offset); Q_UNUSED(name_offset);
Q_UNUSED(name_length); Q_UNUSED(name_length);
//qCDebug(KDECONNECT_CORE) << "Received DNS record of type" << recordTypeToStr(record_type) << "from socket" << sock << "with type" << entryTypeToStr(entry_type); // qCDebug(KDECONNECT_CORE) << "Received DNS record of type" << recordTypeToStr(record_type) << "from socket" << sock << "with type" <<
// entryTypeToStr(entry_type);
Discoverer::MdnsService *discoveredService = (Discoverer::MdnsService *)user_data; Discoverer::MdnsService *discoveredService = (Discoverer::MdnsService *)user_data;
switch (record_type) { switch (record_type) {
case MDNS_RECORDTYPE_PTR: { case MDNS_RECORDTYPE_PTR: {
// We don't use mdns_record_parse_ptr() because we want to extract just the service name instead of the full "<instance-name>._<service-type>._tcp.local." string // We don't use mdns_record_parse_ptr() because we want to extract just the service name instead of the full
// "<instance-name>._<service-type>._tcp.local." string
mdns_string_pair_t instanceNamePos = mdns_get_next_substring(data, size, record_offset); mdns_string_pair_t instanceNamePos = mdns_get_next_substring(data, size, record_offset);
discoveredService->name = QString::fromLatin1((char *)data + instanceNamePos.offset, instanceNamePos.length); discoveredService->name = QString::fromLatin1((char *)data + instanceNamePos.offset, instanceNamePos.length);
//static char instanceNameBuffer[256]; // static char instanceNameBuffer[256];
//mdns_string_t instanceName = mdns_record_parse_ptr(data, size, record_offset, record_length, instanceNameBuffer, sizeof(instanceNameBuffer)); // mdns_string_t instanceName = mdns_record_parse_ptr(data, size, record_offset, record_length, instanceNameBuffer, sizeof(instanceNameBuffer));
//discoveredService->name = QString::fromLatin1(instanceName.str, instanceName.length); // discoveredService->name = QString::fromLatin1(instanceName.str, instanceName.length);
if (discoveredService->address == QHostAddress::Null) { if (discoveredService->address == QHostAddress::Null) {
discoveredService->address = QHostAddress(from); // In case we don't receive a A record, use from as address discoveredService->address = QHostAddress(from); // In case we don't receive a A record, use from as address
} }
@ -112,7 +125,7 @@ static int query_callback(int sock, const struct sockaddr* from, size_t addrlen,
static char nameBuffer[256]; static char nameBuffer[256];
mdns_record_srv_t record = mdns_record_parse_srv(data, size, record_offset, record_length, nameBuffer, sizeof(nameBuffer)); mdns_record_srv_t record = mdns_record_parse_srv(data, size, record_offset, record_length, nameBuffer, sizeof(nameBuffer));
// We can use the IP to connect so we don't need to store the "<hostname>.local." address. // We can use the IP to connect so we don't need to store the "<hostname>.local." address.
//discoveredService->qualifiedHostname = QString::fromLatin1(record.name.str, record.name.length); // discoveredService->qualifiedHostname = QString::fromLatin1(record.name.str, record.name.length);
discoveredService->port = record.port; discoveredService->port = record.port;
} break; } break;
case MDNS_RECORDTYPE_A: { case MDNS_RECORDTYPE_A: {
@ -122,8 +135,8 @@ static int query_callback(int sock, const struct sockaddr* from, size_t addrlen,
} break; } break;
case MDNS_RECORDTYPE_AAAA: case MDNS_RECORDTYPE_AAAA:
// Ignore IPv6 for now // Ignore IPv6 for now
//sockaddr_in6 addr6; // sockaddr_in6 addr6;
//mdns_record_parse_aaaa(data, size, record_offset, record_length, &addr6); // mdns_record_parse_aaaa(data, size, record_offset, record_length, &addr6);
break; break;
case MDNS_RECORDTYPE_TXT: { case MDNS_RECORDTYPE_TXT: {
mdns_record_txt_t records[24]; mdns_record_txt_t records[24];
@ -251,7 +264,8 @@ static mdns_string_t createMdnsString(const QByteArray &str)
return mdns_string_t{str.constData(), (size_t)str.length()}; return mdns_string_t{str.constData(), (size_t)str.length()};
} }
int countCommonLeadingBits(quint32 int1, quint32 int2) { int countCommonLeadingBits(quint32 int1, quint32 int2)
{
int count = 0; int count = 0;
while (int1 != 0 && int2 != 0) { while (int1 != 0 && int2 != 0) {
if ((int1 & 0x80000000) == (int2 & 0x80000000)) { if ((int1 & 0x80000000) == (int2 & 0x80000000)) {
@ -283,7 +297,7 @@ static QHostAddress findBestAddressMatchV4(const QVector<QHostAddress> &hostAddr
QHostAddress matchingIp = hostAddresses[0]; QHostAddress matchingIp = hostAddresses[0];
int matchingBits = -1; int matchingBits = -1;
quint32 rawOtherIp = otherIp.toIPv4Address(); quint32 rawOtherIp = otherIp.toIPv4Address();
for (const QHostAddress& ip : hostAddresses) { for (const QHostAddress &ip : hostAddresses) {
Q_ASSERT(ip.protocol() == QAbstractSocket::IPv4Protocol); Q_ASSERT(ip.protocol() == QAbstractSocket::IPv4Protocol);
quint32 rawMyIp = ip.toIPv4Address(); quint32 rawMyIp = ip.toIPv4Address();
// Since we don't have the network mask, we just compare the prefixes of the IPs to find the longest match // Since we don't have the network mask, we just compare the prefixes of the IPs to find the longest match
@ -299,7 +313,7 @@ static QHostAddress findBestAddressMatchV4(const QVector<QHostAddress> &hostAddr
return matchingIp; return matchingIp;
} }
static QHostAddress findBestAddressMatchV6(const QVector<QHostAddress>& hostAddresses, const struct sockaddr *fromAddress) static QHostAddress findBestAddressMatchV6(const QVector<QHostAddress> &hostAddresses, const struct sockaddr *fromAddress)
{ {
Q_ASSERT(!hostAddresses.empty()); Q_ASSERT(!hostAddresses.empty());
// We could do the same logic for v6 that we do for V4, but we don't care that much about IPv6 // We could do the same logic for v6 that we do for V4, but we don't care that much about IPv6
@ -349,10 +363,22 @@ static mdns_record_t createMdnsRecord(const Announcer::AnnouncedInfo &self,
} }
// Callback handling questions incoming on service sockets // Callback handling questions incoming on service sockets
static int service_callback(int sock, const struct sockaddr* from, size_t addrlen, mdns_entry_type_t entry_type, static int service_callback(int sock,
uint16_t query_id, uint16_t record_type, uint16_t rclass, uint32_t ttl, const void* data, const struct sockaddr *from,
size_t size, size_t name_offset, size_t name_length, size_t record_offset, size_t addrlen,
size_t record_length, void* user_data) { mdns_entry_type_t entry_type,
uint16_t query_id,
uint16_t record_type,
uint16_t rclass,
uint32_t ttl,
const void *data,
size_t size,
size_t name_offset,
size_t name_length,
size_t record_offset,
size_t record_length,
void *user_data)
{
Q_UNUSED(ttl); Q_UNUSED(ttl);
Q_UNUSED(name_length); Q_UNUSED(name_length);
Q_UNUSED(record_offset); Q_UNUSED(record_offset);
@ -379,9 +405,20 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE); uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE);
if (unicast) { if (unicast) {
ret = mdns_query_answer_unicast(sock, from, addrlen, sendbuffer, sizeof(sendbuffer), query_id, ret = mdns_query_answer_unicast(sock,
(mdns_record_type_t)record_type, nameMdnsString.str, nameMdnsString.length, from,
answer, nullptr, 0, nullptr, 0); addrlen,
sendbuffer,
sizeof(sendbuffer),
query_id,
(mdns_record_type_t)record_type,
nameMdnsString.str,
nameMdnsString.length,
answer,
nullptr,
0,
nullptr,
0);
} else { } else {
ret = mdns_query_answer_multicast(sock, sendbuffer, sizeof(sendbuffer), answer, nullptr, 0, nullptr, 0); ret = mdns_query_answer_multicast(sock, sendbuffer, sizeof(sendbuffer), answer, nullptr, 0, nullptr, 0);
} }
@ -409,12 +446,22 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE); uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE);
if (unicast) { if (unicast) {
ret = mdns_query_answer_unicast(sock, from, addrlen, sendbuffer, sizeof(sendbuffer), query_id, ret = mdns_query_answer_unicast(sock,
(mdns_record_type_t)record_type, nameMdnsString.str, nameMdnsString.length, from,
answer, nullptr, 0, additional.constData(), additional.length()); addrlen,
sendbuffer,
sizeof(sendbuffer),
query_id,
(mdns_record_type_t)record_type,
nameMdnsString.str,
nameMdnsString.length,
answer,
nullptr,
0,
additional.constData(),
additional.length());
} else { } else {
ret = mdns_query_answer_multicast(sock, sendbuffer, sizeof(sendbuffer), answer, nullptr, 0, ret = mdns_query_answer_multicast(sock, sendbuffer, sizeof(sendbuffer), answer, nullptr, 0, additional.constData(), additional.length());
additional.constData(), additional.length());
} }
} }
} else if (name == self.serviceInstance) { } else if (name == self.serviceInstance) {
@ -439,12 +486,22 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE); uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE);
if (unicast) { if (unicast) {
ret = mdns_query_answer_unicast(sock, from, addrlen, sendbuffer, sizeof(sendbuffer), query_id, ret = mdns_query_answer_unicast(sock,
(mdns_record_type_t)record_type, nameMdnsString.str, nameMdnsString.length, from,
answer, nullptr, 0, additional.constData(), additional.length()); addrlen,
sendbuffer,
sizeof(sendbuffer),
query_id,
(mdns_record_type_t)record_type,
nameMdnsString.str,
nameMdnsString.length,
answer,
nullptr,
0,
additional.constData(),
additional.length());
} else { } else {
ret = mdns_query_answer_multicast(sock, sendbuffer, sizeof(sendbuffer), answer, nullptr, 0, ret = mdns_query_answer_multicast(sock, sendbuffer, sizeof(sendbuffer), answer, nullptr, 0, additional.constData(), additional.length());
additional.constData(), additional.length());
} }
} }
} else if (name == self.hostname) { } else if (name == self.hostname) {
@ -465,12 +522,22 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE); uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE);
if (unicast) { if (unicast) {
ret = mdns_query_answer_unicast(sock, from, addrlen, sendbuffer, sizeof(sendbuffer), query_id, ret = mdns_query_answer_unicast(sock,
(mdns_record_type_t)record_type, nameMdnsString.str, nameMdnsString.length, from,
answer, nullptr, 0, additional.constData(), additional.length()); addrlen,
sendbuffer,
sizeof(sendbuffer),
query_id,
(mdns_record_type_t)record_type,
nameMdnsString.str,
nameMdnsString.length,
answer,
nullptr,
0,
additional.constData(),
additional.length());
} else { } else {
ret = mdns_query_answer_multicast(sock, sendbuffer, sizeof(sendbuffer), answer, nullptr, 0, ret = mdns_query_answer_multicast(sock, sendbuffer, sizeof(sendbuffer), answer, nullptr, 0, additional.constData(), additional.length());
additional.constData(), additional.length());
} }
} else if (((record_type == MDNS_RECORDTYPE_AAAA) || (record_type == MDNS_RECORDTYPE_ANY)) && !self.addressesV6.empty()) { } else if (((record_type == MDNS_RECORDTYPE_AAAA) || (record_type == MDNS_RECORDTYPE_ANY)) && !self.addressesV6.empty()) {
// The AAAA query was for our qualified hostname and we have an IPv6 address, answer with an AAAA // The AAAA query was for our qualified hostname and we have an IPv6 address, answer with an AAAA
@ -489,12 +556,22 @@ static int service_callback(int sock, const struct sockaddr* from, size_t addrle
uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE); uint16_t unicast = (rclass & MDNS_UNICAST_RESPONSE);
if (unicast) { if (unicast) {
ret = mdns_query_answer_unicast(sock, from, addrlen, sendbuffer, sizeof(sendbuffer), query_id, ret = mdns_query_answer_unicast(sock,
(mdns_record_type_t)record_type, nameMdnsString.str, nameMdnsString.length, from,
answer, nullptr, 0, additional.constData(), additional.length()); addrlen,
sendbuffer,
sizeof(sendbuffer),
query_id,
(mdns_record_type_t)record_type,
nameMdnsString.str,
nameMdnsString.length,
answer,
nullptr,
0,
additional.constData(),
additional.length());
} else { } else {
ret = mdns_query_answer_multicast(sock, sendbuffer, sizeof(sendbuffer), answer, nullptr, 0, ret = mdns_query_answer_multicast(sock, sendbuffer, sizeof(sendbuffer), answer, nullptr, 0, additional.constData(), additional.length());
additional.constData(), additional.length());
} }
} }
} // else request is not for me } // else request is not for me

View file

@ -21,7 +21,6 @@
*/ */
namespace MdnsWrapper namespace MdnsWrapper
{ {
class KDECONNECTCORE_EXPORT Discoverer : public QObject class KDECONNECTCORE_EXPORT Discoverer : public QObject
{ {
Q_OBJECT Q_OBJECT

View file

@ -96,7 +96,7 @@ void DBusInstancePrivate::launchDBusDaemon()
m_dbusProcess->setStandardOutputFile(KdeConnectConfig::instance().privateDBusAddressPath()); m_dbusProcess->setStandardOutputFile(KdeConnectConfig::instance().privateDBusAddressPath());
m_dbusProcess->setStandardErrorFile(QProcess::nullDevice()); m_dbusProcess->setStandardErrorFile(QProcess::nullDevice());
m_dbusProcess->start(); m_dbusProcess->start();
m_dbusProcess->waitForStarted(); // Avoid potential racing condition m_dbusProcess->waitForStarted(); // Avoid potential racing condition
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
// Set launchctl env // Set launchctl env

View file

@ -19,7 +19,6 @@ extern "C" {
namespace SslHelper namespace SslHelper
{ {
QString getSslError() QString getSslError()
{ {
char buf[256]; char buf[256];

View file

@ -34,11 +34,7 @@ IndicatorHelper::IndicatorHelper()
m_splashScreen = new QSplashScreen(splashPixmap); m_splashScreen = new QSplashScreen(splashPixmap);
// Icon is white, set the text color to black // Icon is white, set the text color to black
m_splashScreen->showMessage( m_splashScreen->showMessage(i18n("Launching") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::black);
i18n("Launching") + QStringLiteral("\n"),
Qt::AlignHCenter | Qt::AlignBottom,
Qt::black
);
m_splashScreen->show(); m_splashScreen->show();
} }
@ -88,11 +84,7 @@ int IndicatorHelper::daemonHook(QProcess &kdeconnectd)
} }
// Start daemon // Start daemon
m_splashScreen->showMessage( m_splashScreen->showMessage(i18n("Launching daemon") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::black);
i18n("Launching daemon") + QStringLiteral("\n"),
Qt::AlignHCenter | Qt::AlignBottom,
Qt::black
);
// Here we will try to bring our private session D-Bus // Here we will try to bring our private session D-Bus
if (!hasUsableSessionBus) { if (!hasUsableSessionBus) {
@ -101,11 +93,7 @@ int IndicatorHelper::daemonHook(QProcess &kdeconnectd)
DBusHelper::launchDBusDaemon(); DBusHelper::launchDBusDaemon();
// Wait for dbus daemon env // Wait for dbus daemon env
QProcess getLaunchdDBusEnv; QProcess getLaunchdDBusEnv;
m_splashScreen->showMessage( m_splashScreen->showMessage(i18n("Waiting D-Bus") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::black);
i18n("Waiting D-Bus") + QStringLiteral("\n"),
Qt::AlignHCenter | Qt::AlignBottom,
Qt::black
);
int retry = 0; int retry = 0;
getLaunchdDBusEnv.setProgram(QStringLiteral("launchctl")); getLaunchdDBusEnv.setProgram(QStringLiteral("launchctl"));
getLaunchdDBusEnv.setArguments({QStringLiteral("getenv"), QStringLiteral(KDECONNECT_SESSION_DBUS_LAUNCHD_ENV)}); getLaunchdDBusEnv.setArguments({QStringLiteral("getenv"), QStringLiteral(KDECONNECT_SESSION_DBUS_LAUNCHD_ENV)});

View file

@ -78,8 +78,7 @@ DeviceNotificationsDbusInterface::DeviceNotificationsDbusInterface(const QString
NotificationDbusInterface::NotificationDbusInterface(const QString &deviceId, const QString &notificationId, QObject *parent) NotificationDbusInterface::NotificationDbusInterface(const QString &deviceId, const QString &notificationId, QObject *parent)
: OrgKdeKdeconnectDeviceNotificationsNotificationInterface(DaemonDbusInterface::activatedService(), : OrgKdeKdeconnectDeviceNotificationsNotificationInterface(DaemonDbusInterface::activatedService(),
QLatin1String("/modules/kdeconnect/devices/%1/notifications/").arg(deviceId) QLatin1String("/modules/kdeconnect/devices/%1/notifications/").arg(deviceId) + notificationId,
+ notificationId,
QDBusConnection::sessionBus(), QDBusConnection::sessionBus(),
parent) parent)
, id(notificationId) , id(notificationId)

View file

@ -26,7 +26,8 @@ K_PLUGIN_CLASS_WITH_JSON(MprisControlPlugin, "kdeconnect_mpriscontrol.json")
namespace namespace
{ {
const QString DEFAULT_PLAYER = i18nc("@title Users select this to control the current media player when we can't detect a specific player name like VLC", "Current Player"); const QString DEFAULT_PLAYER =
i18nc("@title Users select this to control the current media player when we can't detect a specific player name like VLC", "Current Player");
} }
MprisControlPlugin::MprisControlPlugin(QObject *parent, const QVariantList &args) MprisControlPlugin::MprisControlPlugin(QObject *parent, const QVariantList &args)
@ -289,8 +290,7 @@ bool MprisControlPlugin::sendAlbumArt(std::variant<NetworkPacket, QString> const
void MprisControlPlugin::handleDefaultPlayer(const NetworkPacket &np) void MprisControlPlugin::handleDefaultPlayer(const NetworkPacket &np)
{ {
if (np.has(QStringLiteral("action"))) { if (np.has(QStringLiteral("action"))) {
INPUT input = {0};
INPUT input={0};
input.type = INPUT_KEYBOARD; input.type = INPUT_KEYBOARD;
input.ki.time = 0; input.ki.time = 0;
@ -300,28 +300,25 @@ void MprisControlPlugin::handleDefaultPlayer(const NetworkPacket &np)
const QString &action = np.get<QString>(QStringLiteral("action")); const QString &action = np.get<QString>(QStringLiteral("action"));
if (action == QStringLiteral("PlayPause") || (action == QStringLiteral("Play")) || (action == QStringLiteral("Pause")) ) { if (action == QStringLiteral("PlayPause") || (action == QStringLiteral("Play")) || (action == QStringLiteral("Pause"))) {
input.ki.wVk = VK_MEDIA_PLAY_PAUSE; input.ki.wVk = VK_MEDIA_PLAY_PAUSE;
::SendInput(1,&input,sizeof(INPUT)); ::SendInput(1, &input, sizeof(INPUT));
} else if (action == QStringLiteral("Stop")) { } else if (action == QStringLiteral("Stop")) {
input.ki.wVk = VK_MEDIA_STOP; input.ki.wVk = VK_MEDIA_STOP;
::SendInput(1,&input,sizeof(INPUT)); ::SendInput(1, &input, sizeof(INPUT));
} } else if (action == QStringLiteral("Next")) {
else if (action == QStringLiteral("Next")) { input.ki.wVk = VK_MEDIA_NEXT_TRACK;
input.ki.wVk = VK_MEDIA_NEXT_TRACK; ::SendInput(1, &input, sizeof(INPUT));
::SendInput(1,&input,sizeof(INPUT)); } else if (action == QStringLiteral("Previous")) {
}
else if (action == QStringLiteral("Previous")) {
input.ki.wVk = VK_MEDIA_PREV_TRACK; input.ki.wVk = VK_MEDIA_PREV_TRACK;
::SendInput(1,&input,sizeof(INPUT)); ::SendInput(1, &input, sizeof(INPUT));
} } else if (action == QStringLiteral("Stop")) {
else if (action == QStringLiteral("Stop")) {
input.ki.wVk = VK_MEDIA_STOP; input.ki.wVk = VK_MEDIA_STOP;
::SendInput(1,&input,sizeof(INPUT)); ::SendInput(1, &input, sizeof(INPUT));
} }
} }
//Send something read from the mpris interface // Send something read from the mpris interface
NetworkPacket answer(PACKET_TYPE_MPRIS); NetworkPacket answer(PACKET_TYPE_MPRIS);
answer.set(QStringLiteral("player"), DEFAULT_PLAYER); answer.set(QStringLiteral("player"), DEFAULT_PLAYER);
bool somethingToSend = false; bool somethingToSend = false;

View file

@ -20,7 +20,8 @@
#include <core/kdeconnectplugin.h> #include <core/kdeconnectplugin.h>
#include <core/kdeconnectpluginconfig.h> #include <core/kdeconnectpluginconfig.h>
namespace { namespace
{
// https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html // https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html
inline constexpr const char *NOTIFY_SIGNATURE = "susssasa{sv}i"; inline constexpr const char *NOTIFY_SIGNATURE = "susssasa{sv}i";
inline constexpr const char *IMAGE_DATA_SIGNATURE = "iiibiiay"; inline constexpr const char *IMAGE_DATA_SIGNATURE = "iiibiiay";
@ -142,7 +143,6 @@ QVariant nextVariant(DBusMessageIter *iter)
case DBUS_TYPE_STRING: case DBUS_TYPE_STRING:
return QVariant(QString::fromUtf8(value.str)); return QVariant(QString::fromUtf8(value.str));
case DBUS_STRUCT_BEGIN_CHAR: { case DBUS_STRUCT_BEGIN_CHAR: {
} }
default: default:
break; break;
@ -253,13 +253,13 @@ DBusNotificationsListener::~DBusNotificationsListener()
} }
void DBusNotificationsListener::onNotify(const QString &appName, void DBusNotificationsListener::onNotify(const QString &appName,
uint replacesId, uint replacesId,
const QString &appIcon, const QString &appIcon,
const QString &summary, const QString &summary,
const QString &body, const QString &body,
const QStringList &actions, const QStringList &actions,
const QVariantMap &hints, const QVariantMap &hints,
int timeout) int timeout)
{ {
Q_UNUSED(actions); Q_UNUSED(actions);
@ -330,7 +330,8 @@ void DBusNotificationsListener::onNotify(const QString &appName,
auto it = hints.constFind(QStringLiteral("image-data")); auto it = hints.constFind(QStringLiteral("image-data"));
if (it != hints.cend() || (it = hints.constFind(QStringLiteral("image_data"))) != hints.cend()) { if (it != hints.cend() || (it = hints.constFind(QStringLiteral("image_data"))) != hints.cend()) {
iconSource = iconForImageData(it.value()); iconSource = iconForImageData(it.value());
} else if ((it = hints.constFind(QStringLiteral("image-path"))) != hints.cend() || (it = hints.constFind(QStringLiteral("image_path"))) != hints.cend()) { } else if ((it = hints.constFind(QStringLiteral("image-path"))) != hints.cend()
|| (it = hints.constFind(QStringLiteral("image_path"))) != hints.cend()) {
iconSource = iconForIconName(it.value().toString()); iconSource = iconForIconName(it.value().toString());
} else if (!appIcon.isEmpty()) { } else if (!appIcon.isEmpty()) {
iconSource = iconForIconName(appIcon); iconSource = iconForIconName(appIcon);
@ -346,13 +347,13 @@ void DBusNotificationsListener::onNotify(const QString &appName,
} }
bool DBusNotificationsListener::parseImageDataArgument(const QVariant &argument, bool DBusNotificationsListener::parseImageDataArgument(const QVariant &argument,
int &width, int &width,
int &height, int &height,
int &rowStride, int &rowStride,
int &bitsPerSample, int &bitsPerSample,
int &channels, int &channels,
bool &hasAlpha, bool &hasAlpha,
QByteArray &imageData) const QByteArray &imageData) const
{ {
// FIXME // FIXME
// if (!argument.canConvert<QDBusArgument>()) { // if (!argument.canConvert<QDBusArgument>()) {

View file

@ -38,13 +38,16 @@ private Q_SLOTS:
QSignalSpy spy(&discoverer, &MdnsWrapper::Discoverer::serviceFound); QSignalSpy spy(&discoverer, &MdnsWrapper::Discoverer::serviceFound);
connect(&discoverer, &MdnsWrapper::Discoverer::serviceFound, this, [instanceName, instancePort, txtKey, txtValue](const MdnsWrapper::Discoverer::MdnsService &service) { connect(&discoverer,
QCOMPARE(instanceName, service.name); &MdnsWrapper::Discoverer::serviceFound,
QCOMPARE(instancePort, service.port); this,
QVERIFY(service.txtRecords.size() == 1); [instanceName, instancePort, txtKey, txtValue](const MdnsWrapper::Discoverer::MdnsService &service) {
QVERIFY(service.txtRecords.contains(txtKey)); QCOMPARE(instanceName, service.name);
QCOMPARE(txtValue, service.txtRecords.value(txtKey)); QCOMPARE(instancePort, service.port);
}); QVERIFY(service.txtRecords.size() == 1);
QVERIFY(service.txtRecords.contains(txtKey));
QCOMPARE(txtValue, service.txtRecords.value(txtKey));
});
announcer.startAnnouncing(); announcer.startAnnouncing();
discoverer.startDiscovering(serviceType); discoverer.startDiscovering(serviceType);