WIP, Konachan API implementation

This commit is contained in:
Luca Beltrame 2015-08-22 20:02:17 +02:00
parent 0c18e639a9
commit 08498f5ee2
2 changed files with 147 additions and 0 deletions

View file

@ -0,0 +1,87 @@
/*
* Copyright 2015 Luca Beltrame <lbeltrame@kde.org>
*
* This file is part of Danbooru Client.
*
* Danbooru Client is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Danbooru Client is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Danbooru Client. If not, see <http://www.gnu.org/licenses/>.
*/
#include "konachan.h"
#include "danboorupost.h"
#include "danboorupool.h"
#include "danboorutag.h"
#include "utils.h"
// KF5
#include <KIO/Job>
#include <KIO/Scheduler>
#include <KImageCache>
namespace Danbooru {
///////
// URIs
///////
const QLatin1String KonachanDanbooruService::postUri() const {
return QLatin1String("post/index.json");
}
const QLatin1String KonachanDanbooruService::poolUri() const {
return QLatin1String("pool/index.json");
}
const QLatin1String KonachanDanbooruService::artistUri() const {
return QLatin1String("artist/index.json");
}
const QLatin1String KonachanDanbooruService::tagUri() const {
return QLatin1String("tag/index.xml");
}
const QLatin1String KonachanDanbooruService::poolDataUri() const {
return QLatin1String("pool/show.xml");
}
const QLatin1String KonachanDanbooruService::relatedTagUri() const {
return QLatin1String("tag/related.json");
}
void KonachanDanbooruService::getPostList() {
// We can't fetch more than 100 items, API limitation
QMap<QString, QString> parameters;
parameters.insert("limit", QString::number(m_maxPosts));
parameters.insert("page", QString::number(m_currentPage));
QUrl danbooruUrl = requestUrl(m_url, POST_URL, m_username,
m_password, parameters, m_tags);
// qCDebug(LIBDANBOORU) << "Final constructed post URL" << danbooruUrl;
KIO::StoredTransferJob *job = KIO::storedGet(danbooruUrl, KIO::NoReload,
KIO::HideProgressInfo);
// This job can use JSON data
job->setProperty("needsXML", false);
connect(job, &KIO::StoredTransferJob::result, this, &KonachanDanbooruService::processPostList);
}
} //namespace Danbooru

View file

@ -0,0 +1,60 @@
/*
* Copyright 2015 Luca Beltrame <lbeltrame@kde.org>
*
* This file is part of Danbooru Client.
*
* Danbooru Client is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Danbooru Client is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Danbooru Client. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DANBOORU_KONACHAN_H
#define DANBOORU_KONACHAN_H
#include "servicebase.h"
#include "danbooru.h"
class KJob;
namespace Danbooru {
class KonachanDanbooruService: public DanbooruServiceBase {
Q_OBJECT
private:
const QLatin1String postUri() const override;
const QLatin1String poolUri() const override;
const QLatin1String artistUri() const override;
const QLatin1String tagUri() const override;
const QLatin1String poolDataUri() const override;
const QLatin1String relatedTagUri() const override;
public:
using DanbooruServiceBase::DanbooruServiceBase; // superclass constructor
~KonachanDanbooruService() override;
void getPostList() override;
void getPoolList() override;
private Q_SLOTS:
void processPostList(KJob *job);
void processTagList(KJob *job);
void downloadAllTags(KJob *job);
};
} // namespace Danbooru
#endif