+ bool conversion_window::on_idle()
+ {
+ if (state_ == state_initial)
+ {
+ // Put pointer in the top-left so that no links appear in
+ // the hover state when we take a screenshot.
+ warp_pointer(get_window(),
+ -frame_params_.width, -frame_params_.height);
+
+ load_next_page();
+
+ state_ = state_processing;
+ }
+ else if (state_ == state_processing && !browser_is_busy())
+ {
+ try
+ {
+ if (!process())
+ {
+ state_ = state_finished;
+ Gtk::Main::quit();
+ }
+ }
+ catch (...)
+ {
+ // Print context of exception.
+ if (!page_queue_.empty())
+ {
+ std::cerr << "ERROR: While processing page <"
+ << page_queue_.front() << ">:\n";
+ if (page_state_.get() && !page_state_->link_target.empty())
+ std::cerr << "ERROR: While processing link to <"
+ << page_state_->link_target << ">:\n";
+ }
+
+ // Print exception message.
+ try
+ {
+ throw;
+ }
+ catch (std::exception & e)
+ {
+ std::cerr << "ERROR: " << e.what() << "\n";
+ }
+ catch (Glib::Exception & e)
+ {
+ std::cerr << "ERROR: " << e.what() << "\n";
+ }
+ catch (...)
+ {
+ std::cerr << "ERROR: Unknown exception\n";
+ }
+
+ Gtk::Main::quit();
+ }
+ }
+
+ // Call again if we're not done.
+ return state_ != state_finished;
+ }
+