2 * Config_FeatureReader.cpp
4 * Created on: Mar 20, 2014
8 #include <Config_Keywords.h>
9 #include <Config_Common.h>
10 #include <Config_FeatureMessage.h>
11 #include <Config_FeatureReader.h>
12 #include <Events_Message.h>
13 #include <Events_Loop.h>
15 #include <libxml/parser.h>
16 #include <libxml/tree.h>
17 #include <libxml/xmlstring.h>
27 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile,
28 const std::string& theLibraryName,
29 const char* theEventGenerated)
30 : Config_XMLReader(theXmlFile),
31 myLibraryName(theLibraryName),
32 myEventGenerated(theEventGenerated ? theEventGenerated : EVENT_FEATURE_LOADED)
36 Config_FeatureReader::~Config_FeatureReader()
40 std::list<std::string> Config_FeatureReader::features() const
45 void Config_FeatureReader::processNode(xmlNodePtr theNode)
47 Events_ID aMenuItemEvent = Events_Loop::eventByName(myEventGenerated);
48 if (isNode(theNode, NODE_FEATURE, NULL)) {
49 Events_Loop* aEvLoop = Events_Loop::loop();
50 Config_FeatureMessage aMessage(aMenuItemEvent, this);
51 fillFeature(theNode, aMessage);
52 myFeatures.push_back(getProperty(theNode, _ID));
53 //If a feature has xml definition for it's widget:
54 aMessage.setUseInput(hasChild(theNode));
55 aEvLoop->send(aMessage);
56 //The m_last* variables always defined before fillFeature() call. XML is a tree.
57 } else if (isNode(theNode, NODE_GROUP, NULL)) {
58 myLastGroup = getProperty(theNode, _ID);
59 } else if (isNode(theNode, NODE_WORKBENCH, NULL)) {
60 myLastWorkbench = getProperty(theNode, _ID);
61 //Process SOURCE, VALIDATOR nodes.
63 Config_XMLReader::processNode(theNode);
66 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
68 return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NODE_FEATURE, NULL);
71 void Config_FeatureReader::fillFeature(xmlNodePtr theNode, Config_FeatureMessage& outFeatureMessage)
73 outFeatureMessage.setId(getProperty(theNode, _ID));
74 outFeatureMessage.setPluginLibrary(myLibraryName);
75 outFeatureMessage.setNestedFeatures(getProperty(theNode, FEATURE_NESTED));
77 bool isInternal = isInternalFeature(theNode);
78 outFeatureMessage.setInternal(isInternal);
80 //Internal feature has no visual representation.
83 outFeatureMessage.setText(getProperty(theNode, FEATURE_TEXT));
84 outFeatureMessage.setTooltip(getProperty(theNode, FEATURE_TOOLTIP));
85 outFeatureMessage.setIcon(getProperty(theNode, FEATURE_ICON));
86 outFeatureMessage.setKeysequence(getProperty(theNode, FEATURE_KEYSEQUENCE));
87 outFeatureMessage.setGroupId(myLastGroup);
88 outFeatureMessage.setWorkbenchId(myLastWorkbench);
91 bool Config_FeatureReader::isInternalFeature(xmlNodePtr theNode)
93 std::string prop = getProperty(theNode, FEATURE_INTERNAL);
94 std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
95 if (prop.empty() || prop == "false" || prop == "0") {