Add tag searching when clicking (broken)
This doesn't work at the moment and I've yet to figure out why...
This commit is contained in:
parent
51792459fb
commit
2623fee54d
2 changed files with 90 additions and 12 deletions
|
@ -37,6 +37,7 @@
|
||||||
#include <KDeclarative/KDeclarative>
|
#include <KDeclarative/KDeclarative>
|
||||||
#include <KConfigDialog>
|
#include <KConfigDialog>
|
||||||
#include <KToggleAction>
|
#include <KToggleAction>
|
||||||
|
#include <KDualAction>
|
||||||
#include <KIO/FileCopyJob>
|
#include <KIO/FileCopyJob>
|
||||||
#include <KIO/MimetypeJob>
|
#include <KIO/MimetypeJob>
|
||||||
|
|
||||||
|
@ -45,9 +46,11 @@
|
||||||
#include "libdanbooru/danboorupool.h"
|
#include "libdanbooru/danboorupool.h"
|
||||||
#include "model/danboorupostmodel.h"
|
#include "model/danboorupostmodel.h"
|
||||||
#include "model/danboorupoolmodel.h"
|
#include "model/danboorupoolmodel.h"
|
||||||
|
#include "model/danboorutagmodel.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "danbooruconnectwidget.h"
|
#include "danbooruconnectwidget.h"
|
||||||
#include "danboorusearchwidget.h"
|
#include "danboorusearchwidget.h"
|
||||||
|
#include "danboorutagwidget.h"
|
||||||
#include "danboorusettings.h"
|
#include "danboorusettings.h"
|
||||||
#include "generalpage.h"
|
#include "generalpage.h"
|
||||||
#include "blacklistpage.h"
|
#include "blacklistpage.h"
|
||||||
|
@ -66,9 +69,11 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
||||||
m_view(new QQuickWidget(this)),
|
m_view(new QQuickWidget(this)),
|
||||||
m_model(new DanbooruPostModel(this)),
|
m_model(new DanbooruPostModel(this)),
|
||||||
m_poolModel(new DanbooruPoolModel(this)),
|
m_poolModel(new DanbooruPoolModel(this)),
|
||||||
|
m_tagModel(new DanbooruTagModel(this)),
|
||||||
m_service(new DanbooruService()),
|
m_service(new DanbooruService()),
|
||||||
m_connectWidget(Q_NULLPTR),
|
m_connectWidget(Q_NULLPTR),
|
||||||
m_searchWidget(new DanbooruSearchWidget(this)),
|
m_searchWidget(new DanbooruSearchWidget(this)),
|
||||||
|
m_tagWidget(new DanbooruTagWidget(this)),
|
||||||
m_tableView(new QTableView(this)),
|
m_tableView(new QTableView(this)),
|
||||||
m_cache(Q_NULLPTR)
|
m_cache(Q_NULLPTR)
|
||||||
{
|
{
|
||||||
|
@ -85,6 +90,7 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
||||||
m_cache = new KImageCache(qApp->applicationName(), DanbooruSettings::self()->cacheSize());
|
m_cache = new KImageCache(qApp->applicationName(), DanbooruSettings::self()->cacheSize());
|
||||||
m_service->setImageCache(m_cache);
|
m_service->setImageCache(m_cache);
|
||||||
m_tableView->setModel(m_poolModel);
|
m_tableView->setModel(m_poolModel);
|
||||||
|
m_tagWidget->setModel(m_tagModel);
|
||||||
|
|
||||||
// Set up declarative bindings for the QQuickWidget
|
// Set up declarative bindings for the QQuickWidget
|
||||||
|
|
||||||
|
@ -125,11 +131,13 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
||||||
actionCollection()->action(QLatin1String("fetch"))->setEnabled(true);
|
actionCollection()->action(QLatin1String("fetch"))->setEnabled(true);
|
||||||
actionCollection()->action(QLatin1String("find"))->setEnabled(true);
|
actionCollection()->action(QLatin1String("find"))->setEnabled(true);
|
||||||
actionCollection()->action(QLatin1String("poolDownload"))->setEnabled(true);
|
actionCollection()->action(QLatin1String("poolDownload"))->setEnabled(true);
|
||||||
|
actionCollection()->action(QLatin1String("tags"))->setEnabled(true);
|
||||||
|
|
||||||
if (DanbooruSettings::self()->autoDownload()) {
|
if (DanbooruSettings::self()->autoDownload()) {
|
||||||
m_view->rootObject()->setProperty("poolMode", QVariant(false));
|
m_view->rootObject()->setProperty("poolMode", QVariant(false));
|
||||||
m_service->setPostTags(QStringList());
|
m_service->setPostTags(QStringList());
|
||||||
m_service->getPostList();
|
m_service->getPostList();
|
||||||
|
m_service->getTagList();
|
||||||
}
|
}
|
||||||
m_connectWidget->hide();
|
m_connectWidget->hide();
|
||||||
statusBar()->hide();
|
statusBar()->hide();
|
||||||
|
@ -144,6 +152,8 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
||||||
&Danbooru::DanbooruPostModel::addPost);
|
&Danbooru::DanbooruPostModel::addPost);
|
||||||
connect(m_service, &Danbooru::DanbooruService::poolDownloaded, m_poolModel,
|
connect(m_service, &Danbooru::DanbooruService::poolDownloaded, m_poolModel,
|
||||||
&DanbooruPoolModel::addPool);
|
&DanbooruPoolModel::addPool);
|
||||||
|
connect(m_service, &Danbooru::DanbooruService::tagDownloaded, m_tagModel,
|
||||||
|
&DanbooruTagModel::addTag);
|
||||||
connect(m_service, &Danbooru::DanbooruService::poolDownloadFinished, [this]() {
|
connect(m_service, &Danbooru::DanbooruService::poolDownloadFinished, [this]() {
|
||||||
m_tableView->resizeColumnsToContents();
|
m_tableView->resizeColumnsToContents();
|
||||||
}
|
}
|
||||||
|
@ -151,7 +161,7 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
||||||
|
|
||||||
connect(m_tableView, &QTableView::doubleClicked, [this](QModelIndex index) {
|
connect(m_tableView, &QTableView::doubleClicked, [this](QModelIndex index) {
|
||||||
auto pool = m_poolModel->poolAt(index.row());
|
auto pool = m_poolModel->poolAt(index.row());
|
||||||
m_model->clear();
|
clearModels();
|
||||||
m_view->rootObject()->setProperty("poolMode", QVariant(true));
|
m_view->rootObject()->setProperty("poolMode", QVariant(true));
|
||||||
m_service->getPool(pool->id());
|
m_service->getPool(pool->id());
|
||||||
|
|
||||||
|
@ -162,10 +172,11 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
||||||
QDockWidget* searchDockWidget = findChild<QDockWidget*>(QLatin1String("SearchView"));
|
QDockWidget* searchDockWidget = findChild<QDockWidget*>(QLatin1String("SearchView"));
|
||||||
searchDockWidget->hide();
|
searchDockWidget->hide();
|
||||||
|
|
||||||
m_model->clear();
|
clearModels();
|
||||||
m_service->setPostTags(m_searchWidget->selectedTags());
|
m_service->setPostTags(m_searchWidget->selectedTags());
|
||||||
m_view->rootObject()->setProperty("poolMode", QVariant(false));
|
m_view->rootObject()->setProperty("poolMode", QVariant(false));
|
||||||
m_service->getPostList();
|
m_service->getPostList();
|
||||||
|
m_service->getRelatedTags(m_searchWidget->selectedTags());
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_searchWidget, &DanbooruSearchWidget::rejected, [this]() {
|
connect(m_searchWidget, &DanbooruSearchWidget::rejected, [this]() {
|
||||||
|
@ -176,6 +187,8 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
||||||
connect(m_view->rootObject(), SIGNAL(downloadRequested(const QUrl&)), this,
|
connect(m_view->rootObject(), SIGNAL(downloadRequested(const QUrl&)), this,
|
||||||
SLOT(slotHandleDownload(const QUrl&)));
|
SLOT(slotHandleDownload(const QUrl&)));
|
||||||
|
|
||||||
|
connect(m_tagWidget, &QListView::doubleClicked, this, &DanbooruMainWindow::searchTag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DanbooruMainWindow::~DanbooruMainWindow()
|
DanbooruMainWindow::~DanbooruMainWindow()
|
||||||
|
@ -209,6 +222,8 @@ void DanbooruMainWindow::loadSettings()
|
||||||
m_connectWidget->setBoards(boardsList);
|
m_connectWidget->setBoards(boardsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_tagWidget->setBlackList(DanbooruSettings::self()->tagBlacklist());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -227,17 +242,22 @@ void DanbooruMainWindow::setupActions()
|
||||||
KToggleAction *poolAction = new KToggleAction(QIcon::fromTheme(QLatin1String("image-x-generic")),
|
KToggleAction *poolAction = new KToggleAction(QIcon::fromTheme(QLatin1String("image-x-generic")),
|
||||||
i18n("Pools"), this);
|
i18n("Pools"), this);
|
||||||
|
|
||||||
|
KDualAction* tagAction = new KDualAction(i18n("Show tags"), i18n("Hide tags"), this);
|
||||||
|
tagAction->setIconForStates(QIcon::fromTheme(QLatin1String("tag")));
|
||||||
|
|
||||||
fetchAction->setEnabled(false);
|
fetchAction->setEnabled(false);
|
||||||
findAction->setEnabled(false);
|
findAction->setEnabled(false);
|
||||||
poolAction->setEnabled(false);
|
poolAction->setEnabled(false);
|
||||||
|
|
||||||
poolAction->setChecked(false);
|
poolAction->setChecked(false);
|
||||||
findAction->setChecked(false);
|
findAction->setChecked(false);
|
||||||
|
tagAction->setEnabled(false);
|
||||||
|
|
||||||
actionCollection()->addAction(QLatin1String("connect"), connectAction);
|
actionCollection()->addAction(QLatin1String("connect"), connectAction);
|
||||||
actionCollection()->addAction(QLatin1String("fetch"), fetchAction);
|
actionCollection()->addAction(QLatin1String("fetch"), fetchAction);
|
||||||
actionCollection()->addAction(QLatin1String("find"), findAction);
|
actionCollection()->addAction(QLatin1String("find"), findAction);
|
||||||
actionCollection()->addAction(QLatin1String("poolDownload"), poolAction);
|
actionCollection()->addAction(QLatin1String("poolDownload"), poolAction);
|
||||||
|
actionCollection()->addAction(QLatin1String("tags"), tagAction);
|
||||||
|
|
||||||
actionCollection()->setDefaultShortcut(connectAction, KStandardShortcut::Open);
|
actionCollection()->setDefaultShortcut(connectAction, KStandardShortcut::Open);
|
||||||
actionCollection()->setDefaultShortcut(findAction, KStandardShortcut::Find);
|
actionCollection()->setDefaultShortcut(findAction, KStandardShortcut::Find);
|
||||||
|
@ -285,6 +305,20 @@ void DanbooruMainWindow::setupActions()
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(tagAction, &KDualAction::activeChanged, [this](bool checked) {
|
||||||
|
|
||||||
|
QDockWidget* tagDockWidget = findChild<QDockWidget*>(QLatin1String("TagView"));
|
||||||
|
|
||||||
|
if (checked) {
|
||||||
|
tagDockWidget->show();
|
||||||
|
m_tagWidget->show();
|
||||||
|
} else {
|
||||||
|
tagDockWidget->hide();
|
||||||
|
m_tagWidget->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -317,6 +351,15 @@ void DanbooruMainWindow::setupDockWidgets() {
|
||||||
searchDockWidget->hide();
|
searchDockWidget->hide();
|
||||||
m_searchWidget->hide();
|
m_searchWidget->hide();
|
||||||
|
|
||||||
|
QDockWidget *tagDockWidget = new QDockWidget(QLatin1String("Tags"), this);
|
||||||
|
tagDockWidget->setAllowedAreas(Qt::RightDockWidgetArea);
|
||||||
|
tagDockWidget->setWidget(m_tagWidget);
|
||||||
|
tagDockWidget->setObjectName("TagView");
|
||||||
|
tagDockWidget->setFeatures(QDockWidget::DockWidgetClosable);
|
||||||
|
addDockWidget(Qt::RightDockWidgetArea, tagDockWidget);
|
||||||
|
|
||||||
|
// tagDockWidget->hide();
|
||||||
|
// m_tagWidget->hide();
|
||||||
|
|
||||||
// Connections
|
// Connections
|
||||||
|
|
||||||
|
@ -328,6 +371,10 @@ void DanbooruMainWindow::setupDockWidgets() {
|
||||||
actionCollection()->action(QLatin1String("find"))->setChecked(visible);
|
actionCollection()->action(QLatin1String("find"))->setChecked(visible);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(tagDockWidget, &QDockWidget::visibilityChanged, [this](bool visible) {
|
||||||
|
qobject_cast<KDualAction*>(actionCollection()->action(QLatin1String("tags")))->setActive(visible);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DanbooruMainWindow::connectToBoard()
|
void DanbooruMainWindow::connectToBoard()
|
||||||
|
@ -337,8 +384,8 @@ void DanbooruMainWindow::connectToBoard()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_model->clear();
|
|
||||||
m_poolModel->clear();
|
clearModels();
|
||||||
m_service->reset();
|
m_service->reset();
|
||||||
statusBar()->show();
|
statusBar()->show();
|
||||||
m_connectWidget->show();
|
m_connectWidget->show();
|
||||||
|
@ -355,6 +402,7 @@ void DanbooruMainWindow::downloadPosts()
|
||||||
m_service->setPostTags(QStringList());
|
m_service->setPostTags(QStringList());
|
||||||
m_view->rootObject()->setProperty("poolMode", QVariant(false));
|
m_view->rootObject()->setProperty("poolMode", QVariant(false));
|
||||||
m_service->getPostList();
|
m_service->getPostList();
|
||||||
|
m_service->getTagList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,14 +437,15 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url) {
|
||||||
// TODO: Remember last user directory - settings?
|
// TODO: Remember last user directory - settings?
|
||||||
|
|
||||||
saveDialog.setConfirmOverwrite(true);
|
saveDialog.setConfirmOverwrite(true);
|
||||||
saveDialog.setDirectory(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
saveDialog.setDirectory(QDir::homePath());
|
||||||
saveDialog.selectFile(url.fileName());
|
saveDialog.selectFile(url.fileName());
|
||||||
|
|
||||||
if (saveDialog.exec()) {
|
if (saveDialog.exec()) {
|
||||||
QString localFileName = saveDialog.selectedFiles().at(0);
|
QUrl localFile = saveDialog.selectedUrls().at(0);
|
||||||
QUrl localFile = QUrl::fromLocalFile(localFileName);
|
|
||||||
|
|
||||||
qDebug() << "URL" << localFile;
|
if (localFile.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
KIO::FileCopyJob *job = KIO::file_copy(url, localFile, -1, KIO::DefaultFlags);
|
KIO::FileCopyJob *job = KIO::file_copy(url, localFile, -1, KIO::DefaultFlags);
|
||||||
|
|
||||||
|
@ -404,10 +453,35 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url) {
|
||||||
if (job->error()) {
|
if (job->error()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// TODO: Tagging
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DanbooruMainWindow::searchTag(const QModelIndex &index)
|
||||||
|
{
|
||||||
|
|
||||||
|
qDebug() << "Clicked"
|
||||||
|
// DanbooruTag *tag = m_tagModel->itemAt(index.row());
|
||||||
|
//
|
||||||
|
// if(!tag) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// auto tagList = QStringList {tag->name()};
|
||||||
|
// clearModels();
|
||||||
|
// m_service->setPostTags(tagList);
|
||||||
|
// m_service->getPostList();
|
||||||
|
// m_service->getRelatedTags(tagList);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DanbooruMainWindow::clearModels()
|
||||||
|
{
|
||||||
|
m_model->clear();
|
||||||
|
m_tagModel->clear();
|
||||||
|
m_poolModel->clear();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Danbooru
|
} // namespace Danbooru
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "libdanbooru/danboorupost.h"
|
#include "libdanbooru/danboorupost.h"
|
||||||
|
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
|
#include <QListView>
|
||||||
|
|
||||||
#include <kxmlguiwindow.h>
|
#include <kxmlguiwindow.h>
|
||||||
#include <KSharedDataCache>
|
#include <KSharedDataCache>
|
||||||
|
@ -35,6 +36,7 @@
|
||||||
|
|
||||||
class QQuickWidget;
|
class QQuickWidget;
|
||||||
|
|
||||||
|
|
||||||
namespace Danbooru
|
namespace Danbooru
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -42,8 +44,10 @@ class DanbooruClientView;
|
||||||
class DanbooruService;
|
class DanbooruService;
|
||||||
class DanbooruPostModel;
|
class DanbooruPostModel;
|
||||||
class DanbooruPoolModel;
|
class DanbooruPoolModel;
|
||||||
|
class DanbooruTagModel;
|
||||||
class DanbooruConnectWidget;
|
class DanbooruConnectWidget;
|
||||||
class DanbooruSearchWidget;
|
class DanbooruSearchWidget;
|
||||||
|
class DanbooruTagWidget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class serves as the main window for danbooru_client. It handles the
|
* This class serves as the main window for danbooru_client. It handles the
|
||||||
|
@ -61,9 +65,11 @@ private:
|
||||||
QQuickWidget *m_view;
|
QQuickWidget *m_view;
|
||||||
DanbooruPostModel *m_model;
|
DanbooruPostModel *m_model;
|
||||||
DanbooruPoolModel *m_poolModel;
|
DanbooruPoolModel *m_poolModel;
|
||||||
|
DanbooruTagModel *m_tagModel;
|
||||||
DanbooruService *m_service;
|
DanbooruService *m_service;
|
||||||
DanbooruConnectWidget *m_connectWidget;
|
DanbooruConnectWidget *m_connectWidget;
|
||||||
DanbooruSearchWidget *m_searchWidget;
|
DanbooruSearchWidget *m_searchWidget;
|
||||||
|
DanbooruTagWidget *m_tagWidget;
|
||||||
QTableView *m_tableView;
|
QTableView *m_tableView;
|
||||||
KImageCache *m_cache;
|
KImageCache *m_cache;
|
||||||
static QHash<int, DanbooruPost::Rating> ratingMap;
|
static QHash<int, DanbooruPost::Rating> ratingMap;
|
||||||
|
@ -83,6 +89,7 @@ private:
|
||||||
void setupActions();
|
void setupActions();
|
||||||
void setupDockWidgets();
|
void setupDockWidgets();
|
||||||
void setupConnections();
|
void setupConnections();
|
||||||
|
void clearModels();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void connectToBoard();
|
void connectToBoard();
|
||||||
|
@ -90,10 +97,7 @@ private Q_SLOTS:
|
||||||
void optionsPreferences();
|
void optionsPreferences();
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void slotHandleDownload(const QUrl &url);
|
void slotHandleDownload(const QUrl &url);
|
||||||
|
void searchTag(const QModelIndex &index);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace Danbooru
|
} // namespace Danbooru
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue