gtkprinter.c 19.4 KB
Newer Older
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
/* GtkPrinter
 * 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
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "gtkintl.h"
#include "gtkprivate.h"

#include "gtkprinter.h"
#include "gtkprinter-private.h"
#include "gtkprintbackend.h"
#include "gtkprintjob.h"
#include "gtkalias.h"

#define GTK_PRINTER_GET_PRIVATE(o)  \
   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_PRINTER, GtkPrinterPrivate))

static void gtk_printer_finalize     (GObject *object);

struct _GtkPrinterPrivate
{
  gchar *name;
  gchar *location;
  gchar *description;
  gchar *icon_name;

46 47 48 49 50 51 52
  guint is_active   : 1;
  guint is_new      : 1;
  guint is_virtual  : 1;
  guint is_default  : 1;
  guint has_details : 1;
  guint accepts_pdf : 1;
  guint accepts_ps  : 1;
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

  gchar *state_message;  
  gint job_count;

  GtkPrintBackend *backend;
};

enum {
  DETAILS_ACQUIRED,
  LAST_SIGNAL
};

enum {
  PROP_0,
  PROP_NAME,
  PROP_BACKEND,
  PROP_IS_VIRTUAL,
  PROP_STATE_MESSAGE,
  PROP_LOCATION,
  PROP_ICON_NAME,
73 74 75
  PROP_JOB_COUNT,
  PROP_ACCEPTS_PDF,
  PROP_ACCEPTS_PS
76 77 78 79 80 81 82 83 84 85 86 87 88
};

static guint signals[LAST_SIGNAL] = { 0 };

static void gtk_printer_set_property (GObject      *object,
				      guint         prop_id,
				      const GValue *value,
				      GParamSpec   *pspec);
static void gtk_printer_get_property (GObject      *object,
				      guint         prop_id,
				      GValue       *value,
				      GParamSpec   *pspec);

Matthias Clasen's avatar
Matthias Clasen committed
89
G_DEFINE_TYPE (GtkPrinter, gtk_printer, G_TYPE_OBJECT)
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

static int
safe_strcmp (const char *a, const char *b)
{
  if (a == b)
    return 0;
  if (a == NULL)
    return -1;
  if (b == NULL)
    return 1;
  return strcmp (a, b);
}

static void
gtk_printer_class_init (GtkPrinterClass *class)
{
  GObjectClass *object_class;
  object_class = (GObjectClass *) class;

  object_class->finalize = gtk_printer_finalize;

  object_class->set_property = gtk_printer_set_property;
  object_class->get_property = gtk_printer_get_property;

  g_type_class_add_private (class, sizeof (GtkPrinterPrivate));

  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_NAME,
                                   g_param_spec_string ("name",
						        P_("Name"),
						        P_("Name of the printer"),
						        NULL,
							GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_BACKEND,
                                   g_param_spec_object ("backend",
						        P_("Backend"),
						        P_("Backend for the printer"),
						        GTK_TYPE_PRINT_BACKEND,
							GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_IS_VIRTUAL,
                                   g_param_spec_boolean ("is-virtual",
							 P_("Is Virtual"),
134
							 P_("FALSE if this represents a real hardware printer"),
135 136
							 FALSE,
							 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
137 138 139 140 141 142 143 144 145 146 147 148 149 150
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_ACCEPTS_PDF,
                                   g_param_spec_boolean ("accepts-pdf",
							 P_("Accepts PDF"),
							 P_("TRUE if this printer can accept PDF"),
							 TRUE,
							 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_ACCEPTS_PS,
                                   g_param_spec_boolean ("accepts-ps",
							 P_("Accepts PostScript"),
							 P_("TRUE if this printer can accept PostScript"),
							 TRUE,
							 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
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
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_STATE_MESSAGE,
                                   g_param_spec_string ("state-message",
						        P_("State Message"),
						        P_("String giving the current state of the printer"),
						        NULL,
							GTK_PARAM_READABLE));
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_LOCATION,
                                   g_param_spec_string ("location",
						        P_("Location"),
						        P_("The location of the printer"),
						        NULL,
							GTK_PARAM_READABLE));
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_ICON_NAME,
                                   g_param_spec_string ("icon-name",
						        P_("Icon Name"),
						        P_("The icon name to use for the printer"),
						        NULL,
							GTK_PARAM_READABLE));
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_JOB_COUNT,
				   g_param_spec_int ("job-count",
 						     P_("Job Count"),
 						     P_("Number of jobs queued in the printer"),
 						     0,
 						     G_MAXINT,
 						     0,
 						     GTK_PARAM_READABLE));

182 183 184 185 186 187 188 189 190 191 192
  /**
   * GtkPrinter::details-acquired:
   * @printer: the #GtkPrinter on which the signal is emitted
   * @success: %TRUE if the details were successfully acquired
   *
   * Gets emitted in response to a request for detailed information
   * about a printer from the print backend. The @success parameter
   * indicates if the information was actually obtained.
   *
   * Since: 2.10
   */
