Add some logging to the KDM creator.
[dcpomatic.git] / src / tools / dcpomatic_kdm.cc
index ee5e454579bfda8812f6b2e324437dd5a4c59401..7a8d7cf349d532749ba69b8cfaf217d7bc232d41 100644 (file)
 */
 
 
 */
 
 
-#include "wx/full_config_dialog.h"
 #include "wx/about_dialog.h"
 #include "wx/about_dialog.h"
-#include "wx/report_problem_dialog.h"
+#include "wx/dcpomatic_button.h"
+#include "wx/editable_list.h"
 #include "wx/file_picker_ctrl.h"
 #include "wx/file_picker_ctrl.h"
-#include "wx/wx_util.h"
-#include "wx/wx_signal_manager.h"
-#include "wx/screens_panel.h"
-#include "wx/kdm_timing_panel.h"
-#include "wx/kdm_output_panel.h"
+#include "wx/full_config_dialog.h"
 #include "wx/job_view_dialog.h"
 #include "wx/job_view_dialog.h"
-#include "wx/file_dialog_wrapper.h"
+#include "wx/kdm_output_panel.h"
+#include "wx/kdm_timing_panel.h"
+#include "wx/nag_dialog.h"
 #include "wx/new_dkdm_folder_dialog.h"
 #include "wx/new_dkdm_folder_dialog.h"
-#include "wx/editable_list.h"
+#include "wx/report_problem_dialog.h"
+#include "wx/screens_panel.h"
 #include "wx/static_text.h"
 #include "wx/static_text.h"
-#include "wx/dcpomatic_button.h"
-#include "wx/nag_dialog.h"
+#include "wx/wx_signal_manager.h"
+#include "wx/wx_util.h"
+#include "lib/cinema.h"
+#include "lib/compose.hpp"
 #include "lib/config.h"
 #include "lib/config.h"
-#include "lib/util.h"
-#include "lib/screen.h"
+#include "lib/cross.h"
+#include "lib/dcpomatic_log.h"
+#include "lib/dkdm_wrapper.h"
+#include "lib/exceptions.h"
+#include "lib/file_log.h"
 #include "lib/job_manager.h"
 #include "lib/kdm_with_metadata.h"
 #include "lib/job_manager.h"
 #include "lib/kdm_with_metadata.h"
-#include "lib/exceptions.h"
+#include "lib/screen.h"
 #include "lib/send_kdm_email_job.h"
 #include "lib/send_kdm_email_job.h"
-#include "lib/compose.hpp"
-#include "lib/cinema.h"
-#include "lib/dkdm_wrapper.h"
-#include "lib/cross.h"
+#include "lib/util.h"
 #include <dcp/encrypted_kdm.h>
 #include <dcp/decrypted_kdm.h>
 #include <dcp/exceptions.h>
 #include <dcp/encrypted_kdm.h>
 #include <dcp/decrypted_kdm.h>
 #include <dcp/exceptions.h>
-#include "lib/warnings.h"
-DCPOMATIC_DISABLE_WARNINGS
-#include <wx/wx.h>
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
+#include <wx/filepicker.h>
 #include <wx/preferences.h>
 #include <wx/splash.h>
 #include <wx/preferences.h>
 #include <wx/splash.h>
-#include <wx/filepicker.h>
-DCPOMATIC_ENABLE_WARNINGS
+#include <wx/treectrl.h>
+#include <wx/wx.h>
+LIBDCP_ENABLE_WARNINGS
 #ifdef __WXOSX__
 #include <ApplicationServices/ApplicationServices.h>
 #endif
 #ifdef __WXOSX__
 #include <ApplicationServices/ApplicationServices.h>
 #endif
@@ -68,11 +70,12 @@ DCPOMATIC_ENABLE_WARNINGS
 
 using std::exception;
 using std::list;
 
 using std::exception;
 using std::list;
-using std::string;
-using std::vector;
-using std::pair;
+using std::make_shared;
 using std::map;
 using std::map;
+using std::pair;
 using std::shared_ptr;
 using std::shared_ptr;
+using std::string;
+using std::vector;
 using boost::bind;
 using boost::optional;
 using boost::ref;
 using boost::bind;
 using boost::optional;
 using boost::ref;
