]> git.decadent.org.uk Git - videolink.git/commitdiff
Cleaned up option processing.
authorBen Hutchings <ben@decadent.org.uk>
Sun, 27 Nov 2005 21:09:44 +0000 (21:09 +0000)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 2 Nov 2008 23:19:45 +0000 (23:19 +0000)
Changed to accept only a single URI, which is then passed to the WebDvdWindow constructor, since all pages reachable from the first URI will be included.
Removed use of "about:" as a default URI.

webdvd.cpp

index ee44118165ef52f31d85b190e5f7b2f65d804e06..a6d456a8f0de6ed9ee20dba636c7b0d14d9c1a4b 100644 (file)
@@ -133,10 +133,12 @@ namespace
     class WebDvdWindow : public Gtk::Window
     {
     public:
-       WebDvdWindow(const video::frame_params & frame_params);
-       void add_page(const std::string & uri);
+       WebDvdWindow(
+           const video::frame_params & frame_params,
+           const std::string & main_page_uri);
 
     private:
+       void add_page(const std::string & uri);
        void add_video(const std::string & uri);
        void load_next_page();
        void on_net_state_change(const char * uri, gint flags, guint status);
@@ -161,7 +163,9 @@ namespace
        std::auto_ptr<link_state> link_state_;
     };
 
-    WebDvdWindow::WebDvdWindow(const video::frame_params & frame_params)
+    WebDvdWindow::WebDvdWindow(
+       const video::frame_params & frame_params,
+       const std::string & main_page_uri)
            : frame_params_(frame_params),
              stylesheet_(load_css("file://" WEBDVD_LIB_DIR "/webdvd.css")),
              loading_(false),
@@ -172,6 +176,9 @@ namespace
        browser_widget_.show();
        browser_widget_.signal_net_state().connect(
            SigC::slot(*this, &WebDvdWindow::on_net_state_change));
+
+       add_page(main_page_uri);
+       load_next_page();
     }
 
     void WebDvdWindow::add_page(const std::string & uri)
@@ -181,8 +188,6 @@ namespace
            .second)
        {
            page_queue_.push(uri);
-           if (!loading_)
-               load_next_page();
        }
     }
 
@@ -812,24 +817,44 @@ int main(int argc, char ** argv)
        setenv("XAUTHORITY", fb.get_x_authority().c_str(), true);
        setenv("DISPLAY", fb.get_x_display().c_str(), true);
 
-       // Initialise Gtk and Mozilla
+       // Initialise Gtk
        Gtk::Main kit(argc, argv);
-       BrowserWidget::init();
            
-       WebDvdWindow window(frame_params);
+       // Check we have the right number of arguments.  We can't
+       // do this earlier because we need to let Gtk read and remove
+       // any of the many options it understands.
        int argi = 1;
-       if (std::strcmp(argv[argi], "--video-std") == 0)
-           argi += 2;
-       else if (std::strcmp(argv[argi], "--") == 0)
-           argi += 1;
-       else if (argv[argi][0] == '-')
-           throw std::runtime_error(
-               std::string("Invalid option: ").append(argv[argi]));
-       if (argi == argc)
-           window.add_page("about:");
-       else
-           for (/* no initialisation */; argi != argc; ++argi)
-               window.add_page(argv[argi]);
+       while (argi != argc)
+       {
+           if (std::strcmp(argv[argi], "--video-std") == 0)
+           {
+               argi += 2;
+           }
+           else if (std::strcmp(argv[argi], "--") == 0)
+           {
+               argi += 1;
+               break;
+           }
+           else if (argv[argi][0] == '-')
+           {
+               std::cerr << "Invalid option: " << argv[argi] << "\n";
+               return EXIT_FAILURE;
+           }
+           else
+               break;
+       }
+       if (argi != argc - 1)
+       {
+           std::cerr << "Usage: " << argv[0]
+                     << (" [gtk-options] [--video-std std-name]"
+                         "front-page-url\n");
+           return EXIT_FAILURE;
+       }
+
+       // Initialise Mozilla
+       BrowserWidget::init();
+
+       WebDvdWindow window(frame_params, argv[argi]);
        Gtk::Main::run(window);
     }
     catch (std::exception & e)