gtkpagesetupunixdialog.c 35 KB
Newer Older
1 2
/* GtkPageSetupUnixDialog 
 * Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
3
 * Copyright © 2006, 2007, 2008 Christian Persch
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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 <string.h>
#include <locale.h>
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include "gtkintl.h"
#include "gtkprivate.h"

#include "gtkliststore.h"
#include "gtkstock.h"
#include "gtktreeviewcolumn.h"
#include "gtktreeselection.h"
#include "gtktreemodel.h"
#include "gtkbutton.h"
#include "gtkscrolledwindow.h"
#include "gtkvbox.h"
#include "gtkhbox.h"
#include "gtkframe.h"
#include "gtkeventbox.h"
#include "gtkcombobox.h"
#include "gtktogglebutton.h"
#include "gtkradiobutton.h"
#include "gtklabel.h"
#include "gtktable.h"
#include "gtkcelllayout.h"
#include "gtkcellrenderertext.h"
#include "gtkalignment.h"
#include "gtkspinbutton.h"
49 50
#include "gtkbbox.h"
#include "gtkhbbox.h"
51 52

#include "gtkpagesetupunixdialog.h"
53
#include "gtkcustompaperunixdialog.h"
54 55
#include "gtkprintbackend.h"
#include "gtkpapersize.h"
Matthias Clasen's avatar
Matthias Clasen committed
56
#include "gtkprintutils.h"
57

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
/**
 * SECTION:gtkpagesetupunixdialog
 * @Short_description: A page setup dialog
 * @Title: GtkPageSetupUnixDialog
 *
 * #GtkPageSetupUnixDialog implements a page setup dialog for platforms
 * which don't provide a native page setup dialog, like Unix. It can
 * be used very much like any other GTK+ dialog, at the cost of
 * the portability offered by the <link
 * linkend="gtk-High-level-Printing-API">high-level printing API</link>
 *
 * Printing support was added in GTK+ 2.10.
 */


73
struct _GtkPageSetupUnixDialogPrivate
74 75 76 77 78 79 80 81 82 83 84 85
{
  GtkListStore *printer_list;
  GtkListStore *page_setup_list;
  GtkListStore *custom_paper_list;
  
  GList *print_backends;

  GtkWidget *printer_combo;
  GtkWidget *paper_size_combo;
  GtkWidget *paper_size_label;

  GtkWidget *portrait_radio;
86
  GtkWidget *reverse_portrait_radio;
87 88 89
  GtkWidget *landscape_radio;
  GtkWidget *reverse_landscape_radio;

90
  gulong request_details_tag;
91
  GtkPrinter *request_details_printer;
92 93 94 95 96 97
  
  GtkPrintSettings *print_settings;

  /* Save last setup so we can re-set it after selecting manage custom sizes */
  GtkPageSetup *last_setup;

Matthias Clasen's avatar
Matthias Clasen committed
98
  gchar *waiting_for_printer;
99 100 101 102 103 104 105 106 107 108 109 110 111 112
};

enum {
  PRINTER_LIST_COL_NAME,
  PRINTER_LIST_COL_PRINTER,
  PRINTER_LIST_N_COLS
};

enum {
  PAGE_SETUP_LIST_COL_PAGE_SETUP,
  PAGE_SETUP_LIST_COL_IS_SEPARATOR,
  PAGE_SETUP_LIST_N_COLS
};

Matthias Clasen's avatar
Matthias Clasen committed
113
G_DEFINE_TYPE (GtkPageSetupUnixDialog, gtk_page_setup_unix_dialog, GTK_TYPE_DIALOG)
114 115 116 117 118

static void gtk_page_setup_unix_dialog_finalize  (GObject                *object);
static void populate_dialog                      (GtkPageSetupUnixDialog *dialog);
static void fill_paper_sizes_from_printer        (GtkPageSetupUnixDialog *dialog,
						  GtkPrinter             *printer);
Alexander Larsson's avatar
Alexander Larsson committed
119 120 121 122 123 124 125 126 127 128 129
static void printer_added_cb                     (GtkPrintBackend        *backend,
						  GtkPrinter             *printer,
						  GtkPageSetupUnixDialog *dialog);
static void printer_removed_cb                   (GtkPrintBackend        *backend,
						  GtkPrinter             *printer,
						  GtkPageSetupUnixDialog *dialog);
static void printer_status_cb                    (GtkPrintBackend        *backend,
						  GtkPrinter             *printer,
						  GtkPageSetupUnixDialog *dialog);


130

131
static const gchar const common_paper_sizes[][16] = {
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
  "na_letter",
  "na_legal",
  "iso_a4",
  "iso_a5",
  "roc_16k",
  "iso_b5",
  "jis_b5",
  "na_number-10",
  "iso_dl",
  "jpn_chou3",
  "na_ledger",
  "iso_a3",
};


static void
gtk_page_setup_unix_dialog_class_init (GtkPageSetupUnixDialogClass *class)
{
  GObjectClass *object_class;
  GtkWidgetClass *widget_class;

  object_class = (GObjectClass *) class;
  widget_class = (GtkWidgetClass *) class;

  object_class->finalize = gtk_page_setup_unix_dialog_finalize;

158
  g_type_class_add_private (class, sizeof (GtkPageSetupUnixDialogPrivate));
159 160 161 162 163
}

static void
gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog)
{
164
  GtkPageSetupUnixDialogPrivate *priv;
165
  GtkTreeIter iter;
166
  gchar *tmp;
167

168 169 170
  priv = dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
                                                     GTK_TYPE_PAGE_SETUP_UNIX_DIALOG,
                                                     GtkPageSetupUnixDialogPrivate);
