Asynchronous operations

By default, PrintOperation::run() returns when a print operation is completed. If you need to run a non-blocking print operation, call PrintOperation::set_allow_async(). Note that set_allow_async() is not supported on all platforms, however the done signal will still be emitted.

run() may return PrintOperation::Result::IN_PROGRESS. To track status and handle the result or error you need to implement signal handlers for the done and status_changed signals:

For instance,

// in class ExampleWindow's method...
auto op = PrintOperation::create();
// ...set up op...
op->signal_done().connect(sigc::bind(sigc::mem_fun(
  *this, &ExampleWindow::on_printoperation_done), op));
// run the op

Second, check for an error and connect to the status_changed signal. For instance:

void ExampleWindow::on_printoperation_done(Gtk::PrintOperation::Result result,
  const Glib::RefPtr<PrintOperation>& op)
{
  if (result == Gtk::PrintOperation::Result::ERROR)
    //notify user
  else if (result == Gtk::PrintOperation::Result::APPLY)
    //Update PrintSettings with the ones used in this PrintOperation

  if (! op->is_finished())
    op->signal_status_changed().connect(sigc::bind(sigc::mem_fun(
      *this, &ExampleWindow::on_printoperation_status_changed), op));
}

Finally, check the status. For instance,

void ExampleWindow::on_printoperation_status_changed(const Glib::RefPtr<PrintOperation>& op)
{
  if (op->is_finished())
    //the print job is finished
  else
    //get the status with get_status() or get_status_string()

  //update UI
}