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.
26 #include <glibmm/miscutils.h>
28 #include "pbd/error.h"
30 #include "ardour/configuration.h"
31 #include "ardour/rc_configuration.h"
32 #include "ardour/filesystem_paths.h"
33 #include "ardour/recent_sessions.h"
34 #include "ardour/utils.h"
39 using namespace ARDOUR;
44 const char * const recent_file_name = "recent";
49 ARDOUR::read_recent_sessions (RecentSessions& rs)
51 sys::path recent_file_path(user_config_directory());
53 recent_file_path /= recent_file_name;
55 const string path = recent_file_path.to_string();
57 ifstream recent (path.c_str());
60 if (errno != ENOENT) {
61 error << string_compose (_("cannot open recent session file %1 (%2)"), path, strerror (errno)) << endmsg;
70 pair<string,string> newpair;
72 getline(recent, newpair.first);
78 getline(recent, newpair.second);
84 rs.push_back (newpair);
87 /* display sorting should be done in the GUI, otherwise the
88 * natural order will be broken
95 ARDOUR::write_recent_sessions (RecentSessions& rs)
97 sys::path recent_file_path(user_config_directory());
99 recent_file_path /= recent_file_name;
101 const string path = recent_file_path.to_string();
103 ofstream recent (path.c_str());
109 for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
110 recent << (*i).first << '\n' << (*i).second << endl;
117 ARDOUR::store_recent_sessions (string name, string path)
121 if (ARDOUR::read_recent_sessions (rs) < 0) {
125 pair<string,string> newpair;
127 newpair.first = name;
128 newpair.second = path;
130 rs.erase(remove(rs.begin(), rs.end(), newpair), rs.end());
132 rs.push_front (newpair);
134 uint32_t max_recent_sessions = Config->get_max_recent_sessions();
136 if (rs.size() > max_recent_sessions) {
137 rs.erase(rs.begin()+max_recent_sessions, rs.end());
140 return ARDOUR::write_recent_sessions (rs);
144 ARDOUR::remove_recent_sessions (const string& path)
149 if (ARDOUR::read_recent_sessions (rs) < 0) {
153 for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
154 if (i->second == path) {
162 return ARDOUR::write_recent_sessions (rs);