diff --git a/src/typeinfo.cpp b/src/typeinfo.cpp index 85ef3e8..80002aa 100644 --- a/src/typeinfo.cpp +++ b/src/typeinfo.cpp @@ -1,122 +1,138 @@ /* * * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "typeinfo.h" #include using namespace KFileMetaData; class TypeInfo::Private { public: Type::Type type; QString name; QString displayName; }; TypeInfo::TypeInfo(Type::Type type) : d(new Private) { d->type = type; switch (type) { + case Type::Empty: + d->name = QStringLiteral("empty"); + d->displayName = QString(); + break; + case Type::Archive: d->name = QStringLiteral("Archive"); d->displayName = i18nc("@label", "Archive"); break; case Type::Audio: d->name = QStringLiteral("Audio"); d->displayName = i18nc("@label", "Audio"); break; case Type::Document: d->name = QStringLiteral("Document"); d->displayName = i18nc("@label", "Document"); break; case Type::Image: d->name = QStringLiteral("Image"); d->displayName = i18nc("@label", "Image"); break; case Type::Presentation: d->name = QStringLiteral("Presentation"); d->displayName = i18nc("@label", "Presentation"); break; case Type::Spreadsheet: d->name = QStringLiteral("Spreadsheet"); d->displayName = i18nc("@label", "Spreadsheet"); break; case Type::Text: d->name = QStringLiteral("Text"); d->displayName = i18nc("@label", "Text"); break; case Type::Video: d->name = QStringLiteral("Video"); d->displayName = i18nc("@label", "Video"); break; case Type::Folder: d->name = QStringLiteral("Folder"); d->displayName = i18nc("@label", "Folder"); break; } } TypeInfo::TypeInfo(const TypeInfo& ti) : d(new Private(*ti.d)) { } TypeInfo::~TypeInfo() { delete d; } TypeInfo& TypeInfo::operator=(const TypeInfo& rhs) { *d = *rhs.d; return *this; } bool TypeInfo::operator==(const TypeInfo& rhs) { return d->type == rhs.d->type && d->name == rhs.d->name && d->displayName == rhs.d->displayName; } QString TypeInfo::displayName() const { return d->displayName; } QString TypeInfo::name() const { return d->name; } Type::Type TypeInfo::type() const { return d->type; } +TypeInfo TypeInfo::fromName(const QString& name) +{ + for (int t = static_cast(Type::FirstType); t != static_cast(Type::LastType); t++) { + TypeInfo ti(static_cast(t)); + if (ti.name().compare(name, Qt::CaseInsensitive) == 0) { + return ti; + } + } + + return TypeInfo(Type::Empty); +} diff --git a/src/typeinfo.h b/src/typeinfo.h index 2b23a26..1142974 100644 --- a/src/typeinfo.h +++ b/src/typeinfo.h @@ -1,61 +1,67 @@ /* * * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef KFILEMETADATA_TYPEINFO_H #define KFILEMETADATA_TYPEINFO_H #include "types.h" #include "kfilemetadata_export.h" #include namespace KFileMetaData { class KFILEMETADATA_EXPORT TypeInfo { public: TypeInfo(Type::Type type); TypeInfo(const TypeInfo& ti); ~TypeInfo(); TypeInfo& operator=(const TypeInfo& rhs); bool operator==(const TypeInfo& rhs); /** * The type identifier */ Type::Type type() const; /** * An internal unique name for the type */ QString name() const; /** * A user visible translated name for this type */ QString displayName() const; + /** + * Construct a TypeInfo from the internal type name. + * The internal type name is case insensitive + */ + static TypeInfo fromName(const QString& name); + private: class Private; Private* d; }; } #endif // KFILEMETADATA_TYPEINFO_H diff --git a/src/types.h b/src/types.h index 88f7cc4..c1a3a11 100644 --- a/src/types.h +++ b/src/types.h @@ -1,93 +1,94 @@ /* * This file is part of KFileMetaData * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef KFILEMETADATA_TYPES #define KFILEMETADATA_TYPES namespace KFileMetaData { namespace Type { /** * A Type represents a way to represent a way to group files based on * a higher level view, which the user generally expects. * * Every extractor provides a list of types applicable for each file. */ enum Type { FirstType = 0, + Empty = 0, /** * Any file which contains a compressed collection of other files * eg - tar, zip, rar, gz */ - Archive = 0, + Archive, /** * Used to mark any file which just contains audio. Do not use this * type if the file also contains Video */ Audio, /** * Any file which contains Video. It may also contain Audio */ Video, /** * Any Image file. This includes both raster and vector formats. */ Image, /** * Any file which counts as a document. Documents are generally * files which contain rich text, formatting and maybe images */ Document, /** * A SpreadSheet file. This is a specialization of the Document type * Any file which has this type should also have the Document type */ Spreadsheet, /** * A Presentation file. This is a specialization of the Document type. * Any file which has this type should also have the Document type */ Presentation, /** * Any file which just contains plain text data counts * as a Text file */ Text, /** * A directory or folder */ Folder, LastType = Folder }; } } #endif