summaryrefslogtreecommitdiff
path: root/client/mainwindow.cc
diff options
context:
space:
mode:
authordeva <deva>2010-06-01 12:58:32 +0000
committerdeva <deva>2010-06-01 12:58:32 +0000
commit74a28aa7125be6a603128ad600c98c4882f3b5c2 (patch)
tree1a9e4ab74f29d5ff10f2701e4e112f4525c0dcec /client/mainwindow.cc
parent9b9c1e2dd3e5807ff7714b378b03b9ba31f42df7 (diff)
From new_protocol branch.
Diffstat (limited to 'client/mainwindow.cc')
-rw-r--r--client/mainwindow.cc128
1 files changed, 116 insertions, 12 deletions
diff --git a/client/mainwindow.cc b/client/mainwindow.cc
index 51bb772..3d49752 100644
--- a/client/mainwindow.cc
+++ b/client/mainwindow.cc
@@ -37,20 +37,50 @@
#include <QScrollArea>
#include <QSettings>
#include <QStatusBar>
+#include <QMessageBox>
+#include <QToolBar>
+#include <QAction>
#include "macrodrawer.h"
-MainWindow::MainWindow(QString cpr, QString templ, QString host, quint16 port, QString user)
+MainWindow::MainWindow(QString cpr, QString templ, QString host,
+ quint16 port, QString user)
: QMainWindow(0, Qt::WindowContextHelpButtonHint),
- netcom(host, port, user, cpr)
+ netcom(host, port)
{
+ isStored = false;
+
header = NULL;
+ this->cpr = cpr;
+ this->user = user;
+
setWindowTitle("Pracro - " + cpr);
QStatusBar *status = statusBar();
status->addPermanentWidget(new QLabel("Pracro v."VERSION));
+ QToolBar *toolbar = addToolBar("controls");
+ toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
+ QAction *close_commit = toolbar->addAction("Close and commit");
+ close_commit->setIcon(QPixmap(":icons/icon_close_commit.png"));
+
+ QAction *close_no_commit = toolbar->addAction("Close no commit");
+ close_no_commit->setIcon(QPixmap(":icons/icon_close_no_commit.png"));
+ /*
+ QAction *close_discard = toolbar->addAction("Close discard");
+ close_discard->setIcon(QPixmap(":icons/icon_discard.png"));
+ connect(close_discard, SIGNAL(triggered()), this, SLOT(closeDiscard()));
+ */
+ toolbar->addSeparator();
+
+ QAction *show_sessions = toolbar->addAction("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()));
+
QScrollArea *s = new QScrollArea();
setCentralWidget(s);
w = new QWidget();
@@ -61,24 +91,77 @@ MainWindow::MainWindow(QString cpr, QString templ, QString host, quint16 port, Q
this->templ = templ;
setStatusBar(status);
-
+
init();
+
+ if(sessions.isEmpty()) {
+ show_sessions->setEnabled(false);
+ }
}
MainWindow::~MainWindow()
{
}
-void MainWindow::closeEvent(QCloseEvent *)
+void MainWindow::closeCommit()
{
- QSettings settings("Aasimon.org", "Pracro");
+ netcom.commit();
+ sessions.remove(cpr);
+ isStored = true;
+ close();
+}
- settings.beginGroup("MainWindow");
- settings.setValue("size", size());
- settings.setValue("pos", pos());
- settings.endGroup();
+void MainWindow::closeNoCommit()
+{
+ QMessageBox::information(this,
+ "Closing without commit",
+ "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;
+ close();
+}
- QApplication::quit();
+void MainWindow::closeDiscard()
+{
+ if(QMessageBox::question(this,
+ "Discard",
+ "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) {
+ netcom.discard();
+ sessions.remove(cpr);
+ isStored = true;
+ close();
+ }
+}
+
+void MainWindow::showSessions()
+{
+ sessions.show();
+}
+
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+ if(isStored || QMessageBox::question(this,
+ "Discard",
+ "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) {
+ QSettings settings("Aasimon.org", "Pracro");
+
+ settings.beginGroup("MainWindow");
+ settings.setValue("size", size());
+ settings.setValue("pos", pos());
+ settings.setValue(QString("sessions"), sessions.toVariant());
+ settings.endGroup();
+
+ event->accept();
+ } else {
+ event->ignore();
+ }
}
void MainWindow::init()
@@ -88,8 +171,21 @@ 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.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;
@@ -112,7 +208,8 @@ void MainWindow::updateTemplateHeaders(QDomNode templatenode)
w->layout()->addWidget(header);
}
- statusBar()->showMessage(template_title + " (" + template_name + ")");
+ statusBar()->showMessage(template_title + " (" + template_name +
+ ") - SessionID: " + netcom.sessionid);
}
@@ -122,6 +219,13 @@ void MainWindow::update()
QDomNodeList templates = xml_doc.documentElement().childNodes();
QDomNode templatenode = templates.at(0); // There can be only one! (Swush, flomp)
+
+ if(templatenode.toElement().tagName() == "error") {
+ QMessageBox::critical(this, "Error",
+ templatenode.toElement().text());
+ return;
+ }
+
updateTemplateHeaders(templatenode);
@@ -142,7 +246,7 @@ void MainWindow::update()
i++;
}
- // if(found == false || macroelement.hasAttribute("header")) {
+ // if(found == false || macroelement.hasAttribute("header")) {
if(found == false || macroelement.tagName() == "header") {
QString num;
num.sprintf("%04d", j);