File: x_print.c

package info (click to toggle)
geda-gaf 1%3A1.6.2-4.3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 38,616 kB
  • sloc: ansic: 80,253; sh: 13,262; lisp: 7,177; makefile: 2,597; perl: 2,401; python: 940; lex: 887; awk: 362; yacc: 289; sed: 27; xml: 23
file content (772 lines) | stat: -rw-r--r-- 22,759 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
/* gEDA - GPL Electronic Design Automation
 * gschem - gEDA Schematic Capture
 * Copyright (C) 1998-2010 Ales Hvezda
 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */
#include <config.h>

#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif

#include "gschem.h"

#ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif

enum
  {
  PROP_FILENAME = 1,
  PROP_COMMAND,
  PROP_PAPERSIZE,
  PROP_ORIENTATION,
  PROP_TYPE,
  PROP_USEFILE
  };

/* Private functions */

static void print_dialog_action_radio_toggled (GtkWidget * w,
                                              PrintDialog * dialog);

static void print_dialog_init (PrintDialog * dialog);
static void print_dialog_init_paper_combobox (PrintDialog * d);
static void print_dialog_init_type_combobox (PrintDialog * d);
static void print_dialog_init_orient_combobox (PrintDialog * d);
static void print_dialog_set_property (GObject * object, guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec);
static void print_dialog_set_property_comboboxes (PrintDialog *dialog,
						  GtkComboBox *cbox,
						  const GValue * value);
static void print_dialog_get_property (GObject * object, guint property_id,
                                      GValue * value, GParamSpec * pspec);
static void print_dialog_get_property_comboboxes (PrintDialog * dialog,
						  GtkComboBox * cbox,
						  GValue * value);
static void print_dialog_class_init (PrintDialogClass * class);



/*!
 *  \brief Callback function to show file chooser dialog
 *
 *  \par Shows file chooser dialog for user to select PostScript file
 *  to print to.
 *  \par Private callback function, should not be called by any code
 *  outside x_print.c
 */
static void
print_dialog_action_choosefile (GtkWidget * w, PrintDialog * dialog)
{
  GtkWidget *filechooser;
  const gchar *filename;
  const gchar *newfilename;
  filechooser = gtk_file_chooser_dialog_new (_("Select PostScript Filename..."),
					     GTK_WINDOW (dialog),
					     GTK_FILE_CHOOSER_ACTION_SAVE,
					     GTK_STOCK_CANCEL,
					     GTK_RESPONSE_CANCEL,
					     GTK_STOCK_OK,
					     GTK_RESPONSE_ACCEPT, NULL);

  /* Set the alternative button order (ok, cancel, help) for other systems */
  gtk_dialog_set_alternative_button_order(GTK_DIALOG(filechooser),
					  GTK_RESPONSE_ACCEPT,
					  GTK_RESPONSE_CANCEL,
					  -1);

  filename = gtk_entry_get_text (GTK_ENTRY (dialog->fnfield));
  gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filechooser), filename);

  gtk_dialog_set_default_response(GTK_DIALOG(filechooser),
				  GTK_RESPONSE_ACCEPT);

  if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT)
    {
      newfilename =
	gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
      gtk_entry_set_text (GTK_ENTRY (dialog->fnfield), newfilename);
    }

  gtk_widget_destroy (filechooser);

}

/*!
 *  \brief Create, initialize and populate a combobox for selecting
 *  what paper size to print to.
 *  \par Private function, should not be
 *  called by any code outside x_print.c
 */
static void
print_dialog_init_paper_combobox (PrintDialog * d)
{
  GtkComboBox *combobox;
  gchar *string;
  gint i;

  combobox = GTK_COMBO_BOX (gtk_combo_box_new_text ());
  gtk_combo_box_set_active (combobox, -1);

  /* Populate combo box with available paper sizes */
  i = 0;
  string = (gchar *) s_papersizes_get (i);
  while (string != NULL)
    {
      gtk_combo_box_insert_text (GTK_COMBO_BOX (combobox), i, string);
      
      i++;
      string = (gchar *) s_papersizes_get (i);
    }

  d->papercbox = combobox;
}

