gtkprintjob.c 23.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* GtkPrintJob
 * Copyright (C) 2006 John (J5) Palmieri  <johnp@redhat.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17
 */

18 19 20 21 22 23 24 25 26 27 28
/**
 * SECTION:gtkprintjob
 * @Title: GtkPrintJob
 * @Short_description: Represents a print job
 *
 * A #GtkPrintJob 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 #GtkPrintUnixDialog API.
 *
 * Use gtk_print_job_get_surface() to obtain the cairo surface
 * onto which the pages must be drawn. Use gtk_print_job_send()
29
 * to send the finished job to the printer. If you don’t use cairo
30 31 32
 * #GtkPrintJob also supports printing of manually generated postscript,
 * via gtk_print_job_set_source_file().
 */
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>

#include <glib/gstdio.h>
#include "gtkintl.h"
#include "gtkprivate.h"

#include "gtkprintjob.h"
#include "gtkprinter.h"
51
#include "gtkprinter-private.h"
52 53 54 55 56 57 58 59 60 61
#include "gtkprintbackend.h"

#ifndef O_BINARY
#define O_BINARY 0
#endif

struct _GtkPrintJobPrivate
{
  gchar *title;

62
  GIOChannel *spool_io;
63 64 65
  cairo_surface_t *surface;

  GtkPrintStatus status;
66
  GtkPrintBackend *backend;
67 68 69 70
  GtkPrinter *printer;
  GtkPrintSettings *settings;
  GtkPageSetup *page_setup;

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
  GtkPrintPages print_pages;
  GtkPageRange *page_ranges;
  gint num_page_ranges;
  GtkPageSet page_set;
  gint num_copies;
  gdouble scale;
  guint number_up;
  GtkNumberUpLayout number_up_layout;

  guint printer_set           : 1;
  guint page_setup_set        : 1;
  guint settings_set          : 1;
  guint track_print_status    : 1;
  guint rotate_to_orientation : 1;
  guint collate               : 1;
  guint reverse               : 1;
87 88 89 90 91 92 93 94 95 96 97
};

static void     gtk_print_job_finalize     (GObject               *object);
static void     gtk_print_job_set_property (GObject               *object,
					    guint                  prop_id,
					    const GValue          *value,
					    GParamSpec            *pspec);
static void     gtk_print_job_get_property (GObject               *object,
					    guint                  prop_id,
					    GValue                *value,
					    GParamSpec            *pspec);
98
static void     gtk_print_job_constructed  (GObject               *object);
99 100 101 102 103 104 105 106

enum {
  STATUS_CHANGED,
  LAST_SIGNAL
};

enum {
  PROP_0,
107 108 109 110 111
  PROP_TITLE,
  PROP_PRINTER,
  PROP_PAGE_SETUP,
  PROP_SETTINGS,
  PROP_TRACK_PRINT_STATUS
112 113 114 115
};

static guint signals[LAST_SIGNAL] = { 0 };

116
G_DEFINE_TYPE_WITH_PRIVATE (GtkPrintJob, gtk_print_job, G_TYPE_OBJECT)
117 118 119 120 121 122 123 124

