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/basename.h"
26 #include "pbd/file_utils.h"
27 #include "pbd/stl_delete.h"
28 #include "pbd/xml++.h"
30 #include "ardour/template_utils.h"
31 #include "ardour/directory_names.h"
32 #include "ardour/filesystem_paths.h"
33 #include "ardour/filename_extensions.h"
34 #include "ardour/search_paths.h"
35 #include "ardour/io.h"
43 user_template_directory ()
45 return Glib::build_filename (user_config_directory(), templates_dir_name);
49 user_route_template_directory ()
51 return Glib::build_filename (user_config_directory(), route_templates_dir_name);
55 template_filter (const string &str, void* /*arg*/)
57 if (!Glib::file_test (str, Glib::FILE_TEST_IS_DIR)) {
65 route_template_filter (const string &str, void* /*arg*/)
67 if (str.find (template_suffix) == str.length() - strlen (template_suffix)) {
75 session_template_dir_to_file (string const & dir)
77 return Glib::build_filename (dir, Glib::path_get_basename(dir) + template_suffix);
82 find_session_templates (vector<TemplateInfo>& template_names)
84 vector<string> templates;
86 find_paths_matching_filter (templates, template_search_path(), template_filter, 0, true, true);
88 if (templates.empty()) {
89 cerr << "Found nothing along " << template_search_path().to_string() << endl;
93 cerr << "Found " << templates.size() << " along " << template_search_path().to_string() << endl;
95 for (vector<string>::iterator i = templates.begin(); i != templates.end(); ++i) {
96 string file = session_template_dir_to_file (*i);
100 if (!tree.read (file.c_str())) {
106 rti.name = basename_nosuffix (*i);
109 template_names.push_back (rti);
114 find_route_templates (vector<TemplateInfo>& template_names)
116 vector<string> templates;
118 find_files_matching_filter (templates, route_template_search_path(), route_template_filter, 0, false, true);
120 if (templates.empty()) {
124 for (vector<string>::iterator i = templates.begin(); i != templates.end(); ++i) {
125 string fullpath = *i;
129 if (!tree.read (fullpath.c_str())) {
133 XMLNode* root = tree.root();
137 rti.name = IO::name_from_state (*root->children().front());
140 template_names.push_back (rti);