mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kio: use QString instead of KUrl as argument for KFileMetaDataPlugin::metaData()
for performance reasons (to not convert KUrl to QString from each plugin) Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
762d5413a0
commit
998d57874d
19 changed files with 59 additions and 50 deletions
|
@ -30,9 +30,9 @@ KFileMetaDataPlugin::~KFileMetaDataPlugin()
|
|||
{
|
||||
}
|
||||
|
||||
QList<KFileMetaInfoItem> KFileMetaDataPlugin::metaData(const KUrl &url)
|
||||
QList<KFileMetaInfoItem> KFileMetaDataPlugin::metaData(const QString &path)
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
Q_UNUSED(path);
|
||||
return QList<KFileMetaInfoItem>();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,11 @@
|
|||
#define KFILEMETADATA_H
|
||||
|
||||
#include "kio_export.h"
|
||||
#include "kurl.h"
|
||||
#include "kfilemetainfo.h"
|
||||
#include "kfilemetainfoitem.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QVariantList>
|
||||
|
||||
/*!
|
||||
Base class for plugins to retrieve file metadata.
|
||||
|
@ -46,7 +45,7 @@ public:
|
|||
KFileMetaDataPlugin(QObject *parent = nullptr);
|
||||
~KFileMetaDataPlugin();
|
||||
|
||||
virtual QList<KFileMetaInfoItem> metaData(const KUrl &url);
|
||||
virtual QList<KFileMetaInfoItem> metaData(const QString &path);
|
||||
};
|
||||
|
||||
#endif // KFILEMETADATA_H
|
||||
|
|
|
@ -72,6 +72,7 @@ void KFileMetaInfoPrivate::init(const QString &filename, const KUrl &url)
|
|||
|
||||
// none of the plugins supports remote files
|
||||
if (url.isLocalFile()) {
|
||||
const QString urlpath = url.toLocalFile();
|
||||
KConfig config("kmetainformationrc", KConfig::NoGlobals);
|
||||
KConfigGroup pluginsgroup = config.group("Plugins");
|
||||
const KMimeType::Ptr filemimetype = KMimeType::findByUrl(url);
|
||||
|
@ -98,7 +99,7 @@ void KFileMetaInfoPrivate::init(const QString &filename, const KUrl &url)
|
|||
kDebug() << "Extracting metadata via" << kfmdname;
|
||||
KFileMetaDataPlugin *kfmdplugininstance = kfmdplugin->createInstance<KFileMetaDataPlugin>();
|
||||
if (kfmdplugininstance) {
|
||||
items.append(kfmdplugininstance->metaData(url));
|
||||
items.append(kfmdplugininstance->metaData(urlpath));
|
||||
delete kfmdplugininstance;
|
||||
} else {
|
||||
kWarning() << "Could not create KFileMetaDataPlugin instance";
|
||||
|
|
|
@ -39,16 +39,16 @@ KFileMetaDataDjVuLibrePlugin::~KFileMetaDataDjVuLibrePlugin()
|
|||
{
|
||||
}
|
||||
|
||||
QList<KFileMetaInfoItem> KFileMetaDataDjVuLibrePlugin::metaData(const KUrl &url)
|
||||
QList<KFileMetaInfoItem> KFileMetaDataDjVuLibrePlugin::metaData(const QString &path)
|
||||
{
|
||||
QList<KFileMetaInfoItem> result;
|
||||
const QByteArray urlpath = url.toLocalFile().toUtf8();
|
||||
const QByteArray pathbytes = path.toUtf8();
|
||||
ddjvu_context_t* djvuctx = ddjvu_context_create("kfilemetadata_djvulibre");
|
||||
if (!djvuctx) {
|
||||
kWarning() << "Could not create DjVu context";
|
||||
return result;
|
||||
}
|
||||
ddjvu_document_t* djvudoc = ddjvu_document_create_by_filename_utf8(djvuctx, urlpath.constData(), FALSE);
|
||||
ddjvu_document_t* djvudoc = ddjvu_document_create_by_filename_utf8(djvuctx, pathbytes.constData(), FALSE);
|
||||
if (!djvudoc) {
|
||||
kWarning() << "Could not create DjVu document";
|
||||
ddjvu_context_release(djvuctx);
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
KFileMetaDataDjVuLibrePlugin(QObject* parent, const QVariantList &args);
|
||||
~KFileMetaDataDjVuLibrePlugin();
|
||||
|
||||
QList<KFileMetaInfoItem> metaData(const KUrl &url) final;
|
||||
QList<KFileMetaInfoItem> metaData(const QString &path) final;
|
||||
};
|
||||
|
||||
#endif // KFILEMETADATA_DJVULIBRE_H
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include "kpluginfactory.h"
|
||||
#include "kdebug.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <epub.h>
|
||||
|
||||
static QString getEPubMetadata(struct epub *epubdocument, enum epub_metadata epubmetadata)
|
||||
|
@ -53,13 +55,13 @@ KFileMetaDataEPubPlugin::~KFileMetaDataEPubPlugin()
|
|||
{
|
||||
}
|
||||
|
||||
QList<KFileMetaInfoItem> KFileMetaDataEPubPlugin::metaData(const KUrl &url)
|
||||
QList<KFileMetaInfoItem> KFileMetaDataEPubPlugin::metaData(const QString &path)
|
||||
{
|
||||
QList<KFileMetaInfoItem> result;
|
||||
const QByteArray urlpath = url.toLocalFile().toLocal8Bit();
|
||||
struct epub *epubdocument = epub_open(urlpath.constData(), 1);
|
||||
const QByteArray pathbytes = QFile::encodeName(path);
|
||||
struct epub *epubdocument = epub_open(pathbytes.constData(), 1);
|
||||
if (!epubdocument) {
|
||||
kWarning() << "Could not open" << urlpath;
|
||||
kWarning() << "Could not open" << pathbytes;
|
||||
return result;
|
||||
}
|
||||
const QString epubid = getEPubMetadata(epubdocument, EPUB_ID);
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
KFileMetaDataEPubPlugin(QObject* parent, const QVariantList &args);
|
||||
~KFileMetaDataEPubPlugin();
|
||||
|
||||
QList<KFileMetaInfoItem> metaData(const KUrl &url) final;
|
||||
QList<KFileMetaInfoItem> metaData(const QString &path) final;
|
||||
};
|
||||
|
||||
#endif // KFILEMETADATA_EPUB_H
|
||||
|
|
|
@ -39,10 +39,10 @@ KFileMetaDataExiv2Plugin::~KFileMetaDataExiv2Plugin()
|
|||
{
|
||||
}
|
||||
|
||||
QList<KFileMetaInfoItem> KFileMetaDataExiv2Plugin::metaData(const KUrl &url)
|
||||
QList<KFileMetaInfoItem> KFileMetaDataExiv2Plugin::metaData(const QString &path)
|
||||
{
|
||||
QList<KFileMetaInfoItem> result;
|
||||
const KExiv2 kexiv2(url.toLocalFile());
|
||||
const KExiv2 kexiv2(path);
|
||||
foreach (const KExiv2Property &kexiv2property, kexiv2.metadata()) {
|
||||
// qDebug() << Q_FUNC_INFO << kexiv2property.name << kexiv2property.value;
|
||||
// for reference:
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
KFileMetaDataExiv2Plugin(QObject* parent, const QVariantList &args);
|
||||
~KFileMetaDataExiv2Plugin();
|
||||
|
||||
QList<KFileMetaInfoItem> metaData(const KUrl &url) final;
|
||||
QList<KFileMetaInfoItem> metaData(const QString &path) final;
|
||||
};
|
||||
|
||||
#endif // KFILEMETADATA_EXIV2_H
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "kmimetype.h"
|
||||
#include "kdebug.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
|
@ -42,14 +44,14 @@ KFileMetaDataFFmpegPlugin::~KFileMetaDataFFmpegPlugin()
|
|||
{
|
||||
}
|
||||
|
||||
QList<KFileMetaInfoItem> KFileMetaDataFFmpegPlugin::metaData(const KUrl &url)
|
||||
QList<KFileMetaInfoItem> KFileMetaDataFFmpegPlugin::metaData(const QString &path)
|
||||
{
|
||||
QList<KFileMetaInfoItem> result;
|
||||
const QByteArray urlpath = url.toLocalFile().toLocal8Bit();
|
||||
const QByteArray pathbytes = QFile::encodeName(path);
|
||||
AVFormatContext *ffmpegcontext = NULL;
|
||||
const int ffmpegresult = avformat_open_input(&ffmpegcontext, urlpath.constData(), NULL, NULL);
|
||||
const int ffmpegresult = avformat_open_input(&ffmpegcontext, pathbytes.constData(), NULL, NULL);
|
||||
if (ffmpegresult != 0 || !ffmpegcontext) {
|
||||
kWarning() << "Could not open" << urlpath;
|
||||
kWarning() << "Could not open" << pathbytes;
|
||||
return result;
|
||||
}
|
||||
for (uint i = 0; i < ffmpegcontext->nb_streams; i++) {
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
KFileMetaDataFFmpegPlugin(QObject* parent, const QVariantList &args);
|
||||
~KFileMetaDataFFmpegPlugin();
|
||||
|
||||
QList<KFileMetaInfoItem> metaData(const KUrl &url) final;
|
||||
QList<KFileMetaInfoItem> metaData(const QString &path) final;
|
||||
};
|
||||
|
||||
#endif // KFILEMETADATA_FFMPEG_H
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include "kpluginfactory.h"
|
||||
#include "kdebug.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_TYPE1_TABLES_H
|
||||
|
@ -34,10 +36,10 @@ KFileMetaDataFreetypePlugin::~KFileMetaDataFreetypePlugin()
|
|||
{
|
||||
}
|
||||
|
||||
QList<KFileMetaInfoItem> KFileMetaDataFreetypePlugin::metaData(const KUrl &url)
|
||||
QList<KFileMetaInfoItem> KFileMetaDataFreetypePlugin::metaData(const QString &path)
|
||||
{
|
||||
QList<KFileMetaInfoItem> result;
|
||||
const QByteArray urlpath = url.toLocalFile().toLocal8Bit();
|
||||
const QByteArray pathbytes = QFile::encodeName(path);
|
||||
FT_Library ftlibrary;
|
||||
FT_Init_FreeType(&ftlibrary);
|
||||
if (!ftlibrary) {
|
||||
|
@ -45,8 +47,8 @@ QList<KFileMetaInfoItem> KFileMetaDataFreetypePlugin::metaData(const KUrl &url)
|
|||
return result;
|
||||
}
|
||||
FT_Face ftface;
|
||||
if (FT_New_Face(ftlibrary, urlpath.constData(), 0, &ftface) != 0) {
|
||||
kWarning() << "Could not open" << urlpath;
|
||||
if (FT_New_Face(ftlibrary, pathbytes.constData(), 0, &ftface) != 0) {
|
||||
kWarning() << "Could not open" << pathbytes;
|
||||
FT_Done_FreeType(ftlibrary);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
KFileMetaDataFreetypePlugin(QObject* parent, const QVariantList &args);
|
||||
~KFileMetaDataFreetypePlugin();
|
||||
|
||||
QList<KFileMetaInfoItem> metaData(const KUrl &url) final;
|
||||
QList<KFileMetaInfoItem> metaData(const QString &path) final;
|
||||
};
|
||||
|
||||
#endif // KFILEMETADATA_FREETYPE_H
|
||||
|
|
|
@ -61,34 +61,33 @@ KFileMetaDataPopplerPlugin::~KFileMetaDataPopplerPlugin()
|
|||
{
|
||||
}
|
||||
|
||||
QList<KFileMetaInfoItem> KFileMetaDataPopplerPlugin::metaData(const KUrl &url)
|
||||
QList<KFileMetaInfoItem> KFileMetaDataPopplerPlugin::metaData(const QString &path)
|
||||
{
|
||||
QList<KFileMetaInfoItem> result;
|
||||
const QString urlpath = url.toLocalFile();
|
||||
poppler::document* popplerdocument = nullptr;
|
||||
// NOTE: data has be kept for as long as the document is open
|
||||
QByteArray popplerbytes;
|
||||
const KDecompressor::KDecompressorType pathtype = KDecompressor::typeForFile(urlpath);
|
||||
const KDecompressor::KDecompressorType pathtype = KDecompressor::typeForFile(path);
|
||||
if (pathtype != KDecompressor::TypeUnknown) {
|
||||
QFile pathfile(urlpath);
|
||||
QFile pathfile(path);
|
||||
if (!pathfile.open(QFile::ReadOnly)) {
|
||||
kWarning() << "Could not open" << urlpath;
|
||||
kWarning() << "Could not open" << path;
|
||||
return result;
|
||||
}
|
||||
KDecompressor kdecompressor;
|
||||
kdecompressor.setType(pathtype);
|
||||
if (!kdecompressor.process(pathfile.readAll())) {
|
||||
kWarning() << "Could not decompress" << urlpath;
|
||||
kWarning() << "Could not decompress" << path;
|
||||
return result;
|
||||
}
|
||||
popplerbytes = kdecompressor.result();
|
||||
popplerdocument = poppler::document::load_from_raw_data(popplerbytes.constData(), popplerbytes.size());
|
||||
} else {
|
||||
const QByteArray urlpathbytes = QFile::encodeName(urlpath);
|
||||
popplerdocument = poppler::document::load_from_file(std::string(urlpathbytes.constData(), urlpathbytes.size()));
|
||||
const QByteArray pathbytes = QFile::encodeName(path);
|
||||
popplerdocument = poppler::document::load_from_file(std::string(pathbytes.constData(), pathbytes.size()));
|
||||
}
|
||||
if (!popplerdocument) {
|
||||
kWarning() << "Could not open" << urlpath;
|
||||
kWarning() << "Could not open" << path;
|
||||
return result;
|
||||
}
|
||||
const QString popplertitle = getString(popplerdocument->get_title());
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
KFileMetaDataPopplerPlugin(QObject* parent, const QVariantList &args);
|
||||
~KFileMetaDataPopplerPlugin();
|
||||
|
||||
QList<KFileMetaInfoItem> metaData(const KUrl &url) final;
|
||||
QList<KFileMetaInfoItem> metaData(const QString &path) final;
|
||||
};
|
||||
|
||||
#endif // KFILEMETADATA_POPPLER_H
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include "kpluginfactory.h"
|
||||
#include "kdebug.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <libspectre/spectre.h>
|
||||
|
||||
KFileMetaDataSpectrePlugin::KFileMetaDataSpectrePlugin(QObject* parent, const QVariantList &args)
|
||||
|
@ -32,19 +34,19 @@ KFileMetaDataSpectrePlugin::~KFileMetaDataSpectrePlugin()
|
|||
{
|
||||
}
|
||||
|
||||
QList<KFileMetaInfoItem> KFileMetaDataSpectrePlugin::metaData(const KUrl &url)
|
||||
QList<KFileMetaInfoItem> KFileMetaDataSpectrePlugin::metaData(const QString &path)
|
||||
{
|
||||
QList<KFileMetaInfoItem> result;
|
||||
const QByteArray urlpath = url.toLocalFile().toLocal8Bit();
|
||||
const QByteArray pathbytes = QFile::encodeName(path);
|
||||
SpectreDocument *spectredocument = spectre_document_new();
|
||||
if (!spectredocument) {
|
||||
kWarning() << "Could not create document";
|
||||
return result;
|
||||
}
|
||||
spectre_document_load(spectredocument, urlpath.constData());
|
||||
spectre_document_load(spectredocument, pathbytes.constData());
|
||||
const SpectreStatus spectrestatus = spectre_document_status(spectredocument);
|
||||
if (spectrestatus != SPECTRE_STATUS_SUCCESS) {
|
||||
kWarning() << "Could not open" << urlpath;
|
||||
kWarning() << "Could not open" << pathbytes;
|
||||
spectre_document_free(spectredocument);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
KFileMetaDataSpectrePlugin(QObject* parent, const QVariantList &args);
|
||||
~KFileMetaDataSpectrePlugin();
|
||||
|
||||
QList<KFileMetaInfoItem> metaData(const KUrl &url) final;
|
||||
QList<KFileMetaInfoItem> metaData(const QString &path) final;
|
||||
};
|
||||
|
||||
#endif // KFILEMETADATA_SPECTRE_H
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "klocale.h"
|
||||
#include "kdebug.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <taglib/fileref.h>
|
||||
#include <taglib/tag.h>
|
||||
|
||||
|
@ -35,18 +37,18 @@ KFileMetaDataTagLibPlugin::~KFileMetaDataTagLibPlugin()
|
|||
{
|
||||
}
|
||||
|
||||
QList<KFileMetaInfoItem> KFileMetaDataTagLibPlugin::metaData(const KUrl &url)
|
||||
QList<KFileMetaInfoItem> KFileMetaDataTagLibPlugin::metaData(const QString &path)
|
||||
{
|
||||
QList<KFileMetaInfoItem> result;
|
||||
const QByteArray urlpath = url.toLocalFile().toLocal8Bit();
|
||||
TagLib::FileRef taglibfile(urlpath);
|
||||
const QByteArray pathbytes = QFile::encodeName(path);
|
||||
TagLib::FileRef taglibfile(pathbytes);
|
||||
if (taglibfile.isNull()) {
|
||||
kWarning() << "Could not open" << urlpath;
|
||||
kWarning() << "Could not open" << pathbytes;
|
||||
return result;
|
||||
}
|
||||
TagLib::Tag *taglibtag = taglibfile.tag();
|
||||
if (!taglibtag) {
|
||||
kDebug() << "Null tag for" << urlpath;
|
||||
kDebug() << "Null tag for" << pathbytes;
|
||||
} else {
|
||||
const QString taglibtitle = QString::fromStdString(taglibtag->title().to8Bit(true));
|
||||
if (!taglibtitle.isEmpty()) {
|
||||
|
@ -114,7 +116,7 @@ QList<KFileMetaInfoItem> KFileMetaDataTagLibPlugin::metaData(const KUrl &url)
|
|||
}
|
||||
TagLib::AudioProperties *taglibaudio = taglibfile.audioProperties();
|
||||
if (!taglibaudio) {
|
||||
kDebug() << "Null audio properties for" << urlpath;
|
||||
kDebug() << "Null audio properties for" << pathbytes;
|
||||
} else {
|
||||
const qlonglong tagliblength = taglibaudio->length();
|
||||
if (tagliblength > 0) {
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
KFileMetaDataTagLibPlugin(QObject* parent, const QVariantList &args);
|
||||
~KFileMetaDataTagLibPlugin();
|
||||
|
||||
QList<KFileMetaInfoItem> metaData(const KUrl &url) final;
|
||||
QList<KFileMetaInfoItem> metaData(const QString &path) final;
|
||||
};
|
||||
|
||||
#endif // KFILEMETADATA_TAGLIB_H
|
||||
|
|
Loading…
Add table
Reference in a new issue