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>
impl<'frontend> Printer<'frontend>
Sourcepub fn description(&self) -> Result<String>
pub fn description(&self) -> Result<String>
A free-form description (info in the C struct).
Sourcepub fn make_and_model(&self) -> Result<String>
pub fn make_and_model(&self) -> Result<String>
The printer’s make and model.
Sourcepub fn backend_name(&self) -> Result<String>
pub fn backend_name(&self) -> Result<String>
The backend name this printer belongs to (e.g. "CUPS").
Sourcepub fn cached_state(&self) -> Result<String>
pub fn cached_state(&self) -> Result<String>
The cached state string (idle, processing, …).
For an authoritative answer use Printer::get_updated_state.
Sourcepub fn get_updated_state(&self) -> Result<String>
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.
Sourcepub fn is_accepting_jobs(&self) -> Result<bool>
pub fn is_accepting_jobs(&self) -> Result<bool>
true when the printer is accepting jobs.
Sourcepub fn set_user_default(&self) -> Result<bool>
pub fn set_user_default(&self) -> Result<bool>
Marks this printer as the user’s default. Returns true on success.
Sourcepub fn set_system_default(&self) -> Result<bool>
pub fn set_system_default(&self) -> Result<bool>
Marks this printer as the system-wide default. Returns true on success.
Sourcepub fn print_file(&self, file_path: &str) -> Result<String>
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.
Sourcepub fn print_fd(&self, title: &str) -> Result<PrintFdHandle>
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.
Sourcepub fn print_socket(&self, title: &str) -> Result<PrintSocketHandle>
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.
Sourcepub fn submit_job(
&self,
file_path: &str,
options: &[(&str, &str)],
title: &str,
) -> Result<String>
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.
Sourcepub fn get_option(&self, option_name: &str) -> Result<Option<String>>
pub fn get_option(&self, option_name: &str) -> Result<Option<String>>
Returns the default value for a named option, if the option exists.
Sourcepub fn get_default(&self, option_name: &str) -> Result<String>
pub fn get_default(&self, option_name: &str) -> Result<String>
Returns the default value for a named option, freeing the GLib string.
Sourcepub fn get_current(&self, option_name: &str) -> Result<String>
pub fn get_current(&self, option_name: &str) -> Result<String>
Returns the current (setting-or-default) value for a named option.
Sourcepub fn acquire_details(&self)
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.
Sourcepub fn acquire_details_with<F>(&self, completion: F)
pub fn acquire_details_with<F>(&self, completion: F)
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.
Sourcepub fn get_options_collection(&self) -> Result<OptionsCollection>
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.
Sourcepub fn get_setting(&self, name: &str) -> Result<Option<String>>
pub fn get_setting(&self, name: &str) -> Result<Option<String>>
Reads a per-printer setting, or returns None when unset.
Sourcepub fn add_setting(&self, name: &str, value: &str) -> Result<()>
pub fn add_setting(&self, name: &str, value: &str) -> Result<()>
Inserts or overwrites a per-printer setting.
Sourcepub fn clear_setting(&self, name: &str) -> Result<bool>
pub fn clear_setting(&self, name: &str) -> Result<bool>
Removes a per-printer setting. Returns Ok(true) when it existed.
Sourcepub fn get_media(&self, media_name: &str) -> Result<Option<String>>
pub fn get_media(&self, media_name: &str) -> Result<Option<String>>
Returns the descriptive name of a media type, if known.
Sourcepub fn get_media_size(&self, media_name: &str) -> Result<MediaSize>
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.
Sourcepub fn get_media_margins(&self, media_name: &str) -> Result<Margins>
pub fn get_media_margins(&self, media_name: &str) -> Result<Margins>
Returns every margin entry the backend reports for a named media type.
Sourcepub fn acquire_translations(&self, locale: &str) -> Result<()>
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.
Sourcepub fn acquire_translations_with<F>(
&self,
locale: &str,
completion: F,
) -> Result<()>
pub fn acquire_translations_with<F>( &self, locale: &str, completion: F, ) -> Result<()>
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.
Sourcepub fn get_option_translation(
&self,
option: &str,
locale: &str,
) -> Result<Option<String>>
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.
Sourcepub fn get_choice_translation(
&self,
option: &str,
choice: &str,
locale: &str,
) -> Result<Option<String>>
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.
Sourcepub fn get_option_translation_from_table(
&self,
option: &str,
locale: &str,
) -> Result<Option<String>>
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.
Sourcepub fn get_choice_translation_from_table(
&self,
option: &str,
choice: &str,
locale: &str,
) -> Result<Option<String>>
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.
Sourcepub fn get_group_translation(
&self,
group: &str,
locale: &str,
) -> Result<Option<String>>
pub fn get_group_translation( &self, group: &str, locale: &str, ) -> Result<Option<String>>
Returns the human-readable label for an option group.
Sourcepub fn get_all_translations(&self, locale: &str) -> Result<()>
pub fn get_all_translations(&self, locale: &str) -> Result<()>
Synchronously populates every translation for the given locale.
Sourcepub fn translations(&self) -> TranslationMap
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.
Sourcepub fn debug_dump(&self)
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.
Sourcepub fn dump_basic_options(&self)
pub fn dump_basic_options(&self)
Dumps the printer’s basic option set to stdout via
cpdbPrintBasicOptions. Diagnostics-only.
Sourcepub fn pickle_to_file(&self, path: &str, frontend: &Frontend) -> Result<()>
pub fn pickle_to_file(&self, path: &str, frontend: &Frontend) -> Result<()>
Serialises this printer to a file (cpdbPicklePrinterToFile).
Sourcepub fn load_from_file(path: &str) -> Result<Printer<'static>>
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.