/*!
 *  \brief Create, initialize and populate a combobox for selecting
 *  the type of printout to produce.
 *  \par Private function, should not be called by any code
 *  outside x_print.c  
 */
static void
print_dialog_init_type_combobox (PrintDialog * d)
{
  GtkListStore *model;
  GtkTreeIter iter;
  GtkCellRenderer *renderer;

  GtkWidget *combobox;
  
  model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);

  gtk_list_store_append (model, &iter);
  gtk_list_store_set (model, &iter, 
		      0, _("Extents with margins"),
		      1, EXTENTS,
		      -1);
  
  gtk_list_store_append (model, &iter);
  gtk_list_store_set (model, &iter,
		      0, _("Extents no margins"),
		      1, EXTENTS_NOMARGINS,
		      -1);
  
  gtk_list_store_append (model, &iter);
  gtk_list_store_set (model, &iter,
		      0, _("Current Window"),
		      1, WINDOW,
		      -1);

  combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (model));
  
  renderer = gtk_cell_renderer_text_new ();
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
			      renderer, TRUE);
  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox),
				 renderer, "text", 0);

  d->typecbox = GTK_COMBO_BOX (combobox);
}

/*!
 *  \brief Create, initialize and populate a combobox for selecting
 *  paper orientation.
 *  \par Private function, should not be called by any code
 *  outside x_print.c  
 */
static void
print_dialog_init_orient_combobox (PrintDialog * d)
{
  GtkListStore *model;
  GtkTreeIter iter;
  GtkCellRenderer *renderer;

  GtkWidget *combobox;
  
  model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);

  gtk_list_store_append (model, &iter);
  gtk_list_store_set (model, &iter, 
		      0, _("Landscape"),
		      1, LANDSCAPE,
		      -1);
  
  gtk_list_store_append (model, &iter);
  gtk_list_store_set (model, &iter,
		      0, _("Portrait"),
		      1, PORTRAIT,
		      -1);

  combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (model));
  
  renderer = gtk_cell_renderer_text_new ();
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
			      renderer, TRUE);
  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox),
				 renderer, "text", 0);

  d->orientcbox = GTK_COMBO_BOX (combobox);
}

/*!
 *  \brief Handle the user clicking on radio buttons to select print
 *  destination.
 *
 *  \par Private callback function, should not be called by any code
 *  outside x_print.c
 */
static void
print_dialog_action_radio_toggled (GtkWidget * w, PrintDialog * dialog)
{
  if (w == GTK_WIDGET (dialog->cmdradio))
    {
      gtk_widget_set_sensitive (GTK_WIDGET (dialog->cmdfield),
                               gtk_toggle_button_get_active
                               (GTK_TOGGLE_BUTTON (w)));
    }
  else if (w == GTK_WIDGET (dialog->fileradio))
    {
      gtk_widget_set_sensitive (GTK_WIDGET (dialog->fnfield),
                               gtk_toggle_button_get_active
                               (GTK_TOGGLE_BUTTON (w)));
      gtk_widget_set_sensitive (GTK_WIDGET (dialog->saveasbutton),
                               gtk_toggle_button_get_active
                               (GTK_TOGGLE_BUTTON (w)));
    }
}


/*! \todo Finish function documentation
 *  \brief
 *  \par Function Description
 *
 */
