From 49940d62d78b2b9601402b22107f9ab79176f70b Mon Sep 17 00:00:00 2001
From: John Rassa <john@rassaonline.net>
Date: Fri, 10 Mar 2017 13:49:15 -0500
Subject: [PATCH] =?UTF-8?q?implemented=20feature=20element=20to=20allow=20?=
 =?UTF-8?q?themes=20to=20support=20new=20features=20w=E2=80=A6=20(#96)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* implemented feature element to allow themes to support new features without breaking older versions of ES

* supported attribute should only allow one value
---
 es-core/src/ThemeData.cpp | 31 +++++++++++++++++++++++++++++--
 es-core/src/ThemeData.h   |  3 +++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp
index 9ed9e093e..e216633e4 100644
--- a/es-core/src/ThemeData.cpp
+++ b/es-core/src/ThemeData.cpp
@@ -23,6 +23,9 @@ ElementMapType makeMap(const T& mapInit)
 	return m;
 }
 
+std::vector<std::string> ThemeData::sSupportedViews = boost::assign::list_of("system")("basic")("detailed")("video");
+std::vector<std::string> ThemeData::sSupportedFeatures = boost::assign::list_of("video");
+
 std::map< std::string, ElementMapType > ThemeData::sElementMap = boost::assign::map_list_of
 	("image", makeMap(boost::assign::map_list_of
 		("pos", NORMALIZED_PAIR)
@@ -181,6 +184,7 @@ void ThemeData::loadFile(const std::string& path)
 
 	parseIncludes(root);
 	parseViews(root);
+	parseFeatures(root);
 }
 
 
@@ -211,11 +215,31 @@ void ThemeData::parseIncludes(const pugi::xml_node& root)
 
 		parseIncludes(root);
 		parseViews(root);
+		parseFeatures(root);
 
 		mPaths.pop_back();
 	}
 }
 
+void ThemeData::parseFeatures(const pugi::xml_node& root)
+{
+	ThemeException error;
+	error.setFiles(mPaths);
+
+	for(pugi::xml_node node = root.child("feature"); node; node = node.next_sibling("feature"))
+	{
+		if(!node.attribute("supported"))
+			throw error << "Feature missing \"supported\" attribute!";
+
+		const std::string supportedAttr = node.attribute("supported").as_string();
+
+		if (std::find(sSupportedFeatures.begin(), sSupportedFeatures.end(), supportedAttr) != sSupportedFeatures.end())
+		{
+			parseViews(node);
+		}
+	}
+}
+
 void ThemeData::parseViews(const pugi::xml_node& root)
 {
 	ThemeException error;
@@ -238,8 +262,11 @@ void ThemeData::parseViews(const pugi::xml_node& root)
 			prevOff = nameAttr.find_first_not_of(delim, off);
 			off = nameAttr.find_first_of(delim, prevOff);
 			
-			ThemeView& view = mViews.insert(std::pair<std::string, ThemeView>(viewKey, ThemeView())).first->second;
-			parseView(node, view);
+			if (std::find(sSupportedViews.begin(), sSupportedViews.end(), viewKey) != sSupportedViews.end())
+			{
+				ThemeView& view = mViews.insert(std::pair<std::string, ThemeView>(viewKey, ThemeView())).first->second;
+				parseView(node, view);
+			}
 		}
 	}
 }
diff --git a/es-core/src/ThemeData.h b/es-core/src/ThemeData.h
index 408d0c52c..082b73684 100644
--- a/es-core/src/ThemeData.h
+++ b/es-core/src/ThemeData.h
@@ -149,10 +149,13 @@ public:
 
 private:
 	static std::map< std::string, std::map<std::string, ElementPropertyType> > sElementMap;
+	static std::vector<std::string> sSupportedFeatures;
+	static std::vector<std::string> sSupportedViews;
 
 	std::deque<boost::filesystem::path> mPaths;
 	float mVersion;
 
+	void parseFeatures(const pugi::xml_node& themeRoot);
 	void parseIncludes(const pugi::xml_node& themeRoot);
 	void parseViews(const pugi::xml_node& themeRoot);
 	void parseView(const pugi::xml_node& viewNode, ThemeView& view);