Rename Subtitle -> Text
[dcpomatic.git] / src / tools / dcpomatic.cc
index 1e6c49d7bc592f2e9e67533eaf5dd69c92333c7a..934e5750521900c0c1487e7824ea55b9ea0be03b 100644 (file)
@@ -44,6 +44,7 @@
 #include "wx/nag_dialog.h"
 #include "wx/export_dialog.h"
 #include "wx/paste_dialog.h"
+#include "wx/focus_manager.h"
 #include "lib/film.h"
 #include "lib/config.h"
 #include "lib/util.h"
@@ -70,7 +71,7 @@
 #include "lib/transcode_job.h"
 #include "lib/dkdm_wrapper.h"
 #include "lib/audio_content.h"
-#include "lib/subtitle_content.h"
+#include "lib/text_content.h"
 #include <dcp/exceptions.h>
 #include <dcp/raw_convert.h>
 #include <wx/generic/aboutdlgg.h>
@@ -109,6 +110,7 @@ using std::exception;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using boost::optional;
+using boost::function;
 using dcp::raw_convert;
 
 class FilmChangedClosingDialog : public boost::noncopyable
@@ -209,6 +211,7 @@ enum {
        ID_jobs_export,
        ID_jobs_send_dcp_to_tms,
        ID_jobs_show_dcp,
+       ID_jobs_open_dcp_in_player,
        ID_tools_video_waveform,
        ID_tools_hints,
        ID_tools_encoding_servers,
@@ -218,7 +221,11 @@ enum {
        ID_help_report_a_problem,
        /* IDs for shortcuts (with no associated menu item) */
        ID_add_file,
-       ID_remove
+       ID_remove,
+       ID_start_stop,
+       ID_timeline,
+       ID_back_frame,
+       ID_forward_frame
 };
 
 class DOMFrame : public wxFrame
@@ -289,6 +296,7 @@ public:
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_export, this),             ID_jobs_export);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_send_dcp_to_tms, this),    ID_jobs_send_dcp_to_tms);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_show_dcp, this),           ID_jobs_show_dcp);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_open_dcp_in_player, this), ID_jobs_open_dcp_in_player);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_video_waveform, this),    ID_tools_video_waveform);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_hints, this),             ID_tools_hints);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_encoding_servers, this),  ID_tools_encoding_servers);
@@ -327,24 +335,44 @@ public:
 
                overall_panel->SetSizer (main_sizer);
 
+               UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
+
+               FocusManager::instance()->SetFocus.connect (boost::bind (&DOMFrame::remove_accelerators, this));
+               FocusManager::instance()->KillFocus.connect (boost::bind (&DOMFrame::add_accelerators, this));
+               add_accelerators ();
+       }
+
+       void add_accelerators ()
+       {
 #ifdef __WXOSX__
-               int accelerators = 3;
+               int accelerators = 7;
 #else
-               int accelerators = 2;
+               int accelerators = 6;
 #endif
                wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
                accel[0].Set (wxACCEL_CTRL, static_cast<int>('A'), ID_add_file);
                accel[1].Set (wxACCEL_NORMAL, WXK_DELETE, ID_remove);
+               accel[2].Set (wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
+               accel[3].Set (wxACCEL_CTRL, static_cast<int>('T'), ID_timeline);
+               accel[4].Set (wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
+               accel[5].Set (wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
 #ifdef __WXOSX__
-               accel[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_EXIT);
+               accel[6].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_EXIT);
 #endif
                Bind (wxEVT_MENU, boost::bind (&ContentPanel::add_file_clicked, _film_editor->content_panel()), ID_add_file);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::remove_clicked, this, _1), ID_remove);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::timeline_pressed, this), ID_timeline);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
                wxAcceleratorTable accel_table (accelerators, accel);
                SetAcceleratorTable (accel_table);
                delete[] accel;
+       }
 
-               UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
+       void remove_accelerators ()
+       {
+               SetAcceleratorTable (wxAcceleratorTable ());
        }
 
        void remove_clicked (wxCommandEvent& ev)
