diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-08-24 11:40:34 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-08-24 14:28:32 +0100 |
| commit | 1a693725f9a8cc6ba58f65b2f1ef03255d295f23 (patch) | |
| tree | 91596f7800dcc02103c90f8f19c763f45281603e /src/tools | |
| parent | a03e9a98ed667eb44c9dfbbeaf6da57f44992914 (diff) | |
Basic template support (#485).
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/dcpomatic.cc | 50 | ||||
| -rw-r--r-- | src/tools/dcpomatic_batch.cc | 10 | ||||
| -rw-r--r-- | src/tools/dcpomatic_cli.cc | 4 | ||||
| -rw-r--r-- | src/tools/dcpomatic_create.cc | 14 | ||||
| -rw-r--r-- | src/tools/dcpomatic_kdm_cli.cc | 5 | ||||
| -rw-r--r-- | src/tools/server_test.cc | 5 |
6 files changed, 65 insertions, 23 deletions
diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index d4695f1fa..63e5ca6b1 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -38,6 +38,7 @@ #include "wx/content_panel.h" #include "wx/report_problem_dialog.h" #include "wx/video_waveform_dialog.h" +#include "wx/save_template_dialog.h" #include "lib/film.h" #include "lib/config.h" #include "lib/util.h" @@ -143,6 +144,7 @@ enum { ID_file_new = 1, ID_file_open, ID_file_save, + ID_file_save_as_template, ID_file_history, /* Allow spare IDs after _history for the recent files list */ ID_content_scale_to_fit_width = 100, @@ -210,6 +212,7 @@ public: Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_new, this), ID_file_new); Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_open, this), ID_file_open); Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_save, this), ID_file_save); + Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_save_as_template, this), ID_file_save_as_template); Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE); Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT); Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES); @@ -278,9 +281,12 @@ public: } } - void new_film (boost::filesystem::path path) + void new_film (boost::filesystem::path path, optional<string> template_name) { shared_ptr<Film> film (new Film (path)); + if (template_name) { + film->use_template (template_name.get()); + } film->write_metadata (); film->set_name (path.filename().generic_string()); set_film (film); @@ -320,7 +326,9 @@ public: delete _video_waveform_dialog; _video_waveform_dialog = 0; set_menu_sensitivity (); - Config::instance()->add_to_history (_film->directory ()); + if (_film->directory()) { + Config::instance()->add_to_history (_film->directory().get()); + } } shared_ptr<Film> film () const { @@ -346,27 +354,27 @@ private: if (r == wxID_OK) { - if (boost::filesystem::is_directory (d->get_path()) && !boost::filesystem::is_empty(d->get_path())) { + if (boost::filesystem::is_directory (d->path()) && !boost::filesystem::is_empty(d->path())) { if (!confirm_dialog ( this, std_to_wx ( String::compose (wx_to_std (_("The directory %1 already exists and is not empty. " "Are you sure you want to use it?")), - d->get_path().string().c_str()) + d->path().string().c_str()) ) )) { return; } - } else if (boost::filesystem::is_regular_file (d->get_path())) { + } else if (boost::filesystem::is_regular_file (d->path())) { error_dialog ( this, - String::compose (wx_to_std (_("%1 already exists as a file, so you cannot use it for a new film.")), d->get_path().c_str()) + String::compose (wx_to_std (_("%1 already exists as a file, so you cannot use it for a new film.")), d->path().c_str()) ); return; } if (maybe_save_then_delete_film ()) { - new_film (d->get_path ()); + new_film (d->path(), d->template_name()); } } @@ -404,6 +412,22 @@ private: _film->write_metadata (); } + void file_save_as_template () + { + SaveTemplateDialog* d = new SaveTemplateDialog (this); + int const r = d->ShowModal (); + if (r == wxID_OK) { + bool ok = true; + if (Config::instance()->existing_template (d->name ())) { + ok = confirm_dialog (d, _("There is already a template with this name. Do you want to overwrite it?")); + } + if (ok) { + Config::instance()->save_template (_film, d->name ()); + } + } + d->Destroy (); + } + void file_history (wxCommandEvent& event) { vector<boost::filesystem::path> history = Config::instance()->history (); @@ -528,7 +552,8 @@ private: boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve (query); Socket socket (5); socket.connect (*endpoint_iterator); - string s = _film->directory().string (); + DCPOMATIC_ASSERT (_film->directory ()); + string s = _film->directory()->string (); socket.write (s.length() + 1); socket.write ((uint8_t *) s.c_str(), s.length() + 1); /* OK\0 */ @@ -616,6 +641,7 @@ private: void jobs_show_dcp () { + DCPOMATIC_ASSERT (_film->directory ()); #ifdef DCPOMATIC_WINDOWS wstringstream args; args << "/select," << _film->dir (_film->dcp_name(false)); @@ -625,14 +651,14 @@ private: #ifdef DCPOMATIC_LINUX int r = system ("which nautilus"); if (WEXITSTATUS (r) == 0) { - r = system (string ("nautilus " + _film->directory().string()).c_str ()); + r = system (string ("nautilus " + _film->directory()->string()).c_str ()); if (WEXITSTATUS (r)) { error_dialog (this, _("Could not show DCP (could not run nautilus)")); } } else { int r = system ("which konqueror"); if (WEXITSTATUS (r) == 0) { - r = system (string ("konqueror " + _film->directory().string()).c_str ()); + r = system (string ("konqueror " + _film->directory()->string()).c_str ()); if (WEXITSTATUS (r)) { error_dialog (this, _("Could not show DCP (could not run konqueror)")); } @@ -826,6 +852,8 @@ private: add_item (_file_menu, _("&Open...\tCtrl-O"), ID_file_open, ALWAYS); _file_menu->AppendSeparator (); add_item (_file_menu, _("&Save\tCtrl-S"), ID_file_save, NEEDS_FILM); + _file_menu->AppendSeparator (); + add_item (_file_menu, _("Save as &template..."), ID_file_save_as_template, NEEDS_FILM); _history_position = _file_menu->GetMenuItems().GetCount(); @@ -1055,7 +1083,7 @@ private: } if (!_film_to_create.empty ()) { - _frame->new_film (_film_to_create); + _frame->new_film (_film_to_create, optional<string> ()); if (!_content_to_add.empty ()) { _frame->film()->examine_and_add_content (content_factory (_frame->film(), _content_to_add)); } diff --git a/src/tools/dcpomatic_batch.cc b/src/tools/dcpomatic_batch.cc index a112e457a..9e2d6969d 100644 --- a/src/tools/dcpomatic_batch.cc +++ b/src/tools/dcpomatic_batch.cc @@ -45,7 +45,7 @@ using boost::shared_ptr; using boost::thread; using boost::scoped_array; -static std::string film_to_load; +static boost::optional<boost::filesystem::path> film_to_load; enum { ID_file_add_film = 1, @@ -318,13 +318,15 @@ class App : public wxApp this->Bind (wxEVT_IDLE, boost::bind (&App::idle, this)); shared_ptr<Film> film; - if (!film_to_load.empty() && boost::filesystem::is_directory (film_to_load)) { + if (film_to_load && boost::filesystem::is_directory (film_to_load.get())) { try { - film.reset (new Film (film_to_load)); + film.reset (new Film (film_to_load.get())); film->read_metadata (); film->make_dcp (); } catch (exception& e) { - error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load film %1 (%2)")), film_to_load, e.what()))); + error_dialog ( + 0, std_to_wx (String::compose (wx_to_std (_("Could not load film %1 (%2)")), film_to_load->string(), e.what())) + ); } } diff --git a/src/tools/dcpomatic_cli.cc b/src/tools/dcpomatic_cli.cc index bd1a4e4aa..00087d6a0 100644 --- a/src/tools/dcpomatic_cli.cc +++ b/src/tools/dcpomatic_cli.cc @@ -173,7 +173,7 @@ show_servers () int main (int argc, char* argv[]) { - string film_dir; + boost::filesystem::path film_dir; bool progress = true; bool no_remote = false; optional<int> threads; @@ -278,7 +278,7 @@ main (int argc, char* argv[]) film.reset (new Film (film_dir)); film->read_metadata (); } catch (std::exception& e) { - cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n"; + cerr << argv[0] << ": error reading film `" << film_dir.string() << "' (" << e.what() << ")\n"; exit (EXIT_FAILURE); } diff --git a/src/tools/dcpomatic_create.cc b/src/tools/dcpomatic_create.cc index fd950807c..a3adc8e3e 100644 --- a/src/tools/dcpomatic_create.cc +++ b/src/tools/dcpomatic_create.cc @@ -44,6 +44,7 @@ using std::list; using std::exception; using boost::shared_ptr; using boost::dynamic_pointer_cast; +using boost::optional; static void syntax (string n) @@ -52,6 +53,7 @@ syntax (string n) << " -v, --version show DCP-o-matic version\n" << " -h, --help show this help\n" << " -n, --name <name> film name\n" + << " -t, --template <name> template name\n" << " -c, --dcp-content-type <type> FTR, SHR, TLR, TST, XSN, RTG, TSR, POL, PSA or ADV\n" << " --container-ratio <ratio> 119, 133, 137, 138, 166, 178, 185 or 239\n" << " --content-ratio <ratio> 119, 133, 137, 138, 166, 178, 185 or 239\n" @@ -88,6 +90,7 @@ main (int argc, char* argv[]) dcpomatic_setup (); string name; + optional<string> template_name; DCPContentType const * dcp_content_type = DCPContentType::from_isdcf_name ("TST"); Ratio const * container_ratio = 0; Ratio const * content_ratio = 0; @@ -103,6 +106,7 @@ main (int argc, char* argv[]) { "version", no_argument, 0, 'v'}, { "help", no_argument, 0, 'h'}, { "name", required_argument, 0, 'n'}, + { "template", required_argument, 0, 'f'}, { "dcp-content-type", required_argument, 0, 'c'}, { "container-ratio", required_argument, 0, 'A'}, { "content-ratio", required_argument, 0, 'B'}, @@ -114,7 +118,7 @@ main (int argc, char* argv[]) { 0, 0, 0, 0} }; - int c = getopt_long (argc, argv, "vhn:c:A:B:C:s:o:DE", long_options, &option_index); + int c = getopt_long (argc, argv, "vhn:f:c:A:B:C:s:o:DE", long_options, &option_index); if (c == -1) { break; } @@ -129,6 +133,9 @@ main (int argc, char* argv[]) case 'n': name = optarg; break; + case 't': + template_name = optarg; + break; case 'c': dcp_content_type = DCPContentType::from_isdcf_name (optarg); if (dcp_content_type == 0) { @@ -206,7 +213,10 @@ main (int argc, char* argv[]) } try { - shared_ptr<Film> film (new Film (output, false)); + shared_ptr<Film> film (new Film (output)); + if (template_name) { + film->use_template (template_name.get()); + } film->set_name (name); film->set_container (container_ratio); diff --git a/src/tools/dcpomatic_kdm_cli.cc b/src/tools/dcpomatic_kdm_cli.cc index 65b98ee42..f0097d7de 100644 --- a/src/tools/dcpomatic_kdm_cli.cc +++ b/src/tools/dcpomatic_kdm_cli.cc @@ -39,6 +39,7 @@ using std::cerr; using std::list; using std::vector; using boost::shared_ptr; +using boost::optional; static void help () @@ -217,7 +218,7 @@ int main (int argc, char* argv[]) valid_to = valid_from.get() + duration_from_string (duration_string); } - string const film_dir = argv[optind]; + boost::filesystem::path const film_dir = argv[optind]; dcpomatic_setup_path_encoding (); dcpomatic_setup (); @@ -230,7 +231,7 @@ int main (int argc, char* argv[]) cout << "Read film " << film->name () << "\n"; } } catch (std::exception& e) { - cerr << program_name << ": error reading film `" << film_dir << "' (" << e.what() << ")\n"; + cerr << program_name << ": error reading film `" << film_dir.string() << "' (" << e.what() << ")\n"; exit (EXIT_FAILURE); } diff --git a/src/tools/server_test.cc b/src/tools/server_test.cc index 5e50df227..cb3d49f31 100644 --- a/src/tools/server_test.cc +++ b/src/tools/server_test.cc @@ -41,6 +41,7 @@ using std::cerr; using std::string; using std::pair; using boost::shared_ptr; +using boost::optional; using dcp::Data; static shared_ptr<Film> film; @@ -101,7 +102,7 @@ help (string n) int main (int argc, char* argv[]) { - string film_dir; + boost::filesystem::path film_dir; string server_host; while (true) { @@ -132,7 +133,7 @@ main (int argc, char* argv[]) } } - if (server_host.empty() || film_dir.empty()) { + if (server_host.empty() || film_dir.string().empty()) { help (argv[0]); exit (EXIT_FAILURE); } |
