Add a basic management dialogue for templates.
[dcpomatic.git] / src / lib / config.cc
index 6f7c8ec556c369a21b5d47b96190a85902789530..1d9cce64e9fb81516081423b7d8a740492f8c306 100644 (file)
@@ -29,7 +29,8 @@
 #include "cinema.h"
 #include "util.h"
 #include "cross.h"
-#include "raw_convert.h"
+#include "film.h"
+#include <dcp/raw_convert.h>
 #include <dcp/name_format.h>
 #include <dcp/colour_matrix.h>
 #include <dcp/certificate_chain.h>
@@ -58,6 +59,7 @@ using std::cerr;
 using boost::shared_ptr;
 using boost::optional;
 using boost::algorithm::trim;
+using dcp::raw_convert;
 
 Config* Config::_instance = 0;
 boost::signals2::signal<void ()> Config::FailedToLoad;
@@ -110,8 +112,8 @@ Config::set_defaults ()
        _cinemas_file = path ("cinemas.xml");
        _show_hints_before_make_dcp = true;
        _kdm_filename_format = dcp::NameFormat ("KDM %f %c %s");
-       _dcp_metadata_filename_format = dcp::NameFormat ("%t_%i");
-       _dcp_asset_filename_format = dcp::NameFormat ("%t_%i");
+       _dcp_metadata_filename_format = dcp::NameFormat ("%t");
+       _dcp_asset_filename_format = dcp::NameFormat ("%t");
 
        _allowed_dcp_frame_rates.clear ();
        _allowed_dcp_frame_rates.push_back (24);
@@ -295,8 +297,8 @@ try
        _cinemas_file = f.optional_string_child("CinemasFile").get_value_or (path ("cinemas.xml").string ());
        _show_hints_before_make_dcp = f.optional_bool_child("ShowHintsBeforeMakeDCP").get_value_or (true);
        _kdm_filename_format = dcp::NameFormat (f.optional_string_child("KDMFilenameFormat").get_value_or ("KDM %f %c %s"));
-       _dcp_metadata_filename_format = dcp::NameFormat (f.optional_string_child("DCPMetadataFilenameFormat").get_value_or ("%t_%i"));
-       _dcp_asset_filename_format = dcp::NameFormat (f.optional_string_child("DCPAssetFilenameFormat").get_value_or ("%t_%i"));
+       _dcp_metadata_filename_format = dcp::NameFormat (f.optional_string_child("DCPMetadataFilenameFormat").get_value_or ("%t"));
+       _dcp_asset_filename_format = dcp::NameFormat (f.optional_string_child("DCPAssetFilenameFormat").get_value_or ("%t"));
 
        /* Replace any cinemas from config.xml with those from the configured file */
        if (boost::filesystem::exists (_cinemas_file)) {
@@ -379,7 +381,7 @@ Config::write_config_xml () const
        }
 
        root->add_child("OnlyServersEncode")->add_child_text (_only_servers_encode ? "1" : "0");
-       root->add_child("TMSProtocol")->add_child_text (raw_convert<string> (_tms_protocol));
+       root->add_child("TMSProtocol")->add_child_text (raw_convert<string> (static_cast<int> (_tms_protocol)));
        root->add_child("TMSIP")->add_child_text (_tms_ip);
        root->add_child("TMSPath")->add_child_text (_tms_path);
        root->add_child("TMSUser")->add_child_text (_tms_user);
@@ -587,3 +589,43 @@ Config::set_cinemas_file (boost::filesystem::path file)
 
        changed (OTHER);
 }
+
+void
+Config::save_template (shared_ptr<const Film> film, string name) const
+{
+       film->write_template (template_path (name));
+}
+
+list<string>
+Config::templates () const
+{
+       list<string> n;
+       for (boost::filesystem::directory_iterator i (path("templates")); i != boost::filesystem::directory_iterator(); ++i) {
+               n.push_back (i->path().filename().string());
+       }
+       return n;
+}
+
+bool
+Config::existing_template (string name) const
+{
+       return boost::filesystem::exists (template_path (name));
+}
+
+boost::filesystem::path
+Config::template_path (string name) const
+{
+       return path("templates") / tidy_for_filename (name);
+}
+
+void
+Config::rename_template (string old_name, string new_name) const
+{
+       boost::filesystem::rename (template_path (old_name), template_path (new_name));
+}
+
+void
+Config::delete_template (string name) const
+{
+       boost::filesystem::remove (template_path (name));
+}