X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Ftemplate_utils.cc;h=f6b6c59fbce1967c74046c0677082a8802e937ea;hb=5fcea5833df6f8562126683521f3c2ad6cb9f1e9;hp=8efe3115366594cbebc75d0de974a13b1b07fc80;hpb=8c9749e42faf7808034ed8b7afce4a2fe6dc6f33;p=ardour.git diff --git a/libs/ardour/template_utils.cc b/libs/ardour/template_utils.cc index 8efe311536..f6b6c59fbc 100644 --- a/libs/ardour/template_utils.cc +++ b/libs/ardour/template_utils.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Paul Davis + Copyright (C) 2012 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,8 +22,8 @@ #include -#include "pbd/basename.h" -#include "pbd/pathscanner.h" +#include "pbd/file_utils.h" +#include "pbd/stl_delete.h" #include "pbd/xml++.h" #include "ardour/template_utils.h" @@ -33,6 +33,8 @@ #include "ardour/search_paths.h" #include "ardour/io.h" +#include "pbd/i18n.h" + using namespace std; using namespace PBD; @@ -56,7 +58,7 @@ template_filter (const string &str, void* /*arg*/) if (!Glib::file_test (str, Glib::FILE_TEST_IS_DIR)) { return false; } - + return true; } @@ -66,7 +68,7 @@ route_template_filter (const string &str, void* /*arg*/) if (str.find (template_suffix) == str.length() - strlen (template_suffix)) { return true; } - + return false; } @@ -78,60 +80,77 @@ session_template_dir_to_file (string const & dir) void -find_session_templates (vector& template_names) +find_session_templates (vector& template_names, bool read_xml) { - vector *templates; - PathScanner scanner; - Searchpath spath (template_search_path()); + vector templates; - templates = scanner (spath.to_string(), template_filter, 0, true, true); + find_paths_matching_filter (templates, template_search_path(), template_filter, 0, true, true); - if (!templates) { - cerr << "Found nothing along " << spath.to_string() << endl; + if (templates.empty()) { + cerr << "Found nothing along " << template_search_path().to_string() << endl; return; } - cerr << "Found " << templates->size() << " along " << spath.to_string() << endl; + cerr << "Found " << templates.size() << " along " << template_search_path().to_string() << endl; - for (vector::iterator i = templates->begin(); i != templates->end(); ++i) { - string file = session_template_dir_to_file (**i); - - XMLTree tree; - - if (!tree.read (file.c_str())) { - continue; - } + for (vector::iterator i = templates.begin(); i != templates.end(); ++i) { + string file = session_template_dir_to_file (*i); TemplateInfo rti; - - rti.name = basename_nosuffix (**i); - rti.path = **i; + rti.name = Glib::path_get_basename (*i); + rti.path = *i; + + if (read_xml) { + + XMLTree tree; + if (!tree.read (file.c_str())) { + cerr << "Failed to parse Route-template XML file: " << file; + continue; + } + + XMLNode* root = tree.root(); + + rti.modified_with = _("(unknown)"); + try { + XMLNode *pv = root->child("ProgramVersion"); + string modified_with; + if (pv != 0) { + pv->get_property (X_("modified-with"), modified_with); + } + rti.modified_with = modified_with; + } catch (XMLException &e) {} + + rti.description = _("No Description"); + try { + XMLNode *desc = root->child("description"); + if (desc != 0) { + rti.description = desc->attribute_value(); + } + } catch (XMLException &e) {} + } template_names.push_back (rti); } - - delete templates; } void find_route_templates (vector& template_names) { - vector *templates; - PathScanner scanner; - Searchpath spath (route_template_search_path()); + vector templates; - templates = scanner (spath.to_string(), route_template_filter, 0, false, true); + find_files_matching_filter (templates, route_template_search_path(), route_template_filter, 0, false, true); - if (!templates) { + if (templates.empty()) { return; } - for (vector::iterator i = templates->begin(); i != templates->end(); ++i) { - string fullpath = *(*i); + for (vector::iterator i = templates.begin(); i != templates.end(); ++i) { + string fullpath = *i; XMLTree tree; if (!tree.read (fullpath.c_str())) { + cerr << "Failed to parse Route-template XML file: " << fullpath; continue; } @@ -139,13 +158,29 @@ find_route_templates (vector& template_names) TemplateInfo rti; + rti.modified_with = _("(unknown)"); + try { + XMLNode *pv = root->child("ProgramVersion"); + string modified_with; + if (pv != 0) { + pv->get_property (X_("modified-with"), modified_with); + } + rti.modified_with = modified_with; + } catch (XMLException &e) {} + + rti.description = _("No Description"); + try { + XMLNode *desc = root->child("description"); + if (desc != 0) { + rti.description = desc->attribute_value(); + } + } catch (XMLException &e) {} + rti.name = IO::name_from_state (*root->children().front()); rti.path = fullpath; template_names.push_back (rti); } - - delete templates; } }