Add functionality to ensure that the basic system works
There are some things missing: - Configuration - Resuming downloads when the list doesn't scroll past the window
This commit is contained in:
parent
d94084bc25
commit
735d08f1a8
3 changed files with 63 additions and 11 deletions
|
@ -4,9 +4,9 @@ set(danbooru_client_SRCS
|
|||
danbooruconnectwidget.cpp
|
||||
model/danboorupostdelegate.cpp
|
||||
model/danboorupostmodel.cpp
|
||||
test.cpp
|
||||
# mainwindow.cpp
|
||||
# danbooru_client.cpp
|
||||
# test.cpp
|
||||
mainwindow.cpp
|
||||
danbooru_client.cpp
|
||||
testwidget.cpp
|
||||
testpostdata.cpp
|
||||
)
|
||||
|
|
|
@ -23,37 +23,53 @@
|
|||
#include <QQuickWidget>
|
||||
#include <QQmlContext>
|
||||
#include <QApplication>
|
||||
#include <QGuiApplication>
|
||||
#include <QStandardPaths>
|
||||
#include <QUrl>
|
||||
#include <QDebug>
|
||||
|
||||
#include <kactioncollection.h>
|
||||
#include <KStandardAction>
|
||||
#include <KLocalizedString>
|
||||
#include <kdeclarative.h>
|
||||
#include <KDeclarative/KDeclarative>
|
||||
|
||||
#include "libdanbooru/danbooruservice.h"
|
||||
#include "libdanbooru/danboorupost.h"
|
||||
#include "model/danboorupostmodel.h"
|
||||
#include "mainwindow.h"
|
||||
#include "danbooruconnectwidget.h"
|
||||
|
||||
namespace Danbooru
|
||||
{
|
||||
|
||||
DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
||||
: KXmlGuiWindow(parent),
|
||||
m_view(0),
|
||||
m_model(0),
|
||||
m_service(0)
|
||||
m_view(new QQuickWidget(this)),
|
||||
m_model(new DanbooruPostModel(this)),
|
||||
m_service(new DanbooruService()),
|
||||
m_cache(0)
|
||||
{
|
||||
auto *m_view = new QQuickWidget(this);
|
||||
// tell the KXmlGuiWindow that this is indeed the main widget
|
||||
auto *m_model = new DanbooruPostModel(this);
|
||||
|
||||
m_service->setParent(this);
|
||||
setCentralWidget(m_view);
|
||||
|
||||
// QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
|
||||
|
||||
qmlRegisterType<Danbooru::DanbooruPost>("DanbooruClient", 1, 0, "DanbooruPost");
|
||||
qmlRegisterType<Danbooru::DanbooruService>("DanbooruClient", 1, 0, "DanbooruService");
|
||||
qRegisterMetaType<DanbooruPost::Rating>();
|
||||
|
||||
// TODO Configurable
|
||||
m_cache = new KImageCache(qApp->applicationName(), 20000000);
|
||||
m_service->setImageCache(m_cache);
|
||||
|
||||
// Set up declarative bindings for the QQuickWidget
|
||||
|
||||
m_view->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
KDeclarative::KDeclarative declarative;
|
||||
declarative.setDeclarativeEngine(m_view->engine());
|
||||
declarative.setupBindings();
|
||||
|
||||
auto qmlViewPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
|
||||
qApp->applicationName() + QChar('/') + QLatin1Literal("danbooruimageview.qml"));
|
||||
|
||||
|
@ -62,6 +78,12 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
|||
ctxt->setContextProperty("danbooruService", m_service);
|
||||
m_view->setSource(QUrl::fromLocalFile(qmlViewPath));
|
||||
|
||||
QVector<QUrl> boardsList = { QUrl("http://konachan.com"), QUrl("https://yande.re") };
|
||||
|
||||
m_connectWidget = new DanbooruConnectWidget(boardsList);
|
||||
statusBar()->addPermanentWidget(m_connectWidget);
|
||||
m_connectWidget->hide();
|
||||
|
||||
// then, setup our actions
|
||||
setupActions();
|
||||
|
||||
|
@ -70,6 +92,28 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
|||
|
||||
setupGUI(KXmlGuiWindow::ToolBar|Keys|Save|Create|StatusBar, "danbooru-clientui.rc");
|
||||
|
||||
// connections
|
||||
|
||||
connect(m_connectWidget, &DanbooruConnectWidget::accepted, [this]() {
|
||||
m_service->setBoardUrl(m_connectWidget->boardUrl());
|
||||
if (!m_connectWidget->isAnonymous() && !m_connectWidget->username().isEmpty()
|
||||
&& !m_connectWidget->password().isEmpty()) {
|
||||
|
||||
m_service->setUserName(m_connectWidget->username());
|
||||
m_service->setPassword(m_connectWidget->password());
|
||||
}
|
||||
|
||||
actionCollection()->action(QLatin1String("fetch"))->setEnabled(true);
|
||||
m_connectWidget->hide();
|
||||
|
||||
});
|
||||
|
||||
connect(m_connectWidget, &DanbooruConnectWidget::rejected, [this]() {
|
||||
m_connectWidget->hide();
|
||||
});
|
||||
|
||||
connect(m_service, &Danbooru::DanbooruService::postDownloaded, m_model, &Danbooru::DanbooruPostModel::addPost);
|
||||
|
||||
}
|
||||
|
||||
DanbooruMainWindow::~DanbooruMainWindow()
|
||||
|
@ -95,7 +139,7 @@ void DanbooruMainWindow::setupActions()
|
|||
actionCollection()->setDefaultShortcut(fetchAction, KStandardShortcut::Find);
|
||||
// actionCollection()->removeAction(actionCollection()->action("help_contents"));
|
||||
|
||||
KStandardAction::quit(qApp, SLOT(close()), actionCollection());
|
||||
KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
|
||||
connect(connectAction, &QAction::triggered, this, &DanbooruMainWindow::connectToBoard);
|
||||
connect(fetchAction, &QAction::triggered, this, &DanbooruMainWindow::downloadPosts);
|
||||
|
||||
|
@ -108,6 +152,9 @@ void DanbooruMainWindow::connectToBoard()
|
|||
return;
|
||||
}
|
||||
|
||||
m_model->clear();
|
||||
m_connectWidget->show();
|
||||
|
||||
}
|
||||
|
||||
void DanbooruMainWindow::downloadPosts()
|
||||
|
@ -116,6 +163,7 @@ void DanbooruMainWindow::downloadPosts()
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO Pick from configuration
|
||||
m_service->getPostList(1, QStringList(), 10);
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#define DANBOORU_CLIENT_H
|
||||
|
||||
#include <kxmlguiwindow.h>
|
||||
#include <KSharedDataCache>
|
||||
#include <KImageCache>
|
||||
|
||||
|
||||
class QQuickWidget;
|
||||
|
||||
|
@ -71,6 +74,7 @@ private:
|
|||
DanbooruPostModel *m_model;
|
||||
DanbooruService *m_service;
|
||||
DanbooruConnectWidget *m_connectWidget;
|
||||
KImageCache *m_cache;
|
||||
|
||||
};
|
||||
} // namespace Danbooru
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue