X-Git-Url: https://git.decadent.org.uk/gitweb/?p=videolink.git;a=blobdiff_plain;f=webdvd.cpp;h=9c26c8fb20ef13df89ffc2ab9c6ea34a57c46282;hp=8019007deb4fda978bc7533328dbbdcd28bfb169;hb=392b6372714c8c2b2bf2389b86fb8f47ef70c2ef;hpb=3fb06bde35cdcd9864329517f4548e1c5f0ad97c diff --git a/webdvd.cpp b/webdvd.cpp index 8019007..9c26c8f 100644 --- a/webdvd.cpp +++ b/webdvd.cpp @@ -1,4 +1,4 @@ -// Copyright 2005 Ben Hutchings . +// Copyright 2005-6 Ben Hutchings . // See the file "COPYING" for licence details. #include @@ -55,11 +55,13 @@ #include "dvd.hpp" #include "generate_dvd.hpp" #include "link_iterator.hpp" +#include "null_prompt_service.hpp" #include "pixbufs.hpp" #include "style_sheets.hpp" #include "temp_file.hpp" #include "video.hpp" #include "x_frame_buffer.hpp" +#include "xml_utils.hpp" #include "xpcom_support.hpp" using xpcom_support::check; @@ -144,35 +146,6 @@ namespace } - std::string xml_escape(const std::string & str) - { - std::string result; - std::size_t begin = 0; - - for (;;) - { - std::size_t end = str.find_first_of("\"&'<>", begin); - result.append(str, begin, end - begin); - if (end == std::string::npos) - return result; - - const char * entity = NULL; - switch (str[end]) - { - case '"': entity = """; break; - case '&': entity = "&"; break; - case '\'': entity = "'"; break; - case '<': entity = "<"; break; - case '>': entity = ">"; break; - } - assert(entity); - result.append(entity); - - begin = end + 1; - } - } - - class webdvd_window : public Gtk::Window { public: @@ -181,6 +154,8 @@ namespace const std::string & main_page_uri, const std::string & output_dir); + bool is_finished() const; + private: dvd_contents::pgc_ref add_menu(const std::string & uri); dvd_contents::pgc_ref add_title(const std::string & uri); @@ -212,6 +187,8 @@ namespace std::auto_ptr background_temp_; struct page_state; std::auto_ptr page_state_; + + bool finished_; }; webdvd_window::webdvd_window( @@ -223,7 +200,8 @@ namespace stylesheet_(load_css("file://" WEBDVD_LIB_DIR "/webdvd.css")), pending_window_update_(false), pending_req_count_(0), - have_tweaked_page_(false) + have_tweaked_page_(false), + finished_(false) { set_size_request(frame_params_.width, frame_params_.height); set_resizable(false); @@ -237,6 +215,11 @@ namespace load_next_page(); } + bool webdvd_window::is_finished() const + { + return finished_; + } + dvd_contents::pgc_ref webdvd_window::add_menu(const std::string & uri) { dvd_contents::pgc_ref next_menu(dvd_contents::menu_pgc, @@ -270,32 +253,30 @@ namespace else { Glib::ustring hostname; - std::string filename(Glib::filename_from_uri(uri, hostname)); + std::string path(Glib::filename_from_uri(uri, hostname)); // FIXME: Should check the hostname - std::string vob_list; + vob_list list; // Store a reference to a linked VOB file, or the contents // of a linked VOB list file. - if (filename.compare(filename.size() - 4, 4, ".vob") == 0) + if (path.compare(path.size() - 4, 4, ".vob") == 0) { - if (!Glib::file_test(filename, Glib::FILE_TEST_IS_REGULAR)) + if (!Glib::file_test(path, Glib::FILE_TEST_IS_REGULAR)) throw std::runtime_error( - filename + " is missing or not a regular file"); - vob_list - .append("\n"); + path + " is missing or not a regular file"); + vob_ref ref; + ref.file = path; + list.push_back(ref); } else { - assert(filename.compare(filename.size() - 8, 8, ".voblist") - == 0); - // TODO: Validate the file contents - vob_list.assign(Glib::file_get_contents(filename)); + assert(path.compare(path.size() - 8, 8, ".voblist") == 0); + read_vob_list(path).swap(list); } - contents_.titles.push_back(dvd_contents::title(vob_list)); + contents_.titles.resize(contents_.titles.size() + 1); + contents_.titles.back().swap(list); return next_title; } } @@ -386,7 +367,10 @@ namespace try { if (!process_page()) + { + finished_ = true; Gtk::Main::quit(); + } } catch (std::exception & e) { @@ -849,6 +833,12 @@ namespace } // namespace +void fatal_error(const std::string & message) +{ + std::cerr << "Fatal error: " << message << "\n"; + Gtk::Main::quit(); +} + int main(int argc, char ** argv) { try @@ -928,6 +918,11 @@ int main(int argc, char ** argv) { argi += 2; } + else if (std::strcmp(argv[argi], "--save-temps") == 0) + { + temp_file::keep_all(true); + argi += 1; + } else if (argv[argi][0] == '-') { std::cerr << "Invalid option: " << argv[argi] << "\n"; @@ -966,16 +961,20 @@ int main(int argc, char ** argv) // Initialise Mozilla browser_widget::initialiser browser_init; set_browser_preferences(); + if (!preview_mode) + null_prompt_service::install(); // Run the browser/converter webdvd_window window(frame_params, menu_url, output_dir); Gtk::Main::run(window); + + return ((preview_mode || window.is_finished()) + ? EXIT_SUCCESS + : EXIT_FAILURE); } catch (std::exception & e) { std::cerr << "Fatal error: " << e.what() << "\n"; return EXIT_FAILURE; } - - return EXIT_SUCCESS; }