File indexing completed on 2022-09-27 16:29:12

0001 /**
0002  * SPDX-FileCopyrightText: (C) 2015 by Gleb Baryshev <gleb.baryshev@gmail.com>
0003  * SPDX-License-Identifier: GPL-2.0-or-later
0004  */
0005 #include "file_metadata.h"
0006 #include <KLocalizedString>
0007 
0008 using namespace KFileMetaData::Property;
0009 
0010 void MetaDataExtractionResult::add(Property property, const QVariant &value)
0011 {
0012     m_groups[property] = value;
0013 }
0014 
0015 QList<QPair<QString, QString>> MetaDataExtractionResult::preferredGroups()
0016 {
0017     // Text captions for some properties. Unspecified properties will get empty captions
0018     static const QMap<Property, QString> PROPERTY_TRANSLATIONS = {{Property::BitRate, i18n("Bit rate")},
0019                                                                   {Property::Channels, i18n("Channels")},
0020                                                                   {Property::Duration, i18n("Duration")},
0021                                                                   {Property::Genre, i18n("Genre")},
0022                                                                   {Property::SampleRate, i18n("Sample rate")},
0023                                                                   {Property::TrackNumber, i18n("Track number")},
0024                                                                   {Property::Comment, i18n("Comment")},
0025                                                                   {Property::Artist, i18n("Artist")},
0026                                                                   {Property::Album, i18n("Album")},
0027                                                                   {Property::Title, i18n("Title")},
0028                                                                   {Property::WordCount, i18n("Word count")},
0029                                                                   {Property::LineCount, i18n("Line count")},
0030                                                                   {Property::Copyright, i18n("Copyright")},
0031                                                                   {Property::CreationDate, i18n("Date")},
0032                                                                   {Property::FrameRate, i18n("Frame rate")}};
0033 
0034     static QList<Property> preferredItems;
0035     if (preferredItems.count() == 0) {
0036         // According to KDE 3 services/kfile_*.desktop
0037 
0038         // audio
0039         preferredItems << Property::Title << Property::Artist << Property::Album << Property::TrackNumber << Property::Genre << Property::BitRate << Property::Duration << Property::CreationDate << Property::Comment << Property::SampleRate
0040                        << Property::Channels << Property::Copyright;
0041         // video
0042         preferredItems /*<< Property::Duration*/ << Property::FrameRate;
0043         // text
0044         preferredItems << Property::LineCount << Property::WordCount;
0045     }
0046 
0047     QList<QPair<QString, QString>> result;
0048     if (m_groups.count() == 0)
0049         return result;
0050 
0051     KFileMetaData::PropertyMap groups = m_groups;
0052 
0053     for (int i = 0; i < preferredItems.count(); i++) {
0054         QVariant value = groups.take(preferredItems[i]);
0055         if (value.isValid())
0056             result.append({PROPERTY_TRANSLATIONS[preferredItems[i]], value.toString()});
0057     }
0058 
0059     // Remaining groups
0060     for (auto it = groups.begin(); it != groups.end(); it++) {
0061         result.append({PROPERTY_TRANSLATIONS[it.key()], it.value().toString()});
0062     }
0063 
0064     return result;
0065 }