Browse Source

Default to loading the UI off the interwebz

at the cost of a lot of upfront import ".." lines leading to the dir containing qmldir
Donald Carr 6 years ago
parent
commit
c9f200d14c

+ 1 - 1
qml/main.qml

@@ -88,7 +88,7 @@ Item {
 
         property string effect: ""
         property string artView: "Trivial"
-        property string backdrop: ""
+        property string backdrop: "Cells"
 
         property bool smoothArt: false
         property bool randomlyMirrorArt: false

+ 1 - 0
qml/qmldir

@@ -7,6 +7,7 @@ ArtBoxBody 1.0 physics/ArtBoxBody.qml
 RectangleBoxBody 1.0 physics/RectangleBoxBody.qml
 BoxBody 1.0 physics/BoxBody.qml
 FPS 1.0 widgets/FPS.qml
+Widget 1.0 widgets/Widget.qml
 Clock 1.0 widgets/Clock.qml
 Resolution 1.0 widgets/Resolution.qml
 CollectionSize 1.0 widgets/CollectionSize.qml

+ 3 - 0
qml/widgets/Clock.qml

@@ -1,5 +1,8 @@
 import QtQuick 2.6
 
+// Required for effortless web serving!
+import ".."
+
 Widget {
     id: root
 

+ 3 - 0
qml/widgets/CollectionSize.qml

@@ -1,5 +1,8 @@
 import QtQuick 2.6
 
+// Required for effortless web serving!
+import ".."
+
 Widget {
     text: "DB:" + nativeUtils.imageCollection.count
 }

+ 3 - 0
qml/widgets/FPS.qml

@@ -3,6 +3,9 @@ import QtQuick 2.0
 // pretty much entirely stolen from:
 // https://github.com/capisce/motionblur/blob/master/main.qml
 
+// Required for effortless web serving!
+import ".."
+
 Widget {
     property real t
     property int frame: 0

+ 3 - 0
qml/widgets/InfoTray.qml

@@ -1,5 +1,8 @@
 import QtQuick 2.6
 
+// Required for effortless web serving!
+import ".."
+
 Item {
     width: childrenRect.width
     height: childrenRect.height

+ 3 - 0
qml/widgets/ItemCount.qml

@@ -1,5 +1,8 @@
 import QtQuick 2.6
 
+// Required for effortless web serving!
+import ".."
+
 Widget {
     text: "Items:" + globalUtil.itemCount
 }

+ 3 - 0
qml/widgets/RebootReq.qml

@@ -1,5 +1,8 @@
 import QtQuick 2.5
 
+// Required for effortless web serving!
+import ".."
+
 Image {
   visible: nativeUtils.rebootRequired
   source: "qrc:///buuf/Free Your Mind.png"

+ 3 - 0
qml/widgets/Resolution.qml

@@ -1,5 +1,8 @@
 import QtQuick 2.6
 
+// Required for effortless web serving!
+import ".."
+
 Widget {
     text: appWindow.width + "x" + appWindow.height
 }

+ 3 - 0
qml/widgets/Widget.qml

@@ -1,5 +1,8 @@
 import QtQuick 2.6
 
+// Required for effortless web serving!
+import ".."
+
 Item {
     width: childrenRect.width
     height: childrenRect.height

+ 38 - 16
src/main.cpp

@@ -102,33 +102,45 @@ void NativeUtils::monitorRunPath(const QString &path)
 
 class ArtView {
 public:
-    static void populateScreen(QScreen *screen = nullptr);
+    ArtView(QScreen *screen = nullptr);
 private:
+    QString localPath;
+    QString webPath;
+    QQuickView *view;
     static QQmlEngine* sharedQmlEngine;
+    bool prioritizeRemoteCopy;
 };
 
 QQmlEngine* ArtView::sharedQmlEngine = nullptr;
 
-void ArtView::populateScreen(QScreen *screen)
+ArtView::ArtView(QScreen *screen)
 {
-    static QString qmlPath;
+    QSettings settings;
+
+    prioritizeRemoteCopy = settings.value("prioritizeRemoteServer", true).toBool();
+
+    // "http://localhost:8000/qml"
+    // "https://raw.githubusercontent.com/sirspudd/artriculate/master/qml";
+    webPath = settings.value("server", "https://raw.githubusercontent.com/sirspudd/artriculate/master/qml").toString();
+
 #ifdef COMPILED_RESOURCES
-    qmlPath = "qrc:/qml";
+    localPath = "qrc:/qml";
 #else
     if (QCoreApplication::applicationDirPath().startsWith("/usr")) {
-        qmlPath = "/usr/share/" % qApp->applicationName() % "/qml";
+        localPath = "/usr/share/" % qApp->applicationName() % "/qml";
     } else {
-        qmlPath = QString("%1%2").arg(ORIGINAL_SOURCE_PATH).arg("/../qml");
+        localPath = QString("%1%2").arg(ORIGINAL_SOURCE_PATH).arg("/../qml");
     }
 #endif
 
-    QQuickView *view;
     if (sharedQmlEngine) {
         view = new QQuickView(sharedQmlEngine, nullptr);
     } else {
         view = new QQuickView();
+
         sharedQmlEngine = view->engine();
-        sharedQmlEngine->addImportPath(qmlPath);
+        // Seems academic given QML files still need to explicitly import ".." the topmost qmldir
+        sharedQmlEngine->addImportPath(webPath);
         sharedQmlEngine->rootContext()->setContextProperty("nativeUtils", new NativeUtils(sharedQmlEngine));
         QObject::connect(sharedQmlEngine, &QQmlEngine::quit, qApp, &QCoreApplication::quit);
     }
@@ -137,7 +149,6 @@ void ArtView::populateScreen(QScreen *screen)
     } else {
         screen = view->screen();
     }
-    QSettings settings;
     QRect geometry = screen->availableGeometry();
     bool transparentToplevel = settings.value("transparentToplevel", false).toBool();
     settings.setValue("transparentToplevel", transparentToplevel);
@@ -147,13 +158,24 @@ void ArtView::populateScreen(QScreen *screen)
         view->setColor(Qt::black);
     }
     view->setResizeMode(QQuickView::SizeRootObjectToView);
-    view->setSource(QUrl(qmlPath + "/main.qml"));
+    view->setSource(QUrl(webPath + "/main.qml"));
+
+    // Does the same thing as showFullScreen for broken backends which dont impl showFS
     view->setGeometry(geometry);
+    // Ideally bypasses compositing
     view->showFullScreen();
 
-    QObject::connect(view, &QQuickView::statusChanged, [](QQuickView::Status status) {
+    QObject::connect(view, &QQuickView::statusChanged, [this](QQuickView::Status status) {
         if (status == QQuickView::Error) {
-            QMetaObject::invokeMethod(qApp, "quit", Qt::QueuedConnection);
+            if (prioritizeRemoteCopy) {
+                prioritizeRemoteCopy = false;
+                qDebug() << "Failed to load qml from:" << webPath;
+                qDebug() << "Attemping local copy!:" << localPath;
+                sharedQmlEngine->addImportPath(localPath);
+                QMetaObject::invokeMethod(view, "setSource", Qt::QueuedConnection, QGenericReturnArgument(), Q_ARG(QUrl, QUrl(localPath + "/main.qml")));
+            } else {
+                QMetaObject::invokeMethod(qApp, "quit", Qt::QueuedConnection);
+            }
         }
     });
 
@@ -245,16 +267,16 @@ int main(int argc, char *argv[])
     QList<QScreen*> screens = QGuiApplication::screens();
 
     if (screenIndex == -2) {
-        ArtView::populateScreen();
+        new ArtView();
     } else if (screenIndex == -1) {
         foreach(QScreen *screen, screens) {
-            ArtView::populateScreen(screen);
+            new ArtView(screen);
         }
     } else {
         if ((screenIndex >= 0) && (screenIndex < screens.length())) {
-            ArtView::populateScreen(screens.at(screenIndex));
+            new ArtView(screens.at(screenIndex));
         } else {
-            ArtView::populateScreen();
+            new ArtView();
         }
     }
     settings.setValue("screenIndex", screenIndex);