diff options
-rw-r--r-- | server/src/macro_parser.cc | 89 | ||||
-rw-r--r-- | server/xml/Makefile.am | 6 | ||||
-rw-r--r-- | server/xml/start.xml | 17 |
3 files changed, 110 insertions, 2 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; diff --git a/server/xml/Makefile.am b/server/xml/Makefile.am index 0e86339..ba48c9b 100644 --- a/server/xml/Makefile.am +++ b/server/xml/Makefile.am @@ -1,9 +1,11 @@ EXTRA_DIST = \ example.xml \ - patient.xml + patient.xml \ + start.xml xmldir = $(datadir)/xml xml_DATA = \ example.xml \ - patient.xml + patient.xml \ + start.xml diff --git a/server/xml/start.xml b/server/xml/start.xml new file mode 100644 index 0000000..858b0d2 --- /dev/null +++ b/server/xml/start.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<macro name="start" version="1.0"> + <window name="mainwindow" + caption="Start" + width="500" + height="560" + layout="vbox"> + <frame name="frame" layout="vbox"> + <label name="macro" caption="Vælg den makro som skal indlæses:"/> + <macrolist name="macro_list"/> + </frame> + <frame name="buttons" layout="hbox"> + <button name="cancel" caption="Annuller" action="cancel" help="Hjælpenisse"/> + <button name="continue" caption="Aktivér marko" action="continue" field="macro_list" help="Hjælpenisse"/> + </frame> + </window> +</macro> |