Currently title, author and resolution are extracted.wilder-5.26
parent
b3943ee1a6
commit
cad08926cc
18 changed files with 298 additions and 142 deletions
@ -1,52 +0,0 @@ |
||||
/*
|
||||
SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com> |
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later |
||||
*/ |
||||
|
||||
#include <QDir> |
||||
#include <QtTest> |
||||
|
||||
#include "commontestdata.h" |
||||
#include "finder/imagesizefinder.h" |
||||
|
||||
class ImageSizeFinderTest : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
private Q_SLOTS: |
||||
void initTestCase(); |
||||
void testImageSizeFinder(); |
||||
|
||||
private: |
||||
QDir m_dataDir; |
||||
}; |
||||
|
||||
void ImageSizeFinderTest::initTestCase() |
||||
{ |
||||
m_dataDir = QDir(QFINDTESTDATA("testdata/default")); |
||||
QVERIFY(!m_dataDir.isEmpty()); |
||||
} |
||||
|
||||
void ImageSizeFinderTest::testImageSizeFinder() |
||||
{ |
||||
const QString path = m_dataDir.absoluteFilePath(ImageBackendTestData::defaultImageFileName1); |
||||
|
||||
ImageSizeFinder *finder = new ImageSizeFinder(path); |
||||
QSignalSpy spy(finder, &ImageSizeFinder::sizeFound); |
||||
|
||||
QThreadPool::globalInstance()->start(finder); |
||||
|
||||
spy.wait(10 * 1000); |
||||
QCOMPARE(spy.size(), 1); |
||||
|
||||
const auto firstSignalResult = spy.takeFirst(); |
||||
QCOMPARE(firstSignalResult.size(), 2); |
||||
|
||||
QCOMPARE(firstSignalResult.at(0).toString(), path); |
||||
QCOMPARE(firstSignalResult.at(1).toSize(), QSize(15, 16)); |
||||
} |
||||
|
||||
QTEST_MAIN(ImageSizeFinderTest) |
||||
|
||||
#include "test_imagesizefinder.moc" |
||||
@ -0,0 +1,56 @@ |
||||
/*
|
||||
SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com> |
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later |
||||
*/ |
||||
|
||||
#include <QDir> |
||||
#include <QtTest> |
||||
|
||||
#include "../finder/mediametadatafinder.h" |
||||
#include "commontestdata.h" |
||||
#include "config-KF5KExiv2.h" |
||||
|
||||
class MediaMetadataFinderTest : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
private Q_SLOTS: |
||||
void initTestCase(); |
||||
void testMediaMetadataFinderCanFindMetadata(); |
||||
|
||||
private: |
||||
QDir m_dataDir; |
||||
}; |
||||
|
||||
void MediaMetadataFinderTest::initTestCase() |
||||
{ |
||||
qRegisterMetaType<MediaMetadata>(); |
||||
|
||||
m_dataDir = QDir(QFINDTESTDATA("testdata/default")); |
||||
QVERIFY(!m_dataDir.isEmpty()); |
||||
} |
||||
|
||||
void MediaMetadataFinderTest::testMediaMetadataFinderCanFindMetadata() |
||||
{ |
||||
MediaMetadataFinder *finder = new MediaMetadataFinder(m_dataDir.absoluteFilePath(ImageBackendTestData::defaultImageFileName1)); |
||||
QSignalSpy spy(finder, &MediaMetadataFinder::metadataFound); |
||||
QThreadPool::globalInstance()->start(finder); |
||||
|
||||
spy.wait(10 * 1000); |
||||
QCOMPARE(spy.count(), 1); |
||||
|
||||
const auto args = spy.takeFirst(); |
||||
QCOMPARE(args.at(0).toString(), m_dataDir.absoluteFilePath(ImageBackendTestData::defaultImageFileName1)); |
||||
|
||||
const auto metadata = args.at(1).value<MediaMetadata>(); |
||||
#if HAVE_KF5KExiv2 |
||||
QTRY_COMPARE(metadata.title, QStringLiteral("DocumentName")); |
||||
QTRY_COMPARE(metadata.author, QStringLiteral("KDE Community")); |
||||
#endif |
||||
QTRY_COMPARE(metadata.resolution, QSize(15, 16)); |
||||
} |
||||
|
||||
QTEST_MAIN(MediaMetadataFinderTest) |
||||
|
||||
#include "test_mediametadatafinder.moc" |
||||
|
Before Width: | Height: | Size: 633 B After Width: | Height: | Size: 709 B |
@ -0,0 +1 @@ |
||||
#cmakedefine01 HAVE_KF5KExiv2 |
||||
@ -1,21 +0,0 @@ |
||||
/*
|
||||
SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com> |
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later |
||||
*/ |
||||
|
||||
#include "imagesizefinder.h" |
||||
|
||||
#include <QImageReader> |
||||
|
||||
ImageSizeFinder::ImageSizeFinder(const QString &path, QObject *parent) |
||||
: QObject(parent) |
||||
, m_path(path) |
||||
{ |
||||
} |
||||
|
||||
void ImageSizeFinder::run() |
||||
{ |
||||
const QImageReader reader(m_path); |
||||
Q_EMIT sizeFound(m_path, reader.size()); |
||||
} |
||||
@ -1,32 +0,0 @@ |
||||
/*
|
||||
SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com> |
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later |
||||
*/ |
||||
|
||||
#ifndef IMAGESIZEFINDER_H |
||||
#define IMAGESIZEFINDER_H |
||||
|
||||
#include <QObject> |
||||
#include <QRunnable> |
||||
|
||||
/**
|
||||
* A runnable that helps find the dimension of an image. |
||||
*/ |
||||
class ImageSizeFinder : public QObject, public QRunnable |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit ImageSizeFinder(const QString &path, QObject *parent = nullptr); |
||||
|
||||
void run() override; |
||||
|
||||
Q_SIGNALS: |
||||
void sizeFound(const QString &path, const QSize &size); |
||||
|
||||
private: |
||||
QString m_path; |
||||
}; |
||||
|
||||
#endif // IMAGESIZEFINDER_H
|
||||
@ -0,0 +1,62 @@ |
||||
/*
|
||||
SPDX-FileCopyrightText: 2007 Aurélien Gâteau <agateau@kde.org> |
||||
SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com> |
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later |
||||
*/ |
||||
|
||||
#include "mediametadatafinder.h" |
||||
|
||||
#include <QFile> |
||||
#include <QImageReader> |
||||
|
||||
#include "config-KF5KExiv2.h" |
||||
#if HAVE_KF5KExiv2 |
||||
#include <KExiv2/KExiv2> |
||||
#endif |
||||
|
||||
MediaMetadataFinder::MediaMetadataFinder(const QString &path, QObject *parent) |
||||
: QObject(parent) |
||||
, m_path(path) |
||||
{ |
||||
} |
||||
|
||||
void MediaMetadataFinder::run() |
||||
{ |
||||
MediaMetadata metadata; |
||||
|
||||
const QImageReader reader(m_path); |
||||
metadata.resolution = reader.size(); |
||||
|
||||
#if HAVE_KF5KExiv2 |
||||
KExiv2Iface::KExiv2 exivImage(m_path); |
||||
|
||||
// Extract title from XPTitle
|
||||
metadata.title = QString::fromUtf8(exivImage.getExifTagData("Exif.Image.XPTitle")); |
||||
|
||||
// Use documentName as title
|
||||
if (metadata.title.isEmpty()) { |
||||
metadata.title = QString::fromUtf8(exivImage.getExifTagData("Exif.Image.DocumentName")); |
||||
} |
||||
|
||||
// Use description as title
|
||||
if (metadata.title.isEmpty()) { |
||||
metadata.title = QString::fromUtf8(exivImage.getExifTagData("Exif.Image.ImageDescription")); |
||||
} |
||||
|
||||
// Extract author from artist
|
||||
metadata.author = QString::fromUtf8(exivImage.getExifTagData("Exif.Image.Artist")); |
||||
|
||||
// Extract author from XPAuthor
|
||||
if (metadata.author.isEmpty()) { |
||||
metadata.author = QString::fromUtf8(exivImage.getExifTagData("Exif.Image.XPAuthor")); |
||||
} |
||||
|
||||
// Extract author from copyright
|
||||
if (metadata.author.isEmpty()) { |
||||
metadata.author = QString::fromUtf8(exivImage.getExifTagData("Exif.Image.Copyright")); |
||||
} |
||||
#endif |
||||
|
||||
Q_EMIT metadataFound(m_path, metadata); |
||||
} |
||||
@ -0,0 +1,40 @@ |
||||
/*
|
||||
SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com> |
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later |
||||
*/ |
||||
|
||||
#ifndef MEDIAMETADATAFINDER_H |
||||
#define MEDIAMETADATAFINDER_H |
||||
|
||||
#include <QObject> |
||||
#include <QRunnable> |
||||
#include <QSize> |
||||
|
||||
struct MediaMetadata { |
||||
QString title; |
||||
QString author; |
||||
QSize resolution; |
||||
}; |
||||
Q_DECLARE_METATYPE(MediaMetadata) |
||||
|
||||
/**
|
||||
* A runnable that helps find the metadata of an image or a video. |
||||
*/ |
||||
class MediaMetadataFinder : public QObject, public QRunnable |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit MediaMetadataFinder(const QString &path, QObject *parent = nullptr); |
||||
|
||||
void run() override; |
||||
|
||||
Q_SIGNALS: |
||||
void metadataFound(const QString &path, const MediaMetadata &metadata); |
||||
|
||||
private: |
||||
QString m_path; |
||||
}; |
||||
|
||||
#endif // MEDIAMETADATAFINDER_H
|
||||
Loading…
Reference in new issue