summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/client.pro2
-rw-r--r--client/client.qrc2
-rw-r--r--client/icons/done.pngbin0 -> 724 bytes
-rw-r--r--client/icons/undone.pngbin0 -> 685 bytes
-rw-r--r--client/mainwindow.cc2
-rw-r--r--client/netcom.cc10
-rw-r--r--client/netcom.h2
-rw-r--r--client/pracro.cc66
-rw-r--r--client/pracro.ini1
-rw-r--r--client/viewer.cc198
-rw-r--r--client/viewer.h80
11 files changed, 339 insertions, 24 deletions
diff --git a/client/client.pro b/client/client.pro
index ec91339..162bf22 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -41,6 +41,7 @@ HEADERS += \
messagebox.h \
netcom.h \
resumewidget.h \
+ viewer.h \
widgetbuilder.h \
widgets.h \
widgets/common.h \
@@ -75,6 +76,7 @@ SOURCES += \
messagebox.cc \
netcom.cc \
resumewidget.cc \
+ viewer.cc \
widgetbuilder.cc \
widgets/common.cc \
widgets/widget.cc \
diff --git a/client/client.qrc b/client/client.qrc
index efcd91f..ffbbda0 100644
--- a/client/client.qrc
+++ b/client/client.qrc
@@ -7,5 +7,7 @@
<file>icons/arrows.png</file>
<file>icons/compressed.png</file>
<file>icons/padlock.png</file>
+ <file>icons/done.png</file>
+ <file>icons/undone.png</file>
</qresource>
</RCC>
diff --git a/client/icons/done.png b/client/icons/done.png
new file mode 100644
index 0000000..89412f8
--- /dev/null
+++ b/client/icons/done.png
Binary files differ
diff --git a/client/icons/undone.png b/client/icons/undone.png
new file mode 100644
index 0000000..5f6792d
--- /dev/null
+++ b/client/icons/undone.png
Binary files differ
diff --git a/client/mainwindow.cc b/client/mainwindow.cc
index beef88c..51bb772 100644
--- a/client/mainwindow.cc
+++ b/client/mainwindow.cc
@@ -77,6 +77,8 @@ void MainWindow::closeEvent(QCloseEvent *)
settings.setValue("size", size());
settings.setValue("pos", pos());
settings.endGroup();
+
+ QApplication::quit();
}
void MainWindow::init()
diff --git a/client/netcom.cc b/client/netcom.cc
index 0da19f8..3b3abb7 100644
--- a/client/netcom.cc
+++ b/client/netcom.cc
@@ -46,13 +46,13 @@ NetCom::~NetCom()
socket.disconnectFromHost();
}
-QDomDocument NetCom::send(QString templ, QString macro)
+QDomDocument NetCom::send(QString templ, QString macro, bool lockgui)
{
printf("Socket state: %d\n", socket.state());
if(socket.state() != 3) printf("Socket state not connected: %s\n", socket.errorString().toStdString().c_str());
- if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(false);
- QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+ if(lockgui && qApp->activeWindow()) qApp->activeWindow()->setEnabled(false);
+ if(lockgui) QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QDomDocument doc;
@@ -85,8 +85,8 @@ QDomDocument NetCom::send(QString templ, QString macro)
printf("\nRecieved request:\n%s", res_doc.toString().toStdString().c_str());
- QApplication::restoreOverrideCursor();
- if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(true);
+ if(lockgui) QApplication::restoreOverrideCursor();
+ if(lockgui && qApp->activeWindow()) qApp->activeWindow()->setEnabled(true);
return res_doc;
}
diff --git a/client/netcom.h b/client/netcom.h
index 8cccaa9..35db221 100644
--- a/client/netcom.h
+++ b/client/netcom.h
@@ -41,7 +41,7 @@ public:
NetCom(QString host, quint16 port, QString user, QString cpr);
~NetCom();
- QDomDocument send(QString templ, QString macro = "");
+ QDomDocument send(QString templ, QString macro = "", bool lockgui = true);
void send(QVector< Widget* > widgets, QString templ, QString macro, QString version);
public slots:
diff --git a/client/pracro.cc b/client/pracro.cc
index 6d9c574..eacdeb1 100644
--- a/client/pracro.cc
+++ b/client/pracro.cc
@@ -35,6 +35,7 @@
#include "netcom.h"
#include "mainwindow.h"
+#include "viewer.h"
#define CPR_DEFAULT ""
#define MACRO_DEFAULT ""
@@ -54,10 +55,6 @@ static void print_usage()
printf("Executes the requested Pracro MACRO using supplied CPR and USER.\n");
printf("\n");
printf(" -h, --help Displays this help text.\n");
- /*
- printf(" -m, --macro MACRO Requests macro MACRO from the Pracro \n"
- " Server, defaults to \""MACRO_DEFAULT"\".\n");
- */
printf(" -t, --template TEMPLATE Requests template TEMPLATE from the Pracro \n"
" Server, defaults to \""TEMPLATE_DEFAULT"\".\n");
printf(" -C, --cpr CPR Defines the cpr for use with the macro,\n"
@@ -65,8 +62,10 @@ static void print_usage()
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");
- // printf(" -t, --test macro Run client in testmode, i.e. run without contactig any\n"
- // " servers. The macro must be a local xml file.\n");
+ printf(" -v, --version Print version information and exit.\n");
+ printf(" -V, --viewer TEMPLATES Show the viewer with TEMPLATES.\n");
+ printf(" -O, --viewer-only TEMPLATES\n");
+ printf(" Show the viewer only (no pracro editor window) with TEMPLATES.\n");
}
static void print_version()
@@ -90,6 +89,9 @@ int main(int argc, char *argv[])
QString macro = MACRO_DEFAULT;
QString templ = TEMPLATE_DEFAULT;
+ bool show_viewer = false;
+ bool show_editor = true;
+ QString templs;
QStringList args = app.arguments();
QStringList::iterator arg = args.begin();
@@ -99,22 +101,18 @@ int main(int argc, char *argv[])
if(*arg == "--help" ||
*arg == "-h") {
print_usage();
+ return 0;
}
else if(*arg == "--version" ||
*arg == "-v") {
print_version();
+ return 0;
}
else if(*arg == "--user" ||
*arg == "-U" ||
*arg == "-u") {
user = getParam(args,arg);
}
- /*
- else if(*arg == "--macro" ||
- *arg == "-m") {
- macro = getParam(args, arg);
- }
- */
else if(*arg == "--template" ||
*arg == "-t") {
templ = getParam(args, arg);
@@ -127,6 +125,17 @@ int main(int argc, char *argv[])
*arg == "-c") {
config = getParam(args, arg);
}
+ else if(*arg == "--viewer" ||
+ *arg == "-V") {
+ templs = getParam(args, arg);
+ show_viewer = true;
+ }
+ else if(*arg == "--viewer-only" ||
+ *arg == "-O") {
+ templs = getParam(args, arg);
+ show_viewer = true;
+ show_editor = false;
+ }
else {
print_version();
print_usage();
@@ -141,16 +150,37 @@ int main(int argc, char *argv[])
settings.beginGroup("server");
host = settings.value("host").toString();
port = settings.value("port").toInt();
+ QString journalpath = settings.value("journalpath").toString();
settings.endGroup();
QTranslator translator;
- translator.load("pracro_dk");
- app.installTranslator(&translator);
+ if(translator.load("pracro_dk")) {
+ app.installTranslator(&translator);
+ }
+
+ if(show_editor && show_viewer) {
+ MainWindow mainwindow(cpr, templ, host, port, user);
+ mainwindow.show();
+
+ Viewer viewer(cpr, templs, host, port, user, journalpath);
+ viewer.show();
- MainWindow mainwindow(cpr, templ, host, port, user);
- mainwindow.show();
+ return app.exec();
+ }
+
+ if(show_editor) {
+ MainWindow mainwindow(cpr, templ, host, port, user);
+ mainwindow.show();
+
+ return app.exec();
+ }
+
+ if(show_viewer) {
+ Viewer viewer(cpr, templs, host, port, user, journalpath);
+ viewer.show();
- int ret = app.exec();
+ return app.exec();
+ }
- return ret;
+ return 1;
}
diff --git a/client/pracro.ini b/client/pracro.ini
index 25fd0bf..55c97f7 100644
--- a/client/pracro.ini
+++ b/client/pracro.ini
@@ -2,3 +2,4 @@
#host=pracserv.j.auh.dk
host=localhost
port=12345
+journalpath="/home/samba/praxis/J1"
diff --git a/client/viewer.cc b/client/viewer.cc
new file mode 100644
index 0000000..22ff2a1
--- /dev/null
+++ b/client/viewer.cc
@@ -0,0 +1,198 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * viewer.cc
+ *
+ * Mon Aug 17 08:53:29 CEST 2009
+ * Copyright 2009 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 "viewer.h"
+
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QFile>
+#include <QScrollBar>
+
+#include <QSettings>
+#include <QTextCodec>
+
+Status::Status()
+{
+ QVBoxLayout *vl = new QVBoxLayout();
+ setLayout(vl);
+ this->caption = new QLabel();
+ vl->addWidget(this->caption);
+
+ QHBoxLayout *ohl = new QHBoxLayout();
+ ohl->setContentsMargins(0,0,0,0);
+ vl->addLayout(ohl);
+
+ hl = new QHBoxLayout();
+ hl->setContentsMargins(0,0,0,0);
+ ohl->addLayout(hl);
+
+ ohl->addStretch();
+}
+
+void Status::setCaption(QString caption)
+{
+ this->caption->setText(caption + ":");
+}
+
+void Status::setStatus(QString macro, QString caption, bool done)
+{
+ if(icons.find(macro) == icons.end()) {
+ QLabel *icon = new QLabel();
+ icon->setContentsMargins(0,0,0,0);
+ icon->setMargin(0);
+ icon->setIndent(0);
+ icon->setWhatsThis(caption);
+ icon->setToolTip(caption);
+ icons[macro] = icon;
+ hl->addWidget(icon);
+ }
+
+ icons[macro]->setPixmap(QPixmap(done?":/icons/done.png":":icons/undone.png"));
+}
+
+Viewer::Viewer(QString cpr, QString templs, QString host, quint16 port,
+ QString user, QString journalpath)
+ : QWidget(NULL)
+{
+ this->templs = templs.split(QRegExp("\\W+"), QString::SkipEmptyParts);
+
+ connect(&updatetimer, SIGNAL(timeout()), this, SLOT(update()));
+ netcom = new NetCom(host, port, user, cpr);
+ host = host; port = port; user = user;
+ this->cpr = cpr;
+ this->journalpath = journalpath;
+ updatetimer.start(10000); // Trigger every 10 seconds
+
+ QVBoxLayout *l = new QVBoxLayout();
+ setLayout(l);
+
+ QStringList::iterator ti = this->templs.begin();
+ while(ti != this->templs.end()) {
+ Status *s = new Status();
+ l->addWidget(s);
+ statuses[*ti] = s;
+ ti++;
+ }
+
+ journal = new QTextEdit();
+ journal->setReadOnly(true);
+ journal->setFontFamily("Courier New");
+ l->addWidget(journal);
+
+ init();
+ update();
+}
+
+Viewer::~Viewer()
+{
+ delete netcom;
+ delete journal;
+}
+
+void Viewer::closeEvent(QCloseEvent *)
+{
+ QSettings settings("Aasimon.org", "Pracro");
+
+ settings.beginGroup("ViewerWindow");
+ settings.setValue("size", size());
+ settings.setValue("pos", pos());
+ settings.endGroup();
+}
+
+void Viewer::init()
+{
+ QSettings settings("Aasimon.org", "Pracro");
+
+ settings.beginGroup("ViewerWindow");
+ resize(settings.value("size", QSize(700, 800)).toSize());
+ move(settings.value("pos", QPoint(0, 0)).toPoint());
+ settings.endGroup();
+}
+
+
+void Viewer::update()
+{
+ QStringList::iterator ti = templs.begin();
+ while(ti != templs.end()) {
+ QDomDocument xml_doc = netcom->send(*ti, "", false);
+
+ QDomNodeList templates = xml_doc.documentElement().childNodes();
+ QDomNode templatenode = templates.at(0); // There can be only one! (Swush, flomp)
+ QDomElement templateelement = templatenode.toElement();
+
+ statuses[*ti]->setCaption(templateelement.attribute("title"));
+
+ QDomNodeList macronodes = templatenode.childNodes();
+ for(int j = 0; j < macronodes.count(); j++) {
+ QDomNode macronode = macronodes.at(j);
+ QDomElement macroelement = macronode.toElement();
+
+ if(macroelement.tagName() != "macro") continue;
+
+ if(macroelement.attribute("static") == "true") continue;
+
+ QString macroname = macroelement.attribute("name");
+ QString caption = macroelement.attribute("caption");
+ QString completed = macroelement.attribute("completed");
+
+ statuses[*ti]->setStatus(macroname, caption, completed == "true");
+ }
+
+ ti++;
+ }
+
+ // re-read journal file:
+ QString crypt;
+ for(int i = cpr.length() - 1; i >= 0; i--) {
+ if(i == 2 || i == 3) continue;
+ crypt += QString::number(9 - cpr.mid(i, 1).toInt());
+ }
+
+ QString filename = journalpath + "/" + cpr.mid(2,2) + "/" + crypt + "/JOURNAL.TXT";
+ filename = "/home/senator/JOURNAL.TXT";
+
+ QTextCodec *cp850 = QTextCodec::codecForName("cp850");
+ if(!cp850) {
+ printf("Could not find decoder for cp850!\n");
+ }
+
+ QFile jfile(filename);
+ jfile.open(QIODevice::ReadOnly);
+ QByteArray jcp850 = jfile.readAll();
+ QString j = cp850->toUnicode(jcp850);
+
+ QString jstrip;
+ for(int i = 0; i < j.length(); i++) {
+ if(j[i] != '·') jstrip += j[i]; // Remove end of line symbols.
+ }
+
+ if(journal->toPlainText() != jstrip) {
+ int pos = journal->verticalScrollBar()->value();
+ journal->setPlainText(jstrip);
+ journal->verticalScrollBar()->setValue(pos);
+ }
+}
diff --git a/client/viewer.h b/client/viewer.h
new file mode 100644
index 0000000..7877b8e
--- /dev/null
+++ b/client/viewer.h
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * viewer.h
+ *
+ * Mon Aug 17 08:53:29 CEST 2009
+ * Copyright 2009 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_VIEWER_H__
+#define __PRACRO_VIEWER_H__
+
+#include <QApplication>
+#include <QTextEdit>
+#include <QTimer>
+#include <QLabel>
+#include <QStringList>
+#include <QMap>
+#include <QHBoxLayout>
+
+#include "netcom.h"
+
+class Status : public QWidget {
+public:
+ Status();
+ void setStatus(QString macro, QString caption, bool done);
+ void setCaption(QString caption);
+
+private:
+ QLabel *caption;
+ QMap<QString, QLabel*> icons;
+ QHBoxLayout *hl;
+};
+
+class Viewer : public QWidget {
+Q_OBJECT
+public:
+ Viewer(QString cpr, QString templ, QString host, quint16 port,
+ QString user, QString journalpath);
+ ~Viewer();
+
+ void init();
+
+protected:
+ void closeEvent(QCloseEvent *);
+
+public slots:
+ void update();
+
+private:
+ QTimer updatetimer;
+
+ QString cpr;
+ QString journalpath;
+ QStringList templs;
+ NetCom *netcom;
+
+ QTextEdit *journal;
+ QMap<QString, Status* > statuses;
+};
+
+#endif/*__PRACRO_VIEWER_H__*/