monster commit: transport mgmt changes from 2.X (omnibus edition); make slave use...
[ardour.git] / libs / ardour / filesystem_paths.cc
1 /*
2     Copyright (C) 2007 Tim Mayberry
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 #include <cstdlib>
20
21 #include "pbd/error.h"
22 #include "pbd/filesystem_paths.h"
23
24 #include <glibmm/miscutils.h>
25
26 #include "ardour/directory_names.h"
27 #include "ardour/filesystem_paths.h"
28
29 #define WITH_STATIC_PATHS 1
30
31 using namespace PBD;
32
33 namespace ARDOUR {
34
35 using std::string;
36
37 sys::path
38 user_config_directory ()
39 {
40         const char* c = 0;
41         sys::path p;
42
43         /* adopt freedesktop standards, and put .ardour3 into $XDG_CONFIG_HOME or ~/.config
44          */
45
46         if ((c = getenv ("XDG_CONFIG_HOME")) != 0) {
47                 p = c;
48         } else {
49                 const string home_dir = Glib::get_home_dir();
50         
51                 if (home_dir.empty ()) {
52                         const string error_msg = "Unable to determine home directory";
53                         
54                         // log the error
55                         error << error_msg << endmsg;
56                         
57                         throw sys::filesystem_error(error_msg);
58                 }
59
60                 p = home_dir;
61                 p /= ".config";
62         }
63         
64         p /= user_config_dir_name;
65
66         return p;
67 }
68
69 sys::path
70 ardour_module_directory ()
71 {
72         sys::path module_directory(MODULE_DIR);
73         module_directory /= "ardour3";
74         return module_directory;
75 }
76
77 SearchPath
78 ardour_search_path ()
79 {
80         SearchPath spath_env(Glib::getenv("ARDOUR_PATH"));
81         return spath_env;
82 }
83
84 SearchPath
85 system_config_search_path ()
86 {
87 #ifdef WITH_STATIC_PATHS
88         SearchPath config_path(string(CONFIG_DIR));
89 #else
90         SearchPath config_path(system_config_directories());
91 #endif
92
93         config_path.add_subdirectory_to_paths("ardour3");
94
95         return config_path;
96 }
97
98 SearchPath
99 system_data_search_path ()
100 {
101 #ifdef WITH_STATIC_PATHS
102         SearchPath data_path(string(DATA_DIR));
103 #else
104         SearchPath data_path(system_data_directories());
105 #endif
106
107         data_path.add_subdirectory_to_paths("ardour3");
108
109         return data_path;
110 }
111
112 } // namespace ARDOUR