+
+void
+Config::save_template (shared_ptr<const Film> film, string name) const
+{
+ film->write_template (template_path (name));
+}
+
+list<string>
+Config::templates () const
+{
+ if (!boost::filesystem::exists (path ("templates"))) {
+ return list<string> ();
+ }
+
+ 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));
+}
+
+/** @return Path to the config.xml containing the actual settings, following a link if required */
+boost::filesystem::path
+Config::config_file ()
+{
+ cxml::Document f ("Config");
+ boost::filesystem::path main = path("config.xml", false);
+ f.read_file (main);
+ optional<string> link = f.optional_string_child("Link");
+ if (link) {
+ return *link;
+ }
+
+ return main;
+}
+
+void
+Config::reset_cover_sheet ()
+{
+ set_cover_sheet_to_default ();
+ changed ();
+}
+
+void
+Config::link (boost::filesystem::path new_file) const
+{
+ xmlpp::Document doc;
+ doc.create_root_node("Config")->add_child("Link")->add_child_text(new_file.string());
+ try {
+ doc.write_to_file_formatted(path("config.xml", true).string());
+ } catch (xmlpp::exception& e) {
+ string s = e.what ();
+ trim (s);
+ throw FileError (s, path("config.xml"));
+ }
+}
+
+void
+Config::copy_and_link (boost::filesystem::path new_file) const
+{
+ write ();
+ boost::filesystem::copy_file (config_file(), new_file, boost::filesystem::copy_option::overwrite_if_exists);
+ link (new_file);
+}