Debian Codegraph @

src/backend/print.rs

raw
1 use std::sync::Arc;
2
3 use async_trait::async_trait;
4
5 use crate::{
6 MaybeAppID, WindowIdentifierType,
7 backend::{
8 Result,
9 request::{Request, RequestImpl},
10 },
11 desktop::{
12 HandleToken,
13 print::{PageSetup, PreparePrint, PreparePrintOptions, PrintOptions, Settings},
14 request::Response,
15 },
16 zvariant::{self, Optional, OwnedObjectPath},
17 };
18
19 #[async_trait]
20 pub trait PrintImpl: RequestImpl {
21 #[allow(clippy::too_many_arguments)]
22 #[doc(alias = "PreparePrint")]
23 async fn prepare_print(
24 &self,
25 token: HandleToken,
26 app_id: Option<MaybeAppID>,
27 parent_window: Option<WindowIdentifierType>,
28 title: String,
29 settings: Settings,
30 page_setup: PageSetup,
31 options: PreparePrintOptions,
32 ) -> Result<PreparePrint>;
33
34 #[doc(alias = "Print")]
35 async fn print(
36 &self,
37 token: HandleToken,
38 app_id: Option<MaybeAppID>,
39 parent_window: Option<WindowIdentifierType>,
40 title: String,
41 fd: zvariant::OwnedFd,
42 options: PrintOptions,
43 ) -> Result<()>;
44 }
45
46 pub(crate) struct PrintInterface {
47 imp: Arc<dyn PrintImpl>,
48 spawn: Arc<dyn futures_util::task::Spawn + Send + Sync>,
49 cnx: zbus::Connection,
50 }
51
52 impl PrintInterface {
53 pub fn new(
54 imp: Arc<dyn PrintImpl>,
55 cnx: zbus::Connection,
56 spawn: Arc<dyn futures_util::task::Spawn + Send + Sync>,
57 ) -> Self {
58 Self { imp, cnx, spawn }
59 }
60 }
61
62 #[zbus::interface(name = "org.freedesktop.impl.portal.Print")]
63 impl PrintInterface {
64 #[zbus(property(emits_changed_signal = "const"), name = "version")]
65 fn version(&self) -> u32 {
66 3
67 }
68
69 #[allow(clippy::too_many_arguments)]
70 #[zbus(out_args("response", "results"))]
71 async fn prepare_print(
72 &self,
73 handle: OwnedObjectPath,
74 app_id: Optional<MaybeAppID>,
75 window_identifier: Optional<WindowIdentifierType>,
76 title: String,
77 settings: Settings,
78 page_setup: PageSetup,
79 options: PreparePrintOptions,
80 ) -> Result<Response<PreparePrint>> {
81 let imp = Arc::clone(&self.imp);
82
83 Request::spawn(
84 "Print::PreparePrint",
85 &self.cnx,
86 handle.clone(),
87 Arc::clone(&self.imp),
88 Arc::clone(&self.spawn),
89 async move {
90 imp.prepare_print(
91 HandleToken::try_from(&handle).unwrap(),
92 app_id.into(),
93 window_identifier.into(),
94 title,
95 settings,
96 page_setup,
97 options,
98 )
99 .await
100 },
101 )
102 .await
103 }
104
105 #[allow(clippy::too_many_arguments)]
106 #[zbus(out_args("response", "results"))]
107 async fn print(
108 &self,
109 handle: OwnedObjectPath,
110 app_id: Optional<MaybeAppID>,
111 window_identifier: Optional<WindowIdentifierType>,
112 title: String,
113 fd: zvariant::OwnedFd,
114 options: PrintOptions,
115 ) -> Result<Response<()>> {
116 let imp = Arc::clone(&self.imp);
117
118 Request::spawn(
119 "Print::Print",
120 &self.cnx,
121 handle.clone(),
122 Arc::clone(&self.imp),
123 Arc::clone(&self.spawn),
124 async move {
125 imp.print(
126 HandleToken::try_from(&handle).unwrap(),
127 app_id.into(),
128 window_identifier.into(),
129 title,
130 fd,
131 options,
132 )
133 .await
134 },
135 )
136 .await
137 }
138 }