Changeset View
Standalone View
src/formatstrings.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 Alexander Stippich <a.stippich@gmx.net> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) any later version. | ||||
8 | * | ||||
9 | * This library is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | * Lesser General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Lesser General Public | ||||
15 | * License along with this library; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
17 | * | ||||
18 | */ | ||||
19 | | ||||
20 | #include "formatstrings.h" | ||||
21 | | ||||
22 | #include <QDateTime> | ||||
23 | #include <KLocalizedString> | ||||
24 | | ||||
25 | using namespace KFileMetaData; | ||||
26 | | ||||
27 | const KFormat FormatStrings::form; | ||||
28 | | ||||
bruns: I don't think using a static default constructed KFormat is a good idea ... | |||||
29 | QString FormatStrings::toStringFunction(const QVariant& value) | ||||
30 | { | ||||
31 | return value.toString(); | ||||
32 | } | ||||
33 | | ||||
34 | QString FormatStrings::joinStringListFunction(const QVariant& value) | ||||
35 | { | ||||
36 | return value.toStringList().join(i18nc("Separation between multiple entries", ", ")); | ||||
37 | } | ||||
38 | | ||||
39 | QString FormatStrings::formatDate(const QVariant& value) | ||||
40 | { | ||||
41 | | ||||
42 | QDateTime dt; | ||||
43 | if (value.type() == QVariant::DateTime) { | ||||
44 | dt = value.toDateTime(); | ||||
45 | } else { | ||||
46 | dt = QDateTime::fromString(value.toString(), Qt::ISODate); | ||||
47 | } | ||||
48 | if (dt.isValid()) { | ||||
49 | QTime time = dt.time(); | ||||
50 | if (!time.hour() && !time.minute() && !time.second()){ | ||||
51 | return FormatStrings::form.formatRelativeDate(dt.date(), QLocale::LongFormat); | ||||
bruns: Why is midnight an invalid time? | |||||
Same with the previous discussing around the orientation values, I simply copied the code. My plan was to improve it later on, but that did not plan out as expected :) astippich: Same with the previous discussing around the orientation values, I simply copied the code. My… | |||||
52 | } else { | ||||
53 | return FormatStrings::form.formatRelativeDateTime(dt, QLocale::LongFormat); | ||||
54 | } | ||||
55 | } | ||||
56 | return QString(); | ||||
57 | } | ||||
58 | | ||||
59 | QString FormatStrings::formatDuration(const QVariant& value) | ||||
60 | { | ||||
61 | return FormatStrings::form.formatDuration(value.toInt() * 1000); | ||||
62 | } | ||||
63 | | ||||
64 | QString FormatStrings::formatBitRate(const QVariant& value) | ||||
65 | { | ||||
66 | return i18nc("@label bitrate (per second)", "%1/s", FormatStrings::form.formatByteSize(value.toInt(), 0, KFormat::MetricBinaryDialect)); | ||||
67 | } | ||||
68 | | ||||
69 | QString FormatStrings::formatSampleRate(const QVariant& value) | ||||
70 | { | ||||
71 | return i18nc("@label samplerate in kilohertz", "%1 kHz", QLocale().toString(value.toDouble() / 1000)); | ||||
72 | } | ||||
73 | | ||||
74 | QString FormatStrings::formatOrientationValue(const QVariant& value) | ||||
75 | { | ||||
76 | QString string; | ||||
77 | switch (value.toInt()) { | ||||
78 | case 1: string = i18nc("@item:intable Image orientation", "Unchanged"); break; | ||||
79 | case 2: string = i18nc("@item:intable Image orientation", "Horizontally flipped"); break; | ||||
80 | case 3: string = i18nc("@item:intable image orientation", "180° rotated"); break; | ||||
81 | case 4: string = i18nc("@item:intable image orientation", "Vertically flipped"); break; | ||||
bruns: for 180°, CCW is irrelevant. | |||||
astippich: That was pretty stupid :) | |||||
82 | case 5: string = i18nc("@item:intable image orientation", "Transposed"); break; | ||||
Thats somewhat ambigous - flipped along the vertical axis, or top/bottom flipped? bruns: Thats somewhat ambigous - flipped along the vertical axis, or top/bottom flipped? | |||||
Actually I don't know, I just copied the code from Dolphin into here. astippich: Actually I don't know, I just copied the code from Dolphin into here.
Seems to be a common term… | |||||
83 | case 6: string = i18nc("@item:intable image orientation", "90° rotated"); break; | ||||
"Transposed" and "Transversed" are very technical terms, and it's hard to understand what they mean in this context. I actually have no idea myself! Could we consider replacing these terms with plainer language? ngraham: "Transposed" and "Transversed" are very technical terms, and it's hard to understand what they… | |||||
Thats mirroring/flipping along the diagonals. You get the same effect when you mirror vertically and rotate +- 90 degrees. I don't think there is a less technical term. bruns: Thats mirroring/flipping along the diagonals. You get the same effect when you mirror… | |||||
84 | case 7: string = i18nc("@item:intable image orientation", "Transversed"); break; | ||||
bruns: Clockwise or CCW? | |||||
astippich: CCW, see https://docs.microsoft.com/en-us/uwp/api/windows.storage.fileproperties. | |||||
Of course I can look this up. But this information is not available when the user looks at the string. Probably we should ask what is the target audience here? The average user only wants the image to be displayed correctly, i.e. apply the transform and be done with it. This IMHO also implies never showing this value by default. For power users, it may be better to also show the numerical value, so they can look up whats meant. Otherwise, it is not only necessary to mention CW or CCW, but also if this is the transform which has been applied to the image, or the inverse transform required to show the image correctly. bruns: Of course I can look this up. But this information is not available when the user looks at the… | |||||
astippich: How about using the descriptions from D15503, which are also consistent with digiKam and… | |||||
IMHO thats not better at all - what does "top, left" refer to? And whats the difference to "left, top"? Every orientation save "normal" and "rotated 180" is ambiguous without further description. It is of no interest for most users, even serious photographers, as it is a technical implementation detail. Creation times, aperture, exposure time ... are useful for users. So we should hide it by default, and for the 0.1% interested in it we can give a description they can lookup themselves, e.g. "Rotated 90° CCW (6)" bruns: IMHO thats not better at all - what does "top, left" refer to? And whats the difference to… | |||||
Phew, I didn't anticipate that these strings are that controversial since I'm basically copying existing behavior. I'm fine with adding "CCW" (I think the number should not be shown, it can still be queried separately after all) if that is sufficient for you. Hiding this information is not the responsibility of KFileMetaData. If we need more fundamental discussion, I'd like to defer that to another revision, since this is currently a drop-in behavior for Dolphin and Baloo-Widgets and copies the status quo. I'd like to land this revision as a starting point to get the infrastructure done and improve upon afterwards. There are many more properties that need special formatting, especially for exif data. astippich: Phew, I didn't anticipate that these strings are that controversial since I'm basically copying… | |||||
85 | case 8: string = i18nc("@item:intable image orientation", "270° rotated"); break; | ||||
86 | default: | ||||
87 | break; | ||||
88 | } | ||||
89 | return string; | ||||
90 | } | ||||
91 | |
I don't think using a static default constructed KFormat is a good idea ...