diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6774188..0b29362 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,96 +1,97 @@ add_definitions(-DTRANSLATION_DOMAIN=\"baloowidgets5\") add_subdirectory(filepropertiesplugin) add_subdirectory(tagsfileitemactionplugin) set(widgets_SRCS kblocklayout.cpp tagwidget.cpp kedittagsdialog.cpp tagcheckbox.cpp filemetadatawidget.cpp filemetadataconfigwidget.cpp filemetadataprovider.cpp filemetadatautil.cpp indexeddataretriever.cpp kcommentwidget.cpp keditcommentdialog.cpp metadatafilter.cpp + ondemandextractor.cpp widgetfactory.cpp filefetchjob.cpp ) ecm_qt_declare_logging_category( widgets_SRCS HEADER "widgetsdebug.h" IDENTIFIER "Baloo::WIDGETS" DEFAULT_SEVERITY Warning CATEGORY_NAME "org.kde.baloo.widgets" ) add_library(KF5BalooWidgets ${widgets_SRCS}) add_library(KF5::BalooWidgets ALIAS KF5BalooWidgets) target_link_libraries(KF5BalooWidgets PUBLIC Qt5::Widgets Qt5::Core KF5::KIOCore # KFileItem KF5::CoreAddons # KProcess, KJob PRIVATE KF5::I18n KF5::FileMetaData KF5::WidgetsAddons KF5::Baloo KF5::CoreAddons KF5::ConfigGui ) set_target_properties(KF5BalooWidgets PROPERTIES VERSION ${BALOO_WIDGETS_VERSION_STRING} SOVERSION ${BALOO_WIDGETS_SOVERSION} EXPORT_NAME BalooWidgets ) target_include_directories(KF5BalooWidgets INTERFACE "$") generate_export_header(KF5BalooWidgets BASE_NAME BALOO_WIDGETS EXPORT_FILE_NAME widgets_export.h) install(TARGETS KF5BalooWidgets EXPORT KF5BalooWidgetsTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) ecm_generate_headers(KF5BalooWidgets_CamelCase_HEADERS HEADER_NAMES TagWidget FileMetaDataWidget FileMetaDataConfigWidget PREFIX baloo REQUIRED_HEADERS KF5BalooWidgets_HEADERS ) install(FILES ${KF5BalooWidgets_CamelCase_HEADERS} DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/BalooWidgets/Baloo COMPONENT Devel ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/widgets_export.h ${KF5BalooWidgets_HEADERS} DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/BalooWidgets/baloo COMPONENT Devel ) # # Extractor Process # add_executable(baloo_filemetadata_temp_extractor extractor.cpp filemetadatautil.cpp) target_link_libraries(baloo_filemetadata_temp_extractor Qt5::Core KF5::I18n KF5::FileMetaData ) install(TARGETS baloo_filemetadata_temp_extractor DESTINATION ${BIN_INSTALL_DIR}) diff --git a/src/indexeddataretriever.cpp b/src/indexeddataretriever.cpp index 280688a..6187861 100644 --- a/src/indexeddataretriever.cpp +++ b/src/indexeddataretriever.cpp @@ -1,85 +1,73 @@ /* * * Copyright (C) 2012 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "indexeddataretriever.h" #include "filemetadatautil_p.h" -#include "widgetsdebug.h" -#include "extractorutil_p.h" -#include -#include #include -#include using namespace Baloo; IndexedDataRetriever::IndexedDataRetriever(const QString& fileUrl, QObject* parent): KJob(parent) { - m_url = QFileInfo(fileUrl).canonicalFilePath(); + QFileInfo fileInfo(fileUrl); + m_url = fileInfo.canonicalFilePath(); + m_canEdit = fileInfo.isWritable(); + + connect(&m_extractor, &Private::OnDemandExtractor::fileFinished, this, &IndexedDataRetriever::slotIndexedFile); } IndexedDataRetriever::~IndexedDataRetriever() { } void IndexedDataRetriever::start() { - const QString exe = QStandardPaths::findExecutable(QLatin1String("baloo_filemetadata_temp_extractor")); - - m_process = new QProcess(this); - m_process->setReadChannel(QProcess::StandardOutput); - - connect(m_process, QOverload::of(&QProcess::finished), this, &IndexedDataRetriever::slotIndexedFile); - m_process->start(exe, QStringList() << m_url); -} - -void IndexedDataRetriever::slotIndexedFile(int exitCode, QProcess::ExitStatus exitStatus) -{ - if (exitStatus == QProcess::CrashExit) { - qCWarning(WIDGETS) << "Extractor crashed when processing" << m_url; - } - QByteArray data = m_process->readAllStandardOutput(); - QDataStream in(&data, QIODevice::ReadOnly); - - KFileMetaData::PropertyMap properties; - in >> properties; - - m_data = Baloo::Private::toNamedVariantMap(properties); + m_extractor.process(m_url); KFileMetaData::UserMetaData umd(m_url); if (umd.isSupported()) { - m_canEdit = QFileInfo(m_url).isWritable(); + m_data = Baloo::Private::convertUserMetaData(umd); + m_canEdit &= true; + } else { + m_data.clear(); + m_canEdit &= false; + } +} - QVariantMap attributes = Baloo::Private::convertUserMetaData(umd); - m_data.unite(attributes); +void IndexedDataRetriever::slotIndexedFile(QProcess::ExitStatus status) +{ + if (status == QProcess::NormalExit) { + QVariantMap properties = Baloo::Private::toNamedVariantMap(m_extractor.properties()); + m_data.unite(properties); } emitResult(); } bool IndexedDataRetriever::canEdit() const { return m_canEdit; } QVariantMap IndexedDataRetriever::data() const { return m_data; } diff --git a/src/indexeddataretriever.h b/src/indexeddataretriever.h index bfa1e37..823e014 100644 --- a/src/indexeddataretriever.h +++ b/src/indexeddataretriever.h @@ -1,54 +1,54 @@ /* * * Copyright (C) 2012 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef INDEXEDDATARETRIEVER_H #define INDEXEDDATARETRIEVER_H #include -#include +#include "ondemandextractor.h" #include namespace Baloo { class IndexedDataRetriever : public KJob { Q_OBJECT public: explicit IndexedDataRetriever(const QString& fileUrl, QObject* parent = nullptr); ~IndexedDataRetriever() override; void start() override; QVariantMap data() const; bool canEdit() const; private Q_SLOTS: - void slotIndexedFile(int exitCode, QProcess::ExitStatus exitStatus); + void slotIndexedFile(QProcess::ExitStatus exitStatus); private: QString m_url; - QProcess* m_process; + Private::OnDemandExtractor m_extractor; QVariantMap m_data; bool m_canEdit = false; }; } #endif // INDEXEDDATARETRIEVER_H diff --git a/src/ondemandextractor.cpp b/src/ondemandextractor.cpp new file mode 100644 index 0000000..a789040 --- /dev/null +++ b/src/ondemandextractor.cpp @@ -0,0 +1,71 @@ +/* + * + * Copyright (C) 2019 Stefan Brüns + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "ondemandextractor.h" +#include "widgetsdebug.h" +#include "extractorutil_p.h" + +#include +#include + +namespace Baloo { +namespace Private { + +OnDemandExtractor::OnDemandExtractor(QObject* parent) : QObject(parent) +{ +} + +OnDemandExtractor::~OnDemandExtractor() +{ +} + +void OnDemandExtractor::process(const QString& filePath) +{ + const QString exe = QStandardPaths::findExecutable(QLatin1String("baloo_filemetadata_temp_extractor")); + + m_process.setReadChannel(QProcess::StandardOutput); + + connect(&m_process, QOverload::of(&QProcess::finished), + this, &OnDemandExtractor::slotIndexedFile); + m_process.start(exe, QStringList{ filePath }); +} + +void OnDemandExtractor::slotIndexedFile(int, QProcess::ExitStatus exitStatus) +{ + if (exitStatus == QProcess::CrashExit) { + qCWarning(WIDGETS) << "Extractor crashed when processing" << m_process.arguments(); + emit fileFinished(exitStatus); + return; + } + QByteArray data = m_process.readAllStandardOutput(); + QDataStream in(&data, QIODevice::ReadOnly); + + m_properties.clear(); + in >> m_properties; + emit fileFinished(QProcess::NormalExit); +} + +KFileMetaData::PropertyMap OnDemandExtractor::properties() const +{ + return m_properties; +} + +} // namespace Private +} // namespace Baloo diff --git a/src/indexeddataretriever.h b/src/ondemandextractor.h similarity index 61% copy from src/indexeddataretriever.h copy to src/ondemandextractor.h index bfa1e37..b78cc03 100644 --- a/src/indexeddataretriever.h +++ b/src/ondemandextractor.h @@ -1,54 +1,56 @@ /* * - * Copyright (C) 2012 Vishesh Handa + * Copyright (C) 2019 Stefan Brüns * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#ifndef INDEXEDDATARETRIEVER_H -#define INDEXEDDATARETRIEVER_H +#ifndef ONDEMANDEXTRACTOR_H +#define ONDEMANDEXTRACTOR_H -#include #include -#include +#include namespace Baloo { +namespace Private { -class IndexedDataRetriever : public KJob +class OnDemandExtractor : public QObject { Q_OBJECT + public: - explicit IndexedDataRetriever(const QString& fileUrl, QObject* parent = nullptr); - ~IndexedDataRetriever() override; + explicit OnDemandExtractor(QObject* parent = nullptr); + ~OnDemandExtractor(); + + void process(const QString& filePath); - void start() override; + KFileMetaData::PropertyMap properties() const; - QVariantMap data() const; - bool canEdit() const; +Q_SIGNALS: + void fileFinished(QProcess::ExitStatus exitStatus); private Q_SLOTS: void slotIndexedFile(int exitCode, QProcess::ExitStatus exitStatus); private: - QString m_url; - QProcess* m_process; - QVariantMap m_data; - bool m_canEdit = false; + QProcess m_process; + KFileMetaData::PropertyMap m_properties; }; -} +} // namespace Private +} // namespace Baloo -#endif // INDEXEDDATARETRIEVER_H +#endif // ONDEMANDEXTRACTOR_H