summaryrefslogtreecommitdiff
path: root/libs/ardour/session_configuration.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2014-06-29 15:45:08 +0200
committerRobin Gareus <robin@gareus.org>2014-06-29 16:11:46 +0200
commit8df35b35ba8cbc7e662f867e47325e2af5cf9262 (patch)
tree1beb9496579e344780eedbd0e424b16ea3e3d0b7 /libs/ardour/session_configuration.cc
parentcef26a4e1ef3833e8a2a7f1ee20fbdea70546779 (diff)
allow to load/save default session-properties
Diffstat (limited to 'libs/ardour/session_configuration.cc')
-rw-r--r--libs/ardour/session_configuration.cc70
1 files changed, 70 insertions, 0 deletions
diff --git a/libs/ardour/session_configuration.cc b/libs/ardour/session_configuration.cc
index 0cfdb52872..f9f43ba4b2 100644
--- a/libs/ardour/session_configuration.cc
+++ b/libs/ardour/session_configuration.cc
@@ -17,9 +17,15 @@
*/
+#include <glib.h>
+#include <glib/gstdio.h> /* for g_stat() */
+#include <glibmm/miscutils.h> /* for build_filename() */
+
+#include "pbd/file_utils.h"
#include "pbd/pathexpand.h"
#include "ardour/types.h"
+#include "ardour/filesystem_paths.h"
#include "ardour/session_configuration.h"
#include "i18n.h"
@@ -122,3 +128,67 @@ SessionConfiguration::map_parameters (boost::function<void (std::string)>& funct
#undef CONFIG_VARIABLE
#undef CONFIG_VARIABLE_SPECIAL
}
+
+
+bool
+SessionConfiguration::load_state ()
+{
+ std::string rcfile;
+ GStatBuf statbuf;
+ if (find_file (ardour_config_search_path(), "session.rc", rcfile)) {
+ if (g_stat (rcfile.c_str(), &statbuf)) {
+ return false;
+ }
+ if (statbuf.st_size == 0) {
+ return false;
+ }
+ XMLTree tree;
+ if (!tree.read (rcfile.c_str())) {
+ error << string_compose(_("%1: cannot part default session options \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
+ return false;
+ }
+
+ XMLNode& root (*tree.root());
+ if (root.name() != X_("SessionDefaults")) {
+ warning << _("Invalid session default XML Root.") << endmsg;
+ return false;
+ }
+
+ XMLNode* node;
+ if (((node = find_named_node (root, X_("Config"))) != 0)) {
+ LocaleGuard lg (X_("POSIX"));
+ set_variables(*node);
+ info << _("Loaded custom session defaults.") << endmsg;
+ } else {
+ warning << _("Found no session defaults in XML file.") << endmsg;
+ return false;
+ }
+
+ /* CUSTOM OVERRIDES */
+ set_audio_search_path("");
+ set_midi_search_path("");
+ set_raid_path("");
+ }
+ return true;
+}
+
+bool
+SessionConfiguration::save_state ()
+{
+ const std::string rcfile = Glib::build_filename (user_config_directory(), "session.rc");
+ if (rcfile.empty()) {
+ return false;
+ }
+
+ XMLTree tree;
+ XMLNode* root = new XMLNode(X_("SessionDefaults"));
+ root->add_child_nocopy (get_variables ());
+ tree.set_root (root);
+
+ if (!tree.write (rcfile.c_str())) {
+ error << _("Could not save session options") << endmsg;
+ return false;
+ }
+
+ return true;
+}