2 * Config_FeatureReader.cpp
4 * Created on: Mar 20, 2014
8 #include <Config_FeatureReader.h>
10 #include <Event_Loop.h>
12 #include <libxml\parser.h>
13 #include <libxml\tree.h>
19 //Hardcoded xml entities
21 const static char* NODE_WORKBENCH = "workbench";
22 const static char* NODE_GROUP = "group";
23 const static char* NODE_FEATURE = "feature";
26 const static char* _ID = "id";
27 //const static char* WORKBENCH_ID = "id";
28 //const static char* GROUP_ID = "id";
29 //const static char* FEATURE_ID = "id";
30 const static char* FEATURE_TEXT = "text";
31 const static char* FEATURE_TOOLTIP = "tooltip";
32 const static char* FEATURE_ICON = "icon";
33 const static char* FEATURE_KEYSEQUENCE = "keysequence";
35 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile)
36 : Config_XMLReader(theXmlFile),
37 myFetchWidgetCfg(false)
42 if (!Event_Loop::Loop()) {
43 std::cout << "Config_FeatureReader::importWorkbench: "
44 << "No event loop registered" << std::endl;
49 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile,
50 const std::string& theLibraryName)
51 : Config_XMLReader(theXmlFile),
52 myLibraryName(theLibraryName),
53 myFetchWidgetCfg(false)
56 if (!Event_Loop::Loop()) {
57 std::cout << "Config_FeatureReader::importWorkbench: "
58 << "No event loop registered" << std::endl;
63 Config_FeatureReader::~Config_FeatureReader()
67 std::string Config_FeatureReader::featureWidgetCfg(std::string theFeatureName)
69 myFetchWidgetCfg = true;
71 myFetchWidgetCfg = false;
75 void Config_FeatureReader::processNode(xmlNodePtr theNode)
77 if (isNode(theNode, NODE_FEATURE, NULL)) {
78 if (myFetchWidgetCfg) {
79 xmlBufferPtr buffer = xmlBufferCreate();
80 int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1);
81 myWidgetCfg = std::string((char*) buffer->content);
83 Event_Loop* aEvLoop = Event_Loop::Loop();
84 Config_FeatureMessage aMessage(aEvLoop->EventByName("menu_item"), this);
85 fillFeature(theNode, aMessage);
86 aEvLoop->Send(aMessage);
89 //The m_last* variables always defined before fillFeature() call. XML is a tree.
90 if (isNode(theNode, NODE_GROUP, NULL)) {
91 myLastGroup = getProperty(theNode, _ID);
93 if (isNode(theNode, NODE_WORKBENCH, NULL)) {
94 myLastWorkbench = getProperty(theNode, _ID);
98 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
100 return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
103 void Config_FeatureReader::fillFeature(xmlNodePtr theRoot, Config_FeatureMessage& outFtMessage)
105 outFtMessage.setId(getProperty(theRoot, _ID));
106 outFtMessage.setText(getProperty(theRoot, FEATURE_TEXT));
107 outFtMessage.setTooltip(getProperty(theRoot, FEATURE_TOOLTIP));
108 outFtMessage.setIcon(getProperty(theRoot, FEATURE_ICON));
109 outFtMessage.setKeysequence(getProperty(theRoot, FEATURE_KEYSEQUENCE));
110 outFtMessage.setGroupId(myLastGroup);
111 outFtMessage.setWorkbenchId(myLastWorkbench);
112 outFtMessage.setPluginLibrary(myLibraryName);