gtkprinter.c 36.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* 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
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
 */

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

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

#include "gtkprinter.h"
Matthias Clasen's avatar
Matthias Clasen committed
27
#include "gtkprinterprivate.h"
28
#include "gtkprintbackendprivate.h"
29
#include "gtkprintjob.h"
30 31

/**
Matthias Clasen's avatar
Matthias Clasen committed
32
 * GtkPrinter:
33
 *
Matthias Clasen's avatar
Matthias Clasen committed
34
 * A `GtkPrinter` object represents a printer.
35
 *
Matthias Clasen's avatar
Matthias Clasen committed
36 37 38 39
 * You only need to deal directly with printers if you use the
 * non-portable [class@Gtk.PrintUnixDialog] API.
 *
 * A `GtkPrinter` allows to get status information about the printer,
40
 * such as its description, its location, the number of queued jobs,
Matthias Clasen's avatar
Matthias Clasen committed
41 42
 * etc. Most importantly, a `GtkPrinter` object can be used to create
 * a [class@Gtk.PrintJob] object, which lets you print to the printer.
43 44 45
 */


46 47 48 49
static void gtk_printer_finalize     (GObject *object);

struct _GtkPrinterPrivate
{
Benjamin Otte's avatar
Benjamin Otte committed
50 51 52 53
  char *name;
  char *location;
  char *description;
  char *icon_name;
54

55 56 57 58 59 60 61 62 63
  guint is_active         : 1;
  guint is_paused         : 1;
  guint is_accepting_jobs : 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;
64

Benjamin Otte's avatar
Benjamin Otte committed
65
  char *state_message;
Benjamin Otte's avatar
Benjamin Otte committed
66
  int job_count;
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

  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,
84 85
  PROP_JOB_COUNT,
  PROP_ACCEPTS_PDF,
86 87 88
  PROP_ACCEPTS_PS,
  PROP_PAUSED,
  PROP_ACCEPTING_JOBS
89 90 91 92 93 94 95 96 97 98 99 100 101
};

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);

102
G_DEFINE_TYPE_WITH_PRIVATE (GtkPrinter, gtk_printer, G_TYPE_OBJECT)
103 104 105 106 107 108 109 110 111 112 113 114

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;

Matthias Clasen's avatar
Matthias Clasen committed
115 116 117 118 119
  /**
   * GtkPrinter:name: (attributes org.gtk.Property.get=gtk_printer_get_name)
   *
   * The name of the printer.
   */
120 121 122 123 124
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_NAME,
                                   g_param_spec_string ("name",
						        P_("Name"),
						        P_("Name of the printer"),
125
						        "",
126
							GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
Matthias Clasen's avatar
Matthias Clasen committed
127 128 129 130 131 132

  /**
   * GtkPrinter:backend: (attributes org.gtk.Property.get=gtk_printer_get_backend)
   *
   * The backend for the printer.
   */
133 134 135 136 137 138 139
  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));
Matthias Clasen's avatar
Matthias Clasen committed
140 141 142 143 144 145

  /**
   * GtkPrinter:is-virtual: (attributes org.gtk.Property.get=gtk_printer_is_virtual)
   *
   * %FALSE if this represents a real hardware device.
   */
146 147 148 149
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_IS_VIRTUAL,
                                   g_param_spec_boolean ("is-virtual",
							 P_("Is Virtual"),
150
							 P_("FALSE if this represents a real hardware printer"),
151 152
							 FALSE,
							 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
Matthias Clasen's avatar
Matthias Clasen committed
153 154 155 156 157 158

  /**
   * GtkPrinter:accepts-pdf: (attributes org.gtk.Property.get=gtk_printer_accepts_pdf)
   *
   * %TRUE if this printer can accept PDF.
   */
159 160 161 162 163
  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"),
164
							 FALSE,
165
							 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
Matthias Clasen's avatar
Matthias Clasen committed
166 167 168 169 170 171

  /**
   * GtkPrinter:accepts-ps: (attributes org.gtk.Property.get=gtk_printer_accepts_ps)
   *
   * %TRUE if this printer can accept PostScript.
   */
172 173 174 175 176 177 178
  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));
