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 <glibmm/miscutils.h>
27 #include "pbd/error.h"
29 #include "ardour/rc_configuration.h"
30 #include "ardour/filesystem_paths.h"
31 #include "ardour/recent_sessions.h"
36 using namespace ARDOUR;
41 const char * const recent_file_name = "recent";
46 ARDOUR::read_recent_sessions (RecentSessions& rs)
48 std::string path = Glib::build_filename (user_config_directory(), recent_file_name);
50 ifstream recent (path.c_str());
53 if (errno != ENOENT) {
54 error << string_compose (_("cannot open recent session file %1 (%2)"), path, strerror (errno)) << endmsg;
63 pair<string,string> newpair;
65 getline(recent, newpair.first);
71 getline(recent, newpair.second);
77 rs.push_back (newpair);
80 /* display sorting should be done in the GUI, otherwise the
81 * natural order will be broken
88 ARDOUR::write_recent_sessions (RecentSessions& rs)
90 std::string path = Glib::build_filename (user_config_directory(), recent_file_name);
92 ofstream recent (path.c_str());
98 for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
99 recent << (*i).first << '\n' << (*i).second << endl;
106 ARDOUR::store_recent_sessions (string name, string path)
110 if (ARDOUR::read_recent_sessions (rs) < 0) {
114 pair<string,string> newpair;
116 newpair.first = name;
117 newpair.second = path;
119 rs.erase(remove(rs.begin(), rs.end(), newpair), rs.end());
121 rs.push_front (newpair);
123 uint32_t max_recent_sessions = Config->get_max_recent_sessions();
125 if (rs.size() > max_recent_sessions) {
126 rs.erase(rs.begin()+max_recent_sessions, rs.end());
129 return ARDOUR::write_recent_sessions (rs);
133 ARDOUR::remove_recent_sessions (const string& path)
138 if (ARDOUR::read_recent_sessions (rs) < 0) {
142 for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
143 if (i->second == path) {
151 return ARDOUR::write_recent_sessions (rs);