1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.Printer;
26 
27 private import glib.ConstructionException;
28 private import glib.ListG;
29 private import glib.Str;
30 private import glib.c.functions;
31 private import gobject.ObjectG;
32 private import gobject.Signals;
33 private import gtk.PageSetup;
34 private import gtk.PaperSize;
35 private import gtk.c.functions;
36 public  import gtk.c.types;
37 private import std.algorithm;
38 
39 
40 /**
41  * A `GtkPrinter` object represents a printer.
42  * 
43  * You only need to deal directly with printers if you use the
44  * non-portable [class@Gtk.PrintUnixDialog] API.
45  * 
46  * A `GtkPrinter` allows to get status information about the printer,
47  * such as its description, its location, the number of queued jobs,
48  * etc. Most importantly, a `GtkPrinter` object can be used to create
49  * a [class@Gtk.PrintJob] object, which lets you print to the printer.
50  */
51 public class Printer : ObjectG
52 {
53 	/** the main Gtk struct */
54 	protected GtkPrinter* gtkPrinter;
55 
56 	/** Get the main Gtk struct */
57 	public GtkPrinter* getPrinterStruct(bool transferOwnership = false)
58 	{
59 		if (transferOwnership)
60 			ownedRef = false;
61 		return gtkPrinter;
62 	}
63 
64 	/** the main Gtk struct as a void* */
65 	protected override void* getStruct()
66 	{
67 		return cast(void*)gtkPrinter;
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (GtkPrinter* gtkPrinter, bool ownedRef = false)
74 	{
75 		this.gtkPrinter = gtkPrinter;
76 		super(cast(GObject*)gtkPrinter, ownedRef);
77 	}
78 
79 
80 	/** */
81 	public static GType getType()
82 	{
83 		return gtk_printer_get_type();
84 	}
85 
86 	/**
87 	 * Creates a new `GtkPrinter`.
88 	 *
89 	 * Params:
90 	 *     name = the name of the printer
91 	 *     backend = a `GtkPrintBackend`
92 	 *     virtual = whether the printer is virtual
93 	 *
94 	 * Returns: a new `GtkPrinter`
95 	 *
96 	 * Throws: ConstructionException GTK+ fails to create the object.
97 	 */
98 	public this(string name, GtkPrintBackend* backend, bool virtual)
99 	{
100 		auto __p = gtk_printer_new(Str.toStringz(name), backend, virtual);
101 
102 		if(__p is null)
103 		{
104 			throw new ConstructionException("null returned by new");
105 		}
106 
107 		this(cast(GtkPrinter*) __p, true);
108 	}
109 
110 	/**
111 	 * Returns whether the printer accepts input in
112 	 * PDF format.
113 	 *
114 	 * Returns: %TRUE if @printer accepts PDF
115 	 */
116 	public bool acceptsPdf()
117 	{
118 		return gtk_printer_accepts_pdf(gtkPrinter) != 0;
119 	}
120 
121 	/**
122 	 * Returns whether the printer accepts input in
123 	 * PostScript format.
124 	 *
125 	 * Returns: %TRUE if @printer accepts PostScript
126 	 */
127 	public bool acceptsPs()
128 	{
129 		return gtk_printer_accepts_ps(gtkPrinter) != 0;
130 	}
131 
132 	/**
133 	 * Compares two printers.
134 	 *
135 	 * Params:
136 	 *     b = another `GtkPrinter`
137 	 *
138 	 * Returns: 0 if the printer match, a negative value if @a < @b,
139 	 *     or a positive value if @a > @b
140 	 */
141 	public int compare(Printer b)
142 	{
143 		return gtk_printer_compare(gtkPrinter, (b is null) ? null : b.getPrinterStruct());
144 	}
145 
146 	/**
147 	 * Returns the backend of the printer.
148 	 *
149 	 * Returns: the backend of @printer
150 	 */
151 	public GtkPrintBackend* getBackend()
152 	{
153 		return gtk_printer_get_backend(gtkPrinter);
154 	}
155 
156 	/**
157 	 * Returns the printer’s capabilities.
158 	 *
159 	 * This is useful when you’re using `GtkPrintUnixDialog`’s
160 	 * manual-capabilities setting and need to know which settings
161 	 * the printer can handle and which you must handle yourself.
162 	 *
163 	 * This will return 0 unless the printer’s details are
164 	 * available, see [method@Gtk.Printer.has_details] and
165 	 * [method@Gtk.Printer.request_details].
166 	 *
167 	 * Returns: the printer’s capabilities
168 	 */
169 	public GtkPrintCapabilities getCapabilities()
170 	{
171 		return gtk_printer_get_capabilities(gtkPrinter);
172 	}
173 
174 	/**
175 	 * Returns default page size of @printer.
176 	 *
177 	 * Returns: a newly allocated `GtkPageSetup` with default page size
178 	 *     of the printer.
179 	 */
180 	public PageSetup getDefaultPageSize()
181 	{
182 		auto __p = gtk_printer_get_default_page_size(gtkPrinter);
183 
184 		if(__p is null)
185 		{
186 			return null;
187 		}
188 
189 		return ObjectG.getDObject!(PageSetup)(cast(GtkPageSetup*) __p, true);
190 	}
191 
192 	/**
193 	 * Gets the description of the printer.
194 	 *
195 	 * Returns: the description of @printer
196 	 */
197 	public string getDescription()
198 	{
199 		return Str.toString(gtk_printer_get_description(gtkPrinter));
200 	}
201 
202 	/**
203 	 * Retrieve the hard margins of @printer.
204 	 *
205 	 * These are the margins that define the area at the borders
206 	 * of the paper that the printer cannot print to.
207 	 *
208 	 * Note: This will not succeed unless the printer’s details are
209 	 * available, see [method@Gtk.Printer.has_details] and
210 	 * [method@Gtk.Printer.request_details].
211 	 *
212 	 * Params:
213 	 *     top = a location to store the top margin in
214 	 *     bottom = a location to store the bottom margin in
215 	 *     left = a location to store the left margin in
216 	 *     right = a location to store the right margin in
217 	 *
218 	 * Returns: %TRUE iff the hard margins were retrieved
219 	 */
220 	public bool getHardMargins(out double top, out double bottom, out double left, out double right)
221 	{
222 		return gtk_printer_get_hard_margins(gtkPrinter, &top, &bottom, &left, &right) != 0;
223 	}
224 
225 	/**
226 	 * Retrieve the hard margins of @printer for @paper_size.
227 	 *
228 	 * These are the margins that define the area at the borders
229 	 * of the paper that the printer cannot print to.
230 	 *
231 	 * Note: This will not succeed unless the printer’s details are
232 	 * available, see [method@Gtk.Printer.has_details] and
233 	 * [method@Gtk.Printer.request_details].
234 	 *
235 	 * Params:
236 	 *     paperSize = a `GtkPaperSize`
237 	 *     top = a location to store the top margin in
238 	 *     bottom = a location to store the bottom margin in
239 	 *     left = a location to store the left margin in
240 	 *     right = a location to store the right margin in
241 	 *
242 	 * Returns: %TRUE iff the hard margins were retrieved
243 	 */
244 	public bool getHardMarginsForPaperSize(PaperSize paperSize, out double top, out double bottom, out double left, out double right)
245 	{
246 		return gtk_printer_get_hard_margins_for_paper_size(gtkPrinter, (paperSize is null) ? null : paperSize.getPaperSizeStruct(), &top, &bottom, &left, &right) != 0;
247 	}
248 
249 	/**
250 	 * Gets the name of the icon to use for the printer.
251 	 *
252 	 * Returns: the icon name for @printer
253 	 */
254 	public string getIconName()
255 	{
256 		return Str.toString(gtk_printer_get_icon_name(gtkPrinter));
257 	}
258 
259 	/**
260 	 * Gets the number of jobs currently queued on the printer.
261 	 *
262 	 * Returns: the number of jobs on @printer
263 	 */
264 	public int getJobCount()
265 	{
266 		return gtk_printer_get_job_count(gtkPrinter);
267 	}
268 
269 	/**
270 	 * Returns a description of the location of the printer.
271 	 *
272 	 * Returns: the location of @printer
273 	 */
274 	public string getLocation()
275 	{
276 		return Str.toString(gtk_printer_get_location(gtkPrinter));
277 	}
278 
279 	/**
280 	 * Returns the name of the printer.
281 	 *
282 	 * Returns: the name of @printer
283 	 */
284 	public string getName()
285 	{
286 		return Str.toString(gtk_printer_get_name(gtkPrinter));
287 	}
288 
289 	/**
290 	 * Returns the state message describing the current state
291 	 * of the printer.
292 	 *
293 	 * Returns: the state message of @printer
294 	 */
295 	public string getStateMessage()
296 	{
297 		return Str.toString(gtk_printer_get_state_message(gtkPrinter));
298 	}
299 
300 	/**
301 	 * Returns whether the printer details are available.
302 	 *
303 	 * Returns: %TRUE if @printer details are available
304 	 */
305 	public bool hasDetails()
306 	{
307 		return gtk_printer_has_details(gtkPrinter) != 0;
308 	}
309 
310 	/**
311 	 * Returns whether the printer is accepting jobs
312 	 *
313 	 * Returns: %TRUE if @printer is accepting jobs
314 	 */
315 	public bool isAcceptingJobs()
316 	{
317 		return gtk_printer_is_accepting_jobs(gtkPrinter) != 0;
318 	}
319 
320 	/**
321 	 * Returns whether the printer is currently active (i.e.
322 	 * accepts new jobs).
323 	 *
324 	 * Returns: %TRUE if @printer is active
325 	 */
326 	public bool isActive()
327 	{
328 		return gtk_printer_is_active(gtkPrinter) != 0;
329 	}
330 
331 	/**
332 	 * Returns whether the printer is the default printer.
333 	 *
334 	 * Returns: %TRUE if @printer is the default
335 	 */
336 	public bool isDefault()
337 	{
338 		return gtk_printer_is_default(gtkPrinter) != 0;
339 	}
340 
341 	/**
342 	 * Returns whether the printer is currently paused.
343 	 *
344 	 * A paused printer still accepts jobs, but it is not
345 	 * printing them.
346 	 *
347 	 * Returns: %TRUE if @printer is paused
348 	 */
349 	public bool isPaused()
350 	{
351 		return gtk_printer_is_paused(gtkPrinter) != 0;
352 	}
353 
354 	/**
355 	 * Returns whether the printer is virtual (i.e. does not
356 	 * represent actual printer hardware, but something like
357 	 * a CUPS class).
358 	 *
359 	 * Returns: %TRUE if @printer is virtual
360 	 */
361 	public bool isVirtual()
362 	{
363 		return gtk_printer_is_virtual(gtkPrinter) != 0;
364 	}
365 
366 	/**
367 	 * Lists all the paper sizes @printer supports.
368 	 *
369 	 * This will return and empty list unless the printer’s details
370 	 * are available, see [method@Gtk.Printer.has_details] and
371 	 * [method@Gtk.Printer.request_details].
372 	 *
373 	 * Returns: a newly
374 	 *     allocated list of newly allocated `GtkPageSetup`s.
375 	 */
376 	public ListG listPapers()
377 	{
378 		auto __p = gtk_printer_list_papers(gtkPrinter);
379 
380 		if(__p is null)
381 		{
382 			return null;
383 		}
384 
385 		return new ListG(cast(GList*) __p, true);
386 	}
387 
388 	/**
389 	 * Requests the printer details.
390 	 *
391 	 * When the details are available, the
392 	 * [signal@Gtk.Printer::details-acquired] signal
393 	 * will be emitted on @printer.
394 	 */
395 	public void requestDetails()
396 	{
397 		gtk_printer_request_details(gtkPrinter);
398 	}
399 
400 	/**
401 	 * Emitted in response to a request for detailed information
402 	 * about a printer from the print backend.
403 	 *
404 	 * The @success parameter indicates if the information was
405 	 * actually obtained.
406 	 *
407 	 * Params:
408 	 *     success = %TRUE if the details were successfully acquired
409 	 */
410 	gulong addOnDetailsAcquired(void delegate(bool, Printer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
411 	{
412 		return Signals.connect(this, "details-acquired", dlg, connectFlags ^ ConnectFlags.SWAPPED);
413 	}
414 }