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 | // nothing to be implemented | 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 | QUrl url = formatURLQuery(keyword, category, format); | 59 | QUrl url = formatURLQuery(keyword, category, format); |
| 41 | if (!url.isEmpty()) { | 60 | if (!url.isEmpty()) { |
| 61 | //QJsonArray json = parseJSON(url, 0).toJsonArray(); | ||
| 62 | //qCDebug(scriptengine) << "first asset name: " << json.at(0).toObject().value("displayName"); | ||
| 42 | QJsonArray json = parseJSON(url, 0).toJsonArray(); | 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 | return json; | 65 | return json; |
| 45 | } else { | 66 | } else { |
| 46 | qCDebug(scriptengine) << "Invalid filters were specified."; | 67 | qCDebug(scriptengine) << "Invalid filters were specified."; |
| 47 | return QJsonArray(); | 68 | return QJsonArray(); |
| 69 | //return ""; | ||
| 48 | } | 70 | } |
| 49 | } | 71 | }*/ |
| 50 | 72 | ||
| 51 | QString GooglePolyScriptingInterface::getFBX(QString keyword, QString category) { | 73 | QString GooglePolyScriptingInterface::getFBX(QString keyword, QString category) { |
| 52 | QUrl url = formatURLQuery(keyword, category, "FBX"); | 74 | QUrl url = formatURLQuery(keyword, category, "FBX"); |
| @@ -60,7 +82,16 @@ QString GooglePolyScriptingInterface::getOBJ(QString keyword, QString category) · 7 unmodified lines | |||
| 60 | 82 | ||
| 61 | QString GooglePolyScriptingInterface::getBlocks(QString keyword, QString category) { | 83 | QString GooglePolyScriptingInterface::getBlocks(QString keyword, QString category) { |
| 62 | QUrl url = formatURLQuery(keyword, category, "BLOCKS"); | 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 | return getModelURL(url); | 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 | // can provide asset name or full URL to model | 106 | // can provide asset name or full URL to model |
| 76 | QString GooglePolyScriptingInterface::getModelInfo(QString name) { | 107 | QString GooglePolyScriptingInterface::getModelInfo(QString name) { |
| 77 | if (name.contains("poly.googleapis")) { | 108 | if (name.contains("poly.googleapis") || name.contains("poly.google.com")) { |
| 78 | QStringList list = name.split("/"); | 109 | QStringList list = name.split("/"); |
| 79 | name = list[4]; | 110 | name = list[4]; |
| 80 | } | 111 | } |
| 81 | QString urlString = QString(getPolyUrl); | 112 | QString urlString = QString(getPolyUrl); |
| 82 | urlString = urlString.replace("model", name) + "key=" + authCode; | 113 | urlString = urlString.replace("model", name) + "key=" + authCode; |
| 83 | qCDebug(scriptengine) << "google get url: " << urlString; | 114 | qCDebug(scriptengine) << "Google URL request: " << urlString; |
| 84 | QUrl url(urlString); | 115 | QUrl url(urlString); |
| 85 | QByteArray json = parseJSON(url, 2).toByteArray(); | 116 | QString json = parseJSON(url, 2).toString(); |
| 86 | return json; | 117 | return json; |
| 87 | } | 118 | } |
| 88 | 119 | ||
| @@ -90,10 +121,6 @@ void GooglePolyScriptingInterface::testPrint(QString input) { · 1 unmodified line | |||
| 90 | qCDebug(scriptengine) << "Google message: " << input; | 121 | qCDebug(scriptengine) << "Google message: " << input; |
| 91 | } | 122 | } |
| 92 | 123 | ||
| 93 | void GooglePolyScriptingInterface::setAPIKey(QString key) { | ||
| 94 | authCode = key; | ||
| 95 | } | ||
| 96 | |||
| 97 | int GooglePolyScriptingInterface::getRandIntInRange(int length) { | 124 | int GooglePolyScriptingInterface::getRandIntInRange(int length) { |
| 98 | QTime time = QTime::currentTime(); | 125 | QTime time = QTime::currentTime(); |
| 99 | qsrand((uint)time.msec()); | 126 | qsrand((uint)time.msec()); |
| @@ -121,7 +148,7 @@ QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString categ · 21 unmodified lines | |||
| 121 | } | 148 | } |
| 122 | 149 | ||
| 123 | QString GooglePolyScriptingInterface::getModelURL(QUrl url) { | 150 | QString GooglePolyScriptingInterface::getModelURL(QUrl url) { |
| 124 | qCDebug(scriptengine) << "Google url request: " << url; | 151 | qCDebug(scriptengine) << "Google URL request: " << url; |
| 125 | if (!url.isEmpty()) { | 152 | if (!url.isEmpty()) { |
| 126 | return parseJSON(url, 1).toString(); | 153 | return parseJSON(url, 1).toString(); |
| 127 | } else { | 154 | } else { |
| @@ -150,9 +177,8 @@ QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) { · 22 unmodified lines | |||
| 150 | if (obj.keys().first() == "error") { | 177 | if (obj.keys().first() == "error") { |
| 151 | QString error = obj.value("error").toObject().value("message").toString(); | 178 | QString error = obj.value("error").toObject().value("message").toString(); |
| 152 | qCDebug(scriptengine) << error; | 179 | qCDebug(scriptengine) << error; |
| 153 | return QJsonObject(); | 180 | return ""; |
| 154 | } | 181 | } |
| 155 | qCDebug(scriptengine) << "the assets: " << obj.value("assets"); | ||
| 156 | if (fileType == 0 || fileType == 1) { | 182 | if (fileType == 0 || fileType == 1) { |
| 157 | QJsonArray arr = obj.value("assets").toArray(); | 183 | QJsonArray arr = obj.value("assets").toArray(); |
| 158 | // return model url | 184 | // return model url |
| @@ -163,11 +189,10 @@ QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) { · 4 unmodified lines | |||
| 163 | return json.value("formats").toArray().at(0).toObject().value("root").toObject().value("url"); | 189 | return json.value("formats").toArray().at(0).toObject().value("root").toObject().value("url"); |
| 164 | } | 190 | } |
| 165 | // return whole asset list | 191 | // return whole asset list |
| 166 | return arr; | 192 | //return arr; |
| 193 | return QJsonDocument(arr); | ||
| 167 | // return specific object | 194 | // return specific object |
| 168 | } else { | 195 | } else { |
| 169 | //return obj; | ||
| 170 | //return doc.toJson(); | ||
| 171 | return jsonString; | 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 | qCDebug(scriptengine) << "first item: " << firstItem; | 294 | qCDebug(scriptengine) << "first item: " << firstItem; |
| 270 | } | 295 | } |
| 271 | 296 | ||
| 272 | <<<<<<< HEAD | ||
| 273 | */ | 297 | */ |