cleanup file loading, this codepath can be used to load url schemes
authorkoda
Sun, 10 Mar 2013 02:32:25 +0100
changeset 8710 8d0a150d42c2
parent 8709 191bd86f97a1
child 8711 053560e0075f
cleanup file loading, this codepath can be used to load url schemes
QTfrontend/HWApplication.cpp
--- a/QTfrontend/HWApplication.cpp	Sun Mar 10 01:27:48 2013 +0100
+++ b/QTfrontend/HWApplication.cpp	Sun Mar 10 02:32:25 2013 +0100
@@ -20,6 +20,8 @@
 #include <QFileOpenEvent>
 
 #include "hwform.h"
+#include "MessageDialog.h"
+
 
 #if !defined(Q_WS_WIN)
 void terminateFrontend(int signal)
@@ -35,23 +37,35 @@
 #if !defined(Q_WS_WIN)
     signal(SIGINT, &terminateFrontend);
 #endif
+#if 0
+    qDebug("%s called with", argv[0]);
+    for (int i = 1; i < argc; i++)
+        qDebug("%d: %s", i, argv[i]);
+#endif
 }
 
 bool HWApplication::event(QEvent *event)
 {
     QFileOpenEvent *openEvent;
+    QString scheme, path;
 
-    switch (event->type())
-    {
-        case QEvent::FileOpen:
-            openEvent = (QFileOpenEvent *)event;
-            if (form) form->PlayDemoQuick(openEvent->file());
+    if (event->type() == QEvent::FileOpen) {
+        openEvent = (QFileOpenEvent *)event;
+        scheme = openEvent->url().scheme();
+        path = openEvent->url().path();
+
+        QFile file(path);
+        if (scheme == "file" && file.exists()) {
+            form->PlayDemoQuick(openEvent->file());
             return true;
-            break;
-        default:
-            return QApplication::event(event);
-            break;
-    }
+        } else {
+            const QString errmsg = tr("Not yet implemented").arg(path);
+            MessageDialog::ShowErrorMessage(errmsg, form);
+            return false;
+        }
+     }
+
+    return QApplication::event(event);
 }