comparison installer.cpp @ 43:4aea515b404f

Query plugin info from RDF
author Chris Cannam
date Tue, 21 Jan 2020 14:26:13 +0000
parents 37d79024d966
children 6dc29a50b89a
comparison
equal deleted inserted replaced
42:37d79024d966 43:4aea515b404f
10 #include <QCheckBox> 10 #include <QCheckBox>
11 #include <QDialogButtonBox> 11 #include <QDialogButtonBox>
12 12
13 #include <vamp-hostsdk/PluginHostAdapter.h> 13 #include <vamp-hostsdk/PluginHostAdapter.h>
14 14
15 #include <dataquay/BasicStore.h>
16 #include <dataquay/RDFException.h>
17
15 #include <iostream> 18 #include <iostream>
19 #include <set>
20
16 using namespace std; 21 using namespace std;
22 using namespace Dataquay;
17 23
18 QString 24 QString
19 getDefaultInstallDirectory() 25 getDefaultInstallDirectory()
20 { 26 {
21 auto pathList = Vamp::PluginHostAdapter::getPluginPath(); 27 auto pathList = Vamp::PluginHostAdapter::getPluginPath();
38 for (auto e: entries) { 44 for (auto e: entries) {
39 cerr << e.toStdString() << endl; 45 cerr << e.toStdString() << endl;
40 } 46 }
41 47
42 return entries; 48 return entries;
49 }
50
51 unique_ptr<BasicStore>
52 loadLibrariesRdf()
53 {
54 QDir dir(":out/");
55 auto entries = dir.entryList({ "*.ttl", "*.n3" });
56
57 unique_ptr<BasicStore> store(new BasicStore);
58
59 for (auto e: entries) {
60
61 QFile f(":out/" + e);
62 if (!f.open(QFile::ReadOnly | QFile::Text)) {
63 cerr << "Failed to open RDF resource file "
64 << e.toStdString() << endl;
65 continue;
66 }
67
68 QByteArray content = f.readAll();
69 f.close();
70
71 try {
72 store->importString(QString::fromUtf8(content),
73 Uri("file:" + e),
74 BasicStore::ImportIgnoreDuplicates);
75 } catch (const RDFException &ex) {
76 cerr << "Failed to import RDF resource file "
77 << e.toStdString() << ": " << ex.what() << endl;
78 }
79 }
80
81 return store;
82 }
83
84 struct LibraryInfo {
85 QString id;
86 QString fileName;
87 QString title;
88 QString maker;
89 QString description;
90 };
91
92 vector<LibraryInfo>
93 getLibraryInfo(const Store &store, QStringList libraries)
94 {
95 /* e.g.
96
97 plugbase:library a vamp:PluginLibrary ;
98 vamp:identifier "qm-vamp-plugins" ;
99 dc:title "Queen Mary plugin set"
100 */
101
102 Triples tt = store.match(Triple(Node(),
103 Uri("a"),
104 store.expand("vamp:PluginLibrary")));
105
106 std::map<QString, QString> wanted; // basename -> full lib name
107 for (auto lib: libraries) {
108 wanted[QFileInfo(lib).baseName()] = lib;
109 }
110
111 vector<LibraryInfo> results;
112
113 for (auto t: tt) {
114
115 Node libId = store.complete(Triple(t.subject(),
116 store.expand("vamp:identifier"),
117 Node()));
118 if (libId.type != Node::Literal) {
119 continue;
120 }
121 auto wi = wanted.find(libId.value);
122 if (wi == wanted.end()) {
123 continue;
124 }
125
126 LibraryInfo info;
127 info.id = wi->first;
128 info.fileName = wi->second;
129
130 Node title = store.complete(Triple(t.subject(),
131 store.expand("dc:title"),
132 Node()));
133 if (title.type == Node::Literal) {
134 info.title = title.value;
135 } else {
136 info.title = info.id;
137 }
138
139 Node maker = store.complete(Triple(t.subject(),
140 store.expand("foaf:maker"),
141 Node()));
142 if (maker.type == Node::Literal) {
143 info.maker = maker.value;
144 }
145
146 Node desc = store.complete(Triple(t.subject(),
147 store.expand("dc:description"),
148 Node()));
149 if (desc.type == Node::Literal) {
150 info.description = desc.value;
151 }
152
153 results.push_back(info);
154 }
155
156 return results;
43 } 157 }
44 158
45 void 159 void
46 installLibrary(QString library, QString target) 160 installLibrary(QString library, QString target)
47 { 161 {
64 return; 178 return;
65 } 179 }
66 } 180 }
67 181
68 QStringList 182 QStringList
69 getUserApprovedPluginLibraries(QStringList libraries) 183 getUserApprovedPluginLibraries(vector<LibraryInfo> libraries)
70 { 184 {
71 QDialog dialog; 185 QDialog dialog;
72 auto layout = new QVBoxLayout; 186 auto layout = new QVBoxLayout;
73 187
74 std::map<QString, QCheckBox *> checkBoxMap; 188 map<QString, QCheckBox *> checkBoxMap;
75 189
76 for (auto lib: libraries) { 190 map<QString, LibraryInfo> orderedInfo;
77 auto cb = new QCheckBox(lib); 191 for (auto info: libraries) {
192 orderedInfo[info.title] = info;
193 }
194
195 for (auto ip: orderedInfo) {
196 LibraryInfo info = ip.second;
197 auto cb = new QCheckBox(info.title);
78 layout->addWidget(cb); 198 layout->addWidget(cb);
79 checkBoxMap[lib] = cb; 199 checkBoxMap[info.fileName] = cb;
80 } 200 }
81 201
82 auto bb = new QDialogButtonBox(QDialogButtonBox::Ok | 202 auto bb = new QDialogButtonBox(QDialogButtonBox::Ok |
83 QDialogButtonBox::Cancel); 203 QDialogButtonBox::Cancel);
84 layout->addWidget(bb); 204 layout->addWidget(bb);
112 return 1; 232 return 1;
113 } 233 }
114 234
115 QStringList libraries = getPluginLibraryList(); 235 QStringList libraries = getPluginLibraryList();
116 236
117 QStringList toInstall = getUserApprovedPluginLibraries(libraries); 237 auto rdfStore = loadLibrariesRdf();
238
239 auto info = getLibraryInfo(*rdfStore, libraries);
240
241 QStringList toInstall = getUserApprovedPluginLibraries(info);
118 242
119 for (auto lib: toInstall) { 243 for (auto lib: toInstall) {
120 installLibrary(lib, target); 244 installLibrary(lib, target);
121 } 245 }
122 246