summaryrefslogtreecommitdiff
path: root/client/mainwindow.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/mainwindow.cc')
-rw-r--r--client/mainwindow.cc307
1 files changed, 153 insertions, 154 deletions
diff --git a/client/mainwindow.cc b/client/mainwindow.cc
index 6ee17c8..30be707 100644
--- a/client/mainwindow.cc
+++ b/client/mainwindow.cc
@@ -36,18 +36,23 @@
#include <QScrollArea>
#include <QSettings>
#include <QStatusBar>
-#include <QMessageBox>
#include <QToolBar>
#include <QAction>
#include <QEvent>
#include <QCloseEvent>
-#include <QLabel>
+
+#include "messagebox.h"
#include "macrodrawer.h"
#include "macrowindow.h"
+#include "macro.h"
+#include "header.h"
+
#include "debug.h"
+extern QWidget *viewer;
+
class Dbg : public QLabel {
public:
Dbg() {
@@ -60,20 +65,40 @@ public:
}
};
-MainWindow::MainWindow(QString cpr, QString templ, QString host,
+MainWindow *gmainwindow = NULL;
+
+MainWindow::MainWindow(QString patientid, QString templ, QString host,
quint16 port, QString user)
: QMainWindow(0, Qt::WindowContextHelpButtonHint),
netcom(this, host, port)
{
+ gmainwindow = this;
+
+ closing = false;
+
+ scrollarea = new QScrollArea();
+ setCentralWidget(scrollarea);
+ w = new QWidget();
+ scrollarea->setWidget(w);
+ scrollarea->setWidgetResizable(true);
+
+ w->setLayout(new QVBoxLayout());
+
+ connect(&netcom, SIGNAL(gotReply(QDomDocument&)),
+ this, SLOT(handle(QDomDocument&)));
+
+ connect(&netcom, SIGNAL(networkError(QString, QString)),
+ this, SLOT(showError(QString, QString)));
+
isStored = false;
header = NULL;
- this->cpr = cpr;
+ this->patientid = patientid;
this->user = user;
this->templ = templ;
- setWindowTitle("Pracro - " + cpr);
+ setWindowTitle("Pracro - " + patientid);
setWindowIcon(QIcon(":/icons/icon.png"));
QStatusBar *status = statusBar();
@@ -95,95 +120,99 @@ MainWindow::MainWindow(QString cpr, QString templ, QString host,
connect(close_discard, SIGNAL(triggered()), this, SLOT(closeDiscard()));
*/
toolbar->addSeparator();
- /*
- QAction *show_sessions = toolbar->addAction(tr("Show sessions"));
- show_sessions->setIcon(QPixmap(":icons/icon_current_sessions.png"));
- */
+
connect(close_commit, SIGNAL(triggered()), this, SLOT(closeCommit()));
connect(close_no_commit, SIGNAL(triggered()), this, SLOT(closeNoCommit()));
- // connect(show_sessions, SIGNAL(triggered()), this, SLOT(showSessions()));
-
- scrollarea = new QScrollArea();
- setCentralWidget(scrollarea);
- w = new QWidget();
- scrollarea->setWidget(w);
- scrollarea->setWidgetResizable(true);
-
- w->setLayout(new QVBoxLayout());
setStatusBar(status);
init();
- /*
- if(sessions.isEmpty()) {
- show_sessions->setEnabled(false);
- }
- */
}
MainWindow::~MainWindow()
{
}
+bool MainWindow::hasOpen(void *me)
+{
+ Entities::iterator i = entities.begin();
+ while(i != entities.end()) {
+ if(me != i.value() && i.value()->isOpen()) return true;
+ i++;
+ }
+ return false;
+}
+
+
void MainWindow::closeCommit()
{
+ if(hasOpen(NULL)) {
+ MessageBox::warning(this, tr("Close first."),
+ tr("Close open macros first."));
+ return;
+ }
netcom.commit();
- // sessions.remove(cpr);
isStored = true;
- close();
+ closing = true;
}
void MainWindow::closeNoCommit()
{
-/*
- QMessageBox::information(this,
- tr("Closing without commit"),
- tr("This session will be stored on this computer "
- "only. To reopen it at a later time, simply "
- "open the same patient again."));
-*/
- // sessions.add(cpr, user, netcom.sessionid);
- isStored = true;
+ if(hasOpen(NULL)) {
+ MessageBox::warning(this, tr("Close first."),
+ tr("Close open macros first."));
+ return;
+ }
netcom.nocommit();
- close();
+ isStored = true;
+ closing = true;
}
void MainWindow::closeDiscard()
{
- if(QMessageBox::question(this,
- tr("Discard"),
- tr("This session will <strong>NOT</strong> be "
- "stored in the journal.<br/>"
- "Are you sure you want to continue?"),
- QMessageBox::Yes | QMessageBox::No)
- == QMessageBox::Yes) {
+ if(hasOpen(NULL)) {
+ MessageBox::warning(this, tr("Close first."),
+ tr("Close open macros first."));
+ return;
+ }
+
+ MessageBox::StandardButton res =
+ MessageBox::question(this,
+ tr("Discard"),
+ tr("This session will <strong>NOT</strong> be "
+ "stored in the journal.<br/>"
+ "Are you sure you want to continue?"),
+ MessageBox::Yes | MessageBox::No);
+
+ if(res == MessageBox::Yes) {
netcom.discard();
- // sessions.remove(cpr);
isStored = true;
- close();
+ closing = true;
}
}
-/*
-void MainWindow::showSessions()
-{
- sessions.show();
-}
-*/
-extern QWidget *viewer;
-//#include <QApplication>
+
void MainWindow::closeEvent(QCloseEvent *event)
{
- if(isStored || QMessageBox::question(this,
+ if(hasOpen(NULL)) {
+ MessageBox::warning(this, "Close first.", "Close open macros first.");
+ event->ignore();
+ return;
+ }
+
+ if(isStored || MessageBox::question(this,
tr("Discard"),
tr("This session will "
"<strong>NOT</strong> be stored in "
"the journal.<br/>"
"Are you sure you want to continue?"),
- QMessageBox::Yes | QMessageBox::No)
- == QMessageBox::Yes) {
+ MessageBox::Yes | MessageBox::No)
+ == MessageBox::Yes) {
if(!isStored) {
netcom.discard();
- // sessions.remove(cpr);
+ isStored = true;
+ closing = true;
+ event->ignore();
+ return;
}
QSettings settings("Aasimon.org", "Pracro");
@@ -191,7 +220,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
settings.beginGroup("MainWindow");
settings.setValue("size", size());
settings.setValue("pos", pos());
- // settings.setValue(QString("sessions"), sessions.toVariant());
settings.endGroup();
event->accept();
@@ -209,36 +237,26 @@ void MainWindow::init()
settings.beginGroup("MainWindow");
resize(settings.value("size", QSize(700, 800)).toSize());
move(settings.value("pos", QPoint(0, 0)).toPoint());
- // sessions.fromVariant(settings.value("sessions"));
settings.endGroup();
- netcom.patientid = cpr;
+ netcom.patientid = patientid;
netcom.templ = templ;
netcom.user = user;
- /*
- if(sessions.contains(cpr)) {
- netcom.sessionid = sessions.getSessionID(cpr);
- if(sessions.getUser(cpr) != user) {
- // What to do? We are running an old session with a new user!
- }
- }
- */
- netcom.initConnection();
- initialising = true;
- update();
- initialising = false;
+ netcom.initConnection();
}
-void MainWindow::updateTemplateHeaders(QDomNode templatenode)
+void MainWindow::updateTemplateHeaders(QDomNode &node)
{
- QDomElement template_elem = templatenode.toElement();
- QString template_title = template_elem.attribute("title");
- QString template_name = template_elem.attribute("name");
+ QDomElement elem = node.toElement();
+
+ if(elem.tagName() != "template") return;
+
+ QString title = elem.attribute("title");
+ QString name = elem.attribute("name");
if(!header) {
header = new QLabel();
- header->setText(template_title);
QFont headerfont = header->font();
headerfont.setBold(true);
headerfont.setPointSize(headerfont.pointSize() + 4);
@@ -247,103 +265,84 @@ void MainWindow::updateTemplateHeaders(QDomNode templatenode)
w->layout()->addWidget(header);
}
- statusBar()->showMessage(template_title + " (" + template_name +
+ header->setText(title);
+
+ statusBar()->showMessage(title + " (" + name +
") - SessionID: " + netcom.sessionid);
}
-void MainWindow::update()
+void MainWindow::showError(QString title, QString text)
{
- QDomDocument xml_doc = netcom.send(templ);
-
- QDomNodeList templates = xml_doc.documentElement().childNodes();
- // There can be only one! (Swush, flomp)
- QDomNode templatenode = templates.at(0);
-
- if(templatenode.toElement().tagName() == "error") {
- QMessageBox::critical(this, "Error",
- templatenode.toElement().text());
- return;
- }
+ MessageBox::critical(this, title, text);
+}
+void MainWindow::updateMacros(QDomNodeList &nodes)
+{
+ for(int j = 0; j < nodes.count(); j++) {
+ QDomNode node = nodes.at(j);
+ QDomElement elem = node.toElement();
- updateTemplateHeaders(templatenode);
+ if(elem.tagName() == "macro" || elem.tagName() == "header") {
+ QString name = elem.attribute("name");
+
+ if(entities.find(j) == entities.end()) {
+ Entity *e = NULL;
+ if(elem.tagName() == "macro") {
+ e = new Macro(entities, netcom, templ, scrollarea);
+ }
+ if(elem.tagName() == "header") {
+ e = new Header();
+ }
+ entities[j] = e;
+ entities[j]->update(node);
+ w->layout()->addWidget(e->widget());
+ } else {
+ entities[j]->update(node);
+ }
+ continue;
+ }
- QDomNodeList macronodes = templatenode.childNodes();
- for(int j = 0; j < macronodes.count(); j++) {
+ showError("XML Error", "Expected macro/header tag. Got '" +
+ elem.tagName() + "' tag.");
+ continue;
- QDomNode macronode = macronodes.at(j);
- QDomElement macroelement = macronode.toElement();
+ }
+}
- // printf("%s\n", macroelement.tagName().toStdString().c_str());
+void MainWindow::handle(QDomDocument &doc)
+{
+ if(closing) close();
- QString macroname = macroelement.attribute("name");
+ DEBUG(mainwindow, "Handle %s\n",
+ doc.toString().toStdString().c_str());
- bool found = false;
- Macros::iterator i = macros.begin();
- while(i != macros.end()) {
- if(i->name == macroname) found |= true;
- i++;
- }
+ QDomNodeList nodes = doc.documentElement().childNodes();
+ for(int j = 0; j < nodes.count(); j++) {
+ QDomNode node = nodes.at(j);
+ QDomElement element = node.toElement();
- // if(found == false || macroelement.hasAttribute("header")) {
- if(found == false || macroelement.tagName() == "header") {
- QString num;
- num.sprintf("%04d", j);
- Macro macro(macronode, scrollarea);
- macros[num + macro.name] = macro;
+ if(element.tagName() == "error") {
+ showError("Pracro Server Error", element.text());
+ continue;
}
- if(found) {
-
- Macros::iterator i = macros.begin();
- while(i != macros.end()) {
- if(i->name == macroname && macroname != "") {
- i->update(macronode);
- }
- i++;
- }
-
+ if(element.tagName() != "template") {
+ showError("XML error", "Outer tag not a template.");
+ continue;
}
- }
- {
- Macros::iterator i = macros.begin();
- while(i != macros.end()) {
- Macro &macro = i.value();
- macro.init((QBoxLayout*)w->layout(), macros, initialising, netcom, templ);
- if(macro.window != NULL) {
- // Remove old connection (if any), to avoid multiple connections.
- disconnect(macro.window, SIGNAL(updateOnCommit()),
- this, SLOT(update()));
-
- connect(macro.window, SIGNAL(updateOnCommit()), this, SLOT(update()));
- }
- i++;
+ if(element.attribute("name") != templ) {
+ showError("XML error",
+ "Got template name that didn't match current session.");
+ continue;
}
- }
- // Make sure that all macros will collapse when a new one is expanded.
- Macros::iterator i = macros.begin();
- while(i != macros.end()) {
- Macro &_m1 = i.value();
- MacroWindow *m1 = _m1.window;
-
- Macros::iterator j = macros.begin();
- while(j != macros.end()) {
- Macro &_m2 = j.value();
- MacroWindow *m2 = _m2.window;
-
- if(m1 && m2 && m1 != m2 && _m2.isstatic == false) {
- // Remove old connection (if any), to avoid multiple connections.
- disconnect(m1, SIGNAL(animating(QWidget*)),
- m2, SLOT(collapseWrapper()));
-
- connect(m1, SIGNAL(animating(QWidget*)), m2, SLOT(collapseWrapper()));
- }
+ // Set headers. titles, etc...
+ updateTemplateHeaders(node);
- j++;
- }
+ // Update macros, header and resumes.
+ QDomNodeList macronodes = node.childNodes();
+ updateMacros(macronodes);
- i++;
}
}