static void
gtk_print_job_class_init (GtkPrintJobClass *class)
{
  GObjectClass *object_class;
  object_class = (GObjectClass *) class;

  object_class->finalize = gtk_print_job_finalize;
125
  object_class->constructed = gtk_print_job_constructed;
126 127 128
  object_class->set_property = gtk_print_job_set_property;
  object_class->get_property = gtk_print_job_get_property;

129 130
  g_object_class_install_property (object_class,
                                   PROP_TITLE,
131 132 133 134 135 136 137
                                   g_param_spec_string ("title",
						        P_("Title"),
						        P_("Title of the print job"),
						        NULL,
							GTK_PARAM_READWRITE |
						        G_PARAM_CONSTRUCT_ONLY));

138 139
  g_object_class_install_property (object_class,
                                   PROP_PRINTER,
140 141 142 143 144 145 146
                                   g_param_spec_object ("printer",
						        P_("Printer"),
						        P_("Printer to print the job to"),
						        GTK_TYPE_PRINTER,
							GTK_PARAM_READWRITE |
						        G_PARAM_CONSTRUCT_ONLY));

147 148
  g_object_class_install_property (object_class,
                                   PROP_SETTINGS,
149 150 151 152 153 154 155
                                   g_param_spec_object ("settings",
						        P_("Settings"),
						        P_("Printer settings"),
						        GTK_TYPE_PRINT_SETTINGS,
							GTK_PARAM_READWRITE |
						        G_PARAM_CONSTRUCT_ONLY));

156 157
  g_object_class_install_property (object_class,
                                   PROP_PAGE_SETUP,
158 159 160 161 162 163 164
                                   g_param_spec_object ("page-setup",
						        P_("Page Setup"),
						        P_("Page Setup"),
						        GTK_TYPE_PAGE_SETUP,
							GTK_PARAM_READWRITE |
						        G_PARAM_CONSTRUCT_ONLY));

165 166 167 168 169 170 171 172 173 174 175
  g_object_class_install_property (object_class,
				   PROP_TRACK_PRINT_STATUS,
				   g_param_spec_boolean ("track-print-status",
							 P_("Track Print Status"),
							 P_("TRUE if the print job will continue to emit "
							    "status-changed signals after the print data "
							    "has been sent to the printer or print server."),
							 FALSE,
							 GTK_PARAM_READWRITE));
  

176 177 178 179 180 181 182 183 184
  /**
   * GtkPrintJob::status-changed:
   * @job: the #GtkPrintJob object on which the signal was emitted
   *
   * Gets emitted when the status of a job changes. The signal handler
   * can use gtk_print_job_get_status() to obtain the new status.
   *
   * Since: 2.10
   */
185
  signals[STATUS_CHANGED] =
Matthias Clasen's avatar
Matthias Clasen committed
186 187 188 189 190 191 192
    g_signal_new (I_("status-changed"),
		  G_TYPE_FROM_CLASS (class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrintJobClass, status_changed),
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
193 194 195
}

static void
196
gtk_print_job_init (GtkPrintJob *job)
197
{
198
  GtkPrintJobPrivate *priv;
199

200
  priv = job->priv = gtk_print_job_get_instance_private (job);
201

202
  priv->spool_io = NULL;
203 204 205 206 207 208 209 210 211 212

  priv->title = g_strdup ("");
  priv->surface = NULL;
  priv->backend = NULL;
  priv->printer = NULL;

  priv->printer_set = FALSE;
  priv->settings_set = FALSE;
  priv->page_setup_set = FALSE;
  priv->status = GTK_PRINT_STATUS_INITIAL;
213
  priv->track_print_status = FALSE;
214 215 216 217 218 219 220 221 222 223 224 225

  priv->print_pages = GTK_PRINT_PAGES_ALL;
  priv->page_ranges = NULL;
  priv->num_page_ranges = 0;
  priv->collate = FALSE;
  priv->reverse = FALSE;
  priv->num_copies = 1;
  priv->scale = 1.0;
  priv->page_set = GTK_PAGE_SET_ALL;
  priv->rotate_to_orientation = FALSE;
  priv->number_up = 1;
  priv->number_up_layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
226 227 228
}


229 230
static void
gtk_print_job_constructed (GObject *object)
231
{
232 233
  GtkPrintJob *job = GTK_PRINT_JOB (object);
  GtkPrintJobPrivate *priv = job->priv;
234

235
  G_OBJECT_CLASS (gtk_print_job_parent_class)->constructed (object);
236 237 238 239

  g_assert (priv->printer_set &&
	    priv->settings_set &&
	    priv->page_setup_set);
240
  
241
  _gtk_printer_prepare_for_print (priv->printer,
242
				  job,
243 244
				  priv->settings,
				  priv->page_setup);
245 246 247 248 249 250
}


static void
gtk_print_job_finalize (GObject *object)
{
251 252
  GtkPrintJob *job = GTK_PRINT_JOB (object);
  GtkPrintJobPrivate *priv = job->priv;
253

254 255 256 257 258 259
  if (priv->surface)
    cairo_surface_destroy (priv->surface);

  if (priv->backend)
    g_object_unref (priv->backend);

260
  if (priv->spool_io != NULL)
261
    {
262 263
      g_io_channel_unref (priv->spool_io);
      priv->spool_io = NULL;
264
    }
265

266 267
  if (priv->printer)
    g_object_unref (priv->printer);
268

269 270
  if (priv->settings)
    g_object_unref (priv->settings);
271

272 273
  if (priv->page_setup)
    g_object_unref (priv->page_setup);
274

275 276 277
  g_free (priv->page_ranges);
  priv->page_ranges = NULL;

278 279 280 281
  g_free (priv->title);
  priv->title = NULL;

  G_OBJECT_CLASS (gtk_print_job_parent_class)->finalize (object);
282 283 284 285
}

/**
 * gtk_print_job_new:
286 287 288 289
 * @title: the job title
 * @printer: a #GtkPrinter
 * @settings: a #GtkPrintSettings
 * @page_setup: a #GtkPageSetup
290 291 292
 *
 * Creates a new #GtkPrintJob.
 *
293
 * Returns: a new #GtkPrintJob
294
 *
295
 * Since: 2.10
296 297
 **/
GtkPrintJob *
298 299
gtk_print_job_new (const gchar      *title,
		   GtkPrinter       *printer,
300
		   GtkPrintSettings *settings,
301
		   GtkPageSetup     *page_setup)
302 303 304 305 306 307 308 309 310 311 312
{
  GObject *result;
  result = g_object_new (GTK_TYPE_PRINT_JOB,
                         "title", title,
			 "printer", printer,
			 "settings", settings,
			 "page-setup", page_setup,
			 NULL);
  return (GtkPrintJob *) result;
}

313 314 315 316 317 318
/**
 * gtk_print_job_get_settings:
 * @job: a #GtkPrintJob
 * 
 * Gets the #GtkPrintSettings of the print job.
 * 
319
 * Returns: (transfer none): the settings of @job
320 321 322
 *
 * Since: 2.10
 */
323
GtkPrintSettings *
324
gtk_print_job_get_settings (GtkPrintJob *job)
325
{
326
  g_return_val_if_fail (GTK_IS_PRINT_JOB (job), NULL);
327
  
328
  return job->priv->settings;
329 330
}

331 332 333 334 335 336
/**
 * gtk_print_job_get_printer:
 * @job: a #GtkPrintJob
 * 
 * Gets the #GtkPrinter of the print job.
 * 
337
 * Returns: (transfer none): the printer of @job
338 339 340
 *
 * Since: 2.10
 */
341
GtkPrinter *
342
gtk_print_job_get_printer (GtkPrintJob *job)
343
{
344
  g_return_val_if_fail (GTK_IS_PRINT_JOB (job), NULL);
345
  
346
  return job->priv->printer;
347 348
}

349 350 351 352 353 354
/**
 * gtk_print_job_get_title:
 * @job: a #GtkPrintJob
 * 
 * Gets the job title.
 * 
355
 * Returns: the title of @job
356 357 358
 *
 * Since: 2.10
 */
359
const gchar *
360
gtk_print_job_get_title (GtkPrintJob *job)
361
{
362
  g_return_val_if_fail (GTK_IS_PRINT_JOB (job), NULL);
363
  
364
  return job->priv->title;
365 366
}

367 368 369 370 371 372
/**
 * gtk_print_job_get_status:
 * @job: a #GtkPrintJob
 * 
 * Gets the status of the print job.
 * 
373
 * Returns: the status of @job
374 375 376
 *
 * Since: 2.10
 */
377
GtkPrintStatus
378
gtk_print_job_get_status (GtkPrintJob *job)
379
{
380
  g_return_val_if_fail (GTK_IS_PRINT_JOB (job), GTK_PRINT_STATUS_FINISHED);
381
  
382
  return job->priv->status;
383 384 385 386 387 388
}

void
gtk_print_job_set_status (GtkPrintJob   *job,
			  GtkPrintStatus status)
{
389 390
  GtkPrintJobPrivate *priv;

391 392
  g_return_if_fail (GTK_IS_PRINT_JOB (job));

393 394 395
  priv = job->priv;

  if (priv->status == status)
396 397
    return;

398
  priv->status = status;
399 400 401
  g_signal_emit (job, signals[STATUS_CHANGED], 0);
}

Matthias Clasen's avatar
Matthias Clasen committed
402 403 404
/**
 * gtk_print_job_set_source_file:
 * @job: a #GtkPrintJob
405
 * @filename: (type filename): the file to be printed
Matthias Clasen's avatar
Matthias Clasen committed
406 407 408 409 410
 * @error: return location for errors
 * 
 * Make the #GtkPrintJob send an existing document to the 
 * printing system. The file can be in any format understood
 * by the platforms printing system (typically PostScript,
Matthias Clasen's avatar
Matthias Clasen committed
411 412
 * but on many platforms PDF may work too). See 
 * gtk_printer_accepts_pdf() and gtk_printer_accepts_ps().
Matthias Clasen's avatar
Matthias Clasen committed
413 414 415 416 417
 * 
 * Returns: %FALSE if an error occurred
 *
 * Since: 2.10
 **/
418 419
gboolean
gtk_print_job_set_source_file (GtkPrintJob *job,
420
			       const gchar *filename,
421 422
			       GError     **error)
{
423
  GtkPrintJobPrivate *priv;
424 425 426
  GError *tmp_error;

  tmp_error = NULL;
427

428
  g_return_val_if_fail (GTK_IS_PRINT_JOB (job), FALSE);
429 430 431

  priv = job->priv;

432 433 434 435
  priv->spool_io = g_io_channel_new_file (filename, "r", &tmp_error);

  if (tmp_error == NULL)
    g_io_channel_set_encoding (priv->spool_io, NULL, &tmp_error);
436

437 438 439
  if (tmp_error != NULL)
    {
      g_propagate_error (error, tmp_error);
440 441
      return FALSE;
    }
442 443

  return TRUE;
444 445
}

446 447 448
/**
 * gtk_print_job_get_surface:
 * @job: a #GtkPrintJob
449
 * @error: (allow-none): return location for errors, or %NULL
450 451 452 453
 * 
 * Gets a cairo surface onto which the pages of
 * the print job should be rendered.
 * 
454
 * Returns: (transfer none): the cairo surface of @job
455 456 457
 *
 * Since: 2.10
 **/
458
cairo_surface_t *
459 460
gtk_print_job_get_surface (GtkPrintJob  *job,
			   GError      **error)
461
{
462
  GtkPrintJobPrivate *priv;
463
  gchar *filename = NULL;
464
  gdouble width, height;
465
  GtkPaperSize *paper_size;
466 467 468 469 470
  int fd;
  GError *tmp_error;

  tmp_error = NULL;

471 472
  g_return_val_if_fail (GTK_IS_PRINT_JOB (job), NULL);

473 474 475 476 477
  priv = job->priv;

  if (priv->surface)
    return priv->surface;
 
478
  g_return_val_if_fail (priv->spool_io == NULL, NULL);
479
 
480 481 482 483 484
  fd = g_file_open_tmp ("gtkprint_XXXXXX", 
			 &filename, 
			 &tmp_error);
  if (fd == -1)
    {
485
      g_free (filename);
486 487 488
      g_propagate_error (error, tmp_error);
      return NULL;
    }
489

490 491 492 493
  fchmod (fd, S_IRUSR | S_IWUSR);
  
#ifdef G_ENABLE_DEBUG 
  /* If we are debugging printing don't delete the tmp files */
494
  if (!(gtk_get_debug_flags () & GTK_DEBUG_PRINTING))
495
#endif /* G_ENABLE_DEBUG */
496
  g_unlink (filename);
497
  g_free (filename);
498

499
  paper_size = gtk_page_setup_get_paper_size (priv->page_setup);
500 501
  width = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS);
  height = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS);
