summaryrefslogtreecommitdiff
path: root/libs/ardour/recent_sessions.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2015-05-08 12:07:33 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2015-06-29 14:18:10 -0400
commit445d742af187a27f035c120545b4fb3a1e4dadd3 (patch)
tree3a4b3ec19f2dd924206476839e0aa8b03cb6041f /libs/ardour/recent_sessions.cc
parent0365c5cc47f5f7c875714049f58f3a71cc53bdf7 (diff)
save recent templates analogously to recent sessions
Diffstat (limited to 'libs/ardour/recent_sessions.cc')
-rw-r--r--libs/ardour/recent_sessions.cc73
1 files changed, 73 insertions, 0 deletions
diff --git a/libs/ardour/recent_sessions.cc b/libs/ardour/recent_sessions.cc
index 7c2297448b..7458c32ff8 100644
--- a/libs/ardour/recent_sessions.cc
+++ b/libs/ardour/recent_sessions.cc
@@ -39,6 +39,7 @@ using namespace PBD;
namespace {
const char * const recent_file_name = "recent";
+ const char * const recent_templates_file_name = "recent_templates";
} // anonymous
@@ -85,6 +86,38 @@ ARDOUR::read_recent_sessions (RecentSessions& rs)
}
int
+ARDOUR::read_recent_templates (std::deque<std::string>& rt)
+{
+ std::string path = Glib::build_filename (user_config_directory(), recent_templates_file_name);
+
+ ifstream recent (path.c_str());
+
+ if (!recent) {
+ if (errno != ENOENT) {
+ error << string_compose (_("cannot open recent template file %1 (%2)"), path, strerror (errno)) << endmsg;
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+
+ while (true) {
+
+ std::string session_template_full_name;
+
+ getline(recent, session_template_full_name);
+
+ if (!recent.good()) {
+ break;
+ }
+
+ rt.push_back (session_template_full_name);
+ }
+
+ return 0;
+}
+
+int
ARDOUR::write_recent_sessions (RecentSessions& rs)
{
std::string path = Glib::build_filename (user_config_directory(), recent_file_name);
@@ -103,6 +136,24 @@ ARDOUR::write_recent_sessions (RecentSessions& rs)
}
int
+ARDOUR::write_recent_templates (std::deque<std::string>& rt)
+{
+ std::string path = Glib::build_filename (user_config_directory(), recent_templates_file_name);
+
+ std::ofstream recent (path.c_str());
+
+ if (!recent) {
+ return -1;
+ }
+
+ for (std::deque<std::string>::const_iterator i = rt.begin(); i != rt.end(); ++i) {
+ recent << (*i) << std::endl;
+ }
+
+ return 0;
+}
+
+int
ARDOUR::store_recent_sessions (string name, string path)
{
RecentSessions rs;
@@ -130,6 +181,28 @@ ARDOUR::store_recent_sessions (string name, string path)
}
int
+ARDOUR::store_recent_templates (const std::string& session_template_full_name)
+{
+ std::deque<std::string> rt;
+
+ if (ARDOUR::read_recent_templates (rt) < 0) {
+ return -1;
+ }
+
+ rt.erase(remove (rt.begin(), rt.end(), session_template_full_name), rt.end());
+
+ rt.push_front (session_template_full_name);
+
+ uint32_t max_recent_templates = Config->get_max_recent_templates ();
+
+ if (rt.size() > max_recent_templates) {
+ rt.erase( rt.begin() + max_recent_templates, rt.end ());
+ }
+
+ return ARDOUR::write_recent_templates (rt);
+}
+
+int
ARDOUR::remove_recent_sessions (const string& path)
{
RecentSessions rs;