Commit 1367923d authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

pk: Use a helper function to delay execution after appstream is ready

Should make more readable, less repeated, compact code
parent 2a0f3363
......@@ -495,13 +495,7 @@ ResultsStream* PackageKitBackend::search(const AbstractResourcesBackend::Filters
});
}
};
if (!m_appstreamInitialized) {
connect(this, &PackageKitBackend::loadedAppStream, stream, f);
} else {
QTimer::singleShot(0, this, f);
}
runWhenInitialized(f, stream);
return stream;
} else if (filter.search.isEmpty()) {
auto stream = new PKResultsStream(this, QStringLiteral("PackageKitStream-all"));
......@@ -511,11 +505,7 @@ ResultsStream* PackageKitBackend::search(const AbstractResourcesBackend::Filters
Q_EMIT stream->setResources(resources);
}
};
if (!m_appstreamInitialized) {
connect(this, &PackageKitBackend::loadedAppStream, stream, f);
} else {
QTimer::singleShot(0, this, f);
}
runWhenInitialized(f, stream);
return stream;
} else {
auto stream = new PKResultsStream(this, QStringLiteral("PackageKitStream-search"));
......@@ -544,15 +534,20 @@ ResultsStream* PackageKitBackend::search(const AbstractResourcesBackend::Filters
stream->finish();
}, Qt::QueuedConnection);
};
if (!m_appstreamInitialized) {
connect(this, &PackageKitBackend::loadedAppStream, stream, f);
} else {
QTimer::singleShot(0, this, f);
}
runWhenInitialized(f, stream);
return stream;
}
}
void PackageKitBackend::runWhenInitialized(const std::function<void ()>& f, QObject* stream)
{
if (!m_appstreamInitialized) {
connect(this, &PackageKitBackend::loadedAppStream, stream, f);
} else {
QTimer::singleShot(0, this, f);
}
}
PKResultsStream * PackageKitBackend::findResourceByPackageName(const QUrl& url)
{
if (url.isLocalFile()) {
......@@ -609,11 +604,7 @@ PKResultsStream * PackageKitBackend::findResourceByPackageName(const QUrl& url)
// if (!pkg)
// qCDebug(LIBDISCOVER_BACKEND_LOG) << "could not find" << host << deprecatedHost;
};
if (!m_appstreamInitialized) {
connect(this, &PackageKitBackend::loadedAppStream, stream, f);
} else {
QTimer::singleShot(0, this, f);
}
runWhenInitialized(f, stream);
return stream;
}
}
......
......@@ -103,6 +103,8 @@ class DISCOVERCOMMON_EXPORT PackageKitBackend : public AbstractResourcesBackend
template <typename T>
T resourcesByPackageNames(const QStringList& names) const;
void runWhenInitialized(const std::function<void()> &f, QObject* stream);
void checkDaemonRunning();
void acquireFetching(bool f);
void includePackagesToAdd();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment