moved QEventLoops inside functions

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-06-22 12:48:55 +03:00
parent 06e1cab41f
commit 0a95b57c0a
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
6 changed files with 35 additions and 27 deletions

View File

@ -149,4 +149,14 @@ Task::Ptr Index::loadVersion(const QString& uid, const QString& version, Net::Mo
loadTask->addTask(versionList->getVersion(version)->loadTask(mode));
return loadTask;
}
Version::Ptr Index::getLoadedVersion(const QString& uid, const QString& version)
{
QEventLoop ev;
auto task = loadVersion(uid, version);
QObject::connect(task.get(), &Task::finished, &ev, &QEventLoop::quit);
task->start();
ev.exec();
return get(uid, version);
}
} // namespace Meta

View File

@ -50,6 +50,9 @@ class Index : public QAbstractListModel, public BaseEntity {
Task::Ptr loadVersion(const QString& uid, const QString& version = {}, Net::Mode mode = Net::Mode::Online, bool force = false);
// this blocks until the version is loaded
Version::Ptr getLoadedVersion(const QString& uid, const QString& version);
public: // for usage by parsers only
void merge(const std::shared_ptr<Index>& other);

View File

@ -254,4 +254,14 @@ BaseVersion::Ptr VersionList::getRecommended() const
return m_recommended;
}
void VersionList::waitToLoad()
{
if (isLoaded())
return;
QEventLoop ev;
auto task = getLoadTask();
QObject::connect(task.get(), &Task::finished, &ev, &QEventLoop::quit);
task->start();
ev.exec();
}
} // namespace Meta

View File

@ -59,6 +59,9 @@ class VersionList : public BaseVersionList, public BaseEntity {
QVector<Version::Ptr> versions() const { return m_versions; }
// this blocks until the version list is loaded
void waitToLoad();
public: // for usage only by parsers
void setName(const QString& name);
void setVersions(const QVector<Version::Ptr>& versions);

View File

@ -91,11 +91,8 @@ std::shared_ptr<class VersionFile> Component::getVersionFile() const
{
if (m_metaVersion) {
if (!m_metaVersion->isLoaded()) {
QEventLoop ev;
auto task = APPLICATION->metadataIndex()->loadVersion(m_metaVersion->uid(), m_metaVersion->version(), Net::Mode::Online);
connect(task.get(), &Task::finished, &ev, &QEventLoop::quit);
task->start();
ev.exec();
// this method is const but the loading of meta changes the information
APPLICATION->metadataIndex()->getLoadedVersion(m_metaVersion->uid(), m_metaVersion->version());
}
return m_metaVersion->data();
} else {
@ -197,10 +194,12 @@ bool Component::isCustomizable()
}
return false;
}
bool Component::isRemovable()
{
return !m_important;
}
bool Component::isRevertible()
{
if (isCustom()) {
@ -210,22 +209,18 @@ bool Component::isRevertible()
}
return false;
}
bool Component::isMoveable()
{
// HACK, FIXME: this was too dumb and wouldn't follow dependency constraints anyway. For now hardcoded to 'true'.
return true;
}
bool Component::isVersionChangeable()
{
auto list = getVersionList();
if (list) {
if (!list->isLoaded()) {
QEventLoop ev;
auto task = list->getLoadTask();
connect(task.get(), &Task::finished, &ev, &QEventLoop::quit);
task->start();
ev.exec();
}
list->waitToLoad();
return list->count() != 0;
}
return false;

View File

@ -36,7 +36,6 @@
#include "ATLPackInstallTask.h"
#include <QEventLoop>
#include <QtConcurrent>
#include <algorithm>
@ -344,13 +343,7 @@ QString PackInstallTask::getVersionForLoader(QString uid)
return Q_NULLPTR;
}
if (!vlist->isLoaded()) {
QEventLoop ev;
auto task = vlist->getLoadTask();
connect(task.get(), &Task::finished, &ev, &QEventLoop::quit);
task->start();
ev.exec();
}
vlist->waitToLoad();
if (m_version.loader.recommended || m_version.loader.latest) {
for (int i = 0; i < vlist->versions().size(); i++) {
@ -1076,13 +1069,7 @@ void PackInstallTask::install()
static Meta::Version::Ptr getComponentVersion(const QString& uid, const QString& version)
{
QEventLoop ev;
auto task = APPLICATION->metadataIndex()->loadVersion(uid, version);
QObject::connect(task.get(), &Task::finished, &ev, &QEventLoop::quit);
task->start();
ev.exec();
return APPLICATION->metadataIndex()->get(uid, version);
return APPLICATION->metadataIndex()->getLoadedVersion(uid, version);
}
} // namespace ATLauncher