2 Copyright (C) 2004 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/error.h"
26 #include "pbd/filesystem.h"
28 #include "ardour/rc_configuration.h"
29 #include "ardour/filesystem_paths.h"
30 #include "ardour/recent_sessions.h"
35 using namespace ARDOUR;
40 const char * const recent_file_name = "recent";
45 ARDOUR::read_recent_sessions (RecentSessions& rs)
47 sys::path recent_file_path(user_config_directory());
49 recent_file_path /= recent_file_name;
51 const string path = recent_file_path.to_string();
53 ifstream recent (path.c_str());
56 if (errno != ENOENT) {
57 error << string_compose (_("cannot open recent session file %1 (%2)"), path, strerror (errno)) << endmsg;
66 pair<string,string> newpair;
68 getline(recent, newpair.first);
74 getline(recent, newpair.second);
80 rs.push_back (newpair);
83 /* display sorting should be done in the GUI, otherwise the
84 * natural order will be broken
91 ARDOUR::write_recent_sessions (RecentSessions& rs)
93 sys::path recent_file_path(user_config_directory());
95 recent_file_path /= recent_file_name;
97 const string path = recent_file_path.to_string();
99 ofstream recent (path.c_str());
105 for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
106 recent << (*i).first << '\n' << (*i).second << endl;
113 ARDOUR::store_recent_sessions (string name, string path)
117 if (ARDOUR::read_recent_sessions (rs) < 0) {
121 pair<string,string> newpair;
123 newpair.first = name;
124 newpair.second = path;
126 rs.erase(remove(rs.begin(), rs.end(), newpair), rs.end());
128 rs.push_front (newpair);
130 uint32_t max_recent_sessions = Config->get_max_recent_sessions();
132 if (rs.size() > max_recent_sessions) {
133 rs.erase(rs.begin()+max_recent_sessions, rs.end());
136 return ARDOUR::write_recent_sessions (rs);
140 ARDOUR::remove_recent_sessions (const string& path)
145 if (ARDOUR::read_recent_sessions (rs) < 0) {
149 for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
150 if (i->second == path) {
158 return ARDOUR::write_recent_sessions (rs);