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.
Il se peut que la fonction membre run() renvoie PRINT_OPERATION_RESULT_IN_PROGRESS. Pour suivre l'état et gérer le résultat ou une erreur, vous devez implémenter des gestionnaires pour les signaux done et status_changed :
For instance,
// 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
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::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)); }
Finally, check the status. For instance,
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 }