KNewStuff
enginebase.cpp
57 qCDebug(KNEWSTUFFCORE) << "Engine addProvider called with provider with id " << provider->d->base->id();
61 QObject::connect(provider->d->base, &ProviderBase::providerInitialized, q, [this, providerBase = provider->d->base] {
73 QObject::connect(provider->d->base, &ProviderBase::signalError, q, [this, provider](const QString &msg) {
76 QObject::connect(provider->d->base, &ProviderBase::signalErrorCode, q, &EngineBase::signalErrorCode);
77 QObject::connect(provider->d->base, &ProviderBase::signalInformation, q, &EngineBase::signalMessage);
78 QObject::connect(provider->d->base, &ProviderBase::basicsLoaded, q, &EngineBase::providersChanged);
97 connect(d->installation, &Installation::signalInstallationError, this, [this](const QString &message) {
98 Q_EMIT signalErrorCode(ErrorCode::InstallationError, i18n("An error occurred during the installation process:\n%1", message), QVariant());
108 configSearchLocations << QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation);
130 resolvedConfigFilePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("knsrcfiles/%1").arg(configfile));
134 Q_EMIT signalErrorCode(KNSCore::ErrorCode::ConfigFileError, i18n("Configuration file does not exist: \"%1\"", configfile), configfile);
142 Q_EMIT signalErrorCode(KNSCore::ErrorCode::ConfigFileError, i18n("Configuration file exists, but cannot be opened: \"%1\"", configfile), configfile);
143 qCCritical(KNEWSTUFFCORE) << "The knsrc file" << configfile << "was found but could not be opened.";
147 const KConfigGroup group = conf.hasGroup(QStringLiteral("KNewStuff")) ? conf.group(QStringLiteral("KNewStuff")) : conf.group(QStringLiteral("KNewStuff3"));
149 Q_EMIT signalErrorCode(KNSCore::ErrorCode::ConfigFileError, i18n("Configuration file is invalid: \"%1\"", configfile), configfile);
150 qCCritical(KNEWSTUFFCORE) << configfile << "doesn't contain a KNewStuff or KNewStuff3 section.";
163 d->providerFileUrl = group.readEntry("ProvidersUrl", QUrl(QStringLiteral("https://autoconfig.kde.org/ocs/providers.xml")));
166 d->providerFileUrl = QUrl::fromLocalFile(QLatin1String("%1.providers").arg(configfile.left(configfile.length() - 6)));
172 QByteArray rawContentWarningType = group.readEntry("ContentWarning", QByteArrayLiteral("Static"));
174 int value = QMetaEnum::fromType<ContentWarningType>().keyToValue(rawContentWarningType.constData(), &ok);
178 qCWarning(KNEWSTUFFCORE) << "Could not parse ContentWarning, invalid entry" << rawContentWarningType;
205 // Cache cleanup option, to help work around people deleting files from underneath KNewStuff (this
211 d->shouldRemoveDeletedEntries = group.readEntry("RemoveDeadEntries", d->shouldRemoveDeletedEntries);
228 connect(d->atticaProviderManager, &Attica::ProviderManager::providerAdded, this, &EngineBase::atticaProviderLoaded);
229 connect(d->atticaProviderManager, &Attica::ProviderManager::failedToLoad, this, &EngineBase::slotProvidersFailed);
237 qCDebug(KNEWSTUFFCORE) << "No xml loader for this url yet, so create one and temporarily store that" << d->providerFileUrl;
246 connect(loader, &XmlLoader::signalHttpError, this, [this](int status, QList<QNetworkReply::RawHeaderPair> rawHeaders) {
252 // Retry-After is not a known header, so we need to do a bit of running around to make that work
253 // Also, the fromHttpDate function is in the private qnetworkrequest header, so we can't use that
254 // So, simple workaround, just pass it through a dummy request and get a formatted date out (the
262 QTimer::singleShot(retryAfter.toMSecsSinceEpoch() - QDateTime::currentMSecsSinceEpoch(), this, &EngineBase::loadProviders);
265 // more than that, spit out TryAgainLaterError to let the user know what we're doing with their time
269 formatter.formatSpelloutDuration(retryAfter.toMSecsSinceEpoch() - QDateTime::currentMSecsSinceEpoch())),
296 list.append(Provider::CategoryMetadata{.id = data.id(), .name = data.name(), .displayName = data.displayName()});
312 // This is slightly mad backwards compat. We back-convert a SearchPreset which requires a convert of
368 } else if (providers.tagName() != QLatin1String("ghnsproviders") && providers.tagName() != QLatin1String("knewstuffproviders")) {
371 i18n("Could not load get hot new stuff providers from file: %1", d->providerFileUrl.toString()),
381 if (isAtticaProviderFile || n.attribute(QStringLiteral("type")).toLower() == QLatin1String("rest")) {
383 connect(provider->d->base, &ProviderBase::categoriesMetadataLoaded, this, [this](const QList<CategoryMetadata> &categories) {
390 connect(provider->d->base, &ProviderBase::searchPresetsLoaded, this, [this](const QList<SearchPreset> &presets) {
402 Q_EMIT signalErrorCode(KNSCore::ErrorCode::ProviderError, i18n("Error initializing provider."), d->providerFileUrl);
413 qCDebug(KNEWSTUFFCORE) << "Found provider: " << atticaProvider.baseUrl() << " but it does not support content";
416 auto provider = QSharedPointer<KNSCore::ProviderCore>(new KNSCore::ProviderCore(new AtticaProvider(atticaProvider, d->categories, {})));
QUrl baseUrl() const
bool hasContentService() const
bool hasGroup(const QString &group) const
KConfigGroup group(const QString &group)
QString readEntry(const char *key, const char *aDefault=nullptr) const
bool exists() const
AccessMode accessMode() const override
QString formatSpelloutDuration(quint64 msecs) const
bool uploadEnabled
Whether or not the configuration says that the providers are expected to support uploading.
Definition enginebase.h:71
QList< Provider::SearchPreset > searchPresets()
Definition enginebase.cpp:308
void signalErrorCode(KNSCore::ErrorCode::ErrorCode errorCode, const QString &message, const QVariant &metadata)
Fires in the case of any critical or serious errors, such as network or API problems.
void addTagFilter(const QString &filter)
Add a single filter entry to the entry tag filter.
Definition enginebase.cpp:440
bool userCanBecomeFan(const Entry &entry)
Whether or not the user is allowed to become a fan of a particular entry.
Definition enginebase.cpp:494
QStringList categories() const
The list of the server-side names of the categories handled by this engine instance.
Definition enginebase.cpp:286
virtual void addProvider(QSharedPointer< KNSCore::Provider > provider)
Add a provider and connect it to the right slots.
Definition enginebase.cpp:339
QList< QSharedPointer< Provider > > providers() const
Definition enginebase.cpp:555
void becomeFan(const Entry &entry)
This will mark the user who is currently authenticated as a fan of the entry passed to the function.
Definition enginebase.cpp:500
bool hasAdoptionCommand() const
Whether or not an adoption command exists for this engine.
Definition enginebase.cpp:528
QSharedPointer< Cache > cache() const
Get the entries cache for this engine (note that it may be null if the engine is not yet initialized)...
Definition enginebase.cpp:421
QList< SearchPreset > searchPresets2()
Definition enginebase.cpp:323
void setTagFilter(const QStringList &filter)
Set a filter for results, which filters out all entries which do not match the filter,...
Definition enginebase.cpp:427
Q_SIGNAL void contentWarningTypeChanged()
Emitted after the initial config load.
QSharedPointer< Provider > provider(const QString &providerId) const
The Provider instance with the passed ID.
Definition enginebase.cpp:507
Q_SIGNAL void uploadEnabledChanged()
Fired when the uploadEnabled property changes.
Q_SIGNAL void useLabelChanged()
Signal gets emitted when the useLabel property changes.
bool userCanVote(const Entry &entry)
Whether or not a user is able to vote on the passed entry.
Definition enginebase.cpp:482
static QStringList availableConfigFiles()
List of all available config files.
Definition enginebase.cpp:102
QStringList downloadTagFilter() const
Gets the current downloadlink tag filter list.
Definition enginebase.cpp:456
void providersChanged()
Fired whenever the list of providers changes.
QString useLabel
Text that should be displayed for the adoption button, this defaults to "Use".
Definition enginebase.h:63
QList< CategoryMetadata > categoriesMetadata2()
The list of metadata for the categories handled by this engine instance.
Definition enginebase.cpp:302
void vote(const Entry &entry, uint rating)
Cast a vote on the passed entry.
Definition enginebase.cpp:488
QList< Attica::Provider * > atticaProviders() const
Definition enginebase.cpp:469
QList< Provider::CategoryMetadata > categoriesMetadata()
Definition enginebase.cpp:292
ResultsStream * search(const KNSCore::Provider::SearchRequest &request)
Returns a stream object that will fulfill the request.
Definition enginebase.cpp:543
void addDownloadTagFilter(const QString &filter)
Add a single filter entry to the download tag filter.
Definition enginebase.cpp:461
QSharedPointer< Provider > defaultProvider() const
Return the first provider in the providers list (usually the default provider)
Definition enginebase.cpp:514
ContentWarningType contentWarningType
Definition enginebase.h:81
void setDownloadTagFilter(const QStringList &filter)
Sets a filter to be applied to the downloads for an entry.
Definition enginebase.cpp:448
void signalMessage(const QString &message)
Indicates a message to be added to the ui's log, or sent to a messagebox.
The ResultsStream is returned by EngineBase::search.
Definition resultsstream.h:34
Q_SCRIPTABLE CaptureState status()
QString i18n(const char *text, const TYPE &arg...)
KCOREADDONS_EXPORT QStringList findAllUniqueFiles(const QStringList &dirs, const QStringList &nameFilters={})
const char * constData() const const
qint64 currentMSecsSinceEpoch()
qint64 currentSecsSinceEpoch()
qint64 toMSecsSinceEpoch() const const
qint64 toSecsSinceEpoch() const const
QDomElement documentElement() const const
QString attribute(const QString &name, const QString &defValue) const const
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
bool isNull() const const
QDomElement nextSiblingElement(const QString &tagName, const QString &namespaceURI) const const
QString completeBaseName() const const
bool exists() const const
void append(QList< T > &&value)
void reserve(qsizetype size)
QMetaEnum fromType()
int keyToValue(const char *key, bool *ok) const const
RawHeaderPair
LastModifiedHeader
QVariant header(KnownHeaders header) const const
void setRawHeader(const QByteArray &headerName, const QByteArray &headerValue)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
LocateDirectory
GenericDataLocation
QString locate(StandardLocation type, const QString &fileName, LocateOptions options)
QStringList locateAll(StandardLocation type, const QString &fileName, LocateOptions options)
QStringList standardLocations(StandardLocation type)
QString left(qsizetype n) const const
qsizetype length() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
singleShot
QUrl fromLocalFile(const QString &localFile)
QDateTime toDateTime() const const
Describes a category: id/name/displayName.
Definition provider.h:112
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:20:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:20:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.