2 Copyright (C) 2012 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "pbd/file_utils.h"
26 #include "pbd/stl_delete.h"
27 #include "pbd/xml++.h"
29 #include "ardour/template_utils.h"
30 #include "ardour/directory_names.h"
31 #include "ardour/filesystem_paths.h"
32 #include "ardour/filename_extensions.h"
33 #include "ardour/search_paths.h"
34 #include "ardour/io.h"
44 user_template_directory ()
46 return Glib::build_filename (user_config_directory(), templates_dir_name);
50 user_route_template_directory ()
52 return Glib::build_filename (user_config_directory(), route_templates_dir_name);
56 template_filter (const string &str, void* /*arg*/)
58 if (!Glib::file_test (str, Glib::FILE_TEST_IS_DIR)) {
66 route_template_filter (const string &str, void* /*arg*/)
68 if (str.find (template_suffix) == str.length() - strlen (template_suffix)) {
76 session_template_dir_to_file (string const & dir)
78 return Glib::build_filename (dir, Glib::path_get_basename(dir) + template_suffix);
83 find_session_templates (vector<TemplateInfo>& template_names, bool read_xml)
85 vector<string> templates;
87 find_paths_matching_filter (templates, template_search_path(), template_filter, 0, true, true);
89 if (templates.empty()) {
90 cerr << "Found nothing along " << template_search_path().to_string() << endl;
94 cerr << "Found " << templates.size() << " along " << template_search_path().to_string() << endl;
96 for (vector<string>::iterator i = templates.begin(); i != templates.end(); ++i) {
97 string file = session_template_dir_to_file (*i);
100 rti.name = Glib::path_get_basename (*i);
106 if (!tree.read (file.c_str())) {
107 cerr << "Failed to parse Route-template XML file: " << file;
111 XMLNode* root = tree.root();
113 rti.modified_with = _("(unknown)");
115 XMLNode *pv = root->child("ProgramVersion");
116 string modified_with;
118 pv->get_property (X_("modified-with"), modified_with);
120 rti.modified_with = modified_with;
121 } catch (XMLException &e) {}
123 rti.description = _("No Description");
125 XMLNode *desc = root->child("description");
127 rti.description = desc->attribute_value();
129 } catch (XMLException &e) {}
132 template_names.push_back (rti);
137 find_route_templates (vector<TemplateInfo>& template_names)
139 vector<string> templates;
141 find_files_matching_filter (templates, route_template_search_path(), route_template_filter, 0, false, true);
143 if (templates.empty()) {
147 for (vector<string>::iterator i = templates.begin(); i != templates.end(); ++i) {
148 string fullpath = *i;
152 if (!tree.read (fullpath.c_str())) {
153 cerr << "Failed to parse Route-template XML file: " << fullpath;
157 XMLNode* root = tree.root();
161 rti.modified_with = _("(unknown)");
163 XMLNode *pv = root->child("ProgramVersion");
164 string modified_with;
166 pv->get_property (X_("modified-with"), modified_with);
168 rti.modified_with = modified_with;
169 } catch (XMLException &e) {}
171 rti.description = _("No Description");
173 XMLNode *desc = root->child("description");
175 rti.description = desc->attribute_value();
177 } catch (XMLException &e) {}
179 rti.name = IO::name_from_state (*root->children().front());
182 template_names.push_back (rti);