diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/builder.cc | 42 | ||||
| -rw-r--r-- | client/builder.h | 11 | ||||
| -rw-r--r-- | client/client.pro | 19 | ||||
| -rw-r--r-- | client/macro.cc | 117 | ||||
| -rw-r--r-- | client/macro.h | 12 | ||||
| -rw-r--r-- | client/main.cc | 205 | ||||
| -rw-r--r-- | client/widgets.h | 44 | 
7 files changed, 167 insertions, 283 deletions
| diff --git a/client/builder.cc b/client/builder.cc index f8addeb..bdbb85b 100644 --- a/client/builder.cc +++ b/client/builder.cc @@ -1,18 +1,32 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            builder.cc + * + *  Fri Aug 31 12:27:45 CEST 2007 + *  Copyright 2007 Lars Bisballe Jensen and Bent Bisballe Nyeng + *  elsenator@gmail.com and 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 "builder.h"  #include "sendrecieve.h" -#include "widgets/widget.h" -#include "widgets/label.h" -#include "widgets/lineedit.h" -#include "widgets/textedit.h" -#include "widgets/pushbutton.h" -#include "widgets/combobox.h" -#include "widgets/listbox.h" -#include "widgets/frame.h" -#include "widgets/groupbox.h" -#include "widgets/radiobuttons.h" -#include "widgets/radiobutton.h" -#include "widgets/checkbox.h" -#include "widgets/window.h" +#include "widgets.h"  #include "macro.h"  #include <QVBoxLayout>  #include <QMessageBox> @@ -218,7 +232,7 @@ void Builder::cont(QString name)      i++;    }    if(doCommit()) { -    new_macro(macro); +    new_macro("FIXME", macro);      mainwidget->close();    } else {     QMessageBox::critical(NULL, "Fejl", diff --git a/client/builder.h b/client/builder.h index 1fbbb86..b7f6fb1 100644 --- a/client/builder.h +++ b/client/builder.h @@ -3,8 +3,8 @@   *            builder.h   *   *  Fri Aug 31 12:27:45 CEST 2007 - *  Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup - *  deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk + *  Copyright 2007 Lars Bisballe Jensen and Bent Bisballe Nyeng + *  elsenator@gmail.com and deva@aasimon.org   ****************************************************************************/  /* @@ -24,9 +24,8 @@   *  along with Pracro; if not, write to the Free Software   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.   */ - -#ifndef _BUILDER_H -#define _BUILDER_H +#ifndef __PRACRO_BUILDER_H__ +#define __PRACRO_BUILDER_H__  #include "widgets/widget.h"  #include <QDomDocument> @@ -59,4 +58,4 @@ private:  }; -#endif +#endif/*__PRACRO_BUILDER_H__*/ diff --git a/client/client.pro b/client/client.pro index 3ab8855..5e15f48 100644 --- a/client/client.pro +++ b/client/client.pro @@ -4,10 +4,15 @@  TEMPLATE = app  TARGET = pracro -DEPENDPATH += . _old widgets -INCLUDEPATH += . _old widgets +DEPENDPATH += . widgets +INCLUDEPATH += . widgets +QT += core gui network xml -HEADERS += sendrecieve.h macro.h builder.h \ +HEADERS += \ +        builder.h \ +        macro.h \ +        sendrecieve.h \ +        widgets.h \  	widgets/widget.h \  	widgets/label.h \  	widgets/lineedit.h \ @@ -21,7 +26,12 @@ HEADERS += sendrecieve.h macro.h builder.h \  	widgets/radiobuttons.h \  	widgets/checkbox.h \  	widgets/window.h -SOURCES += main.cc sendrecieve.cc macro.cc builder.cc \ + +SOURCES += \ +        pracro.cc \ +        builder.cc \ +        macro.cc \ +        sendrecieve.cc \          widgets/widget.cc \          widgets/label.cc \          widgets/lineedit.cc \ @@ -35,7 +45,6 @@ SOURCES += main.cc sendrecieve.cc macro.cc builder.cc \          widgets/radiobuttons.cc \          widgets/checkbox.cc \          widgets/window.cc -QT += core gui network xml  win32 {  	DEFINES += HOST_WIN32 diff --git a/client/macro.cc b/client/macro.cc index 7f8ea27..82c68a4 100644 --- a/client/macro.cc +++ b/client/macro.cc @@ -3,8 +3,8 @@   *            macro.cc   *   *  Fri Aug 31 13:40:17 CEST 2007 - *  Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup - *  deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk + *  Copyright 2007 Bent Bisballe Nyeng and Lars Bisballe Jensen + *  deva@aasimon.org and elsenator@gmail.com   ****************************************************************************/  /* @@ -30,28 +30,78 @@  #include <QDomDocument>  #include <QApplication> -#define MY_EVENT_ID 65432 +#define MACRO_EVENT_ID 65432  extern QString cpr;  extern QString user;  extern QString host;  extern quint16 port; -class MyEvent : public QEvent { +/** + * Macro Event used to trigger the creation of a new macro + */ +class MacroEvent : public QEvent {  public: -  MyEvent(QString macro) : QEvent((QEvent::Type)MY_EVENT_ID) -  { -    this->macro = macro; -  } +  MacroEvent(QString course, QString macro) : +    QEvent((QEvent::Type)MACRO_EVENT_ID), +    macro(macro), +    course(course) {}    QString macro; +  QString course; +}; + +/** + * Macro Event Filter used to catch the Macro Events. + */ +class MacroEventFilter : public QObject { +protected: +  bool eventFilter( QObject *o, QEvent *e );  }; -static QDomDocument xml_request(QString name); +/** + * The single global macro event filter. + * It is created the first time new_macro is called. + */ +MacroEventFilter *macro_event_filter = NULL; + +/** + * This function sends a request to the praco server, and returns the + * parsed answer. + */ +static QDomDocument xml_request(QString course, QString macro) +{ +  // Create the xml request array +  QByteArray xml_array; +  printf("course: %s, macro: %s, cpr: %s, user: %s\n", +         course.toStdString().c_str(), +         macro.toStdString().c_str(), +         cpr.toStdString().c_str(), +         user.toStdString().c_str()); +  xml_array.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); +  xml_array.append("<pracro version=\"1.0\" cpr=\"" + cpr + "\" user=\"" + user + "\">\n"); +  xml_array.append("  <request course=\"" + course + "\" macro=\"" + macro + "\"/>\n"); +  xml_array.append("</pracro>"); + +  // Print to stdout for debug purposes +  char *test = xml_array.data(); +  printf("%s\n", test); + +  // Parse the XML document using setContent of QDomDocument +  QDomDocument xml_req; +  if (!xml_req.setContent(xml_array)) { +    printf("Error: Invalid XML found in request\n"); +  } + +  return xml_req; +} -void create_macro(QString name) +/** + * Create the new macro + */ +static void create_macro(QString course, QString macro)  {    // Build the XML request -  QDomDocument xml_req = xml_request(name); +  QDomDocument xml_req = xml_request(course, macro);    // Fetch the XML document    SendRecieve xml_acquire(host, port); @@ -70,50 +120,29 @@ void create_macro(QString name)    }    // Initiate the macro builder with the xml document +  // FIXME: This should be done in some other way, to prevent the memory leak.    new Builder(&xml_doc); -  //Builder *builder = new Builder(&xml_doc);  } -bool MyEventHandler::eventFilter( QObject *, QEvent *e ) +bool MacroEventFilter::eventFilter( QObject *, QEvent *e )  { -  if ( e->type() == MY_EVENT_ID ) { -    MyEvent *event = (MyEvent*)e; -    create_macro(event->macro); -    // ... DO SOMETHING WITH EVENT +  if ( e->type() == MACRO_EVENT_ID ) { +    MacroEvent *event = (MacroEvent*)e; +    create_macro(event->course, event->macro);      return TRUE; // eat event    } else { -    // standard event processing      return FALSE;    }  } -void new_macro(QString macro) -{ -  MyEvent *event = new MyEvent(macro); -  qApp->postEvent(qApp, event); -  qApp->processEvents(); /* To prevent QT from closing when -                         no windows are present */ -} - -static QDomDocument xml_request(QString name) +void new_macro(QString course, QString macro)  { -  // Create the xml request array -  QByteArray xml_array; -  printf("macro: %s, cpr: %s, user: %s\n", name.toStdString().c_str(), cpr.toStdString().c_str(), user.toStdString().c_str()); -  xml_array.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); -  xml_array.append("<pracro version=\"1.0\" cpr=\"" + cpr + "\" user=\"" + user + "\">\n"); -  xml_array.append("  <request course=\"example2\" macro=\"" + name + "\"/>\n"); -  xml_array.append("</pracro>"); - -  // Print to stdout for debug purposes -  char *test = xml_array.data(); -  printf("%s\n", test); - -  // Parse the XML document using setContent of QDomDocument -  QDomDocument xml_req; -  if (!xml_req.setContent(xml_array)) { -    printf("Error: Invalid XML found in request\n"); +  if(macro_event_filter == NULL) { +    macro_event_filter = new MacroEventFilter(); +    qApp->installEventFilter( macro_event_filter );    } -  return xml_req; +  MacroEvent *event = new MacroEvent(course, macro); +  qApp->postEvent(qApp, event); +  qApp->processEvents(); // To prevent QT from closing when no windows are present  } diff --git a/client/macro.h b/client/macro.h index 8ddd963..f372762 100644 --- a/client/macro.h +++ b/client/macro.h @@ -3,8 +3,8 @@   *            macro.h   *   *  Fri Aug 31 13:40:17 CEST 2007 - *  Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup - *  deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk + *  Copyright 2007 Bent Bisballe Nyeng and Lars Bisballe Jensen + *  deva@aasimon.org and elsenator@gmail.com   ****************************************************************************/  /* @@ -31,12 +31,6 @@  #include <QObject>  #include <QEvent> -class MyEventHandler : public QObject { -protected: -  bool eventFilter( QObject *o, QEvent *e ); -}; - -//void new_macro(QString name, QString cpr, QString user); -void new_macro(QString name); +void new_macro(QString course, QString name);  #endif/*__PRACRO_MACRO_H__*/ diff --git a/client/main.cc b/client/main.cc deleted file mode 100644 index 21e934f..0000000 --- a/client/main.cc +++ /dev/null @@ -1,205 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - *            main.cc - * - *  Fri Jul 13 12:38:45 CEST 2007 - *  Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup - *  deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk - ****************************************************************************/ - -/* - *  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 <QApplication> -#include <QObject> -#include <QEvent> -#include <QStringList> -#include <QSettings> -#include "macro.h" - -#define VERSION "1.0" - -#define CPR_DEFAULT "0000000000" -#define MACRO_DEFAULT "example2" -#define USER_DEFAULT "testuser" -#define CONFIG_DEFAULT "pracro.ini" - -QString macro = MACRO_DEFAULT; -QString cpr = CPR_DEFAULT; -QString user = USER_DEFAULT; -QString config = CONFIG_DEFAULT; -QString host; -quint16 port; - -static void print_usage() -{ -  printf("Usage: pracro -m MACRO -c CPR -U USER\n"); -  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("  -c, --cpr CPR             Defines the cpr for use with the macro,\n" -         "                            defaults to \""CPR_DEFAULT"\".\n"); -  printf("  -C, --config FILE         The configfile to use. Default is \""CONFIG_DEFAULT"\"\n"); -  printf("  -u, --user USER           Defines the requesting user(not the patient),\n" -         "                            defaults to \""USER_DEFAULT"\"\n"); -} - -static void print_version() -{ -  printf("Pracro v"VERSION"\n"); -} - -static QString getParam(QStringList &args, QStringList::iterator &arg) -{ -  arg++; -  if(arg == args.end() || arg->at(0) == '-') { -    print_usage(); -    exit(1); -  } -  return *arg; -} - -int main(int argc, char *argv[]) -{ -  QApplication app(argc, argv); -   -  MyEventHandler *eventhandler = new MyEventHandler(); -  app.installEventFilter( eventhandler ); - -  QStringList args = app.arguments(); -  QStringList::iterator arg = args.begin(); -  arg++; // Skip program name... -  while(arg != args.end()) { -    if(*arg == "--help" || -       *arg == "-h") { -      print_usage(); -    } -    else if(*arg == "--version" || -            *arg == "-v") { -      print_version(); -    } -    else if(*arg == "--user" || -            *arg == "-u") { -      user = getParam(args,arg);  -    } -    else if(*arg == "--macro" || -            *arg == "-m") { -      macro = getParam(args, arg); -    } -    else if(*arg == "--cpr" || -            *arg == "-c") { -      cpr = getParam(args, arg);  -    } -    else if(*arg == "--config" || -            *arg == "-C") { -      config = getParam(args, arg);  -    } -    else { -      print_version(); -      print_usage(); -      return 1; -    } - -    arg++; -  } -     - -#if 0 -  char macro[100] = "start"; -  char _cpr[11] = ""; -  char _user[20] = ""; -  char config[30] = "pracro.ini"; - -  int a; -  for(a=1; a < argc; a++) { -    if(strcmp(argv[a], "-h") == 0 || strcmp(argv[a], "--help") == 0) { -      printf("Usage: pracro -m MACRO -c CPR -U USER\n"); -      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 " -             "Server, defaults to \"example\".\n"); -      printf("  -c, --cpr CPR             Defines the cpr for use with the " -             "macro, defaults to \"0000000000\".\n"); -      printf("  -U, --user USER           Defines the requesting " -             "user(not the patient), defaults to \"testuser\""); -      printf("\n"); -      return 0; -    } -    if(strcmp(argv[a], "-m") == 0 || strcmp(argv[a], "--macro") == 0) { -      if(a+1 == argc || argv[a+1][0] == '-') { -        printf("Missing argument for macro, exiting...\n"); -        exit(1); -      } -      strncpy(macro, argv[a+1], sizeof(macro) - 1); -      a++; -      continue; -    } -    if(strcmp(argv[a], "-c") == 0 || strcmp(argv[a], "--cpr") == 0) { -      if(a+1 == argc || argv[a+1][0] == '-') { -        printf("Missing argument for cpr, exiting...\n"); -        exit(1); -      } -      strncpy(_cpr, argv[a+1], sizeof(_cpr) - 1); -      a++; -      continue; -    } -    if(strcmp(argv[a], "-U") == 0 || strcmp(argv[a], "--user") == 0) { -      if(a+1 == argc || argv[a+1][0] == '-') { -        printf("Missing argument for user, exiting...\n"); -        exit(1); -      } -      strncpy(_user, argv[a+1], sizeof(_user) - 1); -      a++; -      continue; -    } -    if(strcmp(argv[a], "-C") == 0 || strcmp(argv[a], "--config") == 0) { -      if(a+1 == argc || argv[a+1][0] == '-') { -        printf("Missing argument for config, exiting...\n"); -        exit(1); -      } -      strncpy(config, argv[a+1], sizeof(config) - 1); -      a++; -      continue; -    } -  } - -  cpr = _cpr; -  user = _user; - -  if(cpr == "" || user == "") { -    printf("cpr and user not set, exiting...\n"); -    return 1; -  } -#endif/*0*/ - -  QSettings settings(config, QSettings::IniFormat); - -  settings.beginGroup("server"); -  host = settings.value("host").toString(); -  port = settings.value("port").toInt(); -  settings.endGroup(); - -  new_macro(macro); - -  //app.setQuitOnLastWindowClosed(false); -  return app.exec(); -} diff --git a/client/widgets.h b/client/widgets.h new file mode 100644 index 0000000..49dbf72 --- /dev/null +++ b/client/widgets.h @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            widgets.h + * + *  Thu May 29 13:58:01 CEST 2008 + *  Copyright 2008 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_WIDGETS_H__ +#define __PRACRO_WIDGETS_H__ + +#include "widgets/widget.h" +#include "widgets/label.h" +#include "widgets/lineedit.h" +#include "widgets/textedit.h" +#include "widgets/pushbutton.h" +#include "widgets/combobox.h" +#include "widgets/listbox.h" +#include "widgets/frame.h" +#include "widgets/groupbox.h" +#include "widgets/radiobuttons.h" +#include "widgets/radiobutton.h" +#include "widgets/checkbox.h" +#include "widgets/window.h" + +#endif/*__PRACRO_WIDGETS_H__*/ | 
