Replace old drag&drop with new UI
Showing the changes to interface/src/Application.cpp (1 of 6 files). Show all
Unified · Split
| @@ -158,7 +158,6 @@ · 157 unmodified lines | |||
| 158 | #include "Stars.h" | 158 | #include "Stars.h" |
| 159 | #include "ui/AddressBarDialog.h" | 159 | #include "ui/AddressBarDialog.h" |
| 160 | #include "ui/AvatarInputs.h" | 160 | #include "ui/AvatarInputs.h" |
| 161 | #include "ui/AssetUploadDialogFactory.h" | ||
| 162 | #include "ui/DialogsManager.h" | 161 | #include "ui/DialogsManager.h" |
| 163 | #include "ui/LoginDialog.h" | 162 | #include "ui/LoginDialog.h" |
| 164 | #include "ui/overlays/Cube3DOverlay.h" | 163 | #include "ui/overlays/Cube3DOverlay.h" |
| @@ -3978,9 +3977,6 @@ void Application::nodeAdded(SharedNodePointer node) { · 3813 unmodified lines | |||
| 3978 | if (node->getType() == NodeType::AvatarMixer) { | 3977 | if (node->getType() == NodeType::AvatarMixer) { |
| 3979 | // new avatar mixer, send off our identity packet right away | 3978 | // new avatar mixer, send off our identity packet right away |
| 3980 | getMyAvatar()->sendIdentityPacket(); | 3979 | getMyAvatar()->sendIdentityPacket(); |
| 3981 | } else if (node->getType() == NodeType::AssetServer) { | ||
| 3982 | // the addition of an asset-server always re-enables the upload to asset server menu option | ||
| 3983 | Menu::getInstance()->getActionForOption(MenuOption::UploadAsset)->setEnabled(true); | ||
| 3984 | } | 3980 | } |
| 3985 | } | 3981 | } |
| 3986 | 3982 | ||
| @@ -4030,10 +4026,6 @@ void Application::nodeKilled(SharedNodePointer node) { · 43 unmodified lines | |||
| 4030 | } else if (node->getType() == NodeType::AvatarMixer) { | 4026 | } else if (node->getType() == NodeType::AvatarMixer) { |
| 4031 | // our avatar mixer has gone away - clear the hash of avatars | 4027 | // our avatar mixer has gone away - clear the hash of avatars |
| 4032 | DependencyManager::get<AvatarManager>()->clearOtherAvatars(); | 4028 | DependencyManager::get<AvatarManager>()->clearOtherAvatars(); |
| 4033 | } else if (node->getType() == NodeType::AssetServer | ||
| 4034 | && !DependencyManager::get<NodeList>()->soloNodeOfType(NodeType::AssetServer)) { | ||
| 4035 | // this was our last asset server - disable the menu option to upload an asset | ||
| 4036 | Menu::getInstance()->getActionForOption(MenuOption::UploadAsset)->setEnabled(false); | ||
| 4037 | } | 4029 | } |
| 4038 | } | 4030 | } |
| 4039 | void Application::trackIncomingOctreePacket(ReceivedMessage& message, SharedNodePointer sendingNode, bool wasStatsPacket) { | 4031 | void Application::trackIncomingOctreePacket(ReceivedMessage& message, SharedNodePointer sendingNode, bool wasStatsPacket) { |
| @@ -4259,7 +4251,10 @@ bool Application::acceptURL(const QString& urlString, bool defaultUpload) { · 219 unmodified lines | |||
| 4259 | } | 4251 | } |
| 4260 | } | 4252 | } |
| 4261 | 4253 | ||
| 4262 | return defaultUpload && askToUploadAsset(urlString); | 4254 | if (defaultUpload) { |
| 4255 | toggleAssetServerWidget(urlString); | ||
| 4256 | } | ||
| 4257 | return defaultUpload; | ||
| 4263 | } | 4258 | } |
| 4264 | 4259 | ||
| 4265 | void Application::setSessionUUID(const QUuid& sessionUUID) { | 4260 | void Application::setSessionUUID(const QUuid& sessionUUID) { |
| @@ -4321,80 +4316,6 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { · 55 unmodified lines | |||
| 4321 | return true; | 4316 | return true; |
| 4322 | } | 4317 | } |
| 4323 | 4318 | ||
| 4324 | bool Application::askToUploadAsset(const QString& filename) { | ||
| 4325 | if (!DependencyManager::get<NodeList>()->getThisNodeCanRez()) { | ||
| 4326 | OffscreenUi::warning(_window, "Failed Upload", | ||
| 4327 | QString("You don't have upload rights on that domain.\n\n")); | ||
| 4328 | return false; | ||
| 4329 | } | ||
| 4330 | |||
| 4331 | QUrl url { filename }; | ||
| 4332 | if (auto upload = DependencyManager::get<AssetClient>()->createUpload(url.toLocalFile())) { | ||
| 4333 | |||
| 4334 | QMessageBox messageBox; | ||
| 4335 | messageBox.setWindowTitle("Asset upload"); | ||
| 4336 | messageBox.setText("You are about to upload the following file to the asset server:\n" + | ||
| 4337 | url.toDisplayString()); | ||
| 4338 | messageBox.setInformativeText("Do you want to continue?"); | ||
| 4339 | messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); | ||
| 4340 | messageBox.setDefaultButton(QMessageBox::Ok); | ||
| 4341 | |||
| 4342 | // Option to drop model in world for models | ||
| 4343 | if (filename.endsWith(FBX_EXTENSION, Qt::CaseInsensitive) || filename.endsWith(OBJ_EXTENSION, Qt::CaseInsensitive)) { | ||
| 4344 | auto checkBox = new QCheckBox(&messageBox); | ||
| 4345 | checkBox->setText("Add to scene"); | ||
| 4346 | messageBox.setCheckBox(checkBox); | ||
| 4347 | } | ||
| 4348 | |||
| 4349 | if (messageBox.exec() != QMessageBox::Ok) { | ||
| 4350 | upload->deleteLater(); | ||
| 4351 | return false; | ||
| 4352 | } | ||
| 4353 | |||
| 4354 | // connect to the finished signal so we know when the AssetUpload is done | ||
| 4355 | if (messageBox.checkBox() && (messageBox.checkBox()->checkState() == Qt::Checked)) { | ||
| 4356 | // Custom behavior for models | ||
| 4357 | QObject::connect(upload, &AssetUpload::finished, this, &Application::modelUploadFinished); | ||
| 4358 | } else { | ||
| 4359 | QObject::connect(upload, &AssetUpload::finished, | ||
| 4360 | &AssetUploadDialogFactory::getInstance(), | ||
| 4361 | &AssetUploadDialogFactory::handleUploadFinished); | ||
| 4362 | } | ||
| 4363 | |||
| 4364 | // start the upload now | ||
| 4365 | upload->start(); | ||
| 4366 | return true; | ||
| 4367 | } | ||
| 4368 | |||
| 4369 | // display a message box with the error | ||
| 4370 | OffscreenUi::warning(_window, "Failed Upload", QString("Failed to upload %1.\n\n").arg(filename)); | ||
| 4371 | return false; | ||
| 4372 | } | ||
| 4373 | |||
| 4374 | void Application::modelUploadFinished(AssetUpload* upload, const QString& hash) { | ||
| 4375 | auto fileInfo = QFileInfo(upload->getFilename()); | ||
| 4376 | auto filename = fileInfo.fileName(); | ||
| 4377 | |||
| 4378 | if ((upload->getError() == AssetUpload::NoError) && | ||
| 4379 | (filename.endsWith(FBX_EXTENSION, Qt::CaseInsensitive) || | ||
| 4380 | filename.endsWith(OBJ_EXTENSION, Qt::CaseInsensitive))) { | ||
| 4381 | |||
| 4382 | auto entities = DependencyManager::get<EntityScriptingInterface>(); | ||
| 4383 | |||
| 4384 | EntityItemProperties properties; | ||
| 4385 | properties.setType(EntityTypes::Model); | ||
| 4386 | properties.setModelURL(QString("%1:%2.%3").arg(URL_SCHEME_ATP).arg(hash).arg(fileInfo.completeSuffix())); | ||
| 4387 | properties.setPosition(_myCamera.getPosition() + _myCamera.getOrientation() * Vectors::FRONT * 2.0f); | ||
| 4388 | properties.setName(QUrl(upload->getFilename()).fileName()); | ||
| 4389 | |||
| 4390 | entities->addEntity(properties); | ||
| 4391 | |||
| 4392 | upload->deleteLater(); | ||
| 4393 | } else { | ||
| 4394 | AssetUploadDialogFactory::getInstance().handleUploadFinished(upload, hash); | ||
| 4395 | } | ||
| 4396 | } | ||
| 4397 | |||
| 4398 | bool Application::askToWearAvatarAttachmentUrl(const QString& url) { | 4319 | bool Application::askToWearAvatarAttachmentUrl(const QString& url) { |
| 4399 | 4320 | ||
| 4400 | QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); | 4321 | QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); |
| @@ -4494,9 +4415,12 @@ void Application::toggleRunningScriptsWidget() { · 93 unmodified lines | |||
| 4494 | //} | 4415 | //} |
| 4495 | } | 4416 | } |
| 4496 | 4417 | ||
| 4497 | void Application::toggleAssetServerWidget() { | 4418 | void Application::toggleAssetServerWidget(QString filePath) { |
| 4498 | static const QUrl url("AssetServer.qml"); | 4419 | static const QUrl url("AssetServer.qml"); |
| 4499 | DependencyManager::get<OffscreenUi>()->show(url, "AssetServer"); | 4420 | auto urlSetter = [=](QQmlContext* context, QObject* newObject){ |
| 4421 | newObject->setProperty("currentFileUrl", filePath); | ||
| 4422 | }; | ||
| 4423 | DependencyManager::get<OffscreenUi>()->show(url, "AssetServer", urlSetter); | ||
| 4500 | } | 4424 | } |
| 4501 | 4425 | ||
| 4502 | void Application::packageModel() { | 4426 | void Application::packageModel() { |