X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsession_configuration.cc;h=2daeee334801aae2099895b8e91c001968816ea6;hb=b3e7c88988b6b3ade5872935b7c371cf3a6a1040;hp=2cae7021e167a0245e3aca547e1270b11f89b994;hpb=bb9cc45cd22af67ac275a5e73accbe14fee664d8;p=ardour.git diff --git a/libs/ardour/session_configuration.cc b/libs/ardour/session_configuration.cc index 2cae7021e1..2daeee3348 100644 --- a/libs/ardour/session_configuration.cc +++ b/libs/ardour/session_configuration.cc @@ -17,13 +17,23 @@ */ +#include +#include /* for g_stat() */ +#include /* for build_filename() */ + +#include "pbd/error.h" +#include "pbd/file_utils.h" +#include "pbd/locale_guard.h" +#include "pbd/pathexpand.h" + #include "ardour/types.h" -#include "ardour/utils.h" +#include "ardour/filesystem_paths.h" #include "ardour/session_configuration.h" -#include "ardour/ardour.h" +#include "ardour/utils.h" #include "i18n.h" using namespace ARDOUR; +using namespace PBD; SessionConfiguration::SessionConfiguration () : @@ -44,7 +54,7 @@ XMLNode& SessionConfiguration::get_state () { XMLNode* root; - LocaleGuard lg (X_("POSIX")); + LocaleGuard lg (X_("C")); root = new XMLNode ("Ardour"); root->add_child_nocopy (get_variables ()); @@ -57,7 +67,7 @@ XMLNode& SessionConfiguration::get_variables () { XMLNode* node; - LocaleGuard lg (X_("POSIX")); + LocaleGuard lg (X_("C")); node = new XMLNode ("Config"); @@ -76,7 +86,7 @@ SessionConfiguration::get_variables () int -SessionConfiguration::set_state (XMLNode const& root) +SessionConfiguration::set_state (XMLNode const& root, int /*version*/) { if (root.name() != "Ardour") { return -1; @@ -111,13 +121,77 @@ SessionConfiguration::set_variables (const XMLNode& node) } void -SessionConfiguration::map_parameters (sigc::slot theSlot) +SessionConfiguration::map_parameters (boost::function& functor) { #undef CONFIG_VARIABLE #undef CONFIG_VARIABLE_SPECIAL -#define CONFIG_VARIABLE(type,var,name,value) theSlot (name); -#define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) theSlot (name); +#define CONFIG_VARIABLE(type,var,name,value) functor (name); +#define CONFIG_VARIABLE_SPECIAL(type,var,name,value,mutator) functor (name); #include "ardour/session_configuration_vars.h" #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_("C")); + 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; +}