KFileMetaData

embeddedimagedata.cpp
1 /*
2  SPDX-FileCopyrightText: 2018 Alexander Stippich <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6 
7 #include "embeddedimagedata.h"
8 #include "extractorcollection.h"
9 #include "simpleextractionresult.h"
10 #include "writedata.h"
11 #include "writercollection.h"
12 #include "kfilemetadata_debug.h"
13 
14 #include <QMimeDatabase>
15 
16 using namespace KFileMetaData;
17 
18 class Q_DECL_HIDDEN EmbeddedImageData::Private
19 {
20 public:
21  QMimeDatabase mMimeDatabase;
22  static const QStringList mMimetypes;
23 };
24 
25 const QStringList EmbeddedImageData::Private::mMimetypes =
26 {
27  QStringLiteral("audio/flac"),
28  QStringLiteral("audio/mp4"),
29  QStringLiteral("audio/mpeg"),
30  QStringLiteral("audio/mpeg3"),
31  QStringLiteral("audio/ogg"),
32  QStringLiteral("audio/opus"),
33  QStringLiteral("audio/wav"),
34  QStringLiteral("audio/x-aiff"),
35  QStringLiteral("audio/x-ape"),
36  QStringLiteral("audio/x-mpeg"),
37  QStringLiteral("audio/x-ms-wma"),
38  QStringLiteral("audio/x-musepack"),
39  QStringLiteral("audio/x-opus+ogg"),
40  QStringLiteral("audio/x-speex+ogg"),
41  QStringLiteral("audio/x-vorbis+ogg"),
42  QStringLiteral("audio/x-wav"),
43  QStringLiteral("audio/x-wavpack"),
44 };
45 
46 EmbeddedImageData::EmbeddedImageData()
47  : d(std::unique_ptr<Private>(new Private()))
48 {
49 }
50 
51 EmbeddedImageData::~EmbeddedImageData()
52 = default;
53 
54 #if KFILEMETADATA_BUILD_DEPRECATED_SINCE(5, 91)
55 
56 QStringList EmbeddedImageData::mimeTypes() const
57 {
58  return d->mMimetypes;
59 }
60 
63  const EmbeddedImageData::ImageTypes types) const
64 {
65  const auto fileMimeType = d->mMimeDatabase.mimeTypeForFile(fileUrl).name();
68 
69  auto extractors = ec.fetchExtractors(fileMimeType);
70  for (const auto& ex : extractors) {
71  ex->extract(&result);
72  }
73  return result.imageData();
74 }
75 
76 void
79 {
80  const auto fileMimeType = d->mMimeDatabase.mimeTypeForFile(fileUrl).name();
81  KFileMetaData::WriterCollection wc;
82  KFileMetaData::WriteData data(fileUrl, fileMimeType);
83  data.addImageData(imageData);
84 
85  auto writers = wc.fetchWriters(fileMimeType);
86  for (const auto& w : writers) {
87  w->write(data);
88  }
89 }
90 #endif
QMap< ImageType, QByteArray > imageData(const QString &fileUrl, const EmbeddedImageData::ImageTypes types=FrontCover) const
Extracts the images stored in the metadata tags from a file.
void writeImageData(const QString &fileUrl, QMap< ImageType, QByteArray > &imageData)
Extracts the images stored in the metadata tags from a file.
QMap< EmbeddedImageData::ImageType, QByteArray > imageData() const
Return embedded image data.
EmbeddedImageData defines enums for different image types that can be extracted from the metadata of ...
The ExtractorCollection is a helper class which internally loads all the extractor plugins....
QList< Extractor * > fetchExtractors(const QString &mimetype) const
Fetch the extractors which can be used to extract data for the respective file with the given mimetyp...
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu May 26 2022 03:46:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.