summaryrefslogtreecommitdiff
path: root/client/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/main.cc')
-rw-r--r--client/main.cc94
1 files changed, 92 insertions, 2 deletions
diff --git a/client/main.cc b/client/main.cc
index ca0d2c1..21e934f 100644
--- a/client/main.cc
+++ b/client/main.cc
@@ -28,10 +28,53 @@
#include <QApplication>
#include <QObject>
#include <QEvent>
+#include <QStringList>
+#include <QSettings>
#include "macro.h"
-QString cpr;
-QString user;
+#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[])
{
@@ -40,6 +83,45 @@ int main(int argc, char *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] = "";
@@ -107,6 +189,14 @@ int main(int argc, char *argv[])
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);