Asynchronní operace
Standardně se PrintOperation::run() vrací po té, co je tisková operace dokončená. Pokud potřebujete spustit neblokující tiskovou operaci, zavolejte PrintOperation::set_allow_async(). Pamatujte ale, že set_allow_async() není podporováno na všech platformách, ale signál done bude i tak vyslán.
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:
Například
// 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 }