193
  signals[DETAILS_ACQUIRED] =
Matthias Clasen's avatar
Matthias Clasen committed
194 195 196 197 198 199 200
    g_signal_new (I_("details-acquired"),
		  G_TYPE_FROM_CLASS (class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrinterClass, details_acquired),
		  NULL, NULL,
		  g_cclosure_marshal_VOID__BOOLEAN,
		  G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
201 202 203 204 205
}

static void
gtk_printer_init (GtkPrinter *printer)
{
206
  GtkPrinterPrivate *priv;
207

208
  priv = printer->priv = GTK_PRINTER_GET_PRIVATE (printer); 
209

210 211 212 213
  priv->name = NULL;
  priv->location = NULL;
  priv->description = NULL;
  priv->icon_name = NULL;
214

215 216 217
  priv->is_active = TRUE;
  priv->is_new = TRUE;
  priv->has_details = FALSE;
218 219
  priv->accepts_pdf = TRUE;
  priv->accepts_ps = TRUE;
220 221 222

  priv->state_message = NULL;  
  priv->job_count = 0;
223 224 225 226 227 228
}

static void
gtk_printer_finalize (GObject *object)
{
  GtkPrinter *printer = GTK_PRINTER (object);
229
  GtkPrinterPrivate *priv = printer->priv;
230

231 232 233 234 235
  g_free (priv->name);
  g_free (priv->location);
  g_free (priv->description);
  g_free (priv->state_message);
  g_free (priv->icon_name);
236

Alexander Larsson's avatar
Alexander Larsson committed
237 238 239
  if (priv->backend)
    g_object_unref (priv->backend);

240
  G_OBJECT_CLASS (gtk_printer_parent_class)->finalize (object);
241 242 243 244 245 246 247 248 249
}