Matthias Clasen's avatar
Matthias Clasen committed
179 180 181 182 183 184

  /**
   * GtkPrinter:state-message: (attributes org.gtk.Property.get=gtk_printer_get_state_message)
   *
   * String giving the current status of the printer.
   */
185 186 187 188 189
  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"),
190
						        "",
191
							GTK_PARAM_READABLE));
Matthias Clasen's avatar
Matthias Clasen committed
192 193 194 195 196 197

  /**
   * GtkPrinter:location: (attributes org.gtk.Property.get=gtk_printer_get_location)
   *
   * Information about the location of the printer.
   */
198 199 200 201 202
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_LOCATION,
                                   g_param_spec_string ("location",
						        P_("Location"),
						        P_("The location of the printer"),
203
						        "",
204
							GTK_PARAM_READABLE));
Matthias Clasen's avatar
Matthias Clasen committed
205 206 207 208 209 210

  /**
   * GtkPrinter:icon-name: (attributes org.gtk.Property.get=gtk_printer_get_icon_name)
   *
   * Icon name to use for the printer.
   */
211 212 213 214 215
  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"),
216
						        "printer",
217
							GTK_PARAM_READABLE));
Matthias Clasen's avatar
Matthias Clasen committed
218 219 220 221 222 223

  /**
   * GtkPrinter:job-count: (attributes org.gtk.Property.get=gtk_printer_get_job_count)
   *
   * Number of jobs queued in the printer.
   */
224 225 226 227 228 229 230 231 232 233
  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));

234
  /**
Matthias Clasen's avatar
Matthias Clasen committed
235 236 237
   * GtkPrinter:paused: (attributes org.gtk.Property.get=gtk_printer_is_paused)
   *
   * %TRUE if this printer is paused.
238
   *
Matthias Clasen's avatar
Matthias Clasen committed
239
   * A paused printer still accepts jobs, but it does
240 241 242 243 244 245 246 247 248
   * not print them.
   */
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_PAUSED,
                                   g_param_spec_boolean ("paused",
							 P_("Paused Printer"),
							 P_("TRUE if this printer is paused"),
							 FALSE,
							 GTK_PARAM_READABLE));
Matthias Clasen's avatar
Matthias Clasen committed
249

250
  /**
Matthias Clasen's avatar
Matthias Clasen committed
251
   * GtkPrinter:accepting-jobs: (attributes org.gtk.Property.get=gtk_printer_is_accepting_jobs)
252
   *
Matthias Clasen's avatar
Matthias Clasen committed
253
   * %TRUE if the printer is accepting jobs.
Matthias Clasen's avatar
Matthias Clasen committed
254
   */
255 256 257 258 259 260 261 262
  g_object_class_install_property (G_OBJECT_CLASS (class),
                                   PROP_ACCEPTING_JOBS,
                                   g_param_spec_boolean ("accepting-jobs",
							 P_("Accepting Jobs"),
							 P_("TRUE if this printer is accepting new jobs"),
							 TRUE,
							 GTK_PARAM_READABLE));

263 264
  /**
   * GtkPrinter::details-acquired:
Matthias Clasen's avatar
Matthias Clasen committed
265
   * @printer: the `GtkPrinter` on which the signal is emitted
266 267
   * @success: %TRUE if the details were successfully acquired
   *
Matthias Clasen's avatar
Matthias Clasen committed
268 269 270 271 272
   * 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.
273
   */
274
  signals[DETAILS_ACQUIRED] =
Matthias Clasen's avatar
Matthias Clasen committed
275 276 277 278 279
    g_signal_new (I_("details-acquired"),
		  G_TYPE_FROM_CLASS (class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkPrinterClass, details_acquired),
		  NULL, NULL,
280
		  NULL,
Matthias Clasen's avatar
Matthias Clasen committed
281
		  G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
282 283 284 285 286
}

