[qet] qet/qet: [5826] Try to open a .qet file when double click on it or drop it in the qet icons of the dock in mac osx.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 5826
Author:   blacksun
Date:     2019-04-04 21:27:24 +0200 (Thu, 04 Apr 2019)
Log Message:
-----------
Try to open a .qet file when double click on it or drop it in the qet icons of the dock in mac osx. 

Modified Paths:
--------------
    trunk/sources/main.cpp

Modified: trunk/sources/main.cpp
===================================================================
--- trunk/sources/main.cpp	2019-04-03 18:31:46 UTC (rev 5825)
+++ trunk/sources/main.cpp	2019-04-04 19:27:24 UTC (rev 5826)
@@ -18,7 +18,33 @@
 #include "qetapp.h"
 #include "singleapplication.h"
 #include "qet.h"
+#include <QFileOpenEvent>
 
+class MacOSXOpenEvent : public QObject
+{
+		Q_OBJECT
+
+	public:
+		MacOSXOpenEvent(QObject *parent = nullptr) :
+			QObject(parent)
+		{}
+
+		~MacOSXOpenEvent(){}
+
+		bool eventFilter(QObject *obj, QEvent *event)
+		{
+			if (event->type() == QEvent::FileOpen)
+			{
+				SingleApplication *app = dynamic_cast<SingleApplication *>(obj);
+				QFileOpenEvent *open_event = static_cast<QFileOpenEvent*>(event);
+				QString message = "launched-with-args: " + open_event->file();
+				app->sendMessage(message.toUtf8());
+				return true;
+			}
+			return false;
+		}
+};
+
 /**
  * @brief main
  * Main function of QElectroTech
@@ -41,6 +67,12 @@
 #endif
 	
 	SingleApplication app(argc, argv, true);
+#ifdef Q_OS_MACOS
+		//Handle the opening of QET when user double click on a .qet .elmt .tbt file
+		//or drop these same files to the QET icon of the dock
+	MacOSXOpenEvent open_event;
+	app.installEventFilter(open_event);
+#endif
 	
 	if (app.isSecondary())
 	{
@@ -59,3 +91,4 @@
 	
 	return app.exec();
 }
+


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/