6 #include "pbd/basename.h"
7 #include "pbd/pathscanner.h"
10 #include "ardour/template_utils.h"
11 #include "ardour/directory_names.h"
12 #include "ardour/filesystem_paths.h"
13 #include "ardour/filename_extensions.h"
14 #include "ardour/io.h"
22 template_search_path ()
24 SearchPath spath (ardour_data_search_path());
25 spath.add_subdirectory_to_paths(templates_dir_name);
30 route_template_search_path ()
32 SearchPath spath (ardour_data_search_path());
33 spath.add_subdirectory_to_paths(route_templates_dir_name);
38 user_template_directory ()
40 return Glib::build_filename (user_config_directory(), templates_dir_name);
44 user_route_template_directory ()
46 return Glib::build_filename (user_config_directory(), route_templates_dir_name);
50 template_filter (const string &str, void */*arg*/)
52 if (!Glib::file_test (str, Glib::FILE_TEST_IS_DIR)) {
60 route_template_filter (const string &str, void */*arg*/)
62 if (str.find (template_suffix) == str.length() - strlen (template_suffix)) {
70 session_template_dir_to_file (string const & dir)
72 return Glib::build_filename (dir, Glib::path_get_basename(dir) + template_suffix);
77 find_session_templates (vector<TemplateInfo>& template_names)
79 vector<string *> *templates;
81 SearchPath spath (template_search_path());
83 templates = scanner (spath.to_string(), template_filter, 0, true, true);
86 cerr << "Found nothing along " << spath.to_string() << endl;
90 cerr << "Found " << templates->size() << " along " << spath.to_string() << endl;
92 for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
93 string file = session_template_dir_to_file (**i);
97 if (!tree.read (file.c_str())) {
103 rti.name = basename_nosuffix (**i);
106 template_names.push_back (rti);
113 find_route_templates (vector<TemplateInfo>& template_names)
115 vector<string *> *templates;
117 SearchPath spath (route_template_search_path());
119 templates = scanner (spath.to_string(), route_template_filter, 0, false, true);
125 for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
126 string fullpath = *(*i);
130 if (!tree.read (fullpath.c_str())) {
134 XMLNode* root = tree.root();
138 rti.name = IO::name_from_state (*root->children().front());
141 template_names.push_back (rti);