AttachmentStore now has its own runloop, can download attachments
This commit is contained in:
@@ -11,21 +11,18 @@ use crate::daemon::{
|
||||
Attachment, DaemonResult,
|
||||
};
|
||||
|
||||
use crate::dbus::endpoint::DbusRegistry;
|
||||
use crate::dbus::interface::NetBuzzertKordophoneRepository as DbusRepository;
|
||||
use crate::dbus::interface::NetBuzzertKordophoneSettings as DbusSettings;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ServerImpl {
|
||||
event_sink: mpsc::Sender<Event>,
|
||||
dbus_registry: DbusRegistry,
|
||||
}
|
||||
|
||||
impl ServerImpl {
|
||||
pub fn new(event_sink: mpsc::Sender<Event>, dbus_registry: DbusRegistry) -> Self {
|
||||
pub fn new(event_sink: mpsc::Sender<Event>) -> Self {
|
||||
Self {
|
||||
event_sink: event_sink,
|
||||
dbus_registry: dbus_registry,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,28 +184,34 @@ impl DbusRepository for ServerImpl {
|
||||
fn get_attachment_info(
|
||||
&mut self,
|
||||
attachment_id: String,
|
||||
) -> Result<(String, bool, u32), dbus::MethodErr> {
|
||||
) -> Result<(String, String, bool, bool), 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
|
||||
};
|
||||
|
||||
let path = attachment.get_path(false);
|
||||
let downloaded = attachment.is_downloaded(false);
|
||||
|
||||
let preview_path = attachment.get_path(true);
|
||||
let preview_downloaded = attachment.is_downloaded(true);
|
||||
|
||||
(
|
||||
attachment.path.to_string_lossy().to_string(),
|
||||
attachment.downloaded,
|
||||
file_size,
|
||||
// - path: string
|
||||
path.to_string_lossy().to_string(),
|
||||
|
||||
// - preview_path: string
|
||||
preview_path.to_string_lossy().to_string(),
|
||||
|
||||
// - downloaded: boolean
|
||||
downloaded,
|
||||
|
||||
// - preview_downloaded: boolean
|
||||
preview_downloaded,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn download_attachment(&mut self, attachment_id: String) -> Result<(), dbus::MethodErr> {
|
||||
fn download_attachment(&mut self, attachment_id: String, preview: bool) -> 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))
|
||||
self.send_event_sync(|r| Event::DownloadAttachment(attachment_id, preview, r))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user