Handle blacklists and user-supplied URLs in main window

Previously, hardcoded URLs would be supplied to the connect widget: now
the preferences are correctly handled.
This commit is contained in:
Luca Beltrame 2015-02-15 22:03:57 +01:00
parent 64021c47e9
commit 169c10288e

View file

@ -47,6 +47,7 @@
#include "danboorusearchwidget.h" #include "danboorusearchwidget.h"
#include "danboorusettings.h" #include "danboorusettings.h"
#include "generalpage.h" #include "generalpage.h"
#include "blacklistpage.h"
namespace Danbooru namespace Danbooru
{ {
@ -63,17 +64,15 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
m_model(new DanbooruPostModel(this)), m_model(new DanbooruPostModel(this)),
m_poolModel(new DanbooruPoolModel(this)), m_poolModel(new DanbooruPoolModel(this)),
m_service(new DanbooruService()), m_service(new DanbooruService()),
m_connectWidget(nullptr), m_connectWidget(Q_NULLPTR),
m_searchWidget(new DanbooruSearchWidget(this)), m_searchWidget(new DanbooruSearchWidget(this)),
m_tableView(new QTableView(this)), m_tableView(new QTableView(this)),
m_cache(nullptr) m_cache(Q_NULLPTR)
{ {
m_service->setParent(this); m_service->setParent(this);
setCentralWidget(m_view); setCentralWidget(m_view);
// QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
qmlRegisterType<Danbooru::DanbooruPost>("DanbooruClient", 1, 0, "DanbooruPost"); qmlRegisterType<Danbooru::DanbooruPost>("DanbooruClient", 1, 0, "DanbooruPost");
qmlRegisterType<Danbooru::DanbooruService>("DanbooruClient", 1, 0, "DanbooruService"); qmlRegisterType<Danbooru::DanbooruService>("DanbooruClient", 1, 0, "DanbooruService");
qRegisterMetaType<DanbooruPost::Rating>(); qRegisterMetaType<DanbooruPost::Rating>();
@ -100,11 +99,7 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
m_view->setSource(QUrl::fromLocalFile(qmlViewPath)); m_view->setSource(QUrl::fromLocalFile(qmlViewPath));
m_view->rootObject()->setProperty("poolMode", QVariant(false)); m_view->rootObject()->setProperty("poolMode", QVariant(false));
QVector<QUrl> boardsList = { QUrl("http://konachan.com"), QUrl("https://yande.re") };
m_connectWidget = new DanbooruConnectWidget(boardsList, this);
statusBar()->addPermanentWidget(m_connectWidget); statusBar()->addPermanentWidget(m_connectWidget);
m_connectWidget->hide();
setupDockWidgets(); setupDockWidgets();
@ -190,6 +185,24 @@ void DanbooruMainWindow::loadSettings()
m_service->setMaxPosts(DanbooruSettings::self()->maxPosts()); m_service->setMaxPosts(DanbooruSettings::self()->maxPosts());
QVector<QUrl> boardsList;
QStringList::const_iterator it;
for(it = DanbooruSettings::self()->boards().constBegin();
it != DanbooruSettings::self()->boards().constEnd();
++it) {
boardsList.append(QUrl::fromUserInput(*it));
}
if (!m_connectWidget) {
m_connectWidget = new DanbooruConnectWidget(boardsList, this);
} else {
m_connectWidget->setBoards(boardsList);
}
} }
@ -321,6 +334,7 @@ void DanbooruMainWindow::connectToBoard()
m_model->clear(); m_model->clear();
m_poolModel->clear(); m_poolModel->clear();
m_service->reset(); m_service->reset();
statusBar()->show();
m_connectWidget->show(); m_connectWidget->show();
} }
@ -345,6 +359,8 @@ void DanbooruMainWindow::optionsPreferences()
dialog->addPage(new GeneralPage(DanbooruSettings::self(), this), i18n("General"), dialog->addPage(new GeneralPage(DanbooruSettings::self(), this), i18n("General"),
"table"); "table");
dialog->addPage(new BlacklistPage(DanbooruSettings::self(), this), i18n("Tag blacklist"),
"configure");
connect(dialog, &KConfigDialog::settingsChanged, this, &DanbooruMainWindow::loadSettings); connect(dialog, &KConfigDialog::settingsChanged, this, &DanbooruMainWindow::loadSettings);
dialog->show(); dialog->show();
} }