1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{
NumberUpLayout, PageRange, PageSet, PageSetup, PrintPages, PrintSettings, PrintStatus, Printer,
};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// A [`PrintJob`][crate::PrintJob] object represents a job that is sent to a printer.
///
/// You only need to deal directly with print jobs if you use the
/// non-portable [`PrintUnixDialog`][crate::PrintUnixDialog] API.
///
/// Use [`surface()`][Self::surface()] to obtain the cairo surface
/// onto which the pages must be drawn. Use [`send()`][Self::send()]
/// to send the finished job to the printer. If you don’t use cairo
/// [`PrintJob`][crate::PrintJob] also supports printing of manually generated PostScript,
/// via [`set_source_file()`][Self::set_source_file()].
///
/// ## Properties
///
///
/// #### `page-setup`
/// Page setup.
///
/// Readable | Writeable | Construct Only
///
///
/// #### `printer`
/// The printer to send the job to.
///
/// Readable | Writeable | Construct Only
///
///
/// #### `settings`
/// Printer settings.
///
/// Readable | Writeable | Construct Only
///
///
/// #### `title`
/// The title of the print job.
///
/// Readable | Writeable | Construct Only
///
///
/// #### `track-print-status`
/// [`true`] if the print job will continue to emit status-changed
/// signals after the print data has been setn to the printer.
///
/// Readable | Writeable
///
/// ## Signals
///
///
/// #### `status-changed`
/// Emitted when the status of a job changes.
///
/// The signal handler can use [`PrintJob::status()`][crate::PrintJob::status()]
/// to obtain the new status.
///
///
///
/// # Implements
///
/// [`trait@glib::ObjectExt`]
#[doc(alias = "GtkPrintJob")]
pub struct PrintJob(Object<ffi::GtkPrintJob>);
match fn {
type_ => || ffi::gtk_print_job_get_type(),
}
}
impl PrintJob {
/// Creates a new [`PrintJob`][crate::PrintJob].
/// ## `title`
/// the job title
/// ## `printer`
/// a [`Printer`][crate::Printer]
/// ## `settings`
/// a [`PrintSettings`][crate::PrintSettings]
/// ## `page_setup`
/// a [`PageSetup`][crate::PageSetup]
///
/// # Returns
///
/// a new [`PrintJob`][crate::PrintJob]
#[doc(alias = "gtk_print_job_new")]
pub fn new(
title: &str,
printer: &Printer,
settings: &PrintSettings,
page_setup: &PageSetup,
) -> PrintJob {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::gtk_print_job_new(
title.to_glib_none().0,
printer.to_glib_none().0,
settings.to_glib_none().0,
page_setup.to_glib_none().0,
))
}
}
/// Gets whether this job is printed collated.
///
/// # Returns
///
/// whether the job is printed collated
#[doc(alias = "gtk_print_job_get_collate")]
#[doc(alias = "get_collate")]
pub fn is_collate(&self) -> bool {
unsafe { from_glib(ffi::gtk_print_job_get_collate(self.to_glib_none().0)) }
}
/// Gets the n-up setting for this job.
///
/// # Returns
///
/// the n-up setting
#[doc(alias = "gtk_print_job_get_n_up")]
#[doc(alias = "get_n_up")]
pub fn n_up(&self) -> u32 {
unsafe { ffi::gtk_print_job_get_n_up(self.to_glib_none().0) }
}
/// Gets the n-up layout setting for this job.
///
/// # Returns
///
/// the n-up layout
#[doc(alias = "gtk_print_job_get_n_up_layout")]
#[doc(alias = "get_n_up_layout")]
pub fn n_up_layout(&self) -> NumberUpLayout {
unsafe { from_glib(ffi::gtk_print_job_get_n_up_layout(self.to_glib_none().0)) }
}
/// Gets the number of copies of this job.
///
/// # Returns
///
/// the number of copies
#[doc(alias = "gtk_print_job_get_num_copies")]
#[doc(alias = "get_num_copies")]
pub fn num_copies(&self) -> i32 {
unsafe { ffi::gtk_print_job_get_num_copies(self.to_glib_none().0) }
}
/// Gets the page ranges for this job.
///
/// # Returns
///
/// a pointer to an
/// array of [`PageRange`][crate::PageRange] structs
#[doc(alias = "gtk_print_job_get_page_ranges")]
#[doc(alias = "get_page_ranges")]
pub fn page_ranges(&self) -> Vec<PageRange> {
unsafe {
let mut n_ranges = std::mem::MaybeUninit::uninit();
let ret = FromGlibContainer::from_glib_none_num(
ffi::gtk_print_job_get_page_ranges(self.to_glib_none().0, n_ranges.as_mut_ptr()),
n_ranges.assume_init() as _,
);
ret
}
}
/// Gets the [`PageSet`][crate::PageSet] setting for this job.
///
/// # Returns
///
/// the [`PageSet`][crate::PageSet] setting
#[doc(alias = "gtk_print_job_get_page_set")]
#[doc(alias = "get_page_set")]
pub fn page_set(&self) -> PageSet {
unsafe { from_glib(ffi::gtk_print_job_get_page_set(self.to_glib_none().0)) }
}
/// Gets the [`PrintPages`][crate::PrintPages] setting for this job.
///
/// # Returns
///
/// the [`PrintPages`][crate::PrintPages] setting
#[doc(alias = "gtk_print_job_get_pages")]
#[doc(alias = "get_pages")]
pub fn pages(&self) -> PrintPages {
unsafe { from_glib(ffi::gtk_print_job_get_pages(self.to_glib_none().0)) }
}
/// Gets the [`Printer`][crate::Printer] of the print job.
///
/// # Returns
///
/// the printer of @self
#[doc(alias = "gtk_print_job_get_printer")]
#[doc(alias = "get_printer")]
pub fn printer(&self) -> Printer {
unsafe { from_glib_none(ffi::gtk_print_job_get_printer(self.to_glib_none().0)) }
}
/// Gets whether this job is printed reversed.
///
/// # Returns
///
/// whether the job is printed reversed.
#[doc(alias = "gtk_print_job_get_reverse")]
#[doc(alias = "get_reverse")]
pub fn is_reverse(&self) -> bool {
unsafe { from_glib(ffi::gtk_print_job_get_reverse(self.to_glib_none().0)) }
}
/// Gets whether the job is printed rotated.
///
/// # Returns
///
/// whether the job is printed rotated
#[doc(alias = "gtk_print_job_get_rotate")]
#[doc(alias = "get_rotate")]
pub fn is_rotate(&self) -> bool {
unsafe { from_glib(ffi::gtk_print_job_get_rotate(self.to_glib_none().0)) }
}
/// Gets the scale for this job.
///
/// # Returns
///
/// the scale
#[doc(alias = "gtk_print_job_get_scale")]
#[doc(alias = "get_scale")]
pub fn scale(&self) -> f64 {
unsafe { ffi::gtk_print_job_get_scale(self.to_glib_none().0) }
}
/// Gets the [`PrintSettings`][crate::PrintSettings] of the print job.
///
/// # Returns
///
/// the settings of @self
#[doc(alias = "gtk_print_job_get_settings")]
#[doc(alias = "get_settings")]
pub fn settings(&self) -> PrintSettings {
unsafe { from_glib_none(ffi::gtk_print_job_get_settings(self.to_glib_none().0)) }
}
/// Gets the status of the print job.
///
/// # Returns
///
/// the status of @self
#[doc(alias = "gtk_print_job_get_status")]
#[doc(alias = "get_status")]
pub fn status(&self) -> PrintStatus {
unsafe { from_glib(ffi::gtk_print_job_get_status(self.to_glib_none().0)) }
}
/// Gets a cairo surface onto which the pages of
/// the print job should be rendered.
///
/// # Returns
///
/// the cairo surface of @self
#[doc(alias = "gtk_print_job_get_surface")]
#[doc(alias = "get_surface")]
pub fn surface(&self) -> Result<cairo::Surface, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::gtk_print_job_get_surface(self.to_glib_none().0, &mut error);
if error.is_null() {
Ok(from_glib_none(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Gets the job title.
///
/// # Returns
///
/// the title of @self
#[doc(alias = "gtk_print_job_get_title")]
#[doc(alias = "get_title")]
pub fn title(&self) -> glib::GString {
unsafe { from_glib_none(ffi::gtk_print_job_get_title(self.to_glib_none().0)) }
}
/// Returns whether jobs will be tracked after printing.
///
/// For details, see [`set_track_print_status()`][Self::set_track_print_status()].
///
/// # Returns
///
/// [`true`] if print job status will be reported after printing
#[doc(alias = "gtk_print_job_get_track_print_status")]
#[doc(alias = "get_track_print_status")]
pub fn tracks_print_status(&self) -> bool {
unsafe {
from_glib(ffi::gtk_print_job_get_track_print_status(
self.to_glib_none().0,
))
}
}
/// Sets whether this job is printed collated.
/// ## `collate`
/// whether the job is printed collated
#[doc(alias = "gtk_print_job_set_collate")]
pub fn set_collate(&self, collate: bool) {
unsafe {
ffi::gtk_print_job_set_collate(self.to_glib_none().0, collate.into_glib());
}
}
/// Sets the n-up setting for this job.
/// ## `n_up`
/// the n-up value
#[doc(alias = "gtk_print_job_set_n_up")]
pub fn set_n_up(&self, n_up: u32) {
unsafe {
ffi::gtk_print_job_set_n_up(self.to_glib_none().0, n_up);
}
}
/// Sets the n-up layout setting for this job.
/// ## `layout`
/// the n-up layout setting
#[doc(alias = "gtk_print_job_set_n_up_layout")]
pub fn set_n_up_layout(&self, layout: NumberUpLayout) {
unsafe {
ffi::gtk_print_job_set_n_up_layout(self.to_glib_none().0, layout.into_glib());
}
}
/// Sets the number of copies for this job.
/// ## `num_copies`
/// the number of copies
#[doc(alias = "gtk_print_job_set_num_copies")]
pub fn set_num_copies(&self, num_copies: i32) {
unsafe {
ffi::gtk_print_job_set_num_copies(self.to_glib_none().0, num_copies);
}
}
/// Sets the page ranges for this job.
/// ## `ranges`
/// pointer to an array of
/// [`PageRange`][crate::PageRange] structs
#[doc(alias = "gtk_print_job_set_page_ranges")]
pub fn set_page_ranges(&self, ranges: &[PageRange]) {
let n_ranges = ranges.len() as _;
unsafe {
ffi::gtk_print_job_set_page_ranges(
self.to_glib_none().0,
ranges.to_glib_full(),
n_ranges,
);
}
}
/// Sets the [`PageSet`][crate::PageSet] setting for this job.
/// ## `page_set`
/// a [`PageSet`][crate::PageSet] setting
#[doc(alias = "gtk_print_job_set_page_set")]
pub fn set_page_set(&self, page_set: PageSet) {
unsafe {
ffi::gtk_print_job_set_page_set(self.to_glib_none().0, page_set.into_glib());
}
}
/// Sets the [`PrintPages`][crate::PrintPages] setting for this job.
/// ## `pages`
/// the [`PrintPages`][crate::PrintPages] setting
#[doc(alias = "gtk_print_job_set_pages")]
pub fn set_pages(&self, pages: PrintPages) {
unsafe {
ffi::gtk_print_job_set_pages(self.to_glib_none().0, pages.into_glib());
}
}
/// Sets whether this job is printed reversed.
/// ## `reverse`
/// whether the job is printed reversed
#[doc(alias = "gtk_print_job_set_reverse")]
pub fn set_reverse(&self, reverse: bool) {
unsafe {
ffi::gtk_print_job_set_reverse(self.to_glib_none().0, reverse.into_glib());
}
}
/// Sets whether this job is printed rotated.
/// ## `rotate`
/// whether to print rotated
#[doc(alias = "gtk_print_job_set_rotate")]
pub fn set_rotate(&self, rotate: bool) {
unsafe {
ffi::gtk_print_job_set_rotate(self.to_glib_none().0, rotate.into_glib());
}
}
/// Sets the scale for this job.
///
/// 1.0 means unscaled.
/// ## `scale`
/// the scale
#[doc(alias = "gtk_print_job_set_scale")]
pub fn set_scale(&self, scale: f64) {
unsafe {
ffi::gtk_print_job_set_scale(self.to_glib_none().0, scale);
}
}
/// Make the [`PrintJob`][crate::PrintJob] send an existing document to the
/// printing system.
///
/// The file can be in any format understood by the platforms
/// printing system (typically PostScript, but on many platforms
/// PDF may work too). See [`Printer::accepts_pdf()`][crate::Printer::accepts_pdf()] and
/// [`Printer::accepts_ps()`][crate::Printer::accepts_ps()].
///
/// This is similar to [`set_source_file()`][Self::set_source_file()],
/// but takes expects an open file descriptor for the file,
/// instead of a filename.
/// ## `fd`
/// a file descriptor
///
/// # Returns
///
/// [`false`] if an error occurred
#[doc(alias = "gtk_print_job_set_source_fd")]
pub fn set_source_fd(&self, fd: i32) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::gtk_print_job_set_source_fd(self.to_glib_none().0, fd, &mut error);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Make the [`PrintJob`][crate::PrintJob] send an existing document to the
/// printing system.
///
/// The file can be in any format understood by the platforms
/// printing system (typically PostScript, but on many platforms
/// PDF may work too). See [`Printer::accepts_pdf()`][crate::Printer::accepts_pdf()] and
/// [`Printer::accepts_ps()`][crate::Printer::accepts_ps()].
/// ## `filename`
/// the file to be printed
///
/// # Returns
///
/// [`false`] if an error occurred
#[doc(alias = "gtk_print_job_set_source_file")]
pub fn set_source_file(
&self,
filename: impl AsRef<std::path::Path>,
) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::gtk_print_job_set_source_file(
self.to_glib_none().0,
filename.as_ref().to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// If track_status is [`true`], the print job will try to continue report
/// on the status of the print job in the printer queues and printer.
///
/// This can allow your application to show things like “out of paper”
/// issues, and when the print job actually reaches the printer.
///
/// This function is often implemented using some form of polling,
/// so it should not be enabled unless needed.
/// ## `track_status`
/// [`true`] to track status after printing
#[doc(alias = "gtk_print_job_set_track_print_status")]
pub fn set_track_print_status(&self, track_status: bool) {
unsafe {
ffi::gtk_print_job_set_track_print_status(
self.to_glib_none().0,
track_status.into_glib(),
);
}
}
/// Page setup.
#[doc(alias = "page-setup")]
pub fn page_setup(&self) -> Option<PageSetup> {
ObjectExt::property(self, "page-setup")
}
/// Emitted when the status of a job changes.
///
/// The signal handler can use [`status()`][Self::status()]
/// to obtain the new status.
#[doc(alias = "status-changed")]
pub fn connect_status_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn status_changed_trampoline<F: Fn(&PrintJob) + 'static>(
this: *mut ffi::GtkPrintJob,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"status-changed\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
status_changed_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "track-print-status")]
pub fn connect_track_print_status_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_track_print_status_trampoline<F: Fn(&PrintJob) + 'static>(
this: *mut ffi::GtkPrintJob,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::track-print-status\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_track_print_status_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}