From a35b9520e5caba452f75bfe2180f34497bfe5ca0 Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Tue, 24 Feb 2015 00:17:08 +0100 Subject: [PATCH] Handle tagging (optional) in the main window The include may be off but at the moment KFileMetaData is borked.. --- src/mainwindow.cpp | 24 +++++++++++++++++++----- src/mainwindow.h | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 30e6bf8..012f19e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -45,6 +45,10 @@ #include #include +#ifdef WITH_KFILEMETADATA +#include +#endif + // Own #include "libdanbooru/danbooruservice.h" @@ -212,8 +216,8 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent) }); - connect(m_view->rootObject(), SIGNAL(downloadRequested(const QUrl&)), this, - SLOT(slotHandleDownload(const QUrl&))); + connect(m_view->rootObject(), SIGNAL(downloadRequested(const QUrl&, QVariant)), this, + SLOT(slotHandleDownload(const QUrl&, QVariant))); connect(m_tagWidget, &QListView::doubleClicked, this, &DanbooruMainWindow::searchTag); @@ -457,7 +461,10 @@ void DanbooruMainWindow::optionsPreferences() dialog->show(); } -void DanbooruMainWindow::slotHandleDownload(const QUrl &url) { +void DanbooruMainWindow::slotHandleDownload(const QUrl &url, const QVariant tags) { + + + QStringList tagList = tags.toStringList(); QFileDialog saveDialog(this); saveDialog.setFileMode(QFileDialog::AnyFile); @@ -487,11 +494,18 @@ void DanbooruMainWindow::slotHandleDownload(const QUrl &url) { KIO::FileCopyJob *job = KIO::file_copy(url, localFile, -1, KIO::DefaultFlags); - connect(job, &KIO::Job::result, [this](KJob *job) { + connect(job, &KIO::Job::result, [this, localFile, tagList](KJob *job) { + if (job->error()) { return; } - // TODO: Tagging + + #ifdef WITH_KFILEMETADATA + qDebug() << "Local file" << localFile.toLocalFile(); + KFileMetaData::UserMetaData meta(localFile.toLocalFile()); + meta.setTags(tagList); + #endif + }); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 8b1b18b..5657fe9 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -100,7 +100,7 @@ private Q_SLOTS: void downloadPosts(); void optionsPreferences(); void loadSettings(); - void slotHandleDownload(const QUrl &url); + void slotHandleDownload(const QUrl &url, QVariant tags); void searchTag(const QModelIndex &index); };