171 172

  priv->print_backends = NULL;
173

174
  priv->printer_list = gtk_list_store_new (PRINTER_LIST_N_COLS,
175
						   G_TYPE_STRING,
176 177
						   G_TYPE_OBJECT);

178
  gtk_list_store_append (priv->printer_list, &iter);
179
  tmp = g_strdup_printf ("<b>%s</b>\n%s", _("Any Printer"), _("For portable documents"));
180
  gtk_list_store_set (priv->printer_list, &iter,
181
                      PRINTER_LIST_COL_NAME, tmp,
182 183
                      PRINTER_LIST_COL_PRINTER, NULL,
                      -1);
184 185
  g_free (tmp);

186
  priv->page_setup_list = gtk_list_store_new (PAGE_SETUP_LIST_N_COLS,
187 188 189
						      G_TYPE_OBJECT,
						      G_TYPE_BOOLEAN);

190
  priv->custom_paper_list = gtk_list_store_new (1, G_TYPE_OBJECT);
191
  _gtk_print_load_custom_papers (priv->custom_paper_list);
192 193 194 195 196 197 198

  populate_dialog (dialog);
  
  gtk_dialog_add_buttons (GTK_DIALOG (dialog), 
                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                          GTK_STOCK_APPLY, GTK_RESPONSE_OK,
                          NULL);
199 200 201 202
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
					   GTK_RESPONSE_OK,
					   GTK_RESPONSE_CANCEL,
					   -1);
203 204 205 206 207 208 209 210

  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
}

static void
gtk_page_setup_unix_dialog_finalize (GObject *object)
{
  GtkPageSetupUnixDialog *dialog = GTK_PAGE_SETUP_UNIX_DIALOG (object);
211
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
Alexander Larsson's avatar
Alexander Larsson committed
212 213 214
  GtkPrintBackend *backend;
  GList *node;
  
215
  if (priv->request_details_tag)
216
    {
217 218 219 220
      g_signal_handler_disconnect (priv->request_details_printer,
				   priv->request_details_tag);
      g_object_unref (priv->request_details_printer);
      priv->request_details_printer = NULL;
221
      priv->request_details_tag = 0;
222 223
    }
  
224
  if (priv->printer_list)
225
    {
226 227
      g_object_unref (priv->printer_list);
      priv->printer_list = NULL;
228 229
    }

230
  if (priv->page_setup_list)
231
    {
232 233
      g_object_unref (priv->page_setup_list);
      priv->page_setup_list = NULL;
234 235
    }

236 237 238 239 240 241
  if (priv->custom_paper_list)
    {
      g_object_unref (priv->custom_paper_list);
      priv->custom_paper_list = NULL;
    }

242
  if (priv->print_settings)
243
    {
244 245
      g_object_unref (priv->print_settings);
      priv->print_settings = NULL;
246 247
    }

248 249 250
  g_free (priv->waiting_for_printer);
  priv->waiting_for_printer = NULL;

Alexander Larsson's avatar
Alexander Larsson committed
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
  for (node = priv->print_backends; node != NULL; node = node->next)
    {
      backend = GTK_PRINT_BACKEND (node->data);

      g_signal_handlers_disconnect_by_func (backend, printer_added_cb, dialog);
      g_signal_handlers_disconnect_by_func (backend, printer_removed_cb, dialog);
      g_signal_handlers_disconnect_by_func (backend, printer_status_cb, dialog);

      gtk_print_backend_destroy (backend);
      g_object_unref (backend);
    }
  
  g_list_free (priv->print_backends);
  priv->print_backends = NULL;

266
  G_OBJECT_CLASS (gtk_page_setup_unix_dialog_parent_class)->finalize (object);
267 268 269
}

static void
Matthias Clasen's avatar
Matthias Clasen committed
270 271
printer_added_cb (GtkPrintBackend        *backend, 
		  GtkPrinter             *printer, 
272 273
		  GtkPageSetupUnixDialog *dialog)
{
274
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
275
  GtkTreeIter iter;
Matthias Clasen's avatar
Matthias Clasen committed
276
  gchar *str;
277
  const gchar *location;
278 279 280 281 282 283 284 285 286 287

  if (gtk_printer_is_virtual (printer))
    return;

  location = gtk_printer_get_location (printer);
  if (location == NULL)
    location = "";
  str = g_strdup_printf ("<b>%s</b>\n%s",
			 gtk_printer_get_name (printer),
			 location);
288

289 290
  gtk_list_store_append (priv->printer_list, &iter);
  gtk_list_store_set (priv->printer_list, &iter,
291 292 293 294
                      PRINTER_LIST_COL_NAME, str,
                      PRINTER_LIST_COL_PRINTER, printer,
                      -1);

295 296
  g_object_set_data_full (G_OBJECT (printer),
			  "gtk-print-tree-iter",
297 298 299 300
                          gtk_tree_iter_copy (&iter),
                          (GDestroyNotify) gtk_tree_iter_free);
  g_free (str);

301 302
  if (priv->waiting_for_printer != NULL &&
      strcmp (priv->waiting_for_printer,
303 304
	      gtk_printer_get_name (printer)) == 0)
    {
305
      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->printer_combo),
306
				     &iter);
307
      priv->waiting_for_printer = NULL;
308 309 310 311
    }
}

static void
Matthias Clasen's avatar
Matthias Clasen committed
312 313
printer_removed_cb (GtkPrintBackend        *backend, 
		    GtkPrinter             *printer, 
314 315
		    GtkPageSetupUnixDialog *dialog)
{
316
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
317
  GtkTreeIter *iter;
318

319
  iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");
320
  gtk_list_store_remove (GTK_LIST_STORE (priv->printer_list), iter);
321 322 323 324
}