@@ -92,7 +95,7 @@ class DOMFrame : public wxFrame
 {
 public:
        explicit DOMFrame (wxString const & title)
 {
 public:
        explicit DOMFrame (wxString const & title)
-               : wxFrame (0, -1, title)
+               : wxFrame (nullptr, -1, title)
                , _config_dialog (nullptr)
                , _job_view (nullptr)
        {
                , _config_dialog (nullptr)
                , _job_view (nullptr)
        {
@@ -179,8 +182,7 @@ public:
                h = new StaticText (overall_panel, _("Output"));
                h->SetFont (subheading_font);
                right->Add (h, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
                h = new StaticText (overall_panel, _("Output"));
                h->SetFont (subheading_font);
                right->Add (h, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
-               /* XXX: hard-coded non-interop here */
-               _output = new KDMOutputPanel (overall_panel, false);
+               _output = new KDMOutputPanel (overall_panel);
                right->Add (_output, 0, wxALL, DCPOMATIC_SIZER_Y_GAP);
 
                _create = new Button (overall_panel, _("Create KDMs"));
                right->Add (_output, 0, wxALL, DCPOMATIC_SIZER_Y_GAP);
 
                _create = new Button (overall_panel, _("Create KDMs"));
@@ -203,6 +205,8 @@ public:
                _export_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::export_dkdm_clicked, this));
 
                setup_sensitivity ();
                _export_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::export_dkdm_clicked, this));
 
                setup_sensitivity ();
+
+               dcpomatic_log = make_shared<FileLog>(State::write_path("kdm.log"));
        }
 
 private:
        }
 
 private:
@@ -338,7 +342,7 @@ private:
                                                begin,
                                                end,
                                                decrypted.annotation_text().get_value_or (""),
                                                begin,
                                                end,
                                                decrypted.annotation_text().get_value_or (""),
-                                               decrypted.content_title_text(),
+                                               title,
                                                dcp::LocalTime().as_string()
                                                );
 
                                                dcp::LocalTime().as_string()
                                                );
 
@@ -361,11 +365,7 @@ private:
                                        name_values['i'] = encrypted.cpl_id ();
 
                                        /* Encrypt */
                                        name_values['i'] = encrypted.cpl_id ();
 
                                        /* Encrypt */
-                                       kdms.push_back (
-                                               KDMWithMetadataPtr(
-                                                       new KDMWithMetadata(name_values, i->cinema.get(), i->cinema->emails, encrypted)
-                                                       )
-                                               );
+                                       kdms.push_back (make_shared<KDMWithMetadata>(name_values, i->cinema.get(), i->cinema->emails, encrypted));
                                }
                        }
 
                                }
                        }
 
@@ -410,9 +410,9 @@ private:
                _output->setup_sensitivity ();
                wxArrayTreeItemIds sel;
                _dkdm->GetSelections (sel);
                _output->setup_sensitivity ();
                wxArrayTreeItemIds sel;
                _dkdm->GetSelections (sel);
-               shared_ptr<DKDMGroup> group = dynamic_pointer_cast<DKDMGroup>(selected_dkdm());
-               shared_ptr<DKDM> dkdm = dynamic_pointer_cast<DKDM>(selected_dkdm());
-               _create->Enable (!_screens->screens().empty() && sel.GetCount() > 0);
+               auto group = dynamic_pointer_cast<DKDMGroup>(selected_dkdm());
+               auto dkdm = dynamic_pointer_cast<DKDM>(selected_dkdm());
+               _create->Enable (!_screens->screens().empty() && sel.GetCount() > 0 && dkdm);
                _remove_dkdm->Enable (sel.GetCount() > 0 && (!group || group->name() != "root"));
                _export_dkdm->Enable (sel.GetCount() > 0 && dkdm);
        }
                _remove_dkdm->Enable (sel.GetCount() > 0 && (!group || group->name() != "root"));
                _export_dkdm->Enable (sel.GetCount() > 0 && dkdm);
        }
@@ -458,8 +458,8 @@ private:
                                /* Decrypt the DKDM to make sure that we can */
                                dcp::DecryptedKDM dkdm(ekdm, chain->key().get());
 
                                /* Decrypt the DKDM to make sure that we can */
                                dcp::DecryptedKDM dkdm(ekdm, chain->key().get());
 