502 503 504 505
 
  priv->spool_io = g_io_channel_unix_new (fd);
  g_io_channel_set_close_on_unref (priv->spool_io, TRUE);
  g_io_channel_set_encoding (priv->spool_io, NULL, &tmp_error);
506
  
507 508 509 510 511 512 513 514
  if (tmp_error != NULL)
    {
      g_io_channel_unref (priv->spool_io);
      priv->spool_io = NULL;
      g_propagate_error (error, tmp_error);
      return NULL;
    }

515
  priv->surface = _gtk_printer_create_cairo_surface (priv->printer,
Matthias Clasen's avatar
Matthias Clasen committed
516
						     priv->settings,
Matthias Clasen's avatar
Matthias Clasen committed
517
						     width, height,
518 519
						     priv->spool_io);
  
520
  return priv->surface;
521 522
}

523 524 525 526 527 528 529
/**
 * gtk_print_job_set_track_print_status:
 * @job: a #GtkPrintJob
 * @track_status: %TRUE to track status after printing
 * 
 * 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
530
 * can allow your application to show things like “out of paper” issues,
531 532 533 534 535 536 537 538 539
 * 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.
 *
 * Since: 2.10
 */
void
gtk_print_job_set_track_print_status (GtkPrintJob *job,
Matthias Clasen's avatar
Matthias Clasen committed
540
				      gboolean     track_status)