static void
gtk_printer_set_property (GObject         *object,
			  guint            prop_id,
			  const GValue    *value,
			  GParamSpec      *pspec)
{
  GtkPrinter *printer = GTK_PRINTER (object);
250 251
  GtkPrinterPrivate *priv = printer->priv;

252 253 254
  switch (prop_id)
    {
    case PROP_NAME:
255
      priv->name = g_value_dup_string (value);
256 257 258
      break;
    
    case PROP_BACKEND:
Alexander Larsson's avatar
Alexander Larsson committed
259
      priv->backend = GTK_PRINT_BACKEND (g_value_dup_object (value));
260 261 262
      break;

    case PROP_IS_VIRTUAL:
263
      priv->is_virtual = g_value_get_boolean (value);
264 265
      break;

266 267 268 269 270 271 272 273
    case PROP_ACCEPTS_PDF:
      priv->accepts_pdf = g_value_get_boolean (value);
      break;

    case PROP_ACCEPTS_PS:
      priv->accepts_ps = g_value_get_boolean (value);
      break;

274 275 276 277 278 279 280 281 282 283 284 285 286
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
gtk_printer_get_property (GObject    *object,
			  guint       prop_id,
			  GValue     *value,
			  GParamSpec *pspec)
{
  GtkPrinter *printer = GTK_PRINTER (object);
287
  GtkPrinterPrivate *priv = printer->priv;
288 289 290 291

  switch (prop_id)
    {
    case PROP_NAME:
292 293
      if (priv->name)
	g_value_set_string (value, priv->name);
294 295 296 297
      else
	g_value_set_string (value, "");
      break;
    case PROP_BACKEND:
298
      g_value_set_object (value, priv->backend);
299 300
      break;
    case PROP_STATE_MESSAGE:
301 302
      if (priv->state_message)
	g_value_set_string (value, priv->state_message);
303 304 305 306
      else
	g_value_set_string (value, "");
      break;
    case PROP_LOCATION:
307 308
      if (priv->location)
	g_value_set_string (value, priv->location);
309 310 311 312
      else
	g_value_set_string (value, "");
      break;
    case PROP_ICON_NAME:
313 314
      if (priv->icon_name)
	g_value_set_string (value, priv->icon_name);
315 316 317 318
      else
	g_value_set_string (value, "");
      break;
    case PROP_JOB_COUNT:
319
      g_value_set_int (value, priv->job_count);
320
      break;
321 322 323 324 325 326 327 328 329
    case PROP_IS_VIRTUAL:
      g_value_set_boolean (value, priv->is_virtual);
      break;
    case PROP_ACCEPTS_PDF:
      g_value_set_boolean (value, priv->accepts_pdf);
      break;
    case PROP_ACCEPTS_PS:
      g_value_set_boolean (value, priv->accepts_ps);
      break;
330 331 332 333 334 335 336 337
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

/**
 * gtk_printer_new:
338 339
 * @name: the name of the printer
 * @backend: a #GtkPrintBackend
Matthias Clasen's avatar
Matthias Clasen committed
340
 * @virtual_: whether the printer is virtual
341 342 343 344 345
 *
 * Creates a new #GtkPrinter.
 *
 * Return value: a new #GtkPrinter
 *
346
 * Since: 2.10
347 348
 **/
GtkPrinter *
349
gtk_printer_new (const gchar     *name,
350
		 GtkPrintBackend *backend,
Matthias Clasen's avatar
Matthias Clasen committed
351
		 gboolean         virtual_)
352 353 354 355 356 357
{
  GObject *result;
  
  result = g_object_new (GTK_TYPE_PRINTER,
			 "name", name,
			 "backend", backend,
Matthias Clasen's avatar
Matthias Clasen committed
358
			 "is-virtual", virtual_,
359 360 361 362 363
                         NULL);

  return (GtkPrinter *) result;
}

364 365 366 367 368 369 370 371 372 373
/**
 * gtk_printer_get_backend:
 * @printer: a #GtkPrinter
 * 
 * Returns the backend of the printer.
 * 
 * Return value: the backend of @printer
 * 
 * Since: 2.10
 */
374 375 376 377 378 379 380 381
GtkPrintBackend *
gtk_printer_get_backend (GtkPrinter *printer)
{
  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);
  
  return printer->priv->backend;
}

382 383 384 385 386 387 388 389 390 391 392
/**
 * gtk_printer_get_name:
 * @printer: a #GtkPrinter
 * 
 * Returns the name of the printer.
 * 
 * Return value: the name of @printer
 *
 * Since: 2.10
 */
G_CONST_RETURN gchar *
393 394 395 396 397 398 399
gtk_printer_get_name (GtkPrinter *printer)
{
  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);

  return printer->priv->name;
}

400 401 402 403 404 405 406 407 408 409 410
/**
 * gtk_printer_get_description:
 * @printer: a #GtkPrinter
 * 
 * Gets the description of the printer.
 * 
 * Return value: the description of @printer
 *
 * Since: 2.10
 */
G_CONST_RETURN gchar *
411 412 413 414 415 416 417 418
gtk_printer_get_description (GtkPrinter *printer)
{
  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);
  
  return printer->priv->description;
}

gboolean
419 420
gtk_printer_set_description (GtkPrinter  *printer,
			     const gchar *description)
421
{
422 423
  GtkPrinterPrivate *priv;

424 425
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);

426 427 428
  priv = printer->priv;

  if (safe_strcmp (priv->description, description) == 0)
429 430
    return FALSE;

431 432
  g_free (priv->description);
  priv->description = g_strdup (description);
433 434 435 436
  
  return TRUE;
}

