KFileMetaData

typeinfo.cpp
1 /*
2  * <one line to give the library's name and an idea of what it does.>
3  * Copyright (C) 2014 Vishesh Handa <[email protected]>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  */
20 
21 #include "typeinfo.h"
22 
23 #include <KLocalizedString>
24 
25 using namespace KFileMetaData;
26 
27 class Q_DECL_HIDDEN TypeInfo::Private
28 {
29 public:
30  Type::Type type;
31  QString name;
32  QString displayName;
33 };
34 
35 TypeInfo::TypeInfo(Type::Type type)
36  : d(new Private)
37 {
38  d->type = type;
39 
40  switch (type) {
41  case Type::Empty:
42  d->name = QStringLiteral("empty");
43  d->displayName = QString();
44  break;
45 
46  case Type::Archive:
47  d->name = QStringLiteral("Archive");
48  d->displayName = i18nc("@label", "Archive");
49  break;
50 
51  case Type::Audio:
52  d->name = QStringLiteral("Audio");
53  d->displayName = i18nc("@label", "Audio");
54  break;
55 
56  case Type::Document:
57  d->name = QStringLiteral("Document");
58  d->displayName = i18nc("@label", "Document");
59  break;
60 
61  case Type::Image:
62  d->name = QStringLiteral("Image");
63  d->displayName = i18nc("@label", "Image");
64  break;
65 
66  case Type::Presentation:
67  d->name = QStringLiteral("Presentation");
68  d->displayName = i18nc("@label", "Presentation");
69  break;
70 
71  case Type::Spreadsheet:
72  d->name = QStringLiteral("Spreadsheet");
73  d->displayName = i18nc("@label", "Spreadsheet");
74  break;
75 
76  case Type::Text:
77  d->name = QStringLiteral("Text");
78  d->displayName = i18nc("@label", "Text");
79  break;
80 
81  case Type::Video:
82  d->name = QStringLiteral("Video");
83  d->displayName = i18nc("@label", "Video");
84  break;
85 
86  case Type::Folder:
87  d->name = QStringLiteral("Folder");
88  d->displayName = i18nc("@label", "Folder");
89  break;
90  }
91 }
92 
93 TypeInfo::TypeInfo(const TypeInfo& ti)
94  : d(new Private(*ti.d))
95 {
96 }
97 
98 TypeInfo::~TypeInfo()
99 {
100  delete d;
101 }
102 
103 TypeInfo& TypeInfo::operator=(const TypeInfo& rhs)
104 {
105  *d = *rhs.d;
106  return *this;
107 }
108 
109 bool TypeInfo::operator==(const TypeInfo& rhs)
110 {
111  return d->type == rhs.d->type && d->name == rhs.d->name && d->displayName == rhs.d->displayName;
112 }
113 
114 QString TypeInfo::displayName() const
115 {
116  return d->displayName;
117 }
118 
119 QString TypeInfo::name() const
120 {
121  return d->name;
122 }
123 
124 Type::Type TypeInfo::type() const
125 {
126  return d->type;
127 }
128 
129 TypeInfo TypeInfo::fromName(const QString& name)
130 {
131  for (int t = static_cast<int>(Type::FirstType); t <= static_cast<int>(Type::LastType); t++) {
132  TypeInfo ti(static_cast<Type::Type>(t));
133  if (ti.name().compare(name, Qt::CaseInsensitive) == 0) {
134  return ti;
135  }
136  }
137 
138  return TypeInfo(Type::Empty);
139 }
QString name(StandardShortcut id)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
Type type(const QSqlDatabase &db)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun May 31 2020 23:13:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.