Emit no audio from DCPs if none is mapped
[dcpomatic.git] / src / tools / dcpomatic.cc
index 0ed65da8d82291721eac8a2b50355554cf63d9ba..584ebd27ddc7f4d0804d233db88622f53a0df56c 100644 (file)
@@ -36,7 +36,9 @@
 #include "wx/full_config_dialog.h"
 #include "wx/hints_dialog.h"
 #include "wx/html_dialog.h"
+#include "wx/file_dialog.h"
 #include "wx/i18n_hook.h"
+#include "wx/id.h"
 #include "wx/job_manager_view.h"
 #include "wx/kdm_dialog.h"
 #include "wx/nag_dialog.h"
@@ -45,7 +47,6 @@
 #include "wx/report_problem_dialog.h"
 #include "wx/save_template_dialog.h"
 #include "wx/self_dkdm_dialog.h"
-#include "wx/send_i18n_dialog.h"
 #include "wx/servers_list_dialog.h"
 #include "wx/standard_controls.h"
 #include "wx/system_information_dialog.h"
@@ -69,7 +70,7 @@
 #include "lib/dcpomatic_log.h"
 #include "lib/dcpomatic_socket.h"
 #include "lib/dkdm_wrapper.h"
-#include "lib/emailer.h"
+#include "lib/email.h"
 #include "lib/encode_server_finder.h"
 #include "lib/exceptions.h"
 #include "lib/ffmpeg_encoder.h"
@@ -91,6 +92,7 @@
 #include "lib/version.h"
 #include "lib/video_content.h"
 #include <dcp/exceptions.h>
+#include <dcp/filesystem.h>
 #include <dcp/raw_convert.h>
 #include <dcp/warnings.h>
 LIBDCP_DISABLE_WARNINGS
@@ -210,7 +212,7 @@ private:
 map<wxMenuItem*, int> menu_items;
 
 enum {
-       ID_file_new = 1,
+       ID_file_new = DCPOMATIC_MAIN_MENU,
        ID_file_open,
        ID_file_save,
        ID_file_save_as_template,
@@ -218,7 +220,7 @@ enum {
        ID_file_duplicate_and_open,
        ID_file_history,
        /* Allow spare IDs after _history for the recent files list */
-       ID_file_close = 100,
+       ID_file_close = DCPOMATIC_MAIN_MENU + 100,
        ID_edit_copy,
        ID_edit_paste,
        ID_edit_select_all,
@@ -238,10 +240,10 @@ enum {
        ID_tools_encoding_servers,
        ID_tools_manage_templates,
        ID_tools_check_for_updates,
-       ID_tools_send_translations,
        ID_tools_system_information,
        ID_tools_restore_default_preferences,
        ID_tools_export_preferences,
+       ID_tools_import_preferences,
        ID_help_report_a_problem,
        /* IDs for shortcuts (with no associated menu item) */
        ID_add_file,
@@ -349,10 +351,10 @@ public:
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_encoding_servers, this),  ID_tools_encoding_servers);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_manage_templates, this),  ID_tools_manage_templates);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
-               Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_send_translations, this), ID_tools_send_translations);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this),ID_tools_system_information);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_restore_default_preferences, this), ID_tools_restore_default_preferences);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_export_preferences, this), ID_tools_export_preferences);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_import_preferences, this), ID_tools_import_preferences);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this),              wxID_ABOUT);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this),   ID_help_report_a_problem);
 
