Various work on certificate handling for screens; need XML config here, now.
[dcpomatic.git] / src / tools / dvdomatic.cc
index add0f614482d2a319359ed9399597e7a0d3f1c6f..b6662f281d2f9fa777ead37bc233637aeaf3deb4 100644 (file)
 #include "wx/job_manager_view.h"
 #include "wx/config_dialog.h"
 #include "wx/job_wrapper.h"
-//#include "gtk/dvd_title_dialog.h"
 #include "wx/wx_util.h"
 #include "wx/new_film_dialog.h"
 #include "wx/properties_dialog.h"
 #include "wx/wx_ui_signaller.h"
+#include "wx/kdm_dialog.h"
 #include "lib/film.h"
 #include "lib/format.h"
 #include "lib/config.h"
 #include "lib/exceptions.h"
 #include "lib/version.h"
 #include "lib/ui_signaller.h"
+#include "lib/log.h"
 
-using namespace std;
-using namespace boost;
+using std::cout;
+using std::string;
+using std::stringstream;
+using std::map;
+using std::make_pair;
+using boost::shared_ptr;
 
 static FilmEditor* film_editor = 0;
 static FilmViewer* film_viewer = 0;
-
-static Film* film = 0;
+static shared_ptr<Film> film;
+static std::string log_level;
+static std::string film_to_load;
 
 static void set_menu_sensitivity ();
 
@@ -95,8 +101,7 @@ maybe_save_then_delete_film ()
                }
        }
        
-       delete film;
-       film = 0;
+       film.reset ();
 }
 
 enum Sensitivity {
@@ -133,8 +138,8 @@ enum {
        ID_file_quit,
        ID_edit_preferences,
        ID_jobs_make_dcp,
+       ID_jobs_make_kdms,
        ID_jobs_send_dcp_to_tms,
-       ID_jobs_copy_from_dvd,
        ID_jobs_examine_content,
        ID_jobs_make_dcp_from_existing_transcode,
        ID_help_about
@@ -158,10 +163,8 @@ setup_menu (wxMenuBar* m)
 
        wxMenu* jobs = new wxMenu;
        add_item (jobs, "&Make DCP", ID_jobs_make_dcp, NEEDS_FILM);
+       add_item (jobs, "Make &KDMs...", ID_jobs_make_kdms, NEEDS_FILM);
        add_item (jobs, "&Send DCP to TMS", ID_jobs_send_dcp_to_tms, NEEDS_FILM);
-#ifdef DVDOMATIC_POSIX 
-       add_item (jobs, "Copy from &DVD...", ID_jobs_copy_from_dvd, NEEDS_FILM);
-#endif 
        jobs->AppendSeparator ();
        add_item (jobs, "&Examine content", ID_jobs_examine_content, NEEDS_FILM);
        add_item (jobs, "Make DCP from existing &transcode", ID_jobs_make_dcp_from_existing_transcode, NEEDS_FILM);
@@ -199,8 +202,8 @@ public:
                Connect (ID_file_quit, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::file_quit));
                Connect (ID_edit_preferences, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::edit_preferences));
                Connect (ID_jobs_make_dcp, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_make_dcp));
+               Connect (ID_jobs_make_kdms, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_make_kdms));
                Connect (ID_jobs_send_dcp_to_tms, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_send_dcp_to_tms));
-               Connect (ID_jobs_copy_from_dvd, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_copy_from_dvd));
                Connect (ID_jobs_examine_content, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_examine_content));
                Connect (ID_jobs_make_dcp_from_existing_transcode, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_make_dcp_from_existing_transcode));
                Connect (ID_help_about, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::help_about));
@@ -227,7 +230,6 @@ public:
 
                /* XXX: calling these here is a bit of a hack */
                film_editor->setup_visibility ();