static void
gtk_printer_init (GtkPrinter *printer)
{
287
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);
288

289 290 291
  priv->name = NULL;
  priv->location = NULL;
  priv->description = NULL;
292
  priv->icon_name = g_strdup ("printer");
293

294
  priv->is_active = TRUE;
295 296
  priv->is_paused = FALSE;
  priv->is_accepting_jobs = TRUE;
297 298
  priv->is_new = TRUE;
  priv->has_details = FALSE;
299
  priv->accepts_pdf = FALSE;
300
  priv->accepts_ps = TRUE;
301 302 303

  priv->state_message = NULL;  
  priv->job_count = 0;
304 305 306 307 308 309
}

static void
gtk_printer_finalize (GObject *object)
{
  GtkPrinter *printer = GTK_PRINTER (object);
310
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);
311

312 313 314 315 316
  g_free (priv->name);
  g_free (priv->location);
  g_free (priv->description);
  g_free (priv->state_message);
  g_free (priv->icon_name);
317

Alexander Larsson's avatar
Alexander Larsson committed
318 319 320
  if (priv->backend)
    g_object_unref (priv->backend);

321
  G_OBJECT_CLASS (gtk_printer_parent_class)->finalize (object);
322 323 324 325 326 327 328 329 330
}

static void
gtk_printer_set_property (GObject         *object,
			  guint            prop_id,
			  const GValue    *value,
			  GParamSpec      *pspec)
{
  GtkPrinter *printer = GTK_PRINTER (object);
331
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);
332

333 334 335
  switch (prop_id)
    {
    case PROP_NAME:
336
      priv->name = g_value_dup_string (value);
337 338 339
      break;
    
    case PROP_BACKEND:
Alexander Larsson's avatar
Alexander Larsson committed
340
      priv->backend = GTK_PRINT_BACKEND (g_value_dup_object (value));
341 342 343
      break;

    case PROP_IS_VIRTUAL:
344
      priv->is_virtual = g_value_get_boolean (value);
345 346
      break;

347 348 349 350 351 352 353 354
    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;

355 356 357 358 359 360 361 362 363 364 365 366 367
    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);
368
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);
369 370 371 372

  switch (prop_id)
    {
    case PROP_NAME:
373 374
      if (priv->name)
	g_value_set_string (value, priv->name);
375
      else
376
	g_value_set_static_string (value, "");
377 378
      break;
    case PROP_BACKEND:
379
      g_value_set_object (value, priv->backend);
380 381
      break;
    case PROP_STATE_MESSAGE:
382 383
      if (priv->state_message)
	g_value_set_string (value, priv->state_message);
384
      else
385
	g_value_set_static_string (value, "");
386 387
      break;
    case PROP_LOCATION:
388 389
      if (priv->location)
	g_value_set_string (value, priv->location);
390
      else
391
	g_value_set_static_string (value, "");
392 393
      break;
    case PROP_ICON_NAME:
394 395
      if (priv->icon_name)
	g_value_set_string (value, priv->icon_name);
396
      else
397
	g_value_set_static_string (value, "printer");
398 399
      break;
    case PROP_JOB_COUNT:
400
      g_value_set_int (value, priv->job_count);
401
      break;
402 403 404 405 406 407 408 409 410
    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;
411 412 413 414 415 416
    case PROP_PAUSED:
      g_value_set_boolean (value, priv->is_paused);
      break;
    case PROP_ACCEPTING_JOBS:
      g_value_set_boolean (value, priv->is_accepting_jobs);
      break;
417 418 419 420 421 422 423 424
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

/**
 * gtk_printer_new:
425
 * @name: the name of the printer
Matthias Clasen's avatar
Matthias Clasen committed
426
 * @backend: a `GtkPrintBackend`
Matthias Clasen's avatar
Matthias Clasen committed
427
 * @virtual_: whether the printer is virtual
428
 *
Matthias Clasen's avatar
Matthias Clasen committed
429
 * Creates a new `GtkPrinter`.
430
 *
Matthias Clasen's avatar
Matthias Clasen committed
431 432
 * Returns: a new `GtkPrinter`
 */
433
GtkPrinter *
Benjamin Otte's avatar
Benjamin Otte committed
434
gtk_printer_new (const char      *name,
435
		 GtkPrintBackend *backend,
Matthias Clasen's avatar
Matthias Clasen committed
436
		 gboolean         virtual_)
437 438 439 440 441 442
{
  GObject *result;
  
  result = g_object_new (GTK_TYPE_PRINTER,
			 "name", name,
			 "backend", backend,
Matthias Clasen's avatar
Matthias Clasen committed
443
			 "is-virtual", virtual_,
444 445 446 447 448
                         NULL);

  return (GtkPrinter *) result;
}

449
/**
Matthias Clasen's avatar
Matthias Clasen committed
450 451 452
 * gtk_printer_get_backend: (attributes org.gtk.Method.get_property=backend)
 * @printer: a `GtkPrinter`
 *
453
 * Returns the backend of the printer.
Matthias Clasen's avatar
Matthias Clasen committed
454
 *
455
 * Returns: (transfer none): the backend of @printer
456
 */
457 458 459
GtkPrintBackend *
gtk_printer_get_backend (GtkPrinter *printer)
{
460 461
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

462 463
  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);
  
464
  return priv->backend;
465 466
}