@@ -475,7 +477,7 @@ public:
        }
        catch (FileNotFoundError& e) {
                auto const dir = e.file().parent_path();
-               if (boost::filesystem::exists(dir / "ASSETMAP") || boost::filesystem::exists(dir / "ASSETMAP.xml")) {
+               if (dcp::filesystem::exists(dir / "ASSETMAP") || dcp::filesystem::exists(dir / "ASSETMAP.xml")) {
                        error_dialog (
                                this, _("Could not open this folder as a DCP-o-matic project."),
                                _("It looks like you are trying to open a DCP.  File -> Open is for loading DCP-o-matic projects, not DCPs.  To import a DCP, create a new project with File -> New and then click the \"Add DCP...\" button.")
@@ -755,13 +757,31 @@ private:
 
        void tools_export_preferences ()
        {
-               wxFileDialog dialog(
-                       this, _("Specify ZIP file"), wxEmptyString, wxT("dcpomatic_config.zip"), wxT("ZIP files (*.zip)|*.zip"),
-                       wxFD_SAVE | wxFD_OVERWRITE_PROMPT
+               FileDialog dialog(
+                       this, _("Specify ZIP file"), wxT("ZIP files (*.zip)|*.zip"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT, "Preferences", string("dcpomatic_config.zip")
                        );
 
                if (dialog.ShowModal() == wxID_OK) {
-                       save_all_config_as_zip(wx_to_std(dialog.GetPath()));
+                       auto const path = boost::filesystem::path(wx_to_std(dialog.GetPath()));
+                       if (boost::filesystem::exists(path)) {
+                               boost::system::error_code ec;
+                               boost::filesystem::remove(path, ec);
+                               if (ec) {
+                                       error_dialog(nullptr, _("Could not remove existing preferences file"), std_to_wx(path.string()));
+                                       return;
+                               }
+                       }
+
+                       save_all_config_as_zip(path);
+               }
+       }
+
+       void tools_import_preferences()
+       {
+               FileDialog dialog(this, _("Specify ZIP file"), wxT("ZIP files (*.zip)|*.zip"), wxFD_OPEN, "Preferences");
+
+               if (dialog.show()) {
+                       Config::instance()->load_from_zip(dialog.path());
                }
        }
 
@@ -803,11 +823,11 @@ private:
 
                /* Remove any existing DCP if the user agrees */
                auto const dcp_dir = _film->dir (_film->dcp_name(), false);
-               if (boost::filesystem::exists(dcp_dir)) {
+               if (dcp::filesystem::exists(dcp_dir)) {
                        if (!confirm_dialog (this, wxString::Format (_("Do you want to overwrite the existing DCP %s?"), std_to_wx(dcp_dir.string()).data()))) {
                                return;
                        }
-                       boost::filesystem::remove_all (dcp_dir);
+                       dcp::filesystem::remove_all(dcp_dir);
                }
 
                try {
@@ -981,7 +1001,7 @@ private:
                        return;
                }
 
-               if (boost::filesystem::exists(dialog.path())) {
+               if (dcp::filesystem::exists(dialog.path())) {
                        bool ok = confirm_dialog(
                                        this,
                                        wxString::Format(_("File %s already exists.  Do you want to overwrite it?"), std_to_wx(dialog.path().string()).data())
@@ -1084,35 +1104,6 @@ private:
                UpdateChecker::instance()->run();
        }
 
-       void tools_send_translations ()
-       {
-               SendI18NDialog dialog(this);
-               if (dialog.ShowModal() != wxID_OK) {
-                       return;
-               }
-
-               string body;
-               body += dialog.name() + "\n";
-               body += dialog.language() + "\n";
-               body += string(dcpomatic_version) + " " + string(dcpomatic_git_commit) + "\n";
-               body += "--\n";
-               auto translations = I18NHook::translations ();
-               for (auto i: translations) {
-                       body += i.first + "\n" + i.second + "\n\n";
-               }
-               if (dialog.email().find("@") == string::npos) {
-                       error_dialog (this, _("You must enter a valid email address when sending translations, "
-                                             "otherwise the DCP-o-matic maintainers cannot credit you or contact you with questions."));
-               } else {
-                       Emailer emailer(dialog.email(), { "carl@dcpomatic.com" }, "DCP-o-matic translations", body);
-                       try {
-                               emailer.send ("main.carlh.net", 2525, EmailProtocol::STARTTLS);
-                       } catch (NetworkError& e) {
-                               error_dialog (this, _("Could not send translations"), std_to_wx(e.what()));
-                       }
-               }
-       }
-
        void help_about ()
        {
                AboutDialog dialog(this);
@@ -1332,7 +1323,7 @@ private:
                add_item (edit, _("Select all\tShift-Ctrl-A"), ID_edit_select_all, NEEDS_FILM);
 
 #ifdef __WXOSX__
-               add_item (_file_menu, _("&Preferences...\tCtrl-P"), wxID_PREFERENCES, ALWAYS);
+               add_item(_file_menu, _("&Preferences...\tCtrl-,"), wxID_PREFERENCES, ALWAYS);
 #else
                edit->AppendSeparator ();
                /* [Shortcut] Ctrl+P:Open preferences window */
@@ -1376,12 +1367,12 @@ private:
                add_item (tools, _("Encoding servers..."), ID_tools_encoding_servers, 0);
                add_item (tools, _("Manage templates..."), ID_tools_manage_templates, 0);
                add_item (tools, _("Check for updates"), ID_tools_check_for_updates, 0);
-               add_item (tools, _("Send translations..."), ID_tools_send_translations, 0);
                add_item (tools, _("System information..."), ID_tools_system_information, 0);
                tools->AppendSeparator ();
                add_item (tools, _("Restore default preferences"), ID_tools_restore_default_preferences, ALWAYS);
                tools->AppendSeparator ();
                add_item (tools, _("Export preferences..."), ID_tools_export_preferences, ALWAYS);
+               add_item (tools, _("Import preferences..."), ID_tools_import_preferences, ALWAYS);
 
                wxMenu* help = new wxMenu;
 #ifdef __WXOSX__
@@ -1402,7 +1393,8 @@ private:
        void config_changed (Config::Property what)
        {
                /* Instantly save any config changes when using the DCP-o-matic GUI */
-               if (what == Config::CINEMAS) {
+               switch (what) {
+               case Config::CINEMAS:
                        try {
                                Config::instance()->write_cinemas();
                        } catch (exception& e) {
@@ -1414,7 +1406,21 @@ private:
                                                )
                                        );
                        }
-               } else {
+                       break;
+               case Config::DKDM_RECIPIENTS:
+                       try {
+                               Config::instance()->write_dkdm_recipients();
+                       } catch (exception& e) {
+                               error_dialog (
+                                       this,
+                                       wxString::Format (
+                                               _("Could not write to DKDM recipients file at %s.  Your changes have not been saved."),
+                                               std_to_wx(Config::instance()->dkdm_recipients_file().string()).data()
+                                               )
+                                       );
+                       }
+                       break;
+               default:
                        try {
                                Config::instance()->write_config();
                        } catch (exception& e) {
@@ -1581,6 +1587,7 @@ public:
        App ()
                : wxApp ()
        {
+               dcpomatic_setup_path_encoding ();
 #ifdef DCPOMATIC_LINUX
                XInitThreads ();
 #endif
@@ -1633,8 +1640,6 @@ private:
                        make_foreground_application ();
 #endif
 
-                       dcpomatic_setup_path_encoding ();
-
                        /* Enable i18n; this will create a Config object
                           to look for a force-configured language.  This Config
                           object will be wrong, however, because dcpomatic_setup
@@ -1676,7 +1681,7 @@ private:
                        signal_manager = new wxSignalManager (this);
                        Bind (wxEVT_IDLE, boost::bind (&App::idle, this, _1));
 
-                       if (!_film_to_load.empty() && boost::filesystem::is_directory(_film_to_load)) {
+                       if (!_film_to_load.empty() && dcp::filesystem::is_directory(_film_to_load)) {
                                try {
                                        _frame->load_film (_film_to_load);
                                } catch (exception& e) {
@@ -1909,6 +1914,19 @@ private:
                        }
                        return true;
                }
+               case Config::BAD_SIGNER_DN_QUALIFIER:
+               {
+                       RecreateChainDialog dialog(
+                               _frame, _("Recreate signing certificates"),
+                               _("The certificate chain that DCP-o-matic uses for signing DCPs and KDMs contains a small error\n"
+                                 "which will prevent DCPs from being validated correctly on some systems.  This error was caused\n"
+                                 "by a bug in DCP-o-matic which has now been fixed. Do you want to re-create the certificate chain\n"
+                                 "for signing DCPs and KDMs?"),
+                               _("Do nothing"),
+                               Config::NAG_BAD_SIGNER_DN_QUALIFIER
+                               );
+                       return dialog.ShowModal() == wxID_OK;
+               }
                default:
                        DCPOMATIC_ASSERT (false);
                }