Tidy and fix logging.
[dcpomatic.git] / src / tools / dcpomatic.cc
index a2b55691ed6557f9517097a9a7eebf09a9b9a311..bd0c40e889d9c977d543766fb75d4255063cfc02 100644 (file)
@@ -22,6 +22,7 @@
  *  @brief The main DCP-o-matic GUI.
  */
 
+#include "wx/controls.h"
 #include "wx/film_viewer.h"
 #include "wx/film_editor.h"
 #include "wx/job_manager_view.h"
@@ -45,6 +46,7 @@
 #include "wx/export_dialog.h"
 #include "wx/paste_dialog.h"
 #include "wx/focus_manager.h"
+#include "wx/initial_setup_dialog.h"
 #include "lib/film.h"
 #include "lib/config.h"
 #include "lib/util.h"
@@ -53,6 +55,7 @@
 #include "lib/version.h"
 #include "lib/signal_manager.h"
 #include "lib/log.h"
+#include "lib/screen.h"
 #include "lib/job_manager.h"
 #include "lib/exceptions.h"
 #include "lib/cinema.h"
@@ -71,7 +74,9 @@
 #include "lib/transcode_job.h"
 #include "lib/dkdm_wrapper.h"
 #include "lib/audio_content.h"
+#include "lib/check_content_change_job.h"
 #include "lib/text_content.h"
+#include "lib/dcpomatic_log.h"
 #include <dcp/exceptions.h>
 #include <dcp/raw_convert.h>
 #include <wx/generic/aboutdlgg.h>
@@ -88,6 +93,7 @@
 #include <boost/filesystem.hpp>
 #include <boost/noncopyable.hpp>
 #include <boost/foreach.hpp>
+#include <boost/algorithm/string.hpp>
 #include <iostream>
 #include <fstream>
 /* This is OK as it's only used with DCPOMATIC_WINDOWS */
@@ -111,6 +117,8 @@ using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using boost::optional;
 using boost::function;
+using boost::is_any_of;
+using boost::algorithm::find;
 using dcp::raw_convert;
 
 class FilmChangedClosingDialog : public boost::noncopyable
@@ -315,12 +323,14 @@ public:
                */
                wxPanel* overall_panel = new wxPanel (this, wxID_ANY);
 
-               _film_viewer = new FilmViewer (overall_panel);
+               _film_viewer.reset (new FilmViewer (overall_panel));
+               _controls = new Controls (overall_panel, _film_viewer);
                _film_editor = new FilmEditor (overall_panel, _film_viewer);
                JobManagerView* job_manager_view = new JobManagerView (overall_panel, false);
 
                wxBoxSizer* right_sizer = new wxBoxSizer (wxVERTICAL);
-               right_sizer->Add (_film_viewer, 2, wxEXPAND | wxALL, 6);
+               right_sizer->Add (_film_viewer->panel(), 2, wxEXPAND | wxALL, 6);
+               right_sizer->Add (_controls, 0, wxEXPAND | wxALL, 6);
                right_sizer->Add (job_manager_view, 1, wxEXPAND | wxALL, 6);
 
                wxBoxSizer* main_sizer = new wxBoxSizer (wxHORIZONTAL);
@@ -393,6 +403,7 @@ 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)
@@ -414,6 +425,8 @@ public:
                }
 
                set_film (film);
+
+               JobManager::instance()->add(shared_ptr<Job>(new CheckContentChangeJob(film)));
        }
        catch (std::exception& e) {
                wxString p = std_to_wx (file.string ());
@@ -434,7 +447,7 @@ public:
                if (_film->directory()) {
                        Config::instance()->add_to_history (_film->directory().get());
                }
-               _film->Changed.connect (boost::bind (&DOMFrame::set_menu_sensitivity, this));
+               _film->Change.connect (boost::bind (&DOMFrame::film_change, this, _1));
        }
 
        shared_ptr<Film> film () const {
@@ -443,6 +456,13 @@ public:
 
 private:
 
+       void film_change (ChangeType type)
+       {
+               if (type == CHANGE_TYPE_DONE) {
+                       set_menu_sensitivity ();
+               }
+       }
+
        void file_changed (boost::filesystem::path f)
        {
                string s = wx_to_std (_("DCP-o-matic"));
@@ -462,7 +482,24 @@ private:
                        try {
                                new_film (d->path(), d->template_name());
                        } catch (boost::filesystem::filesystem_error& e) {
-                               error_dialog (this, _("Could not create folder to store film"), std_to_wx(e.what()));
+#ifdef DCPOMATIC_WINDOWS
+                               string bad_chars = "<>:\"/|?*";
+                               string const filename = d->path().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) {
+                                               found_bad_chars += bad_chars[i];
+                                       }
+                               }
+                               wxString message = _("Could not create folder to store film.");
+                               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());
+                               }
+                               error_dialog (this, message, std_to_wx(e.what()));
+#else
+                               error_dialog (this, _("Could not create folder to store film."), std_to_wx(e.what()));
+#endif
                        }
                }
 