static void
print_dialog_init (PrintDialog * dialog)
{
  GtkWidget *box;
  GtkWidget *frame;
  GtkWidget *settingstable, *desttable;
  GtkWidget *label;
  GtkWidget *print_button;

  /* Initialize properties */
  g_object_set (G_OBJECT (dialog),
		/* GtkWindow */
		"title", _("Print..."),
		"modal", TRUE, "destroy-with-parent", TRUE, NULL);

  /* Setup hbox for two main panes */
  box = gtk_vbox_new (FALSE, 2);
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), box);

  /* Upper frame */
  frame = gtk_frame_new (_("Settings"));
  gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
  gtk_container_add (GTK_CONTAINER (box), frame);

  /* Upper table with drop-down menus & labels 
   * Left-hand column contains labels, right-hand contains comboboxes*/
  settingstable = gtk_table_new (2, 3, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (settingstable), 5);
  gtk_table_set_row_spacings (GTK_TABLE (settingstable), 5);
  gtk_container_set_border_width (GTK_CONTAINER (settingstable), 5);
  gtk_container_add (GTK_CONTAINER (frame), settingstable);

  label = gtk_label_new (_("Output paper size:"));
  gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
  gtk_table_attach (GTK_TABLE (settingstable),
		    label,
		    0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);

  print_dialog_init_paper_combobox (dialog);
  gtk_table_attach (GTK_TABLE (settingstable),
		    GTK_WIDGET (dialog->papercbox),
		    1, 2, 0, 1, GTK_FILL, 0, 0, 0);

  label = gtk_label_new (_("Type:"));
  gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
  gtk_table_attach (GTK_TABLE (settingstable),
		    label,
		    0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);

  print_dialog_init_type_combobox (dialog);
  gtk_table_attach (GTK_TABLE (settingstable),
		    GTK_WIDGET (dialog->typecbox),
		    1, 2, 1, 2, GTK_FILL, 0, 0, 0);

  label = gtk_label_new (_("Orientation:"));
  gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
  gtk_table_attach (GTK_TABLE (settingstable),
		    label,
		    0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND, 0, 0);

  print_dialog_init_orient_combobox (dialog);
  gtk_table_attach (GTK_TABLE (settingstable),
		    GTK_WIDGET (dialog->orientcbox),
		    1, 2, 2, 3, GTK_FILL, 0, 0, 0);

  /* Lower frame */
  frame = gtk_frame_new (_("Destination"));
  gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
  gtk_container_add (GTK_CONTAINER (box), frame);

  /* Table with destination selectors */
  desttable = gtk_table_new (3, 2, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (desttable), 5);
  gtk_table_set_row_spacings (GTK_TABLE (desttable), 5);
  gtk_container_set_border_width (GTK_CONTAINER (desttable), 5);
  gtk_container_add (GTK_CONTAINER (frame), desttable);

  /* Widgets for printing to file */
  dialog->fileradio =
    GTK_RADIO_BUTTON (gtk_radio_button_new_with_label (NULL, _("File:")));
  gtk_table_attach (GTK_TABLE (desttable),
		    GTK_WIDGET (dialog->fileradio),
		    0, 1, 0, 1, GTK_FILL, GTK_EXPAND, 0, 0);
  g_signal_connect (dialog->fileradio,
		    "toggled",
		    GTK_SIGNAL_FUNC (print_dialog_action_radio_toggled),
		    dialog);

  dialog->fnfield = GTK_ENTRY (gtk_entry_new ());
  gtk_table_attach (GTK_TABLE (desttable),
		    GTK_WIDGET (dialog->fnfield),
		    1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);

  dialog->saveasbutton = GTK_BUTTON(gtk_button_new());
  gtk_container_add(GTK_CONTAINER(dialog->saveasbutton),
		    gtk_image_new_from_stock(GTK_STOCK_OPEN,
					     GTK_ICON_SIZE_SMALL_TOOLBAR));
  gtk_button_set_relief(GTK_BUTTON(dialog->saveasbutton), GTK_RELIEF_NONE);

  gtk_table_attach (GTK_TABLE (desttable),
		    GTK_WIDGET (dialog->saveasbutton), 2, 3, 0, 1,
		    GTK_FILL, 0, 0, 0);
  g_signal_connect (dialog->saveasbutton,
		    "clicked",
		    GTK_SIGNAL_FUNC (print_dialog_action_choosefile), dialog);

  /* Widgets for printing to command */
  dialog->cmdradio =
    GTK_RADIO_BUTTON (gtk_radio_button_new_with_label_from_widget
		      (dialog->fileradio, _("Command:")));
  gtk_table_attach (GTK_TABLE (desttable),
		    GTK_WIDGET (dialog->cmdradio),
		    0, 1, 1, 2,  GTK_FILL, GTK_EXPAND, 0, 0);
  g_signal_connect (dialog->cmdradio,
		    "toggled",
		    GTK_SIGNAL_FUNC (print_dialog_action_radio_toggled),
		    dialog);

  dialog->cmdfield = GTK_ENTRY (gtk_entry_new ());
  gtk_table_attach (GTK_TABLE (desttable), GTK_WIDGET (dialog->cmdfield),
		    1, 3, 1, 2, GTK_EXPAND | GTK_FILL, 0, 0, 0);

  /* Add "Cancel" and "Print" buttons */
   gtk_dialog_add_button (GTK_DIALOG (dialog),
                  GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
   print_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
                  GTK_STOCK_PRINT, GTK_RESPONSE_ACCEPT);
   gtk_widget_grab_focus(print_button);

  /* Set the alternative button order (ok, cancel, help) for other systems */
  gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog),
					  GTK_RESPONSE_ACCEPT,
					  GTK_RESPONSE_REJECT,
					  -1);

  /* Set initial radiobutton selection */
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->cmdradio), TRUE);
}

