Skip to main content

Printer

Struct Printer 

Source
pub struct Printer<'frontend> { /* private fields */ }
Expand description

A safe handle to a cpdb printer object.

See the module docs for the ownership and lifetime model.

Implementations§

Source§

impl<'frontend> Printer<'frontend>

Source

pub fn id(&self) -> Result<String>

The backend-assigned printer ID (stable across sessions).

Source

pub fn name(&self) -> Result<String>

The human-readable printer name.

Source

pub fn location(&self) -> Result<String>

The physical location string supplied by the backend.

Source

pub fn description(&self) -> Result<String>

A free-form description (info in the C struct).

Source

pub fn make_and_model(&self) -> Result<String>

The printer’s make and model.

Source

pub fn backend_name(&self) -> Result<String>

The backend name this printer belongs to (e.g. "CUPS").

Source

pub fn cached_state(&self) -> Result<String>

The cached state string (idle, processing, …).

For an authoritative answer use Printer::get_updated_state.

Source

pub fn get_updated_state(&self) -> Result<String>

Queries the current state from the backend.

The returned string is owned by Rust; the cpdb-libs allocation is freed inside this call.

Source

pub fn is_accepting_jobs(&self) -> Result<bool>

true when the printer is accepting jobs.

Source

pub fn set_user_default(&self) -> Result<bool>

Marks this printer as the user’s default. Returns true on success.

Source

pub fn set_system_default(&self) -> Result<bool>

Marks this printer as the system-wide default. Returns true on success.

Source

pub fn print_file(&self, file_path: &str) -> Result<String>

Submits a file as a print job with no extra options.

Returns the backend-assigned job ID string.

Source

pub fn print_fd(&self, title: &str) -> Result<PrintFdHandle>

Streams a print job over a file descriptor.

cpdb-libs hands back a writable file descriptor; the caller writes the job’s data to it and drops the returned handle to close it. The backend job ID and an optional auxiliary socket path are also returned.

Source

pub fn print_socket(&self, title: &str) -> Result<PrintSocketHandle>

Streams a print job over a Unix-domain socket.

cpdb-libs returns a socket path the caller connects to and writes the job data through, plus the backend-assigned job ID.

Source

pub fn submit_job( &self, file_path: &str, options: &[(&str, &str)], title: &str, ) -> Result<String>

Submits a job with a per-call set of options and an explicit title.

Options are applied to the printer’s settings table via cpdbAddSettingToPrinter before submission, so they take effect for this job and persist for subsequent jobs on the same printer until cleared via Printer::clear_setting.

Returns the backend-assigned job ID string.

Source

pub fn get_option(&self, option_name: &str) -> Result<Option<String>>

Returns the default value for a named option, if the option exists.

Source

pub fn get_default(&self, option_name: &str) -> Result<String>

Returns the default value for a named option, freeing the GLib string.

Source

pub fn get_current(&self, option_name: &str) -> Result<String>

Returns the current (setting-or-default) value for a named option.

Source

pub fn acquire_details(&self)

Asynchronously asks the backend to populate the printer’s full option table. Returns immediately; no completion notification.

Use Printer::acquire_details_with if you need to be told when the operation finishes.

Source

