Skip to content

DRAFT - Network Manager Service #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ boption(SERVICE_MPRIS "Mpris" ON)
boption(SERVICE_PAM "Pam" ON)
boption(SERVICE_GREETD "Greetd" ON)
boption(SERVICE_UPOWER "UPower" ON)
boption(SERVICE_NETWORKMANAGER "NetworkManager" ON)
boption(SERVICE_NOTIFICATIONS "Notifications" ON)
boption(BLUETOOTH "Bluetooth" ON)

Expand Down
6 changes: 5 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
libdrm,
libgbm ? null,
pipewire,
networkmanager,
pam,

gitRev ? (let
Expand All @@ -40,6 +41,7 @@
withWayland ? true,
withX11 ? true,
withPipewire ? true,
withNetworkmanager ? true,
withPam ? true,
withHyprland ? true,
withI3 ? true,
Expand Down Expand Up @@ -70,7 +72,8 @@
++ lib.optionals (withWayland && libgbm != null) [ libdrm libgbm ]
++ lib.optional withX11 xorg.libxcb
++ lib.optional withPam pam
++ lib.optional withPipewire pipewire;
++ lib.optional withPipewire pipewire
++ lib.optional withNetworkmanager networkmanager;

cmakeBuildType = if debug then "Debug" else "RelWithDebInfo";

Expand All @@ -84,6 +87,7 @@
(lib.cmakeBool "WAYLAND" withWayland)
(lib.cmakeBool "SCREENCOPY" (libgbm != null))
(lib.cmakeBool "SERVICE_PIPEWIRE" withPipewire)
(lib.cmakeBool "SERVICE_NETWORKMANAGER" withNetworkmanager)
(lib.cmakeBool "SERVICE_PAM" withPam)
(lib.cmakeBool "HYPRLAND" withHyprland)
(lib.cmakeBool "I3" withI3)
Expand Down
4 changes: 4 additions & 0 deletions src/services/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ if (SERVICE_PIPEWIRE)
add_subdirectory(pipewire)
endif()

if (SERVICE_NETWORKMANAGER)
add_subdirectory(networkmanager)
endif()

if (SERVICE_MPRIS)
add_subdirectory(mpris)
endif()
Expand Down
41 changes: 41 additions & 0 deletions src/services/networkmanager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
find_package(PkgConfig REQUIRED)
# Not using libnm
#pkg_check_modules(networkmanager REQUIRED IMPORTED_TARGET libnm)

set_source_files_properties(org.freedesktop.NetworkManager.xml PROPERTIES
CLASSNAME DBusNetworkManagerService
NO_NAMESPACE TRUE
)
qt_add_dbus_interface(DBUS_INTERFACES
org.freedesktop.NetworkManager.xml
dbus_service
)

qt_add_library(quickshell-service-networkmanager STATIC
core.cpp
${DBUS_INTERFACES}
)

# dbus headers
target_include_directories(quickshell-service-networkmanager PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

qt_add_qml_module(quickshell-service-networkmanager
URI Quickshell.Services.NetworkManager
VERSION 0.1
DEPENDENCIES QtQml
)

# Not sure what this is doing
qs_add_module_deps_light(quickshell-service-networkmanager Quickshell)

install_qml_module(quickshell-service-networkmanager)

target_link_libraries(quickshell-service-networkmanager PRIVATE
Qt::Qml
#Qt::Quick # pch
Qt::DBus
)
qs_add_link_dependencies(quickshell-service-networkmanager quickshell-dbus)
target_link_libraries(quickshell PRIVATE quickshell-service-networkmanagerplugin)

qs_module_pch(quickshell-service-networkmanager)
56 changes: 56 additions & 0 deletions src/services/networkmanager/core.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <qdbusconnection.h>
#include <qlogging.h>
#include <qloggingcategory.h>
#include <qdbusextratypes.h>
#include "core.hpp"
#include "dbus_service.h"
#include <qdbusmetatype.h>
#include <qtypes.h>

#include "../../dbus/bus.hpp"

namespace qs::service::networkmanager {

namespace {
Q_LOGGING_CATEGORY(logNetworkManager, "quickshell.service.networkmanager", QtDebugMsg);
}

NetworkManager::NetworkManager(){
//qDBusRegisterMetaType<QList<quint32>>();

auto bus = QDBusConnection::systemBus();

if (!bus.isConnected()) {
// Log message
qCWarning(logNetworkManager) << "Could not connect to DBus. NetworkManager service will not work.";
return;
}

this->service = new DBusNetworkManagerService("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", bus, this);

if (!this->service->isValid()) {
qCDebug(logNetworkManager) << "NetworkManager service is not currently running, attempting to start it.";

dbus::tryLaunchService(this, bus, "org.freedesktop.NetworkManager", [this](bool success) {
if (success) {
qCDebug(logNetworkManager) << "Successfully launched NetworkManager service.";
this->init();
} else {
qCWarning(logNetworkManager) << "Could not start NetworkManager. The NetworkManager service will not work.";
}
});
} else {
this->init();
}
}

NetworkManager* NetworkManager::instance() {
static NetworkManager* instance = new NetworkManager(); // NOLINT
return instance;
}

void NetworkManager::init() {
qCDebug(logNetworkManager) << "Hi mom";
}

}
26 changes: 26 additions & 0 deletions src/services/networkmanager/core.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <qobject.h>
#include <qdbusextratypes.h>
#include "dbus_service.h"
#include <qtypes.h>

// Define the "au" dbus type
using dbus_type_au = QList<quint32>;
Q_DECLARE_METATYPE(dbus_type_au);
// Define the "a{sv}" dbus type
//using NetworkManagerCapabilities = QList<quint32>;

namespace qs::service::networkmanager {

class NetworkManager : public QObject {
Q_OBJECT;
public:
static NetworkManager* instance(); // Get instance of the class
private:
NetworkManager();
DBusNetworkManagerService* service = nullptr;
void init();
};

}
Loading