Add CMake flag to enable MDNS (off by default)

This commit is contained in:
Albert Vaca Cintora 2023-07-10 18:40:57 +02:00
parent 17dcf80f2d
commit bb8e67efc9
5 changed files with 35 additions and 5 deletions

View file

@ -65,7 +65,7 @@ else()
find_package(Qca-qt${QT_MAJOR_VERSION} ${QCA_MIN_VERSION} REQUIRED)
set(Qca_LIBRARY qca-qt${QT_MAJOR_VERSION})
set(KF5_REQUIRED_COMPONENTS I18n ConfigWidgets DBusAddons IconThemes Notifications KIO KCMUtils Service Solid Kirigami2 People WindowSystem GuiAddons DNSSD)
set(KF5_REQUIRED_COMPONENTS I18n ConfigWidgets DBusAddons IconThemes Notifications KIO KCMUtils Service Solid Kirigami2 People WindowSystem GuiAddons)
set(KF5_OPTIONAL_COMPONENTS DocTools)
set_package_properties(KF5Kirigami2 PROPERTIES

View file

@ -18,6 +18,11 @@ configure_file(dbushelper.h.in ${CMAKE_CURRENT_BINARY_DIR}/dbushelper.h)
add_subdirectory(backends/lan)
add_subdirectory(backends/loopback)
option(MDNS_ENABLED "Use MDNS for device discovery" OFF)
if (MDNS_ENABLED)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS DNSSD)
endif()
option(BLUETOOTH_ENABLED "Bluetooth support for kdeconnect" OFF)
if(BLUETOOTH_ENABLED)
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Bluetooth)
@ -63,7 +68,6 @@ PRIVATE
Qt${QT_MAJOR_VERSION}::DBus
KF5::I18n
KF5::ConfigCore
KF5::DNSSD
)
if(WIN32)
@ -83,6 +87,11 @@ if (LOOPBACK_ENABLED)
target_compile_definitions(kdeconnectcore PRIVATE -DKDECONNECT_LOOPBACK)
endif()
if (MDNS_ENABLED)
target_compile_definitions(kdeconnectcore PRIVATE -DKDECONNECT_MDNS)
target_link_libraries(kdeconnectcore PRIVATE KF5::DNSSD)
endif()
set_target_properties(kdeconnectcore PROPERTIES
VERSION ${KDECONNECT_VERSION}
SOVERSION ${KDECONNECT_VERSION_MAJOR}

View file

@ -1,13 +1,21 @@
set(backends_kdeconnect_SRCS
${backends_kdeconnect_SRCS}
backends/lan/server.cpp
backends/lan/lanlinkprovider.cpp
backends/lan/landevicelink.cpp
backends/lan/compositeuploadjob.cpp
backends/lan/uploadjob.cpp
backends/lan/mdnsdiscovery.cpp
)
if (MDNS_ENABLED)
set(backends_kdeconnect_SRCS
${backends_kdeconnect_SRCS}
backends/lan/mdnsdiscovery.cpp
)
endif()
set(backends_kdeconnect_SRCS
${backends_kdeconnect_SRCS}
PARENT_SCOPE
)

View file

@ -46,7 +46,9 @@ LanLinkProvider::LanLinkProvider(bool testMode, quint16 udpBroadcastPort, quint1
, m_udpListenPort(udpListenPort)
, m_testMode(testMode)
, m_combineBroadcastsTimer(this)
#ifdef KDECONNET_MDNS
, m_mdnsDiscovery(this)
#endif
{
m_combineBroadcastsTimer.setInterval(0); // increase this if waiting a single event-loop iteration is not enough
m_combineBroadcastsTimer.setSingleShot(true);
@ -104,16 +106,21 @@ void LanLinkProvider::onStart()
}
broadcastUdpIdentityPacket();
#ifdef KDECONNET_MDNS
m_mdnsDiscovery.startAnnouncing();
m_mdnsDiscovery.startDiscovering();
#endif
qCDebug(KDECONNECT_CORE) << "LanLinkProvider started";
}
void LanLinkProvider::onStop()
{
#ifdef KDECONNET_MDNS
m_mdnsDiscovery.stopAnnouncing();
m_mdnsDiscovery.stopDiscovering();
#endif
m_udpSocket.close();
m_server->close();
qCDebug(KDECONNECT_CORE) << "LanLinkProvider stopped";
@ -139,8 +146,10 @@ void LanLinkProvider::broadcastToNetwork()
Q_ASSERT(m_tcpPort != 0);
broadcastUdpIdentityPacket();
#ifdef KDECONNET_MDNS
m_mdnsDiscovery.stopDiscovering();
m_mdnsDiscovery.startDiscovering();
#endif
}
void LanLinkProvider::broadcastUdpIdentityPacket()

View file

@ -17,8 +17,10 @@
#include "backends/linkprovider.h"
#include "kdeconnectcore_export.h"
#include "landevicelink.h"
#include "mdnsdiscovery.h"
#include "server.h"
#ifdef KDECONNET_MDNS
#include "mdnsdiscovery.h"
#endif
class KDECONNECTCORE_EXPORT LanLinkProvider : public LinkProvider
{
@ -91,7 +93,9 @@ private:
const bool m_testMode;
QTimer m_combineBroadcastsTimer;
#ifdef KDECONNET_MDNS
MdnsDiscovery m_mdnsDiscovery;
#endif
};
#endif