forked from qt-creator/qt-creator
Vcpkg: Make vcpkgManifests() cancelable
Hide this method in cpp. Pass a promise, so that the function is made cancelable. Make a promise of VcpkgManifest type (instead of returning a list of VcpkgManifest types). Deliver results via promise arg. Collect results via results() method. Remove alias for QList<VcpkgManifest>, as it's used just once now. Change-Id: I06b76da9f40617bd6397fbee31b6db711dddcfb3 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -31,6 +31,20 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace Vcpkg::Internal::Search {
|
namespace Vcpkg::Internal::Search {
|
||||||
|
|
||||||
|
static void vcpkgManifests(QPromise<VcpkgManifest> &promise, const FilePath &vcpkgRoot)
|
||||||
|
{
|
||||||
|
const FilePath portsDir = vcpkgRoot / "ports";
|
||||||
|
const FilePaths manifestFiles =
|
||||||
|
portsDir.dirEntries({{"vcpkg.json"}, QDir::Files, QDirIterator::Subdirectories});
|
||||||
|
for (const FilePath &manifestFile : manifestFiles) {
|
||||||
|
if (promise.isCanceled())
|
||||||
|
return;
|
||||||
|
FileReader reader;
|
||||||
|
if (reader.fetch(manifestFile))
|
||||||
|
promise.addResult(parseVcpkgManifest(reader.data()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class VcpkgPackageSearchDialog : public QDialog
|
class VcpkgPackageSearchDialog : public QDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -44,7 +58,7 @@ private:
|
|||||||
void updateStatus();
|
void updateStatus();
|
||||||
void updatePackages();
|
void updatePackages();
|
||||||
|
|
||||||
VcpkgManifests m_allPackages;
|
QList<VcpkgManifest> m_allPackages;
|
||||||
VcpkgManifest m_selectedPackage;
|
VcpkgManifest m_selectedPackage;
|
||||||
|
|
||||||
const VcpkgManifest m_projectManifest;
|
const VcpkgManifest m_projectManifest;
|
||||||
@@ -140,8 +154,7 @@ VcpkgManifest VcpkgPackageSearchDialog::selectedPackage() const
|
|||||||
|
|
||||||
void VcpkgPackageSearchDialog::listPackages(const QString &filter)
|
void VcpkgPackageSearchDialog::listPackages(const QString &filter)
|
||||||
{
|
{
|
||||||
const VcpkgManifests filteredPackages = filtered(m_allPackages,
|
const auto filteredPackages = filtered(m_allPackages, [&filter](const VcpkgManifest &package) {
|
||||||
[&filter] (const VcpkgManifest &package) {
|
|
||||||
return filter.isEmpty()
|
return filter.isEmpty()
|
||||||
|| package.name.contains(filter, Qt::CaseInsensitive)
|
|| package.name.contains(filter, Qt::CaseInsensitive)
|
||||||
|| package.shortDescription.contains(filter, Qt::CaseInsensitive)
|
|| package.shortDescription.contains(filter, Qt::CaseInsensitive)
|
||||||
@@ -187,33 +200,22 @@ void VcpkgPackageSearchDialog::updateStatus()
|
|||||||
|
|
||||||
void VcpkgPackageSearchDialog::updatePackages()
|
void VcpkgPackageSearchDialog::updatePackages()
|
||||||
{
|
{
|
||||||
using ResultType = VcpkgManifests;
|
|
||||||
|
|
||||||
const auto parseManifests = [=](QPromise<ResultType> &promise, const FilePath &srcPath) {
|
|
||||||
promise.addResult(vcpkgManifests(srcPath));
|
|
||||||
};
|
|
||||||
|
|
||||||
using namespace Tasking;
|
using namespace Tasking;
|
||||||
Group group {
|
|
||||||
onGroupSetup([this]() {
|
const Group group {
|
||||||
m_spinner->show();
|
onGroupSetup([this] { m_spinner->show(); }),
|
||||||
}),
|
AsyncTask<VcpkgManifest>{
|
||||||
AsyncTask<ResultType>{
|
[](Async<VcpkgManifest> &task) {
|
||||||
[parseManifests](Async<ResultType> &task) {
|
task.setConcurrentCallData(vcpkgManifests, settings().vcpkgRoot());
|
||||||
task.setConcurrentCallData(parseManifests,
|
|
||||||
settings().vcpkgRoot());
|
|
||||||
},
|
},
|
||||||
[this](const Async<ResultType> &task) {
|
[this](const Async<VcpkgManifest> &task) { m_allPackages = task.results(); }
|
||||||
m_allPackages = task.result();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onGroupDone([this]() {
|
onGroupDone([this] {
|
||||||
m_spinner->hide();
|
m_spinner->hide();
|
||||||
listPackages({});
|
listPackages({});
|
||||||
updateStatus();
|
updateStatus();
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
m_taskTreeRunner.start(group);
|
m_taskTreeRunner.start(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,23 +267,6 @@ VcpkgManifest parseVcpkgManifest(const QByteArray &vcpkgManifestJsonData, bool *
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
VcpkgManifests vcpkgManifests(const FilePath &vcpkgRoot)
|
|
||||||
{
|
|
||||||
const FilePath portsDir = vcpkgRoot / "ports";
|
|
||||||
VcpkgManifests result;
|
|
||||||
const FilePaths manifestFiles =
|
|
||||||
portsDir.dirEntries({{"vcpkg.json"}, QDir::Files, QDirIterator::Subdirectories});
|
|
||||||
for (const FilePath &manifestFile : manifestFiles) {
|
|
||||||
FileReader reader;
|
|
||||||
if (reader.fetch(manifestFile)) {
|
|
||||||
const QByteArray &manifestData = reader.data();
|
|
||||||
const VcpkgManifest manifest = parseVcpkgManifest(manifestData);
|
|
||||||
result.append(manifest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
VcpkgManifest showVcpkgPackageSearchDialog(const VcpkgManifest &projectManifest, QWidget *parent)
|
VcpkgManifest showVcpkgPackageSearchDialog(const VcpkgManifest &projectManifest, QWidget *parent)
|
||||||
{
|
{
|
||||||
QWidget *dlgParent = parent ? parent : Core::ICore::dialogParent();
|
QWidget *dlgParent = parent ? parent : Core::ICore::dialogParent();
|
||||||
|
@@ -21,10 +21,7 @@ struct VcpkgManifest
|
|||||||
QUrl homepage;
|
QUrl homepage;
|
||||||
};
|
};
|
||||||
|
|
||||||
using VcpkgManifests = QList<VcpkgManifest>;
|
|
||||||
|
|
||||||
VcpkgManifest parseVcpkgManifest(const QByteArray &vcpkgManifestJsonData, bool *ok = nullptr);
|
VcpkgManifest parseVcpkgManifest(const QByteArray &vcpkgManifestJsonData, bool *ok = nullptr);
|
||||||
VcpkgManifests vcpkgManifests(const Utils::FilePath &vcpkgRoot);
|
|
||||||
VcpkgManifest showVcpkgPackageSearchDialog(const VcpkgManifest &projectManifest,
|
VcpkgManifest showVcpkgPackageSearchDialog(const VcpkgManifest &projectManifest,
|
||||||
QWidget *parent = nullptr);
|
QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user