+ if (ret == 0) {
+ /* reload color theme */
+ load_color_theme (false);
+ }
+
+ return ret;
+}
+
+std::string
+UIConfiguration::color_file_name (bool use_my, bool with_version) const
+{
+ string basename;
+
+ if (use_my) {
+ basename += "my-";
+ }
+
+ std::string color_name = color_file.get();
+ size_t sep = color_name.find_first_of("-");
+ if (sep != string::npos) {
+ color_name = color_name.substr (0, sep);
+ }
+
+ basename += color_name;
+ basename += "-";
+ basename += downcase(std::string(PROGRAM_NAME));
+
+ std::string rev (revision);
+ std::size_t pos = rev.find_first_of("-");
+
+ if (with_version && pos != string::npos && pos > 0) {
+ basename += "-";
+ basename += rev.substr (0, pos); // COLORFILE_VERSION - program major.minor
+ }
+
+ basename += color_file_suffix;
+ return basename;
+}
+
+int
+UIConfiguration::load_color_file (string const & path)
+{
+ XMLTree tree;
+
+ info << string_compose (_("Loading color file %1"), path) << endmsg;
+
+ if (!tree.read (path.c_str())) {
+ error << string_compose(_("cannot read color file \"%1\""), path) << endmsg;
+ return -1;
+ }
+
+ if (set_state (*tree.root(), Stateful::loading_state_version)) {
+ error << string_compose(_("color file \"%1\" not loaded successfully."), path) << endmsg;
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+UIConfiguration::load_color_theme (bool allow_own)
+{
+ std::string cfile;
+ bool found = false;
+ /* ColorsChanged() will trigger a parameter_changed () which
+ * in turn calls save_state()
+ */
+ PBD::Unwinder<uint32_t> uw (block_save, block_save + 1);
+
+ if (find_file (theme_search_path(), color_file_name (false, true), cfile)) {
+ found = true;
+ }
+
+ if (!found) {
+ if (find_file (theme_search_path(), color_file_name (false, false), cfile)) {
+ found = true;
+ }
+ }
+
+ if (!found) {
+ warning << string_compose (_("Color file for %1 not found along %2"), color_file.get(), theme_search_path().to_string()) << endmsg;
+ return -1;
+ }
+
+ (void) load_color_file (cfile);
+
+ if (allow_own) {
+
+ found = false;
+
+ PBD::Searchpath sp (user_config_directory());
+
+ /* user's own color files never have the program name in them */
+
+ if (find_file (sp, color_file_name (true, true), cfile)) {
+ found = true;
+ }
+
+ if (!found) {
+ if (find_file (sp, color_file_name (true, false), cfile)) {
+ found = true;
+ }
+ }
+
+ if (found) {
+ (void) load_color_file (cfile);
+ }
+
+ }
+
+ ColorsChanged ();
+
+ return 0;
+}
+
+int
+UIConfiguration::store_color_theme ()
+{
+ XMLNode* root;
+
+ root = new XMLNode("Ardour");
+
+ XMLNode* parent = new XMLNode (X_("Colors"));
+ for (Colors::const_iterator i = colors.begin(); i != colors.end(); ++i) {
+ XMLNode* node = new XMLNode (X_("Color"));
+ node->set_property (X_("name"), i->first);
+ node->set_property (X_("value"), color_to_hex_string (i->second));
+ parent->add_child_nocopy (*node);
+ }
+ root->add_child_nocopy (*parent);
+
+ parent = new XMLNode (X_("ColorAliases"));
+ for (ColorAliases::const_iterator i = color_aliases.begin(); i != color_aliases.end(); ++i) {
+ XMLNode* node = new XMLNode (X_("ColorAlias"));
+ node->set_property (X_("name"), i->first);
+ node->set_property (X_("alias"), i->second);
+ parent->add_child_nocopy (*node);
+ }
+ root->add_child_nocopy (*parent);
+
+ parent = new XMLNode (X_("Modifiers"));
+ for (Modifiers::const_iterator i = modifiers.begin(); i != modifiers.end(); ++i) {
+ XMLNode* node = new XMLNode (X_("Modifier"));
+ node->set_property (X_("name"), i->first);
+ node->set_property (X_("modifier"), i->second.to_string());
+ parent->add_child_nocopy (*node);
+ }
+ root->add_child_nocopy (*parent);
+
+ XMLTree tree;
+ std::string colorfile = Glib::build_filename (user_config_directory(), color_file_name (true, true));;
+
+ tree.set_root (root);
+
+ if (!tree.write (colorfile.c_str())){
+ error << string_compose (_("Color file %1 not saved"), colorfile) << endmsg;
+ return -1;
+ }
+
+ return 0;