diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 1a34eb02..29a9e91f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -42,7 +42,7 @@ jobs: sudo apt-get install -qq wget sudo wget https://raw.githubusercontent.com/fluxer/katana-ubuntu/master/katana.list -O /etc/apt/sources.list.d/katana.list sudo apt-get update -qq - sudo apt-get install -qq cmake katie-dev libenchant-dev libmagick++-dev libmpv-dev xorg-dev mesa-common-dev libavahi-client-dev libepub-dev libpoppler-cpp-dev libtag1-dev libavcodec-dev libavutil-dev libavformat-dev libwebp-dev libudev-dev liblzma-dev libexiv2-dev libbz2-dev libattr1-dev libacl1-dev libcdio-dev libcurl4-openssl-dev libmicrohttpd-dev libdbusmenu-katie media-player-info shared-mime-info xdg-utils + sudo apt-get install -qq cmake katie-dev libenchant-dev libmagick++-dev libmpv-dev xorg-dev mesa-common-dev libavahi-client-dev libepub-dev libpoppler-cpp-dev libtag1-dev libavcodec-dev libavutil-dev libavformat-dev libwebp-dev libudev-dev liblzma-dev libexiv2-dev libbz2-dev libattr1-dev libacl1-dev libcdio-dev libcurl4-openssl-dev libmicrohttpd-dev libspectre-dev libdbusmenu-katie media-player-info shared-mime-info xdg-utils # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/CMakeLists.txt b/CMakeLists.txt index c3d6fdad..5303c96f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -231,6 +231,14 @@ set_package_properties(Poppler PROPERTIES PURPOSE "PDF metadata extraction" ) +macro_optional_find_package(LibSpectre) +set_package_properties(LibSpectre PROPERTIES + DESCRIPTION "Small library for rendering Postscript documents" + URL "https://www.freedesktop.org/wiki/Software/libspectre/" + TYPE RECOMMENDED + PURPOSE "Postscript metadata extraction" +) + macro_optional_find_package(OpenSSL) set_package_properties(OpenSSL PROPERTIES DESCRIPTION "Robust, commercial-grade, full-featured toolkit for general-purpose cryptography and secure communication" diff --git a/appveyor.yml b/appveyor.yml index 5d07e44e..04fc0467 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,7 +24,8 @@ build_script: libexiv2-dev libcdio-dev libssl-dev libcurl4-openssl-dev \ libdbusmenu-katie libavcodec-dev libavutil-dev libavformat-dev \ libtag1-dev media-player-info shared-mime-info media-player-info \ - libepub-dev libpoppler-cpp-dev libmicrohttpd-dev xdg-utils ccache + libepub-dev libpoppler-cpp-dev libmicrohttpd-dev libspectre-dev \ + xdg-utils ccache export PATH="/usr/lib/ccache/:$PATH" diff --git a/kio/metadata/CMakeLists.txt b/kio/metadata/CMakeLists.txt index 7639eeb7..f8f9b0bb 100644 --- a/kio/metadata/CMakeLists.txt +++ b/kio/metadata/CMakeLists.txt @@ -103,3 +103,25 @@ if (POPPLER_FOUND) DESTINATION ${KDE4_SERVICES_INSTALL_DIR} ) endif() + +if (LIBSPECTRE_FOUND) + include_directories(${LIBSPECTRE_INCLUDE_DIR}) + + set(kfilemetadata_spectre_SRCS kfilemetadata_spectre.cpp) + + kde4_add_plugin(kfilemetadata_spectre ${kfilemetadata_spectre_SRCS}) + target_link_libraries(kfilemetadata_spectre + ${KDE4_KIO_LIBS} + ${LIBSPECTRE_LIBRARY} + ) + + install( + TARGETS kfilemetadata_spectre + DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} + ) + + install( + FILES kfilemetadata_spectre.desktop + DESTINATION ${KDE4_SERVICES_INSTALL_DIR} + ) +endif() diff --git a/kio/metadata/kfilemetadata_spectre.cpp b/kio/metadata/kfilemetadata_spectre.cpp new file mode 100644 index 00000000..4def1a67 --- /dev/null +++ b/kio/metadata/kfilemetadata_spectre.cpp @@ -0,0 +1,112 @@ +/* This file is part of the KDE libraries + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + 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 "kfilemetadata_spectre.h" +#include "kpluginfactory.h" +#include "kdebug.h" + +#include + +KFileMetaDataSpectrePlugin::KFileMetaDataSpectrePlugin(QObject* parent, const QVariantList &args) + : KFileMetaDataPlugin(parent) +{ + Q_UNUSED(args); +} + +KFileMetaDataSpectrePlugin::~KFileMetaDataSpectrePlugin() +{ +} + +QStringList KFileMetaDataSpectrePlugin::keys() const +{ + static const QStringList result = QStringList() + << QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#title") + << QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/03/22/nco#creator") + << QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentCreated") + << QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#pageCount"); + return result; +} + +QStringList KFileMetaDataSpectrePlugin::mimeTypes() const +{ + static const QStringList result = QStringList() + << QString::fromLatin1("application/postscript"); + return result; +} + +QList KFileMetaDataSpectrePlugin::metaData(const KUrl &url, const KFileMetaInfo::WhatFlags flags) +{ + Q_UNUSED(flags); + QList result; + const QByteArray urlpath = url.toLocalFile().toLocal8Bit(); + SpectreDocument *spectredocument = spectre_document_new(); + if (!spectredocument) { + kWarning() << "Could not create document"; + return result; + } + spectre_document_load(spectredocument, urlpath.constData()); + SpectreStatus spectrestatus = spectre_document_status(spectredocument); + if (spectrestatus != SPECTRE_STATUS_SUCCESS) { + kWarning() << "Could not open" << urlpath; + spectre_document_free(spectredocument); + return result; + } + const QString spectretitle = QString::fromUtf8(spectre_document_get_title(spectredocument)); + if (!spectretitle.isEmpty()) { + result.append( + KFileMetaInfoItem( + QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#title"), + spectretitle + ) + ); + } + const QString spectrecreator = QString::fromUtf8(spectre_document_get_creator(spectredocument)); + if (!spectrecreator.isEmpty()) { + result.append( + KFileMetaInfoItem( + QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/03/22/nco#creator"), + spectrecreator + ) + ); + } + const QString spectrecreationdate = QString::fromUtf8(spectre_document_get_creation_date(spectredocument)); + if (!spectrecreationdate.isEmpty()) { + result.append( + KFileMetaInfoItem( + QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentCreated"), + spectrecreationdate + ) + ); + } + const uint spectrenpages = spectre_document_get_n_pages(spectredocument); + if (spectrenpages > 0) { + result.append( + KFileMetaInfoItem( + QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#pageCount"), + QString::number(spectrenpages) + ) + ); + } + spectre_document_free(spectredocument); + return result; +} + +K_PLUGIN_FACTORY(KFileMetaDataSpectrePluginFactory, registerPlugin();) +K_EXPORT_PLUGIN(KFileMetaDataSpectrePluginFactory("kfilemetadata_spectre")) + +#include "moc_kfilemetadata_spectre.cpp" diff --git a/kio/metadata/kfilemetadata_spectre.desktop b/kio/metadata/kfilemetadata_spectre.desktop new file mode 100644 index 00000000..47e7e2ad --- /dev/null +++ b/kio/metadata/kfilemetadata_spectre.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Type=Service +Name=KFileMetaDataSpectrePlugin +GenericName=Spectre metadata extractor +X-KDE-Library=kfilemetadata_spectre +X-KDE-ServiceTypes=KFileMetaData/Plugin +InitialPreference=1 diff --git a/kio/metadata/kfilemetadata_spectre.h b/kio/metadata/kfilemetadata_spectre.h new file mode 100644 index 00000000..fb201523 --- /dev/null +++ b/kio/metadata/kfilemetadata_spectre.h @@ -0,0 +1,37 @@ +/* This file is part of the KDE libraries + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + 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. +*/ + +#ifndef KFILEMETADATA_SPECTRE_H +#define KFILEMETADATA_SPECTRE_H + +#include "kfilemetadata.h" + +class KFileMetaDataSpectrePlugin : public KFileMetaDataPlugin +{ + Q_OBJECT +public: + KFileMetaDataSpectrePlugin(QObject* parent, const QVariantList &args); + ~KFileMetaDataSpectrePlugin(); + + QStringList keys() const final; + QStringList mimeTypes() const final; + + QList metaData(const KUrl &url, const KFileMetaInfo::WhatFlags flags) final; +}; + +#endif // KFILEMETADATA_SPECTRE_H