]> Pileus Git - ~andy/gtk/blob - modules/printbackends/cups/gtkprintercups.c
Do not use static GTypeInfo and GInterfaceInfo
[~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   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   printer->default_cover_before = NULL;
79   printer->default_cover_after = NULL;
80   printer->remote = FALSE;
81   printer->get_remote_ppd_poll = 0;
82   printer->get_remote_ppd_attempts = 0;
83   printer->remote_cups_connection_test = NULL;
84   printer->auth_info_required = NULL;
85 }
86
87 static void
88 gtk_printer_cups_finalize (GObject *object)
89 {
90   GtkPrinterCups *printer;
91
92   g_return_if_fail (object != NULL);
93
94   printer = GTK_PRINTER_CUPS (object);
95
96   g_free (printer->device_uri);
97   g_free (printer->printer_uri);
98   g_free (printer->hostname);
99   g_free (printer->ppd_name);
100   g_free (printer->default_cover_before);
101   g_free (printer->default_cover_after);
102   g_strfreev (printer->auth_info_required);
103
104   if (printer->ppd_file)
105     ppdClose (printer->ppd_file);
106
107   if (printer->get_remote_ppd_poll > 0)
108     g_source_remove (printer->get_remote_ppd_poll);
109   printer->get_remote_ppd_attempts = 0;
110
111   gtk_cups_connection_test_free (printer->remote_cups_connection_test);
112
113   G_OBJECT_CLASS (gtk_printer_cups_parent_class)->finalize (object);
114 }
115
116 /**
117  * gtk_printer_cups_new:
118  *
119  * Creates a new #GtkPrinterCups.
120  *
121  * Return value: a new #GtkPrinterCups
122  *
123  * Since: 2.10
124  **/
125 GtkPrinterCups *
126 gtk_printer_cups_new (const char      *name,
127                       GtkPrintBackend *backend)
128 {
129   GObject *result;
130   
131   result = g_object_new (GTK_TYPE_PRINTER_CUPS,
132                          "name", name,
133                          "backend", backend,
134                          "is-virtual", FALSE,
135                          NULL);
136
137   return (GtkPrinterCups *) result;
138 }
139
140 ppd_file_t *
141 gtk_printer_cups_get_ppd (GtkPrinterCups *printer)
142 {
143   return printer->ppd_file;
144 }
145
146 const gchar *
147 gtk_printer_cups_get_ppd_name (GtkPrinterCups  *printer)
148 {
149   const gchar *result;
150
151   result = printer->ppd_name;
152
153   if (result == NULL)
154     result = gtk_printer_get_name (GTK_PRINTER (printer));
155
156   return result;
157 }