467
/**
Matthias Clasen's avatar
Matthias Clasen committed
468 469 470
 * gtk_printer_get_name: (attributes org.gtk.Method.get_property=name)
 * @printer: a `GtkPrinter`
 *
471
 * Returns the name of the printer.
Matthias Clasen's avatar
Matthias Clasen committed
472
 *
473
 * Returns: the name of @printer
474
 */
Benjamin Otte's avatar
Benjamin Otte committed
475
const char *
476 477
gtk_printer_get_name (GtkPrinter *printer)
{
478 479
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

480 481
  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);

482
  return priv->name;
483 484
}

485 486
/**
 * gtk_printer_get_description:
Matthias Clasen's avatar
Matthias Clasen committed
487
 * @printer: a `GtkPrinter`
Matthias Clasen's avatar
Matthias Clasen committed
488
 *
489
 * Gets the description of the printer.
Matthias Clasen's avatar
Matthias Clasen committed
490
 *
491
 * Returns: the description of @printer
492
 */
Benjamin Otte's avatar
Benjamin Otte committed
493
const char *
494 495
gtk_printer_get_description (GtkPrinter *printer)
{
496 497
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

498 499
  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);
  
500
  return priv->description;
501 502 503
}

gboolean
504
gtk_printer_set_description (GtkPrinter  *printer,
Benjamin Otte's avatar
Benjamin Otte committed
505
			     const char *description)
506
{
507
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);
508

509 510
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);

511
  if (g_strcmp0 (priv->description, description) == 0)
512 513
    return FALSE;

514 515
  g_free (priv->description);
  priv->description = g_strdup (description);
516 517 518 519
  
  return TRUE;
}

520
/**
Matthias Clasen's avatar
Matthias Clasen committed
521 522 523
 * gtk_printer_get_state_message: (attributes org.gtk.Method.get_property=state-message)
 * @printer: a `GtkPrinter`
 *
524 525
 * Returns the state message describing the current state
 * of the printer.
Matthias Clasen's avatar
Matthias Clasen committed
526
 *
527
 * Returns: the state message of @printer
528
 */
Benjamin Otte's avatar
Benjamin Otte committed
529
const char *
530 531
gtk_printer_get_state_message (GtkPrinter *printer)
{
532 533
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

534 535
  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);

536
  return priv->state_message;
537 538 539
}

gboolean
540
gtk_printer_set_state_message (GtkPrinter  *printer,
Benjamin Otte's avatar
Benjamin Otte committed
541
			       const char *message)
