mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-04-21 21:52:03 +02:00
nm: add libnm support for connectivity change detection (linux)
Change-Id: I014999c80cfbc725ff36e517696a3ffb237a6213
This commit is contained in:
parent
008ab0aeb2
commit
a4787e2a45
5 changed files with 104 additions and 12 deletions
|
@ -117,6 +117,13 @@ set(COMMON_HEADERS
|
||||||
${SRC_DIR}/qtutils.h
|
${SRC_DIR}/qtutils.h
|
||||||
${SRC_DIR}/utilsadapter.h)
|
${SRC_DIR}/utilsadapter.h)
|
||||||
|
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(LIBNM libnm)
|
||||||
|
|
||||||
|
if(LIBNM_FOUND)
|
||||||
|
add_definitions(-DUSE_LIBNM)
|
||||||
|
endif()
|
||||||
|
|
||||||
find_package(Qt5 CONFIG REQUIRED
|
find_package(Qt5 CONFIG REQUIRED
|
||||||
Core
|
Core
|
||||||
Quick
|
Quick
|
||||||
|
@ -130,7 +137,10 @@ find_package(Qt5 CONFIG REQUIRED
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${SRC_DIR}
|
${SRC_DIR}
|
||||||
${LRC}/include/libringclient
|
${LRC}/include/libringclient
|
||||||
${LRC}/include)
|
${LRC}/include
|
||||||
|
${LIBNM_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
link_libraries(${LIBNM_LIBRARIES})
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
${SRC_DIR}/main.cpp
|
${SRC_DIR}/main.cpp
|
||||||
|
@ -139,13 +149,13 @@ add_executable(${PROJECT_NAME}
|
||||||
${QML_RESOURCES}
|
${QML_RESOURCES}
|
||||||
${QML_RESOURCES_QML})
|
${QML_RESOURCES_QML})
|
||||||
|
|
||||||
# alternative: link_directories(${LRC}/lib)
|
|
||||||
find_library(ringclient ringclient ${LRC}/lib NO_DEFAULT_PATH)
|
find_library(ringclient ringclient ${LRC}/lib NO_DEFAULT_PATH)
|
||||||
find_library(qrencode qrencode)
|
find_library(qrencode qrencode)
|
||||||
|
|
||||||
target_link_libraries(jami-qt
|
target_link_libraries(jami-qt
|
||||||
${QML_LIBS}
|
${QML_LIBS}
|
||||||
${ringclient}
|
${ringclient}
|
||||||
${qrencode})
|
${qrencode}
|
||||||
|
)
|
||||||
|
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
|
|
@ -105,10 +105,17 @@ unix {
|
||||||
LIBS += -lqrencode
|
LIBS += -lqrencode
|
||||||
LIBS += -lX11
|
LIBS += -lX11
|
||||||
|
|
||||||
|
CONFIG += link_pkgconfig
|
||||||
|
PKGCONFIG += libnm
|
||||||
|
|
||||||
isEmpty(PREFIX) { PREFIX = /tmp/$${TARGET}/bin }
|
isEmpty(PREFIX) { PREFIX = /tmp/$${TARGET}/bin }
|
||||||
target.path = $$PREFIX/bin
|
target.path = $$PREFIX/bin
|
||||||
INSTALLS += target
|
INSTALLS += target
|
||||||
|
|
||||||
|
packagesExist(libnm) {
|
||||||
|
DEFINES += USE_LIBNM
|
||||||
|
}
|
||||||
|
|
||||||
# unix specific
|
# unix specific
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/xrectsel.h
|
src/xrectsel.h
|
||||||
|
|
|
@ -16,10 +16,15 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <glib.h>
|
||||||
|
#include <NetworkManager.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "connectivitymonitor.h"
|
#include "connectivitymonitor.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include <QDebug>
|
|
||||||
#include <atlbase.h>
|
#include <atlbase.h>
|
||||||
#include <netlistmgr.h>
|
#include <netlistmgr.h>
|
||||||
|
|
||||||
|
@ -158,4 +163,78 @@ ConnectivityMonitor::~ConnectivityMonitor()
|
||||||
destroy();
|
destroy();
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#ifdef USE_LIBNM
|
||||||
|
static void
|
||||||
|
logConnectionInfo(NMActiveConnection *connection)
|
||||||
|
{
|
||||||
|
if (connection) {
|
||||||
|
qDebug() << "primary network connection:"
|
||||||
|
<< nm_active_connection_get_uuid(connection)
|
||||||
|
<< "default: "
|
||||||
|
<< (nm_active_connection_get_default(connection) ? "yes" : "no");
|
||||||
|
} else {
|
||||||
|
qWarning() << "no primary network connection detected, check network settings";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
primaryConnectionChanged(NMClient *nm, GParamSpec*, ConnectivityMonitor * cm)
|
||||||
|
{
|
||||||
|
auto connection = nm_client_get_primary_connection(nm);
|
||||||
|
logConnectionInfo(connection);
|
||||||
|
cm->connectivityChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nmClientCallback(G_GNUC_UNUSED GObject *source_object,
|
||||||
|
GAsyncResult *result,
|
||||||
|
ConnectivityMonitor * cm)
|
||||||
|
{
|
||||||
|
GError* error = nullptr;
|
||||||
|
if (auto nm_client = nm_client_new_finish(result, &error)) {
|
||||||
|
qDebug() << "NetworkManager client initialized, version: "
|
||||||
|
<< nm_client_get_version(nm_client)
|
||||||
|
<< ", daemon running:"
|
||||||
|
<< (nm_client_get_nm_running(nm_client) ? "yes" : "no")
|
||||||
|
<< ", networking enabled:"
|
||||||
|
<< (nm_client_networking_get_enabled(nm_client) ? "yes" : "no");
|
||||||
|
|
||||||
|
auto connection = nm_client_get_primary_connection(nm_client);
|
||||||
|
logConnectionInfo(connection);
|
||||||
|
g_signal_connect(nm_client, "notify::active-connections",
|
||||||
|
G_CALLBACK(primaryConnectionChanged), cm);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
qWarning() << "error initializing NetworkManager client: "
|
||||||
|
<< error->message;
|
||||||
|
g_clear_error(&error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ConnectivityMonitor::ConnectivityMonitor(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
GCancellable * cancellable = g_cancellable_new();
|
||||||
|
#ifdef USE_LIBNM
|
||||||
|
nm_client_new_async(cancellable, (GAsyncReadyCallback)nmClientCallback, this);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectivityMonitor::~ConnectivityMonitor()
|
||||||
|
{
|
||||||
|
qDebug() << "Destroying connectivity monitor";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ConnectivityMonitor::isOnline()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // Q_OS_WIN
|
#endif // Q_OS_WIN
|
||||||
|
|
|
@ -44,20 +44,18 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// Dummy implementation for non-Windows platforms.
|
|
||||||
// TODO: platform implementations should be in the daemon.
|
// TODO: platform implementations should be in the daemon.
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
class ConnectivityMonitor final : public QObject
|
class ConnectivityMonitor final : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ConnectivityMonitor(QObject* parent = 0) : QObject(parent) {};
|
explicit ConnectivityMonitor(QObject* parent = 0);
|
||||||
~ConnectivityMonitor() = default;
|
~ConnectivityMonitor();
|
||||||
|
|
||||||
|
bool isOnline();
|
||||||
|
|
||||||
bool isOnline() { return false; };
|
|
||||||
signals:
|
signals:
|
||||||
void connectivityChanged();
|
void connectivityChanged();
|
||||||
};
|
};
|
||||||
// clang-format on
|
|
||||||
#endif // Q_OS_WIN
|
#endif // Q_OS_WIN
|
||||||
|
|
|
@ -148,11 +148,9 @@ MainApplication::init()
|
||||||
|
|
||||||
initLrc(results[opts::UPDATEURL].toString(), connectivityMonitor_);
|
initLrc(results[opts::UPDATEURL].toString(), connectivityMonitor_);
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
connect(connectivityMonitor_, &ConnectivityMonitor::connectivityChanged, [] {
|
connect(connectivityMonitor_, &ConnectivityMonitor::connectivityChanged, [] {
|
||||||
LRCInstance::connectivityChanged();
|
LRCInstance::connectivityChanged();
|
||||||
});
|
});
|
||||||
#endif // Q_OS_WIN
|
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
&LRCInstance::instance(),
|
&LRCInstance::instance(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue