Use kdelibs coding style
This commit is contained in:
parent
0084798a2c
commit
d965371d23
31 changed files with 201 additions and 234 deletions
|
@ -108,7 +108,6 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
|||
m_tableView->setModel(m_poolModel);
|
||||
m_tagWidget->setModel(m_proxyModel);
|
||||
|
||||
|
||||
// Set up declarative bindings for the QQuickWidget
|
||||
|
||||
m_view->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
|
@ -117,7 +116,7 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
|||
declarative.setupBindings();
|
||||
|
||||
auto qmlViewPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
|
||||
qApp->applicationName() + QLatin1String("/danbooruimageview.qml"));
|
||||
qApp->applicationName() + QLatin1String("/danbooruimageview.qml"));
|
||||
|
||||
QQmlContext *ctxt = m_view->rootContext();
|
||||
ctxt->setContextProperty("danbooruModel", m_model);
|
||||
|
@ -136,7 +135,7 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
|||
|
||||
// then, setup our actions
|
||||
setupActions();
|
||||
setupGUI(KXmlGuiWindow::ToolBar|Keys|Save|Create, "danbooru-clientui.rc");
|
||||
setupGUI(KXmlGuiWindow::ToolBar | Keys | Save | Create, "danbooru-clientui.rc");
|
||||
|
||||
// connections
|
||||
|
||||
|
@ -144,7 +143,7 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
|||
|
||||
m_service->setBoardUrl(m_connectWidget->boardUrl());
|
||||
if (!m_connectWidget->isAnonymous() && !m_connectWidget->username().isEmpty()
|
||||
&& !m_connectWidget->password().isEmpty()) {
|
||||
&& !m_connectWidget->password().isEmpty()) {
|
||||
|
||||
m_service->setUserName(m_connectWidget->username());
|
||||
m_service->setPassword(m_connectWidget->password());
|
||||
|
@ -178,8 +177,8 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
|||
&DanbooruTagModel::addTag);
|
||||
connect(m_service, &Danbooru::DanbooruService::poolDownloadFinished, [this]() {
|
||||
m_tableView->resizeColumnsToContents();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
connect(m_tableView, &QTableView::doubleClicked, [this](QModelIndex index) {
|
||||
auto pool = m_poolModel->poolAt(index.row());
|
||||
|
@ -192,15 +191,15 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
|||
|
||||
connect(m_searchWidget, &DanbooruSearchWidget::accepted, [this]() {
|
||||
|
||||
QDockWidget* searchDockWidget = findChild<QDockWidget*>(QLatin1String("SearchView"));
|
||||
searchDockWidget->hide();
|
||||
QDockWidget *searchDockWidget = findChild<QDockWidget *>(QLatin1String("SearchView"));
|
||||
searchDockWidget->hide();
|
||||
|
||||
handlePostDownload(m_searchWidget->selectedTags(), true /* relatedTags */);
|
||||
handlePostDownload(m_searchWidget->selectedTags(), true /* relatedTags */);
|
||||
|
||||
});
|
||||
|
||||
connect(m_searchWidget, &DanbooruSearchWidget::rejected, [this]() {
|
||||
QDockWidget* searchDockWidget = findChild<QDockWidget*>(QLatin1String("SearchView"));
|
||||
QDockWidget *searchDockWidget = findChild<QDockWidget *>(QLatin1String("SearchView"));
|
||||
searchDockWidget->hide();
|
||||
});
|
||||
|
||||
|
@ -208,7 +207,7 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
|||
|
||||
if (m_tagModel->rowCount() == 0) {
|
||||
// Only get tags if we don't have any already
|
||||
for (auto tag: m_model->postTags()) {
|
||||
for (auto tag : m_model->postTags()) {
|
||||
m_service->getTagList(1, tag);
|
||||
}
|
||||
}
|
||||
|
@ -216,8 +215,8 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
|
|||
|
||||
});
|
||||
|
||||
connect(m_view->rootObject(), SIGNAL(downloadRequested(const QUrl&, QVariant)), this,
|
||||
SLOT(slotHandleDownload(const QUrl&, QVariant)));
|
||||
connect(m_view->rootObject(), SIGNAL(downloadRequested(QUrl,QVariant)), this,
|
||||
SLOT(slotHandleDownload(QUrl,QVariant)));
|
||||
|
||||
connect(m_tagWidget, &QListView::doubleClicked, this, &DanbooruMainWindow::searchTag);
|
||||
|
||||
|
@ -240,9 +239,9 @@ void DanbooruMainWindow::loadSettings()
|
|||
|
||||
QStringList::const_iterator it;
|
||||
|
||||
for(it = DanbooruSettings::self()->boards().constBegin();
|
||||
it != DanbooruSettings::self()->boards().constEnd();
|
||||
++it) {
|
||||
for (it = DanbooruSettings::self()->boards().constBegin();
|
||||
it != DanbooruSettings::self()->boards().constEnd();
|
||||
++it) {
|
||||
|
||||
boardsList.append(QUrl::fromUserInput(*it));
|
||||
|
||||
|
@ -257,11 +256,10 @@ void DanbooruMainWindow::loadSettings()
|
|||
m_tagWidget->setBlackList(DanbooruSettings::self()->tagBlacklist());
|
||||
|
||||
m_view->rootContext()->setContextProperty("infiniteScroll",
|
||||
DanbooruSettings::self()->infiniteScrolling());
|
||||
DanbooruSettings::self()->infiniteScrolling());
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DanbooruMainWindow::setupActions()
|
||||
{
|
||||
|
||||
|
@ -273,15 +271,15 @@ void DanbooruMainWindow::setupActions()
|
|||
QAction *fetchAction = new QAction(QIcon::fromTheme(QLatin1String("download")),
|
||||
i18n("Download"), this);
|
||||
KToggleAction *findAction = new KToggleAction(QIcon::fromTheme(QLatin1String("edit-find")),
|
||||
i18n("Search"), this);
|
||||
i18n("Search"), this);
|
||||
KToggleAction *poolAction = new KToggleAction(QIcon::fromTheme(QLatin1String("image-x-generic")),
|
||||
i18n("Pools"), this);
|
||||
i18n("Pools"), this);
|
||||
QAction *nextPageAction = new QAction(QIcon::fromTheme(QLatin1String("go-next")),
|
||||
i18n("More posts"), this);
|
||||
QAction *nextPoolAction = new QAction(QIcon::fromTheme(QLatin1String("go-next")),
|
||||
i18n("More pools"), this);
|
||||
|
||||
KDualAction* tagAction = new KDualAction(i18n("Show tags"), i18n("Hide tags"), this);
|
||||
KDualAction *tagAction = new KDualAction(i18n("Show tags"), i18n("Hide tags"), this);
|
||||
tagAction->setIconForStates(QIcon::fromTheme(QLatin1String("tag")));
|
||||
|
||||
fetchAction->setEnabled(false);
|
||||
|
@ -316,7 +314,7 @@ void DanbooruMainWindow::setupActions()
|
|||
return;
|
||||
}
|
||||
|
||||
QDockWidget* poolDockWidget = findChild<QDockWidget*>(QLatin1String("PoolView"));
|
||||
QDockWidget *poolDockWidget = findChild<QDockWidget *>(QLatin1String("PoolView"));
|
||||
|
||||
if (checked) {
|
||||
|
||||
|
@ -329,7 +327,6 @@ void DanbooruMainWindow::setupActions()
|
|||
actionCollection()->action(QLatin1String("morePools"))->setEnabled(true);
|
||||
m_tableView->show();
|
||||
|
||||
|
||||
} else {
|
||||
poolDockWidget->hide();
|
||||
actionCollection()->action(QLatin1String("morePools"))->setEnabled(false);
|
||||
|
@ -339,7 +336,7 @@ void DanbooruMainWindow::setupActions()
|
|||
|
||||
connect(findAction, &KToggleAction::toggled, [this](bool checked) {
|
||||
|
||||
QDockWidget* searchDockWidget = findChild<QDockWidget*>(QLatin1String("SearchView"));
|
||||
QDockWidget *searchDockWidget = findChild<QDockWidget *>(QLatin1String("SearchView"));
|
||||
|
||||
if (checked) {
|
||||
searchDockWidget->show();
|
||||
|
@ -353,7 +350,7 @@ void DanbooruMainWindow::setupActions()
|
|||
|
||||
connect(tagAction, &KDualAction::activeChanged, [this](bool checked) {
|
||||
|
||||
QDockWidget* tagDockWidget = findChild<QDockWidget*>(QLatin1String("TagView"));
|
||||
QDockWidget *tagDockWidget = findChild<QDockWidget *>(QLatin1String("TagView"));
|
||||
|
||||
if (checked) {
|
||||
tagDockWidget->show();
|
||||
|
@ -373,21 +370,21 @@ void DanbooruMainWindow::setupActions()
|
|||
|
||||
QMetaObject::invokeMethod(m_view->rootObject(), "downloadStarted");
|
||||
m_service->nextPostPage();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
connect(nextPoolAction, &QAction::triggered, [this]() {
|
||||
m_service->nextPoolPage();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void DanbooruMainWindow::setupDockWidgets() {
|
||||
void DanbooruMainWindow::setupDockWidgets()
|
||||
{
|
||||
|
||||
// Set up PoolWidget
|
||||
|
||||
QDockWidget* poolDockWidget = new QDockWidget(i18n("Pools"), this);
|
||||
QDockWidget *poolDockWidget = new QDockWidget(i18n("Pools"), this);
|
||||
poolDockWidget->setAllowedAreas(Qt::BottomDockWidgetArea);
|
||||
poolDockWidget->setWidget(m_tableView);
|
||||
poolDockWidget->setObjectName("PoolView");
|
||||
|
@ -433,7 +430,7 @@ void DanbooruMainWindow::setupDockWidgets() {
|
|||
});
|
||||
|
||||
connect(tagDockWidget, &QDockWidget::visibilityChanged, [this](bool visible) {
|
||||
qobject_cast<KDualAction*>(actionCollection()->action(QLatin1String("tags")))->setActive(visible);
|
||||
qobject_cast<KDualAction *>(actionCollection()->action(QLatin1String("tags")))->setActive(visible);
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -459,30 +456,29 @@ void DanbooruMainWindow::downloadPosts()
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
handlePostDownload(QStringList(), false);
|
||||
|
||||
}
|
||||
|
||||
void DanbooruMainWindow::optionsPreferences()
|
||||
{
|
||||
KConfigDialog* dialog = new KConfigDialog(this, "danboorusettings",
|
||||
DanbooruSettings::self());
|
||||
KConfigDialog *dialog = new KConfigDialog(this, "danboorusettings",
|
||||
DanbooruSettings::self());
|
||||
|
||||
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);
|
||||
dialog->show();
|
||||
}
|
||||
|
||||
void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags) {
|
||||
|
||||
void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags)
|
||||
{
|
||||
|
||||
QStringList tagList = tags.toStringList();
|
||||
|
||||
KIO::MimetypeJob* mimeJob = KIO::mimetype(url, KIO::HideProgressInfo);
|
||||
KIO::MimetypeJob *mimeJob = KIO::mimetype(url, KIO::HideProgressInfo);
|
||||
|
||||
QString filters;
|
||||
QString remoteFile = url.fileName();
|
||||
|
@ -498,14 +494,13 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags
|
|||
remoteFile.replace(":", "_");
|
||||
}
|
||||
|
||||
QUrl localFile = QFileDialog::getSaveFileUrl(
|
||||
this,
|
||||
i18n("Save file"),
|
||||
QDir::homePath() + QLatin1Char('/') + remoteFile,
|
||||
filters
|
||||
|
||||
);
|
||||
QUrl localFile = QFileDialog::getSaveFileUrl(
|
||||
this,
|
||||
i18n("Save file"),
|
||||
QDir::homePath() + QLatin1Char('/') + remoteFile,
|
||||
filters
|
||||
|
||||
);
|
||||
|
||||
// TODO: Remember last user directory - settings?
|
||||
|
||||
|
@ -513,17 +508,17 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags
|
|||
|
||||
KIO::FileCopyJob *job = KIO::file_copy(url, localFile, -1, KIO::DefaultFlags);
|
||||
|
||||
connect(job, &KIO::Job::result, [this, localFile, tagList](KJob *job) {
|
||||
connect(job, &KIO::Job::result, [this, localFile, tagList](KJob * job) {
|
||||
|
||||
if (job->error()) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef WITH_KFILEMETADATA
|
||||
#ifdef WITH_KFILEMETADATA
|
||||
qCDebug(DANBOORU_CLIENT) << "Local file" << localFile.toLocalFile();
|
||||
KFileMetaData::UserMetaData meta(localFile.toLocalFile());
|
||||
meta.setTags(tagList);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
});
|
||||
|
||||
|
@ -554,14 +549,13 @@ void DanbooruMainWindow::clearModels()
|
|||
|
||||
}
|
||||
|
||||
|
||||
void DanbooruMainWindow::handlePostDownload(const QStringList &tags, bool relatedTags)
|
||||
{
|
||||
clearModels();
|
||||
m_view->rootObject()->setProperty("poolMode", QVariant(false));
|
||||
m_service->setPostTags(tags);
|
||||
|
||||
if(relatedTags) {
|
||||
if (relatedTags) {
|
||||
m_service->getRelatedTags(tags);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue