Skip to content

Commit

Permalink
Modernize the "mimetype" feature
Browse files Browse the repository at this point in the history
Change-Id: I9b67c2cbc0891a38ece18d521c86fbc7344dce7a
Reviewed-by: Edward Welbourne <[email protected]>
Reviewed-by: Oswald Buddenhagen <[email protected]>
  • Loading branch information
liangqi committed Oct 12, 2018
1 parent 9c8ca26 commit 3eebadc
Show file tree
Hide file tree
Showing 29 changed files with 47 additions and 67 deletions.
4 changes: 0 additions & 4 deletions src/corelib/mimetypes/qmimedatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@

#include <qplatformdefs.h> // always first

#ifndef QT_NO_MIMETYPE

#include "qmimedatabase.h"
#include "qmimedatabase_p.h"

Expand Down Expand Up @@ -803,5 +801,3 @@ QList<QMimeType> QMimeDatabase::allMimeTypes() const
*/

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
3 changes: 1 addition & 2 deletions src/corelib/mimetypes/qmimedatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

#include <QtCore/qmimetype.h>

#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);

#include <QtCore/qstringlist.h>

Expand Down Expand Up @@ -92,5 +92,4 @@ class Q_CORE_EXPORT QMimeDatabase

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
#endif // QMIMEDATABASE_H
3 changes: 1 addition & 2 deletions src/corelib/mimetypes/qmimedatabase_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

#include "qmimetype.h"

#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);

#include "qmimetype_p.h"
#include "qmimeglobpattern_p.h"
Expand Down Expand Up @@ -116,5 +116,4 @@ class QMimeDatabasePrivate

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
#endif // QMIMEDATABASE_P_H
4 changes: 0 additions & 4 deletions src/corelib/mimetypes/qmimeglobpattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

#include "qmimeglobpattern_p.h"

#ifndef QT_NO_MIMETYPE

#include <QRegExp>
#include <QStringList>
#include <QDebug>
Expand Down Expand Up @@ -239,5 +237,3 @@ void QMimeAllGlobPatterns::clear()
}

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
3 changes: 1 addition & 2 deletions src/corelib/mimetypes/qmimeglobpattern_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

#include <QtCore/private/qglobal_p.h>

#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);

#include <QtCore/qstringlist.h>
#include <QtCore/qhash.h>
Expand Down Expand Up @@ -162,5 +162,4 @@ class QMimeAllGlobPatterns

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
#endif // QMIMEGLOBPATTERN_P_H
4 changes: 0 additions & 4 deletions src/corelib/mimetypes/qmimemagicrule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

#include "qmimemagicrule_p.h"

#ifndef QT_NO_MIMETYPE

#include "qmimetypeparser_p.h"
#include <QtCore/QList>
#include <QtCore/QDebug>
Expand Down Expand Up @@ -364,5 +362,3 @@ bool QMimeMagicRule::matches(const QByteArray &data) const
}

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
3 changes: 1 addition & 2 deletions src/corelib/mimetypes/qmimemagicrule_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

#include <QtCore/private/qglobal_p.h>

#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);

#include <QtCore/qbytearray.h>
#include <QtCore/qscopedpointer.h>
Expand Down Expand Up @@ -125,5 +125,4 @@ Q_DECLARE_SHARED(QMimeMagicRule)

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
#endif // QMIMEMAGICRULE_H
3 changes: 0 additions & 3 deletions src/corelib/mimetypes/qmimemagicrulematcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@

#include "qmimemagicrulematcher_p.h"

#ifndef QT_NO_MIMETYPE

#include "qmimetype_p.h"

QT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -106,4 +104,3 @@ unsigned QMimeMagicRuleMatcher::priority() const
}

QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
3 changes: 1 addition & 2 deletions src/corelib/mimetypes/qmimemagicrulematcher_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

#include "qmimemagicrule_p.h"

#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);

#include <QtCore/qbytearray.h>
#include <QtCore/qlist.h>
Expand Down Expand Up @@ -94,5 +94,4 @@ Q_DECLARE_SHARED(QMimeMagicRuleMatcher)

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
#endif // QMIMEMAGICRULEMATCHER_P_H
4 changes: 0 additions & 4 deletions src/corelib/mimetypes/qmimeprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@

