Add Print support

This commit is contained in:
Val Packett 2026-02-27 05:27:53 -03:00
parent 95bc64076d
commit 52a0ccee0d
3 changed files with 82 additions and 5 deletions

View file

@ -2,5 +2,6 @@ pub mod documents;
pub mod file_chooser;
pub mod file_transfer;
pub mod notification;
pub mod print;
pub mod request;
pub mod settings;

View file

@ -0,0 +1,66 @@
use std::collections::HashMap;
use zbus::{Connection, ObjectServer, fdo::Result, zvariant};
use super::request::ReqHandler;
#[derive(Clone)]
pub struct Print {
host: PrintProxy<'static>,
}
#[zbus::interface(
name = "org.freedesktop.portal.Print",
proxy(
default_service = "org.freedesktop.portal.Desktop",
default_path = "/org/freedesktop/portal/desktop"
)
)]
impl Print {
async fn prepare_print(
&self,
#[zbus(header)] hdr: zbus::message::Header<'_>,
#[zbus(object_server)] server: &ObjectServer,
#[zbus(connection)] conn: &Connection,
parent_window: &str,
title: &str,
settings: HashMap<&str, zvariant::Value<'_>>,
page_setup: HashMap<&str, zvariant::Value<'_>>,
options: HashMap<&str, zvariant::Value<'_>>,
) -> Result<zvariant::OwnedObjectPath> {
ReqHandler::prepare(&self.host, hdr, server, conn, &options)
.perform(async || {
self.host
.prepare_print(parent_window, title, settings, page_setup, options)
.await
})
.await
}
async fn print(
&self,
#[zbus(header)] hdr: zbus::message::Header<'_>,
#[zbus(object_server)] server: &ObjectServer,
#[zbus(connection)] conn: &Connection,
parent_window: &str,
title: &str,
fd: zvariant::Fd<'_>,
options: HashMap<&str, zvariant::Value<'_>>,
) -> Result<zvariant::OwnedObjectPath> {
ReqHandler::prepare(&self.host, hdr, server, conn, &options)
.perform(async || self.host.print(parent_window, title, fd, options).await)
.await
}
#[zbus(property, name = "version")]
fn version(&self) -> Result<u32> {
Ok(3)
}
}
impl Print {
pub async fn new(host_session_conn: &Connection) -> Result<Self> {
let host = PrintProxy::builder(host_session_conn).build().await?;
Ok(Self { host })
}
}