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/filesystem_paths.h"
32 #include "ardour/recent_sessions.h"
33 #include "ardour/utils.h"
38 using namespace ARDOUR
;
43 const char * const recent_file_name
= "recent";
48 ARDOUR::read_recent_sessions (RecentSessions
& rs
)
50 sys::path
recent_file_path(user_config_directory());
52 recent_file_path
/= recent_file_name
;
54 const string path
= recent_file_path
.to_string();
56 ifstream
recent (path
.c_str());
59 if (errno
!= ENOENT
) {
60 error
<< string_compose (_("cannot open recent session file %1 (%2)"), path
, strerror (errno
)) << endmsg
;
69 pair
<string
,string
> newpair
;
71 getline(recent
, newpair
.first
);
77 getline(recent
, newpair
.second
);
83 rs
.push_back (newpair
);
86 /* display sorting should be done in the GUI, otherwise the
87 * natural order will be broken
94 ARDOUR::write_recent_sessions (RecentSessions
& rs
)
96 sys::path
recent_file_path(user_config_directory());
98 recent_file_path
/= recent_file_name
;
100 const string path
= recent_file_path
.to_string();
102 ofstream
recent (path
.c_str());
108 for (RecentSessions::iterator i
= rs
.begin(); i
!= rs
.end(); ++i
) {
109 recent
<< (*i
).first
<< '\n' << (*i
).second
<< endl
;
116 ARDOUR::store_recent_sessions (string name
, string path
)
120 if (ARDOUR::read_recent_sessions (rs
) < 0) {
124 pair
<string
,string
> newpair
;
126 newpair
.first
= name
;
127 newpair
.second
= path
;
129 rs
.erase(remove(rs
.begin(), rs
.end(), newpair
), rs
.end());
131 rs
.push_front (newpair
);
133 if (rs
.size() > 10) {
134 rs
.erase(rs
.begin()+10, rs
.end());
137 return ARDOUR::write_recent_sessions (rs
);