Modernize the "mimetype" feature

Change-Id: I9b67c2cbc0891a38ece18d521c86fbc7344dce7a
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
This commit is contained in:
Liang Qi 2018-09-28 11:40:10 +02:00
parent 9c8ca26a48
commit 3eebadc173
29 changed files with 47 additions and 67 deletions

View File

@ -40,8 +40,6 @@
#include <qplatformdefs.h> // always first
#ifndef QT_NO_MIMETYPE
#include "qmimedatabase.h"
#include "qmimedatabase_p.h"
@ -803,5 +801,3 @@ QList<QMimeType> QMimeDatabase::allMimeTypes() const
*/
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -43,7 +43,7 @@
#include <QtCore/qmimetype.h>
#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);
#include <QtCore/qstringlist.h>
@ -92,5 +92,4 @@ private:
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMEDATABASE_H

View File

@ -54,7 +54,7 @@
#include "qmimetype.h"
#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);
#include "qmimetype_p.h"
#include "qmimeglobpattern_p.h"
@ -116,5 +116,4 @@ public:
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMEDATABASE_P_H

View File

@ -39,8 +39,6 @@
#include "qmimeglobpattern_p.h"
#ifndef QT_NO_MIMETYPE
#include <QRegExp>
#include <QStringList>
#include <QDebug>
@ -239,5 +237,3 @@ void QMimeAllGlobPatterns::clear()
}
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -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>
@ -162,5 +162,4 @@ public:
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMEGLOBPATTERN_P_H

View File

@ -42,8 +42,6 @@
#include "qmimemagicrule_p.h"
#ifndef QT_NO_MIMETYPE
#include "qmimetypeparser_p.h"
#include <QtCore/QList>
#include <QtCore/QDebug>
@ -364,5 +362,3 @@ bool QMimeMagicRule::matches(const QByteArray &data) const
}
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -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>
@ -125,5 +125,4 @@ Q_DECLARE_SHARED(QMimeMagicRule)
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMEMAGICRULE_H

View File

@ -41,8 +41,6 @@
#include "qmimemagicrulematcher_p.h"
#ifndef QT_NO_MIMETYPE
#include "qmimetype_p.h"
QT_BEGIN_NAMESPACE
@ -106,4 +104,3 @@ unsigned QMimeMagicRuleMatcher::priority() const
}
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -53,7 +53,7 @@
#include "qmimemagicrule_p.h"
#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);
#include <QtCore/qbytearray.h>
#include <QtCore/qlist.h>
@ -94,5 +94,4 @@ Q_DECLARE_SHARED(QMimeMagicRuleMatcher)
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMEMAGICRULEMATCHER_P_H

View File

@ -40,8 +40,6 @@
#include "qmimeprovider_p.h"
#ifndef QT_NO_MIMETYPE
#include "qmimetypeparser_p.h"
#include <qstandardpaths.h>
#include "qmimemagicrulematcher_p.h"
@ -757,5 +755,3 @@ void QMimeXMLProvider::addMagicMatcher(const QMimeMagicRuleMatcher &matcher)
}
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -54,7 +54,7 @@
#include "qmimedatabase_p.h"
#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);
#include "qmimeglobpattern_p.h"
#include <QtCore/qdatetime.h>
@ -173,5 +173,4 @@ private:
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMEPROVIDER_P_H

View File

@ -40,8 +40,6 @@
#include "qmimetype.h"
#ifndef QT_NO_MIMETYPE
#include "qmimetype_p.h"
#include "qmimedatabase_p.h"
#include "qmimeprovider_p.h"
@ -526,5 +524,3 @@ QDebug operator<<(QDebug debug, const QMimeType &mime)
#endif
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -43,7 +43,7 @@
#include <QtCore/qglobal.h>
#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);
#include <QtCore/qobjectdefs.h>
#include <QtCore/qshareddata.h>
@ -135,5 +135,4 @@ Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QMimeType &mime);
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMETYPE_H

View File

@ -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>
@ -124,5 +124,4 @@ QT_END_NAMESPACE
QT_END_NAMESPACE
#endif
#endif // QT_NO_MIMETYPE
#endif // QMIMETYPE_P_H

View File

@ -41,8 +41,6 @@
#include "qmimetypeparser_p.h"
#ifndef QT_NO_MIMETYPE
#include "qmimetype_p.h"
#include "qmimemagicrulematcher_p.h"
@ -341,5 +339,3 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
}
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -54,7 +54,7 @@
#include "qmimedatabase_p.h"
#ifndef QT_NO_MIMETYPE
QT_REQUIRE_CONFIG(mimetype);
#include "qmimeprovider_p.h"
@ -129,5 +129,4 @@ private:
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // MIMETYPEPARSER_P_H

View File

@ -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"
@ -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);
}

View File

@ -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>

View File

@ -98,7 +98,9 @@ protected:
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;

View File

