Try to make Windows console appearance a preference.
authorCarl Hetherington <cth@carlh.net>
Wed, 17 Sep 2014 23:48:13 +0000 (00:48 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 17 Sep 2014 23:48:13 +0000 (00:48 +0100)
src/lib/config.cc
src/lib/config.h
src/tools/dcpomatic.cc
src/wx/config_dialog.cc

index d624e607045349c9dc21af0d0b29b65f0f2cbd5b..2b7b81cfeec2a3b067ab482c264eeea49a30ec6b 100644 (file)
@@ -76,6 +76,9 @@ Config::Config ()
        , _check_for_test_updates (false)
        , _maximum_j2k_bandwidth (250000000)
        , _log_types (Log::TYPE_GENERAL | Log::TYPE_WARNING | Log::TYPE_ERROR)
+#ifdef DCPOMATIC_WINDOWS         
+       , _win32_console (false)
+#endif   
 {
        _allowed_dcp_frame_rates.push_back (24);
        _allowed_dcp_frame_rates.push_back (25);
@@ -219,6 +222,9 @@ Config::read ()
        _allow_any_dcp_frame_rate = f.optional_bool_child ("AllowAnyDCPFrameRate");
 
        _log_types = f.optional_number_child<int> ("LogTypes").get_value_or (Log::TYPE_GENERAL | Log::TYPE_WARNING | Log::TYPE_ERROR);
+#ifdef DCPOMATIC_WINDOWS       
+       _win32_console = f.optional_bool_child ("Win32Console").get_value_or (false);
+#endif 
 
        list<cxml::NodePtr> his = f.node_children ("History");
        for (list<cxml::NodePtr>::const_iterator i = his.begin(); i != his.end(); ++i) {
@@ -363,6 +369,9 @@ Config::write () const
        root->add_child("MaximumJ2KBandwidth")->add_child_text (raw_convert<string> (_maximum_j2k_bandwidth));
        root->add_child("AllowAnyDCPFrameRate")->add_child_text (_allow_any_dcp_frame_rate ? "1" : "0");
        root->add_child("LogTypes")->add_child_text (raw_convert<string> (_log_types));
+#ifdef DCPOMATIC_WINDOWS       
+       root->add_child("Win32Console")->add_child_text (_win32_console ? "1" : "0");
+#endif 
 
        xmlpp::Element* signer = root->add_child ("Signer");
        dcp::CertificateChain::List certs = _signer->certificates().root_to_leaf ();
index 3cc7c49c463950f8300fac0085266ae9b6df8fad..55a172d78df40ed7c62025ff60c5422c7e9406fc 100644 (file)
@@ -223,6 +223,12 @@ public:
                return _log_types;
        }
 
+#ifdef DCPOMATIC_WINDOWS       
+       bool win32_console () const {
+               return _win32_console;
+       }
+#endif 
+
        std::vector<boost::filesystem::path> history () const {
                return _history;
        }
@@ -420,6 +426,13 @@ public:
                changed ();
        }
 
+#ifdef DCPOMATIC_WINDOWS       
+       void set_win32_console (bool c) {
+               _win32_console = c;
+               changed ();
+       }
+#endif 
+
        void clear_history () {
                _history.clear ();
                changed ();
@@ -494,6 +507,9 @@ private:
        /** maximum allowed J2K bandwidth in bits per second */
        int _maximum_j2k_bandwidth;
        int _log_types;
+#ifdef DCPOMATIC_WINDOWS       
+       bool _win32_console;
+#endif 
        std::vector<boost::filesystem::path> _history;
        
        /** Singleton instance, or 0 */
index 5f6a980751c0806f8596bb0e8715884f0b2b3b3c..e429b7a9d450878594d71fe982c1558d7db92dcd 100644 (file)
@@ -144,20 +144,22 @@ public:
                , _history_position (0)
                , _history_separator (0)
        {
-#if defined(DCPOMATIC_WINDOWS) && defined(DCPOMATIC_WINDOWS_CONSOLE)
-                AllocConsole();
-               
-               HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
-               int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
-               FILE* hf_out = _fdopen(hCrt, "w");
-               setvbuf(hf_out, NULL, _IONBF, 1);
-               *stdout = *hf_out;
-               
-               HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
-               hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
-               FILE* hf_in = _fdopen(hCrt, "r");
-               setvbuf(hf_in, NULL, _IONBF, 128);
-               *stdin = *hf_in;
+#if defined(DCPOMATIC_WINDOWS)
+               if (Config::instance()->win32_console ()) {
+                       AllocConsole();
+                       
+                       HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
+                       int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
+                       FILE* hf_out = _fdopen(hCrt, "w");
+                       setvbuf(hf_out, NULL, _IONBF, 1);
+                       *stdout = *hf_out;
+                       
+                       HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
+                       hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
+                       FILE* hf_in = _fdopen(hCrt, "r");
+                       setvbuf(hf_in, NULL, _IONBF, 128);
+                       *stdin = *hf_in;
+               }
 #endif
 
                wxMenuBar* bar = new wxMenuBar;
index ada0823597957e2a9e4a969045c664bdffd710e8..8d8f44b4ecc6fa05366c05b6366ef7a925a11e30 100644 (file)
@@ -1163,6 +1163,12 @@ public:
                        table->Add (t, 0, wxALL, 6);
                }
 
+#ifdef DCPOMATIC_WINDOWS               
+               _win32_console = new wxCheckBox (panel, wxID_ANY, _("Open console window"));
+               table->Add (_win32_console, 1, wxEXPAND | wxALL);
+               table->AddSpacer (0);
+#endif         
+               
                Config* config = Config::instance ();
                
                _maximum_j2k_bandwidth->SetRange (1, 500);
@@ -1178,6 +1184,10 @@ public:
                _log_error->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&AdvancedPage::log_changed, this));
                _log_timing->SetValue (config->log_types() & Log::TYPE_TIMING);
                _log_timing->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&AdvancedPage::log_changed, this));
+#ifdef DCPOMATIC_WINDOWS
+               _win32_console->SetValue (config->win32_console());
+               _win32_console->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&AdvancedPage::win32_console_changed, this));
+#endif         
                
                return panel;
        }
@@ -1211,6 +1221,13 @@ private:
                }
                Config::instance()->set_log_types (types);
        }
+
+#ifdef DCPOMATIC_WINDOWS       
+       void win32_console_changed ()
+       {
+               Config::instance()->set_win32_console (_win32_console->GetValue ());
+       }
+#endif 
        
        wxSpinCtrl* _maximum_j2k_bandwidth;
        wxCheckBox* _allow_any_dcp_frame_rate;
@@ -1218,6 +1235,9 @@ private:
        wxCheckBox* _log_warning;
        wxCheckBox* _log_error;
        wxCheckBox* _log_timing;
+#ifdef DCPOMATIC_WINDOWS       
+       wxCheckBox* _win32_console;
+#endif 
 };
        
 wxPreferencesEditor*