From 73934812611cc7120175e26761d71fae9233c1e8 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 27 May 2010 09:41:29 +0000 Subject: Use new commit/discard methods in netcom. --- client/mainwindow.cc | 64 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) (limited to 'client/mainwindow.cc') diff --git a/client/mainwindow.cc b/client/mainwindow.cc index aa2337e..46662fa 100644 --- a/client/mainwindow.cc +++ b/client/mainwindow.cc @@ -38,20 +38,36 @@ #include #include #include +#include +#include #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) { 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"); + QAction *close_commit = toolbar->addAction("Close and commit"); + QAction *close_no_commit = toolbar->addAction("Close no commit"); + QAction *close_discard = toolbar->addAction("Close discard"); + QAction *show_sessions = toolbar->addAction("Show sessions"); + connect(close_commit, SIGNAL(triggered()), this, SLOT(closeCommit())); + connect(close_no_commit, SIGNAL(triggered()), this, SLOT(closeNoCommit())); + connect(close_discard, SIGNAL(triggered()), this, SLOT(closeDiscard())); + connect(show_sessions, SIGNAL(triggered()), this, SLOT(showSessions())); + QScrollArea *s = new QScrollArea(); setCentralWidget(s); w = new QWidget(); @@ -70,6 +86,31 @@ MainWindow::~MainWindow() { } +void MainWindow::closeCommit() +{ + netcom.commit(); + sessions.remove(cpr); + close(); +} + +void MainWindow::closeNoCommit() +{ + sessions.add(cpr, user, netcom.sessionid); + close(); +} + +void MainWindow::closeDiscard() +{ + netcom.discard(); + sessions.remove(cpr); + close(); +} + +void MainWindow::showSessions() +{ + sessions.show(); +} + void MainWindow::closeEvent(QCloseEvent *) { QSettings settings("Aasimon.org", "Pracro"); @@ -77,6 +118,7 @@ void MainWindow::closeEvent(QCloseEvent *) settings.beginGroup("MainWindow"); settings.setValue("size", size()); settings.setValue("pos", pos()); + settings.setValue(QString("sessions"), sessions.toVariant()); settings.endGroup(); QApplication::quit(); @@ -89,8 +131,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; @@ -113,7 +168,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); } @@ -150,7 +206,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); -- cgit v1.2.3