Showing the changes to interface/src/ModelUploader.cpp (1 of 2 files). Show all
Unified · Split
| @@ -34,6 +34,7 @@ static const QString TEXDIR_FIELD = "texdir"; · 33 unmodified lines | |||
| 34 | static const QString LOD_FIELD = "lod"; | 34 | static const QString LOD_FIELD = "lod"; |
| 35 | 35 | ||
| 36 | static const QString S3_URL = "http://highfidelity-public.s3-us-west-1.amazonaws.com"; | 36 | static const QString S3_URL = "http://highfidelity-public.s3-us-west-1.amazonaws.com"; |
| 37 | static const QString DATA_SERVER_URL = "https://data-web.highfidelity.io"; | ||
| 37 | static const QString MODEL_URL = "/api/v1/models"; | 38 | static const QString MODEL_URL = "/api/v1/models"; |
| 38 | 39 | ||
| 39 | static const QString SETTING_NAME = "LastModelUploadLocation"; | 40 | static const QString SETTING_NAME = "LastModelUploadLocation"; |
| @@ -201,14 +202,14 @@ void ModelUploader::send() { · 161 unmodified lines | |||
| 201 | 202 | ||
| 202 | JSONCallbackParameters callbackParams; | 203 | JSONCallbackParameters callbackParams; |
| 203 | callbackParams.jsonCallbackReceiver = this; | 204 | callbackParams.jsonCallbackReceiver = this; |
| 204 | callbackParams.jsonCallbackMethod = "uploadSuccess"; | 205 | callbackParams.jsonCallbackMethod = "checkJSON"; |
| 205 | callbackParams.errorCallbackReceiver = this; | 206 | callbackParams.errorCallbackReceiver = this; |
| 206 | callbackParams.errorCallbackMethod = "uploadFailed"; | 207 | callbackParams.errorCallbackMethod = "uploadFailed"; |
| 207 | callbackParams.updateReciever = this; | ||
| 208 | callbackParams.updateSlot = SLOT(uploadUpdate(qint64, qint64)); | ||
| 209 | 208 | ||
| 210 | AccountManager::getInstance().authenticatedRequest(MODEL_URL, QNetworkAccessManager::PostOperation, callbackParams, QByteArray(), _dataMultiPart); | 209 | AccountManager::getInstance().authenticatedRequest(MODEL_URL + "/" + QFileInfo(_url).baseName(), |
| 211 | _dataMultiPart = NULL; | 210 | QNetworkAccessManager::GetOperation, |
| 211 | callbackParams); | ||
| 212 | |||
| 212 | qDebug() << "Sending model..."; | 213 | qDebug() << "Sending model..."; |
| 213 | _progressDialog = new QDialog(); | 214 | _progressDialog = new QDialog(); |
| 214 | _progressBar = new QProgressBar(_progressDialog); | 215 | _progressBar = new QProgressBar(_progressDialog); |
| @@ -226,6 +227,61 @@ void ModelUploader::send() { · 11 unmodified lines | |||
| 226 | _progressBar = NULL; | 227 | _progressBar = NULL; |
| 227 | } | 228 | } |
| 228 | 229 | ||
| 230 | void ModelUploader::checkJSON(const QJsonObject& jsonResponse) { | ||
| 231 | if (jsonResponse.contains("status") && jsonResponse.value("status").toString() == "success") { | ||
| 232 | qDebug() << "status : success"; | ||
| 233 | JSONCallbackParameters callbackParams; | ||
| 234 | callbackParams.jsonCallbackReceiver = this; | ||
| 235 | callbackParams.jsonCallbackMethod = "uploadSuccess"; | ||
| 236 | callbackParams.errorCallbackReceiver = this; | ||
| 237 | callbackParams.errorCallbackMethod = "uploadFailed"; | ||
| 238 | callbackParams.updateReciever = this; | ||
| 239 | callbackParams.updateSlot = SLOT(uploadUpdate(qint64, qint64)); | ||
| 240 | |||
| 241 | if (jsonResponse.contains("exists") && jsonResponse.value("exists").toString() == "true") { | ||
| 242 | qDebug() << "exists : true"; | ||
| 243 | if (jsonResponse.contains("can_update") && jsonResponse.value("can_update").toString() == "true") { | ||
| 244 | qDebug() << "can_update : true"; | ||
| 245 | |||
| 246 | AccountManager::getInstance().authenticatedRequest(MODEL_URL + "/" + QFileInfo(_url).baseName(), | ||
| 247 | QNetworkAccessManager::PutOperation, | ||
| 248 | callbackParams, | ||
| 249 | QByteArray(), | ||
| 250 | _dataMultiPart); | ||
| 251 | _dataMultiPart = NULL; | ||
| 252 | } else { | ||
| 253 | qDebug() << "can_update : false"; | ||
| 254 | if (_progressDialog) { | ||
| 255 | _progressDialog->reject(); | ||
| 256 | } | ||
| 257 | QMessageBox::warning(NULL, | ||
| 258 | QString("ModelUploader::checkJSON()"), | ||
| 259 | QString("This model already exist and is own by someone else."), | ||
| 260 | QMessageBox::Ok); | ||
| 261 | deleteLater(); | ||
| 262 | } | ||
| 263 | } else { | ||
| 264 | qDebug() << "exists : false"; | ||
| 265 | AccountManager::getInstance().authenticatedRequest(MODEL_URL, | ||
| 266 | QNetworkAccessManager::PostOperation, | ||
| 267 | callbackParams, | ||
| 268 | QByteArray(), | ||
| 269 | _dataMultiPart); | ||
| 270 | _dataMultiPart = NULL; | ||
| 271 | } | ||
| 272 | } else { | ||
| 273 | qDebug() << "status : failed"; | ||
| 274 | if (_progressDialog) { | ||
| 275 | _progressDialog->reject(); | ||
| 276 | } | ||
| 277 | QMessageBox::warning(NULL, | ||
| 278 | QString("ModelUploader::checkJSON()"), | ||
| 279 | QString("Something went wrong with the data-server."), | ||
| 280 | QMessageBox::Ok); | ||
| 281 | deleteLater(); | ||
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 229 | void ModelUploader::uploadUpdate(qint64 bytesSent, qint64 bytesTotal) { | 285 | void ModelUploader::uploadUpdate(qint64 bytesSent, qint64 bytesTotal) { |
| 230 | if (_progressDialog) { | 286 | if (_progressDialog) { |
| 231 | _progressBar->setRange(0, bytesTotal); | 287 | _progressBar->setRange(0, bytesTotal); |
| @@ -249,11 +305,11 @@ void ModelUploader::uploadFailed(QNetworkReply::NetworkError errorCode, const QS · 17 unmodified lines | |||
| 249 | if (_progressDialog) { | 305 | if (_progressDialog) { |
| 250 | _progressDialog->reject(); | 306 | _progressDialog->reject(); |
| 251 | } | 307 | } |
| 308 | qDebug() << "Model upload failed (" << errorCode << "): " << errorString; | ||
| 252 | QMessageBox::warning(NULL, | 309 | QMessageBox::warning(NULL, |
| 253 | QString("ModelUploader::uploadFailed()"), | 310 | QString("ModelUploader::uploadFailed()"), |
| 254 | QString("There was a problem with your upload, please try again later."), | 311 | QString("There was a problem with your upload, please try again later."), |
| 255 | QMessageBox::Ok); | 312 | QMessageBox::Ok); |
| 256 | qDebug() << "Model upload failed (" << errorCode << "): " << errorString; | ||
| 257 | deleteLater(); | 313 | deleteLater(); |
| 258 | } | 314 | } |
| 259 | 315 | ||