9#include "alknewstuffengine.h" 
   10#include "alknewstuffentry_p.h" 
   14#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 
   15#include <KNSCore/Cache> 
   16#include <KNSCore/EngineBase> 
   17#include <KNSCore/Provider> 
   18#include <KNSCore/ResultsStream> 
   19#elif QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 
   20#include <KNSCore/Cache> 
   21#include <knewstuff_version.h> 
   22#include <knscore/engine.h> 
   24#include <knewstuff3/core/cache.h> 
   25#include <knewstuff3/downloadmanager.h> 
   26#define KNEWSTUFF_VERSION 0 
   33class AlkNewStuffEngine::Private : 
public QObject 
   38#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 
   39    QPointer<KNSCore::EngineBase> m_engine;
 
   41    QSharedPointer<KNSCore::Cache> m_cache;
 
   42    bool m_providersLoaded{
false};
 
   43    bool m_wantUpdates{
false};
 
   44#elif QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 
   45    QPointer<KNSCore::Engine> m_engine;
 
   46    QSharedPointer<KNSCore::Cache> m_cache;
 
   47    bool m_providersLoaded{
false};
 
   48    bool m_wantUpdates{
false};
 
   50    QPointer<KNS3::DownloadManager> m_engine;
 
   55    explicit Private(AlkNewStuffEngine *
parent);
 
   58    bool init(
const QString &configFile);
 
   59    void checkForUpdates();
 
   61    const AlkNewStuffEntryList installedEntries();
 
   64    void slotUpdatesAvailable(
const KNS3::Entry::List &entries);
 
   74AlkNewStuffEngine::Private::~Private()
 
   77#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) 
   82bool AlkNewStuffEngine::Private::init(
const QString &configFile)
 
   85#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 
   86    m_engine = 
new KNSCore::EngineBase(
this);
 
   87    state = m_engine->init(configFile);
 
   90    m_cache = m_engine->cache();
 
   91    connect(m_engine, &KNSCore::EngineBase::signalProvidersLoaded, 
this, [
this]()
 
   93        alkDebug() << 
"providers loaded";
 
   94        m_providersLoaded = 
true;
 
   99#elif KNEWSTUFF_VERSION >= QT_VERSION_CHECK(5, 0, 0) 
  100    m_engine = 
new KNSCore::Engine(
this);
 
  101    state = m_engine->init(configFile);
 
  104    m_cache = m_engine->cache();
 
  106    q->connect(m_engine, &KNSCore::Engine::signalErrorCode, q, [](
const KNSCore::ErrorCode &, 
const QString &message, 
const QVariant &) {
 
  107        alkDebug() << message;
 
  110    connect(m_engine, &KNSCore::Engine::signalProvidersLoaded, 
this, [
this]()
 
  112        alkDebug() << 
"providers loaded";
 
  113        m_providersLoaded = 
true;
 
  114        m_engine->reloadEntries();
 
  115        alkDebug() << 
"cache" << m_engine->cache() << m_engine->cache()->registry();
 
  117            m_engine->checkForUpdates();
 
  120    connect(m_engine, &KNSCore::Engine::signalUpdateableEntriesLoaded, 
this, [
this](
const KNSCore::EntryInternal::List &entries)
 
  122        alkDebug() << entries.size() << 
"updates loaded";
 
  123        AlkNewStuffEntryList updateEntries;
 
  124        toAlkEntryList(updateEntries, entries);
 
  125        alkDebug() << updateEntries;
 
  126        Q_EMIT q->updatesAvailable(updateEntries);
 
  129    m_engine = 
new KNS3::DownloadManager(configFile, 
this);
 
  130    QFileInfo f(configFile);
 
  131    m_cache = 
new Cache(f.baseName());
 
  132    m_cache->readRegistry();
 
  136    connect(m_engine, SIGNAL(searchResult(KNS3::Entry::List)), 
this,
 
  137            SLOT(slotUpdatesAvailable(KNS3::Entry::List)));
 
  142void AlkNewStuffEngine::Private::checkForUpdates()
 
  144#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 
  145    alkDebug() << 
"FIXME Qt6: no checkforUpdates() - how to proceed ?";
 
  146#elif QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 
  147    if (m_providersLoaded && !m_wantUpdates) {
 
  148        m_engine->checkForUpdates();
 
  150        m_wantUpdates = 
true;
 
  152    m_engine->checkForUpdates();
 
  156const AlkNewStuffEntryList AlkNewStuffEngine::Private::installedEntries()
 
  158    AlkNewStuffEntryList result;
 
  160        toAlkEntryList(result, m_cache->registry());
 
  162    alkDebug() << result;
 
  166void AlkNewStuffEngine::Private::slotUpdatesAvailable(
const KNS3::Entry::List &entries)
 
  168#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 
  171    alkDebug() << entries.size() << 
"updates loaded";
 
  172    AlkNewStuffEntryList updateEntries;
 
  173    toAlkEntryList(updateEntries, entries);
 
  174    alkDebug() << entries;
 
  176    Q_EMIT q->updatesAvailable(updateEntries);
 
  182    , d(new Private(this))
 
  188    bool result = d->init(configFile);
 
 
  194    d->checkForUpdates();
 
 
  197AlkNewStuffEntryList AlkNewStuffEngine::installedEntries()
 const 
  199    return d->installedEntries();
 
  204    d->m_cache->readRegistry();
 
 
  207const char *toString(AlkNewStuffEntry::Status 
status)
 
  210        case AlkNewStuffEntry::Invalid: 
return "Invalid";
 
  211        case AlkNewStuffEntry::Downloadable: 
return "Downloadable";
 
  212        case AlkNewStuffEntry::Installed: 
return "Installed";
 
  213        case AlkNewStuffEntry::Updateable: 
return "Updateable";
 
  214        case AlkNewStuffEntry::Deleted: 
return "Deleted";
 
  215        case AlkNewStuffEntry::Installing: 
return "Installing";
 
  216        case AlkNewStuffEntry::Updating: 
return "Updating";
 
  221#include "alknewstuffengine.moc" 
Wrapper for debug output.
 
Platform independent wrapper for the new stuff engine.
 
void reload()
Reload installed entries.
 
bool init(const QString &configFile)
Initialization of the new stuff engine.
 
void checkForUpdates()
Start check for updates and return Update results are obtained using the updatesAvailable() signal.
 
Q_SCRIPTABLE CaptureState status()
 
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QObject * parent() const const