542
{
543
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);
544

545 546
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);

547
  if (g_strcmp0 (priv->state_message, message) == 0)
548 549
    return FALSE;

550 551
  g_free (priv->state_message);
  priv->state_message = g_strdup (message);
552 553 554 555 556
  g_object_notify (G_OBJECT (printer), "state-message");

  return TRUE;
}

557
/**
Matthias Clasen's avatar
Matthias Clasen committed
558 559 560
 * gtk_printer_get_location: (attributes org.gtk.Method.get_property=location)
 * @printer: a `GtkPrinter`
 *
Matthias Clasen's avatar
Matthias Clasen committed
561
 * Returns a description of the location of the printer.
Matthias Clasen's avatar
Matthias Clasen committed
562
 *
563
 * Returns: the location of @printer
564
 */
Benjamin Otte's avatar
Benjamin Otte committed
565
const char *
566 567
gtk_printer_get_location (GtkPrinter *printer)
{
568 569
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

570 571
  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);

572
  return priv->location;
573 574 575
}

gboolean
576
gtk_printer_set_location (GtkPrinter  *printer,
Benjamin Otte's avatar
Benjamin Otte committed
577
			  const char *location)
578
{
579
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);
580

581 582
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);

583
  if (g_strcmp0 (priv->location, location) == 0)
584 585
    return FALSE;

586 587
  g_free (priv->location);
  priv->location = g_strdup (location);
588 589 590 591 592
  g_object_notify (G_OBJECT (printer), "location");
  
  return TRUE;
}

593
/**
Matthias Clasen's avatar
Matthias Clasen committed
594 595 596
 * gtk_printer_get_icon_name: (attributes org.gtk.Method.get_property=icon-name)
 * @printer: a `GtkPrinter`
 *
597
 * Gets the name of the icon to use for the printer.
Matthias Clasen's avatar
Matthias Clasen committed
598
 *
599
 * Returns: the icon name for @printer
600
 */
Benjamin Otte's avatar
Benjamin Otte committed
601
const char *
602 603
gtk_printer_get_icon_name (GtkPrinter *printer)
{
604 605
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

606 607
  g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);

608
  return priv->icon_name;
609 610 611
}

void
612
gtk_printer_set_icon_name (GtkPrinter  *printer,
Benjamin Otte's avatar
Benjamin Otte committed
613
			   const char *icon)
614
{
615
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);
616

617 618
  g_return_if_fail (GTK_IS_PRINTER (printer));

619 620
  g_free (priv->icon_name);
  priv->icon_name = g_strdup (icon);
621 622 623
  g_object_notify (G_OBJECT (printer), "icon-name");
}

624
/**
Matthias Clasen's avatar
Matthias Clasen committed
625 626 627
 * gtk_printer_get_job_count: (attributes org.gtk.Method.get_property=job-count)
 * @printer: a `GtkPrinter`
 *
628
 * Gets the number of jobs currently queued on the printer.
Matthias Clasen's avatar
Matthias Clasen committed
629
 *
630
 * Returns: the number of jobs on @printer
631
 */
Matthias Clasen's avatar
Matthias Clasen committed
632
int
633 634
gtk_printer_get_job_count (GtkPrinter *printer)
{
635 636
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

637 638
  g_return_val_if_fail (GTK_IS_PRINTER (printer), 0);

639
  return priv->job_count;
640 641 642 643
}

gboolean
gtk_printer_set_job_count (GtkPrinter *printer,
Benjamin Otte's avatar
Benjamin Otte committed
644
			   int         count)
645
{
646
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);
647

648 649
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);

650
  if (priv->job_count == count)
651 652
    return FALSE;

653
  priv->job_count = count;
654 655 656 657 658 659
  
  g_object_notify (G_OBJECT (printer), "job-count");
  
  return TRUE;
}