-               film_viewer->setup_visibility ();
                
                film_editor->FileChanged.connect (bind (&Frame::file_changed, this, _1));
                if (film) {
@@ -263,12 +265,19 @@ public:
                int const r = d->ShowModal ();
                
                if (r == wxID_OK) {
+
+                       if (boost::filesystem::exists (d->get_path())) {
+                               error_dialog (this, String::compose ("The directory %1 already exists.", d->get_path()));
+                               return;
+                       }
+                       
                        maybe_save_then_delete_film ();
-                       film = new Film (d->get_path (), false);
+                       film.reset (new Film (d->get_path (), false));
+                       film->log()->set_level (log_level);
 #if BOOST_FILESYSTEM_VERSION == 3              
-                       film->set_name (filesystem::path (d->get_path()).filename().generic_string());
+                       film->set_name (boost::filesystem::path (d->get_path()).filename().generic_string());
 #else          
-                       film->set_name (filesystem::path (d->get_path()).filename());
+                       film->set_name (boost::filesystem::path (d->get_path()).filename());
 #endif
                        set_film ();
                }
@@ -280,13 +289,19 @@ public:
        {
                wxDirDialog* c = new wxDirDialog (this, wxT ("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
                int const r = c->ShowModal ();
-               c->Destroy ();
                
                if (r == wxID_OK) {
                        maybe_save_then_delete_film ();
-                       film = new Film (wx_to_std (c->GetPath ()));
-                       set_film ();
+                       try {
+                               film.reset (new Film (wx_to_std (c->GetPath ())));
+                               film->log()->set_level (log_level);
+                               set_film ();
+                       } catch (std::exception& e) {
+                               error_dialog (this, String::compose ("Could not open film at %1 (%2)", wx_to_std (c->GetPath()), e.what()));
+                       }
                }
+
+               c->Destroy ();
        }
 
        void file_save (wxCommandEvent &)
@@ -319,24 +334,29 @@ public:
        {
                JobWrapper::make_dcp (this, film, true);
        }
-       
-       void jobs_make_dcp_from_existing_transcode (wxCommandEvent &)
+
+       void jobs_make_kdms (wxCommandEvent &)
        {
-               JobWrapper::make_dcp (this, film, false);
+               if (!film) {
+                       return;
+               }
+               
+               KDMDialog* d = new KDMDialog (this);
+               if (d->ShowModal () == wxID_OK) {
+                       film->make_kdms (
+                               d->screens (),
+                               d->from (),
+                               d->until (),
+                               d->directory ()
+                               );
+               }
+               
+               d->Destroy ();
        }
        
-       void jobs_copy_from_dvd (wxCommandEvent &)
+       void jobs_make_dcp_from_existing_transcode (wxCommandEvent &)
        {
-               try {
-
-//             DVDTitleDialog d;
-//             if (d.run () != Gtk::RESPONSE_OK) {
-//                     return;
-//             }
-                       film->copy_from_dvd ();
-               } catch (DVDError& e) {
-                       error_dialog (this, e.what ());
-               }
+               JobWrapper::make_dcp (this, film, false);
        }
        
        void jobs_send_dcp_to_tms (wxCommandEvent &)
@@ -353,7 +373,11 @@ public:
        {
                wxAboutDialogInfo info;
                info.SetName (_("DVD-o-matic"));
-               info.SetVersion (std_to_wx (String::compose ("version %1 git %2", dvdomatic_version, dvdomatic_git_commit)));
+               if (strcmp (dvdomatic_git_commit, "release") == 0) {
+                       info.SetVersion (std_to_wx (String::compose ("version %1", dvdomatic_version)));
+               } else {
+                       info.SetVersion (std_to_wx (String::compose ("version %1 git %2", dvdomatic_version, dvdomatic_git_commit)));
+               }
                info.SetDescription (_("Free, open-source DCP generation from almost anything."));
                info.SetCopyright (_("(C) Carl Hetherington, Terrence Meiczinger, Paul Davis, Ole Laursen"));
                wxArrayString authors;
@@ -367,16 +391,39 @@ public:
        }
 };
 
+#if wxMINOR_VERSION == 9
+static const wxCmdLineEntryDesc command_line_description[] = {
+       { wxCMD_LINE_OPTION, "l", "log", "set log level (silent, verbose or timing)", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
+        { wxCMD_LINE_PARAM, 0, 0, "film to load", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
+       { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
+};
+#else
+static const wxCmdLineEntryDesc command_line_description[] = {
+       { wxCMD_LINE_OPTION, wxT("l"), wxT("log"), wxT("set log level (silent, verbose or timing)"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
+        { wxCMD_LINE_PARAM, 0, 0, wxT("film to load"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
+       { wxCMD_LINE_NONE, wxT(""), wxT(""), wxT(""), wxCmdLineParamType (0), 0 }
+};
+#endif
+
 class App : public wxApp
 {
        bool OnInit ()
        {
+               if (!wxApp::OnInit()) {
+                       return false;
+               }
+               
+#ifdef DVDOMATIC_POSIX         
+               unsetenv ("UBUNTU_MENUPROXY");
+#endif         
+               
                wxInitAllImageHandlers ();
                
                dvdomatic_setup ();
 
-               if (argc == 2 && boost::filesystem::is_directory (wx_to_std (argv[1]))) {
-                       film = new Film (wx_to_std (argv[1]));
+               if (!film_to_load.empty() && boost::filesystem::is_directory (film_to_load)) {
+                       film.reset (new Film (film_to_load));
+                       film->log()->set_level (log_level);
                }
 
                Frame* f = new Frame (_("DVD-o-matic"));
@@ -390,6 +437,26 @@ class App : public wxApp
                return true;
        }
 
+       void OnInitCmdLine (wxCmdLineParser& parser)
+       {
+               parser.SetDesc (command_line_description);
+               parser.SetSwitchChars (wxT ("-"));
+       }
+
+       bool OnCmdLineParsed (wxCmdLineParser& parser)
+       {
+               if (parser.GetParamCount() > 0) {
+                       film_to_load = wx_to_std (parser.GetParam(0));
+               }
+
+               wxString log;
+               if (parser.Found(wxT("log"), &log)) {
+                       log_level = wx_to_std (log);
+               }
+
+               return true;
+       }
+
        void idle (wxIdleEvent &)
        {
                ui_signaller->ui_idle ();