static void
Matthias Clasen's avatar
Matthias Clasen committed
325 326
printer_status_cb (GtkPrintBackend        *backend, 
                   GtkPrinter             *printer, 
327 328
		   GtkPageSetupUnixDialog *dialog)
{
329
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
330
  GtkTreeIter *iter;
Matthias Clasen's avatar
Matthias Clasen committed
331
  gchar *str;
332
  const gchar *location;
333 334 335 336 337 338 339 340 341
  
  iter = g_object_get_data (G_OBJECT (printer), "gtk-print-tree-iter");

  location = gtk_printer_get_location (printer);
  if (location == NULL)
    location = "";
  str = g_strdup_printf ("<b>%s</b>\n%s",
			 gtk_printer_get_name (printer),
			 location);
342
  gtk_list_store_set (priv->printer_list, iter,
343 344
                      PRINTER_LIST_COL_NAME, str,
                      -1);
345
  g_free (str);
346 347 348 349
}

static void
printer_list_initialize (GtkPageSetupUnixDialog *dialog,
Matthias Clasen's avatar
Matthias Clasen committed
350
			 GtkPrintBackend        *print_backend)
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
{
  GList *list, *node;
  
  g_return_if_fail (print_backend != NULL);

  g_signal_connect_object (print_backend, 
			   "printer-added", 
			   (GCallback) printer_added_cb, 
			   G_OBJECT (dialog), 0);

  g_signal_connect_object (print_backend, 
			   "printer-removed", 
			   (GCallback) printer_removed_cb, 
			   G_OBJECT (dialog), 0);

  g_signal_connect_object (print_backend, 
			   "printer-status-changed", 
			   (GCallback) printer_status_cb, 
			   G_OBJECT (dialog), 0);

  list = gtk_print_backend_get_printer_list (print_backend);

  node = list;
  while (node != NULL)
    {
      printer_added_cb (print_backend, node->data, dialog);
      node = node->next;
    }

  g_list_free (list);
  
}

static void
load_print_backends (GtkPageSetupUnixDialog *dialog)
{
387
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
388 389 390
  GList *node;

  if (g_module_supported ())
391
    priv->print_backends = gtk_print_backend_load_modules ();
392

393
  for (node = priv->print_backends; node != NULL; node = node->next)
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
    printer_list_initialize (dialog, GTK_PRINT_BACKEND (node->data));
}

static gboolean
paper_size_row_is_separator (GtkTreeModel *model,
			     GtkTreeIter  *iter,
			     gpointer      data)
{
  gboolean separator;

  gtk_tree_model_get (model, iter, PAGE_SETUP_LIST_COL_IS_SEPARATOR, &separator, -1);
  return separator;
}

static GtkPageSetup *
get_current_page_setup (GtkPageSetupUnixDialog *dialog)
{
411
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
412 413 414 415 416 417
  GtkPageSetup *current_page_setup;
  GtkComboBox *combo_box;
  GtkTreeIter iter;

  current_page_setup = NULL;
  
418
  combo_box = GTK_COMBO_BOX (priv->paper_size_combo);
419
  if (gtk_combo_box_get_active_iter (combo_box, &iter))
420
    gtk_tree_model_get (GTK_TREE_MODEL (priv->page_setup_list), &iter,
421 422 423 424 425 426 427 428 429 430 431 432 433
			PAGE_SETUP_LIST_COL_PAGE_SETUP, &current_page_setup, -1);

  if (current_page_setup)
    return current_page_setup;

  /* No selected page size, return the default one.
   * This is used to set the first page setup when the dialog is created
   * as there is no selection on the first printer_changed.
   */ 
  return gtk_page_setup_new ();
}

static gboolean
Matthias Clasen's avatar
Matthias Clasen committed
434 435
page_setup_is_equal (GtkPageSetup *a, 
		     GtkPageSetup *b)
436 437 438 439 440 441 442 443 444 445 446
{
  return
    gtk_paper_size_is_equal (gtk_page_setup_get_paper_size (a),
			     gtk_page_setup_get_paper_size (b)) &&
    gtk_page_setup_get_top_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_top_margin (b, GTK_UNIT_MM) &&
    gtk_page_setup_get_bottom_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_bottom_margin (b, GTK_UNIT_MM) &&
    gtk_page_setup_get_left_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_left_margin (b, GTK_UNIT_MM) &&
    gtk_page_setup_get_right_margin (a, GTK_UNIT_MM) == gtk_page_setup_get_right_margin (b, GTK_UNIT_MM);
}

static gboolean
Matthias Clasen's avatar
Matthias Clasen committed
447 448
page_setup_is_same_size (GtkPageSetup *a,
			 GtkPageSetup *b)
449 450 451 452 453 454 455
{
  return gtk_paper_size_is_equal (gtk_page_setup_get_paper_size (a),
				  gtk_page_setup_get_paper_size (b));
}

static gboolean
set_paper_size (GtkPageSetupUnixDialog *dialog,
Matthias Clasen's avatar
Matthias Clasen committed
456 457 458
		GtkPageSetup           *page_setup,
		gboolean                size_only,
		gboolean                add_item)
