]> git.decadent.org.uk Git - videolink.git/commitdiff
Added hack to treat alert prompts as fatal errors.
authorBen Hutchings <ben@decadent.org.uk>
Wed, 5 Apr 2006 23:29:37 +0000 (23:29 +0000)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 2 Nov 2008 23:39:58 +0000 (23:39 +0000)
Added flag for successful finish to webdvd_window and used it to decide the exit code.

null_prompt_service.cpp
webdvd.cpp
webdvd.hpp [new file with mode: 0644]

index c1d24be55a6ef3da5880c49ad6f7e1e14c6a9ca3..dca78103dbdb020e6cdaca48b2142e18b1395849 100644 (file)
@@ -1,11 +1,19 @@
 // Copyright 2006 Ben Hutchings <ben@decadentplace.org.uk>.
 // See the file "COPYING" for licence details.
 
+#include <string>
+
+#include <langinfo.h>
+
 #include <nsCOMPtr.h>
+#include <nsICharsetConverterManager.h>
 #include <nsIComponentManager.h>
 #include <nsIFactory.h>
+#include <nsIServiceManagerUtils.h>
+#include <nsIUnicodeEncoder.h>
 
 #include "null_prompt_service.hpp"
+#include "webdvd.hpp"
 #include "xpcom_support.hpp"
 
 using xpcom_support::check;
@@ -43,20 +51,67 @@ namespace
     {
        return NS_ERROR_NOT_IMPLEMENTED;
     }
+
+    std::string native_error_string(const PRUnichar * text)
+    {
+       std::string result;
+       PRInt32 text_len = 0;
+       while (text[text_len])
+           ++text_len;
+
+       nsCOMPtr<nsICharsetConverterManager> conv_manager;
+       nsCOMPtr<nsIUnicodeEncoder> encoder;
+       static const nsCID charset_converter_manager_cid =
+           NS_ICHARSETCONVERTERMANAGER_CID;
+       if (NS_SUCCEEDED(CallGetService<nsICharsetConverterManager>(
+                            charset_converter_manager_cid,
+                            getter_AddRefs(conv_manager)))
+           && NS_SUCCEEDED(conv_manager->GetUnicodeEncoder(
+                               nl_langinfo(CODESET),
+                               getter_AddRefs(encoder))))
+       {
+           encoder->SetOutputErrorBehavior(
+               nsIUnicodeEncoder::kOnError_Replace, NULL, PRUnichar('?'));
+
+           char buf[1000];  // Hopefully long enough for an error message
+
+           char * out = buf;
+           PRInt32 out_len = sizeof(buf);
+           encoder->Convert(text, &text_len, out, &out_len);
+           out += out_len;
+
+           out_len = sizeof(buf) - out_len;
+           encoder->Finish(out, &out_len);
+           out += out_len;
+
+           result.assign(buf, out);
+       }
+       else
+       {
+           // Convert to ASCII
+           result.resize(text_len);
+           for (PRInt32 i = 0; i != text_len; ++i)
+               result[i] = (text[i] < 0x80) ? text[i] : '?';
+       }
+
+       return result;
+    }
 }
 
 NS_IMPL_ISUPPORTS1(null_prompt_service, nsIPromptService)
 
 NS_IMETHODIMP null_prompt_service::Alert(
-    nsIDOMWindow *, const PRUnichar *, const PRUnichar *)
+    nsIDOMWindow *, const PRUnichar *, const PRUnichar * text)
 {
+    fatal_error(native_error_string(text));
     return NS_OK;
 }
 
 NS_IMETHODIMP null_prompt_service::AlertCheck(
-    nsIDOMWindow *, const PRUnichar *, const PRUnichar *, const PRUnichar *,
-    PRBool *)
+    nsIDOMWindow *, const PRUnichar *, const PRUnichar * text,
+    const PRUnichar *, PRBool *)
 {
+    fatal_error(native_error_string(text));
     return NS_OK;
 }
 
index c4cf8a95f662d35d7ab67c3e14f1a4c50b70b8f1..3c21c28dfe254997d53c819245097d591f6dfc5e 100644 (file)
@@ -154,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);
@@ -185,6 +187,8 @@ namespace
        std::auto_ptr<temp_file> background_temp_;
        struct page_state;
        std::auto_ptr<page_state> page_state_;
+
+       bool finished_;
     };
 
     webdvd_window::webdvd_window(
@@ -196,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);
@@ -210,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,
@@ -357,7 +367,10 @@ namespace
            try
            {
                if (!process_page())
+               {
+                   finished_ = true;
                    Gtk::Main::quit();
+               }
            }
            catch (std::exception & e)
            {
@@ -820,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
@@ -943,12 +962,14 @@ int main(int argc, char ** argv)
        // 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;
 }
diff --git a/webdvd.hpp b/webdvd.hpp
new file mode 100644 (file)
index 0000000..d281814
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef INC_WEBDVD_HPP
+#define INC_WEBDVD_HPP
+
+#include <string>
+
+void fatal_error(const std::string & message);
+
+#endif // !INC_WEBDVD_HPP