better d-bus interface for attachments
This commit is contained in:
@@ -12,7 +12,6 @@ use crate::daemon::{
|
||||
};
|
||||
|
||||
use crate::dbus::endpoint::DbusRegistry;
|
||||
use crate::dbus::interface::NetBuzzertKordophoneAttachment as DbusAttachment;
|
||||
use crate::dbus::interface::NetBuzzertKordophoneRepository as DbusRepository;
|
||||
use crate::dbus::interface::NetBuzzertKordophoneSettings as DbusSettings;
|
||||
|
||||
@@ -159,27 +158,32 @@ impl DbusRepository for ServerImpl {
|
||||
.map(|uuid| uuid.to_string())
|
||||
}
|
||||
|
||||
fn get_attachment(
|
||||
fn get_attachment_info(
|
||||
&mut self,
|
||||
attachment_id: String,
|
||||
) -> Result<dbus::Path<'static>, dbus::MethodErr> {
|
||||
use crate::dbus::interface;
|
||||
|
||||
self.send_event_sync(|r| Event::GetAttachment(attachment_id.clone(), r))
|
||||
.and_then(|attachment| {
|
||||
let id: &str = attachment_id.split("-").take(1).last().unwrap();
|
||||
let obj_path = format!("/net/buzzert/kordophonecd/attachments/{}", &id);
|
||||
log::trace!("Registering attachment at path: {}", &obj_path);
|
||||
|
||||
self.dbus_registry.register_object(
|
||||
&obj_path,
|
||||
attachment,
|
||||
|cr| vec![interface::register_net_buzzert_kordophone_attachment(cr)]
|
||||
);
|
||||
|
||||
Ok(obj_path.into())
|
||||
) -> Result<(String, bool, u32), dbus::MethodErr> {
|
||||
self.send_event_sync(|r| Event::GetAttachment(attachment_id, r))
|
||||
.map(|attachment| {
|
||||
let file_size = if attachment.downloaded {
|
||||
std::fs::metadata(&attachment.path)
|
||||
.map(|m| m.len() as u32)
|
||||
.unwrap_or(0)
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
(
|
||||
attachment.path.to_string_lossy().to_string(),
|
||||
attachment.downloaded,
|
||||
file_size,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn download_attachment(&mut self, attachment_id: String) -> Result<(), dbus::MethodErr> {
|
||||
// For now, just trigger the download event - we'll implement the actual download logic later
|
||||
self.send_event_sync(|r| Event::DownloadAttachment(attachment_id, r))
|
||||
}
|
||||
}
|
||||
|
||||
impl DbusSettings for ServerImpl {
|
||||
@@ -233,21 +237,6 @@ impl DbusSettings for ServerImpl {
|
||||
}
|
||||
}
|
||||
|
||||
impl DbusAttachment for Attachment {
|
||||
fn file_path(&self) -> Result<String, dbus::MethodErr> {
|
||||
Ok(self.path.as_os_str().to_os_string().into_string().unwrap())
|
||||
}
|
||||
|
||||
fn downloaded(&self) -> Result<bool, dbus::MethodErr> {
|
||||
Ok(self.downloaded)
|
||||
}
|
||||
|
||||
fn delete(&mut self) -> Result<(), dbus::MethodErr> {
|
||||
// Mostly a placeholder method because dbuscodegen for some reason barfs on this
|
||||
// if there are no methods defined.
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn run_sync_future<F, T>(f: F) -> Result<T, MethodErr>
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user