pot/merge.
[dcpomatic.git] / src / tools / dcpomatic_batch.cc
index 64015a0e30179faa7a0dd7b78bf05a2109dc2e21..6a0e46cf8b462cdeb781766fab41d079c5369068 100644 (file)
 #include "wx/about_dialog.h"
 #include "wx/dcpomatic_button.h"
 #include "wx/full_config_dialog.h"
+#include "wx/id.h"
 #include "wx/job_manager_view.h"
 #include "wx/servers_list_dialog.h"
+#include "wx/wx_ptr.h"
 #include "wx/wx_signal_manager.h"
 #include "wx/wx_util.h"
 #include "lib/compose.hpp"
 #include "lib/job.h"
 #include "lib/job_manager.h"
 #include "lib/make_dcp.h"
-#include "lib/scope_guard.h"
 #include "lib/transcode_job.h"
 #include "lib/util.h"
 #include "lib/version.h"
+#include <dcp/filesystem.h>
 #include <dcp/warnings.h>
 LIBDCP_DISABLE_WARNINGS
 #include <wx/aboutdlg.h>
@@ -70,7 +72,7 @@ static list<boost::filesystem::path> films_to_load;
 
 
 enum {
-       ID_file_add_film = 1,
+       ID_file_add_film = DCPOMATIC_MAIN_MENU,
        ID_tools_encoding_servers,
        ID_help_about
 };
@@ -129,7 +131,7 @@ public:
                        if (filenames.GetCount() == 1) {
                                /* Try to load a directory */
                                auto path = boost::filesystem::path(wx_to_std(filenames[0]));
-                               if (boost::filesystem::is_directory(path)) {
+                               if (dcp::filesystem::is_directory(path)) {
                                        _frame->start_job(wx_to_std(filenames[0]));
                                        return true;
                                }
@@ -269,13 +271,12 @@ private:
                        return true;
                }
 
-               auto d = new wxMessageDialog (
-                       0,
+               auto d = make_wx<wxMessageDialog>(
+                       nullptr,
                        _("There are unfinished jobs; are you sure you want to quit?"),
                        _("Unfinished jobs"),
                        wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
                        );
-               ScopeGuard sg = [d]{ d->Destroy(); };
 
                return d->ShowModal() == wxID_YES;
        }
@@ -321,15 +322,13 @@ private:
 
        void help_about ()
        {
-               auto d = new AboutDialog (this);
-               ScopeGuard sg = [d]() { d->Destroy(); };
+               auto d = make_wx<AboutDialog>(this);
                d->ShowModal ();
        }
 
        void add_film ()
        {
-               auto dialog = new wxDirDialog(this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
-               ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+               auto dialog = make_wx<wxDirDialog>(this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
                if (_last_parent) {
                        dialog->SetPath(std_to_wx(_last_parent.get().string()));
                }
@@ -394,30 +393,30 @@ static const wxCmdLineEntryDesc command_line_description[] = {
 };
 
 
-class JobServer : public Server
+class JobServer : public Server, public Signaller
 {
 public:
-       explicit JobServer (DOMFrame* frame)
+       JobServer()
                : Server (BATCH_JOB_PORT)
-               , _frame (frame)
        {}
 
        void handle (shared_ptr<Socket> socket) override
        {
                try {
-                       int const length = socket->read_uint32 ();
-                       scoped_array<char> buffer(new char[length]);
-                       socket->read (reinterpret_cast<uint8_t*>(buffer.get()), length);
-                       string s (buffer.get());
-                       _frame->start_job (s);
-                       socket->write (reinterpret_cast<uint8_t const *>("OK"), 3);
+                       auto const length = socket->read_uint32();
+                       if (length < 65536) {
+                               scoped_array<char> buffer(new char[length]);
+                               socket->read(reinterpret_cast<uint8_t*>(buffer.get()), length);
+                               string s(buffer.get());
+                               emit(boost::bind(boost::ref(StartJob), s));
+                               socket->write (reinterpret_cast<uint8_t const *>("OK"), 3);
+                       }
                } catch (...) {
 
                }
        }
 
-private:
-       DOMFrame* _frame;
+       boost::signals2::signal<void(std::string)> StartJob;
 };
 
 
@@ -472,7 +471,8 @@ class App : public wxApp
                _frame->Show ();
 
                try {
-                       auto server = new JobServer (_frame);
+                       auto server = new JobServer();
+                       server->StartJob.connect(bind(&DOMFrame::start_job, _frame, _1));
                        new thread (boost::bind (&JobServer::run, server));
                } catch (boost::system::system_error& e) {
                        error_dialog(_frame, _("Could not listen for new batch jobs.  Perhaps another instance of the DCP-o-matic Batch Converter is running."));
@@ -483,7 +483,7 @@ class App : public wxApp
 
                shared_ptr<Film> film;
                for (auto i: films_to_load) {
-                       if (boost::filesystem::is_directory(i)) {
+                       if (dcp::filesystem::is_directory(i)) {
                                try {
                                        film = make_shared<Film>(i);
                                        film->read_metadata ();