@@ -567,7 +604,7 @@ private:
        {
                DCPOMATIC_ASSERT (_clipboard);
 
-               PasteDialog* d = new PasteDialog (this, static_cast<bool>(_clipboard->video), static_cast<bool>(_clipboard->audio), !_clipboard->caption.empty());
+               PasteDialog* d = new PasteDialog (this, static_cast<bool>(_clipboard->video), static_cast<bool>(_clipboard->audio), !_clipboard->text.empty());
                if (d->ShowModal() == wxID_OK) {
                        BOOST_FOREACH (shared_ptr<Content> i, _film_editor->content_panel()->selected()) {
                                if (d->video() && i->video) {
@@ -579,10 +616,10 @@ private:
                                        i->audio->take_settings_from (_clipboard->audio);
                                }
 
-                               if (d->caption()) {
-                                       list<shared_ptr<TextContent> >::iterator j = i->caption.begin ();
-                                       list<shared_ptr<TextContent> >::const_iterator k = _clipboard->caption.begin ();
-                                       while (j != i->caption.end() && k != _clipboard->caption.end()) {
+                               if (d->text()) {
+                                       list<shared_ptr<TextContent> >::iterator j = i->text.begin ();
+                                       list<shared_ptr<TextContent> >::const_iterator k = _clipboard->text.begin ();
+                                       while (j != i->text.end() && k != _clipboard->text.end()) {
                                                (*j)->take_settings_from (*k);
                                                ++j;
                                                ++k;
@@ -636,7 +673,7 @@ private:
                        }
                }
 
-               if (!get_hints(_film).empty() && Config::instance()->show_hints_before_make_dcp()) {
+               if (Config::instance()->show_hints_before_make_dcp()) {
                        HintsDialog* hints = new HintsDialog (this, _film, false);
                        int const r = hints->ShowModal();
                        hints->Destroy ();
@@ -735,7 +772,7 @@ private:
                        return;
                }
 
-               if (!get_hints(_film).empty() && Config::instance()->show_hints_before_make_dcp()) {
+               if (Config::instance()->show_hints_before_make_dcp()) {
                        HintsDialog* hints = new HintsDialog (this, _film, false);
                        int const r = hints->ShowModal();
                        hints->Destroy ();
@@ -789,7 +826,7 @@ private:
                try {
                        kdm = _film->make_kdm (
                                Config::instance()->decryption_chain()->leaf(),
-                               vector<dcp::Certificate> (),
+                               vector<string>(),
                                d->cpl (),
                                dcp::LocalTime ("2012-01-01T01:00:00+00:00"),
                                dcp::LocalTime ("2112-01-01T01:00:00+00:00"),
@@ -824,7 +861,11 @@ private:
                ExportDialog* d = new ExportDialog (this);
                if (d->ShowModal() == wxID_OK) {
                        shared_ptr<TranscodeJob> job (new TranscodeJob (_film));
-                       job->set_encoder (shared_ptr<FFmpegEncoder> (new FFmpegEncoder (_film, job, d->path(), d->format(), d->mixdown_to_stereo())));
+                       job->set_encoder (
+                               shared_ptr<FFmpegEncoder> (
+                                       new FFmpegEncoder (_film, job, d->path(), d->format(), d->mixdown_to_stereo(), d->split_reels(), d->x264_crf())
+                                       )
+                               );
                        JobManager::instance()->add (job);
                }
                d->Destroy ();
@@ -834,7 +875,7 @@ private:
        {
                ContentList vc = _film_editor->content_panel()->selected_video ();
                for (ContentList::iterator i = vc.begin(); i != vc.end(); ++i) {
-                       (*i)->video->scale_and_crop_to_fit_width ();
+                       (*i)->video->scale_and_crop_to_fit_width (_film);
                }
        }
 
@@ -842,7 +883,7 @@ private:
        {
                ContentList vc = _film_editor->content_panel()->selected_video ();
                for (ContentList::iterator i = vc.begin(); i != vc.end(); ++i) {
-                       (*i)->video->scale_and_crop_to_fit_height ();
+                       (*i)->video->scale_and_crop_to_fit_height (_film);
                }
        }
 
@@ -1283,16 +1324,17 @@ private:
 
        void back_frame ()
        {
-               _film_viewer->back_frame ();
+               _film_viewer->seek_by (-_film_viewer->one_video_frame(), true);
        }
 
        void forward_frame ()
        {
-               _film_viewer->forward_frame ();
+               _film_viewer->seek_by (_film_viewer->one_video_frame(), true);
        }
 
        FilmEditor* _film_editor;
-       FilmViewer* _film_viewer;
+       boost::shared_ptr<FilmViewer> _film_viewer;
+       Controls* _controls;
        VideoWaveformDialog* _video_waveform_dialog;
        HintsDialog* _hints_dialog;
        ServersListDialog* _servers_list_dialog;
@@ -1384,6 +1426,14 @@ private:
                if (splash) {
                        splash->Destroy ();
                }
+
+               if (!Config::instance()->nagged(Config::NAG_INITIAL_SETUP)) {
+                       InitialSetupDialog* d = new InitialSetupDialog ();
+                       d->ShowModal ();
+                       d->Destroy ();
+                       Config::instance()->set_nagged(Config::NAG_INITIAL_SETUP, true);
+               }
+
                _frame->Show ();
 
                if (!_film_to_load.empty() && boost::filesystem::is_directory (_film_to_load)) {
@@ -1397,12 +1447,12 @@ private:
                if (!_film_to_create.empty ()) {
                        _frame->new_film (_film_to_create, optional<string> ());
                        if (!_content_to_add.empty ()) {
-                               BOOST_FOREACH (shared_ptr<Content> i, content_factory (_frame->film(), _content_to_add)) {
+                               BOOST_FOREACH (shared_ptr<Content> i, content_factory(_content_to_add)) {
                                        _frame->film()->examine_and_add_content (i);
                                }
                        }
                        if (!_dcp_to_add.empty ()) {
-                               _frame->film()->examine_and_add_content (shared_ptr<DCPContent> (new DCPContent (_frame->film(), _dcp_to_add)));
+                               _frame->film()->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent(_dcp_to_add)));
                        }
                }