pub fn acquire_details_with<F>(&self, completion: F)
where F: FnOnce(&Printer<'_>, bool) + Send + 'static,

Asynchronously populates the option table, firing completion when the backend responds.

completion is invoked from cpdb-libs’ D-Bus listener thread with success = true when the backend reported success. Panics inside the closure are caught and absorbed.

Source

pub fn get_options_collection(&self) -> Result<OptionsCollection>

Returns an owned snapshot of every option on this printer.

Call Printer::acquire_details before this so the option table is populated by the backend.

Source

pub fn get_setting(&self, name: &str) -> Result<Option<String>>

Reads a per-printer setting, or returns None when unset.

Source

pub fn add_setting(&self, name: &str, value: &str) -> Result<()>

Inserts or overwrites a per-printer setting.

Source

pub fn clear_setting(&self, name: &str) -> Result<bool>

Removes a per-printer setting. Returns Ok(true) when it existed.

Source

pub fn get_media(&self, media_name: &str) -> Result<Option<String>>

Returns the descriptive name of a media type, if known.

Source

pub fn get_media_size(&self, media_name: &str) -> Result<MediaSize>

Returns the media size for a named media type.

Both dimensions are in hundredths of a millimetre.

Source

pub fn get_media_margins(&self, media_name: &str) -> Result<Margins>

Returns every margin entry the backend reports for a named media type.

Source

pub fn acquire_translations(&self, locale: &str) -> Result<()>

Asynchronously fetches translations for the given locale.

Use Printer::acquire_translations_with if you need to be told when the operation finishes.

Source

pub fn acquire_translations_with<F>( &self, locale: &str, completion: F, ) -> Result<()>
where F: FnOnce(&Printer<'_>, bool) + Send + 'static,

Asynchronously fetches translations, firing completion on success/failure.

completion is invoked from cpdb-libs’ D-Bus listener thread. Panics inside the closure are caught and absorbed.

Source

pub fn get_option_translation( &self, option: &str, locale: &str, ) -> Result<Option<String>>

Returns the human-readable label for an option in the given locale.

Source

pub fn get_choice_translation( &self, option: &str, choice: &str, locale: &str, ) -> Result<Option<String>>

Returns the human-readable label for a specific option choice.

Source

pub fn get_option_translation_from_table( &self, option: &str, locale: &str, ) -> Result<Option<String>>

Like get_option_translation, but only consults the in-memory translation table — never falls through to the backend over D-Bus.

Returns None if the option label has not been loaded yet. Call Printer::get_all_translations (or Printer::acquire_translations_with) first to populate the table.

Source

pub fn get_choice_translation_from_table( &self, option: &str, choice: &str, locale: &str, ) -> Result<Option<String>>

Like get_choice_translation, but only consults the in-memory translation table — never falls through to the backend over D-Bus.

Source

pub fn get_group_translation( &self, group: &str, locale: &str, ) -> Result<Option<String>>

Returns the human-readable label for an option group.

Source

pub fn get_all_translations(&self, locale: &str) -> Result<()>

Synchronously populates every translation for the given locale.

Source

pub fn translations(&self) -> TranslationMap

Returns an owned snapshot of the printer’s cached translation table.

Call Printer::get_all_translations (or Printer::acquire_translations_with) first to populate the table. Returns an empty map when no translations have been loaded.

Source

pub fn debug_dump(&self)

Dumps a human-readable description of this printer to stderr via cpdbDebugPrinter. Useful for diagnostics; production code should inspect the typed accessors instead.

Source

pub fn dump_basic_options(&self)

Dumps the printer’s basic option set to stdout via cpdbPrintBasicOptions. Diagnostics-only.

Source

pub fn pickle_to_file(&self, path: &str, frontend: &Frontend) -> Result<()>

Serialises this printer to a file (cpdbPicklePrinterToFile).

Source

pub fn load_from_file(path: &str) -> Result<Printer<'static>>

Loads a printer that was previously serialised via pickle_to_file.

The returned printer is owned — it is freed when dropped.

Trait Implementations§

Source§

impl<'frontend> Debug for Printer<'frontend>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Printer<'_>

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

Auto Trait Implementations§

§

impl<'frontend> !Send for Printer<'frontend>

§

impl<'frontend> !Sync for Printer<'frontend>

§

impl<'frontend> Freeze for Printer<'frontend>

§

impl<'frontend> RefUnwindSafe for Printer<'frontend>

§

impl<'frontend> Unpin for Printer<'frontend>

§

impl<'frontend> UnsafeUnpin for Printer<'frontend>

§

impl<'frontend> UnwindSafe for Printer<'frontend>

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.