Add settings bindings
This commit is contained in:
parent
e660731756
commit
e2c2fdea8f
3 changed files with 36 additions and 15 deletions
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
pub mod connection;
|
pub mod connection;
|
||||||
|
|
||||||
|
use crate::settings::connection::Settings;
|
||||||
use zbus::dbus_proxy;
|
use zbus::dbus_proxy;
|
||||||
|
|
||||||
#[dbus_proxy(
|
#[dbus_proxy(
|
||||||
|
|
@ -33,19 +34,13 @@ pub trait Settings {
|
||||||
/// AddConnection method
|
/// AddConnection method
|
||||||
fn add_connection(
|
fn add_connection(
|
||||||
&self,
|
&self,
|
||||||
connection: std::collections::HashMap<
|
connection: &Settings,
|
||||||
&str,
|
|
||||||
std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
|
||||||
>,
|
|
||||||
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||||
|
|
||||||
/// AddConnection2 method
|
/// AddConnection2 method
|
||||||
fn add_connection2(
|
fn add_connection2(
|
||||||
&self,
|
&self,
|
||||||
settings: std::collections::HashMap<
|
settings: &Settings,
|
||||||
&str,
|
|
||||||
std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
|
||||||
>,
|
|
||||||
flags: u32,
|
flags: u32,
|
||||||
args: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
args: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
||||||
) -> zbus::Result<(
|
) -> zbus::Result<(
|
||||||
|
|
@ -56,10 +51,7 @@ pub trait Settings {
|
||||||
/// AddConnectionUnsaved method
|
/// AddConnectionUnsaved method
|
||||||
fn add_connection_unsaved(
|
fn add_connection_unsaved(
|
||||||
&self,
|
&self,
|
||||||
connection: std::collections::HashMap<
|
connection: &Settings,
|
||||||
&str,
|
|
||||||
std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
|
|
||||||
>,
|
|
||||||
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||||
|
|
||||||
/// GetConnectionByUuid method
|
/// GetConnectionByUuid method
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
enums::{ConnectivityState, State},
|
enums::{ConnectivityState, State},
|
||||||
NetworkManagerProxy,
|
NetworkManagerProxy,
|
||||||
},
|
},
|
||||||
settings::connection::Connection,
|
settings::{connection::Connection, NetworkManagerSettings},
|
||||||
};
|
};
|
||||||
use zbus::{zvariant::ObjectPath, Result};
|
use zbus::{zvariant::ObjectPath, Result};
|
||||||
|
|
||||||
|
|
@ -80,7 +80,11 @@ impl<'a> NetworkManager<'a> {
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn state(&self) -> State {
|
pub async fn state(&self) -> Result<State> {
|
||||||
self.0.state().await.map(State::from).unwrap()
|
self.0.state().await.map(State::from)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn settings(&'a self) -> Result<NetworkManagerSettings<'a>> {
|
||||||
|
NetworkManagerSettings::new(self.0.connection()).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,28 @@
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
pub mod connection;
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue