diff options
author | deva <deva> | 2011-03-10 08:45:16 +0000 |
---|---|---|
committer | deva <deva> | 2011-03-10 08:45:16 +0000 |
commit | ded5e8cd771c9affef086b77e25c93b4868f3f29 (patch) | |
tree | 537bec9b557ca9bd2ba6e5429434fdc0250f1e8d | |
parent | d8a34adcc1a69a2b77881a6e504d0f0ad896eb3a (diff) |
Callback based client implementation is now finished. Testing is up.
-rw-r--r-- | client/client.pro | 3 | ||||
-rw-r--r-- | client/entity.h (renamed from client/sessions.h) | 43 | ||||
-rw-r--r-- | client/header.cc | 59 | ||||
-rw-r--r-- | client/header.h | 47 | ||||
-rw-r--r-- | client/macro.cc | 166 | ||||
-rw-r--r-- | client/macro.h | 21 | ||||
-rw-r--r-- | client/macrodrawer.cc | 13 | ||||
-rw-r--r-- | client/macrodrawer.h | 2 | ||||
-rw-r--r-- | client/macrowindow.cc | 276 | ||||
-rw-r--r-- | client/macrowindow.h | 7 | ||||
-rw-r--r-- | client/mainwindow.cc | 307 | ||||
-rw-r--r-- | client/mainwindow.h | 28 | ||||
-rw-r--r-- | client/netcom.cc | 83 | ||||
-rw-r--r-- | client/netcom.h | 22 | ||||
-rw-r--r-- | client/pracro_dk.ts | 81 | ||||
-rw-r--r-- | client/sessions.cc | 119 |
16 files changed, 592 insertions, 685 deletions
diff --git a/client/client.pro b/client/client.pro index d43e28d..d53c69a 100644 --- a/client/client.pro +++ b/client/client.pro @@ -36,6 +36,8 @@ unix { HEADERS += \ collapser.h \ debug.h \ + entity.h \ + header.h \ launcherwindow.h \ lua.h \ luadb.h \ @@ -72,6 +74,7 @@ SOURCES += \ pracro.cc \ collapser.cc \ debug.cc \ + header.cc \ launcherwindow.cc \ lua.cc \ luadb.cc \ diff --git a/client/sessions.h b/client/entity.h index b42d27b..f7cb600 100644 --- a/client/sessions.h +++ b/client/entity.h @@ -1,10 +1,10 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set et sw=2 ts=2: */ /*************************************************************************** - * sessions.h + * entity.h * - * Wed May 26 14:31:51 CEST 2010 - * Copyright 2010 Bent Bisballe Nyeng + * Fri Mar 4 14:59:47 CET 2011 + * Copyright 2011 Bent Bisballe Nyeng * deva@aasimon.org ****************************************************************************/ @@ -25,34 +25,21 @@ * along with Pracro; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef __PRACRO_SESSIONS_H__ -#define __PRACRO_SESSIONS_H__ +#ifndef __PRACRO_ENTITY_H__ +#define __PRACRO_ENTITY_H__ +#include <QDomNode> #include <QMap> -#include <QString> -#include <QVariant> +#include <QWidget> -//typedef QMap<QString, QList<QString> > Sessions; - -class Sessions { +class Entity { public: - void add(QString cpr, QString user, QString sessionid); - void remove(QString cpr); - void show(); - - QVariant toVariant(); - void fromVariant(const QVariant &v); - - bool contains(QString cpr); - QString getUser(QString cpr); - QString getSessionID(QString cpr); - - bool isEmpty(); - -private: - QMap<QString, QVariant > s; - // QMap<QString, QList<QString> > sessions; - //Sessions sessions; + virtual const char *type() = 0; + virtual void update(QDomNode &node) = 0; + virtual QWidget *widget() = 0; + virtual bool isOpen() { return false; } }; -#endif/*__PRACRO_SESSIONS_H__*/ +typedef QMap<int, Entity*> Entities; + +#endif/*__PRACRO_ENTITY_H__*/ diff --git a/client/header.cc b/client/header.cc new file mode 100644 index 0000000..7a98a77 --- /dev/null +++ b/client/header.cc @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * header.cc + * + * Fri Mar 4 15:02:40 CET 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 "header.h" + +#include <QFont> + +Header::Header() +{ + header = new QLabel(); + QFont headerfont = header->font(); + headerfont.setBold(true); + headerfont.setPointSize(headerfont.pointSize() + 2); + header->setFont(headerfont); +} + +const char *Header::type() +{ + return "header"; +} + +void Header::update(QDomNode &node) +{ + QDomElement elem = node.toElement(); + + if(elem.tagName() != "header") return; + + header->setText(elem.attribute("caption")); +} + + +QWidget *Header::widget() +{ + return header; +} diff --git a/client/header.h b/client/header.h new file mode 100644 index 0000000..9bf1124 --- /dev/null +++ b/client/header.h @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * header.h + * + * Fri Mar 4 15:02:40 CET 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_HEADER_H__ +#define __PRACRO_HEADER_H__ + +#include <QLabel> + +#include "entity.h" + +class Header : public Entity { +public: + Header(); + + const char *type(); + void update(QDomNode &node); + QWidget *widget(); + +private: + QLabel *header; +}; + +#endif/*__PRACRO_HEADER_H__*/ diff --git a/client/macro.cc b/client/macro.cc index 5d88015..ad21cc4 100644 --- a/client/macro.cc +++ b/client/macro.cc @@ -35,140 +35,100 @@ #include "macrodrawer.h" #include "macrowindow.h" -Macro::Macro(QDomNode &n, QScrollArea *scrollarea) +Macro::Macro(Entities &e, NetCom &n, QString t, QScrollArea *s) + : entities(e), netcom(n), templ(t) { window = NULL; drawer = NULL; - this->scrollarea = scrollarea; + scrollarea = s; - update(n); + isstatic = false; + iscompact = false; } -void Macro::update(QDomNode &n) +const char *Macro::type() { - node = n.cloneNode(true); - - QDomElement xml_elem = node.toElement(); - - if(xml_elem.tagName() != "macro" && xml_elem.tagName() != "header") return; - // if(xml_elem.hasAttribute("header")) return; - - name = xml_elem.attribute("name"); - - iscompleted = xml_elem.attribute("completed", "false") == "true"; + return "macro"; } -void Macro::init(QBoxLayout *layout, Macros ¯os, - bool initialising, NetCom &netcom, QString templ) +void Macro::update(QDomNode &node) { - QDomElement xml_elem = node.toElement(); + QDomElement elem = node.toElement(); - if(xml_elem.tagName() != "macro" && xml_elem.tagName() != "header") return; + if(elem.tagName() != "macro") return; - isstatic = xml_elem.attribute("static", "false") == "true"; - iscompact = xml_elem.attribute("compact", "false") == "true"; + name = elem.attribute("name"); + iscompleted = elem.attribute("completed", "false") == "true"; - if(xml_elem.hasAttribute("requires")) { - // Read and parse requirement list. - requires = xml_elem.attribute("requires").split(QRegExp("\\W+"), - QString::SkipEmptyParts); - } + if(window == NULL) { + isstatic = elem.attribute("static", "false") == "true"; + iscompact = elem.attribute("compact", "false") == "true"; - // if(xml_elem.hasAttribute("header")) { - if(xml_elem.tagName() == "header") { - // Macro is a special headline macro. - // Simply create a headline, and ignore the rest. - - // Only add header on initial contruction. - if(initialising == true) { - QLabel *header = new QLabel(); - // header->setText(xml_elem.attribute("header")); - header->setText(xml_elem.attribute("caption")); - QFont headerfont = header->font(); - headerfont.setBold(true); - headerfont.setPointSize(headerfont.pointSize() + 2); - header->setFont(headerfont); - layout->addWidget(header); - } + window = new MacroWindow(netcom, templ, isstatic, iscompact, scrollarea); - return; + QFont f = window->font(); + f.setBold(false); + f.setItalic(false); + window->setFont(f); } - - // if(macros.find(name) == macros.end()) { - if(window == NULL && drawer == NULL) { - window = new MacroWindow(netcom, node, templ, isstatic, iscompact, - scrollarea); - - /* - QWidget *edge = new QWidget(); - edge->setContentsMargins(1,1,1,1); - edge->setAutoFillBackground(true); - edge->setAttribute(Qt::WA_WindowPropagation, true); - QHBoxLayout *edgelayout = new QHBoxLayout(); - edgelayout->setContentsMargins(0,0,0,0); - edge->setLayout(edgelayout); - layout->addWidget(edge); - */ - - drawer = new MacroDrawer(this, xml_elem.attribute("caption", name), - NULL/*edge*/); - drawer->connect(drawer, SIGNAL(toggle()), window, SLOT(toggleMacro())); - drawer->connect(window, SIGNAL(activationChanged(bool)), - drawer, SLOT(activationChange(bool))); - - /* - QObject::connect(drawer, SIGNAL(toggle()), window, SLOT(toggleMacro())); - QObject::connect(window, SIGNAL(activationChanged(bool)), - drawer, SLOT(activationChange(bool))); - */ - - //drawer->setAutoFillBackground(true); - //drawer->setContentsMargins(1,1,1,1); - window->setActive(false); - //drawer->setPalette(QApplication::palette()); - //edge->layout()->addWidget(g); - layout->addWidget(drawer); - + + if(drawer == NULL) { + drawer = new MacroDrawer(this, elem.attribute("caption", name)); QHBoxLayout *l = new QHBoxLayout(); l->setContentsMargins(10,0,10,0); drawer->setLayout(l); l->addWidget(window); - { - QFont f = window->font(); - f.setBold(false); - f.setItalic(false); - window->setFont(f); - } - - } else { - - window->update(node); - if(xml_elem.attribute("static", "false") == "false") { - window->animateToWidget(window->resumewidget); - } + + QObject::connect(drawer, SIGNAL(toggle()), window, SLOT(toggleMacro())); + QObject::connect(window, SIGNAL(activationChanged(bool)), + drawer, SLOT(activationChange(bool))); + } + + window->update(node); + + window->setActive(false); + + // Read and parse requirement list. + if(elem.hasAttribute("requires")) { + QString req = elem.attribute("requires"); + requires = req.split(QRegExp("\\W+"), QString::SkipEmptyParts); } + // Test if requirements are fulfilled QStringList::iterator rs = requires.begin(); QStringList blocking; bool active = true; while(rs != requires.end()) { - // printf("Testing if %s is completed...", rs->toStdString().c_str()); - - Macros::iterator ms = macros.begin(); - while(ms != macros.end()) { - if(ms->name == *rs) { - // printf("Found it %d", ms->iscompleted); - if(ms->iscompleted == false) blocking.append(ms->name); - active = active && ms->iscompleted; + Entities::iterator es = entities.begin(); + while(es != entities.end()) { + Entity *e = *es; + QString type = e->type(); + if(type == "macro") { + Macro *m = (Macro*)e; + if(m->name == *rs) { + if(m->iscompleted == false) blocking.append(m->name); + active = active && m->iscompleted; + } } - ms++; + es++; } - - // printf("\n"); rs++; } window->setActive(active); - if(!active) drawer->setToolTip(QObject::tr("Depends on: ") + blocking.join(", ")); + if(!active) drawer->setToolTip(QObject::tr("Depends on: ") + + blocking.join(", ")); else drawer->setToolTip(""); } + +QWidget *Macro::widget() +{ + return drawer; +} + +bool Macro::isOpen() +{ + return window && isstatic == false && + window->currentWidget() != window->resumewidget; + +} diff --git a/client/macro.h b/client/macro.h index 37f706e..e5b116c 100644 --- a/client/macro.h +++ b/client/macro.h @@ -37,23 +37,24 @@ #include <QScrollArea> #include "netcom.h" +#include "entity.h" -class Macro; class MacroWindow; -typedef QMap<QString, Macro> Macros; - class MacroDrawer; -class Macro { +class Macro : public Entity { public: - Macro() {} - Macro(QDomNode &node, QScrollArea *scrollarea); + Macro(Entities &entities, NetCom &netcom, QString templ, + QScrollArea *scrollarea); - void init(QBoxLayout *layout, Macros ¯os, bool initialising, - NetCom &netcom, QString templ); + const char *type(); void update(QDomNode &node); + QWidget *widget(); + + bool isOpen(); + QString name; QString caption; @@ -71,8 +72,10 @@ public: MacroDrawer *drawer; private: - QDomNode node; QScrollArea *scrollarea; + Entities &entities; + NetCom &netcom; + QString templ; }; #endif/*__PRACRO_MACRO_H__*/ diff --git a/client/macrodrawer.cc b/client/macrodrawer.cc index f42a3b7..8c713b0 100644 --- a/client/macrodrawer.cc +++ b/client/macrodrawer.cc @@ -37,10 +37,9 @@ #include "macro.h" -MacroDrawer::MacroDrawer(Macro *macro, QString title, QWidget *edge) +MacroDrawer::MacroDrawer(Macro *macro, QString title) { button = NULL; - this->edge = edge; if(!macro->isstatic) setTitle(" " + title); setFlat(true); @@ -89,17 +88,7 @@ void MacroDrawer::toggleMe() void MacroDrawer::activationChange(bool active) { - //printf("Active %d\n", (int)active); setEnabled(active); - /* - if(active) { - QPalette palette = edge->palette(); - palette.setBrush(QPalette::Window, QBrush(QColor(150, 150, 255))); - edge->setPalette(palette); - } else { - edge->setPalette(QApplication::palette()); - } - */ if(!active) { // Set padlock icon on button. diff --git a/client/macrodrawer.h b/client/macrodrawer.h index 18d16d7..9cebebc 100644 --- a/client/macrodrawer.h +++ b/client/macrodrawer.h @@ -35,7 +35,7 @@ class Macro; class MacroDrawer : public QGroupBox { Q_OBJECT public: - MacroDrawer(Macro *macro, QString title, QWidget *edge); + MacroDrawer(Macro *macro, QString title); protected: bool eventFilter(QObject *obj, QEvent *event); diff --git a/client/macrowindow.cc b/client/macrowindow.cc index 0770021..7641fdc 100644 --- a/client/macrowindow.cc +++ b/client/macrowindow.cc @@ -36,15 +36,13 @@ #include "widgets/widget.h" #include "widgets/window.h" #include "lua.h" +#include "mainwindow.h" #include "debug.h" -extern QString cpr; -extern QString user; -extern QString host; -extern quint16 port; +extern MainWindow *gmainwindow; -MacroWindow::MacroWindow(NetCom &n, QDomNode &xml_doc, QString templ, +MacroWindow::MacroWindow(NetCom &n, QString templ, bool is_static, bool compact, QScrollArea *scrollarea) : Collapser(NULL, compact?NULL:scrollarea), netcom(n) @@ -62,13 +60,6 @@ MacroWindow::MacroWindow(NetCom &n, QDomNode &xml_doc, QString templ, resumewidget = new ResumeWidget(compact); - // update(xml_doc); - updateResume(xml_doc); - initMacro(xml_doc); - - if(mainwidget) animateToWidget(mainwidget->qwidget(), true); - else animateToWidget(resumewidget); - active = true; connect(this, SIGNAL(doneAnimating(QWidget*)), @@ -83,95 +74,75 @@ MacroWindow::~MacroWindow() void MacroWindow::update(QDomNode &node) { - /* - if(is_static || mainwidget == NULL) { - clear(); - lua->clear(); + QDomElement elem = node.toElement(); + if(elem.tagName() != "macro") return; + + if(macro == "") macro = elem.attribute("name", ""); + if(version == "") version = elem.attribute("version", ""); - initMacro(node); + if(macro != elem.attribute("name", "")) return; + if(version != elem.attribute("version", "")) return; - if(mainwidget) setExpandedWidget(mainwidget->qwidget()); - else setExpandedWidget(NULL); + QDomNodeList children = node.childNodes(); + + // No content reveals resumewidget with 'dummy' text. + if(children.count() == 0) { + animateToWidget(resumewidget); + return; } - */ - updateResume(node); + + QDomNode childnode = children.at(0); + QDomElement childelem = childnode.toElement(); + if(childelem.tagName() == "resume") { + updateResume(childnode); + return; + } + + initMacro(node); } void MacroWindow::updateResume(QDomNode &node) { QDomElement elem = node.toElement(); - if(elem.tagName() == "resume") { - QString resume = elem.text(); - ResumeWidget::state_t state = ResumeWidget::OLD; - if(elem.hasAttribute("state")) { - if(elem.attribute("state") == "old") state = ResumeWidget::OLD; - if(elem.attribute("state") == "new") state = ResumeWidget::NEW; - if(elem.attribute("state") == "dirty") state = ResumeWidget::DIRTY; - } - /* - if(!mainwidget) { // Only call collapse if the macro is in resume state. - collapse(); - } - */ - resumewidget->setText(resume, state); - updateHeight(); - - return; - } - - QDomNodeList children = node.childNodes(); + if(elem.tagName() != "resume") return; - for (int i=0; i<children.count();i++) { - QDomNode child = children.at(i); - updateResume(child); + QString resume = elem.text(); + ResumeWidget::state_t state = ResumeWidget::OLD; + if(elem.hasAttribute("state")) { + if(elem.attribute("state") == "old") state = ResumeWidget::OLD; + if(elem.attribute("state") == "new") state = ResumeWidget::NEW; + if(elem.attribute("state") == "dirty") state = ResumeWidget::DIRTY; } + resumewidget->setText(resume, state); + animateToWidget(resumewidget); } void MacroWindow::initMacro(QDomNode &node) { QDomElement elem = node.toElement(); - if(elem.tagName() == "macro") { - - // Assign the macro name and version to QStrings for use when comitting - macro = elem.attribute("name", ""); - version = elem.attribute("version", ""); - - } else if(elem.tagName() == "scripts") { + if(elem.tagName() == "scripts") { // Nothing to do here - } else if(elem.tagName() == "resume") { - // Handled in updateResume - } else if(elem.tagName() == "script") { + } + if(elem.tagName() == "script") { lua->runScript(elem.text(), NULL, "preload"); - - } else if(elem.tagName() == "widgets") { - - if(mainwidget) { - WARN(macrowindow, - "WARNING: mainwidget already exists! Calling clear().\n"); - clear(); - } - - DEBUG(mainwindow, "----------------------Before-----------------------\n"); + } + if(elem.tagName() == "widgets") { Window *window = new Window(elem, this); - - DEBUG(mainwindow, "----------------------After------------------------\n"); - connect(window, SIGNAL(wasChanged()), this, SLOT(macroChanged())); macrotitle = elem.attribute("caption"); - - mainwidget = window; - - // Moved to expandWrapper (validation bugfix) - // mainwidget->setValues(); - if(is_static) mainwidget->setValues(); + window->setValues(); if(waschanged == true) macroChanged(); + WARN(macrowindow, "New window."); + mainwidget = window; + animateToWidget(mainwidget->qwidget()); + return; // No further recursion here. } @@ -186,29 +157,17 @@ void MacroWindow::initMacro(QDomNode &node) bool MacroWindow::doCommit() { if(mainwidget->valid()) { + QVector< Widget* > wlist; if(mainwidget) wlist = mainwidget->widgetList(); - QDomDocument doc = netcom.send(wlist, templ, macro, version); - - QDomNodeList nl = doc.documentElement().childNodes(); - QDomNode n = nl.at(0); // There can be only one! (Swush, flomp) - - if(n.toElement().tagName() == "error") { - QMessageBox::critical(this, "Server Error", "Server Error: " + - n.toElement().text()); - return false; - } - - qApp->processEvents(); - - animateToWidget(resumewidget); - emit updateOnCommit(); + netcom.send(wlist, templ, macro, version); return true; + } else { - MessageBox::critical(NULL, "Fejl", - "Makroen " + macrotitle + - " er ikke udfyldt korrekt, prűv igen.\n", + MessageBox::critical(NULL, tr("Error"), + tr("The macro ") + macrotitle + + tr(" was not filled out correctly, please try again.\n"), MessageBox::Ok); return false; @@ -228,91 +187,51 @@ void MacroWindow::cancel() void MacroWindow::expandWrapper() { if(currentWidget() != resumewidget) return; - - waschanged = false; - - QDomDocument xml_doc = netcom.send(templ, macro); - - // Initiate the new macro window with the xml document and push - // it to the window list - QDomNodeList templates = xml_doc.documentElement().childNodes(); - - // There can be only one! (Swush, flomp) - QDomNode templatenode = templates.at(0); - QDomNodeList macronodes = templatenode.childNodes(); - for(int j = 0; j < macronodes.count(); j++) { - QDomNode macronode = macronodes.at(j); - - if(true || macronode.childNodes().count()) { - // macrowindows.push_back( new MacroWindow( netcom, macronode ) ); - QDomElement elem = macronode.toElement(); - - if(elem.tagName() == "macro") { - - // Assign the macro name and version to QStrings for use when comitting - QString macroname; - if(elem.hasAttribute("name")) { - if(elem.attribute("name") == macro) { - // update me! - initMacro(macronode); - } - } - } - } - } - - // Set values here, to be sure that the widgets are visible to the value - // system and thereby validate correctly. - if(mainwidget) mainwidget->setValues(); - - if(mainwidget) animateToWidget(mainwidget->qwidget(), true); - - // Set keyboard focus on the first focusable widget in the macro. - QVector< Widget* > widgets; - if(mainwidget) widgets = mainwidget->widgetList(true); - QVector< Widget* >::iterator i = widgets.begin(); - while (i != widgets.end()) { - if(*i) { - Widget* w = *i; - if(w->setKeyboardFocus()) break; - } - i++; - } - + netcom.send(templ, macro); } void MacroWindow::collapseWrapper() { if(currentWidget() == resumewidget) return; - if(waschanged) { - switch(MessageBox::warning(NULL, - "Gem ændringerne i makroen?", - "Du har valgt at lukke makroen " + - macrotitle + ".\n" - "Űnsker du at gemme inden du lukker?", - MessageBox::Save | MessageBox::Close | - MessageBox::Cancel)) { - case MessageBox::Save: - doCommit(); - break; - case MessageBox::Close: - animateToWidget(resumewidget); - break; - case MessageBox::Cancel: - default: - break; - } - } else { - animateToWidget(resumewidget); + if(waschanged == false) { + netcom.send(templ); + return; + } + + MessageBox::StandardButton res = + MessageBox::warning(NULL, + tr("Save the macro changes?"), + tr("you have choosen to close the macro ") + + macrotitle + ".\n" + + tr("do you want to save before closing?"), + MessageBox::Save | MessageBox::Close | + MessageBox::Cancel); + + switch(res) { + case MessageBox::Save: + doCommit(); + break; + case MessageBox::Close: + netcom.send(templ); + break; + case MessageBox::Cancel: + default: + break; } } void MacroWindow::toggleMacro() { if(!active) return; + if(currentWidget() == resumewidget) { - expandWrapper(); + if(gmainwindow && !gmainwindow->hasOpen(this)) { + expandWrapper(); + } else { + MessageBox::warning(this, tr("Close first"), + tr("Close other one first.")); + } } else { collapseWrapper(); } @@ -337,19 +256,36 @@ void MacroWindow::setActive(bool active) void MacroWindow::clear() { - // DEBUG(macrowindow, "clear %p\n", this); - //setExpandedWidget(NULL); - - if(mainwidget) delete mainwidget; - mainwidget = NULL; + lua->clear(); - // lua->clear(); + if(mainwidget) { + delete mainwidget; + mainwidget = NULL; + } } void MacroWindow::animated(QWidget *w) { if(w == resumewidget) { - DEBUG(macrowindow, "collapsed %p\n", this); + clear(); + + } else { + + if(mainwidget == NULL) return; + + waschanged = false; + mainwidget->setValues(); + + // Set keyboard focus on the first focusable widget in the macro. + QVector< Widget* > widgets; + widgets = mainwidget->widgetList(true); + QVector< Widget* >::iterator i = widgets.begin(); + while(i != widgets.end()) { + Widget *w = *i; + if(w && w->setKeyboardFocus()) break; + i++; + } + } } diff --git a/client/macrowindow.h b/client/macrowindow.h index f57fd05..65fcbf1 100644 --- a/client/macrowindow.h +++ b/client/macrowindow.h @@ -40,19 +40,14 @@ class MacroWindow : public Collapser { Q_OBJECT public: - MacroWindow(NetCom &netcom, QDomNode &xml_doc, QString templ, + MacroWindow(NetCom &netcom, QString templ, bool is_static = false, bool compact = false, QScrollArea *scrollarea = NULL); ~MacroWindow(); - LUA *lua; - void update(QDomNode &xml_doc); - void setActive(bool active); - ResumeWidget *resumewidget; - QString macrotitle; public slots: 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 ¯o = 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++; } } diff --git a/client/mainwindow.h b/client/mainwindow.h index 9da8ff2..8449467 100644 --- a/client/mainwindow.h +++ b/client/mainwindow.h @@ -32,41 +32,47 @@ #include <QVector> #include <QPushButton> #include <QFont> +#include <QLabel> +#include <QDomDocument> +#include <QScrollArea> #include "netcom.h" -//#include "sessions.h" -#include "macro.h" +#include "entity.h" -class QLabel; class MainWindow : public QMainWindow { Q_OBJECT public: - MainWindow(QString cpr, QString templ, QString host, quint16 port, + MainWindow(QString patientid, QString templ, QString host, quint16 port, QString user); ~MainWindow(); void closeEvent(QCloseEvent *event); public slots: - void update(); + // void update(); void closeCommit(); void closeNoCommit(); void closeDiscard(); - // void showSessions(); + + void handle(QDomDocument &doc); + void showError(QString title, QString text); + + bool hasOpen(void *me); private: - void updateTemplateHeaders(QDomNode templatenode); + void updateMacros(QDomNodeList &nodes); + void updateTemplateHeaders(QDomNode &templatenode); QString templ; NetCom netcom; - QString cpr; + QString patientid; QString user; - // QMap< QString, MacroWindow* > macros; - Macros macros; QWidget *w; + Entities entities; + QLabel *header; bool initialising; @@ -76,6 +82,8 @@ private: void init(); + bool closing; + bool isStored; }; diff --git a/client/netcom.cc b/client/netcom.cc index 9d9a5bb..0680f8c 100644 --- a/client/netcom.cc +++ b/client/netcom.cc @@ -54,9 +54,6 @@ NetCom::NetCom(QWidget *wdg, QString host, quint16 port) { this->wdg = wdg; - // - // Setup connection - // QUrl url; url.setHost(host); url.setPort(port); @@ -72,25 +69,30 @@ NetCom::NetCom(QWidget *wdg, QString host, quint16 port) NetCom::~NetCom() { - // - // Clean up - // delete manager; } void NetCom::replyFinished(QNetworkReply *reply) { - finished[reply] = true; + if(reply->error() == QNetworkReply::NoError) { + if(reply->hasRawHeader("SessionID")) { + sessionid = reply->rawHeader("SessionID"); + LOG(netcom, "Reply SESSION ID: %s\n", sessionid.toStdString().c_str()); + } + + QDomDocument doc; + doc.setContent(reply->readAll()); + emit gotReply(doc); + + } else { + emit networkError("Network Error", reply->errorString()); + } } -QDomDocument NetCom::makeTransfer(QDomDocument &doc, bool lockgui, - session_state_t state) +void NetCom::makeTransfer(QDomDocument &doc, session_state_t state) { DEBUG(netcom, "Making transfer:\n%s", doc.toString().toStdString().c_str()); - if(lockgui && wdg) wdg->setEnabled(false); - if(lockgui) QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - LOG(netcom, "SESSION ID: %s\n", sessionid.toStdString().c_str()); request.setRawHeader("User-Agent", "Pracro Client v"VERSION); @@ -117,58 +119,33 @@ QDomDocument NetCom::makeTransfer(QDomDocument &doc, bool lockgui, break; } - // QNetworkReply *reply = manager->get(request); - QNetworkReply *reply = manager->post(request, doc.toByteArray()); - finished[reply] = false; - while(finished[reply] == false) { - qApp->processEvents(QEventLoop::WaitForMoreEvents, 100); - } - finished.remove(reply); - - QByteArray data = reply->readAll(); - QDomDocument res_doc; - res_doc.setContent(data); - - DEBUG(netcom, "Recieved reponse:\n%s", data.data()); - - DEBUG(netcom, "Recieved reponse (Parsed):\n%s", res_doc.toByteArray().data()); - - if(reply->hasRawHeader("SessionID")) { - sessionid = reply->rawHeader("SessionID"); - LOG(netcom, "Reply SESSION ID: %s\n", sessionid.toStdString().c_str()); - } - - if(lockgui) QApplication::restoreOverrideCursor(); - if(lockgui && wdg) wdg->setEnabled(true); - - return res_doc; + manager->post(request, doc.toByteArray()); } -QDomDocument NetCom::initConnection() +void NetCom::initConnection() { - QDomDocument doc; - return makeTransfer(doc, true); + send(templ); // Initialise by sending a template-only request. } -QDomDocument NetCom::commit() +void NetCom::commit() { QDomDocument doc; - return makeTransfer(doc, true, ::commit); + makeTransfer(doc, ::commit); } -QDomDocument NetCom::nocommit() +void NetCom::nocommit() { QDomDocument doc; - return makeTransfer(doc, true, ::nocommit); + makeTransfer(doc, ::nocommit); } -QDomDocument NetCom::discard() +void NetCom::discard() { QDomDocument doc; - return makeTransfer(doc, true, ::discard); + makeTransfer(doc, ::discard); } -QDomDocument NetCom::send(QString templ, QString macro, bool lockgui) +void NetCom::send(QString templ, QString macro) { QDomDocument doc; @@ -187,11 +164,11 @@ QDomDocument NetCom::send(QString templ, QString macro, bool lockgui) if(macro != "") request_elem.setAttribute("macro", macro); pracro_elem.appendChild(request_elem); - return makeTransfer(doc, lockgui); + makeTransfer(doc); } -QDomDocument NetCom::send(QVector< Widget* > widgets, QString templ, - QString macro, QString version) +void NetCom::send(QVector< Widget* > widgets, QString templ, + QString macro, QString version) { QDomDocument doc; @@ -229,6 +206,10 @@ QDomDocument NetCom::send(QVector< Widget* > widgets, QString templ, } i++; } + + QDomElement request_elem = doc.createElement("request"); + request_elem.setAttribute("template", templ); + pracro_elem.appendChild(request_elem); - return makeTransfer(doc, true); + makeTransfer(doc); } diff --git a/client/netcom.h b/client/netcom.h index a8be6f6..1ee06d6 100644 --- a/client/netcom.h +++ b/client/netcom.h @@ -54,19 +54,24 @@ public: NetCom(QWidget *wdg, QString host, quint16 port); ~NetCom(); - QDomDocument send(QString templ, QString macro = "", bool lockgui = true); - QDomDocument send(QVector< Widget* > widgets, QString templ, - QString macro, QString version); - QDomDocument initConnection(); - QDomDocument commit(); - QDomDocument nocommit(); - QDomDocument discard(); + void send(QString templ, QString macro = ""); + void send(QVector< Widget* > widgets, QString templ, + QString macro, QString version); + + void initConnection(); + void commit(); + void nocommit(); + void discard(); QString sessionid; QString user; QString patientid; QString templ; +signals: + void gotReply(QDomDocument &doc); + void networkError(QString title, QString text); + public slots: void replyFinished(QNetworkReply*); @@ -79,8 +84,7 @@ private: QMap<QNetworkReply *, bool> finished; - QDomDocument makeTransfer(QDomDocument &dom, bool lockgui, - session_state_t state = none); + void makeTransfer(QDomDocument &dom, session_state_t state = none); }; #endif/*__PRACRO_NETCOM_H__*/ diff --git a/client/pracro_dk.ts b/client/pracro_dk.ts index 9188e10..7234f0a 100644 --- a/client/pracro_dk.ts +++ b/client/pracro_dk.ts @@ -51,41 +51,96 @@ et CPR nummer pĂ„ 10 cifre.</translation> </message> </context> <context> + <name>MacroWindow</name> + <message> + <location filename="macrowindow.cc" line="168"/> + <source>Error</source> + <translation>Der er sket en fejl</translation> + </message> + <message> + <location filename="macrowindow.cc" line="169"/> + <source>The macro </source> + <translation>Makroen </translation> + </message> + <message> + <location filename="macrowindow.cc" line="170"/> + <source> was not filled out correctly, please try again. +</source> + <translation> er ikke.udfyldt korrekt. PrĂžv igen.</translation> + </message> + <message> + <location filename="macrowindow.cc" line="204"/> + <source>Save the macro changes?</source> + <translation>Gem makro ĂŠndringer?</translation> + </message> + <message> + <location filename="macrowindow.cc" line="205"/> + <source>you have choosen to close the macro </source> + <translation>Du har valgt at lukke makroen </translation> + </message> + <message> + <location filename="macrowindow.cc" line="207"/> + <source>do you want to save before closing?</source> + <translation>Ăžnsker du at gemme dine ĂŠndringer fĂžrst?</translation> + </message> + <message> + <location filename="macrowindow.cc" line="232"/> + <source>Close first</source> + <translation>Luk fĂžrst</translation> + </message> + <message> + <location filename="macrowindow.cc" line="232"/> + <source>Close other one first.</source> + <translation>Luk den Ă„bne makro fĂžrst.</translation> + </message> +</context> +<context> <name>MainWindow</name> <message> - <location filename="mainwindow.cc" line="86"/> + <location filename="mainwindow.cc" line="112"/> <source>Close and commit</source> <translation>Gem og commit</translation> </message> <message> - <location filename="mainwindow.cc" line="89"/> + <location filename="mainwindow.cc" line="115"/> <source>Close no commit</source> <translation>Gem uden commit</translation> </message> <message> - <location filename="mainwindow.cc" line="98"/> + <location filename="mainwindow.cc" line="150"/> + <location filename="mainwindow.cc" line="162"/> + <location filename="mainwindow.cc" line="174"/> + <source>Close first.</source> + <translation>Luk fĂžrst.</translation> + </message> + <message> + <location filename="mainwindow.cc" line="151"/> + <location filename="mainwindow.cc" line="163"/> + <location filename="mainwindow.cc" line="175"/> + <source>Close open macros first.</source> + <translation>Luk Ă„bne makroer fĂžrst.</translation> + </message> + <message> <source>Show sessions</source> - <translation>Vis sessioner</translation> + <translation type="obsolete">Vis sessioner</translation> </message> <message> - <location filename="mainwindow.cc" line="138"/> <source>Closing without commit</source> - <translation>Lukker uden commit</translation> + <translation type="obsolete">Lukker uden commit</translation> </message> <message> - <location filename="mainwindow.cc" line="139"/> <source>This session will be stored on this computer only. To reopen it at a later time, simply open the same patient again.</source> - <translation>Denne session bliver husket pĂ„ denne specifikke maskine. For at genĂ„bne pĂ„ et senere tidspunkt, skal du blot genĂ„bne pĂ„ samme patient.</translation> + <translation type="obsolete">Denne session bliver husket pĂ„ denne specifikke maskine. For at genĂ„bne pĂ„ et senere tidspunkt, skal du blot genĂ„bne pĂ„ samme patient.</translation> </message> <message> - <location filename="mainwindow.cc" line="150"/> - <location filename="mainwindow.cc" line="173"/> + <location filename="mainwindow.cc" line="181"/> + <location filename="mainwindow.cc" line="203"/> <source>Discard</source> <translation>KassĂ©r</translation> </message> <message> - <location filename="mainwindow.cc" line="151"/> - <location filename="mainwindow.cc" line="174"/> + <location filename="mainwindow.cc" line="182"/> + <location filename="mainwindow.cc" line="204"/> <source>This session will <strong>NOT</strong> be stored in the journal.<br/>Are you sure you want to continue?</source> <translation>Denne session vil <strong>IKKE</strong> blive gemt i journalen.<br/>Er du sikker pĂ„ du vil fortsĂŠtte?</translation> </message> @@ -197,7 +252,7 @@ et CPR nummer pĂ„ 10 cifre.</translation> <translation>IgnorĂ©r</translation> </message> <message> - <location filename="macro.cc" line="162"/> + <location filename="macro.cc" line="119"/> <source>Depends on: </source> <translation>AfhĂŠnger af: </translation> </message> diff --git a/client/sessions.cc b/client/sessions.cc deleted file mode 100644 index d663b65..0000000 --- a/client/sessions.cc +++ /dev/null @@ -1,119 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set et sw=2 ts=2: */ -/*************************************************************************** - * sessions.cc - * - * Wed May 26 14:31:51 CEST 2010 - * Copyright 2010 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 "sessions.h" - -#include <QDialog> -#include <QGridLayout> -#include <QLabel> - -#define USER 0 -#define SESSIONID 1 - -void Sessions::add(QString cpr, QString user, QString sessionid) -{ - QList<QVariant> data; - data.insert(USER, QVariant(user)); - data.insert(SESSIONID, QVariant(sessionid)); - s[cpr] = data; -} - -void Sessions::remove(QString cpr) -{ - s.remove(cpr); -} - -void Sessions::show() -{ - QDialog dlg; - - QGridLayout *grid = new QGridLayout(); - dlg.setLayout(grid); - dlg.setWindowTitle("Stored sessions"); - dlg.setMinimumSize(300, 40); - - QLabel *lcpr = new QLabel("CPR:"); - QLabel *luser = new QLabel("User:"); - QLabel *lid = new QLabel("SessionID:"); - - grid->addWidget(lcpr, 0, 0); - grid->addWidget(luser, 0, 1); - grid->addWidget(lid, 0, 2); - - int row = 1; - QMap<QString, QVariant>::iterator i = s.begin(); - while(i != s.end()) { - QString patientid = i.key(); - QList<QVariant> data = i.value().toList(); - - QLabel *lcpr = new QLabel(patientid); - QLabel *luser = new QLabel(data[USER].toString()); - QLabel *lid = new QLabel(data[SESSIONID].toString()); - - grid->addWidget(lcpr, row, 0); - grid->addWidget(luser, row, 1); - grid->addWidget(lid, row, 2); - row++; - i++; - } - - dlg.exec(); -} - -bool Sessions::isEmpty() -{ - return s.size() == 0; -} - -QVariant Sessions::toVariant() -{ - return s; -} - -void Sessions::fromVariant(const QVariant &v) -{ - s = v.toMap(); -} - -bool Sessions::contains(QString cpr) -{ - return s.contains(cpr); -} - -QString Sessions::getUser(QString cpr) -{ - if(!contains(cpr)) return ""; - QList<QVariant> data = s[cpr].toList(); - return data[USER].toString(); -} - -QString Sessions::getSessionID(QString cpr) -{ - if(!contains(cpr)) return ""; - QList<QVariant> data = s[cpr].toList(); - return data[SESSIONID].toString(); -} |