-                               shared_ptr<DKDMBase> new_dkdm(new DKDM(ekdm));
-                               auto group = dynamic_pointer_cast<DKDMGroup> (selected_dkdm ());
+                               auto new_dkdm = make_shared<DKDM>(ekdm);
+                               auto group = dynamic_pointer_cast<DKDMGroup> (selected_dkdm());
                                if (!group) {
                                        group = Config::instance()->dkdms ();
                                }
                                if (!group) {
                                        group = Config::instance()->dkdms ();
                                }
@@ -492,8 +492,8 @@ private:
        {
                auto d = new NewDKDMFolderDialog (this);
                if (d->ShowModal() == wxID_OK) {
        {
                auto d = new NewDKDMFolderDialog (this);
                if (d->ShowModal() == wxID_OK) {
-                       shared_ptr<DKDMBase> new_dkdm (new DKDMGroup (wx_to_std (d->get ())));
-                       auto parent = dynamic_pointer_cast<DKDMGroup> (selected_dkdm ());
+                       auto new_dkdm = make_shared<DKDMGroup>(wx_to_std(d->get()));
+                       auto parent = dynamic_pointer_cast<DKDMGroup>(selected_dkdm());
                        if (!parent) {
                                parent = Config::instance()->dkdms ();
                        }
                        if (!parent) {
                                parent = Config::instance()->dkdms ();
                        }
@@ -610,6 +610,7 @@ private:
        JobViewDialog* _job_view;
 };
 
        JobViewDialog* _job_view;
 };
 
+
 /** @class App
  *  @brief The magic App class for wxWidgets.
  */
 /** @class App
  *  @brief The magic App class for wxWidgets.
  */
@@ -618,12 +619,12 @@ class App : public wxApp
 public:
        App ()
                : wxApp ()
 public:
        App ()
                : wxApp ()
-               , _frame (0)
+               , _frame (nullptr)
        {}
 
 private:
 
        {}
 
 private:
 
-       bool OnInit ()
+       bool OnInit () override
        {
                wxSplashScreen* splash = nullptr;
 
        {
                wxSplashScreen* splash = nullptr;
 
@@ -674,7 +675,7 @@ private:
                        _frame->Maximize ();
                        if (splash) {
                                splash->Destroy ();
                        _frame->Maximize ();
                        if (splash) {
                                splash->Destroy ();
-                               splash = 0;
+                               splash = nullptr;
                        }
                        _frame->Show ();
 
                        }
                        _frame->Show ();
 
@@ -693,7 +694,7 @@ private:
        }
 
        /* An unhandled exception has occurred inside the main event loop */
        }
 
        /* An unhandled exception has occurred inside the main event loop */
-       bool OnExceptionInMainLoop ()
+       bool OnExceptionInMainLoop () override
        {
                try {
                        throw;
        {
                try {
                        throw;
@@ -708,10 +709,10 @@ private:
                                );
                } catch (exception& e) {
                        error_dialog (
                                );
                } catch (exception& e) {
                        error_dialog (
-                               0,
+                               nullptr,
                                wxString::Format (
                                        _("An exception occurred: %s.\n\n") + " " + REPORT_PROBLEM,
                                wxString::Format (
                                        _("An exception occurred: %s.\n\n") + " " + REPORT_PROBLEM,
-                                       std_to_wx (e.what ())
+                                       std_to_wx(e.what())
                                        )
                                );
                } catch (...) {
                                        )
                                );
                } catch (...) {
@@ -722,9 +723,9 @@ private:
                return false;
        }
 
                return false;
        }
 
-       void OnUnhandledException ()
+       void OnUnhandledException () override
        {
        {
-               error_dialog (0, _("An unknown exception occurred.") + "  " + REPORT_PROBLEM);
+               error_dialog (nullptr, _("An unknown exception occurred.") + "  " + REPORT_PROBLEM);
        }
 
        void idle ()
        }
 
        void idle ()
@@ -739,7 +740,7 @@ private:
 
        void config_warning (string m)
        {
 
        void config_warning (string m)
        {
-               message_dialog (_frame, std_to_wx (m));
+               message_dialog (_frame, std_to_wx(m));
        }
 
        DOMFrame* _frame;
        }
 
        DOMFrame* _frame;