Implement ratings, blacklists, add some const correctness
This commit is contained in:
		
					parent
					
						
							
								f442c2f605
							
						
					
				
			
			
				commit
				
					
						816b370302
					
				
			
		
					 2 changed files with 60 additions and 14 deletions
				
			
		| 
						 | 
					@ -36,13 +36,15 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Danbooru {
 | 
					namespace Danbooru {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const QMap<QString, Rating> DanbooruPost::RATING_MAP = initRatingMap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    DanbooruPost::DanbooruPost(QVariantMap postData, QPixmap* pixmap,
 | 
					    DanbooruPost::DanbooruPost(QVariantMap postData, QPixmap* pixmap,
 | 
				
			||||||
                               QObject* parent):
 | 
					                               QObject* parent):
 | 
				
			||||||
                               QObject(parent),
 | 
					                               QObject(parent),
 | 
				
			||||||
                               m_pixmap(pixmap)
 | 
					                               m_pixmap(pixmap)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        m_tags = postData.value("tags").toString().split(' ');
 | 
					        m_tags = QSet<QString>::fromList(postData.value("tags").toString().split(' '));
 | 
				
			||||||
        m_id = postData.value("id").toString().toInt();
 | 
					        m_id = postData.value("id").toString().toInt();
 | 
				
			||||||
        m_height = postData.value("height").toString().toInt();
 | 
					        m_height = postData.value("height").toString().toInt();
 | 
				
			||||||
        m_width = postData.value("width").toString().toInt();
 | 
					        m_width = postData.value("width").toString().toInt();
 | 
				
			||||||
| 
						 | 
					@ -50,6 +52,7 @@ namespace Danbooru {
 | 
				
			||||||
        m_url = KUrl(postData.value("file_url").toUrl() );
 | 
					        m_url = KUrl(postData.value("file_url").toUrl() );
 | 
				
			||||||
        m_thumbnailUrl = KUrl(postData.value("preview_url").toUrl());
 | 
					        m_thumbnailUrl = KUrl(postData.value("preview_url").toUrl());
 | 
				
			||||||
        m_size = postData.value("file_size").toInt();
 | 
					        m_size = postData.value("file_size").toInt();
 | 
				
			||||||
 | 
					        m_rating = RATING_MAP.value(postData.value("rating").toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -59,7 +62,16 @@ namespace Danbooru {
 | 
				
			||||||
                               QObject(parent),
 | 
					                               QObject(parent),
 | 
				
			||||||
                               m_pixmap(pixmap)
 | 
					                               m_pixmap(pixmap)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    Q_UNUSED(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 = KUrl(postData.value("file_url").toString());
 | 
				
			||||||
 | 
					    m_thumbnailUrl = KUrl(postData.value("preview_url").toString());
 | 
				
			||||||
 | 
					    m_size = postData.value("file_size").toString().toInt();
 | 
				
			||||||
 | 
					    m_rating = RATING_MAP.value(postData.value("rating").toString());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -69,13 +81,25 @@ namespace Danbooru {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const QMap< QString, Rating > DanbooruPost::initRatingMap()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        QMap<QString, 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)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return m_url == other.m_url && m_id == other.m_id;
 | 
					        return m_url == other.m_url && m_id == other.m_id;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void DanbooruPost::setPixmap(QPixmap* pixmap)
 | 
					    void DanbooruPost::setPixmap(const QPixmap* pixmap)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        m_pixmap = pixmap;
 | 
					        m_pixmap = pixmap;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -102,7 +126,7 @@ namespace Danbooru {
 | 
				
			||||||
        return m_width;
 | 
					        return m_width;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QStringList DanbooruPost::tags() const
 | 
					    const QSet< QString > DanbooruPost::tags() const
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return m_tags;
 | 
					        return m_tags;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -112,7 +136,7 @@ namespace Danbooru {
 | 
				
			||||||
        return m_thumbnailUrl;
 | 
					        return m_thumbnailUrl;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QPixmap* DanbooruPost::pixmap() const
 | 
					    const QPixmap* DanbooruPost::pixmap() const
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return m_pixmap;
 | 
					        return m_pixmap;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -127,6 +151,12 @@ namespace Danbooru {
 | 
				
			||||||
        return m_url;
 | 
					        return m_url;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const Ratings DanbooruPost::rating() const
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return m_rating;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace Danbooru
 | 
					} // namespace Danbooru
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * <one line to give the library's name and an idea of what it does.>
 | 
					 * This file is part of libdanbooru.
 | 
				
			||||||
 * Copyright 2013  Luca Beltrame <lbeltrame@kde.org>
 | 
					 * Copyright 2013  Luca Beltrame <lbeltrame@kde.org>
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software; you can redistribute it and/or
 | 
					 * This program is free software; you can redistribute it and/or
 | 
				
			||||||
| 
						 | 
					@ -33,14 +33,18 @@
 | 
				
			||||||
#include <QtCore/QObject>
 | 
					#include <QtCore/QObject>
 | 
				
			||||||
#include <QtCore/QVariant>
 | 
					#include <QtCore/QVariant>
 | 
				
			||||||
#include <QtCore/QStringList>
 | 
					#include <QtCore/QStringList>
 | 
				
			||||||
 | 
					#include <QtCore/QSet>
 | 
				
			||||||
#include <QtXml/QXmlStreamAttributes>
 | 
					#include <QtXml/QXmlStreamAttributes>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// KDE
 | 
					// KDE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <KUrl>
 | 
					#include <KUrl>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class QPixmap;
 | 
					// Own
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "danbooru.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class QPixmap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Danbooru {
 | 
					namespace Danbooru {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,15 +70,15 @@ namespace Danbooru {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Q_OBJECT
 | 
					    Q_OBJECT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Q_PROPERTY(QPixmap* pixmap READ pixmap WRITE setPixmap)
 | 
					    Q_PROPERTY(const QPixmap* pixmap READ pixmap WRITE setPixmap)
 | 
				
			||||||
    Q_PROPERTY(int id READ id)
 | 
					    Q_PROPERTY(int id READ id)
 | 
				
			||||||
    Q_PROPERTY(KUrl fileUrl READ fileUrl)
 | 
					    Q_PROPERTY(KUrl fileUrl READ fileUrl)
 | 
				
			||||||
    Q_PROPERTY(QStringList tags READ tags)
 | 
					    Q_PROPERTY(QSet<QString> tags READ tags)
 | 
				
			||||||
    Q_PROPERTY(KUrl thumbnailUrl READ thumbnailUrl)
 | 
					    Q_PROPERTY(KUrl thumbnailUrl READ thumbnailUrl)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private:
 | 
					    private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        QPixmap* m_pixmap;
 | 
					        const QPixmap* m_pixmap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // basic features of a post
 | 
					        // basic features of a post
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -85,7 +89,14 @@ namespace Danbooru {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        KUrl m_url;
 | 
					        KUrl m_url;
 | 
				
			||||||
        KUrl m_thumbnailUrl;
 | 
					        KUrl m_thumbnailUrl;
 | 
				
			||||||
        QStringList m_tags;
 | 
					        QSet<QString> m_tags;
 | 
				
			||||||
 | 
					        Ratings m_rating;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static const QMap<QString, Rating> RATING_MAP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Private functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static const QMap< QString, Rating > initRatingMap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -156,7 +167,7 @@ namespace Danbooru {
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * @return The tags associated to the post.
 | 
					         * @return The tags associated to the post.
 | 
				
			||||||
         **/
 | 
					         **/
 | 
				
			||||||
        QStringList tags() const;
 | 
					        const QSet< QString > tags() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * @return The URL to the post's thumbnail.
 | 
					         * @return The URL to the post's thumbnail.
 | 
				
			||||||
| 
						 | 
					@ -166,13 +177,18 @@ namespace Danbooru {
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * @return A pointer to the thumbnail's pixmap.
 | 
					         * @return A pointer to the thumbnail's pixmap.
 | 
				
			||||||
         **/
 | 
					         **/
 | 
				
			||||||
        QPixmap* pixmap() const;
 | 
					        const QPixmap* pixmap() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         * @return The current post's rating.
 | 
				
			||||||
 | 
					         **/
 | 
				
			||||||
 | 
					        const Ratings rating() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * Set the post's pixmap to a specific QPixmap instance's pointer.
 | 
					         * Set the post's pixmap to a specific QPixmap instance's pointer.
 | 
				
			||||||
         *
 | 
					         *
 | 
				
			||||||
         **/
 | 
					         **/
 | 
				
			||||||
        void setPixmap(QPixmap* pixmap);
 | 
					        void setPixmap(const QPixmap* pixmap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * @return A string representation of the post.
 | 
					         * @return A string representation of the post.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue