Commit 013048fe authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

applets/comic/engine: Refactor ComicProvider constructor take enum value instead of string

parent 1d607650
......@@ -26,7 +26,7 @@ static QString identifierToPath(const QString &identifier)
return dataDir + QString::fromLatin1(QUrl::toPercentEncoding(identifier));
}
CachedProvider::CachedProvider(QObject *parent, const KPluginMetaData &data, const QString &type, const QString &identifier)
CachedProvider::CachedProvider(QObject *parent, const KPluginMetaData &data, ComicProvider::IdentifierType type, const QString &identifier)
: ComicProvider(parent, data, type, identifier)
{
QTimer::singleShot(0, this, &CachedProvider::triggerFinished);
......
......@@ -26,7 +26,7 @@ public:
* @param parent The parent object.
* param args The arguments.
*/
explicit CachedProvider(QObject *parent, const KPluginMetaData &data, const QString &type, const QString &identifier);
explicit CachedProvider(QObject *parent, const KPluginMetaData &data, ComicProvider::IdentifierType type, const QString &identifier);
/**
* Destroys the cached provider.
......
......@@ -19,6 +19,7 @@
#include "cachedprovider.h"
#include "comic_debug.h"
#include "comicprovider.h"
#include "comicproviderkross.h"
ComicEngine::ComicEngine()
......@@ -87,7 +88,7 @@ bool ComicEngine::requestSource(const QString &identifier, ComicRequestCallback
// check whether it is cached, make sure second part present
if (parts.count() > 1 && CachedProvider::isCached(identifier)) {
ComicProvider *provider = new CachedProvider(this, KPluginMetaData{}, QStringLiteral("String"), identifier);
ComicProvider *provider = new CachedProvider(this, KPluginMetaData{}, ComicProvider::StringIdentifier, identifier);
m_jobs[identifier] = provider;
connect(provider, &ComicProvider::finished, this, [this, callback, provider]() {
finished(provider, callback);
......@@ -136,6 +137,7 @@ bool ComicEngine::requestSource(const QString &identifier, ComicRequestCallback
// const QString type = service->property(QLatin1String("X-KDE-PlasmaComicProvider-SuffixType"), QVariant::String).toString();
const QString type = pkg.metadata().value(QStringLiteral("X-KDE-PlasmaComicProvider-SuffixType"));
QVariant data;
ComicProvider::IdentifierType identifierType = ComicProvider::StringIdentifier;
if (type == QLatin1String("Date")) {
QDate date = QDate::fromString(parts[1], Qt::ISODate);
if (!date.isValid()) {
......@@ -143,12 +145,15 @@ bool ComicEngine::requestSource(const QString &identifier, ComicRequestCallback
}
data = date;
identifierType = ComicProvider::DateIdentifier;
} else if (type == QLatin1String("Number")) {
data = parts[1].toInt();
identifierType = ComicProvider::NumberIdentifier;
} else if (type == QLatin1String("String")) {
data = parts[1];
identifierType = ComicProvider::StringIdentifier;
}
provider = new ComicProviderKross(this, pkg.metadata(), type, data);
provider = new ComicProviderKross(this, pkg.metadata(), identifierType, data);
provider->setIsCurrent(isCurrentComic);
m_jobs[identifier] = provider;
......@@ -306,5 +311,3 @@ QString ComicEngine::lastCachedIdentifier(const QString &identifier) const
return previousIdentifier;
}
#include "comic.moc"
......@@ -79,21 +79,21 @@ public:
QHash<KJob *, QUrl> mRedirections;
};
ComicProvider::ComicProvider(QObject *parent, const KPluginMetaData &data, const QString &type, const QVariant &identifier)
ComicProvider::ComicProvider(QObject *parent, const KPluginMetaData &data, IdentifierType type, const QVariant &identifier)
: QObject(parent)
, d(new Private(this, data))
{
if (type == QLatin1String("Date")) {
if (type == DateIdentifier) {
d->mRequestedDate = identifier.toDate();
} else if (type == QLatin1String("Number")) {
} else if (type == NumberIdentifier) {
d->mRequestedNumber = identifier.toInt();
} else if (type == QLatin1String("String")) {
} else if (type == StringIdentifier) {
d->mRequestedId = identifier.toString();
int index = d->mRequestedId.indexOf(QLatin1Char(':'));
d->mRequestedComicName = d->mRequestedId.mid(0, index);
} else {
Q_ASSERT(false && "Invalid type passed to comic provider");
qFatal("Invalid type passed to comic provider");
}
d->mTimer->start();
......
......@@ -44,7 +44,7 @@ public:
* @param parent The parent object.
* @param args Arguments passed by the plugin loader.
*/
ComicProvider(QObject *parent, const KPluginMetaData &data, const QString &type, const QVariant &identifier);
ComicProvider(QObject *parent, const KPluginMetaData &data, IdentifierType type, const QVariant &identifier);
/**
* Destroys the comic provider.
......
......@@ -10,7 +10,7 @@
KPackage::PackageStructure *ComicProviderKross::m_packageStructure(nullptr);
ComicProviderKross::ComicProviderKross(QObject *parent, const KPluginMetaData &data, const QString &type, const QVariant &identifier)
ComicProviderKross::ComicProviderKross(QObject *parent, const KPluginMetaData &data, ComicProvider::IdentifierType type, const QVariant &identifier)
: ComicProvider(parent, data, type, identifier)
, m_wrapper(this)
{
......@@ -116,7 +116,3 @@ KPackage::PackageStructure *ComicProviderKross::packageStructure()
}
return m_packageStructure;
}
// K_PLUGIN_FACTORY_WITH_JSON(ComicProviderKrossFactory, "plasma-packagestructure-comic.json", registerPlugin<ComicProviderKross>();)
// #include "comicproviderkross.moc"
......@@ -20,7 +20,7 @@ class ComicProviderKross : public ComicProvider
Q_OBJECT
public:
ComicProviderKross(QObject *parent, const KPluginMetaData &data, const QString &type, const QVariant &identifier);
ComicProviderKross(QObject *parent, const KPluginMetaData &data, ComicProvider::IdentifierType type, const QVariant &identifier);
~ComicProviderKross() override;
static KPackage::PackageStructure *packageStructure();
......
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