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.PrintJob;
26 
27 private import cairo.Surface;
28 private import glib.ConstructionException;
29 private import glib.ErrorG;
30 private import glib.GException;
31 private import glib.Str;
32 private import glib.c.functions;
33 private import gobject.ObjectG;
34 private import gobject.Signals;
35 private import gtk.PageSetup;
36 private import gtk.PrintSettings;
37 private import gtk.Printer;
38 private import gtk.c.functions;
39 public  import gtk.c.types;
40 private import std.algorithm;
41 
42 
43 /**
44  * A `GtkPrintJob` object represents a job that is sent to a printer.
45  * 
46  * You only need to deal directly with print jobs if you use the
47  * non-portable [class@Gtk.PrintUnixDialog] API.
48  * 
49  * Use [method@Gtk.PrintJob.get_surface] to obtain the cairo surface
50  * onto which the pages must be drawn. Use [method@Gtk.PrintJob.send]
51  * to send the finished job to the printer. If you don’t use cairo
52  * `GtkPrintJob` also supports printing of manually generated PostScript,
53  * via [method@Gtk.PrintJob.set_source_file].
54  */
55 public class PrintJob : ObjectG
56 {
57 	/** the main Gtk struct */
58 	protected GtkPrintJob* gtkPrintJob;
59 
60 	/** Get the main Gtk struct */
61 	public GtkPrintJob* getPrintJobStruct(bool transferOwnership = false)
62 	{
63 		if (transferOwnership)
64 			ownedRef = false;
65 		return gtkPrintJob;
66 	}
67 
68 	/** the main Gtk struct as a void* */
69 	protected override void* getStruct()
70 	{
71 		return cast(void*)gtkPrintJob;
72 	}
73 
74 	/**
75 	 * Sets our main struct and passes it to the parent class.
76 	 */
77 	public this (GtkPrintJob* gtkPrintJob, bool ownedRef = false)
78 	{
79 		this.gtkPrintJob = gtkPrintJob;
80 		super(cast(GObject*)gtkPrintJob, ownedRef);
81 	}
82 
83 
84 	/** */
85 	public static GType getType()
86 	{
87 		return gtk_print_job_get_type();
88 	}
89 
90 	/**
91 	 * Creates a new `GtkPrintJob`.
92 	 *
93 	 * Params:
94 	 *     title = the job title
95 	 *     printer = a `GtkPrinter`
96 	 *     settings = a `GtkPrintSettings`
97 	 *     pageSetup = a `GtkPageSetup`
98 	 *
99 	 * Returns: a new `GtkPrintJob`
100 	 *
101 	 * Throws: ConstructionException GTK+ fails to create the object.
102 	 */
103 	public this(string title, Printer printer, PrintSettings settings, PageSetup pageSetup)
104 	{
105 		auto __p = gtk_print_job_new(Str.toStringz(title), (printer is null) ? null : printer.getPrinterStruct(), (settings is null) ? null : settings.getPrintSettingsStruct(), (pageSetup is null) ? null : pageSetup.getPageSetupStruct());
106 
107 		if(__p is null)
108 		{
109 			throw new ConstructionException("null returned by new");
110 		}
111 
112 		this(cast(GtkPrintJob*) __p, true);
113 	}
114 
115 	/**
116 	 * Gets whether this job is printed collated.
117 	 *
118 	 * Returns: whether the job is printed collated
119 	 */
120 	public bool getCollate()
121 	{
122 		return gtk_print_job_get_collate(gtkPrintJob) != 0;
123 	}
124 
125 	/**
126 	 * Gets the n-up setting for this job.
127 	 *
128 	 * Returns: the n-up setting
129 	 */
130 	public uint getNUp()
131 	{
132 		return gtk_print_job_get_n_up(gtkPrintJob);
133 	}
134 
135 	/**
136 	 * Gets the n-up layout setting for this job.
137 	 *
138 	 * Returns: the n-up layout
139 	 */
140 	public GtkNumberUpLayout getNUpLayout()
141 	{
142 		return gtk_print_job_get_n_up_layout(gtkPrintJob);
143 	}
144 
145 	/**
146 	 * Gets the number of copies of this job.
147 	 *
148 	 * Returns: the number of copies
149 	 */
150 	public int getNumCopies()
151 	{
152 		return gtk_print_job_get_num_copies(gtkPrintJob);
153 	}
154 
155 	/**
156 	 * Gets the page ranges for this job.
157 	 *
158 	 * Returns: a pointer to an
159 	 *     array of `GtkPageRange` structs
160 	 */
161 	public GtkPageRange[] getPageRanges()
162 	{
163 		int nRanges;
164 
165 		auto __p = gtk_print_job_get_page_ranges(gtkPrintJob, &nRanges);
166 
167 		return __p[0 .. nRanges];
168 	}
169 
170 	/**
171 	 * Gets the `GtkPageSet` setting for this job.
172 	 *
173 	 * Returns: the `GtkPageSet` setting
174 	 */
175 	public GtkPageSet getPageSet()
176 	{
177 		return gtk_print_job_get_page_set(gtkPrintJob);
178 	}
179 
180 	/**
181 	 * Gets the `GtkPrintPages` setting for this job.
182 	 *
183 	 * Returns: the `GtkPrintPages` setting
184 	 */
185 	public GtkPrintPages getPages()
186 	{
187 		return gtk_print_job_get_pages(gtkPrintJob);
188 	}
189 
190 	/**
191 	 * Gets the `GtkPrinter` of the print job.
192 	 *
193 	 * Returns: the printer of @job
194 	 */
195 	public Printer getPrinter()
196 	{
197 		auto __p = gtk_print_job_get_printer(gtkPrintJob);
198 
199 		if(__p is null)
200 		{
201 			return null;
202 		}
203 
204 		return ObjectG.getDObject!(Printer)(cast(GtkPrinter*) __p);
205 	}
206 
207 	/**
208 	 * Gets whether this job is printed reversed.
209 	 *
210 	 * Returns: whether the job is printed reversed.
211 	 */
212 	public bool getReverse()
213 	{
214 		return gtk_print_job_get_reverse(gtkPrintJob) != 0;
215 	}
216 
217 	/**
218 	 * Gets whether the job is printed rotated.
219 	 *
220 	 * Returns: whether the job is printed rotated
221 	 */
222 	public bool getRotate()
223 	{
224 		return gtk_print_job_get_rotate(gtkPrintJob) != 0;
225 	}
226 
227 	/**
228 	 * Gets the scale for this job.
229 	 *
230 	 * Returns: the scale
231 	 */
232 	public double getScale()
233 	{
234 		return gtk_print_job_get_scale(gtkPrintJob);
235 	}
236 
237 	/**
238 	 * Gets the `GtkPrintSettings` of the print job.
239 	 *
240 	 * Returns: the settings of @job
241 	 */
242 	public PrintSettings getSettings()
243 	{
244 		auto __p = gtk_print_job_get_settings(gtkPrintJob);
245 
246 		if(__p is null)
247 		{
248 			return null;
249 		}
250 
251 		return ObjectG.getDObject!(PrintSettings)(cast(GtkPrintSettings*) __p);
252 	}
253 
254 	/**
255 	 * Gets the status of the print job.
256 	 *
257 	 * Returns: the status of @job
258 	 */
259 	public GtkPrintStatus getStatus()
260 	{
261 		return gtk_print_job_get_status(gtkPrintJob);
262 	}
263 
264 	/**
265 	 * Gets a cairo surface onto which the pages of
266 	 * the print job should be rendered.
267 	 *
268 	 * Returns: the cairo surface of @job
269 	 *
270 	 * Throws: GException on failure.
271 	 */
272 	public Surface getSurface()
273 	{
274 		GError* err = null;
275 
276 		auto __p = gtk_print_job_get_surface(gtkPrintJob, &err);
277 
278 		if (err !is null)
279 		{
280 			throw new GException( new ErrorG(err) );
281 		}
282 
283 		if(__p is null)
284 		{
285 			return null;
286 		}
287 
288 		return new Surface(cast(cairo_surface_t*) __p);
289 	}
290 
291 	/**
292 	 * Gets the job title.
293 	 *
294 	 * Returns: the title of @job
295 	 */
296 	public string getTitle()
297 	{
298 		return Str.toString(gtk_print_job_get_title(gtkPrintJob));
299 	}
300 
301 	/**
302 	 * Returns whether jobs will be tracked after printing.
303 	 *
304 	 * For details, see [method@Gtk.PrintJob.set_track_print_status].
305 	 *
306 	 * Returns: %TRUE if print job status will be reported after printing
307 	 */
308 	public bool getTrackPrintStatus()
309 	{
310 		return gtk_print_job_get_track_print_status(gtkPrintJob) != 0;
311 	}
312 
313 	/**
314 	 * Sends the print job off to the printer.
315 	 *
316 	 * Params:
317 	 *     callback = function to call when the job completes or an error occurs
318 	 *     userData = user data that gets passed to @callback
319 	 *     dnotify = destroy notify for @user_data
320 	 */
321 	public void send(GtkPrintJobCompleteFunc callback, void* userData, GDestroyNotify dnotify)
322 	{
323 		gtk_print_job_send(gtkPrintJob, callback, userData, dnotify);
324 	}
325 
326 	/**
327 	 * Sets whether this job is printed collated.
328 	 *
329 	 * Params:
330 	 *     collate = whether the job is printed collated
331 	 */
332 	public void setCollate(bool collate)
333 	{
334 		gtk_print_job_set_collate(gtkPrintJob, collate);
335 	}
336 
337 	/**
338 	 * Sets the n-up setting for this job.
339 	 *
340 	 * Params:
341 	 *     nUp = the n-up value
342 	 */
343 	public void setNUp(uint nUp)
344 	{
345 		gtk_print_job_set_n_up(gtkPrintJob, nUp);
346 	}
347 
348 	/**
349 	 * Sets the n-up layout setting for this job.
350 	 *
351 	 * Params:
352 	 *     layout = the n-up layout setting
353 	 */
354 	public void setNUpLayout(GtkNumberUpLayout layout)
355 	{
356 		gtk_print_job_set_n_up_layout(gtkPrintJob, layout);
357 	}
358 
359 	/**
360 	 * Sets the number of copies for this job.
361 	 *
362 	 * Params:
363 	 *     numCopies = the number of copies
364 	 */
365 	public void setNumCopies(int numCopies)
366 	{
367 		gtk_print_job_set_num_copies(gtkPrintJob, numCopies);
368 	}
369 
370 	/**
371 	 * Sets the page ranges for this job.
372 	 *
373 	 * Params:
374 	 *     ranges = pointer to an array of
375 	 *         `GtkPageRange` structs
376 	 */
377 	public void setPageRanges(GtkPageRange[] ranges)
378 	{
379 		gtk_print_job_set_page_ranges(gtkPrintJob, ranges.ptr, cast(int)ranges.length);
380 	}
381 
382 	/**
383 	 * Sets the `GtkPageSet` setting for this job.
384 	 *
385 	 * Params:
386 	 *     pageSet = a `GtkPageSet` setting
387 	 */
388 	public void setPageSet(GtkPageSet pageSet)
389 	{
390 		gtk_print_job_set_page_set(gtkPrintJob, pageSet);
391 	}
392 
393 	/**
394 	 * Sets the `GtkPrintPages` setting for this job.
395 	 *
396 	 * Params:
397 	 *     pages = the `GtkPrintPages` setting
398 	 */
399 	public void setPages(GtkPrintPages pages)
400 	{
401 		gtk_print_job_set_pages(gtkPrintJob, pages);
402 	}
403 
404 	/**
405 	 * Sets whether this job is printed reversed.
406 	 *
407 	 * Params:
408 	 *     reverse = whether the job is printed reversed
409 	 */
410 	public void setReverse(bool reverse)
411 	{
412 		gtk_print_job_set_reverse(gtkPrintJob, reverse);
413 	}
414 
415 	/**
416 	 * Sets whether this job is printed rotated.
417 	 *
418 	 * Params:
419 	 *     rotate = whether to print rotated
420 	 */
421 	public void setRotate(bool rotate)
422 	{
423 		gtk_print_job_set_rotate(gtkPrintJob, rotate);
424 	}
425 
426 	/**
427 	 * Sets the scale for this job.
428 	 *
429 	 * 1.0 means unscaled.
430 	 *
431 	 * Params:
432 	 *     scale = the scale
433 	 */
434 	public void setScale(double scale)
435 	{
436 		gtk_print_job_set_scale(gtkPrintJob, scale);
437 	}
438 
439 	/**
440 	 * Make the `GtkPrintJob` send an existing document to the
441 	 * printing system.
442 	 *
443 	 * The file can be in any format understood by the platforms
444 	 * printing system (typically PostScript, but on many platforms
445 	 * PDF may work too). See [method@Gtk.Printer.accepts_pdf] and
446 	 * [method@Gtk.Printer.accepts_ps].
447 	 *
448 	 * This is similar to [method@Gtk.PrintJob.set_source_file],
449 	 * but takes expects an open file descriptor for the file,
450 	 * instead of a filename.
451 	 *
452 	 * Params:
453 	 *     fd = a file descriptor
454 	 *
455 	 * Returns: %FALSE if an error occurred
456 	 *
457 	 * Throws: GException on failure.
458 	 */
459 	public bool setSourceFd(int fd)
460 	{
461 		GError* err = null;
462 
463 		auto __p = gtk_print_job_set_source_fd(gtkPrintJob, fd, &err) != 0;
464 
465 		if (err !is null)
466 		{
467 			throw new GException( new ErrorG(err) );
468 		}
469 
470 		return __p;
471 	}
472 
473 	/**
474 	 * Make the `GtkPrintJob` send an existing document to the
475 	 * printing system.
476 	 *
477 	 * The file can be in any format understood by the platforms
478 	 * printing system (typically PostScript, but on many platforms
479 	 * PDF may work too). See [method@Gtk.Printer.accepts_pdf] and
480 	 * [method@Gtk.Printer.accepts_ps].
481 	 *
482 	 * Params:
483 	 *     filename = the file to be printed
484 	 *
485 	 * Returns: %FALSE if an error occurred
486 	 *
487 	 * Throws: GException on failure.
488 	 */
489 	public bool setSourceFile(string filename)
490 	{
491 		GError* err = null;
492 
493 		auto __p = gtk_print_job_set_source_file(gtkPrintJob, Str.toStringz(filename), &err) != 0;
494 
495 		if (err !is null)
496 		{
497 			throw new GException( new ErrorG(err) );
498 		}
499 
500 		return __p;
501 	}
502 
503 	/**
504 	 * If track_status is %TRUE, the print job will try to continue report
505 	 * on the status of the print job in the printer queues and printer.
506 	 *
507 	 * This can allow your application to show things like “out of paper”
508 	 * issues, and when the print job actually reaches the printer.
509 	 *
510 	 * This function is often implemented using some form of polling,
511 	 * so it should not be enabled unless needed.
512 	 *
513 	 * Params:
514 	 *     trackStatus = %TRUE to track status after printing
515 	 */
516 	public void setTrackPrintStatus(bool trackStatus)
517 	{
518 		gtk_print_job_set_track_print_status(gtkPrintJob, trackStatus);
519 	}
520 
521 	/**
522 	 * Emitted when the status of a job changes.
523 	 *
524 	 * The signal handler can use [method@Gtk.PrintJob.get_status]
525 	 * to obtain the new status.
526 	 */
527 	gulong addOnStatusChanged(void delegate(PrintJob) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
528 	{
529 		return Signals.connect(this, "status-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
530 	}
531 }