Changeset View
Changeset View
Standalone View
Standalone View
src/propertyinfo.cpp
Show All 18 Lines | |||||
19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
20 | * | 20 | * | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "propertyinfo.h" | 23 | #include "propertyinfo.h" | ||
24 | 24 | | |||
25 | #include <KLocalizedString> | 25 | #include <KLocalizedString> | ||
26 | 26 | | |||
27 | #include "formatstrings.h" | ||||
28 | | ||||
27 | using namespace KFileMetaData; | 29 | using namespace KFileMetaData; | ||
28 | 30 | | |||
29 | class Q_DECL_HIDDEN PropertyInfo::Private | 31 | class Q_DECL_HIDDEN PropertyInfo::Private | ||
30 | { | 32 | { | ||
31 | public: | 33 | public: | ||
32 | Property::Property prop; | 34 | Property::Property prop; | ||
33 | QString name; | 35 | QString name; | ||
34 | QString displayName; | 36 | QString displayName; | ||
35 | QVariant::Type valueType; | 37 | QVariant::Type valueType; | ||
36 | bool shouldBeIndexed; | 38 | bool shouldBeIndexed; | ||
39 | QString (*formatAsString)(const QVariant& value) = nullptr; | ||||
37 | }; | 40 | }; | ||
38 | 41 | | |||
39 | PropertyInfo::PropertyInfo(Property::Property property) | 42 | PropertyInfo::PropertyInfo(Property::Property property) | ||
40 | : d(new Private) | 43 | : d(new Private) | ||
41 | { | 44 | { | ||
42 | d->prop = property; | 45 | d->prop = property; | ||
43 | d->shouldBeIndexed = true; | 46 | d->shouldBeIndexed = true; | ||
44 | 47 | | |||
Show All 27 Lines | 73 | case Property::Author: | |||
72 | d->displayName = i18nc("@label", "Author"); | 75 | d->displayName = i18nc("@label", "Author"); | ||
73 | d->valueType = QVariant::StringList; | 76 | d->valueType = QVariant::StringList; | ||
74 | break; | 77 | break; | ||
75 | 78 | | |||
76 | case Property::BitRate: | 79 | case Property::BitRate: | ||
77 | d->name = QStringLiteral("bitRate"); | 80 | d->name = QStringLiteral("bitRate"); | ||
78 | d->displayName = i18nc("@label", "Bitrate"); | 81 | d->displayName = i18nc("@label", "Bitrate"); | ||
79 | d->valueType = QVariant::Int; | 82 | d->valueType = QVariant::Int; | ||
83 | d->formatAsString = &FormatStrings::formatBitRate; | ||||
80 | break; | 84 | break; | ||
81 | 85 | | |||
82 | case Property::Channels: | 86 | case Property::Channels: | ||
83 | d->name = QStringLiteral("channels"); | 87 | d->name = QStringLiteral("channels"); | ||
84 | d->displayName = i18nc("@label", "Channels"); | 88 | d->displayName = i18nc("@label", "Channels"); | ||
85 | d->valueType = QVariant::Int; | 89 | d->valueType = QVariant::Int; | ||
86 | break; | 90 | break; | ||
87 | 91 | | |||
Show All 24 Lines | 113 | case Property::Copyright: | |||
112 | d->valueType = QVariant::String; | 116 | d->valueType = QVariant::String; | ||
113 | d->shouldBeIndexed = false; | 117 | d->shouldBeIndexed = false; | ||
114 | break; | 118 | break; | ||
115 | 119 | | |||
116 | case Property::CreationDate: | 120 | case Property::CreationDate: | ||
117 | d->name = QStringLiteral("creationDate"); | 121 | d->name = QStringLiteral("creationDate"); | ||
118 | d->displayName = i18nc("@label", "Creation Date"); | 122 | d->displayName = i18nc("@label", "Creation Date"); | ||
119 | d->valueType = QVariant::String; | 123 | d->valueType = QVariant::String; | ||
124 | d->formatAsString = &FormatStrings::formatDate; | ||||
120 | break; | 125 | break; | ||
121 | 126 | | |||
122 | case Property::Duration: | 127 | case Property::Duration: | ||
123 | d->name = QStringLiteral("duration"); | 128 | d->name = QStringLiteral("duration"); | ||
124 | d->displayName = i18nc("@label", "Duration"); | 129 | d->displayName = i18nc("@label", "Duration"); | ||
125 | d->valueType = QVariant::Int; | 130 | d->valueType = QVariant::Int; | ||
131 | d->formatAsString = &FormatStrings::formatDuration; | ||||
126 | break; | 132 | break; | ||
127 | 133 | | |||
128 | case Property::Empty: | 134 | case Property::Empty: | ||
129 | d->name = QStringLiteral("empty"); | 135 | d->name = QStringLiteral("empty"); | ||
130 | d->valueType = QVariant::Invalid; | 136 | d->valueType = QVariant::Invalid; | ||
131 | break; | 137 | break; | ||
132 | 138 | | |||
133 | case Property::FrameRate: | 139 | case Property::FrameRate: | ||
Show All 21 Lines | 159 | case Property::Height: | |||
155 | d->displayName = i18nc("@label", "Height"); | 161 | d->displayName = i18nc("@label", "Height"); | ||
156 | d->valueType = QVariant::Int; | 162 | d->valueType = QVariant::Int; | ||
157 | break; | 163 | break; | ||
158 | 164 | | |||
159 | case Property::ImageDateTime: | 165 | case Property::ImageDateTime: | ||
160 | d->name = QStringLiteral("imageDateTime"); | 166 | d->name = QStringLiteral("imageDateTime"); | ||
161 | d->displayName = i18nc("@label EXIF", "Image Date Time"); | 167 | d->displayName = i18nc("@label EXIF", "Image Date Time"); | ||
162 | d->valueType = QVariant::DateTime; | 168 | d->valueType = QVariant::DateTime; | ||
169 | d->formatAsString = &FormatStrings::formatDate; | ||||
163 | break; | 170 | break; | ||
164 | 171 | | |||
165 | case Property::ImageMake: | 172 | case Property::ImageMake: | ||
166 | d->name = QStringLiteral("imageMake"); | 173 | d->name = QStringLiteral("imageMake"); | ||
167 | d->displayName = i18nc("@label EXIF", "Image Make"); | 174 | d->displayName = i18nc("@label EXIF", "Image Make"); | ||
168 | d->valueType = QVariant::String; | 175 | d->valueType = QVariant::String; | ||
169 | d->shouldBeIndexed = false; | 176 | d->shouldBeIndexed = false; | ||
170 | break; | 177 | break; | ||
171 | 178 | | |||
172 | case Property::ImageModel: | 179 | case Property::ImageModel: | ||
173 | d->name = QStringLiteral("imageModel"); | 180 | d->name = QStringLiteral("imageModel"); | ||
174 | d->displayName = i18nc("@label EXIF", "Image Model"); | 181 | d->displayName = i18nc("@label EXIF", "Image Model"); | ||
175 | d->valueType = QVariant::String; | 182 | d->valueType = QVariant::String; | ||
176 | d->shouldBeIndexed = false; | 183 | d->shouldBeIndexed = false; | ||
177 | break; | 184 | break; | ||
178 | 185 | | |||
179 | case Property::ImageOrientation: | 186 | case Property::ImageOrientation: | ||
180 | d->name = QStringLiteral("imageOrientation"); | 187 | d->name = QStringLiteral("imageOrientation"); | ||
181 | d->displayName = i18nc("@label EXIF", "Image Orientation"); | 188 | d->displayName = i18nc("@label EXIF", "Image Orientation"); | ||
182 | d->valueType = QVariant::Int; | 189 | d->valueType = QVariant::Int; | ||
190 | d->formatAsString = &FormatStrings::formatOrientationValue; | ||||
183 | break; | 191 | break; | ||
184 | 192 | | |||
185 | case Property::Keywords: | 193 | case Property::Keywords: | ||
186 | d->name = QStringLiteral("keywords"); | 194 | d->name = QStringLiteral("keywords"); | ||
187 | d->displayName = i18nc("@label", "Keywords"); | 195 | d->displayName = i18nc("@label", "Keywords"); | ||
188 | d->valueType = QVariant::StringList; | 196 | d->valueType = QVariant::StringList; | ||
189 | d->shouldBeIndexed = false; | 197 | d->shouldBeIndexed = false; | ||
190 | break; | 198 | break; | ||
Show All 29 Lines | 226 | case Property::PhotoApertureValue: | |||
220 | d->displayName = i18nc("@label EXIF", "Photo Aperture Value"); | 228 | d->displayName = i18nc("@label EXIF", "Photo Aperture Value"); | ||
221 | d->valueType = QVariant::Double; | 229 | d->valueType = QVariant::Double; | ||
222 | break; | 230 | break; | ||
223 | 231 | | |||
224 | case Property::PhotoDateTimeOriginal: | 232 | case Property::PhotoDateTimeOriginal: | ||
225 | d->name = QStringLiteral("photoDateTimeOriginal"); | 233 | d->name = QStringLiteral("photoDateTimeOriginal"); | ||
226 | d->displayName = i18nc("@label EXIF", "Photo Original Date Time"); | 234 | d->displayName = i18nc("@label EXIF", "Photo Original Date Time"); | ||
227 | d->valueType = QVariant::DateTime; | 235 | d->valueType = QVariant::DateTime; | ||
236 | d->formatAsString = &FormatStrings::formatDate; | ||||
228 | break; | 237 | break; | ||
229 | 238 | | |||
230 | case Property::PhotoExposureBiasValue: | 239 | case Property::PhotoExposureBiasValue: | ||
231 | d->name = QStringLiteral("photoExposureBiasValue"); | 240 | d->name = QStringLiteral("photoExposureBiasValue"); | ||
232 | d->displayName = i18nc("@label EXIF", "Photo Exposure Bias"); | 241 | d->displayName = i18nc("@label EXIF", "Photo Exposure Bias"); | ||
233 | d->valueType = QVariant::Double; | 242 | d->valueType = QVariant::Double; | ||
234 | break; | 243 | break; | ||
235 | 244 | | |||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Line(s) | 347 | case Property::ReleaseYear: | |||
340 | d->displayName = i18nc("@label", "Release Year"); | 349 | d->displayName = i18nc("@label", "Release Year"); | ||
341 | d->valueType = QVariant::Int; | 350 | d->valueType = QVariant::Int; | ||
342 | break; | 351 | break; | ||
343 | 352 | | |||
344 | case Property::SampleRate: | 353 | case Property::SampleRate: | ||
345 | d->name = QStringLiteral("sampleRate"); | 354 | d->name = QStringLiteral("sampleRate"); | ||
346 | d->displayName = i18nc("@label", "Sample Rate"); | 355 | d->displayName = i18nc("@label", "Sample Rate"); | ||
347 | d->valueType = QVariant::Int; | 356 | d->valueType = QVariant::Int; | ||
357 | d->formatAsString = &FormatStrings::formatSampleRate; | ||||
348 | break; | 358 | break; | ||
349 | 359 | | |||
350 | case Property::Subject: | 360 | case Property::Subject: | ||
351 | d->name = QStringLiteral("subject"); | 361 | d->name = QStringLiteral("subject"); | ||
352 | d->displayName = i18nc("@label", "Subject"); | 362 | d->displayName = i18nc("@label", "Subject"); | ||
353 | d->valueType = QVariant::String; | 363 | d->valueType = QVariant::String; | ||
354 | d->shouldBeIndexed = false; | 364 | d->shouldBeIndexed = false; | ||
355 | break; | 365 | break; | ||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Line(s) | 504 | case Property::TranslationLastAuthor: | |||
498 | d->shouldBeIndexed = false; | 508 | d->shouldBeIndexed = false; | ||
499 | break; | 509 | break; | ||
500 | 510 | | |||
501 | case Property::TranslationLastUpDate: | 511 | case Property::TranslationLastUpDate: | ||
502 | d->name = QStringLiteral("translationLastUpDate"); | 512 | d->name = QStringLiteral("translationLastUpDate"); | ||
503 | d->displayName = i18nc("@label translations last update", "Last Update"); | 513 | d->displayName = i18nc("@label translations last update", "Last Update"); | ||
504 | d->valueType = QVariant::String; | 514 | d->valueType = QVariant::String; | ||
505 | d->shouldBeIndexed = false; | 515 | d->shouldBeIndexed = false; | ||
516 | d->formatAsString = &FormatStrings::formatDate; | ||||
506 | break; | 517 | break; | ||
507 | 518 | | |||
508 | case Property::TranslationTemplateDate: | 519 | case Property::TranslationTemplateDate: | ||
509 | d->name = QStringLiteral("translationTemplateDate"); | 520 | d->name = QStringLiteral("translationTemplateDate"); | ||
510 | d->displayName = i18nc("@label date of template creation8", "Template Creation"); | 521 | d->displayName = i18nc("@label date of template creation8", "Template Creation"); | ||
511 | d->valueType = QVariant::String; | 522 | d->valueType = QVariant::String; | ||
512 | d->shouldBeIndexed = false; | 523 | d->shouldBeIndexed = false; | ||
524 | d->formatAsString = &FormatStrings::formatDate; | ||||
513 | break; | 525 | break; | ||
514 | 526 | | |||
515 | case Property::OriginUrl: | 527 | case Property::OriginUrl: | ||
516 | d->name = QStringLiteral("originUrl"); | 528 | d->name = QStringLiteral("originUrl"); | ||
517 | d->displayName = i18nc("@label the URL a file was originally downloaded from", "Downloaded From"); | 529 | d->displayName = i18nc("@label the URL a file was originally downloaded from", "Downloaded From"); | ||
518 | d->valueType = QVariant::Url; | 530 | d->valueType = QVariant::Url; | ||
519 | d->shouldBeIndexed = false; | 531 | d->shouldBeIndexed = false; | ||
520 | break; | 532 | break; | ||
Show All 25 Lines | |||||
546 | // NOTE: new properties must also be added to ::fromName() | 558 | // NOTE: new properties must also be added to ::fromName() | ||
547 | } | 559 | } | ||
548 | 560 | | |||
549 | if (d->valueType == QVariant::Int || d->valueType == QVariant::DateTime || | 561 | if (d->valueType == QVariant::Int || d->valueType == QVariant::DateTime || | ||
550 | d->valueType == QVariant::Double) | 562 | d->valueType == QVariant::Double) | ||
551 | { | 563 | { | ||
552 | d->shouldBeIndexed = false; | 564 | d->shouldBeIndexed = false; | ||
553 | } | 565 | } | ||
566 | | ||||
567 | if (d->formatAsString == nullptr) { | ||||
bruns: I think this would be better written as `d->formatAsString = &FormatStrings::toStringFunction;`… | |||||
568 | if (d->valueType == QVariant::StringList) { | ||||
569 | d->formatAsString = &FormatStrings::joinStringListFunction; | ||||
570 | } else { | ||||
571 | d->formatAsString = &FormatStrings::toStringFunction; | ||||
572 | } | ||||
573 | } | ||||
554 | } | 574 | } | ||
555 | 575 | | |||
556 | PropertyInfo::PropertyInfo(const PropertyInfo& pi) | 576 | PropertyInfo::PropertyInfo(const PropertyInfo& pi) | ||
557 | : d(new Private(*pi.d)) | 577 | : d(new Private(*pi.d)) | ||
558 | { | 578 | { | ||
559 | } | 579 | } | ||
560 | 580 | | |||
561 | PropertyInfo::~PropertyInfo() | 581 | PropertyInfo::~PropertyInfo() | ||
Show All 33 Lines | 614 | { | |||
595 | return d->valueType; | 615 | return d->valueType; | ||
596 | } | 616 | } | ||
597 | 617 | | |||
598 | bool PropertyInfo::shouldBeIndexed() const | 618 | bool PropertyInfo::shouldBeIndexed() const | ||
599 | { | 619 | { | ||
600 | return d->shouldBeIndexed; | 620 | return d->shouldBeIndexed; | ||
601 | } | 621 | } | ||
602 | 622 | | |||
623 | QString PropertyInfo::formatAsDisplayString(const QVariant &value) const | ||||
624 | { | ||||
625 | return (d->formatAsString)(value); | ||||
626 | } | ||||
627 | | ||||
603 | PropertyInfo PropertyInfo::fromName(const QString& name) | 628 | PropertyInfo PropertyInfo::fromName(const QString& name) | ||
604 | { | 629 | { | ||
605 | static QHash<QString, Property::Property> propertyHash = { | 630 | static QHash<QString, Property::Property> propertyHash = { | ||
606 | { QStringLiteral("bitrate"), Property::BitRate }, | 631 | { QStringLiteral("bitrate"), Property::BitRate }, | ||
607 | { QStringLiteral("channels"), Property::Channels }, | 632 | { QStringLiteral("channels"), Property::Channels }, | ||
608 | { QStringLiteral("duration"), Property::Duration }, | 633 | { QStringLiteral("duration"), Property::Duration }, | ||
609 | { QStringLiteral("genre"), Property::Genre }, | 634 | { QStringLiteral("genre"), Property::Genre }, | ||
610 | { QStringLiteral("samplerate"), Property::SampleRate }, | 635 | { QStringLiteral("samplerate"), Property::SampleRate }, | ||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |
I think this would be better written as d->formatAsString = &FormatStrings::toStringFunction; unconditionally on the top (like d->shouldBeIndexed = true), and d->formatAsString = &FormatStrings::joinStringListFunction; in the few matching case statements.