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#include "icnamematch_p.h"
15
16#include <array>
17
18#include <QLocale>
19
20using namespace KFileMetaData;
21
22class KFileMetaData::PropertyInfoData
23{
24 using FormatFunction = QString (&)(const QVariant&);
25
26public:
27 const Property::Property prop;
28 const bool shouldBeIndexed = false;
29 const QString name;
30 const KLazyLocalizedString displayName;
32 const FormatFunction formatAsString = FormatStrings::toStringFunction;
33
34 static constexpr auto fromId(Property::Property property) -> const PropertyInfoData*;
35 static auto fromName(const QString& name) -> const PropertyInfoData*;
36
37 static const PropertyInfoData s_Empty;
38 static const std::array<PropertyInfoData, 78> s_allProperties;
39 static const QHash<LcIdentifierName, const PropertyInfoData*> s_propertyHash;
40};
41
42const PropertyInfoData PropertyInfoData::s_Empty{ Property::Empty, false, QStringLiteral("empty"), kli18nc("@label", "Empty") };
43
44const std::array<PropertyInfoData, 78> PropertyInfoData::s_allProperties
45{
46 PropertyInfoData{ Property::Album, true, QStringLiteral("album"), kli18nc("@label music album", "Album"), QMetaType::QString },
47 PropertyInfoData{ Property::AlbumArtist, true, QStringLiteral("albumArtist"), kli18nc("@label", "Album Artist"), QMetaType::QString },
48 PropertyInfoData{ Property::Artist, true, QStringLiteral("artist"), kli18nc("@label", "Artist"), QMetaType::QString },
49 PropertyInfoData{ Property::AspectRatio, false, QStringLiteral("aspectRatio"), kli18nc("@label", "Aspect Ratio"), QMetaType::Double, FormatStrings::formatAspectRatio },
50 PropertyInfoData{ Property::Author, true, QStringLiteral("author"), kli18nc("@label", "Author"), QMetaType::QString },
51 PropertyInfoData{ Property::BitRate, false, QStringLiteral("bitRate"), kli18nc("@label", "Bitrate"), QMetaType::Int, FormatStrings::formatBitRate },
52 PropertyInfoData{ Property::Channels, false, QStringLiteral("channels"), kli18nc("@label", "Channels"), QMetaType::Int },
53 PropertyInfoData{ Property::Comment, false, QStringLiteral("comment"), kli18nc("@label", "Comment"), QMetaType::QString },
54 PropertyInfoData{ Property::Description, false, QStringLiteral("description"), kli18nc("@label", "Description"), QMetaType::QString },
55 PropertyInfoData{ Property::Composer, true, QStringLiteral("composer"), kli18nc("@label", "Composer"), QMetaType::QString },
56 PropertyInfoData{ Property::Copyright, false, QStringLiteral("copyright"), kli18nc("@label", "Copyright"), QMetaType::QString },
57 PropertyInfoData{ Property::CreationDate, false, QStringLiteral("creationDate"), kli18nc("@label", "Creation Date"), QMetaType::QDateTime, FormatStrings::formatDate },
58 PropertyInfoData{ Property::Duration, false, QStringLiteral("duration"), kli18nc("@label", "Duration"), QMetaType::Int, FormatStrings::formatDuration },
59 PropertyInfoData{ Property::FrameRate, false, QStringLiteral("frameRate"), kli18nc("@label", "Frame Rate"), QMetaType::Double, FormatStrings::formatAsFrameRate },
60 PropertyInfoData{ Property::Generator, false, QStringLiteral("generator"), kli18nc("@label", "Document Generated By"), QMetaType::QString },
61 PropertyInfoData{ Property::Genre, true, QStringLiteral("genre"), kli18nc("@label music genre", "Genre"), QMetaType::QString },
62 PropertyInfoData{ Property::Height, false, QStringLiteral("height"), kli18nc("@label", "Height"), QMetaType::Int },
63 PropertyInfoData{ Property::ImageDateTime, false, QStringLiteral("imageDateTime"), kli18nc("@label EXIF", "Image Date Time"), QMetaType::QDateTime, FormatStrings::formatDate },
64 PropertyInfoData{ Property::Manufacturer, false, QStringLiteral("manufacturer"), kli18nc("@label EXIF", "Manufacturer"), QMetaType::QString },
65 PropertyInfoData{ Property::Model, false, QStringLiteral("model"), kli18nc("@label EXIF", "Model"), QMetaType::QString },
66 PropertyInfoData{ Property::ImageOrientation, false, QStringLiteral("imageOrientation"), kli18nc("@label EXIF", "Image Orientation"), QMetaType::Int, FormatStrings::formatOrientationValue },
67 PropertyInfoData{ Property::Keywords, false, QStringLiteral("keywords"), kli18nc("@label", "Keywords"), QMetaType::QString },
68 PropertyInfoData{ Property::Language, false, QStringLiteral("language"), kli18nc("@label", "Language"), QMetaType::QString },
69 PropertyInfoData{ Property::LineCount, false, QStringLiteral("lineCount"), kli18nc("@label number of lines", "Line Count"), QMetaType::Int },
70 PropertyInfoData{ Property::Lyricist, true, QStringLiteral("lyricist"), kli18nc("@label", "Lyricist"), QMetaType::QString },
71 PropertyInfoData{ Property::PageCount, false, QStringLiteral("pageCount"), kli18nc("@label", "Page Count"), QMetaType::Int },
72 PropertyInfoData{ Property::PhotoApertureValue, false, QStringLiteral("photoApertureValue"), kli18nc("@label EXIF", "Aperture Value"), QMetaType::Double, FormatStrings::formatAsFNumber },
73 PropertyInfoData{ Property::PhotoDateTimeOriginal, false, QStringLiteral("photoDateTimeOriginal"), kli18nc("@label EXIF", "Original Date Time"), QMetaType::QDateTime, FormatStrings::formatDate },
74 PropertyInfoData{ Property::PhotoExposureBiasValue, false, QStringLiteral("photoExposureBiasValue"), kli18nc("@label EXIF", "Exposure Bias"), QMetaType::Double, FormatStrings::formatPhotoExposureBias },
75 PropertyInfoData{ Property::PhotoExposureTime, false, QStringLiteral("photoExposureTime"), kli18nc("@label EXIF", "Exposure Time"), QMetaType::Double, FormatStrings::formatPhotoTime },
76 PropertyInfoData{ Property::PhotoFlash, false, QStringLiteral("photoFlash"), kli18nc("@label EXIF", "Flash"), QMetaType::Int, FormatStrings::formatPhotoFlashValue },
77 PropertyInfoData{ Property::PhotoFNumber, false, QStringLiteral("photoFNumber"), kli18nc("@label EXIF", "F Number"), QMetaType::Double, FormatStrings::formatAsFNumber },
78 PropertyInfoData{ Property::PhotoFocalLength, false, QStringLiteral("photoFocalLength"), kli18nc("@label EXIF", "Focal Length"), QMetaType::Double, FormatStrings::formatAsMilliMeter },
79 PropertyInfoData{ Property::PhotoFocalLengthIn35mmFilm, false, QStringLiteral("photoFocalLengthIn35mmFilm"), kli18nc("@label EXIF", "Focal Length 35mm"), QMetaType::Double, FormatStrings::formatAsMilliMeter },
80 PropertyInfoData{ Property::PhotoGpsLatitude, false, QStringLiteral("photoGpsLatitude"), kli18nc("@label EXIF", "GPS Latitude"), QMetaType::Double, FormatStrings::formatAsDegree },
81 PropertyInfoData{ Property::PhotoGpsLongitude, false, QStringLiteral("photoGpsLongitude"), kli18nc("@label EXIF", "GPS Longitude"), QMetaType::Double, FormatStrings::formatAsDegree },
82 PropertyInfoData{ Property::PhotoGpsAltitude, false, QStringLiteral("photoGpsAltitude"), kli18nc("@label EXIF", "GPS Altitude"), QMetaType::Double, FormatStrings::formatAsMeter },
83 PropertyInfoData{ Property::PhotoISOSpeedRatings, false, QStringLiteral("photoISOSpeedRatings"), kli18nc("@label EXIF", "ISO Speed Rating"), QMetaType::Int },
84 PropertyInfoData{ Property::PhotoMeteringMode, false, QStringLiteral("photoMeteringMode"), kli18nc("@label EXIF", "Metering Mode"), QMetaType::Int },
85 PropertyInfoData{ Property::PhotoPixelXDimension, false, QStringLiteral("photoPixelXDimension"), kli18nc("@label EXIF", "X Dimension"), QMetaType::Int },
86 PropertyInfoData{ Property::PhotoPixelYDimension, false, QStringLiteral("photoPixelYDimension"), kli18nc("@label EXIF", "Y Dimension"), QMetaType::Int },
87 PropertyInfoData{ Property::PhotoSaturation, false, QStringLiteral("photoSaturation"), kli18nc("@label EXIF", "Saturation"), QMetaType::Int },
88 PropertyInfoData{ Property::PhotoSharpness, false, QStringLiteral("photoSharpness"), kli18nc("@label EXIF", "Sharpness"), QMetaType::Int },
89 PropertyInfoData{ Property::PhotoWhiteBalance, false, QStringLiteral("photoWhiteBalance"), kli18nc("@label EXIF", "White Balance"), QMetaType::Int },
90 PropertyInfoData{ Property::Publisher, true, QStringLiteral("publisher"), kli18nc("@label", "Publisher"), QMetaType::QString },
91 PropertyInfoData{ Property::Label, true, QStringLiteral("label"), kli18nc("@label", "Label"), QMetaType::QString },
92 PropertyInfoData{ Property::ReleaseYear, false, QStringLiteral("releaseYear"), kli18nc("@label", "Release Year"), QMetaType::Int },
93 PropertyInfoData{ Property::SampleRate, false, QStringLiteral("sampleRate"), kli18nc("@label", "Sample Rate"), QMetaType::Int, FormatStrings::formatSampleRate },
94 PropertyInfoData{ Property::Subject, false, QStringLiteral("subject"), kli18nc("@label", "Subject"), QMetaType::QString },
95 PropertyInfoData{ Property::Title, true, QStringLiteral("title"), kli18nc("@label", "Title"), QMetaType::QString },
96 PropertyInfoData{ Property::TrackNumber, false, QStringLiteral("trackNumber"), kli18nc("@label music track number", "Track Number"), QMetaType::Int },
97 PropertyInfoData{ Property::DiscNumber, false, QStringLiteral("discNumber"), kli18nc("@label music disc number", "Disc Number"), QMetaType::Int },
98 PropertyInfoData{ Property::Location, true, QStringLiteral("location"), kli18nc("@label", "Location"), QMetaType::QString },
99 PropertyInfoData{ Property::Performer, true, QStringLiteral("performer"), kli18nc("@label", "Performer"), QMetaType::QString },
100 PropertyInfoData{ Property::Ensemble, true, QStringLiteral("ensemble"), kli18nc("@label", "Ensemble"), QMetaType::QString },
101 PropertyInfoData{ Property::Arranger, true, QStringLiteral("arranger"), kli18nc("@label", "Arranger"), QMetaType::QString },
102 PropertyInfoData{ Property::Conductor, true, QStringLiteral("conductor"), kli18nc("@label", "Conductor"), QMetaType::QString },
103 PropertyInfoData{ Property::Compilation, true, QStringLiteral("compilation"), kli18nc("@label", "Compilation"), QMetaType::QString },
104 PropertyInfoData{ Property::License, true, QStringLiteral("license"), kli18nc("@label", "License"), QMetaType::QString },
105 PropertyInfoData{ Property::Lyrics, true, QStringLiteral("lyrics"), kli18nc("@label", "Lyrics"), QMetaType::QString },
106 PropertyInfoData{ Property::Opus, false, QStringLiteral("opus"), kli18nc("@label", "Opus"), QMetaType::Int },
107 PropertyInfoData{ Property::Rating, false, QStringLiteral("embeddedRating"), kli18nc("@label", "Rating"), QMetaType::Int },
108 PropertyInfoData{ Property::ReplayGainAlbumPeak, false, QStringLiteral("replayGainAlbumPeak"), kli18nc("@label ReplayGain is the name of a standard", "ReplayGain Album Peak"), QMetaType::Double, FormatStrings::formatDouble },
109 PropertyInfoData{ Property::ReplayGainAlbumGain, false, QStringLiteral("replayGainAlbumGain"), kli18nc("@label ReplayGain is the name of a standard", "ReplayGain Album Gain"), QMetaType::Double, FormatStrings::formatDouble },
110 PropertyInfoData{ Property::ReplayGainTrackPeak, false, QStringLiteral("replayGainTrackPeak"), kli18nc("@label ReplayGain is the name of a standard", "ReplayGain Track Peak"), QMetaType::Double, FormatStrings::formatDouble },
111 PropertyInfoData{ Property::ReplayGainTrackGain, false, QStringLiteral("replayGainTrackGain"), kli18nc("@label ReplayGain is the name of a standard", "ReplayGain Track Gain"), QMetaType::Double, FormatStrings::formatDouble },
112 PropertyInfoData{ Property::Width, false, QStringLiteral("width"), kli18nc("@label", "Width"), QMetaType::Int },
113 PropertyInfoData{ Property::WordCount, false, QStringLiteral("wordCount"), kli18nc("@label number of words", "Word Count"), QMetaType::Int },
114 PropertyInfoData{ Property::TranslationUnitsTotal, false, QStringLiteral("translationUnitsTotal"), kli18nc("@label number of translatable strings", "Translatable Units"), QMetaType::Int },
115 PropertyInfoData{ Property::TranslationUnitsWithTranslation, false, QStringLiteral("translationUnitsWithTranslation"), kli18nc("@label number of translated strings", "Translations"), QMetaType::Int },
116 PropertyInfoData{ Property::TranslationUnitsWithDraftTranslation, false, QStringLiteral("translationUnitsWithDraftTranslation"), kli18nc("@label number of fuzzy translated strings", "Draft Translations"), QMetaType::Int },
117 PropertyInfoData{ Property::TranslationLastAuthor, false, QStringLiteral("translationLastAuthor"), kli18nc("@label translation author", "Author"), QMetaType::QString },
118 PropertyInfoData{ Property::TranslationLastUpDate, false, QStringLiteral("translationLastUpDate"), kli18nc("@label translations last update", "Last Update"), QMetaType::QString, FormatStrings::formatDate },
119 PropertyInfoData{ Property::TranslationTemplateDate, false, QStringLiteral("translationTemplateDate"), kli18nc("@label date of template creation8", "Template Creation"), QMetaType::QString, FormatStrings::formatDate },
120 PropertyInfoData{ Property::OriginUrl, false, QStringLiteral("originUrl"), kli18nc("@label the URL a file was originally downloaded from", "Downloaded From"), QMetaType::QUrl },
121 PropertyInfoData{ Property::OriginEmailSubject, false, QStringLiteral("originEmailSubject"), kli18nc("@label the subject of an email this file was attached to", "E-Mail Attachment Subject"), QMetaType::QString },
122 PropertyInfoData{ Property::OriginEmailSender, false, QStringLiteral("originEmailSender"), kli18nc("@label the sender of an email this file was attached to", "E-Mail Attachment Sender"), QMetaType::QString },
123 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 }
124};
125
126const QHash<LcIdentifierName, const PropertyInfoData*> PropertyInfoData::s_propertyHash = []()
127{
129 infoHash.reserve(s_allProperties.size());
130
131 for (const auto& info: s_allProperties) {
132 infoHash[QStringView(info.name)] = &info;
133 }
134 return infoHash;
135}();
136
137constexpr auto PropertyInfoData::fromId(Property::Property property) -> const PropertyInfoData*
138{
139 for (const auto& p : s_allProperties) {
140 if (p.prop == property)
141 return &p;
142 }
143 return &s_Empty;
144}
145
146auto PropertyInfoData::fromName(const QString& name) -> const PropertyInfoData*
147{
148 return s_propertyHash.value(LcIdentifierName(name), &s_Empty);
149}
150
151
152PropertyInfo::PropertyInfo(Property::Property property) : d(PropertyInfoData::fromId(property)) {};
153
154PropertyInfo::PropertyInfo() : d(&PropertyInfoData::s_Empty) {};
155
156PropertyInfo::PropertyInfo(const PropertyInfo& pi)
157 : d(pi.d)
158{
159}
160
161PropertyInfo::~PropertyInfo() = default;
162
163PropertyInfo& PropertyInfo::operator=(const PropertyInfo& rhs)
164{
165 d = rhs.d;
166 return *this;
167}
168
169bool PropertyInfo::operator==(const PropertyInfo& rhs) const
170{
171 return d == rhs.d;
172}
173
175{
176 return d->displayName.toString();
177}
178
180{
181 return d->name;
182}
183
185{
186 return d->prop;
187}
188
190{
191 return d->valueType;
192}
193
195{
196 return d->shouldBeIndexed;
197}
198
200{
202 if (d->valueType == QMetaType::QString) {
203 return QLocale().createSeparatedList(value.toStringList());
204 } else {
205 QStringList displayList;
206 const auto valueList = value.toList();
207 for (const auto& entry : valueList) {
208 displayList << d->formatAsString(entry);
209 }
210 return QLocale().createSeparatedList(displayList);
211 }
212 } else {
213 return d->formatAsString(value);
214 }
215}
216
218{
219 PropertyInfo pi;
220 pi.d = PropertyInfoData::fromName(name);
221 return pi;
222}
223
225{
226 static QStringList sNames = []() {
227 QStringList names;
228 names.reserve(PropertyInfoData::s_allProperties.size());
229 for (auto info: PropertyInfoData::s_allProperties) {
230 names.append(info.name);
231 }
232 return names;
233 }();
234 return sNames;
235}
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
Property
The Property enum contains all files property types that KFileMetaData manipulates.
Definition properties.h:26
The KFileMetaData namespace.
void reserve(qsizetype size)
void append(QList< T > &&value)
void reserve(qsizetype size)
QString createSeparatedList(const QStringList &list) const const
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 Sat Dec 21 2024 16:59:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.