summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2017-05-11 15:19:31 +0200
committerAleix Pol <[email protected]>2017-05-11 15:20:08 +0200
commit17cb9796cc0e7eb151cbcf56daf4082c2178b744 (patch)
treed75daed7d903fe95b4560a18382f80ff681407a4
parent361f408eb00cfc11c27c865eb844e019ff765e2f (diff)
Readability & testability
Instead of using QObject::deleteLater, use a ResultsStream::finish
-rw-r--r--libdiscover/backends/KNSBackend/KNSBackend.cpp8
-rw-r--r--libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp2
-rw-r--r--libdiscover/backends/SnapBackend/SnapBackend.cpp4
-rw-r--r--libdiscover/resources/AbstractResourcesBackend.cpp7
-rw-r--r--libdiscover/resources/AbstractResourcesBackend.h2
-rw-r--r--libdiscover/resources/ResourcesProxyModel.cpp2
6 files changed, 16 insertions, 9 deletions
diff --git a/libdiscover/backends/KNSBackend/KNSBackend.cpp b/libdiscover/backends/KNSBackend/KNSBackend.cpp
index f4eae0e..7bb23e2 100644
--- a/libdiscover/backends/KNSBackend/KNSBackend.cpp
+++ b/libdiscover/backends/KNSBackend/KNSBackend.cpp
@@ -328,8 +328,8 @@ ResultsStream * KNSBackend::searchStream(const QString &searchText)
m_responsePending = true;
m_page = 0;
connect(this, &KNSBackend::receivedResources, stream, &ResultsStream::resourcesFound);
- connect(this, &KNSBackend::searchFinished, stream, &ResultsStream::deleteLater);
- connect(this, &KNSBackend::startingSearch, stream, &ResultsStream::deleteLater);
+ connect(this, &KNSBackend::searchFinished, stream, &ResultsStream::finish);
+ connect(this, &KNSBackend::startingSearch, stream, &ResultsStream::finish);
};
if (m_responsePending) {
connect(this, &KNSBackend::availableForQueries, stream, start, Qt::QueuedConnection);
@@ -357,14 +357,14 @@ ResultsStream * KNSBackend::findResourceByPackageName(const QUrl& search)
auto start = [this, entryid, stream]() {
m_responsePending = true;
m_engine->fetchEntryById(entryid);
- connect(m_engine, &KNSCore::Engine::signalError, stream, &QObject::deleteLater);
+ connect(m_engine, &KNSCore::Engine::signalError, stream, &ResultsStream::finish);
connect(m_engine, &KNSCore::Engine::signalEntryDetailsLoaded, stream, [this, stream, entryid](const KNSCore::EntryInternal &entry) {
if (entry.uniqueId() == entryid) {
stream->resourcesFound({resourceForEntry(entry)});
}
m_responsePending = false;
QTimer::singleShot(0, this, &KNSBackend::availableForQueries);
- stream->deleteLater();
+ stream->finish();
});
};
if (m_responsePending) {
diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp
index c6beeff..549b830 100644
--- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp
+++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp
@@ -418,7 +418,7 @@ ResultsStream* PackageKitBackend::search(const AbstractResourcesBackend::Filters
const auto res = resourcesByPackageNames<QVector<AbstractResource*>>({PackageKit::Daemon::packageName(packageId.toString())});
stream->resourcesFound(kFilter<QVector<AbstractResource*>>(res, [ids](AbstractResource* res){ return !ids.contains(res->appstreamId()); }));
}
- stream->deleteLater();
+ stream->finish();
}, Qt::QueuedConnection);
return stream;
}
diff --git a/libdiscover/backends/SnapBackend/SnapBackend.cpp b/libdiscover/backends/SnapBackend/SnapBackend.cpp
index ff41d58..20d7ee1 100644
--- a/libdiscover/backends/SnapBackend/SnapBackend.cpp
+++ b/libdiscover/backends/SnapBackend/SnapBackend.cpp
@@ -78,7 +78,7 @@ ResultsStream* SnapBackend::populate(SnapJob* job, AbstractResource::State state
connect(job, &SnapJob::finished, stream, [stream, this, state](SnapJob* job) {
if (!job->isSuccessful()) {
- stream->deleteLater();
+ stream->finish();
return;
}
@@ -104,7 +104,7 @@ ResultsStream* SnapBackend::populate(SnapJob* job, AbstractResource::State state
}
if (!ret.isEmpty())
stream->resourcesFound(ret);
- stream->deleteLater();
+ stream->finis();
});
job->start();
return stream;
diff --git a/libdiscover/resources/AbstractResourcesBackend.cpp b/libdiscover/resources/AbstractResourcesBackend.cpp
index 2ef5523..094cb11 100644
--- a/libdiscover/resources/AbstractResourcesBackend.cpp
+++ b/libdiscover/resources/AbstractResourcesBackend.cpp
@@ -49,7 +49,7 @@ ResultsStream::ResultsStream(const QString &objectName, const QVector<AbstractRe
QTimer::singleShot(0, this, [resources, this] () {
if (!resources.isEmpty())
Q_EMIT resourcesFound(resources);
- deleteLater();
+ finish();
});
}
@@ -63,6 +63,11 @@ ResultsStream::~ResultsStream()
{
}
+void ResultsStream::finish()
+{
+ deleteLater();
+}
+
AbstractResourcesBackend::AbstractResourcesBackend(QObject* parent)
: QObject(parent)
{
diff --git a/libdiscover/resources/AbstractResourcesBackend.h b/libdiscover/resources/AbstractResourcesBackend.h
index bac9241..42151c0 100644
--- a/libdiscover/resources/AbstractResourcesBackend.h
+++ b/libdiscover/resources/AbstractResourcesBackend.h
@@ -47,6 +47,8 @@ class DISCOVERCOMMON_EXPORT ResultsStream : public QObject
ResultsStream(const QString &objectName, const QVector<AbstractResource*>& resources);
~ResultsStream() override;
+ void finish();
+
Q_SIGNALS:
void resourcesFound(const QVector<AbstractResource*>& resources);
};
diff --git a/libdiscover/resources/ResourcesProxyModel.cpp b/libdiscover/resources/ResourcesProxyModel.cpp
index 74604d5..f9906aa 100644
--- a/libdiscover/resources/ResourcesProxyModel.cpp
+++ b/libdiscover/resources/ResourcesProxyModel.cpp
@@ -217,7 +217,7 @@ void ResourcesProxyModel::invalidateFilter()
connect(m_currentStream, &AggregatedResultsStream::resourcesFound, this, [this](const QVector<AbstractResource*>& resources) {
addResources(resources);
});
- connect(m_currentStream, &AggregatedResultsStream::destroyed, this, [this]() {
+ connect(m_currentStream, &AggregatedResultsStream::finished, this, [this]() {
m_currentStream = nullptr;
Q_EMIT busyChanged(false);
});