459
{
460
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
461 462 463 464
  GtkTreeModel *model;
  GtkTreeIter iter;
  GtkPageSetup *list_page_setup;

465
  model = GTK_TREE_MODEL (priv->page_setup_list);
466 467 468 469 470

  if (gtk_tree_model_get_iter_first (model, &iter))
    {
      do
	{
471
	  gtk_tree_model_get (GTK_TREE_MODEL (priv->page_setup_list), &iter,
472 473 474 475 476 477 478
			      PAGE_SETUP_LIST_COL_PAGE_SETUP, &list_page_setup, -1);
	  if (list_page_setup == NULL)
	    continue;
	  
	  if ((size_only && page_setup_is_same_size (page_setup, list_page_setup)) ||
	      (!size_only && page_setup_is_equal (page_setup, list_page_setup)))
	    {
479
	      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->paper_size_combo),
480 481 482 483 484 485 486 487 488 489 490 491
					     &iter);
	      g_object_unref (list_page_setup);
	      return TRUE;
	    }
	      
	  g_object_unref (list_page_setup);
	  
	} while (gtk_tree_model_iter_next (model, &iter));
    }

  if (add_item)
    {
492 493
      gtk_list_store_append (priv->page_setup_list, &iter);
      gtk_list_store_set (priv->page_setup_list, &iter,
494 495
			  PAGE_SETUP_LIST_COL_IS_SEPARATOR, TRUE,
			  -1);
496 497
      gtk_list_store_append (priv->page_setup_list, &iter);
      gtk_list_store_set (priv->page_setup_list, &iter,
498 499
			  PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
			  -1);
500
      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->paper_size_combo),
501 502 503 504 505 506 507 508 509 510
				     &iter);
      return TRUE;
    }

  return FALSE;
}

static void
fill_custom_paper_sizes (GtkPageSetupUnixDialog *dialog)
{
511
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
512 513 514
  GtkTreeIter iter, paper_iter;
  GtkTreeModel *model;

515
  model = GTK_TREE_MODEL (priv->custom_paper_list);
516 517
  if (gtk_tree_model_get_iter_first (model, &iter))
    {
518 519
      gtk_list_store_append (priv->page_setup_list, &paper_iter);
      gtk_list_store_set (priv->page_setup_list, &paper_iter,
520 521 522 523 524 525 526
			  PAGE_SETUP_LIST_COL_IS_SEPARATOR, TRUE,
			  -1);
      do
	{
	  GtkPageSetup *page_setup;
	  gtk_tree_model_get (model, &iter, 0, &page_setup, -1);

527 528
	  gtk_list_store_append (priv->page_setup_list, &paper_iter);
	  gtk_list_store_set (priv->page_setup_list, &paper_iter,
529 530 531 532 533 534 535
			      PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
			      -1);

	  g_object_unref (page_setup);
	} while (gtk_tree_model_iter_next (model, &iter));
    }
  
536 537
  gtk_list_store_append (priv->page_setup_list, &paper_iter);
  gtk_list_store_set (priv->page_setup_list, &paper_iter,
538 539
                      PAGE_SETUP_LIST_COL_IS_SEPARATOR, TRUE,
                      -1);
540 541
  gtk_list_store_append (priv->page_setup_list, &paper_iter);
  gtk_list_store_set (priv->page_setup_list, &paper_iter,
542 543 544 545 546 547
                      PAGE_SETUP_LIST_COL_PAGE_SETUP, NULL,
                      -1);
}

static void
fill_paper_sizes_from_printer (GtkPageSetupUnixDialog *dialog,
Matthias Clasen's avatar
Matthias Clasen committed
548
			       GtkPrinter             *printer)
549
{
550
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
551 552 553 554
  GList *list, *l;
  GtkPageSetup *current_page_setup, *page_setup;
  GtkPaperSize *paper_size;
  GtkTreeIter iter;
Matthias Clasen's avatar
Matthias Clasen committed
555
  gint i;
556

557
  gtk_list_store_clear (priv->page_setup_list);
558 559 560 561 562 563 564 565 566 567

  if (printer == NULL)
    {
      for (i = 0; i < G_N_ELEMENTS (common_paper_sizes); i++)
	{
	  page_setup = gtk_page_setup_new ();
	  paper_size = gtk_paper_size_new (common_paper_sizes[i]);
	  gtk_page_setup_set_paper_size_and_default_margins (page_setup, paper_size);
	  gtk_paper_size_free (paper_size);
	  
568 569
	  gtk_list_store_append (priv->page_setup_list, &iter);
	  gtk_list_store_set (priv->page_setup_list, &iter,
570 571 572 573 574 575 576
			      PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
			      -1);
	  g_object_unref (page_setup);
	}
    }
  else
    {
577
      list = gtk_printer_list_papers (printer);
578 579 580 581 582
      /* TODO: We should really sort this list so interesting size
	 are at the top */
      for (l = list; l != NULL; l = l->next)
	{
	  page_setup = l->data;
583 584
	  gtk_list_store_append (priv->page_setup_list, &iter);
	  gtk_list_store_set (priv->page_setup_list, &iter,
585 586 587 588 589 590 591 592 593
			      PAGE_SETUP_LIST_COL_PAGE_SETUP, page_setup,
			      -1);
	  g_object_unref (page_setup);
	}
      g_list_free (list);
    }

  fill_custom_paper_sizes (dialog);
  
594 595 596 597 598 599 600 601 602
  current_page_setup = NULL;

  /* When selecting a different printer, select its default paper size */
  if (printer != NULL)
    current_page_setup = gtk_printer_get_default_page_size (printer);

  if (current_page_setup == NULL)
    current_page_setup = get_current_page_setup (dialog);

603 604 605 606 607 608 609 610
  if (!set_paper_size (dialog, current_page_setup, FALSE, FALSE))
    set_paper_size (dialog, current_page_setup, TRUE, TRUE);
  
  if (current_page_setup)
    g_object_unref (current_page_setup);
}

