changeset 43:4aea515b404f

Query plugin info from RDF
author Chris Cannam
date Tue, 21 Jan 2020 14:26:13 +0000
parents 37d79024d966
children 8dbbd57a9395
files installer.cpp installer.pro noconfig.pri repoint-lock.json repoint-project.json
diffstat 5 files changed, 157 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/installer.cpp	Mon Jan 20 14:22:24 2020 +0000
+++ b/installer.cpp	Tue Jan 21 14:26:13 2020 +0000
@@ -12,8 +12,14 @@
 
 #include <vamp-hostsdk/PluginHostAdapter.h>
 
+#include <dataquay/BasicStore.h>
+#include <dataquay/RDFException.h>
+
 #include <iostream>
+#include <set>
+
 using namespace std;
+using namespace Dataquay;
 
 QString
 getDefaultInstallDirectory()
@@ -42,6 +48,114 @@
     return entries;
 }
 
+unique_ptr<BasicStore>
+loadLibrariesRdf()
+{
+    QDir dir(":out/");
+    auto entries = dir.entryList({ "*.ttl", "*.n3" });
+
+    unique_ptr<BasicStore> store(new BasicStore);
+
+    for (auto e: entries) {
+
+        QFile f(":out/" + e);
+        if (!f.open(QFile::ReadOnly | QFile::Text)) {
+            cerr << "Failed to open RDF resource file "
+                 << e.toStdString() << endl;
+            continue;
+        }
+
+        QByteArray content = f.readAll();
+        f.close();
+
+        try {
+            store->importString(QString::fromUtf8(content), 
+                                Uri("file:" + e),
+                                BasicStore::ImportIgnoreDuplicates);
+        } catch (const RDFException &ex) {
+            cerr << "Failed to import RDF resource file "
+                 << e.toStdString() << ": " << ex.what() << endl;
+        }
+    }
+
+    return store;
+}
+
+struct LibraryInfo {
+    QString id;
+    QString fileName;
+    QString title;
+    QString maker;
+    QString description;
+};
+
+vector<LibraryInfo>
+getLibraryInfo(const Store &store, QStringList libraries)
+{
+    /* e.g.
+
+       plugbase:library a vamp:PluginLibrary ;
+       vamp:identifier "qm-vamp-plugins" ; 
+       dc:title "Queen Mary plugin set"
+    */
+
+    Triples tt = store.match(Triple(Node(),
+                                    Uri("a"),
+                                    store.expand("vamp:PluginLibrary")));
+
+    std::map<QString, QString> wanted; // basename -> full lib name
+    for (auto lib: libraries) {
+        wanted[QFileInfo(lib).baseName()] = lib;
+    }
+    
+    vector<LibraryInfo> results;
+    
+    for (auto t: tt) {
+
+        Node libId = store.complete(Triple(t.subject(),
+                                           store.expand("vamp:identifier"),
+                                           Node()));
+        if (libId.type != Node::Literal) {
+            continue;
+        }
+        auto wi = wanted.find(libId.value);
+        if (wi == wanted.end()) {
+            continue;
+        }
+        
+        LibraryInfo info;
+        info.id = wi->first;
+        info.fileName = wi->second;
+        
+        Node title = store.complete(Triple(t.subject(),
+                                           store.expand("dc:title"),
+                                           Node()));
+        if (title.type == Node::Literal) {
+            info.title = title.value;
+        } else {
+            info.title = info.id;
+        }
+        
+        Node maker = store.complete(Triple(t.subject(),
+                                           store.expand("foaf:maker"),
+                                           Node()));
+        if (maker.type == Node::Literal) {
+            info.maker = maker.value;
+        }
+
+        Node desc = store.complete(Triple(t.subject(),
+                                          store.expand("dc:description"),
+                                          Node()));
+        if (desc.type == Node::Literal) {
+            info.description = desc.value;
+        }
+
+        results.push_back(info);
+    }
+
+    return results;
+}
+
 void
 installLibrary(QString library, QString target)
 {
@@ -66,17 +180,23 @@
 }
 
 QStringList
