Start simplifying APIs
This commit is contained in:
		
					parent
					
						
							
								63d2dfdf9c
							
						
					
				
			
			
				commit
				
					
						f7f27699ca
					
				
			
		
					 13 changed files with 178 additions and 287 deletions
				
			
		| 
						 | 
					@ -13,7 +13,7 @@ set (libdanbooru_VERSION ${libdanbooru_VERSION_MAJOR}.${libdanbooru_VERSION_MINO
 | 
				
			||||||
set (libdanbooru_SRCS
 | 
					set (libdanbooru_SRCS
 | 
				
			||||||
     danboorupool.cpp
 | 
					     danboorupool.cpp
 | 
				
			||||||
     servicebase.cpp
 | 
					     servicebase.cpp
 | 
				
			||||||
     konachan.cpp
 | 
					     moebooru.cpp
 | 
				
			||||||
     danboorupost.cpp
 | 
					     danboorupost.cpp
 | 
				
			||||||
     danboorutag.cpp
 | 
					     danboorutag.cpp
 | 
				
			||||||
     utils.cpp
 | 
					     utils.cpp
 | 
				
			||||||
| 
						 | 
					@ -28,8 +28,3 @@ target_link_libraries(danbooru PUBLIC
 | 
				
			||||||
                      KF5::GuiAddons)
 | 
					                      KF5::GuiAddons)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
install(TARGETS danbooru ${INSTALL_TARGETS_DEFAULT_ARGS})
 | 
					install(TARGETS danbooru ${INSTALL_TARGETS_DEFAULT_ARGS})
 | 
				
			||||||
 | 
					 | 
				
			||||||
if (Qt5Test_FOUND)
 | 
					 | 
				
			||||||
    add_subdirectory(autotests)
 | 
					 | 
				
			||||||
    add_subdirectory(tests)
 | 
					 | 
				
			||||||
endif()
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,14 +33,29 @@ namespace Danbooru
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum ApiType {
 | 
					enum ApiType {
 | 
				
			||||||
    OriginalDanbooru = 16,
 | 
					    Danbooru = 16,
 | 
				
			||||||
    KonachanDanbooru = 32,
 | 
					    MoeBooru = 32,
 | 
				
			||||||
    Gelbooru = 64,
 | 
					    Gelbooru = 64,
 | 
				
			||||||
    Unknown = 128
 | 
					    Unknown = 128
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					enum Rating {
 | 
				
			||||||
 | 
					    Safe = 8192,
 | 
				
			||||||
 | 
					    Questionable = 16384,
 | 
				
			||||||
 | 
					    Explicit = 32768
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Q_DECLARE_FLAGS(Ratings, Rating)
 | 
				
			||||||
 | 
					Q_DECLARE_OPERATORS_FOR_FLAGS(Danbooru::Ratings)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace Danbooru
 | 
					} // namespace Danbooru
 | 
				
			||||||
Q_ENUMS(ApiType)
 | 
					
 | 
				
			||||||
 | 
					Q_ENUMS(Danbooru::ApiType)
 | 
				
			||||||
 | 
					Q_ENUMS(Danbooru::Rating)
 | 
				
			||||||
Q_DECLARE_METATYPE(Danbooru::ApiType)
 | 
					Q_DECLARE_METATYPE(Danbooru::ApiType)
 | 
				
			||||||
 | 
					Q_DECLARE_METATYPE(Danbooru::Ratings)
 | 
				
			||||||
 | 
					Q_DECLARE_METATYPE(Danbooru::Rating)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // DANBOORU_H
 | 
					#endif // DANBOORU_H
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,11 +19,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Qt
 | 
					// Qt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QtCore/QString>
 | 
					#include <QString>
 | 
				
			||||||
#include <QtGui/QPixmap>
 | 
					#include <QPixmap>
 | 
				
			||||||
 | 
					 | 
				
			||||||
// KDE
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <QUrl>
 | 
					#include <QUrl>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Own
 | 
					// Own
 | 
				
			||||||
| 
						 | 
					@ -33,94 +30,6 @@
 | 
				
			||||||
namespace Danbooru
 | 
					namespace Danbooru
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const QMap<QString, DanbooruPost::Rating> DanbooruPost::RATING_MAP = initRatingMap();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void DanbooruPost::parseDanbooruDonmai(const QVariantMap &postData) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // HACK: Handle XML (foo-bar) versus JSON (foo_bar) for attributes
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    auto tagString = postData.contains("tag_string") ? QLatin1String("tag_string"): QLatin1String("tag-string");
 | 
					 | 
				
			||||||
    auto width = postData.contains("image_width") ? QLatin1String("image_width"): QLatin1String("image-width");
 | 
					 | 
				
			||||||
    auto height = postData.contains("image_height") ? QLatin1String("image_height"): QLatin1String("image-height");
 | 
					 | 
				
			||||||
    auto fileSize = postData.contains("file_size") ? QLatin1String("file_size"): QLatin1String("file-size");
 | 
					 | 
				
			||||||
    auto fileUrl = postData.contains("file_url") ? QLatin1String("file_url"): QLatin1String("file-url");
 | 
					 | 
				
			||||||
    auto thumbnailUrl = postData.contains("preview_file_url") ? QLatin1String("preview_file_url"): QLatin1String("preview-file-url");
 | 
					 | 
				
			||||||
    auto sampleUrl = postData.contains("large_file_url") ? QLatin1String("large_file_url"): QLatin1String("large-file-url");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_id = postData.value("id").toString().toInt();
 | 
					 | 
				
			||||||
    m_tags = QSet<QString>::fromList(postData.value(tagString).toString().split(' '));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_width = postData.value(width).toString().toInt();
 | 
					 | 
				
			||||||
    m_height = postData.value(height).toString().toInt();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_url = postData.value(fileUrl).toUrl();
 | 
					 | 
				
			||||||
    m_thumbnailUrl = postData.value(thumbnailUrl).toUrl();
 | 
					 | 
				
			||||||
    m_size = postData.value(fileSize).toInt();
 | 
					 | 
				
			||||||
    m_rating = RATING_MAP.value(postData.value("rating").toString());
 | 
					 | 
				
			||||||
    m_sampleUrl = postData.value(sampleUrl).toUrl();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void DanbooruPost::parseDanbooruDonmai(const QXmlStreamAttributes &postData) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_tags = QSet<QString>::fromList(postData.value("tag_string").toString().split(' '));
 | 
					 | 
				
			||||||
    m_id = postData.value("id").toString().toInt();
 | 
					 | 
				
			||||||
    m_height = postData.value("image_height").toString().toInt();
 | 
					 | 
				
			||||||
    m_width = postData.value("image_width").toString().toInt();
 | 
					 | 
				
			||||||
    m_url = QUrl::fromUserInput(postData.value("file_url").toString());
 | 
					 | 
				
			||||||
    m_thumbnailUrl = QUrl::fromUserInput(postData.value("preview_file_url").toString());
 | 
					 | 
				
			||||||
    m_size = postData.value("file_size").toInt();
 | 
					 | 
				
			||||||
    m_rating = RATING_MAP.value(postData.value("rating").toString());
 | 
					 | 
				
			||||||
    m_sampleUrl = QUrl::fromUserInput(postData.value("large_file_url").toString());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // fixup for wrong URLs in danbooru input
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_url.setScheme("http");
 | 
					 | 
				
			||||||
    m_thumbnailUrl.setScheme("http");
 | 
					 | 
				
			||||||
    m_sampleUrl.setScheme("http");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void DanbooruPost::parseDanbooruKonachan(const QXmlStreamAttributes &postData) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_tags = QSet<QString>::fromList(postData.value("tags").toString().split(' '));
 | 
					 | 
				
			||||||
    m_id = postData.value("id").toString().toInt();
 | 
					 | 
				
			||||||
    m_height = postData.value("height").toString().toInt();
 | 
					 | 
				
			||||||
    m_width = postData.value("width").toString().toInt();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_url = QUrl::fromUserInput(postData.value("file_url").toString());
 | 
					 | 
				
			||||||
    m_thumbnailUrl = QUrl::fromUserInput(postData.value("preview_url").toString());
 | 
					 | 
				
			||||||
    m_sampleUrl = QUrl::fromUserInput(postData.value("sample_url").toString());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_size = postData.value("file_size").toString().toInt();
 | 
					 | 
				
			||||||
    m_rating = RATING_MAP.value(postData.value("rating").toString());
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void DanbooruPost::parseDanbooruKonachan(const QVariantMap &postData) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_tags = QSet<QString>::fromList(postData.value("tags").toString().split(' '));
 | 
					 | 
				
			||||||
    m_id = postData.value("id").toString().toInt();
 | 
					 | 
				
			||||||
    m_width =  postData.value("width").toString().toInt();
 | 
					 | 
				
			||||||
    m_height = postData.value("height").toString().toInt();
 | 
					 | 
				
			||||||
    m_url = postData.value("file_url").toUrl();
 | 
					 | 
				
			||||||
    m_thumbnailUrl = postData.value("preview_url").toUrl();
 | 
					 | 
				
			||||||
    m_size = postData.value("file_size").toInt();
 | 
					 | 
				
			||||||
    m_rating = RATING_MAP.value(postData.value("rating").toString());
 | 
					 | 
				
			||||||
    m_sampleUrl = postData.value("sample_url").toUrl();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void DanbooruPost::parseGelbooru(const QVariantMap &postData) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_tags = QSet<QString>::fromList(postData.value("tags").toString().split(' '));
 | 
					 | 
				
			||||||
    m_id = postData.value("id").toString().toInt();
 | 
					 | 
				
			||||||
    m_height = postData.value("height").toString().toInt();
 | 
					 | 
				
			||||||
    m_width = postData.value("width").toString().toInt();
 | 
					 | 
				
			||||||
    m_url = postData.value("file_url").toUrl();
 | 
					 | 
				
			||||||
    m_thumbnailUrl = postData.value("preview_url").toUrl();
 | 
					 | 
				
			||||||
    m_size = 0; // No size information
 | 
					 | 
				
			||||||
    m_rating = RATING_MAP.value(postData.value("rating").toString());
 | 
					 | 
				
			||||||
    m_sampleUrl = postData.value("sample_url").toUrl();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
DanbooruPost::DanbooruPost(QObject *parent): QObject(parent)
 | 
					DanbooruPost::DanbooruPost(QObject *parent): QObject(parent)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    m_pixmap = QPixmap();
 | 
					    m_pixmap = QPixmap();
 | 
				
			||||||
| 
						 | 
					@ -133,81 +42,26 @@ DanbooruPost::DanbooruPost(QObject *parent): QObject(parent)
 | 
				
			||||||
    m_rating = Questionable;
 | 
					    m_rating = Questionable;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DanbooruPost::DanbooruPost(QVariantMap postData,Danbooru::ApiType apiType, QPixmap pixmap,
 | 
					DanbooruPost::DanbooruPost(QVariantMap postData, QObject *parent):
 | 
				
			||||||
                           QObject *parent):
 | 
					 | 
				
			||||||
    QObject(parent),
 | 
					    QObject(parent),
 | 
				
			||||||
    m_pixmap(pixmap)
 | 
					    m_pixmap(QPixmap())
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    m_tags = postData.value("tags").value< QSet<QString> >();
 | 
				
			||||||
    switch(apiType) {
 | 
					    m_height = postData.value("height").toInt();
 | 
				
			||||||
        case ApiType::KonachanDanbooru:
 | 
					    m_width = postData.value("width").toInt();
 | 
				
			||||||
            parseDanbooruKonachan(postData);
 | 
					    m_size = postData.value("size").toInt();
 | 
				
			||||||
            break;
 | 
					    m_url = postData.value("url").toUrl();
 | 
				
			||||||
        case ApiType::OriginalDanbooru:
 | 
					    m_thumbnailUrl = postData.value("thumbnailUrl").toUrl();
 | 
				
			||||||
            parseDanbooruDonmai(postData);
 | 
					    m_sampleUrl = postData.value("sampleUrl").toUrl();
 | 
				
			||||||
            break;
 | 
					    m_rating = postData.value("rating").value<Danbooru::Rating>();
 | 
				
			||||||
        case ApiType::Gelbooru:
 | 
					 | 
				
			||||||
            parseGelbooru(postData);
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        default:
 | 
					 | 
				
			||||||
            parseDanbooruKonachan(postData);
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// DanbooruPost::DanbooruPost(QVariantMap postData, QPixmap pixmap,
 | 
					DanbooruPost::DanbooruPost(QXmlStreamAttributes &postData, QObject *parent):
 | 
				
			||||||
//                            QObject *parent):
 | 
					 | 
				
			||||||
//     QObject(parent),
 | 
					 | 
				
			||||||
//     m_pixmap(pixmap)
 | 
					 | 
				
			||||||
// {
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//     m_tags = QSet<QString>::fromList(postData.value("tags").toString().split(' '));
 | 
					 | 
				
			||||||
//     m_id = postData.value("id").toString().toInt();
 | 
					 | 
				
			||||||
//     m_height = postData.value("height").toString().toInt();
 | 
					 | 
				
			||||||
//     m_width = postData.value("width").toString().toInt();
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//     m_url = postData.value("file_url").toUrl();
 | 
					 | 
				
			||||||
//     m_thumbnailUrl = postData.value("preview_url").toUrl();
 | 
					 | 
				
			||||||
//     m_size = postData.value("file_size").toInt();
 | 
					 | 
				
			||||||
//     m_rating = RATING_MAP.value(postData.value("rating").toString());
 | 
					 | 
				
			||||||
//     m_sampleUrl = postData.value("sample_url").toUrl();
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
DanbooruPost::DanbooruPost(QXmlStreamAttributes &postData, Danbooru::ApiType apiType, QPixmap pixmap, QObject *parent):
 | 
					 | 
				
			||||||
    QObject(parent),
 | 
					    QObject(parent),
 | 
				
			||||||
    m_pixmap(pixmap)
 | 
					    m_pixmap(QPixmap())
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch(apiType) {
 | 
					 | 
				
			||||||
        case ApiType::KonachanDanbooru:
 | 
					 | 
				
			||||||
            parseDanbooruKonachan(postData);
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        case ApiType::OriginalDanbooru:
 | 
					 | 
				
			||||||
            parseDanbooruDonmai(postData);
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        default:
 | 
					 | 
				
			||||||
            parseDanbooruKonachan(postData);
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
DanbooruPost::~DanbooruPost()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const QMap< QString, DanbooruPost::Rating > DanbooruPost::initRatingMap()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    QMap<QString, DanbooruPost::Rating> map;
 | 
					 | 
				
			||||||
    map.insert("s", Safe);
 | 
					 | 
				
			||||||
    map.insert("q", Questionable);
 | 
					 | 
				
			||||||
    map.insert("e", Explicit);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return map;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool DanbooruPost::operator==(const Danbooru::DanbooruPost &other)
 | 
					bool DanbooruPost::operator==(const Danbooru::DanbooruPost &other)
 | 
				
			||||||
| 
						 | 
					@ -290,7 +144,7 @@ const QUrl DanbooruPost::fileUrl() const
 | 
				
			||||||
    return m_url;
 | 
					    return m_url;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Danbooru::DanbooruPost::Rating DanbooruPost::rating() const
 | 
					Danbooru::Rating DanbooruPost::rating() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return m_rating;
 | 
					    return m_rating;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -74,22 +74,6 @@ class DanbooruPost : public QObject
 | 
				
			||||||
    Q_PROPERTY(QUrl thumbnailUrl READ thumbnailUrl)
 | 
					    Q_PROPERTY(QUrl thumbnailUrl READ thumbnailUrl)
 | 
				
			||||||
    Q_PROPERTY(QUrl sampleUrl READ sampleUrl)
 | 
					    Q_PROPERTY(QUrl sampleUrl READ sampleUrl)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @brief Ratings for a Danbooru item
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * A rating is how appropriate is an item for a general audience.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     **/
 | 
					 | 
				
			||||||
    enum Rating {
 | 
					 | 
				
			||||||
        Safe = 1, /**< Safe for the general public **/
 | 
					 | 
				
			||||||
        Questionable = 2, /**< Might contain hints of risqueness of violence **/
 | 
					 | 
				
			||||||
        Explicit = 4 /**< Explicit material **/
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    Q_DECLARE_FLAGS(Ratings, DanbooruPost::Rating)
 | 
					 | 
				
			||||||
    Q_ENUMS(Rating)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QPixmap m_pixmap;
 | 
					    QPixmap m_pixmap;
 | 
				
			||||||
| 
						 | 
					@ -105,19 +89,7 @@ private:
 | 
				
			||||||
    QUrl m_thumbnailUrl;
 | 
					    QUrl m_thumbnailUrl;
 | 
				
			||||||
    QUrl m_sampleUrl;
 | 
					    QUrl m_sampleUrl;
 | 
				
			||||||
    QSet<QString> m_tags;
 | 
					    QSet<QString> m_tags;
 | 
				
			||||||
    DanbooruPost::Rating  m_rating;
 | 
					    Danbooru::Rating  m_rating;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    static const QMap<QString, Rating> RATING_MAP;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Private functions
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    static const QMap< QString, Rating > initRatingMap();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    void parseDanbooruKonachan(const QVariantMap &postData);
 | 
					 | 
				
			||||||
    void parseDanbooruKonachan(const QXmlStreamAttributes &postData);
 | 
					 | 
				
			||||||
    void parseDanbooruDonmai(const QVariantMap &postData);
 | 
					 | 
				
			||||||
    void parseDanbooruDonmai(const QXmlStreamAttributes &postData);
 | 
					 | 
				
			||||||
    void parseGelbooru(const QVariantMap &postData);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -135,9 +107,7 @@ public:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     **/
 | 
					     **/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    explicit DanbooruPost(QVariantMap postData, Danbooru::ApiType apiType=ApiType::KonachanDanbooru,
 | 
					    explicit DanbooruPost(QVariantMap postData, QObject *parent=0);
 | 
				
			||||||
                          QPixmap pixmap = QPixmap(),
 | 
					 | 
				
			||||||
                          QObject *parent=0);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    explicit DanbooruPost(QObject *parent = 0);
 | 
					    explicit DanbooruPost(QObject *parent = 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -155,8 +125,7 @@ public:
 | 
				
			||||||
     * @param parent A pointer to the parent QObject.
 | 
					     * @param parent A pointer to the parent QObject.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     **/
 | 
					     **/
 | 
				
			||||||
    explicit DanbooruPost(QXmlStreamAttributes &postData, Danbooru::ApiType apiType=ApiType::KonachanDanbooru,
 | 
					    explicit DanbooruPost(QXmlStreamAttributes &postData, QObject *parent = 0);
 | 
				
			||||||
                          QPixmap pixmap = QPixmap(),  QObject *parent = 0);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool operator==(const DanbooruPost &);
 | 
					    bool operator==(const DanbooruPost &);
 | 
				
			||||||
| 
						 | 
					@ -251,12 +220,9 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(DanbooruPost::Ratings)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
} // namespace Danbooru
 | 
					} // namespace Danbooru
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Q_DECLARE_METATYPE(Danbooru::DanbooruPost *)
 | 
					Q_DECLARE_METATYPE(Danbooru::DanbooruPost *)
 | 
				
			||||||
Q_DECLARE_METATYPE(Danbooru::DanbooruPost::Rating)
 | 
					 | 
				
			||||||
Q_DECLARE_METATYPE(QSet<QString>)
 | 
					Q_DECLARE_METATYPE(QSet<QString>)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // DANBOORUPOST_H
 | 
					#endif // DANBOORUPOST_H
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -90,7 +90,7 @@ private:
 | 
				
			||||||
    QString m_username;
 | 
					    QString m_username;
 | 
				
			||||||
    QString m_password;
 | 
					    QString m_password;
 | 
				
			||||||
    QSet<QString> m_blacklist;
 | 
					    QSet<QString> m_blacklist;
 | 
				
			||||||
    DanbooruPost::Ratings m_maxRating;
 | 
					    Danbooru::Ratings m_maxRating;
 | 
				
			||||||
    int m_maxPosts;
 | 
					    int m_maxPosts;
 | 
				
			||||||
    int m_currentPage;
 | 
					    int m_currentPage;
 | 
				
			||||||
    QStringList m_tags;
 | 
					    QStringList m_tags;
 | 
				
			||||||
| 
						 | 
					@ -180,7 +180,7 @@ public:
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @return The maximum allowed rating for a post.
 | 
					     * @return The maximum allowed rating for a post.
 | 
				
			||||||
     **/
 | 
					     **/
 | 
				
			||||||
    const DanbooruPost::Ratings maximumAllowedRating() const;
 | 
					    const Danbooru::Ratings maximumAllowedRating() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @return The currently blacklisted tags.
 | 
					     * @return The currently blacklisted tags.
 | 
				
			||||||
| 
						 | 
					@ -238,7 +238,7 @@ public:
 | 
				
			||||||
     * downloaded.
 | 
					     * downloaded.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     **/
 | 
					     **/
 | 
				
			||||||
    void setMaximumAllowedRating(DanbooruPost::Rating rating);
 | 
					    void setMaximumAllowedRating(Danbooru::Rating rating);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @brief Set the board URL to connect to.
 | 
					     * @brief Set the board URL to connect to.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,7 +17,7 @@
 | 
				
			||||||
 * along with Danbooru Client. If not, see <http://www.gnu.org/licenses/>.
 | 
					 * along with Danbooru Client. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "konachan.h"
 | 
					#include "moebooru.h"
 | 
				
			||||||
#include "danboorupost.h"
 | 
					#include "danboorupost.h"
 | 
				
			||||||
#include "danboorupool.h"
 | 
					#include "danboorupool.h"
 | 
				
			||||||
#include "danboorutag.h"
 | 
					#include "danboorutag.h"
 | 
				
			||||||
| 
						 | 
					@ -66,19 +66,9 @@ const QLatin1String KonachanDanbooruService::relatedTagUri() const {
 | 
				
			||||||
// Other methods
 | 
					// Other methods
 | 
				
			||||||
////////////////
 | 
					////////////////
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DanbooruServiceBase::SupportedOperations KonachanDanbooruService::supportedOperations() const {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return SupportedOperations(DanbooruServiceBase::PostDownload | DanbooruServiceBase::PoolDownload |
 | 
					 | 
				
			||||||
           DanbooruServiceBase::TagDownload | DanbooruServiceBase::TagSearch |
 | 
					 | 
				
			||||||
           DanbooruServiceBase::RelatedTagSearch);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
Danbooru::ApiType KonachanDanbooruService::apiType() const {
 | 
					Danbooru::ApiType KonachanDanbooruService::apiType() const {
 | 
				
			||||||
    return Danbooru::ApiType::KonachanDanbooru;
 | 
					    return Danbooru::ApiType::MoeBooru;
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
KonachanDanbooruService::~KonachanDanbooruService() {
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//////////////
 | 
					//////////////
 | 
				
			||||||
| 
						 | 
					@ -42,9 +42,8 @@ private:
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   using DanbooruServiceBase::DanbooruServiceBase; // superclass constructor
 | 
					   using DanbooruServiceBase::DanbooruServiceBase; // superclass constructor
 | 
				
			||||||
   ~KonachanDanbooruService() override;
 | 
					   ~KonachanDanbooruService() override = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   SupportedOperations supportedOperations() const override;
 | 
					 | 
				
			||||||
   Danbooru::ApiType apiType() const override;
 | 
					   Danbooru::ApiType apiType() const override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   void getPostList() override;
 | 
					   void getPostList() override;
 | 
				
			||||||
| 
						 | 
					@ -22,37 +22,32 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Danbooru {
 | 
					namespace Danbooru {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DanbooruServiceBase::DanbooruServiceBase(QUrl boardUrl, QString username,
 | 
					DanbooruServiceBase::DanbooruServiceBase(QUrl boardUrl, QObject* parent):
 | 
				
			||||||
                                 QString password, KImageCache *cache,
 | 
					 | 
				
			||||||
                                 QObject *parent):
 | 
					 | 
				
			||||||
    QObject(parent),
 | 
					    QObject(parent),
 | 
				
			||||||
    m_url(boardUrl),
 | 
					    m_url(boardUrl),
 | 
				
			||||||
    m_username(username),
 | 
					    m_username(QString()),
 | 
				
			||||||
    m_password(password),
 | 
					    m_password(QString()),
 | 
				
			||||||
    m_maxRating(Danbooru::DanbooruPost::Safe),
 | 
					    m_maxRating(Danbooru::Safe),
 | 
				
			||||||
    m_maxPosts(10),
 | 
					    m_maxPosts(10),
 | 
				
			||||||
    m_currentPage(1),
 | 
					    m_currentPage(1),
 | 
				
			||||||
    m_tags(QStringList()),
 | 
					    m_tags(QStringList()),
 | 
				
			||||||
    m_postsToFetch(0),
 | 
					    m_postsToFetch(0)
 | 
				
			||||||
    m_cache(cache){
 | 
					    {
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
DanbooruServiceBase::~DanbooruServiceBase() {
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const QStringList DanbooruServiceBase::allowedRatings() const {
 | 
					const QStringList DanbooruServiceBase::allowedRatings() const {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QStringList ratings;
 | 
					    QStringList ratings;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (m_maxRating.testFlag(DanbooruPost::Safe)) {
 | 
					    if (m_maxRating.testFlag(Danbooru::Safe)) {
 | 
				
			||||||
        ratings.append("Safe");
 | 
					        ratings.append("Safe");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (m_maxRating.testFlag(DanbooruPost::Questionable)) {
 | 
					    if (m_maxRating.testFlag(Danbooru::Questionable)) {
 | 
				
			||||||
        ratings.append("Questionable");
 | 
					        ratings.append("Questionable");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (m_maxRating.testFlag(DanbooruPost::Explicit)) {
 | 
					    if (m_maxRating.testFlag(Danbooru::Explicit)) {
 | 
				
			||||||
        ratings.append("Explicit");
 | 
					        ratings.append("Explicit");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -74,7 +69,7 @@ int DanbooruServiceBase::currentPage() const
 | 
				
			||||||
    return m_currentPage;
 | 
					    return m_currentPage;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const DanbooruPost::Ratings DanbooruServiceBase::maximumAllowedRating() const
 | 
					const Danbooru::Ratings DanbooruServiceBase::maximumAllowedRating() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return m_maxRating;
 | 
					    return m_maxRating;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -151,19 +146,19 @@ void DanbooruServiceBase::setImageCache(KImageCache *cache)
 | 
				
			||||||
    m_cache = cache;
 | 
					    m_cache = cache;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DanbooruServiceBase::setMaximumAllowedRating(DanbooruPost::Rating rating)
 | 
					void DanbooruServiceBase::setMaximumAllowedRating(Danbooru::Rating rating)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    DanbooruPost::Ratings flags;
 | 
					    Danbooru::Ratings flags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch (rating) {
 | 
					    switch (rating) {
 | 
				
			||||||
    case DanbooruPost::Safe:
 | 
					    case Danbooru::Safe:
 | 
				
			||||||
        flags = DanbooruPost::Safe;
 | 
					        flags = Danbooru::Safe;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    case DanbooruPost::Questionable:
 | 
					    case Danbooru::Questionable:
 | 
				
			||||||
        flags = DanbooruPost::Safe | DanbooruPost::Questionable;
 | 
					        flags = Danbooru::Safe | Danbooru::Questionable;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    case DanbooruPost::Explicit:
 | 
					    case Danbooru::Explicit:
 | 
				
			||||||
        flags = DanbooruPost::Safe | DanbooruPost::Questionable | DanbooruPost::Explicit;
 | 
					        flags = Danbooru::Safe | Danbooru::Questionable | Danbooru::Explicit;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,7 +66,7 @@ protected:
 | 
				
			||||||
    QString m_username;
 | 
					    QString m_username;
 | 
				
			||||||
    QString m_password;
 | 
					    QString m_password;
 | 
				
			||||||
    QSet<QString> m_blacklist;
 | 
					    QSet<QString> m_blacklist;
 | 
				
			||||||
    DanbooruPost::Ratings m_maxRating;
 | 
					    Danbooru::Ratings m_maxRating;
 | 
				
			||||||
    int m_maxPosts;
 | 
					    int m_maxPosts;
 | 
				
			||||||
    int m_currentPage;
 | 
					    int m_currentPage;
 | 
				
			||||||
    QStringList m_tags;
 | 
					    QStringList m_tags;
 | 
				
			||||||
| 
						 | 
					@ -77,29 +77,17 @@ protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    enum SupportedOperation {
 | 
					 | 
				
			||||||
        PostDownload = 256,
 | 
					 | 
				
			||||||
        TagDownload = 512,
 | 
					 | 
				
			||||||
        TagSearch = 1024,
 | 
					 | 
				
			||||||
        PoolDownload = 2048,
 | 
					 | 
				
			||||||
        RelatedTagSearch = 4096
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum ApiType {
 | 
					enum ApiType {
 | 
				
			||||||
    OriginalDanbooru = 16,
 | 
					    OriginalDanbooru = 16,
 | 
				
			||||||
    KonachanDanbooru = 32,
 | 
					    MoeBooru = 32,
 | 
				
			||||||
    Gelbooru = 64,
 | 
					    Gelbooru = 64,
 | 
				
			||||||
    Unknown = 128
 | 
					    Unknown = 128
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Q_DECLARE_FLAGS(ApiTypes, DanbooruServiceBase::ApiType)
 | 
					Q_DECLARE_FLAGS(ApiTypes, DanbooruServiceBase::ApiType)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    explicit DanbooruServiceBase(QUrl boardUrl = QUrl(), QObject* parent=nullptr);
 | 
				
			||||||
Q_DECLARE_FLAGS(SupportedOperations, DanbooruServiceBase::SupportedOperation)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    explicit DanbooruServiceBase(QUrl boardUrl = QUrl(), QString username = QString(),
 | 
					 | 
				
			||||||
                    QString password = QString(), KImageCache *cache = 0,
 | 
					 | 
				
			||||||
                    QObject *parent = 0);
 | 
					 | 
				
			||||||
    virtual ~DanbooruServiceBase();
 | 
					    virtual ~DanbooruServiceBase();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /////////////////////////////////////////////
 | 
					    /////////////////////////////////////////////
 | 
				
			||||||
| 
						 | 
					@ -145,7 +133,7 @@ Q_DECLARE_FLAGS(SupportedOperations, DanbooruServiceBase::SupportedOperation)
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @return The maximum allowed rating for a post.
 | 
					     * @return The maximum allowed rating for a post.
 | 
				
			||||||
     **/
 | 
					     **/
 | 
				
			||||||
    const DanbooruPost::Ratings maximumAllowedRating() const;
 | 
					    const Danbooru::Ratings maximumAllowedRating() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @return The number of posts downloaded for each page (max 100)
 | 
					     * @return The number of posts downloaded for each page (max 100)
 | 
				
			||||||
| 
						 | 
					@ -174,11 +162,6 @@ Q_DECLARE_FLAGS(SupportedOperations, DanbooruServiceBase::SupportedOperation)
 | 
				
			||||||
     **/
 | 
					     **/
 | 
				
			||||||
    void reset();
 | 
					    void reset();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @return The operations supported by the API.
 | 
					 | 
				
			||||||
     **/
 | 
					 | 
				
			||||||
    virtual SupportedOperations supportedOperations() const = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ///////////////////////////////
 | 
					    ///////////////////////////////
 | 
				
			||||||
    // Common setters (non-virtual)
 | 
					    // Common setters (non-virtual)
 | 
				
			||||||
    ///////////////////////////////
 | 
					    ///////////////////////////////
 | 
				
			||||||
| 
						 | 
					@ -228,7 +211,7 @@ Q_DECLARE_FLAGS(SupportedOperations, DanbooruServiceBase::SupportedOperation)
 | 
				
			||||||
     * downloaded.
 | 
					     * downloaded.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     **/
 | 
					     **/
 | 
				
			||||||
    void setMaximumAllowedRating(DanbooruPost::Rating rating);
 | 
					    void setMaximumAllowedRating(Danbooru::Rating rating);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @brief Set the maximum number of posts to download for each page.
 | 
					     * @brief Set the maximum number of posts to download for each page.
 | 
				
			||||||
| 
						 | 
					@ -383,6 +366,5 @@ Q_SIGNALS:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Danbooru::DanbooruServiceBase::SupportedOperations)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -44,6 +44,20 @@ namespace {
 | 
				
			||||||
namespace Danbooru
 | 
					namespace Danbooru
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					static const QMap<QString, Rating> RATING_MAP = initRatingMap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const QMap< QString, Danbooru::Rating > initRatingMap()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    QMap<QString, Danbooru::Rating> map;
 | 
				
			||||||
 | 
					    map.insert("s", Safe);
 | 
				
			||||||
 | 
					    map.insert("q", Questionable);
 | 
				
			||||||
 | 
					    map.insert("e", Explicit);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QUrl requestUrl(QUrl &url, const QString &path,
 | 
					QUrl requestUrl(QUrl &url, const QString &path,
 | 
				
			||||||
                const QString &username, const QString &password,
 | 
					                const QString &username, const QString &password,
 | 
				
			||||||
                const dictMap ¶meters, const QStringList &tags)
 | 
					                const dictMap ¶meters, const QStringList &tags)
 | 
				
			||||||
| 
						 | 
					@ -133,7 +147,7 @@ QList< QVariant > parseDanbooruResult(QByteArray data, QString xlmElement, bool
 | 
				
			||||||
    reader.addData(data);
 | 
					    reader.addData(data);
 | 
				
			||||||
    QList<QVariant> postData;
 | 
					    QList<QVariant> postData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (apiType != ApiType::OriginalDanbooru) {
 | 
					    if (apiType != ApiType::Danbooru) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while (!reader.atEnd() && !reader.hasError()) {
 | 
					        while (!reader.atEnd() && !reader.hasError()) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -212,7 +226,7 @@ QVariant parseDanbooruResult(QByteArray data, bool *result)
 | 
				
			||||||
    return postData;
 | 
					    return postData;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating)
 | 
					bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, Danbooru::Ratings maxRating)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (post->rating() > maxRating) {
 | 
					    if (post->rating() > maxRating) {
 | 
				
			||||||
| 
						 | 
					@ -243,4 +257,82 @@ void fixPostUrl(DanbooruPost *post, QUrl boardUrl) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QVariantMap parseResult(const QByteArray &data, ApiType type) {
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    QVariantMap map;
 | 
				
			||||||
 | 
					    bool result;
 | 
				
			||||||
 | 
					    QVariantMap mapped = parseDanbooruResult(data, &result).toMap();
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if (!result) {
 | 
				
			||||||
 | 
					        return QVariantMap();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    int id;
 | 
				
			||||||
 | 
					    QSet<QString> tags;
 | 
				
			||||||
 | 
					    int width;
 | 
				
			||||||
 | 
					    int height;
 | 
				
			||||||
 | 
					    int fileSize;
 | 
				
			||||||
 | 
					    QUrl url;
 | 
				
			||||||
 | 
					    QUrl thumbnailUrl;
 | 
				
			||||||
 | 
					    QUrl sampleUrl;
 | 
				
			||||||
 | 
					    Danbooru::Rating rating;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    switch(type) {
 | 
				
			||||||
 | 
					        case Danbooru::MoeBooru:
 | 
				
			||||||
 | 
					            tags = QSet<QString>::fromList(mapped.value("tags").toString().split(' '));
 | 
				
			||||||
 | 
					            id = mapped.value("id").toString().toInt();
 | 
				
			||||||
 | 
					            height = mapped.value("height").toString().toInt();
 | 
				
			||||||
 | 
					            width = mapped.value("width").toString().toInt();
 | 
				
			||||||
 | 
					            url = QUrl::fromUserInput(mapped.value("file_url").toString());
 | 
				
			||||||
 | 
					            thumbnailUrl = QUrl::fromUserInput(mapped.value("preview_url").toString());
 | 
				
			||||||
 | 
					            sampleUrl = QUrl::fromUserInput(mapped.value("sample_url").toString());
 | 
				
			||||||
 | 
					            rating = RATING_MAP.value(mapped.value("rating").toString());
 | 
				
			||||||
 | 
					            fileSize = mapped.value("file_size").toInt();
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        case Danbooru::Gelbooru:
 | 
				
			||||||
 | 
					            id = 0;
 | 
				
			||||||
 | 
					            tags = QSet<QString>();
 | 
				
			||||||
 | 
					            width = 0;
 | 
				
			||||||
 | 
					            height = 0;
 | 
				
			||||||
 | 
					            fileSize = 0;
 | 
				
			||||||
 | 
					            url = QUrl();
 | 
				
			||||||
 | 
					            thumbnailUrl = QUrl();
 | 
				
			||||||
 | 
					            sampleUrl = QUrl();
 | 
				
			||||||
 | 
					            rating = Danbooru::Safe;
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        default:
 | 
				
			||||||
 | 
					            auto tagKey = mapped.contains("tag_string") ? QLatin1String("tag_string"): QLatin1String("tag-string");
 | 
				
			||||||
 | 
					            auto widthKey = mapped.contains("image_width") ? QLatin1String("image_width"): QLatin1String("image-width");
 | 
				
			||||||
 | 
					            auto heightKey = mapped.contains("image_height") ? QLatin1String("image_height"): QLatin1String("image-height");
 | 
				
			||||||
 | 
					            auto fileSizeKey = mapped.contains("file_size") ? QLatin1String("file_size"): QLatin1String("file-size");
 | 
				
			||||||
 | 
					            auto fileUrlKey = mapped.contains("file_url") ? QLatin1String("file_url"): QLatin1String("file-url");
 | 
				
			||||||
 | 
					            auto thumbnailUrlKey = mapped.contains("preview_file_url") ? QLatin1String("preview_file_url"): QLatin1String("preview-file-url");
 | 
				
			||||||
 | 
					            auto sampleUrlKey = mapped.contains("large_file_url") ? QLatin1String("large_file_url"): QLatin1String("large-file-url");
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					           id = mapped.value("id").toString().toInt();
 | 
				
			||||||
 | 
					           tags = QSet<QString>::fromList(mapped.value(tagKey).toString().split(' '));
 | 
				
			||||||
 | 
					           width = mapped.value(widthKey).toString().toInt();
 | 
				
			||||||
 | 
					           height = mapped.value(heightKey).toString().toInt();
 | 
				
			||||||
 | 
					           url = mapped.value(fileUrlKey).toUrl();
 | 
				
			||||||
 | 
					           thumbnailUrl = mapped.value(thumbnailUrlKey).toUrl();
 | 
				
			||||||
 | 
					           fileSize = mapped.value(fileSizeKey).toInt();
 | 
				
			||||||
 | 
					           rating = RATING_MAP.value(mapped.value("rating").toString());
 | 
				
			||||||
 | 
					           sampleUrl = mapped.value(sampleUrlKey).toUrl();
 | 
				
			||||||
 | 
					           break;
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    map.insert(QLatin1String("width"), width);
 | 
				
			||||||
 | 
					    map.insert(QLatin1String("height"), height);
 | 
				
			||||||
 | 
					    map.insert(QLatin1String("id"), id);
 | 
				
			||||||
 | 
					    map.insert(QLatin1String("url"), url);
 | 
				
			||||||
 | 
					    map.insert(QLatin1String("thumbnailUrl"), url);
 | 
				
			||||||
 | 
					    map.insert(QLatin1String("sampleUrl"), sampleUrl);
 | 
				
			||||||
 | 
					    map.insert(QLatin1String("rating"), rating);
 | 
				
			||||||
 | 
					    map.insert(QLatin1String("size"), fileSize);
 | 
				
			||||||
 | 
					    map.insert(QLatin1String("tags"), QVariant::fromValue(tags));
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					    return(map);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace Danbooru
 | 
					} // namespace Danbooru
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,12 +24,11 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Qt
 | 
					// Qt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QtCore/QStringList>
 | 
					#include <QStringList>
 | 
				
			||||||
 | 
					#include <QVariantMap>
 | 
				
			||||||
// KDE
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <QUrl>
 | 
					#include <QUrl>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @brief Commmon utilities for Danbooru classes.
 | 
					 * @brief Commmon utilities for Danbooru classes.
 | 
				
			||||||
 * @file utils.h
 | 
					 * @file utils.h
 | 
				
			||||||
| 
						 | 
					@ -102,7 +101,7 @@ QUrl requestUrl(QUrl &url, const QString &path, const QString &username,
 | 
				
			||||||
                const QString &password);
 | 
					                const QString &password);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QList<QVariant> parseDanbooruResult(QByteArray data, QString xlmElement,
 | 
					QList<QVariant> parseDanbooruResult(QByteArray data, QString xlmElement,
 | 
				
			||||||
                                    bool *result, ApiType=ApiType::KonachanDanbooru);
 | 
					                                    bool *result, ApiType=ApiType::MoeBooru);
 | 
				
			||||||
QVariant parseDanbooruResult(QByteArray data, bool *result);
 | 
					QVariant parseDanbooruResult(QByteArray data, bool *result);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -117,11 +116,15 @@ QVariant parseDanbooruResult(QByteArray data, bool *result);
 | 
				
			||||||
 * @return true if the post is unwanted, false otherwise.
 | 
					 * @return true if the post is unwanted, false otherwise.
 | 
				
			||||||
 * @author Luca Beltrame (lbeltrame@kde.org)
 | 
					 * @author Luca Beltrame (lbeltrame@kde.org)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating);
 | 
					bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, Danbooru::Ratings maxRating);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void fixPostUrl(DanbooruPost *post, QUrl boardUrl);
 | 
					void fixPostUrl(DanbooruPost *post, QUrl boardUrl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QVariantMap parseResult(const QByteArray &data, Danbooru::ApiType type);
 | 
				
			||||||
 | 
					QVariantMap parseResult(const QXmlStreamAttributes &data, Danbooru::ApiType type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const QMap< QString, Danbooru::Rating > initRatingMap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // UTILS_H
 | 
					#endif // UTILS_H
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -71,10 +71,10 @@
 | 
				
			||||||
namespace Danbooru
 | 
					namespace Danbooru
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QHash<int, DanbooruPost::Rating> DanbooruMainWindow::ratingMap = {
 | 
					QHash<int, Danbooru::Rating> DanbooruMainWindow::ratingMap = {
 | 
				
			||||||
    {0, DanbooruPost::Safe},
 | 
					    {0, Danbooru::Safe},
 | 
				
			||||||
    {1, DanbooruPost::Questionable},
 | 
					    {1, Danbooru::Questionable},
 | 
				
			||||||
    {2, DanbooruPost::Explicit}
 | 
					    {2, Danbooru::Explicit}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
 | 
					DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
 | 
				
			||||||
| 
						 | 
					@ -99,7 +99,7 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    qmlRegisterType<Danbooru::DanbooruPost>("DanbooruClient", 1, 0, "DanbooruPost");
 | 
					    qmlRegisterType<Danbooru::DanbooruPost>("DanbooruClient", 1, 0, "DanbooruPost");
 | 
				
			||||||
    qmlRegisterType<Danbooru::DanbooruService>("DanbooruClient", 1, 0, "DanbooruService");
 | 
					    qmlRegisterType<Danbooru::DanbooruService>("DanbooruClient", 1, 0, "DanbooruService");
 | 
				
			||||||
    qRegisterMetaType<DanbooruPost::Rating>();
 | 
					    qRegisterMetaType<Danbooru::Rating>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    loadSettings();
 | 
					    loadSettings();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -72,7 +72,7 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QTableView *m_tableView;
 | 
					    QTableView *m_tableView;
 | 
				
			||||||
    KImageCache *m_cache;
 | 
					    KImageCache *m_cache;
 | 
				
			||||||
    static QHash<int, DanbooruPost::Rating> ratingMap;
 | 
					    static QHash<int, Danbooru::Rating> ratingMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue