Add missing files for review
Signed-off-by: AMZN-Phil <pconroy@amazon.com>monroegm-disable-blank-issue-2
parent
02364b869e
commit
023e8fcff2
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <O3DEObjectDownloadController.h>
|
||||
#include <O3DEObjectDownloadWorker.h>
|
||||
#include <ProjectButtonWidget.h>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
|
||||
|
||||
namespace O3DE::ProjectManager
|
||||
{
|
||||
O3DEObjectDownloadController::O3DEObjectDownloadController(QWidget* parent)
|
||||
: QObject()
|
||||
, m_lastProgress(0)
|
||||
, m_parent(parent)
|
||||
{
|
||||
m_worker = new O3DEObjectDownloadWorker();
|
||||
m_worker->moveToThread(&m_workerThread);
|
||||
|
||||
connect(&m_workerThread, &QThread::started, m_worker, &O3DEObjectDownloadWorker::StartDownload);
|
||||
connect(m_worker, &O3DEObjectDownloadWorker::Done, this, &O3DEObjectDownloadController::HandleResults);
|
||||
connect(m_worker, &O3DEObjectDownloadWorker::UpdateProgress, this, &O3DEObjectDownloadController::UpdateUIProgress);
|
||||
connect(this, &O3DEObjectDownloadController::StartGemDownload, m_worker, &O3DEObjectDownloadWorker::StartDownload);
|
||||
}
|
||||
|
||||
O3DEObjectDownloadController::~O3DEObjectDownloadController()
|
||||
{
|
||||
connect(&m_workerThread, &QThread::finished, m_worker, &O3DEObjectDownloadWorker::deleteLater);
|
||||
m_workerThread.requestInterruption();
|
||||
m_workerThread.quit();
|
||||
m_workerThread.wait();
|
||||
}
|
||||
|
||||
void O3DEObjectDownloadController::AddGemDownload(const QString& gemName)
|
||||
{
|
||||
m_gemNames.push_back(gemName);
|
||||
if (m_gemNames.size() == 1)
|
||||
{
|
||||
m_worker->SetGemToDownload(m_gemNames[0], false);
|
||||
m_workerThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
void O3DEObjectDownloadController::Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void O3DEObjectDownloadController::UpdateUIProgress(int progress)
|
||||
{
|
||||
m_lastProgress = progress;
|
||||
emit GemDownloadProgress(progress);
|
||||
}
|
||||
|
||||
void O3DEObjectDownloadController::HandleResults(const QString& result)
|
||||
{
|
||||
bool succeeded = true;
|
||||
|
||||
if (!result.isEmpty())
|
||||
{
|
||||
QMessageBox::critical(nullptr, tr("Gem download"), result);
|
||||
succeeded = false;
|
||||
}
|
||||
|
||||
m_gemNames.erase(m_gemNames.begin());
|
||||
emit Done(succeeded);
|
||||
|
||||
if (!m_gemNames.empty())
|
||||
{
|
||||
emit StartGemDownload(m_gemNames[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_workerThread.quit();
|
||||
m_workerThread.wait();
|
||||
}
|
||||
}
|
||||
|
||||
void O3DEObjectDownloadController::HandleCancel()
|
||||
{
|
||||
m_workerThread.quit();
|
||||
emit Done(false);
|
||||
}
|
||||
} // namespace O3DE::ProjectManager
|
||||
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <QString>
|
||||
#include <QThread>
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
#endif
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QProcess)
|
||||
|
||||
namespace O3DE::ProjectManager
|
||||
{
|
||||
QT_FORWARD_DECLARE_CLASS(O3DEObjectDownloadWorker)
|
||||
|
||||
class O3DEObjectDownloadController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit O3DEObjectDownloadController(QWidget* parent = nullptr);
|
||||
~O3DEObjectDownloadController();
|
||||
|
||||
void AddGemDownload(const QString& m_gemName);
|
||||
|
||||
bool IsDownloadQueueEmpty()
|
||||
{
|
||||
return m_gemNames.empty();
|
||||
}
|
||||
|
||||
const AZStd::vector<QString>& GetDownloadQueue() const
|
||||
{
|
||||
return m_gemNames;
|
||||
}
|
||||
|
||||
const QString& GetCurrentDownloadingGem() const
|
||||
{
|
||||
return m_gemNames[0];
|
||||
}
|
||||
public slots:
|
||||
void Start();
|
||||
void UpdateUIProgress(int progress);
|
||||
void HandleResults(const QString& result);
|
||||
void HandleCancel();
|
||||
|
||||
signals:
|
||||
void StartGemDownload(const QString& gemName);
|
||||
void Done(bool success = true);
|
||||
void GemDownloadProgress(int percentage);
|
||||
|
||||
private:
|
||||
O3DEObjectDownloadWorker* m_worker;
|
||||
QThread m_workerThread;
|
||||
QWidget* m_parent;
|
||||
AZStd::vector<QString> m_gemNames;
|
||||
|
||||
int m_lastProgress;
|
||||
};
|
||||
} // namespace O3DE::ProjectManager
|
||||
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <O3DEObjectDownloadController.h>
|
||||
#include <O3DEObjectDownloadWorker.h>
|
||||
#include <PythonBindings.h>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
|
||||
|
||||
namespace O3DE::ProjectManager
|
||||
{
|
||||
O3DEObjectDownloadWorker::O3DEObjectDownloadWorker()
|
||||
: QObject()
|
||||
{
|
||||
}
|
||||
|
||||
void O3DEObjectDownloadWorker::StartDownload()
|
||||
{
|
||||
auto gemDownloadProgress = [=](int downloadProgress)
|
||||
{
|
||||
m_downloadProgress = downloadProgress;
|
||||
emit UpdateProgress(downloadProgress);
|
||||
};
|
||||
AZ::Outcome<void, AZStd::string> gemInfoResult = PythonBindingsInterface::Get()->DownloadGem(m_gemName, gemDownloadProgress);
|
||||
if (gemInfoResult.IsSuccess())
|
||||
{
|
||||
emit Done("");
|
||||
}
|
||||
else
|
||||
{
|
||||
emit Done(tr("Gem download failed"));
|
||||
}
|
||||
}
|
||||
|
||||
void O3DEObjectDownloadWorker::SetGemToDownload(const QString& gemName, bool downloadNow)
|
||||
{
|
||||
m_gemName = gemName;
|
||||
if (downloadNow)
|
||||
{
|
||||
StartDownload();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace O3DE::ProjectManager
|
||||
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <AzCore/Outcome/Outcome.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QString>
|
||||
#endif
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QProcess)
|
||||
|
||||
namespace O3DE::ProjectManager
|
||||
{
|
||||
class O3DEObjectDownloadWorker : public QObject
|
||||
{
|
||||
// QProcess::waitForFinished uses -1 to indicate that the process should not timeout
|
||||
static constexpr int MaxBuildTimeMSecs = -1;
|
||||
// Download was cancelled
|
||||
inline static const QString DownloadCancelled = QObject::tr("Download Cancelled.");
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit O3DEObjectDownloadWorker();
|
||||
~O3DEObjectDownloadWorker() = default;
|
||||
|
||||
public slots:
|
||||
void StartDownload();
|
||||
void SetGemToDownload(const QString& gemName, bool downloadNow = true);
|
||||
|
||||
signals:
|
||||
void UpdateProgress(int progress);
|
||||
void Done(QString result = "");
|
||||
|
||||
private:
|
||||
|
||||
QProcess* m_configProjectProcess = nullptr;
|
||||
QProcess* m_buildProjectProcess = nullptr;
|
||||
|
||||
QString m_gemName;
|
||||
int m_downloadProgress;
|
||||
};
|
||||
} // namespace O3DE::ProjectManager
|
||||
Loading…
Reference in New Issue