]> git.sesse.net Git - ccbs/blobdiff - bigscreen/theme.cpp
Remove a debugging printf.
[ccbs] / bigscreen / theme.cpp
index e873c9d9dfdcb3e16dee7e52bda4298e5384f89b..542d2ada93faf271d6f00d63dbd36a48828b77cb 100644 (file)
@@ -7,11 +7,11 @@
 
 std::map<std::string, std::string> config;
 
-void init_theme()
+void read_config(const char *filename)
 {
-       FILE *fp = fopen("theme.config", "rb");
+       FILE *fp = fopen(filename, "r");
        if (fp == NULL)
-               throw std::runtime_error("Couldn't open theme.config.");
+               throw std::runtime_error("Couldn't open theme file.");
 
        while (!feof(fp)) {
                char buf[1024];
@@ -46,17 +46,35 @@ void init_theme()
                        continue;
                }
 
-               config.insert(std::make_pair(key, value));
+               config[key] = value;
        }
        fclose(fp);
 }
 
+void init_theme()
+{
+       read_config("theme.config");
+       try {
+               read_config("theme.config.local");
+       } catch (...) {
+               // Ignore.
+       }
+}
+
 std::string get_theme_config(const std::string &key, const std::string subkey)
 {
        if (config.count(key + "." + subkey)) {
                return config[key + "." + subkey];
        }
 
+       std::string modkey = key;
+       while (modkey.find_last_of(".") != std::string::npos) {
+               modkey.resize(modkey.find_last_of("."));
+               if (config.count(modkey + "." + subkey)) {
+                       return config[modkey + "." + subkey];
+               }
+       }
+
        return config["default." + subkey];
 }