Rearrange KDM window and replace OK/Cancel with Make KDM button.
[dcpomatic.git] / src / tools / dcpomatic.cc
index 6c789632a2dff6e46c73f10fb91be54985dfe2b0..cd827016d6bd1f710a18e0268185f24d04a2c348 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>
@@ -72,7 +73,6 @@
 #endif
 #include <boost/filesystem.hpp>
 #include <boost/noncopyable.hpp>
-#include <boost/make_shared.hpp>
 #include <iostream>
 #include <fstream>
 #include <sstream>
@@ -94,7 +94,6 @@ using std::exception;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using boost::optional;
-using boost::make_shared;
 
 class FilmChangedDialog : public boost::noncopyable
 {
@@ -171,6 +170,7 @@ public:
                , _hints_dialog (0)
                , _servers_list_dialog (0)
                , _config_dialog (0)
+               , _kdm_dialog (0)
                , _file_menu (0)
                , _history_items (0)
                , _history_position (0)
@@ -277,7 +277,7 @@ public:
 
        void new_film (boost::filesystem::path path)
        {
-               shared_ptr<Film> film = make_shared<Film> (path);
+               shared_ptr<Film> film (new Film (path));
                film->write_metadata ();
                film->set_name (path.filename().generic_string());
                set_film (film);
@@ -286,7 +286,7 @@ public:
        void load_film (boost::filesystem::path file)
        try
        {
-               shared_ptr<Film> film = make_shared<Film> (file);
+               shared_ptr<Film> film (new Film (file));
                list<string> const notes = film->read_metadata ();
 
                if (film->state_version() == 4) {
@@ -457,6 +457,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.
@@ -476,41 +485,13 @@ private:
                        return;
                }
 
-               KDMDialog* d = new KDMDialog (this, _film);
-               if (d->ShowModal () != wxID_OK) {
-                       d->Destroy ();
-                       return;
+               if (_kdm_dialog) {
+                       _kdm_dialog->Destroy ();
+                       _kdm_dialog = 0;
                }
 
-               try {
-                       list<ScreenKDM> screen_kdms = _film->make_kdms (d->screens(), d->cpl(), d->from(), d->until(), d->formulation());
-                       if (d->write_to ()) {
-                               ScreenKDM::write_files (
-                                       _film->name(),
-                                       screen_kdms,
-                                       d->directory()
-                                       );
-                       } else {
-                               JobManager::instance()->add (
-                                       boost::make_shared<SendKDMEmailJob> (
-                                               _film->name(),
-                                               _film->dcp_name(),
-                                               d->from(),
-                                               d->until(),
-                                               CinemaKDMs::collect (screen_kdms),
-                                               _film->log()
-                                               )
-                                       );
-                       }
-               } catch (dcp::NotEncryptedError& e) {
-                       error_dialog (this, _("CPL's content is not encrypted."));
-               } catch (exception& e) {
-                       error_dialog (this, e.what ());
-               } catch (...) {
-                       error_dialog (this, _("An unknown exception occurred."));
-               }
-
-               d->Destroy ();
+               _kdm_dialog = new KDMDialog (this, _film);
+               _kdm_dialog->Show (this);
        }
 
        void jobs_make_dcp_batch ()
@@ -519,6 +500,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
@@ -665,7 +655,7 @@ private:
        void tools_hints ()
        {
                if (!_hints_dialog) {
-                       _hints_dialog = new HintsDialog (this, _film);
+                       _hints_dialog = new HintsDialog (this, _film, true);
                }
 
                _hints_dialog->Show ();
@@ -910,7 +900,7 @@ private:
                }
 
                for (size_t i = 0; i < history.size(); ++i) {
-                       SafeStringStream s;
+                       locked_stringstream s;
                        if (i < 9) {
                                s << "&" << (i + 1) << " ";
                        }
@@ -955,6 +945,7 @@ private:
        HintsDialog* _hints_dialog;
        ServersListDialog* _servers_list_dialog;
        wxPreferencesEditor* _config_dialog;
+       KDMDialog* _kdm_dialog;
        wxMenu* _file_menu;
        shared_ptr<Film> _film;
        int _history_items;
@@ -989,6 +980,8 @@ private:
        {
                wxInitAllImageHandlers ();
 
+               Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
+
                wxSplashScreen* splash = 0;
                try {
                        if (!Config::have_existing ("config.xml")) {
@@ -1158,6 +1151,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;