/* Copyright (C) 2006 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <glibmm/object.h>
#include <gtkmm/pagesetup.h>
#include <gtkmm/printer.h>
#include <gtkmm/printoperation.h>
#include <gtkmm/printsettings.h>
#include <cairomm/surface.h>

_DEFS(gtkmm,gtk)
_PINCLUDE(glibmm/private/object_p.h)

namespace Gtk
{

/** A PrintJob object represents a job that is sent to a printer. You only need to deal 
 * directly with print jobs if you  use the non-portable PrintUnixDialog API.
 * 
 * Use get_surface() to obtain the cairo surface onto which the pages must be drawn. 
 * Use send() to send the finished job to the printer.If you don't use cairo then 
 * PrintJob also supports printing of manually generated postscript, via set_source_file().
 * 
 * @newin{2,10}
 *
 * @ingroup Printing
 */
class PrintJob : public Glib::Object
{
  _CLASS_GOBJECT(PrintJob, GtkPrintJob, GTK_PRINT_JOB, Glib::Object, GObject)
  _GTKMMPROC_WIN32_NO_WRAP

protected:
  _WRAP_CTOR(PrintJob(const Glib::ustring& title, const Glib::RefPtr<Printer>& printer, const Glib::RefPtr<PrintSettings>& settings, const Glib::RefPtr<PageSetup>& page_setup), gtk_print_job_new)

public:
  _WRAP_CREATE(const Glib::ustring& title, const Glib::RefPtr<Printer>& printer, const Glib::RefPtr<PrintSettings>& settings, const Glib::RefPtr<PageSetup>& page_setup)

  _WRAP_METHOD(Glib::RefPtr<PrintSettings> get_settings(), gtk_print_job_get_settings, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const PrintSettings> get_settings() const, gtk_print_job_get_settings, refreturn, constversion)

  _WRAP_METHOD(Glib::RefPtr<Printer> get_printer(), gtk_print_job_get_printer, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Printer> get_printer() const, gtk_print_job_get_printer, refreturn, constversion)

  _WRAP_METHOD(Glib::ustring get_title() const, gtk_print_job_get_title)
  _WRAP_METHOD(PrintStatus get_status() const, gtk_print_job_get_status)
  _IGNORE(gtk_print_job_set_status) // this appears in gtkprinter-private.h
  _WRAP_METHOD(void set_source_file(const std::string& filename), gtk_print_job_set_source_file, errthrow)

  #m4 _CONVERSION(`cairo_surface_t*',`Cairo::RefPtr<Cairo::Surface>',`Cairo::RefPtr<Cairo::Surface>(new Cairo::Surface($3, false /* take reference */))')
  #m4 _CONVERSION(`cairo_surface_t*',`Cairo::RefPtr<const Cairo::Surface>',`Cairo::RefPtr<Cairo::Surface>(new Cairo::Surface($3, false /* take reference */))')

  _WRAP_METHOD(Cairo::RefPtr<Cairo::Surface> get_surface(), gtk_print_job_get_surface, errthrow)
  _WRAP_METHOD(Cairo::RefPtr<const Cairo::Surface> get_surface() const, gtk_print_job_get_surface, errthrow)

  _WRAP_METHOD(void set_track_print_status(bool track_status = true), gtk_print_job_set_track_print_status)
  _WRAP_METHOD(bool get_track_print_status() const, gtk_print_job_get_track_print_status)

  _IGNORE(gtk_print_job_send)

  /** For example, 
   * void on_print_job_complete(const Glib::RefPtr<PrintJob>& job);
   *
   * @throws exception
   */
  typedef sigc::slot< void, const Glib::RefPtr<PrintJob>& > SlotPrintJobComplete;

  /** Sends the print job off to the printer.
   * @param slot A function to call when the job completes or an error occurs.
   */
  void send(const SlotPrintJobComplete& slot);

  _WRAP_SIGNAL(void status_changed(), "status_changed")

  _WRAP_PROPERTY("title", Glib::ustring)
  _WRAP_PROPERTY("printer", Glib::RefPtr<Printer>)
  _WRAP_PROPERTY("settings", Glib::RefPtr<PrintSettings>)
  _WRAP_PROPERTY("page_setup", Glib::RefPtr<PageSetup>)
  _WRAP_PROPERTY("track-print-status", bool)
};

} // namespace Gtk
