First semi-working implementation in c++ of remote Danbooru calls
This commit is contained in:
parent
c0cf369b92
commit
fc691a9301
9 changed files with 1341 additions and 0 deletions
132
src/libdanbooru/danboorupost.cpp
Normal file
132
src/libdanbooru/danboorupost.cpp
Normal file
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* This file is part of libdanbooru.
|
||||
* Copyright 2013 Luca Beltrame <lbeltrame@kde.org>
|
||||
*
|
||||
* This program 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 2 of
|
||||
* the License or (at your option) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Qt
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtGui/QPixmap>
|
||||
|
||||
// KDE
|
||||
|
||||
#include <kurl.h>
|
||||
|
||||
// Own
|
||||
|
||||
#include "danboorupost.h"
|
||||
|
||||
|
||||
namespace Danbooru {
|
||||
|
||||
DanbooruPost::DanbooruPost(QVariantMap postData, QPixmap* pixmap,
|
||||
QObject* parent):
|
||||
QObject(parent),
|
||||
m_pixmap(pixmap)
|
||||
{
|
||||
|
||||
m_tags = 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").toUrl() );
|
||||
m_thumbnailUrl = KUrl(postData.value("preview_url").toUrl());
|
||||
m_size = postData.value("file_size").toInt();
|
||||
|
||||
}
|
||||
|
||||
DanbooruPost::DanbooruPost(QXmlStreamAttributes& postData,
|
||||
QPixmap* pixmap,
|
||||
QObject* parent):
|
||||
QObject(parent),
|
||||
m_pixmap(pixmap)
|
||||
{
|
||||
Q_UNUSED(postData)
|
||||
}
|
||||
|
||||
|
||||
DanbooruPost::~DanbooruPost()
|
||||
{
|
||||
delete m_pixmap;
|
||||
}
|
||||
|
||||
|
||||
bool DanbooruPost::operator==(const Danbooru::DanbooruPost& other)
|
||||
{
|
||||
return m_url == other.m_url && m_id == other.m_id;
|
||||
}
|
||||
|
||||
|
||||
void DanbooruPost::setPixmap(QPixmap* pixmap)
|
||||
{
|
||||
m_pixmap = pixmap;
|
||||
}
|
||||
|
||||
const QString DanbooruPost::toString()
|
||||
{
|
||||
QString display = QString("Danbooru Post with ID %1 and URL %2, width %3 height %4 ");
|
||||
display = display.arg(id()).arg(fileUrl().url()).arg(width()).arg(height());
|
||||
return display;
|
||||
}
|
||||
|
||||
int DanbooruPost::id() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
int DanbooruPost::height() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
int DanbooruPost::width() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
QStringList DanbooruPost::tags() const
|
||||
{
|
||||
return m_tags;
|
||||
}
|
||||
|
||||
const KUrl DanbooruPost::thumbnailUrl() const
|
||||
{
|
||||
return m_thumbnailUrl;
|
||||
}
|
||||
|
||||
QPixmap* DanbooruPost::pixmap() const
|
||||
{
|
||||
return m_pixmap;
|
||||
}
|
||||
|
||||
int DanbooruPost::size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
const KUrl DanbooruPost::fileUrl() const
|
||||
{
|
||||
return m_url;
|
||||
}
|
||||
|
||||
} // namespace Danbooru
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue