Add settings bindings

This commit is contained in:
Lucy 2022-01-21 11:01:06 -05:00
parent e660731756
commit e2c2fdea8f
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
3 changed files with 36 additions and 15 deletions

View file

@ -22,6 +22,7 @@
pub mod connection;
use crate::settings::connection::Settings;
use zbus::dbus_proxy;
#[dbus_proxy(
@ -33,19 +34,13 @@ pub trait Settings {
/// AddConnection method
fn add_connection(
&self,
connection: std::collections::HashMap<
&str,
std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
>,
connection: &Settings,
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
/// AddConnection2 method
fn add_connection2(
&self,
settings: std::collections::HashMap<
&str,
std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
>,
settings: &Settings,
flags: u32,
args: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
) -> zbus::Result<(
@ -56,10 +51,7 @@ pub trait Settings {
/// AddConnectionUnsaved method
fn add_connection_unsaved(
&self,
connection: std::collections::HashMap<
&str,
std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
>,
connection: &Settings,
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
/// GetConnectionByUuid method

View file

@ -9,7 +9,7 @@ use crate::{
enums::{ConnectivityState, State},
NetworkManagerProxy,
},
settings::connection::Connection,
settings::{connection::Connection, NetworkManagerSettings},
};
use zbus::{zvariant::ObjectPath, Result};
@ -80,7 +80,11 @@ impl<'a> NetworkManager<'a> {
Ok(out)
}
pub async fn state(&self) -> State {
self.0.state().await.map(State::from).unwrap()
pub async fn state(&self) -> Result<State> {
self.0.state().await.map(State::from)
}
pub async fn settings(&'a self) -> Result<NetworkManagerSettings<'a>> {
NetworkManagerSettings::new(self.0.connection()).await
}
}

View file

@ -1,3 +1,28 @@
// SPDX-License-Identifier: MPL-2.0
pub mod connection;
use self::connection::Connection;
use crate::interface::settings::{connection::ConnectionSettingsProxy, SettingsProxy};
use zbus::Result;
pub struct NetworkManagerSettings<'a>(SettingsProxy<'a>);
impl<'a> NetworkManagerSettings<'a> {
pub async fn new(connection: &'a zbus::Connection) -> Result<NetworkManagerSettings<'a>> {
SettingsProxy::new(connection).await.map(Self)
}
pub async fn list_connections(&'a self) -> Result<Vec<Connection<'a>>> {
let connections = self.0.list_connections().await?;
let mut out = Vec::with_capacity(connections.len());
for connection in connections {
let connection = ConnectionSettingsProxy::builder(self.0.connection())
.path(connection)?
.build()
.await?;
out.push(connection.into());
}
Ok(out)
}
}