]> git.decadent.org.uk Git - videolink.git/commitdiff
Split videolink_window into an ABC and two concrete classes for the two modes of...
authorBen Hutchings <ben@decadent.org.uk>
Sat, 2 Dec 2006 20:18:18 +0000 (20:18 +0000)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 2 Nov 2008 23:58:13 +0000 (23:58 +0000)
Removed code for disabling scroll-bars since it's redundant with a style-sheet rule.

videolink.cpp

index 74b8a21a067979a5317ba0abc9bd645558e4dc40..4e9fa6b3c27057a7f64f9ae3b0061f274e3da2c7 100644 (file)
@@ -135,15 +135,70 @@ namespace
        return video_format_none;
     }
 
+
+    class base_window : public Gtk::Window
+    {
+    public:
+       base_window(const video::frame_params & frame_params);
+
+    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)
+       : frame_params_(frame_params)
+    {
+       set_size_request(frame_params_.width, frame_params_.height);
+       set_resizable(false);
+
+       add(browser_widget_);
+       browser_widget_.show();
+
+       Glib::signal_idle().connect(SigC::slot(*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
+    {
+    public:
+       preview_window(const video::frame_params & frame_params,
+                      const std::string & main_page_uri);
+
+    private:
+       virtual void do_late_initialisation();
+
+       std::string main_page_uri_;
+    };
+
+    preview_window::preview_window(const video::frame_params & frame_params,
+                                  const std::string & main_page_uri)
+       : base_window(frame_params),
+         main_page_uri_(main_page_uri)
+    {
+    }
+
+    void preview_window::do_late_initialisation()
+    {
+       browser_widget_.load_uri(main_page_uri_);
+    }
     
-    class videolink_window : public Gtk::Window
+    class conversion_window : public base_window
     {
     public:
-       videolink_window(
-           const video::frame_params & frame_params,
-           const std::string & main_page_uri,
-           const std::string & output_dir,
-           dvd_generator::mpeg_encoder encoder);
+       conversion_window(const video::frame_params & frame_params,
+                         const std::string & main_page_uri,
+                         const std::string & output_dir,
+                         dvd_generator::mpeg_encoder encoder);
 
        bool is_finished() const;
 
@@ -154,7 +209,7 @@ namespace
        dvd_generator::pgc_ref add_title(const std::string & uri,
                                         video_format format);
        void load_next_page();
-       bool on_idle();
+       void do_late_initialisation();
        void on_net_state_change(const char * uri, gint flags, guint status);
        bool browser_is_busy() const
            {
@@ -175,9 +230,7 @@ namespace
            nsPresContext * pres_context,
            nsIDOMWindow * dom_window);
 
-       video::frame_params frame_params_;
        std::string output_dir_;
-       browser_widget browser_widget_;
 
        dvd_generator generator_;
        typedef std::map<std::string, dvd_generator::pgc_ref>
@@ -187,44 +240,35 @@ namespace
        std::queue<std::string> page_queue_;
        bool pending_window_update_;
        int pending_req_count_;
-       bool have_tweaked_page_;
        std::auto_ptr<page_state> page_state_;
 
        bool finished_;
     };
 
-    videolink_window::videolink_window(
+    conversion_window::conversion_window(
        const video::frame_params & frame_params,
        const std::string & main_page_uri,
        const std::string & output_dir,
        dvd_generator::mpeg_encoder encoder)
-           : frame_params_(frame_params),
-             output_dir_(output_dir),
-             generator_(frame_params, encoder),
-             pending_window_update_(false),
-             pending_req_count_(0),
-             have_tweaked_page_(false),
-             finished_(false)
+       : base_window(frame_params),
+         output_dir_(output_dir),
+         generator_(frame_params, encoder),
+         pending_window_update_(false),
+         pending_req_count_(0),
+         finished_(false)
     {
-       set_size_request(frame_params_.width, frame_params_.height);
-       set_resizable(false);
-
-       add(browser_widget_);
-       browser_widget_.show();
-       Glib::signal_idle().connect(
-           SigC::slot(*this, &videolink_window::on_idle));
        browser_widget_.signal_net_state().connect(
-           SigC::slot(*this, &videolink_window::on_net_state_change));
+           SigC::slot(*this, &conversion_window::on_net_state_change));
 
        add_menu(main_page_uri);
     }
 
-    bool videolink_window::is_finished() const
+    bool conversion_window::is_finished() const
     {
        return finished_;
     }
 
-    dvd_generator::pgc_ref videolink_window::add_menu(const std::string & uri)
+    dvd_generator::pgc_ref conversion_window::add_menu(const std::string & uri)
     {
        dvd_generator::pgc_ref & pgc_ref = resource_map_[uri];
        if (pgc_ref.type == dvd_generator::unknown_pgc)
@@ -235,7 +279,7 @@ namespace
        return pgc_ref;
     }
 
-    dvd_generator::pgc_ref videolink_window::add_title(const std::string & uri,
+    dvd_generator::pgc_ref conversion_window::add_title(const std::string & uri,
                                                      video_format format)
     {
        dvd_generator::pgc_ref & pgc_ref = resource_map_[uri];
@@ -274,7 +318,7 @@ namespace
        return pgc_ref;
     }
 
-    void videolink_window::load_next_page()
+    void conversion_window::load_next_page()
     {
        assert(!page_queue_.empty());
        const std::string & uri = page_queue_.front();
@@ -283,25 +327,21 @@ namespace
        browser_widget_.load_uri(uri);
     }
 
-    bool videolink_window::on_idle()
+    void conversion_window::do_late_initialisation()
     {
-       if (!output_dir_.empty())
-       {
-           // 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);
-       }
+       // 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();
-       return false; // don't call again thankyou
     }
 
-    void videolink_window::on_net_state_change(const char * uri,
-                                          gint flags, guint status)
+    void conversion_window::on_net_state_change(const char * uri,
+                                               gint flags, guint status)
     {
 #       ifdef DEBUG_ON_NET_STATE_CHANGE
-       std::cout << "videolink_window::on_net_state_change(";
+       std::cout << "conversion_window::on_net_state_change(";
        if (uri)
            std::cout << '"' << uri << '"';
        else
@@ -355,7 +395,6 @@ namespace
            && flags & GTK_MOZ_EMBED_FLAG_START)
        {
            pending_window_update_ = true;
-           have_tweaked_page_ = false;
        }
 
        if (flags & GTK_MOZ_EMBED_FLAG_IS_WINDOW
@@ -400,7 +439,7 @@ namespace
        }
     }
 
-    struct videolink_window::page_state
+    struct conversion_window::page_state
     {
        page_state(Glib::RefPtr<Gdk::Pixbuf> norm_pixbuf,
                   nsIDOMDocument * doc, int width, int height)
@@ -423,7 +462,7 @@ namespace
        bool link_changing;
     };
 
-    bool videolink_window::process()
+    bool conversion_window::process()
     {
        assert(!page_queue_.empty());
 
@@ -437,71 +476,51 @@ namespace
        nsCOMPtr<nsIDOMWindow> dom_window;
        check(browser->GetContentDOMWindow(getter_AddRefs(dom_window)));
 
-       // If we haven't done so already, disable scrollbars.
-       if (!have_tweaked_page_)
+       nsCOMPtr<nsIDOMDocument> basic_doc;
+       check(dom_window->GetDocument(getter_AddRefs(basic_doc)));
+
+       // Start or continue processing links.
+       std::auto_ptr<page_state> state(page_state_);
+       if (!state.get())
+           state.reset(
+               new page_state(
+                   get_screenshot(),
+                   basic_doc, frame_params_.width, frame_params_.height));
+       if (process_links(
+               state.get(),
+               basic_doc, pres_shell, pres_context, dom_window))
        {
-           // This actually only needs to be done once.
-           nsCOMPtr<nsIDOMBarProp> dom_bar_prop;
-           check(dom_window->GetScrollbars(getter_AddRefs(dom_bar_prop)));
-           check(dom_bar_prop->SetVisible(false));
-
-           have_tweaked_page_ = true;
-
-           // Might need to wait a while for things to load or more
-           // likely for a re-layout.
-           if (browser_is_busy())
-               return true;
+           // Save iteration state for later.
+           page_state_ = state;
        }
-
-       // All further work should only be done if we're not in preview mode.
-       if (!output_dir_.empty())
+       else
        {
-           nsCOMPtr<nsIDOMDocument> basic_doc;
-           check(dom_window->GetDocument(getter_AddRefs(basic_doc)));
-
-           // Start or continue processing links.
-           std::auto_ptr<page_state> state(page_state_);
-           if (!state.get())
-               state.reset(
-                   new page_state(
-                       get_screenshot(),
-                       basic_doc, frame_params_.width, frame_params_.height));
-           if (process_links(
-                   state.get(),
-                   basic_doc, pres_shell, pres_context, dom_window))
+           // We've finished work on the links so generate the
+           // menu VOB.
+           quantise_rgba_pixbuf(state->diff_pixbuf,
+                                dvd::button_n_colours);
+           generator_.generate_menu_vob(
+               resource_map_[page_queue_.front()].index,
+               state->norm_pixbuf, state->diff_pixbuf);
+
+           // Move on to the next page, if any, or else generate
+           // the DVD filesystem.
+           page_queue_.pop();
+           if (!page_queue_.empty())
            {
-               // Save iteration state for later.
-               page_state_ = state;
+               load_next_page();
            }
            else
            {
-               // We've finished work on the links so generate the
-               // menu VOB.
-               quantise_rgba_pixbuf(state->diff_pixbuf,
-                                    dvd::button_n_colours);
-               generator_.generate_menu_vob(
-                   resource_map_[page_queue_.front()].index,
-                   state->norm_pixbuf, state->diff_pixbuf);
-
-               // Move on to the next page, if any, or else generate
-               // the DVD filesystem.
-               page_queue_.pop();
-               if (!page_queue_.empty())
-               {
-                   load_next_page();
-               }
-               else
-               {
-                   generator_.generate(output_dir_);
-                   return false;
-               }
+               generator_.generate(output_dir_);
+               return false;
            }
        }
 
        return true;
     }
 
-    Glib::RefPtr<Gdk::Pixbuf> videolink_window::get_screenshot()
+    Glib::RefPtr<Gdk::Pixbuf> conversion_window::get_screenshot()
     {
        Glib::RefPtr<Gdk::Window> window(get_window());
        assert(window);
@@ -513,7 +532,7 @@ namespace
                                   frame_params_.width, frame_params_.height);
     }
 
-    bool videolink_window::process_links(
+    bool conversion_window::process_links(
        page_state * state,
        nsIDOMDocument * basic_doc,
        nsIPresShell * pres_shell,
@@ -922,14 +941,22 @@ int main(int argc, char ** argv)
            null_prompt_service::install();
 
        // Run the browser/converter
-       videolink_window window(frame_params, menu_url, output_dir, encoder);
-       window.show();
-       window.signal_hide().connect(SigC::slot(&Gtk::Main::quit));
-       Gtk::Main::run();
-
-       return ((preview_mode || window.is_finished())
-               ? EXIT_SUCCESS
-               : EXIT_FAILURE);
+       if (preview_mode)
+       {
+           preview_window window(frame_params, menu_url);
+           window.show();
+           window.signal_hide().connect(SigC::slot(&Gtk::Main::quit));
+           Gtk::Main::run();
+           return EXIT_SUCCESS;
+       }
+       else
+       {
+           conversion_window window(frame_params, menu_url, output_dir, encoder);
+           window.show();
+           window.signal_hide().connect(SigC::slot(&Gtk::Main::quit));
+           Gtk::Main::run();
+           return window.is_finished() ? EXIT_SUCCESS  : EXIT_FAILURE;
+       }
     }
     catch (std::exception & e)
     {