/*! \todo Finish function documentation
 *  \brief
 *  \par Function Description
 *
 */
static void
print_dialog_set_property (GObject * object,
                          guint property_id,
                          const GValue * value, GParamSpec * pspec)
{
  PrintDialog *dialog = PRINT_DIALOG (object);
  gboolean file_active = FALSE;

  switch (property_id)
    {
    case PROP_FILENAME:
      gtk_entry_set_text (dialog->fnfield,
                         (char *) g_value_get_string (value));
      return;

    case PROP_COMMAND:
      gtk_entry_set_text (dialog->cmdfield,
                         (char *) g_value_get_string (value));
      return;

    case PROP_PAPERSIZE:
      gtk_combo_box_set_active (dialog->papercbox,
                               g_value_get_int (value));
      return;

    case PROP_ORIENTATION:
      print_dialog_set_property_comboboxes (dialog, 
					    dialog->orientcbox,
					    value);
      return;

    case PROP_TYPE:
      print_dialog_set_property_comboboxes (dialog, 
					    dialog->typecbox,
					    value);
      return;

    case PROP_USEFILE:
      file_active = g_value_get_boolean (value);
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->fileradio),
                                   file_active);
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->cmdradio),
                                   !file_active);
      return;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }
}

/*! \todo Finish function documentation
 *  \brief
 *  \par Function Description
 *
 */
static void
print_dialog_set_property_comboboxes (PrintDialog * dialog,
				      GtkComboBox * cbox,
				      const GValue * value)
{
  GtkTreeIter iter;
  GtkTreeModel *model;

  model = gtk_combo_box_get_model (cbox);
  gtk_tree_model_get_iter_first (model, &iter);

  do {
    GValue temp_value = {0, }; /* Make sure it's blank*/
    gtk_tree_model_get_value (model, &iter, 1, &temp_value);

    if (g_value_get_int (&temp_value) == g_value_get_int (value))
      {
	gtk_combo_box_set_active_iter (cbox, &iter);
	return;
      }

  } while (gtk_tree_model_iter_next (model, &iter));

  gtk_combo_box_set_active (cbox, 0);
}

/*! \todo Finish function documentation
 *  \brief
 *  \par Function Description
 *
 */
