summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authordeva <deva>2011-08-02 08:00:20 +0000
committerdeva <deva>2011-08-02 08:00:20 +0000
commited9e290b441a6486c576c2e2e4baa69fa0f3ed37 (patch)
tree759ace8ca615e3a4167a5e783297cc761b89b992 /client
parent23f39df8b8edeacfa5821050abbdc855acb2edd6 (diff)
New 'open course' feature.
Diffstat (limited to 'client')
-rw-r--r--client/client.pro2
-rw-r--r--client/macro.cc6
-rw-r--r--client/macro.h5
-rw-r--r--client/macrowindow.cc13
-rw-r--r--client/macrowindow.h6
-rw-r--r--client/mainwindow.cc72
-rw-r--r--client/mainwindow.h8
-rw-r--r--client/netcom.cc82
-rw-r--r--client/netcom.h7
-rw-r--r--client/pracro.cc25
-rw-r--r--client/template.cc103
-rw-r--r--client/template.h57
12 files changed, 320 insertions, 66 deletions
diff --git a/client/client.pro b/client/client.pro
index 852a212..44fc02c 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -62,6 +62,7 @@ HEADERS += \
messagebox.h \
netcom.h \
resumewidget.h \
+ template.h \
widgets.h \
widgets/common.h \
widgets/widget.h \
@@ -100,6 +101,7 @@ SOURCES += \
messagebox.cc \
netcom.cc \
resumewidget.cc \
+ template.cc \
widgets/common.cc \
widgets/widget.cc \
widgets/label.cc \
diff --git a/client/macro.cc b/client/macro.cc
index dfe464d..320faa3 100644
--- a/client/macro.cc
+++ b/client/macro.cc
@@ -35,8 +35,8 @@
#include "macrodrawer.h"
#include "macrowindow.h"
-Macro::Macro(Entities &e, NetCom &n, QString t, QScrollArea *s)
- : entities(e), netcom(n), templ(t)
+Macro::Macro(Entities &e, NetCom &n, QString c, QString t, QScrollArea *s)
+ : entities(e), netcom(n), course(c), templ(t)
{
window = NULL;
drawer = NULL;
@@ -69,7 +69,7 @@ void Macro::update(QDomNode &node)
drawer = new MacroDrawer(this, elem.attribute("caption", name));
if(window == NULL) {
- window = new MacroWindow(netcom, templ, isstatic, iscompact,
+ window = new MacroWindow(netcom, course, templ, isstatic, iscompact,
scrollarea, drawer);
QFont f = window->font();
diff --git a/client/macro.h b/client/macro.h
index b24b809..0fd6c51 100644
--- a/client/macro.h
+++ b/client/macro.h
@@ -44,7 +44,8 @@ class MacroDrawer;
class Macro : public Entity {
public:
- Macro(Entities &entities, NetCom &netcom, QString templ,
+ Macro(Entities &entities, NetCom &netcom,
+ QString course, QString templ,
QScrollArea *scrollarea);
virtual ~Macro() {}
@@ -77,6 +78,8 @@ private:
QScrollArea *scrollarea;
Entities &entities;
NetCom &netcom;
+
+ QString course;
QString templ;
};
diff --git a/client/macrowindow.cc b/client/macrowindow.cc
index bbfab8e..44f2797 100644
--- a/client/macrowindow.cc
+++ b/client/macrowindow.cc
@@ -46,7 +46,7 @@ extern MainWindow *gmainwindow;
extern QString cpr;
extern QString user;
-MacroWindow::MacroWindow(NetCom &n, QString templ,
+MacroWindow::MacroWindow(NetCom &n, QString course, QString templ,
bool is_static, bool compact,
QScrollArea *scrollarea,
MacroDrawer *d)
@@ -62,8 +62,9 @@ MacroWindow::MacroWindow(NetCom &n, QString templ,
waschanged = false;
+ this->course = course;
this->templ = templ;
-
+
resumewidget = new ResumeWidget(compact);
active = true;
@@ -172,7 +173,7 @@ bool MacroWindow::doCommit()
QVector< Widget* > wlist;
if(mainwidget) wlist = mainwidget->widgetList();
- netcom.send(wlist, templ, macro, version);
+ netcom.send(wlist, course, templ, macro, version);
return true;
} else {
@@ -198,7 +199,7 @@ void MacroWindow::cancel()
void MacroWindow::expandWrapper()
{
if(currentWidget() != resumewidget) return;
- netcom.send(templ, macro);
+ netcom.send(course, templ, macro);
}
void MacroWindow::collapseWrapper()
@@ -206,7 +207,7 @@ void MacroWindow::collapseWrapper()
if(currentWidget() == resumewidget) return;
if(waschanged == false) {
- netcom.send(templ);
+ netcom.send(course, templ);
return;
}
@@ -224,7 +225,7 @@ void MacroWindow::collapseWrapper()
doCommit();
break;
case MessageBox::Close:
- netcom.send(templ);
+ netcom.send(course, templ);
break;
case MessageBox::Cancel:
default:
diff --git a/client/macrowindow.h b/client/macrowindow.h
index f92b4c0..afc144d 100644
--- a/client/macrowindow.h
+++ b/client/macrowindow.h
@@ -41,7 +41,7 @@ class MacroWindow : public Collapser
{
Q_OBJECT
public:
- MacroWindow(NetCom &netcom, QString templ,
+ MacroWindow(NetCom &netcom, QString course, QString templ,
bool is_static, bool compact,
QScrollArea *scrollarea,
MacroDrawer *drawer);
@@ -77,8 +77,10 @@ private:
bool doCommit();
- QString macro;
+ QString course;
QString templ;
+ QString macro;
+
QString version;
Widget *mainwidget;
diff --git a/client/mainwindow.cc b/client/mainwindow.cc
index dfe112f..6bf0543 100644
--- a/client/mainwindow.cc
+++ b/client/mainwindow.cc
@@ -48,6 +48,7 @@
#include "macro.h"
#include "header.h"
+#include "template.h"
#include "debug.h"
@@ -65,8 +66,8 @@ public:
MainWindow *gmainwindow = NULL;
-MainWindow::MainWindow(QString patientid, QString templ, QString host,
- quint16 port, QString user)
+MainWindow::MainWindow(QString patientid, QString course, QString templ,
+ QString host, quint16 port, QString user)
: QMainWindow(0), // Qt::WindowContextHelpButtonHint
netcom(host, port)
{
@@ -94,6 +95,7 @@ MainWindow::MainWindow(QString patientid, QString templ, QString host,
this->patientid = patientid;
this->user = user;
+ this->course = course;
this->templ = templ;
setWindowTitle("Pracro - " + patientid);
@@ -238,6 +240,7 @@ void MainWindow::init()
netcom.patientid = patientid;
netcom.templ = templ;
+ netcom.course = course;
netcom.user = user;
netcom.initConnection();
@@ -285,7 +288,7 @@ void MainWindow::updateMacros(QDomNodeList &nodes)
if(entities.find(j) == entities.end()) {
Entity *e = NULL;
if(elem.tagName() == "macro") {
- e = new Macro(entities, netcom, templ, scrollarea);
+ e = new Macro(entities, netcom, course, templ, scrollarea);
}
if(elem.tagName() == "header") {
e = new Header();
@@ -306,6 +309,49 @@ void MainWindow::updateMacros(QDomNodeList &nodes)
}
}
+void MainWindow::updateTemplates(QDomNodeList &nodes)
+{
+ for(int j = 0; j < nodes.count(); j++) {
+ QDomNode node = nodes.at(j);
+ QDomElement elem = node.toElement();
+
+ if(elem.tagName() == "template") {
+ QString name = elem.attribute("name");
+
+ if(entities.find(j) == entities.end()) {
+ Template *e = new Template(netcom);
+ connect(e, SIGNAL(setTemplate(QString)),
+ this, SLOT(setTemplate(QString)));
+ entities[j] = e;
+ entities[j]->update(node);
+ w->layout()->addWidget(e->widget());
+ } else {
+ entities[j]->update(node);
+ }
+ continue;
+ }
+
+ showError("XML Error", "Expected template tag. Got '" +
+ elem.tagName() + "' tag.");
+ continue;
+
+ }
+}
+
+void MainWindow::setTemplate(QString name)
+{
+ templ = name;
+
+ Entities::iterator i = entities.begin();
+ while(i != entities.end()) {
+ delete i.value()->widget();
+ // delete i.value();
+ i++;
+ }
+
+ entities.clear();
+}
+
void MainWindow::handle(QDomDocument &doc)
{
if(closing) close();
@@ -323,12 +369,12 @@ void MainWindow::handle(QDomDocument &doc)
continue;
}
- if(element.tagName() != "template") {
- showError("XML error", "Outer tag not a template.");
+ if(element.tagName() != "template" && element.tagName() != "course") {
+ showError("XML error", "Outer tag not a template or course.");
continue;
}
- if(element.attribute("name") != templ) {
+ if(element.tagName() == "template" && element.attribute("name") != templ) {
showError("XML error",
"Got template name that didn't match current session.");
continue;
@@ -337,9 +383,17 @@ void MainWindow::handle(QDomDocument &doc)
// Set headers. titles, etc...
updateTemplateHeaders(node);
- // Update macros, header and resumes.
- QDomNodeList macronodes = node.childNodes();
- updateMacros(macronodes);
+ if(element.tagName() == "course") {
+ // Update macros, header and resumes.
+ QDomNodeList templatenodes = node.childNodes();
+ updateTemplates(templatenodes);
+ }
+
+ if(element.tagName() == "template") {
+ // Update macros, header and resumes.
+ QDomNodeList macronodes = node.childNodes();
+ updateMacros(macronodes);
+ }
}
}
diff --git a/client/mainwindow.h b/client/mainwindow.h
index 8449467..c52db58 100644
--- a/client/mainwindow.h
+++ b/client/mainwindow.h
@@ -42,8 +42,8 @@
class MainWindow : public QMainWindow {
Q_OBJECT
public:
- MainWindow(QString patientid, QString templ, QString host, quint16 port,
- QString user);
+ MainWindow(QString patientid, QString course, QString templ,
+ QString host, quint16 port, QString user);
~MainWindow();
void closeEvent(QCloseEvent *event);
@@ -58,12 +58,16 @@ public slots:
void showError(QString title, QString text);
bool hasOpen(void *me);
+ void setTemplate(QString name);
private:
+ void updateTemplates(QDomNodeList &nodes);
void updateMacros(QDomNodeList &nodes);
void updateTemplateHeaders(QDomNode &templatenode);
+ QString course;
QString templ;
+
NetCom netcom;
QString patientid;
diff --git a/client/netcom.cc b/client/netcom.cc
index 7873c2b..9c755b5 100644
--- a/client/netcom.cc
+++ b/client/netcom.cc
@@ -87,85 +87,116 @@ void NetCom::replyFinished(QNetworkReply *reply)
}
}
-void NetCom::makeTransfer(QDomDocument &doc, session_state_t state)
+void NetCom::makeTransfer(QByteArray body, session_state_t state, QString uri)
{
- DEBUG(netcom, "Making transfer:\n%s", doc.toString().toStdString().c_str());
+ // Use '/course/template/' uri if empty.
+ if(uri == "") {
+ uri = "/";
+ if(course != "") {
+ uri += course + "/";
+ if(templ != "") {
+ uri += templ + "/";
+ }
+ }
+ }
+
+ DEBUG(netcom, "Making transfer:\n%s", QString(body).toStdString().c_str());
LOG(netcom, "SESSION ID: %s\n", sessionid.toStdString().c_str());
request.setRawHeader("User-Agent", "Pracro Client v"VERSION);
-
+ /*
if(sessionid != "") {
request.setRawHeader("SessionID", sessionid.toStdString().c_str());
} else {
request.setRawHeader("SessionPatientID", patientid.toStdString().c_str());
request.setRawHeader("SessionTemplate", templ.toStdString().c_str());
}
+ */
+
+ QUrl url;
+ url.setHost(request.url().host());
+ url.setPort(request.url().port());
+ url.setScheme(request.url().scheme());
switch(state) {
case ::commit:
- request.setRawHeader("SessionCommit", "yes");
+ // request.setRawHeader("SessionCommit", "yes");
+ url.addQueryItem("statechange", "commit");
break;
case ::discard:
- request.setRawHeader("SessionDiscard", "yes");
+ // request.setRawHeader("SessionDiscard", "yes");
+ url.addQueryItem("statechange", "discard");
break;
case ::nocommit:
- request.setRawHeader("SessionNoCommit", "yes");
+ // request.setRawHeader("SessionNoCommit", "yes");
+ url.addQueryItem("statechange", "nocommit");
break;
default:
case ::none:
break;
}
- manager->post(request, doc.toByteArray());
+ url.setPath(uri);
+ if(sessionid != "") url.addQueryItem("sessionid", sessionid);
+ if(patientid != "") url.addQueryItem("patientid", patientid);
+ request.setUrl(url);
+
+ manager->post(request, body);
}
void NetCom::initConnection()
{
- send(templ); // Initialise by sending a template-only request.
+ send(course, templ); // Initialise by sending a template-only request.
}
void NetCom::commit()
{
- QDomDocument doc;
- makeTransfer(doc, ::commit);
+ makeTransfer("", ::commit);
}
void NetCom::nocommit()
{
- QDomDocument doc;
- makeTransfer(doc, ::nocommit);
+ makeTransfer("", ::nocommit);
}
void NetCom::discard()
{
- QDomDocument doc;
- makeTransfer(doc, ::discard);
+ makeTransfer("", ::discard);
}
-void NetCom::send(QString templ, QString macro)
+void NetCom::send(QString course, QString templ, QString macro)
{
- QDomDocument doc;
-
+ /*
QDomProcessingInstruction header =
doc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
doc.appendChild(header);
QDomElement pracro_elem = doc.createElement("pracro");
pracro_elem.setAttribute("version", "1.0");
- pracro_elem.setAttribute("cpr", patientid);
+ pracro_elem.setAttribute("patientid", patientid);
pracro_elem.setAttribute("user", user);
doc.appendChild(pracro_elem);
QDomElement request_elem = doc.createElement("request");
- request_elem.setAttribute("template", templ);
+ request_elem.setAttribute("course", course);
+ if(templ != "") request_elem.setAttribute("template", templ);
if(macro != "") request_elem.setAttribute("macro", macro);
pracro_elem.appendChild(request_elem);
+ */
+ QString uri = "/";
+ if(course != "") {
+ uri += course + "/";
+ if(templ != "") {
+ uri += templ + "/";
+ if(macro != "") uri += macro + "/";
+ }
+ }
- makeTransfer(doc);
+ makeTransfer("", ::none, uri);
}
-void NetCom::send(QVector< Widget* > widgets, QString templ,
+void NetCom::send(QVector< Widget* > widgets, QString course, QString templ,
QString macro, QString version)
{
QDomDocument doc;
@@ -176,11 +207,12 @@ void NetCom::send(QVector< Widget* > widgets, QString templ,
QDomElement pracro_elem = doc.createElement("pracro");
pracro_elem.setAttribute("version", "1.0");
- pracro_elem.setAttribute("cpr", patientid);
+ pracro_elem.setAttribute("patientid", patientid);
pracro_elem.setAttribute("user", user);
doc.appendChild(pracro_elem);
QDomElement commit_elem = doc.createElement("commit");
+ commit_elem.setAttribute("course", course);
commit_elem.setAttribute("template", templ);
commit_elem.setAttribute("macro", macro);
commit_elem.setAttribute("version", version);
@@ -204,10 +236,10 @@ void NetCom::send(QVector< Widget* > widgets, QString templ,
}
i++;
}
-
+ /*
QDomElement request_elem = doc.createElement("request");
request_elem.setAttribute("template", templ);
pracro_elem.appendChild(request_elem);
-
- makeTransfer(doc);
+ */
+ makeTransfer(doc.toByteArray(), ::none, "");
}
diff --git a/client/netcom.h b/client/netcom.h
index 46d40d0..332f4bd 100644
--- a/client/netcom.h
+++ b/client/netcom.h
@@ -54,8 +54,8 @@ public:
NetCom(QString host, quint16 port);
~NetCom();
- void send(QString templ, QString macro = "");
- void send(QVector< Widget* > widgets, QString templ,
+ void send(QString course, QString templ = "", QString macro = "");
+ void send(QVector< Widget* > widgets, QString course, QString templ,
QString macro, QString version);
void initConnection();
@@ -66,6 +66,7 @@ public:
QString sessionid;
QString user;
QString patientid;
+ QString course;
QString templ;
signals:
@@ -84,7 +85,7 @@ private:
QMap<QNetworkReply *, bool> finished;
- void makeTransfer(QDomDocument &dom, session_state_t state = none);
+ void makeTransfer(QByteArray body, session_state_t state, QString uri = "");
};
#endif/*__PRACRO_NETCOM_H__*/
diff --git a/client/pracro.cc b/client/pracro.cc
index d281347..57a8da7 100644
--- a/client/pracro.cc
+++ b/client/pracro.cc
@@ -41,19 +41,15 @@
#include "debug.h"
-#define CPR_DEFAULT ""
-#define MACRO_DEFAULT ""
-#define TEMPLATE_DEFAULT ""
#define USER_DEFAULT "testuser"
#define CONFIG_DEFAULT "pracro.ini"
-QString cpr = CPR_DEFAULT;
+QString cpr;
QString user = USER_DEFAULT;
QString config = CONFIG_DEFAULT;
QString host;
quint16 port;
-QWidget *viewer = NULL;
QFont *fixedfont = NULL;
#ifndef TESTING
@@ -65,10 +61,9 @@ static void print_usage()
printf("\n");
printf(" -h, --help Displays this help text.\n");
printf(" -t, --template TEMPLATE Requests template TEMPLATE from the Pracro \n"
- " Server, defaults to \""TEMPLATE_DEFAULT"\".\n");
+ " Server.\n");
printf(" -C --course COURSE Lists templates in COURSE.\n");
- printf(" -P, --patient PATIENTID Defines the patientid for use with the macro,\n"
- " defaults to \""CPR_DEFAULT"\".\n");
+ printf(" -P, --patient PATIENTID Defines the patientid for use with the macro.\n");
printf(" -c, --config FILE The configfile to use. Default is \""CONFIG_DEFAULT"\"\n");
printf(" -u, -U, --user USER Defines the requesting user(not the patient),\n"
" defaults to \""USER_DEFAULT"\"\n");
@@ -96,8 +91,8 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- QString macro = MACRO_DEFAULT;
- QString templ = TEMPLATE_DEFAULT;
+ QString macro;
+ QString templ;
QString course;
QString templs;
@@ -168,7 +163,8 @@ int main(int argc, char *argv[])
QFont f = fontdb.font("Bitstream Vera Sans Mono", "", 8);
fixedfont = &f;
- if(cpr == CPR_DEFAULT || templ == TEMPLATE_DEFAULT) {
+ /*
+ if(cpr == "" || templ == "") {
LauncherWindow lwnd(argv[0], cpr, templ);
if(lwnd.exec() == QDialog::Accepted && lwnd.getCpr() != "") {
cpr = lwnd.getCpr();
@@ -177,13 +173,12 @@ int main(int argc, char *argv[])
return 1;
}
}
-
- MainWindow mainwindow(cpr, templ, host, port, user);
+ */
+
+ MainWindow mainwindow(cpr, course, templ, host, port, user);
mainwindow.show();
return app.exec();
}
-
-
#endif/*TESTING*/
diff --git a/client/template.cc b/client/template.cc
new file mode 100644
index 0000000..4ffd4ac
--- /dev/null
+++ b/client/template.cc
@@ -0,0 +1,103 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * template.cc
+ *
+ * Fri Jul 1 14:43:46 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "template.h"
+
+#include <QPushButton>
+#include <QVBoxLayout>
+#include <QGroupBox>
+
+Template::Template(NetCom &n)
+ : netcom(n)
+{
+ wdg = new QGroupBox();
+
+ QVBoxLayout *l = new QVBoxLayout();
+ wdg->setLayout(l);
+ wdg->setContentsMargins(50, 50, 50, 50);
+
+ l->addStretch();
+
+ templ = new QLabel();
+ templ->setAlignment(Qt::AlignHCenter);
+ QFont font = templ->font();
+ font.setBold(true);
+ font.setPointSize(font.pointSize() * 1.5);
+ templ->setFont(font);
+ l->addWidget(templ);
+
+ l->addStretch();
+
+ QPushButton *btn = new QPushButton("Open");
+ l->addWidget(btn);
+ connect(btn, SIGNAL(clicked()), this, SLOT(open()));
+
+ l->addStretch();
+
+}
+
+const char *Template::type()
+{
+ return "template";
+}
+
+void Template::update(QDomNode &node)
+{
+ QDomElement elem = node.toElement();
+ templ->setText(elem.attribute("title") + " (" + elem.attribute("name") + ")");
+ name = elem.attribute("name");
+}
+
+void Template::open()
+{
+ emit setTemplate(name);
+ netcom.templ = name;
+ netcom.send(netcom.course, name, "");
+}
+
+QWidget *Template::widget()
+{
+ return wdg;
+}
+
+#ifdef TEST_TEMPLATE
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+TEST_TRUE(false, "No tests yet!");
+
+TEST_END;
+
+#endif/*TEST_TEMPLATE*/
diff --git a/client/template.h b/client/template.h
new file mode 100644
index 0000000..31b635b
--- /dev/null
+++ b/client/template.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * template.h
+ *
+ * Fri Jul 1 14:43:46 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __PRACRO_TEMPLATE_H__
+#define __PRACRO_TEMPLATE_H__
+
+#include <QLabel>
+
+#include "entity.h"
+#include "netcom.h"
+
+class Template : public QObject, public Entity {
+Q_OBJECT
+public:
+ Template(NetCom &netcom);
+ const char *type();
+ void update(QDomNode &node);
+ QWidget *widget();
+
+public slots:
+ void open();
+
+signals:
+ void setTemplate(QString name);
+
+private:
+ QString name;
+ QLabel *templ;
+ QWidget *wdg;
+ NetCom &netcom;
+};
+
+#endif/*__PRACRO_TEMPLATE_H__*/