diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 05420d5..ef30c19 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,88 +1,88 @@ 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 widgetfactory.cpp filefetchjob.cpp ) 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) +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/extractor.cpp b/src/extractor.cpp index 0611805..bd123b3 100644 --- a/src/extractor.cpp +++ b/src/extractor.cpp @@ -1,79 +1,74 @@ /* * This file is part of the KDE Baloo Project * Copyright (C) 2014 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) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * 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, see . * */ +#include "filemetadatautil_p.h" + #include #include #include #include #include #include #include #include #include -#include #include #include int main(int argc, char **argv) { QCoreApplication app(argc, argv); QCommandLineParser parser; parser.addPositionalArgument(QLatin1String("url"), QString()); parser.process(app); if (parser.positionalArguments().size() != 1) { parser.showHelp(1); } const QString url = parser.positionalArguments().first(); const QString mimetype = KFileMetaData::MimeUtils::strictMimeType(url, QMimeDatabase()).name(); KFileMetaData::SimpleExtractionResult result(url, mimetype, KFileMetaData::ExtractionResult::ExtractMetaData); KFileMetaData::ExtractorCollection collection; const QList exList = collection.fetchExtractors(mimetype); for (KFileMetaData::Extractor *ex : exList) { ex->extract(&result); } QFile out; out.open(stdout, QIODevice::WriteOnly); QDataStream stream(&out); - QVariantMap map; - QMapIterator it(result.properties()); - while (it.hasNext()) { - it.next(); - KFileMetaData::PropertyInfo pi(it.key()); - map.insertMulti(pi.name(), it.value()); - } + QVariantMap map = Baloo::Private::toNamedVariantMap(result.properties()); stream << map; qDebug() << map; return 0; } diff --git a/src/filefetchjob.cpp b/src/filefetchjob.cpp index bcf1d47..dd04a97 100644 --- a/src/filefetchjob.cpp +++ b/src/filefetchjob.cpp @@ -1,76 +1,63 @@ /* * * Copyright (C) 2014 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 "filefetchjob.h" #include "filemetadatautil_p.h" #include #include #include -#include using namespace Baloo; FileFetchJob::FileFetchJob(const QStringList& urls, QObject* parent) : KJob(parent) , m_urls(urls) { } void FileFetchJob::start() { QTimer::singleShot(0, this, SLOT(doStart())); } -static QVariantMap convertPropertyMap(const KFileMetaData::PropertyMap& propMap) -{ - QVariantMap map; - KFileMetaData::PropertyMap::const_iterator it = propMap.constBegin(); - for (; it != propMap.constEnd(); it++) { - KFileMetaData::PropertyInfo pi(it.key()); - map.insertMulti(pi.name(), it.value()); - } - - return map; -} - void FileFetchJob::doStart() { for (const QString& filePath : m_urls) { Baloo::File file(filePath); file.load(); - QVariantMap prop = convertPropertyMap(file.properties()); + QVariantMap prop = Baloo::Private::toNamedVariantMap(file.properties()); KFileMetaData::UserMetaData umd(filePath); QVariantMap attributes = Baloo::Private::convertUserMetaData(umd); prop.unite(attributes); m_data << prop; } emitResult(); } QList Baloo::FileFetchJob::data() const { return m_data; } diff --git a/src/filemetadatautil.cpp b/src/filemetadatautil.cpp index 77f9925..7725179 100644 --- a/src/filemetadatautil.cpp +++ b/src/filemetadatautil.cpp @@ -1,56 +1,69 @@ /***************************************************************************** * Copyright (C) 2019 by Stefan Brüns * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 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 * * Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public License * * along with this library; see the file COPYING.LIB. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *****************************************************************************/ #include "filemetadatautil_p.h" #include +#include namespace Baloo { namespace Private { QVariantMap convertUserMetaData(const KFileMetaData::UserMetaData& metaData) { QVariantMap properties; const QStringList tags = metaData.tags(); if (!tags.isEmpty()) { properties.insert(QStringLiteral("tags"), tags); } int rating = metaData.rating(); if (rating) { properties.insert(QStringLiteral("rating"), rating); } const QString comment = metaData.userComment(); if (!comment.isEmpty()) { properties.insert(QStringLiteral("userComment"), comment); } const QString originUrl = metaData.originUrl().toDisplayString(); if (!originUrl.isEmpty()) { properties.insert(QStringLiteral("originUrl"), originUrl); } return properties; } +QVariantMap toNamedVariantMap(const KFileMetaData::PropertyMap& propMap) +{ + QVariantMap map; + KFileMetaData::PropertyMap::const_iterator it = propMap.constBegin(); + for (; it != propMap.constEnd(); it++) { + KFileMetaData::PropertyInfo pi(it.key()); + map.insertMulti(pi.name(), it.value()); + } + + return map; +} + } // namespace KFMPrivate } // namespace Baloo diff --git a/src/filemetadatautil_p.h b/src/filemetadatautil_p.h index 9646417..48b741a 100644 --- a/src/filemetadatautil_p.h +++ b/src/filemetadatautil_p.h @@ -1,36 +1,43 @@ /***************************************************************************** * Copyright (C) 2019 by Stefan Brüns * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 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 * * Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public License * * along with this library; see the file COPYING.LIB. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *****************************************************************************/ #include +#include #include namespace Baloo { namespace Private { /** * Converts the UserMetaData attributes into a variant map * * /sa: KFileMetaData::UserMetaData */ QVariantMap convertUserMetaData(const KFileMetaData::UserMetaData& metaData); +/** + * Converts the property map into a variant map + * using the property name as key. + */ +QVariantMap toNamedVariantMap(const KFileMetaData::PropertyMap& propMap); + } // namespace Private } // namespace Baloo