660 661
/**
 * gtk_printer_has_details:
Matthias Clasen's avatar
Matthias Clasen committed
662 663
 * @printer: a `GtkPrinter`
 *
664
 * Returns whether the printer details are available.
Matthias Clasen's avatar
Matthias Clasen committed
665
 *
666
 * Returns: %TRUE if @printer details are available
667
 */
668
gboolean
669
gtk_printer_has_details (GtkPrinter *printer)
670
{
671 672
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

673 674
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);

675
  return priv->has_details;
676 677 678 679
}

void
gtk_printer_set_has_details (GtkPrinter *printer,
680
			     gboolean    val)
681
{
682 683 684
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

  priv->has_details = val;
685 686
}

687 688
/**
 * gtk_printer_is_active:
Matthias Clasen's avatar
Matthias Clasen committed
689 690 691
 * @printer: a `GtkPrinter`
 *
 * Returns whether the printer is currently active (i.e.
692
 * accepts new jobs).
Matthias Clasen's avatar
Matthias Clasen committed
693
 *
694
 * Returns: %TRUE if @printer is active
695
 */
696 697 698
gboolean
gtk_printer_is_active (GtkPrinter *printer)
{
699 700
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

701 702
  g_return_val_if_fail (GTK_IS_PRINTER (printer), TRUE);
  
703
  return priv->is_active;
704 705 706 707 708 709
}

void
gtk_printer_set_is_active (GtkPrinter *printer,
			   gboolean val)
{
710 711
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

712 713
  g_return_if_fail (GTK_IS_PRINTER (printer));

714
  priv->is_active = val;
715 716
}

717
/**
Matthias Clasen's avatar
Matthias Clasen committed
718 719 720
 * gtk_printer_is_paused: (attributes org.gtk.Method.get_property=paused)
 * @printer: a `GtkPrinter`
 *
721
 * Returns whether the printer is currently paused.
Matthias Clasen's avatar
Matthias Clasen committed
722
 *
723 724
 * A paused printer still accepts jobs, but it is not
 * printing them.
Matthias Clasen's avatar
Matthias Clasen committed
725
 *
726
 * Returns: %TRUE if @printer is paused
727 728 729 730
 */
gboolean
gtk_printer_is_paused (GtkPrinter *printer)
{
731 732
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

733 734
  g_return_val_if_fail (GTK_IS_PRINTER (printer), TRUE);
  
735
  return priv->is_paused;
736 737 738 739 740 741
}

gboolean
gtk_printer_set_is_paused (GtkPrinter *printer,
			   gboolean    val)
{
742
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);
743 744 745 746 747 748 749 750 751 752 753 754

  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);

  if (val == priv->is_paused)
    return FALSE;

  priv->is_paused = val;

  return TRUE;
}

/**
Matthias Clasen's avatar
Matthias Clasen committed
755 756 757
 * gtk_printer_is_accepting_jobs: (attributes org.gtk.Method.get_property=accepting-jobs)
 * @printer: a `GtkPrinter`
 *
758
 * Returns whether the printer is accepting jobs
Matthias Clasen's avatar
Matthias Clasen committed
759
 *
760
 * Returns: %TRUE if @printer is accepting jobs
761 762 763 764
 */
gboolean
gtk_printer_is_accepting_jobs (GtkPrinter *printer)
{
765 766
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

767 768
  g_return_val_if_fail (GTK_IS_PRINTER (printer), TRUE);
  
769
  return priv->is_accepting_jobs;
770 771 772 773 774 775
}

gboolean
gtk_printer_set_is_accepting_jobs (GtkPrinter *printer,
				   gboolean val)
{
776
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);
777 778 779 780 781 782 783 784 785 786

  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);

  if (val == priv->is_accepting_jobs)
    return FALSE;

  priv->is_accepting_jobs = val;

  return TRUE;
}
787

