KFileMetaData

propertyinfo.cpp
1/*
2 This file is part of the KFileMetaData project
3 SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "propertyinfo.h"
9
10#include <KLazyLocalizedString>
11#include <KLocalizedString>
12
13#include "formatstrings_p.h"
14
15#include <array>
16
17#include <QLocale>
18
19using namespace KFileMetaData;
20
21class KFileMetaData::PropertyInfoData
22{
23 using FormatFunction = QString (&)(const QVariant&);
24
25public:
26 const Property::Property prop;
27 const bool shouldBeIndexed = false;
28 const QString name;
29 const KLazyLocalizedString displayName;
31 const FormatFunction formatAsString = FormatStrings::toStringFunction;
32};
33
34const static PropertyInfoData staticEmptyPropertyInfo{ Property::Empty, false, QStringLiteral("empty") };
35
36const static std::array<PropertyInfoData, 78> staticPropertyInfo
37{
38 PropertyInfoData{ Property::Album, true, QStringLiteral("album"), kli18nc("@label music album", "Album"), QMetaType::QString },
39 PropertyInfoData{ Property::AlbumArtist, true, QStringLiteral("albumArtist"), kli18nc("@label", "Album Artist"), QMetaType::QString },
40 PropertyInfoData{ Property::Artist, true, QStringLiteral("artist"), kli18nc("@label", "Artist"), QMetaType::QString },
41 PropertyInfoData{ Property::AspectRatio, false, QStringLiteral("aspectRatio"), kli18nc("@label", "Aspect Ratio"), QMetaType::Double, FormatStrings::formatAspectRatio },
42 PropertyInfoData{ Property::Author, true, QStringLiteral("author"), kli18nc("@label", "Author"), QMetaType::QString },
43 PropertyInfoData{ Property::BitRate, false, QStringLiteral("bitRate"), kli18nc("@label", "Bitrate"), QMetaType::Int, FormatStrings::formatBitRate },
44 PropertyInfoData{ Property::Channels, false, QStringLiteral("channels"), kli18nc("@label", "Channels"), QMetaType::Int },
45 PropertyInfoData{ Property::Comment, false, QStringLiteral("comment"), kli18nc("@label", "Comment"), QMetaType::QString },
46 PropertyInfoData{ Property::Description, false, QStringLiteral("description"), kli18nc("@label", "Description"), QMetaType::QString },
47 PropertyInfoData{ Property::Composer, true, QStringLiteral("composer"), kli18nc("@label", "Composer"), QMetaType::QString },
48 PropertyInfoData{ Property::Copyright, false, QStringLiteral("copyright"), kli18nc("@label", "Copyright"), QMetaType::QString },
49 PropertyInfoData{ Property::CreationDate, false, QStringLiteral("creationDate"), kli18nc("@label", "Creation Date"), QMetaType::QDateTime, FormatStrings::formatDate },
50 PropertyInfoData{ Property::Duration, false, QStringLiteral("duration"), kli18nc("@label", "Duration"), QMetaType::Int, FormatStrings::formatDuration },
51 PropertyInfoData{ Property::FrameRate, false, QStringLiteral("frameRate"), kli18nc("@label", "Frame Rate"), QMetaType::Double, FormatStrings::formatAsFrameRate },
52 PropertyInfoData{ Property::Generator, false, QStringLiteral("generator"), kli18nc("@label", "Document Generated By"), QMetaType::QString },
53 PropertyInfoData{ Property::Genre, true, QStringLiteral("genre"), kli18nc("@label music genre", "Genre"), QMetaType::QString },
54 PropertyInfoData{ Property::Height, false, QStringLiteral("height"), kli18nc("@label", "Height"), QMetaType::Int },
55 PropertyInfoData{ Property::ImageDateTime, false, QStringLiteral("imageDateTime"), kli18nc("@label EXIF", "Image Date Time"), QMetaType::QDateTime, FormatStrings::formatDate },
56 PropertyInfoData{ Property::Manufacturer, false, QStringLiteral("manufacturer"), kli18nc("@label EXIF", "Manufacturer"), QMetaType::QString },
57 PropertyInfoData{ Property::Model, false, QStringLiteral("model"), kli18nc("@label EXIF", "Model"), QMetaType::QString },
58 PropertyInfoData{ Property::ImageOrientation, false, QStringLiteral("imageOrientation"), kli18nc("@label EXIF", "Image Orientation"), QMetaType::Int, FormatStrings::formatOrientationValue },
59 PropertyInfoData{ Property::Keywords, false, QStringLiteral("keywords"), kli18nc("@label", "Keywords"), QMetaType::QString },
60 PropertyInfoData{ Property::Language, false, QStringLiteral("language"), kli18nc("@label", "Language"), QMetaType::QString },
61 PropertyInfoData{ Property::LineCount, false, QStringLiteral("lineCount"), kli18nc("@label number of lines", "Line Count"), QMetaType::Int },
62 PropertyInfoData{ Property::Lyricist, true, QStringLiteral("lyricist"), kli18nc("@label", "Lyricist"), QMetaType::QString },
63 PropertyInfoData{ Property::PageCount, false, QStringLiteral("pageCount"), kli18nc("@label", "Page Count"), QMetaType::Int },
64 PropertyInfoData{ Property::PhotoApertureValue, false, QStringLiteral("photoApertureValue"), kli18nc("@label EXIF", "Aperture Value"), QMetaType::Double, FormatStrings::formatAsFNumber },
65 PropertyInfoData{ Property::PhotoDateTimeOriginal, false, QStringLiteral("photoDateTimeOriginal"), kli18nc("@label EXIF", "Original Date Time"), QMetaType::QDateTime, FormatStrings::formatDate },
66 PropertyInfoData{ Property::PhotoExposureBiasValue, false, QStringLiteral("photoExposureBiasValue"), kli18nc("@label EXIF", "Exposure Bias"), QMetaType::Double, FormatStrings::formatPhotoExposureBias },
67 PropertyInfoData{ Property::PhotoExposureTime, false, QStringLiteral("photoExposureTime"), kli18nc("@label EXIF", "Exposure Time"), QMetaType::Double, FormatStrings::formatPhotoTime },
68 PropertyInfoData{ Property::PhotoFlash, false, QStringLiteral("photoFlash"), kli18nc("@label EXIF", "Flash"), QMetaType::Int, FormatStrings::formatPhotoFlashValue },
69 PropertyInfoData{ Property::PhotoFNumber, false, QStringLiteral("photoFNumber"), kli18nc("@label EXIF", "F Number"), QMetaType::Double, FormatStrings::formatAsFNumber },
70 PropertyInfoData{ Property::PhotoFocalLength, false, QStringLiteral("photoFocalLength"), kli18nc("@label EXIF", "Focal Length"), QMetaType::Double, FormatStrings::formatAsMilliMeter },
71 PropertyInfoData{ Property::PhotoFocalLengthIn35mmFilm, false, QStringLiteral("photoFocalLengthIn35mmFilm"), kli18nc("@label EXIF", "Focal Length 35mm"), QMetaType::Double, FormatStrings::formatAsMilliMeter },
72 PropertyInfoData{ Property::PhotoGpsLatitude, false, QStringLiteral("photoGpsLatitude"), kli18nc("@label EXIF", "GPS Latitude"), QMetaType::Double, FormatStrings::formatAsDegree },
73 PropertyInfoData{ Property::PhotoGpsLongitude, false, QStringLiteral("photoGpsLongitude"), kli18nc("@label EXIF", "GPS Longitude"), QMetaType::Double, FormatStrings::formatAsDegree },
74 PropertyInfoData{ Property::PhotoGpsAltitude, false, QStringLiteral("photoGpsAltitude"), kli18nc("@label EXIF", "GPS Altitude"), QMetaType::Double, FormatStrings::formatAsMeter },
75 PropertyInfoData{ Property::PhotoISOSpeedRatings, false, QStringLiteral("photoISOSpeedRatings"), kli18nc("@label EXIF", "ISO Speed Rating"), QMetaType::Int },
76 PropertyInfoData{ Property::PhotoMeteringMode, false, QStringLiteral("photoMeteringMode"), kli18nc("@label EXIF", "Metering Mode"), QMetaType::Int },
77 PropertyInfoData{ Property::PhotoPixelXDimension, false, QStringLiteral("photoPixelXDimension"), kli18nc("@label EXIF", "X Dimension"), QMetaType::Int },
78 PropertyInfoData{ Property::PhotoPixelYDimension, false, QStringLiteral("photoPixelYDimension"), kli18nc("@label EXIF", "Y Dimension"), QMetaType::Int },
79 PropertyInfoData{ Property::PhotoSaturation, false, QStringLiteral("photoSaturation"), kli18nc("@label EXIF", "Saturation"), QMetaType::Int },
80 PropertyInfoData{ Property::PhotoSharpness, false, QStringLiteral("photoSharpness"), kli18nc("@label EXIF", "Sharpness"), QMetaType::Int },
81 PropertyInfoData{ Property::PhotoWhiteBalance, false, QStringLiteral("photoWhiteBalance"), kli18nc("@label EXIF", "White Balance"), QMetaType::Int },
82 PropertyInfoData{ Property::Publisher, true, QStringLiteral("publisher"), kli18nc("@label", "Publisher"), QMetaType::QString },
83 PropertyInfoData{ Property::Label, true, QStringLiteral("label"), kli18nc("@label", "Label"), QMetaType::QString },
84 PropertyInfoData{ Property::ReleaseYear, false, QStringLiteral("releaseYear"), kli18nc("@label", "Release Year"), QMetaType::Int },
85 PropertyInfoData{ Property::SampleRate, false, QStringLiteral("sampleRate"), kli18nc("@label", "Sample Rate"), QMetaType::Int, FormatStrings::formatSampleRate },
86 PropertyInfoData{ Property::Subject, false, QStringLiteral("subject"), kli18nc("@label", "Subject"), QMetaType::QString },
87 PropertyInfoData{ Property::Title, true, QStringLiteral("title"), kli18nc("@label", "Title"), QMetaType::QString },
88 PropertyInfoData{ Property::TrackNumber, false, QStringLiteral("trackNumber"), kli18nc("@label music track number", "Track Number"), QMetaType::Int },
89 PropertyInfoData{ Property::DiscNumber, false, QStringLiteral("discNumber"), kli18nc("@label music disc number", "Disc Number"), QMetaType::Int },
90 PropertyInfoData{ Property::Location, true, QStringLiteral("location"), kli18nc("@label", "Location"), QMetaType::QString },
91 PropertyInfoData{ Property::Performer, true, QStringLiteral("performer"), kli18nc("@label", "Performer"), QMetaType::QString },
92 PropertyInfoData{ Property::Ensemble, true, QStringLiteral("ensemble"), kli18nc("@label", "Ensemble"), QMetaType::QString },
93 PropertyInfoData{ Property::Arranger, true, QStringLiteral("arranger"), kli18nc("@label", "Arranger"), QMetaType::QString },
94 PropertyInfoData{ Property::Conductor, true, QStringLiteral("conductor"), kli18nc("@label", "Conductor"), QMetaType::QString },
95 PropertyInfoData{ Property::Compilation, true, QStringLiteral("compilation"), kli18nc("@label", "Compilation"), QMetaType::QString },
96 PropertyInfoData{ Property::License, true, QStringLiteral("license"), kli18nc("@label", "License"), QMetaType::QString },
97 PropertyInfoData{ Property::Lyrics, true, QStringLiteral("lyrics"), kli18nc("@label", "Lyrics"), QMetaType::QString },
98 PropertyInfoData{ Property::Opus, false, QStringLiteral("opus"), kli18nc("@label", "Opus"), QMetaType::Int },
99 PropertyInfoData{ Property::Rating, false, QStringLiteral("embeddedRating"), kli18nc("@label", "Rating"), QMetaType::Int },
100 PropertyInfoData{ Property::ReplayGainAlbumPeak, false, QStringLiteral("replayGainAlbumPeak"), kli18nc("@label ReplayGain is the name of a standard", "ReplayGain Album Peak"), QMetaType::Double, FormatStrings::formatDouble },
101 PropertyInfoData{ Property::ReplayGainAlbumGain, false, QStringLiteral("replayGainAlbumGain"), kli18nc("@label ReplayGain is the name of a standard", "ReplayGain Album Gain"), QMetaType::Double, FormatStrings::formatDouble },
102 PropertyInfoData{ Property::ReplayGainTrackPeak, false, QStringLiteral("replayGainTrackPeak"), kli18nc("@label ReplayGain is the name of a standard", "ReplayGain Track Peak"), QMetaType::Double, FormatStrings::formatDouble },
103 PropertyInfoData{ Property::ReplayGainTrackGain, false, QStringLiteral("replayGainTrackGain"), kli18nc("@label ReplayGain is the name of a standard", "ReplayGain Track Gain"), QMetaType::Double, FormatStrings::formatDouble },
104 PropertyInfoData{ Property::Width, false, QStringLiteral("width"), kli18nc("@label", "Width"), QMetaType::Int },
105 PropertyInfoData{ Property::WordCount, false, QStringLiteral("wordCount"), kli18nc("@label number of words", "Word Count"), QMetaType::Int },
106 PropertyInfoData{ Property::TranslationUnitsTotal, false, QStringLiteral("translationUnitsTotal"), kli18nc("@label number of translatable strings", "Translatable Units"), QMetaType::Int },
107 PropertyInfoData{ Property::TranslationUnitsWithTranslation, false, QStringLiteral("translationUnitsWithTranslation"), kli18nc("@label number of translated strings", "Translations"), QMetaType::Int },
108 PropertyInfoData{ Property::TranslationUnitsWithDraftTranslation, false, QStringLiteral("translationUnitsWithDraftTranslation"), kli18nc("@label number of fuzzy translated strings", "Draft Translations"), QMetaType::Int },
109 PropertyInfoData{ Property::TranslationLastAuthor, false, QStringLiteral("translationLastAuthor"), kli18nc("@label translation author", "Author"), QMetaType::QString },
110 PropertyInfoData{ Property::TranslationLastUpDate, false, QStringLiteral("translationLastUpDate"), kli18nc("@label translations last update", "Last Update"), QMetaType::QString, FormatStrings::formatDate },
111 PropertyInfoData{ Property::TranslationTemplateDate, false, QStringLiteral("translationTemplateDate"), kli18nc("@label date of template creation8", "Template Creation"), QMetaType::QString, FormatStrings::formatDate },
112 PropertyInfoData{ Property::OriginUrl, false, QStringLiteral("originUrl"), kli18nc("@label the URL a file was originally downloaded from", "Downloaded From"), QMetaType::QUrl },
113 PropertyInfoData{ Property::OriginEmailSubject, false, QStringLiteral("originEmailSubject"), kli18nc("@label the subject of an email this file was attached to", "E-Mail Attachment Subject"), QMetaType::QString },
114 PropertyInfoData{ Property::OriginEmailSender, false, QStringLiteral("originEmailSender"), kli18nc("@label the sender of an email this file was attached to", "E-Mail Attachment Sender"), QMetaType::QString },
115 PropertyInfoData{ Property::OriginEmailMessageId, false, QStringLiteral("originEmailMessageId"), kli18nc("@label the message ID of an email this file was attached to", "E-Mail Attachment Message ID"), QMetaType::QString }
116};
117
118namespace {
119 auto constexpr propertyDataById(Property::Property property) {
120 for (const auto& p : staticPropertyInfo) {
121 if (p.prop == property)
122 return &p;
123 }
124 return &staticEmptyPropertyInfo;
125 }
126}
127
128PropertyInfo::PropertyInfo(Property::Property property) : d(propertyDataById(property)) {};
129
130PropertyInfo::PropertyInfo() : d(&staticEmptyPropertyInfo) {};
131
132PropertyInfo::PropertyInfo(const PropertyInfo& pi)
133 : d(pi.d)
134{
135}
136
137PropertyInfo::~PropertyInfo() = default;
138
139PropertyInfo& PropertyInfo::operator=(const PropertyInfo& rhs)
140{
141 d = rhs.d;
142 return *this;
143}
144
145bool PropertyInfo::operator==(const PropertyInfo& rhs) const
146{
147 return d == rhs.d;
148}
149
151{
152 return d->displayName.toString();
153}
154
156{
157 return d->name;
158}
159
161{
162 return d->prop;
163}
164
166{
167 return d->valueType;
168}
169
171{
172 return d->shouldBeIndexed;
173}
174
176{
178 if (d->valueType == QMetaType::QString) {
179 return QLocale().createSeparatedList(value.toStringList());
180 } else {
181 QStringList displayList;
182 const auto valueList = value.toList();
183 for (const auto& entry : valueList) {
184 displayList << d->formatAsString(entry);
185 }
186 return QLocale().createSeparatedList(displayList);
187 }
188 } else {
189 return d->formatAsString(value);
190 }
191}
192
193namespace {
194 class LcPropertyName
195 {
196 public:
197 LcPropertyName(const QString& n) : name(n) {};
198 QString name;
199 };
200
201 constexpr QChar trivialToLower(const QChar &c) {
202 if (c.isUpper()) {
203 return QChar::fromLatin1(c.toLatin1() ^ ('a' ^ 'A'));
204 }
205 return c;
206 }
207
208 inline bool operator==(const LcPropertyName &a, const LcPropertyName &b)
209 {
210 if (a.name.size() != b.name.size()) {
211 return false;
212 }
213 for (int i = 0; i < a.name.size(); i++) {
214 if ((a.name[i] != b.name[i]) && (trivialToLower(a.name[i]) != trivialToLower(b.name[i]))) {
215 return false;
216 }
217 }
218 return true;
219 }
220
221 inline size_t qHash(const LcPropertyName &key, size_t seed = 0)
222 {
223 size_t val = seed;
224 for (const auto& c : key.name) {
225 val ^= qHash(trivialToLower(c));
226 }
227 return val;
228 }
229
230 static const QHash<LcPropertyName, PropertyInfo> propertyHash = []() {
232 infoHash.reserve(staticPropertyInfo.size());
233
234 for (const auto& info: staticPropertyInfo) {
235 infoHash[info.name] = info.prop;
236 }
237 return infoHash;
238 }();
239}
240
242{
243 return propertyHash.value(LcPropertyName(name));
244}
245
247{
248 static QStringList sNames = []() {
249 QStringList names;
250 names.reserve(staticPropertyInfo.size());
251 for (auto info: staticPropertyInfo) {
252 names.append(info.name);
253 }
254 return names;
255 }();
256 return sNames;
257}
The PropertyInfo class can be used to obtain extra information about any property.
QString name() const
The internal unique name used to refer to the property.
QString displayName() const
A user visible name of the property.
Property::Property property() const
The enumeration which represents this property.
static QStringList allNames()
Get the names of all valid, supported properties.
static PropertyInfo fromName(const QString &name)
Construct a PropertyInfo from the internal property name.
QString formatAsDisplayString(const QVariant &value) const
Returns the value of the property as a QString with added formatting, added units if needed,...
bool shouldBeIndexed() const
Indicates if this property requires indexing or should just be stored.
QMetaType::Type valueType() const
The type the value of this property should be.
QString toString() const
QString name(StandardShortcut id)
KTEXTEDITOR_EXPORT size_t qHash(KTextEditor::Cursor cursor, size_t seed=0) noexcept
Property
The Property enum contains all files property types that KFileMetaData manipulates.
Definition properties.h:23
QChar fromLatin1(char c)
bool isUpper() const const
char toLatin1() const const
void reserve(int size)
const T value(const Key &key) const const
void append(const T &value)
void reserve(int alloc)
QString createSeparatedList(const QStringList &list) const const
int size() const const
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
QList< QVariant > toList() const const
QStringList toStringList() const const
int userType() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:44:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.