static void
print_dialog_get_property (GObject * object,
                          guint property_id,
                          GValue * value, GParamSpec * pspec)
{
  PrintDialog *dialog = PRINT_DIALOG (object);
  gboolean file_active = FALSE;

  switch (property_id)
    {
    case PROP_FILENAME:
      g_value_set_string (value,
			  gtk_entry_get_text (GTK_ENTRY (dialog->fnfield)));
      return;
 
    case PROP_COMMAND:
      g_value_set_string (value,
			  gtk_entry_get_text (GTK_ENTRY (dialog->cmdfield)));
      return;
 
    case PROP_PAPERSIZE:
      g_value_set_int (value, gtk_combo_box_get_active (dialog->papercbox));
      return;
 
    case PROP_ORIENTATION:
      print_dialog_get_property_comboboxes (dialog,
					    dialog->orientcbox,
					    value);
      return;
      
    case PROP_TYPE:
      print_dialog_get_property_comboboxes (dialog,
					    dialog->typecbox,
					    value);
      return;
 
    case PROP_USEFILE:
      file_active = 
        gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->fileradio));
      g_value_set_boolean (value, file_active);
      return;
            
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }
} 

/*! \todo Finish function documentation
 *  \brief
 *  \par Function Description
 *
 */
static void
print_dialog_get_property_comboboxes (PrintDialog * dialog,
				      GtkComboBox * cbox,
				      GValue * value)
{
  GValue temp_value = {0, };
  GtkTreeModel *model;
  GtkTreeIter iter;

  model = gtk_combo_box_get_model (cbox);

  gtk_combo_box_get_active_iter (cbox, &iter);
  gtk_tree_model_get_value (model, &iter, 1, &temp_value);
  g_value_copy (&temp_value, value);
  g_value_unset (&temp_value);
}

/*! \todo Finish function documentation
 *  \brief
 *  \par Function Description
 *  \bug Hardcoded 'magic' numbers in this function
 *
 */
