1 // Copyright 2005-6 Ben Hutchings <ben@decadent.org.uk>.
2 // See the file "COPYING" for licence details.
18 #include <gdk/gdkkeysyms.h>
19 #include <gdkmm/pixbuf.h>
20 #include <glibmm/convert.h>
21 #include <glibmm/spawn.h>
22 #include <gtkmm/main.h>
23 #include <gtkmm/window.h>
25 #include <imglib2/ImageErrors.h>
26 #include <nsGUIEvent.h>
27 #include <nsIBoxObject.h>
28 #include <nsIContent.h>
29 #include <nsIDocShell.h>
30 #include <nsIDOMAbstractView.h>
31 #include <nsIDOMBarProp.h>
32 #include <nsIDOMDocumentEvent.h>
33 #include <nsIDOMDocumentView.h>
34 #include <nsIDOMElement.h>
35 #include <nsIDOMEventTarget.h>
36 #include <nsIDOMHTMLDocument.h>
37 #include <nsIDOMMouseEvent.h>
38 #include <nsIDOMNSDocument.h>
39 #include <nsIDOMWindow.h>
40 #include <nsIEventStateManager.h>
41 #include <nsIInterfaceRequestorUtils.h>
42 #include <nsIURI.h> // required before nsILink.h
44 #include <nsIPrefBranch.h>
45 #include <nsPresContext.h>
46 #include <nsIPrefService.h>
47 #include <nsIPresShell.h>
48 #include <nsServiceManagerUtils.h>
49 #include <nsIWebBrowser.h>
52 #include "browser_widget.hpp"
53 #include "child_iterator.hpp"
55 #include "generate_dvd.hpp"
56 #include "geometry.hpp"
57 #include "link_iterator.hpp"
58 #include "null_prompt_service.hpp"
59 #include "pixbufs.hpp"
60 #include "style_sheets.hpp"
61 #include "temp_file.hpp"
63 #include "warp_pointer.hpp"
64 #include "x_frame_buffer.hpp"
65 #include "xml_utils.hpp"
66 #include "xpcom_support.hpp"
68 using xpcom_support::check;
72 rectangle get_elem_rect(nsIDOMNSDocument * ns_doc,
77 // Start with this element's bounding box
78 nsCOMPtr<nsIBoxObject> box;
79 check(ns_doc->GetBoxObjectFor(elem, getter_AddRefs(box)));
81 check(box->GetScreenX(&result.left));
82 check(box->GetScreenY(&result.top));
83 check(box->GetWidth(&width));
84 check(box->GetHeight(&height));
85 result.right = result.left + width;
86 result.bottom = result.top + height;
88 // Merge bounding boxes of all child elements
89 for (child_iterator it = child_iterator(elem), end; it != end; ++it)
91 nsCOMPtr<nsIDOMNode> child_node(*it);
93 if (check(child_node->GetNodeType(&child_type)),
94 child_type == nsIDOMNode::ELEMENT_NODE)
96 nsCOMPtr<nsIDOMElement> child_elem(
97 do_QueryInterface(child_node));
98 result |= get_elem_rect(ns_doc, child_elem);
109 video_format_mpeg2_ps,
110 video_format_vob_list
113 video_format video_format_from_uri(const std::string & uri)
115 // FIXME: This is a bit of a hack. Perhaps we could decide
116 // later based on the MIME type determined by Mozilla?
118 const char * extension;
120 } const mapping[] = {
121 {".vob", video_format_mpeg2_ps},
122 {".mpeg", video_format_mpeg2_ps},
123 {".mpeg2", video_format_mpeg2_ps},
124 {".mpg", video_format_mpeg2_ps},
125 {".voblist", video_format_vob_list}
127 for (std::size_t i = 0;
128 i != sizeof(mapping) / sizeof(mapping[0]);
131 std::size_t ext_len = std::strlen(mapping[i].extension);
132 if (uri.size() > ext_len
133 && uri.compare(uri.size() - ext_len, ext_len,
134 mapping[i].extension) == 0)
135 return mapping[i].format;
137 return video_format_none;
141 class base_window : public Gtk::Window
144 base_window(const video::frame_params & frame_params);
147 video::frame_params frame_params_;
148 browser_widget browser_widget_;
152 virtual void do_late_initialisation() = 0;
155 base_window::base_window(const video::frame_params & frame_params)
156 : frame_params_(frame_params)
158 set_size_request(frame_params_.width, frame_params_.height);
159 set_resizable(false);
161 add(browser_widget_);
162 browser_widget_.show();
164 Glib::signal_idle().connect(
165 sigc::mem_fun(this, &base_window::on_idle));
168 bool base_window::on_idle()
170 do_late_initialisation();
171 return false; // don't call again thankyou
174 class preview_window : public base_window
177 preview_window(const video::frame_params & frame_params,
178 const std::string & main_page_uri);
181 virtual void do_late_initialisation();
182 bool on_key_press(GdkEventKey *);
184 std::string main_page_uri_;
187 preview_window::preview_window(const video::frame_params & frame_params,
188 const std::string & main_page_uri)
189 : base_window(frame_params),
190 main_page_uri_(main_page_uri)
192 signal_key_press_event().connect(
193 sigc::mem_fun(this, &preview_window::on_key_press));
196 void preview_window::do_late_initialisation()
198 browser_widget_.load_uri(main_page_uri_);
201 bool preview_window::on_key_press(GdkEventKey * event)
203 switch (event->keyval)
205 case GDK_t: // = top menu
206 browser_widget_.load_uri(main_page_uri_);
208 case GDK_q: // = quit
216 class conversion_window : public base_window
219 conversion_window(const video::frame_params & frame_params,
220 const std::string & main_page_uri,
221 const std::string & output_dir,
222 dvd_generator::mpeg_encoder encoder);
224 bool is_finished() const;
229 dvd_generator::pgc_ref add_menu(const std::string & uri);
230 dvd_generator::pgc_ref add_title(const std::string & uri,
231 video_format format);
232 void load_next_page();
233 void do_late_initialisation();
234 void on_net_state_change(const char * uri, gint flags, guint status);
235 bool browser_is_busy() const
237 return pending_window_update_ || pending_req_count_;
239 // Do as much processing as possible. Return a flag indicating
240 // whether to call again once the browser is idle.
242 // Return a Pixbuf containing a copy of the window contents.
243 Glib::RefPtr<Gdk::Pixbuf> get_screenshot();
244 // Do as much processing as possible on the page links. Return
245 // a flag indicating whether to call again once the browser is
249 nsIDOMDocument * basic_doc,
250 nsIPresShell * pres_shell,
251 nsPresContext * pres_context,
252 nsIDOMWindow * dom_window);
254 std::string output_dir_;
256 dvd_generator generator_;
257 typedef std::map<std::string, dvd_generator::pgc_ref>
259 resource_map_type resource_map_;
261 std::queue<std::string> page_queue_;
262 bool pending_window_update_;
263 int pending_req_count_;
264 std::auto_ptr<page_state> page_state_;
269 conversion_window::conversion_window(
270 const video::frame_params & frame_params,
271 const std::string & main_page_uri,
272 const std::string & output_dir,
273 dvd_generator::mpeg_encoder encoder)
274 : base_window(frame_params),
275 output_dir_(output_dir),
276 generator_(frame_params, encoder),
277 pending_window_update_(false),
278 pending_req_count_(0),
281 browser_widget_.signal_net_state().connect(
282 sigc::mem_fun(this, &conversion_window::on_net_state_change));
284 add_menu(main_page_uri);
287 bool conversion_window::is_finished() const
292 dvd_generator::pgc_ref conversion_window::add_menu(const std::string & uri)
294 dvd_generator::pgc_ref & pgc_ref = resource_map_[uri];
295 if (pgc_ref.type == dvd_generator::unknown_pgc)
297 pgc_ref = generator_.add_menu();
298 page_queue_.push(uri);
303 dvd_generator::pgc_ref conversion_window::add_title(const std::string & uri,
306 dvd_generator::pgc_ref & pgc_ref = resource_map_[uri];
308 if (pgc_ref.type == dvd_generator::unknown_pgc)
310 Glib::ustring hostname;
311 std::string path(Glib::filename_from_uri(uri, hostname));
312 // FIXME: Should check the hostname
316 // Store a reference to a linked VOB file, or the contents
317 // of a linked VOB list file.
318 if (format == video_format_mpeg2_ps)
320 if (!Glib::file_test(path, Glib::FILE_TEST_IS_REGULAR))
321 throw std::runtime_error(
322 path + " is missing or not a regular file");
327 else if (format == video_format_vob_list)
329 read_vob_list(path).swap(list);
333 assert(!"unrecognised format in add_title");
336 pgc_ref = generator_.add_title(list);
342 void conversion_window::load_next_page()
344 assert(!page_queue_.empty());
345 const std::string & uri = page_queue_.front();
346 std::cout << "loading " << uri << std::endl;
348 browser_widget_.load_uri(uri);
351 void conversion_window::do_late_initialisation()
353 // Put pointer in the top-left so that no links appear in
354 // the hover state when we take a screenshot.
355 warp_pointer(get_window(),
356 -frame_params_.width, -frame_params_.height);
361 void conversion_window::on_net_state_change(const char * uri,
362 gint flags, guint status)
364 # ifdef DEBUG_ON_NET_STATE_CHANGE
365 std::cout << "conversion_window::on_net_state_change(";
367 std::cout << '"' << uri << '"';
372 gint flags_left = flags;
373 static const struct {
377 { GTK_MOZ_EMBED_FLAG_START, "STATE_START" },
378 { GTK_MOZ_EMBED_FLAG_REDIRECTING, "STATE_REDIRECTING" },
379 { GTK_MOZ_EMBED_FLAG_TRANSFERRING, "STATE_TRANSFERRING" },
380 { GTK_MOZ_EMBED_FLAG_NEGOTIATING, "STATE_NEGOTIATING" },
381 { GTK_MOZ_EMBED_FLAG_STOP, "STATE_STOP" },
382 { GTK_MOZ_EMBED_FLAG_IS_REQUEST, "STATE_IS_REQUEST" },
383 { GTK_MOZ_EMBED_FLAG_IS_DOCUMENT, "STATE_IS_DOCUMENT" },
384 { GTK_MOZ_EMBED_FLAG_IS_NETWORK, "STATE_IS_NETWORK" },
385 { GTK_MOZ_EMBED_FLAG_IS_WINDOW, "STATE_IS_WINDOW" }
387 for (int i = 0; i != sizeof(flag_names)/sizeof(flag_names[0]); ++i)
389 if (flags & flag_names[i].value)
391 std::cout << flag_names[i].name;
392 flags_left -= flag_names[i].value;
398 std::cout << "0x" << std::setbase(16) << flags_left;
400 std::cout << ", " << "0x" << std::setbase(16) << status << ")\n";
401 # endif // DEBUG_ON_NET_STATE_CHANGE
403 if (flags & GTK_MOZ_EMBED_FLAG_IS_REQUEST)
405 if (flags & GTK_MOZ_EMBED_FLAG_START)
406 ++pending_req_count_;
408 if (flags & GTK_MOZ_EMBED_FLAG_STOP)
410 assert(pending_req_count_ != 0);
411 --pending_req_count_;
415 if (flags & GTK_MOZ_EMBED_FLAG_IS_DOCUMENT
416 && flags & GTK_MOZ_EMBED_FLAG_START)
418 pending_window_update_ = true;
421 if (flags & GTK_MOZ_EMBED_FLAG_IS_WINDOW
422 && flags & GTK_MOZ_EMBED_FLAG_STOP)
424 // Check whether the load was successful, ignoring this
426 if (status != NS_IMAGELIB_ERROR_LOAD_ABORTED)
429 pending_window_update_ = false;
432 if (!browser_is_busy())
442 catch (std::exception & e)
444 std::cerr << "Fatal error";
445 if (!page_queue_.empty())
446 std::cerr << " while processing <" << page_queue_.front()
448 std::cerr << ": " << e.what() << "\n";
451 catch (Glib::Exception & e)
453 std::cerr << "Fatal error";
454 if (!page_queue_.empty())
455 std::cerr << " while processing <" << page_queue_.front()
457 std::cerr << ": " << e.what() << "\n";
463 struct conversion_window::page_state
465 page_state(Glib::RefPtr<Gdk::Pixbuf> norm_pixbuf,
466 nsIDOMDocument * doc, int width, int height)
467 : norm_pixbuf(norm_pixbuf),
468 diff_pixbuf(Gdk::Pixbuf::create(
470 true, 8, // has_alpha, bits_per_sample
477 Glib::RefPtr<Gdk::Pixbuf> norm_pixbuf;
478 Glib::RefPtr<Gdk::Pixbuf> diff_pixbuf;
480 link_iterator links_it, links_end;
486 bool conversion_window::process()
488 assert(!page_queue_.empty());
490 nsCOMPtr<nsIWebBrowser> browser(browser_widget_.get_browser());
491 nsCOMPtr<nsIDocShell> doc_shell(do_GetInterface(browser));
493 nsCOMPtr<nsIPresShell> pres_shell;
494 check(doc_shell->GetPresShell(getter_AddRefs(pres_shell)));
495 nsCOMPtr<nsPresContext> pres_context;
496 check(doc_shell->GetPresContext(getter_AddRefs(pres_context)));
497 nsCOMPtr<nsIDOMWindow> dom_window;
498 check(browser->GetContentDOMWindow(getter_AddRefs(dom_window)));
500 nsCOMPtr<nsIDOMDocument> basic_doc;
501 check(dom_window->GetDocument(getter_AddRefs(basic_doc)));
503 // Start or continue processing links.
504 std::auto_ptr<page_state> state(page_state_);
509 basic_doc, frame_params_.width, frame_params_.height));
512 basic_doc, pres_shell, pres_context, dom_window))
514 // Save iteration state for later.
519 // We've finished work on the links so generate the
521 quantise_rgba_pixbuf(state->diff_pixbuf,
522 dvd::button_n_colours);
523 generator_.generate_menu_vob(
524 resource_map_[page_queue_.front()].index,
525 state->norm_pixbuf, state->diff_pixbuf);
527 // Move on to the next page, if any, or else generate
528 // the DVD filesystem.
530 if (!page_queue_.empty())
536 generator_.generate(output_dir_);
544 Glib::RefPtr<Gdk::Pixbuf> conversion_window::get_screenshot()
546 Glib::RefPtr<Gdk::Window> window(get_window());
548 window->process_updates(true);
550 return Gdk::Pixbuf::create(Glib::RefPtr<Gdk::Drawable>(window),
551 window->get_colormap(),
553 frame_params_.width, frame_params_.height);
556 bool conversion_window::process_links(
558 nsIDOMDocument * basic_doc,
559 nsIPresShell * pres_shell,
560 nsPresContext * pres_context,
561 nsIDOMWindow * dom_window)
563 Glib::RefPtr<Gdk::Window> window(get_window());
566 nsCOMPtr<nsIDOMNSDocument> ns_doc(do_QueryInterface(basic_doc));
568 nsCOMPtr<nsIEventStateManager> event_state_man(
569 pres_context->EventStateManager()); // does not AddRef
570 assert(event_state_man);
571 nsCOMPtr<nsIDOMDocumentEvent> event_factory(
572 do_QueryInterface(basic_doc));
573 assert(event_factory);
574 nsCOMPtr<nsIDOMDocumentView> doc_view(do_QueryInterface(basic_doc));
576 nsCOMPtr<nsIDOMAbstractView> view;
577 check(doc_view->GetDefaultView(getter_AddRefs(view)));
579 rectangle window_rect = {
580 0, 0, frame_params_.width, frame_params_.height
583 unsigned menu_index = resource_map_[page_queue_.front()].index;
585 for (/* no initialisation */;
586 state->links_it != state->links_end;
589 nsCOMPtr<nsIDOMNode> node(*state->links_it);
591 // Find the link URI and separate any fragment from it.
592 nsCOMPtr<nsILink> link(do_QueryInterface(node));
594 nsCOMPtr<nsIURI> uri_iface;
595 check(link->GetHrefURI(getter_AddRefs(uri_iface)));
596 std::string uri_and_fragment, uri, fragment;
598 nsCString uri_and_fragment_ns;
599 check(uri_iface->GetSpec(uri_and_fragment_ns));
600 uri_and_fragment.assign(uri_and_fragment_ns.BeginReading(),
601 uri_and_fragment_ns.EndReading());
603 std::size_t hash_pos = uri_and_fragment.find('#');
604 uri.assign(uri_and_fragment, 0, hash_pos);
605 if (hash_pos != std::string::npos)
606 fragment.assign(uri_and_fragment,
607 hash_pos + 1, std::string::npos);
610 // Is this a new link?
611 if (!state->link_changing)
613 // Find a rectangle enclosing the link and clip it to the
615 nsCOMPtr<nsIDOMElement> elem(do_QueryInterface(node));
617 state->link_rect = get_elem_rect(ns_doc, elem);
618 state->link_rect &= window_rect;
620 if (state->link_rect.empty())
622 std::cerr << "Ignoring invisible link to "
623 << uri_and_fragment << "\n";
627 // Check whether this is a link to a video or a page then
628 // add it to the known resources if not already seen; then
629 // add it to the menu entries.
630 dvd_generator::pgc_ref target;
631 video_format format = video_format_from_uri(uri);
632 if (format != video_format_none)
635 check(uri_iface->SchemeIs("file", &is_file));
638 std::cerr << "Links to video must use the file:"
642 target = add_title(uri, format);
644 std::strtoul(fragment.c_str(), NULL, 10);
646 else // video_format == video_format_none
648 target = add_menu(uri);
649 // TODO: If there's a fragment, work out which button
650 // is closest and set target.sub_index.
653 generator_.add_menu_entry(menu_index,
654 state->link_rect, target);
656 nsCOMPtr<nsIContent> content(do_QueryInterface(node));
658 nsCOMPtr<nsIDOMEventTarget> event_target(
659 do_QueryInterface(node));
660 assert(event_target);
662 nsCOMPtr<nsIDOMEvent> event;
663 check(event_factory->CreateEvent(
664 NS_ConvertASCIItoUTF16("MouseEvents"),
665 getter_AddRefs(event)));
666 nsCOMPtr<nsIDOMMouseEvent> mouse_event(
667 do_QueryInterface(event));
669 check(mouse_event->InitMouseEvent(
670 NS_ConvertASCIItoUTF16("mouseover"),
674 0, // detail: mouse click count
675 state->link_rect.left, // screenX
676 state->link_rect.top, // screenY
677 state->link_rect.left, // clientX
678 state->link_rect.top, // clientY
679 false, false, false, false, // qualifiers
680 0, // button: left (or primary)
681 0)); // related target
683 check(event_target->DispatchEvent(mouse_event,
685 check(event_state_man->SetContentState(content,
686 NS_EVENT_STATE_HOVER));
688 pres_shell->FlushPendingNotifications(Flush_Display);
690 // We may have to exit and wait for image loading
691 // to complete, at which point we will be called
693 if (browser_is_busy())
695 state->link_changing = true;
700 window->process_updates(true);
702 Glib::RefPtr<Gdk::Pixbuf> changed_pixbuf(
704 Glib::RefPtr<Gdk::Drawable>(window),
705 window->get_colormap(),
706 state->link_rect.left,
707 state->link_rect.top,
710 state->link_rect.right - state->link_rect.left,
711 state->link_rect.bottom - state->link_rect.top));
716 state->link_rect.left,
717 state->link_rect.top,
718 state->link_rect.right - state->link_rect.left,
719 state->link_rect.bottom - state->link_rect.top);
725 const video::frame_params & lookup_frame_params(const char * str)
728 static const char * const known_strings[] = {
734 for (std::size_t i = 0;
735 i != sizeof(known_strings)/sizeof(known_strings[0]);
737 if (std::strcmp(str, known_strings[i]) == 0)
739 ? video::frame_params_625
740 : video::frame_params_525;
741 throw std::runtime_error(
742 std::string("Invalid video standard: ").append(str));
745 void print_usage(std::ostream & stream, const char * command_name)
748 "Usage: " << command_name << " [gtk-options] [--preview]\n"
749 " [--video-std {525|525/60|NTSC|ntsc"
750 " | 625|625/50|PAL|pal}]\n"
751 " [--encoder {mjpegtools|mjpegtools-old}]\n"
752 " menu-url [output-dir]\n";
755 void set_browser_preferences()
757 nsCOMPtr<nsIPrefService> pref_service;
758 static const nsCID pref_service_cid = NS_PREFSERVICE_CID;
759 check(CallGetService<nsIPrefService>(pref_service_cid,
760 getter_AddRefs(pref_service)));
761 nsCOMPtr<nsIPrefBranch> pref_branch;
762 check(pref_service->GetBranch("", getter_AddRefs(pref_branch)));
764 // Disable IE-compatibility kluge that causes backgrounds to
765 // sometimes/usually be missing from snapshots. This is only
766 // effective from Mozilla 1.8 onward.
767 check(pref_branch->SetBoolPref(
768 "layout.fire_onload_after_image_background_loads",
771 // Set display resolution. With standard-definition video we
772 // will be fitting ~600 pixels across a screen typically
773 // ranging from 10 to 25 inches wide, for a resolution of
774 // 24-60 dpi. I therefore declare the average horizontal
775 // resolution to be 40 dpi. The vertical resolution will be
776 // slightly different but unfortunately Mozilla doesn't
777 // support non-square pixels (and neither do fontconfig or Xft
780 // The browser.display.screen_resolution preference sets the
781 // the nominal resolution for dimensions expressed in pixels.
782 // (They may be scaled!) In Mozilla 1.7 it also sets the
783 // assumed resolution of the display - hence pixel sizes are
784 // respected on-screen - but this is no longer the case in
785 // 1.8. Therefore it was renamed to layout.css.dpi in 1.8.1.
786 // In 1.8 we need to set the assumed screen resolution
787 // separately, but don't know how yet. Setting one to 40
788 // but not the other is *bad*, so currently we set neither.
791 check(pref_branch->SetIntPref("browser.display.screen_resolution",
798 void fatal_error(const std::string & message)
800 std::cerr << "Fatal error: " << message << "\n";
804 int main(int argc, char ** argv)
808 video::frame_params frame_params = video::frame_params_625;
809 bool preview_mode = false;
810 std::string menu_url;
811 std::string output_dir;
812 dvd_generator::mpeg_encoder encoder =
813 dvd_generator::mpeg_encoder_ffmpeg;
815 // Do initial option parsing. We have to do this before
816 // letting Gtk parse the arguments since we may need to spawn
821 if (std::strcmp(argv[argi], "--") == 0)
825 else if (std::strcmp(argv[argi], "--help") == 0)
827 print_usage(std::cout, argv[0]);
830 else if (std::strcmp(argv[argi], "--preview") == 0)
835 else if (std::strcmp(argv[argi], "--video-std") == 0)
837 if (argi + 1 == argc)
839 std::cerr << "Missing argument to --video-std\n";
840 print_usage(std::cerr, argv[0]);
843 frame_params = lookup_frame_params(argv[argi + 1]);
852 std::auto_ptr<x_frame_buffer> fb;
855 // Spawn Xvfb and set env variables so that Xlib will use it
856 // Use 8 bits each for RGB components, which should translate into
857 // "enough" bits for YUV components.
858 fb.reset(new x_frame_buffer(frame_params.width,
861 setenv("XAUTHORITY", fb->get_authority().c_str(), true);
862 setenv("DISPLAY", fb->get_display().c_str(), true);
866 Gtk::Main kit(argc, argv);
868 // Complete option parsing with Gtk's options out of the way.
872 if (std::strcmp(argv[argi], "--") == 0)
877 else if (std::strcmp(argv[argi], "--preview") == 0)
881 else if (std::strcmp(argv[argi], "--video-std") == 0)
885 else if (std::strcmp(argv[argi], "--save-temps") == 0)
887 temp_file::keep_all(true);
890 else if (std::strcmp(argv[argi], "--encoder") == 0)
892 if (argi + 1 == argc)
894 std::cerr << "Missing argument to --encoder\n";
895 print_usage(std::cerr, argv[0]);
898 if (std::strcmp(argv[argi + 1], "ffmpeg") == 0)
900 encoder = dvd_generator::mpeg_encoder_ffmpeg;
902 else if (std::strcmp(argv[argi + 1], "mjpegtools-old") == 0)
904 encoder = dvd_generator::mpeg_encoder_mjpegtools_old;
906 else if (std::strcmp(argv[argi + 1], "mjpegtools") == 0
907 || std::strcmp(argv[argi + 1], "mjpegtools-new") == 0)
909 encoder = dvd_generator::mpeg_encoder_mjpegtools_new;
913 std::cerr << "Invalid argument to --encoder\n";
914 print_usage(std::cerr, argv[0]);
919 else if (argv[argi][0] == '-')
921 std::cerr << "Invalid option: " << argv[argi] << "\n";
922 print_usage(std::cerr, argv[0]);
931 // Look for a starting URL or filename and (except in preview
932 // mode) an output directory after the options.
933 if (argc - argi != (preview_mode ? 1 : 2))
935 print_usage(std::cerr, argv[0]);
938 if (std::strstr(argv[argi], "://"))
940 // It appears to be an absolute URL, so use it as-is.
941 menu_url = argv[argi];
945 // Assume it's a filename. Resolve it to an absolute URL.
946 std::string path(argv[argi]);
947 if (!Glib::path_is_absolute(path))
948 path = Glib::build_filename(Glib::get_current_dir(), path);
949 menu_url = Glib::filename_to_uri(path);
952 output_dir = argv[argi + 1];
954 // Initialise Mozilla
955 browser_widget::initialiser browser_init;
956 set_browser_preferences();
957 init_agent_style_sheet("file://" VIDEOLINK_SHARE_DIR "/videolink.css");
958 init_agent_style_sheet(std::string("file://" VIDEOLINK_SHARE_DIR "/")
959 .append(frame_params.common_name).append(".css")
962 null_prompt_service::install();
964 // Run the browser/converter
967 preview_window window(frame_params, menu_url);
969 window.signal_hide().connect(sigc::ptr_fun(Gtk::Main::quit));
975 conversion_window window(frame_params, menu_url, output_dir, encoder);
977 window.signal_hide().connect(sigc::ptr_fun(Gtk::Main::quit));
979 return window.is_finished() ? EXIT_SUCCESS : EXIT_FAILURE;
982 catch (std::exception & e)
984 std::cerr << "Fatal error: " << e.what() << "\n";