summaryrefslogtreecommitdiff
path: root/server/src/macro_parser.cc
diff options
context:
space:
mode:
authordeva <deva>2008-03-20 14:55:19 +0000
committerdeva <deva>2008-03-20 14:55:19 +0000
commit885e139e750fa13a581dff70b3d8d91a9170a772 (patch)
tree3e6c470e70c1f600a62bd70ccc40708a6e739cd1 /server/src/macro_parser.cc
parenta224b5f10f45feaf3e34641a3f794d19571e3c62 (diff)
Added test implementation of macrolist special xml node.
Diffstat (limited to 'server/src/macro_parser.cc')
-rw-r--r--server/src/macro_parser.cc89
1 files changed, 89 insertions, 0 deletions
diff --git a/server/src/macro_parser.cc b/server/src/macro_parser.cc
index 9161613..aba7fda 100644
--- a/server/src/macro_parser.cc
+++ b/server/src/macro_parser.cc
@@ -93,6 +93,95 @@ static void start_hndl(void *p, const char *el, const char **attr)
return; // Don't do further parsing of this tag.
}
+ if(name == "macrolist") {
+ std::map< std::string, int > macro_usage;
+
+ macro_usage["example"] = 3;
+ macro_usage["pimmelsus"] = 2;
+ macro_usage["dimmer"] = 1;
+ macro_usage["fnullemam"] = 2;
+ macro_usage["ektosup"] = 0;
+ macro_usage["fillehej"] = 0;
+ macro_usage["heppelis"] = 0;
+ macro_usage["simmermuh"] = 0;
+ macro_usage["skilletran"] = 0;
+ macro_usage["futterbah"] = 0;
+
+ Widget macrolist;
+ Widget *wp;
+
+ if(parser->stack.size() > 0) {// We only pushback the child if there is a parent.
+ parser->stack.back()->widgets.push_back(macrolist);
+ wp = &parser->stack.back()->widgets.back();
+ } else {
+ parser->macro->widgets.push_back(macrolist);
+ wp = &parser->macro->widgets.back();
+ }
+ parser->stack.push_back(wp);
+
+ wp->type = "listbox";
+ wp->properties["name"] = attributes["name"];
+ wp->properties["value"] = "example";
+ wp->properties["help"] = attributes["Noget info tekst."];
+
+ {
+ Widget item;
+ item.type = "item";
+ item.properties["type"] = "header";
+ item.properties["caption"] = "Oftest brugte makroer:";
+ wp->widgets.push_back(item);
+ }
+
+ std::map< std::string, std::string > macro_usage_most;
+ std::map< std::string, int >::iterator i = macro_usage.begin();
+ while(i != macro_usage.end()) {
+ char buf[32];
+ // FIXME: Ugly hack to make sorting work on equal usage number (sub sort alphabetically)
+ // This only works when usage count is less than 999.
+ sprintf(buf, "%03d", 999 - (*i).second);
+ std::string key = std::string(buf) + "-" + (*i).first;
+ if((*i).second != 0) macro_usage_most[key] = (*i).first;
+ i++;
+ }
+
+ std::map< std::string, std::string >::iterator j = macro_usage_most.begin();
+ while(j != macro_usage_most.end()) {
+ Widget item;
+ item.type = "item";
+ item.properties["value"] = (*j).second;
+ item.properties["caption"] = (*j).second;
+ wp->widgets.push_back(item);
+ j++;
+ }
+
+ {
+ Widget item;
+ item.type = "item";
+ item.properties["type"] = "separator";
+ wp->widgets.push_back(item);
+ }
+
+ {
+ Widget item;
+ item.type = "item";
+ item.properties["type"] = "header";
+ item.properties["caption"] = "Alle makroer alfabetisk:";
+ wp->widgets.push_back(item);
+ }
+
+ std::map< std::string, int >::iterator k = macro_usage.begin();
+ while(k != macro_usage.end()) {
+ Widget item;
+ item.type = "item";
+ item.properties["value"] = (*k).first;
+ item.properties["caption"] = (*k).first;
+ wp->widgets.push_back(item);
+ k++;
+ }
+
+ return;// Don't do further parsing of this tag.
+ }
+
Widget widget;
widget.type = name;