Add --config option to dcpomatic2 (#1703).
[dcpomatic.git] / src / tools / dcpomatic.cc
index dcf6d7f4909d0f826b369654935197e5170c4f88..4edfe4cd1b997afd916a9c6e81c10fdde8123f75 100644 (file)
 #include "wx/export_dialog.h"
 #include "wx/paste_dialog.h"
 #include "wx/focus_manager.h"
+#include "wx/html_dialog.h"
 #include "wx/initial_setup_dialog.h"
 #include "wx/send_i18n_dialog.h"
 #include "wx/i18n_hook.h"
 #include "lib/film.h"
+#include "lib/analytics.h"
 #include "lib/emailer.h"
 #include "lib/config.h"
 #include "lib/util.h"
@@ -87,6 +89,7 @@
 #include <wx/cmdline.h>
 #include <wx/preferences.h>
 #include <wx/splash.h>
+#include <wx/wxhtml.h>
 #ifdef __WXMSW__
 #include <shellapi.h>
 #endif
@@ -290,6 +293,8 @@ public:
                _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
                config_changed (Config::OTHER);
 
+               _analytics_message_connection = Analytics::instance()->Message.connect(boost::bind(&DOMFrame::analytics_message, this, _1, _2));
+
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_new, this),                ID_file_new);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this),               ID_file_open);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_save, this),               ID_file_save);
@@ -410,7 +415,6 @@ public:
                film->set_name (path.filename().generic_string());
                film->write_metadata ();
                set_film (film);
-               dcpomatic_log = film->log ();
        }
 
        void load_film (boost::filesystem::path file)
@@ -427,8 +431,8 @@ public:
                                );
                }
 
-               for (list<string>::const_iterator i = notes.begin(); i != notes.end(); ++i) {
-                       error_dialog (0, std_to_wx (*i));
+               BOOST_FOREACH (string i, notes) {
+                       error_dialog (0, std_to_wx(i));
                }
 
                set_film (film);
@@ -458,6 +462,7 @@ public:
                if (_film) {
                        _film->Change.connect (boost::bind (&DOMFrame::film_change, this, _1));
                        _film->Message.connect (boost::bind(&DOMFrame::film_message, this, _1));
+                       dcpomatic_log = _film->log ();
                }
        }
 
@@ -500,7 +505,7 @@ private:
                        } catch (boost::filesystem::filesystem_error& e) {
 #ifdef DCPOMATIC_WINDOWS
                                string bad_chars = "<>:\"/|?*";
-                               string const filename = d->path().string();
+                               string const filename = d->path().filename().string();
                                string found_bad_chars;
                                for (size_t i = 0; i < bad_chars.length(); ++i) {
                                        if (filename.find(bad_chars[i]) != string::npos && found_bad_chars.find(bad_chars[i]) == string::npos) {
@@ -508,9 +513,11 @@ private:
                                        }
                                }
                                wxString message = _("Could not create folder to store film.");
+                               message += "  ";
                                if (!found_bad_chars.empty()) {
-                                       message += "  ";
                                        message += wxString::Format (_("Try removing the %s characters from your folder name."), std_to_wx(found_bad_chars).data());
+                               } else {
+                                       message += _("Please check that you do not have Windows controlled folder access enabled for DCP-o-matic.");
                                }
                                error_dialog (this, message, std_to_wx(e.what()));
 #else
@@ -1031,7 +1038,7 @@ private:
                        list<string> to;
                        to.push_back ("carl@dcpomatic.com");
                        Emailer emailer (d->email(), to, "DCP-o-matic translations", body);
-                       emailer.send ("main.carlh.net", 2525);
+                       emailer.send ("main.carlh.net", 2525, EMAIL_PROTOCOL_STARTTLS);
                }
 
                d->Destroy ();
@@ -1105,6 +1112,9 @@ private:
                */
                _config_changed_connection.disconnect ();
 
+               /* Also stop hearing about analytics-related stuff */
+               _analytics_message_connection.disconnect ();
+
                ev.Skip ();
        }
 
@@ -1403,6 +1413,13 @@ private:
                _film_viewer->seek_by (_film_viewer->one_video_frame(), true);
        }
 
+       void analytics_message (string title, string html)
+       {
+               HTMLDialog* d = new HTMLDialog(this, std_to_wx(title), std_to_wx(html));
+               d->ShowModal();
+               d->Destroy();
+       }
+
        FilmEditor* _film_editor;
        boost::shared_ptr<FilmViewer> _film_viewer;
        StandardControls* _controls;
