Move tag downloading to a separate slot instead of a lambda
If tag downloading is still in progress when the application is closed, it will try to access the instance's pointer, leading to a crash.
This commit is contained in:
parent
92613218e1
commit
114df7aa31
2 changed files with 36 additions and 33 deletions
|
@ -117,40 +117,8 @@ void DanbooruService::getTagList(int limit, QString name)
|
|||
|
||||
KIO::StoredTransferJob *job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::HideProgressInfo);
|
||||
connect(job, &KIO::StoredTransferJob::result, this, &DanbooruService::processTagList);
|
||||
|
||||
connect(job, &KIO::StoredTransferJob::result, [this](KJob * job) {
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
QByteArray data = jobResult->data();
|
||||
|
||||
bool ok;
|
||||
|
||||
// Most Danbooru implementations return tags in wrong order when
|
||||
// using JSON, so we have to fall back to XML
|
||||
QList<QVariant> tagList = parseDanbooruResult(data, "tag", &ok);
|
||||
|
||||
if (!ok) {
|
||||
Q_EMIT(downloadError(QString("Unable to decode data")));
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto element : tagList) {
|
||||
QVariantMap map = element.toMap();
|
||||
DanbooruTag *tag = new DanbooruTag(map);
|
||||
|
||||
if(!tag) {
|
||||
continue;
|
||||
}
|
||||
Q_EMIT(tagDownloaded(tag));
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void DanbooruService::getPool(int poolId, int page)
|
||||
|
@ -381,10 +349,44 @@ void DanbooruService::reset()
|
|||
{
|
||||
m_currentPage = 1;
|
||||
m_tags = QStringList();
|
||||
|
||||
}
|
||||
|
||||
// Slots
|
||||
|
||||
void DanbooruService::processTagList(KJob *job) {
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
QByteArray data = jobResult->data();
|
||||
|
||||
bool ok;
|
||||
|
||||
// Most Danbooru implementations return tags in wrong order when
|
||||
// using JSON, so we have to fall back to XML
|
||||
QList<QVariant> tagList = parseDanbooruResult(data, "tag", &ok);
|
||||
|
||||
if (!ok) {
|
||||
Q_EMIT(downloadError(QString("Unable to decode data")));
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto element : tagList) {
|
||||
QVariantMap map = element.toMap();
|
||||
DanbooruTag *tag = new DanbooruTag(map);
|
||||
|
||||
if(!tag) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Q_EMIT(tagDownloaded(tag));
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruService::processPostList(KJob *job)
|
||||
{
|
||||
|
||||
|
|
|
@ -283,6 +283,7 @@ public:
|
|||
|
||||
private Q_SLOTS:
|
||||
void processPostList(KJob *job);
|
||||
void processTagList(KJob *job);
|
||||
void downloadAllTags(KJob *job);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue