From e85459df34dfee960cbff303a8d4dccb60708845 Mon Sep 17 00:00:00 2001
From: Lucio Zambon <lucio.zambon@elettra.eu>
Date: Tue, 14 Jul 2020 10:19:02 +0200
Subject: [PATCH] Add new file

---
 src/main.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 src/main.cpp

diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..a984d92
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,80 @@
+/***************************************************************************
+ *   Copyright (C) 2006 by LZ   *
+ *      *
+ *                                                                         *
+ *   This program 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.                                   *
+ *                                                                         *
+ *   This program 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 this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+
+#include <TApplication>
+#include "hv.h"
+#include <X11/Xlib.h>
+#include <QX11Info>
+#include <tutil.h>
+#include <QMessageBox>
+
+int main( int argc, char ** argv ) {
+	TApplication a( argc, argv );
+	TUtil::instance()->setLoggingTarget(argv[0]);
+	if (argc < 2) {
+		QMessageBox::information(0, "Error in startup parameters",
+		QString("Error starting the program \"%1\"\nUsage:\n"
+			"%1 modulator_number\n"
+			"modulator_number: [1|2]\n").arg(
+				argv[0]).arg(argv[0]));
+		exit(EXIT_FAILURE);
+	}
+	/*
+		Rewrite parameters passed from command line. This is due to an unfair
+		constraint which limit the command line parameters to any Tango device
+		i.e. you can use parameters to connect a panel to whichever device
+		regardless of any assumption done by widgets in panel, but you cannot
+		pass any other type of parameter for whichever pursue it can be usefull.
+		The trick used here is to parse the appropriate command line parameters
+		and rewrite them in order to satisfy the completely misconceived
+		assumptions done by the method replaceWildcards()
+	*/
+	QString paramString;
+	if (!strcmp(argv[1], "1")) {
+		paramString = "p/mod/ross_p1 p/mod/hv_p1 p/mod/general_p1 booster/interlock/mod1";
+	}
+	else if (!strcmp(argv[1], "2")) {
+		paramString = "p/mod/ross_p2 p/mod/hv_p2 p/mod/general_p2 booster/interlock/mod2";
+	}
+	else if (!strcmp(argv[1], "10")) {
+		paramString = "f/mod/ross_f10 f/mod/hv_f10 f/mod/general_f10 f/mod/intlk_f10";
+	}
+	else {
+		QMessageBox::information(0, "Error in startup parameters",
+		QString("Error starting the program \"%1 %2\"\nUsage:\n"
+			"%1 modulator_number\n"
+			"modulator_number: [1|2]\n").arg(
+				argv[0]).arg(argv[1]));
+		exit(EXIT_FAILURE);
+	}
+	QStringList paramArray = paramString.split(" ");
+	hv mw;
+	// TUtil::replaceWildcards(mw.children(), a.arguments());
+	TUtil::replaceWildcards(mw.children(), paramArray);
+	mw.setWindowTitle(QString("Mod %1 HV").arg(qApp->arguments().at(1)));
+	mw.show();
+
+	/* register to window manager */
+	Display *disp = QX11Info::display();
+	Window root_win = (Window) mw.winId();
+	XSetCommand(disp, root_win, QApplication::argv(), QApplication::argc());
+	return a.exec();
+}
-- 
GitLab