@@ -1418,6 +1435,7 @@ private:
        int _history_position;
        wxMenuItem* _history_separator;
        boost::signals2::scoped_connection _config_changed_connection;
+       boost::signals2::scoped_connection _analytics_message_connection;
        bool _update_news_requested;
        shared_ptr<Content> _clipboard;
 };
@@ -1426,6 +1444,8 @@ static const wxCmdLineEntryDesc command_line_description[] = {
        { wxCMD_LINE_SWITCH, "n", "new", "create new film", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
        { wxCMD_LINE_OPTION, "c", "content", "add content file / directory", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
        { wxCMD_LINE_OPTION, "d", "dcp", "add content DCP", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
+       { wxCMD_LINE_SWITCH, "v", "version", "show DCP-o-matic version", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
+       { wxCMD_LINE_OPTION, "", "config", "directory containing config.xml and cinemas.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
        { wxCMD_LINE_PARAM, 0, 0, "film to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
        { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
 };
@@ -1439,20 +1459,20 @@ public:
        App ()
                : wxApp ()
                , _frame (0)
+               , _splash (0)
        {}
 
 private:
 
        bool OnInit ()
        {
-               wxSplashScreen* splash = 0;
                try {
                        wxInitAllImageHandlers ();
 
                        Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
                        Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
 
-                       splash = maybe_show_splash ();
+                       _splash = maybe_show_splash ();
 
                        SetAppName (_("DCP-o-matic"));
 
@@ -1495,9 +1515,9 @@ private:
                        _frame = new DOMFrame (_("DCP-o-matic"));
                        SetTopWindow (_frame);
                        _frame->Maximize ();
-                       if (splash) {
-                               splash->Destroy ();
-                               splash = 0;
+                       if (_splash) {
+                               _splash->Destroy ();
+                               _splash = 0;
                        }
 
                        if (!Config::instance()->nagged(Config::NAG_INITIAL_SETUP)) {
@@ -1530,7 +1550,7 @@ private:
                        }
 
                        signal_manager = new wxSignalManager (this);
-                       Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
+                       Bind (wxEVT_IDLE, boost::bind (&App::idle, this, _1));
 
                        Bind (wxEVT_TIMER, boost::bind (&App::check, this));
                        _timer.reset (new wxTimer (this));
@@ -1542,8 +1562,8 @@ private:
                }
                catch (exception& e)
                {
-                       if (splash) {
-                               splash->Destroy ();
+                       if (_splash) {
+                               _splash->Destroy ();
                        }
                        error_dialog (0, wxString::Format ("DCP-o-matic could not start."), std_to_wx(e.what()));
                }
@@ -1559,6 +1579,11 @@ private:
 
        bool OnCmdLineParsed (wxCmdLineParser& parser)
        {
+               if (parser.Found (wxT("version"))) {
+                       cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
+                       exit (EXIT_SUCCESS);
+               }
+
                if (parser.GetParamCount() > 0) {
                        if (parser.Found (wxT ("new"))) {
                                _film_to_create = wx_to_std (parser.GetParam (0));
@@ -1577,11 +1602,21 @@ private:
                        _dcp_to_add = wx_to_std (dcp);
                }
 
+               wxString config;
+               if (parser.Found (wxT("config"), &config)) {
+                       State::override_path = wx_to_std (config);
+               }
+
                return true;
        }
 
        void report_exception ()
        {
+               if (_splash) {
+                       _splash->Destroy ();
+                       _splash = 0;
+               }
+
                try {
                        throw;
                } catch (FileError& e) {
@@ -1619,9 +1654,10 @@ private:
                report_exception ();
        }
 
-       void idle ()
+       void idle (wxIdleEvent& ev)
        {
                signal_manager->ui_idle ();
+               ev.Skip ();
        }
 
        void check ()
@@ -1649,6 +1685,11 @@ private:
                        return false;
                }
 
+               if (_splash) {
+                       _splash->Destroy ();
+                       _splash = 0;
+               }
+
                RecreateChainDialog* d = new RecreateChainDialog (_frame);
                int const r = d->ShowModal ();
                d->Destroy ();
@@ -1656,6 +1697,7 @@ private:
        }
 
        DOMFrame* _frame;
+       wxSplashScreen* _splash;
        shared_ptr<wxTimer> _timer;
        string _film_to_load;
        string _film_to_create;