788
/**
Matthias Clasen's avatar
Matthias Clasen committed
789 790 791
 * gtk_printer_is_virtual: (attributes org.gtk.Method.get_property=is-virtual)
 * @printer: a `GtkPrinter`
 *
792
 * Returns whether the printer is virtual (i.e. does not
Matthias Clasen's avatar
Matthias Clasen committed
793
 * represent actual printer hardware, but something like
794
 * a CUPS class).
Matthias Clasen's avatar
Matthias Clasen committed
795
 *
796
 * Returns: %TRUE if @printer is virtual
797
 */
798 799 800
gboolean
gtk_printer_is_virtual (GtkPrinter *printer)
{
801 802
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

803 804
  g_return_val_if_fail (GTK_IS_PRINTER (printer), TRUE);
  
805
  return priv->is_virtual;
806 807
}

808
/**
Matthias Clasen's avatar
Matthias Clasen committed
809 810
 * gtk_printer_accepts_pdf: (attributes org.gtk.Method.get_property=accepts-pdf)
 * @printer: a `GtkPrinter`
811 812
 *
 * Returns whether the printer accepts input in
Matthias Clasen's avatar
Matthias Clasen committed
813
 * PDF format.
814
 *
815
 * Returns: %TRUE if @printer accepts PDF
816
 */
Matthias Clasen's avatar
Matthias Clasen committed
817
gboolean
818 819
gtk_printer_accepts_pdf (GtkPrinter *printer)
{ 
820 821
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

822 823
  g_return_val_if_fail (GTK_IS_PRINTER (printer), TRUE);
  
824
  return priv->accepts_pdf;
825 826
}

827 828 829 830
void
gtk_printer_set_accepts_pdf (GtkPrinter *printer,
			     gboolean val)
{
831 832
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

833 834
  g_return_if_fail (GTK_IS_PRINTER (printer));

835
  priv->accepts_pdf = val;
836 837
}

838
/**
Matthias Clasen's avatar
Matthias Clasen committed
839 840
 * gtk_printer_accepts_ps: (attributes org.gtk.Method.get_property=accepts-ps)
 * @printer: a `GtkPrinter`
841 842
 *
 * Returns whether the printer accepts input in
Matthias Clasen's avatar
Matthias Clasen committed
843
 * PostScript format.
844
 *
845
 * Returns: %TRUE if @printer accepts PostScript
846
 */
Matthias Clasen's avatar
Matthias Clasen committed
847
gboolean
848 849
gtk_printer_accepts_ps (GtkPrinter *printer)
{ 
850 851
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

852 853
  g_return_val_if_fail (GTK_IS_PRINTER (printer), TRUE);
  
854
  return priv->accepts_ps;
855 856
}

857 858 859 860
void
gtk_printer_set_accepts_ps (GtkPrinter *printer,
			    gboolean val)
{
861 862
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

863 864
  g_return_if_fail (GTK_IS_PRINTER (printer));

865
  priv->accepts_ps = val;
866 867
}

868 869 870
gboolean
gtk_printer_is_new (GtkPrinter *printer)
{
871 872
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

873 874
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);
  
875
  return priv->is_new;
876 877 878 879 880 881
}

void
gtk_printer_set_is_new (GtkPrinter *printer,
			gboolean val)
{
882 883
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

884 885
  g_return_if_fail (GTK_IS_PRINTER (printer));

886
  priv->is_new = val;
887 888 889
}


890 891
/**
 * gtk_printer_is_default:
Matthias Clasen's avatar
Matthias Clasen committed
892 893
 * @printer: a `GtkPrinter`
 *
894
 * Returns whether the printer is the default printer.
Matthias Clasen's avatar
Matthias Clasen committed
895
 *
896
 * Returns: %TRUE if @printer is the default
897
 */
898 899 900
gboolean
gtk_printer_is_default (GtkPrinter *printer)
{
901 902
  GtkPrinterPrivate *priv = gtk_printer_get_instance_private (printer);

903 904
  g_return_val_if_fail (GTK_IS_PRINTER (printer), FALSE);
  
905
  return priv->is_default;
906 907 908 909
}

void
gtk_printer_set_is_default (GtkPrinter *printer,
910
			    gboolean    val)