437 438 439 440 441 442 443 444 445 446 447 448
/**
 * gtk_printer_get_state_message:
 * @printer: a #GtkPrinter
 * 
 * Returns the state message describing the current state
 * of the printer.
 * 
 * Return value: the state message of @printer
 *
 * Since: 2.10
 */
G_CONST_RETURN gchar *
449 450 451 452 453 454 455 456
gtk_printer_get_state_message (GtkPrinter *printer)
{
  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);

  return printer->priv->state_message;
}

gboolean
457 458
gtk_printer_set_state_message (GtkPrinter  *printer,
			       const gchar *message)
459
{
460 461
  GtkPrinterPrivate *priv;

462 463
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);

464 465 466
  priv = printer->priv;

  if (safe_strcmp (priv->state_message, message) == 0)
467 468
    return FALSE;

469 470
  g_free (priv->state_message);
  priv->state_message = g_strdup (message);
471 472 473 474 475
  g_object_notify (G_OBJECT (printer), "state-message");

  return TRUE;
}

476 477 478 479 480 481 482 483 484 485 486
/**
 * gtk_printer_get_location:
 * @printer: a #GtkPrinter
 * 
 * Returns a  description of the location of the printer.
 * 
 * Return value: the location of @printer
 *
 * Since: 2.10
 */
G_CONST_RETURN gchar *
487 488 489 490 491 492 493 494
gtk_printer_get_location (GtkPrinter *printer)
{
  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);

  return printer->priv->location;
}

gboolean
495 496
gtk_printer_set_location (GtkPrinter  *printer,
			  const gchar *location)
497
{
498 499
  GtkPrinterPrivate *priv;

500 501
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);

502 503 504
  priv = printer->priv;

  if (safe_strcmp (priv->location, location) == 0)
505 506
    return FALSE;

507 508
  g_free (priv->location);
  priv->location = g_strdup (location);
509 510 511 512 513
  g_object_notify (G_OBJECT (printer), "location");
  
  return TRUE;
}

514 515 516 517 518 519 520 521 522 523 524
/**
 * gtk_printer_get_icon_name:
 * @printer: a #GtkPrinter
 * 
 * Gets the name of the icon to use for the printer.
 * 
 * Return value: the icon name for @printer
 *
 * Since: 2.10
 */
G_CONST_RETURN gchar * 
525 526 527 528 529 530 531 532
gtk_printer_get_icon_name (GtkPrinter *printer)
{
  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);

  return printer->priv->icon_name;
}

void
533 534
gtk_printer_set_icon_name (GtkPrinter  *printer,
			   const gchar *icon)
535
{
536 537
  GtkPrinterPrivate *priv;

538 539
  g_return_if_fail (GTK_IS_PRINTER (printer));

540 541 542 543
  priv = printer->priv;

  g_free (priv->icon_name);
  priv->icon_name = g_strdup (icon);
544 545 546
  g_object_notify (G_OBJECT (printer), "icon-name");
}

547 548 549 550 551 552 553 554 555 556
/**
 * gtk_printer_get_job_count:
 * @printer: a #GtkPrinter
 * 
 * Gets the number of jobs currently queued on the printer.
 * 
 * Return value: the number of jobs on @printer
 *
 * Since: 2.10
 */