static void
Matthias Clasen's avatar
Matthias Clasen committed
611 612
printer_changed_finished_callback (GtkPrinter             *printer,
				   gboolean                success,
613 614
				   GtkPageSetupUnixDialog *dialog)
{
615 616
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;

617 618 619
  g_signal_handler_disconnect (priv->request_details_printer,
			       priv->request_details_tag);
  g_object_unref (priv->request_details_printer);
620
  priv->request_details_tag = 0;
621
  priv->request_details_printer = NULL;
622 623 624 625 626 627 628
  
  if (success)
    fill_paper_sizes_from_printer (dialog, printer);

}

static void
Matthias Clasen's avatar
Matthias Clasen committed
629
printer_changed_callback (GtkComboBox            *combo_box,
630 631
			  GtkPageSetupUnixDialog *dialog)
{
632
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
633 634 635 636
  GtkPrinter *printer;
  GtkTreeIter iter;

  /* If we're waiting for a specific printer but the user changed
Matthias Clasen's avatar
Matthias Clasen committed
637 638
   * to another printer, cancel that wait. 
   */
639
  if (priv->waiting_for_printer)
640
    {
641 642
      g_free (priv->waiting_for_printer);
      priv->waiting_for_printer = NULL;
643 644
    }
  
645
  if (priv->request_details_tag)
646
    {
647 648 649 650
      g_signal_handler_disconnect (priv->request_details_printer,
				   priv->request_details_tag);
      g_object_unref (priv->request_details_printer);
      priv->request_details_printer = NULL;
651
      priv->request_details_tag = 0;
652 653 654 655 656 657 658
    }
  
  if (gtk_combo_box_get_active_iter (combo_box, &iter))
    {
      gtk_tree_model_get (gtk_combo_box_get_model (combo_box), &iter,
			  PRINTER_LIST_COL_PRINTER, &printer, -1);

659
      if (printer == NULL || gtk_printer_has_details (printer))
660 661 662
	fill_paper_sizes_from_printer (dialog, printer);
      else
	{
663
	  priv->request_details_printer = g_object_ref (printer);
664
	  priv->request_details_tag =
665 666
	    g_signal_connect (printer, "details-acquired",
			      G_CALLBACK (printer_changed_finished_callback), dialog);
667
	  gtk_printer_request_details (printer);
668 669 670 671 672 673

	}

      if (printer)
	g_object_unref (printer);

674
      if (priv->print_settings)
675 676 677 678 679 680
	{
	  const char *name = NULL;

	  if (printer)
	    name = gtk_printer_get_name (printer);
	  
681
	  gtk_print_settings_set (priv->print_settings,
682 683 684 685 686 687 688 689
				  "format-for-printer", name);
	}
    }
}

/* We do this munging because we don't want to show zero digits
   after the decimal point, and not to many such digits if they
   are nonzero. I wish printf let you specify max precision for %f... */
Matthias Clasen's avatar
Matthias Clasen committed
690 691 692
static gchar *
double_to_string (gdouble d, 
		  GtkUnit unit)
693
{
Matthias Clasen's avatar
Matthias Clasen committed
694
  gchar *val, *p;
695
  struct lconv *locale_data;
Matthias Clasen's avatar
Matthias Clasen committed
696 697
  const gchar *decimal_point;
  gint decimal_point_len;
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

  locale_data = localeconv ();
  decimal_point = locale_data->decimal_point;
  decimal_point_len = strlen (decimal_point);
  
  /* Max two decimal digits for inch, max one for mm */
  if (unit == GTK_UNIT_INCH)
    val = g_strdup_printf ("%.2f", d);
  else
    val = g_strdup_printf ("%.1f", d);

  if (strstr (val, decimal_point))
    {
      p = val + strlen (val) - 1;
      while (*p == '0')
        p--;
      if (p - val + 1 >= decimal_point_len &&
	  strncmp (p - (decimal_point_len - 1), decimal_point, decimal_point_len) == 0)
        p -= decimal_point_len;
      p[1] = '\0';
    }

  return val;
}

723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739

static void
custom_paper_dialog_response_cb (GtkDialog *custom_paper_dialog,
				 gint       response_id,
				 gpointer   user_data)
{
  GtkPageSetupUnixDialog *page_setup_dialog = GTK_PAGE_SETUP_UNIX_DIALOG (user_data);
  GtkPageSetupUnixDialogPrivate *priv = page_setup_dialog->priv;

  _gtk_print_load_custom_papers (priv->custom_paper_list);

  /* Update printer page list */
  printer_changed_callback (GTK_COMBO_BOX (priv->printer_combo), page_setup_dialog);

  gtk_widget_destroy (GTK_WIDGET (custom_paper_dialog));
}

740
static void
Matthias Clasen's avatar
Matthias Clasen committed
741
paper_size_changed (GtkComboBox            *combo_box,
742
		    GtkPageSetupUnixDialog *dialog)
