Add a basic management dialogue for templates.
[dcpomatic.git] / src / lib / config.cc
index 383ffdbd64598299d59565d6ecfbf34932b2085b..1d9cce64e9fb81516081423b7d8a740492f8c306 100644 (file)
@@ -29,6 +29,7 @@
 #include "cinema.h"
 #include "util.h"
 #include "cross.h"
+#include "film.h"
 #include <dcp/raw_convert.h>
 #include <dcp/name_format.h>
 #include <dcp/colour_matrix.h>
@@ -592,7 +593,39 @@ Config::set_cinemas_file (boost::filesystem::path file)
 void
 Config::save_template (shared_ptr<const Film> film, string name) const
 {
-       boost::filesystem::create_directories (path ("templates"));
-       shared_ptr<xmlpp::Document> doc = film->metadata (false);
-       doc->write_to_file_formatted (path("templates") / tidy_for_filename (name));
+       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));
 }