Skip to main content

Frontend

Struct Frontend 

Source
pub struct Frontend { /* private fields */ }
Expand description

Safe wrapper around cpdb_frontend_obj_t.

Implementations§

Source§

impl Frontend

Source

pub fn new() -> Result<Self>

Creates a new frontend with the default printer-update callback.

Source

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.

Source

pub fn new_with_observer<F>(observer: F) -> Result<Self>
where F: FnMut(&Printer<'_>, PrinterUpdate) + Send + 'static,

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.

Source

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.

Source

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.

Source

pub fn connect_to_dbus(&self) -> Result<()>

Connects to the session D-Bus and activates the print backends.

Source

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.

Source

pub fn disconnect_from_dbus(&self) -> Result<()>

Disconnects from D-Bus.

Source

pub fn activate_backends(&self)

Re-activates the backends (rediscovers printers without disconnecting).

Source

pub fn start_backend_list_refreshing(&self)

Starts the background thread that periodically refreshes the backend list.

Source

pub fn stop_backend_list_refreshing(&self)

Stops the backend-list refreshing thread; blocks until it joins.

Source

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.

Source

pub fn stop_listing_printers(&self)

Stops the printer-listing flow.

Source

pub fn hide_remote_printers(&self)

Hides remote printers from subsequent listings.

Source

pub fn unhide_remote_printers(&self)

Unhides remote printers.

Source

pub fn hide_temporary_printers(&self)

Hides temporary printers from subsequent listings.

Source

pub fn unhide_temporary_printers(&self)

Unhides temporary printers.

Source

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.

Source

pub fn get_default_printer(&self) -> Result<Printer<'_>>

Returns the user-default printer, if one is set.

Source

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.

Source

pub fn refresh_printers(&self)

Asks every backend to refresh its printer list.

Source

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.

Source

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).

Source

pub fn refresh_printer_list(&self, backend_name: &str) -> Result<bool>

Asks a specific backend to refresh its printer list. Returns true on success.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Drop for Frontend

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Frontend

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.