541 542 543 544 545 546 547
{
  GtkPrintJobPrivate *priv;

  g_return_if_fail (GTK_IS_PRINT_JOB (job));

  priv = job->priv;

Matthias Clasen's avatar
Matthias Clasen committed
548 549 550 551 552 553
  track_status = track_status != FALSE;

  if (priv->track_print_status != track_status)
    {
      priv->track_print_status = track_status;
      
554
      g_object_notify (G_OBJECT (job), "track-print-status");
Matthias Clasen's avatar
Matthias Clasen committed
555
    }
556 557 558 559 560 561 562 563 564
}

/**
 * gtk_print_job_get_track_print_status:
 * @job: a #GtkPrintJob
 *
 * Returns wheter jobs will be tracked after printing.
 * For details, see gtk_print_job_set_track_print_status().
 *
565
 * Returns: %TRUE if print job status will be reported after printing
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
 *
 * Since: 2.10
 */
gboolean
gtk_print_job_get_track_print_status (GtkPrintJob *job)
{
  GtkPrintJobPrivate *priv;

  g_return_val_if_fail (GTK_IS_PRINT_JOB (job), FALSE);

  priv = job->priv;
  
  return priv->track_print_status;
}

581 582 583 584 585 586 587 588
static void
gtk_print_job_set_property (GObject      *object,
	                    guint         prop_id,
	                    const GValue *value,
                            GParamSpec   *pspec)

