enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / libs / ardour / file_source.cc
index 5833d29e3a7ebe981b9d00180549888e4c20f84c..c05a0a4bb92826bebc876b62778c510a7c5e6c9d 100644 (file)
 #include "ardour/source.h"
 #include "ardour/utils.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 using namespace Glib;
 
-PBD::Signal3<int,std::string,std::string,std::vector<std::string> > FileSource::AmbiguousFileName;
+PBD::Signal2<int,std::string,std::vector<std::string> > FileSource::AmbiguousFileName;
 
 FileSource::FileSource (Session& session, DataType type, const string& path, const string& origin, Source::Flag flag)
        : Source(session, type, path, flag)
        , _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);
 }
@@ -67,6 +66,7 @@ FileSource::FileSource (Session& session, DataType type, const string& path, con
 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
@@ -140,7 +140,7 @@ FileSource::init (const string& pathstr, bool must_exist)
 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());
@@ -148,9 +148,9 @@ FileSource::set_state (const XMLNode& node, int /*version*/)
                _channel = 0;
        }
 
-        if ((prop = node.property (X_("origin"))) != 0) {
-                _origin = prop->value();
-        }
+       if ((prop = node.property (X_("origin"))) != 0) {
+               _origin = prop->value();
+       }
 
        return 0;
 }
@@ -243,19 +243,15 @@ FileSource::find (Session& s, DataType type, const string& path, bool must_exist
        isnew = false;
 
         if (!Glib::path_is_absolute (path)) {
-                vector<string> dirs;
                 vector<string> hits;
                 string fullpath;
+               std::vector<std::string> dirs = s.source_search_path (type);
 
-                string search_path = s.source_search_path (type);
-
-                if (search_path.length() == 0) {
+                if (dirs.size() == 0) {
                         error << _("FileSource: search path not set") << endmsg;
                         goto out;
                 }
 
-                split (search_path, dirs, ':');
-
                 for (vector<string>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
 
                         fullpath = Glib::build_filename (*i, path);
@@ -278,7 +274,7 @@ FileSource::find (Session& s, DataType type, const string& path, bool must_exist
 
                        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 */
@@ -297,7 +293,7 @@ FileSource::find (Session& s, DataType type, const string& path, bool must_exist
 
                        /* more than one match: ask the user */
 
-                        int which = FileSource::AmbiguousFileName (path, search_path, de_duped_hits).get_value_or (-1);
+                        int which = FileSource::AmbiguousFileName (path, de_duped_hits).get_value_or (-1);
 
                         if (which < 0) {
                                 goto out;
@@ -320,10 +316,10 @@ FileSource::find (Session& s, DataType type, const string& path, bool must_exist
                 } else {
 
                        /* only one match: happy days */
-                       
+
                        keeppath = de_duped_hits[0];
                }
-                                                  
+
        } else {
                 keeppath = path;
         }
@@ -341,7 +337,6 @@ FileSource::find (Session& s, DataType type, const string& path, bool must_exist
         }
 
         found_path = keeppath;
-
         ret = true;
 
   out:
@@ -359,8 +354,6 @@ bool
 FileSource::find_2X (Session& s, DataType type, const string& path, bool must_exist,
                      bool& isnew, uint16_t& chan, string& found_path)
 {
-       string search_path = s.source_search_path (type);
-
        string pathstr = path;
        string::size_type pos;
        bool ret = false;
@@ -371,18 +364,17 @@ FileSource::find_2X (Session& s, DataType type, const string& path, bool must_ex
 
                /* non-absolute pathname: find pathstr in search path */
 
-               vector<string> dirs;
+               vector<string> dirs = s.source_search_path (type);
+
                int cnt;
                string fullpath;
                string keeppath;
 
-               if (search_path.length() == 0) {
+               if (dirs.size() == 0) {
                        error << _("FileSource: search path not set") << endmsg;
                        goto out;
                }
 
-               split (search_path, dirs, ':');
-
                cnt = 0;
 
                for (vector<string>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
@@ -439,16 +431,14 @@ FileSource::find_2X (Session& s, DataType type, const string& path, bool must_ex
                if (cnt > 1) {
 
                        error << string_compose (
-                                       _("FileSource: \"%1\" is ambigous when searching %2\n\t"),
-                                       pathstr, search_path) << endmsg;
+                                       _("FileSource: \"%1\" is ambigous when searching\n\t"), pathstr) << endmsg;
                        goto out;
 
                } else if (cnt == 0) {
 
                        if (must_exist) {
                                error << string_compose(
-                                               _("Filesource: cannot find required file (%1): while searching %2"),
-                                               pathstr, search_path) << endmsg;
+                                               _("Filesource: cannot find required file (%1)"), pathstr) << endmsg;
                                goto out;
                        } else {
                                isnew = true;
@@ -498,13 +488,14 @@ FileSource::find_2X (Session& s, DataType type, const string& path, bool must_ex
                                goto out;
                        }
 
+#ifndef PLATFORM_WINDOWS
                        if (errno != ENOENT) {
                                error << string_compose(
                                                _("Filesource: cannot check for existing file (%1): %2"),
                                                path, strerror (errno)) << endmsg;
                                goto out;
                        }
-
+#endif
                        /* a new file */
                        isnew = true;
                        ret = true;
@@ -553,7 +544,14 @@ FileSource::set_within_session_from_path (const std::string& path)
 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
@@ -568,7 +566,7 @@ FileSource::is_stub () const
        if (!empty()) {
                return false;
        }
-       
+
        if (!removable()) {
                return false;
        }
@@ -579,7 +577,7 @@ FileSource::is_stub () const
 
        return true;
 }
-               
+
 int
 FileSource::rename (const string& newpath)
 {
@@ -592,7 +590,7 @@ 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;
@@ -605,3 +603,5 @@ FileSource::rename (const string& newpath)
 
        return 0;
 }
+
+