#include "qmimeprovider_p.h"

#ifndef QT_NO_MIMETYPE

#include "qmimetypeparser_p.h"
#include <qstandardpaths.h>
#include "qmimemagicrulematcher_p.h"
Expand Down Expand Up @@ -757,5 +755,3 @@ void QMimeXMLProvider::addMagicMatcher(const QMimeMagicRuleMatcher &matcher)
}

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
3 changes: 1 addition & 2 deletions src/corelib/mimetypes/qmimeprovider_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

#include "qmimedatabase_p.h"

#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);

#include "qmimeglobpattern_p.h"
#include <QtCore/qdatetime.h>
Expand Down Expand Up @@ -173,5 +173,4 @@ class QMimeXMLProvider : public QMimeProviderBase

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
#endif // QMIMEPROVIDER_P_H
4 changes: 0 additions & 4 deletions src/corelib/mimetypes/qmimetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@

#include "qmimetype.h"

#ifndef QT_NO_MIMETYPE

#include "qmimetype_p.h"
#include "qmimedatabase_p.h"
#include "qmimeprovider_p.h"
Expand Down Expand Up @@ -526,5 +524,3 @@ QDebug operator<<(QDebug debug, const QMimeType &mime)
#endif

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
3 changes: 1 addition & 2 deletions src/corelib/mimetypes/qmimetype.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

#include <QtCore/qglobal.h>

#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);

#include <QtCore/qobjectdefs.h>
#include <QtCore/qshareddata.h>
Expand Down Expand Up @@ -135,5 +135,4 @@ Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QMimeType &mime);

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
#endif // QMIMETYPE_H
3 changes: 1 addition & 2 deletions src/corelib/mimetypes/qmimetype_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#include <QtCore/private/qglobal_p.h>
#include "qmimetype.h"

#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);

#include <QtCore/qhash.h>
#include <QtCore/qstringlist.h>
Expand Down Expand Up @@ -124,5 +124,4 @@ QT_END_NAMESPACE
QT_END_NAMESPACE
#endif

#endif // QT_NO_MIMETYPE
#endif // QMIMETYPE_P_H
4 changes: 0 additions & 4 deletions src/corelib/mimetypes/qmimetypeparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@

#include "qmimetypeparser_p.h"

#ifndef QT_NO_MIMETYPE

#include "qmimetype_p.h"
#include "qmimemagicrulematcher_p.h"

Expand Down Expand Up @@ -341,5 +339,3 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
}

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
3 changes: 1 addition & 2 deletions src/corelib/mimetypes/qmimetypeparser_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

#include "qmimedatabase_p.h"

#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);

#include "qmimeprovider_p.h"

Expand Down Expand Up @@ -129,5 +129,4 @@ class QMimeTypeParser : public QMimeTypeParserBase

QT_END_NAMESPACE

#endif // QT_NO_MIMETYPE
#endif // MIMETYPEPARSER_P_H
6 changes: 4 additions & 2 deletions src/gui/image/qicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
#include "private/qiconloader_p.h"
#include "qpainter.h"
#include "qfileinfo.h"
#if QT_CONFIG(mimetype)
#include <qmimedatabase.h>
#include <qmimetype.h>
#endif
#include "qpixmapcache.h"
#include "qvariant.h"
#include "qcache.h"
Expand Down Expand Up @@ -1079,10 +1081,10 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State

QFileInfo info(fileName);
QIconEngine *engine = iconEngineFromSuffix(fileName, info.suffix());
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
if (!engine)
engine = iconEngineFromSuffix(fileName, QMimeDatabase().mimeTypeForFile(info).preferredSuffix());
#endif // !QT_NO_MIMETYPE
#endif // mimetype
d = new QIconPrivate(engine ? engine : new QPixmapIconEngine);
}

