Opérations asynchrones

Par défaut, PrintOperation::run() rend la main quand l'opération d'impression est terminée. Si vous voulez lancer une opération d'impression non-bloquante, appelez PrintOperation::set_allow_async(). Notez que set_allow_async() n'est pas pris en charge sur toutes les plates-formes, bien que le signal done soit toujours émis.

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:

Par exemple,

// 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::PrintOperationResult 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
}