743
{
744
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
745 746 747
  GtkTreeIter iter;
  GtkPageSetup *page_setup, *last_page_setup;
  GtkUnit unit;
Matthias Clasen's avatar
Matthias Clasen committed
748 749
  gchar *str, *w, *h;
  gchar *top, *bottom, *left, *right;
750
  GtkLabel *label;
Matthias Clasen's avatar
Matthias Clasen committed
751
  const gchar *unit_str;
752

753
  label = GTK_LABEL (priv->paper_size_label);
754 755 756 757 758 759 760 761
   
  if (gtk_combo_box_get_active_iter (combo_box, &iter))
    {
      gtk_tree_model_get (gtk_combo_box_get_model (combo_box),
			  &iter, PAGE_SETUP_LIST_COL_PAGE_SETUP, &page_setup, -1);

      if (page_setup == NULL)
	{
762 763
          GtkWidget *custom_paper_dialog;

764 765 766 767
          /* Change from "manage" menu item to last value */
          if (priv->last_setup)
            last_page_setup = g_object_ref (priv->last_setup);
          else
768 769
	    last_page_setup = gtk_page_setup_new (); /* "good" default */
	  set_paper_size (dialog, last_page_setup, FALSE, TRUE);
770 771 772
          g_object_unref (last_page_setup);

          /* And show the custom paper dialog */
773 774 775
          custom_paper_dialog = _gtk_custom_paper_unix_dialog_new (GTK_WINDOW (dialog), NULL);
          g_signal_connect (custom_paper_dialog, "response", G_CALLBACK (custom_paper_dialog_response_cb), dialog);
          gtk_window_present (GTK_WINDOW (custom_paper_dialog));
776 777

          return;
778 779
	}

780 781
      if (priv->last_setup)
	g_object_unref (priv->last_setup);
782

783
      priv->last_setup = g_object_ref (page_setup);
784
      
785
      unit = _gtk_print_get_default_user_units ();
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

      if (unit == GTK_UNIT_MM)
	unit_str = _("mm");
      else
	unit_str = _("inch");
	

      w = double_to_string (gtk_page_setup_get_paper_width (page_setup, unit),
			    unit);
      h = double_to_string (gtk_page_setup_get_paper_height (page_setup, unit),
			    unit);
      str = g_strdup_printf ("%s x %s %s", w, h, unit_str);
      g_free (w);
      g_free (h);
      
      gtk_label_set_text (label, str);
      g_free (str);

      top = double_to_string (gtk_page_setup_get_top_margin (page_setup, unit), unit);
      bottom = double_to_string (gtk_page_setup_get_bottom_margin (page_setup, unit), unit);
      left = double_to_string (gtk_page_setup_get_left_margin (page_setup, unit), unit);
      right = double_to_string (gtk_page_setup_get_right_margin (page_setup, unit), unit);

      str = g_strdup_printf (_("Margins:\n"
			       " Left: %s %s\n"
			       " Right: %s %s\n"
			       " Top: %s %s\n"
			       " Bottom: %s %s"
			       ),
			     left, unit_str,
			     right, unit_str,
			     top, unit_str,
			     bottom, unit_str);
      g_free (top);
      g_free (bottom);
      g_free (left);
      g_free (right);
      
824
      gtk_widget_set_tooltip_text (priv->paper_size_label, str);
825 826 827 828 829 830 831
      g_free (str);
      
      g_object_unref (page_setup);
    }
  else
    {
      gtk_label_set_text (label, "");
832
      gtk_widget_set_tooltip_text (priv->paper_size_label, NULL);
833 834 835
      if (priv->last_setup)
	g_object_unref (priv->last_setup);
      priv->last_setup = NULL;
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
    }
}

static void
page_name_func (GtkCellLayout   *cell_layout,
		GtkCellRenderer *cell,
		GtkTreeModel    *tree_model,
		GtkTreeIter     *iter,
		gpointer         data)
{
  GtkPageSetup *page_setup;
  GtkPaperSize *paper_size;
  
  gtk_tree_model_get (tree_model, iter,
		      PAGE_SETUP_LIST_COL_PAGE_SETUP, &page_setup, -1);
  if (page_setup)
    {
      paper_size = gtk_page_setup_get_paper_size (page_setup);
      g_object_set (cell, "text",  gtk_paper_size_get_display_name (paper_size), NULL);
      g_object_unref (page_setup);
    }
  else
    g_object_set (cell, "text",  _("Manage Custom Sizes..."), NULL);
      
}

862 863 864 865 866 867 868 869 870 871 872
static GtkWidget *
create_radio_button (GSList      *group,
		     const gchar *stock_id)
{
  GtkWidget *radio_button, *image, *label, *hbox;
  GtkStockItem item;

  radio_button = gtk_radio_button_new (group);
  image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_LARGE_TOOLBAR);
  gtk_stock_lookup (stock_id, &item);
  label = gtk_label_new (item.label);
873
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
874 875 876 877 878 879 880 881 882
  gtk_container_add (GTK_CONTAINER (radio_button), hbox);
  gtk_container_add (GTK_CONTAINER (hbox), image);
  gtk_container_add (GTK_CONTAINER (hbox), label);

  gtk_widget_show_all (radio_button);

  return radio_button;
}

883
static void
884
populate_dialog (GtkPageSetupUnixDialog *ps_dialog)
885
{
886 887
  GtkPageSetupUnixDialogPrivate *priv = ps_dialog->priv;
  GtkDialog *dialog = GTK_DIALOG (ps_dialog);
888
  GtkWidget *table, *label, *combo, *radio_button;
889
  GtkWidget *action_area, *content_area;
890 891
  GtkCellRenderer *cell;

892 893
  gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);

894 895 896
  content_area = gtk_dialog_get_content_area (dialog);
  action_area = gtk_dialog_get_action_area (dialog);

897
  gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
898 899 900
  gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
  gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
  gtk_box_set_spacing (GTK_BOX (action_area), 6);
901

902
  table = gtk_table_new (5, 4, FALSE);
903
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
904
  gtk_table_set_col_spacings (GTK_TABLE (table), 12);
905
  gtk_container_set_border_width (GTK_CONTAINER (table), 5);
906
  gtk_box_pack_start (GTK_BOX (content_area), table, TRUE, TRUE, 0);
907 908 909
  gtk_widget_show (table);

  label = gtk_label_new_with_mnemonic (_("_Format for:"));
910
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
911 912 913 914 915
  gtk_table_attach (GTK_TABLE (table), label,
		    0, 1, 0, 1,
		    GTK_FILL, 0, 0, 0);
  gtk_widget_show (label);

