pub struct Frontend { /* private fields */ }Expand description
Safe wrapper around cpdb_frontend_obj_t.
Implementations§
Source§impl Frontend
impl Frontend
Sourcepub fn new_with_callback(cb: cpdb_printer_callback) -> Result<Self>
pub fn new_with_callback(cb: cpdb_printer_callback) -> Result<Self>
Creates a new frontend with a raw printer-update callback.
Prefer Frontend::new_with_observer for closure-based callbacks.
This entry point exists for callers that need to interoperate with a
hand-written extern "C" callback.
The callback is invoked from the cpdb-libs internal D-Bus listener
thread when printers are added, removed, or change state. It must be
thread-safe and must not call back into this Frontend.
Sourcepub fn new_with_observer<F>(observer: F) -> Result<Self>
pub fn new_with_observer<F>(observer: F) -> Result<Self>
Creates a new frontend with a closure-based printer observer.
The observer is invoked from cpdb-libs’ internal D-Bus listener
thread when printers are added, removed, or change state. Because
cpdb_printer_callback carries no user_data, the closure is
stored in a process-global registry keyed by the frontend pointer
and removed automatically when the Frontend is dropped.
The closure must be Send + 'static. Panics inside the closure are
caught by catch_unwind and absorbed; do not rely on panic-based
flow control inside callbacks.
Sourcepub unsafe fn from_raw(raw: *mut cpdb_frontend_obj_t) -> Result<Self>
pub unsafe fn from_raw(raw: *mut cpdb_frontend_obj_t) -> Result<Self>
Wraps an already-allocated frontend object.
§Safety
raw must be a valid pointer to a cpdb_frontend_obj_t obtained from
cpdb-libs, not aliased by any other Rust handle, and not yet freed.
Ownership transfers to the returned Frontend.
Sourcepub fn ignore_last_saved_settings(&self)
pub fn ignore_last_saved_settings(&self)
Tells the frontend to ignore the previously saved settings file.
Must be called before Frontend::connect_to_dbus to take effect.
Sourcepub fn connect_to_dbus(&self) -> Result<()>
pub fn connect_to_dbus(&self) -> Result<()>
Connects to the session D-Bus and activates the print backends.
Sourcepub fn dbus_connected() -> bool
pub fn dbus_connected() -> bool
Returns true when cpdb-libs currently holds a live D-Bus connection.
This consults cpdbGetDbusConnection, which is a process-global —
not per-frontend — query, so the result reflects the overall
cpdb-libs state rather than this specific Frontend.
Sourcepub fn disconnect_from_dbus(&self) -> Result<()>
pub fn disconnect_from_dbus(&self) -> Result<()>
Disconnects from D-Bus.
Sourcepub fn activate_backends(&self)
pub fn activate_backends(&self)
Re-activates the backends (rediscovers printers without disconnecting).
Sourcepub fn start_backend_list_refreshing(&self)
pub fn start_backend_list_refreshing(&self)
Starts the background thread that periodically refreshes the backend list.
Sourcepub fn stop_backend_list_refreshing(&self)
pub fn stop_backend_list_refreshing(&self)
Stops the backend-list refreshing thread; blocks until it joins.
Sourcepub fn start_listing(cb: cpdb_printer_callback) -> Result<Self>
pub fn start_listing(cb: cpdb_printer_callback) -> Result<Self>
Starts the printer-listing flow (cpdbStartListingPrinters), creating
a fresh frontend bound to the supplied callback.
Sourcepub fn stop_listing_printers(&self)
pub fn stop_listing_printers(&self)
Stops the printer-listing flow.
Sourcepub fn hide_remote_printers(&self)
pub fn hide_remote_printers(&self)
Hides remote printers from subsequent listings.
Sourcepub fn unhide_remote_printers(&self)
pub fn unhide_remote_printers(&self)
Unhides remote printers.
Sourcepub fn hide_temporary_printers(&self)
pub fn hide_temporary_printers(&self)
Hides temporary printers from subsequent listings.
Sourcepub fn unhide_temporary_printers(&self)
pub fn unhide_temporary_printers(&self)
Unhides temporary printers.
Sourcepub fn find_printer<'f>(
&'f self,
printer_id: &str,
backend_name: &str,
) -> Result<Printer<'f>>
pub fn find_printer<'f>( &'f self, printer_id: &str, backend_name: &str, ) -> Result<Printer<'f>>
Finds a printer by (id, backend).
The returned Printer borrows from self.
Sourcepub fn get_default_printer(&self) -> Result<Printer<'_>>
pub fn get_default_printer(&self) -> Result<Printer<'_>>
Returns the user-default printer, if one is set.
Sourcepub fn get_default_printer_for_backend(
&self,
backend_name: &str,
) -> Result<Printer<'_>>
pub fn get_default_printer_for_backend( &self, backend_name: &str, ) -> Result<Printer<'_>>
Returns the default printer for a specific backend, if one is set.
Sourcepub fn refresh_printers(&self)
pub fn refresh_printers(&self)
Asks every backend to refresh its printer list.
Sourcepub fn add_printer(&self, printer: Printer<'static>) -> Result<bool>
pub fn add_printer(&self, printer: Printer<'static>) -> Result<bool>
Adds an owned printer to the frontend’s table.
Takes ownership of the printer — cpdb-libs becomes responsible for
freeing it. The argument must be an owned Printer (e.g. from
Printer::load_from_file); attempting to insert a borrowed
printer is rejected to prevent the same pointer ending up in two
hash tables.
Returns Ok(true) when the printer was inserted; Ok(false) when
it was rejected by the backend.
Sourcepub fn remove_printer(
&self,
printer_id: &str,
backend_name: &str,
) -> Result<Option<Printer<'static>>>
pub fn remove_printer( &self, printer_id: &str, backend_name: &str, ) -> Result<Option<Printer<'static>>>
Removes a printer from the frontend’s table by (id, backend).
Returns the owned removed printer when present, so the caller can inspect it before dropping (cpdb-libs hands ownership back).
Sourcepub fn refresh_printer_list(&self, backend_name: &str) -> Result<bool>
pub fn refresh_printer_list(&self, backend_name: &str) -> Result<bool>
Asks a specific backend to refresh its printer list. Returns true on success.
Sourcepub fn get_printers(&self) -> Result<Vec<Printer<'_>>>
pub fn get_printers(&self) -> Result<Vec<Printer<'_>>>
Returns every printer currently known by walking the internal hash table.
The returned printers borrow from self.
Sourcepub fn get_printer<'f>(&'f self, name: &str) -> Result<Printer<'f>>
pub fn get_printer<'f>(&'f self, name: &str) -> Result<Printer<'f>>
Looks up the first printer whose name field equals the argument.
When multiple printers share a name across backends, the first one
encountered during hash-table iteration wins. Prefer
Frontend::find_printer when you can supply a backend name.