Implement all common methods

This commit is contained in:
Luca Beltrame 2015-08-22 18:21:50 +02:00
parent 4547000491
commit 0c18e639a9

View file

@ -1 +1,186 @@
/*
* 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 "servicebase.h"
namespace Danbooru {
const QStringList DanbooruServiceBase::allowedRatings() const {
QStringList ratings;
if (m_maxRating.testFlag(DanbooruPost::Safe)) {
ratings.append("Safe");
}
if (m_maxRating.testFlag(DanbooruPost::Questionable)) {
ratings.append("Questionable");
}
if (m_maxRating.testFlag(DanbooruPost::Explicit)) {
ratings.append("Explicit");
}
return ratings;
}
Danbooru::ApiType DanbooruServiceBase::apiType() const {
return Danbooru::ApiType::Unknown;
}
const QSet< QString > DanbooruServiceBase::blacklist() const
{
return m_blacklist;
}
int DanbooruServiceBase::currentPage() const
{
return m_currentPage;
}
const DanbooruPost::Ratings DanbooruServiceBase::maximumAllowedRating() const
{
return m_maxRating;
}
int DanbooruServiceBase::maxPosts() const
{
return m_maxPosts;
}
void DanbooruServiceBase::nextPostPage()
{
m_currentPage++;
getPostList();
}
void DanbooruServiceBase::nextPoolPage()
{
m_currentPage++;
getPoolList();
}
QStringList DanbooruServiceBase::postTags() const
{
return m_tags;
}
void DanbooruServiceBase::reset()
{
m_currentPage = 1;
m_tags = QStringList();
}
//////////
// Setters
//////////
void DanbooruServiceBase::setBlacklist(const QSet< QString > &blacklist)
{
if (!blacklist.isEmpty()) {
m_blacklist = blacklist;
}
}
void DanbooruServiceBase::setBlacklist(const QStringList &blacklist)
{
if (blacklist.isEmpty()) {
return;
}
m_blacklist.clear();
for (auto element : blacklist) {
m_blacklist.insert(element);
}
}
void DanbooruServiceBase::setBoardUrl(const QUrl &url)
{
m_url = url;
}
void DanbooruServiceBase::setCurrentPage(int page)
{
m_currentPage = page;
}
void DanbooruServiceBase::setImageCache(KImageCache *cache)
{
m_cache = cache;
}
void DanbooruServiceBase::setMaximumAllowedRating(DanbooruPost::Rating rating)
{
DanbooruPost::Ratings flags;
switch (rating) {
case DanbooruPost::Safe:
flags = DanbooruPost::Safe;
break;
case DanbooruPost::Questionable:
flags = DanbooruPost::Safe | DanbooruPost::Questionable;
break;
case DanbooruPost::Explicit:
flags = DanbooruPost::Safe | DanbooruPost::Questionable | DanbooruPost::Explicit;
break;
}
m_maxRating = flags;
}
void DanbooruServiceBase::setMaxPosts(int number)
{
m_maxPosts = number < 100 ? number : 100;
}
void DanbooruServiceBase::setPassword(const QString &password)
{
if (password.isEmpty()) {
return;
}
m_password = password;
}
void DanbooruServiceBase::setPostTags(const QStringList &tags)
{
if (!tags.isEmpty()) {
m_tags = tags;
}
}
void DanbooruServiceBase::setUserName(const QString &username)
{
if (username.isEmpty()) {
return;
}
m_username = username;
}
} // namespace Danbooru