557 558 559 560 561 562 563 564 565 566
gint 
gtk_printer_get_job_count (GtkPrinter *printer)
{
  g_return_val_if_fail (GTK_IS_PRINTER (printer), 0);

  return printer->priv->job_count;
}

gboolean
gtk_printer_set_job_count (GtkPrinter *printer,
567
			   gint        count)
568
{
569 570
  GtkPrinterPrivate *priv;

571 572
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);

573 574 575
  priv = printer->priv;

  if (priv->job_count == count)
576 577
    return FALSE;

578
  priv->job_count = count;
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
  
  g_object_notify (G_OBJECT (printer), "job-count");
  
  return TRUE;
}

gboolean
_gtk_printer_has_details (GtkPrinter *printer)
{
  return printer->priv->has_details;
}

void
gtk_printer_set_has_details (GtkPrinter *printer,
			     gboolean val)
{
  printer->priv->has_details = val;
}

598 599 600 601 602 603 604 605 606 607 608
/**
 * gtk_printer_is_active:
 * @printer: a #GtkPrinter
 * 
 * Returns whether the printer is currently active (i.e. 
 * accepts new jobs).
 * 
 * Return value: %TRUE if @printer is active
 *
 * Since: 2.10
 */
609 610 611 612 613 614 615 616 617 618 619 620
gboolean
gtk_printer_is_active (GtkPrinter *printer)
{
  g_return_val_if_fail (GTK_IS_PRINTER (printer), TRUE);
  
  return printer->priv->is_active;
}

void
gtk_printer_set_is_active (GtkPrinter *printer,
			   gboolean val)
{
621 622
  g_return_if_fail (GTK_IS_PRINTER (printer));

623 624 625 626
  printer->priv->is_active = val;
}


627 628 629 630 631 632 633 634 635 636 637 638
/**
 * gtk_printer_is_virtual:
 * @printer: a #GtkPrinter
 * 
 * Returns whether the printer is virtual (i.e. does not
 * represent actual printer hardware, but something like 
 * a CUPS class).
 * 
 * Return value: %TRUE if @printer is virtual
 *
 * Since: 2.10
 */
639 640 641 642 643 644 645 646
gboolean
gtk_printer_is_virtual (GtkPrinter *printer)
{
  g_return_val_if_fail (GTK_IS_PRINTER (printer), TRUE);
  
  return printer->priv->is_virtual;
}

647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
gboolean 
gtk_printer_accepts_pdf (GtkPrinter *printer)
{ 
  g_return_val_if_fail (GTK_IS_PRINTER (printer), TRUE);
  
  return printer->priv->accepts_pdf;
}

gboolean 
gtk_printer_accepts_ps (GtkPrinter *printer)
{ 
  g_return_val_if_fail (GTK_IS_PRINTER (printer), TRUE);
  
  return printer->priv->accepts_ps;
}

663 664 665 666 667 668 669 670 671 672 673 674
gboolean
gtk_printer_is_new (GtkPrinter *printer)
{
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);
  
  return printer->priv->is_new;
}

void
gtk_printer_set_is_new (GtkPrinter *printer,
			gboolean val)
{
675 676
  g_return_if_fail (GTK_IS_PRINTER (printer));

677 678 679 680
  printer->priv->is_new = val;
}


681 682 683 684 685 686 687 688 689 690
/**
 * gtk_printer_is_default:
 * @printer: a #GtkPrinter
 * 
 * Returns whether the printer is the default printer.
 * 
 * Return value: %TRUE if @printer is the default
 *
 * Since: 2.10
 */
691 692 693 694 695 696 697 698 699 700
gboolean
gtk_printer_is_default (GtkPrinter *printer)
{
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);
  
  return printer->priv->is_default;
}

void
gtk_printer_set_is_default (GtkPrinter *printer,
701
			    gboolean    val)
702
{
703 704
  g_return_if_fail (GTK_IS_PRINTER (printer));

705 706 707 708 709 710
  printer->priv->is_default = TRUE;
}

