]> Pileus Git - ~andy/gtk/blob - modules/printbackends/cups/gtkprintercups.c
Get the name of the first printer in a class to use when requesting a PPD
[~andy/gtk] / modules / printbackends / cups / gtkprintercups.c
1 /* GtkPrinterCupsCups
2  * Copyright (C) 2006 John (J5) Palmieri  <johnp@redhat.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21 #include "gtkprintercups.h"
22
23 static void gtk_printer_cups_init       (GtkPrinterCups      *printer);
24 static void gtk_printer_cups_class_init (GtkPrinterCupsClass *class);
25 static void gtk_printer_cups_finalize   (GObject             *object);
26
27 static GtkPrinterClass *gtk_printer_cups_parent_class;
28 static GType gtk_printer_cups_type = 0;
29
30 void 
31 gtk_printer_cups_register_type (GTypeModule *module)
32 {
33   static const GTypeInfo object_info =
34   {
35     sizeof (GtkPrinterCupsClass),
36     (GBaseInitFunc) NULL,
37     (GBaseFinalizeFunc) NULL,
38     (GClassInitFunc) gtk_printer_cups_class_init,
39     NULL,           /* class_finalize */
40     NULL,           /* class_data */
41     sizeof (GtkPrinterCups),
42     0,              /* n_preallocs */
43     (GInstanceInitFunc) gtk_printer_cups_init,
44   };
45
46  gtk_printer_cups_type = g_type_module_register_type (module,
47                                                       GTK_TYPE_PRINTER,
48                                                       "GtkPrinterCups",
49                                                       &object_info, 0);
50 }
51
52 GType
53 gtk_printer_cups_get_type (void)
54 {
55   return gtk_printer_cups_type;
56 }
57
58 static void
59 gtk_printer_cups_class_init (GtkPrinterCupsClass *class)
60 {
61   GObjectClass *object_class = (GObjectClass *) class;
62         
63   gtk_printer_cups_parent_class = g_type_class_peek_parent (class);
64
65   object_class->finalize = gtk_printer_cups_finalize;
66 }
67
68 static void
69 gtk_printer_cups_init (GtkPrinterCups *printer)
70 {
71   printer->device_uri = NULL;
72   printer->printer_uri = NULL;
73   printer->state = 0;
74   printer->hostname = NULL;
75   printer->port = 0;
76   printer->ppd_name = NULL;
77   printer->ppd_file = NULL;
78 }
79
80 static void
81 gtk_printer_cups_finalize (GObject *object)
82 {
83   GtkPrinterCups *printer;
84
85   g_return_if_fail (object != NULL);
86
87   printer = GTK_PRINTER_CUPS (object);
88
89   g_free (printer->device_uri);
90   g_free (printer->printer_uri);
91   g_free (printer->hostname);
92   g_free (printer->ppd_name);
93
94   if (printer->ppd_file)
95     ppdClose (printer->ppd_file);
96
97   G_OBJECT_CLASS (gtk_printer_cups_parent_class)->finalize (object);
98 }
99
100 /**
101  * gtk_printer_cups_new:
102  *
103  * Creates a new #GtkPrinterCups.
104  *
105  * Return value: a new #GtkPrinterCups
106  *
107  * Since: 2.10
108  **/
109 GtkPrinterCups *
110 gtk_printer_cups_new (const char      *name,
111                       GtkPrintBackend *backend)
112 {
113   GObject *result;
114   
115   result = g_object_new (GTK_TYPE_PRINTER_CUPS,
116                          "name", name,
117                          "backend", backend,
118                          "is-virtual", FALSE,
119                          NULL);
120
121   return (GtkPrinterCups *) result;
122 }
123
124 ppd_file_t *
125 gtk_printer_cups_get_ppd (GtkPrinterCups *printer)
126 {
127   return printer->ppd_file;
128 }
129
130 char *
131 gtk_printer_cups_get_ppd_name (GtkPrinterCups  *printer)
132 {
133   gchar *result;
134
135   result = printer->ppd_name;
136
137   if (result == NULL)
138     result = gtk_printer_get_name (GTK_PRINTER (printer));
139
140   return result;
141 }
142