Run astyle-kdelibs on the source
This commit is contained in:
parent
4b85d63d68
commit
39aac8c95b
22 changed files with 1227 additions and 1264 deletions
|
@ -17,8 +17,6 @@
|
|||
* along with Danbooru Client. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "danbooruclientview.h"
|
||||
|
||||
// Own
|
||||
|
@ -35,14 +33,15 @@
|
|||
#include <KRun>
|
||||
#include <KFileDialog>
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
DanbooruClientView::DanbooruClientView(QWidget * parent): QWidget(parent),
|
||||
DanbooruClientView::DanbooruClientView(QWidget *parent): QWidget(parent),
|
||||
m_model(new DanbooruPostModel(this)),
|
||||
m_delegate(0),
|
||||
m_service(0),
|
||||
m_timer(0)
|
||||
{
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
m_delegate = new DanbooruPostDelegate(m_listView);
|
||||
|
@ -51,7 +50,7 @@ namespace Danbooru {
|
|||
m_listView->setResizeMode(QListView::Adjust);
|
||||
m_listView->setWrapping(true);
|
||||
m_listView->setViewMode(QListView::IconMode);
|
||||
m_listView->setGridSize(QSize(256,256));
|
||||
m_listView->setGridSize(QSize(256, 256));
|
||||
|
||||
m_listView->setModel(m_model);
|
||||
m_listView->setItemDelegate(m_delegate);
|
||||
|
@ -60,29 +59,27 @@ namespace Danbooru {
|
|||
|
||||
connect(m_delegate, &DanbooruPostDelegate::postDownloadRequested, this, &DanbooruClientView::slotHandleDownload);
|
||||
connect(m_delegate, &DanbooruPostDelegate::postViewRequested, this, &DanbooruClientView::slotHandleView);
|
||||
// connect(m_listView, SIGNAL(clicked(const QModelIndex&)), parent(),
|
||||
// SLOT(displayInfo(const QModelIndex&));
|
||||
// connect(m_listView, SIGNAL(clicked(QModelIndex)), parent(),
|
||||
// SLOT(displayInfo(QModelIndex));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
DanbooruClientView::~DanbooruClientView()
|
||||
{
|
||||
|
||||
DanbooruClientView::~DanbooruClientView()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DanbooruClientView::slotHandleDownload(QUrl url)
|
||||
{
|
||||
void DanbooruClientView::slotHandleDownload(QUrl url)
|
||||
{
|
||||
// TODO
|
||||
Q_UNUSED(url)
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruClientView::slotHandleView(QUrl url)
|
||||
{
|
||||
KRun* runViewer = new KRun(url, this /*window*/, true /*showProgressInfo*/,
|
||||
void DanbooruClientView::slotHandleView(QUrl url)
|
||||
{
|
||||
KRun *runViewer = new KRun(url, this /*window*/, true /*showProgressInfo*/,
|
||||
"" /*asn*/);
|
||||
runViewer->setAutoDelete(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Danbooru
|
||||
|
|
|
@ -28,13 +28,14 @@
|
|||
|
||||
class QTimer;
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
class DanbooruPostModel;
|
||||
class DanbooruPostDelegate;
|
||||
class DanbooruService;
|
||||
class DanbooruPostModel;
|
||||
class DanbooruPostDelegate;
|
||||
class DanbooruService;
|
||||
|
||||
/**
|
||||
/**
|
||||
* This is the main view class for danbooru_client. Most of the non-menu,
|
||||
* non-toolbar, and non-statusbar (e.g., non frame) GUI code should go
|
||||
* here.
|
||||
|
@ -44,31 +45,31 @@ namespace Danbooru {
|
|||
* @version %{VERSION}
|
||||
*/
|
||||
|
||||
class DanbooruClientView : public QWidget, public Ui::DanbooruClientView
|
||||
{
|
||||
class DanbooruClientView : public QWidget, public Ui::DanbooruClientView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
DanbooruClientView(QWidget *parent=0);
|
||||
DanbooruClientView(QWidget *parent = 0);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~DanbooruClientView();
|
||||
|
||||
private Q_SLOTS:
|
||||
private Q_SLOTS:
|
||||
void slotHandleDownload(QUrl);
|
||||
void slotHandleView(QUrl);
|
||||
|
||||
private:
|
||||
DanbooruPostModel* m_model;
|
||||
DanbooruPostDelegate* m_delegate;
|
||||
DanbooruService* m_service;
|
||||
private:
|
||||
DanbooruPostModel *m_model;
|
||||
DanbooruPostDelegate *m_delegate;
|
||||
DanbooruService *m_service;
|
||||
|
||||
QTimer* m_timer;
|
||||
QTimer *m_timer;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -27,10 +27,10 @@
|
|||
|
||||
#include <KWallet>
|
||||
|
||||
|
||||
using KWallet::Wallet;
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
const QMap< QUrl, QString > initBoardSalts()
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ const QMap< QUrl, QString > initBoardSalts()
|
|||
const QMap<QUrl, QString> DanbooruConnectWidget::boardSalts = initBoardSalts();
|
||||
|
||||
DanbooruConnectWidget::DanbooruConnectWidget(QVector< QUrl > urlList,
|
||||
QWidget* parent):
|
||||
QWidget *parent):
|
||||
QWidget(parent),
|
||||
m_wallet(0)
|
||||
|
||||
|
@ -74,7 +74,7 @@ DanbooruConnectWidget::DanbooruConnectWidget(QVector< QUrl > urlList,
|
|||
|
||||
danbooruUrlComboBox->clear();
|
||||
|
||||
for (auto item: urlList) {
|
||||
for (auto item : urlList) {
|
||||
danbooruUrlComboBox->insertUrl(urlList.indexOf(item), item);
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,6 @@ void DanbooruConnectWidget::getWalletData()
|
|||
|
||||
if (m_wallet->hasEntry(key)) {
|
||||
|
||||
|
||||
if (m_wallet->readMap(key, valueMap) != 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -133,7 +132,6 @@ void DanbooruConnectWidget::getWalletData()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void DanbooruConnectWidget::toggleLineEdits(int state)
|
||||
{
|
||||
if (state == Qt::Unchecked) {
|
||||
|
@ -145,7 +143,6 @@ void DanbooruConnectWidget::toggleLineEdits(int state)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void DanbooruConnectWidget::emitRejected()
|
||||
{
|
||||
Q_EMIT rejected();
|
||||
|
@ -161,7 +158,6 @@ QString DanbooruConnectWidget::username() const
|
|||
return m_username;
|
||||
}
|
||||
|
||||
|
||||
QString DanbooruConnectWidget::password() const
|
||||
{
|
||||
return m_password;
|
||||
|
@ -178,7 +174,7 @@ void DanbooruConnectWidget::accept()
|
|||
if (!m_username.isEmpty() && !m_password.isEmpty()) {
|
||||
|
||||
if (m_wallet && !m_wallet->hasEntry(m_boardUrl.url())) {
|
||||
QMap<QString,QString> dataMap;
|
||||
QMap<QString, QString> dataMap;
|
||||
dataMap.insert(QLatin1String("username"), m_username);
|
||||
dataMap.insert(QLatin1String("password"), m_password);
|
||||
m_wallet->writeMap(m_boardUrl.url(), dataMap);
|
||||
|
@ -190,12 +186,11 @@ void DanbooruConnectWidget::accept()
|
|||
).toHex();
|
||||
}
|
||||
|
||||
DanbooruService* service = new DanbooruService(m_boardUrl, m_username,
|
||||
DanbooruService *service = new DanbooruService(m_boardUrl, m_username,
|
||||
hashedPassword);
|
||||
Q_EMIT(connectionEstablished(service));
|
||||
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
}; // namespace Danbooru
|
||||
|
|
|
@ -28,46 +28,48 @@
|
|||
|
||||
#include <QUrl>
|
||||
|
||||
namespace KWallet {
|
||||
class Wallet;
|
||||
namespace KWallet
|
||||
{
|
||||
class Wallet;
|
||||
}
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
class DanbooruService;
|
||||
class DanbooruService;
|
||||
|
||||
const QMap< QUrl, QString > initBoardSalts();
|
||||
const QMap< QUrl, QString > initBoardSalts();
|
||||
|
||||
class DanbooruConnectWidget: public QWidget, public Ui::DanbooruConnectWidget {
|
||||
class DanbooruConnectWidget: public QWidget, public Ui::DanbooruConnectWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
explicit DanbooruConnectWidget(QVector<QUrl> urlList,
|
||||
QWidget* parent = 0);
|
||||
QWidget *parent = 0);
|
||||
~DanbooruConnectWidget();
|
||||
|
||||
QString username() const;
|
||||
QString password() const;
|
||||
QUrl boardUrl() const;
|
||||
|
||||
private:
|
||||
private:
|
||||
QUrl m_boardUrl;
|
||||
QString m_username;
|
||||
QString m_password;
|
||||
KWallet::Wallet* m_wallet;
|
||||
KWallet::Wallet *m_wallet;
|
||||
static const QMap<QUrl, QString> boardSalts;
|
||||
|
||||
Q_SIGNALS:
|
||||
void connectionEstablished(DanbooruService* service);
|
||||
Q_SIGNALS:
|
||||
void connectionEstablished(DanbooruService *service);
|
||||
void rejected();
|
||||
|
||||
|
||||
private Q_SLOTS:
|
||||
private Q_SLOTS:
|
||||
void checkWallet(bool);
|
||||
void getWalletData();
|
||||
void toggleLineEdits(int state);
|
||||
void emitRejected();
|
||||
void accept();
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Danbooru
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
* @file danbooru.h
|
||||
*
|
||||
**/
|
||||
namespace Danbooru {
|
||||
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
}; // namespace Danbooru
|
||||
|
||||
|
|
|
@ -22,9 +22,10 @@
|
|||
|
||||
#include "danboorupool.h"
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
DanbooruPool::DanbooruPool(const QVariantMap& postData, QObject* parent):
|
||||
DanbooruPool::DanbooruPool(const QVariantMap &postData, QObject *parent):
|
||||
QObject(parent), m_posts(QList<int>())
|
||||
{
|
||||
m_id = postData.value("id").toInt();
|
||||
|
@ -68,13 +69,12 @@ void DanbooruPool::addPosts(QList< int > posts)
|
|||
m_posts.append(posts);
|
||||
}
|
||||
|
||||
void DanbooruPool::addPosts(const QStringList& posts)
|
||||
void DanbooruPool::addPosts(const QStringList &posts)
|
||||
{
|
||||
|
||||
for (auto post: posts) {
|
||||
for (auto post : posts) {
|
||||
m_posts.append(post.toInt());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Danbooru
|
||||
|
|
|
@ -37,9 +37,10 @@
|
|||
#include <QtCore/QStringList>
|
||||
#include <QtXml/QXmlStreamAttributes>
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Class representing a Danbooru pool.
|
||||
*
|
||||
* Pools are organized groups of images, often by a common theme, for
|
||||
|
@ -50,19 +51,19 @@ namespace Danbooru {
|
|||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*
|
||||
* **/
|
||||
class DanbooruPool : public QObject
|
||||
{
|
||||
class DanbooruPool : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
private:
|
||||
int m_id;
|
||||
int m_postCount;
|
||||
QString m_name;
|
||||
QString m_description;
|
||||
QList<int> m_posts;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Construct a Danbooru pool from a QVariantMap.
|
||||
|
@ -76,7 +77,7 @@ namespace Danbooru {
|
|||
*
|
||||
*
|
||||
**/
|
||||
DanbooruPool(const QVariantMap& postData, QObject* parent = 0);
|
||||
DanbooruPool(const QVariantMap &postData, QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* @brief Construct a Danbooru pool from a QVariantMap.
|
||||
|
@ -90,7 +91,7 @@ namespace Danbooru {
|
|||
*
|
||||
*
|
||||
**/
|
||||
DanbooruPool(const QXmlStreamAttributes& postData, QObject* parent=0);
|
||||
DanbooruPool(const QXmlStreamAttributes &postData, QObject *parent = 0);
|
||||
|
||||
int id() const;
|
||||
int postCount() const;
|
||||
|
@ -100,11 +101,11 @@ namespace Danbooru {
|
|||
|
||||
void addPost(int post);
|
||||
void addPosts(QList<int> posts);
|
||||
void addPosts(const QStringList& posts);
|
||||
};
|
||||
void addPosts(const QStringList &posts);
|
||||
};
|
||||
|
||||
}; // namespace Danbooru
|
||||
|
||||
Q_DECLARE_METATYPE(Danbooru::DanbooruPool*)
|
||||
Q_DECLARE_METATYPE(Danbooru::DanbooruPool *)
|
||||
|
||||
#endif // DANBOORUPOOL_H
|
||||
|
|
|
@ -33,14 +33,13 @@
|
|||
|
||||
#include "danboorupost.h"
|
||||
|
||||
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
const QMap<QString, DanbooruPost::Rating> DanbooruPost::RATING_MAP = initRatingMap();
|
||||
|
||||
DanbooruPost::DanbooruPost(QVariantMap postData, QPixmap pixmap,
|
||||
QObject* parent):
|
||||
QObject *parent):
|
||||
QObject(parent),
|
||||
m_pixmap(pixmap)
|
||||
{
|
||||
|
@ -57,7 +56,7 @@ DanbooruPost::DanbooruPost(QVariantMap postData, QPixmap pixmap,
|
|||
|
||||
}
|
||||
|
||||
DanbooruPost::DanbooruPost(QXmlStreamAttributes& postData, QPixmap pixmap, QObject* parent):
|
||||
DanbooruPost::DanbooruPost(QXmlStreamAttributes &postData, QPixmap pixmap, QObject *parent):
|
||||
QObject(parent),
|
||||
m_pixmap(pixmap)
|
||||
{
|
||||
|
@ -73,12 +72,10 @@ DanbooruPost::DanbooruPost(QXmlStreamAttributes& postData, QPixmap pixmap, QObje
|
|||
m_rating = RATING_MAP.value(postData.value("rating").toString());
|
||||
}
|
||||
|
||||
|
||||
DanbooruPost::~DanbooruPost()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const QMap< QString, DanbooruPost::Rating > DanbooruPost::initRatingMap()
|
||||
{
|
||||
|
||||
|
@ -91,13 +88,11 @@ const QMap< QString, DanbooruPost::Rating > DanbooruPost::initRatingMap()
|
|||
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void DanbooruPost::setPixmap(const QPixmap &pixmap)
|
||||
{
|
||||
m_pixmap = pixmap;
|
||||
|
@ -155,7 +150,5 @@ Danbooru::DanbooruPost::Rating DanbooruPost::rating() const
|
|||
return m_rating;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Danbooru
|
||||
|
||||
|
||||
|
|
|
@ -45,10 +45,10 @@
|
|||
|
||||
#include "danbooru.h"
|
||||
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
namespace Danbooru {
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief A class representing a Danbooru post.
|
||||
*
|
||||
* A Danbooru post is an object that models the posts present in a
|
||||
|
@ -65,8 +65,8 @@ namespace Danbooru {
|
|||
* @see DanbooruService, DanbooruPool
|
||||
*
|
||||
**/
|
||||
class DanbooruPost : public QObject
|
||||
{
|
||||
class DanbooruPost : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -76,7 +76,7 @@ namespace Danbooru {
|
|||
Q_PROPERTY(QSet<QString> tags READ tags)
|
||||
Q_PROPERTY(QUrl thumbnailUrl READ thumbnailUrl)
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Ratings for a Danbooru item
|
||||
|
@ -91,8 +91,7 @@ namespace Danbooru {
|
|||
};
|
||||
Q_DECLARE_FLAGS(Ratings, DanbooruPost::Rating)
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
QPixmap m_pixmap;
|
||||
|
||||
|
@ -114,7 +113,7 @@ namespace Danbooru {
|
|||
|
||||
static const QMap< QString, Rating > initRatingMap();
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Construct a Danbooru post from a QVariantMap.
|
||||
|
@ -130,7 +129,7 @@ namespace Danbooru {
|
|||
*
|
||||
**/
|
||||
explicit DanbooruPost(QVariantMap postData, QPixmap pixmap = QPixmap(),
|
||||
QObject* parent = 0);
|
||||
QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* @brief Construct a Danbooru post from XML attributes
|
||||
|
@ -146,10 +145,10 @@ namespace Danbooru {
|
|||
* @param parent A pointer to the parent QObject.
|
||||
*
|
||||
**/
|
||||
explicit DanbooruPost(QXmlStreamAttributes& postData,
|
||||
QPixmap pixmap = QPixmap(), QObject* parent =0);
|
||||
explicit DanbooruPost(QXmlStreamAttributes &postData,
|
||||
QPixmap pixmap = QPixmap(), QObject *parent = 0);
|
||||
|
||||
bool operator==(const DanbooruPost&);
|
||||
bool operator==(const DanbooruPost &);
|
||||
|
||||
~DanbooruPost();
|
||||
|
||||
|
@ -204,7 +203,7 @@ namespace Danbooru {
|
|||
* Set the post's pixmap to a specific QPixmap instance's pointer.
|
||||
*
|
||||
**/
|
||||
void setPixmap(const QPixmap& pixmap);
|
||||
void setPixmap(const QPixmap &pixmap);
|
||||
|
||||
/**
|
||||
* @return A string representation of the post.
|
||||
|
@ -212,16 +211,13 @@ namespace Danbooru {
|
|||
* **/
|
||||
const QString toString();
|
||||
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(DanbooruPost::Ratings)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(DanbooruPost::Ratings)
|
||||
|
||||
}; // namespace Danbooru
|
||||
|
||||
Q_DECLARE_METATYPE(Danbooru::DanbooruPost*)
|
||||
Q_DECLARE_METATYPE(Danbooru::DanbooruPost *)
|
||||
|
||||
#endif // DANBOORUPOST_H
|
||||
|
||||
|
|
|
@ -53,9 +53,9 @@ const QString DanbooruService::ARTIST_URL = "artist/index.json";
|
|||
const QString DanbooruService::POOL_DATA_URL = "pool/show.xml";
|
||||
const QString DanbooruService::RELATED_TAG_URL = "tag/related.json";
|
||||
|
||||
DanbooruService::DanbooruService(QUrl& boardUrl, QString username,
|
||||
QString password, KImageCache* cache,
|
||||
QObject* parent):
|
||||
DanbooruService::DanbooruService(QUrl &boardUrl, QString username,
|
||||
QString password, KImageCache *cache,
|
||||
QObject *parent):
|
||||
QObject(parent),
|
||||
m_url(boardUrl),
|
||||
m_username(username),
|
||||
|
@ -71,7 +71,6 @@ DanbooruService::~DanbooruService()
|
|||
|
||||
}
|
||||
|
||||
|
||||
void DanbooruService::getPostList(int page, QStringList tags, int limit)
|
||||
{
|
||||
|
||||
|
@ -89,7 +88,7 @@ void DanbooruService::getPostList(int page, QStringList tags, int limit)
|
|||
|
||||
// qDebug() << "Final constructed post URL" << danbooruUrl.url();
|
||||
|
||||
KIO::StoredTransferJob* job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::StoredTransferJob *job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::HideProgressInfo);
|
||||
|
||||
// This job can use JSON data
|
||||
|
@ -97,7 +96,6 @@ void DanbooruService::getPostList(int page, QStringList tags, int limit)
|
|||
|
||||
connect(job, &KIO::StoredTransferJob::result, this, &DanbooruService::processPostList);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void DanbooruService::getTagList(int limit, QString name)
|
||||
|
@ -114,17 +112,17 @@ void DanbooruService::getTagList(int limit, QString name)
|
|||
parameters);
|
||||
//qDebug() << "Final constructed tag URL" << danbooruUrl.url();
|
||||
|
||||
KIO::StoredTransferJob* job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::StoredTransferJob *job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::HideProgressInfo);
|
||||
|
||||
connect(job, &KIO::StoredTransferJob::result, [this](KJob* job) {
|
||||
connect(job, &KIO::StoredTransferJob::result, [this](KJob * job) {
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
QByteArray data = jobResult->data();
|
||||
|
||||
bool ok;
|
||||
|
@ -140,7 +138,7 @@ void DanbooruService::getTagList(int limit, QString name)
|
|||
|
||||
for (auto element : tagList) {
|
||||
QVariantMap map = element.toMap();
|
||||
DanbooruTag* tag = new DanbooruTag(map);
|
||||
DanbooruTag *tag = new DanbooruTag(map);
|
||||
Q_EMIT(tagDownloaded(tag));
|
||||
}
|
||||
|
||||
|
@ -164,8 +162,7 @@ void DanbooruService::getPool(int poolId, int page)
|
|||
|
||||
//qDebug() << "Final constructed pool URL" << danbooruUrl.url();
|
||||
|
||||
|
||||
KIO::StoredTransferJob* job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::StoredTransferJob *job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
KIO::HideProgressInfo);
|
||||
|
||||
//HACK: Most Danbooru implementations don't provide valid data on
|
||||
|
@ -194,21 +191,21 @@ void DanbooruService::getPoolList(int page)
|
|||
|
||||
//qDebug() << "Final constructed pool list URL" << danbooruUrl.url();
|
||||
|
||||
KIO::StoredTransferJob* job = KIO::storedGet(danbooruUrl, KIO::NoReload,
|
||||
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, &DanbooruService::processPoolList);
|
||||
|
||||
connect(job, &KIO::StoredTransferJob::result, [this] (KJob* job) {
|
||||
connect(job, &KIO::StoredTransferJob::result, [this](KJob * job) {
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
QByteArray data = jobResult->data();
|
||||
|
||||
bool ok;
|
||||
|
@ -222,7 +219,7 @@ void DanbooruService::getPoolList(int page)
|
|||
for (auto element : poolList) {
|
||||
QVariantMap map = element.toMap();
|
||||
|
||||
DanbooruPool* pool = new DanbooruPool(map);
|
||||
DanbooruPool *pool = new DanbooruPool(map);
|
||||
Q_EMIT(poolDownloaded(pool));
|
||||
}
|
||||
|
||||
|
@ -234,7 +231,7 @@ void DanbooruService::getPoolList(int page)
|
|||
|
||||
}
|
||||
|
||||
void DanbooruService::getRelatedTags(const QStringList& tags,
|
||||
void DanbooruService::getRelatedTags(const QStringList &tags,
|
||||
DanbooruTag::TagType tagType)
|
||||
{
|
||||
|
||||
|
@ -265,19 +262,19 @@ void DanbooruService::getRelatedTags(const QStringList& tags,
|
|||
|
||||
//qDebug() << "Final constructed related tag URL" << danbooruUrl.url();
|
||||
|
||||
StoredTransferJob* job = KIO::storedGet(
|
||||
StoredTransferJob *job = KIO::storedGet(
|
||||
danbooruUrl, KIO::NoReload,
|
||||
KIO::HideProgressInfo
|
||||
);
|
||||
|
||||
connect(job, &StoredTransferJob::result, [this](KJob* job) {
|
||||
connect(job, &StoredTransferJob::result, [this](KJob * job) {
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
QByteArray data = jobResult->data();
|
||||
bool ok;
|
||||
|
||||
|
@ -320,7 +317,7 @@ void DanbooruService::getRelatedTags(const QStringList& tags,
|
|||
|
||||
// Getters / setters
|
||||
|
||||
void DanbooruService::setBlacklist(const QSet< QString >& blacklist)
|
||||
void DanbooruService::setBlacklist(const QSet< QString > &blacklist)
|
||||
{
|
||||
|
||||
if (!blacklist.isEmpty()) {
|
||||
|
@ -329,7 +326,6 @@ void DanbooruService::setBlacklist(const QSet< QString >& blacklist)
|
|||
|
||||
}
|
||||
|
||||
|
||||
const QSet< QString > DanbooruService::blacklist() const
|
||||
{
|
||||
return m_blacklist;
|
||||
|
@ -384,7 +380,7 @@ const DanbooruPost::Ratings DanbooruService::maximumAllowedRating() const
|
|||
|
||||
// Slots
|
||||
|
||||
void DanbooruService::processPostList(KJob* job)
|
||||
void DanbooruService::processPostList(KJob *job)
|
||||
{
|
||||
|
||||
// qDebug() << "Got post data OK";
|
||||
|
@ -393,7 +389,7 @@ void DanbooruService::processPostList(KJob* job)
|
|||
Q_EMIT(downloadError(job->errorString()));
|
||||
}
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
|
||||
if (jobResult == 0) {
|
||||
Q_EMIT(downloadError(QString("Internal error")));
|
||||
|
@ -427,7 +423,7 @@ void DanbooruService::processPostList(KJob* job)
|
|||
for (auto element : postList) {
|
||||
|
||||
QVariantMap map = element.toMap();
|
||||
DanbooruPost* post = new DanbooruPost(map);
|
||||
DanbooruPost *post = new DanbooruPost(map);
|
||||
|
||||
// Remove unwanted posts
|
||||
|
||||
|
@ -453,11 +449,11 @@ void DanbooruService::processPostList(KJob* job)
|
|||
|
||||
} else {
|
||||
|
||||
StoredTransferJob* pixmapJob = KIO::storedGet(post->thumbnailUrl(),
|
||||
StoredTransferJob *pixmapJob = KIO::storedGet(post->thumbnailUrl(),
|
||||
KIO::NoReload, KIO::HideProgressInfo
|
||||
);
|
||||
|
||||
KIO::Scheduler::setJobPriority(static_cast<KIO::SimpleJob*>(job), 1);
|
||||
KIO::Scheduler::setJobPriority(static_cast<KIO::SimpleJob *>(job), 1);
|
||||
|
||||
QVariant variant;
|
||||
variant.setValue(post);
|
||||
|
@ -467,23 +463,26 @@ void DanbooruService::processPostList(KJob* job)
|
|||
|
||||
pixmapJob->setProperty("danbooruPost", variant);
|
||||
|
||||
connect(pixmapJob, &StoredTransferJob::result, [post, this, pix] (KJob* job) mutable {
|
||||
connect(pixmapJob, &StoredTransferJob::result, [post, this, pix](KJob * job) mutable {
|
||||
|
||||
if (job->error()) {
|
||||
if (job->error())
|
||||
{
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
|
||||
if (!pix.loadFromData(jobResult->data())) {
|
||||
if (!pix.loadFromData(jobResult->data()))
|
||||
{
|
||||
Q_EMIT(downloadError(QString("Pixmap data could not be loaded")));
|
||||
return;
|
||||
}
|
||||
|
||||
post->setPixmap(pix);
|
||||
|
||||
if (m_cache) {
|
||||
if (m_cache)
|
||||
{
|
||||
//qDebug() << "Inserting item in cache";
|
||||
m_cache->insertPixmap(post->thumbnailUrl().url(), pix);
|
||||
}
|
||||
|
@ -493,7 +492,8 @@ void DanbooruService::processPostList(KJob* job)
|
|||
//qDebug() << "Current posts remaining" << m_currentPosts;
|
||||
Q_EMIT(postDownloaded(post));
|
||||
|
||||
if (m_postsToFetch == 0) {
|
||||
if (m_postsToFetch == 0)
|
||||
{
|
||||
qDebug() << "Post download finished";
|
||||
Q_EMIT(postDownloadFinished());
|
||||
}
|
||||
|
@ -504,30 +504,26 @@ void DanbooruService::processPostList(KJob* job)
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void DanbooruService::processTagList(KJob* job)
|
||||
void DanbooruService::processTagList(KJob *job)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DanbooruService::processRelatedTagList(KJob* job)
|
||||
void DanbooruService::processRelatedTagList(KJob *job)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DanbooruService::processPoolList(KJob* job)
|
||||
void DanbooruService::processPoolList(KJob *job)
|
||||
{
|
||||
|
||||
|
||||
if (job->error()) {
|
||||
Q_EMIT(downloadError(job->errorString()));
|
||||
}
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
|
||||
if (jobResult == 0) {
|
||||
Q_EMIT(downloadError(QString("Internal error")));
|
||||
|
@ -549,7 +545,7 @@ void DanbooruService::processPoolList(KJob* job)
|
|||
for (auto element : poolList) {
|
||||
QVariantMap map = element.toMap();
|
||||
|
||||
DanbooruPool* pool = new DanbooruPool(map);
|
||||
DanbooruPool *pool = new DanbooruPool(map);
|
||||
Q_EMIT(poolDownloaded(pool));
|
||||
}
|
||||
|
||||
|
@ -558,12 +554,12 @@ void DanbooruService::processPoolList(KJob* job)
|
|||
|
||||
}
|
||||
|
||||
void DanbooruService::downloadAllTags(KJob* job)
|
||||
void DanbooruService::downloadAllTags(KJob *job)
|
||||
{
|
||||
Q_UNUSED(job)
|
||||
}
|
||||
|
||||
void DanbooruService::downloadThumbnail(KJob* job)
|
||||
void DanbooruService::downloadThumbnail(KJob *job)
|
||||
{
|
||||
|
||||
if (job->error()) {
|
||||
|
@ -572,11 +568,11 @@ void DanbooruService::downloadThumbnail(KJob* job)
|
|||
|
||||
QVariant postData = job->property("danbooruPost");
|
||||
|
||||
DanbooruPost* post = postData.value<DanbooruPost*>();
|
||||
DanbooruPost *post = postData.value<DanbooruPost *>();
|
||||
QPixmap pix;
|
||||
// QPixmap* pix = new QPixmap();
|
||||
|
||||
StoredTransferJob* jobResult = qobject_cast<StoredTransferJob*>(job);
|
||||
StoredTransferJob *jobResult = qobject_cast<StoredTransferJob *>(job);
|
||||
|
||||
if (jobResult == 0) {
|
||||
Q_EMIT(downloadError(QString("Internal error")));
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#ifndef DANBOORUSERVICE_H
|
||||
#define DANBOORUSERVICE_H
|
||||
|
||||
|
||||
/**
|
||||
* @brief Classes to interact with Danbooru boards
|
||||
* @file danbooruservice.h
|
||||
|
@ -56,13 +55,14 @@ class KJob;
|
|||
|
||||
using Danbooru::DanbooruTag;
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
class DanbooruPool;
|
||||
class DanbooruPool;
|
||||
|
||||
using KIO::StoredTransferJob;
|
||||
using KIO::StoredTransferJob;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief A class which provides a wrapper around Danbooru's RESTful API.
|
||||
*
|
||||
* This class provides access to Danbooru-based image boards
|
||||
|
@ -73,11 +73,11 @@ namespace Danbooru {
|
|||
*
|
||||
*
|
||||
**/
|
||||
class DanbooruService : public QObject
|
||||
{
|
||||
class DanbooruService : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
// URL fragments
|
||||
|
||||
|
@ -98,9 +98,9 @@ namespace Danbooru {
|
|||
|
||||
unsigned int m_postsToFetch; // To tell when to quit
|
||||
|
||||
KImageCache* m_cache; // Pixmap cache
|
||||
KImageCache *m_cache; // Pixmap cache
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Construct a default instance of the service.
|
||||
|
@ -113,9 +113,9 @@ namespace Danbooru {
|
|||
* @param parent The parent QObject
|
||||
*
|
||||
**/
|
||||
DanbooruService(QUrl& boardUrl, QString username = QString(),
|
||||
QString password = QString(), KImageCache* cache = 0,
|
||||
QObject* parent = 0);
|
||||
DanbooruService(QUrl &boardUrl, QString username = QString(),
|
||||
QString password = QString(), KImageCache *cache = 0,
|
||||
QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* Default destructor.
|
||||
|
@ -130,8 +130,8 @@ namespace Danbooru {
|
|||
* @param limit The number of posts to fetch (maximum 100)
|
||||
*
|
||||
**/
|
||||
void getPostList(int page=1, QStringList tags=QStringList(),
|
||||
int limit=100);
|
||||
void getPostList(int page = 1, QStringList tags = QStringList(),
|
||||
int limit = 100);
|
||||
|
||||
/**
|
||||
* @brief Get a list of pools from the board.
|
||||
|
@ -148,7 +148,7 @@ namespace Danbooru {
|
|||
* @param page The page of the pool posts (if > 100)
|
||||
*
|
||||
**/
|
||||
void getPool(int poolId, int page=1);
|
||||
void getPool(int poolId, int page = 1);
|
||||
|
||||
/**
|
||||
* @brief Get a list of tags from the board
|
||||
|
@ -164,7 +164,7 @@ namespace Danbooru {
|
|||
* @param name The name of the tag to retrieve, or an empty string
|
||||
*
|
||||
**/
|
||||
void getTagList(int limit=10, QString name="");
|
||||
void getTagList(int limit = 10, QString name = "");
|
||||
|
||||
/**
|
||||
* @brief Get tags related to a specific, user supplied list.
|
||||
|
@ -172,7 +172,7 @@ namespace Danbooru {
|
|||
* @param tags The tags to query for related terms
|
||||
* @param tagType The type of tag to query for
|
||||
**/
|
||||
void getRelatedTags(const QStringList& tags, DanbooruTag::TagType tagType = DanbooruTag::General);
|
||||
void getRelatedTags(const QStringList &tags, DanbooruTag::TagType tagType = DanbooruTag::General);
|
||||
|
||||
/**
|
||||
* @return The currently allowed ratings when downloading posts.
|
||||
|
@ -189,7 +189,7 @@ namespace Danbooru {
|
|||
**/
|
||||
const QSet<QString> blacklist() const;
|
||||
|
||||
void setBlacklist(const QSet<QString>& blacklist);
|
||||
void setBlacklist(const QSet<QString> &blacklist);
|
||||
|
||||
/**
|
||||
* @brief Set the maximum allowed rating for the board.
|
||||
|
@ -208,15 +208,15 @@ namespace Danbooru {
|
|||
**/
|
||||
void setBlackList(QStringList blacklist);
|
||||
|
||||
private Q_SLOTS:
|
||||
void processPostList(KJob* job);
|
||||
void processPoolList(KJob* job);
|
||||
void processTagList(KJob* job);
|
||||
void processRelatedTagList(KJob* job);
|
||||
void downloadThumbnail(KJob* job);
|
||||
void downloadAllTags(KJob* job);
|
||||
private Q_SLOTS:
|
||||
void processPostList(KJob *job);
|
||||
void processPoolList(KJob *job);
|
||||
void processTagList(KJob *job);
|
||||
void processRelatedTagList(KJob *job);
|
||||
void downloadThumbnail(KJob *job);
|
||||
void downloadAllTags(KJob *job);
|
||||
|
||||
Q_SIGNALS:
|
||||
Q_SIGNALS:
|
||||
|
||||
/**
|
||||
* Emitted when there are no more posts to download.
|
||||
|
@ -231,7 +231,6 @@ namespace Danbooru {
|
|||
**/
|
||||
void poolDownloadFinished();
|
||||
|
||||
|
||||
/**
|
||||
* Emitted when a download error occurred.
|
||||
*
|
||||
|
@ -246,7 +245,7 @@ namespace Danbooru {
|
|||
* The parameter contains a pointer to the post that has been
|
||||
* downloaded.
|
||||
**/
|
||||
void postDownloaded(Danbooru::DanbooruPost* post);
|
||||
void postDownloaded(Danbooru::DanbooruPost *post);
|
||||
|
||||
/**
|
||||
* Emitted when a pool has been downloaded.
|
||||
|
@ -254,7 +253,7 @@ namespace Danbooru {
|
|||
* The parameter contains a pointer to the pool that has been
|
||||
* downloaded.
|
||||
**/
|
||||
void poolDownloaded(Danbooru::DanbooruPool* pool);
|
||||
void poolDownloaded(Danbooru::DanbooruPool *pool);
|
||||
|
||||
/**
|
||||
* Emitted when a tag has been downloaded.
|
||||
|
@ -262,8 +261,8 @@ namespace Danbooru {
|
|||
* The parameter contains a pointer to the tag that has been
|
||||
* downloaded.
|
||||
**/
|
||||
void tagDownloaded(Danbooru::DanbooruTag* tag);
|
||||
void tagDownloaded(Danbooru::DanbooruTag *tag);
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
#endif // DANBOORUSERVICE_H
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
namespace Danbooru
|
||||
{
|
||||
|
||||
DanbooruTag::DanbooruTag(const QVariantMap& postData, QObject* parent):
|
||||
DanbooruTag::DanbooruTag(const QVariantMap &postData, QObject *parent):
|
||||
QObject(parent)
|
||||
{
|
||||
m_id = postData.value("id").toInt();
|
||||
|
@ -82,5 +82,4 @@ Danbooru::DanbooruTag::TagType DanbooruTag::type() const
|
|||
return m_tagType;
|
||||
}
|
||||
|
||||
|
||||
}; // namespace Danbooru
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DANBOORUTAG_H
|
||||
#define DANBOORUTAG_H
|
||||
|
||||
|
@ -29,13 +28,14 @@
|
|||
|
||||
#include "danbooru.h"
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
class DanbooruTag : public QObject
|
||||
{
|
||||
class DanbooruTag : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
/**
|
||||
* @brief Types of tags
|
||||
*
|
||||
|
@ -51,32 +51,32 @@ namespace Danbooru {
|
|||
General = 1, /**< Generic tags **/
|
||||
Artist = 2, /**< Tags related to artists **/
|
||||
Copyright = 4, /**<Tags related to copyrights **/
|
||||
Character= 8, /**<Tags related to characters **/
|
||||
Character = 8, /**<Tags related to characters **/
|
||||
Unknown = 16 /**< Unknown tags **/
|
||||
};
|
||||
|
||||
private:
|
||||
private:
|
||||
int m_id;
|
||||
int m_count;
|
||||
QString m_name;
|
||||
bool m_ambiguous;
|
||||
TagType m_tagType;
|
||||
|
||||
public:
|
||||
DanbooruTag(const QVariantMap& postData, QObject* parent=0);
|
||||
public:
|
||||
DanbooruTag(const QVariantMap &postData, QObject *parent = 0);
|
||||
int id() const;
|
||||
int count() const;
|
||||
const QString name() const;
|
||||
bool ambiguous() const;
|
||||
TagType type() const;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(TagTypes, DanbooruTag::TagType)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(TagTypes)
|
||||
Q_DECLARE_FLAGS(TagTypes, DanbooruTag::TagType)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(TagTypes)
|
||||
|
||||
}; // namespace Danbooru
|
||||
|
||||
Q_DECLARE_METATYPE(Danbooru::DanbooruTag*)
|
||||
Q_DECLARE_METATYPE(Danbooru::DanbooruTag *)
|
||||
|
||||
#endif // DANBOORUTAG_H
|
||||
|
|
|
@ -34,12 +34,13 @@
|
|||
|
||||
#include <QDebug>
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
QUrl requestUrl(QUrl& url, const QString& path,
|
||||
const QString& username, const QString& password,
|
||||
const dictMap& parameters, const QStringList& tags)
|
||||
{
|
||||
QUrl requestUrl(QUrl &url, const QString &path,
|
||||
const QString &username, const QString &password,
|
||||
const dictMap ¶meters, const QStringList &tags)
|
||||
{
|
||||
|
||||
QUrl danbooruUrl = QUrl(url);
|
||||
danbooruUrl = danbooruUrl.adjusted(QUrl::StripTrailingSlash);
|
||||
|
@ -49,7 +50,7 @@ namespace Danbooru {
|
|||
|
||||
if (!parameters.isEmpty()) {
|
||||
|
||||
for (auto key: parameters.keys()) {
|
||||
for (auto key : parameters.keys()) {
|
||||
danbooruUrl.addQueryItem(key, parameters.value(key));
|
||||
}
|
||||
|
||||
|
@ -68,11 +69,11 @@ namespace Danbooru {
|
|||
}
|
||||
|
||||
return danbooruUrl;
|
||||
}
|
||||
}
|
||||
|
||||
QUrl requestUrl(QUrl& url, const QString& path, const QString& username,
|
||||
const QString& password, const dictMap& parameters)
|
||||
{
|
||||
QUrl requestUrl(QUrl &url, const QString &path, const QString &username,
|
||||
const QString &password, const dictMap ¶meters)
|
||||
{
|
||||
|
||||
QUrl danbooruUrl = QUrl(url);
|
||||
danbooruUrl = danbooruUrl.adjusted(QUrl::StripTrailingSlash);
|
||||
|
@ -82,7 +83,7 @@ namespace Danbooru {
|
|||
|
||||
if (!parameters.isEmpty()) {
|
||||
|
||||
for (auto key: parameters.keys()) {
|
||||
for (auto key : parameters.keys()) {
|
||||
danbooruUrl.addQueryItem(key, parameters.value(key));
|
||||
}
|
||||
|
||||
|
@ -94,11 +95,11 @@ namespace Danbooru {
|
|||
}
|
||||
|
||||
return danbooruUrl;
|
||||
}
|
||||
}
|
||||
|
||||
QUrl requestUrl(QUrl& url, const QString& path, const QString& username,
|
||||
const QString& password)
|
||||
{
|
||||
QUrl requestUrl(QUrl &url, const QString &path, const QString &username,
|
||||
const QString &password)
|
||||
{
|
||||
QUrl danbooruUrl = QUrl(url);
|
||||
danbooruUrl = danbooruUrl.adjusted(QUrl::StripTrailingSlash);
|
||||
danbooruUrl.setPath(danbooruUrl.path() + '/' + path);
|
||||
|
@ -109,18 +110,18 @@ namespace Danbooru {
|
|||
}
|
||||
|
||||
return danbooruUrl;
|
||||
}
|
||||
}
|
||||
|
||||
QList< QVariant > parseDanbooruResult(QByteArray data, QString elementName,
|
||||
bool* result)
|
||||
{
|
||||
QList< QVariant > parseDanbooruResult(QByteArray data, QString elementName,
|
||||
bool *result)
|
||||
{
|
||||
|
||||
QXmlStreamReader reader;
|
||||
reader.addData(data);
|
||||
|
||||
QList<QVariant> postData;
|
||||
|
||||
while(!reader.atEnd() && !reader.hasError()) {
|
||||
while (!reader.atEnd() && !reader.hasError()) {
|
||||
|
||||
QXmlStreamReader::TokenType token = reader.readNext();
|
||||
|
||||
|
@ -128,7 +129,7 @@ namespace Danbooru {
|
|||
continue;
|
||||
}
|
||||
|
||||
if(token == QXmlStreamReader::StartElement &&
|
||||
if (token == QXmlStreamReader::StartElement &&
|
||||
reader.name() == elementName) {
|
||||
|
||||
QVariantMap values;
|
||||
|
@ -137,7 +138,7 @@ namespace Danbooru {
|
|||
|
||||
// qDebug() << attributes;
|
||||
|
||||
for (auto attribute: attributes) {
|
||||
for (auto attribute : attributes) {
|
||||
values.insert(attribute.name().toString(),
|
||||
attribute.value().toString());
|
||||
}
|
||||
|
@ -155,10 +156,10 @@ namespace Danbooru {
|
|||
}
|
||||
*result = true;
|
||||
return postData;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant parseDanbooruResult(QByteArray data, bool* result)
|
||||
{
|
||||
QVariant parseDanbooruResult(QByteArray data, bool *result)
|
||||
{
|
||||
|
||||
QJsonDocument parsed = QJsonDocument::fromJson(data);
|
||||
|
||||
|
@ -171,16 +172,16 @@ namespace Danbooru {
|
|||
*result = true;
|
||||
|
||||
return postData;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating ) {
|
||||
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating)
|
||||
{
|
||||
|
||||
if (post->rating() > maxRating) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto tag: post->tags()) {
|
||||
for (auto tag : post->tags()) {
|
||||
|
||||
if (blacklist.contains(tag)) {
|
||||
return true;
|
||||
|
|
|
@ -39,11 +39,12 @@
|
|||
*
|
||||
**/
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
typedef QMap<QString,QString> dictMap;
|
||||
typedef QMap<QString, QString> dictMap;
|
||||
|
||||
/** @brief Generate a request URL for a Danbooru board.
|
||||
/** @brief Generate a request URL for a Danbooru board.
|
||||
*
|
||||
* Given an URL and an API path, this function builds a
|
||||
* proper URL which is used for the specific API operation.
|
||||
|
@ -62,12 +63,11 @@ namespace Danbooru {
|
|||
*
|
||||
*
|
||||
**/
|
||||
QUrl requestUrl(QUrl& url, const QString& path, const QString& username,
|
||||
const QString& password, const dictMap& parameters,
|
||||
const QStringList& tags);
|
||||
QUrl requestUrl(QUrl &url, const QString &path, const QString &username,
|
||||
const QString &password, const dictMap ¶meters,
|
||||
const QStringList &tags);
|
||||
|
||||
|
||||
/** @brief Generate a request URL for a Danbooru board.
|
||||
/** @brief Generate a request URL for a Danbooru board.
|
||||
*
|
||||
* This is an overloaded function provided for convenience.
|
||||
*
|
||||
|
@ -84,11 +84,10 @@ namespace Danbooru {
|
|||
*
|
||||
*
|
||||
**/
|
||||
QUrl requestUrl(QUrl& url, const QString& path, const QString& username,
|
||||
const QString& password, const dictMap& parameters);
|
||||
QUrl requestUrl(QUrl &url, const QString &path, const QString &username,
|
||||
const QString &password, const dictMap ¶meters);
|
||||
|
||||
|
||||
/** @brief Generate a request URL for a Danbooru board.
|
||||
/** @brief Generate a request URL for a Danbooru board.
|
||||
*
|
||||
* This is an overloaded function provided for convenience.
|
||||
*
|
||||
|
@ -102,15 +101,14 @@ namespace Danbooru {
|
|||
*
|
||||
*
|
||||
**/
|
||||
QUrl requestUrl(QUrl& url, const QString& path, const QString& username,
|
||||
const QString& password);
|
||||
QUrl requestUrl(QUrl &url, const QString &path, const QString &username,
|
||||
const QString &password);
|
||||
|
||||
QList<QVariant> parseDanbooruResult(QByteArray data, QString xlmElement,
|
||||
bool *result);
|
||||
QVariant parseDanbooruResult(QByteArray data, bool *result);
|
||||
|
||||
QList<QVariant> parseDanbooruResult(QByteArray data, QString xlmElement,
|
||||
bool* result);
|
||||
QVariant parseDanbooruResult(QByteArray data, bool* result);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Check if a post can be allowed.
|
||||
*
|
||||
* This convenience function checks if a DanbooruPost is not allowed, either because it
|
||||
|
@ -122,7 +120,7 @@ namespace Danbooru {
|
|||
* @return true if the post is unwanted, false otherwise.
|
||||
* @author Luca Beltrame (lbeltrame@kde.org)
|
||||
*/
|
||||
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating );
|
||||
bool isPostBlacklisted(DanbooruPost *post, QSet<QString> blacklist, DanbooruPost::Ratings maxRating);
|
||||
|
||||
}
|
||||
#endif // UTILS_H
|
||||
|
|
21
src/main.cpp
21
src/main.cpp
|
@ -37,7 +37,7 @@ int main(int argc, char **argv)
|
|||
{
|
||||
K4AboutData about("danbooru_client", 0, ki18n("danbooru_client"), version, ki18n(description),
|
||||
K4AboutData::License_GPL, ki18n("(C) %{CURRENT_YEAR} %{AUTHOR}"), KLocalizedString(), 0, "%{EMAIL}");
|
||||
about.addAuthor( ki18n("%{AUTHOR}"), KLocalizedString(), "%{EMAIL}" );
|
||||
about.addAuthor(ki18n("%{AUTHOR}"), KLocalizedString(), "%{EMAIL}");
|
||||
QApplication app(argc, argv);
|
||||
QCommandLineParser parser;
|
||||
K4AboutData::setApplicationData(aboutData);
|
||||
|
@ -48,28 +48,21 @@ int main(int argc, char **argv)
|
|||
parser.process(app);
|
||||
aboutData.processCommandLine(&parser);
|
||||
|
||||
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("+[URL]"), i18n( "Document to open" )));
|
||||
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("+[URL]"), i18n("Document to open")));
|
||||
|
||||
danbooru_client *widget = new danbooru_client;
|
||||
|
||||
// see if we are starting with session management
|
||||
if (app.isSessionRestored())
|
||||
{
|
||||
if (app.isSessionRestored()) {
|
||||
RESTORE(danbooru_client);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// no session.. just start up normally
|
||||
if (parser.positionalArguments().count() == 0)
|
||||
{
|
||||
if (parser.positionalArguments().count() == 0) {
|
||||
//danbooru_client *widget = new danbooru_client;
|
||||
widget->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int i = 0;
|
||||
for (; i < parser.positionalArguments().count(); i++)
|
||||
{
|
||||
for (; i < parser.positionalArguments().count(); i++) {
|
||||
//danbooru_client *widget = new danbooru_client;
|
||||
widget->show();
|
||||
}
|
||||
|
|
|
@ -30,14 +30,15 @@
|
|||
|
||||
#include <KLocale>
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
DanbooruMainWindow::DanbooruMainWindow()
|
||||
DanbooruMainWindow::DanbooruMainWindow()
|
||||
: KXmlGuiWindow(),
|
||||
m_view(new DanbooruClientView(this)),
|
||||
m_service(0),
|
||||
m_model(new(DanbooruPostModel(this)))
|
||||
{
|
||||
{
|
||||
// tell the KXmlGuiWindow that this is indeed the main widget
|
||||
setCentralWidget(m_view);
|
||||
|
||||
|
@ -54,24 +55,21 @@ namespace Danbooru {
|
|||
// toolbar position, icon size, etc.
|
||||
setupGUI();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
DanbooruMainWindow::~DanbooruMainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
DanbooruMainWindow::~DanbooruMainWindow()
|
||||
{
|
||||
}
|
||||
void DanbooruMainWindow::setupActions()
|
||||
{
|
||||
|
||||
void DanbooruMainWindow::setupActions()
|
||||
{
|
||||
|
||||
|
||||
|
||||
QAction * connectAction = new QAction(
|
||||
QAction *connectAction = new QAction(
|
||||
QIcon::fromTheme(QLatin1String("document-open-remote")),
|
||||
i18n("Connect..."),
|
||||
this);
|
||||
|
||||
QAction * fetchAction = new QAction(QIcon::fromTheme(QLatin1String("download")),
|
||||
QAction *fetchAction = new QAction(QIcon::fromTheme(QLatin1String("download")),
|
||||
i18n("Download"), this);
|
||||
|
||||
connectAction->setShortcut(KStandardShortcut::open());
|
||||
|
@ -86,29 +84,28 @@ namespace Danbooru {
|
|||
connect(connectAction, &QAction::triggered, this, &DanbooruMainWindow::connectToBoard);
|
||||
connect(fetch, SIGNAL(triggered(bool)), this, SLOT(downloadPosts()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruMainWindow::connectToBoard()
|
||||
{
|
||||
void DanbooruMainWindow::connectToBoard()
|
||||
{
|
||||
|
||||
if (!m_view) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruMainWindow::downloadPosts()
|
||||
{
|
||||
void DanbooruMainWindow::downloadPosts()
|
||||
{
|
||||
if (!m_service) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruMainWindow::optionsPreferences()
|
||||
{
|
||||
|
||||
}
|
||||
void DanbooruMainWindow::optionsPreferences()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace Danbooru
|
||||
|
||||
|
|
|
@ -23,17 +23,17 @@
|
|||
#ifndef DANBOORU_CLIENT_H
|
||||
#define DANBOORU_CLIENT_H
|
||||
|
||||
|
||||
#include <KXmlGuiWindow>
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
class DanbooruClientView;
|
||||
class DanbooruService;
|
||||
class DanbooruPostModel;
|
||||
class DanbooruConnectWidget;
|
||||
class DanbooruClientView;
|
||||
class DanbooruService;
|
||||
class DanbooruPostModel;
|
||||
class DanbooruConnectWidget;
|
||||
|
||||
/**
|
||||
/**
|
||||
* This class serves as the main window for danbooru_client. It handles the
|
||||
* menus, toolbars and status bars.
|
||||
*
|
||||
|
@ -41,10 +41,10 @@ namespace Danbooru {
|
|||
* @author Luca Beltrame <lbeltrame@kde.org>
|
||||
* @version 0.01
|
||||
*/
|
||||
class DanbooruMainWindow : public KXmlGuiWindow
|
||||
{
|
||||
class DanbooruMainWindow : public KXmlGuiWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
|
@ -55,23 +55,22 @@ namespace Danbooru {
|
|||
*/
|
||||
virtual ~DanbooruMainWindow();
|
||||
|
||||
private Q_SLOTS:
|
||||
private Q_SLOTS:
|
||||
void connectToBoard();
|
||||
void downloadPosts();
|
||||
void optionsPreferences();
|
||||
|
||||
private:
|
||||
private:
|
||||
void setupActions();
|
||||
void setupConnections();
|
||||
|
||||
private:
|
||||
private:
|
||||
DanbooruClientView *m_view;
|
||||
DanbooruPostModel* m_model;
|
||||
DanbooruService* m_service;
|
||||
DanbooruConnectWidget* m_connectWidget;
|
||||
DanbooruPostModel *m_model;
|
||||
DanbooruService *m_service;
|
||||
DanbooruConnectWidget *m_connectWidget;
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
} // namespace Danbooru
|
||||
|
||||
#endif // _DANBOORU_CLIENT_H_
|
||||
|
|
|
@ -39,14 +39,14 @@
|
|||
#include <KIconLoader>
|
||||
#include <KFormat>
|
||||
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
namespace Danbooru {
|
||||
const int DanbooruPostDelegate::MARGIN = 5;
|
||||
|
||||
const int DanbooruPostDelegate::MARGIN = 5;
|
||||
|
||||
DanbooruPostDelegate::DanbooruPostDelegate(QListView* itemView):QStyledItemDelegate(itemView),
|
||||
DanbooruPostDelegate::DanbooruPostDelegate(QListView *itemView): QStyledItemDelegate(itemView),
|
||||
m_itemView(itemView)
|
||||
{
|
||||
{
|
||||
|
||||
// Get the sizes for the buttons
|
||||
|
||||
|
@ -78,12 +78,12 @@ namespace Danbooru {
|
|||
connect(m_viewButton, &QPushButton::clicked, this, &DanbooruPostDelegate::viewButtonClicked);
|
||||
connect(m_downloadButton, &QPushButton::clicked, this, &DanbooruPostDelegate::downloadButtonClicked);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruPostDelegate::paint(QPainter* painter,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
void DanbooruPostDelegate::paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
|
@ -124,7 +124,6 @@ namespace Danbooru {
|
|||
Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation);
|
||||
|
||||
|
||||
QRect pixRect = scaled.rect();
|
||||
pixRect.moveCenter(rect.center());
|
||||
|
||||
|
@ -161,7 +160,7 @@ namespace Danbooru {
|
|||
|
||||
// Text
|
||||
|
||||
DanbooruPost* post = index.data().value<Danbooru::DanbooruPost*>();
|
||||
DanbooruPost *post = index.data().value<Danbooru::DanbooruPost *>();
|
||||
|
||||
painter->save();
|
||||
|
||||
|
@ -203,11 +202,11 @@ namespace Danbooru {
|
|||
painter->drawText(textRect, imageText);
|
||||
painter->restore();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
QSize DanbooruPostDelegate::sizeHint(const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
QSize DanbooruPostDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
|
||||
Q_UNUSED(option)
|
||||
|
||||
|
@ -217,16 +216,16 @@ namespace Danbooru {
|
|||
|
||||
return m_itemView->gridSize();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex DanbooruPostDelegate::hoveredIndex() const
|
||||
{
|
||||
QModelIndex DanbooruPostDelegate::hoveredIndex() const
|
||||
{
|
||||
const QPoint pos = m_itemView->viewport()->mapFromGlobal(QCursor::pos());
|
||||
return m_itemView->indexAt(pos);
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruPostDelegate::downloadButtonClicked()
|
||||
{
|
||||
void DanbooruPostDelegate::downloadButtonClicked()
|
||||
{
|
||||
QModelIndex index = hoveredIndex();
|
||||
|
||||
if (!index.isValid()) {
|
||||
|
@ -234,15 +233,15 @@ namespace Danbooru {
|
|||
}
|
||||
|
||||
QVariant data = index.data(Qt::DisplayRole);
|
||||
const DanbooruPost* post = data.value<DanbooruPost*>();
|
||||
const DanbooruPost *post = data.value<DanbooruPost *>();
|
||||
|
||||
if (post) {
|
||||
Q_EMIT(postDownloadRequested(post->fileUrl()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruPostDelegate::viewButtonClicked()
|
||||
{
|
||||
void DanbooruPostDelegate::viewButtonClicked()
|
||||
{
|
||||
|
||||
QModelIndex index = hoveredIndex();
|
||||
|
||||
|
@ -251,11 +250,10 @@ namespace Danbooru {
|
|||
}
|
||||
|
||||
QVariant data = index.data(Qt::DisplayRole);
|
||||
const DanbooruPost* post = data.value<DanbooruPost*>();
|
||||
const DanbooruPost *post = data.value<DanbooruPost *>();
|
||||
if (post) {
|
||||
Q_EMIT(postViewRequested(post->fileUrl()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Danbooru
|
||||
|
|
|
@ -37,41 +37,41 @@ class QListView;
|
|||
class QPainter;
|
||||
class QPushButton;
|
||||
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
namespace Danbooru {
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Specific delegate for Danbooru items.
|
||||
*
|
||||
*/
|
||||
|
||||
class DanbooruPost;
|
||||
class DanbooruPost;
|
||||
|
||||
class DanbooruPostDelegate : public QStyledItemDelegate
|
||||
{
|
||||
class DanbooruPostDelegate : public QStyledItemDelegate
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DanbooruPostDelegate(QListView* itemView);
|
||||
public:
|
||||
DanbooruPostDelegate(QListView *itemView);
|
||||
|
||||
void paint(QPainter* painter, const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
QModelIndex hoveredIndex() const;
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
QListView* m_itemView;
|
||||
QPushButton* m_downloadButton;
|
||||
QPushButton* m_viewButton;
|
||||
QListView *m_itemView;
|
||||
QPushButton *m_downloadButton;
|
||||
QPushButton *m_viewButton;
|
||||
|
||||
int m_buttonSize;
|
||||
static const int MARGIN;
|
||||
|
||||
Q_SIGNALS:
|
||||
Q_SIGNALS:
|
||||
|
||||
/**
|
||||
* @brief Emitted when the view button is clicked.
|
||||
|
@ -81,7 +81,6 @@ namespace Danbooru {
|
|||
*/
|
||||
void postViewRequested(QUrl postUrl);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Emitted when the download button is clicked.
|
||||
*
|
||||
|
@ -90,14 +89,11 @@ namespace Danbooru {
|
|||
*/
|
||||
void postDownloadRequested(QUrl postUrl);
|
||||
|
||||
|
||||
private Q_SLOTS:
|
||||
private Q_SLOTS:
|
||||
void viewButtonClicked();
|
||||
void downloadButtonClicked();
|
||||
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Danbooru
|
||||
|
||||
|
|
|
@ -30,38 +30,39 @@
|
|||
#include <QDebug>
|
||||
#include <QPixmap>
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
DanbooruPostModel::DanbooruPostModel(QObject* parent): QAbstractListModel(parent)
|
||||
{
|
||||
DanbooruPostModel::DanbooruPostModel(QObject *parent): QAbstractListModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
DanbooruPostModel::~DanbooruPostModel()
|
||||
{
|
||||
DanbooruPostModel::~DanbooruPostModel()
|
||||
{
|
||||
|
||||
if (!m_items.isEmpty()) {
|
||||
qDeleteAll(m_items);
|
||||
m_items.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int DanbooruPostModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
int DanbooruPostModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
return m_items.size();
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruPostModel::addPost(Danbooru::DanbooruPost* post)
|
||||
{
|
||||
void DanbooruPostModel::addPost(Danbooru::DanbooruPost *post)
|
||||
{
|
||||
|
||||
beginInsertRows(QModelIndex(), m_items.size(), m_items.size());
|
||||
m_items.append(post);
|
||||
endInsertRows();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant DanbooruPostModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
QVariant DanbooruPostModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
|
||||
if (!index.isValid()) {
|
||||
return QVariant();
|
||||
|
@ -75,7 +76,7 @@ namespace Danbooru {
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
DanbooruPost* post = m_items.at(index.row());
|
||||
DanbooruPost *post = m_items.at(index.row());
|
||||
|
||||
if (!post) {
|
||||
return QVariant();
|
||||
|
@ -99,19 +100,20 @@ namespace Danbooru {
|
|||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
void DanbooruPostModel::clear() {
|
||||
void DanbooruPostModel::clear()
|
||||
{
|
||||
|
||||
if (m_items.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
beginRemoveRows(QModelIndex(),0, m_items.size());
|
||||
beginRemoveRows(QModelIndex(), 0, m_items.size());
|
||||
qDeleteAll(m_items);
|
||||
m_items.clear();
|
||||
endRemoveRows();
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -32,11 +32,12 @@
|
|||
#include <QAbstractListModel>
|
||||
#include <QVector>
|
||||
|
||||
namespace Danbooru {
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
class DanbooruPost;
|
||||
class DanbooruPost;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief A model to represent DanbooruItems
|
||||
*
|
||||
* Since items from a Danbooru service are sent by the service itself,
|
||||
|
@ -46,23 +47,23 @@ namespace Danbooru {
|
|||
* Items are added through the addPost() slot.
|
||||
*
|
||||
*/
|
||||
class DanbooruPostModel : public QAbstractListModel
|
||||
{
|
||||
class DanbooruPostModel : public QAbstractListModel
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DanbooruPostModel(QObject* parent=0);
|
||||
public:
|
||||
DanbooruPostModel(QObject *parent = 0);
|
||||
~DanbooruPostModel();
|
||||
|
||||
int rowCount(const QModelIndex& parent=QModelIndex()) const;
|
||||
QVariant data(const QModelIndex& index, int role) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
void clear();
|
||||
|
||||
private:
|
||||
QVector<DanbooruPost*> m_items;
|
||||
private:
|
||||
QVector<DanbooruPost *> m_items;
|
||||
|
||||
public Q_SLOTS:
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* @brief Add a new post to the model
|
||||
*
|
||||
|
@ -71,10 +72,9 @@ namespace Danbooru {
|
|||
* @param post A pointer to a DanbooruPost.
|
||||
*
|
||||
*/
|
||||
void addPost(Danbooru::DanbooruPost* post);
|
||||
void addPost(Danbooru::DanbooruPost *post);
|
||||
|
||||
};
|
||||
};
|
||||
}; // namespace Danbooru
|
||||
|
||||
|
||||
#endif // DANBOORUPOSTMODEL_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue