Commit ffe2d3a5 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

comicupdater: Port away from deprecated KNSCore::DownloadManager

Discussion: https://phabricator.kde.org/T14010
parent 0ecdecaa
......@@ -13,13 +13,14 @@
#include <KConfigDialog>
#include <KNS3/DownloadDialog>
#include <KNSCore/DownloadManager>
#include <KNSCore/Engine>
ComicUpdater::ComicUpdater(QObject *parent)
: QObject(parent)
, mDownloadManager(nullptr)
, mEngine(nullptr)
, mUpdateIntervall(3)
, m_updateTimer(nullptr)
, mProvidersLoaded(false)
{
}
......@@ -69,23 +70,33 @@ void ComicUpdater::checkForUpdate()
if (!mLastUpdate.isValid() || (mLastUpdate.addDays(mUpdateIntervall) < QDateTime::currentDateTime())) {
mLastUpdate = QDateTime::currentDateTime();
mGroup.writeEntry("lastUpdate", mLastUpdate);
downloadManager()->checkForUpdates();
if (mProvidersLoaded) {
engine()->checkForUpdates();
} else {
connect(engine(), &KNSCore::Engine::signalProvidersLoaded, this, [this]() {
engine()->checkForUpdates();
});
}
}
}
void ComicUpdater::slotUpdatesFound(const KNSCore::EntryInternal::List &entries)
{
for (int i = 0; i < entries.count(); ++i) {
downloadManager()->installEntry(entries[i]);
engine()->install(entries[i]);
}
}
KNSCore::DownloadManager *ComicUpdater::downloadManager()
KNSCore::Engine *ComicUpdater::engine()
{
if (!mDownloadManager) {
mDownloadManager = new KNSCore::DownloadManager(QStringLiteral("comic.knsrc"), this);
connect(mDownloadManager, &KNSCore::DownloadManager::searchResult, this, &ComicUpdater::slotUpdatesFound);
if (!mEngine) {
mEngine = new KNSCore::Engine(this);
if (mEngine->init(QStringLiteral("comic.knsrc"))) {
connect(mEngine, &KNSCore::Engine::signalUpdateableEntriesLoaded, this, &ComicUpdater::slotUpdatesFound);
connect(mEngine, &KNSCore::Engine::signalProvidersLoaded, this, [this]() {
mProvidersLoaded = true;
});
}
}
return mDownloadManager;
return mEngine;
}
......@@ -19,7 +19,7 @@ namespace KNS3
}
namespace KNSCore
{
class DownloadManager;
class Engine;
}
namespace Plasma
......@@ -51,14 +51,15 @@ private Q_SLOTS:
void slotUpdatesFound(const KNSCore::EntryInternal::List &entries);
private:
KNSCore::DownloadManager *downloadManager();
KNSCore::Engine *engine();
private:
KNSCore::DownloadManager *mDownloadManager;
KNSCore::Engine *mEngine;
KConfigGroup mGroup;
int mUpdateIntervall;
QDateTime mLastUpdate;
QTimer *m_updateTimer;
bool mProvidersLoaded;
};
#endif
Supports Markdown
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