-getUserApprovedPluginLibraries(QStringList libraries)
+getUserApprovedPluginLibraries(vector<LibraryInfo> libraries)
 {
     QDialog dialog;
     auto layout = new QVBoxLayout;
 
-    std::map<QString, QCheckBox *> checkBoxMap;
+    map<QString, QCheckBox *> checkBoxMap;
+
+    map<QString, LibraryInfo> orderedInfo;
+    for (auto info: libraries) {
+        orderedInfo[info.title] = info;
+    }
     
-    for (auto lib: libraries) {
-        auto cb = new QCheckBox(lib);
+    for (auto ip: orderedInfo) {
+        LibraryInfo info = ip.second;
+        auto cb = new QCheckBox(info.title);
         layout->addWidget(cb);
-        checkBoxMap[lib] = cb;
+        checkBoxMap[info.fileName] = cb;
     }
 
     auto bb = new QDialogButtonBox(QDialogButtonBox::Ok |
@@ -114,7 +234,11 @@
 
     QStringList libraries = getPluginLibraryList();
 
-    QStringList toInstall = getUserApprovedPluginLibraries(libraries);
+    auto rdfStore = loadLibrariesRdf();
+
+    auto info = getLibraryInfo(*rdfStore, libraries);
+    
+    QStringList toInstall = getUserApprovedPluginLibraries(info);
     
     for (auto lib: toInstall) {
         installLibrary(lib, target);
--- a/installer.pro	Mon Jan 20 14:22:24 2020 +0000
+++ b/installer.pro	Tue Jan 21 14:26:13 2020 +0000
@@ -61,10 +61,25 @@
         vamp-plugin-sdk/src/vamp-hostsdk/PluginWrapper.cpp \
         vamp-plugin-sdk/src/vamp-hostsdk/RealTime.cpp
 
+DATAQUAY_SOURCES=$$fromfile(dataquay/lib.pro, SOURCES)
+DATAQUAY_HEADERS=$$fromfile(dataquay/lib.pro, HEADERS)
+
+for (file, DATAQUAY_SOURCES) { SOURCES += $$sprintf("dataquay/%1", $$file) }
+for (file, DATAQUAY_HEADERS) { HEADERS += $$sprintf("dataquay/%1", $$file) }
+
+DEFINES += HAVE_SORD HAVE_SERD USE_SORD NDEBUG
+
 linux* {
-   LIBS += -ldl
+    QMAKE_CXXFLAGS += -I/usr/include/sord-0 -I/usr/include/serd-0
+    LIBS += -lsord-0 -lserd-0 -ldl
 }
 
 macx* {
+    LIBS += -lsord-0 -lserd-0
     QMAKE_POST_LINK += deploy/osx/deploy.sh $$shell_quote($$TARGET)
 }
+
+win32* {
+    LIBS += -lsord -lserd
+}
+    
--- a/noconfig.pri	Mon Jan 20 14:22:24 2020 +0000
+++ b/noconfig.pri	Tue Jan 21 14:26:13 2020 +0000
@@ -5,7 +5,7 @@
 
 PREFIX_PATH = /usr/local
 
-INCLUDEPATH += $$PWD/vamp-plugin-sdk
+INCLUDEPATH += $$PWD/vamp-plugin-sdk $$PWD/dataquay $$PWD/dataquay/dataquay
 
 win32-msvc* {
 
--- a/repoint-lock.json	Mon Jan 20 14:22:24 2020 +0000
+++ b/repoint-lock.json	Tue Jan 21 14:26:13 2020 +0000
@@ -3,14 +3,17 @@
     "vamp-plugin-sdk": {
       "pin": "c42e50a5c297"
     },
+    "dataquay": {
+      "pin": "c523464d1466"
+    },
     "icons/scalable": {
       "pin": "be45984f7915"
     },
     "qm-vamp-plugins": {
-      "pin": "7aa2536321769ece0873c072200b8183c899c924"
+      "pin": "b1aeb4d87b85c27a221aa2cfc436aea24eedf6d4"
     },
     "qm-vamp-plugins/lib/qm-dsp": {
-      "pin": "6bc10532c581a14bd26361249789100e771638cf"
+      "pin": "4d2a4a4e0c2dd0ddf07bf9d2a224ded912712714"
     },
     "constant-q-cpp": {
       "pin": "88464ef869d9473a22d9d5f2d23e27ba33591440"
--- a/repoint-project.json	Mon Jan 20 14:22:24 2020 +0000
+++ b/repoint-project.json	Tue Jan 21 14:26:13 2020 +0000
@@ -18,6 +18,11 @@
             "vcs": "hg",
             "service": "soundsoftware"
         },
+        "dataquay": {
+            "vcs": "hg",
+            "service": "sourcehut",
+            "owner": "breakfastquay"
+        },
         "icons/scalable": {
             "vcs": "hg",
 	    "service": "soundsoftware",