Ασύγχρονες λειτουργίες
Από προεπιλογή, η PrintOperation::run() επιστρέφεται όταν η λειτουργία εκτύπωσης ολοκληρωθεί. Αν χρειάζεστε να εκτελέσετε μια μη ομαδική λειτουργία εκτύπωσης, καλέστε την PrintOperation::set_allow_async(). Σημειώστε ότι η set_allow_async() δεν υποστηρίζεται σε όλα τα λειτουργικά συστήματα, όμως το σήμα done θα εκπεμφθεί.
Η run() μπορεί να επιστρέψει την PRINT_OPERATION_RESULT_IN_PROGRESS. Για ανίχνευση της κατάστασης και χειρισμό του αποτελέσματος ή σφάλματος χρειάζεται να υλοποιηθούν οι χειριστές σήματος για τα σήματα done και 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 }