Allow configuration of KDM filename format.
[dcpomatic.git] / src / tools / dcpomatic.cc
index 6b1d4d260dc3b044252ed5423502d3ca98541f2c..e29d41db7dd5d9c3175694c16f480fc2dba3e5b0 100644 (file)
@@ -58,6 +58,7 @@
 #include "lib/compose.hpp"
 #include "lib/cinema_kdms.h"
 #include "lib/dcpomatic_socket.h"
+#include "lib/hints.h"
 #include <dcp/exceptions.h>
 #include <wx/generic/aboutdlgg.h>
 #include <wx/stdpaths.h>
@@ -455,6 +456,15 @@ private:
                        }
                }
 
+               if (!get_hints(_film).empty() && Config::instance()->show_hints_before_make_dcp()) {
+                       HintsDialog* hints = new HintsDialog (this, _film, false);
+                       int const r = hints->ShowModal();
+                       hints->Destroy ();
+                       if (r == wxID_CANCEL) {
+                               return;
+                       }
+               }
+
                try {
                        /* It seems to make sense to auto-save metadata here, since the make DCP may last
                           a long time, and crashes/power failures are moderately likely.
@@ -482,20 +492,26 @@ private:
 
                try {
                        list<ScreenKDM> screen_kdms = _film->make_kdms (d->screens(), d->cpl(), d->from(), d->until(), d->formulation());
+
+                       NameFormat::Map name_values;
+                       name_values["film_name"] = _film->name();
+                       name_values["from"] = dcp::LocalTime(d->from()).date() + " " + dcp::LocalTime(d->from()).time_of_day();
+                       name_values["to"] = dcp::LocalTime(d->until()).date() + " " + dcp::LocalTime(d->until()).time_of_day();
+
                        if (d->write_to ()) {
                                ScreenKDM::write_files (
-                                       _film->name(),
                                        screen_kdms,
-                                       d->directory()
+                                       d->directory(),
+                                       d->name_format(),
+                                       name_values
                                        );
                        } else {
                                JobManager::instance()->add (
                                        shared_ptr<Job> (new SendKDMEmailJob (
-                                                                _film->name(),
-                                                                _film->dcp_name(),
-                                                                d->from(),
-                                                                d->until(),
                                                                 CinemaKDMs::collect (screen_kdms),
+                                                                d->name_format(),
+                                                                name_values,
+                                                                _film->dcp_name(),
                                                                 _film->log()
                                                                 ))
                                        );
@@ -517,6 +533,15 @@ private:
                        return;
                }
 
+               if (!get_hints(_film).empty() && Config::instance()->show_hints_before_make_dcp()) {
+                       HintsDialog* hints = new HintsDialog (this, _film, false);
+                       int const r = hints->ShowModal();
+                       hints->Destroy ();
+                       if (r == wxID_CANCEL) {
+                               return;
+                       }
+               }
+
                _film->write_metadata ();
 
                /* i = 0; try to connect via socket
@@ -663,7 +688,7 @@ private:
        void tools_hints ()
        {
                if (!_hints_dialog) {
-                       _hints_dialog = new HintsDialog (this, _film);
+                       _hints_dialog = new HintsDialog (this, _film, true);
                }
 
                _hints_dialog->Show ();
@@ -908,7 +933,7 @@ private:
                }
 
                for (size_t i = 0; i < history.size(); ++i) {
-                       SafeStringStream s;
+                       locked_stringstream s;
                        if (i < 9) {
                                s << "&" << (i + 1) << " ";
                        }
@@ -987,6 +1012,8 @@ private:
        {
                wxInitAllImageHandlers ();
 
+               Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
+
                wxSplashScreen* splash = 0;
                try {
                        if (!Config::have_existing ("config.xml")) {
@@ -1156,6 +1183,11 @@ private:
                }
        }
 
+       void config_failed_to_load ()
+       {
+               message_dialog (_frame, _("The existing configuration failed to load.  Default values will be used instead.  These may take a short time to create."));
+       }
+
        DOMFrame* _frame;
        shared_ptr<wxTimer> _timer;
        string _film_to_load;