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/recent_sessions.h>
32 #include <ardour/utils.h>
36 using namespace ARDOUR;
40 ARDOUR::read_recent_sessions (RecentSessions& rs)
42 Glib::ustring path = Glib::build_filename (get_user_ardour_path(), "recent");
44 ifstream recent (path.c_str());
47 if (errno != ENOENT) {
48 error << string_compose (_("cannot open recent session file %1 (%2)"), path, strerror (errno)) << endmsg;
57 pair<string,string> newpair;
59 getline(recent, newpair.first);
65 getline(recent, newpair.second);
71 rs.push_back (newpair);
74 /* display sorting should be done in the GUI, otherwise the
75 * natural order will be broken
82 ARDOUR::write_recent_sessions (RecentSessions& rs)
84 Glib::ustring path = Glib::build_filename (get_user_ardour_path(), "recent");
86 ofstream recent (path.c_str());
92 for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
93 recent << (*i).first << '\n' << (*i).second << endl;
100 ARDOUR::store_recent_sessions (string name, string path)
104 if (ARDOUR::read_recent_sessions (rs) < 0) {
108 pair<string,string> newpair;
110 newpair.first = name;
111 newpair.second = path;
113 rs.erase(remove(rs.begin(), rs.end(), newpair), rs.end());
115 rs.push_front (newpair);
117 if (rs.size() > 10) {
118 rs.erase(rs.begin()+10, rs.end());
121 return ARDOUR::write_recent_sessions (rs);