#include "ardour/source.h"
#include "ardour/utils.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
using namespace std;
using namespace ARDOUR;
, _path (path)
, _file_is_new (!origin.empty()) // if origin is left unspecified (empty string) then file must exist
, _channel (0)
- , _origin (origin)
- , _open (false)
+ , _origin (origin)
{
set_within_session_from_path (path);
}
FileSource::FileSource (Session& session, const XMLNode& node, bool /*must_exist*/)
: Source (session, node)
, _file_is_new (false)
+ , _channel (0)
{
/* this setting of _path is temporary - we expect derived classes
to call ::init() which will actually locate the file
int
FileSource::set_state (const XMLNode& node, int /*version*/)
{
- const XMLProperty* prop;
+ XMLProperty const * prop;
if ((prop = node.property (X_("channel"))) != 0) {
_channel = atoi (prop->value());
_channel = 0;
}
- if ((prop = node.property (X_("origin"))) != 0) {
- _origin = prop->value();
- }
+ if ((prop = node.property (X_("origin"))) != 0) {
+ _origin = prop->value();
+ }
return 0;
}
goto out;
}
- hits.clear ();
-
for (vector<string>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
fullpath = Glib::build_filename (*i, path);
vector<string>::iterator j = i;
++j;
-
+
while (j != hits.end()) {
if (PBD::equivalent_paths (*i, *j)) {
/* *i and *j are the same file; break out of the loop early */
/* no match: error */
if (must_exist) {
- error << string_compose(
- _("Filesource: cannot find required file (%1)"), path) << endmsg;
+ /* do not generate an error here, leave that to
+ whoever deals with the false return value.
+ */
goto out;
} else {
isnew = true;
} else {
/* only one match: happy days */
-
+
keeppath = de_duped_hits[0];
}
-
- } else {
+
+ } else {
keeppath = path;
}
/* Current find() is unable to parse relative path names to yet non-existant
sources. QuickFix(tm)
*/
- if (keeppath == "") {
- if (must_exist) {
+
+ if (keeppath.empty()) {
+ if (must_exist) {
error << "FileSource::find(), keeppath = \"\", but the file must exist" << endl;
} else {
keeppath = path;
}
found_path = keeppath;
-
ret = true;
out:
void
FileSource::set_path (const std::string& newpath)
{
+ close ();
_path = newpath;
+ set_within_session_from_path (newpath);
+ if (_within_session) {
+ _origin = Glib::path_get_basename (newpath);
+ } else {
+ _origin = newpath;
+ }
}
void
if (!empty()) {
return false;
}
-
+
if (!removable()) {
return false;
}
return true;
}
-
+
int
FileSource::rename (const string& newpath)
{
return -1;
}
- if (Glib::file_test (oldpath.c_str(), Glib::FILE_TEST_EXISTS)) {
+ if (Glib::file_test (oldpath.c_str(), Glib::FILE_TEST_EXISTS)) {
/* rename only needed if file exists on disk */
if (::rename (oldpath.c_str(), newpath.c_str()) != 0) {
error << string_compose (_("cannot rename file %1 to %2 (%3)"), oldpath, newpath, strerror(errno)) << endmsg;
return 0;
}
+
+