static void
print_dialog_class_init (PrintDialogClass * class)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (class);

  gobject_class->set_property = print_dialog_set_property;
  gobject_class->get_property = print_dialog_get_property;

  g_object_class_install_property (gobject_class, PROP_FILENAME,
				   g_param_spec_string ("filename",
							"", "", "",
							 G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_COMMAND,
				   g_param_spec_string ("command",
							"", "", "lpr",
							 G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_PAPERSIZE,
				   g_param_spec_int ("papersize",
						     "", "", 0, G_MAXINT, 0,
						     G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_ORIENTATION,
				   g_param_spec_int ("orientation",
						     "", "", 0, G_MAXINT, 0,
						     G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_TYPE,
				   g_param_spec_int ("type",
						     "", "", 0, G_MAXINT, 0,
						     G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_USEFILE,
				   g_param_spec_boolean ("usefile",
							 "", "", FALSE,
							 G_PARAM_READWRITE));
}

/*! \todo Finish function documentation
 *  \brief
 *  \par Function Description
 *
 */
GType
print_dialog_get_type ()
{
  static GType print_dialog_type = 0;
 
  if (!print_dialog_type)
    {
      static const GTypeInfo print_dialog_info = {
	sizeof (PrintDialogClass),
	NULL,			/* base_init */
	NULL,			/* base_finalize */
	(GClassInitFunc) print_dialog_class_init,
	NULL,			/* class_finalize */
	NULL,			/* class_data */
	sizeof (PrintDialog),
	0,			/* n_preallocs */
	(GInstanceInitFunc) print_dialog_init,
      };
      print_dialog_type = g_type_register_static (GSCHEM_TYPE_DIALOG,
						  "PrintDialog",
						  &print_dialog_info, 0);
    }

  return print_dialog_type;
}

/*! \todo Finish function documentation
 *  \brief
 *  \par Function Description
 *
 */
void
x_print_setup (GSCHEM_TOPLEVEL *w_current, char *filename)
{
  TOPLEVEL *toplevel = w_current->toplevel;
  gchar * command = w_current->print_command;
  gint orient = toplevel->print_orientation;
  gint type = toplevel->print_output_type;
  gint paperidx, x, y, result;
  gchar *string, *destination;
  gboolean usefile = FALSE;
  GtkDialog *dialog; 
  GtkWidget *popup_message;

  /* Work out current paper size by iterating through available paper
   * sizes.  Set the default paper size as the active selection */

  /* FIXME: ought to have a TOPLEVEL property containing
   * default paper size name, this is somewhat hackish. No
   * better way of doing it with current implementation of
   * varying paper size though. */
  paperidx = 0;
  while (TRUE)
    {
      string = (gchar *) s_papersizes_get (paperidx);
      s_papersizes_get_size (string, &x, &y);

      if ((x == toplevel->paper_width)
	  && (y == toplevel->paper_height))
	{
	  break;
	}
      if (string == NULL)
	{
	  paperidx = 0;
	  break;
	}
      paperidx++;
    }
 
  /* Create a print dialog, find out whether the user clicks Print or
     Cancel, and then print or return accordingly */
  dialog = GTK_DIALOG (g_object_new (TYPE_PRINT_DIALOG,
                                     "command", command,
                                     "filename", filename,
                                     "papersize", paperidx,
                                     "orientation", orient,
                                     "type", type,
                                     "usefile", usefile,
                                     /* GschemDialog */
                                     "settings-name", "print",
                                     "gschem-toplevel", w_current,
                                     NULL));
  gtk_widget_show_all (GTK_WIDGET (dialog));

  gtk_dialog_set_default_response(GTK_DIALOG(dialog),
				  GTK_RESPONSE_ACCEPT);
  gtk_window_set_transient_for(GTK_WINDOW(dialog),
			       GTK_WINDOW(w_current->main_window));

  result = gtk_dialog_run (dialog);
  
  if (result == GTK_RESPONSE_ACCEPT)
    {
      /* Extract values from dialog and set the paper size */
      g_object_get (dialog,
		    "command", &command,
		    "filename", &filename,
		    "papersize", &paperidx,
		    "orientation", &toplevel->print_orientation,
		    "type", &toplevel->print_output_type,
		    "usefile", &usefile,
		    NULL);

      s_papersizes_get_size (s_papersizes_get (paperidx),
			     &toplevel->paper_width,
			     &toplevel->paper_height);
		
      /* de select everything first */
      o_select_unselect_all( w_current );

      if (usefile && filename[0])
	/* Print to file */
	{
	  destination = filename;
	  result = f_print_file (toplevel, filename);
	}
      else if (command[0])
	/* Print to command and save command for later use. */
	{
	  destination = command;
	  result = f_print_command (toplevel, command);
	  
	  g_free (w_current->print_command);
	  w_current->print_command = g_strdup (command);
	}
      else
	{
	  s_log_message (_("No print destination specified\n"));
	  return;
	}

      /* Check whether it worked */
      if (result)
	{
	  s_log_message (_("Cannot print current schematic to [%s]\n"), 
			 destination);

	  /* Pop up a message warning the user */
	  popup_message = 
	    gtk_message_dialog_new (GTK_WINDOW(dialog),
				    GTK_DIALOG_DESTROY_WITH_PARENT,
				    GTK_MESSAGE_ERROR,
				    GTK_BUTTONS_CLOSE,
				    _("Error printing to file '%s'\n"
				      "Check the log window for more information"),
				    destination);
	  gtk_dialog_run (GTK_DIALOG (popup_message));	  
	}
      else
	{
	  s_log_message (_("Printed current schematic to [%s]\n"), 
			 destination);
	}
    }
   
  /* We don't need the dialog any more */
  gtk_widget_destroy (GTK_WIDGET (dialog));

}