KDeclarative

mimedatabase.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "mimedatabase.h"
8 #include <QJsonObject>
9 #include <QDebug>
10 
11 static QJsonObject mimetypeToJsonObject(const QMimeType& type)
12 {
13  if (!type.isValid()) {
14  qWarning() << "trying to export an invalid type";
15  return QJsonObject();
16  }
17  QJsonObject ret;
18  ret[QStringLiteral("name")] = type.name();
19  ret[QStringLiteral("iconName")] = type.iconName();
20  ret[QStringLiteral("comment")] = type.comment();
21  return ret;
22 }
23 
24 MimeDatabase::MimeDatabase(QObject* parent)
25  : QObject(parent)
26 {
27 }
28 
29 QJsonObject MimeDatabase::mimeTypeForUrl(const QUrl& url) const
30 {
31  return mimetypeToJsonObject(m_db.mimeTypeForUrl(url));
32 }
33 
34 QJsonObject MimeDatabase::mimeTypeForName(const QString& name) const
35 {
36  QMimeType type = m_db.mimeTypeForName(name);
37  if (!type.isValid()) {
38  qWarning() << "wrong mime name" << name;
39  return QJsonObject();
40  }
41  return mimetypeToJsonObject(type);
42 }
bool isValid() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 25 2021 22:44:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.