summaryrefslogtreecommitdiff
path: root/client
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
parent9b9c1e2dd3e5807ff7714b378b03b9ba31f42df7 (diff)
From new_protocol branch.
Diffstat (limited to 'client')
-rw-r--r--client/client.pro17
-rw-r--r--client/client.qrc5
-rw-r--r--client/fonts/COPYRIGHT.TXT124
-rw-r--r--client/fonts/README.TXT11
-rw-r--r--client/fonts/RELEASENOTES.TXT162
-rw-r--r--client/fonts/VeraMono.ttfbin0 -> 49224 bytes
-rw-r--r--client/icons/icon_close_commit.pngbin0 -> 1834 bytes
-rw-r--r--client/icons/icon_close_no_commit.pngbin0 -> 1520 bytes
-rw-r--r--client/icons/icon_current_sessions.pngbin0 -> 1646 bytes
-rw-r--r--client/icons/icon_discard.pngbin0 -> 1654 bytes
-rw-r--r--client/macrowindow.cc25
-rw-r--r--client/mainwindow.cc128
-rw-r--r--client/mainwindow.h18
-rw-r--r--client/netcom.cc177
-rw-r--r--client/netcom.h31
-rw-r--r--client/pracro.cc10
-rw-r--r--client/resumewidget.cc31
-rw-r--r--client/sessions.cc119
-rw-r--r--client/sessions.h58
-rw-r--r--client/viewer.cc9
20 files changed, 788 insertions, 137 deletions
diff --git a/client/client.pro b/client/client.pro
index f6468b4..7db485e 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -15,8 +15,7 @@ debug {
CONFIG += debug
}
-VERSION="-1.2.0"
-DEFINES+=VERSION=\\\"1.2.0\\\"
+DEFINES+=VERSION=\\\"2.0.0-beta1\\\"
win32 {
LIBPATH += lua/lib
@@ -43,6 +42,7 @@ HEADERS += \
messagebox.h \
netcom.h \
resumewidget.h \
+ sessions.h \
viewer.h \
widgetbuilder.h \
widgets.h \
@@ -78,6 +78,7 @@ SOURCES += \
messagebox.cc \
netcom.cc \
resumewidget.cc \
+ sessions.cc \
viewer.cc \
widgetbuilder.cc \
widgets/common.cc \
@@ -100,16 +101,4 @@ SOURCES += \
widgets/altcombobox.cc \
widgets/metawidget.cc
-DISTFILES += \
- icons/add.png \
- icons/arrows.png \
- icons/compressed.png \
- icons/del.png \
- icons/done.png \
- icons/icon.png \
- icons/padlock.png \
- icons/padlock.svg \
- icons/undone.png
-
-
TRANSLATIONS = pracro_dk.ts
diff --git a/client/client.qrc b/client/client.qrc
index ffbbda0..d85a872 100644
--- a/client/client.qrc
+++ b/client/client.qrc
@@ -9,5 +9,10 @@
<file>icons/padlock.png</file>
<file>icons/done.png</file>
<file>icons/undone.png</file>
+ <file>icons/icon_close_commit.png</file>
+ <file>icons/icon_current_sessions.png</file>
+ <file>icons/icon_close_no_commit.png</file>
+ <file>icons/icon_discard.png</file>
+ <file>fonts/VeraMono.ttf</file>
</qresource>
</RCC>
diff --git a/client/fonts/COPYRIGHT.TXT b/client/fonts/COPYRIGHT.TXT
new file mode 100644
index 0000000..e651be1
--- /dev/null
+++ b/client/fonts/COPYRIGHT.TXT
@@ -0,0 +1,124 @@
+Bitstream Vera Fonts Copyright
+
+The fonts have a generous copyright, allowing derivative works (as
+long as "Bitstream" or "Vera" are not in the names), and full
+redistribution (so long as they are not *sold* by themselves). They
+can be be bundled, redistributed and sold with any software.
+
+The fonts are distributed under the following copyright:
+
+Copyright
+=========
+
+Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream
+Vera is a trademark of Bitstream, Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the fonts accompanying this license ("Fonts") and associated
+documentation files (the "Font Software"), to reproduce and distribute
+the Font Software, including without limitation the rights to use,
+copy, merge, publish, distribute, and/or sell copies of the Font
+Software, and to permit persons to whom the Font Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright and trademark notices and this permission notice
+shall be included in all copies of one or more of the Font Software
+typefaces.
+
+The Font Software may be modified, altered, or added to, and in
+particular the designs of glyphs or characters in the Fonts may be
+modified and additional glyphs or characters may be added to the
+Fonts, only if the fonts are renamed to names not containing either
+the words "Bitstream" or the word "Vera".
+
+This License becomes null and void to the extent applicable to Fonts
+or Font Software that has been modified and is distributed under the
+"Bitstream Vera" names.
+
+The Font Software may be sold as part of a larger software package but
+no copy of one or more of the Font Software typefaces may be sold by
+itself.
+
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
+BITSTREAM OR THE GNOME FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL,
+OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT
+SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
+
+Except as contained in this notice, the names of Gnome, the Gnome
+Foundation, and Bitstream Inc., shall not be used in advertising or
+otherwise to promote the sale, use or other dealings in this Font
+Software without prior written authorization from the Gnome Foundation
+or Bitstream Inc., respectively. For further information, contact:
+fonts at gnome dot org.
+
+Copyright FAQ
+=============
+
+ 1. I don't understand the resale restriction... What gives?
+
+ Bitstream is giving away these fonts, but wishes to ensure its
+ competitors can't just drop the fonts as is into a font sale system
+ and sell them as is. It seems fair that if Bitstream can't make money
+ from the Bitstream Vera fonts, their competitors should not be able to
+ do so either. You can sell the fonts as part of any software package,
+ however.
+
+ 2. I want to package these fonts separately for distribution and
+ sale as part of a larger software package or system. Can I do so?
+
+ Yes. A RPM or Debian package is a "larger software package" to begin
+ with, and you aren't selling them independently by themselves.
+ See 1. above.
+
+ 3. Are derivative works allowed?
+ Yes!
+
+ 4. Can I change or add to the font(s)?
+ Yes, but you must change the name(s) of the font(s).
+
+ 5. Under what terms are derivative works allowed?
+
+ You must change the name(s) of the fonts. This is to ensure the
+ quality of the fonts, both to protect Bitstream and Gnome. We want to
+ ensure that if an application has opened a font specifically of these
+ names, it gets what it expects (though of course, using fontconfig,
+ substitutions could still could have occurred during font
+ opening). You must include the Bitstream copyright. Additional
+ copyrights can be added, as per copyright law. Happy Font Hacking!
+
+ 6. If I have improvements for Bitstream Vera, is it possible they might get
+ adopted in future versions?
+
+ Yes. The contract between the Gnome Foundation and Bitstream has
+ provisions for working with Bitstream to ensure quality additions to
+ the Bitstream Vera font family. Please contact us if you have such
+ additions. Note, that in general, we will want such additions for the
+ entire family, not just a single font, and that you'll have to keep
+ both Gnome and Jim Lyles, Vera's designer, happy! To make sense to add
+ glyphs to the font, they must be stylistically in keeping with Vera's
+ design. Vera cannot become a "ransom note" font. Jim Lyles will be
+ providing a document describing the design elements used in Vera, as a
+ guide and aid for people interested in contributing to Vera.
+
+ 7. I want to sell a software package that uses these fonts: Can I do so?
+
+ Sure. Bundle the fonts with your software and sell your software
+ with the fonts. That is the intent of the copyright.
+
+ 8. If applications have built the names "Bitstream Vera" into them,
+ can I override this somehow to use fonts of my choosing?
+
+ This depends on exact details of the software. Most open source
+ systems and software (e.g., Gnome, KDE, etc.) are now converting to
+ use fontconfig (see www.fontconfig.org) to handle font configuration,
+ selection and substitution; it has provisions for overriding font
+ names and subsituting alternatives. An example is provided by the
+ supplied local.conf file, which chooses the family Bitstream Vera for
+ "sans", "serif" and "monospace". Other software (e.g., the XFree86
+ core server) has other mechanisms for font substitution.
+
diff --git a/client/fonts/README.TXT b/client/fonts/README.TXT
new file mode 100644
index 0000000..0f71795
--- /dev/null
+++ b/client/fonts/README.TXT
@@ -0,0 +1,11 @@
+Contained herin is the Bitstream Vera font family.
+
+The Copyright information is found in the COPYRIGHT.TXT file (along
+with being incoporated into the fonts themselves).
+
+The releases notes are found in the file "RELEASENOTES.TXT".
+
+We hope you enjoy Vera!
+
+ Bitstream, Inc.
+ The Gnome Project
diff --git a/client/fonts/RELEASENOTES.TXT b/client/fonts/RELEASENOTES.TXT
new file mode 100644
index 0000000..270bc0d
--- /dev/null
+++ b/client/fonts/RELEASENOTES.TXT
@@ -0,0 +1,162 @@
+Bitstream Vera Fonts - April 16, 2003
+=====================================
+
+The version number of these fonts is 1.10 to distinguish them from the
+beta test fonts.
+
+Note that the Vera copyright is incorporated in the fonts themselves.
+The License field in the fonts contains the copyright license as it
+appears below. The TrueType copyright field is not large enough to
+contain the full license, so the license is incorporated (as you might
+think if you thought about it) into the license field, which
+unfortunately can be obscure to find. (In pfaedit, see: Element->Font
+Info->TTFNames->License).
+
+Our apologies for it taking longer to complete the fonts than planned.
+Beta testers requested a tighter line spacing (less leading) and Jim
+Lyles redesigned Vera's accents to bring its line spacing to more
+typical of other fonts. This took additional time and effort. Our
+thanks to Jim for this effort above and beyond the call of duty.
+
+There are four monospace and sans faces (normal, oblique, bold, bold
+oblique) and two serif faces (normal and bold). Fontconfig/Xft2 (see
+www.fontconfig.org) can artificially oblique the serif faces for you:
+this loses hinting and distorts the faces slightly, but is visibly
+different than normal and bold, and reasonably pleasing.
+
+On systems with fontconfig 2.0 or 2.1 installed, making your sans,
+serif and monospace fonts default to these fonts is very easy. Just
+drop the file local.conf into your /etc/fonts directory. This will
+make the Bitstream fonts your default fonts for all applications using
+fontconfig (if sans, serif, or monospace names are used, as they often
+are as default values in many desktops). The XML in local.conf may
+need modification to enable subpixel decimation, if appropriate,
+however, the commented out phrase does so for XFree86 4.3, in the case
+that the server does not have sufficient information to identify the
+use of a flat panel. Fontconfig 2.2 adds Vera to the list of font
+families and will, by default use it as the default sans, serif and
+monospace fonts.
+
+During the testing of the final Vera fonts, we learned that screen
+fonts in general are only typically hinted to work correctly at
+integer pixel sizes. Vera is coded internally for integer sizes only.
+We need to investigate further to see if there are commonly used fonts
+that are hinted to be rounded but are not rounded to integer sizes due
+to oversights in their coding.
+
+Most fonts work best at 8 pixels and below if anti-aliased only, as
+the amount of work required to hint well at smaller and smaller sizes
+becomes astronomical. GASP tables are typically used to control
+whether hinting is used or not, but Freetype/Xft does not currently
+support GASP tables (which are present in Vera).
+
+To mitigate this problem, both for Vera and other fonts, there will be
+(very shortly) a new fontconfig 2.2 release that will, by default not
+apply hints if the size is below 8 pixels. if you should have a font
+that in fact has been hinted more agressively, you can use fontconfig
+to note this exception. We believe this should improve many hinted
+fonts in addition to Vera, though implemeting GASP support is likely
+the right long term solution.
+
+Font rendering in Gnome or KDE is the combination of algorithms in
+Xft2 and Freetype, along with hinting in the fonts themselves. It is
+vital to have sufficient information to disentangle problems that you
+may observe.
+
+Note that having your font rendering system set up correctly is vital
+to proper judgement of problems of the fonts:
+
+ * Freetype may or may not be configured to in ways that may
+ implement execution of possibly patented (in some parts of the world)
+ TrueType hinting algorithms, particularly at small sizes. Best
+ results are obtained while using these algorithms.
+
+ * The freetype autohinter (used when the possibly patented
+ algorithms are not used) continues to improve with each release. If
+ you are using the autohinter, please ensure you are using an up to
+ date version of freetype before reporting problems.
+
+ * Please identify what version of freetype you are using in any
+ bug reports, and how your freetype is configured.
+
+ * Make sure you are not using the freetype version included in
+ XFree86 4.3, as it has bugs that significantly degrade most fonts,
+ including Vera. if you build XFree86 4.3 from source yourself, you may
+ have installed this broken version without intending it (as I
+ did). Vera was verified with the recently released Freetype 2.1.4. On
+ many systems, 'ldd" can be used to see which freetype shared library
+ is actually being used.
+
+ * Xft/X Render does not (yet) implement gamma correction. This
+ causes significant problems rendering white text on a black background
+ (causing partial pixels to be insufficiently shaded) if the gamma of
+ your monitor has not been compensated for, and minor problems with
+ black text on a while background. The program "xgamma" can be used to
+ set a gamma correction value in the X server's color pallette. Most
+ monitors have a gamma near 2.
+
+ * Note that the Vera family uses minimal delta hinting. Your
+ results on other systems when not used anti-aliased may not be
+ entirely satisfying. We are primarily interested in reports of
+ problems on open source systems implementing Xft2/fontconfig/freetype
+ (which implements antialiasing and hinting adjustements, and
+ sophisticated subpixel decimation on flatpanels). Also, the
+ algorithms used by Xft2 adjust the hints to integer widths and the
+ results are crisper on open source systems than on Windows or
+ MacIntosh.
+
+ * Your fontconfig may (probably does) predate the release of
+ fontconfig 2.2, and you may see artifacts not present when the font is
+ used at very small sizes with hinting enabled. "vc-list -V" can be
+ used to see what version you have installed.
+
+We believe and hope that these fonts will resolve the problems
+reported during beta test. The largest change is the reduction of
+leading (interline spacing), which had annoyed a number of people, and
+reduced Vera's utility for some applcations. The Vera monospace font
+should also now make '0' and 'O' and '1' and 'l' more clearly
+distinguishable.
+
+The version of these fonts is version 1.10. Fontconfig should be
+choosing the new version of the fonts if both the released fonts and
+beta test fonts are installed (though please discard them: they have
+names of form tt20[1-12]gn.ttf). Note that older versions of
+fontconfig sometimes did not rebuild their cache correctly when new
+fonts are installed: please upgrade to fontconfig 2.2. "fc-cache -f"
+can be used to force rebuilding fontconfig's cache files.
+
+If you note problems, please send them to fonts at gnome dot org, with
+exactly which face and size and unicode point you observe the problem
+at. The xfd utility from XFree86 CVS may be useful for this (e.g. "xfd
+-fa sans"). A possibly more useful program to examine fonts at a
+variety of sizes is the "waterfall" program found in Keith Packard's
+CVS.
+
+ $ cvs -d :pserver:anoncvs@keithp.com:/local/src/CVS login
+ Logging in to :pserver:anoncvs@keithp.com:2401/local/src/CVS
+ CVS password: <hit return>
+ $ cvs -d :pserver:anoncvs@keithp.com:/local/src/CVS co waterfall
+ $ cd waterfall
+ $ xmkmf -a
+ $ make
+ # make install
+ # make install.man
+
+Again, please make sure you are running an up-to-date freetype, and
+that you are only examining integer sizes.
+
+Reporting Problems
+==================
+
+Please send problem reports to fonts at gnome org, with the following
+information:
+
+ 1. Version of Freetype, Xft2 and fontconfig
+ 2. Whether TT hinting is being used, or the autohinter
+ 3. Application being used
+ 4. Character/Unicode code point that has problems (if applicable)
+ 5. Version of which operating system
+ 6. Please include a screenshot, when possible.
+
+Please check the fonts list archives before reporting problems to cut
+down on duplication.
diff --git a/client/fonts/VeraMono.ttf b/client/fonts/VeraMono.ttf
new file mode 100644
index 0000000..139f0b4
--- /dev/null
+++ b/client/fonts/VeraMono.ttf
Binary files differ
diff --git a/client/icons/icon_close_commit.png b/client/icons/icon_close_commit.png
new file mode 100644
index 0000000..2da7b33
--- /dev/null
+++ b/client/icons/icon_close_commit.png
Binary files differ
diff --git a/client/icons/icon_close_no_commit.png b/client/icons/icon_close_no_commit.png
new file mode 100644
index 0000000..70e5492
--- /dev/null
+++ b/client/icons/icon_close_no_commit.png
Binary files differ
diff --git a/client/icons/icon_current_sessions.png b/client/icons/icon_current_sessions.png
new file mode 100644
index 0000000..6881af2
--- /dev/null
+++ b/client/icons/icon_current_sessions.png
Binary files differ
diff --git a/client/icons/icon_discard.png b/client/icons/icon_discard.png
new file mode 100644
index 0000000..5cfa574
--- /dev/null
+++ b/client/icons/icon_discard.png
Binary files differ
diff --git a/client/macrowindow.cc b/client/macrowindow.cc
index 98262fd..d9060b0 100644
--- a/client/macrowindow.cc
+++ b/client/macrowindow.cc
@@ -151,11 +151,26 @@ bool MacroWindow::doCommit()
// If all entries passed validation, continue commit
if(faulty == 0) {
- netcom.send(widgets, templ, macro, version);
+ QDomDocument doc = netcom.send(widgets, 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;
+ }
+
emit updateOnCommit();
setCollapsed(true);
return true;
} else {
+ MessageBox::critical(NULL, "Fejl",
+ "Makroen " + macrotitle +
+ " er ikke udfyldt korrekt, prøv igen.\n",
+ MessageBox::Ok);
+
return false;
}
}
@@ -168,13 +183,7 @@ void MacroWindow::close()
void MacroWindow::commit()
{
- if(doCommit()) {
- // close();
- } else {
- MessageBox::critical(NULL, "Fejl",
- "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n",
- MessageBox::Ok);
- }
+ doCommit();
}
void MacroWindow::reset()
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);
diff --git a/client/mainwindow.h b/client/mainwindow.h
index e19b070..afc9d08 100644
--- a/client/mainwindow.h
+++ b/client/mainwindow.h
@@ -31,21 +31,28 @@
#include <QMap>
#include <QVector>
#include <QPushButton>
+#include <QFont>
+
#include "netcom.h"
#include "macrowindow.h"
-
+#include "sessions.h"
#include "macro.h"
class MainWindow : public QMainWindow {
Q_OBJECT
public:
- MainWindow(QString cpr, QString templ, QString host, quint16 port, QString user);
+ MainWindow(QString cpr, QString templ, QString host, quint16 port,
+ QString user);
~MainWindow();
void closeEvent(QCloseEvent *event);
public slots:
void update();
+ void closeCommit();
+ void closeNoCommit();
+ void closeDiscard();
+ void showSessions();
private:
void updateTemplateHeaders(QDomNode templatenode);
@@ -53,6 +60,9 @@ private:
QString templ;
NetCom netcom;
+ QString cpr;
+ QString user;
+
// QMap< QString, MacroWindow* > macros;
Macros macros;
QWidget *w;
@@ -61,7 +71,11 @@ private:
bool initialising;
+ Sessions sessions;
+
void init();
+
+ bool isStored;
};
#endif/*__PRACRO_MAINWINDOW_H__*/
diff --git a/client/netcom.cc b/client/netcom.cc
index 3b3abb7..97f9ee1 100644
--- a/client/netcom.cc
+++ b/client/netcom.cc
@@ -26,64 +26,95 @@
*/
#include "netcom.h"
+#include <QtNetwork>
+
#include <QApplication>
#include <QByteArray>
+#include <QHttp>
+
#include "widgets/widget.h"
-NetCom::NetCom(QString host, quint16 port, QString user, QString cpr)
+#ifdef USE_SSL
+#include <QMessageBox>
+#include <QList>
+#include <QSslError>
+#include <QSslSocket>
+
+#ifdef QT_NO_OPENSSL
+#error "QT not compiled with SSL support."
+#endif
+#endif
+
+NetCom::NetCom(QString host, quint16 port)
{
- this->user = user;
- this->cpr = cpr;
- socket.connectToHost(host, port);
- connect(&socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
- socket.waitForConnected();
- transmitting = false;
+ //
+ // Setup connection
+ //
+ QUrl url;
+ url.setHost(host);
+ url.setPort(port);
+ url.setScheme("http");
+ // url.setScheme("https");
+
+ request.setUrl(url);
+
+ manager = new QNetworkAccessManager(this);
+ connect(manager, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(replyFinished(QNetworkReply*)));
}
NetCom::~NetCom()
{
- socket.disconnectFromHost();
+ //
+ // Clean up
+ //
+ delete manager;
}
-QDomDocument NetCom::send(QString templ, QString macro, bool lockgui)
+void NetCom::replyFinished(QNetworkReply *reply)
+{
+ finished[reply] = true;
+}
+
+QDomDocument NetCom::makeTransfer(QDomDocument &doc,
+ bool commit, bool lockgui, bool discard)
{
- printf("Socket state: %d\n", socket.state());
- if(socket.state() != 3) printf("Socket state not connected: %s\n", socket.errorString().toStdString().c_str());
+ printf("\nMaking transfer:\n%s", doc.toString().toStdString().c_str());
if(lockgui && qApp->activeWindow()) qApp->activeWindow()->setEnabled(false);
if(lockgui) QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
- QDomDocument doc;
-
- QDomProcessingInstruction header = doc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
- doc.appendChild(header);
-
- QDomElement pracro_elem = doc.createElement("pracro");
- pracro_elem.setAttribute("version", "1.0");
- pracro_elem.setAttribute("cpr", cpr);
- pracro_elem.setAttribute("user", user);
- doc.appendChild(pracro_elem);
+ if(sessionid != "") request.setRawHeader("SessionID",
+ sessionid.toStdString().c_str());
+ if(commit) {
+ request.setRawHeader("SessionCommit", "yes");
+ }
- QDomElement request_elem = doc.createElement("request");
- request_elem.setAttribute("template", templ);
- if(macro != "") request_elem.setAttribute("macro", macro);
- pracro_elem.appendChild(request_elem);
-
- printf("\nSending request:\n%s", doc.toString().toStdString().c_str());
+ if(discard) {
+ request.setRawHeader("SessionDiscard", "yes");
+ }
- socket.write(doc.toByteArray());
- // socket.waitForReadyRead();
+ // 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);
- do {
- qApp->processEvents(QEventLoop::WaitForMoreEvents);
- } while(!res_doc.setContent(buffer));
+ QByteArray data = reply->readAll();
+ QDomDocument res_doc;
+ res_doc.setContent(data);
- buffer = "";
+ printf("\nRecieved reponse:\n%s", data.data());
- QDomElement elem = res_doc.documentElement();
+ printf("\nRecieved reponse (Parsed):\n%s", res_doc.toByteArray().data());
- printf("\nRecieved request:\n%s", res_doc.toString().toStdString().c_str());
+ if(reply->hasRawHeader("SessionID")) {
+ sessionid = reply->rawHeader("SessionID");
+ printf("SESSION ID: %s\n", sessionid.toStdString().c_str());
+ }
if(lockgui) QApplication::restoreOverrideCursor();
if(lockgui && qApp->activeWindow()) qApp->activeWindow()->setEnabled(true);
@@ -91,26 +122,58 @@ QDomDocument NetCom::send(QString templ, QString macro, bool lockgui)
return res_doc;
}
-void NetCom::readyRead()
+QDomDocument NetCom::initConnection()
{
- buffer.append(socket.readAll());
+ QDomDocument doc;
+ return makeTransfer(doc, false, true);
}
-void NetCom::send(QVector< Widget* > widgets, QString templ, QString macro, QString version)
+QDomDocument NetCom::commit()
{
- printf("Socket state: %d\n", socket.state());
- if(socket.state() != 3) printf("Socket state not connected: %s\n", socket.errorString().toStdString().c_str());
+ QDomDocument doc;
+ return makeTransfer(doc, true, true);
+}
- // if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(false); // Moved down!
+QDomDocument NetCom::discard()
+{
+ QDomDocument doc;
+ return makeTransfer(doc, false, true, true);
+}
+
+QDomDocument NetCom::send(QString templ, QString macro, bool lockgui)
+{
+ QDomDocument doc;
+
+ QDomProcessingInstruction header =
+ doc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
+ doc.appendChild(header);
+
+ QDomElement pracro_elem = doc.createElement("pracro");
+ pracro_elem.setAttribute("version", "1.0");
+ pracro_elem.setAttribute("cpr", patientid);
+ pracro_elem.setAttribute("user", user);
+ doc.appendChild(pracro_elem);
+
+ QDomElement request_elem = doc.createElement("request");
+ request_elem.setAttribute("template", templ);
+ if(macro != "") request_elem.setAttribute("macro", macro);
+ pracro_elem.appendChild(request_elem);
+
+ return makeTransfer(doc, false, lockgui);
+}
+QDomDocument NetCom::send(QVector< Widget* > widgets, QString templ,
+ QString macro, QString version)
+{
QDomDocument doc;
- QDomProcessingInstruction header = doc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
+ QDomProcessingInstruction header =
+ doc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
doc.appendChild(header);
QDomElement pracro_elem = doc.createElement("pracro");
pracro_elem.setAttribute("version", "1.0");
- pracro_elem.setAttribute("cpr", cpr);
+ pracro_elem.setAttribute("cpr", patientid);
pracro_elem.setAttribute("user", user);
doc.appendChild(pracro_elem);
@@ -120,7 +183,8 @@ void NetCom::send(QVector< Widget* > widgets, QString templ, QString macro, QStr
commit_elem.setAttribute("version", version);
pracro_elem.appendChild(commit_elem);
- // Iterate the different entries, and append their results to the commit string
+ // Iterate the different entries, and append their results to
+ // the commit string
QVector< Widget* >::iterator i = widgets.begin();
while (i != widgets.end()) {
Widget* w = *i;
@@ -134,27 +198,6 @@ void NetCom::send(QVector< Widget* > widgets, QString templ, QString macro, QStr
i++;
}
-
- if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(false);
-
- printf("\nSending commit:\n%s", doc.toString().toStdString().c_str());
-
- socket.write(doc.toByteArray());
- // socket.waitForReadyRead();
-
- //
- // Wait for the (hopefully) empty answer.
- //
- do {
- qApp->processEvents(QEventLoop::WaitForMoreEvents);
- } while(!res_doc.setContent(buffer));
-
- buffer = "";
-
- //QDomElement elem = res_doc.documentElement();
-
- printf("\nRecieved commit:\n%s", res_doc.toString().toStdString().c_str());
-
- QApplication::restoreOverrideCursor();
- if(qApp->activeWindow()) qApp->activeWindow()->setEnabled(true);
+
+ return makeTransfer(doc, false, true);
}
diff --git a/client/netcom.h b/client/netcom.h
index 35db221..88b604e 100644
--- a/client/netcom.h
+++ b/client/netcom.h
@@ -31,6 +31,10 @@
#include <QString>
#include <QTcpSocket>
#include <QDomDocument>
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+
+//#define USE_SSL
//#include "widgets/widget.h"
class Widget;
@@ -38,24 +42,33 @@ class Widget;
class NetCom : public QObject {
Q_OBJECT
public:
- NetCom(QString host, quint16 port, QString user, QString cpr);
+ NetCom(QString host, quint16 port);
~NetCom();
QDomDocument send(QString templ, QString macro = "", bool lockgui = true);
- void send(QVector< Widget* > widgets, QString templ, QString macro, QString version);
+ QDomDocument send(QVector< Widget* > widgets, QString templ, QString macro,
+ QString version);
+ QDomDocument initConnection();
+ QDomDocument commit();
+ QDomDocument discard();
+
+ QString sessionid;
+ QString user;
+ QString patientid;
public slots:
- void readyRead();
+ void replyFinished(QNetworkReply*);
private:
- volatile bool transmitting;
- QTcpSocket socket;
+ QNetworkAccessManager *manager;
+ QNetworkRequest request;
- QByteArray buffer;
- QDomDocument res_doc;
+ // QString sessionid;
- QString user;
- QString cpr;
+ QMap<QNetworkReply *, bool> finished;
+
+ QDomDocument makeTransfer(QDomDocument &dom,
+ bool commit, bool lockgui, bool discard = false);
};
#endif/*__PRACRO_NETCOM_H__*/
diff --git a/client/pracro.cc b/client/pracro.cc
index 37b1399..bb2d952 100644
--- a/client/pracro.cc
+++ b/client/pracro.cc
@@ -34,6 +34,9 @@
#include <QTranslator>
+#include <QFontDatabase>
+#include <QFont>
+
#include "netcom.h"
#include "mainwindow.h"
#include "viewer.h"
@@ -50,6 +53,8 @@ QString config = CONFIG_DEFAULT;
QString host;
quint16 port;
+QFont *fixedfont;
+
static void print_usage()
{
printf("Usage: pracro -m MACRO -c CPR -U USER\n");
@@ -159,6 +164,11 @@ int main(int argc, char *argv[])
app.installTranslator(&translator);
}
+ QFontDatabase fontdb;
+ fontdb.addApplicationFont(":fonts/VeraMono.ttf");
+ QFont f = fontdb.font("Bitstream Vera Sans Mono", "", 8);
+ fixedfont = &f;
+
if(show_editor && show_viewer) {
MainWindow mainwindow(cpr, templ, host, port, user);
mainwindow.show();
diff --git a/client/resumewidget.cc b/client/resumewidget.cc
index ae6bec9..ac18578 100644
--- a/client/resumewidget.cc
+++ b/client/resumewidget.cc
@@ -32,10 +32,14 @@
#include <QTextEdit>
#include <QDialog>
+#include <QFont>
+
#define MAX_COMPACT_SIZE 100
//#define RICH // Experimental syntax highlighter (numbers turn blue)
-//#define FIXED_FONT // Show the resume, using a fixed font.
+#define FIXED_FONT // Show the resume, using a fixed font.
+
+extern QFont *fixedfont; // Defined in pracro.cc
ResumeWidget::ResumeWidget(bool compact)
{
@@ -79,24 +83,6 @@ static QString reformatString(QString help)
return output;
}
-#define LONGLINE 100
-static size_t countLongLines(QString str)
-{
- str += "\n"; // Make sure we end at a newline.
- size_t n = 0;
- size_t len = 0;
- for(size_t i = 0; i < (size_t)str.length(); i++) {
- if(str[i] != '\n') {
- len++;
- } else {
- n += len / LONGLINE;
- len = 0;
- }
- }
-
- return n;
-}
-
void ResumeWidget::setText(QString text)
{
QString f;
@@ -104,9 +90,7 @@ void ResumeWidget::setText(QString text)
fulltext = text;
#ifdef FIXED_FONT
- QFont font = resume->font();
- font.setFamily("Courier New");
- resume->setFont(font);
+ resume->setFont(*fixedfont);
#endif
#ifdef RICH
@@ -135,8 +119,7 @@ void ResumeWidget::setText(QString text)
//resume->setWhatsThis(fulltext); // Only set tooltip if resume has actually been cut off.
}
}
- size_t n = countLongLines(f);
- for(size_t i = 0; i < n; i++) f.append('\n');
+
resume->setText(f);
}
diff --git a/client/sessions.cc b/client/sessions.cc
new file mode 100644
index 0000000..d663b65
--- /dev/null
+++ b/client/sessions.cc
@@ -0,0 +1,119 @@
+/* -*- 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();
+}
diff --git a/client/sessions.h b/client/sessions.h
new file mode 100644
index 0000000..b42d27b
--- /dev/null
+++ b/client/sessions.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * sessions.h
+ *
+ * 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.
+ */
+#ifndef __PRACRO_SESSIONS_H__
+#define __PRACRO_SESSIONS_H__
+
+#include <QMap>
+#include <QString>
+#include <QVariant>
+
+//typedef QMap<QString, QList<QString> > Sessions;
+
+class Sessions {
+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;
+};
+
+#endif/*__PRACRO_SESSIONS_H__*/
diff --git a/client/viewer.cc b/client/viewer.cc
index 09b6e47..c4bd3f5 100644
--- a/client/viewer.cc
+++ b/client/viewer.cc
@@ -81,7 +81,12 @@ Viewer::Viewer(QString cpr, QString templs, QString host, quint16 port,
this->templs = templs.split(QRegExp("\\W+"), QString::SkipEmptyParts);
connect(&updatetimer, SIGNAL(timeout()), this, SLOT(update()));
- netcom = new NetCom(host, port, user, cpr);
+ netcom = new NetCom(host, port);
+ netcom->user = user;
+ netcom->patientid = cpr;
+ netcom->sessionid = "";
+ netcom->initConnection();
+
host = host; port = port; user = user;
this->cpr = cpr;
this->journalpath = journalpath;
@@ -109,6 +114,8 @@ Viewer::Viewer(QString cpr, QString templs, QString host, quint16 port,
Viewer::~Viewer()
{
+ updatetimer.stop();
+ netcom->discard(); // Make sure sessionid is removed.
delete netcom;
delete journal;
}