File indexing completed on 2024-05-19 15:09:24
0001 /* 0002 SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "mimedatabase.h" 0008 #include <QDebug> 0009 #include <QJsonObject> 0010 0011 static QJsonObject mimetypeToJsonObject(const QMimeType &type) 0012 { 0013 if (!type.isValid()) { 0014 qWarning() << "trying to export an invalid type"; 0015 return QJsonObject(); 0016 } 0017 QJsonObject ret; 0018 ret[QStringLiteral("name")] = type.name(); 0019 ret[QStringLiteral("iconName")] = type.iconName(); 0020 ret[QStringLiteral("comment")] = type.comment(); 0021 return ret; 0022 } 0023 0024 MimeDatabase::MimeDatabase(QObject *parent) 0025 : QObject(parent) 0026 { 0027 } 0028 0029 QJsonObject MimeDatabase::mimeTypeForUrl(const QUrl &url) const 0030 { 0031 return mimetypeToJsonObject(m_db.mimeTypeForUrl(url)); 0032 } 0033 0034 QJsonObject MimeDatabase::mimeTypeForName(const QString &name) const 0035 { 0036 QMimeType type = m_db.mimeTypeForName(name); 0037 if (!type.isValid()) { 0038 qWarning() << "wrong mime name" << name; 0039 return QJsonObject(); 0040 } 0041 return mimetypeToJsonObject(type); 0042 } 0043 0044 #include "moc_mimedatabase.cpp"