Expand Down
2 changes: 2 additions & 0 deletions src/platformsupport/themes/genericunix/qgenericunixthemes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
#include <QtCore/QFile>
#include <QtCore/QDebug>
#include <QtCore/QHash>
#if QT_CONFIG(mimetype)
#include <QtCore/QMimeDatabase>
#endif
#include <QtCore/QLoggingCategory>
#include <QtCore/QSettings>
#include <QtCore/QVariant>
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/platforms/cocoa/qcocoaprintdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ class QCocoaPrintDevice : public QPlatformPrintDevice
void loadOutputBins() const override;
void loadDuplexModes() const override;
void loadColorModes() const override;
#if QT_CONFIG(mimetype)
void loadMimeTypes() const override;
#endif

private:
QPageSize createPageSize(const PMPaper &paper) const;
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/platforms/cocoa/qcocoaprintdevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@

#include "qcocoaprintdevice.h"

#if QT_CONFIG(mimetype)
#include <QtCore/qmimedatabase.h>
#endif
#include <qdebug.h>

QT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -417,6 +419,7 @@
return QPrint::GrayScale;
}

#if QT_CONFIG(mimetype)
void QCocoaPrintDevice::loadMimeTypes() const
{
// TODO Check how settings affect returned list
Expand All @@ -438,6 +441,7 @@
}
m_haveMimeTypes = true;
}
#endif // mimetype

bool QCocoaPrintDevice::openPpdFile()
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/platformthemes/platformthemes.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = subdirs
QT_FOR_CONFIG += widgets-private

qtConfig(dbus):qtConfig(regularexpression): SUBDIRS += flatpak
qtConfig(dbus):qtConfig(regularexpression):qtConfig(mimetype): SUBDIRS += flatpak

qtHaveModule(widgets):qtConfig(gtk3): SUBDIRS += gtk3
2 changes: 1 addition & 1 deletion src/plugins/printsupport/cups/qppdprintdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ bool QPpdPrintDevice::isFeatureAvailable(QPrintDevice::PrintDevicePropertyKey ke
return QPlatformPrintDevice::isFeatureAvailable(key, params);
}

#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
void QPpdPrintDevice::loadMimeTypes() const
{
// TODO No CUPS api? Need to manually load CUPS mime.types file?
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/printsupport/cups/qppdprintdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class QPpdPrintDevice : public QPlatformPrintDevice
void loadOutputBins() const override;
void loadDuplexModes() const override;
void loadColorModes() const override;
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
void loadMimeTypes() const override;
#endif

Expand Down
10 changes: 6 additions & 4 deletions src/printsupport/kernel/qplatformprintdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ QPlatformPrintDevice::QPlatformPrintDevice()
m_haveOutputBins(false),
m_haveDuplexModes(false),
m_haveColorModes(false)
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
, m_haveMimeTypes(false)
#endif
{
Expand All @@ -79,7 +79,7 @@ QPlatformPrintDevice::QPlatformPrintDevice(const QString &id)
m_haveOutputBins(false),
m_haveDuplexModes(false),
m_haveColorModes(false)
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
, m_haveMimeTypes(false)
#endif
{
Expand Down Expand Up @@ -376,10 +376,11 @@ QVector<QPrint::ColorMode> QPlatformPrintDevice::supportedColorModes() const
return m_colorModes;
}

#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
void QPlatformPrintDevice::loadMimeTypes() const
{
}
#endif // mimetype

QVariant QPlatformPrintDevice::property(QPrintDevice::PrintDevicePropertyKey key) const
{
Expand All @@ -404,13 +405,14 @@ bool QPlatformPrintDevice::isFeatureAvailable(QPrintDevice::PrintDevicePropertyK
return false;
}

#if QT_CONFIG(mimetype)
QList<QMimeType> QPlatformPrintDevice::supportedMimeTypes() const
{
if (!m_haveMimeTypes)
loadMimeTypes();
return m_mimeTypes;
}
#endif // QT_NO_MIMETYPE
#endif // mimetype

QPageSize QPlatformPrintDevice::createPageSize(const QString &key, const QSize &size, const QString &localizedName)
{
Expand Down
Loading

0 comments on commit 3eebadc

Please sign in to comment.