916 917
  combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (priv->printer_list));
  priv->printer_combo = combo;
918

919 920 921 922 923 924 925 926 927 928
  cell = gtk_cell_renderer_text_new ();
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
                                  "markup", PRINTER_LIST_COL_NAME,
                                  NULL);

  gtk_table_attach (GTK_TABLE (table), combo,
		    1, 4, 0, 1,
		    GTK_FILL | GTK_EXPAND, 0, 0, 0);
  gtk_widget_show (combo);
929
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
930 931

  label = gtk_label_new_with_mnemonic (_("_Paper size:"));
932
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
933 934 935 936 937
  gtk_table_attach (GTK_TABLE (table), label,
		    0, 1, 1, 2,
		    GTK_FILL, 0, 0, 0);
  gtk_widget_show (label);

938 939
  combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (priv->page_setup_list));
  priv->paper_size_combo = combo;
940 941 942 943 944 945 946 947 948 949 950 951
  gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo), 
					paper_size_row_is_separator, NULL, NULL);
  
  cell = gtk_cell_renderer_text_new ();
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
  gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), cell,
				      page_name_func, NULL, NULL);

  gtk_table_attach (GTK_TABLE (table), combo,
		    1, 4, 1, 2,
		    GTK_FILL | GTK_EXPAND, 0, 0, 0);
  gtk_widget_show (combo);
952
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
953

954
  label = gtk_label_new (NULL);
955
  priv->paper_size_label = label;
956
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
957 958 959
  gtk_table_attach (GTK_TABLE (table), label,
		    1, 4, 2, 3,
		    GTK_FILL, 0, 0, 0);
960 961 962
  gtk_widget_show (label);

  label = gtk_label_new_with_mnemonic (_("_Orientation:"));
963
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
964 965 966 967 968
  gtk_table_attach (GTK_TABLE (table), label,
		    0, 1, 3, 4,
		    GTK_FILL, 0, 0, 0);
  gtk_widget_show (label);

969
  radio_button = create_radio_button (NULL, GTK_STOCK_ORIENTATION_PORTRAIT);
970
  priv->portrait_radio = radio_button;
971 972
  gtk_table_attach (GTK_TABLE (table), radio_button,
		    1, 2, 3, 4,
973
		    GTK_EXPAND|GTK_FILL, 0, 0, 0);
974
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), radio_button);
975

976 977
  radio_button = create_radio_button (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)),
				      GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT);
978
  priv->reverse_portrait_radio = radio_button;
979 980
  gtk_table_attach (GTK_TABLE (table), radio_button,
		    2, 3, 3, 4,
981 982 983 984 985 986 987 988
		    GTK_EXPAND|GTK_FILL, 0, 0, 0);

  radio_button = create_radio_button (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)),
				      GTK_STOCK_ORIENTATION_LANDSCAPE);
  priv->landscape_radio = radio_button;
  gtk_table_attach (GTK_TABLE (table), radio_button,
		    1, 2, 4, 5,
		    GTK_EXPAND|GTK_FILL, 0, 0, 0);
989 990 991 992
  gtk_widget_show (radio_button);

  gtk_table_set_row_spacing (GTK_TABLE (table), 3, 0);
  
993 994
  radio_button = create_radio_button (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)),
				      GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE);
995
  priv->reverse_landscape_radio = radio_button;
996
  gtk_table_attach (GTK_TABLE (table), radio_button,
997 998 999
		    2, 3, 4, 5,
		    GTK_EXPAND|GTK_FILL, 0, 0, 0);

1000

1001 1002
  g_signal_connect (priv->paper_size_combo, "changed", G_CALLBACK (paper_size_changed), ps_dialog);
  g_signal_connect (priv->printer_combo, "changed", G_CALLBACK (printer_changed_callback), ps_dialog);
1003
  gtk_combo_box_set_active (GTK_COMBO_BOX (priv->printer_combo), 0);
1004

1005
  load_print_backends (ps_dialog);
1006 1007
}

Matthias Clasen's avatar
Matthias Clasen committed
1008 1009
/**
 * gtk_page_setup_unix_dialog_new:
1010 1011
 * @title: (allow-none): the title of the dialog, or %NULL
 * @parent: (allow-none): transient parent of the dialog, or %NULL
Matthias Clasen's avatar
Matthias Clasen committed
1012 1013 1014 1015 1016 1017 1018
 *
 * Creates a new page setup dialog.
 *
 * Returns: the new #GtkPageSetupUnixDialog
 *
 * Since: 2.10
 */
1019 1020
GtkWidget *
gtk_page_setup_unix_dialog_new (const gchar *title,
Matthias Clasen's avatar
Matthias Clasen committed
1021
				GtkWindow   *parent)
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
{
  GtkWidget *result;

  if (title == NULL)
    title = _("Page Setup");
  
  result = g_object_new (GTK_TYPE_PAGE_SETUP_UNIX_DIALOG,
                         "title", title,
                         NULL);

  if (parent)
    gtk_window_set_transient_for (GTK_WINDOW (result), parent);

  return result;
}

static GtkPageOrientation
get_orientation (GtkPageSetupUnixDialog *dialog)
{
1041 1042 1043
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;

  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->portrait_radio)))
1044
    return GTK_PAGE_ORIENTATION_PORTRAIT;
1045
  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->landscape_radio)))
1046
    return GTK_PAGE_ORIENTATION_LANDSCAPE;
1047
  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->reverse_landscape_radio)))
1048
    return GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE;
1049
  return GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT;
1050 1051 1052
}

static void
Matthias Clasen's avatar
Matthias Clasen committed
1053 1054
set_orientation (GtkPageSetupUnixDialog *dialog, 
		 GtkPageOrientation      orientation)