@ -39,7 +39,9 @@
#include "qcocoaprintdevice.h"
#if QT_CONFIG(mimetype)
#include <QtCore/qmimedatabase.h>
#endif
#include <qdebug.h>
QT_BEGIN_NAMESPACE
@ -417,6 +419,7 @@ QPrint::ColorMode QCocoaPrintDevice::defaultColorMode() const
return QPrint::GrayScale;
}
#if QT_CONFIG(mimetype)
void QCocoaPrintDevice::loadMimeTypes() const
{
// TODO Check how settings affect returned list
@ -438,6 +441,7 @@ void QCocoaPrintDevice::loadMimeTypes() const
}
m_haveMimeTypes = true;
}
#endif // mimetype
bool QCocoaPrintDevice::openPpdFile()
{

View File

@ -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

View File

@ -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?

View File

@ -100,7 +100,7 @@ protected:
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

View File

@ -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
{
@ -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
{
@ -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
{
@ -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)
{

View File

@ -57,7 +57,9 @@
#include <QtCore/qvariant.h>
#include <QtCore/qvector.h>
#if QT_CONFIG(mimetype)
#include <QtCore/qmimetype.h>
#endif
#include <QtGui/qpagelayout.h>
@ -125,7 +127,7 @@ public:
virtual bool setProperty(QPrintDevice::PrintDevicePropertyKey key, const QVariant &value);
virtual bool isFeatureAvailable(QPrintDevice::PrintDevicePropertyKey key, const QVariant &params) const;
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
virtual QList<QMimeType> supportedMimeTypes() const;
#endif
@ -139,7 +141,7 @@ protected:
virtual void loadOutputBins() const;
virtual void loadDuplexModes() const;
virtual void loadColorModes() const;
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
virtual void loadMimeTypes() const;
#endif
@ -178,7 +180,7 @@ protected:
mutable bool m_haveColorModes;
mutable QVector<QPrint::ColorMode> m_colorModes;
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
mutable bool m_haveMimeTypes;
mutable QList<QMimeType> m_mimeTypes;
#endif

View File

@ -260,12 +260,12 @@ bool QPrintDevice::isFeatureAvailable(PrintDevicePropertyKey key, const QVariant
return isValid() ? d->isFeatureAvailable(key, params) : false;
}
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
QList<QMimeType> QPrintDevice::supportedMimeTypes() const
{
return isValid() ? d->supportedMimeTypes() : QList<QMimeType>();
}
#endif // QT_NO_MIMETYPE
#endif // mimetype
# ifndef QT_NO_DEBUG_STREAM
void QPrintDevice::format(QDebug debug) const
@ -296,7 +296,7 @@ void QPrintDevice::format(QDebug debug) const
debug << "), defaultResolution=" << defaultResolution()
<< ", defaultDuplexMode=" << defaultDuplexMode()
<< ", defaultColorMode="<< defaultColorMode();
# ifndef QT_NO_MIMETYPE
# if QT_CONFIG(mimetype)
const QList<QMimeType> mimeTypes = supportedMimeTypes();
if (!mimeTypes.isEmpty()) {
debug << ", supportedMimeTypes=(";
@ -304,7 +304,7 @@ void QPrintDevice::format(QDebug debug) const
debug << " \"" << mimeType.name() << '"';
debug << ')';
}
# endif // !QT_NO_MIMETYPE
# endif // mimetype
} else {
debug << "null";
}

View File

@ -139,7 +139,7 @@ public:
bool setProperty(PrintDevicePropertyKey key, const QVariant &value);
bool isFeatureAvailable(PrintDevicePropertyKey key, const QVariant &params) const;
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
QList<QMimeType> supportedMimeTypes() const;
#endif

View File

@ -59,7 +59,9 @@
#include <stdlib.h>
#include <qsettings.h>
#include <qdebug.h>
#if QT_CONFIG(mimetype)
#include <qmimedatabase.h>
#endif
#include <qapplication.h>
#include <qstylepainter.h>
#include "ui_qfiledialog.h"
@ -1515,7 +1517,7 @@ void QFileDialog::setFilter(QDir::Filters filters)
d->showHiddenAction->setChecked((filters & QDir::Hidden));
}
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
static QString nameFilterForMime(const QString &mimeType)
{
@ -1596,7 +1598,7 @@ void QFileDialog::selectMimeTypeFilter(const QString &filter)
}
}
#endif // QT_NO_MIMETYPE
#endif // mimetype
/*!
* \since 5.9
@ -1609,7 +1611,7 @@ QString QFileDialog::selectedMimeTypeFilter() const
if (!d->usingWidgets())
mimeTypeFilter = d->selectedMimeTypeFilter_sys();
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
if (mimeTypeFilter.isNull() && !d->options->mimeTypeFilters().isEmpty()) {
const auto nameFilter = selectedNameFilter();
const auto mimeTypes = d->options->mimeTypeFilters();
@ -3034,7 +3036,7 @@ void QFileDialogPrivate::createWidgets()
if (!options->sidebarUrls().isEmpty())
q->setSidebarUrls(options->sidebarUrls());
q->setDirectoryUrl(options->initialDirectory());
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
if (!options->mimeTypeFilters().isEmpty())
q->setMimeTypeFilters(options->mimeTypeFilters());
else

View File

@ -127,7 +127,7 @@ public:
QString selectedMimeTypeFilter() const;
QString selectedNameFilter() const;
#ifndef QT_NO_MIMETYPE
#if QT_CONFIG(mimetype)
void setMimeTypeFilters(const QStringList &filters);
QStringList mimeTypeFilters() const;
void selectMimeTypeFilter(const QString &filter);