fix pango font style (prev commit)
[ardour.git] / gtk2_ardour / ui_config.cc
index 10628334fdae605d9ba51e3852f80dfc970eb646..342adb294fd2687ed1bc23c998aa450b3f406235 100644 (file)
 */
 
 #include <unistd.h>
+#include <cstdlib>
 #include <cstdio> /* for snprintf, grrr */
 
 #include <glibmm/miscutils.h>
 
 #include "pbd/failed_constructor.h"
 #include "pbd/xml++.h"
-#include "pbd/filesystem.h"
 #include "pbd/file_utils.h"
 #include "pbd/error.h"
 
-#include "ardour/ardour.h"
+#include "gtkmm2ext/rgb_macros.h"
+
 #include "ardour/filesystem_paths.h"
 
 #include "ui_config.h"
@@ -45,11 +46,13 @@ UIConfiguration::UIConfiguration ()
 #undef  CANVAS_VARIABLE
 #define UI_CONFIG_VARIABLE(Type,var,name,val) var (name,val),
 #define CANVAS_VARIABLE(var,name) var (name),
+#define CANVAS_STRING_VARIABLE(var,name) var (name),
 #include "ui_config_vars.h"
 #include "canvas_vars.h"
 #undef  UI_CONFIG_VARIABLE
 #undef  CANVAS_VARIABLE
-       hack(true)
+#undef  CANVAS_STRING_VARIABLE
+       _dirty (false)
 {
        load_state();
 }
@@ -58,12 +61,21 @@ UIConfiguration::~UIConfiguration ()
 {
 }
 
+void
+UIConfiguration::map_parameters (boost::function<void (std::string)>& functor)
+{
+#undef  UI_CONFIG_VARIABLE
+#define UI_CONFIG_VARIABLE(Type,var,Name,value) functor (Name);
+#include "ui_config_vars.h"
+#undef  UI_CONFIG_VARIABLE
+}
+
 int
 UIConfiguration::load_defaults ()
 {
        int found = 0;
 
-       sys::path default_ui_rc_file;
+       std::string default_ui_rc_file;
        std::string rcfile;
 
        if (getenv ("ARDOUR_SAE")) {
@@ -72,13 +84,11 @@ UIConfiguration::load_defaults ()
                rcfile = "ardour3_ui_default.conf";
        }
 
-       if (find_file_in_search_path (ardour_search_path() + system_config_search_path(),
-                                     rcfile, default_ui_rc_file) )
-       {
+       if (find_file_in_search_path (ardour_config_search_path(), rcfile, default_ui_rc_file) ) {
                XMLTree tree;
                found = 1;
 
-               string rcfile = default_ui_rc_file.to_string();
+               string rcfile = default_ui_rc_file;
 
                info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
 
@@ -91,6 +101,8 @@ UIConfiguration::load_defaults ()
                        error << string_compose(_("default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
                        return -1;
                }
+
+               _dirty = false;
        }
 
        return found;
@@ -101,15 +113,13 @@ UIConfiguration::load_state ()
 {
        bool found = false;
 
-       sys::path default_ui_rc_file;
+       std::string default_ui_rc_file;
 
-       if ( find_file_in_search_path (ardour_search_path() + system_config_search_path(),
-                       "ardour3_ui_default.conf", default_ui_rc_file) )
-       {
+       if ( find_file_in_search_path (ardour_config_search_path(), "ardour3_ui_default.conf", default_ui_rc_file)) {
                XMLTree tree;
                found = true;
 
-               string rcfile = default_ui_rc_file.to_string();
+               string rcfile = default_ui_rc_file;
 
                info << string_compose (_("Loading default ui configuration file %1"), rcfile) << endl;
 
@@ -124,15 +134,13 @@ UIConfiguration::load_state ()
                }
        }
 
-       sys::path user_ui_rc_file;
+       std::string user_ui_rc_file;
 
-       if (find_file_in_search_path (ardour_search_path() + user_config_directory(),
-                       "ardour3_ui.conf", user_ui_rc_file))
-       {
+       if (find_file_in_search_path (ardour_config_search_path(), "ardour3_ui.conf", user_ui_rc_file)) {
                XMLTree tree;
                found = true;
 
-               string rcfile = user_ui_rc_file.to_string();
+               string rcfile = user_ui_rc_file;
 
                info << string_compose (_("Loading user ui configuration file %1"), rcfile) << endmsg;
 
@@ -145,12 +153,15 @@ UIConfiguration::load_state ()
                        error << string_compose(_("user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
                        return -1;
                }
+
+               _dirty = false;
        }
 
        if (!found)
                error << _("could not find any ui configuration file, canvas will look broken.") << endmsg;
 
        pack_canvasvars();
+
        return 0;
 }
 
@@ -159,18 +170,8 @@ UIConfiguration::save_state()
 {
        XMLTree tree;
 
-       try {
-               sys::create_directories (user_config_directory ());
-       }
-       catch (const sys::filesystem_error& ex) {
-               error << "Could not create user configuration directory" << endmsg;
-               return -1;
-       }
-
-       sys::path rcfile_path(user_config_directory());
-
-       rcfile_path /= "ardour3_ui.conf";
-       const string rcfile = rcfile_path.to_string();
+       std::string rcfile(user_config_directory());
+       rcfile = Glib::build_filename (rcfile, "ardour3_ui.conf");
 
        // this test seems bogus?
        if (rcfile.length()) {
@@ -181,6 +182,8 @@ UIConfiguration::save_state()
                }
        }
 
+       _dirty = false;
+
        return 0;
 }
 
@@ -214,10 +217,12 @@ UIConfiguration::get_variables (std::string which_node)
 #undef  CANVAS_VARIABLE
 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
+#define CANVAS_STRING_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
 #include "ui_config_vars.h"
 #include "canvas_vars.h"
 #undef  UI_CONFIG_VARIABLE
 #undef  CANVAS_VARIABLE
+#undef  CANVAS_STRING_VARIABLE
 
        return *node;
 }
@@ -244,6 +249,7 @@ UIConfiguration::set_state (const XMLNode& root, int /*version*/)
 
                }
        }
+
        return 0;
 }
 
