File indexing completed on 2024-05-05 16:09:03

0001 /*
0002     SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #include "typeinfo.h"
0008 
0009 #include <KLocalizedString>
0010 
0011 using namespace KFileMetaData;
0012 
0013 class KFileMetaData::TypeInfoPrivate
0014 {
0015 public:
0016     Type::Type type;
0017     QString name;
0018     QString displayName;
0019 };
0020 
0021 TypeInfo::TypeInfo(Type::Type type)
0022     : d(new TypeInfoPrivate)
0023 {
0024     d->type = type;
0025 
0026     switch (type) {
0027     case Type::Empty:
0028         d->name = QStringLiteral("empty");
0029         d->displayName = QString();
0030         break;
0031 
0032     case Type::Archive:
0033         d->name = QStringLiteral("Archive");
0034         d->displayName = i18nc("@label", "Archive");
0035         break;
0036 
0037     case Type::Audio:
0038         d->name = QStringLiteral("Audio");
0039         d->displayName = i18nc("@label", "Audio");
0040         break;
0041 
0042     case Type::Document:
0043         d->name = QStringLiteral("Document");
0044         d->displayName = i18nc("@label", "Document");
0045         break;
0046 
0047     case Type::Image:
0048         d->name = QStringLiteral("Image");
0049         d->displayName = i18nc("@label", "Image");
0050         break;
0051 
0052     case Type::Presentation:
0053         d->name = QStringLiteral("Presentation");
0054         d->displayName = i18nc("@label", "Presentation");
0055         break;
0056 
0057     case Type::Spreadsheet:
0058         d->name = QStringLiteral("Spreadsheet");
0059         d->displayName = i18nc("@label", "Spreadsheet");
0060         break;
0061 
0062     case Type::Text:
0063         d->name = QStringLiteral("Text");
0064         d->displayName = i18nc("@label", "Text");
0065         break;
0066 
0067     case Type::Video:
0068         d->name = QStringLiteral("Video");
0069         d->displayName = i18nc("@label", "Video");
0070         break;
0071 
0072     case Type::Folder:
0073         d->name = QStringLiteral("Folder");
0074         d->displayName = i18nc("@label", "Folder");
0075         break;
0076     }
0077 }
0078 
0079 TypeInfo::TypeInfo(const TypeInfo& ti)
0080     : d(new TypeInfoPrivate(*ti.d))
0081 {
0082 }
0083 
0084 TypeInfo::~TypeInfo() = default;
0085 
0086 TypeInfo& TypeInfo::operator=(const TypeInfo& rhs)
0087 {
0088     *d = *rhs.d;
0089     return *this;
0090 }
0091 
0092 #if KFILEMETADATA_BUILD_DEPRECATED_SINCE(5, 91)
0093 bool TypeInfo::operator==(const TypeInfo& rhs)
0094 {
0095     return d->type == rhs.d->type && d->name == rhs.d->name && d->displayName == rhs.d->displayName;
0096 }
0097 #endif
0098 
0099 bool TypeInfo::operator==(const TypeInfo& rhs) const
0100 {
0101     return std::tie(d->type, d->name, d->displayName) == std::tie(rhs.d->type, rhs.d->name, rhs.d->displayName);
0102 }
0103 
0104 QString TypeInfo::displayName() const
0105 {
0106     return d->displayName;
0107 }
0108 
0109 QString TypeInfo::name() const
0110 {
0111     return d->name;
0112 }
0113 
0114 Type::Type TypeInfo::type() const
0115 {
0116     return d->type;
0117 }
0118 
0119 TypeInfo TypeInfo::fromName(const QString& name)
0120 {
0121     for (int t = static_cast<int>(Type::FirstType); t <= static_cast<int>(Type::LastType); t++) {
0122         TypeInfo ti(static_cast<Type::Type>(t));
0123         if (ti.name().compare(name, Qt::CaseInsensitive) == 0) {
0124             return ti;
0125         }
0126     }
0127 
0128     return TypeInfo(Type::Empty);
0129 }