{
  GtkPrintJob *job = GTK_PRINT_JOB (object);
589
  GtkPrintJobPrivate *priv = job->priv;
590 591 592 593
  GtkPrintSettings *settings;

  switch (prop_id)
    {
594
    case PROP_TITLE:
595
      g_free (priv->title);
596
      priv->title = g_value_dup_string (value);
597 598
      break;
    
599
    case PROP_PRINTER:
600 601 602
      priv->printer = GTK_PRINTER (g_value_dup_object (value));
      priv->printer_set = TRUE;
      priv->backend = g_object_ref (gtk_printer_get_backend (priv->printer));
603 604
      break;

605
    case PROP_PAGE_SETUP:
606 607
      priv->page_setup = GTK_PAGE_SETUP (g_value_dup_object (value));
      priv->page_setup_set = TRUE;
608 609
      break;
      
610
    case PROP_SETTINGS:
611 612 613
      /* We save a copy of the settings since we modify
       * if when preparing the printer job. */
      settings = GTK_PRINT_SETTINGS (g_value_get_object (value));
614 615
      priv->settings = gtk_print_settings_copy (settings);
      priv->settings_set = TRUE;
616 617
      break;

618 619 620 621
    case PROP_TRACK_PRINT_STATUS:
      gtk_print_job_set_track_print_status (job, g_value_get_boolean (value));
      break;

622 623 624 625 626 627 628 629 630 631 632 633 634
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
gtk_print_job_get_property (GObject    *object,
			    guint       prop_id,
			    GValue     *value,
			    GParamSpec *pspec)
{
  GtkPrintJob *job = GTK_PRINT_JOB (object);
635
  GtkPrintJobPrivate *priv = job->priv;
636 637 638

  switch (prop_id)
    {
639
    case PROP_TITLE:
640
      g_value_set_string (value, priv->title);
641
      break;
642
    case PROP_PRINTER:
643
      g_value_set_object (value, priv->printer);
644
      break;
645
    case PROP_SETTINGS:
646
      g_value_set_object (value, priv->settings);
647
      break;
648
    case PROP_PAGE_SETUP:
649
      g_value_set_object (value, priv->page_setup);
650
      break;
651 652 653
    case PROP_TRACK_PRINT_STATUS:
      g_value_set_boolean (value, priv->track_print_status);
      break;
654 655 656 657 658 659
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

660 661 662
/**
 * gtk_print_job_send:
 * @job: a GtkPrintJob
663
 * @callback: function to call when the job completes or an error occurs
664 665 666 667 668 669 670
 * @user_data: user data that gets passed to @callback
 * @dnotify: destroy notify for @user_data
 * 
 * Sends the print job off to the printer.  
 * 
 * Since: 2.10
 **/
671
void
672 673 674
gtk_print_job_send (GtkPrintJob             *job,
                    GtkPrintJobCompleteFunc  callback,
                    gpointer                 user_data,
675
		    GDestroyNotify           dnotify)
676
{
677 678
  GtkPrintJobPrivate *priv;

679
  g_return_if_fail (GTK_IS_PRINT_JOB (job));
680 681

  priv = job->priv;
682
  g_return_if_fail (priv->spool_io != NULL);
683 684
  
  gtk_print_job_set_status (job, GTK_PRINT_STATUS_SENDING_DATA);
685 686 687
  
  g_io_channel_seek_position (priv->spool_io, 0, G_SEEK_SET, NULL);
  
688
  gtk_print_backend_print_stream (priv->backend, job,
689 690
				  priv->spool_io,
                                  callback, user_data, dnotify);
691
}
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731

/**
 * gtk_print_job_get_pages:
 * @job: a #GtkPrintJob
 *
 * Gets the #GtkPrintPages setting for this job.
 *
 * Returns: the #GtkPrintPages setting
 *
 * Since: 3.0
 */
GtkPrintPages
gtk_print_job_get_pages (GtkPrintJob *job)
{
  return job->priv->print_pages;
}

/**
 * gtk_print_job_set_pages:
 * @job: a #GtkPrintJob
 * @pages: the #GtkPrintPages setting
 *
 * Sets the #GtkPrintPages setting for this job.
 *
 * Since: 3.0
 */
void
gtk_print_job_set_pages (GtkPrintJob   *job,
                         GtkPrintPages  pages)
{
  job->priv->print_pages = pages;
}

/**
 * gtk_print_job_get_page_ranges:
 * @job: a #GtkPrintJob
 * @n_ranges: (out): return location for the number of ranges
 *
 * Gets the page ranges for this job.
 *
732 733
 * Returns: (array length=n_ranges) (transfer none): a pointer to an
 * array of #GtkPageRange structs
734 735 736 737 738 739 740 741 742 743 744 745 746 747
 *
 * Since: 3.0
 */
GtkPageRange *
gtk_print_job_get_page_ranges (GtkPrintJob *job,
                               gint        *n_ranges)
{
  *n_ranges = job->priv->num_page_ranges;
  return job->priv->page_ranges;
}

/**
 * gtk_print_job_set_page_ranges:
 * @job: a #GtkPrintJob
748
 * @ranges: (array length=n_ranges): pointer to an array of
749
 *    #GtkPageRange structs
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
 * @n_ranges: the length of the @ranges array
 *
 * Sets the page ranges for this job.
 *
 * Since: 3.0
 */
void
gtk_print_job_set_page_ranges (GtkPrintJob  *job,
                               GtkPageRange *ranges,
                               gint          n_ranges)
{
  job->priv->page_ranges = ranges;
  job->priv->num_page_ranges = n_ranges;
}

/**
 * gtk_print_job_get_page_set:
 * @job: a #GtkPrintJob
 *
 * Gets the #GtkPageSet setting for this job.
 *
 * Returns: the #GtkPageSet setting
 *
 * Since: 3.0
 */
GtkPageSet
gtk_print_job_get_page_set (GtkPrintJob *job)
{
  return job->priv->page_set;
}

/**
 * gtk_print_job_set_page_set:
 * @job: a #GtkPrintJob
 * @page_set: a #GtkPageSet setting
 *
 * Sets the #GtkPageSet setting for this job.
 *
 * Since: 3.0
 */
void
gtk_print_job_set_page_set (GtkPrintJob *job,
                            GtkPageSet   page_set)
{
  job->priv->page_set = page_set;
}

/**
 * gtk_print_job_get_num_copies:
 * @job: a #GtkPrintJob
 *
 * Gets the number of copies of this job.
 *
 * Returns: the number of copies
 *
 * Since: 3.0
 */
gint
gtk_print_job_get_num_copies (GtkPrintJob *job)
{
  return job->priv->num_copies;
}

/**
 * gtk_print_job_set_num_copies:
 * @job: a #GtkPrintJob
 * @num_copies: the number of copies
 *
 * Sets the number of copies for this job.
 *
 * Since: 3.0
 */
void
gtk_print_job_set_num_copies (GtkPrintJob *job,
                              gint         num_copies)
{
  job->priv->num_copies = num_copies;
}

/**
 * gtk_print_job_get_scale:
 * @job: a #GtkPrintJob
 *
 * Gets the scale for this job (where 1.0 means unscaled).
 *
 * Returns: the scale
 *
 * Since: 3.0
 */
gdouble
gtk_print_job_get_scale (GtkPrintJob *job)

{
  return job->priv->scale;
}

/**
 * gtk_print_job_set_scale:
 * @job: a #GtkPrintJob
 * @scale: the scale
 *
 * Sets the scale for this job (where 1.0 means unscaled).
 *
 * Since: 3.0
 */
void
gtk_print_job_set_scale (GtkPrintJob *job,
                         gdouble      scale)
{
  job->priv->scale = scale;
}

/**
 * gtk_print_job_get_n_up:
 * @job: a #GtkPrintJob
 *
 * Gets the n-up setting for this job.
 *
 * Returns: the n-up setting
 *
 * Since: 3.0
 */
guint
gtk_print_job_get_n_up (GtkPrintJob *job)
{
  return job->priv->number_up;
}

/**
 * gtk_print_job_set_n_up:
 * @job: a #GtkPrintJob
 * @n_up: the n-up value
 *
 * Sets the n-up setting for this job.
 *
 * Since: 3.0
 */
void
gtk_print_job_set_n_up (GtkPrintJob *job,
                        guint        n_up)
{
  job->priv->number_up = n_up;
}

/**
 * gtk_print_job_get_n_up_layout:
 * @job: a #GtkPrintJob
 *
 * Gets the n-up layout setting for this job.
 *
 * Returns: the n-up layout
 *
 * Since: 3.0
 */
GtkNumberUpLayout
gtk_print_job_get_n_up_layout (GtkPrintJob *job)
{
  return job->priv->number_up_layout;
}

/**
 * gtk_print_job_set_n_up_layout:
 * @job: a #GtkPrintJob
 * @layout: the n-up layout setting
 *
 * Sets the n-up layout setting for this job.
 *
 * Since: 3.0
 */
void
gtk_print_job_set_n_up_layout (GtkPrintJob       *job,
                               GtkNumberUpLayout  layout)
{
  job->priv->number_up_layout = layout;
}

/**
 * gtk_print_job_get_rotate:
 * @job: a #GtkPrintJob
 *
 * Gets whether the job is printed rotated.
 *
 * Returns: whether the job is printed rotated
 *
 * Since: 3.0
 */
gboolean
gtk_print_job_get_rotate (GtkPrintJob *job)
{
  return job->priv->rotate_to_orientation;
}

/**
 * gtk_print_job_set_rotate:
 * @job: a #GtkPrintJob
 * @rotate: whether to print rotated
 *
 * Sets whether this job is printed rotated.
 *
 * Since: 3.0
 */
void
gtk_print_job_set_rotate (GtkPrintJob *job,
                          gboolean     rotate)
{
  job->priv->rotate_to_orientation = rotate;
}

/**
 * gtk_print_job_get_collate:
 * @job: a #GtkPrintJob
 *
 * Gets whether this job is printed collated.
 *
 * Returns: whether the job is printed collated
 *
 * Since: 3.0
 */
gboolean
gtk_print_job_get_collate (GtkPrintJob *job)
{
  return job->priv->collate;
}

/**
975
 * gtk_print_job_set_collate:
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
 * @job: a #GtkPrintJob
 * @collate: whether the job is printed collated
 *
 * Sets whether this job is printed collated.
 *
 * Since: 3.0
 */
void
gtk_print_job_set_collate (GtkPrintJob *job,
                           gboolean     collate)
{
  job->priv->collate = collate;
}

/**
 * gtk_print_job_get_reverse:
 * @job: a #GtkPrintJob
 *
 * Gets whether this job is printed reversed.
 *
 * Returns: whether the job is printed reversed.
 *
 * Since: 3.0
 */
gboolean
gtk_print_job_get_reverse (GtkPrintJob *job)
{
  return job->priv->reverse;
}

/**
 * gtk_print_job_set_reverse:
 * @job: a #GtkPrintJob
 * @reverse: whether the job is printed reversed
 *
 * Sets whether this job is printed reversed.
 *
 * Since: 3.0
 */
void
gtk_print_job_set_reverse (GtkPrintJob *job,
                           gboolean     reverse)
{
  job->priv->reverse = reverse;
}