@@ -260,19 +266,49 @@ UIConfiguration::set_variables (const XMLNode& node)
          if (var.set_from_node (node)) { \
                 ParameterChanged (name); \
                 }
+#define CANVAS_STRING_VARIABLE(var,name)       \
+         if (var.set_from_node (node)) { \
+                ParameterChanged (name); \
+                }
 #include "ui_config_vars.h"
 #include "canvas_vars.h"
 #undef  UI_CONFIG_VARIABLE
 #undef  CANVAS_VARIABLE
+#undef  CANVAS_STRING_VARIABLE
 }
 
 void
 UIConfiguration::pack_canvasvars ()
 {
 #undef  CANVAS_VARIABLE
-#define CANVAS_VARIABLE(var,name) canvas_colors.push_back(&var);
+#define CANVAS_VARIABLE(var,name) canvas_colors.insert (std::pair<std::string,ColorVariable<uint32_t>* >(name,&var));
+#define CANVAS_STRING_VARIABLE(var,name) 
 #include "canvas_vars.h"
 #undef  CANVAS_VARIABLE
+#undef  CANVAS_STRING_VARIABLE
+}
+
+uint32_t
+UIConfiguration::color_by_name (const std::string& name)
+{
+       map<std::string,ColorVariable<uint32_t>* >::iterator i = canvas_colors.find (name);
+
+       if (i != canvas_colors.end()) {
+               return i->second->get();
+       }
+
+       // cerr << string_compose (_("Color %1 not found"), name) << endl;
+       return RGBA_TO_UINT (g_random_int()%256,g_random_int()%256,g_random_int()%256,0xff);
 }
 
+void
+UIConfiguration::set_dirty ()
+{
+       _dirty = true;
+}
 
+bool
+UIConfiguration::dirty () const
+{
+       return _dirty;
+}