From 3d5328647308bc46480d7fb584e0929c9bbd1aa6 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Sat, 7 Jul 2007 16:18:54 +0000 Subject: [PATCH] Deferred processing from net_state signal to following idle signal, which seems to fix a problem of background screenshots being taken too early. --- videolink.cpp | 133 ++++++++++++++++++++++++-------------------------- 1 file changed, 65 insertions(+), 68 deletions(-) diff --git a/videolink.cpp b/videolink.cpp index 112125a..2ad703a 100644 --- a/videolink.cpp +++ b/videolink.cpp @@ -146,10 +146,6 @@ namespace protected: video::frame_params frame_params_; browser_widget browser_widget_; - - private: - bool on_idle(); - virtual void do_late_initialisation() = 0; }; base_window::base_window(const video::frame_params & frame_params) @@ -160,15 +156,6 @@ namespace add(browser_widget_); browser_widget_.show(); - - Glib::signal_idle().connect( - sigc::mem_fun(this, &base_window::on_idle)); - } - - bool base_window::on_idle() - { - do_late_initialisation(); - return false; // don't call again thankyou } class preview_window : public base_window @@ -178,7 +165,7 @@ namespace const std::string & main_page_uri); private: - virtual void do_late_initialisation(); + bool on_idle(); bool on_key_press(GdkEventKey *); std::string main_page_uri_; @@ -189,13 +176,16 @@ namespace : base_window(frame_params), main_page_uri_(main_page_uri) { + Glib::signal_idle().connect( + sigc::mem_fun(this, &preview_window::on_idle)); signal_key_press_event().connect( sigc::mem_fun(this, &preview_window::on_key_press)); } - void preview_window::do_late_initialisation() + bool preview_window::on_idle() { browser_widget_.load_uri(main_page_uri_); + return false; // don't call again } bool preview_window::on_key_press(GdkEventKey * event) @@ -230,15 +220,12 @@ namespace dvd_generator::pgc_ref add_title(const std::string & uri, video_format format); void load_next_page(); - void do_late_initialisation(); + bool on_idle(); void on_net_state_change(const char * uri, gint flags, guint status); bool browser_is_busy() const { return pending_window_update_ || pending_req_count_; } - // Try to do as much processing as possible. Quit if done; - // report and quit if an exception occurs. - void try_process(); // Do as much processing as possible. Return a flag indicating // whether to call again once the browser is idle. bool process(); @@ -256,6 +243,12 @@ namespace std::string output_dir_; + enum { + state_initial, + state_processing, + state_finished + } state_; + dvd_generator generator_; typedef std::map resource_map_type; @@ -265,8 +258,6 @@ namespace bool pending_window_update_; int pending_req_count_; std::auto_ptr page_state_; - - bool finished_; }; conversion_window::conversion_window( @@ -276,11 +267,13 @@ namespace dvd_generator::mpeg_encoder encoder) : base_window(frame_params), output_dir_(output_dir), + state_(state_initial), generator_(frame_params, encoder), pending_window_update_(false), - pending_req_count_(0), - finished_(false) + pending_req_count_(0) { + Glib::signal_idle().connect( + sigc::mem_fun(this, &conversion_window::on_idle)); browser_widget_.signal_net_state().connect( sigc::mem_fun(this, &conversion_window::on_net_state_change)); @@ -289,7 +282,7 @@ namespace bool conversion_window::is_finished() const { - return finished_; + return state_ == state_finished; } dvd_generator::pgc_ref conversion_window::add_menu(const std::string & uri) @@ -351,16 +344,6 @@ namespace browser_widget_.load_uri(uri); } - void conversion_window::do_late_initialisation() - { - // 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(); - } - void conversion_window::on_net_state_change(const char * uri, gint flags, guint status) { @@ -431,9 +414,6 @@ namespace pending_window_update_ = false; } - - if (!browser_is_busy()) - try_process(); } struct conversion_window::page_state @@ -460,48 +440,65 @@ namespace bool link_changing; }; - void conversion_window::try_process() + bool conversion_window::on_idle() { - try + if (state_ == state_initial) { - if (!process()) - { - finished_ = true; - Gtk::Main::quit(); - } + // 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; } - catch (...) + else if (state_ == state_processing && !browser_is_busy()) { - // 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"; + if (!process()) + { + state_ = state_finished; + Gtk::Main::quit(); + } } catch (...) { - std::cerr << "ERROR: Unknown exception\n"; - } + // 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"; + } - Gtk::Main::quit(); + // 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; } bool conversion_window::process() -- 2.39.5