5a9c2a9c56ff4529b3afd82d85f638b209a89bdc
[ardour.git] / libs / ardour / ardour / file_source.h
1 /*
2     Copyright (C) 2006-2009 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __ardour_filesource_h__
21 #define __ardour_filesource_h__
22
23 #include <exception>
24 #include <time.h>
25 #include "ardour/source.h"
26
27 namespace ARDOUR {
28
29 class MissingSource : public std::exception {
30 public:
31         virtual const char *what() const throw() { return "source file does not exist"; }
32 };
33
34 /** A source associated with a file on disk somewhere */
35 class FileSource : virtual public Source {
36 public:
37         const Glib::ustring& path() const { return _path; }
38
39         virtual bool safe_file_extension (const Glib::ustring& path) const = 0;
40
41         int  move_to_trash (const Glib::ustring& trash_dir_name);
42         void mark_take (const Glib::ustring& id);
43         void mark_immutable ();
44
45         const Glib::ustring& take_id ()     const { return _take_id; }
46         bool                 is_embedded () const { return _is_embedded; }
47         uint16_t             channel()      const { return _channel; }
48
49         int set_state (const XMLNode&, int version = 3000);
50
51         int set_source_name (const Glib::ustring& newname, bool destructive);
52
53         static void set_search_path (DataType type, const Glib::ustring& path);
54
55         static bool find (DataType type, const Glib::ustring& path,
56                         bool must_exist, bool& is_new, uint16_t& chan,
57                         Glib::ustring& found_path);
58
59 protected:
60         FileSource (Session& session, DataType type,
61                         const Glib::ustring& path, bool embedded,
62                         Source::Flag flags = Source::Flag(0));
63
64         FileSource (Session& session, const XMLNode& node, bool must_exist);
65
66         virtual int init (const Glib::ustring& idstr, bool must_exist);
67
68         virtual int move_dependents_to_trash() { return 0; }
69
70         bool removable () const;
71
72         Glib::ustring _path;
73         Glib::ustring _take_id;
74         bool          _file_is_new;
75         uint16_t      _channel;
76         bool          _is_embedded;
77
78         static std::map<DataType, Glib::ustring> search_paths;
79 };
80
81 } // namespace ARDOUR
82
83 #endif /* __ardour_filesource_h__ */
84