Commit 09654c6a authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Keep track of the kns entries status internally

Entries can change anytime given kns commit:
bcb7dd628811a4fab92274ea9da1d670c6046a1e
parent d5b3f7af
......@@ -40,6 +40,7 @@
// DiscoverCommon includes
#include "Transaction/Transaction.h"
#include "Transaction/TransactionModel.h"
#include "Category/Category.h"
// Own includes
......@@ -77,6 +78,8 @@ class KNSBackendFactory : public AbstractResourcesBackendFactory {
}
};
Q_DECLARE_METATYPE(KNSCore::EntryInternal);
KNSBackend::KNSBackend(QObject* parent, const QString& iconName, const QString &knsrc)
: AbstractResourcesBackend(parent)
, m_fetching(false)
......@@ -122,7 +125,7 @@ KNSBackend::KNSBackend(QObject* parent, const QString& iconName, const QString &
passiveMessage(i18n("%1: %2", name(), error));
});
connect(m_engine, &KNSCore::Engine::signalEntriesLoaded, this, &KNSBackend::receivedEntries, Qt::QueuedConnection);
connect(m_engine, &KNSCore::Engine::signalEntryChanged, this, &KNSBackend::statusChanged);
connect(m_engine, &KNSCore::Engine::signalEntryChanged, this, &KNSBackend::statusChanged, Qt::QueuedConnection);
connect(m_engine, &KNSCore::Engine::signalEntryDetailsLoaded, this, &KNSBackend::statusChanged);
connect(m_engine, &KNSCore::Engine::signalProvidersLoaded, this, &KNSBackend::fetchInstalled);
......@@ -242,6 +245,7 @@ public:
auto manager = res->knsBackend()->engine();
connect(manager, &KNSCore::Engine::signalEntryChanged, this, &KNSTransaction::anEntryChanged);
TransactionModel::global()->addTransaction(this);
}
void anEntryChanged(const KNSCore::EntryInternal& entry) {
......
......@@ -30,6 +30,7 @@ KNSResource::KNSResource(const KNSCore::EntryInternal& entry, QStringList catego
: AbstractResource(parent)
, m_categories(std::move(categories))
, m_entry(entry)
, m_lastStatus(entry.status())
{
connect(this, &KNSResource::stateChanged, parent, &KNSBackend::updatesCountChanged);
}
......@@ -119,10 +120,12 @@ QUrl KNSResource::homepage()
void KNSResource::setEntry(const KNSCore::EntryInternal& entry)
{
const bool diff = entry.status() != m_entry.status();
const bool diff = entry.status() != m_lastStatus;
m_entry = entry;
if (diff)
if (diff) {
m_lastStatus = entry.status();
Q_EMIT stateChanged();
}
}
KNSCore::EntryInternal KNSResource::entry() const
......
......@@ -68,6 +68,7 @@ public:
private:
const QStringList m_categories;
KNSCore::EntryInternal m_entry;
KNS3::Entry::Status m_lastStatus;
};
#endif // KNSRESOURCE_H
......@@ -134,7 +134,9 @@ void KNSBackendTest::reviewsArrived(AbstractResource* r, const QVector<ReviewPtr
void KNSBackendTest::testResourceByUrl()
{
const QUrl url(QStringLiteral("kns://") + m_backend->name() + QStringLiteral("/api.kde-look.org/1136471"));
const QVector<QUrl> res = kTransform<QVector<QUrl>>(getResources(m_backend->findResourceByPackageName(url)), [](AbstractResource* res){ return res->url(); });
auto resources = getResources(m_backend->findResourceByPackageName(url));
const QVector<QUrl> res = kTransform<QVector<QUrl>>(resources, [](AbstractResource* res){ return res->url(); });
QCOMPARE(res.count(), 1);
QCOMPARE(url, res.constFirst());
......@@ -142,4 +144,16 @@ void KNSBackendTest::testResourceByUrl()
f.resourceUrl = url;
const QVector<QUrl> res2 = kTransform<QVector<QUrl>>(getResources(m_backend->search(f)), [](AbstractResource* res){ return res->url(); });
QCOMPARE(res, res2);
auto resource = resources.constFirst();
QVERIFY(!resource->isInstalled()); //Make sure .qttest is clean before running the test
QSignalSpy spy(resource, &AbstractResource::stateChanged);
auto b = resource->backend();
b->installApplication(resource);
QVERIFY(spy.wait());
b->removeApplication(resource);
QVERIFY(spy.wait());
QCOMPARE(spy.count(), 2);
QVERIFY(!resource->isInstalled());
}
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