非同期オペレーション

デフォルトでは、PrintOperation::run()は印刷オペレーションが終了したときにリターンされます。もしもブロックされない印刷オペレーションが必要ならば、PrintOperation::set_allow_async()を呼んでください。注意してほしいのはset_allow_async()はプラットフォームによってはサポートされていないというということです。これに関わらずdoneシグナルは発行されます。

このとき、run()メソッドがPRINT_OPERATION_RESULT_IN_PROGRESSを返す場合があります。ステータスを追跡して、印刷完了あるいは印刷エラーに対応するためには、doneシグナルとstatus_changedシグナルに対してシグナルハンドラを実装する必要があります。

このように:

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

次に、エラーをチェックしてstatus_changedシグナルに接続します。このように:

void ExampleWindow::on_printoperation_done(Gtk::PrintOperationResult result, const Glib::RefPtr<PrintOperation>& op)
{
  if (result == Gtk::PRINT_OPERATION_RESULT_ERROR)
    //notify user
  else if (result == Gtk::PRINT_OPERATION_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));
}

最後に、ステータスをチェックします。このように:

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

  //update UI
}