Showing the changes to interface/src/scripting/GooglePolyScriptingInterface.cpp (1 of 2 files). Show all
Unified · Split
| @@ -36,17 +36,39 @@ GooglePolyScriptingInterface::GooglePolyScriptingInterface() { · 35 unmodified lines | ||
| 36 | 36 | // nothing to be implemented |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | −QJsonArray GooglePolyScriptingInterface::getAssetList(QString keyword, QString category, QString format) { | |
| 39 | +void GooglePolyScriptingInterface::setAPIKey(QString key) { | |
| 40 | + authCode = key; | |
| 41 | +} | |
| 42 | + | |
| 43 | +QByteArray GooglePolyScriptingInterface::getAssetList(QString keyword, QString category, QString format) { | |
| 44 | + QUrl url = formatURLQuery(keyword, category, format); | |
| 45 | + if (!url.isEmpty()) { | |
| 46 | + //QJsonArray json = parseJSON(url, 0).toJsonArray(); | |
| 47 | + //qCDebug(scriptengine) << "first asset name: " << json.at(0).toObject().value("displayName"); | |
| 48 | + QByteArray json = parseJSON(url, 0).toJsonDocument().toJson(); | |
| 49 | + qCDebug(scriptengine) << "asset list as string is: " << json; | |
| 50 | + return json; | |
| 51 | + } else { | |
| 52 | + qCDebug(scriptengine) << "Invalid filters were specified."; | |
| 53 | + //return QJsonArray(); | |
| 54 | + return ""; | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 58 | +/*QJsonArray GooglePolyScriptingInterface::getAssetList(QString keyword, QString category, QString format) { | |
| 40 | 59 | QUrl url = formatURLQuery(keyword, category, format); |
| 41 | 60 | if (!url.isEmpty()) { |
| 61 | + //QJsonArray json = parseJSON(url, 0).toJsonArray(); | |
| 62 | + //qCDebug(scriptengine) << "first asset name: " << json.at(0).toObject().value("displayName"); | |
| 42 | 63 | QJsonArray json = parseJSON(url, 0).toJsonArray(); |
| 43 | − qCDebug(scriptengine) << "first asset name: " << json.at(0).toObject().value("displayName"); | |
| 64 | + qCDebug(scriptengine) << "asset list as array is: " << json; | |
| 44 | 65 | return json; |
| 45 | 66 | } else { |
| 46 | 67 | qCDebug(scriptengine) << "Invalid filters were specified."; |
| 47 | 68 | return QJsonArray(); |
| 69 | + //return ""; | |
| 48 | 70 | } |
| 49 | −} | |
| 71 | +}*/ | |
| 50 | 72 | |
| 51 | 73 | QString GooglePolyScriptingInterface::getFBX(QString keyword, QString category) { |
| 52 | 74 | QUrl url = formatURLQuery(keyword, category, "FBX"); |
| @@ -60,7 +82,16 @@ QString GooglePolyScriptingInterface::getOBJ(QString keyword, QString category) · 7 unmodified lines | ||
| 60 | 82 | |
| 61 | 83 | QString GooglePolyScriptingInterface::getBlocks(QString keyword, QString category) { |
| 62 | 84 | QUrl url = formatURLQuery(keyword, category, "BLOCKS"); |
| 63 | − qCDebug(scriptengine) << "Google url request: " << url; | |
| 85 | + return getModelURL(url); | |
| 86 | +} | |
| 87 | + | |
| 88 | +QString GooglePolyScriptingInterface::getGLTF(QString keyword, QString category) { | |
| 89 | + QUrl url = formatURLQuery(keyword, category, "GLTF"); | |
| 90 | + return getModelURL(url); | |
| 91 | +} | |
| 92 | + | |
| 93 | +QString GooglePolyScriptingInterface::getGLTF2(QString keyword, QString category) { | |
| 94 | + QUrl url = formatURLQuery(keyword, category, "GLTF2"); | |
| 64 | 95 | return getModelURL(url); |
| 65 | 96 | } |
| 66 | 97 | |
| @@ -74,15 +105,15 @@ QString GooglePolyScriptingInterface::getTilt(QString keyword, QString category) · 7 unmodified lines | ||
| 74 | 105 | |
| 75 | 106 | // can provide asset name or full URL to model |
| 76 | 107 | QString GooglePolyScriptingInterface::getModelInfo(QString name) { |
| 77 | − if (name.contains("poly.googleapis")) { | |
| 108 | + if (name.contains("poly.googleapis") || name.contains("poly.google.com")) { | |
| 78 | 109 | QStringList list = name.split("/"); |
| 79 | 110 | name = list[4]; |
| 80 | 111 | } |
| 81 | 112 | QString urlString = QString(getPolyUrl); |
| 82 | 113 | urlString = urlString.replace("model", name) + "key=" + authCode; |
| 83 | − qCDebug(scriptengine) << "google get url: " << urlString; | |
| 114 | + qCDebug(scriptengine) << "Google URL request: " << urlString; | |
| 84 | 115 | QUrl url(urlString); |
| 85 | − QByteArray json = parseJSON(url, 2).toByteArray(); | |
| 116 | + QString json = parseJSON(url, 2).toString(); | |
| 86 | 117 | return json; |
| 87 | 118 | } |
| 88 | 119 | |
| @@ -90,10 +121,6 @@ void GooglePolyScriptingInterface::testPrint(QString input) { · 1 unmodified line | ||
| 90 | 121 | qCDebug(scriptengine) << "Google message: " << input; |
| 91 | 122 | } |
| 92 | 123 | |
| 93 | −void GooglePolyScriptingInterface::setAPIKey(QString key) { | |
| 94 | − authCode = key; | |
| 95 | −} | |
| 96 | − | |
| 97 | 124 | int GooglePolyScriptingInterface::getRandIntInRange(int length) { |
| 98 | 125 | QTime time = QTime::currentTime(); |
| 99 | 126 | qsrand((uint)time.msec()); |
| @@ -121,7 +148,7 @@ QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString categ · 21 unmodified lines | ||
| 121 | 148 | } |
| 122 | 149 | |
| 123 | 150 | QString GooglePolyScriptingInterface::getModelURL(QUrl url) { |
| 124 | − qCDebug(scriptengine) << "Google url request: " << url; | |
| 151 | + qCDebug(scriptengine) << "Google URL request: " << url; | |
| 125 | 152 | if (!url.isEmpty()) { |
| 126 | 153 | return parseJSON(url, 1).toString(); |
| 127 | 154 | } else { |
| @@ -150,9 +177,8 @@ QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) { · 22 unmodified lines | ||
| 150 | 177 | if (obj.keys().first() == "error") { |
| 151 | 178 | QString error = obj.value("error").toObject().value("message").toString(); |
| 152 | 179 | qCDebug(scriptengine) << error; |
| 153 | − return QJsonObject(); | |
| 180 | + return ""; | |
| 154 | 181 | } |
| 155 | − qCDebug(scriptengine) << "the assets: " << obj.value("assets"); | |
| 156 | 182 | if (fileType == 0 || fileType == 1) { |
| 157 | 183 | QJsonArray arr = obj.value("assets").toArray(); |
| 158 | 184 | // return model url |
| @@ -163,11 +189,10 @@ QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) { · 4 unmodified lines | ||
| 163 | 189 | return json.value("formats").toArray().at(0).toObject().value("root").toObject().value("url"); |
| 164 | 190 | } |
| 165 | 191 | // return whole asset list |
| 166 | − return arr; | |
| 192 | + //return arr; | |
| 193 | + return QJsonDocument(arr); | |
| 167 | 194 | // return specific object |
| 168 | 195 | } else { |
| 169 | − //return obj; | |
| 170 | − //return doc.toJson(); | |
| 171 | 196 | return jsonString; |
| 172 | 197 | } |
| 173 | 198 | } |
| @@ -269,5 +294,4 @@ or this :(( http://blog.mathieu-leplatre.info/access-a-json-webservice-with-qt-c · 95 unmodified lines | ||
| 269 | 294 | qCDebug(scriptengine) << "first item: " << firstItem; |
| 270 | 295 | } |
| 271 | 296 | |
| 272 | −<<<<<<< HEAD | |
| 273 | 297 | */ |