KFileMetaData

typeinfo.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Vishesh Handa <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6 
7 #include "typeinfo.h"
8 
9 #include <KLocalizedString>
10 
11 using namespace KFileMetaData;
12 
13 class KFileMetaData::TypeInfoPrivate
14 {
15 public:
16  Type::Type type;
17  QString name;
19 };
20 
21 TypeInfo::TypeInfo(Type::Type type)
22  : d(new TypeInfoPrivate)
23 {
24  d->type = type;
25 
26  switch (type) {
27  case Type::Empty:
28  d->name = QStringLiteral("empty");
29  d->displayName = QString();
30  break;
31 
32  case Type::Archive:
33  d->name = QStringLiteral("Archive");
34  d->displayName = i18nc("@label", "Archive");
35  break;
36 
37  case Type::Audio:
38  d->name = QStringLiteral("Audio");
39  d->displayName = i18nc("@label", "Audio");
40  break;
41 
42  case Type::Document:
43  d->name = QStringLiteral("Document");
44  d->displayName = i18nc("@label", "Document");
45  break;
46 
47  case Type::Image:
48  d->name = QStringLiteral("Image");
49  d->displayName = i18nc("@label", "Image");
50  break;
51 
52  case Type::Presentation:
53  d->name = QStringLiteral("Presentation");
54  d->displayName = i18nc("@label", "Presentation");
55  break;
56 
57  case Type::Spreadsheet:
58  d->name = QStringLiteral("Spreadsheet");
59  d->displayName = i18nc("@label", "Spreadsheet");
60  break;
61 
62  case Type::Text:
63  d->name = QStringLiteral("Text");
64  d->displayName = i18nc("@label", "Text");
65  break;
66 
67  case Type::Video:
68  d->name = QStringLiteral("Video");
69  d->displayName = i18nc("@label", "Video");
70  break;
71 
72  case Type::Folder:
73  d->name = QStringLiteral("Folder");
74  d->displayName = i18nc("@label", "Folder");
75  break;
76  }
77 }
78 
79 TypeInfo::TypeInfo(const TypeInfo& ti)
80  : d(new TypeInfoPrivate(*ti.d))
81 {
82 }
83 
84 TypeInfo::~TypeInfo() = default;
85 
86 TypeInfo& TypeInfo::operator=(const TypeInfo& rhs)
87 {
88  *d = *rhs.d;
89  return *this;
90 }
91 
92 #if KFILEMETADATA_BUILD_DEPRECATED_SINCE(5, 91)
93 bool TypeInfo::operator==(const TypeInfo& rhs)
94 {
95  return d->type == rhs.d->type && d->name == rhs.d->name && d->displayName == rhs.d->displayName;
96 }
97 #endif
98 
99 bool TypeInfo::operator==(const TypeInfo& rhs) const
100 {
101  return std::tie(d->type, d->name, d->displayName) == std::tie(rhs.d->type, rhs.d->name, rhs.d->displayName);
102 }
103 
104 QString TypeInfo::displayName() const
105 {
106  return d->displayName;
107 }
108 
109 QString TypeInfo::name() const
110 {
111  return d->name;
112 }
113 
114 Type::Type TypeInfo::type() const
115 {
116  return d->type;
117 }
118 
119 TypeInfo TypeInfo::fromName(const QString& name)
120 {
121  for (int t = static_cast<int>(Type::FirstType); t <= static_cast<int>(Type::LastType); t++) {
122  TypeInfo ti(static_cast<Type::Type>(t));
123  if (ti.name().compare(name, Qt::CaseInsensitive) == 0) {
124  return ti;
125  }
126  }
127 
128  return TypeInfo(Type::Empty);
129 }
CaseInsensitive
Type type(const QSqlDatabase &db)
AKONADI_CALENDAR_EXPORT QString displayName(Akonadi::ETMCalendar *calendar, const Akonadi::Collection &collection)
const char * name(StandardAction id)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri May 27 2022 03:47:54 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.