void
_gtk_printer_request_details (GtkPrinter *printer)
{
Alexander Larsson's avatar
Alexander Larsson committed
711
  GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
712
  backend_class->printer_request_details (printer);
713 714 715
}

GtkPrinterOptionSet *
716
_gtk_printer_get_options (GtkPrinter       *printer,
717
			  GtkPrintSettings *settings,
718
			  GtkPageSetup     *page_setup)
719
{
Alexander Larsson's avatar
Alexander Larsson committed
720 721
  GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
  return backend_class->printer_get_options (printer, settings, page_setup);
722 723 724 725 726 727
}

gboolean
_gtk_printer_mark_conflicts (GtkPrinter          *printer,
			     GtkPrinterOptionSet *options)
{
Alexander Larsson's avatar
Alexander Larsson committed
728 729
  GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
  return backend_class->printer_mark_conflicts (printer, options);
730 731 732 733 734 735 736
}
  
void
_gtk_printer_get_settings_from_options (GtkPrinter          *printer,
					GtkPrinterOptionSet *options,
					GtkPrintSettings    *settings)
{
Alexander Larsson's avatar
Alexander Larsson committed
737
  GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
738
  backend_class->printer_get_settings_from_options (printer, options, settings);
739 740 741
}

void
742 743
_gtk_printer_prepare_for_print (GtkPrinter       *printer,
				GtkPrintJob      *print_job,
744
				GtkPrintSettings *settings,
745
				GtkPageSetup     *page_setup)
746
{
Alexander Larsson's avatar
Alexander Larsson committed
747
  GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
748
  backend_class->printer_prepare_for_print (printer, print_job, settings, page_setup);
749 750 751
}

cairo_surface_t *
752 753 754 755 756
_gtk_printer_create_cairo_surface (GtkPrinter       *printer,
				   GtkPrintSettings *settings,
				   gdouble           width, 
				   gdouble           height,
				   gint              cache_fd)
757
{
Alexander Larsson's avatar
Alexander Larsson committed
758
  GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
759

760 761
  return backend_class->printer_create_cairo_surface (printer, settings,
						      width, height, cache_fd);
762 763 764 765 766
}

GList  *
_gtk_printer_list_papers (GtkPrinter *printer)
{
Alexander Larsson's avatar
Alexander Larsson committed
767
  GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
768

Alexander Larsson's avatar
Alexander Larsson committed
769
  return backend_class->printer_list_papers (printer);
770 771 772
}

void
773 774 775 776 777
_gtk_printer_get_hard_margins (GtkPrinter *printer,
			       gdouble    *top,
			       gdouble    *bottom,
			       gdouble    *left,
			       gdouble    *right)
778
{
Alexander Larsson's avatar
Alexander Larsson committed
779
  GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
780

Alexander Larsson's avatar
Alexander Larsson committed
781 782 783
  backend_class->printer_get_hard_margins (printer, top, bottom, left, right);
}

784 785 786 787 788 789 790 791
GtkPrintCapabilities
_gtk_printer_get_capabilities (GtkPrinter *printer)
{
  GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);

  return backend_class->printer_get_capabilities (printer);
}

Alexander Larsson's avatar
Alexander Larsson committed
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
gint
gtk_printer_compare (GtkPrinter *a, GtkPrinter *b)
{
  const char *name_a, *name_b;
  
  g_assert (GTK_IS_PRINTER (a) && GTK_IS_PRINTER (b));
  
  name_a = gtk_printer_get_name (a);
  name_b = gtk_printer_get_name (b);
  if (name_a == NULL  && name_b == NULL)
    return 0;
  else if (name_a == NULL)
    return G_MAXINT;
  else if (name_b == NULL)
    return G_MININT;
  else
    return g_ascii_strcasecmp (name_a, name_b);
809 810 811 812
}

#define __GTK_PRINTER_C__
#include "gtkaliasdef.c"