@@ -427,7 +455,11 @@ private:
                int const r = d->ShowModal ();
 
                if (r == wxID_OK && d->check_path() && maybe_save_then_delete_film<FilmChangedClosingDialog>()) {
-                       new_film (d->path(), d->template_name());
+                       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()));
+                       }
                }
 
                d->Destroy ();
@@ -651,55 +683,73 @@ private:
                _kdm_dialog->Show ();
        }
 
-       void jobs_make_dcp_batch ()
+       /** @return false if we succeeded, true if not */
+       bool send_to_other_tool (int port, function<void(boost::filesystem::path)> start, string message)
        {
-               if (!_film) {
-                       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
-                  i = 1; try again, and then try to start the batch converter
+                  i = 1; try again, and then try to start the tool
                   i = 2 onwards; try again.
                */
                for (int i = 0; i < 8; ++i) {
                        try {
                                boost::asio::io_service io_service;
                                boost::asio::ip::tcp::resolver resolver (io_service);
-                               boost::asio::ip::tcp::resolver::query query ("127.0.0.1", raw_convert<string> (BATCH_JOB_PORT));
+                               boost::asio::ip::tcp::resolver::query query ("127.0.0.1", raw_convert<string> (port));
                                boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve (query);
                                Socket socket (5);
                                socket.connect (*endpoint_iterator);
                                DCPOMATIC_ASSERT (_film->directory ());
-                               string s = _film->directory()->string ();
-                               socket.write (s.length() + 1);
-                               socket.write ((uint8_t *) s.c_str(), s.length() + 1);
+                               socket.write (message.length() + 1);
+                               socket.write ((uint8_t *) message.c_str(), message.length() + 1);
                                /* OK\0 */
                                uint8_t ok[3];
                                socket.read (ok, 3);
-                               return;
+                               return false;
                        } catch (exception& e) {
 
                        }
 
                        if (i == 1) {
-                               start_batch_converter (wx_to_std (wxStandardPaths::Get().GetExecutablePath()));
+                               start (wx_to_std (wxStandardPaths::Get().GetExecutablePath()));
                        }
 
                        dcpomatic_sleep (1);
                }
 
-               error_dialog (this, _("Could not find batch converter."));
+               return true;
+       }
+
+       void jobs_make_dcp_batch ()
+       {
+               if (!_film) {
+                       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 ();
+
+               if (send_to_other_tool (BATCH_JOB_PORT, bind (&start_batch_converter, _1), _film->directory()->string())) {
+                       error_dialog (this, _("Could not find batch converter."));
+               }
+       }
+
+       void jobs_open_dcp_in_player ()
+       {
+               if (!_film) {
+                       return;
+               }
+
+               if (send_to_other_tool (PLAYER_PLAY_PORT, bind (&start_player, _1), _film->dir(_film->dcp_name(false)).string())) {
+                       error_dialog (this, _("Could not find player."));
+               }
        }
 
        void jobs_make_self_dkdm ()
@@ -1083,6 +1133,7 @@ private:
                jobs_menu->AppendSeparator ();
                add_item (jobs_menu, _("&Send DCP to TMS"), ID_jobs_send_dcp_to_tms, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
                add_item (jobs_menu, _("S&how DCP"), ID_jobs_show_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
+               add_item (jobs_menu, _("Open DCP in &player"), ID_jobs_open_dcp_in_player, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
 
                wxMenu* tools = new wxMenu;
                add_item (tools, _("Video waveform..."), ID_tools_video_waveform, NEEDS_FILM);
@@ -1197,6 +1248,30 @@ private:
                _update_news_requested = false;
        }
 
+       void start_stop_pressed ()
+       {
+               if (_film_viewer->playing()) {
+                       _film_viewer->stop();
+               } else {
+                       _film_viewer->start();
+               }
+       }
+
+       void timeline_pressed ()
+       {
+               _film_editor->content_panel()->timeline_clicked ();
+       }
+
+       void back_frame ()
+       {
+               _film_viewer->back_frame ();
+       }
+
+       void forward_frame ()
+       {
+               _film_viewer->forward_frame ();
+       }
+
        FilmEditor* _film_editor;
        FilmViewer* _film_viewer;
        VideoWaveformDialog* _video_waveform_dialog;