1055
{
1056 1057
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;

1058 1059 1060
  switch (orientation)
    {
    case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT:
1061 1062
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->reverse_portrait_radio), TRUE);
      break;
1063
    case GTK_PAGE_ORIENTATION_PORTRAIT:
1064
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->portrait_radio), TRUE);
1065 1066
      break;
    case GTK_PAGE_ORIENTATION_LANDSCAPE:
1067
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->landscape_radio), TRUE);
1068 1069
      break;
    case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE:
1070
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->reverse_landscape_radio), TRUE);
1071 1072 1073 1074
      break;
    }
}

Matthias Clasen's avatar
Matthias Clasen committed
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
/**
 * gtk_page_setup_unix_dialog_set_page_setup:
 * @dialog: a #GtkPageSetupUnixDialog
 * @page_setup: a #GtkPageSetup
 * 
 * Sets the #GtkPageSetup from which the page setup
 * dialog takes its values.
 *
 * Since: 2.10
 **/
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
void
gtk_page_setup_unix_dialog_set_page_setup (GtkPageSetupUnixDialog *dialog,
					   GtkPageSetup           *page_setup)
{
  if (page_setup)
    {
      set_paper_size (dialog, page_setup, FALSE, TRUE);
      set_orientation (dialog, gtk_page_setup_get_orientation (page_setup));
    }
}

Matthias Clasen's avatar
Matthias Clasen committed
1096 1097 1098 1099 1100 1101
/**
 * gtk_page_setup_unix_dialog_get_page_setup:
 * @dialog: a #GtkPageSetupUnixDialog
 * 
 * Gets the currently selected page setup from the dialog. 
 * 
1102
 * Returns: (transfer none): the current page setup 
Matthias Clasen's avatar
Matthias Clasen committed
1103 1104 1105
 *
 * Since: 2.10
 **/
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
GtkPageSetup *
gtk_page_setup_unix_dialog_get_page_setup (GtkPageSetupUnixDialog *dialog)
{
  GtkPageSetup *page_setup;
  
  page_setup = get_current_page_setup (dialog);

  gtk_page_setup_set_orientation (page_setup, get_orientation (dialog));

  return page_setup;
}

static gboolean
set_active_printer (GtkPageSetupUnixDialog *dialog,
Matthias Clasen's avatar
Matthias Clasen committed
1120
		    const gchar            *printer_name)
1121
{
1122
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
1123 1124 1125 1126
  GtkTreeModel *model;
  GtkTreeIter iter;
  GtkPrinter *printer;

1127
  model = GTK_TREE_MODEL (priv->printer_list);
1128 1129 1130 1131 1132

  if (gtk_tree_model_get_iter_first (model, &iter))
    {
      do
	{
1133
	  gtk_tree_model_get (GTK_TREE_MODEL (priv->printer_list), &iter,
1134 1135 1136 1137 1138 1139
			      PRINTER_LIST_COL_PRINTER, &printer, -1);
	  if (printer == NULL)
	    continue;
	  
	  if (strcmp (gtk_printer_get_name (printer), printer_name) == 0)
	    {
1140
	      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->printer_combo),
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
					     &iter);
	      g_object_unref (printer);
	      return TRUE;
	    }
	      
	  g_object_unref (printer);
	  
	} while (gtk_tree_model_iter_next (model, &iter));
    }
  
  return FALSE;
}

Matthias Clasen's avatar
Matthias Clasen committed
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
/**
 * gtk_page_setup_unix_dialog_set_print_settings:
 * @dialog: a #GtkPageSetupUnixDialog
 * @print_settings: a #GtkPrintSettings
 * 
 * Sets the #GtkPrintSettings from which the page setup dialog
 * takes its values.
 * 
 * Since: 2.10
 **/
1164 1165 1166 1167
void
gtk_page_setup_unix_dialog_set_print_settings (GtkPageSetupUnixDialog *dialog,
					       GtkPrintSettings       *print_settings)
{
1168
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;
Matthias Clasen's avatar
Matthias Clasen committed
1169
  const gchar *format_for_printer;
1170

1171 1172
  if (priv->print_settings == print_settings) return;

1173 1174
  if (priv->print_settings)
    g_object_unref (priv->print_settings);
1175

1176
  priv->print_settings = print_settings;
1177 1178 1179 1180 1181 1182 1183

  if (print_settings)
    {
      g_object_ref (print_settings);

      format_for_printer = gtk_print_settings_get (print_settings, "format-for-printer");

Matthias Clasen's avatar
Matthias Clasen committed
1184 1185 1186
      /* Set printer if in list, otherwise set when 
       * that printer is added 
       */
1187 1188
      if (format_for_printer &&
	  !set_active_printer (dialog, format_for_printer))
1189
	priv->waiting_for_printer = g_strdup (format_for_printer); 
1190 1191 1192
    }
}

Matthias Clasen's avatar
Matthias Clasen committed
1193 1194 1195 1196 1197 1198
/**
 * gtk_page_setup_unix_dialog_get_print_settings:
 * @dialog: a #GtkPageSetupUnixDialog
 * 
 * Gets the current print settings from the dialog.
 * 
1199
 * Returns: (transfer none): the current print settings
Matthias Clasen's avatar
Matthias Clasen committed
1200 1201 1202
 *
 * Since: 2.10
 **/
1203 1204 1205
GtkPrintSettings *
gtk_page_setup_unix_dialog_get_print_settings (GtkPageSetupUnixDialog *dialog)
{
1206 1207 1208
  GtkPageSetupUnixDialogPrivate *priv = dialog->priv;

  return priv->print_settings;
1209
}